-rw-r--r-- | kabc/kabc.pro | 4 | ||||
-rw-r--r-- | kabc/plugins/dir/dir.pro | 29 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 6 | ||||
-rw-r--r-- | kabc/plugins/file/file.pro | 30 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 6 |
5 files changed, 69 insertions, 6 deletions
diff --git a/kabc/kabc.pro b/kabc/kabc.pro index ea4bbb7..4a8d73a 100644 --- a/kabc/kabc.pro +++ b/kabc/kabc.pro | |||
@@ -1,214 +1,214 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | #release debug | 3 | #release debug |
4 | DESTDIR=../bin | 4 | DESTDIR=../bin |
5 | 5 | ||
6 | TARGET = microkabc | 6 | TARGET = microkabc |
7 | 7 | ||
8 | include( ../variables.pri ) | 8 | include( ../variables.pri ) |
9 | 9 | ||
10 | INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kio/kfile ../qtcompat ../microkde/kdeui | 10 | INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kio/kfile ../qtcompat ../microkde/kdeui |
11 | 11 | ||
12 | #LIBS += -lmicrokde -lldap | 12 | #LIBS += -lmicrokde -lldap |
13 | LIBS += -L$(QPEDIR)/lib | 13 | LIBS += -L$(QPEDIR)/lib |
14 | DEFINES += KAB_EMBEDDED DESKTOP_VERSION | 14 | DEFINES += KAB_EMBEDDED DESKTOP_VERSION |
15 | unix : { | 15 | unix : { |
16 | 16 | ||
17 | OBJECTS_DIR = obj/unix | 17 | OBJECTS_DIR = obj/unix |
18 | MOC_DIR = moc/unix | 18 | MOC_DIR = moc/unix |
19 | } | 19 | } |
20 | win32: { | 20 | win32: { |
21 | DEFINES += _WIN32_ | 21 | DEFINES += _WIN32_ |
22 | OBJECTS_DIR = obj/win | 22 | OBJECTS_DIR = obj/win |
23 | MOC_DIR = moc/win | 23 | MOC_DIR = moc/win |
24 | } | 24 | } |
25 | INTERFACES = \ | 25 | INTERFACES = \ |
26 | 26 | ||
27 | 27 | ||
28 | HEADERS = \ | 28 | HEADERS = \ |
29 | resource.h \ | 29 | resource.h \ |
30 | stdaddressbook.h \ | 30 | stdaddressbook.h \ |
31 | agent.h \ | 31 | agent.h \ |
32 | geo.h \ | 32 | geo.h \ |
33 | key.h \ | 33 | key.h \ |
34 | field.h \ | 34 | field.h \ |
35 | plugin.h \ | 35 | plugin.h \ |
36 | address.h \ | 36 | address.h \ |
37 | addresseelist.h \ | 37 | addresseelist.h \ |
38 | formatfactory.h \ | 38 | formatfactory.h \ |
39 | formatplugin.h \ | 39 | formatplugin.h \ |
40 | phonenumber.h \ | 40 | phonenumber.h \ |
41 | distributionlist.h \ | 41 | distributionlist.h \ |
42 | distributionlistdialog.h \ | 42 | distributionlistdialog.h \ |
43 | distributionlisteditor.h \ | 43 | distributionlisteditor.h \ |
44 | vcardformatplugin.h \ | 44 | vcardformatplugin.h \ |
45 | formats/binaryformat.h \ | ||
46 | formats/vcardformatplugin2.h \ | 45 | formats/vcardformatplugin2.h \ |
47 | picture.h \ | 46 | picture.h \ |
48 | secrecy.h \ | 47 | secrecy.h \ |
49 | sound.h \ | 48 | sound.h \ |
50 | addressbook.h \ | 49 | addressbook.h \ |
51 | timezone.h \ | 50 | timezone.h \ |
52 | addressee.h \ | 51 | addressee.h \ |
53 | addresseedialog.h \ | 52 | addresseedialog.h \ |
54 | vcardconverter.h \ | 53 | vcardconverter.h \ |
55 | vcard21parser.h \ | 54 | vcard21parser.h \ |
56 | vcardformatimpl.h \ | 55 | vcardformatimpl.h \ |
57 | plugins/file/resourcefile.h \ | 56 | plugins/file/resourcefile.h \ |
58 | plugins/file/resourcefileconfig.h \ | 57 | plugins/file/resourcefileconfig.h \ |
59 | plugins/dir/resourcedir.h \ | 58 | plugins/dir/resourcedir.h \ |
60 | plugins/dir/resourcedirconfig.h \ | 59 | plugins/dir/resourcedirconfig.h \ |
61 | vcardparser/vcardline.h \ | 60 | vcardparser/vcardline.h \ |
62 | vcardparser/vcard.h \ | 61 | vcardparser/vcard.h \ |
63 | vcardparser/vcardtool.h \ | 62 | vcardparser/vcardtool.h \ |
64 | vcardparser/vcardparser.h \ | 63 | vcardparser/vcardparser.h \ |
65 | vcard/include/VCardAdrParam.h \ | 64 | vcard/include/VCardAdrParam.h \ |
66 | vcard/include/VCardAdrValue.h \ | 65 | vcard/include/VCardAdrValue.h \ |
67 | vcard/include/VCardAgentParam.h \ | 66 | vcard/include/VCardAgentParam.h \ |
68 | vcard/include/VCardContentLine.h \ | 67 | vcard/include/VCardContentLine.h \ |
69 | vcard/include/VCardDateParam.h \ | 68 | vcard/include/VCardDateParam.h \ |
70 | vcard/include/VCardDateValue.h \ | 69 | vcard/include/VCardDateValue.h \ |
71 | vcard/include/VCardEmailParam.h \ | 70 | vcard/include/VCardEmailParam.h \ |
72 | vcard/include/VCardGeoValue.h \ | 71 | vcard/include/VCardGeoValue.h \ |
73 | vcard/include/VCardGroup.h \ | 72 | vcard/include/VCardGroup.h \ |
74 | vcard/include/VCardImageParam.h \ | 73 | vcard/include/VCardImageParam.h \ |
75 | vcard/include/VCardImageValue.h \ | 74 | vcard/include/VCardImageValue.h \ |
76 | vcard/include/VCardLangValue.h \ | 75 | vcard/include/VCardLangValue.h \ |
77 | vcard/include/VCardNValue.h \ | 76 | vcard/include/VCardNValue.h \ |
78 | vcard/include/VCardParam.h \ | 77 | vcard/include/VCardParam.h \ |
79 | vcard/include/VCardPhoneNumberValue.h \ | 78 | vcard/include/VCardPhoneNumberValue.h \ |
80 | vcard/include/VCardSourceParam.h \ | 79 | vcard/include/VCardSourceParam.h \ |
81 | vcard/include/VCardTelParam.h \ | 80 | vcard/include/VCardTelParam.h \ |
82 | vcard/include/VCardTextParam.h \ | 81 | vcard/include/VCardTextParam.h \ |
83 | vcard/include/VCardTextNSParam.h \ | 82 | vcard/include/VCardTextNSParam.h \ |
84 | vcard/include/VCardTextValue.h \ | 83 | vcard/include/VCardTextValue.h \ |
85 | vcard/include/VCardTextBinParam.h \ | 84 | vcard/include/VCardTextBinParam.h \ |
86 | vcard/include/VCardURIValue.h \ | 85 | vcard/include/VCardURIValue.h \ |
87 | vcard/include/VCardVCard.h \ | 86 | vcard/include/VCardVCard.h \ |
88 | vcard/include/VCardEntity.h \ | 87 | vcard/include/VCardEntity.h \ |
89 | vcard/include/VCardValue.h \ | 88 | vcard/include/VCardValue.h \ |
90 | vcard/include/VCardSoundValue.h \ | 89 | vcard/include/VCardSoundValue.h \ |
91 | vcard/include/VCardAgentValue.h \ | 90 | vcard/include/VCardAgentValue.h \ |
92 | vcard/include/VCardTelValue.h \ | 91 | vcard/include/VCardTelValue.h \ |
93 | vcard/include/VCardTextBinValue.h \ | 92 | vcard/include/VCardTextBinValue.h \ |
94 | vcard/include/VCardOrgValue.h \ | 93 | vcard/include/VCardOrgValue.h \ |
95 | vcard/include/VCardUTCValue.h \ | 94 | vcard/include/VCardUTCValue.h \ |
96 | vcard/include/VCardClassValue.h \ | 95 | vcard/include/VCardClassValue.h \ |
97 | vcard/include/VCardFloatValue.h \ | 96 | vcard/include/VCardFloatValue.h \ |
98 | vcard/include/VCardTextListValue.h \ | 97 | vcard/include/VCardTextListValue.h \ |
99 | vcard/include/generated/AdrParam-generated.h \ | 98 | vcard/include/generated/AdrParam-generated.h \ |
100 | vcard/include/generated/AdrValue-generated.h \ | 99 | vcard/include/generated/AdrValue-generated.h \ |
101 | vcard/include/generated/AgentParam-generated.h \ | 100 | vcard/include/generated/AgentParam-generated.h \ |
102 | vcard/include/generated/ContentLine-generated.h \ | 101 | vcard/include/generated/ContentLine-generated.h \ |
103 | vcard/include/generated/DateParam-generated.h \ | 102 | vcard/include/generated/DateParam-generated.h \ |
104 | vcard/include/generated/DateValue-generated.h \ | 103 | vcard/include/generated/DateValue-generated.h \ |
105 | vcard/include/generated/EmailParam-generated.h \ | 104 | vcard/include/generated/EmailParam-generated.h \ |
106 | vcard/include/generated/GeoValue-generated.h \ | 105 | vcard/include/generated/GeoValue-generated.h \ |
107 | vcard/include/generated/Group-generated.h \ | 106 | vcard/include/generated/Group-generated.h \ |
108 | vcard/include/generated/ImageParam-generated.h \ | 107 | vcard/include/generated/ImageParam-generated.h \ |
109 | vcard/include/generated/ImageValue-generated.h \ | 108 | vcard/include/generated/ImageValue-generated.h \ |
110 | vcard/include/generated/LangValue-generated.h \ | 109 | vcard/include/generated/LangValue-generated.h \ |
111 | vcard/include/generated/NValue-generated.h \ | 110 | vcard/include/generated/NValue-generated.h \ |
112 | vcard/include/generated/Param-generated.h \ | 111 | vcard/include/generated/Param-generated.h \ |
113 | vcard/include/generated/PhoneNumberValue-generated.h \ | 112 | vcard/include/generated/PhoneNumberValue-generated.h \ |
114 | vcard/include/generated/SourceParam-generated.h \ | 113 | vcard/include/generated/SourceParam-generated.h \ |
115 | vcard/include/generated/TelParam-generated.h \ | 114 | vcard/include/generated/TelParam-generated.h \ |
116 | vcard/include/generated/TextParam-generated.h \ | 115 | vcard/include/generated/TextParam-generated.h \ |
117 | vcard/include/generated/TextNSParam-generated.h \ | 116 | vcard/include/generated/TextNSParam-generated.h \ |
118 | vcard/include/generated/TextValue-generated.h \ | 117 | vcard/include/generated/TextValue-generated.h \ |
119 | vcard/include/generated/TextBinParam-generated.h \ | 118 | vcard/include/generated/TextBinParam-generated.h \ |
120 | vcard/include/generated/URIValue-generated.h \ | 119 | vcard/include/generated/URIValue-generated.h \ |
121 | vcard/include/generated/VCard-generated.h \ | 120 | vcard/include/generated/VCard-generated.h \ |
122 | vcard/include/generated/VCardEntity-generated.h \ | 121 | vcard/include/generated/VCardEntity-generated.h \ |
123 | vcard/include/generated/Value-generated.h \ | 122 | vcard/include/generated/Value-generated.h \ |
124 | vcard/include/generated/SoundValue-generated.h \ | 123 | vcard/include/generated/SoundValue-generated.h \ |
125 | vcard/include/generated/AgentValue-generated.h \ | 124 | vcard/include/generated/AgentValue-generated.h \ |
126 | vcard/include/generated/TelValue-generated.h \ | 125 | vcard/include/generated/TelValue-generated.h \ |
127 | vcard/include/generated/TextBinValue-generated.h \ | 126 | vcard/include/generated/TextBinValue-generated.h \ |
128 | vcard/include/generated/OrgValue-generated.h \ | 127 | vcard/include/generated/OrgValue-generated.h \ |
129 | vcard/include/generated/UTCValue-generated.h \ | 128 | vcard/include/generated/UTCValue-generated.h \ |
130 | vcard/include/generated/ClassValue-generated.h \ | 129 | vcard/include/generated/ClassValue-generated.h \ |
131 | vcard/include/generated/FloatValue-generated.h \ | 130 | vcard/include/generated/FloatValue-generated.h \ |
132 | vcard/include/generated/TextListValue-generated.h | 131 | vcard/include/generated/TextListValue-generated.h |
133 | 132 | ||
134 | 133 | ||
135 | # plugins/ldap/resourceldap.h \ | 134 | # plugins/ldap/resourceldap.h \ |
136 | # plugins/ldap/resourceldapconfig.h \ | 135 | # plugins/ldap/resourceldapconfig.h \ |
136 | #formats/binary/binaryformat.h \ | ||
137 | 137 | ||
138 | 138 | ||
139 | SOURCES = \ | 139 | SOURCES = \ |
140 | distributionlist.cpp \ | 140 | distributionlist.cpp \ |
141 | distributionlistdialog.cpp \ | 141 | distributionlistdialog.cpp \ |
142 | distributionlisteditor.cpp \ | 142 | distributionlisteditor.cpp \ |
143 | vcardformatplugin.cpp \ | 143 | vcardformatplugin.cpp \ |
144 | formats/binaryformat.cpp \ | ||
145 | formats/vcardformatplugin2.cpp \ | 144 | formats/vcardformatplugin2.cpp \ |
146 | formatfactory.cpp \ | 145 | formatfactory.cpp \ |
147 | resource.cpp \ | 146 | resource.cpp \ |
148 | stdaddressbook.cpp \ | 147 | stdaddressbook.cpp \ |
149 | plugin.cpp \ | 148 | plugin.cpp \ |
150 | agent.cpp \ | 149 | agent.cpp \ |
151 | geo.cpp \ | 150 | geo.cpp \ |
152 | key.cpp \ | 151 | key.cpp \ |
153 | field.cpp \ | 152 | field.cpp \ |
154 | address.cpp \ | 153 | address.cpp \ |
155 | phonenumber.cpp \ | 154 | phonenumber.cpp \ |
156 | picture.cpp \ | 155 | picture.cpp \ |
157 | secrecy.cpp \ | 156 | secrecy.cpp \ |
158 | sound.cpp \ | 157 | sound.cpp \ |
159 | addressbook.cpp \ | 158 | addressbook.cpp \ |
160 | timezone.cpp \ | 159 | timezone.cpp \ |
161 | addressee.cpp \ | 160 | addressee.cpp \ |
162 | addresseelist.cpp \ | 161 | addresseelist.cpp \ |
163 | addresseedialog.cpp \ | 162 | addresseedialog.cpp \ |
164 | vcardconverter.cpp \ | 163 | vcardconverter.cpp \ |
165 | vcard21parser.cpp \ | 164 | vcard21parser.cpp \ |
166 | vcardformatimpl.cpp \ | 165 | vcardformatimpl.cpp \ |
167 | plugins/file/resourcefile.cpp \ | 166 | plugins/file/resourcefile.cpp \ |
168 | plugins/file/resourcefileconfig.cpp \ | 167 | plugins/file/resourcefileconfig.cpp \ |
169 | plugins/dir/resourcedir.cpp \ | 168 | plugins/dir/resourcedir.cpp \ |
170 | plugins/dir/resourcedirconfig.cpp \ | 169 | plugins/dir/resourcedirconfig.cpp \ |
171 | vcardparser/vcardline.cpp \ | 170 | vcardparser/vcardline.cpp \ |
172 | vcardparser/vcard.cpp \ | 171 | vcardparser/vcard.cpp \ |
173 | vcardparser/vcardtool.cpp \ | 172 | vcardparser/vcardtool.cpp \ |
174 | vcardparser/vcardparser.cpp \ | 173 | vcardparser/vcardparser.cpp \ |
175 | vcard/AdrParam.cpp \ | 174 | vcard/AdrParam.cpp \ |
176 | vcard/AdrValue.cpp \ | 175 | vcard/AdrValue.cpp \ |
177 | vcard/AgentParam.cpp \ | 176 | vcard/AgentParam.cpp \ |
178 | vcard/ContentLine.cpp \ | 177 | vcard/ContentLine.cpp \ |
179 | vcard/DateParam.cpp \ | 178 | vcard/DateParam.cpp \ |
180 | vcard/DateValue.cpp \ | 179 | vcard/DateValue.cpp \ |
181 | vcard/EmailParam.cpp \ | 180 | vcard/EmailParam.cpp \ |
182 | vcard/Entity.cpp \ | 181 | vcard/Entity.cpp \ |
183 | vcard/Enum.cpp \ | 182 | vcard/Enum.cpp \ |
184 | vcard/GeoValue.cpp \ | 183 | vcard/GeoValue.cpp \ |
185 | vcard/ImageParam.cpp \ | 184 | vcard/ImageParam.cpp \ |
186 | vcard/ImageValue.cpp \ | 185 | vcard/ImageValue.cpp \ |
187 | vcard/LangValue.cpp \ | 186 | vcard/LangValue.cpp \ |
188 | vcard/NValue.cpp \ | 187 | vcard/NValue.cpp \ |
189 | vcard/Param.cpp \ | 188 | vcard/Param.cpp \ |
190 | vcard/PhoneNumberValue.cpp \ | 189 | vcard/PhoneNumberValue.cpp \ |
191 | vcard/RToken.cpp \ | 190 | vcard/RToken.cpp \ |
192 | vcard/SourceParam.cpp \ | 191 | vcard/SourceParam.cpp \ |
193 | vcard/TelParam.cpp \ | 192 | vcard/TelParam.cpp \ |
194 | vcard/TextParam.cpp \ | 193 | vcard/TextParam.cpp \ |
195 | vcard/TextValue.cpp \ | 194 | vcard/TextValue.cpp \ |
196 | vcard/TextBinParam.cpp \ | 195 | vcard/TextBinParam.cpp \ |
197 | vcard/URIValue.cpp \ | 196 | vcard/URIValue.cpp \ |
198 | vcard/VCardv.cpp \ | 197 | vcard/VCardv.cpp \ |
199 | vcard/VCardEntity.cpp \ | 198 | vcard/VCardEntity.cpp \ |
200 | vcard/Value.cpp \ | 199 | vcard/Value.cpp \ |
201 | vcard/SoundValue.cpp \ | 200 | vcard/SoundValue.cpp \ |
202 | vcard/AgentValue.cpp \ | 201 | vcard/AgentValue.cpp \ |
203 | vcard/TelValue.cpp \ | 202 | vcard/TelValue.cpp \ |
204 | vcard/TextBinValue.cpp \ | 203 | vcard/TextBinValue.cpp \ |
205 | vcard/OrgValue.cpp \ | 204 | vcard/OrgValue.cpp \ |
206 | vcard/UTCValue.cpp \ | 205 | vcard/UTCValue.cpp \ |
207 | vcard/ClassValue.cpp \ | 206 | vcard/ClassValue.cpp \ |
208 | vcard/FloatValue.cpp \ | 207 | vcard/FloatValue.cpp \ |
209 | vcard/TextListValue.cpp | 208 | vcard/TextListValue.cpp |
210 | 209 | ||
211 | 210 | ||
212 | # plugins/ldap/resourceldap.cpp \ | 211 | # plugins/ldap/resourceldap.cpp \ |
213 | # plugins/ldap/resourceldapconfig.cpp \ | 212 | # plugins/ldap/resourceldapconfig.cpp \ |
214 | 213 | ||
214 | #formats/binary/binaryformat.cpp \ | ||
diff --git a/kabc/plugins/dir/dir.pro b/kabc/plugins/dir/dir.pro new file mode 100644 index 0000000..3db201f --- a/dev/null +++ b/kabc/plugins/dir/dir.pro | |||
@@ -0,0 +1,29 @@ | |||
1 | TEMPLATE= lib | ||
2 | CONFIG += qt warn_on release | ||
3 | #release debug | ||
4 | |||
5 | TARGET = microkabc_dir | ||
6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat | ||
7 | DESTDIR = ../../../bin | ||
8 | #LIBS += -lmicrokde -lmicrokabc | ||
9 | #LIBS += -L$(QPEDIR)/lib | ||
10 | |||
11 | INTERFACES = \ | ||
12 | |||
13 | HEADERS = \ | ||
14 | resourcedir.h \ | ||
15 | resourcedirconfig.h | ||
16 | |||
17 | SOURCES = \ | ||
18 | resourcedir.cpp \ | ||
19 | resourcedirconfig.cpp | ||
20 | |||
21 | unix : { | ||
22 | OBJECTS_DIR = obj/unix | ||
23 | MOC_DIR = moc/unix | ||
24 | } | ||
25 | win32: { | ||
26 | DEFINES += _WIN32_ | ||
27 | OBJECTS_DIR = obj/win | ||
28 | MOC_DIR = moc/win | ||
29 | } \ No newline at end of file | ||
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index be19821..6ea2f4b 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp | |||
@@ -71,288 +71,290 @@ extern "C" | |||
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
74 | ResourceDir::ResourceDir( const KConfig *config ) | 74 | ResourceDir::ResourceDir( const KConfig *config ) |
75 | : Resource( config ) | 75 | : Resource( config ) |
76 | { | 76 | { |
77 | QString path; | 77 | QString path; |
78 | 78 | ||
79 | KConfig *cfg = (KConfig *)config; | 79 | KConfig *cfg = (KConfig *)config; |
80 | if ( cfg ) { | 80 | if ( cfg ) { |
81 | //US path = config->readEntry( "FilePath" ); | 81 | //US path = config->readEntry( "FilePath" ); |
82 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); | 82 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); |
83 | //US mFormatName = config->readEntry( "FileFormat" ); | 83 | //US mFormatName = config->readEntry( "FileFormat" ); |
84 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); | 84 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); |
85 | } else { | 85 | } else { |
86 | path = StdAddressBook::directoryName(); | 86 | path = StdAddressBook::directoryName(); |
87 | mFormatName = "vcard"; | 87 | mFormatName = "vcard"; |
88 | } | 88 | } |
89 | 89 | ||
90 | 90 | ||
91 | FormatFactory *factory = FormatFactory::self(); | 91 | FormatFactory *factory = FormatFactory::self(); |
92 | mFormat = factory->format( mFormatName ); | 92 | mFormat = factory->format( mFormatName ); |
93 | 93 | ||
94 | if ( !mFormat ) { | 94 | if ( !mFormat ) { |
95 | mFormatName = "vcard"; | 95 | mFormatName = "vcard"; |
96 | mFormat = factory->format( mFormatName ); | 96 | mFormat = factory->format( mFormatName ); |
97 | } | 97 | } |
98 | 98 | ||
99 | /*US | 99 | /*US |
100 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); | 100 | //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); |
101 | if (mFormatName == "vcard") | 101 | if (mFormatName == "vcard") |
102 | mFormat = new VCardFormatPlugin2(); | 102 | mFormat = new VCardFormatPlugin2(); |
103 | else if (mFormatName == "binary") | 103 | else if (mFormatName == "binary") |
104 | mFormat = new BinaryFormat(); | 104 | mFormat = new BinaryFormat(); |
105 | else | 105 | else |
106 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); | 106 | qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); |
107 | */ | 107 | */ |
108 | 108 | ||
109 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods | 109 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods |
110 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); | 110 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); |
111 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); | 111 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); |
112 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); | 112 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); |
113 | */ | 113 | */ |
114 | 114 | ||
115 | setPath( path ); | 115 | setPath( path ); |
116 | } | 116 | } |
117 | 117 | ||
118 | ResourceDir::~ResourceDir() | 118 | ResourceDir::~ResourceDir() |
119 | { | 119 | { |
120 | delete mFormat; | 120 | delete mFormat; |
121 | mFormat = 0; | 121 | mFormat = 0; |
122 | } | 122 | } |
123 | 123 | ||
124 | void ResourceDir::writeConfig( KConfig *config ) | 124 | void ResourceDir::writeConfig( KConfig *config ) |
125 | { | 125 | { |
126 | Resource::writeConfig( config ); | 126 | Resource::writeConfig( config ); |
127 | 127 | ||
128 | config->writeEntry( "FilePath", mPath ); | 128 | config->writeEntry( "FilePath", mPath ); |
129 | config->writeEntry( "FileFormat", mFormatName ); | 129 | config->writeEntry( "FileFormat", mFormatName ); |
130 | } | 130 | } |
131 | 131 | ||
132 | Ticket *ResourceDir::requestSaveTicket() | 132 | Ticket *ResourceDir::requestSaveTicket() |
133 | { | 133 | { |
134 | kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; | 134 | kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; |
135 | 135 | ||
136 | if ( !addressBook() ) return 0; | 136 | if ( !addressBook() ) return 0; |
137 | 137 | ||
138 | if ( !lock( mPath ) ) { | 138 | if ( !lock( mPath ) ) { |
139 | kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" | 139 | kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" |
140 | << mPath << "'" << endl; | 140 | << mPath << "'" << endl; |
141 | return 0; | 141 | return 0; |
142 | } | 142 | } |
143 | return createTicket( this ); | 143 | return createTicket( this ); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | bool ResourceDir::doOpen() | 147 | bool ResourceDir::doOpen() |
148 | { | 148 | { |
149 | QDir dir( mPath ); | 149 | QDir dir( mPath ); |
150 | if ( !dir.exists() ) { // no directory available | 150 | if ( !dir.exists() ) { // no directory available |
151 | return dir.mkdir( dir.path() ); | 151 | return dir.mkdir( dir.path() ); |
152 | } else { | 152 | } else { |
153 | QString testName = dir.entryList( QDir::Files )[0]; | 153 | QString testName = dir.entryList( QDir::Files )[0]; |
154 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory | 154 | if ( testName.isNull() || testName.isEmpty() ) // no file in directory |
155 | return true; | 155 | return true; |
156 | 156 | ||
157 | QFile file( mPath + "/" + testName ); | 157 | QFile file( mPath + "/" + testName ); |
158 | if ( file.open( IO_ReadOnly ) ) | 158 | if ( file.open( IO_ReadOnly ) ) |
159 | return true; | 159 | return true; |
160 | 160 | ||
161 | if ( file.size() == 0 ) | 161 | if ( file.size() == 0 ) |
162 | return true; | 162 | return true; |
163 | 163 | ||
164 | bool ok = mFormat->checkFormat( &file ); | 164 | bool ok = mFormat->checkFormat( &file ); |
165 | file.close(); | 165 | file.close(); |
166 | return ok; | 166 | return ok; |
167 | } | 167 | } |
168 | } | 168 | } |
169 | 169 | ||
170 | void ResourceDir::doClose() | 170 | void ResourceDir::doClose() |
171 | { | 171 | { |
172 | } | 172 | } |
173 | 173 | ||
174 | bool ResourceDir::load() | 174 | bool ResourceDir::load() |
175 | { | 175 | { |
176 | kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; | 176 | kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; |
177 | 177 | ||
178 | QDir dir( mPath ); | 178 | QDir dir( mPath ); |
179 | QStringList files = dir.entryList( QDir::Files ); | 179 | QStringList files = dir.entryList( QDir::Files ); |
180 | 180 | ||
181 | QStringList::Iterator it; | 181 | QStringList::Iterator it; |
182 | bool ok = true; | 182 | bool ok = true; |
183 | for ( it = files.begin(); it != files.end(); ++it ) { | 183 | for ( it = files.begin(); it != files.end(); ++it ) { |
184 | QFile file( mPath + "/" + (*it) ); | 184 | QFile file( mPath + "/" + (*it) ); |
185 | 185 | ||
186 | if ( !file.open( IO_ReadOnly ) ) { | 186 | if ( !file.open( IO_ReadOnly ) ) { |
187 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); | 187 | addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); |
188 | ok = false; | 188 | ok = false; |
189 | continue; | 189 | continue; |
190 | } | 190 | } |
191 | 191 | ||
192 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) | 192 | if ( !mFormat->loadAll( addressBook(), this, &file ) ) |
193 | ok = false; | 193 | ok = false; |
194 | 194 | ||
195 | file.close(); | 195 | file.close(); |
196 | } | 196 | } |
197 | 197 | ||
198 | return ok; | 198 | return ok; |
199 | } | 199 | } |
200 | 200 | ||
201 | bool ResourceDir::save( Ticket *ticket ) | 201 | bool ResourceDir::save( Ticket *ticket ) |
202 | { | 202 | { |
203 | kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; | 203 | kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; |
204 | 204 | ||
205 | AddressBook::Iterator it; | 205 | AddressBook::Iterator it; |
206 | bool ok = true; | 206 | bool ok = true; |
207 | 207 | ||
208 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 208 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
209 | if ( (*it).resource() != this || !(*it).changed() ) | 209 | if ( (*it).resource() != this || !(*it).changed() ) |
210 | continue; | 210 | continue; |
211 | 211 | ||
212 | QFile file( mPath + "/" + (*it).uid() ); | 212 | QFile file( mPath + "/" + (*it).uid() ); |
213 | if ( !file.open( IO_WriteOnly ) ) { | 213 | if ( !file.open( IO_WriteOnly ) ) { |
214 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); | 214 | addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); |
215 | continue; | 215 | continue; |
216 | } | 216 | } |
217 | 217 | ||
218 | mFormat->save( *it, &file ); | 218 | mFormat->save( *it, &file ); |
219 | 219 | ||
220 | // mark as unchanged | 220 | // mark as unchanged |
221 | (*it).setChanged( false ); | 221 | (*it).setChanged( false ); |
222 | 222 | ||
223 | file.close(); | 223 | file.close(); |
224 | } | 224 | } |
225 | 225 | ||
226 | delete ticket; | 226 | delete ticket; |
227 | unlock( mPath ); | 227 | unlock( mPath ); |
228 | 228 | ||
229 | return ok; | 229 | return ok; |
230 | } | 230 | } |
231 | 231 | ||
232 | bool ResourceDir::lock( const QString &path ) | 232 | bool ResourceDir::lock( const QString &path ) |
233 | { | 233 | { |
234 | kdDebug(5700) << "ResourceDir::lock()" << endl; | 234 | kdDebug(5700) << "ResourceDir::lock()" << endl; |
235 | 235 | ||
236 | QString p = path; | 236 | QString p = path; |
237 | //US change the implementation how the lockfilename is getting created | 237 | //US change the implementation how the lockfilename is getting created |
238 | //US p.replace( QRegExp("/"), "_" ); | 238 | //US p.replace( QRegExp("/"), "_" ); |
239 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); | 239 | //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); |
240 | KURL url(p); | 240 | KURL url(p); |
241 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 241 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
242 | 242 | ||
243 | 243 | ||
244 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 244 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
245 | 245 | ||
246 | if ( QFile::exists( lockName ) ) return false; | 246 | if ( QFile::exists( lockName ) ) return false; |
247 | 247 | ||
248 | QString lockUniqueName; | 248 | QString lockUniqueName; |
249 | lockUniqueName = p + KApplication::randomString( 8 ); | 249 | lockUniqueName = p + KApplication::randomString( 8 ); |
250 | 250 | ||
251 | url = lockUniqueName; | 251 | url = lockUniqueName; |
252 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 252 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
253 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 253 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
254 | 254 | ||
255 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 255 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
256 | 256 | ||
257 | // Create unique file | 257 | // Create unique file |
258 | QFile file( mLockUniqueName ); | 258 | QFile file( mLockUniqueName ); |
259 | file.open( IO_WriteOnly ); | 259 | file.open( IO_WriteOnly ); |
260 | file.close(); | 260 | file.close(); |
261 | 261 | ||
262 | // Create lock file | 262 | // Create lock file |
263 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 263 | int result = 0; |
264 | #ifndef _WIN32_ | ||
265 | result = ::link( QFile::encodeName( mLockUniqueName ), | ||
264 | QFile::encodeName( lockName ) ); | 266 | QFile::encodeName( lockName ) ); |
265 | 267 | #endif | |
266 | if ( result == 0 ) { | 268 | if ( result == 0 ) { |
267 | addressBook()->emitAddressBookLocked(); | 269 | addressBook()->emitAddressBookLocked(); |
268 | return true; | 270 | return true; |
269 | } | 271 | } |
270 | 272 | ||
271 | // TODO: check stat | 273 | // TODO: check stat |
272 | 274 | ||
273 | return false; | 275 | return false; |
274 | } | 276 | } |
275 | 277 | ||
276 | void ResourceDir::unlock( const QString &path ) | 278 | void ResourceDir::unlock( const QString &path ) |
277 | { | 279 | { |
278 | QString p = path; | 280 | QString p = path; |
279 | //US change the implementation how the lockfilename is getting created | 281 | //US change the implementation how the lockfilename is getting created |
280 | //US p.replace( QRegExp( "/" ), "_" ); | 282 | //US p.replace( QRegExp( "/" ), "_" ); |
281 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); | 283 | //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); |
282 | KURL url(p); | 284 | KURL url(p); |
283 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 285 | QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
284 | 286 | ||
285 | ::unlink( QFile::encodeName( lockName ) ); | 287 | ::unlink( QFile::encodeName( lockName ) ); |
286 | QFile::remove( mLockUniqueName ); | 288 | QFile::remove( mLockUniqueName ); |
287 | addressBook()->emitAddressBookUnlocked(); | 289 | addressBook()->emitAddressBookUnlocked(); |
288 | } | 290 | } |
289 | 291 | ||
290 | void ResourceDir::setPath( const QString &path ) | 292 | void ResourceDir::setPath( const QString &path ) |
291 | { | 293 | { |
292 | /*US ToDo: no synchronization so far. Has to be changed in the future | 294 | /*US ToDo: no synchronization so far. Has to be changed in the future |
293 | mDirWatch.stopScan(); | 295 | mDirWatch.stopScan(); |
294 | mDirWatch.removeDir( mPath ); | 296 | mDirWatch.removeDir( mPath ); |
295 | */ | 297 | */ |
296 | mPath = path; | 298 | mPath = path; |
297 | 299 | ||
298 | /*US ToDo: no synchronization so far. Has to be changed in the future | 300 | /*US ToDo: no synchronization so far. Has to be changed in the future |
299 | mDirWatch.addDir( mPath, true ); | 301 | mDirWatch.addDir( mPath, true ); |
300 | mDirWatch.startScan(); | 302 | mDirWatch.startScan(); |
301 | */ | 303 | */ |
302 | 304 | ||
303 | //US simulate KDirWatch event | 305 | //US simulate KDirWatch event |
304 | pathChanged(); | 306 | pathChanged(); |
305 | 307 | ||
306 | } | 308 | } |
307 | 309 | ||
308 | QString ResourceDir::path() const | 310 | QString ResourceDir::path() const |
309 | { | 311 | { |
310 | return mPath; | 312 | return mPath; |
311 | } | 313 | } |
312 | 314 | ||
313 | void ResourceDir::setFormat( const QString &format ) | 315 | void ResourceDir::setFormat( const QString &format ) |
314 | { | 316 | { |
315 | mFormatName = format; | 317 | mFormatName = format; |
316 | 318 | ||
317 | if ( mFormat ) | 319 | if ( mFormat ) |
318 | delete mFormat; | 320 | delete mFormat; |
319 | 321 | ||
320 | FormatFactory *factory = FormatFactory::self(); | 322 | FormatFactory *factory = FormatFactory::self(); |
321 | mFormat = factory->format( mFormatName ); | 323 | mFormat = factory->format( mFormatName ); |
322 | /*US | 324 | /*US |
323 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); | 325 | qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); |
324 | if (mFormatName == "vcard") | 326 | if (mFormatName == "vcard") |
325 | mFormat = new VCardFormatPlugin2(); | 327 | mFormat = new VCardFormatPlugin2(); |
326 | else if (mFormatName == "binary") | 328 | else if (mFormatName == "binary") |
327 | mFormat = new BinaryFormat(); | 329 | mFormat = new BinaryFormat(); |
328 | else | 330 | else |
329 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); | 331 | qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); |
330 | */ | 332 | */ |
331 | 333 | ||
332 | } | 334 | } |
333 | 335 | ||
334 | QString ResourceDir::format() const | 336 | QString ResourceDir::format() const |
335 | { | 337 | { |
336 | return mFormatName; | 338 | return mFormatName; |
337 | } | 339 | } |
338 | 340 | ||
339 | void ResourceDir::pathChanged() | 341 | void ResourceDir::pathChanged() |
340 | { | 342 | { |
341 | if ( !addressBook() ) | 343 | if ( !addressBook() ) |
342 | return; | 344 | return; |
343 | 345 | ||
344 | load(); | 346 | load(); |
345 | addressBook()->emitAddressBookChanged(); | 347 | addressBook()->emitAddressBookChanged(); |
346 | } | 348 | } |
347 | 349 | ||
348 | void ResourceDir::removeAddressee( const Addressee& addr ) | 350 | void ResourceDir::removeAddressee( const Addressee& addr ) |
349 | { | 351 | { |
350 | QFile::remove( mPath + "/" + addr.uid() ); | 352 | QFile::remove( mPath + "/" + addr.uid() ); |
351 | } | 353 | } |
352 | 354 | ||
353 | void ResourceDir::cleanUp() | 355 | void ResourceDir::cleanUp() |
354 | { | 356 | { |
355 | unlock( mPath ); | 357 | unlock( mPath ); |
356 | } | 358 | } |
357 | 359 | ||
358 | //US #include "resourcedir.moc" | 360 | //US #include "resourcedir.moc" |
diff --git a/kabc/plugins/file/file.pro b/kabc/plugins/file/file.pro new file mode 100644 index 0000000..a5ade93 --- a/dev/null +++ b/kabc/plugins/file/file.pro | |||
@@ -0,0 +1,30 @@ | |||
1 | TEMPLATE= lib | ||
2 | CONFIG += qt warn_on release | ||
3 | #release debug | ||
4 | |||
5 | TARGET = microkabc_file | ||
6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat | ||
7 | |||
8 | DESTDIR = ../../../bin | ||
9 | #LIBS += -lmicrokde -lmicrokabc | ||
10 | #LIBS += -L$(QPEDIR)/lib | ||
11 | |||
12 | INTERFACES = \ | ||
13 | |||
14 | HEADERS = \ | ||
15 | resourcefile.h \ | ||
16 | resourcefileconfig.h | ||
17 | |||
18 | SOURCES = \ | ||
19 | resourcefile.cpp \ | ||
20 | resourcefileconfig.cpp | ||
21 | |||
22 | unix : { | ||
23 | OBJECTS_DIR = obj/unix | ||
24 | MOC_DIR = moc/unix | ||
25 | } | ||
26 | win32: { | ||
27 | DEFINES += _WIN32_ | ||
28 | OBJECTS_DIR = obj/win | ||
29 | MOC_DIR = moc/win | ||
30 | } \ No newline at end of file | ||
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 3920f69..4b4c935 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -97,293 +97,295 @@ ResourceFile::ResourceFile( const QString &fileName, | |||
97 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 97 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
98 | { | 98 | { |
99 | mFormatName = formatName; | 99 | mFormatName = formatName; |
100 | 100 | ||
101 | FormatFactory *factory = FormatFactory::self(); | 101 | FormatFactory *factory = FormatFactory::self(); |
102 | mFormat = factory->format( mFormatName ); | 102 | mFormat = factory->format( mFormatName ); |
103 | 103 | ||
104 | if ( !mFormat ) { | 104 | if ( !mFormat ) { |
105 | mFormatName = "vcard"; | 105 | mFormatName = "vcard"; |
106 | mFormat = factory->format( mFormatName ); | 106 | mFormat = factory->format( mFormatName ); |
107 | } | 107 | } |
108 | 108 | ||
109 | /*US | 109 | /*US |
110 | //US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); | 110 | //US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); |
111 | if (mFormatName == "vcard") { | 111 | if (mFormatName == "vcard") { |
112 | mFormat = new VCardFormatPlugin2(); | 112 | mFormat = new VCardFormatPlugin2(); |
113 | // qDebug("ResourceFile::init format VCardFormatPlugin2"); | 113 | // qDebug("ResourceFile::init format VCardFormatPlugin2"); |
114 | } | 114 | } |
115 | else if (mFormatName == "binary") { | 115 | else if (mFormatName == "binary") { |
116 | mFormat = new BinaryFormat(); | 116 | mFormat = new BinaryFormat(); |
117 | // qDebug("ResourceFile::init format BinaryFormat"); | 117 | // qDebug("ResourceFile::init format BinaryFormat"); |
118 | } | 118 | } |
119 | else | 119 | else |
120 | qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); | 120 | qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); |
121 | */ | 121 | */ |
122 | 122 | ||
123 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods | 123 | /*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods |
124 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 124 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
125 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 125 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
126 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 126 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
127 | */ | 127 | */ |
128 | 128 | ||
129 | setFileName( fileName ); | 129 | setFileName( fileName ); |
130 | } | 130 | } |
131 | 131 | ||
132 | ResourceFile::~ResourceFile() | 132 | ResourceFile::~ResourceFile() |
133 | { | 133 | { |
134 | delete mFormat; | 134 | delete mFormat; |
135 | mFormat = 0; | 135 | mFormat = 0; |
136 | } | 136 | } |
137 | 137 | ||
138 | void ResourceFile::writeConfig( KConfig *config ) | 138 | void ResourceFile::writeConfig( KConfig *config ) |
139 | { | 139 | { |
140 | Resource::writeConfig( config ); | 140 | Resource::writeConfig( config ); |
141 | 141 | ||
142 | config->writeEntry( "FileName", mFileName ); | 142 | config->writeEntry( "FileName", mFileName ); |
143 | config->writeEntry( "FileFormat", mFormatName ); | 143 | config->writeEntry( "FileFormat", mFormatName ); |
144 | 144 | ||
145 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 145 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
146 | 146 | ||
147 | } | 147 | } |
148 | 148 | ||
149 | Ticket *ResourceFile::requestSaveTicket() | 149 | Ticket *ResourceFile::requestSaveTicket() |
150 | { | 150 | { |
151 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 151 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
152 | 152 | ||
153 | if ( !addressBook() ) return 0; | 153 | if ( !addressBook() ) return 0; |
154 | 154 | ||
155 | if ( !lock( mFileName ) ) { | 155 | if ( !lock( mFileName ) ) { |
156 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" | 156 | kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" |
157 | << mFileName << "'" << endl; | 157 | << mFileName << "'" << endl; |
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | return createTicket( this ); | 160 | return createTicket( this ); |
161 | } | 161 | } |
162 | 162 | ||
163 | 163 | ||
164 | bool ResourceFile::doOpen() | 164 | bool ResourceFile::doOpen() |
165 | { | 165 | { |
166 | QFile file( mFileName ); | 166 | QFile file( mFileName ); |
167 | 167 | ||
168 | if ( !file.exists() ) { | 168 | if ( !file.exists() ) { |
169 | // try to create the file | 169 | // try to create the file |
170 | bool ok = file.open( IO_WriteOnly ); | 170 | bool ok = file.open( IO_WriteOnly ); |
171 | if ( ok ) | 171 | if ( ok ) |
172 | file.close(); | 172 | file.close(); |
173 | 173 | ||
174 | return ok; | 174 | return ok; |
175 | } else { | 175 | } else { |
176 | if ( !file.open( IO_ReadWrite ) ) | 176 | if ( !file.open( IO_ReadWrite ) ) |
177 | return false; | 177 | return false; |
178 | 178 | ||
179 | if ( file.size() == 0 ) { | 179 | if ( file.size() == 0 ) { |
180 | file.close(); | 180 | file.close(); |
181 | return true; | 181 | return true; |
182 | } | 182 | } |
183 | 183 | ||
184 | bool ok = mFormat->checkFormat( &file ); | 184 | bool ok = mFormat->checkFormat( &file ); |
185 | file.close(); | 185 | file.close(); |
186 | 186 | ||
187 | return ok; | 187 | return ok; |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | void ResourceFile::doClose() | 191 | void ResourceFile::doClose() |
192 | { | 192 | { |
193 | } | 193 | } |
194 | 194 | ||
195 | bool ResourceFile::load() | 195 | bool ResourceFile::load() |
196 | { | 196 | { |
197 | 197 | ||
198 | 198 | ||
199 | QFile file( mFileName ); | 199 | QFile file( mFileName ); |
200 | if ( !file.open( IO_ReadOnly ) ) { | 200 | if ( !file.open( IO_ReadOnly ) ) { |
201 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | 201 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); |
202 | return false; | 202 | return false; |
203 | } | 203 | } |
204 | 204 | ||
205 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 205 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
206 | 206 | ||
207 | return mFormat->loadAll( addressBook(), this, &file ); | 207 | return mFormat->loadAll( addressBook(), this, &file ); |
208 | } | 208 | } |
209 | 209 | ||
210 | bool ResourceFile::save( Ticket *ticket ) | 210 | bool ResourceFile::save( Ticket *ticket ) |
211 | { | 211 | { |
212 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 212 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
213 | 213 | ||
214 | 214 | ||
215 | // create backup file | 215 | // create backup file |
216 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 216 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
217 | 217 | ||
218 | /*US we use a simpler method to create a backupfile | 218 | /*US we use a simpler method to create a backupfile |
219 | 219 | ||
220 | (void) KSaveFile::backupFile( mFileName, QString::null | 220 | (void) KSaveFile::backupFile( mFileName, QString::null |
221 | ,extension ); | 221 | ,extension ); |
222 | 222 | ||
223 | KSaveFile saveFile( mFileName ); | 223 | KSaveFile saveFile( mFileName ); |
224 | bool ok = false; | 224 | bool ok = false; |
225 | if ( saveFile.status() == 0 && saveFile.file() ) | 225 | if ( saveFile.status() == 0 && saveFile.file() ) |
226 | { | 226 | { |
227 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 227 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
228 | ok = saveFile.close(); | 228 | ok = saveFile.close(); |
229 | } | 229 | } |
230 | */ | 230 | */ |
231 | 231 | ||
232 | //US ToDo: write backupfile | 232 | //US ToDo: write backupfile |
233 | QFile info; | 233 | QFile info; |
234 | info.setName( mFileName ); | 234 | info.setName( mFileName ); |
235 | bool ok = info.open( IO_WriteOnly ); | 235 | bool ok = info.open( IO_WriteOnly ); |
236 | if ( ok ) { | 236 | if ( ok ) { |
237 | mFormat->saveAll( addressBook(), this, &info ); | 237 | mFormat->saveAll( addressBook(), this, &info ); |
238 | 238 | ||
239 | info.close(); | 239 | info.close(); |
240 | ok = true; | 240 | ok = true; |
241 | } | 241 | } |
242 | else { | 242 | else { |
243 | 243 | ||
244 | } | 244 | } |
245 | 245 | ||
246 | if ( !ok ) | 246 | if ( !ok ) |
247 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 247 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
248 | 248 | ||
249 | delete ticket; | 249 | delete ticket; |
250 | unlock( mFileName ); | 250 | unlock( mFileName ); |
251 | 251 | ||
252 | return ok; | 252 | return ok; |
253 | 253 | ||
254 | qDebug("ResourceFile::save has to be changed"); | 254 | qDebug("ResourceFile::save has to be changed"); |
255 | return true; | 255 | return true; |
256 | } | 256 | } |
257 | 257 | ||
258 | bool ResourceFile::lock( const QString &fileName ) | 258 | bool ResourceFile::lock( const QString &fileName ) |
259 | { | 259 | { |
260 | 260 | ||
261 | 261 | ||
262 | QString fn = fileName; | 262 | QString fn = fileName; |
263 | 263 | ||
264 | //US change the implementation how the lockfilename is getting created | 264 | //US change the implementation how the lockfilename is getting created |
265 | //US fn.replace( QRegExp("/"), "_" ); | 265 | //US fn.replace( QRegExp("/"), "_" ); |
266 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 266 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
267 | 267 | ||
268 | KURL url(fn); | 268 | KURL url(fn); |
269 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 269 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
270 | 270 | ||
271 | 271 | ||
272 | 272 | ||
273 | if (QFile::exists( lockName )) return false; | 273 | if (QFile::exists( lockName )) return false; |
274 | 274 | ||
275 | QString lockUniqueName; | 275 | QString lockUniqueName; |
276 | lockUniqueName = fn + KApplication::randomString( 8 ); | 276 | lockUniqueName = fn + KApplication::randomString( 8 ); |
277 | 277 | ||
278 | url = lockUniqueName; | 278 | url = lockUniqueName; |
279 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 279 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
280 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 280 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
281 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 281 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
282 | 282 | ||
283 | // Create unique file | 283 | // Create unique file |
284 | QFile file( mLockUniqueName ); | 284 | QFile file( mLockUniqueName ); |
285 | file.open( IO_WriteOnly ); | 285 | file.open( IO_WriteOnly ); |
286 | file.close(); | 286 | file.close(); |
287 | 287 | ||
288 | // Create lock file | 288 | // Create lock file |
289 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 289 | int result = 0; |
290 | #ifndef _WIN32_ | ||
291 | result = ::link( QFile::encodeName( mLockUniqueName ), | ||
290 | QFile::encodeName( lockName ) ); | 292 | QFile::encodeName( lockName ) ); |
291 | 293 | #endif | |
292 | if ( result == 0 ) { | 294 | if ( result == 0 ) { |
293 | addressBook()->emitAddressBookLocked(); | 295 | addressBook()->emitAddressBookLocked(); |
294 | return true; | 296 | return true; |
295 | } | 297 | } |
296 | 298 | ||
297 | // TODO: check stat | 299 | // TODO: check stat |
298 | 300 | ||
299 | return false; | 301 | return false; |
300 | } | 302 | } |
301 | 303 | ||
302 | void ResourceFile::unlock( const QString &fileName ) | 304 | void ResourceFile::unlock( const QString &fileName ) |
303 | { | 305 | { |
304 | QString fn = fileName; | 306 | QString fn = fileName; |
305 | //US change the implementation how the lockfilename is getting created | 307 | //US change the implementation how the lockfilename is getting created |
306 | //US fn.replace( QRegExp( "/" ), "_" ); | 308 | //US fn.replace( QRegExp( "/" ), "_" ); |
307 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 309 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
308 | //US QString lockName = fn + ".lock"; | 310 | //US QString lockName = fn + ".lock"; |
309 | KURL url(fn); | 311 | KURL url(fn); |
310 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 312 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
311 | 313 | ||
312 | QFile::remove( lockName ); | 314 | QFile::remove( lockName ); |
313 | QFile::remove( mLockUniqueName ); | 315 | QFile::remove( mLockUniqueName ); |
314 | addressBook()->emitAddressBookUnlocked(); | 316 | addressBook()->emitAddressBookUnlocked(); |
315 | } | 317 | } |
316 | 318 | ||
317 | void ResourceFile::setFileName( const QString &fileName ) | 319 | void ResourceFile::setFileName( const QString &fileName ) |
318 | { | 320 | { |
319 | /*US ToDo: no synchronization so far. Has to be changed in the future | 321 | /*US ToDo: no synchronization so far. Has to be changed in the future |
320 | mDirWatch.stopScan(); | 322 | mDirWatch.stopScan(); |
321 | mDirWatch.removeFile( mFileName ); | 323 | mDirWatch.removeFile( mFileName ); |
322 | */ | 324 | */ |
323 | mFileName = fileName; | 325 | mFileName = fileName; |
324 | 326 | ||
325 | 327 | ||
326 | /*US ToDo: no synchronization so far. Has to be changed in the future | 328 | /*US ToDo: no synchronization so far. Has to be changed in the future |
327 | mDirWatch.addFile( mFileName ); | 329 | mDirWatch.addFile( mFileName ); |
328 | mDirWatch.startScan(); | 330 | mDirWatch.startScan(); |
329 | */ | 331 | */ |
330 | //US simulate KDirWatch event | 332 | //US simulate KDirWatch event |
331 | fileChanged(); | 333 | fileChanged(); |
332 | } | 334 | } |
333 | 335 | ||
334 | QString ResourceFile::fileName() const | 336 | QString ResourceFile::fileName() const |
335 | { | 337 | { |
336 | return mFileName; | 338 | return mFileName; |
337 | } | 339 | } |
338 | 340 | ||
339 | void ResourceFile::setFormat( const QString &format ) | 341 | void ResourceFile::setFormat( const QString &format ) |
340 | { | 342 | { |
341 | mFormatName = format; | 343 | mFormatName = format; |
342 | delete mFormat; | 344 | delete mFormat; |
343 | 345 | ||
344 | FormatFactory *factory = FormatFactory::self(); | 346 | FormatFactory *factory = FormatFactory::self(); |
345 | mFormat = factory->format( mFormatName ); | 347 | mFormat = factory->format( mFormatName ); |
346 | /*US | 348 | /*US |
347 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | 349 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); |
348 | if (mFormatName == "vcard") { | 350 | if (mFormatName == "vcard") { |
349 | mFormat = new VCardFormatPlugin2(); | 351 | mFormat = new VCardFormatPlugin2(); |
350 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 352 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
351 | } | 353 | } |
352 | else if (mFormatName == "binary") { | 354 | else if (mFormatName == "binary") { |
353 | mFormat = new BinaryFormat(); | 355 | mFormat = new BinaryFormat(); |
354 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 356 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
355 | } | 357 | } |
356 | else | 358 | else |
357 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | 359 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); |
358 | */ | 360 | */ |
359 | 361 | ||
360 | } | 362 | } |
361 | 363 | ||
362 | QString ResourceFile::format() const | 364 | QString ResourceFile::format() const |
363 | { | 365 | { |
364 | return mFormatName; | 366 | return mFormatName; |
365 | } | 367 | } |
366 | 368 | ||
367 | void ResourceFile::fileChanged() | 369 | void ResourceFile::fileChanged() |
368 | { | 370 | { |
369 | // There is a small theoretical chance that KDirWatch calls us before | 371 | // There is a small theoretical chance that KDirWatch calls us before |
370 | // we are fully constructed | 372 | // we are fully constructed |
371 | if (!addressBook()) | 373 | if (!addressBook()) |
372 | return; | 374 | return; |
373 | load(); | 375 | load(); |
374 | addressBook()->emitAddressBookChanged(); | 376 | addressBook()->emitAddressBookChanged(); |
375 | } | 377 | } |
376 | 378 | ||
377 | void ResourceFile::removeAddressee( const Addressee &addr ) | 379 | void ResourceFile::removeAddressee( const Addressee &addr ) |
378 | { | 380 | { |
379 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | 381 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); |
380 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | 382 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); |
381 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | 383 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); |
382 | } | 384 | } |
383 | 385 | ||
384 | void ResourceFile::cleanUp() | 386 | void ResourceFile::cleanUp() |
385 | { | 387 | { |
386 | unlock( mFileName ); | 388 | unlock( mFileName ); |
387 | } | 389 | } |
388 | 390 | ||
389 | //US #include "resourcefile.moc" | 391 | //US #include "resourcefile.moc" |