Diffstat (limited to 'noncore/apps/dagger/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/dagger/mainwindow.cpp | 710 |
1 files changed, 710 insertions, 0 deletions
diff --git a/noncore/apps/dagger/mainwindow.cpp b/noncore/apps/dagger/mainwindow.cpp new file mode 100644 index 0000000..ace8f36 --- a/dev/null +++ b/noncore/apps/dagger/mainwindow.cpp | |||
@@ -0,0 +1,710 @@ | |||
1 | /* | ||
2 | Dagger - A Bible study program utilizing the Sword library. | ||
3 | Copyright (c) 2004 Dan Williams <drw@handhelds.org> | ||
4 | |||
5 | This file is free software; you can redistribute it and/or modify it under | ||
6 | the terms of the GNU General Public License as published by the Free Software | ||
7 | Foundation; either version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This file is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
11 | PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with this | ||
14 | file; see the file COPYING. If not, write to the Free Software Foundation, Inc., | ||
15 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
16 | */ | ||
17 | |||
18 | #include "mainwindow.h" | ||
19 | #include "navbar.h" | ||
20 | #include "searchbar.h" | ||
21 | #include "opentextdlg.h" | ||
22 | #include "configuredlg.h" | ||
23 | #include "textwidget.h" | ||
24 | |||
25 | #include <opie2/odebug.h> | ||
26 | |||
27 | #include <qpe/qcopenvelope_qws.h> | ||
28 | #include <qpe/qpeapplication.h> | ||
29 | #include <qpe/resource.h> | ||
30 | |||
31 | #include <qaction.h> | ||
32 | #include <qclipboard.h> | ||
33 | #include <qmenubar.h> | ||
34 | #include <qobjectlist.h> | ||
35 | #include <qpopupmenu.h> | ||
36 | #include <qtimer.h> | ||
37 | #include <qtoolbar.h> | ||
38 | |||
39 | #include <markupfiltmgr.h> | ||
40 | |||
41 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags /*fl*/ ) | ||
42 | : QMainWindow( parent, name, WStyle_ContextHelp ) | ||
43 | , m_config( "dagger" ) | ||
44 | , m_tabs( this ) | ||
45 | , m_autoScrollTimer( this ) | ||
46 | { | ||
47 | // Initialize sword library manager | ||
48 | m_config.setGroup( "Sword" ); | ||
49 | m_modulePath = m_config.readEntry( "ModPath", "/usr/local/share/sword" ); | ||
50 | m_swordMgr = new sword::SWMgr( m_modulePath.latin1(), true, | ||
51 | new sword::MarkupFilterMgr( sword::FMT_HTMLHREF ) ); | ||
52 | |||
53 | // Retrieve list of available Sword module options (e.g. footnotes, Strong's numbers, etc.) | ||
54 | sword::OptionsList swordOpts = m_swordMgr->getGlobalOptions(); | ||
55 | for ( sword::OptionsList::iterator it = swordOpts.begin(); it != swordOpts.end(); it++ ) | ||
56 | m_actionSwordOpts.append( new QAction( (*it).c_str(), QString::null, 0, this, 0 ) ); | ||
57 | m_actionSwordOpts.sort(); | ||
58 | |||
59 | // Initialize user interface | ||
60 | setCaption( tr( "Dagger" ) ); | ||
61 | initUI(); | ||
62 | |||
63 | connect( &m_tabs, SIGNAL(currentChanged(QWidget *)), this, SLOT( slotTextDisplayed(QWidget *)) ); | ||
64 | connect( &m_autoScrollTimer, SIGNAL(timeout()), this, SLOT(slotNavNextVerse()) ); | ||
65 | |||
66 | m_bibleIcon = new QPixmap( Resource::loadPixmap( "dagger/bibletext" ) ); | ||
67 | m_commentaryIcon = new QPixmap( Resource::loadPixmap( "dagger/commentary" ) ); | ||
68 | m_lexiconIcon = new QPixmap( Resource::loadPixmap( "dagger/lexicon" ) ); | ||
69 | |||
70 | // Load initial configuration | ||
71 | QTimer::singleShot( 100, this, SLOT( initConfig() ) ); | ||
72 | } | ||
73 | |||
74 | MainWindow::~MainWindow() | ||
75 | { | ||
76 | // Save Sword options | ||
77 | m_config.setGroup( "Sword" ); | ||
78 | m_config.writeEntry( "ModPath", m_modulePath ); | ||
79 | |||
80 | for ( QAction *a = m_actionSwordOpts.first(); a; a = m_actionSwordOpts.next() ) | ||
81 | m_config.writeEntry( a->text(), a->isOn() ); | ||
82 | |||
83 | // Save configuration options | ||
84 | m_config.setGroup( "Config" ); | ||
85 | m_config.writeEntry( "AlwaysOpenNew", m_alwaysOpenNew ); | ||
86 | m_config.writeEntry( "AutoScroll", m_navToolbar->autoScrollRate() ); | ||
87 | m_config.writeEntry( "DisableScreenBlanking", m_disableScreenBlank ); | ||
88 | m_config.writeEntry( "CopyFormat", m_copyFormat ); | ||
89 | m_config.writeEntry( "NavBar", m_actionViewNavToolbar->isOn() ); | ||
90 | m_config.writeEntry( "NumVerses", m_numVerses ); | ||
91 | m_config.writeEntry( "SearchBar", m_actionViewSearchToolbar->isOn() ); | ||
92 | |||
93 | // Save text font | ||
94 | m_config.setGroup( "Font"); | ||
95 | m_config.writeEntry( "Family", m_textFont.family() ); | ||
96 | m_config.writeEntry( "Italic", m_textFont.italic() ); | ||
97 | m_config.writeEntry( "Size", m_textFont.pointSize() ); | ||
98 | m_config.writeEntry( "Weight", m_textFont.weight() ); | ||
99 | |||
100 | // Save bookmarks | ||
101 | m_config.setGroup( "Bookmarks"); | ||
102 | m_config.clearGroup(); | ||
103 | int index = 3; | ||
104 | int id = m_bookmarkMenu->idAt( index ); | ||
105 | while ( id != -1 ) | ||
106 | { | ||
107 | QString bookmark = m_bookmarkMenu->text( id ); | ||
108 | int pos = bookmark.find( " (" ); | ||
109 | QString key = bookmark.left( pos ); | ||
110 | pos += 2; | ||
111 | QString module = bookmark.mid( pos, bookmark.find( ")", pos ) - pos ); | ||
112 | QString modkey; | ||
113 | modkey.sprintf( "%s/%s", module.latin1(), key.latin1() ); | ||
114 | m_config.writeEntry( QString::number( index - 2 ), modkey ); | ||
115 | |||
116 | ++index; | ||
117 | id = m_bookmarkMenu->idAt( index ); | ||
118 | } | ||
119 | |||
120 | // Save opened modules | ||
121 | m_config.setGroup( "Session"); | ||
122 | m_config.clearGroup(); | ||
123 | QObjectList *childlist = queryList( "TextWidget" ); | ||
124 | QObjectListIt it( *childlist ); | ||
125 | TextWidget *module; | ||
126 | int count = 1; | ||
127 | while ( ( module = reinterpret_cast<TextWidget *>(it.current()) ) != 0 ) | ||
128 | { | ||
129 | QString modkey; | ||
130 | modkey.sprintf( "%s/%s", module->getModuleName().latin1(), module->getAbbrevKey().latin1() ); | ||
131 | m_config.writeEntry( QString::number( count ), modkey ); | ||
132 | ++count; | ||
133 | ++it; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | bool MainWindow::eventFilter( QObject *obj, QEvent *event ) | ||
138 | { | ||
139 | if ( event->type() == QEvent::KeyPress ) | ||
140 | { | ||
141 | QKeyEvent *keyev = reinterpret_cast<QKeyEvent *>(event); | ||
142 | if ( keyev->key() == Key_Up ) | ||
143 | { | ||
144 | slotNavPrevVerse(); | ||
145 | return true; | ||
146 | } | ||
147 | else if ( keyev->key() == Key_Down ) | ||
148 | { | ||
149 | slotNavNextVerse(); | ||
150 | return true; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | return QWidget::eventFilter( obj, event ); | ||
155 | } | ||
156 | |||
157 | void MainWindow::initUI() | ||
158 | { | ||
159 | setCentralWidget( &m_tabs ); | ||
160 | m_tabs.installEventFilter( this ); | ||
161 | |||
162 | setToolBarsMovable( false ); | ||
163 | m_barDock = new QToolBar( this ); | ||
164 | m_barDock->setHorizontalStretchable( true ); | ||
165 | |||
166 | m_menuBar = new QMenuBar( m_barDock ); | ||
167 | m_menuBar->setMargin( 0 ); | ||
168 | |||
169 | // Allocate toolbars | ||
170 | m_navToolbar = new NavBar( this ); | ||
171 | m_navToolbar->navBtnsEnable( false ); | ||
172 | connect( m_navToolbar, SIGNAL(prevChapter()), this, SLOT(slotNavPrevChapter()) ); | ||
173 | connect( m_navToolbar, SIGNAL(prevVerse()), this, SLOT(slotNavPrevVerse()) ); | ||
174 | connect( m_navToolbar, SIGNAL(keyChanged(const QString &)), this, SLOT(slotNavKeyChanged(const QString &)) ); | ||
175 | connect( m_navToolbar, SIGNAL(nextVerse()), this, SLOT(slotNavNextVerse()) ); | ||
176 | connect( m_navToolbar, SIGNAL(nextChapter()), this, SLOT(slotNavNextChapter()) ); | ||
177 | connect( m_navToolbar, SIGNAL(autoScroll(bool)), this, SLOT(slotNavAutoScroll(bool)) ); | ||
178 | connect( m_navToolbar, SIGNAL(scrollRateChanged(int)), this, SLOT(slotNavScrollRateChanged(int)) ); | ||
179 | |||
180 | m_searchToolbar = new SearchBar( this ); | ||
181 | connect( m_searchToolbar, SIGNAL(sigResultClicked(const QString &)), this, SLOT(slotSearchResultClicked(const QString &)) ); | ||
182 | |||
183 | // Text menu | ||
184 | QPopupMenu *popup = new QPopupMenu( this ); | ||
185 | |||
186 | QAction *a = new QAction( tr( "Open..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | ||
187 | connect( a, SIGNAL(activated()), this, SLOT(slotTextOpen()) ); | ||
188 | a->addTo( popup ); | ||
189 | |||
190 | m_actionTextClose = new QAction( tr( "Close" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 ); | ||
191 | connect( m_actionTextClose, SIGNAL(activated()), this, SLOT(slotTextClose()) ); | ||
192 | m_actionTextClose->addTo( popup ); | ||
193 | |||
194 | popup->insertSeparator(); | ||
195 | |||
196 | // TODO - need to implent | ||
197 | a = new QAction( tr( "Install..." ), Resource::loadPixmap( "install" ), QString::null, 0, this, 0 ); | ||
198 | a->setEnabled( false ); | ||
199 | connect( a, SIGNAL(activated()), this, SLOT(slotTextInstall()) ); | ||
200 | a->addTo( popup ); | ||
201 | |||
202 | m_menuBar->insertItem( tr( "Text" ), popup ); | ||
203 | |||
204 | // Edit menu | ||
205 | popup = new QPopupMenu( this ); | ||
206 | |||
207 | m_actionEditCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 ); | ||
208 | connect( m_actionEditCopy, SIGNAL(activated()), this, SLOT(slotEditCopy()) ); | ||
209 | m_actionEditCopy->addTo( popup ); | ||
210 | |||
211 | popup->insertSeparator(); | ||
212 | |||
213 | a = new QAction( tr( "Configure..." ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 ); | ||
214 | connect( a, SIGNAL(activated()), this, SLOT(slotEditConfigure()) ); | ||
215 | a->addTo( popup ); | ||
216 | |||
217 | m_menuBar->insertItem( tr( "Edit" ), popup ); | ||
218 | |||
219 | // Bookmark menu | ||
220 | m_bookmarkMenu = new QPopupMenu( this ); | ||
221 | |||
222 | m_actionBookmarkAdd = new QAction( tr( "Add" ), Resource::loadPixmap( "dagger/bookmarkadd" ), QString::null, 0, this, 0 ); | ||
223 | connect( m_actionBookmarkAdd, SIGNAL(activated()), this, SLOT(slotBookmarkAdd()) ); | ||
224 | m_actionBookmarkAdd->addTo( m_bookmarkMenu ); | ||
225 | |||
226 | m_actionBookmarkRemove = new QAction( tr( "Remove" ), Resource::loadPixmap( "dagger/bookmarkremove" ), QString::null, 0, this, 0 ); | ||
227 | connect( m_actionBookmarkRemove, SIGNAL(activated()), this, SLOT(slotBookmarkRemove()) ); | ||
228 | m_actionBookmarkRemove->addTo( m_bookmarkMenu ); | ||
229 | |||
230 | m_bookmarkMenu->insertSeparator(); | ||
231 | |||
232 | m_menuBar->insertItem( tr( "Bookmark" ), m_bookmarkMenu ); | ||
233 | |||
234 | // View menu | ||
235 | popup = new QPopupMenu( this ); | ||
236 | |||
237 | // Retrieve list of available Sword module options (e.g. footnotes, Strong's numbers, etc.) | ||
238 | for ( a = m_actionSwordOpts.first(); a; a = m_actionSwordOpts.next() ) | ||
239 | { | ||
240 | a->setToggleAction( true ); | ||
241 | connect( a, SIGNAL(toggled(bool)), this, SLOT(slotViewSwordOption(bool)) ); | ||
242 | a->addTo( popup ); | ||
243 | } | ||
244 | |||
245 | popup->insertSeparator(); | ||
246 | |||
247 | m_actionViewNavToolbar = new QAction( tr( "Navigation toolbar" ), QString::null, 0, this, 0 ); | ||
248 | m_actionViewNavToolbar->setToggleAction( true ); | ||
249 | connect( m_actionViewNavToolbar, SIGNAL(toggled(bool)), this, SLOT(slotViewNavToolbar(bool)) ); | ||
250 | m_actionViewNavToolbar->addTo( popup ); | ||
251 | |||
252 | m_actionViewSearchToolbar = new QAction( tr( "Search toolbar" ), QString::null, 0, this, 0 ); | ||
253 | m_actionViewSearchToolbar->setToggleAction( true ); | ||
254 | connect( m_actionViewSearchToolbar, SIGNAL(toggled(bool)), this, SLOT(slotViewSearchToolbar(bool)) ); | ||
255 | m_actionViewSearchToolbar->addTo( popup ); | ||
256 | |||
257 | m_menuBar->insertItem( tr( "View" ), popup ); | ||
258 | } | ||
259 | |||
260 | void MainWindow::openModule( const QString &modulename, const QString &key ) | ||
261 | { | ||
262 | sword::SWModule *module = m_swordMgr->Modules[ modulename.latin1() ]; | ||
263 | if ( module ) | ||
264 | { | ||
265 | TextWidget *tw = 0x0; | ||
266 | |||
267 | if ( !m_alwaysOpenNew ) | ||
268 | { | ||
269 | // Try to find if the module is already opened, if so will use that TextWidget | ||
270 | QObjectList *childlist = queryList( "TextWidget" ); | ||
271 | QObjectListIt it( *childlist ); | ||
272 | while ( ( tw = reinterpret_cast<TextWidget *>(it.current()) ) != 0 && | ||
273 | tw->getModuleName() != modulename ) | ||
274 | ++it; | ||
275 | if ( tw && tw->getModuleName() == modulename ) | ||
276 | { | ||
277 | // Set key if one is present | ||
278 | if ( !key.isNull() ) | ||
279 | tw->setKey( key ); | ||
280 | |||
281 | // Raise tab | ||
282 | m_tabs.setCurrentTab( tw ); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | if ( m_alwaysOpenNew || !tw ) | ||
287 | { | ||
288 | // Open module in new tab | ||
289 | QString icon; | ||
290 | QString type = module->Type(); | ||
291 | |||
292 | if ( type == "Biblical Texts" ) | ||
293 | icon = "dagger/bibletext"; | ||
294 | else if ( type == "Commentaries" ) | ||
295 | icon = "dagger/commentary"; | ||
296 | else if ( type == "Lexicons / Dictionaries" ) | ||
297 | icon = "dagger/lexicon"; | ||
298 | |||
299 | tw = new TextWidget( this, module, m_numVerses, &m_textFont ); | ||
300 | connect( tw, SIGNAL(sigRefClicked(const QString &)), | ||
301 | this, SLOT(slotTextRefClicked(const QString &)) ); | ||
302 | connect( this, SIGNAL(sigNumVersesChanged(int)), tw, SLOT(slotNumVersesChanged(int)) ); | ||
303 | connect( this, SIGNAL(sigFontChanged(const QFont *)), tw, SLOT(slotFontChanged(const QFont *)) ); | ||
304 | connect( this, SIGNAL(sigOptionChanged()), tw, SLOT(slotOptionChanged()) ); | ||
305 | |||
306 | m_tabs.addTab( tw, icon, modulename ); | ||
307 | |||
308 | m_actionTextClose->setEnabled( true ); | ||
309 | m_actionEditCopy->setEnabled( true ); | ||
310 | m_actionBookmarkAdd->setEnabled( true ); | ||
311 | |||
312 | // Set key if one is present | ||
313 | if ( !key.isNull() ) | ||
314 | tw->setKey( key ); | ||
315 | } | ||
316 | } | ||
317 | } | ||
318 | |||
319 | int MainWindow::findBookmark( const QString &bookmark ) | ||
320 | { | ||
321 | int index = 3; | ||
322 | int id = m_bookmarkMenu->idAt( index ); | ||
323 | while ( ( id != -1 ) && ( m_bookmarkMenu->text( id ) != bookmark ) ) | ||
324 | { | ||
325 | ++index; | ||
326 | id = m_bookmarkMenu->idAt( index ); | ||
327 | } | ||
328 | |||
329 | return id; | ||
330 | } | ||
331 | |||
332 | void MainWindow::enableScreenBlanking( bool enable ) | ||
333 | { | ||
334 | enable ? QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable | ||
335 | : QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; | ||
336 | } | ||
337 | |||
338 | void MainWindow::initConfig() | ||
339 | { | ||
340 | bool show; | ||
341 | |||
342 | m_config.setGroup( "Sword" ); | ||
343 | for ( QAction *a = m_actionSwordOpts.first(); a; a = m_actionSwordOpts.next() ) | ||
344 | { | ||
345 | show = m_config.readBoolEntry( a->text(), false ); | ||
346 | a->setOn( show ); | ||
347 | m_swordMgr->setGlobalOption ( a->text(), show ? "On" : "Off" ); | ||
348 | } | ||
349 | |||
350 | // Display/hide toolbars based on last run | ||
351 | m_config.setGroup( "Config" ); | ||
352 | |||
353 | m_alwaysOpenNew = m_config.readBoolEntry( "AlwaysOpenNew", false ); | ||
354 | m_navToolbar->setAutoScrollRate( m_config.readNumEntry( "AutoScroll", 50 ) ); | ||
355 | m_disableScreenBlank = m_config.readBoolEntry( "DisableScreenBlanking", false ); | ||
356 | enableScreenBlanking( !m_disableScreenBlank ); | ||
357 | m_copyFormat = m_config.readNumEntry( "CopyFormat", 0 ); | ||
358 | |||
359 | show = m_config.readBoolEntry( "NavBar", false ); | ||
360 | m_actionViewNavToolbar->setOn( show ); | ||
361 | slotViewNavToolbar( show ); | ||
362 | |||
363 | m_numVerses = m_config.readNumEntry( "NumVerses", 5 ); | ||
364 | |||
365 | show = m_config.readBoolEntry( "SearchBar", false ); | ||
366 | m_actionViewSearchToolbar->setOn( show ); | ||
367 | slotViewSearchToolbar( show ); | ||
368 | |||
369 | // Set text font | ||
370 | m_config.setGroup( "Font" ); | ||
371 | QString fontFamily = m_config.readEntry( "Family", QString::null ); | ||
372 | !fontFamily.isNull() ? m_textFont = QFont( fontFamily, | ||
373 | m_config.readNumEntry( "Size", -1 ), | ||
374 | m_config.readNumEntry( "Weight", QFont::Normal ), | ||
375 | m_config.readBoolEntry( "Italic", false ) ) | ||
376 | : m_textFont = font(); // If font is not configured, set to default widget font | ||
377 | |||
378 | // Load bookmarks | ||
379 | m_config.setGroup( "Bookmarks"); | ||
380 | int count = 1; | ||
381 | QString key = m_config.readEntry( QString::number( count ), QString::null ); | ||
382 | while ( !key.isNull() ) | ||
383 | { | ||
384 | int pos = key.find( "/" ); | ||
385 | if ( pos > -1 ) | ||
386 | { | ||
387 | QString bookmark; | ||
388 | bookmark.sprintf( "%s (%s)", key.right( key.length() - ( pos + 1 ) ).latin1(), | ||
389 | key.left( pos ).latin1() ); | ||
390 | QAction *a = new QAction( bookmark, QString::null, 0, this, 0 ); | ||
391 | a->addTo( m_bookmarkMenu ); | ||
392 | connect( a, SIGNAL(activated()), this, SLOT(slotBookmarkSelected()) ); | ||
393 | } | ||
394 | |||
395 | ++count; | ||
396 | key = m_config.readEntry( QString::number( count ), QString::null ); | ||
397 | } | ||
398 | m_actionBookmarkRemove->setEnabled( count > 1 ); | ||
399 | |||
400 | // Load opened modules | ||
401 | m_config.setGroup( "Session"); | ||
402 | QString first; | ||
403 | count = 1; | ||
404 | key = m_config.readEntry( QString::number( count ), QString::null ); | ||
405 | while ( !key.isNull() ) | ||
406 | { | ||
407 | int pos = key.find( "/" ); | ||
408 | if ( pos > -1 ) | ||
409 | { | ||
410 | if ( count == 1 ) | ||
411 | first = key.left( pos ); | ||
412 | openModule( key.left( pos ), key.right( key.length() - ( pos + 1 ) ) ); | ||
413 | } | ||
414 | |||
415 | ++count; | ||
416 | key = m_config.readEntry( QString::number( count ), QString::null ); | ||
417 | } | ||
418 | m_tabs.setCurrentTab( first ); | ||
419 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
420 | if ( text ) | ||
421 | { | ||
422 | setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) ); | ||
423 | m_navToolbar->setKey( text->getAbbrevKey() ); | ||
424 | } | ||
425 | m_actionTextClose->setEnabled( count > 1 ); | ||
426 | m_actionEditCopy->setEnabled( count > 1 ); | ||
427 | } | ||
428 | |||
429 | void MainWindow::slotTextDisplayed( QWidget *textWidget ) | ||
430 | { | ||
431 | TextWidget *text = reinterpret_cast<TextWidget *>(textWidget); | ||
432 | setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) ); | ||
433 | |||
434 | m_navToolbar->setKey( text->getAbbrevKey() ); | ||
435 | m_navToolbar->navBtnsEnable( text->isBibleText() ); | ||
436 | |||
437 | m_searchToolbar->setCurrModule( text ); | ||
438 | } | ||
439 | |||
440 | void MainWindow::slotTextOpen() | ||
441 | { | ||
442 | OpenTextDlg dlg( this, m_swordMgr, m_bibleIcon, m_commentaryIcon, m_lexiconIcon ); | ||
443 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) | ||
444 | { | ||
445 | openModule( dlg.selectedText() ); | ||
446 | } | ||
447 | } | ||
448 | |||
449 | void MainWindow::slotTextClose() | ||
450 | { | ||
451 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
452 | if ( text ) | ||
453 | { | ||
454 | m_tabs.removePage( text ); | ||
455 | delete text; | ||
456 | |||
457 | // If no other modules are open, disable appropriate UI items | ||
458 | if ( !m_tabs.currentWidget() ) | ||
459 | { | ||
460 | m_navToolbar->navBtnsEnable( false ); | ||
461 | m_navToolbar->setKey( QString::null ); | ||
462 | m_searchToolbar->setCurrModule( 0x0 ); | ||
463 | m_actionTextClose->setEnabled( false ); | ||
464 | m_actionEditCopy->setEnabled( false ); | ||
465 | m_actionBookmarkAdd->setEnabled( false ); | ||
466 | m_actionBookmarkRemove->setEnabled( false ); | ||
467 | } | ||
468 | } | ||
469 | } | ||
470 | |||
471 | void MainWindow::slotTextInstall() | ||
472 | { | ||
473 | } | ||
474 | |||
475 | void MainWindow::slotEditCopy() | ||
476 | { | ||
477 | TextWidget *currModule = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
478 | if ( currModule ) | ||
479 | { | ||
480 | QString text; | ||
481 | |||
482 | switch( m_copyFormat ) | ||
483 | { | ||
484 | case 0: text.sprintf( "%s (%s, %s)", currModule->getCurrVerse().latin1(), | ||
485 | currModule->getAbbrevKey().latin1(), | ||
486 | currModule->getModuleName().latin1() ); | ||
487 | break; | ||
488 | case 1: text.sprintf( "%s (%s)", currModule->getCurrVerse().latin1(), | ||
489 | currModule->getAbbrevKey().latin1() ); | ||
490 | break; | ||
491 | case 2: text = currModule->getCurrVerse(); | ||
492 | break; | ||
493 | case 3: text = currModule->getAbbrevKey(); | ||
494 | break; | ||
495 | default: text = QString::null; | ||
496 | }; | ||
497 | |||
498 | if ( !text.isNull() ) | ||
499 | QPEApplication::clipboard()->setText( text ); | ||
500 | } | ||
501 | } | ||
502 | |||
503 | void MainWindow::slotEditConfigure() | ||
504 | { | ||
505 | ConfigureDlg dlg( this, m_modulePath, m_alwaysOpenNew, m_numVerses, m_disableScreenBlank, m_copyFormat, | ||
506 | &m_textFont ); | ||
507 | if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ) | ||
508 | { | ||
509 | m_modulePath = dlg.swordPath(); | ||
510 | m_alwaysOpenNew = dlg.alwaysOpenNew(); | ||
511 | if ( dlg.numVerses() != m_numVerses ) | ||
512 | { | ||
513 | m_numVerses = dlg.numVerses(); | ||
514 | emit sigNumVersesChanged( m_numVerses ); | ||
515 | } | ||
516 | m_disableScreenBlank = dlg.screenBlank(); | ||
517 | enableScreenBlanking( !m_disableScreenBlank ); | ||
518 | m_copyFormat = dlg.copyFormat(); | ||
519 | m_textFont = dlg.selectedFont(); | ||
520 | emit sigFontChanged( &m_textFont ); | ||
521 | } | ||
522 | } | ||
523 | |||
524 | void MainWindow::slotBookmarkAdd() | ||
525 | { | ||
526 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
527 | if ( text ) | ||
528 | { | ||
529 | // See if bookmark doesn't already exists | ||
530 | QString bookmark = text->getFullKey(); | ||
531 | int menuId = findBookmark( bookmark ); | ||
532 | if ( menuId == -1 ) | ||
533 | { | ||
534 | // Bookmark not found, add | ||
535 | QAction *a = new QAction( bookmark, QString::null, 0, this, 0 ); | ||
536 | a->addTo( m_bookmarkMenu ); | ||
537 | connect( a, SIGNAL(activated()), this, SLOT(slotBookmarkSelected()) ); | ||
538 | |||
539 | // Make sure remove option is enabled | ||
540 | m_actionBookmarkRemove->setEnabled( true ); | ||
541 | |||
542 | } | ||
543 | } | ||
544 | } | ||
545 | |||
546 | void MainWindow::slotBookmarkRemove() | ||
547 | { | ||
548 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
549 | if ( text ) | ||
550 | { | ||
551 | // See if bookmark exists for current module key | ||
552 | int menuId = findBookmark( text->getFullKey() ); | ||
553 | if ( menuId != -1 ) | ||
554 | { | ||
555 | // Bookmark found, remove | ||
556 | m_bookmarkMenu->removeItem( menuId ); | ||
557 | |||
558 | //If this was the last bookmark, disable the remove option | ||
559 | if ( m_bookmarkMenu->idAt( 3 ) == -1 ) | ||
560 | m_actionBookmarkRemove->setEnabled( false ); | ||
561 | } | ||
562 | } | ||
563 | } | ||
564 | |||
565 | void MainWindow::slotBookmarkSelected() | ||
566 | { | ||
567 | const QAction *action = reinterpret_cast<const QAction *>(sender()); | ||
568 | if ( action ) | ||
569 | { | ||
570 | QString bookmark = action->text(); | ||
571 | int pos = bookmark.find( " (" ); | ||
572 | QString key = bookmark.left( pos ); | ||
573 | pos += 2; | ||
574 | QString module = bookmark.mid( pos, bookmark.find( ")", pos ) - pos ); | ||
575 | |||
576 | openModule( module, key ); | ||
577 | } | ||
578 | } | ||
579 | |||
580 | void MainWindow::slotViewSwordOption( bool enabled ) | ||
581 | { | ||
582 | const QAction *action = reinterpret_cast<const QAction*>(sender()); | ||
583 | m_swordMgr->setGlobalOption ( action->text(), enabled ? "On" : "Off" ); | ||
584 | |||
585 | emit sigOptionChanged(); | ||
586 | } | ||
587 | |||
588 | void MainWindow::slotViewNavToolbar( bool enabled ) | ||
589 | { | ||
590 | enabled ? m_navToolbar->show() | ||
591 | : m_navToolbar->hide(); | ||
592 | } | ||
593 | |||
594 | void MainWindow::slotViewSearchToolbar( bool enabled ) | ||
595 | { | ||
596 | enabled ? m_searchToolbar->show() | ||
597 | : m_searchToolbar->hide(); | ||
598 | } | ||
599 | |||
600 | void MainWindow::slotNavPrevChapter() | ||
601 | { | ||
602 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
603 | if ( text ) | ||
604 | { | ||
605 | text->prevChapter(); | ||
606 | setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) ); | ||
607 | m_navToolbar->setKey( text->getAbbrevKey() ); | ||
608 | } | ||
609 | } | ||
610 | |||
611 | void MainWindow::slotNavPrevVerse() | ||
612 | { | ||
613 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
614 | if ( text ) | ||
615 | { | ||
616 | text->prevVerse(); | ||
617 | setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) ); | ||
618 | m_navToolbar->setKey( text->getAbbrevKey() ); | ||
619 | } | ||
620 | } | ||
621 | |||
622 | void MainWindow::slotNavKeyChanged( const QString &newKey ) | ||
623 | { | ||
624 | QString key = newKey; | ||
625 | key.replace( QRegExp( "[-=.]" ), ":" ); | ||
626 | |||
627 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
628 | if ( text ) | ||
629 | { | ||
630 | text->setKey( key ); | ||
631 | setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) ); | ||
632 | } | ||
633 | } | ||
634 | |||
635 | void MainWindow::slotNavNextVerse() | ||
636 | { | ||
637 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
638 | if ( text ) | ||
639 | { | ||
640 | text->nextVerse(); | ||
641 | setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) ); | ||
642 | m_navToolbar->setKey( text->getAbbrevKey() ); | ||
643 | } | ||
644 | } | ||
645 | |||
646 | void MainWindow::slotNavNextChapter() | ||
647 | { | ||
648 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
649 | if ( text ) | ||
650 | { | ||
651 | text->nextChapter(); | ||
652 | setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) ); | ||
653 | m_navToolbar->setKey( text->getAbbrevKey() ); | ||
654 | } | ||
655 | } | ||
656 | |||
657 | void MainWindow::slotNavAutoScroll( bool enabled ) | ||
658 | { | ||
659 | m_autoScrollTimer.stop(); | ||
660 | |||
661 | if ( enabled ) | ||
662 | m_autoScrollTimer.start( m_navToolbar->autoScrollRate() * 100 ); | ||
663 | } | ||
664 | |||
665 | void MainWindow::slotNavScrollRateChanged( int newRate ) | ||
666 | { | ||
667 | if ( m_autoScrollTimer.isActive() ) | ||
668 | { | ||
669 | m_autoScrollTimer.stop(); | ||
670 | m_autoScrollTimer.start( newRate * 100 ); | ||
671 | } | ||
672 | } | ||
673 | |||
674 | void MainWindow::slotSearchResultClicked( const QString &key ) | ||
675 | { | ||
676 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
677 | if ( text ) | ||
678 | { | ||
679 | text->setKey( key ); | ||
680 | setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) ); | ||
681 | m_navToolbar->setKey( text->getAbbrevKey() ); | ||
682 | } | ||
683 | } | ||
684 | |||
685 | void MainWindow::slotTextRefClicked( const QString &ref ) | ||
686 | { | ||
687 | //owarn << "Reference: " << ref << oendl; | ||
688 | if ( !ref.isNull() ) | ||
689 | { | ||
690 | TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget()); | ||
691 | if ( text ) | ||
692 | { | ||
693 | QString module; | ||
694 | QString key( ref ); | ||
695 | key.remove( 0, 2 ); | ||
696 | |||
697 | QChar book = ref.at( 1 ); | ||
698 | // TODO- this is ugly, need better way to determine type of reference | ||
699 | // take a look at SWModule::getRawEntry() | ||
700 | int keyValue = key.toInt(); | ||
701 | if ( book == 'H' && keyValue <= 8674 ) | ||
702 | module = "StrongsHebrew"; | ||
703 | else if ( book == 'G' && keyValue <= 5624 ) | ||
704 | module = "StrongsGreek"; | ||
705 | |||
706 | if ( !module.isEmpty() ) | ||
707 | openModule( module, key ); | ||
708 | } | ||
709 | } | ||
710 | } | ||