Bibletime – a bible study tool
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.

bibletime.cpp 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*********
  2. *
  3. * This file is part of BibleTime's source code, http://www.bibletime.info/.
  4. *
  5. * Copyright 1999-2006 by the BibleTime developers.
  6. * The BibleTime source code is licensed under the GNU General Public License version 2.0.
  7. *
  8. **********/
  9. //local includes
  10. #include "config.h"
  11. #include "bibletime.h"
  12. //frontend includes
  13. #include "frontend/cmdiarea.h"
  14. #include "frontend/kstartuplogo.h"
  15. #include "frontend/mainindex/cmainindex.h"
  16. #include "frontend/displaywindow/cdisplaywindow.h"
  17. #include "frontend/displaywindow/creadwindow.h"
  18. #include "frontend/displaywindow/cwritewindow.h"
  19. #include "frontend/keychooser/ckeychooser.h"
  20. #include "frontend/cbtconfig.h"
  21. #include "util/ctoolclass.h"
  22. #include "util/cpointers.h"
  23. //backend includes
  24. #include "backend/cswordmoduleinfo.h"
  25. #include "backend/cswordbiblemoduleinfo.h"
  26. #include "backend/cswordcommentarymoduleinfo.h"
  27. #include "backend/cswordlexiconmoduleinfo.h"
  28. #include "backend/cswordbookmoduleinfo.h"
  29. #include "backend/cswordversekey.h"
  30. #include "backend/cswordldkey.h"
  31. //TQt includes
  32. #include <tqsplitter.h>
  33. //KDE includes
  34. #include <tdeversion.h>
  35. #include <tdeaction.h>
  36. #include <tdeapplication.h>
  37. #include <tdeconfig.h>
  38. #include <tdecmdlineargs.h>
  39. #include <tdelocale.h>
  40. #include <tdeaccel.h>
  41. #include <tdemenubar.h>
  42. #include <tdetoolbar.h>
  43. #include <krandomsequence.h>
  44. using namespace Profile;
  45. BibleTime::BibleTime()
  46. : BibleTimeInterface("BibleTimeInterface"),
  47. #if TDE_VERSION >= 0x030200
  48. TDEMainWindow(TDEMainWindow::NoDCOPObject, 0,0, WType_TopLevel),
  49. #else
  50. TDEMainWindow(0,0, WType_TopLevel),
  51. #endif
  52. m_windowActionCollection(0),
  53. m_initialized(false),
  54. m_moduleList(0),
  55. m_progress(0),
  56. m_currentProfile(0),
  57. m_mainSplitter(0),
  58. m_leftPaneSplitter(0),
  59. m_mdi(0),
  60. m_profileMgr(),
  61. m_backend(0),
  62. m_mainIndex(0) {
  63. setObjId("BibleTimeInterface");
  64. setHelpMenuEnabled(false);
  65. initBackends();
  66. initView();
  67. initActions();
  68. createGUI("bibletimeui.rc");
  69. initMenubar();
  70. initConnections();
  71. readSettings();
  72. setPlainCaption("BibleTime " VERSION);
  73. // we don't save the geometry, it's stored in the startup profile
  74. setAutoSaveSettings(TQString("MainWindow"), false);
  75. }
  76. BibleTime::~BibleTime() {
  77. // delete m_dcopInterface;
  78. // The backend is deleted by the BibleTimeApp instance
  79. }
  80. /** Saves the properties of BibleTime to the application wide configfile */
  81. void BibleTime::saveSettings() {
  82. if (m_mdi) {
  83. m_mdi->saveSettings();
  84. }
  85. accel()->writeSettings(CBTConfig::getConfig());
  86. CBTConfig::set
  87. (CBTConfig::toolbar, m_viewToolbar_action->isChecked());
  88. CBTConfig::set
  89. (CBTConfig::mainIndex, m_viewMainIndex_action->isChecked());
  90. CBTConfig::set
  91. (CBTConfig::infoDisplay, m_viewInfoDisplay_action->isChecked());
  92. CBTConfig::set
  93. (CBTConfig::mainSplitterSizes, m_mainSplitter->sizes());
  94. CBTConfig::set
  95. (CBTConfig::leftPaneSplitterSizes, m_leftPaneSplitter->sizes());
  96. // set the default to false
  97. /* CBTConfig::set(CBTConfig::autoTileVertical, false);
  98. CBTConfig::set(CBTConfig::autoTileHorizontal, false);
  99. CBTConfig::set(CBTConfig::autoCascade, false);
  100. */
  101. CBTConfig::set
  102. (CBTConfig::autoTileVertical, m_windowAutoTileVertical_action->isChecked());
  103. CBTConfig::set
  104. (CBTConfig::autoTileHorizontal, m_windowAutoTileHorizontal_action->isChecked());
  105. CBTConfig::set
  106. (CBTConfig::autoCascade, m_windowAutoCascade_action->isChecked());
  107. CProfile* p = m_profileMgr.startupProfile();
  108. if (p) {
  109. saveProfile(p);
  110. }
  111. }
  112. /** Reads the settings from the configfile and sets the right properties. */
  113. void BibleTime::readSettings() {
  114. // accel()->readSettings(CBTConfig::getConfig());
  115. CBTConfig::setupAccelSettings(CBTConfig::application, actionCollection());
  116. m_viewToolbar_action->setChecked( CBTConfig::get
  117. (CBTConfig::toolbar) );
  118. slotToggleToolbar();
  119. m_viewMainIndex_action->setChecked( CBTConfig::get
  120. (CBTConfig::mainIndex) );
  121. slotToggleMainIndex();
  122. m_viewInfoDisplay_action->setChecked( CBTConfig::get
  123. (CBTConfig::infoDisplay) );
  124. slotToggleInfoDisplay();
  125. m_mainSplitter->setSizes(
  126. CBTConfig::get
  127. (CBTConfig::mainSplitterSizes)
  128. );
  129. m_leftPaneSplitter->setSizes(
  130. CBTConfig::get
  131. (CBTConfig::leftPaneSplitterSizes)
  132. );
  133. if ( CBTConfig::get
  134. (CBTConfig::autoTileVertical) ) {
  135. m_windowAutoTileVertical_action->setChecked( true );
  136. m_windowManualMode_action->setChecked(false);
  137. slotAutoTileVertical();
  138. }
  139. else if ( CBTConfig::get
  140. (CBTConfig::autoTileHorizontal) ) {
  141. m_windowAutoTileHorizontal_action->setChecked( true );
  142. m_windowManualMode_action->setChecked(false);
  143. slotAutoTileHorizontal();
  144. }
  145. else if ( CBTConfig::get
  146. (CBTConfig::autoCascade) ) {
  147. m_windowAutoCascade_action->setChecked(true);
  148. m_windowManualMode_action->setChecked(false);
  149. slotAutoCascade();
  150. }
  151. else {
  152. m_windowManualMode_action->setChecked(true);
  153. slotManualArrangementMode();
  154. }
  155. }
  156. /** Creates a new presenter in the MDI area according to the type of the module. */
  157. CDisplayWindow* BibleTime::createReadDisplayWindow(ListCSwordModuleInfo modules, const TQString& key) {
  158. kapp->setOverrideCursor( waitCursor );
  159. CDisplayWindow* displayWindow = CDisplayWindow::createReadInstance(modules, m_mdi);
  160. if ( displayWindow ) {
  161. displayWindow->init();
  162. displayWindow->show();
  163. // if (!key.isEmpty())
  164. displayWindow->lookup(key);
  165. }
  166. kapp->restoreOverrideCursor();
  167. return displayWindow;
  168. }
  169. /** Creates a new presenter in the MDI area according to the type of the module. */
  170. CDisplayWindow* BibleTime::createReadDisplayWindow(CSwordModuleInfo* module, const TQString& key) {
  171. ListCSwordModuleInfo list;
  172. list.append(module);
  173. return createReadDisplayWindow(list, key);
  174. }
  175. CDisplayWindow* BibleTime::createWriteDisplayWindow(CSwordModuleInfo* module, const TQString& key, const CDisplayWindow::WriteWindowType& type) {
  176. kapp->setOverrideCursor( waitCursor );
  177. ListCSwordModuleInfo modules;
  178. modules.append(module);
  179. CDisplayWindow* displayWindow = CDisplayWindow::createWriteInstance(modules, m_mdi, type);
  180. if ( displayWindow ) {
  181. displayWindow->init();
  182. displayWindow->show();
  183. displayWindow->lookup(key);
  184. }
  185. kapp->restoreOverrideCursor();
  186. return displayWindow;
  187. }
  188. /** Refreshes all presenters.*/
  189. void BibleTime::refreshDisplayWindows() {
  190. unsigned int index;
  191. for ( index = 0; index < m_mdi->windowList().count(); index++) {
  192. CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(m_mdi->windowList().at(index));
  193. if (window) {
  194. window->reload();
  195. }
  196. }
  197. }
  198. /** Called before quit. */
  199. bool BibleTime::queryExit() {
  200. bool ret = false;
  201. if (m_initialized) {
  202. saveSettings();
  203. ret = true;
  204. }
  205. return ret;
  206. }
  207. /** Called before a window is closed */
  208. bool BibleTime::queryClose() {
  209. bool ret = true;
  210. for ( unsigned int index = 0; index < m_mdi->windowList().count(); ++index) {
  211. if (CDisplayWindow* window = dynamic_cast<CDisplayWindow*>(m_mdi->windowList().at(index))
  212. ) {
  213. ret = ret && window->queryClose();
  214. }
  215. }
  216. return ret;
  217. }
  218. /** Reimplementation used for sessions management. */
  219. void BibleTime::saveProperties(TDEConfig* /*myConfig*/) {}
  220. /** Reimplementation used for session management. */
  221. void BibleTime::readProperties(TDEConfig* /*myConfig*/) {}
  222. /** Restores the workspace if the flag for this is set in the config. */
  223. void BibleTime::restoreWorkspace() {
  224. if (CProfile* p = m_profileMgr.startupProfile()) {
  225. loadProfile(p);
  226. }
  227. }
  228. /** Sets the caption of the mainwindow */
  229. void BibleTime::setCaption( const TQString& ) {
  230. TDEMainWindow::setPlainCaption( TDEApplication::kApplication()->makeStdCaption( m_mdi->currentApplicationCaption() ) );
  231. }
  232. /** Sets the plain caption of the main window */
  233. void BibleTime::setPlainCaption( const TQString& ) {
  234. TDEMainWindow::setPlainCaption( TDEApplication::kApplication()->makeStdCaption( m_mdi->currentApplicationCaption() ) );
  235. }
  236. /** Processes the commandline options given to BibleTime. */
  237. void BibleTime::processCommandline() {
  238. TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
  239. // if (CBTConfig::get(CBTConfig::crashedLastTime)) {
  240. if (!CBTConfig::get
  241. (CBTConfig::crashedTwoTimes) && !args->isSet("ignore-session")) { //restore workspace if it crashed only once
  242. restoreWorkspace();
  243. }
  244. // }
  245. //open every time a module if the command line option was set.
  246. if ( args->isSet("open-default-bible") && !CBTConfig::get
  247. (CBTConfig::crashedLastTime) && !CBTConfig::get
  248. (CBTConfig::crashedTwoTimes)) { //restore workspace if it crashed ony once
  249. TQString bibleKey = args->getOption("open-default-bible");
  250. CSwordModuleInfo* bible = CBTConfig::get
  251. (CBTConfig::standardBible);
  252. if (bibleKey == "<random>") {
  253. CSwordVerseKey vk(0);
  254. const int maxIndex = 32400;
  255. KRandomSequence rs;
  256. int newIndex = rs.getLong(maxIndex);
  257. vk.setPosition(sword::TOP);
  258. #ifdef SWORD_API_1_7
  259. vk.setIndex(newIndex);
  260. #else
  261. vk.Index(newIndex);
  262. #endif
  263. bibleKey = vk.key();
  264. }
  265. createReadDisplayWindow(bible, bibleKey);
  266. // if (isVisible())
  267. m_mdi->myTileVertical();//we are sure only one window is open, which should be displayed fullscreen in the working area
  268. }
  269. }
  270. void BibleTime::polish() {
  271. m_initialized = true;
  272. TDEMainWindow::polish();
  273. applyMainWindowSettings(CBTConfig::getConfig(), TQString::fromLatin1("MainWindow"));
  274. }
  275. #include "bibletime.moc"