void K3bCddbOptionTab::apply() { KConfig* c = kapp->config(); c->setGroup( "Cddb" ); c->writeEntry( "use remote cddb", m_checkRemoteCddb->isChecked() ); c->writeEntry( "use local cddb query", m_checkUseLocalCddb->isChecked() ); c->writeEntry( "save cddb entries locally", m_checkSaveLocalEntries->isChecked() ); c->writeEntry( "use manual cgi path", m_checkManualCgiPath->isChecked() ); c->writeEntry( "cgi path", m_editManualCgiPath->text() ); QStringList cddbServer; QStringList localCddbDirs; QListViewItemIterator it( m_viewLocalDir ); while( it.current() ) { localCddbDirs.append( it.current()->text(0) ); ++it; } QListViewItemIterator it1( m_viewCddbServer ); while( it1.current() ) { cddbServer.append( it1.current()->text(0) + " " + it1.current()->text(1) + ":" + it1.current()->text(2) ); ++it1; } // new config c->writeEntry( "cddb server", cddbServer ); // old config <= 0.7.3 if( c->hasKey( "http server" ) ) c->deleteEntry( "http server" ); if( c->hasKey( "cddbp server" ) ) c->deleteEntry( "cddbp server" ); c->writePathEntry( "local cddb dirs", localCddbDirs ); }
void MoodPlugin::init() { toolbar=new KToolBar((QMainWindow*)ktagebuchapp,QMainWindow::Top); new QLabel(i18n("Mood :"),toolbar); combobox=new KComboBox(toolbar); KConfig *config = ktagebuchapp->getConfig(); config->setGroup("Mood Plugin"); if (!config->hasKey("moods")) mPrefs->save(); QStringList strList=QStringList(config->readListEntry("moods")); for (QStringList::Iterator it=strList.begin();it!=strList.end();++it){ combobox->insertItem(i18n(*it)); } combobox->show(); loadEntry(); }
/** * read the configfile */ void PingCfgDlg::readConfig() { QString s; KConfig *kc = kapp->getConfig(); kc->setGroup(configGroupName); if (kc->hasKey("binaryType")) { s = kc->readEntry("binaryType"); if (!stricmp(s, "nslookup")) { cfgNslookupBtn->setChecked(TRUE); } else { cfgPingBtn->setChecked(TRUE); } } else { cfgPingBtn->setChecked(TRUE); } }
KBBGame::KBBGame() : KTopLevelWidget() { int i; setCaption(QString("KBlackBox ")+KBVERSION); menu = new KMenuBar(this, "menu"); QPopupMenu *game = new QPopupMenu; QPopupMenu *file = new QPopupMenu; sizesm = new QPopupMenu; ballsm = new QPopupMenu; QPopupMenu *help = new QPopupMenu; options = new QPopupMenu; CHECK_PTR( file ); CHECK_PTR( game ); CHECK_PTR( help ); CHECK_PTR( sizesm ); CHECK_PTR( ballsm ); CHECK_PTR( options ); CHECK_PTR( menu ); help->insertItem( trans->translate("&Help"), ID_HELP ); help->setAccel( CTRL+Key_H, ID_HELP ); help->insertSeparator(); help->insertItem( trans->translate("&About KBlackBox"), ID_ABOUT ); help->setAccel( CTRL+Key_A, ID_ABOUT ); help->insertItem( trans->translate("About &Qt"), ID_ABOUT_QT ); file->insertItem( trans->translate("&Quit"), ID_QUIT ); file->setAccel( CTRL+Key_Q, ID_QUIT ); game->insertItem( trans->translate("&New"), ID_NEW ); game->insertItem( trans->translate("&Give up"), ID_GIVEUP ); game->insertItem( trans->translate("&Done"), ID_DONE ); game->insertSeparator(); game->insertItem( trans->translate("&Resize"), ID_RESIZE ); sizes1id = sizesm->insertItem( " 8 x 8 ", this, SLOT(size1()) ); sizes2id = sizesm->insertItem( " 10 x 10 ", this, SLOT(size2()) ); sizes3id = sizesm->insertItem( " 12 x 12 ", this, SLOT(size3()) ); sizesm->setCheckable( TRUE ); balls1id = ballsm->insertItem( " 4 ", this, SLOT(balls1()) ); balls2id = ballsm->insertItem( " 6 ", this, SLOT(balls2()) ); balls3id = ballsm->insertItem( " 8 ", this, SLOT(balls3()) ); ballsm->setCheckable( TRUE ); options->insertItem( trans->translate("&Size"), sizesm ); options->insertItem( trans->translate("&Balls"), ballsm ); tut1id = options->insertItem( trans->translate("&Tutorial"), this, SLOT(tutorialSwitch()) ); options->setCheckable( TRUE ); connect( file, SIGNAL(activated(int)), SLOT(callBack(int)) ); connect( help, SIGNAL(activated(int)), SLOT(callBack(int)) ); connect( game, SIGNAL(activated(int)), SLOT(callBack(int)) ); menu->insertItem( trans->translate("&File"), file ); menu->insertItem( trans->translate("&Game"), game ); menu->insertItem( trans->translate("&Options"), options ); menu->insertSeparator(); menu->insertItem( trans->translate("&Help"), help ); menu->show(); setMenu( menu ); KIconLoader *loader = kapp->getIconLoader(); QPixmap **pix = new QPixmap*[NROFTYPES]; pix[0] = new QPixmap(); *pix[0] = loader->loadIcon( pFNames[0] ); if (!pix[0]->isNull()) { debug( "Pixmap \"%s\" loaded.", pFNames[0] ); for (i = 1; i < NROFTYPES; i++) { pix[i] = new QPixmap; *pix[i] = loader->loadIcon( pFNames[i] ); if (!pix[i]->isNull()) { debug( "Pixmap \"%s\" loaded.", pFNames[i] ); } else { pix[i] = pix[i-1]; pix[i]->detach(); debug( "Cannot find pixmap \"%s\". Using previous one.", pFNames[i] ); } } } else { debug( "Cannot find pixmap \"%s\". Pixmaps will not be loaded.", pFNames[0] ); delete pix[0]; delete pix; pix = NULL; } gr = new KBBGraphic( pix, this ); connect( gr, SIGNAL(inputAt(int,int,int)), this, SLOT(gotInputAt(int,int,int)) ); connect( this, SIGNAL(gameRuns(bool)), gr, SLOT(setInputAccepted(bool)) ); connect( gr, SIGNAL(endMouseClicked()), this, SLOT(gameFinished()) ); /* QToolTip::add( doneButton, trans->translate( "Click here when you think you placed all the balls.") ); */ QString tmps; stat = new KStatusBar( this ); tmps.sprintf( "aaaaaaaa" ); stat->insertItem( (const char *) tmps, SSCORE ); tmps.sprintf( "aaaaaaaaaaa" ); stat->insertItem( (const char *) tmps, SBALLS ); tmps.sprintf( "aaaaaaa" ); stat->insertItem( (const char *) tmps, SRUN ); tmps.sprintf( "aaaaaaaaaa" ); stat->insertItem( (const char *) tmps, SSIZE ); setStatusBar( stat ); tool = new KToolBar( this ); tool->insertButton( loader->loadIcon("exit.xpm"), ID_QUIT, TRUE, trans->translate("Quit") ); tool->insertButton( loader->loadIcon("reload.xpm"), ID_NEW, TRUE, trans->translate("New") ); tool->insertButton( loader->loadIcon("giveup.xpm"), ID_GIVEUP, TRUE, trans->translate("Give up") ); tool->insertButton( loader->loadIcon("done.xpm"), ID_DONE, TRUE, trans->translate("Done") ); tool->insertSeparator(); tool->insertButton( loader->loadIcon("help.xpm"), ID_HELP, TRUE, trans->translate("Help") ); connect( tool, SIGNAL(clicked(int)), SLOT(callBack(int)) ); addToolBar( tool ); tool->setBarPos( KToolBar::Top ); tool->show(); /* Game initializations */ running = FALSE; gameBoard = NULL; KConfig *kConf; int j; kConf = KApplication::getKApplication()->getConfig(); kConf->setGroup( "KBlackBox Setup" ); if (kConf->hasKey( "Balls" )) { i = kConf->readNumEntry( "Balls" ); balls = i; switch (i) { case 4: ballsm->setItemChecked( balls1id, TRUE ); break; case 6: ballsm->setItemChecked( balls2id, TRUE ); break; case 8: ballsm->setItemChecked( balls3id, TRUE ); break; } } else { balls = 4; ballsm->setItemChecked( balls1id, TRUE ); } if ((kConf->hasKey( "Width" )) && (kConf->hasKey( "Balls" ))) { i = kConf->readNumEntry( "Width" ); j = kConf->readNumEntry( "Height" ); gr->setSize( i+4, j+4 ); // +4 is the space for "lasers" and an edge... gameBoard = new RectOnArray( gr->numC(), gr->numR() ); switch (i) { case 8: sizesm->setItemChecked( sizes1id, TRUE ); break; case 10: sizesm->setItemChecked( sizes2id, TRUE ); break; case 12: sizesm->setItemChecked( sizes3id, TRUE ); break; } } else { gr->setSize( 8+4, 8+4 ); // +4 is the space for "lasers" and an edge... gameBoard = new RectOnArray( gr->numC(), gr->numR() ); sizesm->setItemChecked( sizes1id, TRUE ); } if (kConf->hasKey( "tutorial" )) { tutorial = (bool) kConf->readNumEntry( "tutorial" ); } else tutorial = FALSE; options->setItemChecked( tut1id, tutorial ); QString s, s1; int pos; setMinSize(); gameResize(); if (kConf->hasKey( "appsize" )) { s = kConf->readEntry( "appsize" ); debug("%s", (const char *) s); pos = s.find( 'x' ); s1 = s.right( s.length() - pos - 1 ); s.truncate( pos - 1 ); // debug("%s", (const char *) s); // debug("%s", (const char *) s1); resize( s.toInt(), s1.toInt() ); } setScore( 0 ); ballsPlaced = 0; updateStats(); setView( gr ); newGame(); }
/* --| main |------------------------------------------------------ */ extern "C" int KDE_EXPORT kdemain(int argc, char *argv[]) { setgid(getgid()); setuid(getuid()); // drop privileges // deal with shell/command //////////////////////////// bool histon = true; bool menubaron = true; bool tabbaron = true; bool frameon = true; bool scrollbaron = true; bool showtip = true; KAboutData aboutData("konsole", I18N_NOOP("Konsole"), KONSOLE_VERSION, description, KAboutData::License_GPL_V2, "Copyright (c) 1997-2006, Lars Doelle"); aboutData.addAuthor("Robert Knight", I18N_NOOP("Maintainer"), "*****@*****.**"); aboutData.addAuthor("Lars Doelle", I18N_NOOP("Author"), "*****@*****.**"); aboutData.addCredit("Kurt V. Hindenburg", I18N_NOOP("bug fixing and improvements"), "*****@*****.**"); aboutData.addCredit("Waldo Bastian", I18N_NOOP("bug fixing and improvements"), "*****@*****.**"); aboutData.addCredit("Stephan Binner", I18N_NOOP("bug fixing and improvements"), "*****@*****.**"); aboutData.addCredit("Chris Machemer", I18N_NOOP("bug fixing"), "*****@*****.**"); aboutData.addCredit("Stephan Kulow", I18N_NOOP("Solaris support and work on history"), "*****@*****.**"); aboutData.addCredit("Alexander Neundorf", I18N_NOOP("faster startup, bug fixing"), "*****@*****.**"); aboutData.addCredit("Peter Silva", I18N_NOOP("decent marking"), "*****@*****.**"); aboutData.addCredit("Lotzi Boloni", I18N_NOOP("partification\n" "Toolbar and session names"), "*****@*****.**"); aboutData.addCredit("David Faure", I18N_NOOP("partification\n" "overall improvements"), "*****@*****.**"); aboutData.addCredit("Antonio Larrosa", I18N_NOOP("transparency"), "*****@*****.**"); aboutData.addCredit("Matthias Ettrich", I18N_NOOP("most of main.C donated via kvt\n" "overall improvements"), "*****@*****.**"); aboutData.addCredit("Warwick Allison", I18N_NOOP("schema and selection improvements"), "*****@*****.**"); aboutData.addCredit("Dan Pilone", I18N_NOOP("SGI Port"), "*****@*****.**"); aboutData.addCredit("Kevin Street", I18N_NOOP("FreeBSD port"), "*****@*****.**"); aboutData.addCredit("Sven Fischer", I18N_NOOP("bug fixing"), "*****@*****.**"); aboutData.addCredit("Dale M. Flaven", I18N_NOOP("bug fixing"), "*****@*****.**"); aboutData.addCredit("Martin Jones", I18N_NOOP("bug fixing"), "*****@*****.**"); aboutData.addCredit("Lars Knoll", I18N_NOOP("bug fixing"), "*****@*****.**"); aboutData.addCredit("", I18N_NOOP("Thanks to many others.\n" "The above list only reflects the contributors\n" "I managed to keep track of.")); KCmdLineArgs::init(argc, argv, &aboutData); KCmdLineArgs::addCmdLineOptions(options); // Add our own options. // 1.53 sec KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); KCmdLineArgs *qtargs = KCmdLineArgs::parsedArgs("qt"); has_noxft = !args->isSet("xft"); TEWidget::setAntialias(!has_noxft); TEWidget::setStandalone(true); // The following Qt options have no effect; warn users. if(qtargs->isSet("background")) kdWarning() << "The Qt option -bg, --background has no effect." << endl; if(qtargs->isSet("foreground")) kdWarning() << "The Qt option -fg, --foreground has no effect." << endl; if(qtargs->isSet("button")) kdWarning() << "The Qt option -btn, --button has no effect." << endl; if(qtargs->isSet("font")) kdWarning() << "The Qt option -fn, --font has no effect." << endl; KApplication *a = NULL; #ifdef COMPOSITE if(args->isSet("real-transparency")) { char *display = 0; if(qtargs->isSet("display")) display = qtargs->getOption("display").data(); Display *dpy = XOpenDisplay(display); if(!dpy) { kdError() << "cannot connect to X server " << display << endl; exit(1); } int screen = DefaultScreen(dpy); Colormap colormap = 0; Visual *visual = 0; int event_base, error_base; if(XRenderQueryExtension(dpy, &event_base, &error_base)) { int nvi; XVisualInfo templ; templ.screen = screen; templ.depth = 32; templ.c_class = TrueColor; XVisualInfo *xvi = XGetVisualInfo(dpy, VisualScreenMask | VisualDepthMask | VisualClassMask, &templ, &nvi); for(int i = 0; i < nvi; i++) { XRenderPictFormat *format = XRenderFindVisualFormat(dpy, xvi[i].visual); if(format->type == PictTypeDirect && format->direct.alphaMask) { visual = xvi[i].visual; colormap = XCreateColormap(dpy, RootWindow(dpy, screen), visual, AllocNone); kdDebug() << "found visual with alpha support" << endl; argb_visual = true; break; } } } // The QApplication ctor used is normally intended for applications not using Qt // as the primary toolkit (e.g. Motif apps also using Qt), with some slightly // unpleasant side effects (e.g. #83974). This code checks if qt-copy patch #0078 // is applied, which allows turning this off. bool *qt_no_foreign_hack = static_cast< bool * >(dlsym(RTLD_DEFAULT, "qt_no_foreign_hack")); if(qt_no_foreign_hack) *qt_no_foreign_hack = true; // else argb_visual = false ... ? *shrug* if(argb_visual) a = new KApplication(dpy, Qt::HANDLE(visual), Qt::HANDLE(colormap)); else XCloseDisplay(dpy); } if(a == NULL) a = new KApplication; #else KApplication *a = new KApplication; #endif QString dataPathBase = KStandardDirs::kde_default("data").append("konsole/"); KGlobal::dirs()->addResourceType("wallpaper", dataPathBase + "wallpapers"); KImageIO::registerFormats(); // add io for additional image formats // 2.1 secs QString title; if(args->isSet("T")) { title = QFile::decodeName(args->getOption("T")); } if(qtargs->isSet("title")) { title = QFile::decodeName(qtargs->getOption("title")); } QString term = ""; if(args->isSet("tn")) { term = QString::fromLatin1(args->getOption("tn")); } login_shell = args->isSet("ls"); QStrList eargs; const char *shell = 0; if(!args->getOption("e").isEmpty()) { if(args->isSet("ls")) KCmdLineArgs::usage(i18n("You can't use BOTH -ls and -e.\n")); shell = strdup(args->getOption("e")); eargs.append(shell); for(int i = 0; i < args->count(); i++) eargs.append(args->arg(i)); if(title.isEmpty() && (kapp->caption() == kapp->aboutData()->programName())) { title = QFile::decodeName(shell); // program executed in the title bar } showtip = false; } QCString sz = ""; sz = args->getOption("vt_sz"); histon = args->isSet("hist"); menubaron = args->isSet("menubar"); tabbaron = args->isSet("tabbar") && args->isSet("toolbar"); frameon = args->isSet("frame"); scrollbaron = args->isSet("scrollbar"); QCString wname = qtargs->getOption("name"); full_script = args->isSet("script"); auto_close = args->isSet("close"); fixed_size = !args->isSet("resize"); if(!full_script) a->dcopClient()->setQtBridgeEnabled(false); QCString type = ""; if(args->isSet("type")) { type = args->getOption("type"); } if(args->isSet("types")) { QStringList types = KGlobal::dirs()->findAllResources("appdata", "*.desktop", false, true); types.sort(); for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it) { QString file = *it; file = file.mid(file.findRev('/') + 1); if(file.endsWith(".desktop")) file = file.left(file.length() - 8); printf("%s\n", QFile::encodeName(file).data()); } return 0; } if(args->isSet("schemas") || args->isSet("schemata")) { ColorSchemaList colors; colors.checkSchemas(); for(int i = 0; i < (int)colors.count(); i++) { ColorSchema *schema = colors.find(i); QString relPath = schema->relPath(); if(!relPath.isEmpty()) printf("%s\n", QFile::encodeName(relPath).data()); } return 0; } if(args->isSet("keytabs")) { QStringList lst = KGlobal::dirs()->findAllResources("data", "konsole/*.keytab"); printf("default\n"); // 'buildin' keytab lst.sort(); for(QStringList::Iterator it = lst.begin(); it != lst.end(); ++it) { QFileInfo fi(*it); QString file = fi.baseName(); printf("%s\n", QFile::encodeName(file).data()); } return 0; } QString workDir = QFile::decodeName(args->getOption("workdir")); QString keytab = ""; if(args->isSet("keytab")) keytab = QFile::decodeName(args->getOption("keytab")); QString schema = ""; if(args->isSet("schema")) schema = args->getOption("schema"); KConfig *sessionconfig = 0; QString profile = ""; if(args->isSet("profile")) { profile = args->getOption("profile"); QString path = locate("data", "konsole/profiles/" + profile); if(QFile::exists(path)) sessionconfig = new KConfig(path, true); else profile = ""; } if(args->isSet("profiles")) { QStringList profiles = KGlobal::dirs()->findAllResources("data", "konsole/profiles/*", false, true); profiles.sort(); for(QStringList::ConstIterator it = profiles.begin(); it != profiles.end(); ++it) { QString file = *it; file = file.mid(file.findRev('/') + 1); printf("%s\n", QFile::encodeName(file).data()); } return 0; } // FIXME: more: font args->clear(); int c = 0, l = 0; if(!sz.isEmpty()) { char *ls = (char *)strchr(sz.data(), 'x'); if(ls != NULL) { *ls = '\0'; ls++; c = atoi(sz.data()); l = atoi(ls); } else { KCmdLineArgs::usage(i18n("expected --vt_sz <#columns>x<#lines> e.g. 80x40\n")); } } if(!kapp->authorizeKAction("size")) fixed_size = true; // /////////////////////////////////////////////// // Ignore SIGHUP so that we don't get killed when // our parent-shell gets closed. signal(SIGHUP, SIG_IGN); putenv((char *)"COLORTERM="); // to trigger mc's color detection KonsoleSessionManaged ksm; if(a->isRestored() || !profile.isEmpty()) { if(!shell) shell = konsole_shell(eargs); if(profile.isEmpty()) sessionconfig = a->sessionConfig(); sessionconfig->setDesktopGroup(); int n = 1; QString key; QString sTitle; QString sPgm; QString sTerm; QString sIcon; QString sCwd; int n_tabbar; // TODO: Session management stores everything in same group, // should use one group / mainwindow while(KMainWindow::canBeRestored(n) || !profile.isEmpty()) { sessionconfig->setGroup(QString("%1").arg(n)); if(!sessionconfig->hasKey("Pgm0")) sessionconfig->setDesktopGroup(); // Backwards compatible int session_count = sessionconfig->readNumEntry("numSes"); int counter = 0; wname = sessionconfig->readEntry("class", wname).latin1(); sPgm = sessionconfig->readEntry("Pgm0", shell); sessionconfig->readListEntry("Args0", eargs); sTitle = sessionconfig->readEntry("Title0", title); sTerm = sessionconfig->readEntry("Term0"); sIcon = sessionconfig->readEntry("Icon0", "konsole"); sCwd = sessionconfig->readPathEntry("Cwd0"); workDir = sessionconfig->readPathEntry("workdir"); n_tabbar = QMIN(sessionconfig->readUnsignedNumEntry("tabbar", Konsole::TabBottom), 2); Konsole *m = new Konsole(wname, histon, menubaron, tabbaron, frameon, scrollbaron, 0 /*type*/, true, n_tabbar, workDir); m->newSession(sPgm, eargs, sTerm, sIcon, sTitle, sCwd); m->enableFullScripting(full_script); m->enableFixedSize(fixed_size); m->restore(n); sessionconfig->setGroup(QString("%1").arg(n)); if(!sessionconfig->hasKey("Pgm0")) sessionconfig->setDesktopGroup(); // Backwards compatible m->makeGUI(); m->setEncoding(sessionconfig->readNumEntry("Encoding0")); m->setSchema(sessionconfig->readEntry("Schema0")); // Use konsolerc default as tmpFont instead? QFont tmpFont = KGlobalSettings::fixedFont(); m->initSessionFont(sessionconfig->readFontEntry("SessionFont0", &tmpFont)); m->initSessionKeyTab(sessionconfig->readEntry("KeyTab0")); m->initMonitorActivity(sessionconfig->readBoolEntry("MonitorActivity0", false)); m->initMonitorSilence(sessionconfig->readBoolEntry("MonitorSilence0", false)); m->initMasterMode(sessionconfig->readBoolEntry("MasterMode0", false)); m->initTabColor(sessionconfig->readColorEntry("TabColor0")); // -1 will be changed to the default history in konsolerc m->initHistory(sessionconfig->readNumEntry("History0", -1), sessionconfig->readBoolEntry("HistoryEnabled0", true)); counter++; // show() before 2nd+ sessions are created allows --profile to // initialize the TE size correctly. m->show(); while(counter < session_count) { key = QString("Title%1").arg(counter); sTitle = sessionconfig->readEntry(key, title); key = QString("Args%1").arg(counter); sessionconfig->readListEntry(key, eargs); key = QString("Pgm%1").arg(counter); // if the -e option is passed on the command line, this overrides the program specified // in the profile file if(args->isSet("e")) sPgm = (shell ? QFile::decodeName(shell) : QString::null); else sPgm = sessionconfig->readEntry(key, shell); key = QString("Term%1").arg(counter); sTerm = sessionconfig->readEntry(key); key = QString("Icon%1").arg(counter); sIcon = sessionconfig->readEntry(key, "konsole"); key = QString("Cwd%1").arg(counter); sCwd = sessionconfig->readPathEntry(key); m->newSession(sPgm, eargs, sTerm, sIcon, sTitle, sCwd); m->setSessionTitle(sTitle); // Use title as is key = QString("Schema%1").arg(counter); m->setSchema(sessionconfig->readEntry(key)); key = QString("Encoding%1").arg(counter); m->setEncoding(sessionconfig->readNumEntry(key)); key = QString("SessionFont%1").arg(counter); QFont tmpFont = KGlobalSettings::fixedFont(); m->initSessionFont(sessionconfig->readFontEntry(key, &tmpFont)); key = QString("KeyTab%1").arg(counter); m->initSessionKeyTab(sessionconfig->readEntry(key)); key = QString("MonitorActivity%1").arg(counter); m->initMonitorActivity(sessionconfig->readBoolEntry(key, false)); key = QString("MonitorSilence%1").arg(counter); m->initMonitorSilence(sessionconfig->readBoolEntry(key, false)); key = QString("MasterMode%1").arg(counter); m->initMasterMode(sessionconfig->readBoolEntry(key, false)); key = QString("TabColor%1").arg(counter); m->initTabColor(sessionconfig->readColorEntry(key)); // -1 will be changed to the default history in konsolerc key = QString("History%1").arg(counter); QString key2 = QString("HistoryEnabled%1").arg(counter); m->initHistory(sessionconfig->readNumEntry(key, -1), sessionconfig->readBoolEntry(key2, true)); counter++; } m->setDefaultSession(sessionconfig->readEntry("DefaultSession", "shell.desktop")); m->initFullScreen(); if(!profile.isEmpty()) { m->callReadPropertiesInternal(sessionconfig, 1); profile = ""; // Hack to work-around sessions initialized with minimum size for(int i = 0; i < counter; i++) m->activateSession(i); m->setColLin(c, l); // will use default height and width if called with (0,0) } // works only for the first one, but there won't be more. n++; m->activateSession(sessionconfig->readNumEntry("ActiveSession", 0)); m->setAutoClose(auto_close); } } else { Konsole *m = new Konsole(wname, histon, menubaron, tabbaron, frameon, scrollbaron, type, false, 0, workDir); m->newSession((shell ? QFile::decodeName(shell) : QString::null), eargs, term, QString::null, title, workDir); m->enableFullScripting(full_script); m->enableFixedSize(fixed_size); // 3.8 :-( // exit(0); if(!keytab.isEmpty()) m->initSessionKeyTab(keytab); if(!schema.isEmpty()) { if(schema.right(7) != ".schema") schema += ".schema"; m->setSchema(schema); m->activateSession(0); // Fixes BR83162, transp. schema + notabbar } m->setColLin(c, l); // will use default height and width if called with (0,0) m->initFullScreen(); m->show(); if(showtip) m->showTipOnStart(); m->setAutoClose(auto_close); } int ret = a->exec(); //// Temporary code, waiting for Qt to do this properly // Delete all toplevel widgets that have WDestructiveClose QWidgetList *list = QApplication::topLevelWidgets(); // remove all toplevel widgets that have a parent (i.e. they // got WTopLevel explicitly), they'll be deleted by the parent list->first(); while(list->current()) { if(list->current()->parentWidget() != NULL || !list->current()->testWFlags(Qt::WDestructiveClose)) { list->remove(); continue; } list->next(); } QWidgetListIt it(*list); QWidget *w; while((w = it.current()) != 0) { ++it; delete w; } delete list; delete a; return ret; }
/* * Constructor */ PingDlg::PingDlg(QString commandName, QWidget* parent, const char* name) : CommandDlg(commandName, parent, name) { KConfig *kc = kapp->getConfig(); layout1 = new QBoxLayout(commandBinOK, QBoxLayout::TopToBottom, SEPARATION); CHECK_PTR(layout1); layout2 = new QBoxLayout(QBoxLayout::LeftToRight, SEPARATION); CHECK_PTR(layout2); layout1->addLayout(layout2, 0); // Frame for options frame1 = new QFrame(commandBinOK, "frame_1"); CHECK_PTR(frame1); frame1->setFrameStyle(QFrame::Box | QFrame::Sunken); layout1->addWidget(frame1, 0); layout3 = new QBoxLayout(frame1, QBoxLayout::LeftToRight, SEPARATION/2); CHECK_PTR(layout3); // Make the layout of CommandDlg layout2->addWidget(commandLbl1); layout2->addWidget(commandArgs); layout2->addSpacing(2*SEPARATION); layout2->addWidget(commandGoBtn); layout2->addWidget(commandStopBtn); // Layout of options layout3->addStretch(10); pingCb1 = new QCheckBox(i18n("Make host &name resolution"), frame1, "cb_1"); pingCb1->setChecked(TRUE); pingCb1->adjustSize(); pingCb1->setFixedSize(pingCb1->width(), 2*fontMetrics().height()); layout3->addWidget(pingCb1, 0); layout3->addStretch(10); layout3->activate(); layout1->addWidget(commandTextArea, 10); layout1->activate(); /* * Look at the command binary to see which widget to display */ kc->setGroup(configGroupName); if (!kc->hasKey("path")) { // It's the first execution, // so we have to search for the pathname kc->writeEntry("path", commandName); checkBinaryAndDisplayWidget(); if (commandFound) { // All is OK : we can enable this tab. if (!kc->hasKey("enable")) { kc->writeEntry("enable", 1); } } } else { checkBinaryAndDisplayWidget(); } // Commit changes in configfile (if needed) kc->sync(); }
void kPanel::readInConfiguration(){ KConfig *config = KApplication::getKApplication()->getConfig(); config->setGroup("kpanelButtons"); QStrList button; QStrList buttondelta; QString button_entry_value; config->readListEntry("Buttons", button); QString a; config->readListEntry("ButtonDelta", buttondelta); float x; float y; float real_space; if (orientation == vertical){ real_space = height() - bound_bottom_right + bound_top_left - panel_button->y() - panel_button->height(); x = margin; y = panel_button->y() + panel_button->height(); } else{ real_space = width() - bound_bottom_right + bound_top_left - panel_button->x() - panel_button->width(); y = margin; x = panel_button->x() + panel_button->width(); } int num = -1; float delta = 0; QString tmp; int control = 1; float controldelta = -1; if (config->hasKey("control")) control = config->readNumEntry("control"); if (config->hasKey("controldelta")) controldelta = QString(config->readEntry("controldelta")).toFloat(); if (controldelta >= 0){ bound_top_left = 0; bound_bottom_right = 0; } while (num < 0 || !button_entry_value.isNull()){ if (num>=0){ if (button_entry_value == "system"){ // the unremovable kde_button! if (orientation == horizontal){ kde_button->move((int)(x + delta * real_space / 10000) , (int)y); x = kde_button->x() + kde_button->width(); } else { kde_button->move((int)x, (int)(y + delta * real_space / 10000)); y = kde_button->y() + kde_button->height(); } } else { if (orientation == horizontal) x += delta * real_space / 10000; else y +=delta * real_space / 10000; PMenuItem* pmi = 0; bool buttonAdded = false; if (button_entry_value == "windowlist"){ addButtonInternal(0, (int)x, (int)y, "windowlist"); buttonAdded = true; has_windowlist_button = true; } // --sven: kdisknav button start -- else if (button_entry_value == "kdisknav"){ addButtonInternal(0, (int)x, (int)y, "kdisknav"); buttonAdded = true; has_kdisknav_button = true; } // --sven: kdisknav button end -- else { pmi = pmenu->searchItem( button_entry_value); if (pmi){ addButtonInternal(pmi, (int)x, (int)y); buttonAdded = true; } } if (buttonAdded){ if (orientation == horizontal) x += entries[nbuttons-1].button->width(); else y += entries[nbuttons-1].button->height(); } } } if (num >= control && controldelta>=0){ if (orientation == horizontal){ control_group->move((int)(x + controldelta * real_space / 10000), control_group->y()); if (control_group->x() + control_group->width() > width()) control_group->move(width() - control_group->width(), (int)y); bound_top_left = control_group->x(); bound_bottom_right = control_group->x() + control_group->width(); x = bound_bottom_right; } else { control_group->move(control_group->x(), (int)(y + controldelta * real_space / 10000)); if (control_group->y() + control_group->height() > height()) control_group->move((int)x, height() - control_group->height()); bound_top_left = control_group->y(); bound_bottom_right = control_group->y() + control_group->height(); y = bound_bottom_right; } controldelta = -1; } num++; if (num == 0){ button_entry_value = button.first(); tmp = buttondelta.first(); delta = tmp.isNull()?0:tmp.toFloat(); } else { button_entry_value = button.next(); tmp = buttondelta.next(); delta = tmp.isNull()?0:tmp.toFloat(); } } // kdisknav config->setGroup("kdisknav"); if (config->hasKey("MaxRecentFoldersEntries")) max_recent_folders_entries = config->readEntry("MaxRecentFoldersEntries").toUInt(); else { // config->writeEntry("MaxRecentFoldersEntries", 4); max_recent_folders_entries = 4; } if (config->hasKey("MaxRecentFilesEntries")) max_recent_files_entries = config->readEntry("MaxRecentFilesEntries").toUInt(); else { // config->writeEntry("MaxRecentFilesEntries", 4); max_recent_files_entries = 4; } if (config->hasKey("MaxNavigableFolderEntries")) max_navigable_folder_entries = config->readEntry("MaxNavigableFolderEntries").toUInt(); else { // config->writeEntry("MaxNavigableFolderEntries", 200); max_navigable_folder_entries = 200; } if (config->hasKey("ShowDotFiles")) show_dot_files = (config->readEntry("ShowDotFiles") == "on"); else { // config->writeEntry("ShowDotFiles", "off"); show_dot_files = false; } if (config->hasKey("IgnoreCase")) ignore_case = (config->readEntry("IgnoreCase") == "on"); else { // config->writeEntry("IgnoreCase", "off"); ignore_case = false; } if (config->hasKey("RecentFolders")) config->readListEntry("RecentFolders", recent_folders); if (config->hasKey("RecentFiles")) config->readListEntry("RecentFiles", recent_files); if (config->hasKey("ShowGlobalSection")) show_shared_section = (config->readEntry("ShowGlobalSection") == "on"); else show_shared_section = true; if (config->hasKey("ShowLocalSection")) show_personal_section = (config->readEntry("ShowLocalSection") == "on"); else { show_personal_section = true; } if (config->hasKey("ShowRecentSection")) show_recent_section = (config->readEntry("ShowRecentSection") == "on"); else { show_recent_section = true; } if (config->hasKey("ShowOptionEntry")) show_option_entry = (config->readEntry("ShowOptionEntry") == "on"); else { show_option_entry = true; } }
void KMDITitleLabel::readConfiguration(){ KConfig* config; QString key; // int i; killTimers(); config = new("KConfig") KConfig(KApplication::kde_configdir() + "/kwmrc", KApplication::localconfigdir() + "/kwmrc"); // this belongs in kapp.... config->setGroup("WM"); activeTitleBlend = config->readColorEntry( "activeBlend",&black); inactiveTitleBlend = config->readColorEntry( "inactiveBlend",&kapp->backgroundColor); config->setGroup( "General" ); //BORDER = 4; key = config->readEntry("WindowMoveType"); if( key == "Transparent") options.WindowMoveType = TRANSPARENT; else if( key == "Opaque") options.WindowMoveType = OPAQUE; else{ config->writeEntry("WindowMoveType","Transparent"); options.WindowMoveType = TRANSPARENT; } key = config->readEntry("WindowResizeType"); if( key == "Transparent") options.WindowResizeType = TRANSPARENT; else if( key == "Opaque") options.WindowResizeType = OPAQUE; else{ config->writeEntry("WindowResizeType","Transparent"); options.WindowResizeType = TRANSPARENT; } key = config->readEntry("FocusPolicy"); if( key == "ClickToFocus") options.FocusPolicy = CLICK_TO_FOCUS; else if( key == "FocusFollowsMouse" || key == "FocusFollowMouse") options.FocusPolicy = FOCUS_FOLLOWS_MOUSE; else if( key == "ClassicFocusFollowsMouse" || key == "ClassicFocusFollowMouse") options.FocusPolicy = CLASSIC_FOCUS_FOLLOWS_MOUSE; else if( key == "ClassicSloppyFocus") options.FocusPolicy = CLASSIC_SLOPPY_FOCUS; else{ config->writeEntry("FocusPolicy","ClickToFocus"); options.FocusPolicy = CLICK_TO_FOCUS; } key = config->readEntry("AltTabMode"); if( key == "KDE") options.AltTabMode = KDE_STYLE; else if( key == "CDE") options.AltTabMode = CDE_STYLE; else{ config->writeEntry("AltTabMode","KDE"); options.AltTabMode = KDE_STYLE; } if (CLASSIC_FOCUS) options.AltTabMode = CDE_STYLE; key = config->readEntry("TitlebarLook"); if( key == "shadedHorizontal") options.TitlebarLook = H_SHADED; else if( key == "shadedVertical") options.TitlebarLook = V_SHADED; else if( key == "plain") options.TitlebarLook = PLAIN; else if( key == "pixmap") options.TitlebarLook = PIXMAP; else{ config->writeEntry("TitlebarLook", "shadedHorizontal"); options.TitlebarLook = H_SHADED; } //CT 23Sep1998 - fixed the name of the titlebar pixmaps to become // consistent with the buttons pixmaps definition technique if (options.TitlebarLook == PIXMAP) { *options.titlebarPixmapActive = loadIcon("activetitlebar.xpm"); *options.titlebarPixmapInactive = loadIcon("inactivetitlebar.xpm"); if (options.titlebarPixmapInactive->size() == QSize(0,0)) *options.titlebarPixmapInactive = *options.titlebarPixmapActive; if (options.titlebarPixmapActive->size() == QSize(0,0)) options.TitlebarLook = PLAIN; } //CT 12Jun1998 - variable animation speed from 0 (none!!) to 10 (max) if (config->hasKey("ResizeAnimation")) { options.ResizeAnimation = config->readNumEntry("ResizeAnimation"); if( options.ResizeAnimation < 1 ) options.ResizeAnimation = 0; if( options.ResizeAnimation > 10 ) options.ResizeAnimation = 10; } else{ options.ResizeAnimation = 1; config->writeEntry("ResizeAnimation", options.ResizeAnimation); } config->sync(); delete config; }
Kopete::Away::Away() : QObject( kapp , "Kopete::Away") { int dummy = 0; dummy = dummy; // shut up d = new KopeteAwayPrivate; // Set up the away messages d->awayMessage = QString::null; d->autoAwayMessage = QString::null; d->useAutoAwayMessage = false; d->globalAway = false; d->autoaway = false; d->useAutoAway = true; // Empty the list d->awayMessageList.clear(); // set the XAutoLock info #ifdef Q_WS_X11 Display *dsp = qt_xdisplay(); #endif d->mouse_x = d->mouse_y=0; d->mouse_mask = 0; #ifdef Q_WS_X11 d->root = DefaultRootWindow (dsp); d->screen = ScreenOfDisplay (dsp, DefaultScreen (dsp)); #endif d->useXidle = false; d->useMit = false; #ifdef HasXidle d->useXidle = XidleQueryExtension(qt_xdisplay(), &dummy, &dummy); #endif #ifdef HasScreenSaver if(!d->useXidle) d->useMit = XScreenSaverQueryExtension(qt_xdisplay(), &dummy, &dummy); #endif #ifdef Q_WS_X11 d->xIdleTime = 0; #endif kdDebug(14010) << k_funcinfo << "Idle detection methods:" << endl; kdDebug(14010) << k_funcinfo << "\tKScreensaverIface::isBlanked()" << endl; #ifdef Q_WS_X11 kdDebug(14010) << k_funcinfo << "\tX11 XQueryPointer()" << endl; #endif if (d->useXidle) { kdDebug(14010) << k_funcinfo << "\tX11 Xidle extension" << endl; } if (d->useMit) { kdDebug(14010) << k_funcinfo << "\tX11 MIT Screensaver extension" << endl; } load(); KSettings::Dispatcher::self()->registerInstance( KGlobal::instance(), this, SLOT( load() ) ); // Set up the config object KConfig *config = KGlobal::config(); /* Load the saved away messages */ config->setGroup("Away Messages"); // Away Messages if(config->hasKey("Messages")) { d->awayMessageList = config->readListEntry("Messages"); } else if(config->hasKey("Titles")) // Old config format { QStringList titles = config->readListEntry("Titles"); // Get the titles for(QStringList::iterator i = titles.begin(); i != titles.end(); ++i) { d->awayMessageList.append( config->readEntry(*i) ); // And add it to the list } /* Save this list to disk */ save(); } else { d->awayMessageList.append( i18n( "Sorry, I am busy right now" ) ); d->awayMessageList.append( i18n( "I am gone right now, but I will be back later" ) ); /* Save this list to disk */ save(); } // Auto away message if(config->hasKey("AutoAwayMessage")) { d->autoAwayMessage = config->readEntry("AutoAwayMessage"); } else { d->autoAwayMessage = i18n( "I am gone right now, but I will be back later" ); // Save the default auto away message to disk save(); } // init the timer d->timer = new QTimer(this, "AwayTimer"); connect(d->timer, SIGNAL(timeout()), this, SLOT(slotTimerTimeout())); d->timer->start(4000); //init the time and other setActive(); }
/****************************************************************************** * If the preferences were written by a previous version of KAlarm, do any * necessary conversions. */ void Preferences::convertOldPrefs() { KConfig *config = KGlobal::config(); config->setGroup(GENERAL_SECTION); int version = KAlarm::getVersionNumber(config->readEntry(VERSION_NUM)); if(version >= KAlarm::Version(1, 4, 22)) return; // config format is up to date if(version <= KAlarm::Version(1, 4, 21)) { // Convert KAlarm 1.4.21 preferences static const QString OLD_REMIND_UNITS = QString::fromLatin1("DefRemindUnits"); config->setGroup(DEFAULTS_SECTION); int intUnit = config->readNumEntry(OLD_REMIND_UNITS, 0); QString strUnit = (intUnit == 1) ? QString::fromLatin1("Days") : (intUnit == 2) ? QString::fromLatin1("Weeks") : QString::fromLatin1("HoursMinutes"); config->deleteEntry(OLD_REMIND_UNITS); config->writeEntry(DEF_REMIND_UNITS, strUnit); } if(version <= KAlarm::Version(1, 4, 20)) { // Convert KAlarm 1.4.20 preferences static const QString VIEW_SECTION = QString::fromLatin1("View"); static const QString SHOW_ARCHIVED_ALARMS = QString::fromLatin1("ShowArchivedAlarms"); static const QString SHOW_EXPIRED_ALARMS = QString::fromLatin1("ShowExpiredAlarms"); static const QString SHOW_ALARM_TIME = QString::fromLatin1("ShowAlarmTime"); static const QString SHOW_TIME_TO_ALARM = QString::fromLatin1("ShowTimeToAlarm"); config->setGroup(GENERAL_SECTION); bool showExpired = config->readBoolEntry(SHOW_EXPIRED_ALARMS, false); bool showTime = config->readBoolEntry(SHOW_ALARM_TIME, true); bool showTimeTo = config->readBoolEntry(SHOW_TIME_TO_ALARM, false); config->deleteEntry(SHOW_EXPIRED_ALARMS); config->deleteEntry(SHOW_ALARM_TIME); config->deleteEntry(SHOW_TIME_TO_ALARM); config->setGroup(VIEW_SECTION); config->writeEntry(SHOW_ARCHIVED_ALARMS, showExpired); config->writeEntry(SHOW_ALARM_TIME, showTime); config->writeEntry(SHOW_TIME_TO_ALARM, showTimeTo); } if(version <= KAlarm::Version(1, 4, 5)) { // Convert KAlarm 1.4.5 preferences static const QString DEF_SOUND = QString::fromLatin1("DefSound"); config->setGroup(DEFAULTS_SECTION); bool sound = config->readBoolEntry(DEF_SOUND, false); if(!sound) config->writeEntry(DEF_SOUND_TYPE, SoundPicker::NONE); config->deleteEntry(DEF_SOUND); } if(version < KAlarm::Version(1, 3, 0)) { // Convert KAlarm pre-1.3 preferences static const QString EMAIL_ADDRESS = QString::fromLatin1("EmailAddress"); static const QString EMAIL_USE_CTRL_CENTRE = QString::fromLatin1("EmailUseControlCenter"); static const QString EMAIL_BCC_USE_CTRL_CENTRE = QString::fromLatin1("EmailBccUseControlCenter"); QMap<QString, QString> entries = config->entryMap(GENERAL_SECTION); if(entries.find(EMAIL_FROM) == entries.end() && entries.find(EMAIL_USE_CTRL_CENTRE) != entries.end()) { // Preferences were written by KAlarm pre-1.2.1 config->setGroup(GENERAL_SECTION); bool useCC = false; bool bccUseCC = false; const bool default_emailUseControlCentre = true; const bool default_emailBccUseControlCentre = true; useCC = config->readBoolEntry(EMAIL_USE_CTRL_CENTRE, default_emailUseControlCentre); // EmailBccUseControlCenter was missing in preferences written by KAlarm pre-0.9.5 bccUseCC = config->hasKey(EMAIL_BCC_USE_CTRL_CENTRE) ? config->readBoolEntry(EMAIL_BCC_USE_CTRL_CENTRE, default_emailBccUseControlCentre) : useCC; config->writeEntry(EMAIL_FROM, (useCC ? FROM_CONTROL_CENTRE : config->readEntry(EMAIL_ADDRESS))); config->writeEntry(EMAIL_BCC_ADDRESS, (bccUseCC ? FROM_CONTROL_CENTRE : config->readEntry(EMAIL_BCC_ADDRESS))); config->deleteEntry(EMAIL_ADDRESS); config->deleteEntry(EMAIL_BCC_USE_CTRL_CENTRE); config->deleteEntry(EMAIL_USE_CTRL_CENTRE); } // Convert KAlarm 1.2 preferences static const QString DEF_CMD_XTERM = QString::fromLatin1("DefCmdXterm"); config->setGroup(DEFAULTS_SECTION); if(config->hasKey(DEF_CMD_XTERM)) { config->writeEntry(DEF_CMD_LOG_TYPE, (config->readBoolEntry(DEF_CMD_XTERM, false) ? EditAlarmDlg::EXEC_IN_TERMINAL : EditAlarmDlg::DISCARD_OUTPUT)); config->deleteEntry(DEF_CMD_XTERM); } } config->setGroup(GENERAL_SECTION); config->writeEntry(VERSION_NUM, KALARM_VERSION); config->sync(); }
Kfm::Kfm() { pKfm = this; pHistory = new QStrList; kapp->setTopWidget( this ); HTMLCache::load(); pIconLoader = new KIconLoader(); // We need this in KfmGui::KfmGui(), so moved it here. DF. QStrList* list = pIconLoader->getDirList(); list->clear(); QString tmp = kapp->kde_icondir().copy(); list->append( tmp.data() ); tmp = KApplication::localkdedir(); tmp += "/share/icons"; list->append( tmp.data() ); KConfig *config = kapp->getConfig(); QStrList dirList; config->setGroup("KDE Setup"); config->readListEntry( "IconPath", dirList, ':' ); for (const char *it=dirList.first(); it; it = dirList.next()) { QDir dir( it ); if (dir.exists()) list->append( it ); } if ( KfmGui::rooticons ) { kapp->enableSessionManagement( TRUE ); kapp->setWmCommand( "" ); connect( kapp, SIGNAL( saveYourself() ), this, SLOT( slotSave() ) ); connect( kapp, SIGNAL( shutDown() ), this, SLOT( slotShutDown() ) ); // Global configuration config->setGroup("KFM Misc Defaults"); bAllowURLProps = config->readBoolEntry( "EnablePerURLProps", false ); bTreeViewFollowMode = config->readBoolEntry( "TreeFollowsView", false); config->setGroup( "SM" ); bool flag = config->hasKey( "URLs" ); QStrList urlList; int n = config->readListEntry( "URLs", urlList ); if ( !flag && KfmGui::rooticons == true ) { QString home = "file:"; home.detach(); home += QDir::homeDirPath().data(); KfmGui *m = new KfmGui( 0L, 0L, home.data() ); m->show(); } if ( flag ) { int i; for ( i = 1; i <= n; i++ ) { KfmGui *m = new KfmGui( 0L, 0L, urlList.at( i - 1 ) ); m->readProperties(i); m->show(); } } } // Install HTTP Cookies { KConfig *config = kapp->getConfig(); config->setGroup( "Browser Settings/HTTP" ); bool cookiesEnabled = config->readBoolEntry( "Cookies", true ); if ( cookiesEnabled) { cookiejar = new KCookieJar(); cookiejar->loadConfig( config ); QString cookieFile = kapp->localkdedir().data(); cookieFile += "/share/apps/kfm/cookies"; cookiejar->loadCookies( cookieFile.data() ); } } connect( &timer, SIGNAL( timeout() ), this, SLOT( slotTouch() ) ); // Call every hour timer.start( 3600000 ); }
void TopLevel::config() { if (!confdlg) { confdlg = new KDialogBase(KDialogBase::Plain, i18n("Configure Tea Cooker"), KDialogBase::Ok|KDialogBase::Cancel|KDialogBase::Help, KDialogBase::Ok, this, "config", true); QWidget *page = confdlg->plainPage(); // FIXME: enforce sensible initial/default size of dialog // FIXME: modal is ok, but can avoid always-on-top? QBoxLayout *top_box = new QVBoxLayout(page, 0, 8); // whole config-stuff QBoxLayout *box = new QHBoxLayout(top_box); // list + properties /* left side - tea list and list-modifying buttons */ QBoxLayout *leftside = new QVBoxLayout(box); QGroupBox *listgroup = new QGroupBox(2, Vertical, i18n("Tea List"), page); leftside->addWidget(listgroup, 0, 0); listbox = new QListView(listgroup, "listBox"); listbox->addColumn(i18n("Name")); listbox->header()->setClickEnabled(false, listbox->header()->count()-1); listbox->addColumn(i18n("Time")); listbox->header()->setClickEnabled(false, listbox->header()->count()-1); listbox->setSorting(-1); connect(listbox, SIGNAL(selectionChanged()), SLOT(listBoxItemSelected())); // now buttons for editing the tea-list QWidget *listgroup_widget = new QWidget(listgroup); QBoxLayout *hbox = new QHBoxLayout(listgroup_widget); hbox->setSpacing(4); btn_new = new QPushButton(QString::null, listgroup_widget); QToolTip::add(btn_new, i18n("New")); btn_new->setPixmap(SmallIcon("filenew")); btn_new->setMinimumSize(btn_new->sizeHint() * 1.2); connect(btn_new, SIGNAL(clicked()), SLOT(newButtonClicked())); hbox->addWidget(btn_new); btn_del = new QPushButton(QString::null, listgroup_widget); QToolTip::add(btn_del, i18n("Delete")); btn_del->setIconSet(SmallIconSet("editdelete")); btn_del->setMinimumSize(btn_new->sizeHint() * 1.2); connect(btn_del, SIGNAL(clicked()), SLOT(delButtonClicked())); hbox->addWidget(btn_del); btn_up = new QPushButton(QString::null, listgroup_widget); QToolTip::add(btn_up, i18n("Up")); btn_up->setIconSet(SmallIconSet("up")); btn_up->setMinimumSize(btn_up->sizeHint() * 1.2); connect(btn_up, SIGNAL(clicked()), SLOT(upButtonClicked())); hbox->addWidget(btn_up); btn_down = new QPushButton(QString::null, listgroup_widget); QToolTip::add(btn_down, i18n("Down")); btn_down->setIconSet(SmallIconSet("down")); btn_down->setMinimumSize(btn_down->sizeHint() * 1.2); connect(btn_down, SIGNAL(clicked()), SLOT(downButtonClicked())); hbox->addWidget(btn_down); hbox->addStretch(10); /* right side - tea properties */ QBoxLayout *rightside = new QVBoxLayout(box); editgroup = new QGroupBox(2, Vertical, i18n("Tea Properties"), page); rightside->addWidget(editgroup, 0, 0); QHBox *propbox = new QHBox(editgroup); // FIXME: - must enforce correct vertical alignment of each label-editor pair // (better use one HBox for each label-editor pair?) QVBox *propleft = new QVBox(propbox); QVBox *propright = new QVBox(propbox); nameEdit = new QLineEdit(propright); nameEdit->setFixedHeight(nameEdit->sizeHint().height()); nameEdit->setAlignment(QLineEdit::AlignLeft); QLabel *l = new QLabel(nameEdit, i18n("Name:"), propleft); l->setFixedSize(l->sizeHint()); connect(nameEdit, SIGNAL(textChanged(const QString&)), SLOT(nameEditTextChanged(const QString&)) ); timeEdit = new TimeEdit(propright); timeEdit->setFixedHeight(timeEdit->sizeHint().height()); l = new QLabel(timeEdit, i18n("Tea time:"), propleft); l->setFixedSize(l->sizeHint()); connect(timeEdit, SIGNAL(valueChanged(int)), SLOT(spinBoxValueChanged(int))); /* bottom - timeout actions */ QGroupBox *actiongroup = new QGroupBox(4, Vertical, i18n("Action"), page); top_box->addWidget(actiongroup, 0, 0); QWidget *actionconf_widget = new QWidget(actiongroup); QBoxLayout *actionconf_hbox = new QHBoxLayout(actionconf_widget); btn_conf = new QPushButton(i18n("Configure Events..."), actionconf_widget); actionconf_hbox->addWidget(btn_conf); connect(btn_conf, SIGNAL(clicked()), SLOT(confButtonClicked())); actionconf_hbox->addStretch(10); eventEnable = new QCheckBox(i18n("Event"), actiongroup); popupEnable = new QCheckBox(i18n("Popup"), actiongroup); eventEnable->setFixedHeight(eventEnable->sizeHint().height()); popupEnable->setFixedHeight(popupEnable->sizeHint().height()); QHBox *actionbox = new QHBox(actiongroup); actionEnable = new QCheckBox(actionbox); // FIXME: add text to this line: // QLabel *actionLabel = new QLabel(i18n("Execute: "), actiongroup); actionEdit = new QLineEdit(actionbox); actionEdit->setFixedHeight(actionEdit->sizeHint().height()); QToolTip::add(actionEdit, i18n("Enter command here; '%t' will be replaced with name of steeping tea")); connect(actionEnable, SIGNAL(toggled(bool)), SLOT(actionEnableToggled(bool))); rightside->addStretch(); // single checkbox visEnable = new QCheckBox(i18n("Visualize progress in icon tray"), page); top_box->addWidget(visEnable, 0, 0); // let listbox claim all remaining vertical space top_box->setStretchFactor(box, 10); connect(confdlg, SIGNAL(helpClicked()), SLOT(help())); } // now add all defined teas (and their times) to the listview // this is done backwards because QListViewItems are inserted at the top listbox->clear(); for (int i=teas.count()-1; i>=0; i--) { TeaListItem *item = new TeaListItem(listbox); item->setName(teas[i].name); item->setTime(teas[i].time); if ((unsigned int)i == current_selected) current_item = item; } // select first entry in listbox; if no entries present then disable right side if (listempty) { enable_controls(); disable_properties(); nameEdit->setText(""); timeEdit->setValue(1); } else { listbox->setSelected(listbox->firstChild(), true); } // ------------------------- eventEnable->setChecked(useNotify); popupEnable->setChecked(usePopup); actionEnable->setChecked(useAction); actionEdit->setText(action); actionEdit->setEnabled(useAction); visEnable->setChecked(useTrayVis); if (confdlg->exec() == QDialog::Accepted) { // activate new settings useNotify = eventEnable->isChecked(); usePopup = popupEnable->isChecked(); useAction = actionEnable->isChecked(); action = actionEdit->text(); useTrayVis = visEnable->isChecked(); teas.clear(); // Copy over teas and times from the QListView int i = 0; teas.clear(); teas.resize(listbox->childCount()); for (QListViewItemIterator it(listbox); it.current() != 0; ++it) { teas[i].name = static_cast<TeaListItem *>(it.current())->name(); teas[i].time = static_cast<TeaListItem *>(it.current())->time(); if (it.current() == current_item) current_selected = i; i++; } listempty = (teas.count() == 0); rebuildTeaMenus(); // and store to config KConfig *config = kapp->config(); // remove old-style entries from default-group (if present) if (config->hasKey("UserTea")) config->deleteEntry("UserTea"); config->setGroup("General"); config->writeEntry("Beep", useNotify); config->writeEntry("Popup", usePopup); config->writeEntry("UseAction", useAction); config->writeEntry("Action", action); config->writeEntry("Tea", current_selected); config->writeEntry("UseTrayVis", useTrayVis); // first get rid of all previous tea-entries from config, then write anew config->deleteGroup("Teas", true); // deep remove of whole group config->setGroup("Teas"); config->writeEntry("Number", teas.count()); QString key; int index = 1; for (QValueVector<tea_struct>::ConstIterator it = teas.begin(); it != teas.end(); ++it) { key.sprintf("Tea%d Name", index); config->writeEntry(key, it->name); key.sprintf("Tea%d Time", index); config->writeEntry(key, it->time); index++; } config->sync(); } }
TopLevel::TopLevel() : KSystemTray() { setBackgroundMode(X11ParentRelative); // what for? QString n, key; unsigned int num; teas.clear(); KConfig *config = kapp->config(); config->setGroup("Teas"); if (config->hasKey("Number")) { // assuming this is a new-style config num = config->readNumEntry("Number", 0); teas.resize(num); QString tempstr; for (unsigned int index=1; index<=num; ++index) { key.sprintf("Tea%d Time", index); tempstr = config->readEntry(key, NULL); teas[index-1].time = tempstr.toInt(); key.sprintf("Tea%d Name", index); teas[index-1].name = config->readEntry(key, NULL); // FIXME: check for non-existence! } config->setGroup("General"); } else { // either old-style config or first start, so provide some sensible defaults // (which are the same as in old-style kteatime) tea_struct temp; temp.name = i18n("Black Tea"); temp.time = 180; teas.append(temp); temp.name = i18n("Earl Grey"); temp.time = 300; teas.append(temp); temp.name = i18n("Fruit Tea"); temp.time = 480; teas.append(temp); // switch back to old-style default group config->setGroup(NULL); // look for old-style "UserTea"-entry and add that one also if (config->hasKey("UserTea")) { num = config->readNumEntry("UserTea", 150); temp.name = i18n("Other Tea"); temp.time = num; teas.append(temp); } } current_selected = config->readNumEntry("Tea", 0); if (current_selected >= teas.count()) current_selected = 0; listempty = (teas.count() == 0); startAct = new KAction(i18n("&Start"), "1rightarrow", 0, this, SLOT(start()), actionCollection(), "start"); stopAct = new KAction(i18n("Sto&p"), "cancel", 0, this, SLOT(stop()), actionCollection(), "stop"); confAct = new KAction(i18n("&Configure..."), "configure", 0, this, SLOT(config()), actionCollection(), "configure"); anonAct = new KAction(i18n("&Anonymous..."), 0, 0, this, SLOT(anonymous()), actionCollection(), "anonymous"); // KAction *quitAct = actionCollection()->action("file_quit"); // create app menu (displayed on right-click) menu = new QPopupMenu(); menu->setCheckable(true); connect(menu, SIGNAL(activated(int)), this, SLOT(teaSelected(int))); // this menu will be displayed when no tea is steeping, and left mouse button is clicked start_menu = new QPopupMenu(); start_menu->setCheckable(true); // menu isn't tickable, but this gives some add. spacing connect(start_menu, SIGNAL(activated(int)), this, SLOT(teaStartSelected(int))); rebuildTeaMenus(); // populate tops of menus with tea-entries from config KHelpMenu* help = new KHelpMenu(this, KGlobal::instance()->aboutData(), false); KPopupMenu* helpMnu = help->menu(); start_menu->insertSeparator(); anonAct->plug(start_menu); menu->insertSeparator(); anonAct->plug(menu); startAct->plug(menu); stopAct->plug(menu); menu->insertSeparator(); confAct->plug(menu); menu->insertItem(SmallIcon("help"), i18n("&Help"), helpMnu); menu->insertItem(SmallIcon("exit"), i18n("Quit"), kapp, SLOT(quit())); // quitAct->plug(menu); // FIXME: this doesn't seem to work with above definition of quitAct? // (need special 'quit'-method?) // this menu will be displayed when a tea is steeping, and left mouse button is clicked steeping_menu = new QPopupMenu(); // steeping_menu->insertItem(SmallIcon("cancel"), i18n("Just &Cancel Current"), this, SLOT(stop())); stopAct->plug(steeping_menu); // FIXME: can provide different text for this incarnation? // start_menu->insertSeparator(); // startAct->plug(start_menu); // FIXME: include "start" entry here for quick access to current tea? // read remaining entries from config-file useNotify = config->readBoolEntry("Beep", true); // "Beep" should really be named "Notify" usePopup = config->readBoolEntry("Popup", true); useAction = config->readBoolEntry("UseAction", true); action = config->readEntry("Action"); useTrayVis = config->readBoolEntry("UseTrayVis", true); mugPixmap = loadIcon("mug"); teaNotReadyPixmap = loadIcon("tea_not_ready"); teaAnim1Pixmap = loadIcon("tea_anim1"); teaAnim2Pixmap = loadIcon("tea_anim2"); confdlg = 0L; anondlg = 0L; stop(); // reset timer, disable some menu entries, etc. }