Akonadi Contacts

akonadi-contacts/plugins/categorieseditwidget.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "categorieseditwidget.h"
10 
11 #include <KPluginFactory>
12 #include <QHBoxLayout>
13 #include <item.h>
14 #include <tag.h>
15 #include <tagwidget.h>
16 
17 K_PLUGIN_CLASS_WITH_JSON(CategoriesEditWidget, "categorieseditwidgetplugin.json")
18 
20  : ContactEditor::CategoriesEditAbstractWidget(parent)
21  , mTagWidget(new Akonadi::TagWidget(this))
22 {
23  auto layout = new QHBoxLayout(this);
24  layout->setContentsMargins(0, 0, 0, 0);
25  layout->addWidget(mTagWidget);
26 }
27 
28 CategoriesEditWidget::~CategoriesEditWidget()
29 {
30 }
31 
32 void CategoriesEditWidget::setReadOnly(bool readOnly)
33 {
34  mTagWidget->setReadOnly(readOnly);
35 }
36 
37 void CategoriesEditWidget::loadContact(const KContacts::Addressee &contact)
38 {
39  Akonadi::Tag::List tags;
40 
41  const QStringList categories = contact.categories();
42  tags.reserve(categories.count());
43  for (const QString &category : categories) {
44  tags.append(Akonadi::Tag::fromUrl(QUrl(category)));
45  }
46 
47  mTagWidget->setSelection(tags);
48 }
49 
50 void CategoriesEditWidget::storeContact(KContacts::Addressee &contact) const
51 {
52  QStringList categories;
53 
54  const Akonadi::Tag::List tags = mTagWidget->selection();
55  categories.reserve(tags.count());
56  for (const Akonadi::Tag &tag : tags) {
57  categories.append(tag.url().url());
58  }
59 
60  contact.setCategories(categories);
61 }
62 
63 #include "categorieseditwidget.moc"
QStringList categories() const
void reserve(int alloc)
A widget for editing the categories of a contact.
void setCategories(const QStringList &category)
int count(const T &value) const const
void append(const T &value)
#define K_PLUGIN_CLASS_WITH_JSON(classname, jsonFile)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.