[Amis-vcs] SF.net SVN: amis: [2220] branches/amis3
Brought to you by:
julienq,
marisademeglio
From: <mar...@us...> - 2007-11-05 16:19:46
|
Revision: 2220 http://amis.svn.sourceforge.net/amis/?rev=2220&view=rev Author: marisademeglio Date: 2007-11-05 08:19:49 -0800 (Mon, 05 Nov 2007) Log Message: ----------- Added open URL menu item and dialog to amisAccessibleUi.xml Added generic and MFC-specific search text functions. Need to replace annoying pop-up command window with this instead. Modified Paths: -------------- branches/amis3/AmisCore/AmisCore.vcproj branches/amis3/AmisGuiMFC2/AmisGuiMFC2.aps branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj branches/amis3/AmisGuiMFC2/src/Preferences.cpp branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp branches/amis3/DefaultLangpack/amisAccessibleUi.xml Added Paths: ----------- branches/amis3/AmisCore/include/util/SearchForFiles.h branches/amis3/AmisCore/src/util/SearchForFiles.cpp branches/amis3/AmisGuiMFC2/include/SearchForFilesMFC.h branches/amis3/AmisGuiMFC2/src/SearchForFilesMFC.cpp Modified: branches/amis3/AmisCore/AmisCore.vcproj =================================================================== --- branches/amis3/AmisCore/AmisCore.vcproj 2007-10-22 00:36:38 UTC (rev 2219) +++ branches/amis3/AmisCore/AmisCore.vcproj 2007-11-05 16:19:49 UTC (rev 2220) @@ -478,6 +478,9 @@ UsePrecompiledHeader="0"/> </FileConfiguration> </File> + <File + RelativePath=".\src\util\SearchForFiles.cpp"> + </File> </Filter> </Filter> <Filter @@ -635,6 +638,9 @@ RelativePath=".\include\util\findfilecontainer.h"> </File> <File + RelativePath=".\include\util\SearchForFiles.h"> + </File> + <File RelativePath=".\include\util\xercesutils.h"> </File> </Filter> Added: branches/amis3/AmisCore/include/util/SearchForFiles.h =================================================================== --- branches/amis3/AmisCore/include/util/SearchForFiles.h (rev 0) +++ branches/amis3/AmisCore/include/util/SearchForFiles.h 2007-11-05 16:19:49 UTC (rev 2220) @@ -0,0 +1,54 @@ +#ifndef SEARCHFORFILES_H +#define SEARCHFORFILES_H + +#include <string> +#include <vector> +#include "AmisCore.h" +#include "Media.h" +#include "ambulant/net/url.h" + +namespace amis +{ +namespace util +{ + +//will we need this struct? it is leftover. +//if so, does it belong here? +struct BookInfo +{ + amis::MediaGroup* mpTitle; + string mFilePath; +}; + +//this class is mostly virtual +//it needs platform-specific implementations +//one example is the MFC implementation in AMIS for Windows +class SearchForFiles +{ +public: + SearchForFiles(); + virtual ~SearchForFiles()=0; + + virtual int startSearch(std::string)=0; + + void setRecursiveSearch(bool); + bool isRecursiveSearch(); + + void addSearchCriteria(std::string); + amis::StdStringList getSearchCriteria(); + void clearSearchCriteria(); + bool matchesCriteria(std::string); + + //this function should be called by implementations of SearchForFiles + void addSearchResult(const ambulant::net::url*); + amis::UrlList getSearchResults(); + void clearSearchResults(); + +private: + bool mbIsRecursive; + amis::StdStringList mCriteria; + amis::UrlList mResults; +}; +} +} +#endif \ No newline at end of file Added: branches/amis3/AmisCore/src/util/SearchForFiles.cpp =================================================================== --- branches/amis3/AmisCore/src/util/SearchForFiles.cpp (rev 0) +++ branches/amis3/AmisCore/src/util/SearchForFiles.cpp 2007-11-05 16:19:49 UTC (rev 2220) @@ -0,0 +1,96 @@ +/* +AMIS: Adaptive Multimedia Information System +Software for playing DAISY books +Homepage: http://amis.sf.net + +Copyright (C) 2004-2007 DAISY for All Project + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +//for string transformations +#include <algorithm> + +#include "util/SearchForFiles.h" + +amis::util::SearchForFiles::SearchForFiles() +{ + mbIsRecursive = true; +} +amis::util::SearchForFiles::~SearchForFiles() +{ +} + +void amis::util::SearchForFiles::setRecursiveSearch(bool isRecursive) +{ + mbIsRecursive = isRecursive; +} + +bool amis::util::SearchForFiles::isRecursiveSearch() +{ + return mbIsRecursive; +} + +/*! + search criteria is defined as a desired substring of a filename + so to find all the opf files, just ask for .opf. not *.opf. +*/ +void amis::util::SearchForFiles::addSearchCriteria(std::string criterion) +{ + std::string criterion_lower = criterion; + //make lower case + std::transform(criterion_lower.begin(), criterion_lower.end(), criterion_lower.begin(), (int(*)(int))tolower); + mCriteria.push_back(criterion_lower); +} + +amis::StdStringList amis::util::SearchForFiles::getSearchCriteria() +{ + return mCriteria; +} +bool amis::util::SearchForFiles::matchesCriteria(std::string data) +{ + std::string data_lower = data; + //make lower case + std::transform(data_lower.begin(), data_lower.end(), data_lower.begin(), (int(*)(int))tolower); + + for (int i=0; i<mCriteria.size(); i++) + { + if (data_lower.find(mCriteria[i]) != std::string::npos) return true; + } + if (mCriteria.size() > 0) return false; + //if there are no criteria, everything is always a match + else return true; +} + +void amis::util::SearchForFiles::clearSearchCriteria() +{ + mCriteria.clear(); +} + +//this function should ONLY be called by implementations of SearchForFiles +void amis::util::SearchForFiles::addSearchResult(const ambulant::net::url* searchResult) +{ + mResults.push_back(*searchResult); +} + +amis::UrlList amis::util::SearchForFiles::getSearchResults() +{ + return mResults; +} + +void amis::util::SearchForFiles::clearSearchResults() +{ + mResults.clear(); +} \ No newline at end of file Modified: branches/amis3/AmisGuiMFC2/AmisGuiMFC2.aps =================================================================== (Binary files differ) Modified: branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj =================================================================== --- branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2007-10-22 00:36:38 UTC (rev 2219) +++ branches/amis3/AmisGuiMFC2/AmisGuiMFC2.vcproj 2007-11-05 16:19:49 UTC (rev 2220) @@ -144,6 +144,9 @@ RelativePath=".\include\Preferences.h"> </File> <File + RelativePath=".\include\SearchForFilesMFC.h"> + </File> + <File RelativePath=".\include\stdafx.h"> </File> <File @@ -300,6 +303,9 @@ </FileConfiguration> </File> <File + RelativePath=".\src\SearchForFilesMFC.cpp"> + </File> + <File RelativePath=".\src\stdafx.cpp"> <FileConfiguration Name="Debug|Win32"> Added: branches/amis3/AmisGuiMFC2/include/SearchForFilesMFC.h =================================================================== --- branches/amis3/AmisGuiMFC2/include/SearchForFilesMFC.h (rev 0) +++ branches/amis3/AmisGuiMFC2/include/SearchForFilesMFC.h 2007-11-05 16:19:49 UTC (rev 2220) @@ -0,0 +1,30 @@ +#ifndef SEARCHFORFILESMFC_H +#define SEARCHFORFILESMFC_H + +#include <string> +#include <vector> +#include "stdafx.h" +#include "util/SearchForFiles.h" + +using namespace std; +namespace amis +{ +namespace util +{ +class SearchForFilesMFC : public amis::util::SearchForFiles +{ +public: + SearchForFilesMFC(); + ~SearchForFilesMFC(); + + int startSearch(std::string); + void stopSearch(); + +private: + int recursiveSearch(LPCTSTR); + void doEvents(); + bool mbShouldStop; +}; +} +} +#endif \ No newline at end of file Modified: branches/amis3/AmisGuiMFC2/src/Preferences.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/Preferences.cpp 2007-10-22 00:36:38 UTC (rev 2219) +++ branches/amis3/AmisGuiMFC2/src/Preferences.cpp 2007-11-05 16:19:49 UTC (rev 2220) @@ -51,7 +51,7 @@ mbPauseOnApplicationLostFocus = true; - this->mbIsSelfVoicing = true; + this->mbIsSelfVoicing = false; this->mUiLang = "./settings/lang/eng-US/"; this->mbUseTTSNotAudio = false; } Added: branches/amis3/AmisGuiMFC2/src/SearchForFilesMFC.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/SearchForFilesMFC.cpp (rev 0) +++ branches/amis3/AmisGuiMFC2/src/SearchForFilesMFC.cpp 2007-11-05 16:19:49 UTC (rev 2220) @@ -0,0 +1,119 @@ +/* +AMIS: Adaptive Multimedia Information System +Software for playing DAISY books +Homepage: http://amis.sf.net + +Copyright (C) 2004-2007 DAISY for All Project + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include "stdafx.h" +#include "util/SearchForFiles.h" +#include "SearchForFilesMFC.h" +#include "ambulant/net/url.h" + +using namespace amis::util; + +SearchForFilesMFC::SearchForFilesMFC() +{ + mbShouldStop = false; +} + +SearchForFilesMFC::~SearchForFilesMFC() +{ + clearSearchResults(); +} + +int SearchForFilesMFC::startSearch(std::string searchPath) +{ + USES_CONVERSION; + mbShouldStop = false; + + clearSearchResults(); + + //call the search routine, which returns the number of files found + return recursiveSearch(A2T(searchPath.c_str())); +} + +void SearchForFilesMFC::stopSearch() +{ + mbShouldStop = true; +} + +int SearchForFilesMFC::recursiveSearch(LPCTSTR path) +{ + USES_CONVERSION; + + CFileFind finder; + CString filename; + int files_found = 0; + + BOOL b_is_working = finder.FindFile(path); + while (b_is_working) + { + b_is_working = finder.FindNextFile(); + + // handle messages + doEvents(); + + // received a stop signal + if (mbShouldStop == true) break; + + if (finder.IsDots()) continue; + + // if it's a directory, recursively search it + if (finder.IsDirectory() && isRecursiveSearch()) + { + CString str = finder.GetFilePath(); + files_found += recursiveSearch(str + _T("\\*.*")); + } + else + { + filename = finder.GetFileName(); + + if (matchesCriteria(T2A(filename))) + { + files_found++; + //save the file path + CString file_path = finder.GetFilePath(); + std::string file_path_string = T2A(file_path); + ambulant::net::url file_path_url = ambulant::net::url::from_url(file_path_string); + addSearchResult(&file_path_url); + } + } + } + + amis::UrlList results = getSearchResults(); + return results.size(); +} + +//peek at the message queue +void SearchForFilesMFC::doEvents() +{ + MSG msg; + + while ( ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE ) ) + { + if ( ::GetMessage(&msg, NULL, 0, 0)) + { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + else + { + break; + } + } +} \ No newline at end of file Modified: branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp =================================================================== --- branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp 2007-10-22 00:36:38 UTC (rev 2219) +++ branches/amis3/AmisGuiMFC2/src/gui/AmisGuiMFC2.cpp 2007-11-05 16:19:49 UTC (rev 2220) @@ -186,8 +186,12 @@ amis::dtb::DtbWithHooks::Instance()->setCallbackForPreprocessingBookKey(registerBookKeyFile); - if (amis::Preferences::Instance()->mbIsSelfVoicing == true) - { + //marisa removed this if-statement + //the self-voicing data should be ready to go whether or not self-voicing is turned on at the start + //the self-voicing data is also the dynamic localization data, so it is used all over the place + //maybe this needs to be changed someday and all strings must be duplicated in the RC file .. ? for now it's ok. + //if (amis::Preferences::Instance()->mbIsSelfVoicing == true) + //{ //read in the new self-voicing/accessible UI data DataReader new_data_reader; DataTree* p_new_data_tree; @@ -231,7 +235,7 @@ { amis::Preferences::Instance()->mbIsSelfVoicing = false; } - } + //} Modified: branches/amis3/DefaultLangpack/amisAccessibleUi.xml =================================================================== --- branches/amis3/DefaultLangpack/amisAccessibleUi.xml 2007-10-22 00:36:38 UTC (rev 2219) +++ branches/amis3/DefaultLangpack/amisAccessibleUi.xml 2007-11-05 16:19:49 UTC (rev 2220) @@ -32,6 +32,23 @@ <audio src="./audio/006_O.mp3" from="file:///c:/devel/amis/Defaultlangpack/prompts/prom0007.smil#text_0007" /> </mnemonic> </action> + <!--new action--> + <action mfcid="ID_MENU_FILE_OPENURL" widget="menuItem"> + <note>This is going to be a menu item</note> + <icon src="./open.png" type="smallIcon" /> + <caption> + <text>Open URL...</text> + <originalText>Open URL...</originalText> + </caption> + <description> + <text>Open a Daisy book from a URL</text> + <originalText>Open a Daisy book from a URL</originalText> + </description> + <accelerator> + <text>Ctrl+U</text> + <originalText>Ctrl+U</originalText> + </accelerator> + </action> <action mfcid="ID_MENU_FILE_LOADCD" widget="menuItem toolbarItem"> <note>This is going to be a menu item and a toolbar item</note> <icon src="./settings/img/cd3.ico" type="smallIcon" /> @@ -1906,6 +1923,55 @@ </list> </control> </dialog> + <!--new dialog--> + <dialog mfcid="IDD_OPENURL"> + <note>This is the open URL dialog</note> + <caption> + <text>Open URL</text> + <originalText>Open URL</originalText> + </caption> + <description mfcid="IDC_DESC"> + <text>Enter the URL of the book you want to open:</text> + <originalText>Enter the URL of the book you want to open:</originalText> + </description> + <prompt type="instructions"> + <promptItem refid="tabAround" /> + <promptItem> + <text>After typing in the URL, press enter.</text> + <originalText>After typing in the URL, press enter.</originalText> + </promptItem> + <promptItem refid="altC_to_cancel" /> + <promptItem refid="repeatLastPromptInstr" /> + <promptItem refid="hearDlgInstructions" /> + </prompt> + <control mfcid="IDOK" widget="button"> + <caption> + <promptItem refid="ok_button_caption" /> + </caption> + <description> + <text>Press to load the URL.</text> + <originalText>Press to load the URL.</originalText> + </description> + </control> + <control mfcid="IDCANCEL" widget="button"> + <caption> + <promptItem refid="cancel_button_caption" /> + </caption> + <description> + <promptItem refid="cancel_button_description" /> + </description> + <mnemonic> + <text>C</text> + <originalText>C</originalText> + </mnemonic> + </control> + <control mfcid="IDC_URL" widget="textfield"> + <description> + <text>Type the URL in this field.</text> + <originalText>Type the URL in this field.</originalText> + </description> + </control> + </dialog> </dialogs> <prompts> <promptItemRefs> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |