KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

349 lines
8.2 KiB

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