1 /***************************************************************************
2 * Copyright (C) 2007 by Tarek Saidi *
3 * tarek.saidi@arcor.de *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; version 2 of the License. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
22 QList<KpxBookmarks::BookmarkEntry> KpxBookmarks::Bookmarks;
24 void KpxBookmarks::load(){
25 if (!config->settings.contains("Bookmarks/size") || config->settings.value("Bookmarks/size").toInt()==0)
28 int size = config->settings.value("Bookmarks/size").toInt();
29 for(int i=1;i<=size;i++){
31 entry.Title = config->settings.value( QString("Bookmarks/%1/Title").arg(i) ).toString();
32 entry.Path = config->settings.value( QString("Bookmarks/%1/Path").arg(i) ).toString();
33 if (!entry.Title.isNull() && !entry.Path.isNull())
38 int KpxBookmarks::count(){
39 return Bookmarks.size();
42 QString KpxBookmarks::title(int i){
43 return Bookmarks[i].Title;
46 QString KpxBookmarks::path(int i){
47 return Bookmarks[i].Path;
51 int KpxBookmarks::add(const QString& Title,const QString& Path){
55 entry.Index=Bookmarks.size();
58 return Bookmarks.size()-1;
61 void KpxBookmarks::save(){
62 for (int i=0;i<count();i++){
63 config->settings.setValue( QString("Bookmarks/%1/Title").arg(i+1), Bookmarks[i].Title );
64 config->settings.setValue( QString("Bookmarks/%1/Path").arg(i+1), Bookmarks[i].Path );
66 config->settings.setValue("Bookmarks/size", count());
68 // remove orphaned entries
70 while ( config->settings.contains( QString("Bookmarks/%1/Title").arg(i) ) ){
71 config->settings.remove( QString("Bookmarks/%1/Title").arg(i) );
72 config->settings.remove( QString("Bookmarks/%1/Path").arg(i) );
77 void KpxBookmarks::remove(int index){
78 Bookmarks.removeAt(index);
82 void KpxBookmarks::edit(const QString& Title,const QString& Path,int i){
83 Bookmarks[i].Title=Title;
84 Bookmarks[i].Path=Path;
89 void KpxBookmarks::resort(QList<int> order){
90 QList<BookmarkEntry> NewList;
91 for(int i=0;i<order.size();i++){
92 NewList << Bookmarks[order[i]];