bool Helper::handleGetSaveX( bool url ) { if( !readArguments( 4 )) return false; QString startDir = getArgument(); QString filter = getArgument().replace("/", "\\/"); // TODO: ignored int selectFilter = getArgument().toInt(); QString title = getArgument(); long wid = getArgumentParent(); if( !allArgumentsUsed()) return false; if (title.isEmpty()) title = i18n("Save As"); // TODO: confirm overwrite if (url) { QUrl result = QFileDialog::getSaveFileUrl(nullptr, title, startDir); if (result.isValid()) { outputLine(QStringLiteral("0")); outputLine(result.url()); return true; } } else { QString result = QFileDialog::getSaveFileName(nullptr, title, startDir); if (!result.isEmpty()) { KRecentDocument::add(QUrl::fromLocalFile(result)); outputLine(QStringLiteral("0")); outputLine(result); return true; } } return false; }
int main(int argc, char *argv[]) { bool running = false; // Two verbosity levels myPrintf[QUIET] = quietprint; myPrintf[VERBOSE] = printf; // Before continuing, read the arguments running = readArguments( argc, argv ); // If the arguments are correct, start a simulation while ( running ) { myPrintf[ verbosemode ] ( "main : running is true\n" ); // Init graphics SDL_Surface * screen = NULL; screen = init_sdl(); // Simulates simulation ( screen ); // End of graphics SDL_FreeSurface(screen); quit_sdl(); // Quit running mode running = false; }; return 0; }
bool Helper::handleGetDirectoryX( bool url ) { if( !readArguments( 2 )) return false; QString startDir = getArgument(); QString title = getArgument(); long wid = getArgumentParent(); if( !allArgumentsUsed()) return false; if (url) { QUrl result = QFileDialog::getExistingDirectoryUrl(nullptr, title, startDir); if (result.isValid()) { outputLine(result.url()); return true; } } else { QString result = QFileDialog::getExistingDirectory(nullptr, title, startDir); if (!result.isEmpty()) { outputLine(QUrl::fromLocalFile(result).url()); return true; } } return false; }
int main(int argc, char *argv[]) { int fhs_file; FHS_HEADERv1 header; clock_t start, end; uint_least16_t docsWritten = 0; initHTML(); initHyperSpaceClassifier(); if(readArguments(argc, argv) == -1) exit(-1); printf("Loading hashes -- be patient!\n"); start=clock(); loadMassCategories(); printf("\nWriting out preload file: %s\n", fhs_out_file); fhs_file = openFHS(fhs_out_file, &header, 1); docsWritten = writeFHSHashesPreload(fhs_file, &header, &HSJudgeHashList); close(fhs_file); end=clock(); printf("Wrote out: %"PRIu32" hashes as %"PRIu16" documents.\n", HSJudgeHashList.used, docsWritten); printf("Preload making took %lf seconds\n", (double)((end-start)/(CLOCKS_PER_SEC))); deinitHyperSpaceClassifier(); deinitHTML(); return 0; }
bool Helper::handleAppsDialog() { if( !readArguments( 1 )) return false; QString title = getArgument(); long wid = getArgumentParent(); if( !allArgumentsUsed()) return false; KOpenWithDialog dialog( NULL ); if( !title.isEmpty()) dialog.setWindowTitle( title ); dialog.hideNoCloseOnExit(); dialog.hideRunInTerminal(); // TODO if( wid != 0 ) KWindowSystem::setMainWindow( &dialog, wid ); if( dialog.exec()) { KService::Ptr service = dialog.service(); QString command; if( service ) command = service->exec(); else if( !dialog.text().isEmpty()) command = dialog.text(); else return false; command = command.split( " " ).first(); // only the actual command command = QStandardPaths::findExecutable(command); if( command.isEmpty()) return false; outputLine( QUrl::fromUserInput( command ).url()); return true; } return false; }
bool Helper::handleReveal() { if( !readArguments( 1 )) return false; QString path = getArgument(); if( !allArgumentsUsed()) return false; //KApplication::updateUserTimestamp( 0 ); // TODO const KService::List apps = KMimeTypeTrader::self()->query("inode/directory", "Application"); if (apps.size() != 0) { QString command = apps.at(0)->exec().split( " " ).first(); // only the actual command if (command == "dolphin" || command == "konqueror") { command = QStandardPaths::findExecutable(command); if( command.isEmpty()) return false; return KProcess::startDetached(command, QStringList() << "--select" << path); } } QFileInfo info(path); QString dir = info.dir().path(); (void) new KRun( QUrl::fromLocalFile(dir), NULL ); // TODO parent return true; // TODO check for errors? }
int main(int argc, char** argv) { readArguments(argc, argv); volume = new Volume(); if(!strcmp(pathExtension, "tif")) volume->loadTIFData(path, firstSlice, lastSlice); else if(!strcmp(pathExtension, "pgm")) volume->loadPGMData(path, firstSlice, lastSlice); else volume->loadRAWData(path, firstSlice, firstSlice, lastSlice); //triCubicInterpolationPreFilter = new TriCubicInterpolationPreFilter(); //triCubicInterpolationPreFilter->applyPreFilterForAccurateCubicBSplineInterpolation(volume->getData(), volume->getWidth(), volume->getHeight(), volume->getDepth()); minMaxOctree = new MinMaxOctree(volume->getWidth(), volume->getHeight(), volume->getDepth()); minMaxOctree->build(volume->getData(), volume->getWidth(), volume->getHeight(), volume->getDepth()); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_ALPHA); glutInitWindowSize(windowWidth, windowHeight); glutCreateWindow("Volume Rendering"); glutReshapeFunc(reshape); glutDisplayFunc(display); glutIdleFunc(idle); glutKeyboardFunc(keyboard); glutSpecialFunc(specialKeyboard); glutMouseFunc(mouse); glewInit(); initGL(); initShader("Shaders/VRBlendRaycasting", VOLUME_RENDERING_SHADER); initShader("Shaders/VRContextPreservingPreIntegrationRaycasting", CONTEXT_PRESERVING_VOLUME_RENDERING_SHADER); initShader("Shaders/VRPreIntegrationRaycasting", PRE_INTEGRATION_TRANSFER_FUNCTION_SHADER); initShader("Shaders/VRLocalIlluminationPreIntegrationRaycasting", LOCAL_ILLUMINATION_SHADER); initShader("Shaders/VRNonPolygonalRaycasting", NON_POLYGONAL_SHADER); initShader("Shaders/FCNormalEstimation", FC_NORMAL_ESTIMATION_SHADER); initShader("Shaders/FCCurvatureEstimation", FC_CURVATURE_ESTIMATION_SHADER); initShader("Shaders/FCFinalRendering", FC_FINAL_RENDERING_SHADER); glUseProgram(0); glutMainLoop(); delete volume; delete minMaxOctree; delete myGLImageViewer; delete myGLCloudViewer; delete transferFunction; delete triCubicInterpolationPreFilter; return 0; }
bool Helper::handleHandlerExists() { if( !readArguments( 1 )) return false; QString protocol = getArgument(); if( !allArgumentsUsed()) return false; return KProtocolInfo::isKnownProtocol( protocol ); }
int main(int argc, char* argv[]) { if(argc == 4) { //remember: argv[0] = executable_name readArguments(argv); } else { printf(RED "Error: Wrong number of arguments\n" RESET); printf("Usage: " YELLOW "calc " MAGENTA " [add|sub|mul|div] " CYAN "[number1] " GREEN "[number2]" RESET "\n"); } return EXIT_SUCCESS; }
bool Helper::handleIsDefaultBrowser() { if( !readArguments( 0 )) return false; QString browser = KConfigGroup( KSharedConfig::openConfig( "kdeglobals" ), "General" ) .readEntry( "BrowserApplication" ); return browser == "MozillaFirefox" || browser == "MozillaFirefox.desktop" || browser == "!firefox" || browser == "!/usr/bin/firefox" || browser == "firefox" || browser == "firefox.desktop"; }
bool Helper::handleRun() { if( !readArguments( 2 )) return false; QString app = getArgument(); QString arg = getArgument(); if( !allArgumentsUsed()) return false; //KApplication::updateUserTimestamp( 0 ); // TODO return KRun::runCommand( KShell::quoteArg( app ) + " " + KShell::quoteArg( arg ), NULL ); // TODO parent, ASN }
bool Helper::handleCheck() { if( !readArguments( 1 )) return false; int version = getArgument().toInt(); // requested version if( !allArgumentsUsed()) return false; if( version <= HELPER_VERSION ) // we must have the exact requested version return true; QTextStream( stderr ) << "KDE helper version too old." << endl; return false; }
bool Helper::handleOpenNews() { if( !readArguments( 0 )) return false; KService::Ptr news = KService::serviceByDesktopName( "knode" ); // TODO there is no KDE setting for this if( news ) { //KApplication::updateUserTimestamp( 0 ); // TODO return KRun::runService( *news, QList<QUrl>(), NULL ); // TODO parent } return false; }
bool Helper::handleGetDefaultFeedReader() { if( !readArguments( 0 )) return false; // firefox wants the full path QString reader = QStandardPaths::findExecutable("akregator"); // TODO there is no KDE setting for this if( !reader.isEmpty()) { outputLine( reader ); return true; } return false; }
void Launcher::init() { _arguments = readArguments(_argc, _argv); prepareSettings(); QCoreApplication::setApplicationName(qsl("TelegramDesktop")); #ifndef OS_MAC_OLD QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling, true); #endif // OS_MAC_OLD initHook(); }
bool Helper::handleGetAppDescForScheme() { if( !readArguments( 1 )) return false; QString scheme = getArgument(); if( !allArgumentsUsed()) return false; QString app = getAppForProtocol( scheme ); if( !app.isEmpty()) { outputLine( app ); return true; } return false; }
bool Helper::handleDownloadFinished() { if( !readArguments( 1 )) return false; QString download = getArgument(); if( !allArgumentsUsed()) return false; // TODO cheat a bit due to i18n freeze - the strings are in the .notifyrc file, // taken from KGet, but the notification itself needs the text too. // So create it from there. KConfig cfg( "kmozillahelper.notifyrc", KConfig::FullConfig, QStandardPaths::AppDataLocation ); QString message = KConfigGroup( &cfg, "Event/downloadfinished" ).readEntry( "Comment" ); KNotification::event( "downloadfinished", download + " : " + message ); return true; }
bool Helper::handleSetDefaultBrowser() { if( !readArguments( 1 )) return false; bool alltypes = ( getArgument() == "ALLTYPES" ); if( !allArgumentsUsed()) return false; KConfigGroup( KSharedConfig::openConfig( "kdeglobals" ), "General" ) .writeEntry( "BrowserApplication", "firefox" ); if( alltypes ) { // TODO there is no API for this and it is a bit complex } return true; }
bool Helper::handleGetFromExtension() { if( !readArguments( 1 )) return false; QString ext = getArgument(); if( !allArgumentsUsed()) return false; if( !ext.isEmpty()) { QList<QMimeType> mimeList = QMimeDatabase().mimeTypesForFileName("foo." + ext); for (const QMimeType &mime : mimeList) if (mime.isValid() && writeMimeInfo(mime)) return true; return false; } return false; }
bool Helper::handleGetOpenX( bool url ) { if( !readArguments( 4 )) return false; QString startDir = getArgument(); QString filter = getArgument().replace("/", "\\/"); // TODO: not used int selectFilter = getArgument().toInt(); QString title = getArgument(); bool multiple = isArgument( "MULTIPLE" ); long wid = getArgumentParent(); if( !allArgumentsUsed()) return false; if (title.isEmpty()) title = i18n("Open"); if (url) { QList<QUrl> result; if (multiple) result = QFileDialog::getOpenFileUrls(nullptr, title, startDir); else result << QFileDialog::getOpenFileUrl(nullptr, title, startDir); result.removeAll(QUrl()); if (!result.isEmpty()) { outputLine(QStringLiteral("0")); // filter is not implemented, so always 0 (All Files) for (const QUrl &url : result) outputLine(url.url()); return true; } } else { QStringList result; if (multiple) result = QFileDialog::getOpenFileNames(nullptr, title, startDir); else result << QFileDialog::getOpenFileName(nullptr, title, startDir); result.removeAll(QString()); if (!result.isEmpty()) { outputLine(QStringLiteral("0")); for (const QString &str : result) outputLine(str); return true; } } return false; }
bool Helper::handleGetFromType() { if( !readArguments( 1 )) return false; QString type = getArgument(); if( !allArgumentsUsed()) return false; QMimeType mime = QMimeDatabase().mimeTypeForName(type); if (mime.isValid()) return writeMimeInfo(mime); // firefox also asks for protocol handlers using getfromtype QString app = getAppForProtocol( type ); if( !app.isEmpty()) { outputLine( type ); outputLine( type ); // TODO probably no way to find a good description outputLine( app ); return true; } return false; }
bool Helper::handleOpen() { if( !readArguments( 1 )) return false; QUrl url = QUrl::fromUserInput(getArgument()); QString mime; if( isArgument( "MIMETYPE" )) mime = getArgument(); if( !allArgumentsUsed()) return false; //KApplication::updateUserTimestamp( 0 ); // TODO // try to handle the case when the server has broken mimetypes and e.g. claims something is application/octet-stream QMimeType mimeType = QMimeDatabase().mimeTypeForName(mime); if (!mime.isEmpty() && mimeType.isValid() && KMimeTypeTrader::self()->preferredService(mimeType.name())) return KRun::runUrl( url, mime, NULL ); // TODO parent else { (void) new KRun( url, NULL ); // TODO parent // QObject::connect( run, SIGNAL( finished()), &app, SLOT( openDone())); // QObject::connect( run, SIGNAL( error()), &app, SLOT( openDone())); return true; // TODO check for errors? } }
bool Helper::handleGetProxy() { if( !readArguments( 1 )) return false; QUrl url = QUrl::fromUserInput( getArgument()); if( !allArgumentsUsed()) return false; QString proxy; KProtocolManager::slaveProtocol( url, proxy ); if( proxy.isEmpty() || proxy == "DIRECT" ) // TODO return DIRECT if empty? { outputLine( "DIRECT" ); return true; } QUrl proxyurl = QUrl::fromUserInput( proxy ); if( proxyurl.isValid()) { // firefox wants this format outputLine( "PROXY" " " + proxyurl.host() + ":" + QString::number( proxyurl.port())); // TODO there is also "SOCKS " type return true; } return false; }
bool StaticRecordsReader::readRecord(char *mem, qint64 memSize, qint64 pos, qint64 &readedSize, Record &record, SimpleEventInfo *info) { quint64 time = 0; if(!translateArg(mem, memSize, pos, time)) return false; readedSize += sizeof(quint64); char *bytesValue = new char[sizeof(quint64)]; copyArg(mem, bytesValue, pos, sizeof(quint64)); pos += sizeof(quint64); record.byteRecord.append(bytesValue, sizeof(quint64)); record.time = time; delete[] bytesValue; quint8 eventID = 0; if(!translateArg(mem, memSize, pos, eventID)) return false; readedSize += sizeof(quint8); bytesValue = new char[sizeof(quint8)]; copyArg(mem, bytesValue, pos, sizeof(quint8)); pos += sizeof(quint8); record.byteRecord.append(bytesValue, sizeof(quint8)); record.eventID = eventID; delete[] bytesValue; if(!readArguments(mem, memSize, pos, readedSize, record, info, eventID)) return false; return true; }
bool Helper::handleOpenMail() { if( !readArguments( 0 )) return false; // this is based on ktoolinvocation_x11.cpp, there is no API for this KConfig config( "emaildefaults" ); QString groupname = KConfigGroup( &config, "Defaults" ).readEntry( "Profile", "Default" ); KConfigGroup group( &config, QString( "PROFILE_%1" ).arg( groupname )); QString command = group.readPathEntry( "EmailClient", QString()); if( command.isEmpty()) command = "kmail"; if( group.readEntry( "TerminalClient", false )) { QString terminal = KConfigGroup( KSharedConfig::openConfig(), "General" ).readPathEntry( "TerminalApplication", "konsole" ); command = terminal + " -e " + command; } KService::Ptr mail = KService::serviceByDesktopName( command.split( " " ).first()); if( mail ) { //KApplication::updateUserTimestamp( 0 ); // TODO return KRun::runService( *mail, QList<QUrl>(), NULL ); // TODO parent } return false; }
int main(int argc, const char * argv[]) { printVersion(); // check number of arguments and if all arguments can be read if (argc < 3 || !readArguments(argc, argv)) { printUsage(); return -1; } // check if the input path exist if (!FS_NAMESPACE::exists(inFilePath)) { std::cout << "Error: Invalid input file/directory \"" << inFilePath.string() << "\"!" << std::endl; return -2; } if (createBinary) { // check if argument 2 is a file if (FS_NAMESPACE::is_directory(outFilePath)) { std::cout << "Error: Output must be a file if -b is used!" << std::endl; return -2; } } else if (appendFile) { // check if argument 2 is a file if (FS_NAMESPACE::is_directory(outFilePath)) { std::cout << "Error: Output must be a file if -a is used!" << std::endl; return -2; } } else if (FS_NAMESPACE::is_directory(inFilePath) != FS_NAMESPACE::is_directory(outFilePath)) { // check if output directory exists if (FS_NAMESPACE::is_directory(outFilePath) && !FS_NAMESPACE::exists(outFilePath)) { std::cout << "Error: Invalid output directory \"" << outFilePath.string() << "\"!" << std::endl; return -2; } // check if arguments 1 and 2 are both files or both directories std::cout << "Error: Input and output file must be both either a file or a directory!" << std::endl; return -2; } if (appendFile) { // append file a to b if (!appendAtoB(outFilePath, inFilePath)) { std::cout << "Error: Failed to append data to executable!" << std::endl; return -3; } } else { // build list of files to process std::vector<FileData> fileList; if (FS_NAMESPACE::is_directory(inFilePath) && FS_NAMESPACE::is_directory(inFilePath)) { // both files are directories, build file ist fileList = getFileDataFrom(inFilePath, outFilePath, inFilePath, useRecursion); if (fileList.empty()) { std::cout << "Error: No files to convert!" << std::endl; return -3; } } else { // just add single input/output file FileData temp; temp.inPath = inFilePath; temp.outPath = outFilePath; temp.internalName = inFilePath.filename().string(); // remove all, but the file name and extension if (beVerbose) { std::cout << "Found input file " << inFilePath << std::endl; std::cout << "Internal name will be \"" << temp.internalName << "\"" << std::endl; std::cout << "Output path is " << temp.outPath << std::endl; } // get file size try { temp.size = static_cast<uint64_t>(FS_NAMESPACE::file_size(inFilePath)); if (beVerbose) { std::cout << "Size is " << temp.size << " bytes." << std::endl; } } catch (...) { std::cout << "Error: Failed to get size of " << inFilePath << "!" << std::endl; temp.size = 0; } fileList.push_back(temp); } // does the user want an binary file? if (createBinary) { // yes. build it. if (!createBlob(fileList, outFilePath)) { std::cout << "Error: Failed to convert to binary file!" << std::endl; return -4; } } else { // no. convert files to .c/.cpp. loop through list, converting files for (auto fdIt = fileList.begin(); fdIt != fileList.cend(); ++fdIt) { if (!convertFile(*fdIt, commonHeaderFilePath)) { std::cout << "Error: Failed to convert all files. Aborting!" << std::endl; return -4; } } // do we need to write a header file? if (!commonHeaderFilePath.empty()) { if (!createCommonHeader(fileList, commonHeaderFilePath, !utilitiesFilePath.empty(), useC)) { return -5; } // do we need to create utilities? if (!utilitiesFilePath.empty()) { if (!createUtilities(fileList, utilitiesFilePath, commonHeaderFilePath, useC, combineResults)) { return -6; } } } } } // if (!appendFile) { // profit!!! std::cout << "res2h succeeded." << std::endl; return 0; }