[Marble-commits] KDE/kdeedu/marble

Dennis Nienhüser earthwings at gentoo.org
Thu Oct 7 00:07:16 CEST 2010


SVN commit 1183306 by nienhueser:

Do not require a default bookmarks.kml to be available, but create the default document in memory if no custom bookmarks.kml exists yet. Fixes some crashes when bookmarks.kml is not available and also enables localization of the default folder name.

 D             data/bookmarks/bookmarks.kml  
 M  +2 -5      src/QtMainWindow.cpp  
 M  +56 -35    src/lib/BookmarkManager.cpp  
 M  +9 -10     src/lib/BookmarkManager_p.h  
 M  +2 -4      src/marble_part.cpp  


--- trunk/KDE/kdeedu/marble/src/QtMainWindow.cpp #1183305:1183306
@@ -102,12 +102,9 @@
     connect( m_configDialog, SIGNAL( clearPersistentCacheClicked() ),
              m_controlView->marbleWidget(), SLOT( clearPersistentTileCache() ) );
 
-	//Load Bookmark File, First time read from system path then once bookmark is used
-    //a copy of bookmarks.kml will be created in local path
-    if( m_controlView->marbleWidget()->loadBookmarkFile( "bookmarks/bookmarks.kml" ) )
-        mDebug() << "Bookmark File Loaded Successfully";
+    // Load bookmark file. If it does not exist, a default one will be used.
+    m_controlView->marbleWidget()->loadBookmarkFile( "bookmarks/bookmarks.kml" );
 
-
     createActions();
     createMenus();
     createStatusBar();
