From ad0ea7798b82cc3a4dfed4c2fce6f2cb1b6805e4 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 16:50:14 +0200 Subject: 1.6 --- Application.cpp | 252 ++++++++++++++++++++++++-------------------------------- 1 file changed, 107 insertions(+), 145 deletions(-) (limited to 'Application.cpp') diff --git a/Application.cpp b/Application.cpp index c53953ff..81c4ac87 100644 --- a/Application.cpp +++ b/Application.cpp @@ -45,7 +45,7 @@ void Application::initialize() throw runtime_error(_("Could not set working directory to directory containing executable file!")); //set program language - programLanguage = new CustomLocale; + programLanguage.loadLanguageFromCfg(); //activate support for .png files wxImage::AddHandler(new wxPNGHandler); @@ -54,9 +54,9 @@ void Application::initialize() GlobalResources::loadResourceFiles(); //test if ffs is to be started on UI with config file passed as commandline parameter - wxString configFileUI = FreeFileSync::FFS_LastConfigFile; - if (argc >= 2 && wxFileExists(argv[1]) && FreeFileSync::isFFS_ConfigFile(argv[1])) - configFileUI = argv[1]; + wxString configFileForUI = FreeFileSync::FFS_LastConfigFile; + if (argc > 1 && wxFileExists(argv[1]) && FreeFileSync::isFFS_ConfigFile(argv[1])) + configFileForUI = argv[1]; //should it start in commandline mode? else if (argc > 1) @@ -71,15 +71,13 @@ void Application::initialize() else return; //wait for the user to close the status window } - else - ; //no parameters passed, continue with UI - - - //show UI dialog - MainDialog* frame = new MainDialog(0L, configFileUI); - frame->SetIcon(wxICON(aaaa)); // To Set App Icon - - frame->Show(); + else //no parameters passed: continue with UI + { + //show UI dialog + MainDialog* frame = new MainDialog(0L, configFileForUI, &programLanguage); + frame->SetIcon(*GlobalResources::programIcon); //set application icon + frame->Show(); + } } @@ -101,7 +99,6 @@ int Application::OnRun() int Application::OnExit() { GlobalResources::unloadResourceFiles(); - delete programLanguage; return 0; } @@ -115,22 +112,18 @@ SyncDirection convertCmdlineCfg(const wxString& cfg, const int i) { case 'L': return syncDirLeft; - break; case 'R': return syncDirRight; - break; case 'N': return syncDirNone; - break; default: assert(false); + return syncDirNone; } - //dummy return value to suppress compiler warning - return syncDirNone; } -void Application::initLog() +void Application::logInit() { wxString tmp = wxDateTime::Now().FormatISOTime(); tmp.Replace(":", ""); @@ -144,19 +137,24 @@ void Application::initLog() logFile<processHasFinished(statusAborted); //enable okay and close events + syncStatusFrame->processHasFinished(SyncStatus::statusAborted); //enable okay and close events else if (failedItems) - syncStatusFrame->processHasFinished(statusCompletedWithErrors); + syncStatusFrame->processHasFinished(SyncStatus::statusCompletedWithErrors); else - syncStatusFrame->processHasFinished(statusCompletedWithSuccess); + syncStatusFrame->processHasFinished(SyncStatus::statusCompletedWithSuccess); } } @@ -473,18 +504,18 @@ void CommandLineStatusUpdater::initNewProcess(int objectsTotal, double dataTotal if (!silentMode) { if (currentProcess == FreeFileSync::scanningFilesProcess) - syncStatusFrame->setCurrentStatus(statusScanning); + syncStatusFrame->setCurrentStatus(SyncStatus::statusScanning); else if (currentProcess == FreeFileSync::compareFileContentProcess) { syncStatusFrame->resetGauge(objectsTotal, dataTotal); - syncStatusFrame->setCurrentStatus(statusComparing); + syncStatusFrame->setCurrentStatus(SyncStatus::statusComparing); } else if (currentProcess == FreeFileSync::synchronizeFilesProcess) { syncStatusFrame->resetGauge(objectsTotal, dataTotal); - syncStatusFrame->setCurrentStatus(statusSynchronizing); + syncStatusFrame->setCurrentStatus(SyncStatus::statusSynchronizing); } else assert(false); } @@ -509,22 +540,21 @@ void CommandLineStatusUpdater::updateProcessedData(int objectsProcessed, double int CommandLineStatusUpdater::reportError(const wxString& text) { - if (silentMode) //write error message log and abort the complete session + if (silentMode) //write error message log and abort the complete session if necessary { - app->writeLog(text, _("Error")); + app->logWrite(text, _("Error")); - if (skipErrors) // <- /|\ before return, the logfile is written!!! + if (continueErrors) // <- /|\ before return, the logfile is written!!! return StatusUpdater::continueNext; else { abortionRequested = true; throw AbortThisProcess(); } - } else //show dialog to user who can decide how to continue { - if (skipErrors) //this option can be set from commandline or by the user in the error dialog on UI + if (continueErrors) //this option can be set from commandline or by the user in the error dialog on UI { unhandledErrors.Add(text); return StatusUpdater::continueNext; @@ -534,7 +564,7 @@ int CommandLineStatusUpdater::reportError(const wxString& text) wxString errorMessage = text + _("\n\nContinue with next object, retry or abort synchronization?"); - ErrorDlg* errorDlg = new ErrorDlg(errorMessage, skipErrors); + ErrorDlg* errorDlg = new ErrorDlg(errorMessage, continueErrors); int rv = errorDlg->ShowModal(); errorDlg->Destroy(); @@ -578,71 +608,3 @@ void CommandLineStatusUpdater::updateFinalStatus(const wxString& text) //set by if (!silentMode) syncStatusFrame->setStatusText_NoUpdate(text); } - - -//###################################################################################################### - - -wxString exchangeEscapeChars(char* temp) -{ - wxString output(temp); - output.Replace("\\\\", "\\"); - output.Replace("\\n", "\n"); - output.Replace("\\t", "\t"); - output.Replace("\"\"", """"); - output.Replace("\\\"", "\""); - return output; -} - - -CustomLocale::CustomLocale(int language, int flags) - :wxLocale(language, flags) -{ - char temp[100000]; -// wxString languageFile; -// switch (language) -// { -// case wxLANGUAGE_GERMAN: - wxString languageFile = "language.dat"; -// break; -// default: ; -// } - - //load language file into buffer - if (languageFile.size() != 0) - { - ifstream langFile(languageFile.c_str()); - if (langFile) - { - int rowNumber = 0; - TranslationLine currentLine; - while (langFile.getline(temp, 100000)) - { - if (rowNumber%2 == 0) - currentLine.original = exchangeEscapeChars(temp); - else - { - currentLine.translation = exchangeEscapeChars(temp); - translationDB.insert(currentLine); - } - ++rowNumber; - } - langFile.close(); - } - } -} - - -const wxChar* CustomLocale::GetString(const wxChar* szOrigString, const wxChar* szDomain) const -{ - TranslationLine currentLine; - currentLine.original = szOrigString; - - //look for translation in buffer table - Translation::iterator i; - if ((i = translationDB.find(currentLine)) != translationDB.end()) - return (i->translation.c_str()); - //fallback - return (szOrigString); -} - -- cgit