Add extra cleanup sauce to buildgen.sh for gettext mess
[barry.git] / gui / src / Thread.h
bloba7703795009dff3ab677072a280af758c2ab1e38
1 ///
2 /// \file Thread.h
3 /// Thread class for device manipulation
4 ///
6 /*
7 Copyright (C) 2007-2010, 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; }
103 void Reset() { m_interface.Reset(); }
104 bool Connect();
105 bool Connect(const std::string &password);
106 void Disconnect();
108 void SetActive() { m_active = true; }
109 void UnsetActive();
111 bool Connected() const { return m_connected; }
112 bool Working() const { return !(m_thread_state & THREAD_STATE_IDLE); }
113 bool Error() const { return m_error; }
115 bool PasswordRequired() const { return password_required; }
116 bool PasswordOutOfTries() const { return password_out_of_tries; }
117 unsigned int PasswordRemainingTries() const { return password_remaining_tries; }
118 std::string BadPasswordError() const { return bad_password_error; }
120 bool BadSize() const { return bad_size; }
121 std::string BadSizeError() const { return bad_size_error; }
123 bool Backup(std::string label);
124 bool Restore(std::string filename);
125 bool RestoreAndBackup(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