[sword-svn] r167 - trunk/src/SwordReader_GUI

dtrotzjr at www.crosswire.org dtrotzjr at www.crosswire.org
Sat Aug 2 22:06:54 MST 2008


Author: dtrotzjr
Date: 2008-08-02 22:06:53 -0700 (Sat, 02 Aug 2008)
New Revision: 167

Modified:
   trunk/src/SwordReader_GUI/SRMainFrame.cpp
   trunk/src/SwordReader_GUI/SRMainFrame.h
   trunk/src/SwordReader_GUI/SRModuleView.cpp
   trunk/src/SwordReader_GUI/SRModuleView.h
Log:
Resolved issue 0000019 where the Word's of Christ option was not being set correctly in the menu.
Resolved issue 0000011 - Preferences are now persistent.

The options we save currently are:
[GlobalOptions]
Cross-references
Footnotes
Headings
Morphological Tags
Strong's Numbers
Words of Christ in Red

[History]
LastPassage
LastVersion

Modified: trunk/src/SwordReader_GUI/SRMainFrame.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.cpp	2008-08-03 00:52:25 UTC (rev 166)
+++ trunk/src/SwordReader_GUI/SRMainFrame.cpp	2008-08-03 05:06:53 UTC (rev 167)
@@ -62,6 +62,7 @@
 
 SRMainFrame::~SRMainFrame()
 {
+    SaveOptions();
     if(m_swmgr)
         delete m_swmgr;
     if(m_bufModOptions)
@@ -148,6 +149,8 @@
 
     InitSword();
 
+    LoadOptions();
+
     m_viewBook = new SRBookChooser(s_wcsBookNames,MENU_CHAP);
     if(!m_viewBook->Create(this, view_rect))
         return FALSE;
@@ -164,9 +167,6 @@
     if(!m_viewFind->Create(this, view_rect))
         return FALSE;
 
-    m_viewModules[m_nCurrentModule]->Show();
-    m_viewModules[m_nCurrentModule]->RefreshScreen();
-
     m_viewBook->Hide();
     m_viewChapter->Hide();
     m_viewVerse->Hide();
@@ -202,8 +202,6 @@
 
     sword::ModMap::iterator it;
     sword::SWModule* curMod = NULL;
-    sword::SWModule* textMod = NULL;
-    sword::VerseKey* verse = NULL;
 
     for (it = m_swmgr->Modules.begin(); it != m_swmgr->Modules.end(); it++) {
         curMod = (*it).second;
@@ -227,14 +225,7 @@
         }
     }
     
-    textMod = m_swmgr->getModule((*m_confOptions)["History"].getWithDefault("LastVersion", "KJV"));
-    if(!textMod){
-        textMod = m_modTexts->begin()->second;
-    }
-    m_viewModules[m_nCurrentModule]->SetModule(textMod);
 
-    verse = new VerseKey((*m_confOptions)["History"].getWithDefault("LastPassage", "Gen 1:1"));
-    m_viewModules[m_nCurrentModule]->SetKey(*verse);
 
     if(!m_menuBar || !m_menuBar->FillTranslationsSubMenu(m_modTexts, this->m_viewModules[m_nCurrentModule]->GetModule(), MENU_TRANS_START))
         return FALSE;
@@ -243,7 +234,6 @@
     if(!GetSupportedOptions())
         return FALSE;
 
-    delete verse;
     
     m_viewModules[m_nCurrentModule]->SetSwordReady();
 
@@ -338,10 +328,20 @@
             }else{
                 return FALSE;
             }
+            SaveOptions();
     }
     return TRUE;
 }
 
+VOID SRMainFrame::SaveOptions()
+{
+    (*m_confOptions)["History"]["LastVersion"] = m_viewModules[m_nCurrentModule]->GetModule()->Name();
+    (*m_confOptions)["History"]["LastPassage"] = m_viewModules[m_nCurrentModule]->GetVerseKey().getText();
+    for(int i = 0; i < m_nTotalOpts; i++){
+        (*m_confOptions)["GlobalOptions"][m_bufModOptions[i].c_str()] = m_swmgr->getGlobalOption(m_bufModOptions[i]);
+    }
+    m_confOptions->Save();
+}
 
 BOOL SRMainFrame::OnSize(UINT nType, int cx, int cy) 
 {   
@@ -359,6 +359,7 @@
 VOID SRMainFrame::SetBook(INT nBook)
 {
     m_viewModules[m_nCurrentModule]->SetBook(nBook);
+    SaveOptions();
     UpdateWindowTitle();
 }
 
@@ -366,6 +367,7 @@
 VOID SRMainFrame::SetChapter(INT nChapter)
 {
     m_viewModules[m_nCurrentModule]->SetChapter(nChapter);
+    SaveOptions();
     UpdateWindowTitle();
 }
 
@@ -373,12 +375,14 @@
 VOID SRMainFrame::SetVerse(INT nVerse, BOOL fScroll)
 {
     m_viewModules[m_nCurrentModule]->SetVerse(nVerse, fScroll); 
+    SaveOptions();
     UpdateWindowTitle();
 }
 
 BOOL SRMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
 {
     BOOL fRetVal = m_viewModules[m_nCurrentModule]->OnKeyDown(nChar, nRepCnt, nFlags);
+    SaveOptions();
     UpdateWindowTitle();
     return fRetVal;
 }
@@ -389,6 +393,7 @@
     for(int i = 0; i < nModIndex; i++)
         it++;
     m_viewModules[m_nCurrentModule]->SetModule(it->second); 
+    SaveOptions();
     UpdateWindowTitle();
 }
 
@@ -458,6 +463,39 @@
     m_viewModules[m_nCurrentModule]->RefreshScreen(TRUE);
 }
 
