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

kabc

  • 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
36using namespace KABC;
37
38ResourceFileConfig::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
70void ResourceFileConfig::setEditMode( bool value )
71{
72 mFormatBox->setEnabled( !value );
73 mInEditMode = value;
74}
75
76void 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
93void 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
109void 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:95
KABC::FormatFactory::info
FormatInfo info(const QString &type) const
Returns the info structure for a special type.
Definition: formatfactory.cpp:136
KABC::FormatFactory::self
static FormatFactory * self()
Returns the global format factory.
Definition: formatfactory.cpp:68
KABC::FormatFactory::formats
QStringList formats()
Returns a list of all available format types.
Definition: formatfactory.cpp:118
KABC::ResourceFile
This resource allows access to a local file.
Definition: resourcefile.h:47
KABC::ResourceFile::fileName
QString fileName() const
Return name of file used for loading and saving the address book.
Definition: resourcefile.cpp:412
KABC::ResourceFile::setFileName
void setFileName(const QString &)
Set name of file to be used for saving.
Definition: resourcefile.cpp:399
KABC::ResourceFile::setFormat
void setFormat(const QString &name)
Sets a new format by name.
Definition: resourcefile.cpp:417
KABC::ResourceFile::format
QString format() const
Returns the format name.
Definition: resourcefile.cpp:426
KABC::StdAddressBook::fileName
static QString fileName()
Returns the default file name for vcard-based addressbook.
Definition: stdaddressbook.cpp:64
KRES::Resource
KABC
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)
Definition: address.h:29
KABC::FormatInfo
Dataype to hold information on format plugins.
Definition: formatfactory.h:39
KABC::FormatInfo::isNull
bool isNull() const
Returns whether this info object is null.
Definition: formatfactory.h:45
KABC::FormatInfo::nameLabel
QString nameLabel
Localized string used as format's name, e.g.
Definition: formatfactory.h:65
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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
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