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

kabc

  • sources
  • kde-4.14
  • kdepimlibs
  • kabc
  • plugins
  • file
resourcefileconfig.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "resourcefileconfig.h"
22 #include "resourcefile.h"
23 
24 #include "kabc/formatfactory.h"
25 #include "kabc/stdaddressbook.h"
26 
27 #include <kdebug.h>
28 #include <klocalizedstring.h>
29 #include <kstandarddirs.h>
30 #include <kdialog.h>
31 
32 #include <QFormLayout>
33 
34 #include <unistd.h>
35 
36 using namespace KABC;
37 
38 ResourceFileConfig::ResourceFileConfig( QWidget *parent )
39  : ConfigWidget( parent )
40 {
41  QFormLayout *mainLayout = new QFormLayout( this );
42  mainLayout->setMargin( 0 );
43 
44  mFormatBox = new KComboBox( this );
45 
46  mainLayout->addRow( i18n( "Format:" ), mFormatBox );
47 
48  mFileNameEdit = new KUrlRequester( this );
49  mFileNameEdit->setMode( KFile::File | KFile::LocalOnly );
50 
51  mainLayout->addRow( i18n( "Location:" ), mFileNameEdit );
52 
53  connect( mFileNameEdit, SIGNAL(textChanged(QString)),
54  SLOT(checkFilePermissions(QString)) );
55 
56  FormatFactory *factory = FormatFactory::self();
57  QStringList formats = factory->formats();
58  QStringList::Iterator it;
59  for ( it = formats.begin(); it != formats.end(); ++it ) {
60  FormatInfo info = factory->info( *it );
61  if ( !info.isNull() ) {
62  mFormatTypes << ( *it );
63  mFormatBox->addItem( info.nameLabel );
64  }
65  }
66 
67  mInEditMode = false;
68 }
69 
70 void ResourceFileConfig::setEditMode( bool value )
71 {
72  mFormatBox->setEnabled( !value );
73  mInEditMode = value;
74 }
75 
76 void ResourceFileConfig::loadSettings( KRES::Resource *res )
77 {
78  ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
79 
80  if ( !resource ) {
81  kDebug() << "cast failed";
82  return;
83  }
84 
85  mFormatBox->setCurrentIndex( mFormatTypes.indexOf( resource->format() ) );
86 
87  mFileNameEdit->setUrl( KUrl::fromPath( resource->fileName() ) );
88  if ( mFileNameEdit->url().isEmpty() ) {
89  mFileNameEdit->setUrl( KUrl::fromPath( KABC::StdAddressBook::fileName() ) );
90  }
91 }
92 
93 void ResourceFileConfig::saveSettings( KRES::Resource *res )
94 {
95  ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
96 
97  if ( !resource ) {
98  kDebug() << "cast failed";
99  return;
100  }
101 
102  if ( !mInEditMode ) {
103  resource->setFormat( mFormatTypes[ mFormatBox->currentIndex() ] );
104  }
105 
106  resource->setFileName( mFileNameEdit->url().path() );
107 }
108 
109 void ResourceFileConfig::checkFilePermissions( const QString &fileName )
110 {
111  // If file exist but is not writeable...
112  if ( access( QFile::encodeName( fileName ), F_OK ) == 0 ) {
113  emit setReadOnly( access( QFile::encodeName( fileName ), W_OK ) < 0 );
114  }
115 }
116 
KABC::FormatFactory
Class for loading format plugins.
Definition: formatfactory.h:94
KABC::FormatFactory::self
static FormatFactory * self()
Returns the global format factory.
Definition: formatfactory.cpp:68
QWidget
KABC::FormatFactory::info
FormatInfo info(const QString &type) const
Returns the info structure for a special type.
Definition: formatfactory.cpp:136
KABC::FormatInfo::isNull
bool isNull() const
Returns whether this info object is null.
Definition: formatfactory.h:45
KABC::StdAddressBook::fileName
static QString fileName()
Returns the default file name for vcard-based addressbook.
Definition: stdaddressbook.cpp:64
KABC::FormatInfo
Dataype to hold information on format plugins.
Definition: formatfactory.h:38
KABC::ResourceFile::fileName
QString fileName() const
Return name of file used for loading and saving the address book.
Definition: resourcefile.cpp:412
KABC::FormatFactory::formats
QStringList formats()
Returns a list of all available format types.
Definition: formatfactory.cpp:118
QList::Iterator
typedef Iterator
QString
QLayout::setMargin
void setMargin(int margin)
QFormLayout::addRow
void addRow(QWidget *label, QWidget *field)
QStringList
KRES::Resource
QList::end
iterator end()
KABC::ResourceFile::format
QString format() const
Returns the format name.
Definition: resourcefile.cpp:426
KABC::FormatInfo::nameLabel
QString nameLabel
Localized string used as format's name, e.g.
Definition: formatfactory.h:65
KABC::ResourceFile::setFileName
void setFileName(const QString &)
Set name of file to be used for saving.
Definition: resourcefile.cpp:399
KABC::ResourceFile
This resource allows access to a local file.
Definition: resourcefile.h:46
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QList::begin
iterator begin()
QFile::encodeName
QByteArray encodeName(const QString &fileName)
KABC::ResourceFile::setFormat
void setFormat(const QString &name)
Sets a new format by name.
Definition: resourcefile.cpp:417
QFormLayout
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

Skip menu "kabc"
  • Main Page
  • Namespace List
  • Namespace Members
  • 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