conversation.cpp 1.79 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
    Copyright (C) 2011  Lasath Fernando <kde@lasath.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/


#include "conversation.h"
21
#include "messages-model.h"
22 23

#include <TelepathyQt4/TextChannel>
Lasath Fernando's avatar
Lasath Fernando committed
24
#include <KDebug>
25
#include "conversation-target.h"
26

Lasath Fernando's avatar
Lasath Fernando committed
27 28
class Conversation::ConversationPrivate
{
29
public:
30 31
    MessagesModel* model;
    ConversationTarget* target;
Lasath Fernando's avatar
Lasath Fernando committed
32
    Tp::AccountPtr account;
33 34
};

35 36
Conversation::Conversation(Tp::TextChannelPtr channel, Tp::AccountPtr account) :
        d (new ConversationPrivate)
37
{
Lasath Fernando's avatar
Lasath Fernando committed
38 39
    kDebug();

40 41
    d->model = new MessagesModel();
    d->model->setTextChannel(channel);
42

43
    d->target = new ConversationTarget(channel->targetContact());
44

45
    d->account = account;
Lasath Fernando's avatar
Lasath Fernando committed
46 47
}

48
Conversation::Conversation(QObject* parent) : QObject(parent)
Lasath Fernando's avatar
Lasath Fernando committed
49
{
50
    kError() << "Conversation should not be created directly. Use ConversationWatcher instead.";
51
    Q_ASSERT(false);
52 53
}

54
MessagesModel* Conversation::model() const
55
{
Lasath Fernando's avatar
Lasath Fernando committed
56
    return d->model;
57 58
}

59
ConversationTarget* Conversation::target() const
60
{
61
    return d->target;
62 63
}

64 65
Conversation::~Conversation()
{
Lasath Fernando's avatar
Lasath Fernando committed
66
    kDebug();
Lasath Fernando's avatar
Lasath Fernando committed
67
    delete d->model;
68 69
    delete d->target;
    delete d;
70
}