• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • core
  • io
  • filesystem
externalbookmarkstorage.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 
24 #include "externalbookmarkstorage.h"
25 
26 // lib
27 #include "bytearraydocument.h"
28 // Okteta core
29 #include <bookmarkable.h>
30 #include <bookmarksconstiterator.h>
31 #include <bookmark.h>
32 #include <abstractbytearraymodel.h>
33 // KDE
34 #include <KStandardDirs>
35 #include <KBookmarkManager>
36 #include <KBookmarkGroup>
37 
38 
39 namespace Kasten2
40 {
41 
42 ExternalBookmarkStorage::ExternalBookmarkStorage()
43 {
44  const QString bookmarksFileName =
45  KStandardDirs::locateLocal( "data", QLatin1String("okteta/bookmarks.xml") );
46  mBookmarkManager = KBookmarkManager::managerForFile( bookmarksFileName, QLatin1String("okteta") );
47 }
48 
49 
50 void ExternalBookmarkStorage::readBookmarks( ByteArrayDocument* document, const KUrl& url )
51 {
52  Okteta::AbstractByteArrayModel* byteArray = document->content();
53  Okteta::Bookmarkable* bookmarkable = qobject_cast<Okteta::Bookmarkable*>( byteArray );
54 
55  bookmarkable->removeAllBookmarks();
56 
57  const QString urlString = url.isLocalFile() ? url.path() : url.prettyUrl();
58 
59  KBookmarkGroup root = mBookmarkManager->root();
60 
61  for( KBookmark bm = root.first(); ! bm.isNull(); bm = root.next(bm) )
62  {
63  if( bm.isSeparator() || ! bm.isGroup() )
64  continue;
65 
66  if( bm.fullText() == urlString )
67  {
68  KBookmarkGroup bmGroup = bm.toGroup();
69 
70  QList<Okteta::Bookmark> bookmarksToBeCreated;
71  Okteta::Bookmark bookmark;
72  for( bm = bmGroup.first(); ! bm.isNull(); bm = bmGroup.next(bm) )
73  {
74  if( bm.isSeparator() || bm.isGroup() )
75  continue;
76 
77  bookmark.setOffset( bm.url().htmlRef().toULongLong() );
78  bookmark.setName( bm.fullText() );
79 
80  bookmarksToBeCreated.append( bookmark );
81  }
82 
83  bookmarkable->addBookmarks( bookmarksToBeCreated );
84 
85  break;
86  }
87  }
88 }
89 
90 void ExternalBookmarkStorage::writeBookmarks( ByteArrayDocument* document, const KUrl& url )
91 {
92  Okteta::AbstractByteArrayModel* byteArray = document->content();
93  Okteta::Bookmarkable* bookmarkable = qobject_cast<Okteta::Bookmarkable*>( byteArray );
94 
95  if( ! bookmarkable )
96  return;
97 
98  const QString urlString = url.isLocalFile() ? url.path() : url.prettyUrl();
99 
100  KBookmarkGroup root = mBookmarkManager->root();
101 
102  // rm old bookmarkable
103  KBookmark bm = root.first();
104  while( ! bm.isNull() )
105  {
106  if( bm.isSeparator() || ! bm.isGroup() )
107  continue;
108 
109  if( bm.fullText() == urlString )
110  {
111  root.deleteBookmark( bm );
112  break;
113  }
114 
115  bm = root.next( bm );
116  }
117 
118  // store current bookmarks
119  KBookmarkGroup bookmarkGroup = root.createNewFolder( urlString );
120  Okteta::BookmarksConstIterator bit = bookmarkable->createBookmarksConstIterator();
121  while( bit.hasNext() )
122  {
123  const Okteta::Bookmark& bookmark = bit.next();
124  KUrl bookmarkUrl = url;
125  bookmarkUrl.setHTMLRef( QString::number(bookmark.offset()) );
126  bookmarkGroup.addBookmark( bookmark.name(), bookmarkUrl, QString() );
127  }
128 
129  mBookmarkManager->save( false );
130 }
131 
132 ExternalBookmarkStorage::~ExternalBookmarkStorage() {}
133 
134 }
Okteta::AbstractByteArrayModel
could it be useful to hide the data access behind an iterator? * class KDataBufferIterator { public: ...
Definition: abstractbytearraymodel.h:79
abstractbytearraymodel.h
bookmark.h
Okteta::Bookmark::offset
Address offset() const
Definition: bookmark.h:66
Okteta::Bookmark
Definition: bookmark.h:38
Okteta::Bookmark::name
QString name() const
Definition: bookmark.h:67
Kasten2::ExternalBookmarkStorage::writeBookmarks
void writeBookmarks(ByteArrayDocument *document, const KUrl &url)
Definition: externalbookmarkstorage.cpp:90
Kasten2::ExternalBookmarkStorage::ExternalBookmarkStorage
ExternalBookmarkStorage()
Definition: externalbookmarkstorage.cpp:42
Okteta::Bookmark::setOffset
void setOffset(Address offset)
Definition: bookmark.h:71
Okteta::Bookmarkable::addBookmarks
virtual void addBookmarks(const QList< Okteta::Bookmark > &bookmarks)=0
Okteta::Bookmarkable
Definition: bookmarkable.h:39
Okteta::Bookmarkable::createBookmarksConstIterator
virtual Okteta::BookmarksConstIterator createBookmarksConstIterator() const =0
Kasten2::ExternalBookmarkStorage::~ExternalBookmarkStorage
~ExternalBookmarkStorage()
Definition: externalbookmarkstorage.cpp:132
Okteta::BookmarksConstIterator
Definition: bookmarksconstiterator.h:36
Okteta::Bookmarkable::removeAllBookmarks
virtual void removeAllBookmarks()=0
bookmarksconstiterator.h
Kasten2::ExternalBookmarkStorage::mBookmarkManager
KBookmarkManager * mBookmarkManager
Definition: externalbookmarkstorage.h:46
externalbookmarkstorage.h
Kasten2::ByteArrayDocument::content
virtual Okteta::AbstractByteArrayModel * content() const
Definition: bytearraydocument.cpp:61
Okteta::BookmarksConstIterator::next
const Okteta::Bookmark & next()
Definition: bookmarksconstiterator.h:78
Kasten2::ExternalBookmarkStorage::readBookmarks
void readBookmarks(ByteArrayDocument *document, const KUrl &url)
Definition: externalbookmarkstorage.cpp:50
Okteta::BookmarksConstIterator::hasNext
bool hasNext() const
Definition: bookmarksconstiterator.h:69
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
bytearraydocument.h
Okteta::Bookmark::setName
void setName(const QString &name)
Definition: bookmark.h:70
bookmarkable.h
QList
Definition: bookmarkable.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal