Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

kcelbookmarkmanager.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           kcelbookmarkmanager.cpp  -  description
00003                              -------------------
00004     begin                : Sat Aug 31 2002
00005     copyright            : (C) 2002 by chris
00006     email                : chris@tux.teyssier.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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 

Generated on Sat Jan 14 22:30:31 2006 for Celestia by  doxygen 1.4.1