Akonadi Contacts

freebusyeditwidget.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "freebusyeditwidget.h"
10 
11 #include <kcontacts/addressee.h>
12 #include <kurlrequester.h>
13 #include <KConfig>
14 #include <KLineEdit>
15 #include <KLocalizedString>
16 #include <KConfigGroup>
17 #include <QHBoxLayout>
18 #include <QStandardPaths>
19 
20 FreeBusyEditWidget::FreeBusyEditWidget(QWidget *parent)
21  : QWidget(parent)
22 {
23  QHBoxLayout *layout = new QHBoxLayout(this);
24  layout->setContentsMargins(0, 0, 0, 0);
25 
26  mURL = new KUrlRequester(this);
27  mURL->lineEdit()->setTrapReturnKey(true);
28  mURL->lineEdit()->setPlaceholderText(i18n("Add FreeBusy"));
29  layout->addWidget(mURL);
30  setFocusProxy(mURL);
32 }
33 
34 FreeBusyEditWidget::~FreeBusyEditWidget()
35 {
36 }
37 
38 static QString freeBusyUrlStore()
39 {
40  return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/korganizer/freebusyurls");
41 }
42 
43 void FreeBusyEditWidget::loadContact(const KContacts::Addressee &contact)
44 {
45  if (contact.preferredEmail().isEmpty()) {
46  return;
47  }
48 
49  KConfig config(freeBusyUrlStore());
50  mURL->setUrl(QUrl(config.group(contact.preferredEmail()).readEntry("url")));
51 }
52 
53 void FreeBusyEditWidget::storeContact(KContacts::Addressee &contact) const
54 {
55  if (contact.preferredEmail().isEmpty()) {
56  return;
57  }
58 
59  KConfig config(freeBusyUrlStore());
60  config.group(contact.preferredEmail()).writeEntry("url", mURL->url().url());
61 }
62 
63 void FreeBusyEditWidget::setReadOnly(bool readOnly)
64 {
65  mURL->setEnabled(!readOnly);
66 }
QLayout * layout() const const
StrongFocus
void setContentsMargins(int left, int top, int right, int bottom)
QString writableLocation(QStandardPaths::StandardLocation type)
void setFocusPolicy(Qt::FocusPolicy policy)
KSharedConfigPtr config()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setFocusProxy(QWidget *w)
bool isEmpty() const const
QString preferredEmail() const
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Sep 25 2020 23:09:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.