Support writing to mp3 files
[skype-call-recorder.git] / recorder.cpp
blobad8079c490e90f0e44b25b672cdf8ac549b033e3
1 /*
2 Skype Call Recorder
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
21 http://www.fsf.org/
24 #include <iostream>
26 #include <QMessageBox>
27 #include <QTextEdit>
28 #include <QTimer>
29 #include <QDir>
31 #include "recorder.h"
32 #include "common.h"
33 #include "trayicon.h"
34 #include "preferences.h"
35 #include "skype.h"
36 #include "call.h"
38 Recorder::Recorder(int argc, char **argv) :
39 QApplication(argc, argv),
40 debugWidget(NULL)
42 setDebugHandler(this);
44 debug("Initializing application");
46 loadSettings();
48 setupGUI();
49 setupSkype();
50 setupCallHandler();
52 QTimer::singleShot(0, skype, SLOT(connectToSkype()));
55 Recorder::~Recorder() {
56 delete preferencesDialog;
57 delete debugWidget;
60 void Recorder::setupGUI() {
61 trayIcon = new TrayIcon(this);
62 setQuitOnLastWindowClosed(false);
64 // TODO: temporary
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() {
80 skype = new Skype;
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);
109 #undef X
111 c = preferences.count() - c;
113 if (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");
139 saveSettings();
140 quit();
143 void Recorder::skypeNotify(const QString &s) {
144 QStringList args = s.split(' ');
145 QString cmd = args.takeFirst();
146 if (cmd == "CALL")
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) {
165 if (debugWidget)
166 debugWidget->append(s);
167 else
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();