File indexing completed on 2024-05-12 16:39:41
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004-2017 Jarosław Staniek <staniek@kde.org> 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 "kexistartupdata.h" 0021 #include "kexi.h" 0022 #include "KexiCommandLineOptions.h" 0023 #include "config-kexi.h" 0024 0025 #include <KDbDriver> 0026 #include <KDbDriverManager> 0027 0028 #include <KAboutData> 0029 0030 #include <QCommandLineParser> 0031 0032 // Don't use Q_GLOBAL_STATIC as destroys the object *after* QApplication is gone but we have to cleanup before -> use qAddPostRoutine 0033 static KexiStartupData* s_startupData = nullptr; 0034 0035 class Q_DECL_HIDDEN KexiStartupData::Private 0036 { 0037 public: 0038 Private(); 0039 ~Private(); 0040 0041 QCommandLineParser parser; 0042 KexiCommandLineOptions options; 0043 KexiProjectData *projectData; 0044 Action action; 0045 KexiStartupData::Import importActionData; 0046 bool forcedUserMode; 0047 bool forcedDesignMode; 0048 bool isProjectNavigatorVisible; 0049 bool isMainMenuVisible; 0050 bool createDB; 0051 bool dropDB; 0052 bool alsoOpenDB; 0053 bool forcedFullScreen; 0054 }; 0055 0056 KexiStartupData::Private::Private() 0057 : options(&parser) 0058 , projectData(0), action(KexiStartupData::DoNothing), forcedUserMode(false) 0059 , forcedDesignMode(false), isProjectNavigatorVisible(false), forcedFullScreen(false) 0060 { 0061 } 0062 0063 KexiStartupData::Private::~Private() 0064 { 0065 delete projectData; 0066 } 0067 0068 KexiStartupData::KexiStartupData() : d(new Private) 0069 { 0070 s_startupData = this; 0071 } 0072 0073 KexiStartupData::~KexiStartupData() 0074 { 0075 s_startupData = nullptr; 0076 delete d; 0077 } 0078 0079 //static 0080 KexiStartupData* KexiStartupData::global() 0081 { 0082 return s_startupData; 0083 } 0084 0085 KexiProjectData *KexiStartupData::projectData() 0086 { 0087 return d->projectData; 0088 } 0089 0090 void KexiStartupData::setProjectData(KexiProjectData *data) 0091 { 0092 if (data != d->projectData) { 0093 delete d->projectData; 0094 } 0095 d->projectData = data; 0096 } 0097 0098 KexiStartupData::Action KexiStartupData::action() const 0099 { 0100 return d->action; 0101 } 0102 0103 void KexiStartupData::setAction(KexiStartupData::Action action) 0104 { 0105 d->action = action; 0106 } 0107 0108 bool KexiStartupData::forcedUserMode() const 0109 { 0110 return d->forcedUserMode; 0111 } 0112 0113 void KexiStartupData::setForcedUserMode(bool set) 0114 { 0115 d->forcedUserMode = set; 0116 } 0117 0118 bool KexiStartupData::forcedDesignMode() const 0119 { 0120 return d->forcedDesignMode; 0121 } 0122 0123 void KexiStartupData::setForcedDesignMode(bool set) 0124 { 0125 d->forcedDesignMode = set; 0126 } 0127 0128 bool KexiStartupData::isProjectNavigatorVisible() const 0129 { 0130 if (d->forcedUserMode && !d->forcedDesignMode) 0131 return d->isProjectNavigatorVisible; 0132 return true; 0133 } 0134 0135 void KexiStartupData::setProjectNavigatorVisible(bool set) 0136 { 0137 d->isProjectNavigatorVisible = set; 0138 } 0139 0140 bool KexiStartupData::isMainMenuVisible() const 0141 { 0142 return d->isMainMenuVisible; 0143 } 0144 0145 void KexiStartupData::setMainMenuVisible(bool set) 0146 { 0147 d->isMainMenuVisible = set; 0148 } 0149 0150 KexiStartupData::Import KexiStartupData::importActionData() const 0151 { 0152 return d->importActionData; 0153 } 0154 0155 void KexiStartupData::setImportActionData(KexiStartupData::Import import) 0156 { 0157 d->importActionData = import; 0158 } 0159 0160 KexiStartupData::Import::Import() 0161 { 0162 } 0163 0164 KexiStartupData::Import::operator bool() const 0165 { 0166 return !fileName.isEmpty() && !mimeType.isEmpty(); 0167 } 0168 0169 bool KexiStartupData::forcedFullScreen() const 0170 { 0171 return d->forcedFullScreen; 0172 } 0173 0174 void KexiStartupData::setForcedFullScreen(bool set) 0175 { 0176 d->forcedFullScreen = set; 0177 } 0178 0179 //! Command line options 0180 KexiCommandLineOptions KexiStartupData::options() const 0181 { 0182 return d->options; 0183 } 0184 0185 tristate KexiStartupData::parseOptions(const QStringList &arguments, 0186 const QList<QCommandLineOption> &extraOptions) 0187 { 0188 d->parser.setApplicationDescription(KAboutData::applicationData().shortDescription()); 0189 KAboutData::applicationData().setupCommandLine(&d->parser); // adds -h and -v too 0190 0191 #define ADD_OPTION_BASE(o) \ 0192 if (!d->parser.addOption(o)) { \ 0193 qWarning() << "Could not add option" << o.names(); \ 0194 return false; \ 0195 } 0196 #define ADD_OPTION(o) ADD_OPTION_BASE(d->options.o) 0197 ADD_OPTION(createDb) 0198 ADD_OPTION(createAndOpenDb) 0199 ADD_OPTION(dropDb) 0200 ADD_OPTION(dbDriver) 0201 ADD_OPTION(fileType) 0202 ADD_OPTION(connectionShortcut) 0203 ADD_OPTION(readOnly) 0204 ADD_OPTION(userMode) 0205 ADD_OPTION(designMode) 0206 ADD_OPTION(showNavigator) 0207 ADD_OPTION(hideMenu) 0208 ADD_OPTION(open) 0209 ADD_OPTION(design) 0210 ADD_OPTION(editText) 0211 ADD_OPTION(execute) 0212 ADD_OPTION(newObject) 0213 #ifdef KEXI_QUICK_PRINTING_SUPPORT 0214 ADD_OPTION(print) 0215 ADD_OPTION(printPreview) 0216 #endif 0217 ADD_OPTION(user) 0218 ADD_OPTION(host) 0219 ADD_OPTION(port) 0220 ADD_OPTION(localSocket) 0221 ADD_OPTION(skipConnDialog) 0222 ADD_OPTION(fullScreen) 0223 ADD_OPTION(listPlugins) 0224 for(const QCommandLineOption& option : extraOptions) { 0225 ADD_OPTION_BASE(option) 0226 } 0227 #undef ADD_OPTION_BASE 0228 #undef ADD_OPTION 0229 0230 d->parser.addPositionalArgument("file", 0231 xi18nc("<file> argument description for the command line", 0232 "Kexi database project filename, Kexi shortcut filename, or name of a Kexi " 0233 "database project on a server to open.")); 0234 0235 d->parser.process(arguments); 0236 KAboutData::applicationData().processCommandLine(&d->parser); 0237 return true; 0238 } 0239 0240 bool KexiStartupData::isSet(const QCommandLineOption & option) const 0241 { 0242 return d->parser.isSet(option); 0243 } 0244 0245 QString KexiStartupData::value(const QCommandLineOption & option) const 0246 { 0247 return d->parser.value(option); 0248 } 0249 0250 QStringList KexiStartupData::values(const QCommandLineOption &option) const 0251 { 0252 return d->parser.values(option); 0253 } 0254 0255 QStringList KexiStartupData::positionalArguments() const 0256 { 0257 return d->parser.positionalArguments(); 0258 } 0259 0260 QString KexiStartupData::helpText() const 0261 { 0262 return d->parser.helpText(); 0263 }