1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
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) version 3. *
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 ***************************************************************************/
21 #include "corebuffersyncer.h"
24 #include "coresession.h"
25 #include "corenetwork.h"
26 #include "ircchannel.h"
28 CoreBufferSyncer::CoreBufferSyncer(CoreSession *parent)
29 : BufferSyncer(Core::bufferLastSeenMsgIds(parent->user()), parent),
34 void CoreBufferSyncer::requestSetLastSeenMsg(BufferId buffer, const MsgId &msgId) {
35 if(setLastSeenMsg(buffer, msgId))
36 dirtyBuffers << buffer;
39 void CoreBufferSyncer::storeDirtyIds() {
40 UserId userId = _coreSession->user();
42 foreach(BufferId bufferId, dirtyBuffers) {
43 msgId = lastSeenMsg(bufferId);
45 Core::setBufferLastSeenMsg(userId, bufferId, msgId);
50 void CoreBufferSyncer::removeBuffer(BufferId bufferId) {
51 BufferInfo bufferInfo = Core::getBufferInfo(_coreSession->user(), bufferId);
52 if(!bufferInfo.isValid()) {
53 qWarning() << "CoreBufferSyncer::removeBuffer(): invalid BufferId:" << bufferId << "for User:" << _coreSession->user();
57 if(bufferInfo.type() == BufferInfo::StatusBuffer) {
58 qWarning() << "CoreBufferSyncer::removeBuffer(): Status Buffers cannot be removed!";
62 if(bufferInfo.type() == BufferInfo::ChannelBuffer) {
63 CoreNetwork *net = _coreSession->network(bufferInfo.networkId());
65 qWarning() << "CoreBufferSyncer::removeBuffer(): Received BufferInfo with unknown networkId!";
68 IrcChannel *chan = net->ircChannel(bufferInfo.bufferName());
70 qWarning() << "CoreBufferSyncer::removeBuffer(): Unable to remove Buffer for joined Channel:" << bufferInfo.bufferName();
74 if(Core::removeBuffer(_coreSession->user(), bufferId))
75 BufferSyncer::removeBuffer(bufferId);
78 void CoreBufferSyncer::renameBuffer(BufferId bufferId, QString newName) {
79 BufferInfo bufferInfo = Core::getBufferInfo(_coreSession->user(), bufferId);
80 if(!bufferInfo.isValid()) {
81 qWarning() << "CoreBufferSyncer::renameBuffer(): invalid BufferId:" << bufferId << "for User:" << _coreSession->user();
85 if(bufferInfo.type() != BufferInfo::QueryBuffer) {
86 qWarning() << "CoreBufferSyncer::renameBuffer(): only QueryBuffers can be renamed" << bufferId;
90 if(Core::renameBuffer(_coreSession->user(), bufferId, newName))
91 BufferSyncer::renameBuffer(bufferId, newName);
94 void CoreBufferSyncer::mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2) {
95 BufferInfo bufferInfo1 = Core::getBufferInfo(_coreSession->user(), bufferId1);
96 BufferInfo bufferInfo2 = Core::getBufferInfo(_coreSession->user(), bufferId2);
97 if(!bufferInfo1.isValid() || !bufferInfo2.isValid()) {
98 qWarning() << "CoreBufferSyncer::mergeBufferPermanently(): invalid BufferIds:" << bufferId1 << bufferId2 << "for User:" << _coreSession->user();
102 if(bufferInfo1.type() != BufferInfo::QueryBuffer || bufferInfo2.type() != BufferInfo::QueryBuffer) {
103 qWarning() << "CoreBufferSyncer::mergeBufferPermanently(): only QueryBuffers can be merged!" << bufferId1 << bufferId2;
107 if(Core::mergeBuffersPermanently(_coreSession->user(), bufferId1, bufferId2)) {
108 BufferSyncer::mergeBuffersPermanently(bufferId1, bufferId2);