kexi

kexi.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003-2005 Jaroslaw Staniek <js@iidea.pl>
3
4 This program 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 program 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 program; see the file COPYING. 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 "kexi.h"
21#include "kexiaboutdata.h"
22#include "kexicmdlineargs.h"
23
24#include <kexiutils/identifier.h>
25#include <kexidb/msghandler.h>
26
27#include <tqtimer.h>
28#include <tqimage.h>
29#include <tqpixmap.h>
30#include <tqpixmapcache.h>
31#include <tqcolor.h>
32#include <tqfileinfo.h>
33
34#include <kdebug.h>
35#include <kcursor.h>
36#include <tdeapplication.h>
37#include <kiconloader.h>
38#include <kiconeffect.h>
39#include <ksharedptr.h>
40#include <kmimetype.h>
41#include <kstaticdeleter.h>
42#include <tdeglobalsettings.h>
43
44using namespace Kexi;
45
48class KexiInternal : public TDEShared
49{
50 public:
51 KexiInternal() : TDEShared()
52 , connset(0)
53 , smallFont(0)
54 {
55 }
56 ~KexiInternal()
57 {
58 delete connset;
59 delete smallFont;
60 }
63 KexiDBConnectionSet recentConnections;
66 TQFont *smallFont;
67};
68
69static KStaticDeleter<KexiInternal> Kexi_intDeleter;
70KexiInternal* _int = 0;
71
72#define _INIT_SHARED { if (!_int) Kexi_intDeleter.setObject( _int, new KexiInternal() ); }
73
75{
76 _INIT_SHARED;
77 //delayed
78 if (!_int->connset) {
79 //load stored set data, OK?
80 _int->connset = new KexiDBConnectionSet();
81 _int->connset->load();
82 }
83 return *_int->connset;
84}
85
87 _INIT_SHARED;
88 return _int->recentProjects;
89}
90
92{
93 _INIT_SHARED;
94 return _int->driverManager;
95}
96
98{
99 _INIT_SHARED;
100 return _int->partManager;
101}
102
104{
105 delete _int;
106}
107
108//temp
109bool _tempShowForms = true;
111#ifndef KEXI_FORMS_SUPPORT
112 _tempShowForms = false;
113#endif
114 return _tempShowForms;
115}
116
117bool _tempShowReports = true;
119#ifndef KEXI_REPORTS_SUPPORT
120 _tempShowReports = false;
121#endif
122 return _tempShowReports;
123}
124
125bool _tempShowMacros = true;
127#ifndef KEXI_MACROS_SUPPORT
128 _tempShowMacros = false;
129#endif
130 return _tempShowMacros;
131}
132
133bool _tempShowScripts = true;
135#ifndef KEXI_SCRIPTS_SUPPORT
136 _tempShowScripts = false;
137#endif
138 return _tempShowScripts;
139}
140
141//--------------------------------------------------------------------------------
142
143TQFont Kexi::smallFont(TQWidget *init)
144{
145 _INIT_SHARED;
146 if (!_int->smallFont) {
147 _int->smallFont = new TQFont( init->font() );
148 const int wdth = TDEGlobalSettings::desktopGeometry(init).width();
149 int size = 10 + TQMAX(0, wdth - 1100) / 100;
150 size = TQMIN( init->fontInfo().pixelSize(), size );
151 _int->smallFont->setPixelSize( size );
152 }
153 return *_int->smallFont;
154}
155
156//--------------------------------------------------------------------------------
158{
159 if (m==NoViewMode) return i18n("No View");
160 else if (m==DataViewMode) return i18n("Data View");
161 else if (m==DesignViewMode) return i18n("Design View");
162 else if (m==TextViewMode) return i18n("Text View");
163
164 return i18n("Unknown");
165}
166
167//--------------------------------------------------------------------------------
168
169TQString Kexi::msgYouCanImproveData() {
170 return i18n("You can correct data in this row or use \"Cancel row changes\" function.");
171}
172
173//--------------------------------------------------------------------------------
174
175ObjectStatus::ObjectStatus()
176: msgHandler(0)
177{
178}
179
180ObjectStatus::ObjectStatus(const TQString& message, const TQString& description)
181: msgHandler(0)
182{
183 setStatus(message, description);
184}
185
186ObjectStatus::ObjectStatus(KexiDB::Object* dbObject, const TQString& message, const TQString& description)
187: msgHandler(0)
188{
189 setStatus(dbObject, message, description);
190}
191
192ObjectStatus::~ObjectStatus()
193{
194 delete msgHandler;
195}
196
197const ObjectStatus& ObjectStatus::status() const
198{
199 return *this;
200}
201
202bool ObjectStatus::error() const
203{
204 return !message.isEmpty()
205 || (dynamic_cast<KexiDB::Object*>((TQObject*)dbObj) && dynamic_cast<KexiDB::Object*>((TQObject*)dbObj)->error());
206}
207
208void ObjectStatus::setStatus(const TQString& message, const TQString& description)
209{
210 this->dbObj=0;
211 this->message=message;
212 this->description=description;
213}
214
215void ObjectStatus::setStatus(KexiDB::Object* dbObject, const TQString& message, const TQString& description)
216{
217 if (dynamic_cast<TQObject*>(dbObject)) {
218 dbObj = dynamic_cast<TQObject*>(dbObject);
219 }
220 this->message=message;
221 this->description=description;
222}
223
224void ObjectStatus::setStatus(KexiDB::ResultInfo* result, const TQString& message, const TQString& description)
225{
226 if (result) {
227 if (message.isEmpty())
228 this->message = result->msg;
229 else
230 this->message = message + " " + result->msg;
231
232 if (description.isEmpty())
233 this->description = result->desc;
234 else
235 this->description = description + " " + result->desc;
236 }
237 else
238 clearStatus();
239}
240
241void ObjectStatus::setStatus(KexiDB::Object* dbObject, KexiDB::ResultInfo* result,
242 const TQString& message, const TQString& description)
243{
244 if (!dbObject)
245 setStatus(result, message, description);
246 else if (!result)
247 setStatus(dbObject, message, description);
248 else {
249 setStatus(dbObject, message, description);
250 setStatus(result, this->message, this->description);
251 }
252}
253
254void ObjectStatus::clearStatus()
255{
256 message=TQString();
257 description=TQString();
258}
259
260TQString ObjectStatus::singleStatusString() const {
261 if (message.isEmpty() || description.isEmpty())
262 return message;
263 return message + " " + description;
264}
265
266void ObjectStatus::append( const ObjectStatus& otherStatus ) {
267 if (message.isEmpty()) {
268 message = otherStatus.message;
269 description = otherStatus.description;
270 return;
271 }
272 const TQString s( otherStatus.singleStatusString() );
273 if (s.isEmpty())
274 return;
275 if (description.isEmpty()) {
276 description = s;
277 return;
278 }
279 description = description + " " + s;
280}
281
283class ObjectStatusMessageHandler : public KexiDB::MessageHandler
284{
285 public:
286 ObjectStatusMessageHandler(ObjectStatus *status)
287 : KexiDB::MessageHandler()
288 , m_status(status)
289 {
290 }
291 virtual ~ObjectStatusMessageHandler()
292 {
293 }
294
295 virtual void showErrorMessage(const TQString &title,
296 const TQString &details = TQString())
297 {
298 m_status->setStatus(title, details);
299 }
300
301 virtual void showErrorMessage(KexiDB::Object *obj, const TQString& msg = TQString())
302 {
303 m_status->setStatus(obj, msg);
304 }
305
306 ObjectStatus *m_status;
307};
308
309ObjectStatus::operator KexiDB::MessageHandler*()
310{
311 if (!msgHandler)
312 msgHandler = new ObjectStatusMessageHandler(this);
313 return msgHandler;
314}
315
316void Kexi::initCmdLineArgs(int argc, char *argv[], TDEAboutData* aboutData)
317{
318 TDEAboutData *about = aboutData;
319 if (!about)
320 about = Kexi::createAboutData();
321#ifdef CUSTOM_VERSION
322# include "../custom_startup.h"
323#endif
324 TDECmdLineArgs::init( argc, argv, about );
325 TDECmdLineArgs::addCmdLineOptions( options );
326}
327
328void KEXI_UNFINISHED(const TQString& feature_name, const TQString& extra_text)
329{
330 TQString msg;
331 if (feature_name.isEmpty())
332 msg = i18n("This function is not available for version %1 of %2 application.")
333 .arg(KEXI_VERSION_STRING)
334 .arg(KEXI_APP_NAME);
335 else {
336 TQString feature_name_(feature_name);
337 msg = i18n("\"%1\" function is not available for version %2 of %3 application.")
338 .arg(feature_name_.replace("&",""))
339 .arg(KEXI_VERSION_STRING)
340 .arg(KEXI_APP_NAME);
341 }
342
343 TQString extra_text_(extra_text);
344 if (!extra_text_.isEmpty())
345 extra_text_.prepend("\n");
346
347 KMessageBox::sorry(0, msg + extra_text_);
348}
Database driver management, e.g. finding and loading drivers.
bool error() const
Definition object.h:38
TQString desc
error message and detailed description, both empty by default
Definition error.h:131
KexiPart's manager: looks up and instantiates them.
Stores information about multiple kexi project-data items.
KexiDB::MessageHandler * msgHandler
This is in fact KexiDB::Object.
Definition kexi.h:133
High-level database connectivity library with database backend drivers.
Namespace for general Kexi functions.
Definition kexi.h:38
KEXICORE_EXPORT bool & tempShowScripts()
false by default, flag loaded on main window startup
Definition kexi.cpp:134
KEXICORE_EXPORT void deleteGlobalObjects()
can be called to delete global objects like driverManager and partManager (and thus,...
Definition kexi.cpp:103
KEXICORE_EXPORT bool & tempShowForms()
false by default, flag loaded on main window startup
Definition kexi.cpp:110
KEXICORE_EXPORT bool & tempShowMacros()
false by default, flag loaded on main window startup
Definition kexi.cpp:126
KEXICORE_EXPORT TQFont smallFont(TQWidget *init=0)
Definition kexi.cpp:143
KEXICORE_EXPORT KexiPart::Manager & partManager()
shared part manager
Definition kexi.cpp:97
KEXICORE_EXPORT KexiDB::DriverManager & driverManager()
shared driver manager
Definition kexi.cpp:91
KEXICORE_EXPORT bool & tempShowReports()
false by default, flag loaded on main window startup
Definition kexi.cpp:118
KEXICORE_EXPORT KexiDBConnectionSet & connset()
A set of known connections.
Definition kexi.cpp:74
KEXICORE_EXPORT TQString nameForViewMode(int m)
i18n'ed name of view mode m
Definition kexi.cpp:157
KEXICORE_EXPORT KexiProjectSet & recentProjects()
A set avaiulable of project infos.
Definition kexi.cpp:86
@ TextViewMode
Also known as SQL View Mode.
Definition kexi.h:48
@ NoViewMode
In KexiViewBase::afterSwitchFrom() and KexiViewBase::beforeSwitchTo() means that parent dialog of the...
Definition kexi.h:44