-rw-r--r-- | kabc/kabcE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 4 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 4 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldap.cpp | 4 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 20 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 95 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 225 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.h | 3 |
8 files changed, 146 insertions, 211 deletions
diff --git a/kabc/kabcE.pro b/kabc/kabcE.pro index 598d4fc..62a66eb 100644 --- a/kabc/kabcE.pro +++ b/kabc/kabcE.pro | |||
@@ -1,193 +1,193 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | TARGET = microkabc | 3 | TARGET = microkabc |
4 | 4 | ||
5 | 5 | ||
6 | INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../microkde/kio/kio ../libkdepim ../qtcompat $(QPEDIR)/include | 6 | INCLUDEPATH += . .. ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../microkde/kio/kio ../libkdepim ../qtcompat $(QPEDIR)/include |
7 | OBJECTS_DIR = obj/$(PLATFORM) | 7 | OBJECTS_DIR = obj/$(PLATFORM) |
8 | MOC_DIR = moc/$(PLATFORM) | 8 | MOC_DIR = moc/$(PLATFORM) |
9 | DESTDIR = $(QPEDIR)/lib | 9 | DESTDIR = $(QPEDIR)/lib |
10 | LIBS += -lmicrokde | 10 | LIBS += -lmicrokde |
11 | LIBS += -lmicrokdepim | 11 | LIBS += -lmicrokdepim |
12 | #LIBS += -lldap | 12 | #LIBS += -lldap |
13 | LIBS += -L$(QPEDIR)/lib | 13 | LIBS += -L$(QPEDIR)/lib |
14 | DEFINES += KAB_EMBEDDED | 14 | DEFINES += KAB_EMBEDDED |
15 | 15 | ||
16 | INTERFACES = \ | 16 | INTERFACES = \ |
17 | 17 | ||
18 | HEADERS = \ | 18 | HEADERS = \ |
19 | address.h \ | 19 | address.h \ |
20 | addressbook.h \ | 20 | addressbook.h \ |
21 | addressee.h \ | 21 | addressee.h \ |
22 | addresseedialog.h \ | 22 | addresseedialog.h \ |
23 | addresseelist.h \ | 23 | addresseelist.h \ |
24 | agent.h \ | 24 | agent.h \ |
25 | distributionlist.h \ | 25 | distributionlist.h \ |
26 | distributionlistdialog.h \ | 26 | distributionlistdialog.h \ |
27 | distributionlisteditor.h \ | 27 | distributionlisteditor.h \ |
28 | field.h \ | 28 | field.h \ |
29 | formatfactory.h \ | 29 | formatfactory.h \ |
30 | formatplugin.h \ | 30 | formatplugin.h \ |
31 | geo.h \ | 31 | geo.h \ |
32 | key.h \ | 32 | key.h \ |
33 | phonenumber.h \ | 33 | phonenumber.h \ |
34 | picture.h \ | 34 | picture.h \ |
35 | plugin.h \ | 35 | plugin.h \ |
36 | resource.h \ | 36 | resource.h \ |
37 | secrecy.h \ | 37 | secrecy.h \ |
38 | sound.h \ | 38 | sound.h \ |
39 | stdaddressbook.h \ | 39 | stdaddressbook.h \ |
40 | syncprefwidget.h \ | 40 | syncprefwidget.h \ |
41 | timezone.h \ | 41 | timezone.h \ |
42 | tmpaddressbook.h \ | 42 | tmpaddressbook.h \ |
43 | vcardconverter.h \ | 43 | vcardconverter.h \ |
44 | vcard21parser.h \ | 44 | vcard21parser.h \ |
45 | vcardformatimpl.h \ | 45 | vcardformatimpl.h \ |
46 | vcardformatplugin.h \ | 46 | vcardformatplugin.h \ |
47 | vcardparser/vcardline.h \ | 47 | vcardparser/vcardline.h \ |
48 | vcardparser/vcard.h \ | 48 | vcardparser/vcard.h \ |
49 | vcardparser/vcardtool.h \ | 49 | vcardparser/vcardtool.h \ |
50 | vcardparser/vcardparser.h \ | 50 | vcardparser/vcardparser.h \ |
51 | vcard/include/VCardAdrParam.h \ | 51 | vcard/include/VCardAdrParam.h \ |
52 | vcard/include/VCardAdrValue.h \ | 52 | vcard/include/VCardAdrValue.h \ |
53 | vcard/include/VCardAgentParam.h \ | 53 | vcard/include/VCardAgentParam.h \ |
54 | vcard/include/VCardContentLine.h \ | 54 | vcard/include/VCardContentLine.h \ |
55 | vcard/include/VCardDateParam.h \ | 55 | vcard/include/VCardDateParam.h \ |
56 | vcard/include/VCardDateValue.h \ | 56 | vcard/include/VCardDateValue.h \ |
57 | vcard/include/VCardEmailParam.h \ | 57 | vcard/include/VCardEmailParam.h \ |
58 | vcard/include/VCardGeoValue.h \ | 58 | vcard/include/VCardGeoValue.h \ |
59 | vcard/include/VCardGroup.h \ | 59 | vcard/include/VCardGroup.h \ |
60 | vcard/include/VCardImageParam.h \ | 60 | vcard/include/VCardImageParam.h \ |
61 | vcard/include/VCardImageValue.h \ | 61 | vcard/include/VCardImageValue.h \ |
62 | vcard/include/VCardLangValue.h \ | 62 | vcard/include/VCardLangValue.h \ |
63 | vcard/include/VCardNValue.h \ | 63 | vcard/include/VCardNValue.h \ |
64 | vcard/include/VCardParam.h \ | 64 | vcard/include/VCardParam.h \ |
65 | vcard/include/VCardPhoneNumberValue.h \ | 65 | vcard/include/VCardPhoneNumberValue.h \ |
66 | vcard/include/VCardSourceParam.h \ | 66 | vcard/include/VCardSourceParam.h \ |
67 | vcard/include/VCardTelParam.h \ | 67 | vcard/include/VCardTelParam.h \ |
68 | vcard/include/VCardTextParam.h \ | 68 | vcard/include/VCardTextParam.h \ |
69 | vcard/include/VCardTextNSParam.h \ | 69 | vcard/include/VCardTextNSParam.h \ |
70 | vcard/include/VCardTextValue.h \ | 70 | vcard/include/VCardTextValue.h \ |
71 | vcard/include/VCardTextBinParam.h \ | 71 | vcard/include/VCardTextBinParam.h \ |
72 | vcard/include/VCardURIValue.h \ | 72 | vcard/include/VCardURIValue.h \ |
73 | vcard/include/VCardVCard.h \ | 73 | vcard/include/VCardVCard.h \ |
74 | vcard/include/VCardEntity.h \ | 74 | vcard/include/VCardEntity.h \ |
75 | vcard/include/VCardValue.h \ | 75 | vcard/include/VCardValue.h \ |
76 | vcard/include/VCardSoundValue.h \ | 76 | vcard/include/VCardSoundValue.h \ |
77 | vcard/include/VCardAgentValue.h \ | 77 | vcard/include/VCardAgentValue.h \ |
78 | vcard/include/VCardTelValue.h \ | 78 | vcard/include/VCardTelValue.h \ |
79 | vcard/include/VCardTextBinValue.h \ | 79 | vcard/include/VCardTextBinValue.h \ |
80 | vcard/include/VCardOrgValue.h \ | 80 | vcard/include/VCardOrgValue.h \ |
81 | vcard/include/VCardUTCValue.h \ | 81 | vcard/include/VCardUTCValue.h \ |
82 | vcard/include/VCardClassValue.h \ | 82 | vcard/include/VCardClassValue.h \ |
83 | vcard/include/VCardFloatValue.h \ | 83 | vcard/include/VCardFloatValue.h \ |
84 | vcard/include/VCardTextListValue.h \ | 84 | vcard/include/VCardTextListValue.h \ |
85 | vcard/include/generated/AdrParam-generated.h \ | 85 | vcard/include/generated/AdrParam-generated.h \ |
86 | vcard/include/generated/AdrValue-generated.h \ | 86 | vcard/include/generated/AdrValue-generated.h \ |
87 | vcard/include/generated/AgentParam-generated.h \ | 87 | vcard/include/generated/AgentParam-generated.h \ |
88 | vcard/include/generated/ContentLine-generated.h \ | 88 | vcard/include/generated/ContentLine-generated.h \ |
89 | vcard/include/generated/DateParam-generated.h \ | 89 | vcard/include/generated/DateParam-generated.h \ |
90 | vcard/include/generated/DateValue-generated.h \ | 90 | vcard/include/generated/DateValue-generated.h \ |
91 | vcard/include/generated/EmailParam-generated.h \ | 91 | vcard/include/generated/EmailParam-generated.h \ |
92 | vcard/include/generated/GeoValue-generated.h \ | 92 | vcard/include/generated/GeoValue-generated.h \ |
93 | vcard/include/generated/Group-generated.h \ | 93 | vcard/include/generated/Group-generated.h \ |
94 | vcard/include/generated/ImageParam-generated.h \ | 94 | vcard/include/generated/ImageParam-generated.h \ |
95 | vcard/include/generated/ImageValue-generated.h \ | 95 | vcard/include/generated/ImageValue-generated.h \ |
96 | vcard/include/generated/LangValue-generated.h \ | 96 | vcard/include/generated/LangValue-generated.h \ |
97 | vcard/include/generated/NValue-generated.h \ | 97 | vcard/include/generated/NValue-generated.h \ |
98 | vcard/include/generated/Param-generated.h \ | 98 | vcard/include/generated/Param-generated.h \ |
99 | vcard/include/generated/PhoneNumberValue-generated.h \ | 99 | vcard/include/generated/PhoneNumberValue-generated.h \ |
100 | vcard/include/generated/SourceParam-generated.h \ | 100 | vcard/include/generated/SourceParam-generated.h \ |
101 | vcard/include/generated/TelParam-generated.h \ | 101 | vcard/include/generated/TelParam-generated.h \ |
102 | vcard/include/generated/TextParam-generated.h \ | 102 | vcard/include/generated/TextParam-generated.h \ |
103 | vcard/include/generated/TextNSParam-generated.h \ | 103 | vcard/include/generated/TextNSParam-generated.h \ |
104 | vcard/include/generated/TextValue-generated.h \ | 104 | vcard/include/generated/TextValue-generated.h \ |
105 | vcard/include/generated/TextBinParam-generated.h \ | 105 | vcard/include/generated/TextBinParam-generated.h \ |
106 | vcard/include/generated/URIValue-generated.h \ | 106 | vcard/include/generated/URIValue-generated.h \ |
107 | vcard/include/generated/VCard-generated.h \ | 107 | vcard/include/generated/VCard-generated.h \ |
108 | vcard/include/generated/VCardEntity-generated.h \ | 108 | vcard/include/generated/VCardEntity-generated.h \ |
109 | vcard/include/generated/Value-generated.h \ | 109 | vcard/include/generated/Value-generated.h \ |
110 | vcard/include/generated/SoundValue-generated.h \ | 110 | vcard/include/generated/SoundValue-generated.h \ |
111 | vcard/include/generated/AgentValue-generated.h \ | 111 | vcard/include/generated/AgentValue-generated.h \ |
112 | vcard/include/generated/TelValue-generated.h \ | 112 | vcard/include/generated/TelValue-generated.h \ |
113 | vcard/include/generated/TextBinValue-generated.h \ | 113 | vcard/include/generated/TextBinValue-generated.h \ |
114 | vcard/include/generated/OrgValue-generated.h \ | 114 | vcard/include/generated/OrgValue-generated.h \ |
115 | vcard/include/generated/UTCValue-generated.h \ | 115 | vcard/include/generated/UTCValue-generated.h \ |
116 | vcard/include/generated/ClassValue-generated.h \ | 116 | vcard/include/generated/ClassValue-generated.h \ |
117 | vcard/include/generated/FloatValue-generated.h \ | 117 | vcard/include/generated/FloatValue-generated.h \ |
118 | vcard/include/generated/TextListValue-generated.h | 118 | vcard/include/generated/TextListValue-generated.h |
119 | 119 | ||
120 | 120 | ||
121 | 121 | ||
122 | 122 | ||
123 | SOURCES = \ | 123 | SOURCES = \ |
124 | address.cpp \ | 124 | address.cpp \ |
125 | addressbook.cpp \ | 125 | addressbook.cpp \ |
126 | addressee.cpp \ | 126 | addressee.cpp \ |
127 | addresseedialog.cpp \ | 127 | addresseedialog.cpp \ |
128 | addresseelist.cpp \ | 128 | addresseelist.cpp \ |
129 | agent.cpp \ | 129 | agent.cpp \ |
130 | distributionlist.cpp \ | 130 | distributionlist.cpp \ |
131 | distributionlistdialog.cpp \ | 131 | distributionlistdialog.cpp \ |
132 | distributionlisteditor.cpp \ | 132 | distributionlisteditor.cpp \ |
133 | field.cpp \ | 133 | field.cpp \ |
134 | formatfactory.cpp \ | 134 | formatfactory.cpp \ |
135 | geo.cpp \ | 135 | geo.cpp \ |
136 | key.cpp \ | 136 | key.cpp \ |
137 | phonenumber.cpp \ | 137 | phonenumber.cpp \ |
138 | picture.cpp \ | 138 | picture.cpp \ |
139 | plugin.cpp \ | 139 | plugin.cpp \ |
140 | resource.cpp \ | 140 | resource.cpp \ |
141 | secrecy.cpp \ | 141 | secrecy.cpp \ |
142 | sound.cpp \ | 142 | sound.cpp \ |
143 | stdaddressbook.cpp \ | 143 | stdaddressbook.cpp \ |
144 | syncprefwidget.cpp \ | 144 | syncprefwidget.cpp \ |
145 | timezone.cpp \ | 145 | timezone.cpp \ |
146 | tmpaddressbook.cpp \ | 146 | tmpaddressbook.cpp \ |
147 | vcardconverter.cpp \ | 147 | vcardconverter.cpp \ |
148 | vcard21parser.cpp \ | 148 | vcard21parser.cpp \ |
149 | vcardformatimpl.cpp \ | 149 | vcardformatimpl.cpp \ |
150 | vcardformatplugin.cpp \ | 150 | vcardformatplugin.cpp \ |
151 | vcardparser/vcardline.cpp \ | 151 | vcardparser/vcardline.cpp \ |
152 | vcardparser/vcard.cpp \ | 152 | vcardparser/vcard.cpp \ |
153 | vcardparser/vcardtool.cpp \ | 153 | vcardparser/vcardtool.cpp \ |
154 | vcardparser/vcardparser.cpp \ | 154 | vcardparser/vcardparser.cpp \ |
155 | vcard/AdrParam.cpp \ | 155 | vcard/AdrParam.cpp \ |
156 | vcard/AdrValue.cpp \ | 156 | vcard/AdrValue.cpp \ |
157 | vcard/AgentParam.cpp \ | 157 | vcard/AgentParam.cpp \ |
158 | vcard/ContentLine.cpp \ | 158 | vcard/ContentLine.cpp \ |
159 | vcard/DateParam.cpp \ | 159 | vcard/DateParam.cpp \ |
160 | vcard/DateValue.cpp \ | 160 | vcard/DateValue.cpp \ |
161 | vcard/EmailParam.cpp \ | 161 | vcard/EmailParam.cpp \ |
162 | vcard/Entity.cpp \ | 162 | vcard/Entity.cpp \ |
163 | vcard/Enum.cpp \ | 163 | vcard/Enum.cpp \ |
164 | vcard/GeoValue.cpp \ | 164 | vcard/GeoValue.cpp \ |
165 | vcard/ImageParam.cpp \ | 165 | vcard/ImageParam.cpp \ |
166 | vcard/ImageValue.cpp \ | 166 | vcard/ImageValue.cpp \ |
167 | vcard/LangValue.cpp \ | 167 | vcard/LangValue.cpp \ |
168 | vcard/NValue.cpp \ | 168 | vcard/NValue.cpp \ |
169 | vcard/Param.cpp \ | 169 | vcard/Param.cpp \ |
170 | vcard/PhoneNumberValue.cpp \ | 170 | vcard/PhoneNumberValue.cpp \ |
171 | vcard/RToken.cpp \ | 171 | vcard/RToken.cpp \ |
172 | vcard/SourceParam.cpp \ | 172 | vcard/SourceParam.cpp \ |
173 | vcard/TelParam.cpp \ | 173 | vcard/TelParam.cpp \ |
174 | vcard/TextParam.cpp \ | 174 | vcard/TextParam.cpp \ |
175 | vcard/TextValue.cpp \ | 175 | vcard/TextValue.cpp \ |
176 | vcard/TextBinParam.cpp \ | 176 | vcard/TextBinParam.cpp \ |
177 | vcard/URIValue.cpp \ | 177 | vcard/URIValue.cpp \ |
178 | vcard/VCardv.cpp \ | 178 | vcard/VCardv.cpp \ |
179 | vcard/VCardEntity.cpp \ | 179 | vcard/VCardEntity.cpp \ |
180 | vcard/Value.cpp \ | 180 | vcard/Value.cpp \ |
181 | vcard/SoundValue.cpp \ | 181 | vcard/SoundValue.cpp \ |
182 | vcard/AgentValue.cpp \ | 182 | vcard/AgentValue.cpp \ |
183 | vcard/TelValue.cpp \ | 183 | vcard/TelValue.cpp \ |
184 | vcard/TextBinValue.cpp \ | 184 | vcard/TextBinValue.cpp \ |
185 | vcard/OrgValue.cpp \ | 185 | vcard/OrgValue.cpp \ |
186 | vcard/UTCValue.cpp \ | 186 | vcard/UTCValue.cpp \ |
187 | vcard/ClassValue.cpp \ | 187 | vcard/ClassValue.cpp \ |
188 | vcard/FloatValue.cpp \ | 188 | vcard/FloatValue.cpp \ |
189 | vcard/TextListValue.cpp | 189 | vcard/TextListValue.cpp |
190 | 190 | ||
191 | 191 | ||
192 | # plugins/ldap/resourceldap.cpp \ | 192 | # plugins/ldap/resourceldap.cpp \ |
193 | # plugins/ldap/resourceldapconfig.cpp \ | 193 | # plugins/ldap/resourceldapconfig.cpp \ |
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index d978e61..29f1e3a 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp | |||
@@ -1,365 +1,365 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@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 | 28 | ||
29 | #include <sys/types.h> | 29 | #include <sys/types.h> |
30 | #include <sys/stat.h> | 30 | #include <sys/stat.h> |
31 | #ifndef _WIN32_ | 31 | #ifndef _WIN32_ |
32 | #include <unistd.h> | 32 | #include <unistd.h> |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | #include <qtimer.h> | 36 | #include <qtimer.h> |
37 | #include <qwidget.h> | 37 | #include <qwidget.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 | //US #include <kgenericfactory.h> | 42 | //US #include <kgenericfactory.h> |
43 | #include <kglobal.h> | 43 | #include <kglobal.h> |
44 | #include <klocale.h> | 44 | #include <klocale.h> |
45 | #include <kstandarddirs.h> | 45 | #include <kstandarddirs.h> |
46 | #include <kurlrequester.h> | 46 | #include <kurlrequester.h> |
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | 48 | ||
49 | #include "addressbook.h" | 49 | #include "addressbook.h" |
50 | 50 | ||
51 | #include "formatfactory.h" | 51 | #include "formatfactory.h" |
52 | 52 | ||
53 | #include "resourcedirconfig.h" | 53 | #include "resourcedirconfig.h" |
54 | #include "stdaddressbook.h" | 54 | #include "stdaddressbook.h" |
55 | 55 | ||
56 | //US | 56 | //US |
57 | #include <qdir.h> | 57 | #include <qdir.h> |
58 | 58 | ||
59 | #include "resourcedir.h" | 59 | #include "resourcedir.h" |
60 | #include "syncwidget.h" | 60 | #include "syncprefwidget.h" |
61 | 61 | ||
62 | using namespace KABC; | 62 | using namespace KABC; |
63 | 63 | ||
64 | extern "C" | 64 | extern "C" |
65 | #ifdef _WIN32_ | 65 | #ifdef _WIN32_ |
66 | __declspec(dllexport) | 66 | __declspec(dllexport) |
67 | #else | 67 | #else |
68 | { | 68 | { |
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | //US void *init_kabc_dir() | 71 | //US void *init_kabc_dir() |
72 | void *init_microkabc_dir() | 72 | void *init_microkabc_dir() |
73 | { | 73 | { |
74 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, KRES::SyncWidget>(); | 74 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidget>(); |
75 | } | 75 | } |
76 | #ifndef _WIN32_ | 76 | #ifndef _WIN32_ |
77 | } | 77 | } |
78 | #endif | 78 | #endif |
79 | 79 | ||
80 | ResourceDir::ResourceDir( const KConfig *config, bool syncable ) | 80 | ResourceDir::ResourceDir( const KConfig *config, bool syncable ) |
81 | : Resource( config, syncable ) | 81 | : Resource( config, syncable ) |
82 | { | 82 | { |
83 | QString path; | 83 | QString path; |
84 | 84 | ||
85 | KConfig *cfg = (KConfig *)config; | 85 | KConfig *cfg = (KConfig *)config; |
86 | if ( cfg ) { | 86 | if ( cfg ) { |
87 | //US path = config->readEntry( "FilePath" ); | 87 | //US path = config->readEntry( "FilePath" ); |
88 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); | 88 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); |
89 | //US mFormatName = config->readEntry( "FileFormat" ); | 89 | //US mFormatName = config->readEntry( "FileFormat" ); |
90 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); | 90 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); |
91 | } else { | 91 | } else { |
92 | path = StdAddressBook::directoryName(); | 92 | path = StdAddressBook::directoryName(); |
93 | mFormatName = "vcard"; | 93 | mFormatName = "vcard"; |
94 | } | 94 | } |
95 | 95 | ||
96 | 96 | ||
97 | FormatFactory *factory = FormatFactory::self(); | 97 | FormatFactory *factory = FormatFactory::self(); |
98 | mFormat = factory->format( mFormatName ); | 98 | mFormat = factory->format( mFormatName ); |
99 | 99 | ||
100 | if ( !mFormat ) { | 100 | if ( !mFormat ) { |
101 | mFormatName = "vcard"; | 101 | mFormatName = "vcard"; |
102 | mFormat = factory->format( mFormatName ); | 102 | mFormat = factory->format( mFormatName ); |
103 | } | 103 | } |
104 | 104 | ||
105 | /*US | 105 | /*US |
106 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); | 106 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); |
107 | if (mFormatName == "vcard") | 107 | if (mFormatName == "vcard") |
108 | mFormat = new VCardFormatPlugin2(); | 108 | mFormat = new VCardFormatPlugin2(); |
109 | else if (mFormatName == "binary") | 109 | else if (mFormatName == "binary") |
110 | mFormat = new BinaryFormat(); | 110 | mFormat = new BinaryFormat(); |
111 | else | 111 | else |
112 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); | 112 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); |
113 | */ | 113 | */ |
114 | 114 | ||
115 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); | 115 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); |
116 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); | 116 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); |
117 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); | 117 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); |
118 | 118 | ||
119 | setPath( path ); | 119 | setPath( path ); |
120 | } | 120 | } |
121 | 121 | ||
122 | ResourceDir::~ResourceDir() | 122 | ResourceDir::~ResourceDir() |
123 | { | 123 | { |
124 | delete mFormat; | 124 | delete mFormat; |
125 | mFormat = 0; | 125 | mFormat = 0; |
126 | } | 126 | } |
127 | 127 | ||
128 | void ResourceDir::writeConfig( KConfig *config ) | 128 | void ResourceDir::writeConfig( KConfig *config ) |
129 | { | 129 | { |
130 | config->setGroup( "Resource_" + identifier() ); | 130 | config->setGroup( "Resource_" + identifier() ); |
131 | Resource::writeConfig( config ); | 131 | Resource::writeConfig( config ); |
132 | 132 | ||
133 | config->writeEntry( "FilePath", mPath ); | 133 | config->writeEntry( "FilePath", mPath ); |
134 | config->writeEntry( "FileFormat", mFormatName ); | 134 | config->writeEntry( "FileFormat", mFormatName ); |
135 | } | 135 | } |
136 | 136 | ||
137 | Ticket *ResourceDir::requestSaveTicket() | 137 | Ticket *ResourceDir::requestSaveTicket() |
138 | { | 138 | { |
139 | kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; | 139 | kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; |
140 | 140 | ||
141 | if ( !addressBook() ) return 0; | 141 | if ( !addressBook() ) return 0; |
142 | 142 | ||
143 | if ( !lock( mPath ) ) { | 143 | if ( !lock( mPath ) ) { |
144 | kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" | 144 | kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" |
145 | << mPath << "'" << endl; | 145 | << mPath << "'" << endl; |
146 | return 0; | 146 | return 0; |
147 | } | 147 | } |
148 | return createTicket( this ); | 148 | return createTicket( this ); |
149 | } | 149 | } |
150 | 150 | ||
151 | 151 | ||
152 | bool ResourceDir::doOpen() | 152 | bool ResourceDir::doOpen() |
153 | { | 153 | { |
154 | QDir dir( mPath ); | 154 | QDir dir( mPath ); |
155 | if ( !dir.exists() ) { // no directory available | 155 | if ( !dir.exists() ) { // no directory available |
156 | return dir.mkdir( dir.path() ); | 156 | return dir.mkdir( dir.path() ); |
157 | } else { | 157 | } else { |
158 | QString testName = dir.entryList( QDir::Files )[0]; | 158 | QString testName = dir.entryList( QDir::Files )[0]; |
159 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory | 159 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory |
160 | return true; | 160 | return true; |
161 | 161 | ||
162 | QFile file( mPath + "/" + testName ); | 162 | QFile file( mPath + "/" + testName ); |
163 | if ( file.open( IO_ReadOnly ) ) | 163 | if ( file.open( IO_ReadOnly ) ) |
164 | return true; | 164 | return true; |
165 | 165 | ||
166 | if ( file.size() == 0 ) | 166 | if ( file.size() == 0 ) |
167 | return true; | 167 | return true; |
168 | 168 | ||
169 | bool ok = mFormat->checkFormat( &file ); | 169 | bool ok = mFormat->checkFormat( &file ); |
170 | file.close(); | 170 | file.close(); |
171 | return ok; | 171 | return ok; |
172 | } | 172 | } |
173 | } | 173 | } |
174 | 174 | ||
175 | void ResourceDir::doClose() | 175 | void ResourceDir::doClose() |
176 | { | 176 | { |
177 | } | 177 | } |
178 | 178 | ||
179 | bool ResourceDir::load() | 179 | bool ResourceDir::load() |
180 | { | 180 | { |
181 | kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; | 181 | kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; |
182 | 182 | ||
183 | QDir dir( mPath ); | 183 | QDir dir( mPath ); |
184 | QStringList files = dir.entryList( QDir::Files ); | 184 | QStringList files = dir.entryList( QDir::Files ); |
185 | 185 | ||
186 | QStringList::Iterator it; | 186 | QStringList::Iterator it; |
187 | bool ok = true; | 187 | bool ok = true; |
188 | for ( it = files.begin(); it != files.end(); ++it ) { | 188 | for ( it = files.begin(); it != files.end(); ++it ) { |
189 | QFile file( mPath + "/" + (*it) ); | 189 | QFile file( mPath + "/" + (*it) ); |
190 | 190 | ||
191 | if ( !file.open( IO_ReadOnly ) ) { | 191 | if ( !file.open( IO_ReadOnly ) ) { |
192 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); | 192 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); |
193 | ok = false; | 193 | ok = false; |
194 | continue; | 194 | continue; |
195 | } | 195 | } |
196 | 196 | ||
197 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) | 197 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) |
198 | ok = false; | 198 | ok = false; |
199 | 199 | ||
200 | file.close(); | 200 | file.close(); |
201 | } | 201 | } |
202 | 202 | ||
203 | return ok; | 203 | return ok; |
204 | } | 204 | } |
205 | 205 | ||
206 | bool ResourceDir::save( Ticket *ticket ) | 206 | bool ResourceDir::save( Ticket *ticket ) |
207 | { | 207 | { |
208 | kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; | 208 | kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; |
209 | 209 | ||
210 | AddressBook::Iterator it; | 210 | AddressBook::Iterator it; |
211 | bool ok = true; | 211 | bool ok = true; |
212 | 212 | ||
213 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 213 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
214 | if ( (*it).resource() != this || !(*it).changed() ) | 214 | if ( (*it).resource() != this || !(*it).changed() ) |
215 | continue; | 215 | continue; |
216 | 216 | ||
217 | QFile file( mPath + "/" + (*it).uid() ); | 217 | QFile file( mPath + "/" + (*it).uid() ); |
218 | if ( !file.open( IO_WriteOnly ) ) { | 218 | if ( !file.open( IO_WriteOnly ) ) { |
219 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); | 219 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); |
220 | continue; | 220 | continue; |
221 | } | 221 | } |
222 | 222 | ||
223 | mFormat->save( *it, &file ); | 223 | mFormat->save( *it, &file ); |
224 | 224 | ||
225 | // mark as unchanged | 225 | // mark as unchanged |
226 | (*it).setChanged( false ); | 226 | (*it).setChanged( false ); |
227 | 227 | ||
228 | file.close(); | 228 | file.close(); |
229 | } | 229 | } |
230 | 230 | ||
231 | delete ticket; | 231 | delete ticket; |
232 | unlock( mPath ); | 232 | unlock( mPath ); |
233 | 233 | ||
234 | return ok; | 234 | return ok; |
235 | } | 235 | } |
236 | 236 | ||
237 | bool ResourceDir::lock( const QString &path ) | 237 | bool ResourceDir::lock( const QString &path ) |
238 | { | 238 | { |
239 | kdDebug(5700) << "ResourceDir::lock()" << endl; | 239 | kdDebug(5700) << "ResourceDir::lock()" << endl; |
240 | 240 | ||
241 | QString p = path; | 241 | QString p = path; |
242 | //US change the implementation how the lockfilename is getting created | 242 | //US change the implementation how the lockfilename is getting created |
243 | //US p.replace( QRegExp("/"), "_" ); | 243 | //US p.replace( QRegExp("/"), "_" ); |
244 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); | 244 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); |
245 | KURL url(p); | 245 | KURL url(p); |
246 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 246 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
247 | 247 | ||
248 | 248 | ||
249 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 249 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
250 | 250 | ||
251 | if ( QFile::exists( lockName ) ) return false; | 251 | if ( QFile::exists( lockName ) ) return false; |
252 | 252 | ||
253 | QString lockUniqueName; | 253 | QString lockUniqueName; |
254 | lockUniqueName = p + KApplication::randomString( 8 ); | 254 | lockUniqueName = p + KApplication::randomString( 8 ); |
255 | 255 | ||
256 | url = lockUniqueName; | 256 | url = lockUniqueName; |
257 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 257 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
258 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 258 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
259 | 259 | ||
260 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 260 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
261 | 261 | ||
262 | // Create unique file | 262 | // Create unique file |
263 | QFile file( mLockUniqueName ); | 263 | QFile file( mLockUniqueName ); |
264 | file.open( IO_WriteOnly ); | 264 | file.open( IO_WriteOnly ); |
265 | file.close(); | 265 | file.close(); |
266 | 266 | ||
267 | // Create lock file | 267 | // Create lock file |
268 | int result = 0; | 268 | int result = 0; |
269 | #ifndef _WIN32_ | 269 | #ifndef _WIN32_ |
270 | result = ::link( QFile::encodeName( mLockUniqueName ), | 270 | result = ::link( QFile::encodeName( mLockUniqueName ), |
271 | QFile::encodeName( lockName ) ); | 271 | QFile::encodeName( lockName ) ); |
272 | #endif | 272 | #endif |
273 | if ( result == 0 ) { | 273 | if ( result == 0 ) { |
274 | addressBook()->emitAddressBookLocked(); | 274 | addressBook()->emitAddressBookLocked(); |
275 | return true; | 275 | return true; |
276 | } | 276 | } |
277 | 277 | ||
278 | // TODO: check stat | 278 | // TODO: check stat |
279 | 279 | ||
280 | return false; | 280 | return false; |
281 | } | 281 | } |
282 | 282 | ||
283 | void ResourceDir::unlock( const QString &path ) | 283 | void ResourceDir::unlock( const QString &path ) |
284 | { | 284 | { |
285 | QString p = path; | 285 | QString p = path; |
286 | //US change the implementation how the lockfilename is getting created | 286 | //US change the implementation how the lockfilename is getting created |
287 | //US p.replace( QRegExp( "/" ), "_" ); | 287 | //US p.replace( QRegExp( "/" ), "_" ); |
288 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); | 288 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); |
289 | KURL url(p); | 289 | KURL url(p); |
290 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 290 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
291 | 291 | ||
292 | ::unlink( QFile::encodeName( lockName ) ); | 292 | ::unlink( QFile::encodeName( lockName ) ); |
293 | QFile::remove( mLockUniqueName ); | 293 | QFile::remove( mLockUniqueName ); |
294 | addressBook()->emitAddressBookUnlocked(); | 294 | addressBook()->emitAddressBookUnlocked(); |
295 | } | 295 | } |
296 | 296 | ||
297 | void ResourceDir::setPath( const QString &path ) | 297 | void ResourceDir::setPath( const QString &path ) |
298 | { | 298 | { |
299 | mDirWatch.stopScan(); | 299 | mDirWatch.stopScan(); |
300 | mDirWatch.removeDir( mPath ); | 300 | mDirWatch.removeDir( mPath ); |
301 | 301 | ||
302 | mPath = path; | 302 | mPath = path; |
303 | 303 | ||
304 | mDirWatch.addDir( mPath, true ); | 304 | mDirWatch.addDir( mPath, true ); |
305 | mDirWatch.startScan(); | 305 | mDirWatch.startScan(); |
306 | 306 | ||
307 | //US simulate KDirWatch event | 307 | //US simulate KDirWatch event |
308 | //US pathChanged(); | 308 | //US pathChanged(); |
309 | 309 | ||
310 | } | 310 | } |
311 | 311 | ||
312 | QString ResourceDir::path() const | 312 | QString ResourceDir::path() const |
313 | { | 313 | { |
314 | return mPath; | 314 | return mPath; |
315 | } | 315 | } |
316 | 316 | ||
317 | void ResourceDir::setFormat( const QString &format ) | 317 | void ResourceDir::setFormat( const QString &format ) |
318 | { | 318 | { |
319 | mFormatName = format; | 319 | mFormatName = format; |
320 | 320 | ||
321 | if ( mFormat ) | 321 | if ( mFormat ) |
322 | delete mFormat; | 322 | delete mFormat; |
323 | 323 | ||
324 | FormatFactory *factory = FormatFactory::self(); | 324 | FormatFactory *factory = FormatFactory::self(); |
325 | mFormat = factory->format( mFormatName ); | 325 | mFormat = factory->format( mFormatName ); |
326 | /*US | 326 | /*US |
327 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); | 327 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); |
328 | if (mFormatName == "vcard") | 328 | if (mFormatName == "vcard") |
329 | mFormat = new VCardFormatPlugin2(); | 329 | mFormat = new VCardFormatPlugin2(); |
330 | else if (mFormatName == "binary") | 330 | else if (mFormatName == "binary") |
331 | mFormat = new BinaryFormat(); | 331 | mFormat = new BinaryFormat(); |
332 | else | 332 | else |
333 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); | 333 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); |
334 | */ | 334 | */ |
335 | 335 | ||
336 | } | 336 | } |
337 | 337 | ||
338 | QString ResourceDir::format() const | 338 | QString ResourceDir::format() const |
339 | { | 339 | { |
340 | return mFormatName; | 340 | return mFormatName; |
341 | } | 341 | } |
342 | 342 | ||
343 | void ResourceDir::pathChanged() | 343 | void ResourceDir::pathChanged() |
344 | { | 344 | { |
345 | if ( !addressBook() ) | 345 | if ( !addressBook() ) |
346 | return; | 346 | return; |
347 | 347 | ||
348 | QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); | 348 | QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); |
349 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 349 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
350 | load(); | 350 | load(); |
351 | addressBook()->emitAddressBookChanged(); | 351 | addressBook()->emitAddressBookChanged(); |
352 | } | 352 | } |
353 | } | 353 | } |
354 | 354 | ||
355 | void ResourceDir::removeAddressee( const Addressee& addr ) | 355 | void ResourceDir::removeAddressee( const Addressee& addr ) |
356 | { | 356 | { |
357 | QFile::remove( mPath + "/" + addr.uid() ); | 357 | QFile::remove( mPath + "/" + addr.uid() ); |
358 | } | 358 | } |
359 | 359 | ||
360 | void ResourceDir::cleanUp() | 360 | void ResourceDir::cleanUp() |
361 | { | 361 | { |
362 | unlock( mPath ); | 362 | unlock( mPath ); |
363 | } | 363 | } |
364 | 364 | ||
365 | //US #include "resourcedir.moc" | 365 | //US #include "resourcedir.moc" |
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 361b36b..d98efc8 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -1,399 +1,399 @@ | |||
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 | 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 "syncwidget.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, KRES::SyncWidget>(); | 69 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidget>(); |
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; |
79 | 79 | ||
80 | KConfig *cfg = (KConfig *)config; | 80 | KConfig *cfg = (KConfig *)config; |
81 | if ( cfg ) { | 81 | if ( cfg ) { |
82 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); | 82 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); |
83 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 83 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
84 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); | 84 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); |
85 | } else { | 85 | } else { |
86 | fileName = StdAddressBook::fileName(); | 86 | fileName = StdAddressBook::fileName(); |
87 | formatName = "vcard"; | 87 | formatName = "vcard"; |
88 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); | 88 | // qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); |
89 | } | 89 | } |
90 | 90 | ||
91 | init( fileName, formatName ); | 91 | init( fileName, formatName ); |
92 | } | 92 | } |
93 | 93 | ||
94 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , | 94 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , |
95 | const QString &formatName ) | 95 | const QString &formatName ) |
96 | : Resource( 0, syncable ) | 96 | : Resource( 0, syncable ) |
97 | { | 97 | { |
98 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 98 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
99 | init( fileName, formatName ); | 99 | init( fileName, formatName ); |
100 | } | 100 | } |
101 | 101 | ||
102 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 102 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
103 | { | 103 | { |
104 | mFormatName = formatName; | 104 | mFormatName = formatName; |
105 | 105 | ||
106 | FormatFactory *factory = FormatFactory::self(); | 106 | FormatFactory *factory = FormatFactory::self(); |
107 | mFormat = factory->format( mFormatName ); | 107 | mFormat = factory->format( mFormatName ); |
108 | 108 | ||
109 | if ( !mFormat ) { | 109 | if ( !mFormat ) { |
110 | mFormatName = "vcard"; | 110 | mFormatName = "vcard"; |
111 | mFormat = factory->format( mFormatName ); | 111 | mFormat = factory->format( mFormatName ); |
112 | } | 112 | } |
113 | 113 | ||
114 | /*US | 114 | /*US |
115 | //US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); | 115 | //US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); |
116 | if (mFormatName == "vcard") { | 116 | if (mFormatName == "vcard") { |
117 | mFormat = new VCardFormatPlugin2(); | 117 | mFormat = new VCardFormatPlugin2(); |
118 | // qDebug("ResourceFile::init format VCardFormatPlugin2"); | 118 | // qDebug("ResourceFile::init format VCardFormatPlugin2"); |
119 | } | 119 | } |
120 | else if (mFormatName == "binary") { | 120 | else if (mFormatName == "binary") { |
121 | mFormat = new BinaryFormat(); | 121 | mFormat = new BinaryFormat(); |
122 | // qDebug("ResourceFile::init format BinaryFormat"); | 122 | // qDebug("ResourceFile::init format BinaryFormat"); |
123 | } | 123 | } |
124 | else | 124 | else |
125 | qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); | 125 | qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); |
126 | */ | 126 | */ |
127 | 127 | ||
128 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 128 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
129 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 129 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
130 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 130 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
131 | 131 | ||
132 | setFileName( fileName ); | 132 | setFileName( fileName ); |
133 | } | 133 | } |
134 | 134 | ||
135 | ResourceFile::~ResourceFile() | 135 | ResourceFile::~ResourceFile() |
136 | { | 136 | { |
137 | delete mFormat; | 137 | delete mFormat; |
138 | mFormat = 0; | 138 | mFormat = 0; |
139 | } | 139 | } |
140 | 140 | ||
141 | void ResourceFile::writeConfig( KConfig *config ) | 141 | void ResourceFile::writeConfig( KConfig *config ) |
142 | { | 142 | { |
143 | 143 | ||
144 | config->setGroup( "Resource_" + identifier() ); | 144 | config->setGroup( "Resource_" + identifier() ); |
145 | Resource::writeConfig( config ); | 145 | Resource::writeConfig( config ); |
146 | 146 | ||
147 | config->writeEntry( "FileName", mFileName ); | 147 | config->writeEntry( "FileName", mFileName ); |
148 | config->writeEntry( "FileFormat", mFormatName ); | 148 | config->writeEntry( "FileFormat", mFormatName ); |
149 | 149 | ||
150 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 150 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
151 | 151 | ||
152 | } | 152 | } |
153 | 153 | ||
154 | Ticket *ResourceFile::requestSaveTicket() | 154 | Ticket *ResourceFile::requestSaveTicket() |
155 | { | 155 | { |
156 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 156 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
157 | 157 | ||
158 | if ( !addressBook() ) return 0; | 158 | if ( !addressBook() ) return 0; |
159 | 159 | ||
160 | if ( !lock( mFileName ) ) { | 160 | if ( !lock( mFileName ) ) { |
161 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" | 161 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" |
162 | << mFileName << "'" << endl; | 162 | << mFileName << "'" << endl; |
163 | return 0; | 163 | return 0; |
164 | } | 164 | } |
165 | return createTicket( this ); | 165 | return createTicket( this ); |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | bool ResourceFile::doOpen() | 169 | bool ResourceFile::doOpen() |
170 | { | 170 | { |
171 | QFile file( mFileName ); | 171 | QFile file( mFileName ); |
172 | 172 | ||
173 | if ( !file.exists() ) { | 173 | if ( !file.exists() ) { |
174 | // try to create the file | 174 | // try to create the file |
175 | bool ok = file.open( IO_WriteOnly ); | 175 | bool ok = file.open( IO_WriteOnly ); |
176 | if ( ok ) | 176 | if ( ok ) |
177 | file.close(); | 177 | file.close(); |
178 | 178 | ||
179 | return ok; | 179 | return ok; |
180 | } else { | 180 | } else { |
181 | if ( !file.open( IO_ReadWrite ) ) | 181 | if ( !file.open( IO_ReadWrite ) ) |
182 | return false; | 182 | return false; |
183 | 183 | ||
184 | if ( file.size() == 0 ) { | 184 | if ( file.size() == 0 ) { |
185 | file.close(); | 185 | file.close(); |
186 | return true; | 186 | return true; |
187 | } | 187 | } |
188 | 188 | ||
189 | bool ok = mFormat->checkFormat( &file ); | 189 | bool ok = mFormat->checkFormat( &file ); |
190 | file.close(); | 190 | file.close(); |
191 | 191 | ||
192 | return ok; | 192 | return ok; |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | void ResourceFile::doClose() | 196 | void ResourceFile::doClose() |
197 | { | 197 | { |
198 | } | 198 | } |
199 | 199 | ||
200 | bool ResourceFile::load() | 200 | bool ResourceFile::load() |
201 | { | 201 | { |
202 | 202 | ||
203 | 203 | ||
204 | QFile file( mFileName ); | 204 | QFile file( mFileName ); |
205 | if ( !file.open( IO_ReadOnly ) ) { | 205 | if ( !file.open( IO_ReadOnly ) ) { |
206 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | 206 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); |
207 | return false; | 207 | return false; |
208 | } | 208 | } |
209 | 209 | ||
210 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 210 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
211 | 211 | ||
212 | return mFormat->loadAll( addressBook(), this, &file ); | 212 | return mFormat->loadAll( addressBook(), this, &file ); |
213 | } | 213 | } |
214 | 214 | ||
215 | bool ResourceFile::save( Ticket *ticket ) | 215 | bool ResourceFile::save( Ticket *ticket ) |
216 | { | 216 | { |
217 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 217 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
218 | 218 | ||
219 | 219 | ||
220 | // create backup file | 220 | // create backup file |
221 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 221 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
222 | 222 | ||
223 | /*US we use a simpler method to create a backupfile | 223 | /*US we use a simpler method to create a backupfile |
224 | 224 | ||
225 | (void) KSaveFile::backupFile( mFileName, QString::null | 225 | (void) KSaveFile::backupFile( mFileName, QString::null |
226 | ,extension ); | 226 | ,extension ); |
227 | 227 | ||
228 | KSaveFile saveFile( mFileName ); | 228 | KSaveFile saveFile( mFileName ); |
229 | bool ok = false; | 229 | bool ok = false; |
230 | if ( saveFile.status() == 0 && saveFile.file() ) | 230 | if ( saveFile.status() == 0 && saveFile.file() ) |
231 | { | 231 | { |
232 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 232 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
233 | ok = saveFile.close(); | 233 | ok = saveFile.close(); |
234 | } | 234 | } |
235 | */ | 235 | */ |
236 | 236 | ||
237 | //US ToDo: write backupfile | 237 | //US ToDo: write backupfile |
238 | QFile info; | 238 | QFile info; |
239 | info.setName( mFileName ); | 239 | info.setName( mFileName ); |
240 | bool ok = info.open( IO_WriteOnly ); | 240 | bool ok = info.open( IO_WriteOnly ); |
241 | if ( ok ) { | 241 | if ( ok ) { |
242 | mFormat->saveAll( addressBook(), this, &info ); | 242 | mFormat->saveAll( addressBook(), this, &info ); |
243 | 243 | ||
244 | info.close(); | 244 | info.close(); |
245 | ok = true; | 245 | ok = true; |
246 | } | 246 | } |
247 | else { | 247 | else { |
248 | 248 | ||
249 | } | 249 | } |
250 | 250 | ||
251 | if ( !ok ) | 251 | if ( !ok ) |
252 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 252 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
253 | 253 | ||
254 | delete ticket; | 254 | delete ticket; |
255 | unlock( mFileName ); | 255 | unlock( mFileName ); |
256 | 256 | ||
257 | return ok; | 257 | return ok; |
258 | 258 | ||
259 | qDebug("ResourceFile::save has to be changed"); | 259 | qDebug("ResourceFile::save has to be changed"); |
260 | return true; | 260 | return true; |
261 | } | 261 | } |
262 | 262 | ||
263 | bool ResourceFile::lock( const QString &fileName ) | 263 | bool ResourceFile::lock( const QString &fileName ) |
264 | { | 264 | { |
265 | 265 | ||
266 | 266 | ||
267 | QString fn = fileName; | 267 | QString fn = fileName; |
268 | 268 | ||
269 | //US change the implementation how the lockfilename is getting created | 269 | //US change the implementation how the lockfilename is getting created |
270 | //US fn.replace( QRegExp("/"), "_" ); | 270 | //US fn.replace( QRegExp("/"), "_" ); |
271 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 271 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
272 | 272 | ||
273 | KURL url(fn); | 273 | KURL url(fn); |
274 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 274 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
275 | 275 | ||
276 | 276 | ||
277 | 277 | ||
278 | if (QFile::exists( lockName )) return false; | 278 | if (QFile::exists( lockName )) return false; |
279 | 279 | ||
280 | QString lockUniqueName; | 280 | QString lockUniqueName; |
281 | lockUniqueName = fn + KApplication::randomString( 8 ); | 281 | lockUniqueName = fn + KApplication::randomString( 8 ); |
282 | 282 | ||
283 | url = lockUniqueName; | 283 | url = lockUniqueName; |
284 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 284 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
285 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 285 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
286 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 286 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
287 | 287 | ||
288 | // Create unique file | 288 | // Create unique file |
289 | QFile file( mLockUniqueName ); | 289 | QFile file( mLockUniqueName ); |
290 | file.open( IO_WriteOnly ); | 290 | file.open( IO_WriteOnly ); |
291 | file.close(); | 291 | file.close(); |
292 | 292 | ||
293 | // Create lock file | 293 | // Create lock file |
294 | int result = 0; | 294 | int result = 0; |
295 | #ifndef _WIN32_ | 295 | #ifndef _WIN32_ |
296 | result = ::link( QFile::encodeName( mLockUniqueName ), | 296 | result = ::link( QFile::encodeName( mLockUniqueName ), |
297 | QFile::encodeName( lockName ) ); | 297 | QFile::encodeName( lockName ) ); |
298 | #endif | 298 | #endif |
299 | if ( result == 0 ) { | 299 | if ( result == 0 ) { |
300 | addressBook()->emitAddressBookLocked(); | 300 | addressBook()->emitAddressBookLocked(); |
301 | return true; | 301 | return true; |
302 | } | 302 | } |
303 | 303 | ||
304 | // TODO: check stat | 304 | // TODO: check stat |
305 | 305 | ||
306 | return false; | 306 | return false; |
307 | } | 307 | } |
308 | 308 | ||
309 | void ResourceFile::unlock( const QString &fileName ) | 309 | void ResourceFile::unlock( const QString &fileName ) |
310 | { | 310 | { |
311 | QString fn = fileName; | 311 | QString fn = fileName; |
312 | //US change the implementation how the lockfilename is getting created | 312 | //US change the implementation how the lockfilename is getting created |
313 | //US fn.replace( QRegExp( "/" ), "_" ); | 313 | //US fn.replace( QRegExp( "/" ), "_" ); |
314 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 314 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
315 | //US QString lockName = fn + ".lock"; | 315 | //US QString lockName = fn + ".lock"; |
316 | KURL url(fn); | 316 | KURL url(fn); |
317 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 317 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
318 | 318 | ||
319 | QFile::remove( lockName ); | 319 | QFile::remove( lockName ); |
320 | QFile::remove( mLockUniqueName ); | 320 | QFile::remove( mLockUniqueName ); |
321 | addressBook()->emitAddressBookUnlocked(); | 321 | addressBook()->emitAddressBookUnlocked(); |
322 | } | 322 | } |
323 | 323 | ||
324 | void ResourceFile::setFileName( const QString &fileName ) | 324 | void ResourceFile::setFileName( const QString &fileName ) |
325 | { | 325 | { |
326 | mDirWatch.stopScan(); | 326 | mDirWatch.stopScan(); |
327 | mDirWatch.removeFile( mFileName ); | 327 | mDirWatch.removeFile( mFileName ); |
328 | 328 | ||
329 | mFileName = fileName; | 329 | mFileName = fileName; |
330 | 330 | ||
331 | 331 | ||
332 | mDirWatch.addFile( mFileName ); | 332 | mDirWatch.addFile( mFileName ); |
333 | mDirWatch.startScan(); | 333 | mDirWatch.startScan(); |
334 | 334 | ||
335 | //US simulate KDirWatch event | 335 | //US simulate KDirWatch event |
336 | //US fileChanged(); | 336 | //US fileChanged(); |
337 | } | 337 | } |
338 | 338 | ||
339 | QString ResourceFile::fileName() const | 339 | QString ResourceFile::fileName() const |
340 | { | 340 | { |
341 | return mFileName; | 341 | return mFileName; |
342 | } | 342 | } |
343 | 343 | ||
344 | void ResourceFile::setFormat( const QString &format ) | 344 | void ResourceFile::setFormat( const QString &format ) |
345 | { | 345 | { |
346 | mFormatName = format; | 346 | mFormatName = format; |
347 | delete mFormat; | 347 | delete mFormat; |
348 | 348 | ||
349 | FormatFactory *factory = FormatFactory::self(); | 349 | FormatFactory *factory = FormatFactory::self(); |
350 | mFormat = factory->format( mFormatName ); | 350 | mFormat = factory->format( mFormatName ); |
351 | /*US | 351 | /*US |
352 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | 352 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); |
353 | if (mFormatName == "vcard") { | 353 | if (mFormatName == "vcard") { |
354 | mFormat = new VCardFormatPlugin2(); | 354 | mFormat = new VCardFormatPlugin2(); |
355 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 355 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
356 | } | 356 | } |
357 | else if (mFormatName == "binary") { | 357 | else if (mFormatName == "binary") { |
358 | mFormat = new BinaryFormat(); | 358 | mFormat = new BinaryFormat(); |
359 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 359 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
360 | } | 360 | } |
361 | else | 361 | else |
362 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | 362 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); |
363 | */ | 363 | */ |
364 | 364 | ||
365 | } | 365 | } |
366 | 366 | ||
367 | QString ResourceFile::format() const | 367 | QString ResourceFile::format() const |
368 | { | 368 | { |
369 | return mFormatName; | 369 | return mFormatName; |
370 | } | 370 | } |
371 | 371 | ||
372 | void ResourceFile::fileChanged() | 372 | void ResourceFile::fileChanged() |
373 | { | 373 | { |
374 | // There is a small theoretical chance that KDirWatch calls us before | 374 | // There is a small theoretical chance that KDirWatch calls us before |
375 | // we are fully constructed | 375 | // we are fully constructed |
376 | if (!addressBook()) | 376 | if (!addressBook()) |
377 | return; | 377 | return; |
378 | 378 | ||
379 | 379 | ||
380 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 380 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); |
381 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 381 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
382 | load(); | 382 | load(); |
383 | addressBook()->emitAddressBookChanged(); | 383 | addressBook()->emitAddressBookChanged(); |
384 | } | 384 | } |
385 | } | 385 | } |
386 | 386 | ||
387 | void ResourceFile::removeAddressee( const Addressee &addr ) | 387 | void ResourceFile::removeAddressee( const Addressee &addr ) |
388 | { | 388 | { |
389 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | 389 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); |
390 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | 390 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); |
391 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | 391 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); |
392 | } | 392 | } |
393 | 393 | ||
394 | void ResourceFile::cleanUp() | 394 | void ResourceFile::cleanUp() |
395 | { | 395 | { |
396 | unlock( mFileName ); | 396 | unlock( mFileName ); |
397 | } | 397 | } |
398 | 398 | ||
399 | //US #include "resourcefile.moc" | 399 | //US #include "resourcefile.moc" |
diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp index 4b9dede..198e80a 100644 --- a/kabc/plugins/ldap/resourceldap.cpp +++ b/kabc/plugins/ldap/resourceldap.cpp | |||
@@ -1,445 +1,445 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@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 <kdebug.h> | 28 | #include <kdebug.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klineedit.h> | 30 | #include <klineedit.h> |
31 | #include <klocale.h> | 31 | #include <klocale.h> |
32 | #include <kconfig.h> | 32 | #include <kconfig.h> |
33 | #include <kstringhandler.h> | 33 | #include <kstringhandler.h> |
34 | 34 | ||
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | 36 | ||
37 | #include "resourceldap.h" | 37 | #include "resourceldap.h" |
38 | #include "resourceldapconfig.h" | 38 | #include "resourceldapconfig.h" |
39 | #include "syncwidget.h" | 39 | #include "syncprefwidget.h" |
40 | 40 | ||
41 | using namespace KABC; | 41 | using namespace KABC; |
42 | 42 | ||
43 | extern "C" | 43 | extern "C" |
44 | { | 44 | { |
45 | //US void *init_kabc_ldap() | 45 | //US void *init_kabc_ldap() |
46 | void *init_microkabc_ldap() | 46 | void *init_microkabc_ldap() |
47 | { | 47 | { |
48 | return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, KRES::SyncWidget>(); | 48 | return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, SyncPrefWidget>(); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); | 52 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); |
53 | 53 | ||
54 | 54 | ||
55 | ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) | 55 | ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) |
56 | : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) | 56 | : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) |
57 | { | 57 | { |
58 | KConfig *cfg = (KConfig *)config; | 58 | KConfig *cfg = (KConfig *)config; |
59 | if ( cfg ) { | 59 | if ( cfg ) { |
60 | mUser = cfg->readEntry( "LdapUser" ); | 60 | mUser = cfg->readEntry( "LdapUser" ); |
61 | mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); | 61 | mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); |
62 | mDn = cfg->readEntry( "LdapDn" ); | 62 | mDn = cfg->readEntry( "LdapDn" ); |
63 | mHost = cfg->readEntry( "LdapHost" ); | 63 | mHost = cfg->readEntry( "LdapHost" ); |
64 | mPort = cfg->readNumEntry( "LdapPort", 389 ); | 64 | mPort = cfg->readNumEntry( "LdapPort", 389 ); |
65 | mFilter = cfg->readEntry( "LdapFilter" ); | 65 | mFilter = cfg->readEntry( "LdapFilter" ); |
66 | mAnonymous = cfg->readBoolEntry( "LdapAnonymous" ); | 66 | mAnonymous = cfg->readBoolEntry( "LdapAnonymous" ); |
67 | 67 | ||
68 | QStringList attributes = cfg->readListEntry( "LdapAttributes" ); | 68 | QStringList attributes = cfg->readListEntry( "LdapAttributes" ); |
69 | for ( uint pos = 0; pos < attributes.count(); pos += 2 ) | 69 | for ( uint pos = 0; pos < attributes.count(); pos += 2 ) |
70 | mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); | 70 | mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); |
71 | } | 71 | } |
72 | 72 | ||
73 | /** | 73 | /** |
74 | If you want to add new attributes, append them here, add a | 74 | If you want to add new attributes, append them here, add a |
75 | translation string in the ctor of AttributesDialog and | 75 | translation string in the ctor of AttributesDialog and |
76 | handle them in the load() method below. | 76 | handle them in the load() method below. |
77 | These are the default values from | 77 | These are the default values from |
78 | */ | 78 | */ |
79 | if ( mAttributes.count() == 0 ) { | 79 | if ( mAttributes.count() == 0 ) { |
80 | mAttributes.insert( "commonName", "cn" ); | 80 | mAttributes.insert( "commonName", "cn" ); |
81 | mAttributes.insert( "formattedName", "displayName" ); | 81 | mAttributes.insert( "formattedName", "displayName" ); |
82 | mAttributes.insert( "familyName", "sn" ); | 82 | mAttributes.insert( "familyName", "sn" ); |
83 | mAttributes.insert( "givenName", "givenName" ); | 83 | mAttributes.insert( "givenName", "givenName" ); |
84 | mAttributes.insert( "mail", "mail" ); | 84 | mAttributes.insert( "mail", "mail" ); |
85 | mAttributes.insert( "mailAlias", "" ); | 85 | mAttributes.insert( "mailAlias", "" ); |
86 | mAttributes.insert( "phoneNumber", "telephoneNumber" ); | 86 | mAttributes.insert( "phoneNumber", "telephoneNumber" ); |
87 | mAttributes.insert( "uid", "uid" ); | 87 | mAttributes.insert( "uid", "uid" ); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | void ResourceLDAP::writeConfig( KConfig *config ) | 91 | void ResourceLDAP::writeConfig( KConfig *config ) |
92 | { | 92 | { |
93 | Resource::writeConfig( config ); | 93 | Resource::writeConfig( config ); |
94 | 94 | ||
95 | config->writeEntry( "LdapUser", mUser ); | 95 | config->writeEntry( "LdapUser", mUser ); |
96 | config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); | 96 | config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); |
97 | config->writeEntry( "LdapDn", mDn ); | 97 | config->writeEntry( "LdapDn", mDn ); |
98 | config->writeEntry( "LdapHost", mHost ); | 98 | config->writeEntry( "LdapHost", mHost ); |
99 | config->writeEntry( "LdapPort", mPort ); | 99 | config->writeEntry( "LdapPort", mPort ); |
100 | config->writeEntry( "LdapFilter", mFilter ); | 100 | config->writeEntry( "LdapFilter", mFilter ); |
101 | config->writeEntry( "LdapAnonymous", mAnonymous ); | 101 | config->writeEntry( "LdapAnonymous", mAnonymous ); |
102 | 102 | ||
103 | QStringList attributes; | 103 | QStringList attributes; |
104 | QMap<QString, QString>::Iterator it; | 104 | QMap<QString, QString>::Iterator it; |
105 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) | 105 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) |
106 | attributes << it.key() << it.data(); | 106 | attributes << it.key() << it.data(); |
107 | 107 | ||
108 | config->writeEntry( "LdapAttributes", attributes ); | 108 | config->writeEntry( "LdapAttributes", attributes ); |
109 | } | 109 | } |
110 | 110 | ||
111 | Ticket *ResourceLDAP::requestSaveTicket() | 111 | Ticket *ResourceLDAP::requestSaveTicket() |
112 | { | 112 | { |
113 | if ( !addressBook() ) { | 113 | if ( !addressBook() ) { |
114 | kdDebug(5700) << "no addressbook" << endl; | 114 | kdDebug(5700) << "no addressbook" << endl; |
115 | return 0; | 115 | return 0; |
116 | } | 116 | } |
117 | 117 | ||
118 | return createTicket( this ); | 118 | return createTicket( this ); |
119 | } | 119 | } |
120 | 120 | ||
121 | bool ResourceLDAP::doOpen() | 121 | bool ResourceLDAP::doOpen() |
122 | { | 122 | { |
123 | if ( mLdap ) | 123 | if ( mLdap ) |
124 | return false; | 124 | return false; |
125 | 125 | ||
126 | if ( !mPort ) | 126 | if ( !mPort ) |
127 | mPort = 389; | 127 | mPort = 389; |
128 | 128 | ||
129 | mLdap = ldap_init( mHost.local8Bit(), mPort ); | 129 | mLdap = ldap_init( mHost.local8Bit(), mPort ); |
130 | if ( !mLdap ) { | 130 | if ( !mLdap ) { |
131 | addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) ); | 131 | addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) ); |
132 | return false; | 132 | return false; |
133 | } | 133 | } |
134 | 134 | ||
135 | if ( !mUser.isEmpty() && !mAnonymous ) { | 135 | if ( !mUser.isEmpty() && !mAnonymous ) { |
136 | if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) { | 136 | if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) { |
137 | addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) ); | 137 | addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) ); |
138 | return false; | 138 | return false; |
139 | } | 139 | } |
140 | 140 | ||
141 | kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl; | 141 | kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl; |
142 | } else { | 142 | } else { |
143 | if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) { | 143 | if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) { |
144 | addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) ); | 144 | addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) ); |
145 | return false; | 145 | return false; |
146 | } | 146 | } |
147 | 147 | ||
148 | kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl; | 148 | kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl; |
149 | } | 149 | } |
150 | 150 | ||
151 | int deref = LDAP_DEREF_ALWAYS; | 151 | int deref = LDAP_DEREF_ALWAYS; |
152 | if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) { | 152 | if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) { |
153 | kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl; | 153 | kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl; |
154 | return false; | 154 | return false; |
155 | } | 155 | } |
156 | 156 | ||
157 | if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) { | 157 | if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) { |
158 | kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl; | 158 | kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl; |
159 | return false; | 159 | return false; |
160 | } | 160 | } |
161 | 161 | ||
162 | return true; | 162 | return true; |
163 | } | 163 | } |
164 | 164 | ||
165 | void ResourceLDAP::doClose() | 165 | void ResourceLDAP::doClose() |
166 | { | 166 | { |
167 | if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) { | 167 | if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) { |
168 | kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl; | 168 | kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl; |
169 | return; | 169 | return; |
170 | } | 170 | } |
171 | 171 | ||
172 | mLdap = 0; | 172 | mLdap = 0; |
173 | } | 173 | } |
174 | 174 | ||
175 | bool ResourceLDAP::load() | 175 | bool ResourceLDAP::load() |
176 | { | 176 | { |
177 | LDAPMessage *res; | 177 | LDAPMessage *res; |
178 | LDAPMessage *msg; | 178 | LDAPMessage *msg; |
179 | BerElement *track; | 179 | BerElement *track; |
180 | char *names; | 180 | char *names; |
181 | char **values; | 181 | char **values; |
182 | 182 | ||
183 | char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ]; | 183 | char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ]; |
184 | 184 | ||
185 | QMap<QString, QString>::Iterator it; | 185 | QMap<QString, QString>::Iterator it; |
186 | int i = 0; | 186 | int i = 0; |
187 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { | 187 | for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { |
188 | if ( !it.data().isEmpty() ) { | 188 | if ( !it.data().isEmpty() ) { |
189 | unsigned int len = it.data().utf8().length(); | 189 | unsigned int len = it.data().utf8().length(); |
190 | LdapSearchAttr[ i ] = new char[ len+1 ]; | 190 | LdapSearchAttr[ i ] = new char[ len+1 ]; |
191 | memcpy( LdapSearchAttr[ i ], it.data().utf8(), len ); | 191 | memcpy( LdapSearchAttr[ i ], it.data().utf8(), len ); |
192 | LdapSearchAttr[ i ][ len ] = 0; | 192 | LdapSearchAttr[ i ][ len ] = 0; |
193 | ++i; | 193 | ++i; |
194 | } | 194 | } |
195 | } | 195 | } |
196 | LdapSearchAttr[ i ] = 0; | 196 | LdapSearchAttr[ i ] = 0; |
197 | 197 | ||
198 | QString filter = mFilter; | 198 | QString filter = mFilter; |
199 | if ( filter.isEmpty() ) | 199 | if ( filter.isEmpty() ) |
200 | filter = "cn=*"; | 200 | filter = "cn=*"; |
201 | 201 | ||
202 | int result; | 202 | int result; |
203 | if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(), | 203 | if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(), |
204 | LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) { | 204 | LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) { |
205 | addressBook()->error( i18n( "Unable to search on server '%1': %2" ) | 205 | addressBook()->error( i18n( "Unable to search on server '%1': %2" ) |
206 | .arg( mHost ) | 206 | .arg( mHost ) |
207 | .arg( ldap_err2string( result ) ) ); | 207 | .arg( ldap_err2string( result ) ) ); |
208 | 208 | ||
209 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) | 209 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) |
210 | delete [] LdapSearchAttr[ i ]; | 210 | delete [] LdapSearchAttr[ i ]; |
211 | delete [] LdapSearchAttr; | 211 | delete [] LdapSearchAttr; |
212 | 212 | ||
213 | return false; | 213 | return false; |
214 | } | 214 | } |
215 | 215 | ||
216 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { | 216 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { |
217 | Addressee addr; | 217 | Addressee addr; |
218 | addr.setResource( this ); | 218 | addr.setResource( this ); |
219 | for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) { | 219 | for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) { |
220 | values = ldap_get_values( mLdap, msg, names ); | 220 | values = ldap_get_values( mLdap, msg, names ); |
221 | for ( int i = 0; i < ldap_count_values( values ); ++i ) { | 221 | for ( int i = 0; i < ldap_count_values( values ); ++i ) { |
222 | QString name = QString::fromUtf8( names ).lower(); | 222 | QString name = QString::fromUtf8( names ).lower(); |
223 | QString value = QString::fromUtf8( values[ i ] ); | 223 | QString value = QString::fromUtf8( values[ i ] ); |
224 | 224 | ||
225 | if ( name == mAttributes[ "commonName" ].lower() ) { | 225 | if ( name == mAttributes[ "commonName" ].lower() ) { |
226 | if ( !addr.formattedName().isEmpty() ) { | 226 | if ( !addr.formattedName().isEmpty() ) { |
227 | QString fn = addr.formattedName(); | 227 | QString fn = addr.formattedName(); |
228 | addr.setNameFromString( value ); | 228 | addr.setNameFromString( value ); |
229 | addr.setFormattedName( fn ); | 229 | addr.setFormattedName( fn ); |
230 | } else | 230 | } else |
231 | addr.setNameFromString( value ); | 231 | addr.setNameFromString( value ); |
232 | } else if ( name == mAttributes[ "formattedName" ].lower() ) { | 232 | } else if ( name == mAttributes[ "formattedName" ].lower() ) { |
233 | addr.setFormattedName( value ); | 233 | addr.setFormattedName( value ); |
234 | } else if ( name == mAttributes[ "givenName" ].lower() ) { | 234 | } else if ( name == mAttributes[ "givenName" ].lower() ) { |
235 | addr.setGivenName( value ); | 235 | addr.setGivenName( value ); |
236 | } else if ( name == mAttributes[ "mail" ].lower() ) { | 236 | } else if ( name == mAttributes[ "mail" ].lower() ) { |
237 | addr.insertEmail( value, true ); | 237 | addr.insertEmail( value, true ); |
238 | } else if ( name == mAttributes[ "mailAlias" ].lower() ) { | 238 | } else if ( name == mAttributes[ "mailAlias" ].lower() ) { |
239 | addr.insertEmail( value, false ); | 239 | addr.insertEmail( value, false ); |
240 | } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { | 240 | } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { |
241 | PhoneNumber phone; | 241 | PhoneNumber phone; |
242 | phone.setNumber( value ); | 242 | phone.setNumber( value ); |
243 | addr.insertPhoneNumber( phone ); | 243 | addr.insertPhoneNumber( phone ); |
244 | break; // read only the home number | 244 | break; // read only the home number |
245 | } else if ( name == mAttributes[ "familyName" ].lower() ) { | 245 | } else if ( name == mAttributes[ "familyName" ].lower() ) { |
246 | addr.setFamilyName( value ); | 246 | addr.setFamilyName( value ); |
247 | } else if ( name == mAttributes[ "uid" ].lower() ) { | 247 | } else if ( name == mAttributes[ "uid" ].lower() ) { |
248 | addr.setUid( value ); | 248 | addr.setUid( value ); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | ldap_value_free( values ); | 251 | ldap_value_free( values ); |
252 | } | 252 | } |
253 | ber_free( track, 0 ); | 253 | ber_free( track, 0 ); |
254 | 254 | ||
255 | addressBook()->insertAddressee( addr ); | 255 | addressBook()->insertAddressee( addr ); |
256 | } | 256 | } |
257 | 257 | ||
258 | ldap_msgfree( res ); | 258 | ldap_msgfree( res ); |
259 | 259 | ||
260 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) | 260 | for ( i = 0; LdapSearchAttr[ i ]; ++i ) |
261 | delete [] LdapSearchAttr[ i ]; | 261 | delete [] LdapSearchAttr[ i ]; |
262 | delete [] LdapSearchAttr; | 262 | delete [] LdapSearchAttr; |
263 | 263 | ||
264 | return true; | 264 | return true; |
265 | } | 265 | } |
266 | 266 | ||
267 | bool ResourceLDAP::save( Ticket * ) | 267 | bool ResourceLDAP::save( Ticket * ) |
268 | { | 268 | { |
269 | AddressBook::Iterator it; | 269 | AddressBook::Iterator it; |
270 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 270 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
271 | if ( (*it).resource() == this && (*it).changed() ) { | 271 | if ( (*it).resource() == this && (*it).changed() ) { |
272 | LDAPMod **mods = NULL; | 272 | LDAPMod **mods = NULL; |
273 | 273 | ||
274 | addModOp( &mods, "objectClass", "organizationalPerson" ); | 274 | addModOp( &mods, "objectClass", "organizationalPerson" ); |
275 | addModOp( &mods, "objectClass", "person" ); | 275 | addModOp( &mods, "objectClass", "person" ); |
276 | addModOp( &mods, "objectClass", "Top" ); | 276 | addModOp( &mods, "objectClass", "Top" ); |
277 | addModOp( &mods, mAttributes[ "commonName" ].utf8(), (*it).assembledName() ); | 277 | addModOp( &mods, mAttributes[ "commonName" ].utf8(), (*it).assembledName() ); |
278 | addModOp( &mods, mAttributes[ "formattedName" ].utf8(), (*it).formattedName() ); | 278 | addModOp( &mods, mAttributes[ "formattedName" ].utf8(), (*it).formattedName() ); |
279 | addModOp( &mods, mAttributes[ "givenName" ].utf8(), (*it).givenName() ); | 279 | addModOp( &mods, mAttributes[ "givenName" ].utf8(), (*it).givenName() ); |
280 | addModOp( &mods, mAttributes[ "familyName" ].utf8(), (*it).familyName() ); | 280 | addModOp( &mods, mAttributes[ "familyName" ].utf8(), (*it).familyName() ); |
281 | addModOp( &mods, mAttributes[ "uid" ].utf8(), (*it).uid() ); | 281 | addModOp( &mods, mAttributes[ "uid" ].utf8(), (*it).uid() ); |
282 | 282 | ||
283 | QStringList emails = (*it).emails(); | 283 | QStringList emails = (*it).emails(); |
284 | QStringList::ConstIterator mailIt; | 284 | QStringList::ConstIterator mailIt; |
285 | bool first = true; | 285 | bool first = true; |
286 | for ( mailIt = emails.begin(); mailIt != emails.end(); ++mailIt ) { | 286 | for ( mailIt = emails.begin(); mailIt != emails.end(); ++mailIt ) { |
287 | if ( first ) { | 287 | if ( first ) { |
288 | addModOp( &mods, mAttributes[ "mail" ].utf8(), (*mailIt) ); | 288 | addModOp( &mods, mAttributes[ "mail" ].utf8(), (*mailIt) ); |
289 | first = false; | 289 | first = false; |
290 | } else | 290 | } else |
291 | addModOp( &mods, mAttributes[ "mailAlias" ].utf8(), (*mailIt) ); | 291 | addModOp( &mods, mAttributes[ "mailAlias" ].utf8(), (*mailIt) ); |
292 | } | 292 | } |
293 | 293 | ||
294 | PhoneNumber number = (*it).phoneNumber( PhoneNumber::Home ); | 294 | PhoneNumber number = (*it).phoneNumber( PhoneNumber::Home ); |
295 | addModOp( &mods, mAttributes[ "phoneNumber" ].utf8(), number.number() ); | 295 | addModOp( &mods, mAttributes[ "phoneNumber" ].utf8(), number.number() ); |
296 | 296 | ||
297 | QString dn = "cn=" + (*it).assembledName() + "," + mDn; | 297 | QString dn = "cn=" + (*it).assembledName() + "," + mDn; |
298 | 298 | ||
299 | int retval; | 299 | int retval; |
300 | if ( (retval = ldap_add_s( mLdap, dn.local8Bit(), mods )) != LDAP_SUCCESS ) | 300 | if ( (retval = ldap_add_s( mLdap, dn.local8Bit(), mods )) != LDAP_SUCCESS ) |
301 | addressBook()->error( i18n( "Unable to modify '%1' on server '%2'" ).arg( (*it).uid() ).arg( mHost ) ); | 301 | addressBook()->error( i18n( "Unable to modify '%1' on server '%2'" ).arg( (*it).uid() ).arg( mHost ) ); |
302 | 302 | ||
303 | ldap_mods_free( mods, 1 ); | 303 | ldap_mods_free( mods, 1 ); |
304 | 304 | ||
305 | // mark as unchanged | 305 | // mark as unchanged |
306 | (*it).setChanged( false ); | 306 | (*it).setChanged( false ); |
307 | } | 307 | } |
308 | } | 308 | } |
309 | 309 | ||
310 | return true; | 310 | return true; |
311 | } | 311 | } |
312 | 312 | ||
313 | void ResourceLDAP::removeAddressee( const Addressee &addr ) | 313 | void ResourceLDAP::removeAddressee( const Addressee &addr ) |
314 | { | 314 | { |
315 | LDAPMessage *res; | 315 | LDAPMessage *res; |
316 | LDAPMessage *msg; | 316 | LDAPMessage *msg; |
317 | 317 | ||
318 | QString filter = QString( "(&(uid=%1)(%2))" ).arg( addr.uid() ).arg( mFilter ); | 318 | QString filter = QString( "(&(uid=%1)(%2))" ).arg( addr.uid() ).arg( mFilter ); |
319 | 319 | ||
320 | kdDebug(5700) << "ldap:removeAddressee" << filter << endl; | 320 | kdDebug(5700) << "ldap:removeAddressee" << filter << endl; |
321 | 321 | ||
322 | ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, filter.local8Bit(), | 322 | ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, filter.local8Bit(), |
323 | 0, 0, &res ); | 323 | 0, 0, &res ); |
324 | 324 | ||
325 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { | 325 | for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { |
326 | char *dn = ldap_get_dn( mLdap, msg ); | 326 | char *dn = ldap_get_dn( mLdap, msg ); |
327 | kdDebug(5700) << "found " << dn << endl; | 327 | kdDebug(5700) << "found " << dn << endl; |
328 | if ( ldap_delete_s( mLdap, dn ) != LDAP_SUCCESS ) | 328 | if ( ldap_delete_s( mLdap, dn ) != LDAP_SUCCESS ) |
329 | addressBook()->error( i18n( "Unable to delete '%1' on server '%2'" ).arg( dn ).arg( mHost ) ); | 329 | addressBook()->error( i18n( "Unable to delete '%1' on server '%2'" ).arg( dn ).arg( mHost ) ); |
330 | ldap_memfree( dn ); | 330 | ldap_memfree( dn ); |
331 | } | 331 | } |
332 | 332 | ||
333 | ldap_msgfree( res ); | 333 | ldap_msgfree( res ); |
334 | } | 334 | } |
335 | 335 | ||
336 | void ResourceLDAP::setUser( const QString &user ) | 336 | void ResourceLDAP::setUser( const QString &user ) |
337 | { | 337 | { |
338 | mUser = user; | 338 | mUser = user; |
339 | } | 339 | } |
340 | 340 | ||
341 | QString ResourceLDAP::user() const | 341 | QString ResourceLDAP::user() const |
342 | { | 342 | { |
343 | return mUser; | 343 | return mUser; |
344 | } | 344 | } |
345 | 345 | ||
346 | void ResourceLDAP::setPassword( const QString &password ) | 346 | void ResourceLDAP::setPassword( const QString &password ) |
347 | { | 347 | { |
348 | mPassword = password; | 348 | mPassword = password; |
349 | } | 349 | } |
350 | 350 | ||
351 | QString ResourceLDAP::password() const | 351 | QString ResourceLDAP::password() const |
352 | { | 352 | { |
353 | return mPassword; | 353 | return mPassword; |
354 | } | 354 | } |
355 | 355 | ||
356 | void ResourceLDAP::setDn( const QString &dn ) | 356 | void ResourceLDAP::setDn( const QString &dn ) |
357 | { | 357 | { |
358 | mDn = dn; | 358 | mDn = dn; |
359 | } | 359 | } |
360 | 360 | ||
361 | QString ResourceLDAP::dn() const | 361 | QString ResourceLDAP::dn() const |
362 | { | 362 | { |
363 | return mDn; | 363 | return mDn; |
364 | } | 364 | } |
365 | 365 | ||
366 | void ResourceLDAP::setHost( const QString &host ) | 366 | void ResourceLDAP::setHost( const QString &host ) |
367 | { | 367 | { |
368 | mHost = host; | 368 | mHost = host; |
369 | } | 369 | } |
370 | 370 | ||
371 | QString ResourceLDAP::host() const | 371 | QString ResourceLDAP::host() const |
372 | { | 372 | { |
373 | return mHost; | 373 | return mHost; |
374 | } | 374 | } |
375 | 375 | ||
376 | void ResourceLDAP::setPort( int port ) | 376 | void ResourceLDAP::setPort( int port ) |
377 | { | 377 | { |
378 | mPort = port; | 378 | mPort = port; |
379 | } | 379 | } |
380 | 380 | ||
381 | int ResourceLDAP::port() const | 381 | int ResourceLDAP::port() const |
382 | { | 382 | { |
383 | return mPort; | 383 | return mPort; |
384 | } | 384 | } |
385 | 385 | ||
386 | void ResourceLDAP::setFilter( const QString &filter ) | 386 | void ResourceLDAP::setFilter( const QString &filter ) |
387 | { | 387 | { |
388 | mFilter = filter; | 388 | mFilter = filter; |
389 | } | 389 | } |
390 | 390 | ||
391 | QString ResourceLDAP::filter() const | 391 | QString ResourceLDAP::filter() const |
392 | { | 392 | { |
393 | return mFilter; | 393 | return mFilter; |
394 | } | 394 | } |
395 | 395 | ||
396 | void ResourceLDAP::setIsAnonymous( bool value ) | 396 | void ResourceLDAP::setIsAnonymous( bool value ) |
397 | { | 397 | { |
398 | mAnonymous = value; | 398 | mAnonymous = value; |
399 | } | 399 | } |
400 | 400 | ||
401 | bool ResourceLDAP::isAnonymous() const | 401 | bool ResourceLDAP::isAnonymous() const |
402 | { | 402 | { |
403 | return mAnonymous; | 403 | return mAnonymous; |
404 | } | 404 | } |
405 | 405 | ||
406 | void ResourceLDAP::setAttributes( const QMap<QString, QString> &attributes ) | 406 | void ResourceLDAP::setAttributes( const QMap<QString, QString> &attributes ) |
407 | { | 407 | { |
408 | mAttributes = attributes; | 408 | mAttributes = attributes; |
409 | } | 409 | } |
410 | 410 | ||
411 | QMap<QString, QString> ResourceLDAP::attributes() const | 411 | QMap<QString, QString> ResourceLDAP::attributes() const |
412 | { | 412 | { |
413 | return mAttributes; | 413 | return mAttributes; |
414 | } | 414 | } |
415 | 415 | ||
416 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ) | 416 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ) |
417 | { | 417 | { |
418 | if ( value.isNull() ) | 418 | if ( value.isNull() ) |
419 | return; | 419 | return; |
420 | 420 | ||
421 | LDAPMod**mods; | 421 | LDAPMod**mods; |
422 | 422 | ||
423 | mods = *pmods; | 423 | mods = *pmods; |
424 | 424 | ||
425 | uint i = 0; | 425 | uint i = 0; |
426 | if ( mods != 0 ) | 426 | if ( mods != 0 ) |
427 | for ( ; mods[ i ] != 0; ++i ); | 427 | for ( ; mods[ i ] != 0; ++i ); |
428 | 428 | ||
429 | if (( mods = (LDAPMod **)realloc( mods, (i + 2) * sizeof( LDAPMod * ))) == 0 ) { | 429 | if (( mods = (LDAPMod **)realloc( mods, (i + 2) * sizeof( LDAPMod * ))) == 0 ) { |
430 | kdError() << "ResourceLDAP: realloc" << endl; | 430 | kdError() << "ResourceLDAP: realloc" << endl; |
431 | return; | 431 | return; |
432 | } | 432 | } |
433 | 433 | ||
434 | *pmods = mods; | 434 | *pmods = mods; |
435 | mods[ i + 1 ] = 0; | 435 | mods[ i + 1 ] = 0; |
436 | 436 | ||
437 | mods[ i ] = new LDAPMod; | 437 | mods[ i ] = new LDAPMod; |
438 | 438 | ||
439 | mods[ i ]->mod_op = 0; | 439 | mods[ i ]->mod_op = 0; |
440 | mods[ i ]->mod_type = strdup( attr.utf8() ); | 440 | mods[ i ]->mod_type = strdup( attr.utf8() ); |
441 | mods[ i ]->mod_values = new char*[ 2 ]; | 441 | mods[ i ]->mod_values = new char*[ 2 ]; |
442 | mods[ i ]->mod_values[ 0 ] = strdup( value.utf8() ); | 442 | mods[ i ]->mod_values[ 0 ] = strdup( value.utf8() ); |
443 | mods[ i ]->mod_values[ 1 ] = 0; | 443 | mods[ i ]->mod_values[ 1 ] = 0; |
444 | } | 444 | } |
445 | 445 | ||
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index 1222242..5559827 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp | |||
@@ -1,391 +1,375 @@ | |||
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 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | 31 | ||
32 | #include <qdir.h> | 32 | #include <qdir.h> |
33 | #include <qfile.h> | 33 | #include <qfile.h> |
34 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | 36 | ||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
44 | 44 | ||
45 | //US #include "formatfactory.h" | 45 | //US #include "formatfactory.h" |
46 | //US #include <qpe/qpeapplication.h> | 46 | //US #include <qpe/qpeapplication.h> |
47 | 47 | ||
48 | #include <opie/ocontactaccess.h> | 48 | #include <opie/ocontactaccess.h> |
49 | #include <opie/ocontactaccessbackend_xml.h> | 49 | #include <opie/ocontactaccessbackend_xml.h> |
50 | 50 | ||
51 | #include "resourceopieconfig.h" | 51 | #include "resourceopieconfig.h" |
52 | #include "stdaddressbook.h" | 52 | #include "stdaddressbook.h" |
53 | #include "syncwidget.h" | 53 | #include "syncprefwidget.h" |
54 | 54 | ||
55 | #include "opieconverter.h" | 55 | #include "opieconverter.h" |
56 | 56 | ||
57 | #include "resourceopie.h" | 57 | #include "resourceopie.h" |
58 | 58 | ||
59 | using namespace KABC; | 59 | using namespace KABC; |
60 | extern "C" | 60 | extern "C" |
61 | { | 61 | { |
62 | void *init_microkabc_opie() | 62 | void *init_microkabc_opie() |
63 | { | 63 | { |
64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, KRES::SyncWidget>(); | 64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidget>(); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) | 68 | ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) |
69 | : Resource( config, syncable ), mAccess(0), mConverter (0) | 69 | : Resource( config, syncable ), mAccess(0), mConverter (0) |
70 | { | 70 | { |
71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
72 | 72 | ||
73 | KConfig *cfg = (KConfig *)config; | 73 | KConfig *cfg = (KConfig *)config; |
74 | if ( cfg ) { | 74 | if ( cfg ) { |
75 | fileName = cfg->readEntry( "FileName", fileName ); | 75 | fileName = cfg->readEntry( "FileName", fileName ); |
76 | 76 | ||
77 | } | 77 | } |
78 | 78 | ||
79 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); | ||
80 | |||
81 | init( fileName ); | 79 | init( fileName ); |
82 | } | 80 | } |
83 | 81 | ||
84 | ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) | 82 | ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) |
85 | : Resource( 0, syncable ) | 83 | : Resource( 0, syncable ) |
86 | { | 84 | { |
87 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); | ||
88 | init( fileName ); | 85 | init( fileName ); |
89 | } | 86 | } |
90 | 87 | ||
91 | void ResourceOpie::init( const QString &fileName ) | 88 | void ResourceOpie::init( const QString &fileName ) |
92 | { | 89 | { |
93 | 90 | ||
94 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 91 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
95 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 92 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
96 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 93 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
97 | 94 | ||
98 | |||
99 | setFileName( fileName ); | 95 | setFileName( fileName ); |
100 | |||
101 | } | 96 | } |
102 | 97 | ||
103 | ResourceOpie::~ResourceOpie() | 98 | ResourceOpie::~ResourceOpie() |
104 | { | 99 | { |
105 | if (mConverter != 0) | 100 | if (mConverter != 0) |
106 | delete mConverter; | 101 | delete mConverter; |
107 | 102 | ||
108 | if(mAccess != 0) | 103 | if(mAccess != 0) |
109 | delete mAccess; | 104 | delete mAccess; |
110 | |||
111 | } | 105 | } |
112 | 106 | ||
113 | void ResourceOpie::writeConfig( KConfig *config ) | 107 | void ResourceOpie::writeConfig( KConfig *config ) |
114 | { | 108 | { |
115 | Resource::writeConfig( config ); | 109 | Resource::writeConfig( config ); |
116 | 110 | ||
117 | config->writeEntry( "FileName", fileName() ); | 111 | config->writeEntry( "FileName", fileName() ); |
118 | } | 112 | } |
119 | 113 | ||
120 | Ticket *ResourceOpie::requestSaveTicket() | 114 | Ticket *ResourceOpie::requestSaveTicket() |
121 | { | 115 | { |
122 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | 116 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; |
123 | 117 | ||
124 | qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); | 118 | qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); |
125 | 119 | ||
126 | if ( !addressBook() ) return 0; | 120 | if ( !addressBook() ) return 0; |
127 | 121 | ||
128 | if ( !lock( fileName() ) ) { | 122 | if ( !lock( fileName() ) ) { |
129 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" | 123 | kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" |
130 | << fileName() << "'" << endl; | 124 | << fileName() << "'" << endl; |
131 | return 0; | 125 | return 0; |
132 | } | 126 | } |
133 | return createTicket( this ); | 127 | return createTicket( this ); |
134 | } | 128 | } |
135 | 129 | ||
136 | 130 | ||
137 | bool ResourceOpie::doOpen() | 131 | bool ResourceOpie::doOpen() |
138 | { | 132 | { |
139 | qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); | 133 | qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); |
140 | 134 | ||
141 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); | 135 | OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); |
142 | mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); | 136 | mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); |
143 | 137 | ||
144 | if ( !mAccess ) { | 138 | if ( !mAccess ) { |
145 | qDebug("Unable to load file() %s", fileName().latin1()); | 139 | qDebug("Unable to load file() %s", fileName().latin1()); |
146 | return false; | 140 | return false; |
147 | } | 141 | } |
148 | 142 | ||
149 | mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available | 143 | mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available |
150 | 144 | ||
151 | 145 | ||
152 | if (mConverter == 0) | 146 | if (mConverter == 0) |
153 | { | 147 | { |
154 | mConverter = new OpieConverter(); | 148 | mConverter = new OpieConverter(); |
155 | bool res = mConverter->init(); | 149 | bool res = mConverter->init(); |
156 | if ( !res ) | 150 | if ( !res ) |
157 | { | 151 | { |
158 | qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); | 152 | qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); |
159 | delete mAccess; | 153 | delete mAccess; |
160 | mAccess = 0; | 154 | mAccess = 0; |
161 | return false; | 155 | return false; |
162 | } | 156 | } |
163 | } | 157 | } |
164 | 158 | ||
165 | 159 | ||
166 | 160 | ||
167 | return true; | 161 | return true; |
168 | } | 162 | } |
169 | 163 | ||
170 | void ResourceOpie::doClose() | 164 | void ResourceOpie::doClose() |
171 | { | 165 | { |
172 | qDebug("ResourceOpie::doClose: %s", fileName().latin1()); | 166 | qDebug("ResourceOpie::doClose: %s", fileName().latin1()); |
173 | 167 | ||
174 | if(mAccess) | 168 | if(mAccess) |
175 | { | 169 | { |
176 | delete mAccess; | 170 | delete mAccess; |
177 | mAccess = 0; | 171 | mAccess = 0; |
178 | } | 172 | } |
179 | // it seems so, that deletion of access deletes backend as well | 173 | // it seems so, that deletion of access deletes backend as well |
180 | //delete backend; | 174 | //delete backend; |
181 | 175 | ||
182 | return; | 176 | return; |
183 | 177 | ||
184 | } | 178 | } |
185 | 179 | ||
186 | 180 | ||
187 | bool ResourceOpie::load() | 181 | bool ResourceOpie::load() |
188 | { | 182 | { |
189 | qDebug("ResourceOpie::load: %s", fileName().latin1()); | 183 | qDebug("ResourceOpie::load: %s", fileName().latin1()); |
190 | 184 | ||
191 | bool res = false; | 185 | bool res = false; |
192 | 186 | ||
193 | OContactAccess::List::Iterator it; | 187 | OContactAccess::List::Iterator it; |
194 | OContactAccess::List allList = mAccess->allRecords(); | 188 | OContactAccess::List allList = mAccess->allRecords(); |
195 | for ( it = allList.begin(); it != allList.end(); ++it ) | 189 | for ( it = allList.begin(); it != allList.end(); ++it ) |
196 | { | 190 | { |
197 | const OContact c = (*it); | 191 | const OContact c = (*it); |
198 | 192 | ||
199 | KABC::Addressee addressee; | 193 | KABC::Addressee addressee; |
200 | 194 | ||
201 | res = mConverter->opieToAddressee( c, addressee ); | 195 | res = mConverter->opieToAddressee( c, addressee ); |
202 | 196 | ||
203 | if ( !addressee.isEmpty() && res ) | 197 | if ( !addressee.isEmpty() && res ) |
204 | { | 198 | { |
205 | addressee.setResource( this ); | 199 | addressee.setResource( this ); |
206 | addressBook()->insertAddressee( addressee ); | 200 | addressBook()->insertAddressee( addressee ); |
207 | } | 201 | } |
208 | 202 | ||
209 | } | 203 | } |
210 | 204 | ||
211 | 205 | ||
212 | return true; | 206 | return true; |
213 | } | 207 | } |
214 | 208 | ||
215 | bool ResourceOpie::save( Ticket *ticket ) | 209 | bool ResourceOpie::save( Ticket *ticket ) |
216 | { | 210 | { |
217 | qDebug("ResourceOpie::save: %s", fileName().latin1()); | 211 | qDebug("ResourceOpie::save: %s", fileName().latin1()); |
218 | 212 | ||
219 | 213 | ||
220 | 214 | ||
221 | KABC::AddressBook::Iterator it; | 215 | KABC::AddressBook::Iterator it; |
222 | bool res; | 216 | bool res; |
223 | 217 | ||
224 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 218 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
225 | OContact c; | 219 | OContact c; |
226 | KABC::Addressee addressee = (*it); | 220 | KABC::Addressee addressee = (*it); |
227 | 221 | ||
228 | res = mConverter->addresseeToOpie( *it, c ); | 222 | res = mConverter->addresseeToOpie( *it, c ); |
229 | if (res == true) | 223 | if (res == true) |
230 | { | 224 | { |
231 | res = mAccess->add(c); | 225 | res = mAccess->add(c); |
232 | if (res == false) | 226 | if (res == false) |
233 | qDebug("Unable to append Contact %s", c.fullName().latin1()); | 227 | qDebug("Unable to append Contact %s", c.fullName().latin1()); |
234 | } | 228 | } |
235 | else | 229 | else |
236 | { | 230 | { |
237 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | 231 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); |
238 | } | 232 | } |
239 | } | 233 | } |
240 | 234 | ||
241 | mAccess->save(); | 235 | mAccess->save(); |
242 | 236 | ||
243 | delete ticket; | 237 | delete ticket; |
244 | unlock( fileName() ); | 238 | unlock( fileName() ); |
245 | 239 | ||
246 | return true; | 240 | return true; |
247 | 241 | ||
248 | } | 242 | } |
249 | 243 | ||
250 | bool ResourceOpie::lock( const QString &lockfileName ) | 244 | bool ResourceOpie::lock( const QString &lockfileName ) |
251 | { | 245 | { |
252 | qDebug("ResourceOpie::lock: %s", fileName().latin1()); | 246 | qDebug("ResourceOpie::lock: %s", fileName().latin1()); |
253 | 247 | ||
254 | |||
255 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); | ||
256 | kdDebug(5700) << "ResourceOpie::lock()" << endl; | 248 | kdDebug(5700) << "ResourceOpie::lock()" << endl; |
257 | 249 | ||
258 | QString fn = lockfileName; | 250 | QString fn = lockfileName; |
259 | 251 | ||
260 | //US change the implementation how the lockfilename is getting created | ||
261 | //US fn.replace( QRegExp("/"), "_" ); | ||
262 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
263 | |||
264 | KURL url(fn); | 252 | KURL url(fn); |
265 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 253 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
266 | 254 | ||
267 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 255 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
268 | 256 | ||
269 | if (QFile::exists( lockName )) return false; | 257 | if (QFile::exists( lockName )) return false; |
270 | 258 | ||
271 | QString lockUniqueName; | 259 | QString lockUniqueName; |
272 | lockUniqueName = fn + KApplication::randomString( 8 ); | 260 | lockUniqueName = fn + KApplication::randomString( 8 ); |
273 | 261 | ||
274 | url = lockUniqueName; | 262 | url = lockUniqueName; |
275 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 263 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
276 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 264 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
277 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 265 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
278 | 266 | ||
279 | // Create unique file | 267 | // Create unique file |
280 | QFile file( mLockUniqueName ); | 268 | QFile file( mLockUniqueName ); |
281 | file.open( IO_WriteOnly ); | 269 | file.open( IO_WriteOnly ); |
282 | file.close(); | 270 | file.close(); |
283 | 271 | ||
284 | // Create lock file | 272 | // Create lock file |
285 | int result = 0; | 273 | int result = 0; |
286 | #ifndef _WIN32_ | 274 | #ifndef _WIN32_ |
287 | result = ::link( QFile::encodeName( mLockUniqueName ), | 275 | result = ::link( QFile::encodeName( mLockUniqueName ), |
288 | QFile::encodeName( lockName ) ); | 276 | QFile::encodeName( lockName ) ); |
289 | #endif | 277 | #endif |
290 | if ( result == 0 ) { | 278 | if ( result == 0 ) { |
291 | addressBook()->emitAddressBookLocked(); | 279 | addressBook()->emitAddressBookLocked(); |
292 | return true; | 280 | return true; |
293 | } | 281 | } |
294 | 282 | ||
295 | // TODO: check stat | 283 | // TODO: check stat |
296 | 284 | ||
297 | return false; | 285 | return false; |
298 | } | 286 | } |
299 | 287 | ||
300 | void ResourceOpie::unlock( const QString &fileName ) | 288 | void ResourceOpie::unlock( const QString &fileName ) |
301 | { | 289 | { |
302 | qDebug("ResourceOpie::unlock() %s", fileName.latin1()); | 290 | qDebug("ResourceOpie::unlock() %s", fileName.latin1()); |
303 | 291 | ||
304 | QString fn = fileName; | 292 | QString fn = fileName; |
305 | //US change the implementation how the lockfilename is getting created | ||
306 | //US fn.replace( QRegExp( "/" ), "_" ); | ||
307 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
308 | //US QString lockName = fn + ".lock"; | ||
309 | KURL url(fn); | 293 | KURL url(fn); |
310 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 294 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
311 | 295 | ||
312 | QFile::remove( lockName ); | 296 | QFile::remove( lockName ); |
313 | QFile::remove( mLockUniqueName ); | 297 | QFile::remove( mLockUniqueName ); |
314 | addressBook()->emitAddressBookUnlocked(); | 298 | addressBook()->emitAddressBookUnlocked(); |
315 | } | 299 | } |
316 | 300 | ||
317 | void ResourceOpie::setFileName( const QString &newFileName ) | 301 | void ResourceOpie::setFileName( const QString &newFileName ) |
318 | { | 302 | { |
319 | mDirWatch.stopScan(); | 303 | mDirWatch.stopScan(); |
320 | mDirWatch.removeFile( fileName() ); | 304 | mDirWatch.removeFile( fileName() ); |
321 | 305 | ||
322 | Resource::setFileName( newFileName ); | 306 | Resource::setFileName( newFileName ); |
323 | 307 | ||
324 | mDirWatch.addFile( fileName() ); | 308 | mDirWatch.addFile( fileName() ); |
325 | mDirWatch.startScan(); | 309 | mDirWatch.startScan(); |
326 | 310 | ||
327 | } | 311 | } |
328 | 312 | ||
329 | 313 | ||
330 | void ResourceOpie::fileChanged() | 314 | void ResourceOpie::fileChanged() |
331 | { | 315 | { |
332 | // There is a small theoretical chance that KDirWatch calls us before | 316 | // There is a small theoretical chance that KDirWatch calls us before |
333 | // we are fully constructed | 317 | // we are fully constructed |
334 | if (!addressBook()) | 318 | if (!addressBook()) |
335 | return; | 319 | return; |
336 | 320 | ||
337 | QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 321 | QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
338 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 322 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
339 | load(); | 323 | load(); |
340 | addressBook()->emitAddressBookChanged(); | 324 | addressBook()->emitAddressBookChanged(); |
341 | } | 325 | } |
342 | 326 | ||
343 | load(); | 327 | load(); |
344 | addressBook()->emitAddressBookChanged(); | 328 | addressBook()->emitAddressBookChanged(); |
345 | } | 329 | } |
346 | 330 | ||
347 | void ResourceOpie::removeAddressee( const Addressee &addr ) | 331 | void ResourceOpie::removeAddressee( const Addressee &addr ) |
348 | { | 332 | { |
349 | } | 333 | } |
350 | 334 | ||
351 | void ResourceOpie::cleanUp() | 335 | void ResourceOpie::cleanUp() |
352 | { | 336 | { |
353 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); | 337 | // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); |
354 | 338 | ||
355 | unlock( fileName() ); | 339 | unlock( fileName() ); |
356 | } | 340 | } |
357 | 341 | ||
358 | 342 | ||
359 | /** | 343 | /** |
360 | * This method returns the number of elements that are currently in the resource. | 344 | * This method returns the number of elements that are currently in the resource. |
361 | */ | 345 | */ |
362 | int ResourceOpie::count() const | 346 | int ResourceOpie::count() const |
363 | { | 347 | { |
364 | qDebug("ResourceOpie::count: %x", mAccess); | 348 | qDebug("ResourceOpie::count: %x", mAccess); |
365 | 349 | ||
366 | if (mAccess != 0) | 350 | if (mAccess != 0) |
367 | { | 351 | { |
368 | OContactAccess::List contactList = mAccess->allRecords(); | 352 | OContactAccess::List contactList = mAccess->allRecords(); |
369 | return contactList.count(); | 353 | return contactList.count(); |
370 | } | 354 | } |
371 | else | 355 | else |
372 | return 0; | 356 | return 0; |
373 | } | 357 | } |
374 | 358 | ||
375 | 359 | ||
376 | /** | 360 | /** |
377 | * This method removes all elements from the resource!! (Not from the addressbook) | 361 | * This method removes all elements from the resource!! (Not from the addressbook) |
378 | */ | 362 | */ |
379 | bool ResourceOpie::clear() | 363 | bool ResourceOpie::clear() |
380 | { | 364 | { |
381 | if (mAccess != 0) { | 365 | if (mAccess != 0) { |
382 | mAccess->clear(); | 366 | mAccess->clear(); |
383 | return true; | 367 | return true; |
384 | } | 368 | } |
385 | else | 369 | else |
386 | return false; | 370 | return false; |
387 | } | 371 | } |
388 | 372 | ||
389 | 373 | ||
390 | 374 | ||
391 | //US #include "resourceopie.moc" | 375 | //US #include "resourceopie.moc" |
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index dc88272..4a35f19 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -1,383 +1,358 @@ | |||
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 | #include <sys/types.h> | 27 | #include <sys/types.h> |
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | 30 | ||
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qfileinfo.h> | 33 | #include <qfileinfo.h> |
34 | #include <qregexp.h> | 34 | #include <qregexp.h> |
35 | //US #include <qtimer.h> | 35 | //US #include <qtimer.h> |
36 | 36 | ||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
44 | 44 | ||
45 | #include <qpe/pim/addressbookaccess.h> | 45 | #include <qpe/pim/addressbookaccess.h> |
46 | 46 | ||
47 | 47 | ||
48 | #include "resourceqtopiaconfig.h" | 48 | #include "resourceqtopiaconfig.h" |
49 | #include "stdaddressbook.h" | 49 | #include "stdaddressbook.h" |
50 | 50 | ||
51 | #include "qtopiaconverter.h" | 51 | #include "qtopiaconverter.h" |
52 | #include "syncwidget.h" | 52 | #include "syncprefwidget.h" |
53 | 53 | ||
54 | #include "resourceqtopia.h" | 54 | #include "resourceqtopia.h" |
55 | 55 | ||
56 | using namespace KABC; | 56 | using namespace KABC; |
57 | extern "C" | 57 | extern "C" |
58 | { | 58 | { |
59 | void *init_microkabc_qtopia() | 59 | void *init_microkabc_qtopia() |
60 | { | 60 | { |
61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, KRES::SyncWidget>(); | 61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidget>(); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) | 65 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) |
66 | : Resource( config, syncable ), mConverter (0) | 66 | : Resource( config, syncable ), mConverter (0) |
67 | { | 67 | { |
68 | // we can not choose the filename. Therefore use the default to display | 68 | // we can not choose the filename. Therefore use the default to display |
69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
70 | |||
71 | init( fileName ); | 70 | init( fileName ); |
72 | } | 71 | } |
73 | 72 | ||
74 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) | 73 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) |
75 | : Resource( 0, syncable ) | 74 | : Resource( 0, syncable ) |
76 | { | 75 | { |
77 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | ||
78 | init( fileName ); | 76 | init( fileName ); |
79 | } | 77 | } |
80 | 78 | ||
81 | void ResourceQtopia::init( const QString &fileName ) | 79 | void ResourceQtopia::init( const QString &fileName ) |
82 | { | 80 | { |
83 | 81 | ||
84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
87 | 85 | ||
88 | setFileName( fileName ); | 86 | setFileName( fileName ); |
89 | } | 87 | } |
90 | 88 | ||
91 | ResourceQtopia::~ResourceQtopia() | 89 | ResourceQtopia::~ResourceQtopia() |
92 | { | 90 | { |
93 | if (mConverter != 0) | 91 | if (mConverter != 0) |
94 | delete mConverter; | 92 | delete mConverter; |
95 | 93 | ||
96 | if(mAccess != 0) | 94 | if(mAccess != 0) |
97 | delete mAccess; | 95 | delete mAccess; |
98 | } | 96 | } |
99 | 97 | ||
100 | void ResourceQtopia::writeConfig( KConfig *config ) | 98 | void ResourceQtopia::writeConfig( KConfig *config ) |
101 | { | 99 | { |
102 | Resource::writeConfig( config ); | 100 | Resource::writeConfig( config ); |
103 | } | 101 | } |
104 | 102 | ||
105 | Ticket *ResourceQtopia::requestSaveTicket() | 103 | Ticket *ResourceQtopia::requestSaveTicket() |
106 | { | 104 | { |
107 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; | 105 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; |
108 | 106 | ||
107 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); | ||
108 | |||
109 | if ( !addressBook() ) return 0; | 109 | if ( !addressBook() ) return 0; |
110 | 110 | ||
111 | if ( !lock( fileName() ) ) { | 111 | if ( !lock( fileName() ) ) { |
112 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 112 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" |
113 | << fileName() << "'" << endl; | 113 | << fileName() << "'" << endl; |
114 | return 0; | 114 | return 0; |
115 | } | 115 | } |
116 | return createTicket( this ); | 116 | return createTicket( this ); |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | bool ResourceQtopia::doOpen() | 120 | bool ResourceQtopia::doOpen() |
121 | { | 121 | { |
122 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); | 122 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); |
123 | 123 | ||
124 | mAccess = new AddressBookAccess(); | 124 | mAccess = new AddressBookAccess(); |
125 | 125 | ||
126 | if ( !mAccess ) { | 126 | if ( !mAccess ) { |
127 | qDebug("Unable to load file() %s", fileName().latin1()); | 127 | qDebug("Unable to load file() %s", fileName().latin1()); |
128 | return false; | 128 | return false; |
129 | } | 129 | } |
130 | 130 | ||
131 | bool res = false; | 131 | |
132 | if (mConverter == 0) | 132 | if (mConverter == 0) |
133 | { | 133 | { |
134 | mConverter = new QtopiaConverter(); | 134 | mConverter = new QtopiaConverter(); |
135 | res = mConverter->init(); | 135 | bool res = mConverter->init(); |
136 | if ( !res ) | 136 | if ( !res ) |
137 | { | 137 | { |
138 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); | 138 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); |
139 | qDebug(msg); | 139 | qDebug(msg); |
140 | delete mAccess; | 140 | delete mAccess; |
141 | mAccess = 0; | 141 | mAccess = 0; |
142 | return false; | 142 | return false; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | return true; | 146 | return true; |
147 | } | 147 | } |
148 | 148 | ||
149 | void ResourceQtopia::doClose() | 149 | void ResourceQtopia::doClose() |
150 | { | 150 | { |
151 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); | 151 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); |
152 | 152 | ||
153 | if(mAccess) | 153 | if(mAccess) |
154 | { | 154 | { |
155 | delete mAccess; | 155 | delete mAccess; |
156 | mAccess = 0; | 156 | mAccess = 0; |
157 | } | 157 | } |
158 | // it seems so, that deletion of access deletes backend as well | 158 | // it seems so, that deletion of access deletes backend as well |
159 | //delete backend; | 159 | //delete backend; |
160 | 160 | ||
161 | return; | 161 | return; |
162 | } | 162 | } |
163 | 163 | ||
164 | bool ResourceQtopia::load() | 164 | bool ResourceQtopia::load() |
165 | { | 165 | { |
166 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); | 166 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); |
167 | 167 | ||
168 | AddressBookIterator it(*mAccess); | 168 | AddressBookIterator it(*mAccess); |
169 | const PimContact* contact; | 169 | const PimContact* contact; |
170 | bool res; | 170 | bool res; |
171 | 171 | ||
172 | for (contact=it.toFirst(); it.current(); ++it) | 172 | for (contact=it.toFirst(); it.current(); ++it) |
173 | { | 173 | { |
174 | contact = it.current(); | 174 | contact = it.current(); |
175 | 175 | ||
176 | KABC::Addressee addressee; | 176 | KABC::Addressee addressee; |
177 | 177 | ||
178 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); | 178 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); |
179 | 179 | ||
180 | if ( !addressee.isEmpty() && res ) | 180 | if ( !addressee.isEmpty() && res ) |
181 | { | 181 | { |
182 | addressee.setResource( this ); | 182 | addressee.setResource( this ); |
183 | addressBook()->insertAddressee( addressee ); | 183 | addressBook()->insertAddressee( addressee ); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | return true; | 187 | return true; |
188 | } | 188 | } |
189 | 189 | ||
190 | bool ResourceQtopia::save( Ticket *ticket ) | 190 | bool ResourceQtopia::save( Ticket *ticket ) |
191 | { | 191 | { |
192 | /*US | 192 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); |
193 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
194 | kdDebug(5700) << "ResourceQtopia::save()" << endl; | ||
195 | |||
196 | // create backup file | ||
197 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | ||
198 | 193 | ||
199 | /*US we use a simpler method to create a backupfile | ||
200 | |||
201 | (void) KSaveFile::backupFile( mFileName, QString::null | ||
202 | ,extension ); | ||
203 | |||
204 | KSaveFile saveFile( mFileName ); | ||
205 | bool ok = false; | ||
206 | if ( saveFile.status() == 0 && saveFile.file() ) | ||
207 | { | ||
208 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | ||
209 | ok = saveFile.close(); | ||
210 | } | ||
211 | */ | ||
212 | 194 | ||
213 | /*US | 195 | KABC::AddressBook::Iterator it; |
214 | //US ToDo: write backupfile | 196 | bool res; |
215 | QFile info; | ||
216 | info.setName( mFileName ); | ||
217 | bool ok = info.open( IO_WriteOnly ); | ||
218 | if ( ok ) { | ||
219 | //US mFormat->saveAll( addressBook(), this, &info ); | ||
220 | 197 | ||
221 | info.close(); | 198 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
222 | ok = true; | 199 | PimContact c; |
223 | } | 200 | KABC::Addressee addressee = (*it); |
224 | else { | ||
225 | 201 | ||
202 | res = mConverter->addresseeToQtopia( *it, c ); | ||
203 | if (res == true) | ||
204 | { | ||
205 | mAccess->addContact(c); | ||
206 | // if (res == false) | ||
207 | // qDebug("Unable to append Contact %s", c.fullName().latin1()); | ||
208 | } | ||
209 | else | ||
210 | { | ||
211 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | ||
212 | } | ||
226 | } | 213 | } |
227 | 214 | ||
228 | if ( !ok ) | 215 | // mAccess->addressBookUpdated(); |
229 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | ||
230 | 216 | ||
231 | delete ticket; | 217 | delete ticket; |
232 | unlock( mFileName ); | 218 | unlock( fileName() ); |
233 | |||
234 | return ok; | ||
235 | |||
236 | qDebug("ResourceQtopia::save has to be changed"); | ||
237 | |||
238 | |||
239 | access->save(); | ||
240 | |||
241 | */ | ||
242 | 219 | ||
243 | return true; | 220 | return true; |
244 | } | 221 | } |
245 | 222 | ||
246 | bool ResourceQtopia::lock( const QString &fileName ) | 223 | bool ResourceQtopia::lock( const QString &lockfileName ) |
247 | { | 224 | { |
248 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; | 225 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); |
249 | 226 | ||
250 | QString fn = fileName; | 227 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; |
251 | 228 | ||
252 | //US change the implementation how the lockfilename is getting created | 229 | QString fn = lockfileName; |
253 | //US fn.replace( QRegExp("/"), "_" ); | ||
254 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
255 | 230 | ||
256 | KURL url(fn); | 231 | KURL url(fn); |
257 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 232 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
258 | 233 | ||
259 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 234 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
260 | 235 | ||
261 | if (QFile::exists( lockName )) return false; | 236 | if (QFile::exists( lockName )) return false; |
262 | 237 | ||
263 | QString lockUniqueName; | 238 | QString lockUniqueName; |
264 | lockUniqueName = fn + KApplication::randomString( 8 ); | 239 | lockUniqueName = fn + KApplication::randomString( 8 ); |
265 | 240 | ||
266 | url = lockUniqueName; | 241 | url = lockUniqueName; |
267 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 242 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
268 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 243 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
269 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 244 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
270 | 245 | ||
271 | // Create unique file | 246 | // Create unique file |
272 | QFile file( mLockUniqueName ); | 247 | QFile file( mLockUniqueName ); |
273 | file.open( IO_WriteOnly ); | 248 | file.open( IO_WriteOnly ); |
274 | file.close(); | 249 | file.close(); |
275 | 250 | ||
276 | // Create lock file | 251 | // Create lock file |
277 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 252 | int result = 0; |
253 | #ifndef _WIN32_ | ||
254 | result = ::link( QFile::encodeName( mLockUniqueName ), | ||
278 | QFile::encodeName( lockName ) ); | 255 | QFile::encodeName( lockName ) ); |
279 | 256 | #endif | |
280 | if ( result == 0 ) { | 257 | if ( result == 0 ) { |
281 | addressBook()->emitAddressBookLocked(); | 258 | addressBook()->emitAddressBookLocked(); |
282 | return true; | 259 | return true; |
283 | } | 260 | } |
284 | 261 | ||
285 | // TODO: check stat | 262 | // TODO: check stat |
286 | 263 | ||
287 | return false; | 264 | return false; |
288 | } | 265 | } |
289 | 266 | ||
290 | void ResourceQtopia::unlock( const QString &fileName ) | 267 | void ResourceQtopia::unlock( const QString &fileName ) |
291 | { | 268 | { |
269 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); | ||
270 | |||
292 | QString fn = fileName; | 271 | QString fn = fileName; |
293 | //US change the implementation how the lockfilename is getting created | ||
294 | //US fn.replace( QRegExp( "/" ), "_" ); | ||
295 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
296 | //US QString lockName = fn + ".lock"; | ||
297 | KURL url(fn); | 272 | KURL url(fn); |
298 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 273 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
299 | 274 | ||
300 | QFile::remove( lockName ); | 275 | QFile::remove( lockName ); |
301 | QFile::remove( mLockUniqueName ); | 276 | QFile::remove( mLockUniqueName ); |
302 | addressBook()->emitAddressBookUnlocked(); | 277 | addressBook()->emitAddressBookUnlocked(); |
303 | } | 278 | } |
304 | 279 | ||
305 | void ResourceQtopia::setFileName( const QString &newFileName ) | 280 | void ResourceQtopia::setFileName( const QString &newFileName ) |
306 | { | 281 | { |
307 | mDirWatch.stopScan(); | 282 | mDirWatch.stopScan(); |
308 | mDirWatch.removeFile( fileName() ); | 283 | mDirWatch.removeFile( fileName() ); |
309 | 284 | ||
310 | Resource::setFileName( newFileName ); | 285 | Resource::setFileName( newFileName ); |
311 | 286 | ||
312 | mDirWatch.addFile( fileName() ); | 287 | mDirWatch.addFile( fileName() ); |
313 | mDirWatch.startScan(); | 288 | mDirWatch.startScan(); |
314 | } | 289 | } |
315 | 290 | ||
316 | 291 | ||
317 | void ResourceQtopia::fileChanged() | 292 | void ResourceQtopia::fileChanged() |
318 | { | 293 | { |
319 | // There is a small theoretical chance that KDirWatch calls us before | 294 | // There is a small theoretical chance that KDirWatch calls us before |
320 | // we are fully constructed | 295 | // we are fully constructed |
321 | if (!addressBook()) | 296 | if (!addressBook()) |
322 | return; | 297 | return; |
323 | 298 | ||
324 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 299 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
325 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 300 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
326 | load(); | 301 | load(); |
327 | addressBook()->emitAddressBookChanged(); | 302 | addressBook()->emitAddressBookChanged(); |
328 | } | 303 | } |
329 | } | 304 | } |
330 | 305 | ||
331 | void ResourceQtopia::removeAddressee( const Addressee &addr ) | 306 | void ResourceQtopia::removeAddressee( const Addressee &addr ) |
332 | { | 307 | { |
333 | } | 308 | } |
334 | 309 | ||
335 | void ResourceQtopia::cleanUp() | 310 | void ResourceQtopia::cleanUp() |
336 | { | 311 | { |
337 | unlock( fileName() ); | 312 | unlock( fileName() ); |
338 | } | 313 | } |
339 | 314 | ||
340 | 315 | ||
341 | 316 | ||
342 | /** | 317 | /** |
343 | * This method returns the number of elements that are currently in the resource. | 318 | * This method returns the number of elements that are currently in the resource. |
344 | */ | 319 | */ |
345 | int ResourceQtopia::count() const | 320 | int ResourceQtopia::count() const |
346 | { | 321 | { |
347 | if (mAccess != 0) | 322 | if (mAccess != 0) |
348 | { | 323 | { |
349 | int counter = 0; | 324 | int counter = 0; |
350 | AddressBookIterator it2(*mAccess); | 325 | AddressBookIterator it2(*mAccess); |
351 | for (it2.toFirst(); it2.current(); ++it2) { | 326 | for (it2.toFirst(); it2.current(); ++it2) { |
352 | counter++; | 327 | counter++; |
353 | } | 328 | } |
354 | 329 | ||
355 | return counter; | 330 | return counter; |
356 | } | 331 | } |
357 | else | 332 | else |
358 | return 0; | 333 | return 0; |
359 | } | 334 | } |
360 | 335 | ||
361 | 336 | ||
362 | /** | 337 | /** |
363 | * This method removes all elements from the resource!! (Not from the addressbook) | 338 | * This method removes all elements from the resource!! (Not from the addressbook) |
364 | */ | 339 | */ |
365 | bool ResourceQtopia::clear() | 340 | bool ResourceQtopia::clear() |
366 | { | 341 | { |
367 | if (mAccess != 0) | 342 | if (mAccess != 0) |
368 | { | 343 | { |
369 | AddressBookIterator it2(*mAccess); | 344 | AddressBookIterator it2(*mAccess); |
370 | for (it2.toFirst(); it2.current(); ++it2) { | 345 | for (it2.toFirst(); it2.current(); ++it2) { |
371 | mAccess->removeContact(*it2.current()); | 346 | mAccess->removeContact(*it2.current()); |
372 | } | 347 | } |
373 | return true; | 348 | return true; |
374 | } | 349 | } |
375 | else | 350 | else |
376 | return false; | 351 | return false; |
377 | } | 352 | } |
378 | 353 | ||
379 | 354 | ||
380 | 355 | ||
381 | 356 | ||
382 | 357 | ||
383 | //US #include "resourceqtopia.moc" | 358 | //US #include "resourceqtopia.moc" |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 7b909de..14f272d 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -1,382 +1,355 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
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 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | 31 | ||
32 | #include <qdir.h> | 32 | #include <qdir.h> |
33 | #include <qfile.h> | 33 | #include <qfile.h> |
34 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | //US #include <qtimer.h> | 36 | //US #include <qtimer.h> |
37 | 37 | ||
38 | #include <kapplication.h> | 38 | #include <kapplication.h> |
39 | #include <kconfig.h> | 39 | #include <kconfig.h> |
40 | #include <kdebug.h> | 40 | #include <kdebug.h> |
41 | #include <klocale.h> | 41 | #include <klocale.h> |
42 | //US #include <ksavefile.h> | 42 | //US #include <ksavefile.h> |
43 | #include <kstandarddirs.h> | 43 | #include <kstandarddirs.h> |
44 | #include <kmessagebox.h> | 44 | #include <kmessagebox.h> |
45 | 45 | ||
46 | #include <sl/slzdb.h> | 46 | #include <sl/slzdb.h> |
47 | 47 | ||
48 | 48 | ||
49 | #include "resourcesharpdtmconfig.h" | 49 | #include "resourcesharpdtmconfig.h" |
50 | #include "resourcesharpdtm.h" | 50 | #include "resourcesharpdtm.h" |
51 | 51 | ||
52 | #include "syncprefwidget.h" | ||
53 | |||
52 | #include "stdaddressbook.h" | 54 | #include "stdaddressbook.h" |
53 | 55 | ||
54 | #include "sharpdtmconverter.h" | 56 | #include "sharpdtmconverter.h" |
55 | 57 | ||
56 | using namespace KABC; | 58 | using namespace KABC; |
57 | extern "C" | 59 | extern "C" |
58 | { | 60 | { |
59 | void *init_microkabc_sharpdtm() | 61 | void *init_microkabc_sharpdtm() |
60 | { | 62 | { |
61 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); | 63 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidget>(); |
62 | } | 64 | } |
63 | } | 65 | } |
64 | 66 | ||
65 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) | 67 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) |
66 | : Resource( config, syncable ), mConverter (0) | 68 | : Resource( config, syncable ), mConverter (0) |
67 | { | 69 | { |
68 | // we can not choose the filename. Therefore use the default to display | 70 | // we can not choose the filename. Therefore use the default to display |
69 | 71 | ||
70 | QString fileName = SlZDataBase::addressbookFileName(); | 72 | QString fileName = SlZDataBase::addressbookFileName(); |
71 | init( fileName ); | 73 | init( fileName ); |
72 | } | 74 | } |
73 | 75 | ||
74 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) | 76 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) |
75 | : Resource( 0, syncable ) | 77 | : Resource( 0, syncable ) |
76 | { | 78 | { |
77 | // qDebug("ResourceFile::ResourceSharpDTM : 3 %s, %s", fileName.latin1(), formatName.latin1()); | ||
78 | init( fileName ); | 79 | init( fileName ); |
79 | } | 80 | } |
80 | 81 | ||
81 | void ResourceSharpDTM::init( const QString &fileName ) | 82 | void ResourceSharpDTM::init( const QString &fileName ) |
82 | { | 83 | { |
83 | 84 | ||
84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 85 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 86 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 87 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
87 | 88 | ||
88 | setFileName( fileName ); | 89 | setFileName( fileName ); |
89 | } | 90 | } |
90 | 91 | ||
91 | ResourceSharpDTM::~ResourceSharpDTM() | 92 | ResourceSharpDTM::~ResourceSharpDTM() |
92 | { | 93 | { |
93 | // if (mConverter != 0) | 94 | if (mConverter != 0) |
94 | // delete mConverter; | 95 | delete mConverter; |
95 | 96 | ||
97 | if(mAccess != 0) | ||
98 | delete mAccess; | ||
96 | } | 99 | } |
97 | 100 | ||
98 | void ResourceSharpDTM::writeConfig( KConfig *config ) | 101 | void ResourceSharpDTM::writeConfig( KConfig *config ) |
99 | { | 102 | { |
100 | Resource::writeConfig( config ); | 103 | Resource::writeConfig( config ); |
101 | } | 104 | } |
102 | 105 | ||
103 | Ticket *ResourceSharpDTM::requestSaveTicket() | 106 | Ticket *ResourceSharpDTM::requestSaveTicket() |
104 | { | 107 | { |
105 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; | 108 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket()" << endl; |
109 | |||
110 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); | ||
106 | 111 | ||
107 | if ( !addressBook() ) return 0; | 112 | if ( !addressBook() ) return 0; |
108 | 113 | ||
109 | if ( !lock( mFileName ) ) { | 114 | if ( !lock( fileName() ) ) { |
110 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 115 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket(): Unable to lock file '" |
111 | << mFileName << "'" << endl; | 116 | << fileName() << "'" << endl; |
112 | return 0; | 117 | return 0; |
113 | } | 118 | } |
114 | return createTicket( this ); | 119 | return createTicket( this ); |
115 | } | 120 | } |
116 | 121 | ||
117 | 122 | ||
118 | bool ResourceSharpDTM::doOpen() | 123 | bool ResourceSharpDTM::doOpen() |
119 | { | 124 | { |
120 | /*US | 125 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); |
121 | QFile file( mFileName ); | ||
122 | |||
123 | if ( !file.exists() ) { | ||
124 | // try to create the file | ||
125 | bool ok = file.open( IO_WriteOnly ); | ||
126 | if ( ok ) | ||
127 | file.close(); | ||
128 | |||
129 | return ok; | ||
130 | } else { | ||
131 | if ( !file.open( IO_ReadWrite ) ) | ||
132 | return false; | ||
133 | |||
134 | if ( file.size() == 0 ) { | ||
135 | file.close(); | ||
136 | return true; | ||
137 | } | ||
138 | |||
139 | //US bool ok = mFormat->checkFormat( &file ); | ||
140 | bool ok = true; | ||
141 | |||
142 | file.close(); | ||
143 | |||
144 | return ok; | ||
145 | } | ||
146 | */ | ||
147 | return true; | ||
148 | } | ||
149 | |||
150 | void ResourceSharpDTM::doClose() | ||
151 | { | ||
152 | } | ||
153 | |||
154 | bool ResourceSharpDTM::load() | ||
155 | { | ||
156 | kdDebug(5700) << "ResourcSharpDTM::load(): '" << mFileName << "'" << endl; | ||
157 | |||
158 | // qDebug("ResourceSharpDTM::load: Try to load file() %s", mFileName.latin1()); | ||
159 | 126 | ||
160 | // the last parameter in the SlZDataBase constructor means "readonly" | 127 | // the last parameter in the SlZDataBase constructor means "readonly" |
161 | SlZDataBase* access = new SlZDataBase(mFileName, | 128 | mAccess = new SlZDataBase(fileName(), |
162 | SlZDataBase::addressbookItems(), | 129 | SlZDataBase::addressbookItems(), |
163 | NULL, true); | 130 | NULL, true); |
164 | if ( !access ) { | 131 | |
165 | qDebug("Unable to load file() %s", mFileName.latin1()); | 132 | if ( !mAccess ) { |
166 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | 133 | qDebug("Unable to load file() %s", fileName().latin1()); |
167 | return false; | 134 | return false; |
168 | } | 135 | } |
169 | 136 | ||
170 | bool res = false; | ||
171 | if (mConverter == 0) | 137 | if (mConverter == 0) |
172 | { | 138 | { |
173 | mConverter = new SharpDTMConverter(); | 139 | mConverter = new SharpDTMConverter(); |
174 | res = mConverter->init(); | 140 | bool res = mConverter->init(); |
175 | if ( !res ) | 141 | if ( !res ) |
176 | { | 142 | { |
177 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | 143 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); |
178 | 144 | ||
179 | qDebug(msg); | 145 | qDebug(msg); |
180 | addressBook()->error( i18n( msg ) ); | 146 | delete mAccess; |
181 | delete access; | 147 | mAccess = 0; |
182 | return false; | 148 | return false; |
183 | } | 149 | } |
184 | } | 150 | } |
185 | 151 | ||
186 | { //create a new scope | 152 | return true; |
187 | CardId id; | 153 | } |
154 | |||
155 | void ResourceSharpDTM::doClose() | ||
156 | { | ||
157 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); | ||
188 | 158 | ||
189 | for (bool res=access->first(); res == true; res=access->next()) { | 159 | if(mAccess) |
190 | id = access->cardId(); | 160 | { |
161 | delete mAccess; | ||
162 | mAccess = 0; | ||
163 | } | ||
164 | // it seems so, that deletion of access deletes backend as well | ||
165 | //delete backend; | ||
191 | 166 | ||
192 | KABC::Addressee addressee; | 167 | return; |
168 | } | ||
193 | 169 | ||
194 | res = mConverter->sharpToAddressee( id, access, addressee ); | 170 | bool ResourceSharpDTM::load() |
171 | { | ||
172 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); | ||
195 | 173 | ||
196 | if ( !addressee.isEmpty() && res ) | 174 | bool res = false; |
197 | { | 175 | |
198 | addressee.setResource( this ); | 176 | CardId id; |
199 | addressBook()->insertAddressee( addressee ); | 177 | |
200 | } | 178 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) |
179 | { | ||
180 | id = mAccess->cardId(); | ||
181 | |||
182 | KABC::Addressee addressee; | ||
183 | |||
184 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | ||
185 | |||
186 | if ( !addressee.isEmpty() && res ) | ||
187 | { | ||
188 | addressee.setResource( this ); | ||
189 | addressBook()->insertAddressee( addressee ); | ||
201 | } | 190 | } |
202 | } | 191 | } |
203 | 192 | ||
204 | delete access; | ||
205 | return true; | 193 | return true; |
206 | } | 194 | } |
207 | 195 | ||
208 | bool ResourceSharpDTM::save( Ticket *ticket ) | 196 | bool ResourceSharpDTM::save( Ticket *ticket ) |
209 | { | 197 | { |
210 | /*US | 198 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); |
211 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
212 | kdDebug(5700) << "ResourceQtopia::save()" << endl; | ||
213 | 199 | ||
214 | // create backup file | ||
215 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | ||
216 | 200 | ||
217 | /*US we use a simpler method to create a backupfile | 201 | KABC::AddressBook::Iterator it; |
202 | bool res; | ||
218 | 203 | ||
219 | (void) KSaveFile::backupFile( mFileName, QString::null | 204 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
220 | ,extension ); | 205 | CardId id = 0;// 0 means new card |
206 | KABC::Addressee addressee = (*it); | ||
221 | 207 | ||
222 | KSaveFile saveFile( mFileName ); | 208 | res = mAccess->startEditCard(id); |
223 | bool ok = false; | 209 | if (res == true) |
224 | if ( saveFile.status() == 0 && saveFile.file() ) | 210 | { |
225 | { | 211 | res = mConverter->addresseeToSharp( *it, mAccess, id ); |
226 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 212 | if (res == true) |
227 | ok = saveFile.close(); | 213 | { |
228 | } | 214 | res = mAccess->finishEditCard(&id); |
229 | */ | 215 | if (res == false) |
230 | 216 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | |
231 | /*US | 217 | } |
232 | //US ToDo: write backupfile | 218 | else |
233 | QFile info; | 219 | { |
234 | info.setName( mFileName ); | 220 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
235 | bool ok = info.open( IO_WriteOnly ); | 221 | mAccess->cancelEditCard(); |
236 | if ( ok ) { | 222 | } |
237 | //US mFormat->saveAll( addressBook(), this, &info ); | 223 | } |
238 | 224 | else | |
239 | info.close(); | 225 | { |
240 | ok = true; | 226 | qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1()); |
241 | } | 227 | } |
242 | else { | ||
243 | 228 | ||
244 | } | 229 | } |
245 | 230 | ||
246 | if ( !ok ) | 231 | //US mAccess->save(); |
247 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | ||
248 | 232 | ||
249 | delete ticket; | 233 | delete ticket; |
250 | unlock( mFileName ); | 234 | unlock( fileName() ); |
251 | 235 | ||
252 | return ok; | ||
253 | |||
254 | qDebug("ResourceQtopia::save has to be changed"); | ||
255 | */ | ||
256 | return true; | 236 | return true; |
257 | } | 237 | } |
258 | 238 | ||
259 | bool ResourceSharpDTM::lock( const QString &fileName ) | 239 | bool ResourceSharpDTM::lock( const QString &lockfileName ) |
260 | { | 240 | { |
261 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; | 241 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); |
262 | 242 | ||
263 | QString fn = fileName; | 243 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; |
264 | 244 | ||
265 | //US change the implementation how the lockfilename is getting created | 245 | QString fn = lockfileName; |
266 | //US fn.replace( QRegExp("/"), "_" ); | ||
267 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
268 | 246 | ||
269 | KURL url(fn); | 247 | KURL url(fn); |
270 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 248 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
271 | 249 | ||
272 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 250 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
273 | 251 | ||
274 | if (QFile::exists( lockName )) return false; | 252 | if (QFile::exists( lockName )) return false; |
275 | 253 | ||
276 | QString lockUniqueName; | 254 | QString lockUniqueName; |
277 | lockUniqueName = fn + KApplication::randomString( 8 ); | 255 | lockUniqueName = fn + KApplication::randomString( 8 ); |
278 | 256 | ||
279 | url = lockUniqueName; | 257 | url = lockUniqueName; |
280 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 258 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
281 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 259 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
282 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 260 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
283 | 261 | ||
284 | // Create unique file | 262 | // Create unique file |
285 | QFile file( mLockUniqueName ); | 263 | QFile file( mLockUniqueName ); |
286 | file.open( IO_WriteOnly ); | 264 | file.open( IO_WriteOnly ); |
287 | file.close(); | 265 | file.close(); |
288 | 266 | ||
289 | // Create lock file | 267 | // Create lock file |
290 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 268 | int result = 0; |
269 | #ifndef _WIN32_ | ||
270 | result = ::link( QFile::encodeName( mLockUniqueName ), | ||
291 | QFile::encodeName( lockName ) ); | 271 | QFile::encodeName( lockName ) ); |
292 | 272 | #endif | |
293 | if ( result == 0 ) { | 273 | if ( result == 0 ) { |
294 | addressBook()->emitAddressBookLocked(); | 274 | addressBook()->emitAddressBookLocked(); |
295 | return true; | 275 | return true; |
296 | } | 276 | } |
297 | 277 | ||
298 | // TODO: check stat | 278 | // TODO: check stat |
299 | 279 | ||
300 | return false; | 280 | return false; |
301 | } | 281 | } |
302 | 282 | ||
303 | void ResourceSharpDTM::unlock( const QString &fileName ) | 283 | void ResourceSharpDTM::unlock( const QString &fileName ) |
304 | { | 284 | { |
285 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); | ||
286 | |||
305 | QString fn = fileName; | 287 | QString fn = fileName; |
306 | //US change the implementation how the lockfilename is getting created | ||
307 | //US fn.replace( QRegExp( "/" ), "_" ); | ||
308 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
309 | //US QString lockName = fn + ".lock"; | ||
310 | KURL url(fn); | 288 | KURL url(fn); |
311 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 289 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
312 | 290 | ||
313 | QFile::remove( lockName ); | 291 | QFile::remove( lockName ); |
314 | QFile::remove( mLockUniqueName ); | 292 | QFile::remove( mLockUniqueName ); |
315 | addressBook()->emitAddressBookUnlocked(); | 293 | addressBook()->emitAddressBookUnlocked(); |
316 | } | 294 | } |
317 | 295 | ||
318 | void ResourceSharpDTM::setFileName( const QString &fileName ) | 296 | void ResourceSharpDTM::setFileName( const QString &newFileName ) |
319 | { | 297 | { |
320 | mDirWatch.stopScan(); | 298 | mDirWatch.stopScan(); |
321 | mDirWatch.removeFile( mFileName ); | 299 | mDirWatch.removeFile( fileName() ); |
322 | 300 | ||
323 | mFileName = fileName; | 301 | Resource::setFileName( newFileName ); |
324 | 302 | ||
325 | mDirWatch.addFile( mFileName ); | 303 | mDirWatch.addFile( fileName() ); |
326 | mDirWatch.startScan(); | 304 | mDirWatch.startScan(); |
327 | 305 | ||
328 | } | 306 | } |
329 | 307 | ||
330 | QString ResourceSharpDTM::fileName() const | ||
331 | { | ||
332 | return mFileName; | ||
333 | } | ||
334 | |||
335 | void ResourceSharpDTM::fileChanged() | 308 | void ResourceSharpDTM::fileChanged() |
336 | { | 309 | { |
337 | // There is a small theoretical chance that KDirWatch calls us before | 310 | // There is a small theoretical chance that KDirWatch calls us before |
338 | // we are fully constructed | 311 | // we are fully constructed |
339 | if (!addressBook()) | 312 | if (!addressBook()) |
340 | return; | 313 | return; |
341 | 314 | ||
342 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 315 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
343 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 316 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
344 | load(); | 317 | load(); |
345 | addressBook()->emitAddressBookChanged(); | 318 | addressBook()->emitAddressBookChanged(); |
346 | } | 319 | } |
347 | } | 320 | } |
348 | 321 | ||
349 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) | 322 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) |
350 | { | 323 | { |
351 | } | 324 | } |
352 | 325 | ||
353 | void ResourceSharpDTM::cleanUp() | 326 | void ResourceSharpDTM::cleanUp() |
354 | { | 327 | { |
355 | unlock( mFileName ); | 328 | unlock( fileName() ); |
356 | } | 329 | } |
357 | 330 | ||
358 | /** | 331 | /** |
359 | * This method returns the number of elements that are currently in the resource. | 332 | * This method returns the number of elements that are currently in the resource. |
360 | */ | 333 | */ |
361 | int ResourceSharpDTM::count() const | 334 | int ResourceSharpDTM::count() const |
362 | { | 335 | { |
363 | if (mAccess != 0) | 336 | if (mAccess != 0) |
364 | return mAccess->count(); | 337 | return mAccess->count(); |
365 | else | 338 | else |
366 | return 0; | 339 | return 0; |
367 | } | 340 | } |
368 | 341 | ||
369 | 342 | ||
370 | /** | 343 | /** |
371 | * This method removes all elements from the resource!! (Not from the addressbook) | 344 | * This method removes all elements from the resource!! (Not from the addressbook) |
372 | */ | 345 | */ |
373 | bool ResourceSharpDTM::clear() | 346 | bool ResourceSharpDTM::clear() |
374 | { | 347 | { |
375 | if (mAccess != 0) | 348 | if (mAccess != 0) |
376 | return mAccess->deleteCard(0, SlZDataBase::AllCard ); | 349 | return mAccess->deleteCard(0, SlZDataBase::AllCard ); |
377 | else | 350 | else |
378 | return false; | 351 | return false; |
379 | } | 352 | } |
380 | 353 | ||
381 | 354 | ||
382 | 355 | ||
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.h b/kabc/plugins/sharpdtm/resourcesharpdtm.h index f495e9d..60d38a1 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.h +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.h | |||
@@ -1,153 +1,156 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
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 | 28 | ||
29 | #ifndef KABC_RESOURCESHARPDTM_H | 29 | #ifndef KABC_RESOURCESHARPDTM_H |
30 | #define KABC_RESOURCESHARPDTM_H | 30 | #define KABC_RESOURCESHARPDTM_H |
31 | 31 | ||
32 | #include <kconfig.h> | 32 | #include <kconfig.h> |
33 | #include <kdirwatch.h> | 33 | #include <kdirwatch.h> |
34 | 34 | ||
35 | #include <sys/types.h> | 35 | #include <sys/types.h> |
36 | 36 | ||
37 | #include "resource.h" | 37 | #include "resource.h" |
38 | 38 | ||
39 | 39 | ||
40 | class SlZDataBase; | ||
41 | |||
40 | namespace KABC { | 42 | namespace KABC { |
41 | 43 | ||
42 | class ResourceConfigWidget; | 44 | class ResourceConfigWidget; |
43 | class SharpDTMConverter; | 45 | class SharpDTMConverter; |
44 | 46 | ||
45 | /** | 47 | /** |
46 | @internal | 48 | @internal |
47 | */ | 49 | */ |
48 | class ResourceSharpDTM : public Resource | 50 | class ResourceSharpDTM : public Resource |
49 | { | 51 | { |
50 | Q_OBJECT | 52 | Q_OBJECT |
51 | 53 | ||
52 | public: | 54 | public: |
53 | 55 | ||
54 | /** | 56 | /** |
55 | Constructor. | 57 | Constructor. |
56 | 58 | ||
57 | @param cfg The config object where custom resource settings are stored. | 59 | @param cfg The config object where custom resource settings are stored. |
58 | */ | 60 | */ |
59 | ResourceSharpDTM( const KConfig *cfg, bool syncable ); | 61 | ResourceSharpDTM( const KConfig *cfg, bool syncable ); |
60 | 62 | ||
61 | /** | 63 | /** |
62 | Construct file resource on file @arg fileName using format @arg formatName. | 64 | Construct file resource on file @arg fileName using format @arg formatName. |
63 | */ | 65 | */ |
64 | ResourceSharpDTM( const QString &fileName, bool syncable ); | 66 | ResourceSharpDTM( const QString &fileName, bool syncable ); |
65 | 67 | ||
66 | /** | 68 | /** |
67 | * Destructor. | 69 | * Destructor. |
68 | */ | 70 | */ |
69 | ~ResourceSharpDTM(); | 71 | ~ResourceSharpDTM(); |
70 | 72 | ||
71 | /** | 73 | /** |
72 | Writes the config back. | 74 | Writes the config back. |
73 | */ | 75 | */ |
74 | virtual void writeConfig( KConfig *cfg ); | 76 | virtual void writeConfig( KConfig *cfg ); |
75 | 77 | ||
76 | /** | 78 | /** |
77 | * Tries to open the file and checks for the proper format. | 79 | * Tries to open the file and checks for the proper format. |
78 | * This method should be called before @ref load(). | 80 | * This method should be called before @ref load(). |
79 | */ | 81 | */ |
80 | virtual bool doOpen(); | 82 | virtual bool doOpen(); |
81 | 83 | ||
82 | /** | 84 | /** |
83 | * Closes the file again. | 85 | * Closes the file again. |
84 | */ | 86 | */ |
85 | virtual void doClose(); | 87 | virtual void doClose(); |
86 | 88 | ||
87 | /** | 89 | /** |
88 | * Requests a save ticket, that is used by @ref save() | 90 | * Requests a save ticket, that is used by @ref save() |
89 | */ | 91 | */ |
90 | virtual Ticket *requestSaveTicket(); | 92 | virtual Ticket *requestSaveTicket(); |
91 | 93 | ||
92 | /** | 94 | /** |
93 | * Loads all addressees from file to the address book. | 95 | * Loads all addressees from file to the address book. |
94 | * Returns true if all addressees could be loaded otherwise false. | 96 | * Returns true if all addressees could be loaded otherwise false. |
95 | */ | 97 | */ |
96 | virtual bool load(); | 98 | virtual bool load(); |
97 | 99 | ||
98 | /** | 100 | /** |
99 | * Saves all addresses from address book to file. | 101 | * Saves all addresses from address book to file. |
100 | * Returns true if all addressees could be saved otherwise false. | 102 | * Returns true if all addressees could be saved otherwise false. |
101 | * | 103 | * |
102 | * @param ticket The ticket returned by @ref requestSaveTicket() | 104 | * @param ticket The ticket returned by @ref requestSaveTicket() |
103 | */ | 105 | */ |
104 | virtual bool save( Ticket *ticket ); | 106 | virtual bool save( Ticket *ticket ); |
105 | 107 | ||
106 | /** | 108 | /** |
107 | * Remove a addressee from its source. | 109 | * Remove a addressee from its source. |
108 | * This method is mainly called by KABC::AddressBook. | 110 | * This method is mainly called by KABC::AddressBook. |
109 | */ | 111 | */ |
110 | virtual void removeAddressee( const Addressee& addr ); | 112 | virtual void removeAddressee( const Addressee& addr ); |
111 | 113 | ||
112 | /** | 114 | /** |
113 | * Set name of file to be used for saving. | 115 | * Set name of file to be used for saving. |
114 | */ | 116 | */ |
115 | virtual void setFileName( const QString & ); | 117 | virtual void setFileName( const QString & ); |
116 | 118 | ||
117 | /** | 119 | /** |
118 | * This method is called by an error handler if the application | 120 | * This method is called by an error handler if the application |
119 | * crashed | 121 | * crashed |
120 | */ | 122 | */ |
121 | virtual void cleanUp(); | 123 | virtual void cleanUp(); |
122 | 124 | ||
123 | /** | 125 | /** |
124 | * This method returns the number of elements that are currently in the resource. | 126 | * This method returns the number of elements that are currently in the resource. |
125 | */ | 127 | */ |
126 | virtual int count() const; | 128 | virtual int count() const; |
127 | 129 | ||
128 | /** | 130 | /** |
129 | * This method removes all elements from the resource!! (Not from the addressbook) | 131 | * This method removes all elements from the resource!! (Not from the addressbook) |
130 | */ | 132 | */ |
131 | virtual bool clear(); | 133 | virtual bool clear(); |
132 | 134 | ||
133 | 135 | ||
134 | protected slots: | 136 | protected slots: |
135 | void fileChanged(); | 137 | void fileChanged(); |
136 | 138 | ||
137 | protected: | 139 | protected: |
138 | void init( const QString &fileName ); | 140 | void init( const QString &fileName ); |
139 | 141 | ||
140 | bool lock( const QString &fileName ); | 142 | bool lock( const QString &fileName ); |
141 | void unlock( const QString &fileName ); | 143 | void unlock( const QString &fileName ); |
142 | 144 | ||
143 | private: | 145 | private: |
146 | SlZDataBase* mAccess; | ||
144 | SharpDTMConverter* mConverter; | 147 | SharpDTMConverter* mConverter; |
145 | 148 | ||
146 | QString mLockUniqueName; | 149 | QString mLockUniqueName; |
147 | 150 | ||
148 | KDirWatch mDirWatch; | 151 | KDirWatch mDirWatch; |
149 | }; | 152 | }; |
150 | 153 | ||
151 | } | 154 | } |
152 | 155 | ||
153 | #endif | 156 | #endif |