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 <Akonadi/Item>
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 namespace
25 {
26 static const char myContactViewerDialogGroupName[] = "ContactViewer";
27 }
28 class Akonadi::ContactViewerDialogPrivate
29 {
30 public:
31  explicit ContactViewerDialogPrivate(ContactViewerDialog *parent)
32  : q(parent)
33  {
34  }
35 
36  void readConfig()
37  {
38  KConfig config(QStringLiteral("akonadi_contactrc"));
39  KConfigGroup group(&config, myContactViewerDialogGroupName);
40  const QSize size = group.readEntry("Size", QSize(500, 600));
41  if (size.isValid()) {
42  q->resize(size);
43  }
44  }
45 
46  void writeConfig()
47  {
48  KConfig config(QStringLiteral("akonadi_contactrc"));
49  KConfigGroup group(&config, myContactViewerDialogGroupName);
50  group.writeEntry("Size", q->size());
51  group.sync();
52  }
53 
54  ContactViewerDialog *const q;
55  ContactViewer *mViewer = nullptr;
56 };
57 
59  : QDialog(parent)
60  , d(new ContactViewerDialogPrivate(this))
61 {
62  setWindowTitle(i18nc("@title:window", "Show Contact"));
63  auto mainLayout = new QVBoxLayout(this);
64 
65  auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, this);
66  auto mainWidget = new QWidget(this);
67  mainLayout->addWidget(mainWidget);
68  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
69  okButton->setDefault(true);
70  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
73 
74  auto layout = new QVBoxLayout(mainWidget);
75 
76  d->mViewer = new ContactViewer(this);
77  layout->addWidget(d->mViewer);
78 
79  auto actions = new ContactDefaultActions(this);
80  actions->connectToView(d->mViewer);
81 
82  mainLayout->addWidget(buttonBox);
83 
84  d->readConfig();
85 }
86 
88 {
89  d->writeConfig();
90 }
91 
93 {
94  return d->mViewer->contact();
95 }
96 
98 {
99  return d->mViewer;
100 }
101 
103 {
104  d->mViewer->setContact(contact);
105 }
QList< QAction * > actions() const const
QWidget(QWidget *parent, Qt::WindowFlags f)
bool isValid() const const
virtual void reject()
void setShortcut(const QKeySequence &key)
void setContact(const Akonadi::Item &contact)
Sets the contact that shall be displayed in the dialog.
QLayout * layout() const const
void readConfig()
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)
ContactViewer * viewer() const
Returns the ContactViewer that is used by this dialog.
~ContactViewerDialog() override
Destroys the contact viewer dialog.
A convenience class that handles different contact related actions.
ContactViewerDialog(QWidget *parent=nullptr)
Creates a new contact viewer dialog.
void setWindowTitle(const QString &)
virtual void accept()
A viewer component for contacts in Akonadi.
Definition: contactviewer.h:64
Key_Return
KSharedConfigPtr config()
void addWidget(QWidget *w)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setDefault(bool)
Akonadi::Item contact() const
Returns the contact that is currently displayed.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:04 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.