kexi

kexi.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kexi.h"
00021 #include "kexiaboutdata.h"
00022 #include "kexicmdlineargs.h"
00023 
00024 #include <kexiutils/identifier.h>
00025 #include <kexidb/msghandler.h>
00026 
00027 #include <qtimer.h>
00028 #include <qimage.h>
00029 #include <qpixmap.h>
00030 #include <qpixmapcache.h>
00031 #include <qcolor.h>
00032 #include <qfileinfo.h>
00033 
00034 #include <kdebug.h>
00035 #include <kcursor.h>
00036 #include <kapplication.h>
00037 #include <kiconloader.h>
00038 #include <kiconeffect.h>
00039 #include <ksharedptr.h>
00040 #include <kmimetype.h>
00041 #include <kstaticdeleter.h>
00042 #include <kglobalsettings.h>
00043 
00044 using namespace Kexi;
00045 
00048 class KexiInternal : public KShared
00049 {
00050     public:
00051         KexiInternal() : KShared()
00052          , connset(0)
00053          , smallFont(0)
00054         {
00055         }
00056         ~KexiInternal()
00057         {
00058             delete connset;
00059             delete smallFont;
00060         }
00061         KexiDBConnectionSet* connset;
00062         KexiProjectSet recentProjects;
00063         KexiDBConnectionSet recentConnections;
00064         KexiDB::DriverManager driverManager;
00065         KexiPart::Manager partManager;
00066         QFont *smallFont;
00067 };
00068 
00069 static KStaticDeleter<KexiInternal> Kexi_intDeleter;
00070 KexiInternal* _int = 0;
00071 
00072 #define _INIT_SHARED { if (!_int) Kexi_intDeleter.setObject( _int, new KexiInternal() ); }
00073 
00074 KexiDBConnectionSet& Kexi::connset()
00075 {
00076     _INIT_SHARED;
00077     //delayed
00078     if (!_int->connset) {
00079         //load stored set data, OK?
00080         _int->connset = new KexiDBConnectionSet();
00081         _int->connset->load();
00082     }
00083     return *_int->connset;
00084 }
00085 
00086 KexiProjectSet& Kexi::recentProjects() { 
00087     _INIT_SHARED;
00088     return _int->recentProjects;
00089 }
00090 
00091 KexiDB::DriverManager& Kexi::driverManager()
00092 {
00093     _INIT_SHARED;
00094     return _int->driverManager;
00095 }
00096 
00097 KexiPart::Manager& Kexi::partManager()
00098 {
00099     _INIT_SHARED;
00100     return _int->partManager;
00101 }
00102 
00103 void Kexi::deleteGlobalObjects()
00104 {
00105     delete _int;
00106 }
00107 
00108 //temp
00109 bool _tempShowForms = true;
00110 bool& Kexi::tempShowForms() { 
00111 #ifndef KEXI_FORMS_SUPPORT
00112     _tempShowForms = false; 
00113 #endif
00114     return _tempShowForms;
00115 }
00116 
00117 bool _tempShowReports = true;
00118 bool& Kexi::tempShowReports() { 
00119 #ifndef KEXI_REPORTS_SUPPORT
00120     _tempShowReports = false; 
00121 #endif
00122     return _tempShowReports;
00123 }
00124 
00125 bool _tempShowScripts = true;
00126 bool& Kexi::tempShowScripts() { 
00127 #ifndef KEXI_SCRIPTS_SUPPORT
00128     _tempShowScripts = false; 
00129 #endif
00130     return _tempShowScripts;
00131 }
00132 
00133 //--------------------------------------------------------------------------------
00134 
00135 QFont Kexi::smallFont(QWidget *init)
00136 {
00137     _INIT_SHARED;
00138     if (!_int->smallFont) {
00139         _int->smallFont = new QFont( init->font() );
00140         const int wdth = KGlobalSettings::desktopGeometry(init).width();
00141         int size = 10 + QMAX(0, wdth - 1100) / 100;
00142         size = QMIN( init->fontInfo().pixelSize(), size );
00143         _int->smallFont->setPixelSize( size );
00144     }
00145     return *_int->smallFont;
00146 }
00147 
00148 //--------------------------------------------------------------------------------
00149 QString Kexi::nameForViewMode(int m)
00150 {
00151     if (m==NoViewMode) return i18n("No View");
00152     else if (m==DataViewMode) return i18n("Data View");
00153     else if (m==DesignViewMode) return i18n("Design View");
00154     else if (m==TextViewMode) return i18n("Text View");
00155 
00156     return i18n("Unknown");
00157 }
00158 
00159 //--------------------------------------------------------------------------------
00160 
00161 QString Kexi::msgYouCanImproveData() {
00162     return i18n("You can correct data in this row or use \"Cancel row changes\" function.");
00163 }
00164 
00165 //--------------------------------------------------------------------------------
00166 
00167 ObjectStatus::ObjectStatus()
00168 : msgHandler(0)
00169 {
00170 }
00171 
00172 ObjectStatus::ObjectStatus(const QString& message, const QString& description)
00173 : msgHandler(0)
00174 {
00175     setStatus(message, description);
00176 }
00177 
00178 ObjectStatus::ObjectStatus(KexiDB::Object* dbObject, const QString& message, const QString& description)
00179 : msgHandler(0)
00180 {
00181     setStatus(dbObject, message, description);
00182 }
00183 
00184 ObjectStatus::~ObjectStatus()
00185 {
00186     delete msgHandler;
00187 }
00188 
00189 const ObjectStatus& ObjectStatus::status() const
00190 {
00191     return *this;
00192 }
00193 
00194 bool ObjectStatus::error() const
00195 {
00196     return !message.isEmpty() || !message.isEmpty();
00197 }
00198 
00199 void ObjectStatus::setStatus(const QString& message, const QString& description)
00200 {
00201     this->dbObj=0;
00202     this->message=message;
00203     this->description=description;
00204 }
00205 
00206 void ObjectStatus::setStatus(KexiDB::Object* dbObject, const QString& message, const QString& description)
00207 {
00208     if (dynamic_cast<QObject*>(dbObject)) {
00209         dbObj = dynamic_cast<QObject*>(dbObject);
00210     }
00211     this->message=message;
00212     this->description=description;
00213 }
00214 
00215 void ObjectStatus::clearStatus()
00216 {
00217     message=QString::null;
00218     description=QString::null;
00219 }
00220 
00221 QString ObjectStatus::singleStatusString() const { 
00222     if (message.isEmpty() || description.isEmpty())
00223         return message;
00224     return message + " " + description;
00225 }
00226 
00227 void ObjectStatus::append( const ObjectStatus& otherStatus ) {
00228     if (message.isEmpty()) {
00229         message = otherStatus.message;
00230         description = otherStatus.description;
00231         return;
00232     }
00233     QString s = otherStatus.singleStatusString();
00234     if (s.isEmpty())
00235         return;
00236     if (description.isEmpty()) {
00237         description = s;
00238         return;
00239     }
00240     description = description + " " + s;
00241 }
00242 
00244 class ObjectStatusMessageHandler : public KexiDB::MessageHandler
00245 {
00246     public:
00247         ObjectStatusMessageHandler(ObjectStatus *status) 
00248             : KexiDB::MessageHandler()
00249             , m_status(status)
00250         {
00251         }
00252         virtual ~ObjectStatusMessageHandler()
00253         {
00254         }
00255 
00256         virtual void showErrorMessage(const QString &title, 
00257             const QString &details = QString::null)
00258         {
00259             m_status->setStatus(title, details);
00260         }
00261         
00262         virtual void showErrorMessage(KexiDB::Object *obj, const QString& msg = QString::null)
00263         {
00264             m_status->setStatus(obj, msg);
00265         }
00266 
00267         ObjectStatus *m_status;
00268 };
00269 
00270 ObjectStatus::operator KexiDB::MessageHandler*()
00271 {
00272     if (!msgHandler)
00273         msgHandler = new ObjectStatusMessageHandler(this);
00274     return msgHandler;
00275 }
00276 
00277 void Kexi::initCmdLineArgs(int argc, char *argv[], KAboutData* aboutData)
00278 {
00279     KAboutData *about = aboutData;
00280     if (!about)
00281         about = newKexiAboutData();
00282 #ifdef CUSTOM_VERSION
00283 # include "../custom_startup.h"
00284 #endif
00285     KCmdLineArgs::init( argc, argv, about );
00286     KCmdLineArgs::addCmdLineOptions( options );
00287 }
KDE Home | KDE Accessibility Home | Description of Access Keys