f0c8f9b9b549a58afeddc05657d86fd4512cdbc3
[yandex-traffic] / tests / conn / mainwindow.hpp
1 #ifndef __MAINWINDOW_H__
2 #define __MAINWINDOW_H__
3
4 #include <QtGui>
5 #include <connection.hpp>
6
7 class MainWindow : public QPushButton
8 {
9     Q_OBJECT
10 public:
11     MainWindow ()
12         : QPushButton ()
13     {
14         ConnectionChecker *cc = ConnectionChecker::instance ();
15
16         connect (cc, SIGNAL (connected (bool)), SLOT (connected (bool)));
17         connect (cc, SIGNAL (type_changed (ConnectionChecker::network_type_t)), SLOT (type_changed (ConnectionChecker::network_type_t)));
18
19         setText (cc->isConnected () ? "Connected" : "Not connected");
20         connect (this, SIGNAL (clicked ()), SLOT (checkConnection ()));
21     }
22
23 protected slots:
24     void connected (bool active)
25     {
26         if (active)
27             printf ("Device connected\n");
28         else
29             printf ("Device not connected\n");
30         setText (ConnectionChecker::instance ()->isConnected () ? "Connected" : "Not connected");
31     }
32
33     void type_changed (ConnectionChecker::network_type_t type)
34     {
35         switch (type) {
36             case ConnectionChecker::Net_None:
37                 printf ("Type: none\n");
38                 break;
39             case ConnectionChecker::Net_WLAN:
40                 printf ("Type: WLAN\n");
41                 break;
42             case ConnectionChecker::Net_GSM:
43                 printf ("Type: GSM\n");
44                 break;
45         }
46     }
47
48     void checkConnection ()
49     {
50         ConnectionChecker::instance ()->requestState ();
51     }
52 };
53
54 #endif // __MAINWINDOW_H__