1 /***************************************************************************
2 * Copyright (C) 2005-07 by The Quassel Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
25 // This is kept here for importing the old file-based backlog.
29 void Storage::importOldBacklog() {
30 qDebug() << "Deleting backlog database...";
31 logDb.exec(QString("DELETE FROM 'Backlog$%1$' WHERE SenderId != '$VERSION$'").arg(user));
32 logDb.exec(QString("DELETE FROM 'Senders$%1$'").arg(user));
33 logDb.exec(QString("DELETE FROM 'Buffers$%1$'").arg(user));
34 nextMsgId = 1; nextBufferId = 1; nextSenderId = 1;
35 qDebug() << "Importing old backlog files...";
37 if(!backLogEnabledOld) return;
39 qDebug() << "Backlog successfully imported, you have to restart Quassel now!";
45 // file name scheme: quassel-backlog-2006-29-10.bin
46 void Storage::initBackLogOld(UserId uid) {
47 backLogDir = QDir(Global::quasselDir + "/backlog");
48 if(!backLogDir.exists()) {
49 qWarning(QString("Creating backlog directory \"%1\"...").arg(backLogDir.absolutePath()).toAscii());
50 if(!backLogDir.mkpath(backLogDir.absolutePath())) {
51 qWarning(QString("Could not create backlog directory! Disabling logging...").toAscii());
52 backLogEnabledOld = false;
57 //if(!backLogDir.isReadable()) {
58 // qWarning(QString("Cannot read directory \"%1\". Disabling logging...").arg(backLogDir.absolutePath()).toAscii());
59 // backLogEnabled = false;
62 QStringList networks = backLogDir.entryList(QDir::Dirs|QDir::NoDotAndDotDot|QDir::Readable, QDir::Name);
63 foreach(QString net, networks) {
64 QDir dir(backLogDir.absolutePath() + "/" + net);
66 qWarning(QString("Could not change to directory \"%1\"!").arg(dir.absolutePath()).toAscii());
69 QStringList logs = dir.entryList(QStringList("quassel-backlog-*.bin"), QDir::Files|QDir::Readable, QDir::Name);
70 foreach(QString name, logs) {
71 QFile f(dir.absolutePath() + "/" + name);
72 if(!f.open(QIODevice::ReadOnly)) {
73 qWarning(QString("Could not open \"%1\" for reading!").arg(f.fileName()).toAscii());
77 in.setVersion(QDataStream::Qt_4_2);
78 QByteArray verstring; quint8 vernum; in >> verstring >> vernum;
79 if(verstring != BACKLOG_STRING) {
80 qWarning(QString("\"%1\" is not a Quassel backlog file!").arg(f.fileName()).toAscii());
83 if(vernum != BACKLOG_FORMAT) {
84 qWarning(QString("\"%1\": Version mismatch!").arg(f.fileName()).toAscii());
87 qDebug() << "Reading backlog from" << f.fileName();
88 logFileDates[net] = QDate::fromString(f.fileName(),
89 QString("'%1/quassel-backlog-'yyyy-MM-dd'.bin'").arg(dir.absolutePath()));
90 if(!logFileDates[net].isValid()) {
91 qWarning(QString("\"%1\" has an invalid file name!").arg(f.fileName()).toAscii());
96 QByteArray s, m, targ;
97 in >> ts >> t >> f >> targ >> s >> m;
98 QString target = QString::fromUtf8(targ);
99 QString sender = QString::fromUtf8(s);
100 QString text = QString::fromUtf8(m);
102 if((f & Message::PrivMsg) && !(f & Message::Self)) {
103 id = getBufferId(uid, net, sender);
105 id = getBufferId(uid, net, target);
107 Message msg(QDateTime::fromTime_t(ts), id, (Message::Type)t, text, sender, f);
108 //backLog[net].append(m);
114 backLogEnabledOld = true;