summaryrefslogtreecommitdiff
path: root/RealtimeSync/trayMenu.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:07:15 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:07:15 +0200
commit8318453bf9d4fd50b137ff6c6fc8d1fd22aa6395 (patch)
tree975c6e590c31e56007006a23e7b15d0245d75b08 /RealtimeSync/trayMenu.cpp
parent3.6 (diff)
downloadFreeFileSync-8318453bf9d4fd50b137ff6c6fc8d1fd22aa6395.tar.gz
FreeFileSync-8318453bf9d4fd50b137ff6c6fc8d1fd22aa6395.tar.bz2
FreeFileSync-8318453bf9d4fd50b137ff6c6fc8d1fd22aa6395.zip
3.7
Diffstat (limited to 'RealtimeSync/trayMenu.cpp')
-rw-r--r--RealtimeSync/trayMenu.cpp79
1 files changed, 64 insertions, 15 deletions
diff --git a/RealtimeSync/trayMenu.cpp b/RealtimeSync/trayMenu.cpp
index 79076abd..436ee904 100644
--- a/RealtimeSync/trayMenu.cpp
+++ b/RealtimeSync/trayMenu.cpp
@@ -9,7 +9,9 @@
#include <wx/taskbar.h>
#include <wx/app.h>
#include "resources.h"
-//#include <memory>
+#include <algorithm>
+#include <iterator>
+#include "../shared/stringConv.h"
#include <wx/utils.h>
#include <wx/menu.h>
#include "watcher.h"
@@ -23,7 +25,7 @@
using namespace RealtimeSync;
-class WaitCallbackImpl : private wxEvtHandler, public RealtimeSync::WaitCallback //keep this order: else VC++ generated wrong code
+class WaitCallbackImpl : private wxEvtHandler, public RealtimeSync::WaitCallback //keep this order: else VC++ generates wrong code
{
public:
WaitCallbackImpl();
@@ -31,6 +33,9 @@ public:
virtual void requestUiRefresh();
+ void showIconActive();
+ void showIconWaiting();
+
void requestAbort()
{
m_abortRequested = true;
@@ -114,13 +119,7 @@ WaitCallbackImpl::WaitCallbackImpl() :
{
trayMenu = new RtsTrayIcon(this); //not in initialization list: give it a valid parent object!
-#ifdef FFS_WIN
- const wxIcon& realtimeIcon = *GlobalResources::getInstance().programIcon;
-#elif defined FFS_LINUX
- wxIcon realtimeIcon;
- realtimeIcon.CopyFromBitmap(GlobalResources::getInstance().getImageByName(wxT("RTS_tray_linux.png"))); //use a 22x22 bitmap for perfect fit
-#endif
- trayMenu->SetIcon(realtimeIcon, wxString(wxT("RealtimeSync")) + wxT(" - ") + _("Monitoring active..."));
+ showIconActive();
//register double-click
trayMenu->Connect(wxEVT_TASKBAR_LEFT_DCLICK, wxCommandEventHandler(WaitCallbackImpl::OnRequestResume), NULL, this);
@@ -139,6 +138,30 @@ WaitCallbackImpl::~WaitCallbackImpl()
}
+void WaitCallbackImpl::showIconActive()
+{
+ wxIcon realtimeIcon;
+#ifdef FFS_WIN
+ realtimeIcon.CopyFromBitmap(GlobalResources::getInstance().getImageByName(wxT("RTS_tray_win.png"))); //use a 16x16 bitmap
+#elif defined FFS_LINUX
+ realtimeIcon.CopyFromBitmap(GlobalResources::getInstance().getImageByName(wxT("RTS_tray_linux.png"))); //use a 22x22 bitmap for perfect fit
+#endif
+ trayMenu->SetIcon(realtimeIcon, wxString(wxT("RealtimeSync")) + wxT(" - ") + _("Monitoring active..."));
+}
+
+
+void WaitCallbackImpl::showIconWaiting()
+{
+ wxIcon realtimeIcon;
+#ifdef FFS_WIN
+ realtimeIcon.CopyFromBitmap(GlobalResources::getInstance().getImageByName(wxT("RTS_tray_waiting_win.png"))); //use a 16x16 bitmap
+#elif defined FFS_LINUX
+ realtimeIcon.CopyFromBitmap(GlobalResources::getInstance().getImageByName(wxT("RTS_tray_waiting_linux.png"))); //use a 22x22 bitmap for perfect fit
+#endif
+ trayMenu->SetIcon(realtimeIcon, wxString(wxT("RealtimeSync")) + wxT(" - ") + _("Waiting for all directories to become available..."));
+}
+
+
void WaitCallbackImpl::OnContextMenuSelection(wxCommandEvent& event)
{
const int eventId = event.GetId();
@@ -188,9 +211,22 @@ void WaitCallbackImpl::requestUiRefresh()
}
//##############################################################################################################
+namespace
+{
+std::vector<Zstring> convert(const std::vector<wxString>& dirList)
+{
+ std::vector<Zstring> output;
+ std::transform(dirList.begin(), dirList.end(),
+ std::back_inserter(output), static_cast<Zstring (*)(const wxString&)>(FreeFileSync::wxToZ));
+ return output;
+}
+}
+
RealtimeSync::MonitorResponse RealtimeSync::startDirectoryMonitor(const xmlAccess::XmlRealConfig& config)
{
+ const std::vector<Zstring> dirList = convert(config.directories);
+
try
{
WaitCallbackImpl callback;
@@ -198,18 +234,31 @@ RealtimeSync::MonitorResponse RealtimeSync::startDirectoryMonitor(const xmlAcces
if (config.commandline.empty())
throw FreeFileSync::FileError(_("Command line is empty!"));
- long lastExec = 0;
while (true)
{
+ //execute commandline
+ callback.showIconWaiting();
+ waitForMissingDirs(dirList, &callback);
+ callback.showIconActive();
+
wxExecute(config.commandline, wxEXEC_SYNC); //execute command
wxLog::FlushActive(); //show wxWidgets error messages (if any)
- //wait
- waitForChanges(config.directories, &callback);
- lastExec = wxGetLocalTime();
+ //wait for changes (and for all directories to become available)
+ switch (waitForChanges(dirList, &callback))
+ {
+ case CHANGE_DIR_MISSING: //don't execute the commandline before all directories are available!
+ callback.showIconWaiting();
+ waitForMissingDirs(dirList, &callback);
+ callback.showIconActive();
+ break;
+ case CHANGE_DETECTED:
+ break;
+ }
//some delay
- while (wxGetLocalTime() - lastExec < static_cast<long>(config.delay))
+ const long nextExec = wxGetLocalTime() + static_cast<long>(config.delay);
+ while (wxGetLocalTime() < nextExec)
{
callback.requestUiRefresh();
wxMilliSleep(RealtimeSync::UI_UPDATE_INTERVAL);
@@ -222,7 +271,7 @@ RealtimeSync::MonitorResponse RealtimeSync::startDirectoryMonitor(const xmlAcces
}
catch (const FreeFileSync::FileError& error)
{
- wxMessageBox(error.show().c_str(), _("Error"), wxOK | wxICON_ERROR);
+ wxMessageBox(error.show(), _("Error"), wxOK | wxICON_ERROR);
return RESUME;
}
bgstack15