1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
/* This file is part of the KDE project
Copyright (C) 2003-2005 Jaroslaw Staniek <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "kexi.h"
#include "kexiaboutdata.h"
#include "kexicmdlineargs.h"
#include <kexiutils/identifier.h>
#include <kexidb/msghandler.h>
#include <qtimer.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qpixmapcache.h>
#include <qcolor.h>
#include <qfileinfo.h>
#include <kdebug.h>
#include <kcursor.h>
#include <kapplication.h>
#include <kiconloader.h>
#include <kiconeffect.h>
#include <ksharedptr.h>
#include <kmimetype.h>
#include <kstaticdeleter.h>
#include <kglobalsettings.h>
using namespace Kexi;
//! used for speedup
//! @internal
class KexiInternal : public KShared
{
public:
KexiInternal() : KShared()
, connset(0)
, smallFont(0)
{
}
~KexiInternal()
{
delete connset;
delete smallFont;
}
KexiDBConnectionSet* connset;
KexiProjectSet recentProjects;
KexiDBConnectionSet recentConnections;
KexiDB::DriverManager driverManager;
KexiPart::Manager partManager;
QFont *smallFont;
};
static KStaticDeleter<KexiInternal> Kexi_intDeleter;
KexiInternal* _int = 0;
#define _INIT_SHARED { if (!_int) Kexi_intDeleter.setObject( _int, new KexiInternal() ); }
KexiDBConnectionSet& Kexi::connset()
{
_INIT_SHARED;
//delayed
if (!_int->connset) {
//load stored set data, OK?
_int->connset = new KexiDBConnectionSet();
_int->connset->load();
}
return *_int->connset;
}
KexiProjectSet& Kexi::recentProjects() {
_INIT_SHARED;
return _int->recentProjects;
}
KexiDB::DriverManager& Kexi::driverManager()
{
_INIT_SHARED;
return _int->driverManager;
}
KexiPart::Manager& Kexi::partManager()
{
_INIT_SHARED;
return _int->partManager;
}
void Kexi::deleteGlobalObjects()
{
delete _int;
}
//temp
bool _tempShowForms = true;
bool& Kexi::tempShowForms() {
#ifndef KEXI_FORMS_SUPPORT
_tempShowForms = false;
#endif
return _tempShowForms;
}
bool _tempShowReports = true;
bool& Kexi::tempShowReports() {
#ifndef KEXI_REPORTS_SUPPORT
_tempShowReports = false;
#endif
return _tempShowReports;
}
bool _tempShowMacros = true;
bool& Kexi::tempShowMacros() {
#ifndef KEXI_MACROS_SUPPORT
_tempShowMacros = false;
#endif
return _tempShowMacros;
}
bool _tempShowScripts = true;
bool& Kexi::tempShowScripts() {
#ifndef KEXI_SCRIPTS_SUPPORT
_tempShowScripts = false;
#endif
return _tempShowScripts;
}
//--------------------------------------------------------------------------------
QFont Kexi::smallFont(QWidget *init)
{
_INIT_SHARED;
if (!_int->smallFont) {
_int->smallFont = new QFont( init->font() );
const int wdth = KGlobalSettings::desktopGeometry(init).width();
int size = 10 + QMAX(0, wdth - 1100) / 100;
size = QMIN( init->fontInfo().pixelSize(), size );
_int->smallFont->setPixelSize( size );
}
return *_int->smallFont;
}
//--------------------------------------------------------------------------------
QString Kexi::nameForViewMode(int m)
{
if (m==NoViewMode) return i18n("No View");
else if (m==DataViewMode) return i18n("Data View");
else if (m==DesignViewMode) return i18n("Design View");
else if (m==TextViewMode) return i18n("Text View");
return i18n("Unknown");
}
//--------------------------------------------------------------------------------
QString Kexi::msgYouCanImproveData() {
return i18n("You can correct data in this row or use \"Cancel row changes\" function.");
}
//--------------------------------------------------------------------------------
ObjectStatus::ObjectStatus()
: msgHandler(0)
{
}
ObjectStatus::ObjectStatus(const QString& message, const QString& description)
: msgHandler(0)
{
setStatus(message, description);
}
ObjectStatus::ObjectStatus(KexiDB::Object* dbObject, const QString& message, const QString& description)
: msgHandler(0)
{
setStatus(dbObject, message, description);
}
ObjectStatus::~ObjectStatus()
{
delete msgHandler;
}
const ObjectStatus& ObjectStatus::status() const
{
return *this;
}
bool ObjectStatus::error() const
{
return !message.isEmpty()
|| (dynamic_cast<KexiDB::Object*>((QObject*)dbObj) && dynamic_cast<KexiDB::Object*>((QObject*)dbObj)->error());
}
void ObjectStatus::setStatus(const QString& message, const QString& description)
{
this->dbObj=0;
this->message=message;
this->description=description;
}
void ObjectStatus::setStatus(KexiDB::Object* dbObject, const QString& message, const QString& description)
{
if (dynamic_cast<QObject*>(dbObject)) {
dbObj = dynamic_cast<QObject*>(dbObject);
}
this->message=message;
this->description=description;
}
void ObjectStatus::setStatus(KexiDB::ResultInfo* result, const QString& message, const QString& description)
{
if (result) {
if (message.isEmpty())
this->message = result->msg;
else
this->message = message + " " + result->msg;
if (description.isEmpty())
this->description = result->desc;
else
this->description = description + " " + result->desc;
}
else
clearStatus();
}
void ObjectStatus::setStatus(KexiDB::Object* dbObject, KexiDB::ResultInfo* result,
const QString& message, const QString& description)
{
if (!dbObject)
setStatus(result, message, description);
else if (!result)
setStatus(dbObject, message, description);
else {
setStatus(dbObject, message, description);
setStatus(result, this->message, this->description);
}
}
void ObjectStatus::clearStatus()
{
message=QString::null;
description=QString::null;
}
QString ObjectStatus::singleStatusString() const {
if (message.isEmpty() || description.isEmpty())
return message;
return message + " " + description;
}
void ObjectStatus::append( const ObjectStatus& otherStatus ) {
if (message.isEmpty()) {
message = otherStatus.message;
description = otherStatus.description;
return;
}
const QString s( otherStatus.singleStatusString() );
if (s.isEmpty())
return;
if (description.isEmpty()) {
description = s;
return;
}
description = description + " " + s;
}
//! @internal
class ObjectStatusMessageHandler : public KexiDB::MessageHandler
{
public:
ObjectStatusMessageHandler(ObjectStatus *status)
: KexiDB::MessageHandler()
, m_status(status)
{
}
virtual ~ObjectStatusMessageHandler()
{
}
virtual void showErrorMessage(const QString &title,
const QString &details = QString::null)
{
m_status->setStatus(title, details);
}
virtual void showErrorMessage(KexiDB::Object *obj, const QString& msg = QString::null)
{
m_status->setStatus(obj, msg);
}
ObjectStatus *m_status;
};
ObjectStatus::operator KexiDB::MessageHandler*()
{
if (!msgHandler)
msgHandler = new ObjectStatusMessageHandler(this);
return msgHandler;
}
void Kexi::initCmdLineArgs(int argc, char *argv[], KAboutData* aboutData)
{
KAboutData *about = aboutData;
if (!about)
about = Kexi::createAboutData();
#ifdef CUSTOM_VERSION
# include "../custom_startup.h"
#endif
KCmdLineArgs::init( argc, argv, about );
KCmdLineArgs::addCmdLineOptions( options );
}
void KEXI_UNFINISHED(const QString& feature_name, const QString& extra_text)
{
QString msg;
if (feature_name.isEmpty())
msg = i18n("This function is not available for version %1 of %2 application.")
.arg(KEXI_VERSION_STRING)
.arg(KEXI_APP_NAME);
else {
QString feature_name_(feature_name);
msg = i18n("\"%1\" function is not available for version %2 of %3 application.")
.arg(feature_name_.replace("&",""))
.arg(KEXI_VERSION_STRING)
.arg(KEXI_APP_NAME);
}
QString extra_text_(extra_text);
if (!extra_text_.isEmpty())
extra_text_.prepend("\n");
KMessageBox::sorry(0, msg + extra_text_);
}
|