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 _tempShowMacros = true;
00126 bool& Kexi::tempShowMacros() {
00127 #ifndef KEXI_MACROS_SUPPORT
00128     _tempShowMacros = false; 
00129 #endif
00130     return _tempShowMacros;
00131 }
00132 
00133 bool _tempShowScripts = true;
00134 bool& Kexi::tempShowScripts() { 
00135 #ifndef KEXI_SCRIPTS_SUPPORT
00136     _tempShowScripts = false; 
00137 #endif
00138     return _tempShowScripts;
00139 }
00140 
00141 //--------------------------------------------------------------------------------
00142 
00143 QFont Kexi::smallFont(QWidget *init)
00144 {
00145     _INIT_SHARED;
00146     if (!_int->smallFont) {
00147         _int->smallFont = new QFont( init->font() );
00148         const int wdth = KGlobalSettings::desktopGeometry(init).width();
00149         int size = 10 + QMAX(0, wdth - 1100) / 100;
00150         size = QMIN( init->fontInfo().pixelSize(), size );
00151         _int->smallFont->setPixelSize( size );
00152     }
00153     return *_int->smallFont;
00154 }
00155 
00156 //--------------------------------------------------------------------------------
00157 QString Kexi::nameForViewMode(int m)
00158 {
00159     if (m==NoViewMode) return i18n("No View");
00160     else if (m==DataViewMode) return i18n("Data View");
00161     else if (m==DesignViewMode) return i18n("Design View");
00162     else if (m==TextViewMode) return i18n("Text View");
00163 
00164     return i18n("Unknown");
00165 }
00166 
00167 //--------------------------------------------------------------------------------
00168 
00169 QString Kexi::msgYouCanImproveData() {
00170     return i18n("You can correct data in this row or use \"Cancel row changes\" function.");
00171 }
00172 
00173 //--------------------------------------------------------------------------------
00174 
00175 ObjectStatus::ObjectStatus()
00176 : msgHandler(0)
00177 {
00178 }
00179 
00180 ObjectStatus::ObjectStatus(const QString& message, const QString& description)
00181 : msgHandler(0)
00182 {
00183     setStatus(message, description);
00184 }
00185 
00186 ObjectStatus::ObjectStatus(KexiDB::Object* dbObject, const QString& message, const QString& description)
00187 : msgHandler(0)
00188 {
00189     setStatus(dbObject, message, description);
00190 }
00191 
00192 ObjectStatus::~ObjectStatus()
00193 {
00194     delete msgHandler;
00195 }
00196 
00197 const ObjectStatus& ObjectStatus::status() const
00198 {
00199     return *this;
00200 }
00201 
00202 bool ObjectStatus::error() const
00203 {
00204     return !message.isEmpty() 
00205         || (dynamic_cast<KexiDB::Object*>((QObject*)dbObj) && dynamic_cast<KexiDB::Object*>((QObject*)dbObj)->error());
00206 }
00207 
00208 void ObjectStatus::setStatus(const QString& message, const QString& description)
00209 {
00210     this->dbObj=0;
00211     this->message=message;
00212     this->description=description;
00213 }
00214 
00215 void ObjectStatus::setStatus(KexiDB::Object* dbObject, const QString& message, const QString& description)
00216 {
00217     if (dynamic_cast<QObject*>(dbObject)) {
00218         dbObj = dynamic_cast<QObject*>(dbObject);
00219     }
00220     this->message=message;
00221     this->description=description;
00222 }
00223 
00224 void ObjectStatus::setStatus(KexiDB::ResultInfo* result, const QString& message, const QString& description)
00225 {
00226     if (result) {
00227         if (message.isEmpty())
00228             this->message = result->msg;
00229         else
00230             this->message = message + " " + result->msg;
00231 
00232         if (description.isEmpty())
00233             this->description = result->desc;
00234         else
00235             this->description = description + " " + result->desc;
00236     }
00237     else
00238         clearStatus();
00239 }
00240 
00241 void ObjectStatus::setStatus(KexiDB::Object* dbObject, KexiDB::ResultInfo* result, 
00242     const QString& message, const QString& description)
00243 {
00244     if (!dbObject)
00245         setStatus(result, message, description);
00246     else if (!result)
00247         setStatus(dbObject, message, description);
00248     else {
00249         setStatus(dbObject, message, description);
00250         setStatus(result, this->message, this->description);
00251     }
00252 }
00253 
00254 void ObjectStatus::clearStatus()
00255 {
00256     message=QString::null;
00257     description=QString::null;
00258 }
00259 
00260 QString ObjectStatus::singleStatusString() const { 
00261     if (message.isEmpty() || description.isEmpty())
00262         return message;
00263     return message + " " + description;
00264 }
00265 
00266 void ObjectStatus::append( const ObjectStatus& otherStatus ) {
00267     if (message.isEmpty()) {
00268         message = otherStatus.message;
00269         description = otherStatus.description;
00270         return;
00271     }
00272     const QString s( otherStatus.singleStatusString() );
00273     if (s.isEmpty())
00274         return;
00275     if (description.isEmpty()) {
00276         description = s;
00277         return;
00278     }
00279     description = description + " " + s;
00280 }
00281 
00283 class ObjectStatusMessageHandler : public KexiDB::MessageHandler
00284 {
00285     public:
00286         ObjectStatusMessageHandler(ObjectStatus *status) 
00287             : KexiDB::MessageHandler()
00288             , m_status(status)
00289         {
00290         }
00291         virtual ~ObjectStatusMessageHandler()
00292         {
00293         }
00294 
00295         virtual void showErrorMessage(const QString &title, 
00296             const QString &details = QString::null)
00297         {
00298             m_status->setStatus(title, details);
00299         }
00300         
00301         virtual void showErrorMessage(KexiDB::Object *obj, const QString& msg = QString::null)
00302         {
00303             m_status->setStatus(obj, msg);
00304         }
00305 
00306         ObjectStatus *m_status;
00307 };
00308 
00309 ObjectStatus::operator KexiDB::MessageHandler*()
00310 {
00311     if (!msgHandler)
00312         msgHandler = new ObjectStatusMessageHandler(this);
00313     return msgHandler;
00314 }
00315 
00316 void Kexi::initCmdLineArgs(int argc, char *argv[], KAboutData* aboutData)
00317 {
00318     KAboutData *about = aboutData;
00319     if (!about)
00320         about = Kexi::createAboutData();
00321 #ifdef CUSTOM_VERSION
00322 # include "../custom_startup.h"
00323 #endif
00324     KCmdLineArgs::init( argc, argv, about );
00325     KCmdLineArgs::addCmdLineOptions( options );
00326 }
00327 
00328 void KEXI_UNFINISHED(const QString& feature_name, const QString& extra_text) 
00329 {
00330     QString msg;
00331     if (feature_name.isEmpty())
00332         msg = i18n("This function is not available for version %1 of %2 application.")
00333             .arg(KEXI_VERSION_STRING)
00334             .arg(KEXI_APP_NAME); 
00335     else {
00336         QString feature_name_(feature_name);
00337         msg = i18n("\"%1\" function is not available for version %2 of %3 application.")
00338             .arg(feature_name_.replace("&",""))
00339             .arg(KEXI_VERSION_STRING)
00340             .arg(KEXI_APP_NAME);
00341     }
00342 
00343     QString extra_text_(extra_text);
00344     if (!extra_text_.isEmpty())
00345         extra_text_.prepend("\n");
00346 
00347     KMessageBox::sorry(0, msg + extra_text_);
00348 }
KDE Home | KDE Accessibility Home | Description of Access Keys