1 | /* |
2 | * kPPP: A pppd Front End for the KDE project |
3 | * |
4 | * $Id$ |
5 | * |
6 | * Copyright (C) 1997 Bernd Johannes Wuebben |
7 | * wuebben@math.cornell.edu |
8 | * |
9 | * This file was contributed by Harri Porten <porten@tu-harburg.de> |
10 | * |
11 | * |
12 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU Library General Public |
14 | * License as published by the Free Software Foundation; either |
15 | * version 2 of the License, or (at your option) any later version. |
16 | * |
17 | * This program is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | * Library General Public License for more details. |
21 | * |
22 | * You should have received a copy of the GNU Library General Public |
23 | * License along with this program; if not, write to the Free |
24 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
25 | */ |
26 | |
27 | #include <kactioncollection.h> |
28 | #include <kwindowsystem.h> |
29 | #include <klocale.h> |
30 | #include <kiconloader.h> |
31 | #include <kmenu.h> |
32 | |
33 | #include "docking.h" |
34 | #include "main.h" |
35 | #include "pppstats.h" |
36 | //Added by qt3to4: |
37 | |
38 | extern KPPPWidget *p_kppp; |
39 | |
40 | // static member |
41 | DockWidget *DockWidget::dock_widget = 0; |
42 | |
43 | DockWidget::DockWidget(QWidget *parent, const char *name, PPPStats *st) |
44 | : KSystemTrayIcon(parent), stats(st) { |
45 | |
46 | setObjectName(name); |
47 | |
48 | // load pixmaps |
49 | dock_none_pixmap = UserIcon("dock_none" ); |
50 | dock_left_pixmap = UserIcon("dock_left" ); |
51 | dock_right_pixmap = UserIcon("dock_right" ); |
52 | dock_both_pixmap = UserIcon("dock_both" ); |
53 | |
54 | setIcon(dock_none_pixmap); |
55 | |
56 | // popup menu for right mouse button |
57 | popup_m = contextMenu(); |
58 | popup_m->addAction(i18n("Details" ), p_kppp, SLOT(showStats())); |
59 | popup_m->addSeparator(); |
60 | popup_m->addAction(i18n("Disconnect" ), p_kppp, SLOT(disconnect())); |
61 | // TODO see if we can rather connect the quit action to the |
62 | // main window's quit handling, bypassing KSystemTrayIcon::maybeQuit |
63 | QAction *quit = |
64 | actionCollection()->action(KStandardAction::name(KStandardAction::Quit)); |
65 | if (quit != 0) |
66 | quit->setVisible(false); |
67 | // connect to stats for little modem animation |
68 | connect(stats, SIGNAL(statsChanged(int)), SLOT(paintIcon(int))); |
69 | |
70 | DockWidget::dock_widget = this; |
71 | } |
72 | |
73 | |
74 | DockWidget::~DockWidget() { |
75 | DockWidget::dock_widget = 0; |
76 | } |
77 | |
78 | |
79 | void DockWidget::paintIcon (int status) { |
80 | // animate modem lights |
81 | |
82 | if(isVisible()) { |
83 | switch(status) |
84 | { |
85 | case PPPStats::BytesBoth: |
86 | setIcon( dock_both_pixmap ); |
87 | break; |
88 | case PPPStats::BytesIn: |
89 | setIcon ( dock_left_pixmap ); |
90 | break; |
91 | case PPPStats::BytesOut: |
92 | setIcon ( dock_right_pixmap ); |
93 | break; |
94 | case PPPStats::BytesNone: |
95 | default: |
96 | setIcon ( dock_none_pixmap ); |
97 | break; |
98 | } |
99 | } |
100 | } |
101 | |
102 | |
103 | void DockWidget::take_stats() { |
104 | if (isVisible()) { |
105 | stats->initStats(); |
106 | stats->start(); |
107 | } |
108 | } |
109 | |
110 | |
111 | void DockWidget::stop_stats() { |
112 | stats->stop(); |
113 | } |
114 | |
115 | #include "docking.moc" |
116 | |