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.

cplainwritewindow.cpp 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #include "cplainwritewindow.h"
  10. #include "frontend/keychooser/ckeychooser.h"
  11. #include "frontend/cprofilewindow.h"
  12. #include "frontend/cbtconfig.h"
  13. #include "util/cresmgr.h"
  14. //TQt includes
  15. #include <tqregexp.h>
  16. //KDE includes
  17. #include <tdeaction.h>
  18. #include <tdeaccel.h>
  19. #include <tdelocale.h>
  20. #include <tdemessagebox.h>
  21. using namespace Profile;
  22. CPlainWriteWindow::CPlainWriteWindow(ListCSwordModuleInfo moduleList, CMDIArea* parent, const char *name ) : CWriteWindow(moduleList, parent, name) {
  23. setKey( CSwordKey::createInstance(moduleList.first()) );
  24. }
  25. CPlainWriteWindow::~CPlainWriteWindow() {}
  26. /** Initialize the state of this widget. */
  27. void CPlainWriteWindow::initView() {
  28. // tqWarning("CPlainWriteWindow::initView()");
  29. setDisplayWidget( CDisplay::createWriteInstance(this) );
  30. setCentralWidget( displayWidget()->view() );
  31. setMainToolBar( new TDEToolBar(this) );
  32. mainToolBar()->setFullSize(true);
  33. addDockWindow(mainToolBar());
  34. setKeyChooser( CKeyChooser::createInstance(modules(), key(), mainToolBar()) );
  35. mainToolBar()->insertWidget(0,keyChooser()->sizeHint().width(),keyChooser());
  36. mainToolBar()->setFullSize(false);
  37. }
  38. void CPlainWriteWindow::initToolbars() {
  39. m_actions.syncWindow = new TDEToggleAction(i18n("Sync with active Bible"),
  40. CResMgr::displaywindows::commentaryWindow::syncWindow::icon,
  41. CResMgr::displaywindows::commentaryWindow::syncWindow::accel,
  42. actionCollection(),
  43. CResMgr::displaywindows::commentaryWindow::syncWindow::actionName
  44. );
  45. m_actions.syncWindow->setToolTip(CResMgr::displaywindows::commentaryWindow::syncWindow::tooltip);
  46. m_actions.syncWindow->plug(mainToolBar());
  47. m_actions.saveText = new TDEAction(i18n("Save text"),
  48. CResMgr::displaywindows::writeWindow::saveText::icon,
  49. CResMgr::displaywindows::writeWindow::saveText::accel,
  50. TQT_TQOBJECT(this), TQT_SLOT(saveCurrentText()),
  51. actionCollection(),
  52. CResMgr::displaywindows::writeWindow::saveText::actionName
  53. );
  54. m_actions.saveText->setToolTip( CResMgr::displaywindows::writeWindow::saveText::tooltip );
  55. m_actions.saveText->plug(mainToolBar());
  56. m_actions.deleteEntry = new TDEAction(i18n("Delete current entry"),
  57. CResMgr::displaywindows::writeWindow::deleteEntry::icon,
  58. CResMgr::displaywindows::writeWindow::deleteEntry::accel,
  59. TQT_TQOBJECT(this), TQT_SLOT(deleteEntry()),
  60. actionCollection(),
  61. CResMgr::displaywindows::writeWindow::deleteEntry::actionName
  62. );
  63. m_actions.deleteEntry->setToolTip( CResMgr::displaywindows::writeWindow::deleteEntry::tooltip );
  64. m_actions.deleteEntry->plug(mainToolBar());
  65. m_actions.restoreText = new TDEAction(i18n("Restore original text"),
  66. CResMgr::displaywindows::writeWindow::restoreText::icon,
  67. CResMgr::displaywindows::writeWindow::restoreText::accel,
  68. TQT_TQOBJECT(this), TQT_SLOT(restoreText()),
  69. actionCollection(),
  70. CResMgr::displaywindows::writeWindow::restoreText::actionName
  71. );
  72. m_actions.restoreText->setToolTip( CResMgr::displaywindows::writeWindow::restoreText::tooltip );
  73. m_actions.restoreText->plug(mainToolBar());
  74. }
  75. void CPlainWriteWindow::initConnections() {
  76. CWriteWindow::initConnections();
  77. connect(keyChooser(), TQT_SIGNAL(keyChanged(CSwordKey*)),
  78. TQT_TQOBJECT(this), TQT_SLOT(lookup(CSwordKey*)));
  79. connect(displayWidget()->connectionsProxy(), TQT_SIGNAL(textChanged()),
  80. TQT_TQOBJECT(this), TQT_SLOT(textChanged()) );
  81. }
  82. void CPlainWriteWindow::storeProfileSettings( CProfileWindow* profileWindow ) {
  83. CWriteWindow::storeProfileSettings(profileWindow);
  84. profileWindow->setWindowSettings( m_actions.syncWindow->isChecked() );
  85. };
  86. void CPlainWriteWindow::applyProfileSettings( CProfileWindow* profileWindow ) {
  87. CWriteWindow::applyProfileSettings(profileWindow);
  88. if (profileWindow->windowSettings()) {
  89. m_actions.syncWindow->setChecked(true);
  90. }
  91. };
  92. /** Saves the text for the current key. Directly writes the changed text into the module. */
  93. void CPlainWriteWindow::saveCurrentText( const TQString& /*key*/ ) {
  94. TQString t = displayWidget()->plainText();
  95. //since t is a complete HTML page at the moment, strip away headers and footers of a HTML page
  96. TQRegExp re("(?:<html.*>.+<body.*>)", false); //remove headers, case insensitive
  97. re.setMinimal(true);
  98. t.replace(re, "");
  99. t.replace(TQRegExp("</body></html>", false), "");//remove footer
  100. const TQString& oldKey = this->key()->key();
  101. if( modules().first()->isWritable() ) {
  102. modules().first()->write(this->key(), t );
  103. this->key()->key( oldKey );
  104. displayWidget()->setModified(false);
  105. textChanged();
  106. } else {
  107. KMessageBox::error( this,
  108. TQString::fromLatin1("<qt><B>%1</B><BR>%2</qt>")
  109. .arg( i18n("Module is not writable.") )
  110. .arg( i18n("Either the module may not be edited, or "
  111. "you do not have write permission.") ),
  112. i18n("Module not writable") );
  113. }
  114. }
  115. /** Loads the original text from the module. */
  116. void CPlainWriteWindow::restoreText() {
  117. lookup(key());
  118. displayWidget()->setModified(false);
  119. textChanged();
  120. }
  121. /** Is called when the current text was changed. */
  122. void CPlainWriteWindow::textChanged() {
  123. m_actions.saveText->setEnabled( displayWidget()->isModified() );
  124. m_actions.restoreText->setEnabled( displayWidget()->isModified() );
  125. }
  126. /** Deletes the module entry and clears the edit widget, */
  127. void CPlainWriteWindow::deleteEntry() {
  128. modules().first()->deleteEntry( key() );
  129. lookup( key() );
  130. displayWidget()->setModified(false);
  131. }
  132. /** Setups the popup menu of this display widget. */
  133. void CPlainWriteWindow::setupPopupMenu() {}
  134. const bool CPlainWriteWindow::syncAllowed() const {
  135. return m_actions.syncWindow->isChecked();
  136. }
  137. void CPlainWriteWindow::initActions() {
  138. }
  139. void CPlainWriteWindow::insertKeyboardActions( TDEActionCollection* const ) {
  140. }
  141. #include "cplainwritewindow.moc"