+VOID SRMainFrame::LoadOptions()
+{
+    SWBuf val;    
+    sword::SWModule* textMod = NULL;
+    sword::VerseKey* verse = NULL;
+    INT nCurID = 0;
+    
+    for(int i = 0; i < m_nTotalOpts; i++){
+        val = (*m_confOptions)["GlobalOptions"].getWithDefault(m_bufModOptions[i],"Off");
+        m_swmgr->setGlobalOption(m_bufModOptions[i],val);
+        m_menuBar->CheckOptionsMenuItem(i + MENU_OPTS_START, (val == "On" ? TRUE : FALSE));
+    }    
+    
+    textMod = m_swmgr->getModule((*m_confOptions)["History"].getWithDefault("LastVersion", "KJV"));
+    if(!textMod){
+        textMod = m_modTexts->begin()->second;
+    }
+    m_viewModules[m_nCurrentModule]->SetModule(textMod);
+    nCurID = MENU_TRANS_START;
+    for (ModuleMap::iterator it = m_modTexts->begin(); it != m_modTexts->end(); it++) {
+        if(it->second == m_viewModules[m_nCurrentModule]->GetModule()){
+            m_menuBar->CheckTranslationsMenuItem(nCurID);
+            break;
+        }
+        nCurID++;
+    }    
+
+    verse = new VerseKey((*m_confOptions)["History"].getWithDefault("LastPassage", "Gen 1:1"));
+    m_viewModules[m_nCurrentModule]->SetKey(*verse);
+    
+    delete verse;
+}
+
 void SRMainFrame::SetWindowTitle(const WCString &wcsTitle)
 {    
     SetWindowText(m_hWnd,wcsTitle.w_str());

Modified: trunk/src/SwordReader_GUI/SRMainFrame.h
===================================================================
--- trunk/src/SwordReader_GUI/SRMainFrame.h	2008-08-03 00:52:25 UTC (rev 166)
+++ trunk/src/SwordReader_GUI/SRMainFrame.h	2008-08-03 05:06:53 UTC (rev 167)
@@ -49,6 +49,8 @@
     VOID SetBook(INT nBook);
     VOID SetChapter(INT nChapter);
     VOID SetVerse(INT nVerse, BOOL fScroll);
+    VOID SaveOptions();
+    VOID LoadOptions();
 private:
     INT           m_nTotalOpts;
     SWConfig     *m_confOptions;

Modified: trunk/src/SwordReader_GUI/SRModuleView.cpp
===================================================================
--- trunk/src/SwordReader_GUI/SRModuleView.cpp	2008-08-03 00:52:25 UTC (rev 166)
+++ trunk/src/SwordReader_GUI/SRModuleView.cpp	2008-08-03 05:06:53 UTC (rev 167)
@@ -41,15 +41,30 @@
 {
     if(m_pModule == pModule)
         return;
+    AbortThread();
     m_pModule = pModule;
     m_fChapterChanged = TRUE;
     LoadTextView();
 }
 
+VOID SRModuleView::AbortThread()
+{
+    INT rc;
+    if(m_fThreadRunning){
+        m_fAbortThread = TRUE;
+        rc = WaitForSingleObject(m_hLoadTextThread, INFINITE);
+        if(rc != WAIT_FAILED){
+            ::Sleep(100);// Let's sleep for a bit and give the thread a chance to spawn.
+            rc = WaitForSingleObject(m_hLoadTextThread, INFINITE);
+        }
+    }
+}
+
 VOID SRModuleView::SetKey(const VerseKey &verse)
 {
     if(m_verse == verse)
         return;
+    AbortThread();
     
     if(verse.Book() != m_verse.Book() || (m_verse.Book == verse.Book() && m_verse.Chapter() != verse.Chapter()))
         m_fChapterChanged = true;
@@ -102,16 +117,12 @@
 	WCString buf, text, s;
     BOOL done = FALSE;
     char strNum[10];
-    INT rc;
     
     if(!m_fSwordInit)
         return;
 
-    if(!fInThread && m_fThreadRunning){
-        m_fAbortThread = TRUE;
-        rc = WaitForSingleObject(m_hLoadTextThread, INFINITE);
-        if(rc != WAIT_OBJECT_0)
-            return; // Need to deal with this in a better manner.
+    if(!fInThread){
+        AbortThread();
     }
     if(!fInThread && !m_fChapterChanged) // This text should still be valid...
         return;
@@ -242,6 +253,7 @@
 {
     if(m_hLoadTextThread)
         CloseHandle(m_hLoadTextThread);
+    m_fThreadRunning = TRUE;
     m_hLoadTextThread = CreateThread(NULL, 0, LoadTextThread, (LPVOID) this, 0, &m_dwLoadTextThreadID);
 }
 
@@ -277,6 +289,7 @@
     LoadTextView();
 }
 
+
 BOOL SRModuleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
 {
     INT a = 0;
@@ -314,6 +327,7 @@
     default:
         return FALSE;
     }
+    
     return TRUE;
 }
 

Modified: trunk/src/SwordReader_GUI/SRModuleView.h
===================================================================
--- trunk/src/SwordReader_GUI/SRModuleView.h	2008-08-03 00:52:25 UTC (rev 166)
+++ trunk/src/SwordReader_GUI/SRModuleView.h	2008-08-03 05:06:53 UTC (rev 167)
@@ -35,6 +35,7 @@
     VOID        CreateLoadTextThread();
     WCString    GetVerseHeader(VerseKey key) const;
     VOID        DrawLoadingProgress(const VerseKey& keyCur);
+    VOID        AbortThread();
 
     VerseKey    m_verse;
     INT         m_nLoadedTill;




More information about the sword-cvs mailing list