3 Copyright (C) 2008 jlh (jlh at gmx dot ch)
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the
7 Free Software Foundation; either version 2 of the License, version 3 of
8 the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 The GNU General Public License version 2 is included with the source of
20 this program under the file name COPYING. You can also get a copy on
24 #include <QSystemTrayIcon>
27 #include <QSignalMapper>
33 #include "preferences.h"
36 TrayIcon::TrayIcon(QObject
*p
) : QSystemTrayIcon(p
) {
39 if (preferences
.get(Pref::GuiWindowed
).toBool()) {
42 if (!QSystemTrayIcon::isSystemTrayAvailable()) {
43 debug("Warning: No system tray detected. Will check again in 10 seconds.");
44 QTimer::singleShot(10000, this, SLOT(checkTrayPresence()));
48 smStart
= new QSignalMapper(this);
49 smStop
= new QSignalMapper(this);
50 smStopAndDelete
= new QSignalMapper(this);
52 connect(smStart
, SIGNAL(mapped(int)), this, SIGNAL(startRecording(int)));
53 connect(smStop
, SIGNAL(mapped(int)), this, SIGNAL(stopRecording(int)));
54 connect(smStopAndDelete
, SIGNAL(mapped(int)), this, SIGNAL(stopRecordingAndDelete(int)));
57 separator
= menu
->addSeparator();
58 menu
->addAction("&Browse previous calls", this, SIGNAL(requestBrowseCalls()));
59 menu
->addAction("Open &preferences...", this, SIGNAL(requestOpenPreferences()));
61 aboutMenu
= menu
->addMenu("&About");
62 aboutMenu
->addAction("&About " PROGRAM_NAME
, this, SIGNAL(requestAbout()));
63 aboutMenu
->addAction("Visit &website", this, SIGNAL(requestWebsite()));
66 menu
->addAction("&Exit", this, SIGNAL(requestQuit()));
71 connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason
)), this, SLOT(activate()));
76 TrayIcon::~TrayIcon() {
81 void TrayIcon::createMainWindow() {
82 window
= new MainWindow
;
83 connect(window
, SIGNAL(activate()), this, SLOT(activate()));
84 connect(window
, SIGNAL(destroyed()), this, SIGNAL(requestQuit()));
85 window
->setColor(colored
);
88 void TrayIcon::checkTrayPresence() {
89 if (QSystemTrayIcon::isSystemTrayAvailable()) {
90 debug("System tray now present, all ok.");
92 QWidget
*dialog
= new NoSystemTrayDialog
;
94 connect(dialog
, SIGNAL(useWindowedModeNow()) , this, SLOT(createMainWindow()));
95 connect(dialog
, SIGNAL(useWindowedModeAlways()), this, SLOT(createMainWindow()));
96 connect(dialog
, SIGNAL(useWindowedModeAlways()), this, SLOT(setWindowedMode()));
97 connect(dialog
, SIGNAL(doQuit()), this, SIGNAL(requestQuit()));
101 void TrayIcon::setWindowedMode() {
102 preferences
.get(Pref::GuiWindowed
).set(true);
105 void TrayIcon::setColor(bool color
) {
108 setIcon(QIcon(color
? ":/icon.png" : ":/icongray.png"));
111 window
->setColor(color
);
115 void TrayIcon::activate() {
116 contextMenu()->popup(QCursor::pos());
119 void TrayIcon::startedCall(int id
, const QString
&skypeName
) {
120 CallData
&data
= callMap
[id
];
122 data
.skypeName
= skypeName
;
123 data
.isRecording
= false;
124 data
.menu
= new QMenu(QString("Call with ") + skypeName
, menu
);
125 data
.startAction
= data
.menu
->addAction("&Start recording", smStart
, SLOT(map()));
126 data
.stopAction
= data
.menu
->addAction("S&top recording", smStop
, SLOT(map()));
127 data
.stopAndDeleteAction
= data
.menu
->addAction("Stop recording and &delete file", smStopAndDelete
, SLOT(map()));
129 data
.startAction
->setEnabled(true);
130 data
.stopAction
->setEnabled(false);
131 data
.stopAndDeleteAction
->setEnabled(false);
133 smStart
->setMapping(data
.startAction
, id
);
134 smStop
->setMapping(data
.stopAction
, id
);
135 smStopAndDelete
->setMapping(data
.stopAndDeleteAction
, id
);
137 menu
->insertMenu(separator
, data
.menu
);
142 void TrayIcon::stoppedCall(int id
) {
143 if (!callMap
.contains(id
))
145 CallData
&data
= callMap
[id
];
147 // deleting the menu deletes the actions, which automatically removes
148 // the signal mappings
154 void TrayIcon::startedRecording(int id
) {
155 if (!callMap
.contains(id
))
157 CallData
&data
= callMap
[id
];
158 data
.isRecording
= true;
159 data
.startAction
->setEnabled(false);
160 data
.stopAction
->setEnabled(true);
161 data
.stopAndDeleteAction
->setEnabled(true);
163 if (supportsMessages() && preferences
.get(Pref::NotifyRecordingStart
).toBool()) {
164 showMessage("Recording started",
165 QString("The call with %1 is now being recorded.").arg(data
.skypeName
),
172 void TrayIcon::stoppedRecording(int id
) {
173 if (!callMap
.contains(id
))
175 CallData
&data
= callMap
[id
];
176 data
.isRecording
= false;
177 data
.startAction
->setEnabled(true);
178 data
.stopAction
->setEnabled(false);
179 data
.stopAndDeleteAction
->setEnabled(false);
184 void TrayIcon::updateToolTip() {
185 QString str
= PROGRAM_NAME
;
187 if (!callMap
.isEmpty()) {
188 for (CallMap::const_iterator i
= callMap
.constBegin(); i
!= callMap
.constEnd(); ++i
) {
189 const CallData
&data
= i
.value();
190 str
+= QString(data
.isRecording
?
191 "\nThe call with '%1' is being recorded" :
192 "\nThe call with '%1' is not being recorded").arg(data
.skypeName
);