• Skip to content
  • Skip to link menu
  • KDE API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • KTp
  • Declarative
conversation.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Lasath Fernando <kde@lasath.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 
20 #include "conversation.h"
21 #include "messages-model.h"
22 
23 #include <TelepathyQt/TextChannel>
24 #include <KDebug>
25 #include "conversation-target.h"
26 
27 #include "channel-delegator.h"
28 
29 class Conversation::ConversationPrivate
30 {
31  public:
32  MessagesModel *messages;
33  ConversationTarget *target;
34  bool valid;
35  Tp::AccountPtr account;
36 };
37 
38 Conversation::Conversation(const Tp::TextChannelPtr &channel,
39  const Tp::AccountPtr &account,
40  QObject *parent) :
41  QObject(parent),
42  d (new ConversationPrivate)
43 {
44  kDebug();
45 
46  d->account = account;
47 
48  d->messages = new MessagesModel(account, this);
49  d->messages->setTextChannel(channel);
50 
51  d->target = new ConversationTarget(account, KTp::ContactPtr::qObjectCast(channel->targetContact()), this);
52 
53  d->valid = channel->isValid();
54  connect(channel.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
55  SLOT(onChannelInvalidated(Tp::DBusProxy*,QString,QString)));
56 }
57 
58 Conversation::Conversation(QObject *parent) : QObject(parent)
59 {
60  kError() << "Conversation should not be created directly. Use ConversationWatcher instead.";
61  Q_ASSERT(false);
62 }
63 
64 MessagesModel* Conversation::messages() const
65 {
66  return d->messages;
67 }
68 
69 ConversationTarget* Conversation::target() const
70 {
71  return d->target;
72 }
73 
74 bool Conversation::isValid()
75 {
76  return d->valid;
77 }
78 
79 void Conversation::onChannelInvalidated(Tp::DBusProxy *proxy, const QString &errorName, const QString &errorMessage)
80 {
81  kDebug() << proxy << errorName << ":" << errorMessage;
82 
83  d->valid = false;
84 
85  Q_EMIT validityChanged(d->valid);
86 }
87 
88 void Conversation::delegateToProperClient()
89 {
90  ChannelDelegator::delegateChannel(d->account, d->messages->textChannel());
91  Q_EMIT conversationDelegated();
92 }
93 
94 void Conversation::requestClose()
95 {
96  kDebug();
97  d->messages->textChannel()->requestClose();
98 }
99 
100 Conversation::~Conversation()
101 {
102  kDebug();
103  requestClose();
104  delete d;
105 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Mar 22 2013 10:58:52 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

ktp-common-internals API Reference

Skip menu "ktp-common-internals API Reference"
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal