• Skip to content
  • Skip to link menu
KDE API Documentation - persondetailsview.cpp Source File (KPeople)
  • KDE Home
  • Contact Us
 

KPeople

  • frameworks
  • kpeople
  • src
  • widgets
persondetailsview.cpp
1 /*
2  Copyright (C) 2011 Martin Klapetek <mklapetek@kde.org>
3  Copyright (C) 2013 David Edmundson <davidedmundsonk@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library 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 GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #include "persondetailsview.h"
21 
22 #include <QFormLayout>
23 #include <QLabel>
24 #include <QVBoxLayout>
25 #include <QDebug>
26 #include <QList>
27 #include <QStandardPaths>
28 
29 #include <KLocalizedString>
30 #include <KService>
31 #include <KServiceTypeTrader>
32 #include <KPluginInfo>
33 #include <KPluginLoader>
34 #include <KPluginFactory>
35 
36 #include "abstractfieldwidgetfactory.h"
37 #include "plugins/emaildetailswidget.h"
38 #include "global.h"
39 
40 #include "ui_person-details-presentation.h"
41 
42 namespace KPeople
43 {
44 
45 class PersonDetailsViewPrivate
46 {
47 public:
48  PersonData *m_person;
49  Ui::PersonDetailsPresentation *m_personDetailsPresentation;
50  QWidget *m_mainWidget;
51  QList<AbstractFieldWidgetFactory *> m_plugins;
52 };
53 }
54 
55 using namespace KPeople;
56 
57 class CoreFieldsPlugin : public AbstractFieldWidgetFactory
58 {
59 public:
60  CoreFieldsPlugin(const QString &field);
61  virtual ~CoreFieldsPlugin();
62  virtual QString label() const;
63  virtual int sortWeight() const;
64  virtual QWidget *createDetailsWidget(const PersonData &person, QWidget *parent) const;
65 private:
66  QString m_field;
67 };
68 
69 CoreFieldsPlugin::CoreFieldsPlugin(const QString &field):
70  m_field(field)
71 {
72 }
73 
74 CoreFieldsPlugin::~CoreFieldsPlugin()
75 {
76 
77 }
78 
79 QString CoreFieldsPlugin::label() const
80 {
81 #warning fixme, should be made user-visible somehow
82  return m_field;
83 }
84 
85 int CoreFieldsPlugin::sortWeight() const
86 {
87  return 1;
88 }
89 
90 QWidget *CoreFieldsPlugin::createDetailsWidget(const PersonData &person, QWidget *parent) const
91 {
92 // we have a plugin specific for e-mails.
93  if (m_field == QLatin1String("email")) {
94  return 0;
95  }
96 
97  const QString &text = person.contactCustomProperty(m_field).toString();
98  if (text.isEmpty()) {
99  return 0;
100  }
101  return new QLabel(text, parent);
102 }
103 
104 PersonDetailsView::PersonDetailsView(QWidget *parent)
105  : QWidget(parent),
106  d_ptr(new PersonDetailsViewPrivate())
107 {
108  Q_D(PersonDetailsView);
109  setLayout(new QVBoxLayout(this));
110  d->m_mainWidget = new QWidget(this);
111  d->m_person = 0;
112 
113  QWidget *details = new QWidget();
114  d->m_personDetailsPresentation = new Ui::PersonDetailsPresentation();
115  d->m_personDetailsPresentation->setupUi(details);
116  layout()->addWidget(details);
117  layout()->addWidget(d->m_mainWidget);
118  layout()->addItem(new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding));
119 
120  //create plugins
121 #warning figure out a way to list properties
122  QStringList fields { QStringLiteral("name"), QStringLiteral("all-email") };
123  Q_FOREACH (const QString &field, fields) {
124  d->m_plugins << new CoreFieldsPlugin(field);
125  }
126 
127  d->m_plugins << new EmailFieldsPlugin();
128 
129  // load every KPeopleWidgets Plugin
130  KService::List pluginList = KServiceTypeTrader::self()->query(QLatin1String("KPeopleWidgets/Plugin"));
131 
132  QList<KPluginInfo> plugins = KPluginInfo::fromServices(pluginList);
133 
134  Q_FOREACH (const KPluginInfo &p, plugins) {
135  QString error;
136  AbstractFieldWidgetFactory *f = p.service()->createInstance<AbstractFieldWidgetFactory>(this, QVariantList(), &error);
137  if (f) {
138  d->m_plugins << f;
139  }
140  }
141 
142  //TODO Sort plugins
143 }
144 
145 PersonDetailsView::~PersonDetailsView()
146 {
147  delete d_ptr;
148 }
149 
150 void PersonDetailsView::setPerson(PersonData *person)
151 {
152  Q_D(PersonDetailsView);
153  if (d->m_person) {
154  disconnect(d->m_person, SIGNAL(dataChanged()), this, SLOT(reload()));
155  }
156 
157  d->m_person = person;
158  connect(d->m_person, SIGNAL(dataChanged()), this, SLOT(reload()));
159  reload();
160 }
161 
162 // void PersonDetailsView::setPersonsModel(PersonsModel *model)
163 // {
164 // Q_D(PersonDetailsView);
165 // Q_FOREACH (AbstractPersonDetailsWidget *detailsWidget, d->m_detailWidgets) {
166 // detailsWidget->setPersonsModel(model);
167 // }
168 // }
169 
170 void PersonDetailsView::reload()
171 {
172  Q_D(PersonDetailsView);
173 
174  //replace the entire main widget
175  int layoutIndex = layout()->indexOf(d->m_mainWidget);
176  layout()->takeAt(layoutIndex);
177  d->m_mainWidget->deleteLater();
178  d->m_mainWidget = new QWidget(this);
179  dynamic_cast<QVBoxLayout *>(layout())->insertWidget(layoutIndex, d->m_mainWidget);
180 
181  QFormLayout *layout = new QFormLayout(d->m_mainWidget);
182  layout->setSpacing(4);
183 
184  //update header information
185  //FIXME - possibly split this out into a new class with a nice setPerson method
186 
187  QPixmap avatar = d->m_person->photo();
188 
189  d->m_personDetailsPresentation->avatarPixmapLabel->setPixmap(avatar.scaled(96, 96, Qt::KeepAspectRatio)); //FIXME
190  d->m_personDetailsPresentation->presencePixmapLabel->setPixmap(QIcon::fromTheme(d->m_person->presenceIconName()).pixmap(32, 32)); //FIXME
191  d->m_personDetailsPresentation->nameLabel->setText(d->m_person->name());
192 
193  Q_FOREACH (AbstractFieldWidgetFactory *widgetFactory, d->m_plugins) {
194  const QString label = widgetFactory->label() + QLatin1Char(':');
195  QWidget *widget = widgetFactory->createDetailsWidget(d->m_person->personUri(), this);
196 
197  if (widget) {
198  QFont font = widget->font();
199  font.setBold(true);
200  widget->setFont(font);
201  QLabel *widgetLabel = new QLabel(label, this);
202  layout->addRow(widgetLabel, widget);
203  }
204  }
205 }
KPeople::PersonDetailsView
Use PersonDetailsView to integrate a person's information in the GUI.
Definition: persondetailsview.h:40
KPeople::PersonData
Allows to query the information about a given person.
Definition: persondata.h:44
KPeople
The KPeople namespace contains all the classes for Libkpeople.
KPeople::PersonData::contactCustomProperty
QVariant contactCustomProperty(const QString &key) const
Definition: persondata.cpp:136
KPeople::PersonDetailsView::setPerson
void setPerson(PersonData *person)
Specifies the person for which the details will be displayed.
Definition: persondetailsview.cpp:150
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Fri Feb 13 2015 15:16:39 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KPeople

Skip menu "KPeople"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List

Class Picker

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