File indexing completed on 2024-04-28 05:11:32
0001 /* 0002 SPDX-FileCopyrightText: 2004 Cornelius Schumacher <schumacher@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0005 */ 0006 0007 #include "freebusyurldialog.h" 0008 0009 #include <KLineEdit> 0010 #include <KLocalizedString> 0011 0012 #include <KConfig> 0013 #include <KConfigGroup> 0014 #include <QBoxLayout> 0015 #include <QDialogButtonBox> 0016 #include <QFrame> 0017 #include <QLabel> 0018 #include <QPushButton> 0019 #include <QStandardPaths> 0020 #include <QVBoxLayout> 0021 0022 using namespace IncidenceEditorNG; 0023 0024 FreeBusyUrlDialog::FreeBusyUrlDialog(const AttendeeData::Ptr &attendee, QWidget *parent) 0025 : QDialog(parent) 0026 { 0027 setModal(true); 0028 setWindowTitle(i18nc("@title:window", "Edit Free/Busy Location")); 0029 auto mainLayout = new QVBoxLayout(this); 0030 0031 auto topFrame = new QFrame(this); 0032 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0033 mainLayout->addWidget(topFrame); 0034 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0035 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0036 connect(buttonBox, &QDialogButtonBox::rejected, this, &FreeBusyUrlDialog::reject); 0037 mainLayout->addWidget(buttonBox); 0038 okButton->setDefault(true); 0039 0040 QBoxLayout *topLayout = new QVBoxLayout(topFrame); 0041 topLayout->setContentsMargins(0, 0, 0, 0); 0042 0043 mWidget = new FreeBusyUrlWidget(attendee, topFrame); 0044 topLayout->addWidget(mWidget); 0045 0046 mWidget->loadConfig(); 0047 connect(okButton, &QPushButton::clicked, this, &FreeBusyUrlDialog::slotOk); 0048 } 0049 0050 void FreeBusyUrlDialog::slotOk() 0051 { 0052 mWidget->saveConfig(); 0053 accept(); 0054 } 0055 0056 FreeBusyUrlWidget::FreeBusyUrlWidget(const AttendeeData::Ptr &attendee, QWidget *parent) 0057 : QWidget(parent) 0058 , mUrlEdit(new KLineEdit(this)) 0059 , mAttendee(attendee) 0060 { 0061 QBoxLayout *topLayout = new QVBoxLayout(this); 0062 0063 auto label = new QLabel(xi18n("Location of Free/Busy information for %1 <placeholder>%2</placeholder>:", mAttendee->name(), mAttendee->email()), this); 0064 topLayout->addWidget(label); 0065 0066 mUrlEdit->setFocus(); 0067 mUrlEdit->setWhatsThis(i18nc("@info:whatsthis", "Enter the location of the Free/Busy information for the attendee.")); 0068 mUrlEdit->setToolTip(i18nc("@info:tooltip", "Enter the location of the information.")); 0069 topLayout->addWidget(mUrlEdit); 0070 } 0071 0072 FreeBusyUrlWidget::~FreeBusyUrlWidget() = default; 0073 0074 static QString freeBusyUrlStore() 0075 { 0076 return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/korganizer/freebusyurls"); 0077 } 0078 0079 void FreeBusyUrlWidget::loadConfig() 0080 { 0081 KConfig config(freeBusyUrlStore()); 0082 mUrlEdit->setText(config.group(mAttendee->email()).readEntry("url")); 0083 } 0084 0085 void FreeBusyUrlWidget::saveConfig() 0086 { 0087 const QString url = mUrlEdit->text(); 0088 KConfig config(freeBusyUrlStore()); 0089 config.group(mAttendee->email()).writeEntry("url", url); 0090 } 0091 0092 #include "moc_freebusyurldialog.cpp"