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

kmail

  • sources
  • kde-4.12
  • kdepim
  • kmail
  • identity
identityeditvcarddialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012-2013 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 #include "identityeditvcarddialog.h"
19 
20 #include <KABC/VCardConverter>
21 #include <KLocale>
22 #include <Akonadi/Contact/ContactEditor>
23 #include <KDebug>
24 #include <KMessageBox>
25 
26 #include <QHBoxLayout>
27 #include <QFile>
28 
29 IdentityEditVcardDialog::IdentityEditVcardDialog(const QString &fileName, QWidget *parent)
30  : KDialog(parent)
31 {
32  if (QFile(fileName).exists()) {
33  setCaption( i18n( "Edit own vCard" ) );
34  setButtons( User1|Ok|Cancel );
35  setButtonText(User1, i18n("Delete current vcard"));
36  connect(this, SIGNAL(user1Clicked()), this, SLOT(slotDeleteCurrentVCard()));
37  } else {
38  setCaption( i18n("Create own vCard") );
39  setButtons( Ok|Cancel );
40  }
41 
42  setDefaultButton( Ok );
43  setModal( true );
44  QWidget *mainWidget = new QWidget( this );
45  QHBoxLayout *mainLayout = new QHBoxLayout( mainWidget );
46  mainLayout->setSpacing( KDialog::spacingHint() );
47  mainLayout->setMargin( KDialog::marginHint() );
48  setMainWidget( mainWidget );
49 
50  mContactEditor = new Akonadi::ContactEditor( Akonadi::ContactEditor::CreateMode, Akonadi::ContactEditor::VCardMode, this );
51  mainLayout->addWidget(mContactEditor);
52  loadVcard(fileName);
53 }
54 
55 IdentityEditVcardDialog::~IdentityEditVcardDialog()
56 {
57 }
58 
59 void IdentityEditVcardDialog::slotDeleteCurrentVCard()
60 {
61  if (KMessageBox::Yes == KMessageBox::questionYesNo(this, i18n("Are you sure to want to delete this vcard?"), i18n("Delete vcard"))) {
62  deleteCurrentVcard();
63  reject();
64  }
65 }
66 
67 void IdentityEditVcardDialog::deleteCurrentVcard()
68 {
69  if (!mVcardFileName.isEmpty()) {
70  QFile file(mVcardFileName);
71  if (file.exists()) {
72  if (!file.remove()) {
73  KMessageBox::error(this, i18n("We cannot delete vcard file."), i18n("Delete vcard"));
74  }
75  }
76  }
77 }
78 
79 void IdentityEditVcardDialog::loadVcard( const QString &vcardFileName)
80 {
81  if (vcardFileName.isEmpty()) {
82  return;
83  }
84  mVcardFileName = vcardFileName;
85  QFile file( vcardFileName );
86 
87  if ( file.open( QIODevice::ReadOnly ) ) {
88  const QByteArray data = file.readAll();
89  file.close();
90  if ( !data.isEmpty() ) {
91  KABC::VCardConverter converter;
92  KABC::Addressee addr = converter.parseVCard( data );
93  mContactEditor->setContactTemplate(addr);
94  }
95  }
96 }
97 
98 QString IdentityEditVcardDialog::saveVcard() const
99 {
100  const KABC::Addressee addr = mContactEditor->contact();
101  KABC::VCardConverter converter;
102  QFile file(mVcardFileName);
103  if ( file.open( QIODevice::WriteOnly |QIODevice::Text ) ) {
104  const QByteArray data = converter.exportVCard( addr, KABC::VCardConverter::v3_0 );
105  file.write( data );
106  file.flush();
107  file.close();
108  } else {
109  kDebug()<<"We cannot open file: "<<mVcardFileName;
110  }
111  return mVcardFileName;
112 }
113 
114 #include "identityeditvcarddialog.moc"
IdentityEditVcardDialog::saveVcard
QString saveVcard() const
saveVcard
Definition: identityeditvcarddialog.cpp:98
IdentityEditVcardDialog::IdentityEditVcardDialog
IdentityEditVcardDialog(const QString &fileName, QWidget *parent=0)
Definition: identityeditvcarddialog.cpp:29
QWidget
KDialog
IdentityEditVcardDialog::~IdentityEditVcardDialog
~IdentityEditVcardDialog()
Definition: identityeditvcarddialog.cpp:55
identityeditvcarddialog.h
IdentityEditVcardDialog::loadVcard
void loadVcard(const QString &vcardFileName)
loadVcard load vcard in a contact editor
Definition: identityeditvcarddialog.cpp:79
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmail

Skip menu "kmail"
  • 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

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