[dasher: 152/217] Made XmlSettingsStore one and only storage mechanism for settings



commit a2dc350a39c094c9259131458bc547fbb9acbe7e
Author: Ada Majorek <amajorek google com>
Date:   Wed Dec 23 22:39:14 2015 -0800

    Made XmlSettingsStore one and only storage mechanism for settings
    
    When config command line parameter is not provided, settings.xml file is
    used. Otherwise settings.*.xml file is choosen.
    I

 Src/DasherCore/DasherInterfaceBase.cpp |    2 -
 Src/DasherCore/DasherInterfaceBase.h   |    8 +-
 Src/DasherCore/XmlSettingsStore.cpp    |   50 ++------
 Src/DasherCore/XmlSettingsStore.h      |   10 +-
 Src/Gtk2/DasherControl.cpp             |   12 --
 Src/Gtk2/DasherControl.h               |    2 -
 Src/Gtk2/FileUtils.cpp                 |   22 ++++
 Src/Gtk2/FileUtils.h                   |    1 +
 Src/Gtk2/GConfStore.cpp                |   96 --------------
 Src/Gtk2/GSettingsStore.cpp            |   43 -------
 Src/Gtk2/GnomeSettingsStore.h          |   45 -------
 Src/Gtk2/Makefile.am                   |    9 --
 Src/Gtk2/NoStore.cpp                   |   29 -----
 Src/Gtk2/dasher_main.cpp               |   26 ++---
 Src/Win32/Common/WinOptions.cpp        |  216 --------------------------------
 Src/Win32/Common/WinOptions.h          |   45 -------
 Src/Win32/Dasher.cpp                   |  104 ++++++---------
 Src/Win32/Dasher.h                     |   12 ++-
 Src/Win32/DasherControl_vc2013.vcxproj |    2 -
 Src/Win32/DasherWindow.cpp             |   26 ++---
 Src/Win32/DasherWindow.h               |    4 +-
 Src/Win32/WinMain.cpp                  |   10 +-
 configure.ac                           |    2 -
 23 files changed, 126 insertions(+), 650 deletions(-)
---
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index 82e4410..c3781b9 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -189,8 +189,6 @@ CDasherInterfaceBase::~CDasherInterfaceBase() {
   }
 
   delete m_pFramerate;
-  delete m_fileUtils;
-
 }
 
 void CDasherInterfaceBase::PreSetNotify(int iParameter, const std::string &sNewValue) {
diff --git a/Src/DasherCore/DasherInterfaceBase.h b/Src/DasherCore/DasherInterfaceBase.h
index e1d31a7..da9b438 100644
--- a/Src/DasherCore/DasherInterfaceBase.h
+++ b/Src/DasherCore/DasherInterfaceBase.h
@@ -82,6 +82,10 @@ public:
        /// \param pattern string matching just filename (not path), potentially
        /// including '*'s (as per glob)
        virtual void ScanFiles(AbstractParser *parser, const std::string &strPattern) = 0;
+
+       // Writes file to user data directory. 
+       virtual bool WriteUserDataFile(const std::string &filename, const std::string &strNewText, bool 
append) = 0;
+
 };
 
 /// The central class in the core of Dasher. Ties together the rest of
@@ -238,8 +242,8 @@ public:
   /// \param filename name of training file, without path (e.g. "training_english_GB.txt")
   /// \param strNewText text to append
   ///
