[dasher: 39/217] Cleanup of unused file encoding option.



commit 4a1d29bb2d7efa2987aa90852d2c25f87db04d6f
Author: ipomoena <amajorek google com>
Date:   Fri Sep 18 16:42:09 2015 -0700

    Cleanup of unused file encoding option.
    
    Interestingly m_Encoding was uninitialized and code for sawing in
    various formats there. So in rare occasion, file could be written in
    UTF16BE or UTF16LE instead of default platform encoding

 Src/Common/AppSettingsData.h           |    1 -
 Src/Common/AppSettingsHeader.h         |    2 +-
 Src/Common/IOstreamDasherEdit.cc       |    3 -
 Src/Common/IOstreamDasherEdit.h        |    1 -
 Src/DasherCore/Alphabet/AlphInfo.h     |    1 -
 Src/DasherCore/DasherInterfaceBase.cpp |    2 +-
 Src/DasherCore/DasherTypes.h           |    3 +-
 Src/Gtk2/Preferences.cpp               |    4 +-
 Src/Gtk2/dasher_editor.cpp             |   40 +---------------
 Src/Qt/QtDasherPlugin.h                |    2 -
 Src/Win32/EditWrapper.cpp              |   19 -------
 Src/Win32/EditWrapper.h                |   43 -----------------
 Src/Win32/Widgets/Edit.cpp             |   81 ++------------------------------
 Src/Win32/Widgets/Edit.h               |    2 -
 14 files changed, 10 insertions(+), 194 deletions(-)
