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>
25 #include <QMessageBox>
28 #include <QSignalMapper>
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();
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)));
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()));
59 menu
->addAction("&Exit", this, SIGNAL(requestQuit()));
62 setToolTip(PROGRAM_NAME
);
64 connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason
)), this, SLOT(activate(QSystemTrayIcon::ActivationReason
)));
69 TrayIcon::~TrayIcon() {
70 for (CallMap::const_iterator i
= callMap
.constBegin(); i
!= callMap
.constEnd(); ++i
)
71 delete i
.value().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
))
107 CallData
&data
= callMap
[id
];
109 // deleting the menu deletes the actions, which automatically removes
110 // the signal mappings
114 void TrayIcon::startedRecording(int id
) {
115 if (!callMap
.contains(id
))
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
))
126 CallData
&data
= callMap
[id
];
127 data
.startAction
->setEnabled(true);
128 data
.stopAction
->setEnabled(false);
129 data
.stopAndDeleteAction
->setEnabled(false);