File indexing completed on 2024-05-19 05:21:23
0001 /* 0002 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kontactconfiguredialog.h" 0008 #include "kontact_debug.h" 0009 #include <KConfig> 0010 #include <KConfigGroup> 0011 #include <KSharedConfig> 0012 #include <QDBusInterface> 0013 #include <QDBusReply> 0014 #include <QPushButton> 0015 0016 using namespace Kontact; 0017 namespace 0018 { 0019 static const char myKontactConfigureDialogConfigGroupName[] = "KontactConfigureDialog"; 0020 } 0021 KontactConfigureDialog::KontactConfigureDialog(QWidget *parent) 0022 : KontactSettingsDialog(parent) 0023 { 0024 setFaceType(Tree); 0025 connect(button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &KontactConfigureDialog::slotOk); 0026 connect(button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &KontactConfigureDialog::slotApply); 0027 } 0028 0029 KontactConfigureDialog::~KontactConfigureDialog() 0030 { 0031 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myKontactConfigureDialogConfigGroupName)); 0032 group.writeEntry("width", width()); 0033 group.writeEntry("height", height()); 0034 } 0035 0036 void KontactConfigureDialog::emitConfigChanged() 0037 { 0038 // Add code from plugins which needs to be call when we close kontact dialog config 0039 QDBusInterface kmailIface(QStringLiteral("org.kde.kmail"), QStringLiteral("/KMail"), QStringLiteral("org.kde.kmail.kmail"), QDBusConnection::sessionBus()); 0040 if (kmailIface.isValid()) { 0041 QDBusReply<void> reply; 0042 if (!(reply = kmailIface.call(QStringLiteral("updateConfig"))).isValid()) { 0043 const QDBusError err = kmailIface.lastError(); 0044 qCritical() << "Communication problem with KMail. " 0045 << "Error message was:" << err.name() << ": \"" << err.message() << "\""; 0046 } 0047 } 0048 QDBusInterface knotesIface(QStringLiteral("org.kde.kontact"), 0049 QStringLiteral("/KNotes"), 0050 QStringLiteral("org.kde.kontact.KNotes"), 0051 QDBusConnection::sessionBus()); 0052 if (knotesIface.isValid()) { 0053 QDBusReply<void> reply; 0054 if (!(reply = knotesIface.call(QStringLiteral("updateConfig"))).isValid()) { 0055 const QDBusError err = knotesIface.lastError(); 0056 qCritical() << "Communication problem with KNotes. " 0057 << "Error message was:" << err.name() << ": \"" << err.message() << "\""; 0058 } 0059 } 0060 } 0061 0062 void KontactConfigureDialog::slotApply() 0063 { 0064 slotApplyClicked(); 0065 emitConfigChanged(); 0066 } 0067 0068 void KontactConfigureDialog::slotOk() 0069 { 0070 slotOkClicked(); 0071 emitConfigChanged(); 0072 } 0073 0074 QSize KontactConfigureDialog::sizeHint() const 0075 { 0076 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myKontactConfigureDialogConfigGroupName)); 0077 const int width = group.readEntry("width", 800); 0078 const int height = group.readEntry("height", 600); 0079 return QSize(width, height); 0080 } 0081 0082 #include "moc_kontactconfiguredialog.cpp"