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");
83 if (!preferences
.get("suppress.firstruninformation").toBool())
87 void Recorder::setupSkype() {
88 skype
= new Skype(this);
89 connect(skype
, SIGNAL(notify(const QString
&)), this, SLOT(skypeNotify(const QString
&)));
90 connect(skype
, SIGNAL(connected(bool)), this, SLOT(skypeConnected(bool)));
91 connect(skype
, SIGNAL(connectionFailed(const QString
&)), this, SLOT(skypeConnectionFailed(const QString
&)));
93 connect(skype
, SIGNAL(connected(bool)), trayIcon
, SLOT(setColor(bool)));
96 void Recorder::setupCallHandler() {
97 callHandler
= new CallHandler(this, skype
);
99 connect(trayIcon
, SIGNAL(startRecording(int)), callHandler
, SLOT(startRecording(int)));
100 connect(trayIcon
, SIGNAL(stopRecording(int)), callHandler
, SLOT(stopRecording(int)));
101 connect(trayIcon
, SIGNAL(stopRecordingAndDelete(int)), callHandler
, SLOT(stopRecordingAndDelete(int)));
103 connect(callHandler
, SIGNAL(startedCall(int, const QString
&)), trayIcon
, SLOT(startedCall(int, const QString
&)));
104 connect(callHandler
, SIGNAL(stoppedCall(int)), trayIcon
, SLOT(stoppedCall(int)));
105 connect(callHandler
, SIGNAL(startedRecording(int)), trayIcon
, SLOT(startedRecording(int)));
106 connect(callHandler
, SIGNAL(stoppedRecording(int)), trayIcon
, SLOT(stoppedRecording(int)));
109 QString
Recorder::getConfigFile() const {
110 return QDir::homePath() + "/.skypecallrecorder.rc";
113 void Recorder::loadPreferences() {
114 preferences
.load(getConfigFile());
115 int c
= preferences
.count();
117 #define X(n, v) preferences.get(#n).setIfNotSet(v);
118 // default preferences
119 X(autorecord
.default, "ask"); // "yes", "ask", "no"
120 X(autorecord
.ask
, ""); // comma separated skypenames to always ask for
121 X(autorecord
.yes
, ""); // comma separated skypenames to always record
122 X(autorecord
.no
, ""); // comma separated skypenames to never record
123 X(output
.path
, "~/Skype Calls");
124 X(output
.pattern
, "Calls with &s/Call with &s, %a %b %d %Y, %H:%M:%S");
125 X(output
.format
, "mp3"); // "mp3" or "wav"
126 X(output
.format
.mp3
.bitrate
, 64);
127 X(output
.format
.vorbis
.quality
, 3);
128 X(output
.channelmode
, "stereo"); // mono, stereo, oerets
129 X(output
.savetags
, true);
130 X(suppress
.legalinformation
, false);
131 X(suppress
.firstruninformation
, false);
134 c
= preferences
.count() - c
;
137 debug(QString("Loading %1 built-in default preference(s)").arg(c
));
140 void Recorder::savePreferences() {
141 preferences
.save(getConfigFile());
142 // TODO: when failure?
145 void Recorder::about() {
147 aboutDialog
= new AboutDialog
;
149 aboutDialog
->raise();
150 aboutDialog
->activateWindow();
153 void Recorder::openPreferences() {
154 debug("Show preferences dialog");
155 preferencesDialog
->show();
156 preferencesDialog
->raise();
157 preferencesDialog
->activateWindow();
160 void Recorder::closePreferences() {
161 debug("Hide preferences dialog");
162 preferencesDialog
->hide();
165 void Recorder::browseCalls() {
167 QStringList arguments
;
169 const char *v
= std::getenv("GNOME_DESKTOP_SESSION_ID");
172 program
= "gnome-open";
174 // otherwise, just launch kfmclient. KDE could be detected via
175 // KDE_FULL_SESSION=true
176 program
= "kfmclient";
180 QString path
= getOutputPath();
183 int ret
= QProcess::execute(program
, arguments
);
186 QMessageBox::information(NULL
, PROGRAM_NAME
, QString("Failed to launch '%1 %2', exit code %3").
187 arg(program
, arguments
.join(" ")).arg(ret
));
191 void Recorder::quitConfirmation() {
192 debug("Request to quit");
197 void Recorder::skypeNotify(const QString
&s
) {
198 QStringList args
= s
.split(' ');
199 QString cmd
= args
.takeFirst();
201 callHandler
->callCmd(args
);
204 void Recorder::skypeConnected(bool conn
) {
206 debug("skype connection established");
208 debug("skype not connected");
211 void Recorder::skypeConnectionFailed(const QString
&reason
) {
212 debug("skype connection failed, reason: " + reason
);
214 QMessageBox::critical(NULL
, PROGRAM_NAME
" - Error",
215 QString("The connection to Skype failed! %1 cannot operate without this "
216 "connection, please make sure you haven't blocked access from within Skype.\n\n"
217 "Internal reason for failure: %2").arg(PROGRAM_NAME
, reason
));
220 void Recorder::debugMessage(const QString
&s
) {
221 std::cout
<< s
.toLocal8Bit().constData() << "\n";
224 int main(int argc
, char **argv
) {
225 Recorder
recorder(argc
, argv
);
227 return recorder
.exec();