Bumped copyright dates for 2013
[barry.git] / gui / src / Thread.h
blob4dbb31782795c94b79625e9331c8c64d96f8d357
1 ///
2 /// \file Thread.h
3 /// Thread class for device manipulation
4 ///
6 /*
7 Copyright (C) 2007-2013, Net Direct Inc. (http://www.netdirect.ca/)
8 Copyright (C) 2009, Ryan Li (ryan@ryanium.com)
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 __BARRYBACKUP_THREAD_H__
24 #define __BARRYBACKUP_THREAD_H__
26 #include <gtkmm.h>
27 #include "DeviceIface.h"
29 // bit masks for various thread state
30 #define THREAD_STATE_IDLE 0x01 // currently idle
31 #define THREAD_STATE_BACKUP 0x02 // last operation requested
32 // was backup... if idle bit
33 // is 0, backup is still going
34 #define THREAD_STATE_RESTORE 0x04 // last op was restore... same
35 // as backup
38 class Thread : public Barry::ConfigFile
40 private:
41 Glib::Dispatcher m_signal_progress;
42 Glib::Dispatcher m_signal_error;
43 Glib::Dispatcher m_signal_done;
44 Glib::Dispatcher m_signal_erase_db;
45 Glib::Dispatcher m_signal_restored_db;
47 Device m_dev;
48 DeviceInterface m_interface;
50 Glib::Dispatcher *m_update;
52 std::string m_status;
54 unsigned int m_recordFinished;
55 unsigned int m_recordTotal;
57 // Barry::BadPassword related variables
58 bool password_out_of_tries;
59 unsigned int password_remaining_tries;
60 bool password_required;
61 std::string bad_password_error;
63 // Barry::BadSize related variables
64 bool bad_size;
65 std::string bad_size_error;
67 // whether the device is active in Gtk::TreeView
68 bool m_active;
70 // marked as true after thread finished,
71 // and false when the value is retrieved.
72 bool m_finished_marker;
74 // states
75 bool m_connected;
76 bool m_error;
77 unsigned int m_thread_state;
78 std::string m_erasing_db_name;
80 protected:
81 void SetStatus(std::string);
83 public:
84 Thread(Device, Glib::Dispatcher *);
85 ~Thread() {}
87 std::string LastInterfaceError() { return m_interface.get_last_error(); }
88 std::string LastConfigError() { return ConfigFile::get_last_error(); }
90 const Barry::DatabaseDatabase &GetDBDB() { return m_interface.GetDBDB(); }
92 void LoadConfig();
94 Barry::Pin GetPIN() { return m_dev.GetPIN(); }
95 std::string GetFullname();
97 std::string Status() const { return m_status; }
98 bool CheckFinishedMarker();
99 unsigned int GetRecordFinished() const { return m_recordFinished; }
100 unsigned int GetRecordTotal() const { return m_recordTotal; }
101 unsigned int GetThreadState() const { return m_thread_state; }
102 std::vector<std::string> CompareTotals() const;
104 void Reset() { m_interface.Reset(); }
105 bool Connect();
106 bool Connect(const std::string &password);
107 void Disconnect();
109 void SetActive() { m_active = true; }
110 void UnsetActive();
112 bool Connected() const { return m_connected; }
113 bool Working() const { return !(m_thread_state & THREAD_STATE_IDLE); }
114 bool Error() const { return m_error; }
116 bool PasswordRequired() const { return password_required; }
117 bool PasswordOutOfTries() const { return password_out_of_tries; }
118 unsigned int PasswordRemainingTries() const { return password_remaining_tries; }
119 std::string BadPasswordError() const { return bad_password_error; }
121 bool BadSize() const { return bad_size; }
122 std::string BadSizeError() const { return bad_size_error; }
124 bool Backup(std::string label);
125 bool Restore(std::string filename);
127 void on_thread_progress();
128 void on_thread_error();
129 void on_thread_done();
130 void on_thread_erase_db();
131 void on_thread_restored_db();
134 #endif