You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
4.1 KiB
107 lines
4.1 KiB
15 years ago
|
/*=========================================================================
|
||
|
| KABCDAV
|
||
|
|--------------------------------------------------------------------------
|
||
|
| (c) 2010 Timothy Pearson
|
||
|
|
|
||
|
| This project is released under the GNU General Public License.
|
||
|
| Please see the file COPYING for more details.
|
||
|
|--------------------------------------------------------------------------
|
||
|
| Remote address book writing class.
|
||
|
========================================================================*/
|
||
|
|
||
|
/*=========================================================================
|
||
|
| INCLUDES
|
||
|
========================================================================*/
|
||
|
|
||
|
#include "writer.h"
|
||
|
#include <kdebug.h>
|
||
|
#include <string>
|
||
|
|
||
|
/*=========================================================================
|
||
|
| DEFINES
|
||
|
========================================================================*/
|
||
|
|
||
|
// Use carddav_modify_object() function.
|
||
|
// If it's not set, a pair of carddav_delete_object/carddav_add_object
|
||
|
// is used for modifying objects.
|
||
15 years ago
|
// It's done, because, for some reason, Zimbra returns an error
|
||
|
// on carddav_modify_object.
|
||
|
//#define USE_CARDDAV_MODIFY
|
||
15 years ago
|
|
||
|
/*=========================================================================
|
||
|
| NAMESPACE
|
||
|
========================================================================*/
|
||
|
|
||
|
using namespace KABC;
|
||
|
|
||
|
/*=========================================================================
|
||
|
| METHODS
|
||
|
========================================================================*/
|
||
|
|
||
|
void CardDavWriter::cleanJob() {
|
||
|
CardDavJob::cleanJob();
|
||
|
}
|
||
|
|
||
|
int CardDavWriter::runJob(runtime_info* RT) {
|
||
|
kdDebug() << "writer::run, url: " << url() << "\n";
|
||
|
|
||
|
int res = OK;
|
||
|
|
||
13 years ago
|
kdDebug() << "pushing added objects" << '\n';
|
||
15 years ago
|
res = pushObjects(mAdded, carddav_add_object, OK, RT);
|
||
|
if (OK == res) {
|
||
|
#ifdef USE_CARDDAV_MODIFY
|
||
13 years ago
|
kdDebug() << "pushing changed objects" << '\n';
|
||
15 years ago
|
if (getUseURI() == false)
|
||
|
res = pushObjects(mChanged, carddav_modify_object, OK, RT);
|
||
|
else
|
||
|
res = pushObjects(mChanged, carddav_modify_object_by_uri, OK, RT);
|
||
15 years ago
|
if (OK == res) {
|
||
13 years ago
|
kdDebug() << "pushing deleted objects" << '\n';
|
||
14 years ago
|
while (mDeleted.contains("BEGIN:VCARD", TRUE) > 0) {
|
||
|
int endLocation = mDeleted.find("END:VCARD", 0, TRUE);
|
||
14 years ago
|
TQString deletedCurSeq = mDeleted.mid(0, endLocation+9);
|
||
|
mDeleted = mDeleted.remove(0, endLocation+9);
|
||
|
if (getUseURI() == false)
|
||
|
res = pushObjects(deletedCurSeq, carddav_delete_object, OK, RT);
|
||
|
else
|
||
|
res = pushObjects(deletedCurSeq, carddav_delete_object_by_uri, OK, RT);
|
||
|
}
|
||
15 years ago
|
}
|
||
|
#else // if USE_CARDDAV_MODIFY
|
||
13 years ago
|
kdDebug() << "pushing changed objects (delete)" << '\n';
|
||
15 years ago
|
if (getUseURI() == false)
|
||
|
res = pushObjects(mChanged, carddav_delete_object, OK, RT);
|
||
|
else
|
||
|
res = pushObjects(mChanged, carddav_delete_object_by_uri, OK, RT);
|
||
15 years ago
|
if (OK == res) {
|
||
13 years ago
|
kdDebug() << "pushing changed objects (add)" << '\n';
|
||
15 years ago
|
if (getUseURI() == false)
|
||
|
res = pushObjects(mChanged, carddav_add_object, OK, RT);
|
||
|
else
|
||
|
res = pushObjects(mChanged, carddav_add_object, OK, RT);
|
||
15 years ago
|
if (OK == res) {
|
||
13 years ago
|
kdDebug() << "pushing deleted objects" << '\n';
|
||
14 years ago
|
while (mDeleted.contains("BEGIN:VCARD", TRUE) > 0) {
|
||
|
int endLocation = mDeleted.find("END:VCARD", 0, TRUE);
|
||
14 years ago
|
TQString deletedCurSeq = mDeleted.mid(0, endLocation+9);
|
||
|
mDeleted = mDeleted.remove(0, endLocation+9);
|
||
|
if (getUseURI() == false)
|
||
|
res = pushObjects(deletedCurSeq, carddav_delete_object, OK, RT);
|
||
|
else
|
||
|
res = pushObjects(deletedCurSeq, carddav_delete_object_by_uri, OK, RT);
|
||
|
}
|
||
15 years ago
|
}
|
||
|
}
|
||
|
#endif // if USE_CARDDAV_MODIFY
|
||
|
}
|
||
|
|
||
|
if (OK != res) {
|
||
|
clearObjects();
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
// EOF ========================================================================
|