1 /***************************************************************************
2 kcelbookmarkmanager.cpp - description
3 -------------------
4 begin : Sat Aug 31 2002
5 copyright : (C) 2002 by chris
6 email : chris@tux.teyssier.org
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include <qfile.h>
19 #include <qdir.h>
20 #include <kstandarddirs.h>
21 #include "kcelbookmarkmanager.h"
22
self()23 KBookmarkManager* KCelBookmarkManager::self() {
24 if ( !s_bookmarkManager )
25 {
26 QString bookmarksFile = locateLocal("data", QString::fromLatin1("celestia/bookmarks.xml"));
27 QFile local(bookmarksFile);
28 if (!local.exists()) {
29 QString bookmarksFileDefault = locate("data", QString::fromLatin1("celestia/bookmarks.xml"));
30 copy(bookmarksFileDefault, bookmarksFile);
31 QString faviconsDefault = locate("data", QString::fromLatin1("celestia/favicons/"));
32 QDir faviconsDir(faviconsDefault, "*.png");
33 QStringList iconsList = faviconsDir.entryList();
34 QString faviconsDest = locateLocal("cache", "favicons/");
35 for ( QStringList::Iterator i = iconsList.begin(); i != iconsList.end(); ++i ) {
36 copy(faviconsDefault + *i, faviconsDest + *i);
37 }
38 }
39 s_bookmarkManager = KBookmarkManager::managerForFile( bookmarksFile );
40 s_bookmarkManager->setShowNSBookmarks(false);
41 }
42 return s_bookmarkManager;
43 }
44
45
copy(const QString & source,const QString & destination)46 void KCelBookmarkManager::copy(const QString& source, const QString& destination) {
47 QFile src(source), dst(destination);
48 if (!src.exists()) return;
49
50 src.open(IO_ReadOnly);
51 dst.open(IO_WriteOnly);
52 int bufSize=16384;
53 char* buf = new char[bufSize];
54 int len = src.readBlock(buf, bufSize);
55 do {
56 dst.writeBlock(buf, len);
57 len = src.readBlock(buf, len);
58 } while (len > 0);
59 src.close();
60 dst.close();
61 delete[] buf;
62 }
63
64
65