📄 kapp.cpp
字号:
configPath += "/config"; if ( checkAccess(configPath, W_OK) ) { if ( mkdir (configPath.data(), 0700) == 0 ) // make it private chown(configPath.data(), getuid(), getgid()); } } } } } // try to read a global application file QString aGlobalAppConfigName = kde_configdir() + "/" + aAppName + "rc"; QFile aGlobalAppConfigFile( aGlobalAppConfigName ); // try to open read-only bool bSuccess = aGlobalAppConfigFile.open( IO_ReadOnly ); if( !bSuccess ) // there is no global app config file aGlobalAppConfigName = ""; aGlobalAppConfigFile.close(); // now for the local app config file QString aConfigName = KApplication::localkdedir(); aConfigName += "/share/config/"; aConfigName += aAppName; aConfigName += "rc"; QFile aConfigFile( aConfigName ); // We may write to the file if ( ! checkAccess(aConfigName.data(), W_OK ) ) bSuccess = false; else { // Open the application-specific config file. It will be created if // it does not exist yet. bSuccess = aConfigFile.open( IO_ReadWrite ); // Set uid/gid (neccesary for SUID programs) if ( bSuccess ) chown(aConfigFile.name(), getuid(), getgid()); } if( !bSuccess ) { // try to open at least read-only bSuccess = aConfigFile.open( IO_ReadOnly ); if( !bSuccess ) { // we didn't succeed to open an app-config file pConfig = new KConfig( aGlobalAppConfigName ); eConfigState = APPCONFIG_NONE; } else { // we succeeded to open an app-config file read-only pConfig = new KConfig( aGlobalAppConfigName, aConfigName ); eConfigState = APPCONFIG_READONLY; } } else { // we succeeded to open an app-config file read-write pConfig = new KConfig( aGlobalAppConfigName, aConfigName ); eConfigState = APPCONFIG_READWRITE; } pCharsets = new KCharsets(); pLocale = new KLocale(aAppName); bLocaleConstructed = true; // Drag 'n drop stuff taken from kfm display = desktop()->x11Display(); DndSelection = XInternAtom( display, "DndSelection", False ); DndProtocol = XInternAtom( display, "DndProtocol", False ); DndEnterProtocol = XInternAtom( display, "DndEnterProtocol", False ); DndLeaveProtocol = XInternAtom( display, "DndLeaveProtocol", False ); DndRootProtocol = XInternAtom( display, "DndRootProtocol", False ); lastEnteredDropZone = 0L; dropZones.setAutoDelete( FALSE ); // initialize file search paths pSearchPaths = new QStrList(); buildSearchPaths(); WM_SAVE_YOURSELF = XInternAtom( display, "WM_SAVE_YOURSELF", False ); WM_PROTOCOLS = XInternAtom( display, "WM_PROTOCOLS", False ); KDEChangePalette = XInternAtom( display, "KDEChangePalette", False ); KDEChangeGeneral = XInternAtom( display, "KDEChangeGeneral", False ); KDEChangeStyle = XInternAtom( display, "KDEChangeStyle", False); readSettings(); kdisplaySetPalette(); kdisplaySetStyleAndFont(); // install an event filter for KDebug installEventFilter( this ); pSessionConfig = 0L; bIsRestored = False; bSessionManagement = False; bSessionManagementUserDefined = False; pTopWidget = 0L; // register a communication window for desktop changes (Matthias) { Atom a = XInternAtom(qt_xdisplay(), "KDE_DESKTOP_WINDOW", False); QWidget* w = new QWidget(0,0); long data = 1; XChangeProperty(qt_xdisplay(), w->winId(), a, a, 32, PropModeReplace, (unsigned char *)&data, 1); } aWmCommand = argv()[0];}KConfig* KApplication::getSessionConfig() { if (pSessionConfig) return pSessionConfig; // create a instance specific config object QString aConfigName = KApplication::localkdedir(); aConfigName += "/share/config/"; aConfigName += aAppName; aConfigName += "rc"; QString aSessionConfigName; QString num; int i = 0; do { i++; num.setNum(i); aSessionConfigName = aConfigName + "." + num; } while (QFile::exists(aSessionConfigName)); QFile aConfigFile(aSessionConfigName); bool bSuccess; if ( ! checkAccess( aConfigFile.name(), W_OK ) ) bSuccess = false; else { bSuccess = aConfigFile.open( IO_ReadWrite ); } if( bSuccess ){ chown(aConfigFile.name(), getuid(), getgid()); aConfigFile.close(); pSessionConfig = new KConfig(0L, aSessionConfigName); aSessionName = aAppName.copy(); aSessionName += "rc."; aSessionName += num; } return pSessionConfig;}void KApplication::enableSessionManagement(bool userdefined){ bSessionManagement = True; bSessionManagementUserDefined = userdefined; if (topWidget()){ KWM::enableSessionManagement(topWidget()->winId()); }}void KApplication::setWmCommand(const char* s){ aWmCommand = s; if (topWidget() && !bSessionManagement) KWM::setWmCommand( topWidget()->winId(), aWmCommand);}KIconLoader* KApplication::getIconLoader(){ if( !pIconLoader ) pIconLoader = new KIconLoader(); return pIconLoader;}QPopupMenu* KApplication::getHelpMenu( bool /*bAboutQtMenu*/, const char* aboutAppText ){ QPopupMenu* pMenu = new QPopupMenu(); int id = pMenu->insertItem( klocale->translate( "&Contents" ) ); pMenu->connectItem( id, this, SLOT( appHelpActivated() ) ); pMenu->setAccel( Key_F1, id ); pMenu->insertSeparator(); id = pMenu->insertItem( QString(klocale->translate( "&About" )) + " " + aAppName + "..."); if( aboutAppText ) { pMenu->connectItem( id, this, SLOT( aboutApp() ) ); aAppAboutString = aboutAppText; } id = pMenu->insertItem( klocale->translate( "About &KDE..." ) ); pMenu->connectItem( id, this, SLOT( aboutKDE() ) ); /* if( bAboutQtMenu ) { id = pMenu->insertItem( klocale->translate( "About Qt" ) ); pMenu->connectItem( id, this, SLOT( aboutQt() ) ); } */ return pMenu;}void KApplication::appHelpActivated(){ invokeHTMLHelp( aAppName + "/" + "index.html", "" );}void KApplication::aboutKDE(){ QMessageBox::about( 0L, klocale->translate( "About KDE" ), klocale->translate("\nThe KDE Desktop Environment was written by the KDE Team,\n""a world-wide network of software engineers committed to\n""free software development.\n\n""Visit http://www.kde.org for more information on the KDE\n""Project. Please consider joining and supporting KDE.\n\n""Please report bugs at http://bugs.kde.org.\n"));}void KApplication::aboutApp(){ QMessageBox::about( 0L, getCaption(), aAppAboutString );}void KApplication::aboutQt(){ // QMessageBox::aboutQt( NULL, getCaption() );}KLocale* KApplication::getLocale(){ if( !pLocale ) pLocale = new KLocale(); return pLocale;}bool KApplication::eventFilter ( QObject*, QEvent* e ){ if ( e->type() == Event_KeyPress ) { QKeyEvent *k = (QKeyEvent*)e; if( ( k->key() == Key_F12 ) && ( k->state() & ControlButton ) && ( k->state() & ShiftButton ) ) { KDebugDialog* pDialog = new KDebugDialog(); /* Fill dialog fields with values from config data */ KConfig* pConfig = getConfig(); QString aOldGroup = pConfig->getGroup(); pConfig->setGroup( "KDebug" ); pDialog->setInfoOutput( pConfig->readNumEntry( "InfoOutput", 4 ) ); pDialog->setInfoFile( pConfig->readEntry( "InfoFilename", "kdebug.dbg" ) ); pDialog->setInfoShow( pConfig->readEntry( "InfoShow", "" ) ); pDialog->setWarnOutput( pConfig->readNumEntry( "WarnOutput", 4 ) ); pDialog->setWarnFile( pConfig->readEntry( "WarnFilename", "kdebug.dbg" ) ); pDialog->setWarnShow( pConfig->readEntry( "WarnShow", "" ) ); pDialog->setErrorOutput( pConfig->readNumEntry( "ErrorOutput", 4 ) ); pDialog->setErrorFile( pConfig->readEntry( "ErrorFilename", "kdebug.dbg" ) ); pDialog->setErrorShow( pConfig->readEntry( "ErrorShow", "" ) ); pDialog->setFatalOutput( pConfig->readNumEntry( "FatalOutput", 4 ) ); pDialog->setFatalFile( pConfig->readEntry( "FatalFilename", "kdebug.dbg" ) ); pDialog->setFatalShow( pConfig->readEntry( "FatalShow", "" ) ); pDialog->setAbortFatal( pConfig->readNumEntry( "AbortFatal", 0 ) ); /* Show dialog */ int nRet = pDialog->exec(); if( nRet == QDialog::Accepted ) { /* User pressed OK, retrieve values */ pConfig->writeEntry( "InfoOutput", pDialog->infoOutput() ); pConfig->writeEntry( "InfoFilename", pDialog->infoFile() ); pConfig->writeEntry( "InfoShow", pDialog->infoShow() ); pConfig->writeEntry( "WarnOutput", pDialog->warnOutput() ); pConfig->writeEntry( "WarnFilename", pDialog->warnFile() ); pConfig->writeEntry( "WarnShow", pDialog->warnShow() ); pConfig->writeEntry( "ErrorOutput", pDialog->errorOutput() ); pConfig->writeEntry( "ErrorFilename", pDialog->errorFile() ); pConfig->writeEntry( "ErrorShow", pDialog->errorShow() ); pConfig->writeEntry( "FatalOutput", pDialog->fatalOutput() ); pConfig->writeEntry( "FatalFilename", pDialog->fatalFile() ); pConfig->writeEntry( "FatalShow", pDialog->fatalShow() ); pConfig->writeEntry( "AbortFatal", pDialog->abortFatal() ); //bAreaCalculated = false; } else { /* User pressed Cancel, do nothing */ } /* restore old group */ pConfig->setGroup( aOldGroup ); return TRUE; // do not process event further } } return FALSE; // process event further}void KApplication::parseCommandLine( int& argc, char** argv ){ enum parameter_code { unknown = 0, caption, icon, miniicon, restore }; const char *parameter_strings[] = { "-caption", "-icon", "-miniicon", "-restore" , 0 }; aDummyString2 = " "; int i = 1; parameter_code parameter; while( i < argc ) { parameter = unknown; for ( int p = 0 ; parameter_strings[p]; p++) if ( !strcmp( argv[i], parameter_strings[p]) ) { parameter = static_cast<parameter_code>(p + 1); break; } if ( parameter != unknown && argc < i +2 ) { // last argument without parameters argc -= 1; break; // jump out of the while loop } switch (parameter) { case caption: aCaption = argv[i+1]; aDummyString2 += parameter_strings[caption-1]; aDummyString2 += " \""; aDummyString2 += argv[i+1]; aDummyString2 += "\" "; break; case icon: if (argv[i+1][0] == '/') aIconPixmap = QPixmap(argv[i+1]); else aIconPixmap = getIconLoader()->loadApplicationIcon( argv[i+1] ); if (aMiniIconPixmap.isNull()){ if (argv[i+1][0] == '/') aMiniIconPixmap = aIconPixmap; else aMiniIconPixmap = getIconLoader()->loadApplicationMiniIcon( argv[i+1] ); } aDummyString2 += parameter_strings[icon-1]; aDummyString2 += " "; aDummyString2 += argv[i+1]; aDummyString2 += " "; break; case miniicon: if (argv[i+1][0] == '/') aMiniIconPixmap = QPixmap(argv[i+1]); else aMiniIconPixmap = getIconLoader()->loadApplicationMiniIcon( argv[i+1] ); aDummyString2 += parameter_strings[miniicon-1]; aDummyString2 += " "; aDummyString2 += argv[i+1]; aDummyString2 += " "; break; case restore: { aSessionName = argv[i+1]; QString aSessionConfigName; if (argv[i+1][0] == '/') aSessionConfigName = argv[i+1]; else { aSessionConfigName = KApplication::localkdedir(); aSessionConfigName += "/share/config/"; aSessionConfigName += argv[i+1]; } if (QFile::exists(aSessionConfigName)){ QFile aConfigFile(aSessionConfigName); bool bSuccess; if ( ! checkAccess( aConfigFile.name(), W_OK ) ) bSuccess = false; else bSuccess = aConfigFile.open( IO_ReadWrite ); if( bSuccess ){ // Set uid/gid (neccesary for SUID programs) chown(aConfigFile.name(), getuid(), getgid()); aConfigFile.close(); pSessionConfig = new KConfig(0L, aSessionConfigName); // do not write back. the application will get // a new one if demanded. pSessionConfig->rollback(); if (pSessionConfig){ bIsRestored = True; } aConfigFile.remove(); } } } break; case unknown: i++; } if ( parameter != unknown ) { // remove arguments for( int j = i; j < argc-2; j++ ) argv[j] = argv[j+2]; argc -=2 ; } } if (aIconPixmap.isNull()){ aIconPixmap = getIconLoader()->loadApplicationIcon( aAppName + ".xpm"); } if (aMiniIconPixmap.isNull()){ aMiniIconPixmap = getIconLoader()->loadApplicationMiniIcon( aAppName + ".xpm"); }}KApplication::~KApplication(){ removeEventFilter( this ); if( pIconLoader ) delete pIconLoader; if( pLocale ) delete pLocale; delete pCharsets; delete pSearchPaths; delete pConfig; // Carefully shut down the process controller: It is very likely // that we receive a SIGCHLD while the destructor is running // (since we are in the process of shutting down, an opportunity
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -