File indexing completed on 2024-05-05 17:04:26
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2012 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include <QApplication> 0021 #include <QCommandLineParser> 0022 #include <QFontDatabase> 0023 #include <QFile> 0024 #include <QStringList> 0025 #include <QString> 0026 #include <QProcessEnvironment> 0027 #include <QDir> 0028 #include <QMessageBox> 0029 #include <QSplashScreen> 0030 #include <QDebug> 0031 0032 #include <KIconLoader> 0033 #include <KLocalizedString> 0034 #include <KAboutData> 0035 0036 #include "MainWindow.h" 0037 0038 //#include "sketch/SketchInputContext.h" 0039 0040 #include <calligraversion.h> 0041 0042 int main( int argc, char** argv ) 0043 { 0044 #if defined HAVE_X11 0045 QApplication::setAttribute(Qt::AA_X11InitThreads); 0046 #endif 0047 0048 QApplication app(argc, argv); 0049 0050 KAboutData aboutData(QStringLiteral("calligragemini"), 0051 i18n("Calligra Gemini"), 0052 QStringLiteral(CALLIGRA_VERSION_STRING), 0053 i18n("Calligra Gemini: Writing and Presenting at Home and on the Go"), 0054 KAboutLicense::GPL, 0055 i18n("(c) 1999-%1 The Calligra team and KO GmbH.\n", QStringLiteral(CALLIGRA_YEAR)), 0056 QString(), 0057 QStringLiteral("https://www.calligra.org"), 0058 QStringLiteral("submit@bugs.kde.org")); 0059 0060 app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, true); 0061 KAboutData::setApplicationData(aboutData); 0062 0063 QCommandLineParser parser; 0064 aboutData.setupCommandLine(&parser); 0065 0066 parser.addPositionalArgument(QStringLiteral("[file(s)]"), i18n("Document to open")); 0067 parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("vkb"), i18n("Use the virtual keyboard"))); 0068 0069 parser.process(app); 0070 aboutData.processCommandLine(&parser); 0071 0072 QStringList fileNames; 0073 foreach(const QString &fileName, parser.positionalArguments()) { 0074 if (QFile::exists(fileName)) { 0075 fileNames << fileName; 0076 } 0077 } 0078 0079 #ifdef Q_OS_WIN 0080 QDir appdir(app.applicationDirPath()); 0081 appdir.cdUp(); 0082 0083 QString envStringSet; 0084 QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); 0085 if (!env.contains("XDG_DATA_DIRS")) { 0086 _putenv_s("XDG_DATA_DIRS", QString(appdir.absolutePath() + "/bin/data").toLocal8Bit()); 0087 envStringSet.append("XDG_DATA_DIRS "); 0088 } 0089 _putenv_s("PATH", QString(appdir.absolutePath() + "/bin" + ";" 0090 + appdir.absolutePath() + "/lib" + ";" 0091 + appdir.absolutePath() + "/lib" + "/kde4" + ";" 0092 + appdir.absolutePath()).toLocal8Bit()); 0093 0094 if(envStringSet.length() > 0) { 0095 qDebug() << envStringSet << "were set from main, restarting application in new environment!"; 0096 // Pass all the arguments along, but don't include the application name... 0097 QStringList allArguments; 0098 for(int i = 0; i < argc; i++) { 0099 allArguments << argv[i]; 0100 } 0101 QProcess::startDetached(app.applicationFilePath(), allArguments.mid(1)); 0102 exit(0); 0103 } 0104 0105 app.addLibraryPath(appdir.absolutePath()); 0106 app.addLibraryPath(appdir.absolutePath() + "/bin"); 0107 app.addLibraryPath(appdir.absolutePath() + "/lib"); 0108 app.addLibraryPath(appdir.absolutePath() + "/lib/kde4"); 0109 #endif 0110 0111 KIconLoader::global()->addAppDir("calligra"); 0112 KIconLoader::global()->addAppDir("calligragemini"); 0113 KIconLoader::global()->addAppDir("calligrawords"); 0114 KIconLoader::global()->addAppDir("calligrastage"); 0115 KIconLoader::global()->addAppDir("calligrasheets"); 0116 0117 app.processEvents(); 0118 0119 MainWindow window(fileNames); 0120 0121 if (parser.isSet("vkb")) { 0122 // app.setInputContext(new SketchInputContext(&app)); 0123 } 0124 0125 #ifdef Q_OS_WIN 0126 window.showMaximized(); 0127 #else 0128 window.show(); 0129 #endif 0130 0131 return app.exec(); 0132 }