Bibletime – a bible study tool
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

bibletime_slots.cpp 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. //own includes
  10. #include "bibletime.h"
  11. #include "config.h"
  12. #include "backend/cswordversekey.h"
  13. #include "util/ctoolclass.h"
  14. #include "frontend/cmdiarea.h"
  15. #include "frontend/cprofilemgr.h"
  16. #include "frontend/cprofile.h"
  17. #include "frontend/cprofilewindow.h"
  18. #include "frontend/coptionsdialog.h"
  19. #include "frontend/cswordsetupdialog.h"
  20. #include "frontend/cbtconfig.h"
  21. #include "frontend/cinputdialog.h"
  22. #include "frontend/cinfodisplay.h"
  23. #include "frontend/mainindex/cmainindex.h"
  24. #include "frontend/mainindex/cindexitem.h"
  25. #include "frontend/displaywindow/cdisplaywindow.h"
  26. #include "frontend/displaywindow/cbiblereadwindow.h"
  27. #include "frontend/searchdialog/csearchdialog.h"
  28. #include <errno.h>
  29. //QT includes
  30. #include <tqprogressdialog.h>
  31. #include <tqlistview.h>
  32. #include <tqvaluelist.h>
  33. #include <tqclipboard.h>
  34. #include <tqinputdialog.h>
  35. //KDE includes
  36. #include <kaction.h>
  37. #include <kapplication.h>
  38. #include <kaboutkde.h>
  39. #include <kaboutdialog.h>
  40. #include <kbugreport.h>
  41. #include <kaboutapplication.h>
  42. #include <kstandarddirs.h>
  43. #include <kmenubar.h>
  44. #include <kaboutdata.h>
  45. #include <kglobal.h>
  46. #include <klocale.h>
  47. #include <kedittoolbar.h>
  48. #include <kpopupmenu.h>
  49. #include <khelpmenu.h>
  50. #include <ktip.h>
  51. //Sword includes
  52. #include <versekey.h>
  53. using namespace Profile;
  54. /* An action which stores a user defined pointer to a widget.
  55. * @author Joachim Ansorg
  56. */
  57. class KUserDataAction : public TDEToggleAction {
  58. public:
  59. KUserDataAction( TQString caption, const TDEShortcut& shortcut, const TQObject* receiver, const char* slot, TDEActionCollection* actionCollection)
  60. : TDEToggleAction(caption, shortcut, receiver, slot, actionCollection), m_userData(0) { /* no impl */
  61. };
  62. void setUserData(TQWidget* const data) {
  63. m_userData = data;
  64. };
  65. TQWidget* const getUserData() const {
  66. return m_userData;
  67. };
  68. private:
  69. TQWidget* m_userData;
  70. };
  71. /** Opens the optionsdialog of BibleTime. */
  72. void BibleTime::slotSettingsOptions() {
  73. COptionsDialog *dlg = new COptionsDialog(this, "COptionsDialog", actionCollection());
  74. connect(dlg, TQT_SIGNAL(signalSettingsChanged()), TQT_SLOT(slotSettingsChanged()) );
  75. dlg->exec();
  76. dlg->delayedDestruct();
  77. }
  78. /** Is called when settings in the optionsdialog were changed (ok or apply) */
  79. void BibleTime::slotSettingsChanged() {
  80. const TQString language = CBTConfig::get
  81. (CBTConfig::language);
  82. m_backend->booknameLanguage(language);
  83. TQListViewItemIterator it( m_mainIndex );
  84. CItemBase* item = 0;
  85. for ( ; it.current(); ++it ) {
  86. if ( (item = dynamic_cast<CItemBase*>(it.current())) ) {
  87. item->update();
  88. }
  89. }
  90. refreshDisplayWindows();
  91. refreshProfileMenus();
  92. }
  93. /** Opens the sword setup dialog of BibleTime. */
  94. void BibleTime::slotSwordSetupDialog() {
  95. BookshelfManager::CSwordSetupDialog *dlg = new BookshelfManager::CSwordSetupDialog(this, "CSwordSetupDialog");
  96. connect(dlg, TQT_SIGNAL(signalSwordSetupChanged()), TQT_SLOT(slotSwordSetupChanged()) );
  97. dlg->exec();
  98. dlg->delayedDestruct();
  99. }
  100. /** Is called when settings in the sword setup dialog were changed (ok or apply) */
  101. void BibleTime::slotSwordSetupChanged() {
  102. /*
  103. Refresh everything here what might have changed
  104. these are the mainindex, the searchdialog, the displaywindows
  105. But at first we have to reset the Sword backend to reload the modules
  106. */
  107. m_mainIndex->saveBookmarks();
  108. CPointers::deleteBackend();
  109. m_backend = new CSwordBackend();
  110. CPointers::setBackend(m_backend);
  111. m_backend->initModules();
  112. m_mainIndex->reloadSword();
  113. // refresh display windows
  114. refreshDisplayWindows();
  115. }
  116. /** Shows the daily tip */
  117. void BibleTime::slotHelpTipOfDay() {
  118. KTipDialog::setShowOnStart( CBTConfig::get
  119. (CBTConfig::tips) );
  120. KTipDialog::showTip(this, "bibletime/tips", true);
  121. }
  122. /** Is called just before the window menu is ahown. */
  123. void BibleTime::slotWindowMenuAboutToShow() {
  124. Q_ASSERT(m_windowMenu);
  125. if (!m_windowMenu) {
  126. return;
  127. }
  128. if ( m_mdi->windowList().isEmpty() ) {
  129. m_windowCascade_action->setEnabled(false);
  130. m_windowTileVertical_action->setEnabled(false);
  131. m_windowTileHorizontal_action->setEnabled(false);
  132. m_windowCloseAll_action->setEnabled(false);
  133. }
  134. else if (m_mdi->windowList().count() == 1) {
  135. m_windowTileVertical_action->setEnabled( false );
  136. m_windowTileHorizontal_action->setEnabled( false );
  137. m_windowCascade_action->setEnabled( false );
  138. m_windowCloseAll_action->setEnabled( true );
  139. // m_windowMenu->insertSeparator();
  140. }
  141. else {
  142. slotUpdateWindowArrangementActions(0); //update the window tile/cascade states
  143. m_windowCloseAll_action->setEnabled( true );
  144. }
  145. TQPtrList<TDEAction>::iterator end = m_windowOpenWindowsList.end();
  146. for (TQPtrList<TDEAction>::iterator it = m_windowOpenWindowsList.begin(); it != end; ++it ) {
  147. (*it)->unplugAll();
  148. }
  149. m_windowOpenWindowsList.setAutoDelete(true);
  150. m_windowOpenWindowsList.clear();
  151. if (!m_windowActionCollection) {
  152. m_windowActionCollection = new TDEActionCollection(this);
  153. }
  154. TQWidgetList windows = m_mdi->windowList();
  155. const int count = windows.count();
  156. for ( int i = 0; i < count; ++i ) {
  157. TQWidget* w = windows.at(i);
  158. Q_ASSERT(w);
  159. KUserDataAction* action = new KUserDataAction(w->caption(), TDEShortcut(), TQT_TQOBJECT(this), TQT_SLOT(slotWindowMenuActivated()), m_windowActionCollection);
  160. Q_ASSERT(action);
  161. action->setUserData(w);
  162. m_windowOpenWindowsList.append(action);
  163. action->setChecked( w == m_mdi->activeWindow() );
  164. action->plug(m_windowMenu);
  165. }
  166. }
  167. /** This slot is connected with the windowAutoTile_action object */
  168. void BibleTime::slotUpdateWindowArrangementActions( TDEAction* clickedAction ) {
  169. /* If a toggle action was clicked we see if it checked ot unchecked and
  170. * enable/disable the simple cascade and tile options accordingly
  171. */
  172. m_windowTileVertical_action->setEnabled( m_windowManualMode_action->isChecked() );
  173. m_windowTileHorizontal_action->setEnabled( m_windowManualMode_action->isChecked() );
  174. m_windowCascade_action->setEnabled( m_windowManualMode_action->isChecked() );
  175. if (clickedAction) {
  176. m_windowManualMode_action->setEnabled(
  177. m_windowManualMode_action != clickedAction
  178. && m_windowTileHorizontal_action != clickedAction
  179. && m_windowTileVertical_action != clickedAction
  180. && m_windowCascade_action != clickedAction
  181. );
  182. m_windowAutoTileVertical_action->setEnabled( m_windowAutoTileVertical_action != clickedAction );
  183. m_windowAutoTileHorizontal_action->setEnabled( m_windowAutoTileHorizontal_action != clickedAction );
  184. m_windowAutoCascade_action->setEnabled( m_windowAutoCascade_action != clickedAction );
  185. }
  186. if (clickedAction == m_windowManualMode_action) {
  187. m_windowAutoTileVertical_action->setChecked(false);
  188. m_windowAutoTileHorizontal_action->setChecked(false);
  189. m_windowAutoCascade_action->setChecked(false);
  190. m_mdi->setGUIOption( CMDIArea::Nothing );
  191. }
  192. else if (clickedAction == m_windowAutoTileVertical_action) {
  193. m_windowManualMode_action->setChecked(false);
  194. m_windowAutoTileHorizontal_action->setChecked(false);
  195. m_windowAutoCascade_action->setChecked(false);
  196. m_mdi->setGUIOption( CMDIArea::autoTileVertical );
  197. }
  198. else if (clickedAction == m_windowAutoTileHorizontal_action) {
  199. m_windowManualMode_action->setChecked(false);
  200. m_windowAutoTileVertical_action->setChecked(false);
  201. m_windowAutoCascade_action->setChecked(false);
  202. m_mdi->setGUIOption( CMDIArea::autoTileHorizontal );
  203. }
  204. else if (clickedAction == m_windowAutoCascade_action) {
  205. m_windowManualMode_action->setChecked(false);
  206. m_windowAutoTileHorizontal_action->setChecked(false);
  207. m_windowAutoTileVertical_action->setChecked(false);
  208. m_mdi->setGUIOption( CMDIArea::autoCascade );
  209. }
  210. else if (clickedAction == m_windowCascade_action) {
  211. m_mdi->setGUIOption( CMDIArea::Nothing );
  212. m_mdi->myCascade();
  213. }
  214. else if (clickedAction == m_windowTileVertical_action) {
  215. m_mdi->setGUIOption( CMDIArea::Nothing );
  216. m_mdi->myTileVertical();
  217. }
  218. else if (clickedAction == m_windowTileHorizontal_action) {
  219. m_mdi->setGUIOption( CMDIArea::Nothing );
  220. m_mdi->myTileHorizontal();
  221. }
  222. }
  223. void BibleTime::slotManualArrangementMode() {
  224. slotUpdateWindowArrangementActions( m_windowManualMode_action );
  225. }
  226. /** This slot is connected with the windowAutoTile_action object */
  227. void BibleTime::slotAutoTileHorizontal() {
  228. slotUpdateWindowArrangementActions( m_windowAutoTileHorizontal_action );
  229. }
  230. /** This slot is connected with the windowAutoTile_action object */
  231. void BibleTime::slotAutoTileVertical() {
  232. slotUpdateWindowArrangementActions( m_windowAutoTileVertical_action );
  233. }
  234. void BibleTime::slotCascade() {
  235. slotUpdateWindowArrangementActions( m_windowCascade_action );
  236. }
  237. void BibleTime::slotTileVertical() {
  238. slotUpdateWindowArrangementActions( m_windowTileVertical_action );
  239. }
  240. void BibleTime::slotTileHorizontal() {
  241. slotUpdateWindowArrangementActions( m_windowTileHorizontal_action );
  242. }
  243. /** This slot is connected with the windowAutoCascade_action object */
  244. void BibleTime::slotAutoCascade() {
  245. slotUpdateWindowArrangementActions( m_windowAutoCascade_action );
  246. }
  247. void BibleTime::slotWindowMenuActivated() {
  248. if (!m_windowMenu) {
  249. return;
  250. }
  251. const KUserDataAction* action = dynamic_cast<const KUserDataAction*>(sender());
  252. Q_ASSERT(action);
  253. if (action) {
  254. TQWidget* const window = action->getUserData();
  255. Q_ASSERT(window);
  256. if ( window ) {
  257. window->setFocus();
  258. }
  259. }
  260. }
  261. /** Shows/hides the toolbar */
  262. void BibleTime::slotToggleToolbar() {
  263. Q_ASSERT(toolBar("mainToolBar"));
  264. if (m_viewToolbar_action->isChecked()) {
  265. toolBar("mainToolBar")->show();
  266. }
  267. else {
  268. toolBar("mainToolBar")->hide();
  269. }
  270. }
  271. /** Shows or hides the groupmanager.
  272. */
  273. void BibleTime::slotToggleMainIndex() {
  274. //we use the parent widget because the main index is enclosed in a layout which adds the label at the top
  275. if (m_viewMainIndex_action->isChecked()) {
  276. m_mainIndex->parentWidget()->show();
  277. }
  278. else {
  279. m_mainIndex->parentWidget()->hide();
  280. }
  281. }
  282. /** Shows or hides the groupmanager. */
  283. void BibleTime::slotToggleInfoDisplay() {
  284. if (m_viewInfoDisplay_action->isChecked()) {
  285. m_infoDisplay->show();
  286. }
  287. else {
  288. m_infoDisplay->hide();
  289. }
  290. }
  291. /** Opens a toolbar editor */
  292. void BibleTime::slotSettingsToolbar() {
  293. KEditToolbar dlg(actionCollection());
  294. if (dlg.exec()) {
  295. createGUI();
  296. }
  297. }
  298. void BibleTime::slotSearchModules() {
  299. //get the modules of the open windows
  300. ListCSwordModuleInfo modules;
  301. TQWidgetList windows = m_mdi->windowList();
  302. for ( int i = 0; i < static_cast<int>(windows.count()); ++i ) {
  303. if (CDisplayWindow* w = dynamic_cast<CDisplayWindow*>(windows.at(i))) {
  304. ListCSwordModuleInfo windowModules = w->modules();
  305. ListCSwordModuleInfo::iterator end_it = windowModules.end();
  306. for (ListCSwordModuleInfo::iterator it(windowModules.begin()); it != end_it; ++it) {
  307. modules.append(*it);
  308. };
  309. };
  310. };
  311. Search::CSearchDialog::openDialog(modules, TQString());
  312. }
  313. /* Search default Bible slot
  314. * Call CSearchDialog::openDialog with only the default bible module
  315. */
  316. void BibleTime::slotSearchDefaultBible() {
  317. ListCSwordModuleInfo module;
  318. CSwordModuleInfo* bible = CBTConfig::get
  319. (CBTConfig::standardBible);
  320. if (bible) {
  321. module.append(bible);
  322. }
  323. Search::CSearchDialog::openDialog(module, TQString());
  324. }
  325. void BibleTime::openOnlineHelp_Handbook() {
  326. kapp->invokeHelp("", "bibletime/handbook/");
  327. }
  328. void BibleTime::openOnlineHelp_Howto() {
  329. kapp->invokeHelp("", "bibletime/howto/");
  330. }
  331. /** Saves the current settings into the currently activatred profile. */
  332. void BibleTime::saveProfile(int ID) {
  333. m_mdi->setUpdatesEnabled(false);
  334. TDEPopupMenu* popup = m_windowSaveProfile_action->popupMenu();
  335. const TQString profileName = popup->text(ID).remove("&");
  336. CProfile* p = m_profileMgr.profile( profileName );
  337. Q_ASSERT(p);
  338. if ( p ) {
  339. saveProfile(p);
  340. }
  341. m_mdi->setUpdatesEnabled(true);
  342. }
  343. void BibleTime::saveProfile(CProfile* profile) {
  344. if (!profile) {
  345. return;
  346. }
  347. //save mainwindow settings
  348. storeProfileSettings(profile);
  349. TQWidgetList windows = m_mdi->windowList();
  350. TQPtrList<CProfileWindow> profileWindows;
  351. for (TQWidget* w = windows.first(); w; w = windows.next()) {
  352. CDisplayWindow* displayWindow = dynamic_cast<CDisplayWindow*>(w);
  353. if (!displayWindow) {
  354. continue;
  355. }
  356. CProfileWindow* profileWindow = new CProfileWindow();
  357. displayWindow->storeProfileSettings(profileWindow);
  358. profileWindows.append(profileWindow);
  359. }
  360. profile->save(profileWindows);
  361. //clean up memory - delete all created profile windows
  362. profileWindows.setAutoDelete(true);
  363. profileWindows.clear();
  364. }
  365. void BibleTime::loadProfile(int ID) {
  366. TDEPopupMenu* popup = m_windowLoadProfile_action->popupMenu();
  367. //HACK: workaround the inserted & char by TDEPopupMenu
  368. const TQString profileName = popup->text(ID).remove("&");
  369. CProfile* p = m_profileMgr.profile( profileName );
  370. // tqWarning("requesting popup: %s", popup->text(ID).latin1());
  371. Q_ASSERT(p);
  372. if ( p ) {
  373. m_mdi->deleteAll();
  374. loadProfile(p);
  375. }
  376. }
  377. void BibleTime::loadProfile(CProfile* p) {
  378. Q_ASSERT(p);
  379. if (!p) {
  380. return;
  381. }
  382. TQPtrList<CProfileWindow> windows = p->load();
  383. Q_ASSERT(windows.count());
  384. //load mainwindow setttings
  385. applyProfileSettings(p);
  386. m_mdi->setUpdatesEnabled(false);//don't auto tile or auto cascade, this would mess up everything!!
  387. TQWidget* focusWindow = 0;
  388. // for (CProfileWindow* w = windows.last(); w; w = windows.prev()) { //from the last one to make sure the order is right in the mdi area
  389. for (CProfileWindow* w = windows.first(); w; w = windows.next()) {
  390. const TQString key = w->key();
  391. TQStringList usedModules = w->modules();
  392. ListCSwordModuleInfo modules;
  393. for ( TQStringList::Iterator it = usedModules.begin(); it != usedModules.end(); ++it ) {
  394. if (CSwordModuleInfo* m = m_backend->findModuleByName(*it)) {
  395. modules.append(m);
  396. }
  397. }
  398. if (!modules.count()) { //are the modules still installed? If not continue wih next session window
  399. continue;
  400. }
  401. //is w->isWriteWindow is false we create a write window, otherwise a read window
  402. CDisplayWindow* displayWindow = 0;
  403. if (w->writeWindowType() > 0) { //create a write window
  404. displayWindow = createWriteDisplayWindow(modules.first(), key, CDisplayWindow::WriteWindowType(w->writeWindowType()) );
  405. }
  406. else { //create a read window
  407. displayWindow = createReadDisplayWindow(modules, key);
  408. }
  409. if (displayWindow) { //if a window was created initialize it.
  410. if (w->hasFocus()) {
  411. focusWindow = displayWindow;
  412. }
  413. displayWindow->applyProfileSettings(w);
  414. };
  415. }
  416. m_mdi->setUpdatesEnabled(true);
  417. if (focusWindow) {
  418. focusWindow->setFocus();
  419. }
  420. }
  421. void BibleTime::deleteProfile(int ID) {
  422. TDEPopupMenu* popup = m_windowDeleteProfile_action->popupMenu();
  423. //HACK: work around the inserted & char by TDEPopupMenu
  424. const TQString profileName = popup->text(ID).remove("&");
  425. CProfile* p = m_profileMgr.profile( profileName );
  426. Q_ASSERT(p);
  427. if ( p ) {
  428. m_profileMgr.remove(p);
  429. }
  430. refreshProfileMenus();
  431. }
  432. void BibleTime::toggleFullscreen() {
  433. m_windowFullscreen_action->isChecked() ? showFullScreen() : showNormal();
  434. m_mdi->triggerWindowUpdate();
  435. }
  436. /** Saves current settings into a new profile. */
  437. void BibleTime::saveToNewProfile() {
  438. bool ok = false;
  439. const TQString name = TQInputDialog::getText(i18n("Session name:"), i18n("Please enter a name for the new session."), TQLineEdit::Normal, TQString(), &ok, this);
  440. if (ok && !name.isEmpty()) {
  441. CProfile* profile = m_profileMgr.create(name);
  442. saveProfile(profile);
  443. };
  444. refreshProfileMenus();
  445. }
  446. /** Slot to refresh the save profile and load profile menus. */
  447. void BibleTime::refreshProfileMenus() {
  448. TDEPopupMenu* savePopup = m_windowSaveProfile_action->popupMenu();
  449. savePopup->clear();
  450. TDEPopupMenu* loadPopup = m_windowLoadProfile_action->popupMenu();
  451. loadPopup->clear();
  452. TDEPopupMenu* deletePopup = m_windowDeleteProfile_action->popupMenu();
  453. deletePopup->clear();
  454. //refresh the load, save and delete profile menus
  455. m_profileMgr.refresh();
  456. TQPtrList<CProfile> profiles = m_profileMgr.profiles();
  457. const bool enableActions = bool(profiles.count() != 0);
  458. m_windowSaveProfile_action->setEnabled(enableActions);
  459. m_windowLoadProfile_action->setEnabled(enableActions);
  460. m_windowDeleteProfile_action->setEnabled(enableActions);
  461. for (CProfile* p = profiles.first(); p; p = profiles.next()) {
  462. savePopup->insertItem(p->name());
  463. loadPopup->insertItem(p->name());
  464. deletePopup->insertItem(p->name());
  465. }
  466. }