Add 2009 to copyright and fix its format
[skype-call-recorder.git] / writer.cpp
blobe6bba62616e48fbcf98c2ff5bd2d7d5360b34197
1 /*
2 Skype Call Recorder
3 Copyright 2008 - 2009 by 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 <QFileInfo>
25 #include <QDir>
27 #include "writer.h"
28 #include "common.h"
30 AudioFileWriter::AudioFileWriter() :
31 sampleRate(0),
32 stereo(false),
33 samplesWritten(0),
34 mustWriteTags(true)
38 AudioFileWriter::~AudioFileWriter() {
39 if (file.isOpen()) {
40 debug("WARNING: AudioFileWriter::~AudioFileWriter(): File has not been closed, closing it now");
41 close();
45 void AudioFileWriter::setTags(const QString &comment, const QDateTime &t) {
46 tagComment = comment;
47 tagTime = t;
48 mustWriteTags = true;
51 bool AudioFileWriter::open(const QString &fn, long sr, bool s) {
52 bool b = QDir().mkpath(QFileInfo(fn).path());
53 if (!b)
54 return false;
56 file.setFileName(fn);
57 sampleRate = sr;
58 stereo = s;
60 debug(QString("Opening '%1'").arg(file.fileName()));
62 return file.open(QIODevice::WriteOnly);
65 void AudioFileWriter::close() {
66 if (!file.isOpen()) {
67 debug("WARNING: AudioFileWriter::close() called, but file not open");
68 return;
71 debug(QString("Closing '%1', wrote %2 samples, %3 seconds").arg(file.fileName()).arg(samplesWritten).arg(samplesWritten / sampleRate));
72 return file.close();