bookmarksyncee.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <kdebug.h>
00023
00024 #include <kbookmarkmanager.h>
00025
00026 #include "bookmarksyncee.h"
00027
00028 using namespace KSync;
00029
00030 BookmarkSyncEntry::BookmarkSyncEntry( KBookmark bm, Syncee *parent )
00031 : SyncEntry( parent ), mBookmark( bm )
00032 {
00033 }
00034
00035 QString BookmarkSyncEntry::type() const
00036 {
00037 return "BookmarkSyncEntry";
00038 }
00039
00040 QString BookmarkSyncEntry::name()
00041 {
00042 return mBookmark.text();
00043 }
00044
00045 QString BookmarkSyncEntry::id()
00046 {
00047 return mBookmark.url().url();
00048 }
00049
00050 QString BookmarkSyncEntry::timestamp()
00051 {
00052 return mBookmark.text() + mBookmark.url().url();
00053 }
00054
00055 bool BookmarkSyncEntry::equals( SyncEntry *entry )
00056 {
00057 BookmarkSyncEntry *bmEntry = dynamic_cast<BookmarkSyncEntry *>(entry);
00058 if (!bmEntry) {
00059 kdDebug() << "BookmarkSyncee::addEntry(): Wrong type." << endl;
00060 return false;
00061 }
00062
00063 KBookmark bm = bmEntry->bookmark();
00064
00065 kdDebug() << "equals: '" << mBookmark.fullText() << "' <-> '"
00066 << bm.fullText() << "'" << endl;
00067
00068 if ( mBookmark.fullText() != bmEntry->bookmark().fullText() ) return false;
00069 if ( mBookmark.url() != bmEntry->bookmark().url() ) return false;
00070
00071
00072 return true;
00073 }
00074
00075 BookmarkSyncEntry *BookmarkSyncEntry::clone()
00076 {
00077 return new BookmarkSyncEntry( *this );
00078 }
00079
00080
00081 BookmarkSyncee::BookmarkSyncee()
00082 {
00083 mBookmarkManager = 0;
00084 mOwnBookmarkManager = true;
00085
00086 init();
00087 }
00088
00089 BookmarkSyncee::BookmarkSyncee( KBookmarkManager *bmm )
00090 {
00091 mBookmarkManager = bmm;
00092 mOwnBookmarkManager = false;
00093
00094 init();
00095 }
00096
00097 BookmarkSyncee::~BookmarkSyncee()
00098 {
00099 if ( mOwnBookmarkManager ) delete mBookmarkManager;
00100 }
00101
00102 void BookmarkSyncee::init()
00103 {
00104 mEntries.setAutoDelete( true );
00105
00106 mBookmarks.clear();
00107
00108 listGroup( mBookmarkManager->root() );
00109
00110 mBookmarkIterator = mBookmarks.begin();
00111 }
00112
00113 void BookmarkSyncee::listGroup( KBookmarkGroup group )
00114 {
00115 for( KBookmark bm = group.first(); !bm.isNull(); bm = group.next( bm ) ) {
00116 if ( bm.isGroup() ) {
00117 listGroup( bm.toGroup() );
00118 } else if ( bm.isSeparator() ) {
00119
00120 } else {
00121 kdDebug() << "appending '" << bm.text() << "' ("
00122 << bm.parentGroup().fullText() << ")" << endl;
00123 mBookmarks.append( bm.internalElement() );
00124 }
00125 }
00126 }
00127
00128 BookmarkSyncEntry *BookmarkSyncee::firstEntry()
00129 {
00130 mBookmarkIterator = mBookmarks.begin();
00131 return createEntry( KBookmark( *mBookmarkIterator ) );
00132 }
00133
00134 BookmarkSyncEntry *BookmarkSyncee::nextEntry()
00135 {
00136 return createEntry( KBookmark( *( ++mBookmarkIterator ) ) );
00137 }
00138
00139 #if 0
00140 BookmarkSyncEntry *BookmarkSyncee::findEntry( const QString &id )
00141 {
00142 QValueList<QDomElement>::Iterator bmIt = mBookmarks.begin();
00143 while ( bmIt != mBookmarks.end() ) {
00144 if ( KBookmark( *bmIt ).url().url() == id ) {
00145 return createEntry( KBookmark( *bmIt ) );
00146 }
00147 ++bmIt;
00148 }
00149
00150 return 0;
00151 }
00152 #endif
00153
00154 void BookmarkSyncee::addEntry( SyncEntry *entry )
00155 {
00156 BookmarkSyncEntry *bmEntry = dynamic_cast<BookmarkSyncEntry *>( entry );
00157 if ( !bmEntry ) {
00158 kdDebug() << "BookmarkSyncee::addEntry(): Wrong type." << endl;
00159 } else {
00160 KBookmark bm = bmEntry->bookmark();
00161 KBookmarkGroup bmGroup = findGroup( bm.parentGroup() );
00162 KBookmark newBookmark = bmGroup.addBookmark( mBookmarkManager,
00163 bm.fullText(), bm.url() );
00164 mBookmarks.append( newBookmark.internalElement() );
00165 }
00166 }
00167
00168 void BookmarkSyncee::removeEntry( SyncEntry *entry )
00169 {
00170 BookmarkSyncEntry *bmEntry = dynamic_cast<BookmarkSyncEntry *>( entry );
00171 if ( !bmEntry ) {
00172 kdDebug() << "BookmarkSyncee::addEntry(): Wrong type." << endl;
00173 } else {
00174 KBookmark bm = bmEntry->bookmark();
00175 kdDebug() << "Remove " << bm.text() << endl;
00176
00177
00178
00179
00180
00181
00182 }
00183 }
00184
00185 KBookmarkGroup BookmarkSyncee::findGroup( KBookmarkGroup group )
00186 {
00187 if ( group.fullText().isEmpty() ) return mBookmarkManager->root();
00188
00189 QValueList<QDomElement>::Iterator bmIt = mBookmarks.begin();
00190 while ( bmIt != mBookmarks.end() ) {
00191 KBookmark bm( *bmIt );
00192 if ( bm.isGroup() && ( bm.fullText() == group.fullText() ) ) {
00193 return bm.toGroup();
00194 }
00195 ++bmIt;
00196 }
00197 KBookmarkGroup newGroup =
00198 mBookmarkManager->root().createNewFolder( mBookmarkManager,
00199 group.fullText() );
00200 mBookmarks.append( newGroup.internalElement() );
00201
00202 return newGroup;
00203 }
00204
00205 BookmarkSyncEntry *BookmarkSyncee::createEntry( KBookmark bm )
00206 {
00207 if ( !bm.isNull() ) {
00208 BookmarkSyncEntry *entry = new BookmarkSyncEntry( bm, this );
00209 mEntries.append( entry );
00210 return entry;
00211 } else {
00212 return 0;
00213 }
00214 }
00215
00216 bool BookmarkSyncee::writeBackup( const QString & )
00217 {
00218 return false;
00219 }
00220
00221 bool BookmarkSyncee::restoreBackup( const QString & )
00222 {
00223 return false;
00224 }
This file is part of the documentation for kitchensync Library Version 3.3.2.