20 #include "persondetailsview.h"
22 #include <QFormLayout>
24 #include <QVBoxLayout>
27 #include <QStandardPaths>
29 #include <KLocalizedString>
31 #include <KServiceTypeTrader>
32 #include <KPluginInfo>
33 #include <KPluginLoader>
34 #include <KPluginFactory>
36 #include "abstractfieldwidgetfactory.h"
37 #include "plugins/emaildetailswidget.h"
40 #include "ui_person-details-presentation.h"
45 class PersonDetailsViewPrivate
49 Ui::PersonDetailsPresentation *m_personDetailsPresentation;
50 QWidget *m_mainWidget;
51 QList<AbstractFieldWidgetFactory *> m_plugins;
57 class CoreFieldsPlugin :
public AbstractFieldWidgetFactory
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;
69 CoreFieldsPlugin::CoreFieldsPlugin(
const QString &field):
74 CoreFieldsPlugin::~CoreFieldsPlugin()
79 QString CoreFieldsPlugin::label()
const
81 #warning fixme, should be made user-visible somehow
85 int CoreFieldsPlugin::sortWeight()
const
90 QWidget *CoreFieldsPlugin::createDetailsWidget(
const PersonData &person, QWidget *parent)
const
93 if (m_field == QLatin1String(
"email")) {
101 return new QLabel(text, parent);
104 PersonDetailsView::PersonDetailsView(QWidget *parent)
106 d_ptr(new PersonDetailsViewPrivate())
109 setLayout(
new QVBoxLayout(
this));
110 d->m_mainWidget =
new QWidget(
this);
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));
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);
127 d->m_plugins <<
new EmailFieldsPlugin();
130 KService::List pluginList = KServiceTypeTrader::self()->query(QLatin1String(
"KPeopleWidgets/Plugin"));
132 QList<KPluginInfo> plugins = KPluginInfo::fromServices(pluginList);
134 Q_FOREACH (
const KPluginInfo &p, plugins) {
136 AbstractFieldWidgetFactory *f = p.service()->createInstance<AbstractFieldWidgetFactory>(
this, QVariantList(), &error);
145 PersonDetailsView::~PersonDetailsView()
154 disconnect(d->m_person, SIGNAL(dataChanged()),
this, SLOT(reload()));
157 d->m_person = person;
158 connect(d->m_person, SIGNAL(dataChanged()),
this, SLOT(reload()));
170 void PersonDetailsView::reload()
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);
181 QFormLayout *layout =
new QFormLayout(d->m_mainWidget);
182 layout->setSpacing(4);
187 QPixmap avatar = d->m_person->photo();
189 d->m_personDetailsPresentation->avatarPixmapLabel->setPixmap(avatar.scaled(96, 96, Qt::KeepAspectRatio));
190 d->m_personDetailsPresentation->presencePixmapLabel->setPixmap(QIcon::fromTheme(d->m_person->presenceIconName()).pixmap(32, 32));
191 d->m_personDetailsPresentation->nameLabel->setText(d->m_person->name());
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);
198 QFont font = widget->font();
200 widget->setFont(font);
201 QLabel *widgetLabel =
new QLabel(label,
this);
202 layout->addRow(widgetLabel, widget);
Use PersonDetailsView to integrate a person's information in the GUI.
Allows to query the information about a given person.
The KPeople namespace contains all the classes for Libkpeople.
QVariant contactCustomProperty(const QString &key) const
void setPerson(PersonData *person)
Specifies the person for which the details will be displayed.