author | ulf69 <ulf69> | 2004-08-04 22:45:22 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-04 22:45:22 (UTC) |
commit | c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852 (patch) (unidiff) | |
tree | dc59744a6d59ba241e793ce051da485d0bf16d06 /kabc/plugins/file/resourcefile.cpp | |
parent | b83866e08ddcc5cb2734801977927f48b53a2e1c (diff) | |
download | kdepimpi-c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852.zip kdepimpi-c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852.tar.gz kdepimpi-c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852.tar.bz2 |
final changes for addressbook sync config dialog
Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index d98efc8..da2e4d7 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -21,154 +21,144 @@ | |||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
30 | #ifndef _WIN32_ | 30 | #ifndef _WIN32_ |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qfileinfo.h> | 35 | #include <qfileinfo.h> |
36 | #include <qregexp.h> | 36 | #include <qregexp.h> |
37 | #include <qtimer.h> | 37 | #include <qtimer.h> |
38 | 38 | ||
39 | #include <kapplication.h> | 39 | #include <kapplication.h> |
40 | #include <kconfig.h> | 40 | #include <kconfig.h> |
41 | #include <kdebug.h> | 41 | #include <kdebug.h> |
42 | #include <klocale.h> | 42 | #include <klocale.h> |
43 | //US #include <ksavefile.h> | 43 | //US #include <ksavefile.h> |
44 | #include <kstandarddirs.h> | 44 | #include <kstandarddirs.h> |
45 | #include <kmessagebox.h> | 45 | #include <kmessagebox.h> |
46 | 46 | ||
47 | #include "formatfactory.h" | 47 | #include "formatfactory.h" |
48 | 48 | ||
49 | #include "resource.h" | 49 | #include "resource.h" |
50 | #include "resourcefileconfig.h" | 50 | #include "resourcefileconfig.h" |
51 | #include "stdaddressbook.h" | 51 | #include "stdaddressbook.h" |
52 | 52 | ||
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | #include "syncprefwidget.h" | 54 | #include "syncprefwidget.h" |
55 | 55 | ||
56 | 56 | ||
57 | using namespace KABC; | 57 | using namespace KABC; |
58 | 58 | ||
59 | extern "C" | 59 | extern "C" |
60 | #ifdef _WIN32_ | 60 | #ifdef _WIN32_ |
61 | __declspec(dllexport) | 61 | __declspec(dllexport) |
62 | #else | 62 | #else |
63 | { | 63 | { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | //US void *init_kabc_file() | 66 | //US void *init_kabc_file() |
67 | void *init_microkabc_file() | 67 | void *init_microkabc_file() |
68 | { | 68 | { |
69 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidget>(); | 69 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); |
70 | } | 70 | } |
71 | #ifndef _WIN32_ | 71 | #ifndef _WIN32_ |
72 | } | 72 | } |
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) | 75 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) |
76 | : Resource( config, syncable ) , mFormat( 0 ) | 76 | : Resource( config, syncable ) , mFormat( 0 ) |
77 | { | 77 | { |
78 | QString fileName, formatName; | 78 | QString fileName, formatName, default_fileName; |
79 | |||
80 | if (syncable == true) | ||
81 | default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; | ||
82 | else | ||
83 | default_fileName = StdAddressBook::fileName(); | ||
79 | 84 | ||
80 | KConfig *cfg = (KConfig *)config; | 85 | KConfig *cfg = (KConfig *)config; |
81 | if ( cfg ) { | 86 | if ( cfg ) { |
82 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); | 87 | fileName = cfg->readEntry( "FileName", default_fileName ); |
83 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 88 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
84 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); | ||
85 | } else { | 89 | } else { |
86 | fileName = StdAddressBook::fileName(); | 90 | fileName = default_fileName; |
87 | formatName = "vcard"; | 91 | formatName = "vcard"; |
88 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); | ||
89 | } | 92 | } |
90 | 93 | ||
91 | init( fileName, formatName ); | 94 | init( fileName, formatName ); |
92 | } | 95 | } |
93 | 96 | ||
94 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , | 97 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , |
95 | const QString &formatName ) | 98 | const QString &formatName ) |
96 | : Resource( 0, syncable ) | 99 | : Resource( 0, syncable ) |
97 | { | 100 | { |
98 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 101 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
99 | init( fileName, formatName ); | 102 | init( fileName, formatName ); |
100 | } | 103 | } |
101 | 104 | ||
102 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 105 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
103 | { | 106 | { |
104 | mFormatName = formatName; | 107 | mFormatName = formatName; |
105 | 108 | ||
106 | FormatFactory *factory = FormatFactory::self(); | 109 | FormatFactory *factory = FormatFactory::self(); |
107 | mFormat = factory->format( mFormatName ); | 110 | mFormat = factory->format( mFormatName ); |
108 | 111 | ||
109 | if ( !mFormat ) { | 112 | if ( !mFormat ) { |
110 | mFormatName = "vcard"; | 113 | mFormatName = "vcard"; |
111 | mFormat = factory->format( mFormatName ); | 114 | mFormat = factory->format( mFormatName ); |
112 | } | 115 | } |
113 | 116 | ||
114 | /*US | ||
115 | //US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); | ||
116 | if (mFormatName == "vcard") { | ||
117 | mFormat = new VCardFormatPlugin2(); | ||
118 | // qDebug("ResourceFile::init format VCardFormatPlugin2"); | ||
119 | } | ||
120 | else if (mFormatName == "binary") { | ||
121 | mFormat = new BinaryFormat(); | ||
122 | // qDebug("ResourceFile::init format BinaryFormat"); | ||
123 | } | ||
124 | else | ||
125 | qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); | ||
126 | */ | ||
127 | 117 | ||
128 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 118 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
129 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 119 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
130 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 120 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
131 | 121 | ||
132 | setFileName( fileName ); | 122 | setFileName( fileName ); |
133 | } | 123 | } |
134 | 124 | ||
135 | ResourceFile::~ResourceFile() | 125 | ResourceFile::~ResourceFile() |
136 | { | 126 | { |
137 | delete mFormat; | 127 | delete mFormat; |
138 | mFormat = 0; | 128 | mFormat = 0; |
139 | } | 129 | } |
140 | 130 | ||
141 | void ResourceFile::writeConfig( KConfig *config ) | 131 | void ResourceFile::writeConfig( KConfig *config ) |
142 | { | 132 | { |
143 | 133 | ||
144 | config->setGroup( "Resource_" + identifier() ); | 134 | config->setGroup( "Resource_" + identifier() ); |
145 | Resource::writeConfig( config ); | 135 | Resource::writeConfig( config ); |
146 | 136 | ||
147 | config->writeEntry( "FileName", mFileName ); | 137 | config->writeEntry( "FileName", mFileName ); |
148 | config->writeEntry( "FileFormat", mFormatName ); | 138 | config->writeEntry( "FileFormat", mFormatName ); |
149 | 139 | ||
150 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 140 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
151 | 141 | ||
152 | } | 142 | } |
153 | 143 | ||
154 | Ticket *ResourceFile::requestSaveTicket() | 144 | Ticket *ResourceFile::requestSaveTicket() |
155 | { | 145 | { |
156 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 146 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
157 | 147 | ||
158 | if ( !addressBook() ) return 0; | 148 | if ( !addressBook() ) return 0; |
159 | 149 | ||
160 | if ( !lock( mFileName ) ) { | 150 | if ( !lock( mFileName ) ) { |
161 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" | 151 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" |
162 | << mFileName << "'" << endl; | 152 | << mFileName << "'" << endl; |
163 | return 0; | 153 | return 0; |
164 | } | 154 | } |
165 | return createTicket( this ); | 155 | return createTicket( this ); |
166 | } | 156 | } |
167 | 157 | ||
168 | 158 | ||
169 | bool ResourceFile::doOpen() | 159 | bool ResourceFile::doOpen() |
170 | { | 160 | { |
171 | QFile file( mFileName ); | 161 | QFile file( mFileName ); |
172 | 162 | ||
173 | if ( !file.exists() ) { | 163 | if ( !file.exists() ) { |
174 | // try to create the file | 164 | // try to create the file |