--- trunk/KDE/kdeedu/marble/src/lib/BookmarkManager.cpp #1183305:1183306
@@ -22,6 +22,43 @@
 namespace Marble
 {
 
+BookmarkManagerPrivate::BookmarkManagerPrivate()
+        : m_bookmarkDocument( 0 ), m_bookmarkFileRelativePath( "bookmarks/bookmarks.kml" )
+{
+    // nothing to do
+}
+
+BookmarkManagerPrivate::~BookmarkManagerPrivate()
+{
+    delete m_bookmarkDocument;
+}
+
+GeoDataDocument* BookmarkManagerPrivate::createEmptyBookmarkDocument()
+{
+    GeoDataFolder* folder = new GeoDataFolder;
+    folder->setName( QObject::tr( "Default" ) );
+    GeoDataDocument* result = new GeoDataDocument;
+    result->append( folder );
+    return result;
+}
+
+GeoDataDocument* BookmarkManagerPrivate::bookmarkDocument()
+{
+    if ( !m_bookmarkDocument ) {
+        m_bookmarkDocument = createEmptyBookmarkDocument();
+    }
+
+    Q_ASSERT( m_bookmarkDocument );
+    return m_bookmarkDocument;
+}
+
+void BookmarkManagerPrivate::resetBookmarks()
+{
+    delete m_bookmarkDocument;
+    m_bookmarkDocument = 0;
+    bookmarkDocument();
+}
+
 BookmarkManager::BookmarkManager( QObject *parent )
      : QObject( parent ), d( new BookmarkManagerPrivate() )
 {
@@ -29,8 +66,6 @@
 
 BookmarkManager::~BookmarkManager()
 {
-    
-    delete d->m_bookmarkDocument;   
     delete d;
 }
 
@@ -41,7 +76,6 @@
 
 bool BookmarkManager::loadFile( const QString &relativeFilePath)
 {
-
     d->m_bookmarkFileRelativePath = relativeFilePath;
     QString absoluteFilePath = MarbleDirs::path( d->m_bookmarkFileRelativePath ); 
 
@@ -52,7 +86,7 @@
         QFile file( absoluteFilePath );
         
         if ( !file.exists() ) {
-            mDebug() <<  " File does not exist in local and system path! ";
+            mDebug() <<  "Bookmark file" << relativeFilePath << "does not exist in local and system data directory.";
             return false;
         }
 
@@ -60,10 +94,12 @@
         file.open( QIODevice::ReadOnly );
 
         if ( !parser.read( &file ) ) {
-            qWarning( "Could not parse file!" );
+            mDebug() << "Could not parse file" << absoluteFilePath;
+        }
             
+        if ( d->m_bookmarkDocument ) {
+            delete d->m_bookmarkDocument;
         }
-        
         d->m_bookmarkDocument = dynamic_cast<GeoDataDocument*>(parser.releaseDocument() );
         Q_ASSERT( d->m_bookmarkDocument );
 
@@ -94,15 +130,14 @@
 
 QVector<GeoDataFolder*> BookmarkManager::folders() const
 {
-    return d->m_bookmarkDocument ? d->m_bookmarkDocument->folderList() : QVector<GeoDataFolder*>();
+    return d->bookmarkDocument()->folderList();
 }
 
 void BookmarkManager::addNewBookmarkFolder( const QString &folder)
 {
     //If name is empty string
-    if( folder == "" )
-    {
-        mDebug() << "Folder with empty name is not acceptable, please give an another name" ;
+    if ( folder.isEmpty() ) {
+        mDebug() << "Folder with empty name is not acceptable, please give it another name" ;
         return;
     }
     
@@ -112,29 +147,22 @@
     QVector<GeoDataFolder*>::const_iterator i = folderList.constBegin();
     QVector<GeoDataFolder*>::const_iterator end = folderList.constEnd();
     for (; i != end; ++i ) {
-        if( folder == (*i)->name() )
-        {
-            mDebug() << "Folder with same name already exist, please give an another name";
+        if ( folder == ( *i )->name() ) {
+            mDebug() << "Folder with same name already exist, please give it another name";
             return;
         }
     }
 
-
     GeoDataFolder *bookmarkFolder = new GeoDataFolder();
     bookmarkFolder->setName( folder );
 
-    d->m_bookmarkDocument->append( bookmarkFolder );
+    d->bookmarkDocument()->append( bookmarkFolder );
     updateBookmarkFile();
 }
 
 void BookmarkManager::removeAllBookmarks()
 {
-    d->m_bookmarkDocument->clear();
-    
-    GeoDataFolder *defaultFolder = new GeoDataFolder();
-    defaultFolder->setName( "Default" );
-    d->m_bookmarkDocument->append( defaultFolder );
-   
+    d->resetBookmarks();
      updateBookmarkFile();
 }
 
@@ -142,39 +170,32 @@
 {
     QString absoluteLocalFilePath = MarbleDirs::localPath()+ '/'+d->m_bookmarkFileRelativePath ;
 
-
     if ( ! d->m_bookmarkFileRelativePath.isNull() ) {
         GeoWriter writer;
         writer.setDocumentType( "http://earth.google.com/kml/2.2" );
 
         QFile file( absoluteLocalFilePath );
     
-        if( !file.exists() )
-        {
-            mDebug() << " Bookmarks file doesn't exist, creating Bookmarks.kml in MarbleDirs::localPath()/relativeFilePath ";
-            
+        if ( !file.exists() ) {
             // Extracting directory of file : for bookmarks it will be MarbleDirs::localPath()+/bookmarks/
-            QFileInfo *fileInfo = new QFileInfo( absoluteLocalFilePath );
-            QString directoryPath = fileInfo->path();
-            delete fileInfo;
+            QFileInfo fileInfo( absoluteLocalFilePath );
+            QString directoryPath = fileInfo.path();
 
             //Creating all directories, which doesn't exist
-            QDir *directory = new QDir(  MarbleDirs::localPath() );
-            directory->mkpath( directoryPath );
-            delete directory;
+            QDir directory(  MarbleDirs::localPath() );
+            directory.mkpath( directoryPath );
         }
 
         file.open( QIODevice::ReadWrite );
 
-        if ( !writer.write( &file, *( d->m_bookmarkDocument )  ) ) {
-            qWarning( "Could not write the file." );
+        if ( !writer.write( &file, *( d->bookmarkDocument() )  ) ) {
+            mDebug() << "Could not write the bookmarks file" << absoluteLocalFilePath;
             return false;
         }
         emit bookmarksChanged();
         return true;
     }
     return false;
-    
 }
 
 }
--- trunk/KDE/kdeedu/marble/src/lib/BookmarkManager_p.h #1183305:1183306
@@ -19,24 +19,23 @@
 class GeoDataDocument;
 class BookmarkManagerPrivate
 {
-
-
  public:
+    BookmarkManagerPrivate();
 
-    BookmarkManagerPrivate()
-      : m_bookmarkDocument( 0 ),
-      m_bookmarkFileRelativePath()
-    {
-    }
+    ~BookmarkManagerPrivate();
 
-    ~BookmarkManagerPrivate()
-    {
-    }
+    GeoDataDocument* bookmarkDocument();
     
+    void resetBookmarks();
 
     GeoDataDocument *m_bookmarkDocument;
 
     QString m_bookmarkFileRelativePath;    
+
+private:
+    GeoDataDocument* createEmptyBookmarkDocument();
 };
+
 }
+
 #endif
--- trunk/KDE/kdeedu/marble/src/marble_part.cpp #1183305:1183306
@@ -142,10 +142,8 @@
     m_statusBarExtension = new KParts::StatusBarExtension( this );
     m_statusBarExtension->statusBar()->setUpdatesEnabled( false );
 
-    //Load Bookmark File, First time read from system path then once bookmark is used 
-    //a copy of bookmarks.kml will be created in local path 
-    if( m_controlView->marbleWidget()->loadBookmarkFile( "bookmarks/bookmarks.kml" ) )
-        mDebug() << "Bookmark File Loaded Successfully";
+    // Load bookmark file. If it does not exist, a default one will be used.
+    m_controlView->marbleWidget()->loadBookmarkFile( "bookmarks/bookmarks.kml" );
 
     initializeCustomTimezone();
 


More information about the Marble-commits mailing list