Write ID3 tags in MP3 files via libid3
[skype-call-recorder.git] / trayicon.cpp
blobd41e6ab99ed9c9d0fb344200f8f03525f05effe3
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>
29 #include "trayicon.h"
30 #include "skype.h"
31 #include "common.h"
33 TrayIcon::TrayIcon(QObject *p) : QSystemTrayIcon(p) {
34 if (!QSystemTrayIcon::isSystemTrayAvailable()) {
35 QMessageBox::critical(NULL, PROGRAM_NAME " - Error",
36 PROGRAM_NAME " cannot start, because it requires a system tray. None was detected. "
37 "(TODO: Make this work even without a system tray.)");
38 emit requestQuitNoConfirmation();
39 return;
42 setColor(false);
44 // current call submenu
45 subMenu = new QMenu("Call with unknown");
46 startAction = subMenu->addAction("&Start recording", this, SIGNAL(startRecording()));
47 stopAction = subMenu->addAction("S&top recording", this, SIGNAL(stopRecording()));
48 stopAndDeleteAction = subMenu->addAction("Stop recording and &delete file", this, SIGNAL(stopRecordingAndDelete()));
50 menu = new QMenu;
52 menu->addAction("&About " PROGRAM_NAME, this, SIGNAL(requestAbout()));
53 currentCallAction = menu->addMenu(subMenu);
54 currentCallAction->setVisible(false);
55 menu->addAction("Open &preferences...", this, SIGNAL(requestOpenPreferences()));
56 menu->addAction("&Browse previous calls", this, SIGNAL(requestBrowseCalls()));
57 menu->addSeparator();
58 menu->addAction("&Exit", this, SIGNAL(requestQuit()));
60 setContextMenu(menu);
61 setToolTip(PROGRAM_NAME);
63 connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(activate(QSystemTrayIcon::ActivationReason)));
65 show();
68 TrayIcon::~TrayIcon() {
69 delete menu;
70 delete subMenu;
73 void TrayIcon::setColor(bool color) {
74 setIcon(QIcon(color ? ":/icon.png" : ":/icongray.png"));
78 void TrayIcon::activate(QSystemTrayIcon::ActivationReason) {
79 contextMenu()->popup(QCursor::pos());
82 void TrayIcon::startedCall(const QString &skypeName) {
83 currentCallAction->setText("Call with " + skypeName);
84 currentCallAction->setVisible(true);
85 startAction->setEnabled(true);
86 stopAction->setEnabled(false);
87 stopAndDeleteAction->setEnabled(false);
90 void TrayIcon::stoppedCall() {
91 currentCallAction->setVisible(false);
94 void TrayIcon::startedRecording() {
95 startAction->setEnabled(false);
96 stopAction->setEnabled(true);
97 stopAndDeleteAction->setEnabled(true);
100 void TrayIcon::stoppedRecording() {
101 startAction->setEnabled(true);
102 stopAction->setEnabled(false);
103 stopAndDeleteAction->setEnabled(false);