main.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 448 行 · 第 1/2 页
CPP
448 行
{ return p;}void AssistantServer::incomingConnection( int socket ){ AssistantSocket *as = new AssistantSocket( socket, this ); connect( as, SIGNAL(showLinkRequest(QString)), this, SIGNAL(showLinkRequest(QString)) ); emit newConnect();}int main( int argc, char ** argv ){ Q_INIT_RESOURCE(assistant); bool withGUI = true;#ifndef Q_WS_WIN if ( argc > 1 ) { QString arg = QString::fromLocal8Bit(argv[1]); arg = arg.toLower(); if ( arg == QLatin1String("-addcontentfile") || arg == QLatin1String("-removecontentfile") || arg == QLatin1String("-help") || arg == QLatin1String("/?") ) withGUI = false; }#endif QApplication a(argc, argv, withGUI); a.setOrganizationName(QLatin1String("Trolltech")); a.setApplicationName(QLatin1String("Assistant")); QString resourceDir; AssistantServer *as = 0; QStringList catlist; QString file, profileName, aDocPath; bool server = false; bool hideSidebar = false; bool configLoaded = false; if ( argc == 2 ) { file = QString::fromLocal8Bit(argv[1]); if (file.startsWith(QLatin1String("-")) || file == QLatin1String("/?")) { file.clear(); } else { QFileInfo fi(file); file = fi.absoluteFilePath(); file = MainWindow::urlifyFileName(file); } } if ( file.isEmpty() ) { for ( int i = 1; i < argc; i++ ) { QString opt = QString::fromLocal8Bit(argv[i]).toLower(); if ( opt == QLatin1String("-file") ) { INDEX_CHECK( "Missing file argument!" ); i++; file = QFile::decodeName(argv[i]); } else if ( opt == QLatin1String("-server") ) { server = true; } else if ( opt == QLatin1String("-profile") ) { INDEX_CHECK( "Missing profile argument!" ); profileName = QFile::decodeName(argv[++i]); } else if ( opt == QLatin1String("-addcontentfile") ) { INDEX_CHECK( "Missing content file!" ); Config *c = Config::loadConfig(QString()); QFileInfo file( QFile::decodeName(argv[i+1]) ); if( !file.exists() ) { fprintf(stderr, "Could not locate content file: %s\n", qPrintable(file.absoluteFilePath())); return 1; } DocuParser *parser = DocuParser::createParser( file.absoluteFilePath() ); if( parser ) { QFile f( QFile::decodeName(argv[i+1]) ); if( !parser->parse( &f ) ) { fprintf(stderr, "Failed to parse file: %s\n", qPrintable(file.absoluteFilePath())); return 1; } parser->addTo( c->profile() ); c->setDocRebuild( true ); c->save(); } return 0; } else if ( opt == QLatin1String("-removecontentfile") ) { INDEX_CHECK("Missing content file!"); Config *c = Config::loadConfig(QString()); Profile *profile = c->profile(); QString contentFile = QString::fromLocal8Bit(argv[i+i]); QStringList entries;#ifdef Q_WS_WIN contentFile.replace(QLatin1Char('\\'), QLatin1Char('/')); entries = profile->docs.filter(contentFile, Qt::CaseInsensitive);#else entries = profile->docs.filter(contentFile);#endif if (entries.count() == 0) { fprintf(stderr, "Could not locate content file: %s\n", qPrintable(contentFile)); return 1; } else if (entries.count() > 1) { fprintf(stderr, "More than one entry matching file name found, " "please specify full path to file"); return 1; } else { QFileInfo file(entries[0]); if( !file.exists() ) { fprintf(stderr, "Could not locate content file: %s\n", qPrintable(file.absoluteFilePath())); return 1; } profile->removeDocFileEntry( file.absoluteFilePath() ); c->setDocRebuild( true ); c->save(); } return 0; } else if ( QString( QLatin1String(argv[i]) ).toLower() == QLatin1String("-docpath") ) { INDEX_CHECK( "Missing path!" ); QDir dir(QString::fromLocal8Bit(argv[i+1])); if ( dir.exists() ) { Config *c = Config::loadConfig(QString()); c->saveProfile(Profile::createDefaultProfile(dir.absolutePath())); c->loadDefaultProfile(); c->setDocRebuild(true); c->save(); configLoaded = true; ++i; } else { fprintf(stderr, "The specified path does not exist!\n"); return 1; } } else if ( opt == QLatin1String("-hidesidebar") ) { hideSidebar = true; } else if ( opt == QLatin1String("-help") || opt == QLatin1String("/?") ) { QString helpText = QLatin1String( "Usage: assistant [option]\n" "Options:\n" " -file Filename assistant opens the specified file\n" " -server reads commands from a socket after\n" " assistant has started\n" " -profile fileName starts assistant and displays the\n" " profile specified in the file fileName.\n" " -addContentFile file adds the content file 'file' to the set of\n" " documentation available by default\n" " -removeContentFile file removes the content file 'file' from the\n" " documentation available by default\n" " -docPath path sets the Qt documentation root path to\n" " 'path' and starts assistant\n" " -hideSidebar assistant will hide the sidebar.\n" " -resourceDir assistant will load translations from\n" " this directory.\n" " -help shows this help.");#ifdef Q_WS_WIN QMessageBox::information( 0, QLatin1String("Qt Assistant"), QLatin1String("<pre>") + helpText + QLatin1String("</pre>") );#else fprintf(stdout, "%s\n", qPrintable(helpText));#endif exit( 0 ); } else if ( opt == QLatin1String("-resourcedir") ) { INDEX_CHECK( "Missing resource directory argument!" ); resourceDir = QFile::decodeName( argv[++i] ); } else { fprintf(stderr, "Unrecognized option %s. Try -help to get help.\n", qPrintable(opt)); return 1; } } } if( resourceDir.isNull() ) resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); QTranslator translator( 0 ); translator.load( QLatin1String("assistant_") + QLocale::system().name(), resourceDir ); a.installTranslator( &translator ); QTranslator qtTranslator( 0 ); qtTranslator.load( QLatin1String("qt_") + QLocale::system().name(), resourceDir ); a.installTranslator( &qtTranslator ); Config *conf = 0; if (configLoaded) conf = Config::configuration(); else conf = Config::loadConfig( profileName ); if (!conf) { fprintf( stderr, "Profile '%s' does not exist!\n", profileName.toLatin1().constData() ); fflush( stderr ); return -1; } QStringList links = conf->source(); conf->hideSideBar( hideSidebar ); QPointer<MainWindow> mw = new MainWindow(); mw->setObjectName(QLatin1String("Assistant")); if ( server ) { as = new AssistantServer(); printf("%d\n", as->serverPort() ); fflush( stdout ); as->connect( as, SIGNAL(showLinkRequest(QString)), mw, SLOT(showLinkFromClient(QString)) ); }#if !defined(QT_NO_DBUS) && defined(Q_OS_UNIX) new AssistantAdaptor(mw);#endif // QT_NO_DBUS FontSettings settings = conf->fontSettings(); if (mw->font() != settings.windowFont) a.setFont(settings.windowFont, "QWidget"); mw->show(); if (!file.isEmpty()) mw->showLink( MainWindow::urlifyFileName(file) ); else if (file.isEmpty()) mw->showLinks( links ); a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) ); int appExec = a.exec(); delete (MainWindow*)mw; return appExec;}#include "main.moc"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?