Bumped copyright dates for 2013
[barry.git] / desktop / src / MigrateDlg.h
blob5fabb09ede80df0be98901f8ab633656cebed51e
1 ///
2 /// \file MigrateDlg.h
3 /// Dialog for the "Migrate Device" main menu mode button...
4 /// going with a dialog instead of a mode class this time.
5 ///
7 /*
8 Copyright (C) 2012-2013, 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_MIGRATEDLG_H__
24 #define __BARRYDESKTOP_MIGRATEDLG_H__
26 #include <wx/wx.h>
27 #include "deviceset.h"
28 #include "EasyCondition.h"
30 // Event types for the MigrateDlg
31 DECLARE_EVENT_TYPE(MET_THREAD_FINISHED, -1)
32 DECLARE_EVENT_TYPE(MET_CHECK_DEST_PIN, -1)
33 DECLARE_EVENT_TYPE(MET_SET_STATUS_MSG, -1)
34 DECLARE_EVENT_TYPE(MET_PROMPT_PASSWORD, -1)
35 DECLARE_EVENT_TYPE(MET_ERROR_MSG, -1)
37 class MigrateDlg : public wxDialog
39 DECLARE_EVENT_TABLE() // sets to protected:
41 private:
42 // external data sources
43 const Barry::Probe::Results &m_results;
44 int m_current_device_index;
46 // in case we need to rescan the USB for a newly plugged device
47 Barry::Probe::Results m_new_results;
49 // migration settings, for the thread
50 bool m_migrate_thread_created; // true until joined
51 pthread_t m_migrate_thread;
52 volatile bool m_abort_flag;
53 volatile bool m_thread_running;
54 const Barry::ProbeResult *m_source_device, *m_dest_device;
55 Barry::DeviceParser::WriteMode m_write_mode;
56 EasyCondition m_waiter;
57 wxString m_password;
59 // backup data, used by the thread in BackupSource()
60 std::string m_backup_tarfile;
61 Barry::DatabaseDatabase m_source_dbdb;
63 // dialog controls
64 wxSizer *m_topsizer;
65 wxChoice *m_source_combo, *m_dest_combo, *m_write_mode_combo;
66 wxButton *m_migrate_button;
67 wxCheckBox *m_wipe_check;
68 wxStaticText *m_status;
69 wxGauge *m_progress;
71 protected:
72 void CreateLayout();
73 void AddDescriptionSizer(wxSizer *sizer);
74 void AddMainSizer(wxSizer *sizer);
75 void AddStatusSizer(wxSizer *sizer);
77 void Main_AddSourceSizer(wxSizer *sizer);
78 void Main_AddButtonSizer(wxSizer *sizer);
79 void Main_AddDestSizer(wxSizer *sizer);
81 void EnableControls(bool enable = true);
82 void DoSafeClose();
84 void SendEvent(int event_type);
85 void SendStatusEvent(const wxString &msg, int pos = -1, int max = -1);
86 void SendErrorMsgEvent(const wxString &msg);
88 // thread helper functions, called from the thread
89 void BackupSource();
90 void CheckDestPin();
91 void RestoreToDest();
93 public:
94 MigrateDlg(wxWindow *parent, const Barry::Probe::Results &results,
95 int current_device_index = -1);
97 void WaitForEvent();
98 const wxString& GetPassword() const { return m_password; }
100 // event handlers
101 void OnMigrateNow(wxCommandEvent &event);
102 void OnCancel(wxCommandEvent &event);
103 void OnCloseWindow(wxCloseEvent &event);
104 void OnThreadFinished(wxCommandEvent &event);
105 void OnCheckDestPin(wxCommandEvent &event);
106 void OnSetStatusMsg(wxCommandEvent &event);
107 void OnPromptPassword(wxCommandEvent &event);
108 void OnErrorMsg(wxCommandEvent &event);
110 // migration thread function
111 static void* MigrateThread(void *arg);
114 #endif