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

kmail

  • sources
  • kde-4.14
  • kdepim
  • kmail
  • identity
identityeditvcarddialog.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012-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 #include "identityeditvcarddialog.h"
19 
20 #include <KABC/VCardConverter>
21 #include <KLocalizedString>
22 #include <Akonadi/Contact/ContactEditor>
23 #include <KDebug>
24 #include <KMessageBox>
25 #include <KStandardDirs>
26 
27 #include <QHBoxLayout>
28 #include <QFile>
29 
30 IdentityEditVcardDialog::IdentityEditVcardDialog(const QString &fileName, QWidget *parent)
31  : KDialog(parent)
32 {
33  if (QFile(fileName).exists()) {
34  setCaption( i18n( "Edit own vCard" ) );
35  setButtons( User1|Ok|Cancel );
36  setButtonText(User1, i18n("Delete current vCard"));
37  connect(this, SIGNAL(user1Clicked()), this, SLOT(slotDeleteCurrentVCard()));
38  } else {
39  setCaption( i18n("Create own vCard") );
40  setButtons( Ok|Cancel );
41  }
42 
43  setDefaultButton( Ok );
44  setModal( true );
45  QWidget *mainWidget = new QWidget( this );
46  QHBoxLayout *mainLayout = new QHBoxLayout( mainWidget );
47  mainLayout->setSpacing( KDialog::spacingHint() );
48  mainLayout->setMargin( KDialog::marginHint() );
49  setMainWidget( mainWidget );
50 
51  mContactEditor = new Akonadi::ContactEditor( Akonadi::ContactEditor::CreateMode, Akonadi::ContactEditor::VCardMode, this );
52  mainLayout->addWidget(mContactEditor);
53  loadVcard(fileName);
54 }
55 
56 IdentityEditVcardDialog::~IdentityEditVcardDialog()
57 {
58 }
59 
60 void IdentityEditVcardDialog::slotDeleteCurrentVCard()
61 {
62  if (mVcardFileName.isEmpty())
63  return;
64  if (KMessageBox::Yes == KMessageBox::questionYesNo(this, i18n("Are you sure to want to delete this vCard?"), i18n("Delete vCard"))) {
65  if(mVcardFileName.startsWith(KGlobal::dirs()->localkdedir())) {
66  deleteCurrentVcard(true);
67  } else {
68  deleteCurrentVcard(false);
69  }
70  reject();
71  }
72 }
73 
74 void IdentityEditVcardDialog::deleteCurrentVcard(bool deleteOnDisk)
75 {
76  if (!mVcardFileName.isEmpty()) {
77  if (deleteOnDisk) {
78  QFile file(mVcardFileName);
79  if (file.exists()) {
80  if (!file.remove()) {
81  KMessageBox::error(this, i18n("We cannot delete vCard file."), i18n("Delete vCard"));
82  }
83  }
84  }
85  Q_EMIT vcardRemoved();
86  }
87 }
88 
89 void IdentityEditVcardDialog::loadVcard( const QString &vcardFileName)
90 {
91  if (vcardFileName.isEmpty()) {
92  return;
93  }
94  mVcardFileName = vcardFileName;
95  QFile file( vcardFileName );
96 
97  if ( file.open( QIODevice::ReadOnly ) ) {
98  const QByteArray data = file.readAll();
99  file.close();
100  if ( !data.isEmpty() ) {
101  KABC::VCardConverter converter;
102  KABC::Addressee addr = converter.parseVCard( data );
103  mContactEditor->setContactTemplate(addr);
104  }
105  }
106 }
107 
108 QString IdentityEditVcardDialog::saveVcard() const
109 {
110  const KABC::Addressee addr = mContactEditor->contact();
111  KABC::VCardConverter converter;
112  QFile file(mVcardFileName);
113  if ( file.open( QIODevice::WriteOnly |QIODevice::Text ) ) {
114  const QByteArray data = converter.exportVCard( addr, KABC::VCardConverter::v3_0 );
115  file.write( data );
116  file.flush();
117  file.close();
118  } else {
119  kDebug()<<"We cannot open file: "<<mVcardFileName;
120  }
121  return mVcardFileName;
122 }
123 
QFile::flush
bool flush()
QWidget
IdentityEditVcardDialog::saveVcard
QString saveVcard() const
saveVcard
Definition: identityeditvcarddialog.cpp:108
QByteArray
IdentityEditVcardDialog::IdentityEditVcardDialog
IdentityEditVcardDialog(const QString &fileName, QWidget *parent=0)
Definition: identityeditvcarddialog.cpp:30
QByteArray::isEmpty
bool isEmpty() const
QHBoxLayout
KDialog
IdentityEditVcardDialog::~IdentityEditVcardDialog
~IdentityEditVcardDialog()
Definition: identityeditvcarddialog.cpp:56
QFile
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QString::isEmpty
bool isEmpty() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QIODevice::readAll
QByteArray readAll()
QString
QLayout::setMargin
void setMargin(int margin)
QFile::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
QFile::close
virtual void close()
identityeditvcarddialog.h
IdentityEditVcardDialog::loadVcard
void loadVcard(const QString &vcardFileName)
loadVcard load vcard in a contact editor
Definition: identityeditvcarddialog.cpp:89
QIODevice::write
qint64 write(const char *data, qint64 maxSize)
IdentityEditVcardDialog::vcardRemoved
void vcardRemoved()
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:34:33 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
  • 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