summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/dagger/mainwindow.cpp51
1 files changed, 41 insertions, 10 deletions
diff --git a/noncore/apps/dagger/mainwindow.cpp b/noncore/apps/dagger/mainwindow.cpp
index e886bd8..3dd9eff 100644
--- a/noncore/apps/dagger/mainwindow.cpp
+++ b/noncore/apps/dagger/mainwindow.cpp
@@ -1,225 +1,226 @@
/*
Dagger - A Bible study program utilizing the Sword library.
Copyright (c) 2004 Dan Williams <drw@handhelds.org>
This file is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later version.
This file is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this
file; see the file COPYING. If not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "mainwindow.h"
#include "navbar.h"
#include "searchbar.h"
#include "opentextdlg.h"
#include "configuredlg.h"
#include "textwidget.h"
#include <opie2/odebug.h>
#include <qpe/qcopenvelope_qws.h>
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
#include <qaction.h>
#include <qclipboard.h>
#include <qmenubar.h>
+#include <qmessagebox.h>
#include <qobjectlist.h>
#include <qpopupmenu.h>
#include <qtimer.h>
#include <qtoolbar.h>
#include <markupfiltmgr.h>
MainWindow::MainWindow( QWidget *parent, const char *name, WFlags /*fl*/ )
: QMainWindow( parent, name, WStyle_ContextHelp )
, m_config( "dagger" )
, m_tabs( this )
, m_autoScrollTimer( this )
{
// Initialize sword library manager
m_config.setGroup( "Sword" );
m_modulePath = m_config.readEntry( "ModPath", "/usr/local/share/sword" );
m_swordMgr = new sword::SWMgr( m_modulePath.latin1(), true,
new sword::MarkupFilterMgr( sword::FMT_HTMLHREF ) );
// Retrieve list of available Sword module options (e.g. footnotes, Strong's numbers, etc.)
sword::StringList swordOpts = m_swordMgr->getGlobalOptions();
for ( sword::StringList::iterator it = swordOpts.begin(); it != swordOpts.end(); it++ )
m_actionSwordOpts.append( new QAction( (*it).c_str(), QString::null, 0, this, 0 ) );
m_actionSwordOpts.sort();
// Initialize user interface
setCaption( tr( "Dagger" ) );
initUI();
connect( &m_tabs, SIGNAL(currentChanged(QWidget *)), this, SLOT( slotTextDisplayed(QWidget *)) );
connect( &m_autoScrollTimer, SIGNAL(timeout()), this, SLOT(slotNavNextVerse()) );
m_bibleIcon = new QPixmap( Resource::loadPixmap( "dagger/bibletext" ) );
m_commentaryIcon = new QPixmap( Resource::loadPixmap( "dagger/commentary" ) );
m_lexiconIcon = new QPixmap( Resource::loadPixmap( "dagger/lexicon" ) );
// Load initial configuration
QTimer::singleShot( 100, this, SLOT( initConfig() ) );
}
MainWindow::~MainWindow()
{
// Re-enable screen blanking if it was disabled
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
// Save Sword options
m_config.setGroup( "Sword" );
m_config.writeEntry( "ModPath", m_modulePath );
for ( QAction *a = m_actionSwordOpts.first(); a; a = m_actionSwordOpts.next() )
m_config.writeEntry( a->text(), a->isOn() );
// Save configuration options
m_config.setGroup( "Config" );
m_config.writeEntry( "AlwaysOpenNew", m_alwaysOpenNew );
m_config.writeEntry( "AutoScroll", m_navToolbar->autoScrollRate() );
m_config.writeEntry( "DisableScreenBlanking", m_disableScreenBlank );
m_config.writeEntry( "CopyFormat", m_copyFormat );
m_config.writeEntry( "NavBar", m_actionViewNavToolbar->isOn() );
m_config.writeEntry( "NumVerses", m_numVerses );
m_config.writeEntry( "SearchBar", m_actionViewSearchToolbar->isOn() );
// Save text font
m_config.setGroup( "Font");
m_config.writeEntry( "Family", m_textFont.family() );
m_config.writeEntry( "Italic", m_textFont.italic() );
m_config.writeEntry( "Size", m_textFont.pointSize() );
m_config.writeEntry( "Weight", m_textFont.weight() );
// Save bookmarks
m_config.setGroup( "Bookmarks");
m_config.clearGroup();
int index = 3;
int id = m_bookmarkMenu->idAt( index );
while ( id != -1 )
{
QString bookmark = m_bookmarkMenu->text( id );
int pos = bookmark.find( " (" );
QString key = bookmark.left( pos );
pos += 2;
QString module = bookmark.mid( pos, bookmark.find( ")", pos ) - pos );
QString modkey;
modkey.sprintf( "%s/%s", module.latin1(), key.latin1() );
m_config.writeEntry( QString::number( index - 2 ), modkey );
++index;
id = m_bookmarkMenu->idAt( index );
}
// Save opened modules
m_config.setGroup( "Session");
m_config.clearGroup();
QObjectList *childlist = queryList( "TextWidget" );
QObjectListIt it( *childlist );
TextWidget *module;
int count = 1;
while ( ( module = reinterpret_cast<TextWidget *>(it.current()) ) != 0 )
{
QString modkey;
modkey.sprintf( "%s/%s", module->getModuleName().latin1(), module->getAbbrevKey().latin1() );
m_config.writeEntry( QString::number( count ), modkey );
++count;
++it;
}
}
bool MainWindow::eventFilter( QObject *obj, QEvent *event )
{
if ( event->type() == QEvent::KeyPress )
{
QKeyEvent *keyev = reinterpret_cast<QKeyEvent *>(event);
if ( keyev->key() == Key_Up )
{
slotNavPrevVerse();
return true;
}
else if ( keyev->key() == Key_Down )
{
slotNavNextVerse();
return true;
}
}
return QWidget::eventFilter( obj, event );
}
void MainWindow::initUI()
{
setCentralWidget( &m_tabs );
m_tabs.installEventFilter( this );
setToolBarsMovable( false );
m_barDock = new QToolBar( this );
m_barDock->setHorizontalStretchable( true );
m_menuBar = new QMenuBar( m_barDock );
m_menuBar->setMargin( 0 );
// Allocate toolbars
m_navToolbar = new NavBar( this );
m_navToolbar->navBtnsEnable( false );
connect( m_navToolbar, SIGNAL(prevPage()), this, SLOT(slotNavPrevPage()) );
connect( m_navToolbar, SIGNAL(prevVerse()), this, SLOT(slotNavPrevVerse()) );
connect( m_navToolbar, SIGNAL(keyChanged(const QString &)), this, SLOT(slotNavKeyChanged(const QString &)) );
connect( m_navToolbar, SIGNAL(nextVerse()), this, SLOT(slotNavNextVerse()) );
connect( m_navToolbar, SIGNAL(nextPage()), this, SLOT(slotNavNextPage()) );
connect( m_navToolbar, SIGNAL(autoScroll(bool)), this, SLOT(slotNavAutoScroll(bool)) );
connect( m_navToolbar, SIGNAL(scrollRateChanged(int)), this, SLOT(slotNavScrollRateChanged(int)) );
m_searchToolbar = new SearchBar( this );
connect( m_searchToolbar, SIGNAL(sigResultClicked(const QString &)), this, SLOT(slotSearchResultClicked(const QString &)) );
// Text menu
QPopupMenu *popup = new QPopupMenu( this );
QAction *a = new QAction( tr( "Open..." ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
connect( a, SIGNAL(activated()), this, SLOT(slotTextOpen()) );
a->addTo( popup );
m_actionTextClose = new QAction( tr( "Close" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( m_actionTextClose, SIGNAL(activated()), this, SLOT(slotTextClose()) );
m_actionTextClose->addTo( popup );
popup->insertSeparator();
// TODO - need to implent
a = new QAction( tr( "Install..." ), Resource::loadPixmap( "install" ), QString::null, 0, this, 0 );
a->setEnabled( false );
connect( a, SIGNAL(activated()), this, SLOT(slotTextInstall()) );
a->addTo( popup );
m_menuBar->insertItem( tr( "Text" ), popup );
// Edit menu
popup = new QPopupMenu( this );
m_actionEditCopy = new QAction( tr( "Copy" ), Resource::loadPixmap( "copy" ), QString::null, 0, this, 0 );
connect( m_actionEditCopy, SIGNAL(activated()), this, SLOT(slotEditCopy()) );
m_actionEditCopy->addTo( popup );
popup->insertSeparator();
a = new QAction( tr( "Configure..." ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 );
connect( a, SIGNAL(activated()), this, SLOT(slotEditConfigure()) );
a->addTo( popup );
m_menuBar->insertItem( tr( "Edit" ), popup );
// Bookmark menu
m_bookmarkMenu = new QPopupMenu( this );
m_actionBookmarkAdd = new QAction( tr( "Add" ), Resource::loadPixmap( "dagger/bookmarkadd" ), QString::null, 0, this, 0 );
@@ -498,216 +499,246 @@ void MainWindow::slotEditCopy()
default: text = QString::null;
};
if ( !text.isNull() )
QPEApplication::clipboard()->setText( text );
}
}
void MainWindow::slotEditConfigure()
{
ConfigureDlg dlg( this, m_modulePath, m_alwaysOpenNew, m_numVerses, m_disableScreenBlank, m_copyFormat,
&m_textFont );
if ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted )
{
m_modulePath = dlg.swordPath();
m_alwaysOpenNew = dlg.alwaysOpenNew();
if ( dlg.numVerses() != m_numVerses )
{
m_numVerses = dlg.numVerses();
emit sigNumVersesChanged( m_numVerses );
}
m_disableScreenBlank = dlg.screenBlank();
enableScreenBlanking( !m_disableScreenBlank );
m_copyFormat = dlg.copyFormat();
m_textFont = dlg.selectedFont();
emit sigFontChanged( &m_textFont );
}
}
void MainWindow::slotBookmarkAdd()
{
TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget());
if ( text )
{
// See if bookmark doesn't already exists
QString bookmark = text->getFullKey();
int menuId = findBookmark( bookmark );
if ( menuId == -1 )
{
// Bookmark not found, add
QAction *a = new QAction( bookmark, QString::null, 0, this, 0 );
a->addTo( m_bookmarkMenu );
connect( a, SIGNAL(activated()), this, SLOT(slotBookmarkSelected()) );
// Make sure remove option is enabled
m_actionBookmarkRemove->setEnabled( true );
}
}
}
void MainWindow::slotBookmarkRemove()
{
TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget());
if ( text )
{
// See if bookmark exists for current module key
int menuId = findBookmark( text->getFullKey() );
if ( menuId != -1 )
{
// Bookmark found, remove
m_bookmarkMenu->removeItem( menuId );
//If this was the last bookmark, disable the remove option
if ( m_bookmarkMenu->idAt( 3 ) == -1 )
m_actionBookmarkRemove->setEnabled( false );
}
}
}
void MainWindow::slotBookmarkSelected()
{
const QAction *action = reinterpret_cast<const QAction *>(sender());
if ( action )
{
QString bookmark = action->text();
int pos = bookmark.find( " (" );
QString key = bookmark.left( pos );
pos += 2;
QString module = bookmark.mid( pos, bookmark.find( ")", pos ) - pos );
openModule( module, key );
}
}
void MainWindow::slotViewSwordOption( bool enabled )
{
const QAction *action = reinterpret_cast<const QAction*>(sender());
m_swordMgr->setGlobalOption ( action->text(), enabled ? "On" : "Off" );
emit sigOptionChanged();
}
void MainWindow::slotViewNavToolbar( bool enabled )
{
enabled ? m_navToolbar->show()
: m_navToolbar->hide();
}
void MainWindow::slotViewSearchToolbar( bool enabled )
{
enabled ? m_searchToolbar->show()
: m_searchToolbar->hide();
}
void MainWindow::slotNavPrevPage()
{
TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget());
if ( text )
{
text->prevPage();
setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) );
m_navToolbar->setKey( text->getAbbrevKey() );
}
}
void MainWindow::slotNavPrevVerse()
{
TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget());
if ( text )
{
text->prevVerse();
setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) );
m_navToolbar->setKey( text->getAbbrevKey() );
}
}
void MainWindow::slotNavKeyChanged( const QString &newKey )
{
QString key = newKey;
key.replace( QRegExp( "[-=.]" ), ":" );
TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget());
if ( text )
{
text->setKey( key );
setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) );
}
}
void MainWindow::slotNavNextVerse()
{
TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget());
if ( text )
{
text->nextVerse();
setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) );
m_navToolbar->setKey( text->getAbbrevKey() );
}
}
void MainWindow::slotNavNextPage()
{
TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget());
if ( text )
{
text->nextPage();
setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) );
m_navToolbar->setKey( text->getAbbrevKey() );
}
}
void MainWindow::slotNavAutoScroll( bool enabled )
{
m_autoScrollTimer.stop();
if ( enabled )
m_autoScrollTimer.start( m_navToolbar->autoScrollRate() * 100 );
}
void MainWindow::slotNavScrollRateChanged( int newRate )
{
if ( m_autoScrollTimer.isActive() )
{
m_autoScrollTimer.stop();
m_autoScrollTimer.start( newRate * 100 );
}
}
void MainWindow::slotSearchResultClicked( const QString &key )
{
TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget());
if ( text )
{
text->setKey( key );
setCaption( QString( "%1 - Dagger" ).arg( text->getFullKey() ) );
m_navToolbar->setKey( text->getAbbrevKey() );
}
}
void MainWindow::slotTextRefClicked( const QString &ref )
{
+//printf( "Ref clicked: '%s'\n", ref.latin1() );
+/*
+Ref clicked: 'type=Strongs value=G3482'
+Ref clicked: 'type=Strongs value=H07225'
+Ref clicked: 'type=morph class=x-Robinson:N-PRI value=N-PRI'
+Ref clicked: 'type=morph class=x-StrongsMorph:TH8804 value=TH8804'
+*/
//owarn << "Reference: " << ref << oendl;
if ( !ref.isNull() )
{
TextWidget *text = reinterpret_cast<TextWidget *>(m_tabs.currentWidget());
if ( text )
{
+ // Parse type
+ int pos = ref.find( "type=", 0, false ) + 5;
+ QString typeStr = ref.mid( pos, ref.find( ' ', pos ) - pos );
+
+ // Parse class (for morph. only)
+ QString classStr;
+ if ( typeStr == "morph" )
+ {
+ pos = ref.find( "class=", 0, false ) + 5;
+ QString classStr = ref.mid( pos, ref.find( ' ', pos ) - pos );
+
+ // TODO - need to strip 'x-' from beginning and ':key' at end?
+ }
+
+ // Parse value
+ pos = ref.find( "value=", 0, false ) + 6;
+ QString valueStr = ref.mid( pos, ref.find( ' ', pos ) - pos );
+
+ if ( typeStr == "Strongs" )
+ {
+ //Determine if is a Hebrew or Greek reference
QString module;
- QString key( ref );
- key.remove( 0, 2 );
-
- QChar book = ref.at( 1 );
- // TODO- this is ugly, need better way to determine type of reference
- // take a look at SWModule::getRawEntry()
- int keyValue = key.toInt();
- if ( book == 'H' && keyValue <= 8674 )
+ if ( valueStr.at( 0 ) == 'H' )
module = "StrongsHebrew";
- else if ( book == 'G' && keyValue <= 5624 )
+ else
module = "StrongsGreek";
- if ( !module.isEmpty() )
+ // Get key
+ QString key( valueStr );
+ key.remove( 0, 1 );
+ // Open reference
openModule( module, key );
}
+ else if ( typeStr == "morph" )
+ {
+ QMessageBox::information( this, tr( "Morphological Tags" ),
+ tr( "Morphological tag cross-referencing not implemented yet." ) );
+ }
+ }
}
}