Support building .deb package for Debian
[skype-call-recorder.git] / trayicon.cpp
blob286e7f59c0724da0b43c0b74dea0f3e5db8e6fc9
1 /*
2 Skype Call Recorder
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
21 http://www.fsf.org/
24 #include <QSystemTrayIcon>
25 #include <QMenu>
26 #include <QCursor>
27 #include <QSignalMapper>
28 #include <QTimer>
30 #include "trayicon.h"
31 #include "common.h"
32 #include "skype.h"
33 #include "preferences.h"
34 #include "gui.h"
36 TrayIcon::TrayIcon(QObject *p) : QSystemTrayIcon(p) {
37 setColor(false);
39 if (preferences.get(Pref::GuiWindowed).toBool()) {
40 createMainWindow();
41 } else {
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)));
56 menu = new QMenu;
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()));
65 menu->addSeparator();
66 menu->addAction("&Exit", this, SIGNAL(requestQuit()));
68 setContextMenu(menu);
69 updateToolTip();
71 connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activate()));
73 show();
76 TrayIcon::~TrayIcon() {
77 delete menu;
78 delete window;
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.");
91 } else {
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) {
106 colored = color;
108 setIcon(QIcon(color ? ":/icon.png" : ":/icongray.png"));
110 if (window)
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);
139 updateToolTip();
142 void TrayIcon::stoppedCall(int id) {
143 if (!callMap.contains(id))
144 return;
145 CallData &data = callMap[id];
146 delete data.menu;
147 // deleting the menu deletes the actions, which automatically removes
148 // the signal mappings
149 callMap.remove(id);
151 updateToolTip();
154 void TrayIcon::startedRecording(int id) {
155 if (!callMap.contains(id))
156 return;
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),
166 Information, 5000);
169 updateToolTip();
172 void TrayIcon::stoppedRecording(int id) {
173 if (!callMap.contains(id))
174 return;
175 CallData &data = callMap[id];
176 data.isRecording = false;
177 data.startAction->setEnabled(true);
178 data.stopAction->setEnabled(false);
179 data.stopAndDeleteAction->setEnabled(false);
181 updateToolTip();
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);
196 setToolTip(str);