• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi/contact

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
  • contact
  • editor
customfieldeditordialog.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "customfieldeditordialog.h"
23 
24 #include <kcombobox.h>
25 #include <klineedit.h>
26 #include <klocalizedstring.h>
27 
28 #include <QCheckBox>
29 #include <QFormLayout>
30 #include <QRegExpValidator>
31 
32 CustomFieldEditorDialog::CustomFieldEditorDialog(QWidget *parent)
33  : KDialog(parent)
34 {
35  setCaption(i18n("Edit Custom Field"));
36  setButtons(Ok | Cancel | Details);
37 
38  QWidget *widget = new QWidget(this);
39  setMainWidget(widget);
40 
41  QFormLayout *layout = new QFormLayout(widget);
42 
43  mKey = new KLineEdit;
44  mTitle = new KLineEdit;
45  mType = new KComboBox;
46  mScope = new QCheckBox(i18n("Use field for all contacts"));
47 
48  layout->addRow(i18nc("The title of a custom field", "Title"), mTitle);
49  layout->addRow(i18nc("The type of a custom field", "Type"), mType);
50  layout->addRow(QString(), mScope);
51 
52  QWidget *detailsWidget = new QWidget;
53  QFormLayout *detailsLayout = new QFormLayout(detailsWidget);
54  detailsLayout->addRow(i18n("Key"), mKey);
55 
56  setDetailsWidget(detailsWidget);
57  setButtonText(Details, i18nc("@label Opens the advanced dialog", "Advanced"));
58 
59  mType->addItem(i18n("Text"), CustomField::TextType);
60  mType->addItem(i18n("Numeric"), CustomField::NumericType);
61  mType->addItem(i18n("Boolean"), CustomField::BooleanType);
62  mType->addItem(i18n("Date"), CustomField::DateType);
63  mType->addItem(i18n("Time"), CustomField::TimeType);
64  mType->addItem(i18n("DateTime"), CustomField::DateTimeType);
65  mType->addItem(i18n("Url"), CustomField::UrlType);
66 
67  mKey->setValidator(new QRegExpValidator(QRegExp(QLatin1String("[a-zA-Z0-9\\-]+")), this));
68  mTitle->setFocus();
69 }
70 
71 void CustomFieldEditorDialog::setCustomField(const CustomField &field)
72 {
73  mCustomField = field;
74 
75  mKey->setText(mCustomField.key());
76  mTitle->setText(mCustomField.title());
77  mType->setCurrentIndex(mType->findData(mCustomField.type()));
78  mScope->setChecked((mCustomField.scope() == CustomField::GlobalScope));
79 }
80 
81 CustomField CustomFieldEditorDialog::customField() const
82 {
83  CustomField customField(mCustomField);
84 
85  customField.setKey(mKey->text());
86  customField.setTitle(mTitle->text());
87  customField.setType(static_cast<CustomField::Type>(mType->itemData(mType->currentIndex()).toInt()));
88 
89  if (customField.scope() != CustomField::ExternalScope) {
90  // do not change the scope for externally defined custom fields
91  customField.setScope(mScope->isChecked() ? CustomField::GlobalScope : CustomField::LocalScope);
92  }
93 
94  return customField;
95 }
CustomField
A class that represents non-standard contact fields.
Definition: customfields_p.h:47
QWidget
QRegExpValidator
QRegExp
QCheckBox
CustomField::ExternalScope
Field has been defined by the external data source (e.g. vCard)
Definition: customfields_p.h:65
QString
QFormLayout::addRow
void addRow(QWidget *label, QWidget *field)
CustomField::GlobalScope
Field has been defined by user for all contacts.
Definition: customfields_p.h:64
CustomField::LocalScope
Field has been defined by user for one contact.
Definition: customfields_p.h:63
QLatin1String
QFormLayout
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi/contact

Skip menu "akonadi/contact"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal