rem
stringlengths
0
274k
add
stringlengths
0
169k
context
stringlengths
9
471k
I18N_NOOP("Informs KDE about a change in hostname."),
I18N_NOOP("Informs KDE about a change in hostname"),
int main(int argc, char **argv){ KLocale::setMainCatalogue("kdelibs"); KAboutData d(appName, I18N_NOOP("KDontChangeTheHostName"), appVersion, I18N_NOOP("Informs KDE about a change in hostname."), KAboutData::License_GPL, "(c) 2001 Waldo Bastian"); d.addAuthor("Waldo Bastian", I18N_NOOP("Author"), "[email protected]"); KCmdLineArgs::init(argc, argv, &d); KCmdLineArgs::addCmdLineOptions(options); KInstance k(&d); KHostName hn; hn.changeX(); hn.changeDcop(); hn.changeStdDirs("socket"); hn.changeStdDirs("tmp"); hn.changeSessionManager();}
konfig = new KConfig(file, true, args->isSet("usekdeglobals"));
konfig = new KConfig(file, true, false);
int main(int argc, char **argv){ KAboutData aboutData("kreadconfig", I18N_NOOP("KReadConfig"), "1.0.1", I18N_NOOP("Read KConfig entries - for use in shell scripts"), KAboutData::License_GPL, "(c) 2001 Red Hat, Inc."); aboutData.addAuthor("Bernhard Rosenkraenzer", 0, "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args=KCmdLineArgs::parsedArgs(); QString group=QString::fromLocal8Bit(args->getOption("group")); QString key=QString::fromLocal8Bit(args->getOption("key")); QString file=QString::fromLocal8Bit(args->getOption("file")); QCString dflt=args->getOption("default"); QCString type=args->getOption("type").lower(); if (key.isNull()) { KCmdLineArgs::usage(); return 1; } KInstance inst(&aboutData); KConfig *konfig; bool configMustDeleted = false; if (file.isEmpty()) konfig = KGlobal::config(); else { konfig = new KConfig(file, true, args->isSet("usekdeglobals")); configMustDeleted=true; } konfig->setGroup(group); if(type=="bool") { dflt=dflt.lower(); bool def=(dflt=="true" || dflt=="on" || dflt=="yes" || dflt=="1"); bool retValue = !konfig->readBoolEntry(key, def); if ( configMustDeleted ) delete konfig; return retValue; } else if((type=="num") || (type=="int")) { long retValue = konfig->readLongNumEntry(key, dflt.toLong()); if ( configMustDeleted ) delete konfig; return retValue; } else if (type=="path"){ fprintf(stdout, "%s\n", konfig->readPathEntry(key, dflt).local8Bit().data()); if ( configMustDeleted ) delete konfig; return 0; } else { /* Assume it's a string... */ fprintf(stdout, "%s\n", konfig->readEntry(key, dflt).local8Bit().data()); if ( configMustDeleted ) delete konfig; return 0; }}
cerr << "fakesyn starting" << endl;
int main(int oargc, char **oargv) { cerr << "fakesyn starting" << endl; int argc; char **argv; parse_config_options(oargc, oargv, argc, argv); int start = 0; // build new argc+argv for fuse typedef char* pchar; int nargc = 0; char **nargv = new pchar[argc]; nargv[nargc++] = argv[0]; string syn_sarg1; int syn_mode = SYNCLIENT_MODE_WRITEFILE; int syn_iarg1, syn_iarg2, syn_iarg3; int mkfs = 0; for (int i=1; i<argc; i++) { if (strcmp(argv[i], "--fastmkfs") == 0) { mkfs = MDS_MKFS_FAST; } else if (strcmp(argv[i], "--fullmkfs") == 0) { mkfs = MDS_MKFS_FULL; } else if (strcmp(argv[i],"--synsarg1") == 0) syn_sarg1 = argv[++i]; else if (strcmp(argv[i],"--syniarg1") == 0) syn_iarg1 = atoi(argv[++i]); else if (strcmp(argv[i],"--syniarg2") == 0) syn_iarg2 = atoi(argv[++i]); else if (strcmp(argv[i],"--syniarg3") == 0) syn_iarg3 = atoi(argv[++i]); else if (strcmp(argv[i],"--synmode") == 0) { ++i; if (strcmp(argv[i],"writefile") == 0) syn_mode = SYNCLIENT_MODE_WRITEFILE; else if (strcmp(argv[i],"makedirs") == 0) syn_mode = SYNCLIENT_MODE_MAKEDIRS; else if (strcmp(argv[i],"fullwalk") == 0) syn_mode = SYNCLIENT_MODE_FULLWALK; else if (strcmp(argv[i],"randomwalk") == 0) syn_mode = SYNCLIENT_MODE_RANDOMWALK; else { cerr << "unknown syn mode " << argv[i] << endl; return -1; } } else { // unknown arg, pass it on. nargv[nargc++] = argv[i]; } } MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD); char hostname[100]; gethostname(hostname,100); int pid = getpid(); // create mds MDS *mds[NUMMDS]; for (int i=0; i<NUMMDS; i++) { //cerr << "mds" << i << " on rank " << myrank << " " << hostname << "." << pid << endl; mds[i] = new MDS(mdc, i, new FakeMessenger(MSG_ADDR_MDS(i))); start++; } // create osd OSD *osd[NUMOSD]; for (int i=0; i<NUMOSD; i++) { //cerr << "osd" << i << " on rank " << myrank << " " << hostname << "." << pid << endl; osd[i] = new OSD(i, new FakeMessenger(MSG_ADDR_OSD(i))); start++; } // create client Client *client[NUMCLIENT]; SyntheticClient *syn[NUMCLIENT]; for (int i=0; i<NUMCLIENT; i++) { //cerr << "client" << i << " on rank " << myrank << " " << hostname << "." << pid << endl; CheesySerializer *serializer = new CheesySerializer( new FakeMessenger(MSG_ADDR_CLIENT(i)) ); client[i] = new Client(mdc, i, serializer); start++; } // start message loop fakemessenger_startthread(); // init for (int i=0; i<NUMMDS; i++) { mds[i]->init(); } for (int i=0; i<NUMOSD; i++) { osd[i]->init(); } // create client for (int i=0; i<NUMCLIENT; i++) { client[i]->init(); // use my argc, argv (make sure you pass a mount point!) //cout << "mounting" << endl; client[i]->mount(mkfs); //cout << "starting synthetic client " << endl; syn[i] = new SyntheticClient(client[i]); char s[20]; sprintf(s,"syn.%d", i); syn[i]->sarg1 = s; syn[i]->mode = syn_mode; syn[i]->iarg1 = syn_iarg1; syn[i]->iarg2 = syn_iarg2; syn[i]->iarg3 = syn_iarg3; syn[i]->start_thread(); } for (int i=0; i<NUMCLIENT; i++) { cout << "waiting for synthetic client " << i << " to finish" << endl; syn[i]->join_thread(); delete syn[i]; client[i]->unmount(); //cout << "unmounted" << endl; client[i]->shutdown(); } // wait for it to finish fakemessenger_wait(); // cleanup for (int i=0; i<NUMMDS; i++) { delete mds[i]; } for (int i=0; i<NUMOSD; i++) { delete osd[i]; } for (int i=0; i<NUMCLIENT; i++) { delete client[i]; } delete mdc; free(argv); delete[] nargv; cout << "fakesyn done" << endl; return 0;}
CheesySerializer *serializer = new CheesySerializer( new FakeMessenger(MSG_ADDR_CLIENT(i)) ); client[i] = new Client(mdc, i, serializer);
client[i] = new Client(mdc, i, new FakeMessenger(MSG_ADDR_CLIENT(i)));
int main(int oargc, char **oargv) { cerr << "fakesyn starting" << endl; int argc; char **argv; parse_config_options(oargc, oargv, argc, argv); int start = 0; // build new argc+argv for fuse typedef char* pchar; int nargc = 0; char **nargv = new pchar[argc]; nargv[nargc++] = argv[0]; string syn_sarg1; int syn_mode = SYNCLIENT_MODE_WRITEFILE; int syn_iarg1, syn_iarg2, syn_iarg3; int mkfs = 0; for (int i=1; i<argc; i++) { if (strcmp(argv[i], "--fastmkfs") == 0) { mkfs = MDS_MKFS_FAST; } else if (strcmp(argv[i], "--fullmkfs") == 0) { mkfs = MDS_MKFS_FULL; } else if (strcmp(argv[i],"--synsarg1") == 0) syn_sarg1 = argv[++i]; else if (strcmp(argv[i],"--syniarg1") == 0) syn_iarg1 = atoi(argv[++i]); else if (strcmp(argv[i],"--syniarg2") == 0) syn_iarg2 = atoi(argv[++i]); else if (strcmp(argv[i],"--syniarg3") == 0) syn_iarg3 = atoi(argv[++i]); else if (strcmp(argv[i],"--synmode") == 0) { ++i; if (strcmp(argv[i],"writefile") == 0) syn_mode = SYNCLIENT_MODE_WRITEFILE; else if (strcmp(argv[i],"makedirs") == 0) syn_mode = SYNCLIENT_MODE_MAKEDIRS; else if (strcmp(argv[i],"fullwalk") == 0) syn_mode = SYNCLIENT_MODE_FULLWALK; else if (strcmp(argv[i],"randomwalk") == 0) syn_mode = SYNCLIENT_MODE_RANDOMWALK; else { cerr << "unknown syn mode " << argv[i] << endl; return -1; } } else { // unknown arg, pass it on. nargv[nargc++] = argv[i]; } } MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD); char hostname[100]; gethostname(hostname,100); int pid = getpid(); // create mds MDS *mds[NUMMDS]; for (int i=0; i<NUMMDS; i++) { //cerr << "mds" << i << " on rank " << myrank << " " << hostname << "." << pid << endl; mds[i] = new MDS(mdc, i, new FakeMessenger(MSG_ADDR_MDS(i))); start++; } // create osd OSD *osd[NUMOSD]; for (int i=0; i<NUMOSD; i++) { //cerr << "osd" << i << " on rank " << myrank << " " << hostname << "." << pid << endl; osd[i] = new OSD(i, new FakeMessenger(MSG_ADDR_OSD(i))); start++; } // create client Client *client[NUMCLIENT]; SyntheticClient *syn[NUMCLIENT]; for (int i=0; i<NUMCLIENT; i++) { //cerr << "client" << i << " on rank " << myrank << " " << hostname << "." << pid << endl; CheesySerializer *serializer = new CheesySerializer( new FakeMessenger(MSG_ADDR_CLIENT(i)) ); client[i] = new Client(mdc, i, serializer); start++; } // start message loop fakemessenger_startthread(); // init for (int i=0; i<NUMMDS; i++) { mds[i]->init(); } for (int i=0; i<NUMOSD; i++) { osd[i]->init(); } // create client for (int i=0; i<NUMCLIENT; i++) { client[i]->init(); // use my argc, argv (make sure you pass a mount point!) //cout << "mounting" << endl; client[i]->mount(mkfs); //cout << "starting synthetic client " << endl; syn[i] = new SyntheticClient(client[i]); char s[20]; sprintf(s,"syn.%d", i); syn[i]->sarg1 = s; syn[i]->mode = syn_mode; syn[i]->iarg1 = syn_iarg1; syn[i]->iarg2 = syn_iarg2; syn[i]->iarg3 = syn_iarg3; syn[i]->start_thread(); } for (int i=0; i<NUMCLIENT; i++) { cout << "waiting for synthetic client " << i << " to finish" << endl; syn[i]->join_thread(); delete syn[i]; client[i]->unmount(); //cout << "unmounted" << endl; client[i]->shutdown(); } // wait for it to finish fakemessenger_wait(); // cleanup for (int i=0; i<NUMMDS; i++) { delete mds[i]; } for (int i=0; i<NUMOSD; i++) { delete osd[i]; } for (int i=0; i<NUMCLIENT; i++) { delete client[i]; } delete mdc; free(argv); delete[] nargv; cout << "fakesyn done" << endl; return 0;}
if (id != app.dcopClient()->registerAs(id))
if (id != app.dcopClient()->registerAs(id, false))
int main(int argc, char *argv[]){ KApplication app(argc, argv, "kcmroot"); app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); // see if we really run as root if (getuid() != 0) { cerr << "Only root will run this program!" << endl; exit(-1); } // check parameters if ((argc < 2) || (argc > 3)) { cerr << i18n("usage: kcmroot module.desktop [dcopserver]") << endl; exit(-1); } // load the module ModuleInfo info(argv[1]); KCModule *module = ModuleLoader::module(info, 0); if (module) { RemoteProxy proxy(module, info.moduleId()); if (!app.dcopClient()->attach()) return -1; QCString id = info.moduleId(); if (id != app.dcopClient()->registerAs(id)) cerr << "Warning: multiple instances registered" << endl; // show the proxy module->move(10000, 10000); return app.exec(); } return -1;}
if(qApp->applicationFilePath().contains("/src/qgis"))
int main(int argc, char *argv[]){ ///////////////////////////////////////////////////////////////// // Command line options 'behaviour' flag setup //////////////////////////////////////////////////////////////// // // Parse the command line arguments, looking to see if the user has asked for any // special behaviours. Any remaining non command arguments will be kept aside to // be passed as a list of layers and / or a project that should be loaded. // // This behaviour is used to load the app, snapshot the map, // save the image to disk and then exit QString mySnapshotFileName=""; // This behaviour will cause QGIS to autoload a project QString myProjectFileName=""; // This behaviour will allow you to force the use of a translation file // which is useful for testing QString myTranslationFileName=""; // This is the 'leftover' arguments collection QStringList * myFileList=new QStringList();#ifndef WIN32 if ( !bundleclicked(argc, argv) ) { //////////////////////////////////////////////////////////////// // USe the GNU Getopts utility to parse cli arguments // Invokes ctor `GetOpt (int argc, char **argv, char *optstring);' /////////////////////////////////////////////////////////////// int optionChar; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"snapshot", required_argument, 0, 's'}, {"lang", required_argument, 0, 'l'}, {"project", required_argument, 0, 'p'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "slp", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 's': mySnapshotFileName = optarg; break; case 'l': myTranslationFileName = optarg; break; case 'p': myProjectFileName = optarg; break; case 'h': case '?': usage( argv[0] ); return 2; // XXX need standard exit codes break; default: std::cerr << argv[0] << ": getopt returned character code " << optionChar << "\n"; return 1; // XXX need standard exit codes } } // Add any remaining args to the file list - we will attempt to load them // as layers in the map view further down....#ifdef QGISDEBUG std::cout << "Files specified on command line: " << optind << std::endl;#endif if (optind < argc) { while (optind < argc) {#ifdef QGISDEBUG int idx = optind; std::cout << idx << ": " << argv[idx] << std::endl;#endif myFileList->append(argv[optind++]); } } }#endif //WIN32 ///////////////////////////////////////////////////////////////////// // Now we have the handlers for the different behaviours... //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// // Initialise the application and the translation stuff /////////////////////////////////////////////////////////////////////#ifdef Q_WS_X11 bool myUseGuiFlag = getenv( "DISPLAY" ) != 0;#else bool myUseGuiFlag = TRUE;#endif if (!myUseGuiFlag) { std::cerr << "QGIS starting in non-interactive mode not supported.\n You are seeing this message most likely because you have no DISPLAY environment variable set." << std::endl; exit(1); //exit for now until a version of qgis is capabable of running non interactive } QApplication a(argc, argv, myUseGuiFlag ); // Check to see if qgis was started from the source directory. // This is done by looking for Makefile in the directory where qgis was // started from. If running from the src directory, exit gracefully if(qApp->applicationFilePath().contains("/src/qgis")) { // check to see if configure is present in the directory QFileInfo fi(qApp->applicationDirPath() + "/Makefile"); if(fi.exists()) { QMessageBox::critical(0,"QGIS Not Installed", "You appear to be running QGIS from the source directory.\n" "You must install QGIS using make install and run it from the " "installed directory."); exit(1); } } // a.setFont(QFont("helvetica", 11));#if defined(Q_OS_MACX) || defined(WIN32) QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";#endif QTranslator tor(0); // For WIN32, get the locale if (myTranslationFileName!="") { QString translation = "qgis_" + myTranslationFileName; tor.load(translation, QString(PKGDATAPATH) + "/i18n"); } else {#ifdef QGISDEBUG std::cout << "Setting translation to " << PKGDATAPATH << "/i18n/qgis_" << QTextCodec::locale() << std::endl; #endif tor.load(QString("qgis_") + QTextCodec::locale(), QString(PKGDATAPATH) + "/i18n"); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp; // "QgisApp" used to find canonical instance qgis->setName( "QgisApp" ); a.setMainWidget(qgis); ///////////////////////////////////////////////////////////////////// // If no --project was specified, parse the args to look for a // // .qgs file and set myProjectFileName to it. This allows loading // // of a project file by clicking on it in various desktop managers // // where an appropriate mime-type has been set up. // ///////////////////////////////////////////////////////////////////// if(myProjectFileName.isEmpty()) { // check for a .qgs for(int i = 0; i < argc; i++) { QString arg = argv[i]; if(arg.contains(".qgs")) { myProjectFileName = argv[i]; break; } } } ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if( ! myProjectFileName.isEmpty() ) {// if ( ! qgis->addProject(myProjectFileName) )// {// #ifdef QGISDEBUG// std::cerr << "unable to load project " << myProjectFileName << "\n";// #endif// } try { if ( ! qgis->addProject(myProjectFileName) ) {#ifdef QGISDEBUG std::cerr << "unable to load project " << myProjectFileName << "\n";#endif } } catch ( QgsIOException & io_exception ) { QMessageBox::critical( 0x0, "QGIS: Unable to load project", "Unable to load project " + myProjectFileName ); } } ///////////////////////////////////////////////////////////////////// // autoload any filenames that were passed in on the command line /////////////////////////////////////////////////////////////////////#ifdef QGISDEBUG std::cout << "Number of files in myFileList: " << myFileList->count() << std::endl;#endif for ( QStringList::Iterator myIterator = myFileList->begin(); myIterator != myFileList->end(); ++myIterator ) {#ifdef QGISDEBUG std::cout << "Trying to load file : " << *myIterator << std::endl;#endif QString myLayerName = *myIterator; // don't load anything with a .qgs extension - these are project files if(!myLayerName.contains(".qgs")) { // try to add all these layers - any unsupported file types will // be rejected automatically // The funky bool ok is so this can be debugged a bit easier... //nope - try and load it as raster bool ok = qgis->addRasterLayer(QFileInfo(myLayerName), false); if(!ok){ //nope - try and load it as a shape/ogr ok = qgis->addLayer(QFileInfo(myLayerName)); //we have no idea what this layer is... if(!ok){ std::cout << "Unable to load " << myLayerName << std::endl; } } } } ///////////////////////////////////////////////////////////////////// // Take a snapshot of the map view then exit if snapshot mode requested ///////////////////////////////////////////////////////////////////// if(mySnapshotFileName!="") { /*You must have at least one paintEvent() delivered for the window to be rendered properly. It looks like you don't run the event loop in non-interactive mode, so the event is never occuring. To achieve this without runing the event loop: show the window, then call qApp->processEvents(), grab the pixmap, save it, hide the window and exit. */ //qgis->show(); a.processEvents(); QPixmap * myQPixmap = new QPixmap(800,600); myQPixmap->fill(); qgis->saveMapAsImage(mySnapshotFileName,myQPixmap); a.processEvents(); qgis->hide(); return 1; } ///////////////////////////////////////////////////////////////////// // Continue on to interactive gui... ///////////////////////////////////////////////////////////////////// qgis->show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec();}
QFileInfo fi(qApp->applicationDirPath() + "/Makefile");
QFileInfo fi(appDir + "/" + testFile);
int main(int argc, char *argv[]){ ///////////////////////////////////////////////////////////////// // Command line options 'behaviour' flag setup //////////////////////////////////////////////////////////////// // // Parse the command line arguments, looking to see if the user has asked for any // special behaviours. Any remaining non command arguments will be kept aside to // be passed as a list of layers and / or a project that should be loaded. // // This behaviour is used to load the app, snapshot the map, // save the image to disk and then exit QString mySnapshotFileName=""; // This behaviour will cause QGIS to autoload a project QString myProjectFileName=""; // This behaviour will allow you to force the use of a translation file // which is useful for testing QString myTranslationFileName=""; // This is the 'leftover' arguments collection QStringList * myFileList=new QStringList();#ifndef WIN32 if ( !bundleclicked(argc, argv) ) { //////////////////////////////////////////////////////////////// // USe the GNU Getopts utility to parse cli arguments // Invokes ctor `GetOpt (int argc, char **argv, char *optstring);' /////////////////////////////////////////////////////////////// int optionChar; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"snapshot", required_argument, 0, 's'}, {"lang", required_argument, 0, 'l'}, {"project", required_argument, 0, 'p'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "slp", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 's': mySnapshotFileName = optarg; break; case 'l': myTranslationFileName = optarg; break; case 'p': myProjectFileName = optarg; break; case 'h': case '?': usage( argv[0] ); return 2; // XXX need standard exit codes break; default: std::cerr << argv[0] << ": getopt returned character code " << optionChar << "\n"; return 1; // XXX need standard exit codes } } // Add any remaining args to the file list - we will attempt to load them // as layers in the map view further down....#ifdef QGISDEBUG std::cout << "Files specified on command line: " << optind << std::endl;#endif if (optind < argc) { while (optind < argc) {#ifdef QGISDEBUG int idx = optind; std::cout << idx << ": " << argv[idx] << std::endl;#endif myFileList->append(argv[optind++]); } } }#endif //WIN32 ///////////////////////////////////////////////////////////////////// // Now we have the handlers for the different behaviours... //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// // Initialise the application and the translation stuff /////////////////////////////////////////////////////////////////////#ifdef Q_WS_X11 bool myUseGuiFlag = getenv( "DISPLAY" ) != 0;#else bool myUseGuiFlag = TRUE;#endif if (!myUseGuiFlag) { std::cerr << "QGIS starting in non-interactive mode not supported.\n You are seeing this message most likely because you have no DISPLAY environment variable set." << std::endl; exit(1); //exit for now until a version of qgis is capabable of running non interactive } QApplication a(argc, argv, myUseGuiFlag ); // Check to see if qgis was started from the source directory. // This is done by looking for Makefile in the directory where qgis was // started from. If running from the src directory, exit gracefully if(qApp->applicationFilePath().contains("/src/qgis")) { // check to see if configure is present in the directory QFileInfo fi(qApp->applicationDirPath() + "/Makefile"); if(fi.exists()) { QMessageBox::critical(0,"QGIS Not Installed", "You appear to be running QGIS from the source directory.\n" "You must install QGIS using make install and run it from the " "installed directory."); exit(1); } } // a.setFont(QFont("helvetica", 11));#if defined(Q_OS_MACX) || defined(WIN32) QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";#endif QTranslator tor(0); // For WIN32, get the locale if (myTranslationFileName!="") { QString translation = "qgis_" + myTranslationFileName; tor.load(translation, QString(PKGDATAPATH) + "/i18n"); } else {#ifdef QGISDEBUG std::cout << "Setting translation to " << PKGDATAPATH << "/i18n/qgis_" << QTextCodec::locale() << std::endl; #endif tor.load(QString("qgis_") + QTextCodec::locale(), QString(PKGDATAPATH) + "/i18n"); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp; // "QgisApp" used to find canonical instance qgis->setName( "QgisApp" ); a.setMainWidget(qgis); ///////////////////////////////////////////////////////////////////// // If no --project was specified, parse the args to look for a // // .qgs file and set myProjectFileName to it. This allows loading // // of a project file by clicking on it in various desktop managers // // where an appropriate mime-type has been set up. // ///////////////////////////////////////////////////////////////////// if(myProjectFileName.isEmpty()) { // check for a .qgs for(int i = 0; i < argc; i++) { QString arg = argv[i]; if(arg.contains(".qgs")) { myProjectFileName = argv[i]; break; } } } ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if( ! myProjectFileName.isEmpty() ) {// if ( ! qgis->addProject(myProjectFileName) )// {// #ifdef QGISDEBUG// std::cerr << "unable to load project " << myProjectFileName << "\n";// #endif// } try { if ( ! qgis->addProject(myProjectFileName) ) {#ifdef QGISDEBUG std::cerr << "unable to load project " << myProjectFileName << "\n";#endif } } catch ( QgsIOException & io_exception ) { QMessageBox::critical( 0x0, "QGIS: Unable to load project", "Unable to load project " + myProjectFileName ); } } ///////////////////////////////////////////////////////////////////// // autoload any filenames that were passed in on the command line /////////////////////////////////////////////////////////////////////#ifdef QGISDEBUG std::cout << "Number of files in myFileList: " << myFileList->count() << std::endl;#endif for ( QStringList::Iterator myIterator = myFileList->begin(); myIterator != myFileList->end(); ++myIterator ) {#ifdef QGISDEBUG std::cout << "Trying to load file : " << *myIterator << std::endl;#endif QString myLayerName = *myIterator; // don't load anything with a .qgs extension - these are project files if(!myLayerName.contains(".qgs")) { // try to add all these layers - any unsupported file types will // be rejected automatically // The funky bool ok is so this can be debugged a bit easier... //nope - try and load it as raster bool ok = qgis->addRasterLayer(QFileInfo(myLayerName), false); if(!ok){ //nope - try and load it as a shape/ogr ok = qgis->addLayer(QFileInfo(myLayerName)); //we have no idea what this layer is... if(!ok){ std::cout << "Unable to load " << myLayerName << std::endl; } } } } ///////////////////////////////////////////////////////////////////// // Take a snapshot of the map view then exit if snapshot mode requested ///////////////////////////////////////////////////////////////////// if(mySnapshotFileName!="") { /*You must have at least one paintEvent() delivered for the window to be rendered properly. It looks like you don't run the event loop in non-interactive mode, so the event is never occuring. To achieve this without runing the event loop: show the window, then call qApp->processEvents(), grab the pixmap, save it, hide the window and exit. */ //qgis->show(); a.processEvents(); QPixmap * myQPixmap = new QPixmap(800,600); myQPixmap->fill(); qgis->saveMapAsImage(mySnapshotFileName,myQPixmap); a.processEvents(); qgis->hide(); return 1; } ///////////////////////////////////////////////////////////////////// // Continue on to interactive gui... ///////////////////////////////////////////////////////////////////// qgis->show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec();}
qDebug( "kio_ftp : Starting");
KInstance instance( "kio_ftp" );
int main( int, char ** ){ signal(SIGCHLD, KIOProtocol::sigchld_handler); signal(SIGSEGV, KIOProtocol::sigsegv_handler); // KProtocolManager manager; qDebug( "kio_ftp : Starting"); KInstance instance( "kio_ftp" ); KIOConnection parent( 0, 1 ); FtpProtocol ftp( &parent ); ftp.dispatchLoop(); qDebug( "kio_ftp : Done" );}
KInstance instance( "kio_ftp" );
kdebug( KDEBUG_INFO, 0, "Starting");
int main( int, char ** ){ signal(SIGCHLD, KIOProtocol::sigchld_handler); signal(SIGSEGV, KIOProtocol::sigsegv_handler); // KProtocolManager manager; qDebug( "kio_ftp : Starting"); KInstance instance( "kio_ftp" ); KIOConnection parent( 0, 1 ); FtpProtocol ftp( &parent ); ftp.dispatchLoop(); qDebug( "kio_ftp : Done" );}
qDebug( "kio_ftp : Done" );
kdebug( KDEBUG_INFO, 0, "Done");
int main( int, char ** ){ signal(SIGCHLD, KIOProtocol::sigchld_handler); signal(SIGSEGV, KIOProtocol::sigsegv_handler); // KProtocolManager manager; qDebug( "kio_ftp : Starting"); KInstance instance( "kio_ftp" ); KIOConnection parent( 0, 1 ); FtpProtocol ftp( &parent ); ftp.dispatchLoop(); qDebug( "kio_ftp : Done" );}
fakemessenger_stopthread();
fakemessenger_wait();
int main(int oargc, char **oargv) { cerr << "fakefuse starting" << endl; int argc; char **argv; parse_config_options(oargc, oargv, argc, argv); MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD); // start messenger thread fakemessenger_startthread(); //g_timer.add_event_after(5.0, new C_Test2); //g_timer.add_event_after(10.0, new C_Test); int mkfs = 0; for (int i=1; i<argc; i++) { if (strcmp(argv[i], "--fastmkfs") == 0) { mkfs = MDS_MKFS_FAST; argv[i] = 0; argc--; break; } if (strcmp(argv[i], "--fullmkfs") == 0) { mkfs = MDS_MKFS_FULL; argv[i] = 0; argc--; break; } } // create osd OSD *osd[NUMOSD]; for (int i=0; i<NUMOSD; i++) { osd[i] = new OSD(i, new FakeMessenger(MSG_ADDR_OSD(i))); osd[i]->init(); } // create mds MDS *mds[NUMMDS]; for (int i=0; i<NUMMDS; i++) { mds[i] = new MDS(mdc, i, new FakeMessenger(MSG_ADDR_MDS(i))); mds[i]->init(); } // create client Client *client[NUMCLIENT]; for (int i=0; i<NUMCLIENT; i++) { client[i] = new Client(mdc, i, new FakeMessenger(MSG_ADDR_CLIENT(0))); client[i]->init(); // start up fuse // use my argc, argv (make sure you pass a mount point!) cout << "starting fuse on pid " << getpid() << endl; client[i]->mount(mkfs); ceph_fuse_main(client[i], argc, argv); client[i]->unmount(); cout << "fuse finished on pid " << getpid() << endl; client[i]->shutdown(); } // wait for it to finish cout << "DONE -----" << endl; fakemessenger_stopthread(); // blocks until messenger stops // cleanup for (int i=0; i<NUMMDS; i++) { delete mds[i]; } for (int i=0; i<NUMOSD; i++) { delete osd[i]; } for (int i=0; i<NUMCLIENT; i++) { delete client[i]; } delete mdc; return 0;}
kdebug(KDEBUG_FATAL,1401,"It seems that the khelpcenter server isn't running!");
kdFatal(1401) << "It seems that the khelpcenter server isn't running!" << endl;
int main(int argc, char *argv[]){ bool enableTree = false; int command = 0; QString url; // no parameters -> print usage if(argc == 1) { usage(); return 0; } // parse command line parameters for (int i = 1; i < argc; i++) { if (strcasecmp(argv[i], "configure") == 0) { command = 1; break; } else if (strcasecmp(argv[i], "-enable_tree") == 0) { enableTree = true; } else if (command == 2) // already found 'open'...this must be a url { url = argv[i]; } else if (strcasecmp( argv[i], "open" ) == 0) { command = 2; } } if (command == 0) { usage(); return 0; } KOMApplication app(argc, argv, "khelpcenterclient"); // init CORBA stuff CORBA::Object_var obj = app.orb()->bind("IDL:KHelpCenter/HelpCenterCom:1.0", "inet:localhost:8887"); if(CORBA::is_nil(obj)) { kdebug(KDEBUG_FATAL,1401,"It seems that the khelpcenter server isn't running!"); return 0; } KHelpCenter::HelpCenterCom_var server = KHelpCenter::HelpCenterCom::_narrow(obj); kdebug(KDEBUG_INFO,1401,"binding to KOM interface: IDL:KHelpCenter/HelpCenterCom:1.0"); if (command == 1) { kdebug(KDEBUG_INFO,1401,"khelpcenterclient -configure"); server->configure(); } else if (command == 2) { if (url.isEmpty()) url = "file:" + locate("html", "default/khelpcenter/main.html"); kdebug(KDEBUG_INFO,1401,"khelpcenterclient open %s", url.ascii()); server->openHelpView (url, enableTree); } return 0;}
kdebug(KDEBUG_INFO,1401,"binding to KOM interface: IDL:KHelpCenter/HelpCenterCom:1.0");
kdDebug(1401) << "binding to KOM interface: IDL:KHelpCenter/HelpCenterCom:1.0" << endl;
int main(int argc, char *argv[]){ bool enableTree = false; int command = 0; QString url; // no parameters -> print usage if(argc == 1) { usage(); return 0; } // parse command line parameters for (int i = 1; i < argc; i++) { if (strcasecmp(argv[i], "configure") == 0) { command = 1; break; } else if (strcasecmp(argv[i], "-enable_tree") == 0) { enableTree = true; } else if (command == 2) // already found 'open'...this must be a url { url = argv[i]; } else if (strcasecmp( argv[i], "open" ) == 0) { command = 2; } } if (command == 0) { usage(); return 0; } KOMApplication app(argc, argv, "khelpcenterclient"); // init CORBA stuff CORBA::Object_var obj = app.orb()->bind("IDL:KHelpCenter/HelpCenterCom:1.0", "inet:localhost:8887"); if(CORBA::is_nil(obj)) { kdebug(KDEBUG_FATAL,1401,"It seems that the khelpcenter server isn't running!"); return 0; } KHelpCenter::HelpCenterCom_var server = KHelpCenter::HelpCenterCom::_narrow(obj); kdebug(KDEBUG_INFO,1401,"binding to KOM interface: IDL:KHelpCenter/HelpCenterCom:1.0"); if (command == 1) { kdebug(KDEBUG_INFO,1401,"khelpcenterclient -configure"); server->configure(); } else if (command == 2) { if (url.isEmpty()) url = "file:" + locate("html", "default/khelpcenter/main.html"); kdebug(KDEBUG_INFO,1401,"khelpcenterclient open %s", url.ascii()); server->openHelpView (url, enableTree); } return 0;}
kdebug(KDEBUG_INFO,1401,"khelpcenterclient -configure");
kdDebug(1401) << "khelpcenterclient -configure" << endl;
int main(int argc, char *argv[]){ bool enableTree = false; int command = 0; QString url; // no parameters -> print usage if(argc == 1) { usage(); return 0; } // parse command line parameters for (int i = 1; i < argc; i++) { if (strcasecmp(argv[i], "configure") == 0) { command = 1; break; } else if (strcasecmp(argv[i], "-enable_tree") == 0) { enableTree = true; } else if (command == 2) // already found 'open'...this must be a url { url = argv[i]; } else if (strcasecmp( argv[i], "open" ) == 0) { command = 2; } } if (command == 0) { usage(); return 0; } KOMApplication app(argc, argv, "khelpcenterclient"); // init CORBA stuff CORBA::Object_var obj = app.orb()->bind("IDL:KHelpCenter/HelpCenterCom:1.0", "inet:localhost:8887"); if(CORBA::is_nil(obj)) { kdebug(KDEBUG_FATAL,1401,"It seems that the khelpcenter server isn't running!"); return 0; } KHelpCenter::HelpCenterCom_var server = KHelpCenter::HelpCenterCom::_narrow(obj); kdebug(KDEBUG_INFO,1401,"binding to KOM interface: IDL:KHelpCenter/HelpCenterCom:1.0"); if (command == 1) { kdebug(KDEBUG_INFO,1401,"khelpcenterclient -configure"); server->configure(); } else if (command == 2) { if (url.isEmpty()) url = "file:" + locate("html", "default/khelpcenter/main.html"); kdebug(KDEBUG_INFO,1401,"khelpcenterclient open %s", url.ascii()); server->openHelpView (url, enableTree); } return 0;}
kdebug(KDEBUG_INFO,1401,"khelpcenterclient open %s", url.ascii());
kdDebug(1401) << "khelpcenterclient open " << url << endl;
int main(int argc, char *argv[]){ bool enableTree = false; int command = 0; QString url; // no parameters -> print usage if(argc == 1) { usage(); return 0; } // parse command line parameters for (int i = 1; i < argc; i++) { if (strcasecmp(argv[i], "configure") == 0) { command = 1; break; } else if (strcasecmp(argv[i], "-enable_tree") == 0) { enableTree = true; } else if (command == 2) // already found 'open'...this must be a url { url = argv[i]; } else if (strcasecmp( argv[i], "open" ) == 0) { command = 2; } } if (command == 0) { usage(); return 0; } KOMApplication app(argc, argv, "khelpcenterclient"); // init CORBA stuff CORBA::Object_var obj = app.orb()->bind("IDL:KHelpCenter/HelpCenterCom:1.0", "inet:localhost:8887"); if(CORBA::is_nil(obj)) { kdebug(KDEBUG_FATAL,1401,"It seems that the khelpcenter server isn't running!"); return 0; } KHelpCenter::HelpCenterCom_var server = KHelpCenter::HelpCenterCom::_narrow(obj); kdebug(KDEBUG_INFO,1401,"binding to KOM interface: IDL:KHelpCenter/HelpCenterCom:1.0"); if (command == 1) { kdebug(KDEBUG_INFO,1401,"khelpcenterclient -configure"); server->configure(); } else if (command == 2) { if (url.isEmpty()) url = "file:" + locate("html", "default/khelpcenter/main.html"); kdebug(KDEBUG_INFO,1401,"khelpcenterclient open %s", url.ascii()); server->openHelpView (url, enableTree); } return 0;}
FileTypeDialog * dlg = new FileTypeDialog( mime ); dlg->setCaption( i18n("Edit File Type %1").arg(mime->name()) ); dlg->exec(); delete dlg;
dlg.setCaption( i18n("Edit File Type %1").arg(mime->name()) ); app.setMainWidget( &dlg ); dlg.show();
int main(int argc, char ** argv){ KServiceTypeProfile::setConfigurationMode(); KLocale::setMainCatalogue("filetypes"); KAboutData aboutData( "keditfiletype", I18N_NOOP("KEditFileType"), "1.0", I18N_NOOP("KDE file type editor - simplified version for editing a single file type"), KAboutData::License_GPL, I18N_NOOP("(c) 2000, KDE developers") ); aboutData.addAuthor("Preston Brown",0, "[email protected]"); aboutData.addAuthor("David Faure",0, "[email protected]"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->count() == 0) KCmdLineArgs::usage(); KMimeType::Ptr mime = KMimeType::mimeType( args->arg(0) ); if (!mime) kdFatal() << "Mimetype " << args->arg(0) << " not found" << endl; args->clear(); FileTypeDialog * dlg = new FileTypeDialog( mime ); dlg->setCaption( i18n("Edit File Type %1").arg(mime->name()) ); dlg->exec(); delete dlg; return 0;}
return 0;
return app.exec();
int main(int argc, char ** argv){ KServiceTypeProfile::setConfigurationMode(); KLocale::setMainCatalogue("filetypes"); KAboutData aboutData( "keditfiletype", I18N_NOOP("KEditFileType"), "1.0", I18N_NOOP("KDE file type editor - simplified version for editing a single file type"), KAboutData::License_GPL, I18N_NOOP("(c) 2000, KDE developers") ); aboutData.addAuthor("Preston Brown",0, "[email protected]"); aboutData.addAuthor("David Faure",0, "[email protected]"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->count() == 0) KCmdLineArgs::usage(); KMimeType::Ptr mime = KMimeType::mimeType( args->arg(0) ); if (!mime) kdFatal() << "Mimetype " << args->arg(0) << " not found" << endl; args->clear(); FileTypeDialog * dlg = new FileTypeDialog( mime ); dlg->setCaption( i18n("Edit File Type %1").arg(mime->name()) ); dlg->exec(); delete dlg; return 0;}
exit(0);
return 0;
int main(int argc, char *argv[]){ KAboutData aboutData( "khelpcenter", I18N_NOOP("KDE HelpCenter"), HELPCENTER_VERSION, I18N_NOOP("The KDE Help Center"), KAboutData::License_GPL, "(c) 1999-2000, Matthias Elter"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); KApplication::addCmdLineOptions(); KApplication app( false, false ); // no GUI in this process app.dcopClient()->attach(); Listener listener; QCString dcopService; QString error; // try to connect to an already running konqueror, if one exists QCStringList apps = app.dcopClient()->registeredApplications(); QCStringList::ConstIterator it; for (it = apps.begin(); it != apps.end(); ++it) if ((*it).left(9) == "konqueror") { createHelpWindow(*it); exit(0); } // run a new konqueror instance app.dcopClient()->setNotifications( true ); QObject::connect( app.dcopClient(), SIGNAL( applicationRegistered( const QCString& ) ), &listener, SLOT( slotAppRegistered( const QCString & ) ) ); if (app.startServiceByDesktopName("konqueror", QString::fromLatin1("--silent"), &error)) { warning("Could not launch browser:\n%s\n", error.local8Bit().data()); return 1; } app.exec();}
command += QCString(args->arg(i)) + " ";
proc << args->arg(i);
int main( int argc, char *argv[] ){ // David, 05/03/2000 KAboutData aboutData( "kstart", I18N_NOOP("KStart"), KSTART_VERSION, I18N_NOOP("" "Utility to launch applications with special window properties \n" "such as iconified, maximized, a certain virtual desktop, a special decoration\n" "and so on." ), KAboutData::License_GPL, "(C) 1997-2000 Matthias Ettrich ([email protected])" ); aboutData.addAuthor( "Matthias Ettrich", 0, "[email protected]" ); aboutData.addAuthor( "David Faure", 0, "[email protected]" ); aboutData.addAuthor( "Richard J. Moore", 0, "[email protected]" ); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if ( args->count() == 0 ) KCmdLineArgs::usage(i18n("No command specified")); // Perhaps we should use a konsole-like solution here (shell, list of args...) for(int i=0; i < args->count(); i++) command += QCString(args->arg(i)) + " "; kwinmodule = new KWinModule; desktop = args->getOption( "desktop" ).toInt(); if ( args->isSet ( "alldesktops") ) desktop = NETWinInfo::OnAllDesktops; if ( args->isSet ( "currentdesktop") ) desktop = kwinmodule->currentDesktop(); windowtitle = args->getOption( "window" ); windowclass = args->getOption( "windowclass" ); if( windowclass ) windowclass = windowclass.lower(); if( windowtitle.isEmpty() && windowclass.isEmpty()) kdWarning() << "Omitting both --window and --windowclass arguments is not recommended" << endl; QCString s = args->getOption( "type" ); if ( !s.isEmpty() ) { s = s.lower(); if ( s == "desktop" ) windowtype = NET::Desktop; else if ( s == "dock" ) windowtype = NET::Dock; else if ( s == "tool" ) windowtype = NET::Tool; else if ( s == "menu" ) windowtype = NET::Menu; else if ( s == "dialog" ) windowtype = NET::Dialog; else if ( s == "override" ) windowtype = NET::Override; else if ( s == "topmenu" ) windowtype = NET::TopMenu; else windowtype = NET::Normal; } if ( args->isSet( "keepabove" ) ) { state |= NET::KeepAbove; mask |= NET::KeepAbove; } else if ( args->isSet( "keepbelow" ) ) { state |= NET::KeepBelow; mask |= NET::KeepBelow; } if ( args->isSet( "skiptaskbar" ) ) { state |= NET::SkipTaskbar; mask |= NET::SkipTaskbar; } if ( args->isSet( "skippager" ) ) { state |= NET::SkipPager; mask |= NET::SkipPager; } activate = args->isSet("activate"); if ( args->isSet("maximize") ) { state |= NET::Max; mask |= NET::Max; } if ( args->isSet("maximize-vertically") ) { state |= NET::MaxVert; mask |= NET::MaxVert; } if ( args->isSet("maximize-horizontally") ) { state |= NET::MaxHoriz; mask |= NET::MaxHoriz; } iconify = args->isSet("iconify"); toSysTray = args->isSet("tosystray"); if ( args->isSet("fullscreen") ) { NETRootInfo i( qt_xdisplay(), NET::Supported ); if( i.isSupported( NET::FullScreen )) { state |= NET::FullScreen; mask |= NET::FullScreen; } else { windowtype = NET::Override; fullscreen = true; } } fcntl(ConnectionNumber(qt_xdisplay()), F_SETFD, 1); args->clear(); KStart start; return app.exec();}
KGlobal::locale()->insertCatalogue("kio_media");
int main(int argc, char **argv){ KCmdLineArgs::init(argc, argv, "kio_media_mounthelper", "kio_media_mounthelper", "kio_media_mounthelper", "0.1"); KCmdLineArgs::addCmdLineOptions( options ); KApplication::addCmdLineOptions(); if (KCmdLineArgs::parsedArgs()->count()==0) KCmdLineArgs::usage(); KApplication *app = new MountHelper(); KGlobal::locale()->insertCatalogue("kio_media"); app->dcopClient()->attach(); app->exec();}
QString myArgString; QFile myQFile; QStringList myFileStringList; bool myFileExistsFlag;
int main(int argc, char *argv[]){ QString myArgString; QFile myQFile; QStringList myFileStringList; bool myFileExistsFlag; QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (argc == 2) { QString translation = "qgis_" + QString(argv[1]); tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); qgis->show(); // // autoload any filenames that were passed in on the command line // for (int myIteratorInt = 1; myIteratorInt < argc; myIteratorInt++) {#ifdef QGISDEBUG printf("%d: %s\n", myIteratorInt, argv[myIteratorInt]);#endif myQFile.setName(argv[myIteratorInt]); myFileExistsFlag = myQFile.open(IO_ReadOnly); myQFile.close(); if (myFileExistsFlag) {#ifdef QGISDEBUG printf("OK\n");#endif myArgString = argv[myIteratorInt];#ifdef QGISDEBUG printf("Layer count: %d\n", myFileStringList.count());#endif myFileStringList.append(myArgString); } }#ifdef QGISDEBUG printf("rCount: %d\n", myFileStringList.count());#endif if (!myFileStringList.isEmpty()) {#ifdef QGISDEBUG printf("Loading vector files...\n");#endif //try to add all these layers - any unsupported file types will be refected automatically qgis->addRasterLayer(myFileStringList); qgis->addLayer(myFileStringList); } a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); // //turn control over to the main application loop... // int result = a.exec(); return result;}
for (int myIteratorInt = 1; myIteratorInt < argc; myIteratorInt++)
for (int i = 1; i < argc; i++)
int main(int argc, char *argv[]){ QString myArgString; QFile myQFile; QStringList myFileStringList; bool myFileExistsFlag; QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (argc == 2) { QString translation = "qgis_" + QString(argv[1]); tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); qgis->show(); // // autoload any filenames that were passed in on the command line // for (int myIteratorInt = 1; myIteratorInt < argc; myIteratorInt++) {#ifdef QGISDEBUG printf("%d: %s\n", myIteratorInt, argv[myIteratorInt]);#endif myQFile.setName(argv[myIteratorInt]); myFileExistsFlag = myQFile.open(IO_ReadOnly); myQFile.close(); if (myFileExistsFlag) {#ifdef QGISDEBUG printf("OK\n");#endif myArgString = argv[myIteratorInt];#ifdef QGISDEBUG printf("Layer count: %d\n", myFileStringList.count());#endif myFileStringList.append(myArgString); } }#ifdef QGISDEBUG printf("rCount: %d\n", myFileStringList.count());#endif if (!myFileStringList.isEmpty()) {#ifdef QGISDEBUG printf("Loading vector files...\n");#endif //try to add all these layers - any unsupported file types will be refected automatically qgis->addRasterLayer(myFileStringList); qgis->addLayer(myFileStringList); } a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); // //turn control over to the main application loop... // int result = a.exec(); return result;}
printf("%d: %s\n", myIteratorInt, argv[myIteratorInt]);
printf("%d: %s\n", i, argv[i]);
int main(int argc, char *argv[]){ QString myArgString; QFile myQFile; QStringList myFileStringList; bool myFileExistsFlag; QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (argc == 2) { QString translation = "qgis_" + QString(argv[1]); tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); qgis->show(); // // autoload any filenames that were passed in on the command line // for (int myIteratorInt = 1; myIteratorInt < argc; myIteratorInt++) {#ifdef QGISDEBUG printf("%d: %s\n", myIteratorInt, argv[myIteratorInt]);#endif myQFile.setName(argv[myIteratorInt]); myFileExistsFlag = myQFile.open(IO_ReadOnly); myQFile.close(); if (myFileExistsFlag) {#ifdef QGISDEBUG printf("OK\n");#endif myArgString = argv[myIteratorInt];#ifdef QGISDEBUG printf("Layer count: %d\n", myFileStringList.count());#endif myFileStringList.append(myArgString); } }#ifdef QGISDEBUG printf("rCount: %d\n", myFileStringList.count());#endif if (!myFileStringList.isEmpty()) {#ifdef QGISDEBUG printf("Loading vector files...\n");#endif //try to add all these layers - any unsupported file types will be refected automatically qgis->addRasterLayer(myFileStringList); qgis->addLayer(myFileStringList); } a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); // //turn control over to the main application loop... // int result = a.exec(); return result;}
myQFile.setName(argv[myIteratorInt]); myFileExistsFlag = myQFile.open(IO_ReadOnly); myQFile.close(); if (myFileExistsFlag) {
if ( qgis->addRasterLayer(argv[i]) ) { continue; } else if ( qgis->addLayer(argv[i]) ) { continue; } else {
int main(int argc, char *argv[]){ QString myArgString; QFile myQFile; QStringList myFileStringList; bool myFileExistsFlag; QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (argc == 2) { QString translation = "qgis_" + QString(argv[1]); tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); qgis->show(); // // autoload any filenames that were passed in on the command line // for (int myIteratorInt = 1; myIteratorInt < argc; myIteratorInt++) {#ifdef QGISDEBUG printf("%d: %s\n", myIteratorInt, argv[myIteratorInt]);#endif myQFile.setName(argv[myIteratorInt]); myFileExistsFlag = myQFile.open(IO_ReadOnly); myQFile.close(); if (myFileExistsFlag) {#ifdef QGISDEBUG printf("OK\n");#endif myArgString = argv[myIteratorInt];#ifdef QGISDEBUG printf("Layer count: %d\n", myFileStringList.count());#endif myFileStringList.append(myArgString); } }#ifdef QGISDEBUG printf("rCount: %d\n", myFileStringList.count());#endif if (!myFileStringList.isEmpty()) {#ifdef QGISDEBUG printf("Loading vector files...\n");#endif //try to add all these layers - any unsupported file types will be refected automatically qgis->addRasterLayer(myFileStringList); qgis->addLayer(myFileStringList); } a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); // //turn control over to the main application loop... // int result = a.exec(); return result;}
printf("OK\n");
std::cerr << argv[i] << " is not a recognized file\n";
int main(int argc, char *argv[]){ QString myArgString; QFile myQFile; QStringList myFileStringList; bool myFileExistsFlag; QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (argc == 2) { QString translation = "qgis_" + QString(argv[1]); tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); qgis->show(); // // autoload any filenames that were passed in on the command line // for (int myIteratorInt = 1; myIteratorInt < argc; myIteratorInt++) {#ifdef QGISDEBUG printf("%d: %s\n", myIteratorInt, argv[myIteratorInt]);#endif myQFile.setName(argv[myIteratorInt]); myFileExistsFlag = myQFile.open(IO_ReadOnly); myQFile.close(); if (myFileExistsFlag) {#ifdef QGISDEBUG printf("OK\n");#endif myArgString = argv[myIteratorInt];#ifdef QGISDEBUG printf("Layer count: %d\n", myFileStringList.count());#endif myFileStringList.append(myArgString); } }#ifdef QGISDEBUG printf("rCount: %d\n", myFileStringList.count());#endif if (!myFileStringList.isEmpty()) {#ifdef QGISDEBUG printf("Loading vector files...\n");#endif //try to add all these layers - any unsupported file types will be refected automatically qgis->addRasterLayer(myFileStringList); qgis->addLayer(myFileStringList); } a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); // //turn control over to the main application loop... // int result = a.exec(); return result;}
myArgString = argv[myIteratorInt]; #ifdef QGISDEBUG printf("Layer count: %d\n", myFileStringList.count()); #endif myFileStringList.append(myArgString); } } #ifdef QGISDEBUG printf("rCount: %d\n", myFileStringList.count()); #endif if (!myFileStringList.isEmpty()) { #ifdef QGISDEBUG printf("Loading vector files...\n"); #endif qgis->addRasterLayer(myFileStringList); qgis->addLayer(myFileStringList);
}
int main(int argc, char *argv[]){ QString myArgString; QFile myQFile; QStringList myFileStringList; bool myFileExistsFlag; QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (argc == 2) { QString translation = "qgis_" + QString(argv[1]); tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); qgis->show(); // // autoload any filenames that were passed in on the command line // for (int myIteratorInt = 1; myIteratorInt < argc; myIteratorInt++) {#ifdef QGISDEBUG printf("%d: %s\n", myIteratorInt, argv[myIteratorInt]);#endif myQFile.setName(argv[myIteratorInt]); myFileExistsFlag = myQFile.open(IO_ReadOnly); myQFile.close(); if (myFileExistsFlag) {#ifdef QGISDEBUG printf("OK\n");#endif myArgString = argv[myIteratorInt];#ifdef QGISDEBUG printf("Layer count: %d\n", myFileStringList.count());#endif myFileStringList.append(myArgString); } }#ifdef QGISDEBUG printf("rCount: %d\n", myFileStringList.count());#endif if (!myFileStringList.isEmpty()) {#ifdef QGISDEBUG printf("Loading vector files...\n");#endif //try to add all these layers - any unsupported file types will be refected automatically qgis->addRasterLayer(myFileStringList); qgis->addLayer(myFileStringList); } a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); // //turn control over to the main application loop... // int result = a.exec(); return result;}
client[i]->issue_request();
client[i]->mount();
int main(int argc, char **argv) { cerr << "hi there" << endl; if (argc > 1) { int d = atoi(argv[1]); if (d > 0) g_conf.debug = d; cerr << " debug level " << d << endl; } MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD); // local config settings g_conf.num_client = g_conf.num_fakeclient; // to fool mds, hack gross // create mds MDS *mds[NUMMDS]; for (int i=0; i<NUMMDS; i++) { mds[i] = new MDS(mdc, i, new FakeMessenger(MSG_ADDR_MDS(i))); mds[i]->init(); } // create osds OSD *osd[NUMOSD]; for (int i=0; i<NUMOSD; i++) { osd[i] = new OSD(i, new FakeMessenger(MSG_ADDR_OSD(i))); osd[i]->init(); } // create clients FakeClient *client[NUMCLIENT]; for (int i=0; i<NUMCLIENT; i++) { client[i] = new FakeClient(mdc, i, new FakeMessenger(MSG_ADDR_CLIENT(i)), g_conf.fakeclient_requests); client[i]->init(); } // seed initial requests for (int i=0; i<NUMCLIENT; i++) //for (int i=0; i<1; i++) client[i]->issue_request(); // loop fakemessenger_do_loop(); //mds[0]->shutdown_start(); //fakemessenger_do_loop(); // if (argc > 1 && strcmp(argv[1], "nocheck") == 0) { cerr << "---- nocheck" << endl; } else { cout << "---- check ----" << endl; for (int i=0; i<NUMMDS; i++) mds[i]->mdcache->shutdown_pass(); } // cleanup cout << "cleanup" << endl; for (int i=0; i<NUMMDS; i++) { if (mds[i]->shutdown_final() == 0) { //cout << "clean shutdown of mds " << i << endl; delete mds[i]; } else { cout << "problems shutting down mds " << i << endl; } } for (int i=0; i<NUMOSD; i++) { if (osd[i]->shutdown() == 0) { //cout << "clean shutdown of osd " << i << endl; delete osd[i]; } else { cout << "problems shutting down osd " << i << endl; } } for (int i=0; i<NUMCLIENT; i++) { if (client[i]->shutdown() == 0) { //cout << "clean shutdown of client " << i << endl; delete client[i]; } else { cout << "problems shutting down client " << i << endl; } } delete mdc; cout << "done." << endl; return 0;}
KLocale::setMainCatalogue(0);
int main(int _argc, char *_argv[]){ KCmdLineArgs::init( _argc, _argv, "kcmshell", I18N_NOOP("A tool to start single kcontrol modules"), "2.0pre" ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->isSet("list")) { QStringList files; KGlobal::dirs()->findAllResources("apps", "Settings/*.desktop", true, true, files); QStringList modules; QStringList descriptions; uint maxwidth = 0; for (QStringList::ConstIterator it = files.begin(); it != files.end(); it++) { if (KDesktopFile::isDesktopFile(*it)) { KDesktopFile file(*it, true); QString module = *it; if (module.left(9) == "Settings/") module = module.mid(9); if (module.right(8) == ".desktop") module.truncate(module.length() - 8); modules.append(module); if (module.length() > maxwidth) maxwidth = module.length(); descriptions.append(QString("%2 (%3)").arg(file.readName()).arg(file.readComment())); } } QByteArray vl; vl.fill(' ', 80); QString verylong = vl; for (uint i = 0; i < modules.count(); i++) { cout << (*modules.at(i)).latin1(); cout << verylong.left(maxwidth - (*modules.at(i)).length()); cout << " - "; cout << (*descriptions.at(i)).local8Bit(); cout << endl; } return 0; } if (args->count() != 1) { args->usage(); return -1; } // locate the desktop file QStringList files; if (args->arg(0)[0] == '/') files.append(args->arg(0)); else files = KGlobal::dirs()-> findAllResources("apps", QString("Settings/%1.desktop").arg(args->arg(0)), true); // check the matches if (files.count() > 1) cerr << i18n("Module name not unique. Taking the first match.") << endl; if (files.count() <= 0) { cerr << i18n("Module not found!") << endl; return -1; } args->clear(); // load the module ModuleInfo info(files[0]); KCModule *module = ModuleLoader::module(info, 0); if (module) { // create the dialog KCDialog dlg(module, info.docPath(), 0, 0, true); dlg.setCaption(info.name()); // run the dialog return dlg.exec(); } return 0;}
QString tmp = conf->readEntry("AutostartOnKDEStartup", "0"); if (tmp == "0" && (strcmp(argv[1], "--kdestartup") == 0))
QString tmp = conf->readEntry("AutostartOnKDEStartup", "true"); for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } QString arg = argv[i]; } if ((arg == "--kdestartup") && (tmp != "true"))
int main(int argc, char *argv[]){ KApplication app(argc, argv, "kwelcome"); // check for --kdestartup KConfig *conf = kapp->getConfig(); conf->setGroup("General Settings"); QString tmp = conf->readEntry("AutostartOnKDEStartup", "0"); if (tmp == "0" && (strcmp(argv[1], "--kdestartup") == 0)) return 0; KWelcome *widget = new KWelcome(); app.setMainWidget(widget); app.setTopWidget(widget); widget->show(); return app.exec();}
int c;
qInstallMsgHandler(msgHandler);
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
cout << Usage << TryHelp << endl;
printf(Usage); printf(TryHelp);
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); }
if (pw == 0L) qFatal("User %s does not exist", s.latin1());
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl;
printf("kdesu version %s\n", Version); printf("\n"); printf(" Copyright (C) 1998 Pietro Iglio <[email protected]>\n"); printf(" Copyright (C) 1999 Geert Jansen %s", Email); printf("\n");
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl;
printf(Usage); printf("Runs a command as another user.\n"); printf("\n"); printf("Options:\n"); printf(" -c COMMAND Run command COMMAND. The entire command\n"); printf(" line has to be passed as a single argument.\n"); printf(" -f FILE Run command as root if file specified by FILE\n"); printf(" is not writeable under current uid.\n"); printf(" -n Do not keep password\n"); printf(" -s Stop the daemon (forgets all passwords)\n"); printf(" -t Enable terminal output (no password keeping).\n"); printf(" -q Be quiet (shows no warnings)\n"); printf(" -d Show debug information\n"); printf(" -v Show version information\n"); printf("\n"); printf("Please report bugs to %s\n", Email);
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); }
if (client.ping() == -1) qFatal("Daemon not running -- nothing to stop");
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
cout << "Daemon stopped\n";
printf("Daemon stopped\n");
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
error("Could not stop daemon"); exit(1);
qFatal("Could not stop daemon");
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); }
if (!fi.exists()) qFatal("File does not exist: %s", file.latin1());
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); }
if (setrlimit(RLIMIT_CORE, &rlim)) qFatal("rlimit(): %s", strerror(errno));
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
error("Cannot connect to daemon -- not keeping password");
qWarning("Cannot connect to daemon -- not keeping password");
int main(int argc, char *argv[]){ int c; QString command, file; bool keep = true; bool terminal = false; KStartParams parm(argc, argv); QString s; // Parse user name argument uid_t uid; QString user; int i=0; s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } if (s.at(0) != '-') { struct passwd *pw = getpwnam(s.latin1()); if (pw == 0L) { error("User %s does not exist", s.latin1()); exit(1); } user = s; uid = pw->pw_uid; s = parm.get(i++); } else { user = "root"; uid = 0; } // Parse options while (s != "-c") { if (s.at(0) != '-') { cout << Usage << TryHelp << endl; exit(1); } bool next = false; for (int j=1; j<s.length(); j++) { switch (s.at(j).latin1()) { case 'f': file = parm.get(i++); if (file.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } next = true; break; case 't': terminal = true; break; case 'n': keep = false; break; case 'q': _show_dbg = 0; _show_wrn = 0; break; case 'd': _show_dbg++; break; // Exiting comand from here case 'v': cerr << "kdesu version " << Version << endl; cerr << endl; cerr << " Copyright (C) 1998 Pietro Iglio <[email protected]>\n"; cerr << " Copyright (C) 1999 Geert Jansen " << Email << endl; cerr << endl; exit(0); case 'h': cerr << Usage; cerr << "Runs a command as another user.\n"; cerr << endl; cerr << "Options:\n"; cerr << " -c COMMAND Run command COMMAND. The entire command\n"; cerr << " line has to be passed as a single argument.\n"; cerr << " -f FILE Run command as root if file specified by FILE\n"; cerr << " is not writeable under current uid.\n"; cerr << " -n Do not keep password\n"; cerr << " -s Stop the daemon (forgets all passwords)\n"; cerr << " -t Enable terminal output (no password keeping).\n"; cerr << " -q Be quiet (shows no warnings)\n"; cerr << " -d Show debug information\n"; cerr << " -v Show version information\n"; cerr << endl; cerr << "Please report bugs to " << Email << endl; exit(0); case 's': { KDEsuClient client; if (client.ping() == -1) { error("Daemon not running -- nothing to stop"); exit(1); } if (client.stopServer() != -1) { cout << "Daemon stopped\n"; return 0; } error("Could not stop daemon"); exit(1); } } if (next) break; } s = parm.get(i++); if (s.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } } // Parse command command = parm.get(i++); if (command.isEmpty()) { cout << Usage << TryHelp << endl; exit(1); } while (!(s = parm.get(i++)).isEmpty()) { command += " "; command += s; } // Don't use su if we're don't need to. bool change_uid = (getuid() != uid); // If file is not writeable, change uid if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); } QFileInfo fi(file); if (!fi.exists()) { error("File does not exist: %s", file.latin1()); exit(1); } change_uid = !fi.isWritable(); } if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Try to exec the command with kdesud. if (keep && !terminal) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); if (client.exec(command) != -1) return 0; } else // The user has to enter a password and this very probably // gives enough time to start up the daemon. keep = (client.startServer() != -1); } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { xerror("rlimit(): %s"); exit(1); } // From here, we need the GUI: create a KApplication KApplication *app = new KApplication(argc, argv, "kdesu"); // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Common"); QString val = config->readEntry("EchoMode", "x"); int echo_mode; if (val == "OneStar") echo_mode = OneStar; else if (val == "ThreeStars") echo_mode = ThreeStars; else if (val == "NoStars") echo_mode = NoStars; else echo_mode = defEchomode; bool keep_cfg = config->readBoolEntry("KeepPassword", defKeep); int pw_timeout = config->readNumEntry("KeepPasswordTimeout", defTimeout); // Start the dialog QString txt; if (user == "root") txt = i18n("The action you requested needs root priviliges.\n" "Please enter root's password below or click\n" "Ignore to continue with your current priviliges."); else txt = i18n("The action you requested needs additional priviliges.\n" "Please enter the password for \"%1\" below or click\n" "Ignore to continue with your current privileges.").arg(user); KPasswordDlg *pwDlg = new KPasswordDlg(txt, command, user, ((keep&&!terminal) ? 1+keep_cfg : 0)); pwDlg->setEchoMode(echo_mode); pwDlg->exec(); char *pass = new char[KPasswordEdit::PassLen]; switch (pwDlg->result()) { case KPasswordDlg::Accepted: strcpy(pass, pwDlg->getPass()); change_uid = true; break; case KPasswordDlg::Rejected: return 0; case KPasswordDlg::AsUser: change_uid = false; break; } keep = pwDlg->keepPass(); delete pwDlg; // This destroys the Qt event loop and makes sure the dialog goes away. delete app; if (!change_uid) { UserProcess proc(command); return proc.exec(); } // Change uid if (keep) { KDEsuClient client; if (client.ping() != -1) { client.setUser(user); client.setPass(pass, pw_timeout); return client.exec(command); } else error("Cannot connect to daemon -- not keeping password"); } SuProcess proc; proc.setCommand(command); proc.setUser(user); proc.setTerminal(terminal); proc.setErase(true); return proc.exec(pass);}
if ( args->isSet( "dialog" ) ) { showPropertiesDialog( args ); return true; }
int main( int argc, char **argv ){ KAboutData about( "kfile", I18N_NOOP( "kfile" ), KFILEVERSION, I18N_NOOP("A commandline tool to read and modify metadata of files." ), KAboutData::License_LGPL, "(c) 2002, Carsten Pfeiffer", 0 /*text*/, "http://devel-home.kde.org/~pfeiffer/", "[email protected]" ); about.addAuthor( "Carsten Pfeiffer", 0, "[email protected]", "http://devel-home.kde.org/~pfeiffer/" ); KCmdLineArgs::init( argc, argv, &about ); KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); bool useGUI = args->isSet( "dialog" ); KApplication app( useGUI, useGUI ); QPtrList<FileProps> m_props; m_props.setAutoDelete( true ); bool quiet = args->isSet( "quiet" ); if ( args->isSet( "supportedMimetypes" ) ) printSupportedMimeTypes(); int files = args->count(); if ( files == 0 ) KCmdLineArgs::usage( i18n("No files specified") ); // exit()s QString mimeType; for ( int i = 0; i < files; i++ ) { if ( args->isSet( "dialog" ) ) { showPropertiesDialog( args ); return true; } if ( args->isSet( "mimetype" ) ) printMimeTypes( args ); FileProps *props = new FileProps( args->arg(i), args->url(i).path() ); if ( props->isValid() ) m_props.append( props ); else if ( !quiet ) cerr << args->arg(i) << ": " << i18n("Cannot determine metadata").local8Bit() << endl; } processMetaDataOptions( m_props, args ); return 0;}
FileProps *props = new FileProps( args->arg(i), args->url(i).path() );
FileProps *props = new FileProps( args->url(i).path(), groupsToUse );
int main( int argc, char **argv ){ KAboutData about( "kfile", I18N_NOOP( "kfile" ), KFILEVERSION, I18N_NOOP("A commandline tool to read and modify metadata of files." ), KAboutData::License_LGPL, "(c) 2002, Carsten Pfeiffer", 0 /*text*/, "http://devel-home.kde.org/~pfeiffer/", "[email protected]" ); about.addAuthor( "Carsten Pfeiffer", 0, "[email protected]", "http://devel-home.kde.org/~pfeiffer/" ); KCmdLineArgs::init( argc, argv, &about ); KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); bool useGUI = args->isSet( "dialog" ); KApplication app( useGUI, useGUI ); QPtrList<FileProps> m_props; m_props.setAutoDelete( true ); bool quiet = args->isSet( "quiet" ); if ( args->isSet( "supportedMimetypes" ) ) printSupportedMimeTypes(); int files = args->count(); if ( files == 0 ) KCmdLineArgs::usage( i18n("No files specified") ); // exit()s QString mimeType; for ( int i = 0; i < files; i++ ) { if ( args->isSet( "dialog" ) ) { showPropertiesDialog( args ); return true; } if ( args->isSet( "mimetype" ) ) printMimeTypes( args ); FileProps *props = new FileProps( args->arg(i), args->url(i).path() ); if ( props->isValid() ) m_props.append( props ); else if ( !quiet ) cerr << args->arg(i) << ": " << i18n("Cannot determine metadata").local8Bit() << endl; } processMetaDataOptions( m_props, args ); return 0;}
else if ( !quiet ) cerr << args->arg(i) << ": " <<
else { if ( !quiet ) { cerr << args->arg(i) << ": " <<
int main( int argc, char **argv ){ KAboutData about( "kfile", I18N_NOOP( "kfile" ), KFILEVERSION, I18N_NOOP("A commandline tool to read and modify metadata of files." ), KAboutData::License_LGPL, "(c) 2002, Carsten Pfeiffer", 0 /*text*/, "http://devel-home.kde.org/~pfeiffer/", "[email protected]" ); about.addAuthor( "Carsten Pfeiffer", 0, "[email protected]", "http://devel-home.kde.org/~pfeiffer/" ); KCmdLineArgs::init( argc, argv, &about ); KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); bool useGUI = args->isSet( "dialog" ); KApplication app( useGUI, useGUI ); QPtrList<FileProps> m_props; m_props.setAutoDelete( true ); bool quiet = args->isSet( "quiet" ); if ( args->isSet( "supportedMimetypes" ) ) printSupportedMimeTypes(); int files = args->count(); if ( files == 0 ) KCmdLineArgs::usage( i18n("No files specified") ); // exit()s QString mimeType; for ( int i = 0; i < files; i++ ) { if ( args->isSet( "dialog" ) ) { showPropertiesDialog( args ); return true; } if ( args->isSet( "mimetype" ) ) printMimeTypes( args ); FileProps *props = new FileProps( args->arg(i), args->url(i).path() ); if ( props->isValid() ) m_props.append( props ); else if ( !quiet ) cerr << args->arg(i) << ": " << i18n("Cannot determine metadata").local8Bit() << endl; } processMetaDataOptions( m_props, args ); return 0;}
cout.flush();
int main( int argc, char **argv ){ KAboutData about( "kfile", I18N_NOOP( "kfile" ), KFILEVERSION, I18N_NOOP("A commandline tool to read and modify metadata of files." ), KAboutData::License_LGPL, "(c) 2002, Carsten Pfeiffer", 0 /*text*/, "http://devel-home.kde.org/~pfeiffer/", "[email protected]" ); about.addAuthor( "Carsten Pfeiffer", 0, "[email protected]", "http://devel-home.kde.org/~pfeiffer/" ); KCmdLineArgs::init( argc, argv, &about ); KCmdLineArgs::addCmdLineOptions( options ); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); bool useGUI = args->isSet( "dialog" ); KApplication app( useGUI, useGUI ); QPtrList<FileProps> m_props; m_props.setAutoDelete( true ); bool quiet = args->isSet( "quiet" ); if ( args->isSet( "supportedMimetypes" ) ) printSupportedMimeTypes(); int files = args->count(); if ( files == 0 ) KCmdLineArgs::usage( i18n("No files specified") ); // exit()s QString mimeType; for ( int i = 0; i < files; i++ ) { if ( args->isSet( "dialog" ) ) { showPropertiesDialog( args ); return true; } if ( args->isSet( "mimetype" ) ) printMimeTypes( args ); FileProps *props = new FileProps( args->arg(i), args->url(i).path() ); if ( props->isValid() ) m_props.append( props ); else if ( !quiet ) cerr << args->arg(i) << ": " << i18n("Cannot determine metadata").local8Bit() << endl; } processMetaDataOptions( m_props, args ); return 0;}
KCDialog dlg(module, QString::null, 0, 0, true);
KCDialog dlg(module, info.docPath(), 0, 0, true);
int main(int _argc, char *_argv[]){ KCmdLineArgs::init( _argc, _argv, "kcmshell", I18N_NOOP("A tool to start single kcontrol modules"), "2.0pre" ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KLocale::setMainCatalogue("kcontrol"); KApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->isSet("list")) { QStringList files; KGlobal::dirs()->findAllResources("apps", "Settings/*.desktop", true, true, files); QStringList modules; QStringList descriptions; uint maxwidth = 0; for (QStringList::ConstIterator it = files.begin(); it != files.end(); it++) { if (KDesktopFile::isDesktopFile(*it)) { KDesktopFile file(*it, true); QString module = *it; if (module.left(9) == "Settings/") module = module.mid(9); if (module.right(8) == ".desktop") module.truncate(module.length() - 8); modules.append(module); if (module.length() > maxwidth) maxwidth = module.length(); descriptions.append(QString("%2 (%3)").arg(file.readName()).arg(file.readComment())); } } QByteArray vl; vl.fill(' ', 80); QString verylong = vl; for (uint i = 0; i < modules.count(); i++) { cout << (*modules.at(i)).latin1(); cout << verylong.left(maxwidth - (*modules.at(i)).length()); cout << " - "; cout << (*descriptions.at(i)).local8Bit(); cout << endl; } return 0; } if (args->count() != 1) { args->usage(); return -1; } // locate the desktop file QStringList files; if (args->arg(0)[0] == '/') files.append(args->arg(0)); else files = KGlobal::dirs()-> findAllResources("apps", QString("Settings/%1.desktop").arg(args->arg(0)), true); // check the matches if (files.count() > 1) cerr << i18n("Module name not unique. Taking the first match.") << endl; if (files.count() <= 0) { cerr << i18n("Module not found!") << endl; return -1; } args->clear(); // load the module ModuleInfo info(files[0]); KCModule *module = ModuleLoader::module(info, 0); if (module) { // create the dialog KCDialog dlg(module, QString::null, 0, 0, true); dlg.setCaption(info.name()); // run the dialog return dlg.exec(); } return 0;}
uiserver = new UIServer;
uiserver = new UIServer();
int main(int argc, char **argv){ KLocale::setMainCatalogue("kdelibs"); // GS 5/2001 - I changed the name to "KDE" to make it look better // in the titles of dialogs which are displayed. KAboutData aboutdata("kio_uiserver", I18N_NOOP("KDE"), "0.8", I18N_NOOP("KDE Progress Information UI Server"), KAboutData::License_GPL, "(C) 2000, David Faure & Matt Koss"); // Who's the maintainer ? :) aboutdata.addAuthor("David Faure",I18N_NOOP("Developer"),"[email protected]"); aboutdata.addAuthor("Matej Koss",I18N_NOOP("Developer"),"[email protected]"); KCmdLineArgs::init( argc, argv, &aboutdata ); // KCmdLineArgs::addCmdLineOptions( options ); KUniqueApplication::addCmdLineOptions(); if (!KUniqueApplication::start()) { kdDebug(7024) << "kio_uiserver is already running!" << endl; return (0); } KUniqueApplication app; // This app is started automatically, no need for session management app.disableSessionManagement(); app.dcopClient()->setDaemonMode( true ); uiserver = new UIServer; app.setMainWidget( uiserver ); return app.exec();}
{"includedir", no_argument, 0, 'i'}, {"libdir", no_argument, 0, 'l'},
{"cflags", no_argument, 0, 'c'}, {"libs", no_argument, 0, 'l'}, {"plugindir", no_argument, 0, 'w'},
int main(int argc, char **argv){ int optionChar; // options structure static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"prefix", no_argument, 0, 'p'}, {"bindir", no_argument, 0, 'b'}, {"includedir", no_argument, 0, 'i'}, {"libdir", no_argument, 0, 'l'}, {0, 0, 0, 0} }; // If no argument is given, show hint if(argc == 1) { std::cout << "qgis_config: argument required" << std::endl; std::cout << "Try \"qgis_config --help\" for more information." << std::endl; }else { // One or more arguments supplied while (1) { /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "pbil", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 'p': std::cout << PREFIX << std::endl; break; case 'b': std::cout << BIN_DIR << std::endl; break; case 'i': std::cout << INCLUDE_DIR << std::endl; break; case 'l': std::cout << LIB_DIR << std::endl; break; case 'h': usage(); return 1; break; default: std::cout << "Try \"qgis_config --help\" for more information." << std::endl; return 1; } } } // return success return 0;}
optionChar = getopt_long (argc, argv, "pbil",
optionChar = getopt_long (argc, argv, "pbclw",
int main(int argc, char **argv){ int optionChar; // options structure static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"prefix", no_argument, 0, 'p'}, {"bindir", no_argument, 0, 'b'}, {"includedir", no_argument, 0, 'i'}, {"libdir", no_argument, 0, 'l'}, {0, 0, 0, 0} }; // If no argument is given, show hint if(argc == 1) { std::cout << "qgis_config: argument required" << std::endl; std::cout << "Try \"qgis_config --help\" for more information." << std::endl; }else { // One or more arguments supplied while (1) { /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "pbil", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 'p': std::cout << PREFIX << std::endl; break; case 'b': std::cout << BIN_DIR << std::endl; break; case 'i': std::cout << INCLUDE_DIR << std::endl; break; case 'l': std::cout << LIB_DIR << std::endl; break; case 'h': usage(); return 1; break; default: std::cout << "Try \"qgis_config --help\" for more information." << std::endl; return 1; } } } // return success return 0;}
case 'i': std::cout << INCLUDE_DIR << std::endl;
case 'c': std::cout << "-I" << INCLUDE_DIR << " "; std::cout << "-I" << INCLUDE_DIR << "/qgis" << std::endl;
int main(int argc, char **argv){ int optionChar; // options structure static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"prefix", no_argument, 0, 'p'}, {"bindir", no_argument, 0, 'b'}, {"includedir", no_argument, 0, 'i'}, {"libdir", no_argument, 0, 'l'}, {0, 0, 0, 0} }; // If no argument is given, show hint if(argc == 1) { std::cout << "qgis_config: argument required" << std::endl; std::cout << "Try \"qgis_config --help\" for more information." << std::endl; }else { // One or more arguments supplied while (1) { /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "pbil", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 'p': std::cout << PREFIX << std::endl; break; case 'b': std::cout << BIN_DIR << std::endl; break; case 'i': std::cout << INCLUDE_DIR << std::endl; break; case 'l': std::cout << LIB_DIR << std::endl; break; case 'h': usage(); return 1; break; default: std::cout << "Try \"qgis_config --help\" for more information." << std::endl; return 1; } } } // return success return 0;}
std::cout << LIB_DIR << std::endl;
std::cout << "-L" << LIB_DIR << " "; std::cout << " -lqgis" << std::endl; break; case 'w': std::cout << PLUGIN_DIR << std::endl;
int main(int argc, char **argv){ int optionChar; // options structure static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"prefix", no_argument, 0, 'p'}, {"bindir", no_argument, 0, 'b'}, {"includedir", no_argument, 0, 'i'}, {"libdir", no_argument, 0, 'l'}, {0, 0, 0, 0} }; // If no argument is given, show hint if(argc == 1) { std::cout << "qgis_config: argument required" << std::endl; std::cout << "Try \"qgis_config --help\" for more information." << std::endl; }else { // One or more arguments supplied while (1) { /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "pbil", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 'p': std::cout << PREFIX << std::endl; break; case 'b': std::cout << BIN_DIR << std::endl; break; case 'i': std::cout << INCLUDE_DIR << std::endl; break; case 'l': std::cout << LIB_DIR << std::endl; break; case 'h': usage(); return 1; break; default: std::cout << "Try \"qgis_config --help\" for more information." << std::endl; return 1; } } } // return success return 0;}
KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
int main(int argc, char *argv[]){ // FIXME: this can be considered a poor man's solution, as it's not // directly obvious to a gui user. :) // anyway, i vote against removing it even when we have a proper gui // implementation. -- ossi const char *duser = ::getenv("ADMIN_ACCOUNT"); if (duser && duser[0]) options[3].def = duser; KAboutData aboutData("kdesu", I18N_NOOP("KDE su"), Version, I18N_NOOP("Runs a program with elevated privileges."), KAboutData::License_Artistic, "Copyright (c) 1998-2000 Geert Jansen, Pietro Iglio"); aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"), "[email protected]", "http://www.stack.nl/~geertj/"); aboutData.addAuthor("Pietro Iglio", I18N_NOOP("Original author"), "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KApplication::disableAutoDcopRegistration(); KApplication *app = new KApplication; { KStartupInfoId id; id.initId( app->startupId()); id.setupStartupEnv(); // make KDE_STARTUP_ENV env. var. available again } // Stop daemon and exit? if (args->isSet("s")) { KDEsuClient client; if (client.ping() == -1) { kdError(1206) << "Daemon not running -- nothing to stop\n"; exit(1); } if (client.stopServer() != -1) { kdDebug(1206) << "Daemon stopped\n"; exit(0); } kdError(1206) << "Could not stop daemon\n"; exit(1); } // Get target uid QCString user = args->getOption("u"); QCString auth_user = user; struct passwd *pw = getpwnam(user); if (pw == 0L) { kdError(1206) << "User " << user << " does not exist\n"; exit(1); } bool change_uid = (getuid() != pw->pw_uid); // If file is writeable, do not change uid QString file = QFile::decodeName(args->getOption("f")); if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); if (file.isEmpty()) { kdError(1206) << "Config file not found: " << file << "\n"; exit(1); } } QFileInfo fi(file); if (!fi.exists()) { kdError(1206) << "File does not exist: " << file << "\n"; exit(1); } change_uid = !fi.isWritable(); } // Get priority/scheduler QCString tmp = args->getOption("p"); bool ok; int priority = tmp.toInt(&ok); if (!ok || (priority < 0) || (priority > 100)) { KCmdLineArgs::usage(i18n("Illegal priority: %1").arg(tmp)); exit(1); } int scheduler = SuProcess::SchedNormal; if (args->isSet("r")) scheduler = SuProcess::SchedRealtime; if ((priority > 50) || (scheduler != SuProcess::SchedNormal)) { change_uid = true; auth_user = "root"; } // Get command if (args->isSet("c")) { command = args->getOption("c"); for (int i=0; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); } } else { if( args->count() == 0 ) { KCmdLineArgs::usage(i18n("No command specified!")); exit(1); } command = args->arg(0); for (int i=1; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); }}// CJM - Test lines remove when working// kdWarning(1206) << args->count();// kdWarning(1206) << command; // Don't change uid if we're don't need to. if (!change_uid) return system(command); // Check for daemon and start if necessary bool just_started = false; bool have_daemon = true; KDEsuClient client; if (!client.isServerSGID()) { kdWarning(1206) << "Daemon not safe (not sgid), not using it.\n"; have_daemon = false; } else if (client.ping() == -1) { if (client.startServer() == -1) { kdWarning(1206) << "Could not start daemon, reduced functionality.\n"; have_daemon = false; } just_started = true; } // Try to exec the command with kdesud. bool keep = !args->isSet("n") && have_daemon; bool terminal = args->isSet("t"); bool new_dcop = args->isSet("newdcop"); QCStringList env; QCString options; env << ( "KDE_STARTUP_ENV=" + kapp->startupId()); if (pw->pw_uid) { // Only propagate KDEHOME for non-root users, // root uses KDEROOTHOME // Translate the KDEHOME of this user to the new user. QString kdeHome = KGlobal::dirs()->relativeLocation("home", KGlobal::dirs()->localkdedir()); if (kdeHome[0] != '/') kdeHome.prepend("~/"); else kdeHome=QString::null; // Use default env << ("KDEHOME="+ QFile::encodeName(kdeHome)); } if (!new_dcop) { QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("tmp", "ksycoca")); env << ksycoca; options += "xf"; // X-only, dcop forwarding enabled. } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); if (client.exec(command, user, options, env) != -1) return 0; } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { kdError(1206) << "rlimit(): " << ERR << "\n"; exit(1); } // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Passwords"); int timeout = config->readNumEntry("Timeout", defTimeout); // Check if we need a password SuProcess proc; proc.setUser(auth_user); int needpw = proc.checkNeedPassword(); if (needpw < 0) { QString err = i18n("Su returned with an error!\n"); KMessageBox::error(0L, err); exit(1); } if (needpw == 0) { keep = 0; kdDebug() << "Don't need password!!\n"; } // Start the dialog QCString password; if (needpw) { KStartupInfoId id; id.initId( app->startupId()); KStartupInfoData data; data.setSilent( KStartupInfoData::Yes ); KStartupInfo::sendChange( id, data ); KDEsuDialog dlg(user, auth_user, keep && !terminal); dlg.addLine(i18n("Command:"), command); if ((priority != 50) || (scheduler != SuProcess::SchedNormal)) { QString prio; if (scheduler == SuProcess::SchedRealtime) prio += i18n("realtime: "); prio += QString("%1/100").arg(priority); dlg.addLine(i18n("Priority:"), prio); } int ret = dlg.exec(); if (ret == KDEsuDialog::Rejected) { KStartupInfo::sendFinish( id ); exit(0); } if (ret == KDEsuDialog::AsUser) change_uid = false; password = dlg.password(); keep = dlg.keep(); data.setSilent( KStartupInfoData::No ); KStartupInfo::sendChange( id, data ); } // Some events may need to be handled (like a button animation) app->processEvents(); if (!change_uid) return system(command); // Run command if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); return client.exec(command, user, options, env); } else { SuProcess proc; proc.setTerminal(terminal); proc.setErase(true); proc.setUser(user); if (!new_dcop) { proc.setXOnly(true); proc.setDCOPForwarding(true); } proc.setEnvironment(env); proc.setPriority(priority); proc.setScheduler(scheduler); proc.setCommand(command); return proc.exec(password); }}
if (args->isSet("s"))
int result = startApp(); if (result == 127)
int main(int argc, char *argv[]){ // FIXME: this can be considered a poor man's solution, as it's not // directly obvious to a gui user. :) // anyway, i vote against removing it even when we have a proper gui // implementation. -- ossi const char *duser = ::getenv("ADMIN_ACCOUNT"); if (duser && duser[0]) options[3].def = duser; KAboutData aboutData("kdesu", I18N_NOOP("KDE su"), Version, I18N_NOOP("Runs a program with elevated privileges."), KAboutData::License_Artistic, "Copyright (c) 1998-2000 Geert Jansen, Pietro Iglio"); aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"), "[email protected]", "http://www.stack.nl/~geertj/"); aboutData.addAuthor("Pietro Iglio", I18N_NOOP("Original author"), "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KApplication::disableAutoDcopRegistration(); KApplication *app = new KApplication; { KStartupInfoId id; id.initId( app->startupId()); id.setupStartupEnv(); // make KDE_STARTUP_ENV env. var. available again } // Stop daemon and exit? if (args->isSet("s")) { KDEsuClient client; if (client.ping() == -1) { kdError(1206) << "Daemon not running -- nothing to stop\n"; exit(1); } if (client.stopServer() != -1) { kdDebug(1206) << "Daemon stopped\n"; exit(0); } kdError(1206) << "Could not stop daemon\n"; exit(1); } // Get target uid QCString user = args->getOption("u"); QCString auth_user = user; struct passwd *pw = getpwnam(user); if (pw == 0L) { kdError(1206) << "User " << user << " does not exist\n"; exit(1); } bool change_uid = (getuid() != pw->pw_uid); // If file is writeable, do not change uid QString file = QFile::decodeName(args->getOption("f")); if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); if (file.isEmpty()) { kdError(1206) << "Config file not found: " << file << "\n"; exit(1); } } QFileInfo fi(file); if (!fi.exists()) { kdError(1206) << "File does not exist: " << file << "\n"; exit(1); } change_uid = !fi.isWritable(); } // Get priority/scheduler QCString tmp = args->getOption("p"); bool ok; int priority = tmp.toInt(&ok); if (!ok || (priority < 0) || (priority > 100)) { KCmdLineArgs::usage(i18n("Illegal priority: %1").arg(tmp)); exit(1); } int scheduler = SuProcess::SchedNormal; if (args->isSet("r")) scheduler = SuProcess::SchedRealtime; if ((priority > 50) || (scheduler != SuProcess::SchedNormal)) { change_uid = true; auth_user = "root"; } // Get command if (args->isSet("c")) { command = args->getOption("c"); for (int i=0; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); } } else { if( args->count() == 0 ) { KCmdLineArgs::usage(i18n("No command specified!")); exit(1); } command = args->arg(0); for (int i=1; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); }}// CJM - Test lines remove when working// kdWarning(1206) << args->count();// kdWarning(1206) << command; // Don't change uid if we're don't need to. if (!change_uid) return system(command); // Check for daemon and start if necessary bool just_started = false; bool have_daemon = true; KDEsuClient client; if (!client.isServerSGID()) { kdWarning(1206) << "Daemon not safe (not sgid), not using it.\n"; have_daemon = false; } else if (client.ping() == -1) { if (client.startServer() == -1) { kdWarning(1206) << "Could not start daemon, reduced functionality.\n"; have_daemon = false; } just_started = true; } // Try to exec the command with kdesud. bool keep = !args->isSet("n") && have_daemon; bool terminal = args->isSet("t"); bool new_dcop = args->isSet("newdcop"); QCStringList env; QCString options; env << ( "KDE_STARTUP_ENV=" + kapp->startupId()); if (pw->pw_uid) { // Only propagate KDEHOME for non-root users, // root uses KDEROOTHOME // Translate the KDEHOME of this user to the new user. QString kdeHome = KGlobal::dirs()->relativeLocation("home", KGlobal::dirs()->localkdedir()); if (kdeHome[0] != '/') kdeHome.prepend("~/"); else kdeHome=QString::null; // Use default env << ("KDEHOME="+ QFile::encodeName(kdeHome)); } if (!new_dcop) { QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("tmp", "ksycoca")); env << ksycoca; options += "xf"; // X-only, dcop forwarding enabled. } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); if (client.exec(command, user, options, env) != -1) return 0; } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { kdError(1206) << "rlimit(): " << ERR << "\n"; exit(1); } // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Passwords"); int timeout = config->readNumEntry("Timeout", defTimeout); // Check if we need a password SuProcess proc; proc.setUser(auth_user); int needpw = proc.checkNeedPassword(); if (needpw < 0) { QString err = i18n("Su returned with an error!\n"); KMessageBox::error(0L, err); exit(1); } if (needpw == 0) { keep = 0; kdDebug() << "Don't need password!!\n"; } // Start the dialog QCString password; if (needpw) { KStartupInfoId id; id.initId( app->startupId()); KStartupInfoData data; data.setSilent( KStartupInfoData::Yes ); KStartupInfo::sendChange( id, data ); KDEsuDialog dlg(user, auth_user, keep && !terminal); dlg.addLine(i18n("Command:"), command); if ((priority != 50) || (scheduler != SuProcess::SchedNormal)) { QString prio; if (scheduler == SuProcess::SchedRealtime) prio += i18n("realtime: "); prio += QString("%1/100").arg(priority); dlg.addLine(i18n("Priority:"), prio); } int ret = dlg.exec(); if (ret == KDEsuDialog::Rejected) { KStartupInfo::sendFinish( id ); exit(0); } if (ret == KDEsuDialog::AsUser) change_uid = false; password = dlg.password(); keep = dlg.keep(); data.setSilent( KStartupInfoData::No ); KStartupInfo::sendChange( id, data ); } // Some events may need to be handled (like a button animation) app->processEvents(); if (!change_uid) return system(command); // Run command if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); return client.exec(command, user, options, env); } else { SuProcess proc; proc.setTerminal(terminal); proc.setErase(true); proc.setUser(user); if (!new_dcop) { proc.setXOnly(true); proc.setDCOPForwarding(true); } proc.setEnvironment(env); proc.setPriority(priority); proc.setScheduler(scheduler); proc.setCommand(command); return proc.exec(password); }}
KDEsuClient client; if (client.ping() == -1) { kdError(1206) << "Daemon not running -- nothing to stop\n"; exit(1); } if (client.stopServer() != -1) { kdDebug(1206) << "Daemon stopped\n"; exit(0); } kdError(1206) << "Could not stop daemon\n"; exit(1);
KMessageBox::sorry(0, i18n("Command '%1' not found.").arg(command));
int main(int argc, char *argv[]){ // FIXME: this can be considered a poor man's solution, as it's not // directly obvious to a gui user. :) // anyway, i vote against removing it even when we have a proper gui // implementation. -- ossi const char *duser = ::getenv("ADMIN_ACCOUNT"); if (duser && duser[0]) options[3].def = duser; KAboutData aboutData("kdesu", I18N_NOOP("KDE su"), Version, I18N_NOOP("Runs a program with elevated privileges."), KAboutData::License_Artistic, "Copyright (c) 1998-2000 Geert Jansen, Pietro Iglio"); aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"), "[email protected]", "http://www.stack.nl/~geertj/"); aboutData.addAuthor("Pietro Iglio", I18N_NOOP("Original author"), "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KApplication::disableAutoDcopRegistration(); KApplication *app = new KApplication; { KStartupInfoId id; id.initId( app->startupId()); id.setupStartupEnv(); // make KDE_STARTUP_ENV env. var. available again } // Stop daemon and exit? if (args->isSet("s")) { KDEsuClient client; if (client.ping() == -1) { kdError(1206) << "Daemon not running -- nothing to stop\n"; exit(1); } if (client.stopServer() != -1) { kdDebug(1206) << "Daemon stopped\n"; exit(0); } kdError(1206) << "Could not stop daemon\n"; exit(1); } // Get target uid QCString user = args->getOption("u"); QCString auth_user = user; struct passwd *pw = getpwnam(user); if (pw == 0L) { kdError(1206) << "User " << user << " does not exist\n"; exit(1); } bool change_uid = (getuid() != pw->pw_uid); // If file is writeable, do not change uid QString file = QFile::decodeName(args->getOption("f")); if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); if (file.isEmpty()) { kdError(1206) << "Config file not found: " << file << "\n"; exit(1); } } QFileInfo fi(file); if (!fi.exists()) { kdError(1206) << "File does not exist: " << file << "\n"; exit(1); } change_uid = !fi.isWritable(); } // Get priority/scheduler QCString tmp = args->getOption("p"); bool ok; int priority = tmp.toInt(&ok); if (!ok || (priority < 0) || (priority > 100)) { KCmdLineArgs::usage(i18n("Illegal priority: %1").arg(tmp)); exit(1); } int scheduler = SuProcess::SchedNormal; if (args->isSet("r")) scheduler = SuProcess::SchedRealtime; if ((priority > 50) || (scheduler != SuProcess::SchedNormal)) { change_uid = true; auth_user = "root"; } // Get command if (args->isSet("c")) { command = args->getOption("c"); for (int i=0; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); } } else { if( args->count() == 0 ) { KCmdLineArgs::usage(i18n("No command specified!")); exit(1); } command = args->arg(0); for (int i=1; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); }}// CJM - Test lines remove when working// kdWarning(1206) << args->count();// kdWarning(1206) << command; // Don't change uid if we're don't need to. if (!change_uid) return system(command); // Check for daemon and start if necessary bool just_started = false; bool have_daemon = true; KDEsuClient client; if (!client.isServerSGID()) { kdWarning(1206) << "Daemon not safe (not sgid), not using it.\n"; have_daemon = false; } else if (client.ping() == -1) { if (client.startServer() == -1) { kdWarning(1206) << "Could not start daemon, reduced functionality.\n"; have_daemon = false; } just_started = true; } // Try to exec the command with kdesud. bool keep = !args->isSet("n") && have_daemon; bool terminal = args->isSet("t"); bool new_dcop = args->isSet("newdcop"); QCStringList env; QCString options; env << ( "KDE_STARTUP_ENV=" + kapp->startupId()); if (pw->pw_uid) { // Only propagate KDEHOME for non-root users, // root uses KDEROOTHOME // Translate the KDEHOME of this user to the new user. QString kdeHome = KGlobal::dirs()->relativeLocation("home", KGlobal::dirs()->localkdedir()); if (kdeHome[0] != '/') kdeHome.prepend("~/"); else kdeHome=QString::null; // Use default env << ("KDEHOME="+ QFile::encodeName(kdeHome)); } if (!new_dcop) { QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("tmp", "ksycoca")); env << ksycoca; options += "xf"; // X-only, dcop forwarding enabled. } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); if (client.exec(command, user, options, env) != -1) return 0; } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { kdError(1206) << "rlimit(): " << ERR << "\n"; exit(1); } // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Passwords"); int timeout = config->readNumEntry("Timeout", defTimeout); // Check if we need a password SuProcess proc; proc.setUser(auth_user); int needpw = proc.checkNeedPassword(); if (needpw < 0) { QString err = i18n("Su returned with an error!\n"); KMessageBox::error(0L, err); exit(1); } if (needpw == 0) { keep = 0; kdDebug() << "Don't need password!!\n"; } // Start the dialog QCString password; if (needpw) { KStartupInfoId id; id.initId( app->startupId()); KStartupInfoData data; data.setSilent( KStartupInfoData::Yes ); KStartupInfo::sendChange( id, data ); KDEsuDialog dlg(user, auth_user, keep && !terminal); dlg.addLine(i18n("Command:"), command); if ((priority != 50) || (scheduler != SuProcess::SchedNormal)) { QString prio; if (scheduler == SuProcess::SchedRealtime) prio += i18n("realtime: "); prio += QString("%1/100").arg(priority); dlg.addLine(i18n("Priority:"), prio); } int ret = dlg.exec(); if (ret == KDEsuDialog::Rejected) { KStartupInfo::sendFinish( id ); exit(0); } if (ret == KDEsuDialog::AsUser) change_uid = false; password = dlg.password(); keep = dlg.keep(); data.setSilent( KStartupInfoData::No ); KStartupInfo::sendChange( id, data ); } // Some events may need to be handled (like a button animation) app->processEvents(); if (!change_uid) return system(command); // Run command if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); return client.exec(command, user, options, env); } else { SuProcess proc; proc.setTerminal(terminal); proc.setErase(true); proc.setUser(user); if (!new_dcop) { proc.setXOnly(true); proc.setDCOPForwarding(true); } proc.setEnvironment(env); proc.setPriority(priority); proc.setScheduler(scheduler); proc.setCommand(command); return proc.exec(password); }}
QCString user = args->getOption("u"); QCString auth_user = user; struct passwd *pw = getpwnam(user); if (pw == 0L) { kdError(1206) << "User " << user << " does not exist\n"; exit(1); } bool change_uid = (getuid() != pw->pw_uid); QString file = QFile::decodeName(args->getOption("f")); if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); if (file.isEmpty()) { kdError(1206) << "Config file not found: " << file << "\n"; exit(1); } } QFileInfo fi(file); if (!fi.exists()) { kdError(1206) << "File does not exist: " << file << "\n"; exit(1); } change_uid = !fi.isWritable(); } QCString tmp = args->getOption("p"); bool ok; int priority = tmp.toInt(&ok); if (!ok || (priority < 0) || (priority > 100)) { KCmdLineArgs::usage(i18n("Illegal priority: %1").arg(tmp)); exit(1); } int scheduler = SuProcess::SchedNormal; if (args->isSet("r")) scheduler = SuProcess::SchedRealtime; if ((priority > 50) || (scheduler != SuProcess::SchedNormal)) { change_uid = true; auth_user = "root"; } if (args->isSet("c")) { command = args->getOption("c"); for (int i=0; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); } } else { if( args->count() == 0 ) { KCmdLineArgs::usage(i18n("No command specified!")); exit(1); } command = args->arg(0); for (int i=1; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); }} if (!change_uid) return system(command); bool just_started = false; bool have_daemon = true; KDEsuClient client; if (!client.isServerSGID()) { kdWarning(1206) << "Daemon not safe (not sgid), not using it.\n"; have_daemon = false; } else if (client.ping() == -1) { if (client.startServer() == -1) { kdWarning(1206) << "Could not start daemon, reduced functionality.\n"; have_daemon = false; } just_started = true; } bool keep = !args->isSet("n") && have_daemon; bool terminal = args->isSet("t"); bool new_dcop = args->isSet("newdcop"); QCStringList env; QCString options; env << ( "KDE_STARTUP_ENV=" + kapp->startupId()); if (pw->pw_uid) { QString kdeHome = KGlobal::dirs()->relativeLocation("home", KGlobal::dirs()->localkdedir()); if (kdeHome[0] != '/') kdeHome.prepend("~/"); else kdeHome=QString::null; env << ("KDEHOME="+ QFile::encodeName(kdeHome)); } if (!new_dcop) { QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("tmp", "ksycoca")); env << ksycoca; options += "xf"; } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); if (client.exec(command, user, options, env) != -1) return 0; } struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { kdError(1206) << "rlimit(): " << ERR << "\n"; exit(1); } KConfig *config = KGlobal::config(); config->setGroup("Passwords"); int timeout = config->readNumEntry("Timeout", defTimeout); SuProcess proc; proc.setUser(auth_user); int needpw = proc.checkNeedPassword(); if (needpw < 0) { QString err = i18n("Su returned with an error!\n"); KMessageBox::error(0L, err); exit(1); } if (needpw == 0) { keep = 0; kdDebug() << "Don't need password!!\n"; } QCString password; if (needpw) { KStartupInfoId id; id.initId( app->startupId()); KStartupInfoData data; data.setSilent( KStartupInfoData::Yes ); KStartupInfo::sendChange( id, data ); KDEsuDialog dlg(user, auth_user, keep && !terminal); dlg.addLine(i18n("Command:"), command); if ((priority != 50) || (scheduler != SuProcess::SchedNormal)) { QString prio; if (scheduler == SuProcess::SchedRealtime) prio += i18n("realtime: "); prio += QString("%1/100").arg(priority); dlg.addLine(i18n("Priority:"), prio); } int ret = dlg.exec(); if (ret == KDEsuDialog::Rejected) { KStartupInfo::sendFinish( id ); exit(0); } if (ret == KDEsuDialog::AsUser) change_uid = false; password = dlg.password(); keep = dlg.keep(); data.setSilent( KStartupInfoData::No ); KStartupInfo::sendChange( id, data ); } app->processEvents(); if (!change_uid) return system(command); if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); return client.exec(command, user, options, env); } else { SuProcess proc; proc.setTerminal(terminal); proc.setErase(true); proc.setUser(user); if (!new_dcop) { proc.setXOnly(true); proc.setDCOPForwarding(true); } proc.setEnvironment(env); proc.setPriority(priority); proc.setScheduler(scheduler); proc.setCommand(command); return proc.exec(password); }
return result;
int main(int argc, char *argv[]){ // FIXME: this can be considered a poor man's solution, as it's not // directly obvious to a gui user. :) // anyway, i vote against removing it even when we have a proper gui // implementation. -- ossi const char *duser = ::getenv("ADMIN_ACCOUNT"); if (duser && duser[0]) options[3].def = duser; KAboutData aboutData("kdesu", I18N_NOOP("KDE su"), Version, I18N_NOOP("Runs a program with elevated privileges."), KAboutData::License_Artistic, "Copyright (c) 1998-2000 Geert Jansen, Pietro Iglio"); aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"), "[email protected]", "http://www.stack.nl/~geertj/"); aboutData.addAuthor("Pietro Iglio", I18N_NOOP("Original author"), "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KApplication::disableAutoDcopRegistration(); KApplication *app = new KApplication; { KStartupInfoId id; id.initId( app->startupId()); id.setupStartupEnv(); // make KDE_STARTUP_ENV env. var. available again } // Stop daemon and exit? if (args->isSet("s")) { KDEsuClient client; if (client.ping() == -1) { kdError(1206) << "Daemon not running -- nothing to stop\n"; exit(1); } if (client.stopServer() != -1) { kdDebug(1206) << "Daemon stopped\n"; exit(0); } kdError(1206) << "Could not stop daemon\n"; exit(1); } // Get target uid QCString user = args->getOption("u"); QCString auth_user = user; struct passwd *pw = getpwnam(user); if (pw == 0L) { kdError(1206) << "User " << user << " does not exist\n"; exit(1); } bool change_uid = (getuid() != pw->pw_uid); // If file is writeable, do not change uid QString file = QFile::decodeName(args->getOption("f")); if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); if (file.isEmpty()) { kdError(1206) << "Config file not found: " << file << "\n"; exit(1); } } QFileInfo fi(file); if (!fi.exists()) { kdError(1206) << "File does not exist: " << file << "\n"; exit(1); } change_uid = !fi.isWritable(); } // Get priority/scheduler QCString tmp = args->getOption("p"); bool ok; int priority = tmp.toInt(&ok); if (!ok || (priority < 0) || (priority > 100)) { KCmdLineArgs::usage(i18n("Illegal priority: %1").arg(tmp)); exit(1); } int scheduler = SuProcess::SchedNormal; if (args->isSet("r")) scheduler = SuProcess::SchedRealtime; if ((priority > 50) || (scheduler != SuProcess::SchedNormal)) { change_uid = true; auth_user = "root"; } // Get command if (args->isSet("c")) { command = args->getOption("c"); for (int i=0; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); } } else { if( args->count() == 0 ) { KCmdLineArgs::usage(i18n("No command specified!")); exit(1); } command = args->arg(0); for (int i=1; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); }}// CJM - Test lines remove when working// kdWarning(1206) << args->count();// kdWarning(1206) << command; // Don't change uid if we're don't need to. if (!change_uid) return system(command); // Check for daemon and start if necessary bool just_started = false; bool have_daemon = true; KDEsuClient client; if (!client.isServerSGID()) { kdWarning(1206) << "Daemon not safe (not sgid), not using it.\n"; have_daemon = false; } else if (client.ping() == -1) { if (client.startServer() == -1) { kdWarning(1206) << "Could not start daemon, reduced functionality.\n"; have_daemon = false; } just_started = true; } // Try to exec the command with kdesud. bool keep = !args->isSet("n") && have_daemon; bool terminal = args->isSet("t"); bool new_dcop = args->isSet("newdcop"); QCStringList env; QCString options; env << ( "KDE_STARTUP_ENV=" + kapp->startupId()); if (pw->pw_uid) { // Only propagate KDEHOME for non-root users, // root uses KDEROOTHOME // Translate the KDEHOME of this user to the new user. QString kdeHome = KGlobal::dirs()->relativeLocation("home", KGlobal::dirs()->localkdedir()); if (kdeHome[0] != '/') kdeHome.prepend("~/"); else kdeHome=QString::null; // Use default env << ("KDEHOME="+ QFile::encodeName(kdeHome)); } if (!new_dcop) { QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("tmp", "ksycoca")); env << ksycoca; options += "xf"; // X-only, dcop forwarding enabled. } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); if (client.exec(command, user, options, env) != -1) return 0; } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { kdError(1206) << "rlimit(): " << ERR << "\n"; exit(1); } // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Passwords"); int timeout = config->readNumEntry("Timeout", defTimeout); // Check if we need a password SuProcess proc; proc.setUser(auth_user); int needpw = proc.checkNeedPassword(); if (needpw < 0) { QString err = i18n("Su returned with an error!\n"); KMessageBox::error(0L, err); exit(1); } if (needpw == 0) { keep = 0; kdDebug() << "Don't need password!!\n"; } // Start the dialog QCString password; if (needpw) { KStartupInfoId id; id.initId( app->startupId()); KStartupInfoData data; data.setSilent( KStartupInfoData::Yes ); KStartupInfo::sendChange( id, data ); KDEsuDialog dlg(user, auth_user, keep && !terminal); dlg.addLine(i18n("Command:"), command); if ((priority != 50) || (scheduler != SuProcess::SchedNormal)) { QString prio; if (scheduler == SuProcess::SchedRealtime) prio += i18n("realtime: "); prio += QString("%1/100").arg(priority); dlg.addLine(i18n("Priority:"), prio); } int ret = dlg.exec(); if (ret == KDEsuDialog::Rejected) { KStartupInfo::sendFinish( id ); exit(0); } if (ret == KDEsuDialog::AsUser) change_uid = false; password = dlg.password(); keep = dlg.keep(); data.setSilent( KStartupInfoData::No ); KStartupInfo::sendChange( id, data ); } // Some events may need to be handled (like a button animation) app->processEvents(); if (!change_uid) return system(command); // Run command if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); return client.exec(command, user, options, env); } else { SuProcess proc; proc.setTerminal(terminal); proc.setErase(true); proc.setUser(user); if (!new_dcop) { proc.setXOnly(true); proc.setDCOPForwarding(true); } proc.setEnvironment(env); proc.setPriority(priority); proc.setScheduler(scheduler); proc.setCommand(command); return proc.exec(password); }}
client[i]->unmount();
int main(int argc, char **argv) { cout << "fakefuse starting" << endl; MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD); // start messenger thread fakemessenger_startthread(); g_timer.add_event_after(5.0, new C_Test2); g_timer.add_event_after(10.0, new C_Test); // create mds MDS *mds[NUMMDS]; for (int i=0; i<NUMMDS; i++) { mds[i] = new MDS(mdc, i, new FakeMessenger(MSG_ADDR_MDS(i))); mds[i]->init(); } // create osd OSD *osd[NUMOSD]; for (int i=0; i<NUMOSD; i++) { osd[i] = new OSD(i, new FakeMessenger(MSG_ADDR_OSD(i))); osd[i]->init(); } // create client Client *client[NUMCLIENT]; for (int i=0; i<NUMCLIENT; i++) { // build a serialized fakemessenger... FakeMessenger *fake = new FakeMessenger(MSG_ADDR_CLIENT(0)); CheesySerializer *serializer = new CheesySerializer(fake); fake->set_dispatcher(serializer); client[i] = new Client(mdc, i, serializer); client[i]->init(); // start up fuse // use my argc, argv (make sure you pass a mount point!) cout << "starting fuse on pid " << getpid() << endl; ceph_fuse_main(client[i], argc, argv); cout << "fuse finished on pid " << getpid() << endl; client[i]->shutdown(); } // wait for it to finish cout << "DONE -----" << endl; fakemessenger_stopthread(); // blocks until messenger stops // shutdown /* cout << "---- check ----" << endl; for (int i=0; i<NUMMDS; i++) { if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_MDS(i),world)) continue; mds[i]->mdcache->shutdown_pass(); } */ // cleanup for (int i=0; i<NUMMDS; i++) { delete mds[i]; } for (int i=0; i<NUMOSD; i++) { delete osd[i]; } for (int i=0; i<NUMCLIENT; i++) { delete client[i]; } delete mdc; return 0;}
kdDebug() << "Initializing " << libName << ": " << factory << endl;
kdDebug(1208) << "Initializing " << libName << ": " << factory << endl;
int main(int argc, char *argv[]){ KLocale::setMainCatalogue("kcontrol"); KAboutData aboutData( "kcminit", I18N_NOOP("KCMInit"), "$Id$", I18N_NOOP("KCMInit - runs startups initialization for Control Modules.")); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app; KLocale::setMainCatalogue(0); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); QCString arg; if (args->count() == 1) { arg = args->arg(0); } // get the library loader instance KLibLoader *loader = KLibLoader::self(); KService::List list; if (!arg.isEmpty()) { QString path = KCGlobal::baseGroup(); path += arg; path += ".desktop"; KService::Ptr serv = KService::serviceByDesktopPath( path ); if (!serv) { // Path didn't work. Trying as a name serv = KService::serviceByDesktopName( arg ); } if ( !serv || serv->library().isEmpty() || serv->init().isEmpty()) { kdError(1208) << i18n("Module %1 not found!").arg(arg) << endl; return -1; } else list.append(serv); } else { // locate the desktop files list = KService::allInitServices(); } // look for X-KDE-Init=... entries for(KService::List::Iterator it = list.begin(); it != list.end(); ++it) { KService::Ptr service = (*it); if (service->library().isEmpty() || service->init().isEmpty()) continue; // Skip // try to load the library QString libName = QString("libkcm_%1").arg(service->library()); KLibrary *lib = loader->library(QFile::encodeName(libName)); if (lib) { // get the init_ function QString factory = QString("init_%1").arg(service->init()); void *init = lib->symbol(factory.utf8()); if (init) { // initialize the module kdDebug() << "Initializing " << libName << ": " << factory << endl; void (*func)() = (void(*)())init; func(); } loader->unloadLibrary(QFile::encodeName(libName)); } } if ( !kapp->dcopClient()->isAttached() ) kapp->dcopClient()->attach(); kapp->dcopClient()->send( "ksplash", "", "upAndRunning(QString)", QString("kcminit")); return 0;}
if ( qgis->addRasterLayer(argv[i]) ) { continue;
if(!qgis->addProject(path)){ bool ok = qgis->addRasterLayer(path); if(!ok){ ok = qgis->addLayer(argv[i]); if(!ok){ std::cout << "Unable to load " << argv[i] << std::endl; } }
int main(int argc, char *argv[]){ QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (argc == 2) { QString translation = "qgis_" + QString(argv[1]); tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); qgis->show(); // // autoload any filenames that were passed in on the command line // for (int i = 1; i < argc; i++) {#ifdef QGISDEBUG printf("%d: %s\n", i, argv[i]);#endif // try to add all these layers - any unsupported file types will // be refected automatically if ( qgis->addRasterLayer(argv[i]) ) { // NOP continue; } else if ( qgis->addLayer(argv[i]) ) { // NOP continue; } else { // XXX should have complaint here about file not being valid#ifdef QGISDEBUG std::cerr << argv[i] << " is not a recognized file\n"; #endif } } a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); // //turn control over to the main application loop... // int result = a.exec(); return result;}
else if ( qgis->addLayer(argv[i]) ) { continue; } else { #ifdef QGISDEBUG std::cerr << argv[i] << " is not a recognized file\n"; #endif }
int main(int argc, char *argv[]){ QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (argc == 2) { QString translation = "qgis_" + QString(argv[1]); tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); qgis->show(); // // autoload any filenames that were passed in on the command line // for (int i = 1; i < argc; i++) {#ifdef QGISDEBUG printf("%d: %s\n", i, argv[i]);#endif // try to add all these layers - any unsupported file types will // be refected automatically if ( qgis->addRasterLayer(argv[i]) ) { // NOP continue; } else if ( qgis->addLayer(argv[i]) ) { // NOP continue; } else { // XXX should have complaint here about file not being valid#ifdef QGISDEBUG std::cerr << argv[i] << " is not a recognized file\n"; #endif } } a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); // //turn control over to the main application loop... // int result = a.exec(); return result;}
kdebug( KDEBUG_INFO, 7103, "Done" );
int main( int, char ** ){ signal(SIGCHLD, KIOProtocol::sigchld_handler);// signal(SIGSEGV, IOProtocol::sigsegv_handler); KInstance instance( "kio_http" ); KIOConnection parent( 0, 1 ); HTTPProtocol http( &parent ); http.dispatchLoop();}
a.processEvents();
int main(int argc, char *argv[]){ ///////////////////////////////////////////////////////////////// // Command line options 'behaviour' flag setup //////////////////////////////////////////////////////////////// // // Parse the command line arguments, looking to see if the user has asked for any // special behaviours. Any remaining non command arguments will be kept aside to // be passed as a list of layers and / or a project that should be loaded. // // This behaviour is used to load the app, snapshot the map, // save the image to disk and then exit QString mySnapshotFileName=""; // This behaviour will cause QGIS to autoload a project QString myProjectFileName=""; // This behaviour will allow you to force the use of a translation file // which is useful for testing QString myTranslationFileName=""; // This is the 'leftover' arguments collection QStringList * myFileList=new QStringList(); //////////////////////////////////////////////////////////////// // USe the GNU Getopts utility to parse cli arguments // Invokes ctor `GetOpt (int argc, char **argv, char *optstring);' /////////////////////////////////////////////////////////////// int optionChar; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"snapshot", required_argument, 0, 's'}, {"lang", required_argument, 0, 'l'}, {"project", required_argument, 0, 'p'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "slp", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 's': mySnapshotFileName=optarg; break; case 'l': myTranslationFileName=optarg; break; case 'p': myProjectFileName=optarg; break; case 'h': case '?': usage( argv[0] ); return 2; // XXX need standard exit codes break; default: std::cerr << argv[0] << ": getopt returned character code " << optionChar << "\n"; return 1; // XXX need standard exit codes } } // Add any remaining args to the file list - we will attempt to load them // as layers in the map view further down....#ifdef QGISDEBUG std::cout << "Files specified on command line: " << optind << std::endl;#endif if (optind < argc) { while (optind < argc) {#ifdef QGISDEBUG int idx = optind; std::cout << idx << ": " << argv[idx] << std::endl;#endif myFileList->append(argv[optind++]); } } ///////////////////////////////////////////////////////////////////// // Now we have the handlers for the different behaviours... //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// // Initialise the application and the translation stuff ///////////////////////////////////////////////////////////////////// QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (myTranslationFileName!="") { QString translation = "qgis_" + myTranslationFileName; tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if(myProjectFileName!="") { if ( ! qgis->addProject(myProjectFileName) ) {#ifdef QGISDEBUG std::cerr << "unable to load project " << myProjectFileName << "\n";#endif } } ///////////////////////////////////////////////////////////////////// // autoload any filenames that were passed in on the command line /////////////////////////////////////////////////////////////////////#ifdef QGISDEBUG std::cout << "Number of files in myFileList: " << myFileList->count() << std::endl;#endif for ( QStringList::Iterator myIterator = myFileList->begin(); myIterator != myFileList->end(); ++myIterator ) {#ifdef QGISDEBUG std::cout << "Trying to load file : " << *myIterator << std::endl;#endif QString myLayerName = *myIterator; // try to add all these layers - any unsupported file types will // be rejected automatically // The funky bool ok is so this can be debugged a bit easier... //nope - try and load it as raster bool ok = qgis->addRasterLayer(myLayerName); if(!ok){ //nope - try and load it as a shape/ogr ok = qgis->addLayer(myLayerName); //we have no idea what this layer is... if(!ok){ std::cout << "Unable to load " << myLayerName << std::endl; } } } ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if(myProjectFileName!="") { qgis->addProject(myProjectFileName); } ///////////////////////////////////////////////////////////////////// // Take a snapshot of the map view then exit if snapshot mode requested ///////////////////////////////////////////////////////////////////// if(mySnapshotFileName!="") { // qgis->show(); QPixmap * myQPixmap = new QPixmap(800,600); myQPixmap->fill(); qgis->saveMapAsImage(mySnapshotFileName,myQPixmap); return 1; } ///////////////////////////////////////////////////////////////////// // Continue on to interactive gui... ///////////////////////////////////////////////////////////////////// qgis->show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec();}
a.processEvents(); qgis->hide();
int main(int argc, char *argv[]){ ///////////////////////////////////////////////////////////////// // Command line options 'behaviour' flag setup //////////////////////////////////////////////////////////////// // // Parse the command line arguments, looking to see if the user has asked for any // special behaviours. Any remaining non command arguments will be kept aside to // be passed as a list of layers and / or a project that should be loaded. // // This behaviour is used to load the app, snapshot the map, // save the image to disk and then exit QString mySnapshotFileName=""; // This behaviour will cause QGIS to autoload a project QString myProjectFileName=""; // This behaviour will allow you to force the use of a translation file // which is useful for testing QString myTranslationFileName=""; // This is the 'leftover' arguments collection QStringList * myFileList=new QStringList(); //////////////////////////////////////////////////////////////// // USe the GNU Getopts utility to parse cli arguments // Invokes ctor `GetOpt (int argc, char **argv, char *optstring);' /////////////////////////////////////////////////////////////// int optionChar; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"snapshot", required_argument, 0, 's'}, {"lang", required_argument, 0, 'l'}, {"project", required_argument, 0, 'p'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "slp", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 's': mySnapshotFileName=optarg; break; case 'l': myTranslationFileName=optarg; break; case 'p': myProjectFileName=optarg; break; case 'h': case '?': usage( argv[0] ); return 2; // XXX need standard exit codes break; default: std::cerr << argv[0] << ": getopt returned character code " << optionChar << "\n"; return 1; // XXX need standard exit codes } } // Add any remaining args to the file list - we will attempt to load them // as layers in the map view further down....#ifdef QGISDEBUG std::cout << "Files specified on command line: " << optind << std::endl;#endif if (optind < argc) { while (optind < argc) {#ifdef QGISDEBUG int idx = optind; std::cout << idx << ": " << argv[idx] << std::endl;#endif myFileList->append(argv[optind++]); } } ///////////////////////////////////////////////////////////////////// // Now we have the handlers for the different behaviours... //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// // Initialise the application and the translation stuff ///////////////////////////////////////////////////////////////////// QApplication a(argc, argv); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (myTranslationFileName!="") { QString translation = "qgis_" + myTranslationFileName; tor.load(translation, "."); } else { tor.load(QString("qgis_") + QTextCodec::locale(), "."); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if(myProjectFileName!="") { if ( ! qgis->addProject(myProjectFileName) ) {#ifdef QGISDEBUG std::cerr << "unable to load project " << myProjectFileName << "\n";#endif } } ///////////////////////////////////////////////////////////////////// // autoload any filenames that were passed in on the command line /////////////////////////////////////////////////////////////////////#ifdef QGISDEBUG std::cout << "Number of files in myFileList: " << myFileList->count() << std::endl;#endif for ( QStringList::Iterator myIterator = myFileList->begin(); myIterator != myFileList->end(); ++myIterator ) {#ifdef QGISDEBUG std::cout << "Trying to load file : " << *myIterator << std::endl;#endif QString myLayerName = *myIterator; // try to add all these layers - any unsupported file types will // be rejected automatically // The funky bool ok is so this can be debugged a bit easier... //nope - try and load it as raster bool ok = qgis->addRasterLayer(myLayerName); if(!ok){ //nope - try and load it as a shape/ogr ok = qgis->addLayer(myLayerName); //we have no idea what this layer is... if(!ok){ std::cout << "Unable to load " << myLayerName << std::endl; } } } ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if(myProjectFileName!="") { qgis->addProject(myProjectFileName); } ///////////////////////////////////////////////////////////////////// // Take a snapshot of the map view then exit if snapshot mode requested ///////////////////////////////////////////////////////////////////// if(mySnapshotFileName!="") { // qgis->show(); QPixmap * myQPixmap = new QPixmap(800,600); myQPixmap->fill(); qgis->saveMapAsImage(mySnapshotFileName,myQPixmap); return 1; } ///////////////////////////////////////////////////////////////////// // Continue on to interactive gui... ///////////////////////////////////////////////////////////////////// qgis->show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec();}
if(myProjectFileName!="") { qgis->addProject(myProjectFileName); }
int main(int argc, char *argv[]){ ///////////////////////////////////////////////////////////////// // Command line options 'behaviour' flag setup //////////////////////////////////////////////////////////////// // // Parse the command line arguments, looking to see if the user has asked for any // special behaviours. Any remaining non command arguments will be kept aside to // be passed as a list of layers and / or a project that should be loaded. // // This behaviour is used to load the app, snapshot the map, // save the image to disk and then exit QString mySnapshotFileName=""; // This behaviour will cause QGIS to autoload a project QString myProjectFileName=""; // This behaviour will allow you to force the use of a translation file // which is useful for testing QString myTranslationFileName=""; // This is the 'leftover' arguments collection QStringList * myFileList=new QStringList(); //////////////////////////////////////////////////////////////// // USe the GNU Getopts utility to parse cli arguments // Invokes ctor `GetOpt (int argc, char **argv, char *optstring);' /////////////////////////////////////////////////////////////// int optionChar; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"snapshot", required_argument, 0, 's'}, {"lang", required_argument, 0, 'l'}, {"project", required_argument, 0, 'p'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "slp", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 's': mySnapshotFileName=optarg; break; case 'l': myTranslationFileName=optarg; break; case 'p': myProjectFileName=optarg; break; case 'h': case '?': usage( argv[0] ); return 2; // XXX need standard exit codes break; default: std::cerr << argv[0] << ": getopt returned character code " << optionChar << "\n"; return 1; // XXX need standard exit codes } } // Add any remaining args to the file list - we will attempt to load them // as layers in the map view further down....#ifdef QGISDEBUG std::cout << "Files specified on command line: " << optind << std::endl;#endif if (optind < argc) { while (optind < argc) {#ifdef QGISDEBUG int idx = optind; std::cout << idx << ": " << argv[idx] << std::endl;#endif myFileList->append(argv[optind++]); } } ///////////////////////////////////////////////////////////////////// // Now we have the handlers for the different behaviours... //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// // Initialise the application and the translation stuff /////////////////////////////////////////////////////////////////////#ifdef Q_WS_X11 bool myUseGuiFlag = getenv( "DISPLAY" ) != 0;#else bool myUseGuiFlag = TRUE;#endif if (!myUseGuiFlag) { std::cerr << "QGIS starting in non-interactive mode because you have no DISPLAY environment variable set." << std::endl; } QApplication a(argc, argv, myUseGuiFlag ); // a.setFont(QFont("helvetica", 11)); QTranslator tor(0); // set the location where your .qm files are in load() below as the last parameter instead of "." // for development, use "/" to use the english original as // .qm files are stored in the base project directory. if (myTranslationFileName!="") { QString translation = "qgis_" + myTranslationFileName; tor.load(translation, QString(PKGDATAPATH) + "/i18n"); } else { tor.load(QString("qgis_") + QTextCodec::locale(), QString(PKGDATAPATH) + "/i18n"); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp(); a.setMainWidget(qgis); ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if(myProjectFileName!="") { if ( ! qgis->addProject(myProjectFileName) ) {#ifdef QGISDEBUG std::cerr << "unable to load project " << myProjectFileName << "\n";#endif } } ///////////////////////////////////////////////////////////////////// // autoload any filenames that were passed in on the command line /////////////////////////////////////////////////////////////////////#ifdef QGISDEBUG std::cout << "Number of files in myFileList: " << myFileList->count() << std::endl;#endif for ( QStringList::Iterator myIterator = myFileList->begin(); myIterator != myFileList->end(); ++myIterator ) {#ifdef QGISDEBUG std::cout << "Trying to load file : " << *myIterator << std::endl;#endif QString myLayerName = *myIterator; // try to add all these layers - any unsupported file types will // be rejected automatically // The funky bool ok is so this can be debugged a bit easier... //nope - try and load it as raster bool ok = qgis->addRasterLayer(myLayerName); if(!ok){ //nope - try and load it as a shape/ogr ok = qgis->addLayer(myLayerName); //we have no idea what this layer is... if(!ok){ std::cout << "Unable to load " << myLayerName << std::endl; } } } ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if(myProjectFileName!="") { qgis->addProject(myProjectFileName); } ///////////////////////////////////////////////////////////////////// // Take a snapshot of the map view then exit if snapshot mode requested ///////////////////////////////////////////////////////////////////// if(mySnapshotFileName!="") { /*You must have at least one paintEvent() delivered for the window to be rendered properly. It looks like you don't run the event loop in non-interactive mode, so the event is never occuring. To achieve this without runing the event loop: show the window, then call qApp->processEvents(), grab the pixmap, save it, hide the window and exit. */ //qgis->show(); a.processEvents(); QPixmap * myQPixmap = new QPixmap(800,600); myQPixmap->fill(); qgis->saveMapAsImage(mySnapshotFileName,myQPixmap); a.processEvents(); qgis->hide(); return 1; } ///////////////////////////////////////////////////////////////////// // Continue on to interactive gui... ///////////////////////////////////////////////////////////////////// qgis->show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec();}
if (app.startServiceByDesktopName("konqueror", "--silent", dcopService, error))
if (app.startServiceByDesktopName("konqueror", QString::fromLatin1("--silent"), &error))
int main(int argc, char *argv[]){ KAboutData aboutData( "khelpcenter", I18N_NOOP("KDE HelpCenter"), HELPCENTER_VERSION, I18N_NOOP("The KDE Help Center"), KAboutData::License_GPL, "(c) 1999-2000, Matthias Elter"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); KCmdLineArgs::init( argc, argv, &aboutData ); KCmdLineArgs::addCmdLineOptions( options ); KApplication::addCmdLineOptions(); KApplication app( false, false ); // no GUI in this process app.dcopClient()->attach(); Listener listener; QCString dcopService; QString error; // try to connect to an already running konqueror, if one exists QCStringList apps = app.dcopClient()->registeredApplications(); QCStringList::ConstIterator it; for (it = apps.begin(); it != apps.end(); ++it) if ((*it).left(9) == "konqueror") { createHelpWindow(*it); exit(0); } // run a new konqueror instance app.dcopClient()->setNotifications( true ); QObject::connect( app.dcopClient(), SIGNAL( applicationRegistered( const QCString& ) ), &listener, SLOT( slotAppRegistered( const QCString & ) ) ); if (app.startServiceByDesktopName("konqueror", "--silent", dcopService, error)) { warning("Could not launch browser:\n%s\n", error.local8Bit().data()); return 1; } app.exec();}
KDEsuDialog *dlg = new KDEsuDialog(user, auth_user, keep && !terminal); dlg->addLine(i18n("Command:"), command);
KStartupInfoId id; id.initId( app->startupId()); KStartupInfoData data; data.setSuspend( KStartupInfoData::Yes ); KStartupInfo::sendChange( id, data ); KDEsuDialog dlg(user, auth_user, keep && !terminal); dlg.addLine(i18n("Command:"), command);
int main(int argc, char *argv[]){ // FIXME: this can be considered a poor man's solution, as it's not // directly obvious to a gui user. :) // anyway, i vote against removing it even when we have a proper gui // implementation. -- ossi const char *duser = ::getenv("ADMIN_ACCOUNT"); if (duser && duser[0]) options[3].def = duser; KAboutData aboutData("kdesu", I18N_NOOP("KDE su"), Version, I18N_NOOP("Runs a program with elevated privileges."), KAboutData::License_Artistic, "Copyright (c) 1998-2000 Geert Jansen, Pietro Iglio"); aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"), "[email protected]", "http://www.stack.nl/~geertj/"); aboutData.addAuthor("Pietro Iglio", I18N_NOOP("Original author"), "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KApplication::disableAutoDcopRegistration(); KApplication *app = new KApplication; // Stop daemon and exit? if (args->isSet("s")) { KDEsuClient client; if (client.ping() == -1) { kdError(1206) << "Daemon not running -- nothing to stop\n"; exit(1); } if (client.stopServer() != -1) { kdDebug(1206) << "Daemon stopped\n"; exit(0); } kdError(1206) << "Could not stop daemon\n"; exit(1); } // Get target uid QCString user = args->getOption("u"); QCString auth_user = user; struct passwd *pw = getpwnam(user); if (pw == 0L) { kdError(1206) << "User " << user << " does not exist\n"; exit(1); } bool change_uid = (getuid() != pw->pw_uid); // If file is writeable, do not change uid QString file = QFile::decodeName(args->getOption("f")); if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); if (file.isEmpty()) { kdError(1206) << "Config file not found: " << file << "\n"; exit(1); } } QFileInfo fi(file); if (!fi.exists()) { kdError(1206) << "File does not exist: " << file << "\n"; exit(1); } change_uid = !fi.isWritable(); } // Get priority/scheduler QCString tmp = args->getOption("p"); bool ok; int priority = tmp.toInt(&ok); if (!ok || (priority < 0) || (priority > 100)) { KCmdLineArgs::usage(i18n("Illegal priority: %1").arg(tmp)); exit(1); } int scheduler = SuProcess::SchedNormal; if (args->isSet("r")) scheduler = SuProcess::SchedRealtime; if ((priority > 50) || (scheduler != SuProcess::SchedNormal)) { change_uid = true; auth_user = "root"; } // Get command if (args->isSet("c")) { command = args->getOption("c"); for (int i=0; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); } } else { if( args->count() == 0 ) { KCmdLineArgs::usage(i18n("No command specified!")); exit(1); } command = args->arg(0); for (int i=1; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); }}// CJM - Test lines remove when working// kdWarning(1206) << args->count();// kdWarning(1206) << command; // Don't change uid if we're don't need to. if (!change_uid) return system(command); // Check for daemon and start if necessary bool just_started = false; bool have_daemon = true; KDEsuClient client; if (!client.isServerSGID()) { kdWarning(1206) << "Daemon not safe (not sgid), not using it.\n"; have_daemon = false; } else if (client.ping() == -1) { if (client.startServer() == -1) { kdWarning(1206) << "Could not start daemon, reduced functionality.\n"; have_daemon = false; } just_started = true; } // Try to exec the command with kdesud. bool keep = !args->isSet("n") && have_daemon; bool terminal = args->isSet("t"); bool new_dcop = args->isSet("newdcop"); QCStringList env; QCString options; if (!new_dcop) { QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("tmp", "ksycoca")); env << ksycoca; options += "xf"; // X-only, dcop forwarding enabled. } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); if (client.exec(command, user, options, env) != -1) return 0; } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { kdError(1206) << "rlimit(): " << ERR << "\n"; exit(1); } // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Passwords"); int timeout = config->readNumEntry("Timeout", defTimeout); // Check if we need a password SuProcess proc; proc.setUser(auth_user); int needpw = proc.checkNeedPassword(); if (needpw < 0) { QString err = i18n("Su returned with an error!\n"); KMessageBox::error(0L, err); exit(1); } if (needpw == 0) { keep = 0; kdDebug() << "Don't need password!!\n"; } // Start the dialog QCString password; if (needpw) { KDEsuDialog *dlg = new KDEsuDialog(user, auth_user, keep && !terminal); dlg->addLine(i18n("Command:"), command); if ((priority != 50) || (scheduler != SuProcess::SchedNormal)) { QString prio; if (scheduler == SuProcess::SchedRealtime) prio += i18n("realtime: "); prio += QString("%1/100").arg(priority); dlg->addLine(i18n("Priority:"), prio); } int ret = dlg->exec(); if (ret == KDEsuDialog::Rejected) exit(0); if (ret == KDEsuDialog::AsUser) change_uid = false; password = dlg->password(); keep = dlg->keep(); delete dlg; } // Some events may need to be handled (like a button animation) app->processEvents(); if (!change_uid) return system(command); // Run command if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); return client.exec(command, user, options, env); } else { SuProcess proc; proc.setTerminal(terminal); proc.setErase(true); proc.setUser(user); if (!new_dcop) { proc.setXOnly(true); proc.setDCOPForwarding(true); proc.setEnvironment(env); } proc.setPriority(priority); proc.setScheduler(scheduler); proc.setCommand(command); return proc.exec(password); }}
dlg->addLine(i18n("Priority:"), prio); } int ret = dlg->exec();
dlg.addLine(i18n("Priority:"), prio); } int ret = dlg.exec();
int main(int argc, char *argv[]){ // FIXME: this can be considered a poor man's solution, as it's not // directly obvious to a gui user. :) // anyway, i vote against removing it even when we have a proper gui // implementation. -- ossi const char *duser = ::getenv("ADMIN_ACCOUNT"); if (duser && duser[0]) options[3].def = duser; KAboutData aboutData("kdesu", I18N_NOOP("KDE su"), Version, I18N_NOOP("Runs a program with elevated privileges."), KAboutData::License_Artistic, "Copyright (c) 1998-2000 Geert Jansen, Pietro Iglio"); aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"), "[email protected]", "http://www.stack.nl/~geertj/"); aboutData.addAuthor("Pietro Iglio", I18N_NOOP("Original author"), "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KApplication::disableAutoDcopRegistration(); KApplication *app = new KApplication; // Stop daemon and exit? if (args->isSet("s")) { KDEsuClient client; if (client.ping() == -1) { kdError(1206) << "Daemon not running -- nothing to stop\n"; exit(1); } if (client.stopServer() != -1) { kdDebug(1206) << "Daemon stopped\n"; exit(0); } kdError(1206) << "Could not stop daemon\n"; exit(1); } // Get target uid QCString user = args->getOption("u"); QCString auth_user = user; struct passwd *pw = getpwnam(user); if (pw == 0L) { kdError(1206) << "User " << user << " does not exist\n"; exit(1); } bool change_uid = (getuid() != pw->pw_uid); // If file is writeable, do not change uid QString file = QFile::decodeName(args->getOption("f")); if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); if (file.isEmpty()) { kdError(1206) << "Config file not found: " << file << "\n"; exit(1); } } QFileInfo fi(file); if (!fi.exists()) { kdError(1206) << "File does not exist: " << file << "\n"; exit(1); } change_uid = !fi.isWritable(); } // Get priority/scheduler QCString tmp = args->getOption("p"); bool ok; int priority = tmp.toInt(&ok); if (!ok || (priority < 0) || (priority > 100)) { KCmdLineArgs::usage(i18n("Illegal priority: %1").arg(tmp)); exit(1); } int scheduler = SuProcess::SchedNormal; if (args->isSet("r")) scheduler = SuProcess::SchedRealtime; if ((priority > 50) || (scheduler != SuProcess::SchedNormal)) { change_uid = true; auth_user = "root"; } // Get command if (args->isSet("c")) { command = args->getOption("c"); for (int i=0; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); } } else { if( args->count() == 0 ) { KCmdLineArgs::usage(i18n("No command specified!")); exit(1); } command = args->arg(0); for (int i=1; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); }}// CJM - Test lines remove when working// kdWarning(1206) << args->count();// kdWarning(1206) << command; // Don't change uid if we're don't need to. if (!change_uid) return system(command); // Check for daemon and start if necessary bool just_started = false; bool have_daemon = true; KDEsuClient client; if (!client.isServerSGID()) { kdWarning(1206) << "Daemon not safe (not sgid), not using it.\n"; have_daemon = false; } else if (client.ping() == -1) { if (client.startServer() == -1) { kdWarning(1206) << "Could not start daemon, reduced functionality.\n"; have_daemon = false; } just_started = true; } // Try to exec the command with kdesud. bool keep = !args->isSet("n") && have_daemon; bool terminal = args->isSet("t"); bool new_dcop = args->isSet("newdcop"); QCStringList env; QCString options; if (!new_dcop) { QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("tmp", "ksycoca")); env << ksycoca; options += "xf"; // X-only, dcop forwarding enabled. } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); if (client.exec(command, user, options, env) != -1) return 0; } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { kdError(1206) << "rlimit(): " << ERR << "\n"; exit(1); } // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Passwords"); int timeout = config->readNumEntry("Timeout", defTimeout); // Check if we need a password SuProcess proc; proc.setUser(auth_user); int needpw = proc.checkNeedPassword(); if (needpw < 0) { QString err = i18n("Su returned with an error!\n"); KMessageBox::error(0L, err); exit(1); } if (needpw == 0) { keep = 0; kdDebug() << "Don't need password!!\n"; } // Start the dialog QCString password; if (needpw) { KDEsuDialog *dlg = new KDEsuDialog(user, auth_user, keep && !terminal); dlg->addLine(i18n("Command:"), command); if ((priority != 50) || (scheduler != SuProcess::SchedNormal)) { QString prio; if (scheduler == SuProcess::SchedRealtime) prio += i18n("realtime: "); prio += QString("%1/100").arg(priority); dlg->addLine(i18n("Priority:"), prio); } int ret = dlg->exec(); if (ret == KDEsuDialog::Rejected) exit(0); if (ret == KDEsuDialog::AsUser) change_uid = false; password = dlg->password(); keep = dlg->keep(); delete dlg; } // Some events may need to be handled (like a button animation) app->processEvents(); if (!change_uid) return system(command); // Run command if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); return client.exec(command, user, options, env); } else { SuProcess proc; proc.setTerminal(terminal); proc.setErase(true); proc.setUser(user); if (!new_dcop) { proc.setXOnly(true); proc.setDCOPForwarding(true); proc.setEnvironment(env); } proc.setPriority(priority); proc.setScheduler(scheduler); proc.setCommand(command); return proc.exec(password); }}
password = dlg->password(); keep = dlg->keep(); delete dlg;
password = dlg.password(); keep = dlg.keep(); data.setSuspend( KStartupInfoData::No ); KStartupInfo::sendChange( id, data );
int main(int argc, char *argv[]){ // FIXME: this can be considered a poor man's solution, as it's not // directly obvious to a gui user. :) // anyway, i vote against removing it even when we have a proper gui // implementation. -- ossi const char *duser = ::getenv("ADMIN_ACCOUNT"); if (duser && duser[0]) options[3].def = duser; KAboutData aboutData("kdesu", I18N_NOOP("KDE su"), Version, I18N_NOOP("Runs a program with elevated privileges."), KAboutData::License_Artistic, "Copyright (c) 1998-2000 Geert Jansen, Pietro Iglio"); aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"), "[email protected]", "http://www.stack.nl/~geertj/"); aboutData.addAuthor("Pietro Iglio", I18N_NOOP("Original author"), "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KApplication::disableAutoDcopRegistration(); KApplication *app = new KApplication; // Stop daemon and exit? if (args->isSet("s")) { KDEsuClient client; if (client.ping() == -1) { kdError(1206) << "Daemon not running -- nothing to stop\n"; exit(1); } if (client.stopServer() != -1) { kdDebug(1206) << "Daemon stopped\n"; exit(0); } kdError(1206) << "Could not stop daemon\n"; exit(1); } // Get target uid QCString user = args->getOption("u"); QCString auth_user = user; struct passwd *pw = getpwnam(user); if (pw == 0L) { kdError(1206) << "User " << user << " does not exist\n"; exit(1); } bool change_uid = (getuid() != pw->pw_uid); // If file is writeable, do not change uid QString file = QFile::decodeName(args->getOption("f")); if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); if (file.isEmpty()) { kdError(1206) << "Config file not found: " << file << "\n"; exit(1); } } QFileInfo fi(file); if (!fi.exists()) { kdError(1206) << "File does not exist: " << file << "\n"; exit(1); } change_uid = !fi.isWritable(); } // Get priority/scheduler QCString tmp = args->getOption("p"); bool ok; int priority = tmp.toInt(&ok); if (!ok || (priority < 0) || (priority > 100)) { KCmdLineArgs::usage(i18n("Illegal priority: %1").arg(tmp)); exit(1); } int scheduler = SuProcess::SchedNormal; if (args->isSet("r")) scheduler = SuProcess::SchedRealtime; if ((priority > 50) || (scheduler != SuProcess::SchedNormal)) { change_uid = true; auth_user = "root"; } // Get command if (args->isSet("c")) { command = args->getOption("c"); for (int i=0; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); } } else { if( args->count() == 0 ) { KCmdLineArgs::usage(i18n("No command specified!")); exit(1); } command = args->arg(0); for (int i=1; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); }}// CJM - Test lines remove when working// kdWarning(1206) << args->count();// kdWarning(1206) << command; // Don't change uid if we're don't need to. if (!change_uid) return system(command); // Check for daemon and start if necessary bool just_started = false; bool have_daemon = true; KDEsuClient client; if (!client.isServerSGID()) { kdWarning(1206) << "Daemon not safe (not sgid), not using it.\n"; have_daemon = false; } else if (client.ping() == -1) { if (client.startServer() == -1) { kdWarning(1206) << "Could not start daemon, reduced functionality.\n"; have_daemon = false; } just_started = true; } // Try to exec the command with kdesud. bool keep = !args->isSet("n") && have_daemon; bool terminal = args->isSet("t"); bool new_dcop = args->isSet("newdcop"); QCStringList env; QCString options; if (!new_dcop) { QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("tmp", "ksycoca")); env << ksycoca; options += "xf"; // X-only, dcop forwarding enabled. } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); if (client.exec(command, user, options, env) != -1) return 0; } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { kdError(1206) << "rlimit(): " << ERR << "\n"; exit(1); } // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Passwords"); int timeout = config->readNumEntry("Timeout", defTimeout); // Check if we need a password SuProcess proc; proc.setUser(auth_user); int needpw = proc.checkNeedPassword(); if (needpw < 0) { QString err = i18n("Su returned with an error!\n"); KMessageBox::error(0L, err); exit(1); } if (needpw == 0) { keep = 0; kdDebug() << "Don't need password!!\n"; } // Start the dialog QCString password; if (needpw) { KDEsuDialog *dlg = new KDEsuDialog(user, auth_user, keep && !terminal); dlg->addLine(i18n("Command:"), command); if ((priority != 50) || (scheduler != SuProcess::SchedNormal)) { QString prio; if (scheduler == SuProcess::SchedRealtime) prio += i18n("realtime: "); prio += QString("%1/100").arg(priority); dlg->addLine(i18n("Priority:"), prio); } int ret = dlg->exec(); if (ret == KDEsuDialog::Rejected) exit(0); if (ret == KDEsuDialog::AsUser) change_uid = false; password = dlg->password(); keep = dlg->keep(); delete dlg; } // Some events may need to be handled (like a button animation) app->processEvents(); if (!change_uid) return system(command); // Run command if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); return client.exec(command, user, options, env); } else { SuProcess proc; proc.setTerminal(terminal); proc.setErase(true); proc.setUser(user); if (!new_dcop) { proc.setXOnly(true); proc.setDCOPForwarding(true); proc.setEnvironment(env); } proc.setPriority(priority); proc.setScheduler(scheduler); proc.setCommand(command); return proc.exec(password); }}
proc.setEnvironment(env); }
} proc.setEnvironment(env);
int main(int argc, char *argv[]){ // FIXME: this can be considered a poor man's solution, as it's not // directly obvious to a gui user. :) // anyway, i vote against removing it even when we have a proper gui // implementation. -- ossi const char *duser = ::getenv("ADMIN_ACCOUNT"); if (duser && duser[0]) options[3].def = duser; KAboutData aboutData("kdesu", I18N_NOOP("KDE su"), Version, I18N_NOOP("Runs a program with elevated privileges."), KAboutData::License_Artistic, "Copyright (c) 1998-2000 Geert Jansen, Pietro Iglio"); aboutData.addAuthor("Geert Jansen", I18N_NOOP("Maintainer"), "[email protected]", "http://www.stack.nl/~geertj/"); aboutData.addAuthor("Pietro Iglio", I18N_NOOP("Original author"), "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KApplication::disableAutoDcopRegistration(); KApplication *app = new KApplication; // Stop daemon and exit? if (args->isSet("s")) { KDEsuClient client; if (client.ping() == -1) { kdError(1206) << "Daemon not running -- nothing to stop\n"; exit(1); } if (client.stopServer() != -1) { kdDebug(1206) << "Daemon stopped\n"; exit(0); } kdError(1206) << "Could not stop daemon\n"; exit(1); } // Get target uid QCString user = args->getOption("u"); QCString auth_user = user; struct passwd *pw = getpwnam(user); if (pw == 0L) { kdError(1206) << "User " << user << " does not exist\n"; exit(1); } bool change_uid = (getuid() != pw->pw_uid); // If file is writeable, do not change uid QString file = QFile::decodeName(args->getOption("f")); if (change_uid && !file.isEmpty()) { if (file.at(0) != '/') { KStandardDirs dirs; dirs.addKDEDefaults(); file = dirs.findResource("config", file); if (file.isEmpty()) { kdError(1206) << "Config file not found: " << file << "\n"; exit(1); } } QFileInfo fi(file); if (!fi.exists()) { kdError(1206) << "File does not exist: " << file << "\n"; exit(1); } change_uid = !fi.isWritable(); } // Get priority/scheduler QCString tmp = args->getOption("p"); bool ok; int priority = tmp.toInt(&ok); if (!ok || (priority < 0) || (priority > 100)) { KCmdLineArgs::usage(i18n("Illegal priority: %1").arg(tmp)); exit(1); } int scheduler = SuProcess::SchedNormal; if (args->isSet("r")) scheduler = SuProcess::SchedRealtime; if ((priority > 50) || (scheduler != SuProcess::SchedNormal)) { change_uid = true; auth_user = "root"; } // Get command if (args->isSet("c")) { command = args->getOption("c"); for (int i=0; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); } } else { if( args->count() == 0 ) { KCmdLineArgs::usage(i18n("No command specified!")); exit(1); } command = args->arg(0); for (int i=1; i<args->count(); i++) { QString arg = QFile::decodeName(args->arg(i)); KRun::shellQuote(arg); command += " "; command += QFile::encodeName(arg); }}// CJM - Test lines remove when working// kdWarning(1206) << args->count();// kdWarning(1206) << command; // Don't change uid if we're don't need to. if (!change_uid) return system(command); // Check for daemon and start if necessary bool just_started = false; bool have_daemon = true; KDEsuClient client; if (!client.isServerSGID()) { kdWarning(1206) << "Daemon not safe (not sgid), not using it.\n"; have_daemon = false; } else if (client.ping() == -1) { if (client.startServer() == -1) { kdWarning(1206) << "Could not start daemon, reduced functionality.\n"; have_daemon = false; } just_started = true; } // Try to exec the command with kdesud. bool keep = !args->isSet("n") && have_daemon; bool terminal = args->isSet("t"); bool new_dcop = args->isSet("newdcop"); QCStringList env; QCString options; if (!new_dcop) { QCString ksycoca = "KDESYCOCA="+QFile::encodeName(locateLocal("tmp", "ksycoca")); env << ksycoca; options += "xf"; // X-only, dcop forwarding enabled. } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); if (client.exec(command, user, options, env) != -1) return 0; } // Set core dump size to 0 because we will have // root's password in memory. struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 0; if (setrlimit(RLIMIT_CORE, &rlim)) { kdError(1206) << "rlimit(): " << ERR << "\n"; exit(1); } // Read configuration KConfig *config = KGlobal::config(); config->setGroup("Passwords"); int timeout = config->readNumEntry("Timeout", defTimeout); // Check if we need a password SuProcess proc; proc.setUser(auth_user); int needpw = proc.checkNeedPassword(); if (needpw < 0) { QString err = i18n("Su returned with an error!\n"); KMessageBox::error(0L, err); exit(1); } if (needpw == 0) { keep = 0; kdDebug() << "Don't need password!!\n"; } // Start the dialog QCString password; if (needpw) { KDEsuDialog *dlg = new KDEsuDialog(user, auth_user, keep && !terminal); dlg->addLine(i18n("Command:"), command); if ((priority != 50) || (scheduler != SuProcess::SchedNormal)) { QString prio; if (scheduler == SuProcess::SchedRealtime) prio += i18n("realtime: "); prio += QString("%1/100").arg(priority); dlg->addLine(i18n("Priority:"), prio); } int ret = dlg->exec(); if (ret == KDEsuDialog::Rejected) exit(0); if (ret == KDEsuDialog::AsUser) change_uid = false; password = dlg->password(); keep = dlg->keep(); delete dlg; } // Some events may need to be handled (like a button animation) app->processEvents(); if (!change_uid) return system(command); // Run command if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); return client.exec(command, user, options, env); } else { SuProcess proc; proc.setTerminal(terminal); proc.setErase(true); proc.setUser(user); if (!new_dcop) { proc.setXOnly(true); proc.setDCOPForwarding(true); proc.setEnvironment(env); } proc.setPriority(priority); proc.setScheduler(scheduler); proc.setCommand(command); return proc.exec(password); }}
HelpCenterCom *helpcentercom = new HelpCenterCom;
HelpCenterCom *helpcentercom; helpcentercom = new HelpCenterCom;
int main(int argc, char *argv[]){ // error handler for man stuff Error.SetHandler( (void (*)(int, const char *))errorHandler ); // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); // init app KOMApplication app(argc, argv, "khelpcenter.bin"); HelpCenterCom *helpcentercom = new HelpCenterCom; app.boa()->impl_is_ready(CORBA::ImplementationDef::_nil()); kdebug(KDEBUG_INFO,1401,"KOM interface ready: IDL:KHelpCenter/HelpCenterCom:1.0"); app.exec(); return 0;}
aboutData->addAuthor("Daniel Molkentin", I18N_NOOP("Current Maintainer"), "[email protected]");
if (argv_0.right(11) == "kinfocenter") aboutData->addAuthor("Helge Deller", I18N_NOOP("Current Maintainer"), "[email protected]"); else aboutData->addAuthor("Daniel Molkentin", I18N_NOOP("Current Maintainer"), "[email protected]");
int main(int argc, char *argv[]){ KLocale::setMainCatalogue("kcontrol"); KAboutData aboutKControl( "kcontrol", I18N_NOOP("KDE Control Center"), KCONTROL_VERSION, I18N_NOOP("The KDE Control Center"), KAboutData::License_GPL, I18N_NOOP("(c) 1998-2002, The KDE Control Center Developers")); KAboutData aboutKInfoCenter( "kinfocenter", I18N_NOOP("KDE Info Center"), KCONTROL_VERSION, I18N_NOOP("The KDE Info Center"), KAboutData::License_GPL, I18N_NOOP("(c) 1998-2002, The KDE Control Center Developers")); QCString argv_0 = argv[0]; KAboutData *aboutData; if (argv_0.right(11) == "kinfocenter") { aboutData = &aboutKInfoCenter; KCGlobal::setIsInfoCenter(true); } else { aboutData = &aboutKControl; KCGlobal::setIsInfoCenter(false); } aboutData->addAuthor("Daniel Molkentin", I18N_NOOP("Current Maintainer"), "[email protected]"); aboutData->addAuthor("Matthias Hoelzer-Kluepfel",0, "[email protected]"); aboutData->addAuthor("Matthias Elter",0, "[email protected]"); aboutData->addAuthor("Matthias Ettrich",0, "[email protected]"); aboutData->addAuthor("Waldo Bastian",0, "[email protected]"); KCmdLineArgs::init( argc, argv, aboutData ); KUniqueApplication::addCmdLineOptions(); KCGlobal::init(); if (!KControlApp::start()) { kdDebug(1208) << "kcontrol is already running!\n" << endl; return (0); } KControlApp app; // show the whole stuff app.mainWidget()->show(); return app.exec();}
KGlobal::locale()->setLanguage(args->getOption("lang"));
int main(int _argc, char *_argv[]){ KAboutData aboutData( "kcmshell", I18N_NOOP("KDE Control Module"), KCONTROL_VERSION, I18N_NOOP("A tool to start single KDE control modules"), KAboutData::License_GPL, "(c) 1999-2001, The KDE Developers"); aboutData.addAuthor("Daniel Molkentin", I18N_NOOP("Current Maintainer"), "[email protected]"); aboutData.addAuthor("Matthias Hoelzer-Kluepfel",0, "[email protected]"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); aboutData.addAuthor("Matthias Ettrich",0, "[email protected]"); KCmdLineArgs::init(_argc, _argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KLocale::setMainCatalogue("kcontrol"); kcmApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KGlobal::iconLoader()->addAppDir( "kcontrol" ); if (args->isSet("list")) { QStringList files; KGlobal::dirs()->findAllResources("apps", KCGlobal::baseGroup() + "*.desktop", true, true, files); QStringList modules; QStringList descriptions; uint maxwidth = 0; for (QStringList::ConstIterator it = files.begin(); it != files.end(); it++) { if (KDesktopFile::isDesktopFile(*it)) { KDesktopFile file(*it, true); if (file.readEntry("Hidden") == "true") continue; QString module = *it; if (module.startsWith(KCGlobal::baseGroup())) module = module.mid(KCGlobal::baseGroup().length()); if (module.right(8) == ".desktop") module.truncate(module.length() - 8); modules.append(module); if (module.length() > maxwidth) maxwidth = module.length(); descriptions.append(QString("%2 (%3)").arg(file.readName()).arg(file.readComment())); } } QByteArray vl; vl.fill(' ', 80); QString verylong = vl; for (uint i = 0; i < modules.count(); i++) { fprintf(stdout, "%s%s - %s\n", (*modules.at(i)).local8Bit().data(), verylong.left(maxwidth - (*modules.at(i)).length()).local8Bit().data(), (*descriptions.at(i)).local8Bit().data()); }#if defined(QT_THREAD_SUPPORT) app.unlock();#endif return 0; } if (args->count() < 1) { args->usage(); return -1; } if (args->count() == 1) { app.setDCOPName(args->arg(0)); if (app.isRunning()) { app.waitForExit(); return 0; } QString path = locateModule(args->arg(0)); if (path.isEmpty()) {#if defined(QT_THREAD_SUPPORT) app.unlock();#endif return 0; } // load the module ModuleInfo info(path); KCModule *module = ModuleLoader::loadModule(info, false); if (module) { // create the dialog QCString embedStr = args->getOption("embed"); bool embed = false; int id = -1; if (!embedStr.isEmpty()) id = embedStr.toInt(&embed); if (!args->isSet("silent")) { if (!embed) { KCDialog * dlg = new KCDialog(module, module->buttons(), info.docPath(), 0, 0, true ); dlg->setCaption(info.name()); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // run the dialog dlg->exec(); delete dlg; } // if we are going to be embedded, embed else { QWidget *dlg = new ProxyWidget(module, info.name(), "kcmshell", false); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); QXEmbed::embedClientIntoWindow(dlg, id); kapp->exec(); delete dlg; } } else { //Silent kapp->exec(); } ModuleLoader::unloadModule(info); return 0; } KMessageBox::detailedError(0, i18n("There was an error loading the module."),i18n("<qt><p>The diagnostics is:<br>%1" "<p>Possible reasons:</p><ul><li>An error occurred during your last " "KDE upgrade leaving an orphaned control module<li>You have old third party " "modules lying around.</ul><p>Check these points carefully and try to remove " "the module mentioned in the error message. If this fails, consider contacting " "your distributor or packager.</p></qt>") .arg(KLibLoader::self()->lastErrorMessage())); return 0; } // multiple control modules QStringList modules; for (int i = 0; i < args->count(); i++) { QString path = locateModule(args->arg(i)); if(!path.isEmpty()) modules.append(path); } if (modules.count() < 1) return -1; // create the dialog KExtendedCDialog * dlg = new KExtendedCDialog(0, 0, true); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // add modules for (QStringList::ConstIterator it = modules.begin(); it != modules.end(); ++it) dlg->addModule(*it, false); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) { // NOTE: This has to be changed for QT 3.0. See above! QXEmbed::embedClientIntoWindow(dlg, id); delete dlg; return 0; } } // run the dialog dlg->exec(); delete dlg; return 0;}
debug( "kio_http : Starting");
int main( int argc, char **argv ){ signal(SIGCHLD, sigchld_handler); signal(SIGSEGV, sigsegv_handler); debug( "kio_http : Starting"); Connection parent( 0, 1 ); HTTPProtocol http( &parent ); http.dispatchLoop(); debug( "kio_http : Done" );}
debug( "kio_http : Done" );
int main( int argc, char **argv ){ signal(SIGCHLD, sigchld_handler); signal(SIGSEGV, sigsegv_handler); debug( "kio_http : Starting"); Connection parent( 0, 1 ); HTTPProtocol http( &parent ); http.dispatchLoop(); debug( "kio_http : Done" );}
HELPCENTER_VERSION, description, KAboutData::GPL,
HELPCENTER_VERSION, description, KAboutData::License_GPL,
int main(int argc, char *argv[]){ KAboutData aboutData( "khelpcenter", I18N_NOOP("KDE HelpCenter"), HELPCENTER_VERSION, description, KAboutData::GPL, "(c) 1999-2000, Matthias Elter"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); KCmdLineArgs::init( argc, argv, &aboutData );// KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KApplication app( false, false ); // no GUI in this process app.dcopClient()->attach(); // we want to get applicationRegistered app.dcopClient()->setNotifications( true ); Listener listener; QObject::connect( app.dcopClient(), SIGNAL( applicationRegistered( const QCString& ) ), &listener, SLOT( slotAppRegistered( const QCString & ) ) ); system( "konqueror --silent &" ); app.exec();}
KCDialog dlg(module, info.docPath(), 0, 0, true);
KCDialog dlg(module, module->buttons(), info.docPath(), 0, 0, true);
int main(int _argc, char *_argv[]){ KCmdLineArgs::init( _argc, _argv, "kcmshell", I18N_NOOP("A tool to start single kcontrol modules"), "2.0pre" ); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KLocale::setMainCatalogue("kcontrol"); KApplication app; // It has to be unset, if not it will break modules like kcmlocale KLocale::setMainCatalogue(0); KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); if (args->isSet("list")) { QStringList files; KGlobal::dirs()->findAllResources("apps", "Settings/*.desktop", true, true, files); QStringList modules; QStringList descriptions; uint maxwidth = 0; for (QStringList::ConstIterator it = files.begin(); it != files.end(); it++) { if (KDesktopFile::isDesktopFile(*it)) { KDesktopFile file(*it, true); QString module = *it; if (module.left(9) == "Settings/") module = module.mid(9); if (module.right(8) == ".desktop") module.truncate(module.length() - 8); modules.append(module); if (module.length() > maxwidth) maxwidth = module.length(); descriptions.append(QString("%2 (%3)").arg(file.readName()).arg(file.readComment())); } } QByteArray vl; vl.fill(' ', 80); QString verylong = vl; for (uint i = 0; i < modules.count(); i++) { cout << (*modules.at(i)).latin1(); cout << verylong.left(maxwidth - (*modules.at(i)).length()); cout << " - "; cout << (*descriptions.at(i)).local8Bit(); cout << endl; } return 0; } if (args->count() != 1) { args->usage(); return -1; } // locate the desktop file QStringList files; if (args->arg(0)[0] == '/') files.append(args->arg(0)); else files = KGlobal::dirs()-> findAllResources("apps", QString("Settings/%1.desktop").arg(args->arg(0)), true); // check the matches if (files.count() > 1) cerr << i18n("Module name not unique. Taking the first match.") << endl; if (files.count() <= 0) { cerr << i18n("Module %1 not found!").arg(args->arg(0)) << endl; return -1; } args->clear(); // load the module ModuleInfo info(files[0]); KCModule *module = ModuleLoader::module(info); if (module) { // create the dialog KCDialog dlg(module, info.docPath(), 0, 0, true); dlg.setCaption(info.name()); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg.setAcceptDrops(true); // run the dialog return dlg.exec(); } return 0;}
int pid = getpid();
int main(int oargc, char **oargv) { //cerr << "fakesyn starting" << endl; int argc; char **argv; parse_config_options(oargc, oargv, argc, argv); int start = 0; // build new argc+argv for fuse typedef char* pchar; int nargc = 0; char **nargv = new pchar[argc]; nargv[nargc++] = argv[0]; list<int> syn_modes; list<int> syn_iargs; list<string> syn_sargs; int mkfs = 0; for (int i=1; i<argc; i++) { cout << "asdf" << endl; if (strcmp(argv[i], "--fastmkfs") == 0) { mkfs = MDS_MKFS_FAST; } else if (strcmp(argv[i], "--fullmkfs") == 0) { mkfs = MDS_MKFS_FULL; } else if (strcmp(argv[i],"--syn") == 0) { ++i; if (strcmp(argv[i],"writefile") == 0) { syn_modes.push_back( SYNCLIENT_MODE_WRITEFILE ); syn_iargs.push_back( atoi(argv[++i]) ); syn_iargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"readfile") == 0) { syn_modes.push_back( SYNCLIENT_MODE_READFILE ); syn_iargs.push_back( atoi(argv[++i]) ); syn_iargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"makedirs") == 0) { syn_modes.push_back( SYNCLIENT_MODE_MAKEDIRS ); syn_iargs.push_back( atoi(argv[++i]) ); syn_iargs.push_back( atoi(argv[++i]) ); syn_iargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"fullwalk") == 0) { syn_modes.push_back( SYNCLIENT_MODE_FULLWALK ); //syn_sargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"randomwalk") == 0) { syn_modes.push_back( SYNCLIENT_MODE_RANDOMWALK ); syn_iargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"trace_include") == 0) { syn_modes.push_back( SYNCLIENT_MODE_TRACEINCLUDE ); syn_iargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"trace_lib") == 0) { syn_modes.push_back( SYNCLIENT_MODE_TRACELIB ); syn_iargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"trace_openssh") == 0) { syn_modes.push_back( SYNCLIENT_MODE_TRACEOPENSSH ); syn_iargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"trace_opensshlib") == 0) { syn_modes.push_back( SYNCLIENT_MODE_TRACEOPENSSHLIB ); syn_iargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"trace") == 0) { syn_modes.push_back( SYNCLIENT_MODE_TRACE ); syn_sargs.push_back( argv[++i] ); syn_iargs.push_back( atoi(argv[++i]) ); } else if (strcmp(argv[i],"until") == 0) { syn_modes.push_back( SYNCLIENT_MODE_UNTIL ); syn_iargs.push_back( atoi(argv[++i]) ); } else { cerr << "unknown syn mode " << argv[i] << endl; return -1; } } else { // unknown arg, pass it on. nargv[nargc++] = argv[i]; } } MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD); char hostname[100]; gethostname(hostname,100); int pid = getpid(); // create mds MDS *mds[NUMMDS]; for (int i=0; i<NUMMDS; i++) { //cerr << "mds" << i << " on rank " << myrank << " " << hostname << "." << pid << endl; mds[i] = new MDS(mdc, i, new FakeMessenger(MSG_ADDR_MDS(i))); start++; } // create osd OSD *osd[NUMOSD]; for (int i=0; i<NUMOSD; i++) { //cerr << "osd" << i << " on rank " << myrank << " " << hostname << "." << pid << endl; osd[i] = new OSD(i, new FakeMessenger(MSG_ADDR_OSD(i))); start++; } // create client Client *client[NUMCLIENT]; SyntheticClient *syn[NUMCLIENT]; for (int i=0; i<NUMCLIENT; i++) { //cerr << "client" << i << " on rank " << myrank << " " << hostname << "." << pid << endl; client[i] = new Client(mdc, i, new FakeMessenger(MSG_ADDR_CLIENT(i))); start++; } // start message loop fakemessenger_startthread(); // init for (int i=0; i<NUMMDS; i++) { mds[i]->init(); } for (int i=0; i<NUMOSD; i++) { osd[i]->init(); } // create client for (int i=0; i<NUMCLIENT; i++) { client[i]->init(); // use my argc, argv (make sure you pass a mount point!) //cout << "mounting" << endl; client[i]->mount(mkfs); //cout << "starting synthetic client " << endl; syn[i] = new SyntheticClient(client[i]); syn[i]->modes = syn_modes; syn[i]->sargs = syn_sargs; syn[i]->iargs = syn_iargs; syn[i]->start_thread(); } for (int i=0; i<NUMCLIENT; i++) { cout << "waiting for synthetic client " << i << " to finish" << endl; syn[i]->join_thread(); delete syn[i]; client[i]->unmount(); //cout << "unmounted" << endl; client[i]->shutdown(); } // wait for it to finish fakemessenger_wait(); // cleanup for (int i=0; i<NUMMDS; i++) { delete mds[i]; } for (int i=0; i<NUMOSD; i++) { delete osd[i]; } for (int i=0; i<NUMCLIENT; i++) { delete client[i]; } delete mdc; free(argv); delete[] nargv; cout << "fakesyn done" << endl; return 0;}
qDebug( "kio_smb : main 3");
int main( int argc, char **argv ){ signal(SIGCHLD, sigchld_handler); signal(SIGSEGV, sigsegv_handler); qDebug( "kio_smb : Starting"); QtApp = new QApplication( argc, argv ); Connection parent( 0, 1 ); SmbProtocol smb( &parent ); smb.dispatchLoop(); qDebug( "kio_smb : Done" );}
QCoreApplication::setOrganizationName("QuantumGIS"); QCoreApplication::setOrganizationDomain("qgis.org"); QCoreApplication::setApplicationName("qgis");
int main(int argc, char *argv[]){ // Set up the custom qWarning/qDebug custom handler qInstallMsgHandler( myMessageOutput ); ///////////////////////////////////////////////////////////////// // Command line options 'behaviour' flag setup //////////////////////////////////////////////////////////////// // // Parse the command line arguments, looking to see if the user has asked for any // special behaviours. Any remaining non command arguments will be kept aside to // be passed as a list of layers and / or a project that should be loaded. // // This behaviour is used to load the app, snapshot the map, // save the image to disk and then exit QString mySnapshotFileName=""; // This behaviour will set initial extent of map canvas QString myInitialExtent=""; // This behaviour will allow you to force the use of a translation file // which is useful for testing QString myTranslationCode="";#ifndef WIN32 if ( !bundleclicked(argc, argv) ) { //////////////////////////////////////////////////////////////// // USe the GNU Getopts utility to parse cli arguments // Invokes ctor `GetOpt (int argc, char **argv, char *optstring);' /////////////////////////////////////////////////////////////// int optionChar; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"snapshot", required_argument, 0, 's'}, {"lang", required_argument, 0, 'l'}, {"project", required_argument, 0, 'p'}, {"extent", required_argument, 0, 'e'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "slpe", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 's': mySnapshotFileName = QDir::convertSeparators(QFileInfo(QFile::decodeName(optarg)).absFilePath()); break; case 'l': myTranslationCode = optarg; break; case 'p': myProjectFileName = QDir::convertSeparators(QFileInfo(QFile::decodeName(optarg)).absFilePath()); break; case 'e': myInitialExtent = optarg; break; case 'h': case '?': usage( argv[0] ); return 2; // XXX need standard exit codes break; default: std::cerr << argv[0] << ": getopt returned character code " << optionChar << "\n"; return 1; // XXX need standard exit codes } } // Add any remaining args to the file list - we will attempt to load them // as layers in the map view further down....#ifdef QGISDEBUG std::cout << "Files specified on command line: " << optind << std::endl;#endif if (optind < argc) { while (optind < argc) {#ifdef QGISDEBUG int idx = optind; std::cout << idx << ": " << argv[idx] << std::endl;#endif myFileList.append(QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[optind++])).absFilePath())); } } }#endif //WIN32 ///////////////////////////////////////////////////////////////////// // Now we have the handlers for the different behaviours... //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// // Initialise the application and the translation stuff /////////////////////////////////////////////////////////////////////#ifdef Q_WS_X11 bool myUseGuiFlag = getenv( "DISPLAY" ) != 0;#else bool myUseGuiFlag = TRUE;#endif if (!myUseGuiFlag) { std::cerr << "QGIS starting in non-interactive mode not supported.\n You are seeing this message most likely because you have no DISPLAY environment variable set." << std::endl; exit(1); //exit for now until a version of qgis is capabable of running non interactive } QApplication a(argc, argv, myUseGuiFlag );#ifdef Q_OS_MACX // Install OpenDocuments AppleEvent handler after application object is initialized // but before any other event handling (including dialogs or splash screens) occurs. // If an OpenDocuments event has been created before the application was launched, // it must be handled before some other event handler runs and dismisses it as unknown. // If run at startup, the handler will set either or both of myProjectFileName and myFileList. AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, openDocumentsAEHandler, 0, false);#endif // Check to see if qgis was started from the source directory. // This is done by looking for Makefile in the directory where qgis was // started from. If running from the src directory, exit gracefully // Get the application path. This method is required to support qt 3.1.2 // which does not support the applicationFilePath and applicationDirPath // functions. We assume that OS X and Win32 systems will be using at least // Qt 3.2 and therefore support the required functions.#if defined(Q_OS_MACX) || defined(WIN32) QString appPath = qApp->applicationFilePath(); QString appDir = qApp->applicationDirPath(); QString testFile = "Makefile";#else QString appPath = argv[0]; QString appDir = appPath.left(appPath.findRev("/")); QString testFile = "lt-qgis";#endif if(appPath.contains("/src/")) { // check to see if configure is present in the directory QFileInfo fi(appDir + "/" + testFile); if(fi.exists()) { QMessageBox::critical(0,"QGIS Not Installed", "You appear to be running QGIS from the source directory.\n" "You must install QGIS using make install and run it from the " "installed directory."); exit(1); } } // a.setFont(QFont("helvetica", 11));#if defined(Q_OS_MACX) || defined(WIN32) QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";#endif QString i18nPath = QString(PKGDATAPATH) + "/i18n"; if (myTranslationCode.isEmpty()) { myTranslationCode = QTextCodec::locale(); }#ifdef QGISDEBUG std::cout << "Setting translation to " << i18nPath.toLocal8Bit().data() << "/qgis_" << myTranslationCode.toLocal8Bit().data() << std::endl;#endif /* Translation file for Qt. * The strings from the QMenuBar context section are used by Qt/Mac to shift * the About, Preferences and Quit items to the Mac Application menu. * These items must be translated identically in both qt_ and qgis_ files. */ QTranslator qttor(0); if (qttor.load(QString("qt_") + myTranslationCode, i18nPath)) { a.installTranslator(&qttor); } /* Translation file for QGIS. */ QTranslator qgistor(0); if (qgistor.load(QString("qgis_") + myTranslationCode, i18nPath)) { a.installTranslator(&qgistor); } /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp; // "QgisApp" used to find canonical instance qgis->setName( "QgisApp" ); a.setMainWidget(qgis); ///////////////////////////////////////////////////////////////////// // If no --project was specified, parse the args to look for a // // .qgs file and set myProjectFileName to it. This allows loading // // of a project file by clicking on it in various desktop managers // // where an appropriate mime-type has been set up. // ///////////////////////////////////////////////////////////////////// if(myProjectFileName.isEmpty()) { // check for a .qgs for(int i = 0; i < argc; i++) { QString arg = QDir::convertSeparators(QFileInfo(QFile::decodeName(argv[i])).absFilePath()); if(arg.contains(".qgs")) { myProjectFileName = arg; break; } } } ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if( ! myProjectFileName.isEmpty() ) { qgis->openProject(myProjectFileName); } ///////////////////////////////////////////////////////////////////// // autoload any filenames that were passed in on the command line /////////////////////////////////////////////////////////////////////#ifdef QGISDEBUG std::cout << "Number of files in myFileList: " << myFileList.count() << std::endl;#endif for ( QStringList::Iterator myIterator = myFileList.begin(); myIterator != myFileList.end(); ++myIterator ) {#ifdef QGISDEBUG std::cout << "Trying to load file : " << (*myIterator).toLocal8Bit().data() << std::endl;#endif QString myLayerName = *myIterator; // don't load anything with a .qgs extension - these are project files if(!myLayerName.contains(".qgs")) { qgis->openLayer(myLayerName); } } ///////////////////////////////////////////////////////////////////// // Set initial extent if requested ///////////////////////////////////////////////////////////////////// if ( ! myInitialExtent.isEmpty() ) { double coords[4]; int pos, posOld = 0; bool ok; // XXX is it necessary to switch to "C" locale? // parse values from string // extent is defined by string "xmin,ymin,xmax,ymax" for (int i = 0; i < 3; i++) { // find comma and get coordinate pos = myInitialExtent.find(',', posOld); if (pos == -1) { ok = false; break; } coords[i] = QString( myInitialExtent.mid(posOld, pos - posOld) ).toDouble(&ok); if (!ok) break; posOld = pos+1; } // parse last coordinate if (ok) coords[3] = QString( myInitialExtent.mid(posOld) ).toDouble(&ok); if (!ok) std::cout << "Error while parsing initial extent!" << std::endl; else { // set extent from parsed values QgsRect rect(coords[0],coords[1],coords[2],coords[3]); qgis->setExtent(rect); } } ///////////////////////////////////////////////////////////////////// // Take a snapshot of the map view then exit if snapshot mode requested ///////////////////////////////////////////////////////////////////// if(mySnapshotFileName!="") { /*You must have at least one paintEvent() delivered for the window to be rendered properly. It looks like you don't run the event loop in non-interactive mode, so the event is never occuring. To achieve this without runing the event loop: show the window, then call qApp->processEvents(), grab the pixmap, save it, hide the window and exit. */ //qgis->show(); a.processEvents(); QPixmap * myQPixmap = new QPixmap(800,600); myQPixmap->fill(); qgis->saveMapAsImage(mySnapshotFileName,myQPixmap); a.processEvents(); qgis->hide(); return 1; } ///////////////////////////////////////////////////////////////////// // Continue on to interactive gui... ///////////////////////////////////////////////////////////////////// qgis->show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec();}
int i; QString url, initDoc; for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } initDoc = argv[i]; } if ( initDoc.isEmpty() ) { initDoc = "file:"; initDoc += kapp->kde_htmldir().copy(); initDoc += "/default/khelpcenter/main.html"; } url = initDoc; if ( !strchr( url, ':' ) ) { if ( initDoc[0] == '.' || initDoc[0] != '/' ) { QFileInfo fi( initDoc ); initDoc = fi.absFilePath(); } url = "file:"; url += initDoc; }
int main(int argc, char *argv[]){ int i; QString url, initDoc; // pase command line parameters for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { // skip -caption, -icon, -miniicon if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } initDoc = argv[i]; } if ( initDoc.isEmpty() ) // no url parameter...use main.html { initDoc = "file:"; initDoc += kapp->kde_htmldir().copy(); initDoc += "/default/khelpcenter/main.html"; } url = initDoc; if ( !strchr( url, ':' ) ) { if ( initDoc[0] == '.' || initDoc[0] != '/' ) { QFileInfo fi( initDoc ); initDoc = fi.absFilePath(); } url = "file:"; url += initDoc; } // error handler for info and man stuff Error.SetHandler( (void (*)(int, const char *))errorHandler ); // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); // init app KApplication app(argc, argv, "khelpcenter"); HelpCenter *toplevel; if (app.isRestored()) { int n = 1; while ( KTMainWindow::canBeRestored( n ) ) { toplevel = new HelpCenter; toplevel->restore( n ); n++; } return app.exec(); } else { toplevel = new HelpCenter; app.setMainWidget(toplevel); app.setTopWidget(toplevel); toplevel->openURL(url); toplevel->show(); return app.exec(); }}
KApplication app(argc, argv, "khelpcenter");
KOMApplication app(argc, argv, "khelpcenter.bin");
int main(int argc, char *argv[]){ int i; QString url, initDoc; // pase command line parameters for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { // skip -caption, -icon, -miniicon if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } initDoc = argv[i]; } if ( initDoc.isEmpty() ) // no url parameter...use main.html { initDoc = "file:"; initDoc += kapp->kde_htmldir().copy(); initDoc += "/default/khelpcenter/main.html"; } url = initDoc; if ( !strchr( url, ':' ) ) { if ( initDoc[0] == '.' || initDoc[0] != '/' ) { QFileInfo fi( initDoc ); initDoc = fi.absFilePath(); } url = "file:"; url += initDoc; } // error handler for info and man stuff Error.SetHandler( (void (*)(int, const char *))errorHandler ); // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); // init app KApplication app(argc, argv, "khelpcenter"); HelpCenter *toplevel; if (app.isRestored()) { int n = 1; while ( KTMainWindow::canBeRestored( n ) ) { toplevel = new HelpCenter; toplevel->restore( n ); n++; } return app.exec(); } else { toplevel = new HelpCenter; app.setMainWidget(toplevel); app.setTopWidget(toplevel); toplevel->openURL(url); toplevel->show(); return app.exec(); }}
HelpCenter *toplevel;
int main(int argc, char *argv[]){ int i; QString url, initDoc; // pase command line parameters for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { // skip -caption, -icon, -miniicon if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } initDoc = argv[i]; } if ( initDoc.isEmpty() ) // no url parameter...use main.html { initDoc = "file:"; initDoc += kapp->kde_htmldir().copy(); initDoc += "/default/khelpcenter/main.html"; } url = initDoc; if ( !strchr( url, ':' ) ) { if ( initDoc[0] == '.' || initDoc[0] != '/' ) { QFileInfo fi( initDoc ); initDoc = fi.absFilePath(); } url = "file:"; url += initDoc; } // error handler for info and man stuff Error.SetHandler( (void (*)(int, const char *))errorHandler ); // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); // init app KApplication app(argc, argv, "khelpcenter"); HelpCenter *toplevel; if (app.isRestored()) { int n = 1; while ( KTMainWindow::canBeRestored( n ) ) { toplevel = new HelpCenter; toplevel->restore( n ); n++; } return app.exec(); } else { toplevel = new HelpCenter; app.setMainWidget(toplevel); app.setTopWidget(toplevel); toplevel->openURL(url); toplevel->show(); return app.exec(); }}
if (app.isRestored()) { int n = 1; while ( KTMainWindow::canBeRestored( n ) ) { toplevel = new HelpCenter; toplevel->restore( n ); n++; } return app.exec(); } else { toplevel = new HelpCenter;
HelpCenterCom *helpcentercom = new HelpCenterCom(); app.boa()->impl_is_ready( CORBA::ImplementationDef::_nil() );
int main(int argc, char *argv[]){ int i; QString url, initDoc; // pase command line parameters for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { // skip -caption, -icon, -miniicon if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } initDoc = argv[i]; } if ( initDoc.isEmpty() ) // no url parameter...use main.html { initDoc = "file:"; initDoc += kapp->kde_htmldir().copy(); initDoc += "/default/khelpcenter/main.html"; } url = initDoc; if ( !strchr( url, ':' ) ) { if ( initDoc[0] == '.' || initDoc[0] != '/' ) { QFileInfo fi( initDoc ); initDoc = fi.absFilePath(); } url = "file:"; url += initDoc; } // error handler for info and man stuff Error.SetHandler( (void (*)(int, const char *))errorHandler ); // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); // init app KApplication app(argc, argv, "khelpcenter"); HelpCenter *toplevel; if (app.isRestored()) { int n = 1; while ( KTMainWindow::canBeRestored( n ) ) { toplevel = new HelpCenter; toplevel->restore( n ); n++; } return app.exec(); } else { toplevel = new HelpCenter; app.setMainWidget(toplevel); app.setTopWidget(toplevel); toplevel->openURL(url); toplevel->show(); return app.exec(); }}
app.setMainWidget(toplevel); app.setTopWidget(toplevel); toplevel->openURL(url); toplevel->show(); return app.exec(); }
app.exec(); return 0;
int main(int argc, char *argv[]){ int i; QString url, initDoc; // pase command line parameters for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { // skip -caption, -icon, -miniicon if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } initDoc = argv[i]; } if ( initDoc.isEmpty() ) // no url parameter...use main.html { initDoc = "file:"; initDoc += kapp->kde_htmldir().copy(); initDoc += "/default/khelpcenter/main.html"; } url = initDoc; if ( !strchr( url, ':' ) ) { if ( initDoc[0] == '.' || initDoc[0] != '/' ) { QFileInfo fi( initDoc ); initDoc = fi.absFilePath(); } url = "file:"; url += initDoc; } // error handler for info and man stuff Error.SetHandler( (void (*)(int, const char *))errorHandler ); // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); // init app KApplication app(argc, argv, "khelpcenter"); HelpCenter *toplevel; if (app.isRestored()) { int n = 1; while ( KTMainWindow::canBeRestored( n ) ) { toplevel = new HelpCenter; toplevel->restore( n ); n++; } return app.exec(); } else { toplevel = new HelpCenter; app.setMainWidget(toplevel); app.setTopWidget(toplevel); toplevel->openURL(url); toplevel->show(); return app.exec(); }}
KOMApplication app( argc, argv, "khelpcenterd.bin");
KOMApplication app(argc, argv, "KDE HelpCenter");
int main(int argc, char *argv[]){ // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); // init app KOMApplication app( argc, argv, "khelpcenterd.bin"); KOMAutoLoader<HelpWindowFactory_Impl> HelpWindowFactoryLoader("IDL:KHelpCenter/HelpWindowFactory:1.0" , "KHelpCenter"); app.exec(); return 0;}
QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter");
KGlobal::dirs()->addResourceType("plugins", KStandardDirs::kde_default("data") + "khelpcenter/plugins");
int main(int argc, char *argv[]){ bool standalone = false; HelpCenter *hc; // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); for (int i=0; i< argc; i++) { if (strcmp(argv[i], "--standalone") == 0) standalone = true; } if (standalone) { KApplication app(argc, argv, "KDE HelpCenter"); hc = new HelpCenter; QString _url = "file:"; _url += kapp->kde_htmldir().copy(); _url += "/default/khelpcenter/main.html"; hc->show(); hc->openURL(_url, true); int rv = app.exec(); if (hc) delete hc; return rv; } else { // init KOM server app KOMApplication app(argc, argv, "KDE HelpCenter"); KOMAutoLoader<HelpWindowFactory_Impl> HelpWindowFactoryLoader("IDL:KHelpCenter/HelpWindowFactory:1.0" , "KHelpCenter"); app.exec(); return 0; } }
QString _url = "file:"; _url += kapp->kde_htmldir().copy(); _url += "/default/khelpcenter/main.html";
QString _url = "file:" + locate("html", "default/khelpcenter/main.html");
int main(int argc, char *argv[]){ bool standalone = false; HelpCenter *hc; // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); for (int i=0; i< argc; i++) { if (strcmp(argv[i], "--standalone") == 0) standalone = true; } if (standalone) { KApplication app(argc, argv, "KDE HelpCenter"); hc = new HelpCenter; QString _url = "file:"; _url += kapp->kde_htmldir().copy(); _url += "/default/khelpcenter/main.html"; hc->show(); hc->openURL(_url, true); int rv = app.exec(); if (hc) delete hc; return rv; } else { // init KOM server app KOMApplication app(argc, argv, "KDE HelpCenter"); KOMAutoLoader<HelpWindowFactory_Impl> HelpWindowFactoryLoader("IDL:KHelpCenter/HelpWindowFactory:1.0" , "KHelpCenter"); app.exec(); return 0; } }
QXEmbed::embedClientIntoWindow(dlg, id);
{ QXEmbed::embedClientIntoWindow(dlg, id); delete dlg; ModuleLoader::unloadModule(info); return 0; }
int main(int _argc, char *_argv[]){ KAboutData aboutData( "kcmshell", I18N_NOOP("KDE Control Module"), "2.0", I18N_NOOP("A tool to start single KDE control modules"), KAboutData::License_GPL, "(c) 1999-2000, The KDE Developers"); aboutData.addAuthor("Matthias Hoelzer-Kluepfel",0, "[email protected]"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); KCmdLineArgs::init(_argc, _argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KLocale::setMainCatalogue("kcontrol"); kcmApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KGlobal::iconLoader()->addAppDir( "kcontrol" ); if (args->isSet("list")) { QStringList files; KGlobal::dirs()->findAllResources("apps", KCGlobal::baseGroup() + "*.desktop", true, true, files); QStringList modules; QStringList descriptions; uint maxwidth = 0; for (QStringList::ConstIterator it = files.begin(); it != files.end(); it++) { if (KDesktopFile::isDesktopFile(*it)) { KDesktopFile file(*it, true); QString module = *it; if (module.startsWith(KCGlobal::baseGroup())) module = module.mid(KCGlobal::baseGroup().length()); if (module.right(8) == ".desktop") module.truncate(module.length() - 8); modules.append(module); if (module.length() > maxwidth) maxwidth = module.length(); descriptions.append(QString("%2 (%3)").arg(file.readName()).arg(file.readComment())); } } QByteArray vl; vl.fill(' ', 80); QString verylong = vl; for (uint i = 0; i < modules.count(); i++) { fprintf(stdout, "%s%s - %s\n", (*modules.at(i)).local8Bit().data(), verylong.left(maxwidth - (*modules.at(i)).length()).local8Bit().data(), (*descriptions.at(i)).local8Bit().data()); } return 0; } if (args->count() < 1) { args->usage(); return -1; } if (args->count() == 1) { app.setDCOPName(args->arg(0)); if (app.isRunning()) { app.waitForExit(); return 0; } QString path = locateModule(args->arg(0)); if (path.isEmpty()) return 0; // load the module ModuleInfo info(path); KCModule *module = ModuleLoader::loadModule(info, false); if (module) { // create the dialog KCDialog * dlg = new KCDialog(module, module->buttons(), info.docPath(), 0, 0, true); dlg->setCaption(info.name()); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) QXEmbed::embedClientIntoWindow(dlg, id); } // run the dialog int ret = dlg->exec(); delete dlg; ModuleLoader::unloadModule(info); return ret; } KMessageBox::error(0, i18n("There was an error loading the module.\nThe diagnostics is:\n%1") .arg(KLibLoader::self()->lastErrorMessage())); return 0; } // multiple control modules QStringList modules; for (int i = 0; i < args->count(); i++) { QString path = locateModule(args->arg(i)); if(!path.isEmpty()) modules.append(path); } if (modules.count() < 1) return -1; // create the dialog KExtendedCDialog * dlg = new KExtendedCDialog(0, 0, true); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // add modules for (QStringList::ConstIterator it = modules.begin(); it != modules.end(); ++it) dlg->addModule(*it, false); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) QXEmbed::embedClientIntoWindow(dlg, id); } // run the dialog int ret = dlg->exec(); delete dlg; return ret;}
int ret = dlg->exec();
dlg->exec();
int main(int _argc, char *_argv[]){ KAboutData aboutData( "kcmshell", I18N_NOOP("KDE Control Module"), "2.0", I18N_NOOP("A tool to start single KDE control modules"), KAboutData::License_GPL, "(c) 1999-2000, The KDE Developers"); aboutData.addAuthor("Matthias Hoelzer-Kluepfel",0, "[email protected]"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); KCmdLineArgs::init(_argc, _argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KLocale::setMainCatalogue("kcontrol"); kcmApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KGlobal::iconLoader()->addAppDir( "kcontrol" ); if (args->isSet("list")) { QStringList files; KGlobal::dirs()->findAllResources("apps", KCGlobal::baseGroup() + "*.desktop", true, true, files); QStringList modules; QStringList descriptions; uint maxwidth = 0; for (QStringList::ConstIterator it = files.begin(); it != files.end(); it++) { if (KDesktopFile::isDesktopFile(*it)) { KDesktopFile file(*it, true); QString module = *it; if (module.startsWith(KCGlobal::baseGroup())) module = module.mid(KCGlobal::baseGroup().length()); if (module.right(8) == ".desktop") module.truncate(module.length() - 8); modules.append(module); if (module.length() > maxwidth) maxwidth = module.length(); descriptions.append(QString("%2 (%3)").arg(file.readName()).arg(file.readComment())); } } QByteArray vl; vl.fill(' ', 80); QString verylong = vl; for (uint i = 0; i < modules.count(); i++) { fprintf(stdout, "%s%s - %s\n", (*modules.at(i)).local8Bit().data(), verylong.left(maxwidth - (*modules.at(i)).length()).local8Bit().data(), (*descriptions.at(i)).local8Bit().data()); } return 0; } if (args->count() < 1) { args->usage(); return -1; } if (args->count() == 1) { app.setDCOPName(args->arg(0)); if (app.isRunning()) { app.waitForExit(); return 0; } QString path = locateModule(args->arg(0)); if (path.isEmpty()) return 0; // load the module ModuleInfo info(path); KCModule *module = ModuleLoader::loadModule(info, false); if (module) { // create the dialog KCDialog * dlg = new KCDialog(module, module->buttons(), info.docPath(), 0, 0, true); dlg->setCaption(info.name()); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) QXEmbed::embedClientIntoWindow(dlg, id); } // run the dialog int ret = dlg->exec(); delete dlg; ModuleLoader::unloadModule(info); return ret; } KMessageBox::error(0, i18n("There was an error loading the module.\nThe diagnostics is:\n%1") .arg(KLibLoader::self()->lastErrorMessage())); return 0; } // multiple control modules QStringList modules; for (int i = 0; i < args->count(); i++) { QString path = locateModule(args->arg(i)); if(!path.isEmpty()) modules.append(path); } if (modules.count() < 1) return -1; // create the dialog KExtendedCDialog * dlg = new KExtendedCDialog(0, 0, true); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // add modules for (QStringList::ConstIterator it = modules.begin(); it != modules.end(); ++it) dlg->addModule(*it, false); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) QXEmbed::embedClientIntoWindow(dlg, id); } // run the dialog int ret = dlg->exec(); delete dlg; return ret;}
return ret;
return 0;
int main(int _argc, char *_argv[]){ KAboutData aboutData( "kcmshell", I18N_NOOP("KDE Control Module"), "2.0", I18N_NOOP("A tool to start single KDE control modules"), KAboutData::License_GPL, "(c) 1999-2000, The KDE Developers"); aboutData.addAuthor("Matthias Hoelzer-Kluepfel",0, "[email protected]"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); KCmdLineArgs::init(_argc, _argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KLocale::setMainCatalogue("kcontrol"); kcmApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KGlobal::iconLoader()->addAppDir( "kcontrol" ); if (args->isSet("list")) { QStringList files; KGlobal::dirs()->findAllResources("apps", KCGlobal::baseGroup() + "*.desktop", true, true, files); QStringList modules; QStringList descriptions; uint maxwidth = 0; for (QStringList::ConstIterator it = files.begin(); it != files.end(); it++) { if (KDesktopFile::isDesktopFile(*it)) { KDesktopFile file(*it, true); QString module = *it; if (module.startsWith(KCGlobal::baseGroup())) module = module.mid(KCGlobal::baseGroup().length()); if (module.right(8) == ".desktop") module.truncate(module.length() - 8); modules.append(module); if (module.length() > maxwidth) maxwidth = module.length(); descriptions.append(QString("%2 (%3)").arg(file.readName()).arg(file.readComment())); } } QByteArray vl; vl.fill(' ', 80); QString verylong = vl; for (uint i = 0; i < modules.count(); i++) { fprintf(stdout, "%s%s - %s\n", (*modules.at(i)).local8Bit().data(), verylong.left(maxwidth - (*modules.at(i)).length()).local8Bit().data(), (*descriptions.at(i)).local8Bit().data()); } return 0; } if (args->count() < 1) { args->usage(); return -1; } if (args->count() == 1) { app.setDCOPName(args->arg(0)); if (app.isRunning()) { app.waitForExit(); return 0; } QString path = locateModule(args->arg(0)); if (path.isEmpty()) return 0; // load the module ModuleInfo info(path); KCModule *module = ModuleLoader::loadModule(info, false); if (module) { // create the dialog KCDialog * dlg = new KCDialog(module, module->buttons(), info.docPath(), 0, 0, true); dlg->setCaption(info.name()); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) QXEmbed::embedClientIntoWindow(dlg, id); } // run the dialog int ret = dlg->exec(); delete dlg; ModuleLoader::unloadModule(info); return ret; } KMessageBox::error(0, i18n("There was an error loading the module.\nThe diagnostics is:\n%1") .arg(KLibLoader::self()->lastErrorMessage())); return 0; } // multiple control modules QStringList modules; for (int i = 0; i < args->count(); i++) { QString path = locateModule(args->arg(i)); if(!path.isEmpty()) modules.append(path); } if (modules.count() < 1) return -1; // create the dialog KExtendedCDialog * dlg = new KExtendedCDialog(0, 0, true); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // add modules for (QStringList::ConstIterator it = modules.begin(); it != modules.end(); ++it) dlg->addModule(*it, false); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) QXEmbed::embedClientIntoWindow(dlg, id); } // run the dialog int ret = dlg->exec(); delete dlg; return ret;}
QXEmbed::embedClientIntoWindow(dlg, id);
{ QXEmbed::embedClientIntoWindow(dlg, id); delete dlg; return 0; }
int main(int _argc, char *_argv[]){ KAboutData aboutData( "kcmshell", I18N_NOOP("KDE Control Module"), "2.0", I18N_NOOP("A tool to start single KDE control modules"), KAboutData::License_GPL, "(c) 1999-2000, The KDE Developers"); aboutData.addAuthor("Matthias Hoelzer-Kluepfel",0, "[email protected]"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); KCmdLineArgs::init(_argc, _argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KLocale::setMainCatalogue("kcontrol"); kcmApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KGlobal::iconLoader()->addAppDir( "kcontrol" ); if (args->isSet("list")) { QStringList files; KGlobal::dirs()->findAllResources("apps", KCGlobal::baseGroup() + "*.desktop", true, true, files); QStringList modules; QStringList descriptions; uint maxwidth = 0; for (QStringList::ConstIterator it = files.begin(); it != files.end(); it++) { if (KDesktopFile::isDesktopFile(*it)) { KDesktopFile file(*it, true); QString module = *it; if (module.startsWith(KCGlobal::baseGroup())) module = module.mid(KCGlobal::baseGroup().length()); if (module.right(8) == ".desktop") module.truncate(module.length() - 8); modules.append(module); if (module.length() > maxwidth) maxwidth = module.length(); descriptions.append(QString("%2 (%3)").arg(file.readName()).arg(file.readComment())); } } QByteArray vl; vl.fill(' ', 80); QString verylong = vl; for (uint i = 0; i < modules.count(); i++) { fprintf(stdout, "%s%s - %s\n", (*modules.at(i)).local8Bit().data(), verylong.left(maxwidth - (*modules.at(i)).length()).local8Bit().data(), (*descriptions.at(i)).local8Bit().data()); } return 0; } if (args->count() < 1) { args->usage(); return -1; } if (args->count() == 1) { app.setDCOPName(args->arg(0)); if (app.isRunning()) { app.waitForExit(); return 0; } QString path = locateModule(args->arg(0)); if (path.isEmpty()) return 0; // load the module ModuleInfo info(path); KCModule *module = ModuleLoader::loadModule(info, false); if (module) { // create the dialog KCDialog * dlg = new KCDialog(module, module->buttons(), info.docPath(), 0, 0, true); dlg->setCaption(info.name()); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) QXEmbed::embedClientIntoWindow(dlg, id); } // run the dialog int ret = dlg->exec(); delete dlg; ModuleLoader::unloadModule(info); return ret; } KMessageBox::error(0, i18n("There was an error loading the module.\nThe diagnostics is:\n%1") .arg(KLibLoader::self()->lastErrorMessage())); return 0; } // multiple control modules QStringList modules; for (int i = 0; i < args->count(); i++) { QString path = locateModule(args->arg(i)); if(!path.isEmpty()) modules.append(path); } if (modules.count() < 1) return -1; // create the dialog KExtendedCDialog * dlg = new KExtendedCDialog(0, 0, true); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // add modules for (QStringList::ConstIterator it = modules.begin(); it != modules.end(); ++it) dlg->addModule(*it, false); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) QXEmbed::embedClientIntoWindow(dlg, id); } // run the dialog int ret = dlg->exec(); delete dlg; return ret;}
QCString signal = args->getOption( "signal" ); int signalnum = signal.toInt(); if (signalnum < 0) signalnum = 11; QString appname = QFile::decodeName(args->getOption( "appname" ));
int signalnum = args->getOption( "signal" ).toInt();
int main( int argc, char* argv[] ){ // Make sure that DrKonqi doesn't start DrKonqi when it crashes :-] setenv("KDE_DEBUG", "true", 1); KAboutData aboutData( "drkonqi", I18N_NOOP("The KDE Crash Handler"), version, description, KAboutData::License_BSD, "(C) 2000, Hans Petter Bieker"); aboutData.addAuthor("Hans Petter Bieker", 0, "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); KApplication a; // parse command line arguments KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); QCString signal = args->getOption( "signal" ); int signalnum = signal.toInt(); if (signalnum < 0) signalnum = 11; QString appname = QFile::decodeName(args->getOption( "appname" )); Toplevel *w = new Toplevel(signalnum, appname); return w->exec();}
Toplevel *w = new Toplevel(signalnum, appname);
KAboutData oldabout(args->getOption("appname"), args->getOption("programname"), args->getOption("appversion"), 0, 0, 0, 0, 0, args->getOption("bugaddress")); Toplevel *w = new Toplevel(signalnum, oldabout);
int main( int argc, char* argv[] ){ // Make sure that DrKonqi doesn't start DrKonqi when it crashes :-] setenv("KDE_DEBUG", "true", 1); KAboutData aboutData( "drkonqi", I18N_NOOP("The KDE Crash Handler"), version, description, KAboutData::License_BSD, "(C) 2000, Hans Petter Bieker"); aboutData.addAuthor("Hans Petter Bieker", 0, "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); KApplication a; // parse command line arguments KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); QCString signal = args->getOption( "signal" ); int signalnum = signal.toInt(); if (signalnum < 0) signalnum = 11; QString appname = QFile::decodeName(args->getOption( "appname" )); Toplevel *w = new Toplevel(signalnum, appname); return w->exec();}
ModuleInfo info(path);
KCModuleInfo info(path);
int main(int _argc, char *_argv[]){ KAboutData aboutData( "kcmshell", I18N_NOOP("KDE Control Module"), KCONTROL_VERSION, I18N_NOOP("A tool to start single KDE control modules"), KAboutData::License_GPL, "(c) 1999-2002, The KDE Developers"); aboutData.addAuthor("Daniel Molkentin", I18N_NOOP("Current Maintainer"), "[email protected]"); aboutData.addAuthor("Matthias Hoelzer-Kluepfel",0, "[email protected]"); aboutData.addAuthor("Matthias Elter",0, "[email protected]"); aboutData.addAuthor("Matthias Ettrich",0, "[email protected]"); aboutData.addAuthor("Waldo Bastian",0, "[email protected]"); KCmdLineArgs::init(_argc, _argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. KLocale::setMainCatalogue("kcontrol"); kcmApplication app; KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KGlobal::iconLoader()->addAppDir( "kcontrol" ); KGlobal::locale()->setLanguage(args->getOption("lang")); if (args->isSet("list")) { QStringList files; KGlobal::dirs()->findAllResources("apps", KCGlobal::baseGroup() + "*.desktop", true, true, files); QStringList modules; QStringList descriptions; uint maxwidth = 0; for (QStringList::ConstIterator it = files.begin(); it != files.end(); it++) { if (KDesktopFile::isDesktopFile(*it)) { KDesktopFile file(*it, true); if (file.readEntry("Hidden") == "true") continue; QString module = *it; if (module.startsWith(KCGlobal::baseGroup())) module = module.mid(KCGlobal::baseGroup().length()); if (module.right(8) == ".desktop") module.truncate(module.length() - 8); modules.append(module); if (module.length() > maxwidth) maxwidth = module.length(); descriptions.append(QString("%2 (%3)").arg(file.readName()).arg(file.readComment())); } } QByteArray vl; vl.fill(' ', 80); QString verylong = vl; for (uint i = 0; i < modules.count(); i++) { fprintf(stdout, "%s%s - %s\n", (*modules.at(i)).local8Bit().data(), verylong.left(maxwidth - (*modules.at(i)).length()).local8Bit().data(), (*descriptions.at(i)).local8Bit().data()); }#if defined(QT_THREAD_SUPPORT) app.unlock();#endif return 0; } if (args->count() < 1) { args->usage(); return -1; } if (args->count() == 1) { app.setDCOPName(args->arg(0)); if (app.isRunning()) { app.waitForExit(); return 0; } QString path = locateModule(args->arg(0)); if (path.isEmpty()) {#if defined(QT_THREAD_SUPPORT) app.unlock();#endif return 0; } // load the module ModuleInfo info(path); KCModule *module = KCModuleLoader::loadModule(info, false); if (module) { // create the dialog QCString embedStr = args->getOption("embed"); bool embed = false; int id = -1; if (!embedStr.isEmpty()) id = embedStr.toInt(&embed); if (!args->isSet("silent")) { if (!embed) { KCDialog * dlg = new KCDialog(module, module->buttons(), info.docPath(), 0, 0, true ); dlg->setCaption(info.name()); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // run the dialog dlg->exec(); delete dlg; } // if we are going to be embedded, embed else { QWidget *dlg = new ProxyWidget(module, info.name(), "kcmshell", false); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); QXEmbed::embedClientIntoWindow(dlg, id); kapp->exec(); delete dlg; } } else { //Silent kapp->exec(); } KCModuleLoader::unloadModule(info); return 0; } KCModuleLoader::showLastLoaderError(0L); return 0; } // multiple control modules QStringList modules; for (int i = 0; i < args->count(); i++) { QString path = locateModule(args->arg(i)); if(!path.isEmpty()) modules.append(path); } if (modules.count() < 1) return -1; // create the dialog KCMultiDialog * dlg = new KCMultiDialog(0, 0, true); // Needed for modules that use d'n'd (not really the right // solution for this though, I guess) dlg->setAcceptDrops(true); // add modules for (QStringList::ConstIterator it = modules.begin(); it != modules.end(); ++it) dlg->addModule(*it, false); // if we are going to be embedded, embed QCString embed = args->getOption("embed"); if (!embed.isEmpty()) { bool ok; int id = embed.toInt(&ok); if (ok) { // NOTE: This has to be changed for QT 3.0. See above! QXEmbed::embedClientIntoWindow(dlg, id); delete dlg; return 0; } } // run the dialog dlg->exec(); delete dlg; return 0;}
KHelpBrowser *khb = new KHelpBrowser;
khcMainWindow *khb = new khcMainWindow;
int main(int argc, char *argv[]){ bool server = false; // create local data directory if necessary QDir dir; dir.setPath(KApplication::localkdedir() + "/share/apps"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps"); dir.setPath(KApplication::localkdedir() + "/share/apps/khelpcenter"); if (!dir.exists()) dir.mkdir(KApplication::localkdedir() + "/share/apps/khelpcenter"); for (int i=0; i< argc; i++) { if (strcmp(argv[i], "--server") == 0 || strcmp(argv[i], "-s") == 0) server = true; } if (server) { // activate autoloader for interface "HelpBrowserFactory" OPApplication app(argc, argv, "khelpcenter"); KOMAutoLoader<HelpBrowserFactory_Impl> HelpBrowserFactoryLoader("IDL:KHelpCenter/HelpBrowserFactory:1.0" , "HelpBrowser"); app.exec(); return 0; } else { // standalone app OPApplication app(argc, argv, "khelpcenter"); KHelpBrowser *khb = new KHelpBrowser; khb->show(); app.exec(); if (khb) delete khb; return 0; }}
for (i = 1; i < argc; i++)
for (int i = 1; i < argc; i++)
int main(int argc, char *argv[]){ KApplication app(argc, argv, "kwelcome"); // check for --kdestartup KConfig *conf = kapp->getConfig(); conf->setGroup("General Settings"); QString tmp = conf->readEntry("AutostartOnKDEStartup", "true"); for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { // skip caption if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } QString arg = argv[i]; } if ((arg == "--kdestartup") && (tmp != "true")) return 0; KWelcome *widget = new KWelcome(); app.setMainWidget(widget); app.setTopWidget(widget); widget->show(); return app.exec();}
if ( argv[i][0] == '-' ) { if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; }
int main(int argc, char *argv[]){ KApplication app(argc, argv, "kwelcome"); // check for --kdestartup KConfig *conf = kapp->getConfig(); conf->setGroup("General Settings"); QString tmp = conf->readEntry("AutostartOnKDEStartup", "true"); for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { // skip caption if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } QString arg = argv[i]; } if ((arg == "--kdestartup") && (tmp != "true")) return 0; KWelcome *widget = new KWelcome(); app.setMainWidget(widget); app.setTopWidget(widget); widget->show(); return app.exec();}
if ((arg == "--kdestartup") && (tmp != "true")) return 0;
int main(int argc, char *argv[]){ KApplication app(argc, argv, "kwelcome"); // check for --kdestartup KConfig *conf = kapp->getConfig(); conf->setGroup("General Settings"); QString tmp = conf->readEntry("AutostartOnKDEStartup", "true"); for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { // skip caption if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } QString arg = argv[i]; } if ((arg == "--kdestartup") && (tmp != "true")) return 0; KWelcome *widget = new KWelcome(); app.setMainWidget(widget); app.setTopWidget(widget); widget->show(); return app.exec();}
return app.exec();
int rc = app.exec(); if (widget != 0) delete widget; return rc;
int main(int argc, char *argv[]){ KApplication app(argc, argv, "kwelcome"); // check for --kdestartup KConfig *conf = kapp->getConfig(); conf->setGroup("General Settings"); QString tmp = conf->readEntry("AutostartOnKDEStartup", "true"); for (i = 1; i < argc; i++) { if ( argv[i][0] == '-' ) { // skip caption if ( strcasecmp( argv[i], "-caption" ) == 0 ) i++; if ( strcasecmp( argv[i], "-icon" ) == 0 ) i++; if ( strcasecmp( argv[i], "-miniicon" ) == 0 ) i++; continue; } QString arg = argv[i]; } if ((arg == "--kdestartup") && (tmp != "true")) return 0; KWelcome *widget = new KWelcome(); app.setMainWidget(widget); app.setTopWidget(widget); widget->show(); return app.exec();}
I18N_NOOP("The KDE Crash Handler"), version, description, KAboutData::License_BSD, "(C) 2000, Hans Petter Bieker");
I18N_NOOP("The KDE Crash Handler"), version, description, KAboutData::License_BSD, "(C) 2000-2003, Hans Petter Bieker");
int main( int argc, char* argv[] ){ // Drop privs. setgid(getgid()); setuid(getuid()); // Make sure that DrKonqi doesn't start DrKonqi when it crashes :-] setenv("KDE_DEBUG", "true", 1); KAboutData aboutData( "drkonqi", I18N_NOOP("The KDE Crash Handler"), version, description, KAboutData::License_BSD, "(C) 2000, Hans Petter Bieker"); aboutData.addAuthor("Hans Petter Bieker", 0, "[email protected]"); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions( options ); KApplication::disableAutoDcopRegistration(); KApplication a; a.disableSessionManagement(); KrashConfig krashconf; Toplevel w(&krashconf); return w.exec();}
qgis->getMapCanvas()->setExtent(rect);
qgis->setExtent(rect);
int main(int argc, char *argv[]){ // Set up the custom qWarning/qDebug custom handler qInstallMsgHandler( myMessageOutput ); ///////////////////////////////////////////////////////////////// // Command line options 'behaviour' flag setup //////////////////////////////////////////////////////////////// // // Parse the command line arguments, looking to see if the user has asked for any // special behaviours. Any remaining non command arguments will be kept aside to // be passed as a list of layers and / or a project that should be loaded. // // This behaviour is used to load the app, snapshot the map, // save the image to disk and then exit QString mySnapshotFileName=""; // This behaviour will set initial extent of map canvas QString myInitialExtent=""; // This behaviour will allow you to force the use of a translation file // which is useful for testing QString myTranslationFileName="";#ifndef WIN32 if ( !bundleclicked(argc, argv) ) { //////////////////////////////////////////////////////////////// // USe the GNU Getopts utility to parse cli arguments // Invokes ctor `GetOpt (int argc, char **argv, char *optstring);' /////////////////////////////////////////////////////////////// int optionChar; while (1) { static struct option long_options[] = { /* These options set a flag. */ {"help", no_argument, 0, 'h'}, /* These options don't set a flag. * We distinguish them by their indices. */ {"snapshot", required_argument, 0, 's'}, {"lang", required_argument, 0, 'l'}, {"project", required_argument, 0, 'p'}, {"extent", required_argument, 0, 'e'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; optionChar = getopt_long (argc, argv, "slpe", long_options, &option_index); /* Detect the end of the options. */ if (optionChar == -1) break; switch (optionChar) { case 0: /* If this option set a flag, do nothing else now. */ if (long_options[option_index].flag != 0) break; printf ("option %s", long_options[option_index].name); if (optarg) printf (" with arg %s", optarg); printf ("\n"); break; case 's': mySnapshotFileName = optarg; break; case 'l': myTranslationFileName = optarg; break; case 'p': myProjectFileName = optarg; break; case 'e': myInitialExtent = optarg; break; case 'h': case '?': usage( argv[0] ); return 2; // XXX need standard exit codes break; default: std::cerr << argv[0] << ": getopt returned character code " << optionChar << "\n"; return 1; // XXX need standard exit codes } } // Add any remaining args to the file list - we will attempt to load them // as layers in the map view further down....#ifdef QGISDEBUG std::cout << "Files specified on command line: " << optind << std::endl;#endif if (optind < argc) { while (optind < argc) {#ifdef QGISDEBUG int idx = optind; std::cout << idx << ": " << argv[idx] << std::endl;#endif myFileList.append(argv[optind++]); } } }#endif //WIN32 ///////////////////////////////////////////////////////////////////// // Now we have the handlers for the different behaviours... //////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// // Initialise the application and the translation stuff /////////////////////////////////////////////////////////////////////#ifdef Q_WS_X11 bool myUseGuiFlag = getenv( "DISPLAY" ) != 0;#else bool myUseGuiFlag = TRUE;#endif if (!myUseGuiFlag) { std::cerr << "QGIS starting in non-interactive mode not supported.\n You are seeing this message most likely because you have no DISPLAY environment variable set." << std::endl; exit(1); //exit for now until a version of qgis is capabable of running non interactive } QApplication a(argc, argv, myUseGuiFlag );#ifdef Q_OS_MACX // Install OpenDocuments AppleEvent handler after application object is initialized // but before any other event handling (including dialogs or splash screens) occurs. // If an OpenDocuments event has been created before the application was launched, // it must be handled before some other event handler runs and dismisses it as unknown. // If run at startup, the handler will set either or both of myProjectFileName and myFileList. AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, openDocumentsAEHandler, 0, false);#endif // Check to see if qgis was started from the source directory. // This is done by looking for Makefile in the directory where qgis was // started from. If running from the src directory, exit gracefully // Get the application path. This method is required to support qt 3.1.2 // which does not support the applicationFilePath and applicationDirPath // functions. We assume that OS X and Win32 systems will be using at least // Qt 3.2 and therefore support the required functions.#if defined(Q_OS_MACX) || defined(WIN32) QString appPath = qApp->applicationFilePath(); QString appDir = qApp->applicationDirPath(); QString testFile = "Makefile";#else QString appPath = argv[0]; QString appDir = appPath.left(appPath.findRev("/")); QString testFile = "lt-qgis";#endif if(appPath.contains("/src/")) { // check to see if configure is present in the directory QFileInfo fi(appDir + "/" + testFile); if(fi.exists()) { QMessageBox::critical(0,"QGIS Not Installed", "You appear to be running QGIS from the source directory.\n" "You must install QGIS using make install and run it from the " "installed directory."); exit(1); } } // a.setFont(QFont("helvetica", 11));#if defined(Q_OS_MACX) || defined(WIN32) QString PKGDATAPATH = qApp->applicationDirPath() + "/share/qgis";#endif QTranslator tor(0); // For WIN32, get the locale if (myTranslationFileName!="") { QString translation = "qgis_" + myTranslationFileName; tor.load(translation, QString(PKGDATAPATH) + "/i18n"); } else {#ifdef QGISDEBUG std::cout << "Setting translation to " << PKGDATAPATH << "/i18n/qgis_" << QTextCodec::locale() << std::endl; #endif tor.load(QString("qgis_") + QTextCodec::locale(), QString(PKGDATAPATH) + "/i18n"); } //tor.load("qgis_go", "." ); a.installTranslator(&tor); /* uncomment the following line, if you want a Windows 95 look */ //a.setStyle("Windows"); QgisApp *qgis = new QgisApp; // "QgisApp" used to find canonical instance qgis->setName( "QgisApp" ); a.setMainWidget(qgis); ///////////////////////////////////////////////////////////////////// // If no --project was specified, parse the args to look for a // // .qgs file and set myProjectFileName to it. This allows loading // // of a project file by clicking on it in various desktop managers // // where an appropriate mime-type has been set up. // ///////////////////////////////////////////////////////////////////// if(myProjectFileName.isEmpty()) { // check for a .qgs for(int i = 0; i < argc; i++) { QString arg = argv[i]; if(arg.contains(".qgs")) { myProjectFileName = argv[i]; break; } } } ///////////////////////////////////////////////////////////////////// // Load a project file if one was specified ///////////////////////////////////////////////////////////////////// if( ! myProjectFileName.isEmpty() ) { qgis->openProject(myProjectFileName); } ///////////////////////////////////////////////////////////////////// // autoload any filenames that were passed in on the command line /////////////////////////////////////////////////////////////////////#ifdef QGISDEBUG std::cout << "Number of files in myFileList: " << myFileList.count() << std::endl;#endif for ( QStringList::Iterator myIterator = myFileList.begin(); myIterator != myFileList.end(); ++myIterator ) {#ifdef QGISDEBUG std::cout << "Trying to load file : " << (*myIterator).local8Bit() << std::endl;#endif QString myLayerName = *myIterator; // don't load anything with a .qgs extension - these are project files if(!myLayerName.contains(".qgs")) { qgis->openLayer(myLayerName); } } ///////////////////////////////////////////////////////////////////// // Set initial extent if requested ///////////////////////////////////////////////////////////////////// if ( ! myInitialExtent.isEmpty() ) { double coords[4]; int pos, posOld = 0; bool ok; // XXX is it necessary to switch to "C" locale? // parse values from string // extent is defined by string "xmin,ymin,xmax,ymax" for (int i = 0; i < 3; i++) { // find comma and get coordinate pos = myInitialExtent.find(',', posOld); if (pos == -1) { ok = false; break; } coords[i] = QString( myInitialExtent.mid(posOld, pos - posOld) ).toDouble(&ok); if (!ok) break; posOld = pos+1; } // parse last coordinate if (ok) coords[3] = QString( myInitialExtent.mid(posOld) ).toDouble(&ok); if (!ok) std::cout << "Error while parsing initial extent!" << std::endl; else { // set extent from parsed values QgsRect rect(coords[0],coords[1],coords[2],coords[3]); qgis->getMapCanvas()->setExtent(rect); } } ///////////////////////////////////////////////////////////////////// // Take a snapshot of the map view then exit if snapshot mode requested ///////////////////////////////////////////////////////////////////// if(mySnapshotFileName!="") { /*You must have at least one paintEvent() delivered for the window to be rendered properly. It looks like you don't run the event loop in non-interactive mode, so the event is never occuring. To achieve this without runing the event loop: show the window, then call qApp->processEvents(), grab the pixmap, save it, hide the window and exit. */ //qgis->show(); a.processEvents(); QPixmap * myQPixmap = new QPixmap(800,600); myQPixmap->fill(); qgis->saveMapAsImage(mySnapshotFileName,myQPixmap); a.processEvents(); qgis->hide(); return 1; } ///////////////////////////////////////////////////////////////////// // Continue on to interactive gui... ///////////////////////////////////////////////////////////////////// qgis->show(); a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit())); return a.exec();}
if ( !doit() ) { debug( "kio_file : Could not do it :-("); exit(1); }
Connection parent( 0, 1 ); FileProtocol file( &parent ); file.dispatchLoop();
int main( int argc, char **argv ){ signal(SIGCHLD,sig_handler); signal(SIGSEGV,sig_handler2); ProtocolManager manager; debug( "kio_file : Starting"); if ( !doit() ) { debug( "kio_file : Could not do it :-("); exit(1); } debug( "kio_file : Done" );}