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
26 #include <QMessageBox>
37 #include "preferences.h"
41 Recorder::Recorder(int argc
, char **argv
) :
42 QApplication(argc
, argv
),
43 preferencesDialog(NULL
)
45 recorderInstance
= this;
47 debug("Initializing application");
49 // check for already running instance
50 if (!lockFile
.lock(QDir::homePath() + "/.skypecallrecorder.lock")) {
51 debug("Other instance is running");
52 QTimer::singleShot(0, this, SLOT(quit()));
63 Recorder::~Recorder() {
64 delete preferencesDialog
;
67 void Recorder::setupGUI() {
68 setWindowIcon(QIcon(":/icon.png"));
69 setQuitOnLastWindowClosed(false);
71 trayIcon
= new TrayIcon(this);
72 connect(trayIcon
, SIGNAL(requestQuit()), this, SLOT(quitConfirmation()));
73 connect(trayIcon
, SIGNAL(requestQuitNoConfirmation()), this, SLOT(quit()));
74 connect(trayIcon
, SIGNAL(requestAbout()), this, SLOT(about()));
75 connect(trayIcon
, SIGNAL(requestOpenPreferences()), this, SLOT(openPreferences()));
76 connect(trayIcon
, SIGNAL(requestBrowseCalls()), this, SLOT(browseCalls()));
78 preferencesDialog
= new PreferencesDialog();
79 connect(preferencesDialog
, SIGNAL(finished(int)), this, SLOT(savePreferences()));
81 debug("GUI initialized");
84 void Recorder::setupSkype() {
85 skype
= new Skype(this);
86 connect(skype
, SIGNAL(notify(const QString
&)), this, SLOT(skypeNotify(const QString
&)));
87 connect(skype
, SIGNAL(connected(bool)), this, SLOT(skypeConnected(bool)));
88 connect(skype
, SIGNAL(connectionFailed(const QString
&)), this, SLOT(skypeConnectionFailed(const QString
&)));
90 connect(skype
, SIGNAL(connected(bool)), trayIcon
, SLOT(setColor(bool)));
93 void Recorder::setupCallHandler() {
94 callHandler
= new CallHandler(this, skype
);
96 connect(trayIcon
, SIGNAL(startRecording(int)), callHandler
, SLOT(startRecording(int)));
97 connect(trayIcon
, SIGNAL(stopRecording(int)), callHandler
, SLOT(stopRecording(int)));
98 connect(trayIcon
, SIGNAL(stopRecordingAndDelete(int)), callHandler
, SLOT(stopRecordingAndDelete(int)));
100 connect(callHandler
, SIGNAL(startedCall(int, const QString
&)), trayIcon
, SLOT(startedCall(int, const QString
&)));
101 connect(callHandler
, SIGNAL(stoppedCall(int)), trayIcon
, SLOT(stoppedCall(int)));
102 connect(callHandler
, SIGNAL(startedRecording(int)), trayIcon
, SLOT(startedRecording(int)));
103 connect(callHandler
, SIGNAL(stoppedRecording(int)), trayIcon
, SLOT(stoppedRecording(int)));
106 QString
Recorder::getConfigFile() const {
107 return QDir::homePath() + "/.skypecallrecorder.rc";
110 void Recorder::loadPreferences() {
111 preferences
.load(getConfigFile());
112 int c
= preferences
.count();
114 #define X(n, v) preferences.get(#n).setIfNotSet(v);
115 // default preferences
116 X(autorecord
.default, "ask"); // "yes", "ask", "no"
117 X(autorecord
.ask
, ""); // comma separated skypenames to always ask for
118 X(autorecord
.yes
, ""); // comma separated skypenames to always record
119 X(autorecord
.no
, ""); // comma separated skypenames to never record
120 X(output
.path
, "~/Skype Calls");
121 X(output
.pattern
, "Calls with &s/Call with &s, %a %b %d %Y, %H:%M:%S");
122 X(output
.format
, "mp3"); // "mp3" or "wav"
123 X(output
.format
.mp3
.bitrate
, 96);
124 X(output
.channelmode
, "stereo"); // mono, stereo, oerets
125 X(output
.savetags
, true);
126 X(suppress
.legalinformation
, false);
129 c
= preferences
.count() - c
;
132 debug(QString("Loading %1 built-in default preference(s)").arg(c
));
135 void Recorder::savePreferences() {
136 preferences
.save(getConfigFile());
137 // TODO: when failure?
140 void Recorder::about() {
142 aboutDialog
= new AboutDialog
;
144 aboutDialog
->raise();
145 aboutDialog
->activateWindow();
148 void Recorder::openPreferences() {
149 debug("Show preferences dialog");
150 preferencesDialog
->show();
151 preferencesDialog
->raise();
152 preferencesDialog
->activateWindow();
155 void Recorder::closePreferences() {
156 debug("Hide preferences dialog");
157 preferencesDialog
->hide();
160 void Recorder::browseCalls() {
162 QStringList arguments
;
164 const char *v
= std::getenv("GNOME_DESKTOP_SESSION_ID");
167 program
= "gnome-open";
169 // otherwise, just launch kfmclient. KDE could be detected via
170 // KDE_FULL_SESSION=true
171 program
= "kfmclient";
175 QString path
= getOutputPath();
178 int ret
= QProcess::execute(program
, arguments
);
181 QMessageBox::information(NULL
, PROGRAM_NAME
, QString("Failed to launch '%1 %2', exit code %3").
182 arg(program
, arguments
.join(" ")).arg(ret
));
186 void Recorder::quitConfirmation() {
187 debug("Request to quit");
192 void Recorder::skypeNotify(const QString
&s
) {
193 QStringList args
= s
.split(' ');
194 QString cmd
= args
.takeFirst();
196 callHandler
->callCmd(args
);
199 void Recorder::skypeConnected(bool conn
) {
201 debug("skype connection established");
203 debug("skype not connected");
206 void Recorder::skypeConnectionFailed(const QString
&reason
) {
207 debug("skype connection failed, reason: " + reason
);
209 QMessageBox::critical(NULL
, PROGRAM_NAME
" - Error",
210 QString("The connection to Skype failed! %1 cannot operate without this "
211 "connection, please make sure you haven't blocked access from within Skype.\n\n"
212 "Internal reason for failure: %2").arg(PROGRAM_NAME
, reason
));
215 void Recorder::debugMessage(const QString
&s
) {
216 std::cout
<< s
.toLocal8Bit().constData() << "\n";
219 int main(int argc
, char **argv
) {
220 Recorder
recorder(argc
, argv
);
222 return recorder
.exec();