conversation.cpp 2.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
    <one line to give the library's name and an idea of what it does.>
    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"
#include "conversation-model.h"
23 24

#include <TelepathyQt4/TextChannel>
Lasath Fernando's avatar
Lasath Fernando committed
25
#include <KDebug>
26
#include "chat-widget.h"
27

Lasath Fernando's avatar
Lasath Fernando committed
28 29
class Conversation::ConversationPrivate
{
30
public:
Lasath Fernando's avatar
Lasath Fernando committed
31 32
    ConversationModel* model;
    Tp::AccountPtr account;
33
    Tp::ContactPtr contact;
34 35
};

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

Lasath Fernando's avatar
Lasath Fernando committed
41 42
    d->model = new ConversationModel();
    d->model->setTextChannel ( channel );
43

Lasath Fernando's avatar
Lasath Fernando committed
44
    d->account = account;
45 46
    d->contact = channel->targetContact();

47
    connect(d->contact.constData(), SIGNAL(aliasChanged(QString)), SIGNAL(nickChanged(QString)));
48 49
    connect(d->contact.constData(), SIGNAL(avatarDataChanged(Tp::AvatarData)), SLOT(onAvatarDataChanged(Tp::AvatarData)));
    connect(d->contact.constData(), SIGNAL(presenceChanged(Tp::Presence)), SLOT(onPresenceChanged(Tp::Presence)));
Lasath Fernando's avatar
Lasath Fernando committed
50 51 52 53
}

Conversation::Conversation ( QObject* parent ) : QObject ( parent )
{
54
    kError() << "Conversation should not be created directly. Use ConversationWatcher instead.";
55 56
}

Lasath Fernando's avatar
Lasath Fernando committed
57
ConversationModel* Conversation::model() const
58
{
Lasath Fernando's avatar
Lasath Fernando committed
59
    return d->model;
60 61
}

62
QIcon Conversation::avatar() const
63
{
64
    return QIcon(d->contact->avatarData().fileName);
65 66 67 68 69 70 71
}

QString Conversation::nick() const
{
    return d->contact->alias();
}

72
QIcon Conversation::presenceIcon() const
73 74 75 76
{
    return ChatWidget::iconForPresence(d->contact->presence().type());
}

77 78
Conversation::~Conversation()
{
Lasath Fernando's avatar
Lasath Fernando committed
79
    kDebug();
Lasath Fernando's avatar
Lasath Fernando committed
80
    delete d->model;
81 82
}

83 84 85 86 87 88 89 90 91
void Conversation::onPresenceChanged ( Tp::Presence )
{
    Q_EMIT presenceIconChanged(presenceIcon());
}

void Conversation::onAvatarDataChanged ( Tp::AvatarData )
{
    Q_EMIT avatarChanged(avatar());
}