-
-  virtual void WriteTrainFile(const std::string &filename, const std::string &strNewText) {
+  void WriteTrainFile(const std::string &filename, const std::string &strNewText) {
+    m_fileUtils->WriteUserDataFile(filename, strNewText, true);
   };
 
   // App Interface
diff --git a/Src/DasherCore/XmlSettingsStore.cpp b/Src/DasherCore/XmlSettingsStore.cpp
index e545e65..f47ef0c 100644
--- a/Src/DasherCore/XmlSettingsStore.cpp
+++ b/Src/DasherCore/XmlSettingsStore.cpp
@@ -1,17 +1,11 @@
 #include "XmlSettingsStore.h"
+#include "DasherInterfaceBase.h"
 
 #include <iostream>
 #include <fstream>
 #include <string.h>
 #include <algorithm>
 
-#if defined(_WIN32) || defined(_WIN64) 
-#include "WinUTF8.h"
-#define strcasecmp _stricmp 
-#define widen(a) WinUTF8::UTF8string_to_wstring((a))
-#else
-#define widen(a) (a)
-#endif
 
 namespace Dasher {
 namespace {
@@ -29,29 +23,17 @@ bool Read(const std::map<std::string, T> values, const std::string& key,
 
 }  // namespace
 
-XmlSettingsStore::XmlSettingsStore(const std::string& filename,
+XmlSettingsStore::XmlSettingsStore(const std::string& filename, CFileUtils* fileUtils,
                                    CMessageDisplay* pDisplay)
-    : AbstractXMLParser(pDisplay), filename_(filename) {}
-
-bool XmlSettingsStore::Load() {
-  bool result = true;
-  std::ifstream f(widen(filename_));
-  if (f.good()) {
-    f.close();
-    if (!ParseFile(filename_, true /* user */)) {
-      m_pMsgs->Message("Failed to load the XML settings", true /* interrupt */);
-      result = false;
-    }
-  } else {
-    m_pMsgs->FormatMessageWithString("XML File not found: ", filename_.c_str());
-    result = false;
-  }
+    : AbstractXMLParser(pDisplay), filename_(filename),fileutils_(fileUtils) {}
+
+void XmlSettingsStore::Load() {
+  fileutils_->ScanFiles(this, filename_);
   // Load all the settings or create defaults for the ones that don't exist.
   // The superclass 'ParseFile' saves default settings if not found.
   mode_ = EXPLICIT_SAVE;
   LoadPersistent();
   mode_ = SAVE_IMMEDIATELY;
-  return result;
 }
 
 bool XmlSettingsStore::LoadSetting(const std::string& key, bool* value) {
@@ -93,10 +75,9 @@ bool XmlSettingsStore::Save() {
   if (!modified_) {
     return true;
   }
-  try {
+  
     modified_ = false;
-    std::ofstream out;
-    out.open(widen(filename_), std::ios::out | std::ios::trunc);
+    std::stringstream out;
     out << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
     out << "<settings>\n";
     for (const auto& p : long_settings_) {
@@ -114,13 +95,8 @@ bool XmlSettingsStore::Save() {
           << "\"/>\n";
     }
     out << "</settings>\n";
-    out.close();
-  } catch (...) {
-    // TODO(localize).
-    m_pMsgs->Message("Failed to save the settings", true /* interrupt */);
-    return false;
-  }
-  return true;
+    return fileutils_->WriteUserDataFile(filename_, out.str(),false);
+
 }
 
 bool XmlSettingsStore::GetNameAndValue(const XML_Char** attributes,
@@ -190,13 +166,13 @@ void XmlSettingsStore::XmlStartHandler(const XML_Char* element_name,
     long_settings_[name] = v;
   } else if (element == "bool") {
 
-    if (strcasecmp(value.c_str(), "true") == 0) {
+    if (strcmp(value.c_str(), "True") == 0) {
       boolean_settings_[name] = true;
-    } else if (strcasecmp(value.c_str(), "false") == 0) {
+    } else if (strcmp(value.c_str(), "False") == 0) {
       boolean_settings_[name] = false;
     } else {
       m_pMsgs->FormatMessageWith2Strings(
-          "XML configuration: boolean value should be 'true' or 'false' found "
+          "XML configuration: boolean value should be 'True' or 'False' found "
           "%s = '%s'",
           name.c_str(), value.c_str());
     }
diff --git a/Src/DasherCore/XmlSettingsStore.h b/Src/DasherCore/XmlSettingsStore.h
index 37c892b..0d6ec04 100644
--- a/Src/DasherCore/XmlSettingsStore.h
+++ b/Src/DasherCore/XmlSettingsStore.h
@@ -11,16 +11,17 @@
 #include "SettingsStore.h"
 #include "AbstractXMLParser.h"
 
-namespace Dasher {
+class CFileUtils;
 
+namespace Dasher {
 // This class is not thread-safe.
-class XmlSettingsStore : public Dasher::CSettingsStore, AbstractXMLParser {
+class XmlSettingsStore : public Dasher::CSettingsStore, public AbstractXMLParser {
  public:
-  XmlSettingsStore(const std::string& filename, CMessageDisplay* pDisplay);
+  XmlSettingsStore(const std::string& filename, CFileUtils* fileUtils, CMessageDisplay* pDisplay);
   ~XmlSettingsStore() override = default;
   // Load the XML file and fills in the default values needed.
   // Returns true on success.
-  bool Load();
+  void Load();
   // Saves the XML file, returns true on success.
   bool Save();
 
@@ -54,6 +55,7 @@ class XmlSettingsStore : public Dasher::CSettingsStore, AbstractXMLParser {
 
   Mode mode_ = EXPLICIT_SAVE;
   std::string filename_;
+  CFileUtils* fileutils_;
   bool modified_ = false;
   std::map<std::string, bool> boolean_settings_;
   std::map<std::string, long> long_settings_;
diff --git a/Src/Gtk2/DasherControl.cpp b/Src/Gtk2/DasherControl.cpp
index ac83a8e..81974d6 100644
--- a/Src/Gtk2/DasherControl.cpp
+++ b/Src/Gtk2/DasherControl.cpp
@@ -408,18 +408,6 @@ CGameModule *CDasherControl::CreateGameModule() {
   return CDashIntfScreenMsgs::CreateGameModule();
 }
 
-void CDasherControl::WriteTrainFile(const std::string &filename, const std::string &strNewText) {
-  if(strNewText.length() == 0)
-    return;
-
-  std::string strFilename(m_user_data_dir);
-  strFilename+=filename;
-
-  int fd=open(strFilename.c_str(),O_CREAT|O_WRONLY|O_APPEND,S_IRUSR|S_IWUSR);
-  write(fd,strNewText.c_str(),strNewText.length());
-  close(fd);
-}
-
 // TODO: Sort these methods out
 void CDasherControl::ExternalKeyDown(int iKeyVal) {
 //   if(m_pKeyboardHelper) {
diff --git a/Src/Gtk2/DasherControl.h b/Src/Gtk2/DasherControl.h
index c1c9dfd..a43bbc9 100644
--- a/Src/Gtk2/DasherControl.h
+++ b/Src/Gtk2/DasherControl.h
@@ -27,7 +27,6 @@
 
 //#include "../DasherCore/DasherSettingsInterface.h"
 #include "../DasherCore/DashIntfScreenMsgs.h"
-#include "GnomeSettingsStore.h"
 #include "../DasherCore/UserLog.h"
 #include "FileUtils.h"
 
@@ -134,7 +133,6 @@ public:
 
   ///Override to broadcast dasher_stop signal...
   void Done() override;
-  void WriteTrainFile(const std::string &filename, const std::string &strNewText) override;
 
   void ClearAllContext() override ;
   std::string GetAllContext() override;
diff --git a/Src/Gtk2/FileUtils.cpp b/Src/Gtk2/FileUtils.cpp
index 3f0a280..58f72e9 100644
--- a/Src/Gtk2/FileUtils.cpp
+++ b/Src/Gtk2/FileUtils.cpp
@@ -35,3 +35,25 @@ void FileUtils::ScanFiles(AbstractParser *parser, const std::string &strPattern)
 
   globScan(parser, user, sys);
 }
+
+
+bool FileUtils::WriteUserDataFile(const std::string &filename, const std::string &strNewText, bool append) {
+  if (strNewText.length() == 0)
+    return true;
+
+  std::string user_data_dir = getenv("HOME");
+  user_data_dir += "/.dasher/";
+  std::string strFilename(user_data_dir);
+  strFilename = filename;
+  int mode = O_CREAT | O_WRONLY;
+  if (append)
+  {
+    mode = O_CREAT | O_WRONLY | O_APPEND;
+  }
+  int fd = open(strFilename.c_str(), mode, S_IRUSR | S_IWUSR);
+  if (!fd) return false;
+ 
+  int written = write(fd, strNewText.c_str(), strNewText.length());
+  close(fd);
+  return written == strNewText.length();
+
diff --git a/Src/Gtk2/FileUtils.h b/Src/Gtk2/FileUtils.h
index bebfb12..a638c69 100644
--- a/Src/Gtk2/FileUtils.h
+++ b/Src/Gtk2/FileUtils.h
@@ -9,6 +9,7 @@ public:
   ~FileUtils() override = default;
   int GetFileSize(const std::string &strFileName) override;
   void ScanFiles(AbstractParser *parser, const std::string &strPattern) override;
+  bool WriteUserDataFile(const std::string &filename, const std::string &strNewText, bool append) override;
 };
 
 #endif //DASHER_FILEUTILS_H
diff --git a/Src/Gtk2/Makefile.am b/Src/Gtk2/Makefile.am
index 8b7a900..ea912fb 100644
--- a/Src/Gtk2/Makefile.am
+++ b/Src/Gtk2/Makefile.am
@@ -32,7 +32,6 @@ libdashercontrol_la_SOURCES = \
                DasherControl.h \
                FileUtils.h \
                FileUtils.cpp \
-               GnomeSettingsStore.h \
                GtkDasherControl.cpp \
                GtkDasherControl.h \
                KeyboardHelper.cpp \
@@ -46,14 +45,6 @@ libdashercontrol_la_SOURCES = \
                mouse_input.h \
                $(settings_store)
 
-if USE_GCONF
-libdashercontrol_la_SOURCES += GConfStore.cpp
-else
-if USE_GSETTINGS
-libdashercontrol_la_SOURCES += GSettingsStore.cpp
-else
-libdashercontrol_la_SOURCES += NoStore.cpp
-endif
 endif
 
 if USE_SPEECHDISPATCHER
diff --git a/Src/Gtk2/dasher_main.cpp b/Src/Gtk2/dasher_main.cpp
index 20882ee..7164e65 100644
--- a/Src/Gtk2/dasher_main.cpp
+++ b/Src/Gtk2/dasher_main.cpp
@@ -26,7 +26,6 @@
 #include "math.h"
 
 #include "dasher_main_private.h"
-#include "GnomeSettingsStore.h"
 #include "XmlSettingsStore.h"
 
 enum {
@@ -173,18 +172,17 @@ DasherMain *
 dasher_main_new(int *argc, char ***argv, SCommandLine *pCommandLine) {
     DasherMain *pDasherMain = (DasherMain *)(g_object_new(dasher_main_get_type(), NULL));
     DasherMainPrivate *pPrivate = DASHER_MAIN_GET_PRIVATE(pDasherMain);
-
+  string configFileName = "settings.xml";
+  if (pCommandLine->szConfigFile != nullptr)
+    configFileName = "settings." + pCommandLine->szConfigFile + ".xml";
   static XmlErrorDisplay display;
-  Dasher::CSettingsStore* settings;
-  if (pCommandLine->szConfigFile == nullptr) {
-    settings = new CGnomeSettingsStore();
-  } else {
-    auto xml_settings = new Dasher::XmlSettingsStore(pCommandLine->szConfigFile, &display);
-    xml_settings->Load();
-    // Save the defaults if needed.
-    xml_settings->Save();
-    settings = xml_settings;
-  }
+  // TODO Pass that instance of fileutils to DasherControl, instead of creating new one. 
+  static FileUtils fileUtils;
+  auto settings = new Dasher::XmlSettingsStore(configFileName, &fileUtils, &display);
+  settings->Load();
+  // Save the defaults if needed.
+  settings->Save();
+
   DasherAppSettings::Create(settings);
   pPrivate->pAppSettings = DasherAppSettings::Get();
   pPrivate->parameter_callback_id_ =
@@ -210,10 +208,6 @@ dasher_main_new(int *argc, char ***argv, SCommandLine *pCommandLine) {
         return 0;
       }
     }
-    else { 
-      // By default use traditional mode
-      pPrivate->pAppSettings->SetLong(APP_LP_STYLE, APP_STYLE_TRAD);
-    }
 
     dasher_main_load_interface(pDasherMain);
 
diff --git a/Src/Win32/Dasher.cpp b/Src/Win32/Dasher.cpp
index c92f898..310f4f4 100644
--- a/Src/Win32/Dasher.cpp
+++ b/Src/Win32/Dasher.cpp
@@ -11,16 +11,10 @@
 #include "DasherWindow.h"
 #include "Widgets/Edit.h"
 
-#ifndef _WIN32_WCE
 #include "Sockets/SocketInput.h"
 #include "BTSocketInput.h"
-#endif
 #include <Sphelper.h>
-#include "Common/WinOptions.h"
-
-#ifndef _WIN32_WCE
 #include <sys/stat.h>
-#endif
 
 using namespace std;
 using namespace Dasher;
@@ -159,52 +153,38 @@ bool Dasher::CDasher::GetWindowSize(int* pTop, int* pLeft, int* pBottom, int* pR
     return false;
 }
 
-void Dasher::CDasher::WriteTrainFile(const std::string &filename, const std::string &strNewText) {
-  if(strNewText.size() == 0)
-    return;
-
-  Tstring UserDataDir, Tfilename, TTrainFile;
-  UTF8string_to_wstring(filename, Tfilename);
-  WinHelper::GetUserDirectory(&UserDataDir);
-  UserDataDir += TEXT("dasher.rc\\");
-  TTrainFile = UserDataDir + Tfilename;
+bool CWinFileUtils::WriteUserDataFile(const std::string &filename, const std::string &strNewText, bool 
append) {
+  if (strNewText.size() == 0)
+    return true;
 
-  HANDLE hFile = CreateFile(TTrainFile.c_str(),
-                            GENERIC_WRITE, 0, NULL, 
-                            OPEN_ALWAYS, 
-                            FILE_ATTRIBUTE_NORMAL, 0);
+  string fullpath = GetDataPath(true) + filename;
+  auto CreationDisposition = append ? OPEN_ALWAYS : CREATE_ALWAYS;
+  HANDLE hFile = CreateFile(UTF8string_to_wstring(fullpath).c_str(),
+         GENERIC_WRITE, 0, NULL,
+         CreationDisposition,
+         FILE_ATTRIBUTE_NORMAL, 0);
 
   if(hFile == INVALID_HANDLE_VALUE) {
     OutputDebugString(TEXT("Can not open file\n"));
+    return false;
   }
-  else {
     DWORD NumberOfBytesWritten;
     SetFilePointer(hFile, 0, NULL, FILE_END);
-
-  // Surely there are better ways to write to files than this??
-
-    for(unsigned int i = 0; i < strNewText.size(); i++) {
-      WriteFile(hFile, &strNewText[i], 1, &NumberOfBytesWritten, NULL);
-    }
-
+    WriteFile(hFile, &strNewText.c_str()[0], strNewText.size(), &NumberOfBytesWritten, NULL);
     CloseHandle(hFile);
-  }
+
+    return NumberOfBytesWritten == strNewText.size();
 }
 
-void CWinFileUtils::ScanDirectory(const Tstring &strMask, std::vector<std::string> &vFileList) {
+void CWinFileUtils::ScanDirectory(const string &strMask, std::vector<std::string> &vFileList) {
   using namespace WinUTF8;
-
-  std::string filename;
   WIN32_FIND_DATA find;
-  HANDLE handle;
-
-  handle = FindFirstFile(strMask.c_str(), &find);
+  wstring wideMask = UTF8string_to_wstring(strMask);
+  HANDLE handle = FindFirstFile(wideMask.c_str(), &find);
   if(handle != INVALID_HANDLE_VALUE) {
-    wstring_to_UTF8string(wstring(find.cFileName), filename);
-    vFileList.push_back(filename);
+    vFileList.push_back(wstring_to_UTF8string(find.cFileName));
     while(FindNextFile(handle, &find) != false) {
-      wstring_to_UTF8string(wstring(find.cFileName), filename);
-      vFileList.push_back(filename);
+               vFileList.push_back(wstring_to_UTF8string(find.cFileName));
     }
     FindClose(handle);
   }
@@ -214,45 +194,43 @@ void CWinFileUtils::ScanFiles(AbstractParser *parser, const std::string &strPatt
   using namespace WinHelper;
   using namespace WinUTF8;
   
-  Tstring pattern;
-  UTF8string_to_wstring(strPattern, pattern);
-  
   std::vector<std::string> vFileList;
-  
-  Tstring AppData;
-  GetAppDirectory(&AppData);
-  AppData += TEXT("system.rc\\");
-  CreateDirectory(AppData.c_str(), NULL);// TODO: Any harm if they already exist
-  string sysDir;
-  wstring_to_UTF8string(AppData,sysDir);
-  AppData += pattern;
-  ScanDirectory(AppData, vFileList);
+
+  string sysDir = GetDataPath(false);
+  ScanDirectory(sysDir +strPattern, vFileList);
   for (vector<std::string>::iterator it=vFileList.begin(); it!=vFileList.end(); it++)
     parser->ParseFile(sysDir + (*it),false);
 
   vFileList.clear();
   
-  Tstring UserData;
-  GetUserDirectory(&UserData);
-  UserData += TEXT("dasher.rc\\");
-  CreateDirectory(UserData.c_str(), NULL);      // Try and create folders. Doesn't seem
-  string userDir;
-  wstring_to_UTF8string(UserData,userDir);
-  UserData +=pattern;
-  ScanDirectory(UserData, vFileList); 
+  string userDir = GetDataPath(true);
+  ScanDirectory(userDir + strPattern, vFileList); 
   for (vector<std::string>::iterator it=vFileList.begin(); it!=vFileList.end(); it++)
     parser->ParseFile(userDir + (*it),true);
 }
 
+std::string CWinFileUtils::GetDataPath(bool user) {
+       using namespace WinHelper;
+       using namespace WinUTF8;
+       wstring DataPath;
+       if (user) {
+               GetUserDirectory(&DataPath);
+               DataPath += TEXT("dasher.rc\\");
+       }
+       else {
+               GetAppDirectory(&DataPath);
+               DataPath += TEXT("system.rc\\");
+
+       }
+       CreateDirectory(DataPath.c_str(), NULL);// TODO: Any harm if they already exist
+
+       return wstring_to_UTF8string(DataPath.c_str());
+}
+
 int CWinFileUtils::GetFileSize(const std::string &strFileName) {
-#ifndef _WIN32_WCE
   struct _stat sStatInfo;
   _stat(strFileName.c_str(), &sStatInfo);
   return sStatInfo.st_size;
-#else
-  // TODO: Fix this on Win CE
-  return 0;
-#endif
 }
 
 // TODO: Check that syntax here is sensible
diff --git a/Src/Win32/Dasher.h b/Src/Win32/Dasher.h
index 484bc84..488c24e 100644
--- a/Src/Win32/Dasher.h
+++ b/Src/Win32/Dasher.h
@@ -23,11 +23,18 @@ class CEdit;
 class CDasherWindow;
 
 namespace Dasher {
-class CWinFileUtils :public CFileUtils{
+class CWinFileUtils :public CFileUtils {
+public:
   virtual int GetFileSize(const std::string &strFileName) override;
   virtual void ScanFiles(AbstractParser *parser, const std::string &strPattern) override;
+  bool WriteUserDataFile(const std::string &filename, const std::string &strNewText, bool append) override;
 private:
-  void ScanDirectory(const Tstring &strMask, std::vector<std::string> &vFileList);
+  void ScanDirectory(const std::string &strMask, std::vector<std::string> &vFileList);
+  // Returns location where program data is stored.
+  // When user is false, result is system data location.
+  // When user is true, result is user data data location.
+  virtual std::string GetDataPath(bool user);
+
 };
 
 class CDasher : public CDashIntfScreenMsgs
@@ -54,7 +61,6 @@ public:
   unsigned int ctrlMove(bool bForwards, CControlManager::EditDistance iDist) override;
   unsigned int ctrlDelete(bool bForwards, CControlManager::EditDistance iDist) override;
     
-  virtual void WriteTrainFile(const std::string &filename, const std::string &strNewText) override;
   void Main(); 
 
   virtual std::string GetAllContext() override;
diff --git a/Src/Win32/DasherControl_vc2013.vcxproj b/Src/Win32/DasherControl_vc2013.vcxproj
index 984652a..fa77dc2 100644
--- a/Src/Win32/DasherControl_vc2013.vcxproj
+++ b/Src/Win32/DasherControl_vc2013.vcxproj
@@ -186,7 +186,6 @@
     <ClCompile Include="BTSocketInput.cpp" />
     <ClCompile Include="Common\WinHelper.cpp" />
     <ClCompile Include="Common\WinLocalisation.cpp" />
-    <ClCompile Include="Common\WinOptions.cpp" />
     <ClCompile Include="Common\WinUTF8.cpp" />
     <ClCompile Include="Dasher.cpp" />
     <ClCompile Include="DasherMouseInput.cpp" />
@@ -201,7 +200,6 @@
     <ClInclude Include="BTSocketInput.h" />
     <ClInclude Include="Common\WinCommon.h" />
     <ClInclude Include="Common\WinLocalisation.h" />
-    <ClInclude Include="Common\WinOptions.h" />
     <ClInclude Include="Common\WinUTF8.h" />
     <ClInclude Include="Dasher.h" />
     <ClInclude Include="DasherMouseInput.h" />
diff --git a/Src/Win32/DasherWindow.cpp b/Src/Win32/DasherWindow.cpp
index 4fe043d..c12236b 100644
--- a/Src/Win32/DasherWindow.cpp
+++ b/Src/Win32/DasherWindow.cpp
@@ -25,7 +25,6 @@
 
 #include "Widgets/Toolbar.h"
 #include "WinCommon.h"
-#include "WinOptions.h"
 #include "../DasherCore/XmlSettingsStore.h"
 #include <windows.h>
 #include "resource.h"
@@ -53,7 +52,7 @@ public:
 // text services framework stuff, which were never really finished. If
 // required, look in version control history (prior to May 2007).
 
-CDasherWindow::CDasherWindow(const CString& xml_config_file) : xml_config_file_(xml_config_file) {
+CDasherWindow::CDasherWindow(const wstring& configName) : m_configName(configName){
   m_bFullyCreated = false;
   m_pAppSettings = 0;
   m_pToolbar = 0;
@@ -80,20 +79,15 @@ HWND CDasherWindow::Create() {
   Tstring WindowTitle;
   WinLocalisation::GetResourceString(IDS_APP_TITLE, &WindowTitle);
 
+  string configFileName = "settings.xml";
+  if (!m_configName.empty())
+    configFileName = "settings." + WinUTF8::wstring_to_UTF8string(m_configName.c_str()) + ".xml";
   static XmlErrorDisplay display;
-  CFileUtils* fileUtils = new CWinFileUtils();
-  Dasher::CSettingsStore* settings;
-  if (xml_config_file_.IsEmpty()) {
-      settings = new CWinOptions("Inference Group", "Dasher3");
-  }
-  else {
-      std::string utf8_path = WinUTF8::narrow(xml_config_file_);
-      auto xml_settings = new Dasher::XmlSettingsStore(utf8_path, &display);
-      xml_settings->Load();
-      // Save the defaults if needed.
-      xml_settings->Save();
-      settings = xml_settings;
-  }
+  static CWinFileUtils fileUtils;
+  auto settings = new Dasher::XmlSettingsStore(configFileName, &fileUtils, &display);
+  settings->Load();
+  // Save the defaults if needed.
+  settings->Save();
 
   m_pAppSettings = new CAppSettings(0, 0, settings);  // Takes ownership of the settings store.
   int iStyle(m_pAppSettings->GetLongParameter(APP_LP_STYLE));
@@ -114,7 +108,7 @@ HWND CDasherWindow::Create() {
   m_pEdit->Create(hWnd, m_pAppSettings->GetBoolParameter(APP_BP_TIME_STAMP));
   m_pEdit->SetFont(m_pAppSettings->GetStringParameter(APP_SP_EDIT_FONT), 
m_pAppSettings->GetLongParameter(APP_LP_EDIT_FONT_SIZE));
 
-  m_pDasher = new CDasher(hWnd, this, m_pEdit, settings, fileUtils); // Takes ownership of the fileUtils
+  m_pDasher = new CDasher(hWnd, this, m_pEdit, settings, &fileUtils);
 
   // Create a CAppSettings
   m_pAppSettings->SetHwnd(hWnd);
diff --git a/Src/Win32/DasherWindow.h b/Src/Win32/DasherWindow.h
index dc77c19..99c7b65 100644
--- a/Src/Win32/DasherWindow.h
+++ b/Src/Win32/DasherWindow.h
@@ -25,7 +25,7 @@ class CDasherWindow :
        public CSplitterOwner 
 {
 public:
-  CDasherWindow(const CString& xml_config_file);
+  CDasherWindow(const wstring& configName);
        ~CDasherWindow();
 
        DECLARE_WND_CLASS(_T("DASHER"))
@@ -90,7 +90,7 @@ private:
        HICON m_hIconSm;
 
        HMENU m_hMenu;
-  CString xml_config_file_;
+  std::wstring m_configName;
   std::unique_ptr<Dasher::CSettingsStore> setting_store_;
        // Misc window handling
        void Layout();
diff --git a/Src/Win32/WinMain.cpp b/Src/Win32/WinMain.cpp
index a7b9b21..0e024d8 100644
--- a/Src/Win32/WinMain.cpp
+++ b/Src/Win32/WinMain.cpp
@@ -19,7 +19,6 @@
 using namespace Dasher;
 class CDasherApp : public CAtlExeModuleT< CDasherApp >
 {
-  CDasherWindow *m_pDasherWindow;
 public:
   /*
   Entry point to program on Windows systems
@@ -29,7 +28,7 @@ public:
   Control is passed to the main GUI loop, and only returns when the main window closes.
   */
   HRESULT Run(int nShowCmd){
-    m_pDasherWindow = new CDasherWindow(xml_config_file_);
+    m_pDasherWindow = new CDasherWindow(m_configName);
 
     m_pDasherWindow->Create();
     m_pDasherWindow->Show(nShowCmd);
@@ -53,7 +52,7 @@ public:
          auto argv = CommandLineToArgvW(lpCmdLine, &argc);
          for (int i = 0; i < argc; ++i) {
                    if (wcsicmp(argv[i], L"/config") == 0 && i + 1 < argc) {
-            xml_config_file_ = argv[i + 1];
+            m_configName = argv[i + 1];
                    }
          }
          LocalFree(argv);
@@ -61,7 +60,10 @@ public:
   }
 
   static VOID CALLBACK HandleWinEvent(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, 
LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime);
-  CString xml_config_file_;
+private:
+  wstring m_configName;
+  CDasherWindow *m_pDasherWindow;
+
 } DasherApp;
 
 
diff --git a/configure.ac b/configure.ac
index edb7fc7..4497ab0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -405,8 +405,6 @@ AC_SUBST(hildon_CFLAGS)
 
 AC_SUBST(GETTEXT_PACKAGE)
 
-AM_CONDITIONAL(USE_GCONF, test x$have_gconf = xtrue)
-AM_CONDITIONAL(USE_GSETTINGS, test x$have_gsettings = xtrue)
 AM_CONDITIONAL(DOGTK, test x$BUILDGTK = xtrue)
 AM_CONDITIONAL(DOQTE, test x$WITHQTE = xtrue)
 AM_CONDITIONAL(USE_SPEECHDISPATCHER, test $speech_module = speechdispatcher)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]