kexi
kexi.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00078 if (!_int->connset) {
00079
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
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()
00197 || (dynamic_cast<KexiDB::Object*>((QObject*)dbObj) && dynamic_cast<KexiDB::Object*>((QObject*)dbObj)->error());
00198 }
00199
00200 void ObjectStatus::setStatus(const QString& message, const QString& description)
00201 {
00202 this->dbObj=0;
00203 this->message=message;
00204 this->description=description;
00205 }
00206
00207 void ObjectStatus::setStatus(KexiDB::Object* dbObject, const QString& message, const QString& description)
00208 {
00209 if (dynamic_cast<QObject*>(dbObject)) {
00210 dbObj = dynamic_cast<QObject*>(dbObject);
00211 }
00212 this->message=message;
00213 this->description=description;
00214 }
00215
00216 void ObjectStatus::clearStatus()
00217 {
00218 message=QString::null;
00219 description=QString::null;
00220 }
00221
00222 QString ObjectStatus::singleStatusString() const {
00223 if (message.isEmpty() || description.isEmpty())
00224 return message;
00225 return message + " " + description;
00226 }
00227
00228 void ObjectStatus::append( const ObjectStatus& otherStatus ) {
00229 if (message.isEmpty()) {
00230 message = otherStatus.message;
00231 description = otherStatus.description;
00232 return;
00233 }
00234 QString s = otherStatus.singleStatusString();
00235 if (s.isEmpty())
00236 return;
00237 if (description.isEmpty()) {
00238 description = s;
00239 return;
00240 }
00241 description = description + " " + s;
00242 }
00243
00245 class ObjectStatusMessageHandler : public KexiDB::MessageHandler
00246 {
00247 public:
00248 ObjectStatusMessageHandler(ObjectStatus *status)
00249 : KexiDB::MessageHandler()
00250 , m_status(status)
00251 {
00252 }
00253 virtual ~ObjectStatusMessageHandler()
00254 {
00255 }
00256
00257 virtual void showErrorMessage(const QString &title,
00258 const QString &details = QString::null)
00259 {
00260 m_status->setStatus(title, details);
00261 }
00262
00263 virtual void showErrorMessage(KexiDB::Object *obj, const QString& msg = QString::null)
00264 {
00265 m_status->setStatus(obj, msg);
00266 }
00267
00268 ObjectStatus *m_status;
00269 };
00270
00271 ObjectStatus::operator KexiDB::MessageHandler*()
00272 {
00273 if (!msgHandler)
00274 msgHandler = new ObjectStatusMessageHandler(this);
00275 return msgHandler;
00276 }
00277
00278 void Kexi::initCmdLineArgs(int argc, char *argv[], KAboutData* aboutData)
00279 {
00280 KAboutData *about = aboutData;
00281 if (!about)
00282 about = newKexiAboutData();
00283 #ifdef CUSTOM_VERSION
00284 # include "../custom_startup.h"
00285 #endif
00286 KCmdLineArgs::init( argc, argv, about );
00287 KCmdLineArgs::addCmdLineOptions( options );
00288 }
|