diff options
Diffstat (limited to 'library')
-rw-r--r-- | library/CustomGrid.cpp | 37 | ||||
-rw-r--r-- | library/globalFunctions.cpp | 4 | ||||
-rw-r--r-- | library/globalFunctions.h | 17 | ||||
-rw-r--r-- | library/misc.cpp | 59 | ||||
-rw-r--r-- | library/multithreading.cpp | 2 | ||||
-rw-r--r-- | library/multithreading.h | 2 | ||||
-rw-r--r-- | library/resources.cpp | 132 | ||||
-rw-r--r-- | library/wxWidgets.h | 5 |
8 files changed, 136 insertions, 122 deletions
diff --git a/library/CustomGrid.cpp b/library/CustomGrid.cpp index 053244f5..93f2107a 100644 --- a/library/CustomGrid.cpp +++ b/library/CustomGrid.cpp @@ -53,29 +53,29 @@ public: if (selectedForSynchronization) switch (result) { - case fileOnLeftSideOnly: - return "<|"; + case FILE_LEFT_SIDE_ONLY: + return wxT("<|"); break; - case fileOnRightSideOnly: - return "|>"; + case FILE_RIGHT_SIDE_ONLY: + return wxT("|>"); break; - case rightFileNewer: - return ">>"; + case FILE_RIGHT_NEWER: + return wxT(">>"); break; - case leftFileNewer: - return "<<"; + case FILE_LEFT_NEWER: + return wxT("<<"); break; - case filesDifferent: - return "!="; + case FILE_DIFFERENT: + return wxT("!="); break; - case filesEqual: - return "=="; + case FILE_EQUAL: + return wxT("=="); break; default: assert (false); return wxEmptyString; } - else return "(-)"; + else return wxT("(-)"); } @@ -93,7 +93,7 @@ public: case 1: if (col < 4) { - if (gridLine.fileDescrLeft.objType == isDirectory) + if (gridLine.fileDescrLeft.objType == TYPE_DIRECTORY) { switch (col) { @@ -107,7 +107,7 @@ public: return gridLine.fileDescrLeft.lastWriteTime; } } - else if (gridLine.fileDescrLeft.objType == isFile) + else if (gridLine.fileDescrLeft.objType == TYPE_FILE) { switch (col) { @@ -127,7 +127,7 @@ public: case 2: if (col < 4) { - if (gridLine.fileDescrRight.objType == isDirectory) + if (gridLine.fileDescrRight.objType == TYPE_DIRECTORY) { switch (col) { @@ -141,7 +141,7 @@ public: return gridLine.fileDescrRight.lastWriteTime; } } - else if (gridLine.fileDescrRight.objType == isFile) + else if (gridLine.fileDescrRight.objType == TYPE_FILE) { switch (col) { @@ -426,8 +426,7 @@ void CustomGrid::setScrollFriends(CustomGrid* grid1, CustomGrid* grid2, CustomGr void CustomGrid::setGridDataTable(GridView* gridRefUI, FileCompareResult* gridData) -{ - //set underlying grid data +{ //set underlying grid data assert(gridDataTable); gridDataTable->setGridDataTable(gridRefUI, gridData); } diff --git a/library/globalFunctions.cpp b/library/globalFunctions.cpp index d91fa8b1..5afb1650 100644 --- a/library/globalFunctions.cpp +++ b/library/globalFunctions.cpp @@ -71,7 +71,7 @@ int globalFunctions::wxStringToInt(const wxString& number) if (number.ToLong(&result)) return result; else - throw std::runtime_error("Error when converting number to long"); + throw RuntimeException(_("Error when converting wxString to long")); } @@ -82,7 +82,7 @@ double globalFunctions::wxStringToDouble(const wxString& number) if (number.ToDouble(&result)) return result; else - throw std::runtime_error("Error when converting number to double"); + throw RuntimeException(_("Error when converting wxString to double")); } diff --git a/library/globalFunctions.h b/library/globalFunctions.h index d9c0d69f..55e37c61 100644 --- a/library/globalFunctions.h +++ b/library/globalFunctions.h @@ -4,7 +4,6 @@ #include <string> #include <algorithm> #include <wx/string.h> -#include <stdexcept> //for std::runtime_error using namespace std; @@ -34,4 +33,20 @@ namespace globalFunctions wxString& includeNumberSeparator(wxString& number); } + + +class RuntimeException //Exception class used to notify of general runtime exceptions +{ +public: + RuntimeException(const wxString& txt) : errorMessage(txt) {} + + wxString show() const + { + return errorMessage; + } + +private: + wxString errorMessage; +}; + #endif // GLOBALFUNCTIONS_H_INCLUDED diff --git a/library/misc.cpp b/library/misc.cpp index 2a5c0ec2..44dcaf0e 100644 --- a/library/misc.cpp +++ b/library/misc.cpp @@ -3,15 +3,13 @@ #include <wx/msgdlg.h> #include "resources.h" -wxString exchangeEscapeChars(char* temp) +void exchangeEscapeChars(wxString& data) { - wxString output(temp); - output.Replace("\\\\", "\\"); - output.Replace("\\n", "\n"); - output.Replace("\\t", "\t"); - output.Replace("\"\"", """"); - output.Replace("\\\"", "\""); - return output; + data.Replace(wxT("\\\\"), wxT("\\")); + data.Replace(wxT("\\n"), wxT("\n")); + data.Replace(wxT("\\t"), wxT("\t")); + data.Replace(wxT("\"\""), wxT("""")); + data.Replace(wxT("\\\""), wxT("\"")); } @@ -25,13 +23,13 @@ CustomLocale::~CustomLocale() { //write language to file ofstream output("lang.dat"); - if (!output) + if (output) { - wxMessageBox(wxString(_("Could not write to ")) + "\"" + "lang.dat" + "\"", _("An exception occured!"), wxOK | wxICON_ERROR); - return; + output<<currentLanguage<<char(0); + output.close(); } - output<<currentLanguage<<char(0); - output.close(); + else + wxMessageBox(wxString(_("Could not write to ")) + wxT("\"") + wxT("lang.dat") + wxT("\""), _("An exception occured!"), wxOK | wxICON_ERROR); } @@ -61,7 +59,7 @@ void CustomLocale::loadLanguageFile(int language) { currentLanguage = language; - wxString languageFile; + string languageFile; switch (language) { case wxLANGUAGE_GERMAN: @@ -69,16 +67,17 @@ void CustomLocale::loadLanguageFile(int language) break; default: - languageFile = ""; + languageFile = string(); currentLanguage = wxLANGUAGE_ENGLISH; } //load language file into buffer translationDB.clear(); - char temp[100000]; - if (!languageFile.IsEmpty()) + const int bufferSize = 100000; + char temp[bufferSize]; + if (!languageFile.empty()) { - ifstream langFile(languageFile.c_str()); + ifstream langFile(languageFile.c_str(), ios::binary); if (langFile) { int rowNumber = 0; @@ -89,22 +88,20 @@ void CustomLocale::loadLanguageFile(int language) //Linux: 0xa //Mac: 0xd //Win: 0xd 0xa -#ifdef FFS_WIN - while (langFile.getline(temp, 100000)) - { -#elif defined FFS_LINUX - while (langFile.getline(temp, 100000, 0xd)) //specify delimiter explicitely + while (langFile.getline(temp, bufferSize, 0xd)) //specify delimiter explicitely { - //strangely this approach does NOT work under windows :( - langFile.get(); //delimiter 0xd is completely ignored (and also not extracted) -#else - assert (false); -#endif + langFile.get(); //discard the 0xa character + + //wxString formattedString(temp, *wxConvUTF8, bufferSize); //convert UTF8 input to Unicode + wxString formattedString(temp); + + exchangeEscapeChars(formattedString); + if (rowNumber%2 == 0) - currentLine.original = exchangeEscapeChars(temp); + currentLine.original = formattedString; else { - currentLine.translation = exchangeEscapeChars(temp); + currentLine.translation = formattedString; translationDB.insert(currentLine); } ++rowNumber; @@ -112,7 +109,7 @@ void CustomLocale::loadLanguageFile(int language) langFile.close(); } else - wxMessageBox(wxString(_("Could not read language file ")) + "\"" + languageFile + "\"", _("An exception occured!"), wxOK | wxICON_ERROR); + wxMessageBox(wxString(_("Could not read language file ")) + wxT("\"") + wxString(languageFile.c_str(), wxConvUTF8) + wxT("\""), _("An exception occured!"), wxOK | wxICON_ERROR); } else ; //if languageFile is empty language is defaulted to english diff --git a/library/multithreading.cpp b/library/multithreading.cpp index 099836de..bb598194 100644 --- a/library/multithreading.cpp +++ b/library/multithreading.cpp @@ -144,7 +144,7 @@ void UpdateWhileExecuting::execute(StatusUpdater* statusUpdater) theWorkerThread->beginProcessing.Signal(); theWorkerThread->readyToBeginProcessing.Unlock(); - while (receivingResult.WaitTimeout(uiUpdateInterval) == wxCOND_TIMEOUT) + while (receivingResult.WaitTimeout(UI_UPDATE_INTERVAL) == wxCOND_TIMEOUT) statusUpdater->triggerUI_Refresh(); //ATTENTION: Exception "AbortThisProcess" may be thrown here!!! } diff --git a/library/multithreading.h b/library/multithreading.h index 36b37f2a..56cff890 100644 --- a/library/multithreading.h +++ b/library/multithreading.h @@ -35,7 +35,7 @@ protected: }; -const int uiUpdateInterval = 100; //perform ui updates not more often than necessary, 100 seems to be a good value with only a minimal performance loss +const int UI_UPDATE_INTERVAL = 100; //perform ui updates not more often than necessary, 100 seems to be a good value with only a minimal performance loss class WorkerThread; diff --git a/library/resources.cpp b/library/resources.cpp index 73e11575..6e5feaf7 100644 --- a/library/resources.cpp +++ b/library/resources.cpp @@ -3,7 +3,7 @@ #include <wx/zipstrm.h> #include <wx/image.h> #include <wx/icon.h> -#include <stdexcept> //for std::runtime_error +#include "globalFunctions.h" #ifdef FFS_WIN wxChar GlobalResources::fileNameSeparator = '\\'; @@ -14,21 +14,21 @@ assert(false); #endif //these two global variables are language-dependent => cannot be set statically! See CustomLocale -const wxChar* GlobalResources::decimalPoint = ""; -const wxChar* GlobalResources::thousandsSeparator = ""; +const wxChar* GlobalResources::decimalPoint = wxEmptyString; +const wxChar* GlobalResources::thousandsSeparator = wxEmptyString; //command line parameters -const wxChar* GlobalResources::paramCompare = "cmp"; -const wxChar* GlobalResources::paramCfg = "cfg"; -const wxChar* GlobalResources::paramInclude = "incl"; -const wxChar* GlobalResources::paramExclude = "excl"; -const wxChar* GlobalResources::paramContinueError = "continue"; -const wxChar* GlobalResources::paramRecycler = "recycler"; -const wxChar* GlobalResources::paramSilent = "silent"; +const wxChar* GlobalResources::paramCompare = wxT("cmp"); +const wxChar* GlobalResources::paramCfg = wxT("cfg"); +const wxChar* GlobalResources::paramInclude = wxT("incl"); +const wxChar* GlobalResources::paramExclude = wxT("excl"); +const wxChar* GlobalResources::paramContinueError = wxT("continue"); +const wxChar* GlobalResources::paramRecycler = wxT("recycler"); +const wxChar* GlobalResources::paramSilent = wxT("silent"); -const wxChar* GlobalResources::valueSizeDate = "SIZEDATE"; -const wxChar* GlobalResources::valueContent = "CONTENT"; +const wxChar* GlobalResources::valueSizeDate = wxT("SIZEDATE"); +const wxChar* GlobalResources::valueContent = wxT("CONTENT"); map<wxString, wxBitmap*> GlobalResources::bitmapResource; @@ -90,57 +90,57 @@ wxIcon* GlobalResources::programIcon = 0; void GlobalResources::loadResourceFiles() { //map, allocate and initialize pictures - bitmapResource["left arrow.png"] = (bitmapLeftArrow = new wxBitmap(wxNullBitmap)); - bitmapResource["right arrow.png"] = (bitmapRightArrow = new wxBitmap(wxNullBitmap)); - bitmapResource["no arrow.png"] = (bitmapNoArrow = new wxBitmap(wxNullBitmap)); - bitmapResource["start sync.png"] = (bitmapStartSync = new wxBitmap(wxNullBitmap)); - bitmapResource["start sync dis.png"] = (bitmapStartSyncDis = new wxBitmap(wxNullBitmap)); - bitmapResource["delete.png"] = (bitmapDelete = new wxBitmap(wxNullBitmap)); - bitmapResource["email.png"] = (bitmapEmail = new wxBitmap(wxNullBitmap)); - bitmapResource["about.png"] = (bitmapAbout = new wxBitmap(wxNullBitmap)); - bitmapResource["website.png"] = (bitmapWebsite = new wxBitmap(wxNullBitmap)); - bitmapResource["exit.png"] = (bitmapExit = new wxBitmap(wxNullBitmap)); - bitmapResource["sync.png"] = (bitmapSync = new wxBitmap(wxNullBitmap)); - bitmapResource["compare.png"] = (bitmapCompare = new wxBitmap(wxNullBitmap)); - bitmapResource["sync disabled.png"] = (bitmapSyncDisabled = new wxBitmap(wxNullBitmap)); - bitmapResource["swap.png"] = (bitmapSwap = new wxBitmap(wxNullBitmap)); - bitmapResource["help.png"] = (bitmapHelp = new wxBitmap(wxNullBitmap)); - bitmapResource["leftOnly.png"] = (bitmapLeftOnly = new wxBitmap(wxNullBitmap)); - bitmapResource["leftNewer.png"] = (bitmapLeftNewer = new wxBitmap(wxNullBitmap)); - bitmapResource["different.png"] = (bitmapDifferent = new wxBitmap(wxNullBitmap)); - bitmapResource["rightNewer.png"] = (bitmapRightNewer = new wxBitmap(wxNullBitmap)); - bitmapResource["rightOnly.png"] = (bitmapRightOnly = new wxBitmap(wxNullBitmap)); - bitmapResource["leftOnlyDeact.png"] = (bitmapLeftOnlyDeact = new wxBitmap(wxNullBitmap)); - bitmapResource["leftNewerDeact.png"] = (bitmapLeftNewerDeact = new wxBitmap(wxNullBitmap)); - bitmapResource["differentDeact.png"] = (bitmapDifferentDeact = new wxBitmap(wxNullBitmap)); - bitmapResource["rightNewerDeact.png"] = (bitmapRightNewerDeact = new wxBitmap(wxNullBitmap)); - bitmapResource["rightOnlyDeact.png"] = (bitmapRightOnlyDeact = new wxBitmap(wxNullBitmap)); - bitmapResource["equal.png"] = (bitmapEqual = new wxBitmap(wxNullBitmap)); - bitmapResource["equalDeact.png"] = (bitmapEqualDeact = new wxBitmap(wxNullBitmap)); - bitmapResource["include.png"] = (bitmapInclude = new wxBitmap(wxNullBitmap)); - bitmapResource["exclude.png"] = (bitmapExclude = new wxBitmap(wxNullBitmap)); - bitmapResource["filter active.png"] = (bitmapFilterOn = new wxBitmap(wxNullBitmap)); - bitmapResource["filter not active.png"] = (bitmapFilterOff = new wxBitmap(wxNullBitmap)); - bitmapResource["warning.png"] = (bitmapWarning = new wxBitmap(wxNullBitmap)); - bitmapResource["small arrow up.png"] = (bitmapSmallUp = new wxBitmap(wxNullBitmap)); - bitmapResource["small arrow down.png"] = (bitmapSmallDown = new wxBitmap(wxNullBitmap)); - bitmapResource["save.png"] = (bitmapSave = new wxBitmap(wxNullBitmap)); - bitmapResource["FFS.png"] = (bitmapFFS = new wxBitmap(wxNullBitmap)); - bitmapResource["deleteFile.png"] = (bitmapDeleteFile = new wxBitmap(wxNullBitmap)); - bitmapResource["gpl.png"] = (bitmapGPL = new wxBitmap(wxNullBitmap)); - bitmapResource["statusPause.png"] = (bitmapStatusPause = new wxBitmap(wxNullBitmap)); - bitmapResource["statusError.png"] = (bitmapStatusError = new wxBitmap(wxNullBitmap)); - bitmapResource["statusSuccess.png"] = (bitmapStatusSuccess = new wxBitmap(wxNullBitmap)); - bitmapResource["statusWarning.png"] = (bitmapStatusWarning = new wxBitmap(wxNullBitmap)); - bitmapResource["statusScanning.png"] = (bitmapStatusScanning = new wxBitmap(wxNullBitmap)); - bitmapResource["statusComparing.png"] = (bitmapStatusComparing = new wxBitmap(wxNullBitmap)); - bitmapResource["statusSyncing.png"] = (bitmapStatusSyncing = new wxBitmap(wxNullBitmap)); - bitmapResource["logo.png"] = (bitmapLogo = new wxBitmap(wxNullBitmap)); - bitmapResource["finished.png"] = (bitmapFinished = new wxBitmap(wxNullBitmap)); - bitmapResource["statusEdge.png"] = (bitmapStatusEdge = new wxBitmap(wxNullBitmap)); - - wxFileInputStream input("Resources.dat"); - if (!input.IsOk()) throw runtime_error(_("Unable to load Resources.dat!")); + bitmapResource[wxT("left arrow.png")] = (bitmapLeftArrow = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("right arrow.png")] = (bitmapRightArrow = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("no arrow.png")] = (bitmapNoArrow = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("start sync.png")] = (bitmapStartSync = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("start sync dis.png")] = (bitmapStartSyncDis = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("delete.png")] = (bitmapDelete = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("email.png")] = (bitmapEmail = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("about.png")] = (bitmapAbout = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("website.png")] = (bitmapWebsite = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("exit.png")] = (bitmapExit = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("sync.png")] = (bitmapSync = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("compare.png")] = (bitmapCompare = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("sync disabled.png")] = (bitmapSyncDisabled = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("swap.png")] = (bitmapSwap = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("help.png")] = (bitmapHelp = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("leftOnly.png")] = (bitmapLeftOnly = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("leftNewer.png")] = (bitmapLeftNewer = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("different.png")] = (bitmapDifferent = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("rightNewer.png")] = (bitmapRightNewer = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("rightOnly.png")] = (bitmapRightOnly = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("leftOnlyDeact.png")] = (bitmapLeftOnlyDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("leftNewerDeact.png")] = (bitmapLeftNewerDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("differentDeact.png")] = (bitmapDifferentDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("rightNewerDeact.png")] = (bitmapRightNewerDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("rightOnlyDeact.png")] = (bitmapRightOnlyDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("equal.png")] = (bitmapEqual = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("equalDeact.png")] = (bitmapEqualDeact = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("include.png")] = (bitmapInclude = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("exclude.png")] = (bitmapExclude = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("filter active.png")] = (bitmapFilterOn = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("filter not active.png")] = (bitmapFilterOff = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("warning.png")] = (bitmapWarning = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("small arrow up.png"]) = (bitmapSmallUp = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("small arrow down.png")] = (bitmapSmallDown = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("save.png")] = (bitmapSave = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("FFS.png")] = (bitmapFFS = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("deleteFile.png")] = (bitmapDeleteFile = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("gpl.png")] = (bitmapGPL = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusPause.png")] = (bitmapStatusPause = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusError.png")] = (bitmapStatusError = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusSuccess.png")] = (bitmapStatusSuccess = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusWarning.png")] = (bitmapStatusWarning = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusScanning.png")] = (bitmapStatusScanning = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusComparing.png")] = (bitmapStatusComparing = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusSyncing.png")] = (bitmapStatusSyncing = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("logo.png")] = (bitmapLogo = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("finished.png")] = (bitmapFinished = new wxBitmap(wxNullBitmap)); + bitmapResource[wxT("statusEdge.png")] = (bitmapStatusEdge = new wxBitmap(wxNullBitmap)); + + wxFileInputStream input(wxT("Resources.dat")); + if (!input.IsOk()) throw RuntimeException(_("Unable to load Resources.dat!")); wxZipInputStream resourceFile(input); @@ -159,11 +159,11 @@ void GlobalResources::loadResourceFiles() animationMoney = new wxAnimation(wxNullAnimation); animationSync = new wxAnimation(wxNullAnimation); - animationMoney->LoadFile("Resources.a01"); - animationSync->LoadFile("Resources.a02"); + animationMoney->LoadFile(wxT("Resources.a01")); + animationSync->LoadFile(wxT("Resources.a02")); #ifdef FFS_WIN - programIcon = new wxIcon("winIcon"); + programIcon = new wxIcon(wxT("winIcon")); #else #include "FreeFileSync.xpm" programIcon = new wxIcon(FreeFileSync_xpm); diff --git a/library/wxWidgets.h b/library/wxWidgets.h index dd27498c..a383a6f4 100644 --- a/library/wxWidgets.h +++ b/library/wxWidgets.h @@ -9,8 +9,11 @@ #endif //__BORLANDC__ #ifndef WX_PRECOMP -// Include your minimal set of headers here, or wx.h #include <wx/wx.h> #endif +#ifdef WX_PRECOMP +// put here all your rarely-changing header files +#endif // WX_PRECOMP + #endif // WXWIDGETS_H_INCLUDED |