desktop: stop the progress bar timer when dealing with a conflict
[barry/progweb.git] / desktop / src / SyncStatusDlg.h
blobaf04d3b6f7fe30b946b70a5d4a1a7fe6d190785c
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, 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()
99 // external data sources
100 DeviceSet::subset_type m_subset;
101 DeviceSet::subset_type::iterator m_next_device, m_current_device;
103 // for handling bsyncjail
104 ExecHelper m_jailexec;
105 std::string m_device_id;
106 bool m_killingjail;
108 // for handling run app
109 ConfigUI::ptr m_ui;
111 // connection holder, to make sure they get deleted if we
112 // go out of scope
113 OptOut::Vector<wxConnectionBase> m_connections;
115 wxTimer m_timer;
117 // dialog controls
118 wxSizer *m_topsizer;
119 wxStaticText *m_short_status;
120 wxGauge *m_throbber;
121 wxTextCtrl *m_status_edit;
122 wxButton *m_runapp_button, *m_syncagain_button, *m_killclose_button;
123 wxButton *m_details_button;
125 protected:
126 void CreateLayout();
127 void AddStatusSizer(wxSizer *sizer);
128 void AddButtonSizer(wxSizer *sizer);
130 // set buttons to "running" state
131 void SetRunning();
132 // set buttons to "close" state
133 void SetClose();
135 void UpdateTitle();
137 public:
138 SyncStatusDlg(wxWindow *parent, const DeviceSet::subset_type &subset);
139 ~SyncStatusDlg();
141 // operations
142 void KillSync();
143 void StartNextSync();
145 void Print(const std::string &msg, const wxColour &colour);
146 void Print(const wxString &msg, const wxColour &colour);
147 void ShortPrint(const std::string &msg);
148 void ShortPrint(const wxString &msg);
149 void Throb();
150 void StartTimer();
151 void StopTimer();
153 DeviceEntry* GetCurrentDevice();
155 // event handlers
156 void OnSlowSync(); // called from StatusConnection
157 void OnInitDialog(wxInitDialogEvent &event);
158 void OnRunApp(wxCommandEvent &event);
159 void OnSyncAgain(wxCommandEvent &event);
160 void OnKillClose(wxCommandEvent &event);
161 void OnShowDetails(wxCommandEvent &event);
162 void OnExecTerminated(wxProcessEvent &event);
163 void OnTimer(wxTimerEvent &event);
165 // virtual overrides from wxServer
166 wxConnectionBase* OnAcceptConnection(const wxString &topic);
169 #endif