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

kaddressbook

  • sources
  • kde-4.14
  • kdepim
  • kaddressbook
  • xxport
  • vcard
vcardviewerdialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 
19 #include "vcardviewerdialog.h"
20 #include <KLocalizedString>
21 #include <KStandardGuiItem>
22 #include <KSharedConfig>
23 #include <KConfigGroup>
24 #include <KGlobal>
25 #include <QLabel>
26 #include <QVBoxLayout>
27 #include <widget/grantleecontactviewer.h>
28 
29 VCardViewerDialog::VCardViewerDialog( const KABC::Addressee::List &list, QWidget *parent )
30  : KDialog( parent ),
31  mContacts( list )
32 {
33  setCaption( i18nc( "@title:window", "Import vCard" ) );
34  setButtons( User1 | User2 | Apply | Cancel );
35  setButtonGuiItem(User1, KStandardGuiItem::no());
36  setButtonGuiItem(User2, KStandardGuiItem::yes());
37  setDefaultButton( User1 );
38  setModal( true );
39  showButtonSeparator( true );
40 
41  QFrame *page = new QFrame( this );
42  setMainWidget( page );
43 
44  QVBoxLayout *layout = new QVBoxLayout( page );
45  layout->setSpacing( spacingHint() );
46  layout->setMargin( marginHint() );
47 
48  QLabel *label =
49  new QLabel(
50  i18nc( "@info", "Do you want to import this contact into your address book?" ), page );
51  QFont font = label->font();
52  font.setBold( true );
53  label->setFont( font );
54  layout->addWidget( label );
55 
56  mView = new KAddressBookGrantlee::GrantleeContactViewer( page );
57 
58  layout->addWidget( mView );
59 
60  setButtonText( Apply, i18nc( "@action:button", "Import All..." ) );
61 
62  mIt = mContacts.begin();
63 
64  connect( this, SIGNAL(user2Clicked()), this, SLOT(slotYes()) );
65  connect( this, SIGNAL(user1Clicked()), this, SLOT(slotNo()) );
66  connect( this, SIGNAL(applyClicked()), this, SLOT(slotApply()) );
67  connect( this, SIGNAL(cancelClicked()), this, SLOT(slotCancel()) );
68 
69  updateView();
70  readConfig();
71 }
72 
73 VCardViewerDialog::~VCardViewerDialog()
74 {
75  writeConfig();
76 }
77 
78 void VCardViewerDialog::readConfig()
79 {
80  KConfigGroup group( KGlobal::config(), "VCardViewerDialog" );
81  const QSize size = group.readEntry( "Size", QSize(600, 400) );
82  if ( size.isValid() ) {
83  resize( size );
84  }
85 }
86 
87 void VCardViewerDialog::writeConfig()
88 {
89  KConfigGroup group( KGlobal::config(), "VCardViewerDialog" );
90  group.writeEntry( "Size", size() );
91  group.sync();
92 }
93 
94 
95 KABC::Addressee::List VCardViewerDialog::contacts() const
96 {
97  return mContacts;
98 }
99 
100 void VCardViewerDialog::updateView()
101 {
102  mView->setRawContact( *mIt );
103 
104  KABC::Addressee::List::Iterator it = mIt;
105  enableButton( Apply, ( ++it ) != mContacts.end() );
106 }
107 
108 void VCardViewerDialog::slotYes()
109 {
110  mIt++;
111 
112  if ( mIt == mContacts.end() ) {
113  slotApply();
114  return;
115  }
116 
117  updateView();
118 }
119 
120 void VCardViewerDialog::slotNo()
121 {
122  if ( mIt == mContacts.end() ) {
123  accept();
124  return;
125  }
126  // remove the current contact from the result set
127  mIt = mContacts.erase( mIt );
128  if ( mIt == mContacts.end() ) {
129  return;
130  }
131 
132  updateView();
133 }
134 
135 void VCardViewerDialog::slotApply()
136 {
137  KDialog::accept();
138 }
139 
140 void VCardViewerDialog::slotCancel()
141 {
142  mContacts.clear();
143  reject();
144 }
QWidget
QSize::isValid
bool isValid() const
VCardViewerDialog::slotNo
void slotNo()
Definition: vcardviewerdialog.cpp:120
QFont
VCardViewerDialog::slotYes
void slotYes()
Definition: vcardviewerdialog.cpp:108
KDialog
QFont::setBold
void setBold(bool enable)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
VCardViewerDialog::slotApply
void slotApply()
Definition: vcardviewerdialog.cpp:135
QVBoxLayout
QLayout::setMargin
void setMargin(int margin)
VCardViewerDialog::VCardViewerDialog
VCardViewerDialog(const KABC::Addressee::List &list, QWidget *parent)
Definition: vcardviewerdialog.cpp:29
vcardviewerdialog.h
QSize
QWidget::font
font
VCardViewerDialog::contacts
KABC::Addressee::List contacts() const
Definition: vcardviewerdialog.cpp:95
QFrame
VCardViewerDialog::~VCardViewerDialog
~VCardViewerDialog()
Definition: vcardviewerdialog.cpp:73
VCardViewerDialog::slotCancel
void slotCancel()
Definition: vcardviewerdialog.cpp:140
QLabel
QBoxLayout::setSpacing
void setSpacing(int spacing)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kaddressbook

Skip menu "kaddressbook"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

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