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>
35 #include "preferences.h"
39 Recorder::Recorder(int argc
, char **argv
) :
40 QApplication(argc
, argv
)
42 recorderInstance
= this;
44 debug("Initializing application");
53 Recorder::~Recorder() {
54 delete preferencesDialog
;
57 void Recorder::setupGUI() {
58 setQuitOnLastWindowClosed(false);
60 trayIcon
= new TrayIcon(this);
61 connect(trayIcon
, SIGNAL(requestQuit()), this, SLOT(quitConfirmation()));
62 connect(trayIcon
, SIGNAL(requestQuitNoConfirmation()), this, SLOT(quit()));
63 connect(trayIcon
, SIGNAL(requestAbout()), this, SLOT(about()));
64 connect(trayIcon
, SIGNAL(requestOpenPreferences()), this, SLOT(openPreferences()));
65 connect(trayIcon
, SIGNAL(requestBrowseCalls()), this, SLOT(browseCalls()));
67 preferencesDialog
= new PreferencesDialog();
68 connect(preferencesDialog
, SIGNAL(finished(int)), this, SLOT(savePreferences()));
70 debug("GUI initialized");
73 void Recorder::setupSkype() {
74 skype
= new Skype(this);
75 connect(skype
, SIGNAL(notify(const QString
&)), this, SLOT(skypeNotify(const QString
&)));
76 connect(skype
, SIGNAL(connected()), this, SLOT(skypeConnected()));
77 connect(skype
, SIGNAL(connectionFailed(const QString
&)), this, SLOT(skypeConnectionFailed(const QString
&)));
80 void Recorder::setupCallHandler() {
81 callHandler
= new CallHandler(this, skype
);
83 connect(trayIcon
, SIGNAL(startRecording()), callHandler
, SLOT(startRecording()));
84 connect(trayIcon
, SIGNAL(stopRecording()), callHandler
, SLOT(stopRecording()));
85 connect(trayIcon
, SIGNAL(stopRecordingAndDelete()), callHandler
, SLOT(stopRecordingAndDelete()));
87 connect(callHandler
, SIGNAL(startedCall(const QString
&)), trayIcon
, SLOT(startedCall(const QString
&)));
88 connect(callHandler
, SIGNAL(stoppedCall()), trayIcon
, SLOT(stoppedCall()));
89 connect(callHandler
, SIGNAL(startedRecording()), trayIcon
, SLOT(startedRecording()));
90 connect(callHandler
, SIGNAL(stoppedRecording()), trayIcon
, SLOT(stoppedRecording()));
93 QString
Recorder::getConfigFile() const {
94 return QDir::homePath() + "/.skypecallrecorder.rc";
97 void Recorder::loadPreferences() {
98 preferences
.load(getConfigFile());
99 int c
= preferences
.count();
101 #define X(n, v) preferences.get(#n).setIfNotSet(v);
102 // default preferences
103 X(autorecord
.default, "ask"); // "yes", "ask", "no"
104 X(autorecord
.ask
, ""); // comma separated skypenames to always ask for
105 X(autorecord
.yes
, ""); // comma separated skypenames to always record
106 X(autorecord
.no
, ""); // comma separated skypenames to never record
107 X(output
.path
, "~/Skype Calls");
108 X(output
.pattern
, "%Y, %B/Skype call with &s, %A %B %d, %Y, %H:%M:%S");
109 X(output
.format
, "mp3"); // "mp3" or "wav"
110 X(output
.format
.mp3
.bitrate
, 96);
111 X(output
.channelmode
, "stereo"); // mono, stereo, oerets
112 X(output
.savetags
, true);
115 c
= preferences
.count() - c
;
118 debug(QString("Loading %1 built-in default preference(s)").arg(c
));
121 void Recorder::savePreferences() {
122 preferences
.save(getConfigFile());
123 // TODO: when failure?
126 void Recorder::about() {
127 QMessageBox::information(NULL
, PROGRAM_NAME
" - About",
128 "This is a place holder for a future about dialog.");
131 void Recorder::openPreferences() {
132 debug("Show preferences dialog");
133 preferencesDialog
->show();
134 preferencesDialog
->raise();
135 preferencesDialog
->activateWindow();
138 void Recorder::closePreferences() {
139 debug("Hide preferences dialog");
140 preferencesDialog
->hide();
143 void Recorder::browseCalls() {
145 QStringList arguments
;
147 const char *v
= std::getenv("GNOME_DESKTOP_SESSION_ID");
150 program
= "gnome-open";
152 // otherwise, just launch kfmclient. KDE could be detected via
153 // KDE_FULL_SESSION=true
154 program
= "kfmclient";
158 QString path
= getOutputPath();
161 int ret
= QProcess::execute(program
, arguments
);
164 QMessageBox::information(NULL
, PROGRAM_NAME
, QString("Failed to launch '%1 %2', exit code %3").
165 arg(program
, arguments
.join(" ")).arg(ret
));
169 void Recorder::quitConfirmation() {
170 debug("Request to quit");
175 void Recorder::skypeNotify(const QString
&s
) {
176 QStringList args
= s
.split(' ');
177 QString cmd
= args
.takeFirst();
179 callHandler
->callCmd(args
);
182 void Recorder::skypeConnected() {
183 debug("skype connection established");
186 void Recorder::skypeConnectionFailed(const QString
&reason
) {
187 debug("skype connection failed, reason: " + reason
);
189 QMessageBox::critical(NULL
, PROGRAM_NAME
" - Error",
190 QString("The connection to Skype failed! %1 cannot operate without this "
191 "connection, please make sure you haven't blocked access from within Skype.\n\n"
192 "Internal reason for failure: %2").arg(PROGRAM_NAME
, reason
));
193 // TODO: if skype is not running: "skype will now continually poll for connections, blah blah"
196 void Recorder::debugMessage(const QString
&s
) {
197 std::cout
<< s
.toLocal8Bit().constData() << "\n";
200 int main(int argc
, char **argv
) {
201 Recorder
recorder(argc
, argv
);
203 return recorder
.exec();