~ubuntu-branches/debian/sid/kexi/sid

« back to all changes in this revision

Viewing changes to src/core/kexistartupdata.cpp

  • Committer: Package Import Robot
  • Author(s): Pino Toscano
  • Date: 2017-06-24 20:10:10 UTC
  • Revision ID: package-import@ubuntu.com-20170624201010-5lrzd5r2vwthwifp
Tags: upstream-3.0.1.1
Import upstream version 3.0.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2004-2015 Jarosław Staniek <staniek@kde.org>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
 * Boston, MA 02110-1301, USA.
 
18
*/
 
19
 
 
20
#include "kexistartupdata.h"
 
21
#include "kexi.h"
 
22
#include "KexiCommandLineOptions.h"
 
23
#include "config-kexi.h"
 
24
 
 
25
#include <KDbDriver>
 
26
#include <KDbDriverManager>
 
27
 
 
28
#include <KAboutData>
 
29
 
 
30
#include <QCommandLineParser>
 
31
 
 
32
class KexiStartupData::Private
 
33
{
 
34
public:
 
35
    Private();
 
36
    ~Private();
 
37
 
 
38
    QCommandLineParser parser;
 
39
    KexiCommandLineOptions options;
 
40
    KexiProjectData *projectData;
 
41
    Action action;
 
42
    KexiStartupData::Import importActionData;
 
43
    bool forcedUserMode;
 
44
    bool forcedDesignMode;
 
45
    bool isProjectNavigatorVisible;
 
46
    bool isMainMenuVisible;
 
47
    bool createDB;
 
48
    bool dropDB;
 
49
    bool alsoOpenDB;
 
50
    bool forcedFullScreen;
 
51
};
 
52
 
 
53
KexiStartupData::Private::Private()
 
54
    : options(&parser)
 
55
    , projectData(0), action(KexiStartupData::DoNothing), forcedUserMode(false)
 
56
    , forcedDesignMode(false), isProjectNavigatorVisible(false), forcedFullScreen(false)
 
57
{
 
58
}
 
59
 
 
60
KexiStartupData::Private::~Private()
 
61
{
 
62
    delete projectData;
 
63
}
 
64
 
 
65
KexiStartupData::KexiStartupData() : d(new Private)
 
66
{
 
67
}
 
68
 
 
69
KexiStartupData::~KexiStartupData()
 
70
{
 
71
    delete d;
 
72
}
 
73
 
 
74
KexiProjectData *KexiStartupData::projectData()
 
75
{
 
76
    return d->projectData;
 
77
}
 
78
 
 
79
void KexiStartupData::setProjectData(KexiProjectData *data)
 
80
{
 
81
    if (data != d->projectData) {
 
82
        delete d->projectData;
 
83
    }
 
84
    d->projectData = data;
 
85
}
 
86
 
 
87
KexiStartupData::Action KexiStartupData::action() const
 
88
{
 
89
    return d->action;
 
90
}
 
91
 
 
92
void KexiStartupData::setAction(KexiStartupData::Action action)
 
93
{
 
94
    d->action = action;
 
95
}
 
96
 
 
97
bool KexiStartupData::forcedUserMode() const
 
98
{
 
99
    return d->forcedUserMode;
 
100
}
 
101
 
 
102
void KexiStartupData::setForcedUserMode(bool set)
 
103
{
 
104
    d->forcedUserMode = set;
 
105
}
 
106
 
 
107
bool KexiStartupData::forcedDesignMode() const
 
108
{
 
109
    return d->forcedDesignMode;
 
110
}
 
111
 
 
112
void KexiStartupData::setForcedDesignMode(bool set)
 
113
{
 
114
    d->forcedDesignMode = set;
 
115
}
 
116
 
 
117
bool KexiStartupData::isProjectNavigatorVisible() const
 
118
{
 
119
    if (d->forcedUserMode && !d->forcedDesignMode)
 
120
        return d->isProjectNavigatorVisible;
 
121
    return true;
 
122
}
 
123
 
 
124
void KexiStartupData::setProjectNavigatorVisible(bool set)
 
125
{
 
126
    d->isProjectNavigatorVisible = set;
 
127
}
 
128
 
 
129
bool KexiStartupData::isMainMenuVisible() const
 
130
{
 
131
    return d->isMainMenuVisible;
 
132
}
 
