[Amis-vcs] SF.net SVN: amis: [2388] branches/amis3
Brought to you by:
julienq,
marisademeglio
From: <mar...@us...> - 2008-03-04 05:15:00
|
Revision: 2388 http://amis.svn.sourceforge.net/amis/?rev=2388&view=rev Author: marisademeglio Date: 2008-03-03 21:15:06 -0800 (Mon, 03 Mar 2008) Log Message: ----------- Added support for opening local books from the command line. Added reopening of the last-read book (although it is still off by default in the preferences) Removed audiere and fftw DLLs since they shouldn't be needed anymore. Modified Paths: -------------- branches/amis3/AmisCore/src/util/Log.cpp branches/amis3/AmisGuiMFC2/AmisGuiMFC2.aps branches/amis3/AmisGuiMFC2/AmisGuiMFC2.rc branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj branches/amis3/AmisGuiMFC2/include/gui/AmisApp.h branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp branches/amis3/AmisGuiMFC2/src/gui/MmDoc.cpp Removed Paths: ------------- branches/amis3/bin/audiere.dll branches/amis3/bin/fftw3.dll Modified: branches/amis3/AmisCore/src/util/Log.cpp =================================================================== --- branches/amis3/AmisCore/src/util/Log.cpp 2008-03-03 06:30:45 UTC (rev 2387) +++ branches/amis3/AmisCore/src/util/Log.cpp 2008-03-04 05:15:06 UTC (rev 2388) @@ -66,6 +66,16 @@ void amis::util::Log::endLog() { +#ifdef AMIS_PLATFORM_WINDOWS + char datestr[10]; + char timestr[10]; + _strdate(datestr); + _strtime(timestr); + mFile<<"End of log\n"<<datestr<<"\n"<<timestr<<endl; +#else + mFile<<"End of log"<<endl; + //TODO: timestamp for other platforms +#endif mFile.close(); mbIsFileOpen = false; } Modified: branches/amis3/AmisGuiMFC2/AmisGuiMFC2.aps =================================================================== (Binary files differ) Modified: branches/amis3/AmisGuiMFC2/AmisGuiMFC2.rc =================================================================== --- branches/amis3/AmisGuiMFC2/AmisGuiMFC2.rc 2008-03-03 06:30:45 UTC (rev 2387) +++ branches/amis3/AmisGuiMFC2/AmisGuiMFC2.rc 2008-03-04 05:15:06 UTC (rev 2388) @@ -383,8 +383,8 @@ CONTROL "Highlight text as it is read aloud",IDC_HIGHLIGHTTEXT, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,59,242,10 CONTROL "Load the most recently read book on startup", - IDC_LOADLASTBOOK,"Button",BS_AUTOCHECKBOX | WS_DISABLED | - WS_TABSTOP,7,76,242,10 + IDC_LOADLASTBOOK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7, + 76,242,10 CONTROL "Start in basic view mode",IDC_STARTINBASICVIEW,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,7,94,242,10 CONTROL "Pause audio when switching applications", Modified: branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj =================================================================== --- branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2008-03-03 06:30:45 UTC (rev 2387) +++ branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2008-03-04 05:15:06 UTC (rev 2388) @@ -36,7 +36,7 @@ <Tool Name="VCLinkerTool" AdditionalDependencies="AmisCoreD.lib xerces-c_2D.lib libambulant_shwin32_D.lib strmiids.lib uuid.lib" - OutputFile="$(OutDir)/AMIS.exe" + OutputFile="$(OutDir)/AMISD.exe" LinkIncremental="2" AdditionalLibraryDirectories="../lib;../../../../ambulant/lib/win32;"$(VSInstallDir)\..\Microsoft Speech SDK 5.1\Lib\i386";"$(VSInstallDir)\..\Visual Leak Detector"" IgnoreDefaultLibraryNames="uafxcwd.lib" Modified: branches/amis3/AmisGuiMFC2/include/gui/AmisApp.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/gui/AmisApp.h 2008-03-03 06:30:45 UTC (rev 2387) +++ branches/amis3/AmisGuiMFC2/include/gui/AmisApp.h 2008-03-04 05:15:06 UTC (rev 2388) @@ -64,6 +64,7 @@ amis::RecentBooks* getRecentBooks(); bool isBookOpen(); void setPauseState(bool play); + bool shouldIgnoreOpenDocEvent(); //Menu handlers afx_msg void OnFileOpen(); @@ -118,6 +119,9 @@ ambulant::net::url mURL; amis::RecentBooks* mpRecentBooks; bool mbBookIsOpen; + bool mbShouldIgnoreOpenDocEvent; + bool mbWasLastExitClean; + public: //afx_msg void OnAppAbout(); DECLARE_MESSAGE_MAP() Modified: branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp 2008-03-03 06:30:45 UTC (rev 2387) +++ branches/amis3/AmisGuiMFC2/src/gui/AmisApp.cpp 2008-03-04 05:15:06 UTC (rev 2388) @@ -124,6 +124,7 @@ BOOL CAmisApp::InitInstance() { + USES_CONVERSION; HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); if (hr == S_FALSE) CoUninitialize(); @@ -173,14 +174,12 @@ // To create the main window, this code creates a new frame window // object and then sets it as the application's main window object CMDIFrameWnd* pFrame = new CMainFrame; - if (!pFrame->LoadFrame(IDR_AMISTYPE)) { amis::util::Log::Instance()->writeError("Could not load MFC frame IDR_AMISTYPE", "CMainFrame::InitInstance", "AmisGuiMFC2"); return FALSE; } - m_pMainWnd = pFrame; // Parse command line for standard shell commands, DDE, file open @@ -190,11 +189,29 @@ // Dispatch commands specified on the command line //it turns out that this step is rather important even if you're not really interested in //the command line because mfc processes dynamic view creation somewhere in here. + //also: + //this will stupidly invoke seemingly any available OnOpenDocument handler if it thinks your + //command parameters want to open a document. + //our workaround is the mbShouldIgnoreOpenDoc event flag + mbShouldIgnoreOpenDocEvent = true; if (!ProcessShellCommand(cmdInfo)) { amis::util::Log::Instance()->writeError("Error processing shell command info", "CAmisApp::InitInstance", "AmisGuiMFC2"); return FALSE; } + mbShouldIgnoreOpenDocEvent = false; + bool b_open_from_cmdline = false; + ambulant::net::url book_to_open; + if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileOpen) + { + //we have to assume that command line parameters are local files + //TODO: introduce a command line parameter to identify URLs + //if we get the two mixed up, then the path gets mangled + b_open_from_cmdline = true; + book_to_open = ambulant::net::url::from_filename(T2A(cmdInfo.m_strFileName)); + amis::util::Log::Instance()->writeMessage("Command line parameter: ", &book_to_open, "CAmisApp::InitInstance", "AmisGuiMFC2"); + } + // try to load shared MDI menus and accelerator table HINSTANCE hInst = AfxGetResourceHandle(); @@ -213,11 +230,24 @@ //set the callback function to handle book key registration amis::dtb::DtbWithHooks::Instance()->setCallbackForPreprocessingBookKey(registerBookKeyFile); + //if we're not opening from the command line, try loading the last-read book + if (b_open_from_cmdline == false + && Preferences::Instance()->getLoadLastBook() == true + && mbWasLastExitClean == true) + book_to_open = mpRecentBooks->getLastRead()->mPath; + + //open a book if we decided to either open the command line parameter or last-read book + if (!book_to_open.is_empty_path()) openBook(&book_to_open); + return TRUE; } int CAmisApp::ExitInstance() { + Preferences::Instance()->setWasExitClean(true); + PreferencesFileIO prefs_io; + prefs_io.writeToFile(Preferences::Instance()->getSourceUrl()->get_file(), Preferences::Instance()); + amis::util::Log::Instance()->writeMessage("Exiting", "CAmisApp::ExitInstance", "AmisGuiMFC2"); if (m_hMDIMenu != NULL) FreeResource(m_hMDIMenu); if (m_hMDIAccel != NULL)FreeResource(m_hMDIAccel); @@ -235,8 +265,7 @@ DataTree::Instance()->DestroyInstance(); - if (mpRecentBooks) - delete mpRecentBooks; + if (mpRecentBooks != NULL) delete mpRecentBooks; amis::util::Log::Instance()->endLog(); amis::util::Log::Instance()->DestroyInstance(); @@ -264,11 +293,15 @@ void CAmisApp::initializePathsAndFiles() { - //read the preferences + //read the preferences and mark the was-exit-clean flag as false amis::io::PreferencesFileIO prefs_io; string prefs_path = "./settings/amisPrefs.xml"; prefs_path = amis::util::FilePathTools::goRelativePath(theApp.getAppPath(), prefs_path); prefs_io.readFromFile(prefs_path); + mbWasLastExitClean = Preferences::Instance()->getWasExitClean(); + Preferences::Instance()->setWasExitClean(false); + prefs_io.writeToFile(prefs_path, Preferences::Instance()); + //read the recent books list string recent_books_path = "./settings/amisRecentBooks.xml"; recent_books_path = amis::util::FilePathTools::goRelativePath(theApp.getAppPath(), recent_books_path); @@ -328,6 +361,10 @@ { return mbBookIsOpen; } +bool CAmisApp::shouldIgnoreOpenDocEvent() +{ + return mbShouldIgnoreOpenDocEvent; +} //this function is used by all functions here that lead to a book being opened void CAmisApp::openBook(const ambulant::net::url* filename) { @@ -337,7 +374,6 @@ MainWndParts::Instance()->updateTitleSelfVoicing(Preferences::Instance()->getIsSelfVoicing()); bool b_a_book_was_open = false; - //close the open book if (mbBookIsOpen == true) { Modified: branches/amis3/AmisGuiMFC2/src/gui/MmDoc.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/MmDoc.cpp 2008-03-03 06:30:45 UTC (rev 2387) +++ branches/amis3/AmisGuiMFC2/src/gui/MmDoc.cpp 2008-03-04 05:15:06 UTC (rev 2388) @@ -53,8 +53,8 @@ #include "gui/MmDoc.h" #include "gui/MmView.h" - #include "gui/MainWndParts.h" +#include "gui/AmisApp.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -126,6 +126,11 @@ BOOL MmDoc::OnOpenDocument(LPCTSTR lpszPathName) { + //med 21 June 07 + //this is a hack to get around the fact that windows will automatically invoke this + //OnOpenDocument handler when it does command line processing (even though I wish it wouldn't) + if (theApp.shouldIgnoreOpenDocEvent() == true) return TRUE; + POSITION pos = GetFirstViewPosition(); if(pos != NULL) { Deleted: branches/amis3/bin/audiere.dll =================================================================== (Binary files differ) Deleted: branches/amis3/bin/fftw3.dll =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |