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

Nepomuk-Core

  • KTp
  • Widgets
contact-grid-dialog.cpp
Go to the documentation of this file.
1 /*
2  * Contact Chooser Dialog
3  *
4  * Copyright (C) 2011 David Edmundson <kde@davidedmundson.co.uk>
5  * Copyright (C) 2012 Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 
23 #include "contact-grid-dialog.h"
24 
25 #include <KDE/KLineEdit>
26 #include <KDE/KPushButton>
27 #include <KDE/KLocalizedString>
28 #include <KDE/KDebug>
29 
30 #include <TelepathyQt/AccountManager>
31 #include <TelepathyQt/AccountFactory>
32 #include <TelepathyQt/PendingReady>
33 #include <TelepathyQt/PendingChannelRequest>
34 
35 #include <KTp/debug.h>
36 #include <KTp/Models/contacts-list-model.h>
37 #include <KTp/Models/contacts-filter-model.h>
38 #include <KTp/Widgets/contact-grid-widget.h>
39 #include <KTp/contact-factory.h>
40 
41 
42 
43 class KTp::ContactGridDialog::Private
44 {
45 public:
46  Private(KTp::ContactGridDialog *parent) :
47  q(parent),
48  contactsModel(0),
49  account(0),
50  contact(0)
51  {
52  }
53 
54  KTp::ContactGridDialog * const q;
55 
56  Tp::AccountManagerPtr accountManager;
57  KTp::ContactsListModel *contactsModel;
58  KTp::ContactGridWidget *contactGridWidget;
59  Tp::AccountPtr account;
60  Tp::ContactPtr contact;
61 
62 public Q_SLOTS:
63  void _k_onAccountManagerReady();
64  void _k_onOkClicked();
65  void _k_onChanged();
66 };
67 
68 
69 void KTp::ContactGridDialog::Private::_k_onAccountManagerReady()
70 {
71  kDebug() << "Account manager is ready";
72  contactsModel->setAccountManager(accountManager);
73 }
74 
75 void KTp::ContactGridDialog::Private::_k_onOkClicked()
76 {
77  // don't do anytghing if no contact has been selected
78  if (!contactGridWidget->hasSelection()) {
79  // show message box?
80  return;
81  }
82 
83  contact = contactGridWidget->selectedContact();
84  account = contactGridWidget->selectedAccount();
85 
86  if (account.isNull()) {
87  kWarning() << "Account is NULL";
88  } else if (contact.isNull()) {
89  kWarning() << "Contact is NULL";
90  } else {
91  kDebug() << "Account is: " << account->displayName();
92  kDebug() << "Contact is: " << contact->alias();
93  }
94 }
95 
96 void KTp::ContactGridDialog::Private::_k_onChanged()
97 {
98  q->button(KDialog::Ok)->setEnabled(contactGridWidget->hasSelection());
99 }
100 
101 
102 
103 KTp::ContactGridDialog::ContactGridDialog(QWidget *parent) :
104  KDialog(parent),
105  d(new Private(this))
106 {
107  resize(500,450);
108 
109  Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(),
110  Tp::Features() << Tp::Account::FeatureCore
111  << Tp::Account::FeatureAvatar
112  << Tp::Account::FeatureProtocolInfo
113  << Tp::Account::FeatureProfile
114  << Tp::Account::FeatureCapabilities);
115 
116  Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(),
117  Tp::Features() << Tp::Connection::FeatureCore
118  << Tp::Connection::FeatureRosterGroups
119  << Tp::Connection::FeatureRoster
120  << Tp::Connection::FeatureSelfContact);
121 
122  Tp::ContactFactoryPtr contactFactory = KTp::ContactFactory::create(Tp::Features() << Tp::Contact::FeatureAlias
123  << Tp::Contact::FeatureAvatarData
124  << Tp::Contact::FeatureSimplePresence
125  << Tp::Contact::FeatureCapabilities);
126 
127  Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
128 
129  d->accountManager = Tp::AccountManager::create(QDBusConnection::sessionBus(),
130  accountFactory,
131  connectionFactory,
132  channelFactory,
133  contactFactory);
134 
135  d->contactsModel = new KTp::ContactsListModel(this);
136  connect(d->accountManager->becomeReady(), SIGNAL(finished(Tp::PendingOperation*)), SLOT(_k_onAccountManagerReady()));
137 
138 
139  d->contactGridWidget = new KTp::ContactGridWidget(d->contactsModel, this);
140  d->contactGridWidget->contactFilterLineEdit()->setClickMessage(i18n("Search in Contacts..."));
141  d->contactGridWidget->filter()->setPresenceTypeFilterFlags(KTp::ContactsFilterModel::ShowOnlyConnected);
142 
143  setMainWidget(d->contactGridWidget);
144 
145  connect(d->contactGridWidget,
146  SIGNAL(selectionChanged(Tp::AccountPtr,Tp::ContactPtr)),
147  SLOT(_k_onChanged()));
148 
149  button(KDialog::Ok)->setDisabled(true);
150 
151  connect(this, SIGNAL(okClicked()), SLOT(_k_onOkClicked()));
152  connect(this, SIGNAL(rejected()), SLOT(close()));
153 }
154 
155 KTp::ContactGridDialog::~ContactGridDialog()
156 {
157  delete d;
158 }
159 
160 Tp::AccountPtr KTp::ContactGridDialog::account()
161 {
162  return d->account;
163 }
164 
165 Tp::ContactPtr KTp::ContactGridDialog::contact()
166 {
167  return d->contact;
168 }
169 
170 KTp::ContactsFilterModel* KTp::ContactGridDialog::filter() const
171 {
172  return d->contactGridWidget->filter();
173 }
174 
175 
176 #include "contact-grid-dialog.moc"
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