Akonadi Contacts

contactviewerdialog.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "contactviewerdialog.h"
10 #include "contactdefaultactions.h"
11 #include "contactviewer.h"
12 
13 #include <item.h>
14 using namespace Akonadi;
15 
16 #include <KConfig>
17 #include <KLocalizedString>
18 
19 #include <KConfigGroup>
20 #include <QDialogButtonBox>
21 #include <QPushButton>
22 #include <QVBoxLayout>
23 
24 class Q_DECL_HIDDEN ContactViewerDialog::Private
25 {
26 public:
27  Private(ContactViewerDialog *parent)
28  : q(parent)
29  {
30  }
31 
32  void readConfig()
33  {
34  KConfig config(QStringLiteral("akonadi_contactrc"));
35  KConfigGroup group(&config, QStringLiteral("ContactViewer"));
36  const QSize size = group.readEntry("Size", QSize(500, 600));
37  if (size.isValid()) {
38  q->resize(size);
39  }
40  }
41 
42  void writeConfig()
43  {
44  KConfig config(QStringLiteral("akonadi_contactrc"));
45  KConfigGroup group(&config, QStringLiteral("ContactViewer"));
46  group.writeEntry("Size", q->size());
47  group.sync();
48  }
49 
50  ContactViewerDialog *const q;
51  ContactViewer *mViewer = nullptr;
52 };
53 
55  : QDialog(parent)
56  , d(new Private(this))
57 {
58  setWindowTitle(i18nc("@title:window", "Show Contact"));
59  auto mainLayout = new QVBoxLayout(this);
60 
61  auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, this);
62  auto mainWidget = new QWidget(this);
63  mainLayout->addWidget(mainWidget);
64  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
65  okButton->setDefault(true);
66  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
69 
70  auto layout = new QVBoxLayout(mainWidget);
71 
72  d->mViewer = new ContactViewer(this);
73  layout->addWidget(d->mViewer);
74 
75  auto actions = new ContactDefaultActions(this);
76  actions->connectToView(d->mViewer);
77 
78  mainLayout->addWidget(buttonBox);
79 
80  d->readConfig();
81 }
82 
84 {
85  d->writeConfig();
86  delete d;
87 }
88 
90 {
91  return d->mViewer->contact();
92 }
93 
95 {
96  return d->mViewer;
97 }
98 
100 {
101  d->mViewer->setContact(contact);
102 }
QLayout * layout() const const
bool isValid() const const
Akonadi::Item contact() const
Returns the contact that is currently displayed.
virtual void reject()
ContactViewer * viewer() const
Returns the ContactViewer that is used by this dialog.
KSharedConfigPtr config()
QString i18nc(const char *context, const char *text, const TYPE &arg...)
A convenience class that handles different contact related actions.
void setShortcut(const QKeySequence &key)
void addWidget(QWidget *w)
virtual void accept()
void readConfig()
A viewer component for contacts in Akonadi.
Definition: contactviewer.h:61
void setWindowTitle(const QString &)
QWidget(QWidget *parent, Qt::WindowFlags f)
void setContact(const Akonadi::Item &contact)
Sets the contact that shall be displayed in the dialog.
ContactViewerDialog(QWidget *parent=nullptr)
Creates a new contact viewer dialog.
A dialog for displaying a contact in Akonadi.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QList< QAction * > actions() const const
void setDefault(bool)
Key_Return
~ContactViewerDialog() override
Destroys the contact viewer dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jun 22 2021 23:08:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.