Warning, file /sdk/cervisia/main.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (C) 1999-2002 Bernd Gehrmann 0003 * bernd@mail.berlios.de 0004 * Copyright (c) 2003-2008 Christian Loose <christian.loose@kdemail.net> 0005 * 0006 * This program is free software; you can redistribute it and/or modify 0007 * it under the terms of the GNU General Public License as published by 0008 * the Free Software Foundation; either version 2 of the License, or 0009 * (at your option) any later version. 0010 * 0011 * This program is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0014 * GNU General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU General Public License 0017 * along with this program; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #include <iostream> 0022 0023 #include <QFileInfo> 0024 0025 #include <KLocalizedString> 0026 #include <QApplication> 0027 #include <QCommandLineParser> 0028 #include <kaboutdata.h> 0029 #include <kconfig.h> 0030 #include <ktoolinvocation.h> 0031 0032 #include "annotatecontroller.h" 0033 #include "annotatedialog.h" 0034 #include "cervisia_version.h" 0035 #include "cervisiashell.h" 0036 #include "cvsserviceinterface.h" 0037 #include "logdialog.h" 0038 #include "misc.h" 0039 #include "repositoryinterface.h" 0040 #include "resolvedialog.h" 0041 0042 static OrgKdeCervisia5CvsserviceCvsserviceInterface *StartDBusService(const QString &directory) 0043 { 0044 // start the cvs D-Bus service 0045 QString error; 0046 QString appId; 0047 if (KToolInvocation::startServiceByDesktopName("org.kde.cvsservice5", QStringList(), &error, &appId)) { 0048 std::cerr << "Starting cvsservice failed with message: " << error.toLocal8Bit().constData() << std::endl; 0049 exit(1); 0050 } 0051 0052 OrgKdeCervisia5RepositoryInterface repository(appId, "/CvsRepository", QDBusConnection::sessionBus()); 0053 0054 repository.setWorkingCopy(directory); 0055 0056 // create a reference to the service 0057 return new OrgKdeCervisia5CvsserviceCvsserviceInterface(appId, "/CvsService", QDBusConnection::sessionBus()); 0058 } 0059 0060 static int ShowResolveDialog(const QString &fileName) 0061 { 0062 auto config = new KConfig("cervisiapartrc"); 0063 0064 auto dlg = new ResolveDialog(*config); 0065 if (dlg->parseFile(fileName)) 0066 dlg->show(); 0067 else 0068 delete dlg; 0069 0070 int result = qApp->exec(); 0071 0072 delete config; 0073 0074 return result; 0075 } 0076 0077 static int ShowLogDialog(const QString &fileName) 0078 { 0079 auto config = new KConfig("cervisiapartrc"); 0080 auto dlg = new LogDialog(*config); 0081 0082 // get directory for file 0083 const QFileInfo fi(fileName); 0084 QString directory = fi.absolutePath(); 0085 0086 // start the cvs DCOP service 0087 OrgKdeCervisia5CvsserviceCvsserviceInterface *cvsService = StartDBusService(directory); 0088 0089 if (dlg->parseCvsLog(cvsService, fi.fileName())) 0090 dlg->show(); 0091 else 0092 delete dlg; 0093 0094 int result = qApp->exec(); 0095 0096 // stop the cvs D-Bus service 0097 cvsService->quit(); 0098 delete cvsService; 0099 0100 delete config; 0101 0102 return result; 0103 } 0104 0105 static int ShowAnnotateDialog(const QString &fileName) 0106 { 0107 auto config = new KConfig("cervisiapartrc"); 0108 auto dlg = new AnnotateDialog(*config); 0109 0110 // get directory for file 0111 const QFileInfo fi(fileName); 0112 QString directory = fi.absolutePath(); 0113 0114 // start the cvs D-Bus service 0115 OrgKdeCervisia5CvsserviceCvsserviceInterface *cvsService = StartDBusService(directory); 0116 0117 AnnotateController ctl(dlg, cvsService); 0118 ctl.showDialog(fi.fileName()); 0119 0120 int result = qApp->exec(); 0121 0122 // stop the cvs D-Bus service 0123 cvsService->quit(); 0124 delete cvsService; 0125 0126 delete config; 0127 0128 return result; 0129 } 0130 0131 extern "C" Q_DECL_EXPORT int kdemain(int argc, char **argv) 0132 { 0133 KLocalizedString::setApplicationDomain("cervisia"); 0134 0135 QApplication app(argc, argv); 0136 0137 KAboutData about("cervisia", 0138 i18n("Cervisia"), 0139 CERVISIA_VERSION_STRING, 0140 i18n("A CVS frontend"), 0141 KAboutLicense::GPL, 0142 i18n("Copyright (c) 1999-2002 Bernd Gehrmann\n" 0143 "Copyright (c) 2002-2008 the Cervisia authors"), 0144 QString(), 0145 QLatin1String("http://cervisia.kde.org")); 0146 0147 about.addAuthor(i18n("Bernd Gehrmann"), 0148 i18n("Original author and former " 0149 "maintainer"), 0150 "bernd@mail.berlios.de"); 0151 about.addAuthor(i18n("Christian Loose"), i18n("Maintainer"), "christian.loose@kdemail.net"); 0152 about.addAuthor(i18n("Andr\303\251 W\303\266bbeking"), i18n("Developer"), "woebbeking@kde.org"); 0153 about.addAuthor(i18n("Carlos Woelz"), i18n("Documentation"), "carloswoelz@imap-mail.com"); 0154 0155 about.addCredit(i18n("Richard Moore"), i18n("Conversion to KPart"), "rich@kde.org"); 0156 about.addCredit(i18n("Laurent Montel"), i18n("Conversion to D-Bus"), "montel@kde.org"); 0157 about.addCredit(i18n("Martin Koller"), i18n("Port to KDE Frameworks 5"), "kollix@aon.at"); 0158 0159 about.setOrganizationDomain(QByteArray("kde.org")); 0160 0161 KAboutData::setApplicationData(about); 0162 0163 QCommandLineParser parser; 0164 about.setupCommandLine(&parser); 0165 0166 parser.addPositionalArgument(QLatin1String("directory"), i18n("The sandbox to be loaded"), QLatin1String("[directory]")); 0167 parser.addOption(QCommandLineOption(QLatin1String("resolve"), i18n("Show resolve dialog for the given file."), QLatin1String("file"))); 0168 parser.addOption(QCommandLineOption(QLatin1String("log"), i18n("Show log dialog for the given file."), QLatin1String("file"))); 0169 parser.addOption(QCommandLineOption(QLatin1String("annotate"), i18n("Show annotation dialog for the given file."), QLatin1String("file"))); 0170 0171 parser.process(app); 0172 about.processCommandLine(&parser); 0173 0174 QString resolvefile = parser.value(QLatin1String("resolve")); 0175 if (!resolvefile.isEmpty()) 0176 return ShowResolveDialog(resolvefile); 0177 0178 // is command line option 'show log dialog' specified? 0179 QString logFile = parser.value(QLatin1String("log")); 0180 if (!logFile.isEmpty()) 0181 return ShowLogDialog(logFile); 0182 0183 // is command line option 'show annotation dialog' specified? 0184 QString annotateFile = parser.value(QLatin1String("annotate")); 0185 if (!annotateFile.isEmpty()) 0186 return ShowAnnotateDialog(annotateFile); 0187 0188 if (app.isSessionRestored()) { 0189 kRestoreMainWindows<CervisiaShell>(); 0190 } else { 0191 auto shell = new CervisiaShell(); 0192 0193 if (parser.positionalArguments().count()) { 0194 QDir dir(parser.positionalArguments()[0]); 0195 QUrl directory = QUrl::fromLocalFile(dir.absolutePath()); 0196 shell->openURL(directory); 0197 } else 0198 shell->openURL(); 0199 0200 shell->setWindowIcon(qApp->windowIcon()); 0201 shell->show(); 0202 } 0203 0204 int res = app.exec(); 0205 cleanupTempFiles(); 0206 return res; 0207 } 0208 0209 // Local Variables: 0210 // c-basic-offset: 4 0211 // End: