fixed an error in storing macs with zeroes.
[woller] / woller.h
1 // Copyright 2010 Ilkka Tengvall
2 //
3 // This file is part of Woller.
4 //
5 // Woller is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Woller is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Woller.  If not, see <http://www.gnu.org/licenses/>.
17
18 #ifndef WOLLER_H
19 #define WOLLER_H
20
21 #include <QtGui>
22 #include <QUdpSocket>
23 #include <QDebug>
24 #include <QWidget>
25 #include <QDialog>
26 #include <QHostAddress>
27 #include <QLabel>
28 #include <QPushButton>
29 #include <QComboBox>
30 #include <QVBoxLayout>
31 #include <QHBoxLayout>
32 #include <QLineEdit>
33
34 //class QLabel;
35 //class QPushButton;
36 //class QComboBox;
37 //class QVBoxLayout;
38 //class QHBoxLayout;
39 //class QLineEdit;
40
41 struct host_s
42 {
43     QString hostname;
44     QString mac;
45     QHostAddress ip;
46 };
47
48
49 class HostWidget : public QWidget
50 {
51     Q_OBJECT
52
53 public:
54     HostWidget(QWidget *parent = 0, host_s *host = 0);
55     ~HostWidget();
56     QLineEdit *hostname;
57     QLineEdit *mac;
58     QLineEdit *ip;
59
60 public slots:
61     void ok_sig();
62     void cancel_sig();
63
64 signals:
65     void change_host();
66
67 private:
68     QVBoxLayout *vlayout;
69     QHBoxLayout *host_row;
70     QLabel *host_lbl;
71     QLabel *mac_lbl;
72     QHBoxLayout *mac_row;
73     QLabel *ip_lbl;
74     QHBoxLayout *ip_row;
75     QPushButton *cancel;
76     QPushButton *ok;
77     QHBoxLayout *button_row;
78     host_s *new_host;
79 };
80
81
82 class ConfigWidget : public QWidget
83 {
84     Q_OBJECT
85
86 public:
87     ConfigWidget(QWidget *parent = 0, QList<host_s> *hosts = 0);
88     ~ConfigWidget();
89     //QListWidget *lista(QWidget *parent = 0);
90     //QListWidget *lista;
91
92 public slots:
93     void add_sig();
94     void edit_sig();
95     void del_sig();
96     void save_sig();
97     void close_sig();
98     void select_sig();
99     void host_added();
100     void host_edited();
101
102 signals:
103     void hosts_changed();
104
105 private:
106 //    QPushButton *add_host;
107     QListWidget *list;
108     QVBoxLayout *button_layout;
109     QHBoxLayout *layout;
110     QPushButton *add_host;
111     QPushButton *edit_host;
112     QPushButton *del_host;
113     QPushButton *save_btn;
114     QPushButton *close_btn;
115     HostWidget *host_widget;
116     QList<host_s> *hosts_list;
117     host_s host_tmp;
118 };
119
120
121 class wol_target
122 {
123
124 public:
125     wol_target();
126     ~wol_target();
127     int wake_me();
128     int get_mac( QString *gmac);
129     int set_mac( const QString mac );
130     int get_ip( QHostAddress *ip );
131     int set_ip( const QHostAddress );
132
133 private:
134 #define WOL_MAGIC_MAC_CNT 16
135 #define WOL_MAGIC_UDP_PORT 9
136     QString *mac;
137     QHostAddress *ip;
138     QByteArray *magic_pkt;
139     int create_magic_pkt( const QString *mac );
140 };
141
142
143
144 #define MAX_MAC_LEN 12
145 #define MAC_COLON_CNT 5
146 #define MAX_MAC_STR_LEN (MAX_MAC_LEN + MAC_COLON_CNT)
147 #define MAX_IP_LEN 15
148
149
150 class Woller : public QWidget
151 {
152     Q_OBJECT
153
154 #define WOLLER_RC_FILE ".wollerrc"
155
156
157 public:
158     Woller(QWidget *parent = 0);
159     ~Woller();
160     QList<host_s> hosts;
161
162 public slots:
163     void send_pkt();
164     void targets_act(int);
165     void add_new(host_s *host);
166     void hosts_changed();
167     void reset_status();
168
169 private:
170     QTimer *status_timer;
171     QLabel *status_lbl;
172     QString *status_orig;
173     QPushButton *fire_btn;
174     QComboBox *targets_cb;
175     QVBoxLayout *vlayout;
176     QHBoxLayout *hlayout;
177     wol_target *target;
178     void config();
179     ConfigWidget *config_win;
180     void save_config();
181     void load_config();
182
183     QList<host_s> *hosts_list;
184     QSettings *settings;
185     void do_list();
186 };
187
188 class MainWindow : public QMainWindow
189 {
190     Q_OBJECT
191
192 public:
193     MainWindow();
194     ~MainWindow();
195
196 protected:
197
198 private slots:
199
200 private:
201
202     Woller *woller;
203 };
204
205 #endif