00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <qfile.h>
00019 #include <qdir.h>
00020 #include <kstandarddirs.h>
00021 #include "kcelbookmarkmanager.h"
00022
00023 KBookmarkManager* KCelBookmarkManager::self() {
00024 if ( !s_bookmarkManager )
00025 {
00026 QString bookmarksFile = locateLocal("data", QString::fromLatin1("celestia/bookmarks.xml"));
00027 QFile local(bookmarksFile);
00028 if (!local.exists()) {
00029 QString bookmarksFileDefault = locate("data", QString::fromLatin1("celestia/bookmarks.xml"));
00030 copy(bookmarksFileDefault, bookmarksFile);
00031 QString faviconsDefault = locate("data", QString::fromLatin1("celestia/favicons/"));
00032 QDir faviconsDir(faviconsDefault, "*.png");
00033 QStringList iconsList = faviconsDir.entryList();
00034 QString faviconsDest = locateLocal("cache", "favicons/");
00035 for ( QStringList::Iterator i = iconsList.begin(); i != iconsList.end(); ++i ) {
00036 copy(faviconsDefault + *i, faviconsDest + *i);
00037 }
00038 }
00039 s_bookmarkManager = KBookmarkManager::managerForFile( bookmarksFile );
00040 s_bookmarkManager->setShowNSBookmarks(false);
00041 }
00042 return s_bookmarkManager;
00043 }
00044
00045
00046 void KCelBookmarkManager::copy(const QString& source, const QString& destination) {
00047 QFile src(source), dst(destination);
00048 if (!src.exists()) return;
00049
00050 src.open(IO_ReadOnly);
00051 dst.open(IO_WriteOnly);
00052 int bufSize=16384;
00053 char* buf = new char[bufSize];
00054 int len = src.readBlock(buf, bufSize);
00055 do {
00056 dst.writeBlock(buf, len);
00057 len = src.readBlock(buf, len);
00058 } while (len > 0);
00059 src.close();
00060 dst.close();
00061 delete[] buf;
00062 }
00063
00064