Akonadi Contacts

freebusyeditwidget.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "freebusyeditwidget.h"
10
11#include <KConfig>
12#include <KConfigGroup>
13#include <KContacts/Addressee>
14#include <KLineEdit>
15#include <KLocalizedString>
16#include <KUrlRequester>
17#include <QHBoxLayout>
18#include <QStandardPaths>
19using namespace Akonadi;
20FreeBusyEditWidget::FreeBusyEditWidget(QWidget *parent)
21 : QWidget(parent)
22 , mURL(new KUrlRequester(this))
23{
24 auto layout = new QHBoxLayout(this);
25 layout->setContentsMargins({});
26
27 mURL->lineEdit()->setTrapReturnKey(true);
28 mURL->lineEdit()->setPlaceholderText(i18nc("@info:placeholder", "Add FreeBusy"));
29 layout->addWidget(mURL);
30 setFocusProxy(mURL);
31 setFocusPolicy(Qt::StrongFocus);
32}
33
34FreeBusyEditWidget::~FreeBusyEditWidget() = default;
35
36static QString freeBusyUrlStore()
37{
38 return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/korganizer/freebusyurls");
39}
40
41void FreeBusyEditWidget::loadContact(const KContacts::Addressee &contact)
42{
43 if (contact.preferredEmail().isEmpty()) {
44 return;
45 }
46
47 KConfig config(freeBusyUrlStore());
48 mURL->setUrl(QUrl(config.group(contact.preferredEmail()).readEntry("url")));
49}
50
51void FreeBusyEditWidget::storeContact(KContacts::Addressee &contact) const
52{
53 if (contact.preferredEmail().isEmpty()) {
54 return;
55 }
56
57 KConfig config(freeBusyUrlStore());
58 config.group(contact.preferredEmail()).writeEntry("url", mURL->url().url());
59}
60
61void FreeBusyEditWidget::setReadOnly(bool readOnly)
62{
63 mURL->setEnabled(!readOnly);
64}
65
66#include "moc_freebusyeditwidget.cpp"
QString preferredEmail() const
void setUrl(const QUrl &url)
QUrl url() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
QString writableLocation(StandardLocation type)
bool isEmpty() const const
StrongFocus
QString url(FormattingOptions options) const const
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.