Akonadi

tagselectiondialog.cpp
1/*
2 This file is part of Akonadi
3
4 SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "tagselectiondialog.h"
10#include "controlgui.h"
11#include "monitor.h"
12#include "tagmodel.h"
13#include "ui_tagselectiondialog.h"
14
15#include <KConfigGroup>
16#include <KSharedConfig>
17
18using namespace Akonadi;
19namespace
20{
21static const char myTagSelectionDialogGroupName[] = "TagSelectionDialog";
22}
23class Akonadi::TagSelectionDialogPrivate
24{
25public:
26 explicit TagSelectionDialogPrivate(QDialog *parent)
27 : q(parent)
28 {
29 }
30
31 void writeConfig() const;
32 void readConfig() const;
33
34 QDialog *const q;
35 Ui::TagSelectionDialog ui;
36};
37
38void TagSelectionDialogPrivate::writeConfig() const
39{
40 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myTagSelectionDialogGroupName));
41 group.writeEntry("Size", q->size());
42}
43
44void TagSelectionDialogPrivate::readConfig() const
45{
46 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myTagSelectionDialogGroupName));
47 const QSize sizeDialog = group.readEntry("Size", QSize(500, 400));
48 if (sizeDialog.isValid()) {
49 q->resize(sizeDialog);
50 }
51}
52
53TagSelectionDialog::TagSelectionDialog(QWidget *parent)
54 : QDialog(parent)
55 , d(new TagSelectionDialogPrivate(this))
56{
57 d->ui.setupUi(this);
58
59 auto monitor = new Monitor(this);
60 monitor->setObjectName(QLatin1StringView("TagSelectionDialogMonitor"));
61 monitor->setTypeMonitored(Monitor::Tags);
62
63 d->ui.tagWidget->setModel(new TagModel(monitor, this));
64 d->ui.tagWidget->setSelectionEnabled(true);
65
66 d->readConfig();
67
69}
70
71TagSelectionDialog::TagSelectionDialog(TagModel *model, QWidget *parent)
72 : QDialog(parent)
73 , d(new TagSelectionDialogPrivate(this))
74{
75 d->ui.setupUi(this);
76
77 d->ui.tagWidget->setModel(model);
78 d->ui.tagWidget->setSelectionEnabled(true);
79
80 d->readConfig();
81
83}
84
85TagSelectionDialog::~TagSelectionDialog()
86{
87 d->writeConfig();
88}
89
90QDialogButtonBox *TagSelectionDialog::buttons() const
91{
92 return d->ui.buttonBox;
93}
94
95Tag::List TagSelectionDialog::selection() const
96{
97 return d->ui.tagWidget->selection();
98}
99
100void TagSelectionDialog::setSelection(const Tag::List &tags)
101{
102 d->ui.tagWidget->setSelection(tags);
103}
104
105#include "moc_tagselectiondialog.cpp"
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
Monitors an item or collection for changes.
Definition monitor.h:71
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
Helper integration between Akonadi and Qt.
bool isValid() const const
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.