2 * This file is a part of QComicBook.
4 * Copyright (C) 2005-2006 Pawel Stolowski <yogin@linux.bydg.org>
6 * QComicBook is free software; you can redestribute it and/or modify it
7 * under terms of GNU General Public License by Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY. See GPL for more details.
13 #include "bookmarks.h"
14 #include "cbsettings.h"
15 #include <qpopupmenu.h>
18 #include <qtextstream.h>
20 using namespace QComicBook;
22 Bookmarks::Bookmarks(QPopupMenu *menu): bmenu(menu), changed(false)
24 blist.setAutoDelete(true);
25 fname = ComicBookSettings::bookmarksDir() + "/bookmarks";
28 Bookmarks::~Bookmarks()
32 bool Bookmarks::load()
37 if (f.open(IO_ReadOnly))
42 QString name = str.readLine();
45 int page = str.readLine().toInt();
53 bool Bookmarks::save()
61 if (f.open(IO_WriteOnly))
64 for (Bookmark *b = blist.first(); b; b = blist.next())
65 str << b->getName() << endl << b->getPage() << endl;
72 void Bookmarks::set(const QString &cbname, int page)
75 for (Bookmark *b = blist.first(); b; b = blist.next())
76 if ((b->getName() == cbname))
78 if (b->getPage() == page) //same page, do nothing
81 bmenu->removeItem(id);
85 id = bmenu->insertItem(b->menuItemName());
91 Bookmark *b = new Bookmark(cbname, page);
93 id = bmenu->insertItem(b->menuItemName());
100 bool Bookmarks::remove(const QString &cbname)
102 for (Bookmark *b = blist.first(); b; b = blist.next())
103 if ((b->getName() == cbname))
105 bmenu->removeItem(b->getId());
106 bmap.remove(b->getId());
113 bool Bookmarks::remove(int id)
115 if (bmap.contains(id))
117 Bookmark *b = bmap[id];
118 bmenu->removeItem(id);
125 bool Bookmarks::get(int id, Bookmark &b)
127 if (bmap.contains(id))
135 QValueList<Bookmark> Bookmarks::get()
137 QValueList<Bookmark> res;
138 for (Bookmark *b = blist.first(); b; b = blist.next())
143 bool Bookmarks::exists(const QString &cbname)
145 for (Bookmark *b = blist.first(); b; b = blist.next())
146 if (b->getName() == cbname)