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>
34 #include "preferences.h"
38 Recorder::Recorder(int argc
, char **argv
) :
39 QApplication(argc
, argv
),
42 setDebugHandler(this);
44 debug("Initializing application");
52 QTimer::singleShot(0, skype
, SLOT(connectToSkype()));
55 Recorder::~Recorder() {
56 delete preferencesDialog
;
60 void Recorder::setupGUI() {
61 trayIcon
= new TrayIcon(this);
62 setQuitOnLastWindowClosed(false);
65 debugWidget
= new QTextEdit
;
66 debugWidget
->setWindowTitle(PROGRAM_NAME
" - Debug");
67 debugWidget
->setFont(QFont("Arial", 8));
68 //debugWidget->show();
69 for (int i
= 0; i
< savedDebugMessages
.size(); i
++)
70 debugWidget
->append(savedDebugMessages
.at(i
));
71 savedDebugMessages
.clear();
73 preferencesDialog
= new PreferencesDialog();
74 connect(preferencesDialog
, SIGNAL(finished(int)), this, SLOT(saveSettings()));
76 debug("GUI initialized");
79 void Recorder::setupSkype() {
81 connect(skype
, SIGNAL(notify(const QString
&)), this, SLOT(skypeNotify(const QString
&)));
82 connect(skype
, SIGNAL(connected()), this, SLOT(skypeConnected()));
83 connect(skype
, SIGNAL(connectionFailed(const QString
&)), this, SLOT(skypeConnectionFailed(const QString
&)));
86 void Recorder::setupCallHandler() {
87 callHandler
= new CallHandler(skype
);
90 QString
Recorder::getConfigFile() const {
91 return QDir::homePath() + "/.skypecallrecorder.rc";
94 void Recorder::loadSettings() {
95 preferences
.load(getConfigFile());
96 int c
= preferences
.count();
98 #define X(n, v) preferences.get(#n).setIfNotSet(v);
99 // default preferences
100 X(autostartmode
, "none"); // "all", "friends", "none"
101 X(friendlist
, "echo123"); // comma separated list
102 X(exceptionlist
, ""); // comma separated list
103 X(output
.path
, "~/Skype Calls");
104 X(output
.pattern
, "%Y, %B/Skype call with &s, %A %B %d, %Y, %H:%M:%S");
105 X(output
.format
, "mp3"); // "mp3" or "wav"
106 X(output
.format
.mp3
.bitrate
, 96);
107 X(output
.channelmode
, "stereo"); // mono, stereo, oerets
108 X(output
.savetags
, true);
111 c
= preferences
.count() - c
;
114 debug(QString("Loading %1 built-in default preference(s)").arg(c
));
117 void Recorder::saveSettings() {
118 preferences
.save(getConfigFile());
119 // TODO: when failure?
122 void Recorder::about() {
123 QMessageBox::information(NULL
, PROGRAM_NAME
" - About",
124 "This is a place holder for a future about dialog.");
127 void Recorder::openSettings() {
128 debug("Show preferences dialog");
129 preferencesDialog
->show();
132 void Recorder::browseCalls() {
133 QMessageBox::information(NULL
, PROGRAM_NAME
,
134 "This feature not implemented yet.");
137 void Recorder::quitConfirmation() {
138 debug("Request to quit");
143 void Recorder::skypeNotify(const QString
&s
) {
144 QStringList args
= s
.split(' ');
145 QString cmd
= args
.takeFirst();
147 callHandler
->callCmd(args
);
150 void Recorder::skypeConnected() {
151 debug("skype connection established");
154 void Recorder::skypeConnectionFailed(const QString
&reason
) {
155 debug("skype connection failed, reason: " + reason
);
157 QMessageBox::critical(NULL
, PROGRAM_NAME
" - Error",
158 QString("The connection to Skype failed! %1 cannot operate without this "
159 "connection, please make sure you haven't blocked access from within Skype.\n\n"
160 "Internal reason for failure: %2").arg(PROGRAM_NAME
).arg(reason
));
161 // TODO: if skype is not running: "skype will now continually poll for connections, blah blah"
164 void Recorder::debugMessage(const QString
&s
) {
166 debugWidget
->append(s
);
168 savedDebugMessages
.append(s
);
169 std::cout
<< s
.toLocal8Bit().constData() << "\n";
172 int main(int argc
, char **argv
) {
173 Recorder
recorder(argc
, argv
);
175 return recorder
.exec();