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>
36 #include "preferences.h"
40 Recorder::Recorder(int argc
, char **argv
) :
41 QApplication(argc
, argv
)
43 recorderInstance
= this;
45 debug("Initializing application");
54 Recorder::~Recorder() {
55 delete preferencesDialog
;
58 void Recorder::setupGUI() {
59 setQuitOnLastWindowClosed(false);
61 trayIcon
= new TrayIcon(this);
62 connect(trayIcon
, SIGNAL(requestQuit()), this, SLOT(quitConfirmation()));
63 connect(trayIcon
, SIGNAL(requestQuitNoConfirmation()), this, SLOT(quit()));
64 connect(trayIcon
, SIGNAL(requestAbout()), this, SLOT(about()));
65 connect(trayIcon
, SIGNAL(requestOpenPreferences()), this, SLOT(openPreferences()));
66 connect(trayIcon
, SIGNAL(requestBrowseCalls()), this, SLOT(browseCalls()));
68 preferencesDialog
= new PreferencesDialog();
69 connect(preferencesDialog
, SIGNAL(finished(int)), this, SLOT(savePreferences()));
71 debug("GUI initialized");
74 void Recorder::setupSkype() {
75 skype
= new Skype(this);
76 connect(skype
, SIGNAL(notify(const QString
&)), this, SLOT(skypeNotify(const QString
&)));
77 connect(skype
, SIGNAL(connected(bool)), this, SLOT(skypeConnected(bool)));
78 connect(skype
, SIGNAL(connectionFailed(const QString
&)), this, SLOT(skypeConnectionFailed(const QString
&)));
80 connect(skype
, SIGNAL(connected(bool)), trayIcon
, SLOT(setColor(bool)));
83 void Recorder::setupCallHandler() {
84 callHandler
= new CallHandler(this, skype
);
86 connect(trayIcon
, SIGNAL(startRecording()), callHandler
, SLOT(startRecording()));
87 connect(trayIcon
, SIGNAL(stopRecording()), callHandler
, SLOT(stopRecording()));
88 connect(trayIcon
, SIGNAL(stopRecordingAndDelete()), callHandler
, SLOT(stopRecordingAndDelete()));
90 connect(callHandler
, SIGNAL(startedCall(const QString
&)), trayIcon
, SLOT(startedCall(const QString
&)));
91 connect(callHandler
, SIGNAL(stoppedCall()), trayIcon
, SLOT(stoppedCall()));
92 connect(callHandler
, SIGNAL(startedRecording()), trayIcon
, SLOT(startedRecording()));
93 connect(callHandler
, SIGNAL(stoppedRecording()), trayIcon
, SLOT(stoppedRecording()));
96 QString
Recorder::getConfigFile() const {
97 return QDir::homePath() + "/.skypecallrecorder.rc";
100 void Recorder::loadPreferences() {
101 preferences
.load(getConfigFile());
102 int c
= preferences
.count();
104 #define X(n, v) preferences.get(#n).setIfNotSet(v);
105 // default preferences
106 X(autorecord
.default, "ask"); // "yes", "ask", "no"
107 X(autorecord
.ask
, ""); // comma separated skypenames to always ask for
108 X(autorecord
.yes
, ""); // comma separated skypenames to always record
109 X(autorecord
.no
, ""); // comma separated skypenames to never record
110 X(output
.path
, "~/Skype Calls");
111 X(output
.pattern
, "Calls with &s/Call with &s, %a %b %d %Y, %H:%M:%S");
112 X(output
.format
, "mp3"); // "mp3" or "wav"
113 X(output
.format
.mp3
.bitrate
, 96);
114 X(output
.channelmode
, "stereo"); // mono, stereo, oerets
115 X(output
.savetags
, true);
118 c
= preferences
.count() - c
;
121 debug(QString("Loading %1 built-in default preference(s)").arg(c
));
124 void Recorder::savePreferences() {
125 preferences
.save(getConfigFile());
126 // TODO: when failure?
129 void Recorder::about() {
131 aboutDialog
= new AboutDialog
;
133 aboutDialog
->raise();
134 aboutDialog
->activateWindow();
137 void Recorder::openPreferences() {
138 debug("Show preferences dialog");
139 preferencesDialog
->show();
140 preferencesDialog
->raise();
141 preferencesDialog
->activateWindow();
144 void Recorder::closePreferences() {
145 debug("Hide preferences dialog");
146 preferencesDialog
->hide();
149 void Recorder::browseCalls() {
151 QStringList arguments
;
153 const char *v
= std::getenv("GNOME_DESKTOP_SESSION_ID");
156 program
= "gnome-open";
158 // otherwise, just launch kfmclient. KDE could be detected via
159 // KDE_FULL_SESSION=true
160 program
= "kfmclient";
164 QString path
= getOutputPath();
167 int ret
= QProcess::execute(program
, arguments
);
170 QMessageBox::information(NULL
, PROGRAM_NAME
, QString("Failed to launch '%1 %2', exit code %3").
171 arg(program
, arguments
.join(" ")).arg(ret
));
175 void Recorder::quitConfirmation() {
176 debug("Request to quit");
181 void Recorder::skypeNotify(const QString
&s
) {
182 QStringList args
= s
.split(' ');
183 QString cmd
= args
.takeFirst();
185 callHandler
->callCmd(args
);
188 void Recorder::skypeConnected(bool conn
) {
190 debug("skype connection established");
192 debug("skype not connected");
195 void Recorder::skypeConnectionFailed(const QString
&reason
) {
196 debug("skype connection failed, reason: " + reason
);
198 QMessageBox::critical(NULL
, PROGRAM_NAME
" - Error",
199 QString("The connection to Skype failed! %1 cannot operate without this "
200 "connection, please make sure you haven't blocked access from within Skype.\n\n"
201 "Internal reason for failure: %2").arg(PROGRAM_NAME
, reason
));
204 void Recorder::debugMessage(const QString
&s
) {
205 std::cout
<< s
.toLocal8Bit().constData() << "\n";
208 int main(int argc
, char **argv
) {
209 Recorder
recorder(argc
, argv
);
211 return recorder
.exec();