This forum has been archived. All content is frozen. Please use KDE Discuss instead.

kbookmarks

Tags: None
(comma "," separated)
K4m1K4tz3
Registered Member
Posts
35
Karma
0

kbookmarks

Mon Feb 02, 2009 2:57 pm
Hi,

first of all, I want to say that I'm new to KDE and Qt. But lets start with my problem.

I want to implement the bookmarks of Konqueror in my application. Maybe with a QTreeView? So the user can click on one of his bookmarks and this one is loaded. I searched in the API of KDE but now I have more questions than before.

So what is the easiest way to implement this? Any tipps?

Thanks.
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

RE: kbookmarks

Mon Feb 02, 2009 3:39 pm
A good starting point is the Bookmark manager class http://api.kde.org/4.x-api/kdelibs-apid ... nager.html

To get an instance managing the user's main bookmarks, you would do something like this
Code: Select all
KBookmarkManager* manager = KBookmarkManager::userBookmarksManager();


You can either iterate manually over the bookmarks it manages or use a http://api.kde.org/4.x-api/kdelibs-apid ... erser.html

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
K4m1K4tz3
Registered Member
Posts
35
Karma
0

RE: kbookmarks

Tue Feb 03, 2009 2:18 pm
First of all: thanks.

But how can I iterate? If I want to iterate, I will need a QList, won't I? How can I get such a list from KBookmarkManager? If I write

Code: Select all
KBookmarkGroup bookmarkGroup = bookmarkManager->root();
KBookmark bookmark = bookmarkGroup.first();
kDebug() << "Bookmark:" << bookmark.text();


I will get the Name of the first folder. But I also want to get whats inside.

I'm confused, sorry.
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

RE: kbookmarks

Tue Feb 03, 2009 9:59 pm
You can use the next() method or maybe even better the traverser.

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
K4m1K4tz3
Registered Member
Posts
35
Karma
0

RE: kbookmarks

Thu Feb 05, 2009 1:27 pm
Could you give me some example code for the traverser?
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

RE: kbookmarks

Thu Feb 05, 2009 2:42 pm
Sure :)

The Traverser is an implementation of the Visitor pattern.
Which means an instance if it is passed along the internal structure and "visits" all nodes.

To use this for your own purpose you need to create a subclass and implement the virtual methods (or in this case only those you want to handle)

Lets assume we want to print the "text" property of each node and have the intentation reflect the depth in the bookmark tree.
Code: Select all
class MyTraverser : public KBookmarkTraverser
{
protected:

virtual void visit (const KBookmark &bookmark)
{
    // print visited bookmark's text() with current offset
    qDebug() root() );


Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
K4m1K4tz3
Registered Member
Posts
35
Karma
0

RE: kbookmarks

Thu Feb 05, 2009 3:46 pm
Thanks. I have changed a little bit and now it works.

The first line has to be:
Code: Select all
class MyTraverser : public KBookmarkGroupTraverser


And I added:
Code: Select all
public:

using KBookmarkGroupTraverser::traverse;


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell