void Small::updateInstance(int no, QCString value) { bool checked = false; switch(no){ case 0: w->textLabel10->setText(value); break; case 1: w->textLabel11->setText(value); break; case 2: w->textLabel12->setText(value); if(value == "ENABLED") checked = true; w->checkBox2 ->setChecked(checked); checked=false; break; case 3: w->textLabel13->setText(value); break; case 4: w->textLabel14->setText(value); break; case 5: w->textLabel15->setText(value); break; case 6: w->spinBox2->setSpecialValueText(value); break; case 7: w->spinBox3->setSpecialValueText(value); break; case 8: if(value == "YES") checked = true; w->checkBox1->setChecked(checked); checked=false; break; case 9: w->comboBox1->setCurrentItem(value.toInt()); break; case 10: // w->spinBox5->setSpecialValueText(value); w->slider2->setValue(value.toInt()); case 11: if(value == "YES") checked = true; // w->checkBox2->setChecked(checked); checked=false; break; default: break; } }
void MemberHandler::startLocation(const QXmlAttributes& attrib) { m_defFile = attrib.value("file"); QCString s; s = attrib.value("line"); if (!s.isEmpty()) m_defLine=s.toInt(); s = attrib.value("bodystart"); if (!s.isEmpty()) m_bodyStart=s.toInt(); s = attrib.value("bodyend"); if (!s.isEmpty()) m_bodyEnd=s.toInt(); }
int KConfigBase::readNumEntry(const char *pKey, int nDefault) const { QCString aValue = readEntryUtf8(pKey); if(aValue.isNull()) return nDefault; else if(aValue == "true" || aValue == "on" || aValue == "yes") return 1; else { bool ok; int rc = aValue.toInt(&ok); return (ok ? rc : nDefault); } }
bool KConfigBase::readBoolEntry(const char *pKey, bool bDefault) const { QCString aValue = readEntryUtf8(pKey); if(aValue.isNull()) return bDefault; else { if(aValue == "true" || aValue == "on" || aValue == "yes" || aValue == "1") return true; else { bool bOK; int val = aValue.toInt(&bOK); if(bOK && val != 0) return true; else return false; } } }
static int startApp() { KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); // 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); } QString icon; if ( args->isSet("i")) icon = args->getOption("i"); bool prompt = true; if ( args->isSet("d")) prompt = false; // 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 = "******"; } // 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); } } // Don't change uid if we're don't need to. if (!change_uid) { int result = system(command); result = WEXITSTATUS(result); return result; } // 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"); bool withIgnoreButton = args->isSet("ignorebutton"); QCStringList env; QCString options; env << ( "DESKTOP_STARTUP_ID=" + 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)); } KUser u; env << (QCString) ("KDESU_USER="******"KDESYCOCA="+QFile::encodeName(locateLocal("cache", "ksycoca")); env << ksycoca; options += "xf"; // X-only, dcop forwarding enabled. } if (keep && !terminal && !just_started) { client.setPriority(priority); client.setScheduler(scheduler); int result = client.exec(command, user, options, env); if (result == 0) { result = client.exitCode(); return result; } } // 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( kapp->startupId()); KStartupInfoData data; data.setSilent( KStartupInfoData::Yes ); KStartupInfo::sendChange( id, data ); KDEsuDialog dlg(user, auth_user, keep && !terminal,icon, withIgnoreButton); if (prompt) 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); if (prompt) 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) kapp->processEvents(); // Run command if (!change_uid) { int result = system(command); result = WEXITSTATUS(result); return result; } else if (keep && have_daemon) { client.setPass(password, timeout); client.setPriority(priority); client.setScheduler(scheduler); int result = client.exec(command, user, options, env); if (result == 0) { result = client.exitCode(); return result; } } 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); int result = proc.exec(password); return result; } return -1; }
bool KoApplication::start() { ResetStarting resetStarting; // reset m_starting to false when we're done Q_UNUSED( resetStarting ); // Find the *.desktop file corresponding to the kapp instance name KoDocumentEntry entry = KoDocumentEntry( KoDocument::readNativeService() ); if ( entry.isEmpty() ) { kdError( 30003 ) << instanceName() << "part.desktop not found." << endl; kdError( 30003 ) << "Run 'kde-config --path services' to see which directories were searched, assuming kde startup had the same environment as your current shell." << endl; kdError( 30003 ) << "Check your installation (did you install KOffice in a different prefix than KDE, without adding the prefix to /etc/kderc ?)" << endl; return false; } // Get the command line arguments which we have to parse KCmdLineArgs *args= KCmdLineArgs::parsedArgs(); int argsCount = args->count(); KCmdLineArgs *koargs = KCmdLineArgs::parsedArgs("koffice"); QCString dpiValues = koargs->getOption( "dpi" ); if ( !dpiValues.isEmpty() ) { int sep = dpiValues.find( QRegExp( "[x, ]" ) ); int dpiX; int dpiY = 0; bool ok = true; if ( sep != -1 ) { dpiY = dpiValues.mid( sep+1 ).toInt( &ok ); dpiValues.truncate( sep ); } if ( ok ) { dpiX = dpiValues.toInt( &ok ); if ( ok ) { if ( !dpiY ) dpiY = dpiX; KoGlobal::setDPI( dpiX, dpiY ); } } } // No argument -> create an empty document if ( !argsCount ) { KoDocument* doc = entry.createDoc( 0, "Document" ); if ( !doc ) return false; KoMainWindow *shell = new KoMainWindow( doc->instance() ); shell->show(); QObject::connect(doc, SIGNAL(sigProgress(int)), shell, SLOT(slotProgress(int))); // for initDoc to fill in the recent docs list // and for KoDocument::slotStarted doc->addShell( shell ); if ( doc->checkAutoSaveFile() ) { shell->setRootDocument( doc ); } else { doc->showStartUpWidget( shell ); } // FIXME This needs to be moved someplace else QObject::disconnect(doc, SIGNAL(sigProgress(int)), shell, SLOT(slotProgress(int))); } else { bool print = koargs->isSet("print"); bool doTemplate = koargs->isSet("template"); koargs->clear(); // Loop through arguments short int n=0; // number of documents open short int nPrinted = 0; for(int i=0; i < argsCount; i++ ) { // For now create an empty document KoDocument* doc = entry.createDoc( 0 ); if ( doc ) { // show a shell asap KoMainWindow *shell = new KoMainWindow( doc->instance() ); if (!print) shell->show(); // are we just trying to open a template? if ( doTemplate ) { QStringList paths; if ( args->url(i).isLocalFile() && QFile::exists(args->url(i).path()) ) { paths << QString(args->url(i).path()); kdDebug(30003) << "using full path..." << endl; } else { QString desktopName(args->arg(i)); QString appName = KGlobal::instance()->instanceName(); paths = KGlobal::dirs()->findAllResources("data", appName +"/templates/*/" + desktopName ); if ( paths.isEmpty()) { paths = KGlobal::dirs()->findAllResources("data", appName +"/templates/" + desktopName ); } if ( paths.isEmpty()) { KMessageBox::error(0L, i18n("No template found for: %1 ").arg(desktopName) ); delete shell; } else if ( paths.count() > 1 ) { KMessageBox::error(0L, i18n("Too many templates found for: %1").arg(desktopName) ); delete shell; } } if ( !paths.isEmpty() ) { KURL templateBase; templateBase.setPath(paths[0]); KDesktopFile templateInfo(paths[0]); QString templateName = templateInfo.readURL(); KURL templateURL; templateURL.setPath( templateBase.directory() + "/" + templateName ); if ( shell->openDocument(doc, templateURL )) { doc->resetURL(); doc->setEmpty(); doc->setTitleModified(); kdDebug(30003) << "Template loaded..." << endl; n++; } else { KMessageBox::error(0L, i18n("Template %1 failed to load.").arg(templateURL.prettyURL()) ); delete shell; } } // now try to load } else if ( shell->openDocument( doc, args->url(i) ) ) { if ( print ) { shell->print(false /*we want to get the dialog*/); // delete shell; done by ~KoDocument nPrinted++; } else { // Normal case, success n++; } } else { // .... if failed // delete doc; done by openDocument // delete shell; done by ~KoDocument } } } if ( print ) return nPrinted > 0; if (n == 0) // no doc, e.g. all URLs were malformed return false; } args->clear(); // not calling this before since the program will quit there. return true; }