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

libkdepim

  • sources
  • kde-4.14
  • kdepim
  • libkdepim
  • widgets
tagwidgets.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include "tagwidgets.h"
19 #include <KJob>
20 #include <QLayout>
21 
22 #include <Akonadi/Tag>
23 #include <Akonadi/TagCreateJob>
24 #include <Akonadi/TagWidget>
25 #include <Akonadi/TagModel>
26 #include <Akonadi/Monitor>
27 
28 using namespace KPIM;
29 
30 TagWidget::TagWidget(QWidget* parent)
31 : QWidget(parent)
32 {
33  mTagWidget = new Akonadi::TagWidget(this);
34  connect(mTagWidget, SIGNAL(selectionChanged(Akonadi::Tag::List)), this, SLOT(onSelectionChanged(Akonadi::Tag::List)));
35  QHBoxLayout *l = new QHBoxLayout;
36  l->setMargin(0);
37  l->setSpacing(0);
38  l->addWidget(mTagWidget);
39  setLayout(l);
40 }
41 
42 void TagWidget::onSelectionChanged(const Akonadi::Tag::List &tags)
43 {
44  Q_UNUSED(tags);
45  mCachedTagNames.clear();
46  Q_FOREACH (const Akonadi::Tag &tag, mTagWidget->selection()) {
47  mCachedTagNames << tag.name();
48  }
49  emit selectionChanged(mCachedTagNames);
50 }
51 
52 void TagWidget::setSelection(const QStringList &tagNames)
53 {
54  mTagList.clear();
55  mCachedTagNames = tagNames;
56  foreach (const QString &name, tagNames) {
57  //TODO fetch by GID instead, we don't really want to create tags here
58  Akonadi::TagCreateJob *tagCreateJob = new Akonadi::TagCreateJob(Akonadi::Tag(name), this);
59  tagCreateJob->setMergeIfExisting(true);
60  connect(tagCreateJob, SIGNAL(result(KJob*)), this, SLOT(onTagCreated(KJob*)));
61  }
62 }
63 
64 void TagWidget::onTagCreated(KJob *job)
65 {
66  if (job->error()) {
67  kWarning() << "Failed to create tag " << job->errorString();
68  return;
69  }
70  Akonadi::TagCreateJob *createJob = static_cast<Akonadi::TagCreateJob*>(job);
71  mTagList << createJob->tag();
72  mTagWidget->setSelection(mTagList);
73 }
74 
75 QStringList TagWidget::selection() const
76 {
77  return mCachedTagNames;
78 }
79 
80 
81 TagSelectionDialog::TagSelectionDialog(QWidget* parent)
82 : Akonadi::TagSelectionDialog(parent)
83 {
84 
85 }
86 
87 void TagSelectionDialog::setSelection(const QStringList &tagNames)
88 {
89  mTagList.clear();
90  foreach (const QString &name, tagNames) {
91  //TODO fetch by GID instead, we don't really want to create tags here
92  Akonadi::TagCreateJob *tagCreateJob = new Akonadi::TagCreateJob(Akonadi::Tag(name), this);
93  tagCreateJob->setMergeIfExisting(true);
94  connect(tagCreateJob, SIGNAL(result(KJob*)), this, SLOT(onTagCreated(KJob*)));
95  }
96 }
97 
98 void TagSelectionDialog::onTagCreated(KJob *job)
99 {
100  if (job->error()) {
101  kWarning() << "Failed to create tag " << job->errorString();
102  return;
103  }
104  Akonadi::TagCreateJob *createJob = static_cast<Akonadi::TagCreateJob*>(job);
105  mTagList << createJob->tag();
106  Akonadi::TagSelectionDialog::setSelection(mTagList);
107 }
108 
109 QStringList TagSelectionDialog::selection() const
110 {
111  QStringList list;
112  Q_FOREACH (const Akonadi::Tag &tag, Akonadi::TagSelectionDialog::selection()) {
113  list << tag.name();
114  }
115  return list;
116 }
117 
QList::clear
void clear()
QWidget
KPIM::TagWidget::TagWidget
TagWidget(QWidget *parent=0)
Definition: tagwidgets.cpp:30
QHBoxLayout
KPIM::TagSelectionDialog::setSelection
void setSelection(const QStringList &)
Definition: tagwidgets.cpp:87
QObject::name
const char * name() const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
tagwidgets.h
QWidget::setLayout
void setLayout(QLayout *layout)
KPIM::TagWidget::setSelection
void setSelection(const QStringList &)
Definition: tagwidgets.cpp:52
KPIM::TagSelectionDialog
Definition: tagwidgets.h:54
QString
KPIM::TagWidget::selection
QStringList selection() const
Definition: tagwidgets.cpp:75
QLayout::setMargin
void setMargin(int margin)
QStringList
KPIM::TagWidget::selectionChanged
void selectionChanged(const QStringList &)
KPIM::TagSelectionDialog::selection
QStringList selection() const
Definition: tagwidgets.cpp:109
KPIM::TagSelectionDialog::TagSelectionDialog
TagSelectionDialog(QWidget *parent=0)
Definition: tagwidgets.cpp:81
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KJob
QBoxLayout::setSpacing
void setSpacing(int spacing)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



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