Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index c89939d..dad4571 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -1,181 +1,188 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 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 | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
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 | #include <kglobalsettings.h> | 46 | #include <kglobalsettings.h> |
47 | 47 | ||
48 | #include "formatfactory.h" | 48 | #include "formatfactory.h" |
49 | 49 | ||
50 | #include "resource.h" | 50 | #include "resource.h" |
51 | #include "resourcefileconfig.h" | 51 | #include "resourcefileconfig.h" |
52 | #include "stdaddressbook.h" | 52 | #include "stdaddressbook.h" |
53 | #define NO_DIRWATCH | 53 | #define NO_DIRWATCH |
54 | #include "resourcefile.h" | 54 | #include "resourcefile.h" |
55 | 55 | ||
56 | //#define ALLOW_LOCKING | 56 | //#define ALLOW_LOCKING |
57 | 57 | ||
58 | 58 | ||
59 | using namespace KABC; | 59 | using namespace KABC; |
60 | 60 | ||
61 | extern "C" | 61 | extern "C" |
62 | #ifdef _WIN32_ | 62 | #ifdef _WIN32_ |
63 | __declspec(dllexport) | 63 | __declspec(dllexport) |
64 | #else | 64 | #else |
65 | { | 65 | { |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | //US void *init_kabc_file() | 68 | //US void *init_kabc_file() |
69 | void *init_microkabc_file() | 69 | void *init_microkabc_file() |
70 | { | 70 | { |
71 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); | 71 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); |
72 | } | 72 | } |
73 | #ifndef _WIN32_ | 73 | #ifndef _WIN32_ |
74 | } | 74 | } |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | ResourceFile::ResourceFile( const KConfig *config ) | 77 | ResourceFile::ResourceFile( const KConfig *config ) |
78 | : Resource( config ) , mFormat( 0 ) | 78 | : Resource( config ) , mFormat( 0 ) |
79 | { | 79 | { |
80 | QString fileName, formatName, default_fileName; | 80 | QString fileName, formatName, default_fileName; |
81 | 81 | ||
82 | default_fileName = StdAddressBook::fileName(); | 82 | default_fileName = StdAddressBook::fileName(); |
83 | mLastBackupDate = -1; | 83 | mLastBackupDate = -1; |
84 | KConfig *cfg = (KConfig *)config; | 84 | KConfig *cfg = (KConfig *)config; |
85 | if ( cfg ) { | 85 | if ( cfg ) { |
86 | #ifdef _WIN32_ | ||
87 | // we use plugins on win32. the group is stored in a static variable | ||
88 | // such that group info not available on win32 plugins | ||
89 | // to fix that, it would be a looooot of work | ||
90 | if ( !cfg->tempGroup().isEmpty() ) | ||
91 | cfg->setGroup( cfg->tempGroup() ); | ||
92 | #endif | ||
86 | fileName = cfg->readEntry( "FileName", default_fileName ); | 93 | fileName = cfg->readEntry( "FileName", default_fileName ); |
87 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 94 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
88 | mFamily = cfg->readEntry( "ResourceName", "std" ); | 95 | mFamily = cfg->readEntry( "ResourceName", "std" ); |
89 | mLastBackupDate = cfg->readNumEntry( "LastBackupDate", 0 ); | 96 | mLastBackupDate = cfg->readNumEntry( "LastBackupDate", 0 ); |
90 | } else { | 97 | } else { |
91 | fileName = default_fileName; | 98 | fileName = default_fileName; |
92 | formatName = "vcard"; | 99 | formatName = "vcard"; |
93 | } | 100 | } |
94 | 101 | ||
95 | init( fileName, formatName ); | 102 | init( fileName, formatName ); |
96 | } | 103 | } |
97 | 104 | ||
98 | ResourceFile::ResourceFile( const QString &fileName , | 105 | ResourceFile::ResourceFile( const QString &fileName , |
99 | const QString &formatName ) | 106 | const QString &formatName ) |
100 | : Resource( 0 ) | 107 | : Resource( 0 ) |
101 | { | 108 | { |
102 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 109 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
103 | 110 | ||
104 | 111 | ||
105 | mLastBackupDate = -1; | 112 | mLastBackupDate = -1; |
106 | init( fileName, formatName ); | 113 | init( fileName, formatName ); |
107 | } | 114 | } |
108 | 115 | ||
109 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 116 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
110 | { | 117 | { |
111 | mFormatName = formatName; | 118 | mFormatName = formatName; |
112 | 119 | ||
113 | FormatFactory *factory = FormatFactory::self(); | 120 | FormatFactory *factory = FormatFactory::self(); |
114 | mFormat = factory->format( mFormatName ); | 121 | mFormat = factory->format( mFormatName ); |
115 | 122 | ||
116 | if ( !mFormat ) { | 123 | if ( !mFormat ) { |
117 | mFormatName = "vcard"; | 124 | mFormatName = "vcard"; |
118 | mFormat = factory->format( mFormatName ); | 125 | mFormat = factory->format( mFormatName ); |
119 | } | 126 | } |
120 | 127 | ||
121 | #ifndef NO_DIRWATCH | 128 | #ifndef NO_DIRWATCH |
122 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 129 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
123 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 130 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
124 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 131 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
125 | #endif | 132 | #endif |
126 | 133 | ||
127 | QString localKdeDir; | 134 | QString localKdeDir; |
128 | localKdeDir = readEnvPath("LOCALMICROKDEHOME"); | 135 | localKdeDir = readEnvPath("LOCALMICROKDEHOME"); |
129 | if ( ! localKdeDir.isEmpty() ) { | 136 | if ( ! localKdeDir.isEmpty() ) { |
130 | qDebug("LOCALMICROKDEHOME is set to: %s",localKdeDir.latin1() ); | 137 | qDebug("LOCALMICROKDEHOME is set to: %s",localKdeDir.latin1() ); |
131 | QFileInfo fi ( fileName ); | 138 | QFileInfo fi ( fileName ); |
132 | QString localname = localKdeDir + "/apps/kabc/" + fi.fileName (); | 139 | QString localname = localKdeDir + "/apps/kabc/" + fi.fileName (); |
133 | QFileInfo fi2 ( localname ); | 140 | QFileInfo fi2 ( localname ); |
134 | if ( ! fi2.exists() || mFamily == "sync_res" ) { | 141 | if ( ! fi2.exists() || mFamily == "sync_res" ) { |
135 | if ( fi.exists() && mFamily == "sync_res") { | 142 | if ( fi.exists() && mFamily == "sync_res") { |
136 | qDebug("LOCAL mode SYNC mode using absolute file path "); | 143 | qDebug("LOCAL mode SYNC mode using absolute file path "); |
137 | setFileName( fileName ); | 144 | setFileName( fileName ); |
138 | return; | 145 | return; |
139 | } else { | 146 | } else { |
140 | KMessageBox::error(0,i18n("Addressbook resource file not found:\n '%1'.\nIn LOCAL mode only resource files in\n'%2'\nare supported.\n(i.e. in the dir ./apps/kabc/ relative to the kapi(.exe) binary.)\n\nIf you are starting KA/Pi for the very first time\nyou will get this error message as well.\nIt will create the missing file automatically for you.").arg(localname).arg(localKdeDir+"/apps/kabc/") ); | 147 | KMessageBox::error(0,i18n("Addressbook resource file not found:\n '%1'.\nIn LOCAL mode only resource files in\n'%2'\nare supported.\n(i.e. in the dir ./apps/kabc/ relative to the kapi(.exe) binary.)\n\nIf you are starting KA/Pi for the very first time\nyou will get this error message as well.\nIt will create the missing file automatically for you.").arg(localname).arg(localKdeDir+"/apps/kabc/") ); |
141 | setFileName( localname ); | 148 | setFileName( localname ); |
142 | return; | 149 | return; |
143 | } | 150 | } |
144 | 151 | ||
145 | } else { | 152 | } else { |
146 | qDebug("Local resource file found. Changing filename to: %s",localname.latin1() ); | 153 | qDebug("Local resource file found. Changing filename to: %s",localname.latin1() ); |
147 | setFileName( localname ); | 154 | setFileName( localname ); |
148 | return; | 155 | return; |
149 | } | 156 | } |
150 | 157 | ||
151 | } | 158 | } |
152 | setFileName( fileName ); | 159 | setFileName( fileName ); |
153 | } | 160 | } |
154 | 161 | ||
155 | ResourceFile::~ResourceFile() | 162 | ResourceFile::~ResourceFile() |
156 | { | 163 | { |
157 | delete mFormat; | 164 | delete mFormat; |
158 | mFormat = 0; | 165 | mFormat = 0; |
159 | } | 166 | } |
160 | 167 | ||
161 | void ResourceFile::writeConfig( KConfig *config ) | 168 | void ResourceFile::writeConfig( KConfig *config ) |
162 | { | 169 | { |
163 | 170 | ||
164 | config->setGroup( "Resource_" + identifier() ); | 171 | config->setGroup( "Resource_" + identifier() ); |
165 | Resource::writeConfig( config ); | 172 | Resource::writeConfig( config ); |
166 | 173 | ||
167 | config->writeEntry( "FileName", fileName() ); | 174 | config->writeEntry( "FileName", fileName() ); |
168 | config->writeEntry( "FileFormat", mFormatName ); | 175 | config->writeEntry( "FileFormat", mFormatName ); |
169 | 176 | ||
170 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 177 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
171 | 178 | ||
172 | } | 179 | } |
173 | 180 | ||
174 | Ticket *ResourceFile::requestSaveTicket() | 181 | Ticket *ResourceFile::requestSaveTicket() |
175 | { | 182 | { |
176 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 183 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
177 | 184 | ||
178 | if ( !addressBook() ) return 0; | 185 | if ( !addressBook() ) return 0; |
179 | 186 | ||
180 | #ifdef ALLOW_LOCKING | 187 | #ifdef ALLOW_LOCKING |
181 | if ( !lock( mFileName ) ) { | 188 | if ( !lock( mFileName ) ) { |