desktop: added timezone list to CalendarEditDlg
[barry.git] / desktop / src / SyncStatusDlg.h
blob94c7d6cd202f17ad11b4abfdc5e7d7583a00029c
1 ///
2 /// \file SyncStatusDlg.h
3 /// The dialog used during a sync, to display status messages
4 /// and error messages, and handle sync conflicts via callback.
5 ///
7 /*
8 Copyright (C) 2010-2012, Net Direct Inc. (http://www.netdirect.ca/)
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 See the GNU General Public License in the COPYING file at the
20 root directory of this project for more details.
23 #ifndef __BARRYDESKTOP_SYNCSTATUSDLG_H__
24 #define __BARRYDESKTOP_SYNCSTATUSDLG_H__
26 #include <wx/wx.h>
27 #include "ipc.h"
28 #include "osbase.h"
29 #include "deviceset.h"
30 #include "exechelper.h"
31 #include "optout.h"
32 #include "configui.h"
33 #include "ConflictDlg.h"
35 class SyncStatusDlg;
37 class StatusConnection : public wxConnection, public OptOut::Element
39 SyncStatusDlg &m_dlg;
40 wxTextCtrl &m_status;
42 public:
43 StatusConnection(SyncStatusDlg &dlg, wxTextCtrl &window);
45 bool OnPoke(const wxString &topic, const wxString &item,
46 wxChar *data, int size, wxIPCFormat format);
48 // wxWidgets bug override - stop the 'delete this' behaviour,
49 // since sometimes events seem to come through after
50 // the delete... not sure why, and hard to debug.
51 // This is with wxWidgets 2.8.7.
53 // With this override, the container in SyncStatusDlg
54 // will handle all the deleting.
55 virtual bool OnDisconnect() { return true; }
58 class ConflictConnection : public wxConnection, public OptOut::Element
60 SyncStatusDlg &m_dlg;
61 SillyBuffer m_buf;
63 // conflict state machine
64 bool m_asking_user;
65 int m_current_sequenceID;
66 int m_current_offset;
67 int m_expected_total_changes;
68 std::string m_supported_commands;
69 std::vector<OpenSync::SyncChange> m_changes;
71 // "always" memory
72 ConflictDlg::AlwaysMemoryBlock m_always;
74 public:
75 ConflictConnection(SyncStatusDlg &dlg);
77 bool OnPoke(const wxString &topic, const wxString &item,
78 wxChar *data, int size, wxIPCFormat format);
79 wxChar* OnRequest(const wxString &topic, const wxString &item,
80 int *size, wxIPCFormat format);
82 // wxWidgets bug override - stop the 'delete this' behaviour,
83 // since sometimes events seem to come through after
84 // the delete... not sure why, and hard to debug.
85 // This is with wxWidgets 2.8.7.
87 // With this override, the container in SyncStatusDlg
88 // will handle all the deleting.
89 virtual bool OnDisconnect() { return true; }
92 class SyncStatusDlg
93 : public wxDialog
94 , public wxServer
95 , public TermCatcher
97 DECLARE_EVENT_TABLE() // sets to protected:
99 private:
100 // external data sources
101 DeviceSet::subset_type m_subset;
102 DeviceSet::subset_type::iterator m_next_device, m_current_device;
104 // for handling bsyncjail
105 ExecHelper m_jailexec;
106 std::string m_device_id;
107 bool m_killingjail;
109 // for handling run app
110 ConfigUI::ptr m_ui;
112 // connection holder, to make sure they get deleted if we
113 // go out of scope
114 OptOut::Vector<wxConnectionBase> m_connections;
116 wxTimer m_timer;
118 // dialog controls
119 wxSizer *m_topsizer;
120 wxStaticText *m_short_status;
121 wxGauge *m_throbber;
122 wxTextCtrl *m_status_edit;
123 wxButton *m_runapp_button, *m_syncagain_button, *m_killclose_button;
124 wxButton *m_details_button;
126 protected:
127 void CreateLayout();
128 void AddStatusSizer(wxSizer *sizer);
129 void AddButtonSizer(wxSizer *sizer);
131 // set buttons to "running" state
132 void SetRunning();
133 // set buttons to "close" state
134 void SetClose();
136 void UpdateTitle();
137 void UpdateLastSyncTime();
139 public:
140 SyncStatusDlg(wxWindow *parent, const DeviceSet::subset_type &subset);
141 ~SyncStatusDlg();
143 // operations
144 void KillSync();
145 void StartNextSync();
147 void Print(const std::string &msg, const wxColour &colour);
148 void Print(const wxString &msg, const wxColour &colour);
149 void ShortPrint(const std::string &msg);
150 void ShortPrint(const wxString &msg);
151 void Throb();
152 void StartTimer();
153 void StopTimer();
155 DeviceEntry* GetCurrentDevice();
157 // event handlers
158 void OnSlowSync(); // called from StatusConnection
159 void OnInitDialog(wxInitDialogEvent &event);
160 void OnRunApp(wxCommandEvent &event);
161 void OnSyncAgain(wxCommandEvent &event);
162 void OnKillClose(wxCommandEvent &event);
163 void OnShowDetails(wxCommandEvent &event);
164 void OnExecTerminated(wxProcessEvent &event);
165 void OnTimer(wxTimerEvent &event);
167 // virtual overrides from wxServer
168 wxConnectionBase* OnAcceptConnection(const wxString &topic);
171 #endif