---
diff --git a/Src/Common/AppSettingsData.h b/Src/Common/AppSettingsData.h
index 913566e..a87777d 100644
--- a/Src/Common/AppSettingsData.h
+++ b/Src/Common/AppSettingsData.h
@@ -66,7 +66,6 @@ app_bp_table app_boolparamtable[] = {
 };
 
 app_lp_table app_longparamtable[] = {
-  {APP_LP_FILE_ENCODING, "FileEncodingFormat", PERS, -2, -2, "FileEncodingFormat"},
   {APP_LP_EDIT_FONT_SIZE, "EditFontSize", PERS, 0, 0, "EditFontSize"},
   {APP_LP_EDIT_HEIGHT, "EditHeight", PERS, 75, 75, "The height of the edit window"},
   {APP_LP_EDIT_WIDTH, "EditWidth", PERS, 200, 200, "EditWidth"},
diff --git a/Src/Common/AppSettingsHeader.h b/Src/Common/AppSettingsHeader.h
index 516500e..2787f1b 100644
--- a/Src/Common/AppSettingsHeader.h
+++ b/Src/Common/AppSettingsHeader.h
@@ -14,7 +14,7 @@ enum {
 };
 
 enum { 
-  APP_LP_FILE_ENCODING = END_OF_APP_BPS, APP_LP_EDIT_FONT_SIZE, APP_LP_EDIT_HEIGHT,
+  APP_LP_EDIT_FONT_SIZE = END_OF_APP_BPS, APP_LP_EDIT_HEIGHT,
   APP_LP_EDIT_WIDTH, 
   APP_LP_SCREEN_WIDTH, APP_LP_SCREEN_HEIGHT, APP_LP_SCREEN_WIDTH_H, APP_LP_SCREEN_HEIGHT_H, 
   APP_LP_STYLE, APP_LP_X, APP_LP_Y,
diff --git a/Src/Common/IOstreamDasherEdit.cc b/Src/Common/IOstreamDasherEdit.cc
index 54bb192..3f5b71e 100644
--- a/Src/Common/IOstreamDasherEdit.cc
+++ b/Src/Common/IOstreamDasherEdit.cc
@@ -119,9 +119,6 @@ void IOstreamDasherEdit::TimeStampNewFiles(bool Value) {
 void IOstreamDasherEdit::deletetext() {
 }
 
-void IOstreamDasherEdit::SetEncoding(Opts::FileEncodingFormats Encoding) {
-}
-
 void IOstreamDasherEdit::SetFont(std::string Name, long Size) {
 }
 
diff --git a/Src/Common/IOstreamDasherEdit.h b/Src/Common/IOstreamDasherEdit.h
index 0bc5dcd..2d6ec83 100644
--- a/Src/Common/IOstreamDasherEdit.h
+++ b/Src/Common/IOstreamDasherEdit.h
@@ -33,7 +33,6 @@ public:
   void deletetext();
   void Clear();
 
-  void SetEncoding(Opts::FileEncodingFormats Encoding);
   void SetFont(std::string Name, long Size);
   bool SaveAs(const std::string filename, bool a);
   bool Save(bool a = false);
diff --git a/Src/DasherCore/Alphabet/AlphInfo.h b/Src/DasherCore/Alphabet/AlphInfo.h
index 16c1e6d..d971912 100644
--- a/Src/DasherCore/Alphabet/AlphInfo.h
+++ b/Src/DasherCore/Alphabet/AlphInfo.h
@@ -137,7 +137,6 @@ private:
   std::string TrainingFile;
   std::string GameModeFile;
   std::string PreferredColours;
-  Opts::AlphabetTypes Encoding;
   Opts::AlphabetTypes Type;
   Opts::ScreenOrientations Orientation;
 
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index 4bc4e45..d6fdea6 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -612,7 +612,7 @@ void CDasherInterfaceBase::ChangeAlphabet() {
 
 Opts::ScreenOrientations CDasherInterfaceBase::ComputeOrientation() {
   Opts::ScreenOrientations pref(Opts::ScreenOrientations(GetLongParameter(LP_ORIENTATION)));
-  if (pref!=Opts::Alphabet) return pref;
+  if (pref!=Opts::AlphabetDefault) return pref;
   if (m_pNCManager) return m_pNCManager->GetAlphabet()->GetOrientation();
   //haven't created the NCManager yet, so not yet reached Realize, but must
   // have been given Screen (to make View). Use default LR for now, as when
diff --git a/Src/DasherCore/DasherTypes.h b/Src/DasherCore/DasherTypes.h
index cbb66b1..93aba72 100644
--- a/Src/DasherCore/DasherTypes.h
+++ b/Src/DasherCore/DasherTypes.h
@@ -69,9 +69,8 @@ namespace Dasher {
   namespace Opts {
     // Numbers should be applied to elements of the following two enumerations as these preferences may be 
stored to file. Constancy between
     // versions is a good idea. It should *not* be assumed that the numbers map onto anything useful. 
Different codepages may be appropriate on different systems for different character sets.
-    enum FileEncodingFormats { UserDefault = -1, AlphabetDefault = -2, UTF8 = 65001, UTF16LE = 1200, UTF16BE 
= 1201 };
     enum AlphabetTypes { MyNone = 0, Arabic = 1256, Baltic = 1257, CentralEurope = 1250, ChineseSimplified = 
936, ChineseTraditional = 950, Cyrillic = 1251, Greek = 1253, Hebrew = 1255, Japanese = 932, Korean = 949, 
Thai = 874, Turkish = 1254, VietNam = 1258, Western = 1252 };
-    enum ScreenOrientations { Alphabet = -2, LeftToRight = 0, RightToLeft = 1, TopToBottom = 2, BottomToTop 
= 3 };
+    enum ScreenOrientations { AlphabetDefault = -2, LeftToRight = 0, RightToLeft = 1, TopToBottom = 2, 
BottomToTop = 3 };
     enum FontSize { Normal = 1, Big = 2, VBig = 4 };
   }
   struct ControlTree {
diff --git a/Src/Gtk2/Preferences.cpp b/Src/Gtk2/Preferences.cpp
index 165ee2c..f905a75 100644
--- a/Src/Gtk2/Preferences.cpp
+++ b/Src/Gtk2/Preferences.cpp
@@ -536,7 +536,7 @@ static void dasher_preferences_dialogue_populate_special_orientation(DasherPrefe
   pPrivate->pBTButton = GTK_TOGGLE_BUTTON(gtk_builder_get_object(pPrivate->pXML, "radiobutton5"));
   GtkToggleButton *pButton;
   switch (dasher_app_settings_get_long(pPrivate->pAppSettings, LP_ORIENTATION)) {
-  case Dasher::Opts::Alphabet:
+  case Dasher::Opts::AlphabetDefault:
     pButton = pPrivate->pAlphOrient; break;
 
   case Dasher::Opts::LeftToRight:
@@ -710,7 +710,7 @@ extern "C" void orientation(GtkRadioButton *widget, gpointer user_data) {
   GtkToggleButton *pButton = GTK_TOGGLE_BUTTON(widget);
   Dasher::Opts::ScreenOrientations orient;
   if (pButton == pPrivate->pAlphOrient) {
-    orient = Dasher::Opts::Alphabet;
+    orient = Dasher::Opts::AlphabetDefault;
   } else if (pButton == pPrivate->pLRButton) {
     orient = Dasher::Opts::LeftToRight;
   } else if (pButton == pPrivate->pRLButton) {
diff --git a/Src/Gtk2/dasher_editor.cpp b/Src/Gtk2/dasher_editor.cpp
index 13ce830..9480bd1 100644
--- a/Src/Gtk2/dasher_editor.cpp
+++ b/Src/Gtk2/dasher_editor.cpp
@@ -602,45 +602,7 @@ dasher_editor_internal_save_as(DasherEditor *pSelf, const gchar *szFilename, boo
   outbuffer[length] = 0;
   g_free(inbuffer);
   inbuffer = outbuffer;
-  outbuffer = NULL;
-
-//   switch (fileencoding) {
-//   case Dasher::Opts::UserDefault:
-//   case Dasher::Opts::AlphabetDefault:
-//     //FIXME - need to call GetAlphabetType and do appropriate stuff regarding
-//     //the character set. Arguably we should always be saving in either UTF-8 or
-//     //the user's locale (which may, of course, be UTF-8) because otherwise
-//     //we're going to read in rubbish, and we shouldn't be encouraging weird
-//     //codepage madness any further
-
-//     //FIXME - error handling
-//     outbuffer = g_locale_from_utf8(inbuffer, -1, &bytes_read, &bytes_written, &error);
-//     if(outbuffer == NULL) {
-//       // We can't represent the text in the current locale, so fall back to
-//       // UTF-8
-//       outbuffer = inbuffer;
-//       bytes_written = length;
-//     }
-//   case Dasher::Opts::UTF8:
-//     outbuffer = inbuffer;
-//     bytes_written = length;
-//     break;
-//     // Does /anyone/ want to save text files in UTF16?
-//     // (in any case, my opinions regarding encouragement of data formats with
-//     // endianness damage are almost certainly unprintable)
-
-//   case Dasher::Opts::UTF16LE:
-//     cd = g_iconv_open("UTF16LE", "UTF8");
-//     outbuffer = g_convert_with_iconv(inbuffer, -1, cd, &bytes_read, &bytes_written, &error);
-//     break;
-//   case Dasher::Opts::UTF16BE:
-//     cd = g_iconv_open("UTF16BE", "UTF8");
-//     outbuffer = g_convert_with_iconv(inbuffer, -1, cd, &bytes_read, &bytes_written, &error);
-//     break;
-//   default:
-    outbuffer = inbuffer;
-    bytes_written = length;
-    //  }
+  bytes_written = length;
 
 #ifdef HAVE_GIO
   if(!dasher_editor_internal_gvfs_save_file(pSelf, szFilename, outbuffer, bytes_written, bAppend)) {
diff --git a/Src/Qt/QtDasherPlugin.h b/Src/Qt/QtDasherPlugin.h
index 2ef18b1..72c998a 100644
--- a/Src/Qt/QtDasherPlugin.h
+++ b/Src/Qt/QtDasherPlugin.h
@@ -27,8 +27,6 @@ Q_OBJECT public:
   void flush(int);
   void Clear() {
   };
-  void SetEncoding(Dasher::Opts::FileEncodingFormats) {
-  };
   void SetFont(std::string Name, long Size) {
   };
 
diff --git a/Src/Win32/Widgets/Edit.cpp b/Src/Win32/Widgets/Edit.cpp
index d3dde9d..df36669 100644
--- a/Src/Win32/Widgets/Edit.cpp
+++ b/Src/Win32/Widgets/Edit.cpp
@@ -94,80 +94,11 @@ bool CEdit::Save() {
   SetFilePointer(FileHandle, NULL, NULL, FILE_BEGIN);
   SetEndOfFile(FileHandle);
 
-  // Get all the text from the edit control
-  LRESULT EditLength = 1 + SendMessage( WM_GETTEXTLENGTH, 0, 0);
-  TCHAR *EditText = new TCHAR[EditLength];
-  EditLength = SendMessage( WM_GETTEXT, (WPARAM) EditLength, (LPARAM) EditText);
-
+  CString wideText;
+  GetWindowText(wideText);
+  CStringA mbcsText(wideText);
   DWORD NumberOfBytesWritten;   // Used by WriteFile
-
-  // This is Windows therefore we tag Unicode files with BOMs (Byte Order Marks) {{{
-  // Then notepad and other Windows apps can recognise the files.
-  // Do NOT write BOMs in a UNIX version, they are not welcome there.
-  // The BOM is just an encoding of U+FEFF (ZERO WIDTH NO-BREAK SPACE)
-  // This is unambiguous as U+FFFE is not a valid Unicode character.
-  // There could be a menu option for this, but most users won't know what a BOM is. }}}
-  unsigned int WideLength = 0;
-  wchar_t *WideText = 0;
-  if((m_Encoding == Opts::UTF16LE) || (m_Encoding == Opts::UTF16BE)) {
-    // These are the UTF-16 formats. If the string isn't already in UTF-16 we need
-    // it to be so.
-#ifdef _UNICODE
-    WideLength = EditLength;
-    WideText = EditText;
-#else
-    WideText = new wchar_t[EditLength + 1];
-    WideLength = MultiByteToWideChar(CodePage, 0, EditText, -1, WideText, EditLength + 1);
-#endif
-  }
-  switch (m_Encoding) {
-  case Opts::UTF8:{            // there is no byte order, but BOM tags it as a UTF-8 file
-      unsigned char BOM[3] = { 0xEF, 0xBB, 0xBF };
-      WriteFile(FileHandle, &BOM, 3, &NumberOfBytesWritten, NULL);
-      Tstring Tmp = EditText;
-      string Output;
-      wstring_to_UTF8string(EditText, Output);
-      WriteFile(FileHandle, Output.c_str(), Output.size(), &NumberOfBytesWritten, NULL);
-      break;
-    }
-  case Opts::UTF16LE:{
-      // TODO I am assuming this machine is LE. Do any windows (perhaps CE) machines run on BE?
-      unsigned char BOM[2] = { 0xFF, 0xFE };
-      WriteFile(FileHandle, &BOM, 2, &NumberOfBytesWritten, NULL);
-      WriteFile(FileHandle, WideText, WideLength * 2, &NumberOfBytesWritten, NULL);
-#ifndef _UNICODE
-      delete[]WideText;
-#endif
-      break;
-    }
-  case Opts::UTF16BE:{         // UTF-16BE
-      // TODO I am again assuming this machine is LE.
-      unsigned char BOM[2] = { 0xFE, 0xFF };
-      WriteFile(FileHandle, &BOM, 2, &NumberOfBytesWritten, NULL);
-      // There will be a better way. Perhaps use _swab instead.
-      for(unsigned int i = 0; i < WideLength; i++) {
-        const char *Hack = (char *)&WideText[i];
-        WriteFile(FileHandle, Hack + 1, 1, &NumberOfBytesWritten, NULL);
-        WriteFile(FileHandle, Hack, 1, &NumberOfBytesWritten, NULL);
-      }
-#ifndef _UNICODE
-      delete[]WideText;
-#endif
-      break;
-    }
-  default:
-#ifdef _UNICODE
-    char *MultiByteText = new char[EditLength * 4];
-    int MultiByteLength = WideCharToMultiByte(CodePage, 0, EditText, EditLength, MultiByteText, EditLength * 
4, NULL, NULL);
-    WriteFile(FileHandle, MultiByteText, MultiByteLength, &NumberOfBytesWritten, NULL);
-    delete[]MultiByteText;
-#else
-    WriteFile(FileHandle, EditText, EditLength, &NumberOfBytesWritten, NULL);
-#endif
-    break;                      // do nothing
-  }
-
-  delete[]EditText;
+  WriteFile(FileHandle, mbcsText, mbcsText.GetLength(), &NumberOfBytesWritten, NULL);
   // The file handle is not closed here. We keep a write-lock on the file to stop other programs confusing 
us.
 
   m_FilenameGUI->SetDirty(false);
@@ -316,10 +247,6 @@ void CEdit::Clear() {
   SendMessage(WM_SETTEXT, 0, (LPARAM) TEXT(""));
 }
 
-void CEdit::SetEncoding(Dasher::Opts::FileEncodingFormats Encoding) {
-  m_Encoding = Encoding;
-}
-
 void CEdit::SetFont(string Name, long Size) {
 #ifndef _WIN32_WCE
   m_FontName = Name;
diff --git a/Src/Win32/Widgets/Edit.h b/Src/Win32/Widgets/Edit.h
index a097e2c..68d31ce 100644
--- a/Src/Win32/Widgets/Edit.h
+++ b/Src/Win32/Widgets/Edit.h
@@ -102,7 +102,6 @@ class CEdit : public ATL::CWindowImpl<CEdit> {
   void SelectAll();
   void Clear();
   
-  void SetEncoding(Dasher::Opts::FileEncodingFormats Encoding);
   void SetFont(std::string Name, long Size);
   
   void SetInterface(Dasher::CDasherInterfaceBase * DasherInterface);
@@ -146,7 +145,6 @@ class CEdit : public ATL::CWindowImpl<CEdit> {
   
   std::string m_Output;         // UTF-8 to go to training file
   UINT CodePage;                // for font and possible for finding the encoding
-  Dasher::Opts::FileEncodingFormats m_Encoding; // file encoding option (may say to use codepage or user 
setting)
   
   DWORD threadid;
   HWND targetwindow;


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