133
 
 
134
void KexiStartupData::setMainMenuVisible(bool set)
 
135
{
 
136
    d->isMainMenuVisible = set;
 
137
}
 
138
 
 
139
KexiStartupData::Import KexiStartupData::importActionData() const
 
140
{
 
141
    return d->importActionData;
 
142
}
 
143
 
 
144
void KexiStartupData::setImportActionData(KexiStartupData::Import import)
 
145
{
 
146
    d->importActionData = import;
 
147
}
 
148
 
 
149
KexiStartupData::Import::Import()
 
150
{
 
151
}
 
152
 
 
153
KexiStartupData::Import::operator bool() const
 
154
{
 
155
    return !fileName.isEmpty() && !mimeType.isEmpty();
 
156
}
 
157
 
 
158
bool KexiStartupData::forcedFullScreen() const
 
159
{
 
160
    return d->forcedFullScreen;
 
161
}
 
162
 
 
163
void KexiStartupData::setForcedFullScreen(bool set)
 
164
{
 
165
    d->forcedFullScreen = set;
 
166
}
 
167
 
 
168
//! Command line options
 
169
KexiCommandLineOptions KexiStartupData::options() const
 
170
{
 
171
    return d->options;
 
172
}
 
173
 
 
174
tristate KexiStartupData::parseOptions()
 
175
{
 
176
    d->parser.setApplicationDescription(KAboutData::applicationData().shortDescription());
 
177
    KAboutData::applicationData().setupCommandLine(&d->parser); // adds -h and -v too
 
178
 
 
179
#define ADD_OPTION(o) \
 
180
    if (!d->parser.addOption(d->options.o)) { \
 
181
        qWarning() << "Could not add option" << d->options.o.names(); \
 
182
        return false; \
 
183
    }
 
184
    ADD_OPTION(createDb)
 
185
    ADD_OPTION(createAndOpenDb)
 
186
    ADD_OPTION(dropDb)
 
187
    ADD_OPTION(dbDriver)
 
188
    ADD_OPTION(fileType)
 
189
    ADD_OPTION(connectionShortcut)
 
190
    ADD_OPTION(readOnly)
 
191
    ADD_OPTION(userMode)
 
192
    ADD_OPTION(designMode)
 
193
    ADD_OPTION(showNavigator)
 
194
    ADD_OPTION(hideMenu)
 
195
    ADD_OPTION(open)
 
196
    ADD_OPTION(design)
 
197
    ADD_OPTION(editText)
 
198
    ADD_OPTION(execute)
 
199
    ADD_OPTION(newObject)
 
200
#ifdef KEXI_QUICK_PRINTING_SUPPORT
 
201
    ADD_OPTION(print)
 
202
    ADD_OPTION(printPreview)
 
203
#endif
 
204
    ADD_OPTION(user)
 
205
    ADD_OPTION(host)
 
206
    ADD_OPTION(port)
 
207
    ADD_OPTION(localSocket)
 
208
    ADD_OPTION(skipConnDialog)
 
209
    ADD_OPTION(fullScreen)
 
210
    ADD_OPTION(listPlugins)
 
211
#undef ADD_OPTION
 
212
 
 
213
    d->parser.addPositionalArgument("file",
 
214
        xi18nc("<file> argument description for the command line",
 
215
               "Kexi database project filename, Kexi shortcut filename, or name of a Kexi "
 
216
               "database project on a server to open."));
 
217
 
 
218
    //qDebug() << QCoreApplication::instance()->arguments();
 
219
    d->parser.process(*qApp);
 
220
    KAboutData::applicationData().processCommandLine(&d->parser);
 
221
    return true;
 
222
}
 
223
 
 
224
bool KexiStartupData::isSet(const QCommandLineOption & option) const
 
225
{
 
226
    return d->parser.isSet(option);
 
227
}
 
228
 
 
229
QString KexiStartupData::value(const QCommandLineOption & option) const
 
230
{
 
231
    return d->parser.value(option);
 
232
}
 
233
 
 
234
QStringList KexiStartupData::positionalArguments() const
 
235
{
 
236
    return d->parser.positionalArguments();
 
237
}
 
238
 
 
239
QString KexiStartupData::helpText() const
 
240
{
 
241
    return d->parser.helpText();
 
242
}