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 #ifndef KEXI_STARTUPDATA_H
0021 #define KEXI_STARTUPDATA_H
0022 
0023 #include <QString>
0024 #include <QCommandLineOption>
0025 #include "kexicore_export.h"
0026 
0027 #include <KDbTristate>
0028 
0029 class KexiProjectData;
0030 class KexiCommandLineOptions;
0031 
0032 //! Startup data used for storing results of startup operations in Kexi.
0033 //! @see KexiStartupHandler
0034 class KEXICORE_EXPORT KexiStartupData
0035 {
0036 public:
0037     enum Action {
0038         DoNothing,
0039         CreateBlankProject,
0040         CreateFromTemplate,
0041         OpenProject,
0042         ImportProject,
0043         ShowWelcomeScreen,
0044         Exit
0045     };
0046 
0047     /*! Data required to perform import action.
0048      It is set by KexiStartupHandler::detectActionForFile()
0049      if a need for project/data importing has been detected. */
0050     class KEXICORE_EXPORT Import
0051     {
0052     public:
0053         Import();
0054         operator bool() const;
0055         QString fileName;
0056         QString mimeType;
0057     };
0058 
0059     KexiStartupData();
0060     virtual ~KexiStartupData();
0061 
0062     //! @return singleton Startup Handler singleton.
0063     //! @see KexiStartupHandler::global()
0064     static KexiStartupData* global();
0065 
0066     Action action() const;
0067 
0068     //! \return project data of a project that should be opened (for action()==OpenProject)
0069     KexiProjectData *projectData();
0070 
0071     //! \return import action's data needed to perform import (for action()==ImportProject)
0072     KexiStartupData::Import importActionData() const;
0073 
0074     /*! \return true if the Design Mode is forced for this project.
0075       Used on startup (by --design-mode comman line switch). */
0076     bool forcedDesignMode() const;
0077 
0078     /*! \return true if the User Mode is forced for this project.
0079       Used on startup (by --user-mode comman line switch).
0080       By default this is false. */
0081     bool forcedUserMode() const;
0082 
0083     /*! \return true if the Project Navigator should be visible even if User Mode is on. */
0084     bool isProjectNavigatorVisible() const;
0085 
0086     /*! \return true if the main menu (usually displayed as the tabbed toolbar) should be visible. */
0087     bool isMainMenuVisible() const;
0088 
0089     /*! \return true if Kexi started fullscreen.
0090       Used on startup (by --fullscreen commandline switch). */
0091     bool forcedFullScreen() const;
0092 
0093     //! @return command line options
0094     KexiCommandLineOptions options() const;
0095 
0096     //! Parses the options and arguments
0097     //! @return true on success
0098     tristate parseOptions(const QStringList &arguments,
0099                           const QList<QCommandLineOption> &extraOptions = QList<QCommandLineOption>());
0100 
0101     //! @return true if the option @a option was passed to the application
0102     bool isSet(const QCommandLineOption & option) const;
0103 
0104     //! @return value for option @a option
0105     QString value(const QCommandLineOption &option) const;
0106 
0107     //! @return list of values for option @a option
0108     QStringList values(const QCommandLineOption &option) const;
0109 
0110     //! @return a list of positional arguments.
0111     //! These are all of the arguments that were not recognized as part of an option.
0112     QStringList positionalArguments() const;
0113 
0114     QString helpText() const;
0115 
0116 protected:
0117     void setAction(Action action);
0118 
0119     //! Set project data of a project that should be opened (for action()==OpenProject).
0120     //! The ownership is passed.
0121     void setProjectData(KexiProjectData *data);
0122 
0123     void setImportActionData(KexiStartupData::Import import);
0124 
0125     void setForcedDesignMode(bool set);
0126 
0127     void setForcedUserMode(bool set);
0128 
0129     void setProjectNavigatorVisible(bool set);
0130 
0131     void setMainMenuVisible(bool set);
0132 
0133     void setForcedFullScreen(bool set);
0134 
0135 private:
0136     class Private;
0137     Private* const d;
0138 };
0139 
0140 #endif