summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (show whitespace changes)
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp66
1 files changed, 41 insertions, 25 deletions
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index 48b7d91..7069f5d 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -81,6 +81,16 @@ ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
81 81
82void ResourceSharpDTM::init( const QString &fileName ) 82void ResourceSharpDTM::init( const QString &fileName )
83{ 83{
84 if (mConverter == 0) {
85 mConverter = new SharpDTMConverter();
86 bool res = mConverter->init();
87 if ( !res )
88 {
89 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
90 qDebug(msg);
91 return;
92 }
93 }
84 setFileName( fileName ); 94 setFileName( fileName );
85} 95}
86 96
@@ -110,30 +120,8 @@ Ticket *ResourceSharpDTM::requestSaveTicket()
110 120
111bool ResourceSharpDTM::doOpen() 121bool ResourceSharpDTM::doOpen()
112{ 122{
113 qDebug("%xResourceSharpDTM::doOpen: %s", this,fileName().latin1()); 123 if (!mConverter)
114
115 if ( ! mAccess ) {
116 // the last parameter in the SlZDataBase constructor means "readonly"
117 mAccess = new SlZDataBase(fileName(),
118 SlZDataBase::addressbookItems(),
119 NULL, false);
120 }
121 if ( !mAccess ) {
122 qDebug("Unable to load file() %s", fileName().latin1());
123 return false; 124 return false;
124 }
125 if (mConverter == 0) {
126 mConverter = new SharpDTMConverter();
127 bool res = mConverter->init();
128 if ( !res )
129 {
130 QString msg("Unable to initialize sharp converter. Most likely a problem with the category file");
131 qDebug(msg);
132 delete mAccess;
133 mAccess = 0;
134 return false;
135 }
136 }
137 return true; 125 return true;
138} 126}
139 127
@@ -144,6 +132,17 @@ void ResourceSharpDTM::doClose()
144 132
145bool ResourceSharpDTM::load() 133bool ResourceSharpDTM::load()
146{ 134{
135 if (!mConverter)
136 return false;
137 QString fileN = SlZDataBase::addressbookFileName();
138 if ( ! mAccess ) {
139 mAccess = new SlZDataBase(fileN,
140 SlZDataBase::addressbookItems(),
141 0, false);
142 }
143 if(mAccess == 0)
144 return false;
145
147 qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1()); 146 qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1());
148 bool res = false; 147 bool res = false;
149 CardId id; 148 CardId id;
@@ -158,11 +157,25 @@ bool ResourceSharpDTM::load()
158 addressBook()->insertAddressee( addressee ); 157 addressBook()->insertAddressee( addressee );
159 } 158 }
160 } 159 }
160 if(mAccess != 0)
161 delete mAccess;
162 mAccess = 0;
163
161 return true; 164 return true;
162} 165}
163 166
164bool ResourceSharpDTM::save( Ticket *ticket ) 167bool ResourceSharpDTM::save( Ticket *ticket )
165{ 168{
169 if (!mConverter)
170 return false;
171 QString fileN = SlZDataBase::addressbookFileName();
172 if ( ! mAccess ) {
173 mAccess = new SlZDataBase(fileN,
174 SlZDataBase::addressbookItems(),
175 0, false);
176 }
177 if(mAccess == 0)
178 return false;
166 qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); 179 qDebug("ResourceSharpDTM::save: %s", fileName().latin1());
167 KABC::AddressBook::Iterator it; 180 KABC::AddressBook::Iterator it;
168 bool res; 181 bool res;
@@ -249,12 +262,15 @@ bool ResourceSharpDTM::save( Ticket *ticket )
249 } 262 }
250 } 263 }
251 delete ticket; 264 delete ticket;
252 265 if(mAccess != 0)
266 delete mAccess;
267 mAccess = 0;
253 return true; 268 return true;
254} 269}
255 270
256bool ResourceSharpDTM::lock( const QString &lockfileName ) 271bool ResourceSharpDTM::lock( const QString &lockfileName )
257{ 272{
273 return true;
258} 274}
259 275
260void ResourceSharpDTM::unlock( const QString &fileName ) 276void ResourceSharpDTM::unlock( const QString &fileName )
@@ -278,7 +294,7 @@ void ResourceSharpDTM::removeAddressee( const Addressee &addr )
278 294
279void ResourceSharpDTM::cleanUp() 295void ResourceSharpDTM::cleanUp()
280{ 296{
281 unlock( fileName() ); 297
282} 298}
283 299
284 300