Updated .gitignore for the barry18 -> barry19 symlink
[barry.git] / desktop / src / SyncStatusDlg.h
blobe5eb37ce7fcabf272fc53710d35a27859d70f123
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 // state
127 bool m_repositioned;
129 protected:
130 void CreateLayout();
131 void AddStatusSizer(wxSizer *sizer);
132 void AddButtonSizer(wxSizer *sizer);
134 // set buttons to "running" state
135 void SetRunning();
136 // set buttons to "close" state
137 void SetClose();
139 void UpdateTitle();
140 void UpdateLastSyncTime();
142 public:
143 SyncStatusDlg(wxWindow *parent, const DeviceSet::subset_type &subset);
144 ~SyncStatusDlg();
146 // operations
147 void KillSync();
148 void StartNextSync();
150 void PrintStd(const std::string &msg, const wxColour &colour);
151 void Print(const wxString &msg, const wxColour &colour);
152 void ShortPrintStd(const std::string &msg);
153 void ShortPrint(const wxString &msg);
154 void Throb();
155 void StartTimer();
156 void StopTimer();
158 DeviceEntry* GetCurrentDevice();
160 // event handlers
161 void OnSlowSync(); // called from StatusConnection
162 void OnInitDialog(wxInitDialogEvent &event);
163 void OnRunApp(wxCommandEvent &event);
164 void OnSyncAgain(wxCommandEvent &event);
165 void OnKillClose(wxCommandEvent &event);
166 void OnShowDetails(wxCommandEvent &event);
167 void OnExecTerminated(wxProcessEvent &event);
168 void OnTimer(wxTimerEvent &event);
170 // virtual overrides from wxServer
171 wxConnectionBase* OnAcceptConnection(const wxString &topic);
174 #endif