f1afc7131c1aa7a468234c0cebbf8f04025aefb2
[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 MAX_IP_LEN 15
146
147
148 class Woller : public QWidget
149 {
150     Q_OBJECT
151
152 #define WOLLER_RC_FILE ".wollerrc"
153
154
155 public:
156     Woller(QWidget *parent = 0);
157     ~Woller();
158     QList<host_s> hosts;
159
160 public slots:
161     void send_pkt();
162     void targets_act(int);
163     void add_new(host_s *host);
164     void hosts_changed();
165     void reset_status();
166
167 private:
168     QTimer *status_timer;
169     QLabel *status_lbl;
170     QString *status_orig;
171     QPushButton *fire_btn;
172     QComboBox *targets_cb;
173     QVBoxLayout *vlayout;
174     QHBoxLayout *hlayout;
175     wol_target *target;
176     void config();
177     ConfigWidget *config_win;
178     void save_config();
179     void load_config();
180
181     QList<host_s> *hosts_list;
182     QSettings *settings;
183     void do_list();
184 };
185
186
187 #endif