File indexing completed on 2024-11-17 04:40:41
0001 /* 0002 This file is part of Akonadi Contact. 0003 0004 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "contactviewerdialog.h" 0010 #include "contactviewer.h" 0011 0012 #include <Akonadi/Item> 0013 using namespace Akonadi; 0014 0015 #include <KConfig> 0016 #include <KLocalizedString> 0017 0018 #include <KConfigGroup> 0019 #include <QDesktopServices> 0020 #include <QDialogButtonBox> 0021 #include <QPushButton> 0022 #include <QVBoxLayout> 0023 0024 namespace 0025 { 0026 static const char myContactViewerDialogGroupName[] = "ContactViewer"; 0027 } 0028 class Akonadi::ContactViewerDialogPrivate 0029 { 0030 public: 0031 explicit ContactViewerDialogPrivate(ContactViewerDialog *parent) 0032 : q(parent) 0033 { 0034 } 0035 0036 void readConfig() 0037 { 0038 KConfig config(QStringLiteral("akonadi_contactrc")); 0039 KConfigGroup group(&config, QLatin1StringView(myContactViewerDialogGroupName)); 0040 const QSize size = group.readEntry("Size", QSize(500, 600)); 0041 if (size.isValid()) { 0042 q->resize(size); 0043 } 0044 } 0045 0046 void writeConfig() 0047 { 0048 KConfig config(QStringLiteral("akonadi_contactrc")); 0049 KConfigGroup group(&config, QLatin1StringView(myContactViewerDialogGroupName)); 0050 group.writeEntry("Size", q->size()); 0051 group.sync(); 0052 } 0053 0054 ContactViewerDialog *const q; 0055 Akonadi::ContactViewer *mViewer = nullptr; 0056 }; 0057 0058 using namespace Akonadi; 0059 0060 ContactViewerDialog::ContactViewerDialog(QWidget *parent) 0061 : QDialog(parent) 0062 , d(new ContactViewerDialogPrivate(this)) 0063 { 0064 setWindowTitle(i18nc("@title:window", "Show Contact")); 0065 auto mainLayout = new QVBoxLayout(this); 0066 0067 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok, this); 0068 auto mainWidget = new QWidget(this); 0069 mainLayout->addWidget(mainWidget); 0070 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0071 okButton->setDefault(true); 0072 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0073 connect(buttonBox, &QDialogButtonBox::accepted, this, &ContactViewerDialog::accept); 0074 connect(buttonBox, &QDialogButtonBox::rejected, this, &ContactViewerDialog::reject); 0075 0076 auto layout = new QVBoxLayout(mainWidget); 0077 0078 d->mViewer = new Akonadi::ContactViewer(this); 0079 layout->addWidget(d->mViewer); 0080 0081 connect(d->mViewer, &Akonadi::ContactViewer::urlClicked, this, [](const QUrl &url) { 0082 QDesktopServices::openUrl(url); 0083 }); 0084 0085 mainLayout->addWidget(buttonBox); 0086 0087 d->readConfig(); 0088 } 0089 0090 ContactViewerDialog::~ContactViewerDialog() 0091 { 0092 d->writeConfig(); 0093 } 0094 0095 Akonadi::Item ContactViewerDialog::contact() const 0096 { 0097 return d->mViewer->contact(); 0098 } 0099 0100 Akonadi::ContactViewer *ContactViewerDialog::viewer() const 0101 { 0102 return d->mViewer; 0103 } 0104 0105 void ContactViewerDialog::setContact(const Akonadi::Item &contact) 0106 { 0107 d->mViewer->setContact(contact); 0108 } 0109 0110 #include "moc_contactviewerdialog.cpp"