preferences: Clarify that &s substitution can be a phone number
[skype-call-recorder.git] / trayicon.cpp
blob6e299484136bdae09a2a53ee5133e2d480ab2c2f
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 <QMessageBox>
26 #include <QMenu>
27 #include <QCursor>
28 #include <QSignalMapper>
30 #include "trayicon.h"
31 #include "common.h"
32 #include "skype.h"
34 TrayIcon::TrayIcon(QObject *p) : QSystemTrayIcon(p) {
35 if (!QSystemTrayIcon::isSystemTrayAvailable()) {
36 QMessageBox::critical(NULL, PROGRAM_NAME " - Error",
37 PROGRAM_NAME " cannot start, because it requires a system tray. None was detected. "
38 "(TODO: Make this work even without a system tray.)");
39 emit requestQuitNoConfirmation();
40 return;
43 smStart = new QSignalMapper(this);
44 smStop = new QSignalMapper(this);
45 smStopAndDelete = new QSignalMapper(this);
47 connect(smStart, SIGNAL(mapped(int)), this, SIGNAL(startRecording(int)));
48 connect(smStop, SIGNAL(mapped(int)), this, SIGNAL(stopRecording(int)));
49 connect(smStopAndDelete, SIGNAL(mapped(int)), this, SIGNAL(stopRecordingAndDelete(int)));
51 setColor(false);
53 menu = new QMenu;
54 separator = menu->addSeparator();
55 menu->addAction("&Browse previous calls", this, SIGNAL(requestBrowseCalls()));
56 menu->addAction("Open &preferences...", this, SIGNAL(requestOpenPreferences()));
57 menu->addAction("&About " PROGRAM_NAME, this, SIGNAL(requestAbout()));
58 menu->addSeparator();
59 menu->addAction("&Exit", this, SIGNAL(requestQuit()));
61 setContextMenu(menu);
62 setToolTip(PROGRAM_NAME);
64 connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activate(QSystemTrayIcon::ActivationReason)));
66 show();
69 TrayIcon::~TrayIcon() {
70 for (CallMap::const_iterator i = callMap.constBegin(); i != callMap.constEnd(); ++i)
71 delete i.value().menu;
73 delete menu;
76 void TrayIcon::setColor(bool color) {
77 setIcon(QIcon(color ? ":/icon.png" : ":/icongray.png"));
81 void TrayIcon::activate(QSystemTrayIcon::ActivationReason) {
82 contextMenu()->popup(QCursor::pos());
85 void TrayIcon::startedCall(int id, const QString &skypeName) {
86 CallData &data = callMap[id];
88 data.menu = new QMenu(QString("Call with ") + skypeName);
89 data.startAction = data.menu->addAction("&Start recording", smStart, SLOT(map()));
90 data.stopAction = data.menu->addAction("S&top recording", smStop, SLOT(map()));
91 data.stopAndDeleteAction = data.menu->addAction("Stop recording and &delete file", smStopAndDelete, SLOT(map()));
93 data.startAction->setEnabled(true);
94 data.stopAction->setEnabled(false);
95 data.stopAndDeleteAction->setEnabled(false);
97 smStart->setMapping(data.startAction, id);
98 smStop->setMapping(data.stopAction, id);
99 smStopAndDelete->setMapping(data.stopAndDeleteAction, id);
101 menu->insertMenu(separator, data.menu);
104 void TrayIcon::stoppedCall(int id) {
105 if (!callMap.contains(id))
106 return;
107 CallData &data = callMap[id];
108 delete data.menu;
109 // deleting the menu deletes the actions, which automatically removes
110 // the signal mappings
111 callMap.remove(id);
114 void TrayIcon::startedRecording(int id) {
115 if (!callMap.contains(id))
116 return;
117 CallData &data = callMap[id];
118 data.startAction->setEnabled(false);
119 data.stopAction->setEnabled(true);
120 data.stopAndDeleteAction->setEnabled(true);
123 void TrayIcon::stoppedRecording(int id) {
124 if (!callMap.contains(id))
125 return;
126 CallData &data = callMap[id];
127 data.startAction->setEnabled(true);
128 data.stopAction->setEnabled(false);
129 data.stopAndDeleteAction->setEnabled(false);