[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeedu/marble/src/lib
From:       Torsten Rahn <tackat () kde ! org>
Date:       2010-12-27 1:02:46
Message-ID: 20101227010246.BEDCDAC8AD () svn ! kde ! org
[Download RAW message or body]

SVN commit 1209509 by rahn:

Changes: Adds an option to delete a theme if it is located in the home
directory of the user. Sub-directories and the theme directory are
removed if there is no other data in them. The mapwizard-patch is
required to apply this patch.

This patch was created for a GCI task by Daniel Marth:
http://www.google-melange.com/gci/task/show/google/gci2010/kde/t129258692177





 M  +101 -4    MarbleThemeSelectView.cpp  
 M  +2 -0      MarbleThemeSelectView.h  


--- trunk/KDE/kdeedu/marble/src/lib/MarbleThemeSelectView.cpp #1209508:1209509
@@ -11,17 +11,91 @@
 //
 
 #include "MarbleThemeSelectView.h"
+#include "MarbleDirs.h"
 
 #include "MapWizard.h"
 #include "MarbleDebug.h"
 #include <QtGui/QResizeEvent>
 #include <QtGui/QMenu>
+#include <QtGui/QMessageBox>
+#include <QtCore/QFileInfo>
+#include <QtCore/QFile>
+#include <QtCore/QDir>
 
 using namespace Marble;
 
+class MarbleThemeSelectView::Private
+{
+public:
+    explicit Private( MarbleThemeSelectView * const parent );
+    void deleteDirectory( const QString& path );
+    void deleteDataDirectories( const QString& path );
+    void deletePreview( const QString& path );
+    QString currentThemeName();
+    QString currentThemePath();
+private:
+    MarbleThemeSelectView *m_parent;
+};
+
+MarbleThemeSelectView::Private::Private( MarbleThemeSelectView * const parent ) 
+    : m_parent( parent )
+{
+
+}
+
+void MarbleThemeSelectView::Private::deleteDirectory( const QString& path )
+{
+    QDir directory( path );
+    foreach( QString filename, directory.entryList( QDir::Files | \
QDir::NoDotAndDotDot ) ) +        QFile( path + filename ).remove();
+    QDir().rmdir( path );
+}
+
+void MarbleThemeSelectView::Private::deleteDataDirectories( const QString& path )
+{
+    QDir directoryv( path );
+    foreach( QString filename, directoryv.entryList( QDir::AllEntries | \
QDir::NoDotAndDotDot ) ) +    {
+        QString filepath = path + "/" + filename;
+        QFile file( filepath );
+        if( QFileInfo( filepath ).isDir() && filename.contains( QRegExp( "^[0-9]+$" \
) ) ) +        {
+            deleteDataDirectories( filepath );
+            QDir().rmdir( filepath );
+        }
+        else if( filename.contains( QRegExp( "^[0-9]\\..+" ) ) )
+            file.remove();
+    }
+}
+
+void MarbleThemeSelectView::Private::deletePreview( const QString& path )
+{
+    QDir directoryv( path, "preview.*" );
+    foreach( QString filename, directoryv.entryList() )
+        QFile( path + "/" + filename ).remove();
+}
+
+QString MarbleThemeSelectView::Private::currentThemeName()
+{
+    QModelIndex index = m_parent->currentIndex();
+    const QAbstractItemModel *model = index.model();
+
+    QModelIndex columnIndex = model->index( index.row(), 0, QModelIndex() );
+    return ( model->data( columnIndex )).toString();
+}
+
+QString MarbleThemeSelectView::Private::currentThemePath()
+{
+    QModelIndex index = m_parent-> currentIndex();
+    const QAbstractItemModel  *model = index.model();
+
+    QModelIndex columnIndex = model->index( index.row(), 1, QModelIndex() );
+    return ( model->data( columnIndex )).toString();
+}
+
 MarbleThemeSelectView::MarbleThemeSelectView(QWidget *parent)
     : QListView( parent ),
-      d( 0 )                    // No private data yet.
+      d( new Private( this ) )
 {
     setViewMode( QListView::IconMode );
     setFlow( QListView::LeftToRight );
@@ -40,6 +114,11 @@
                   SLOT( showContextMenu(QPoint)) );
 }
 
+MarbleThemeSelectView::~MarbleThemeSelectView()
+{
+    delete d;
+}
+
 void MarbleThemeSelectView::resizeEvent(QResizeEvent* event)
 {
     QListView::resizeEvent(event);
@@ -53,9 +132,8 @@
 {
     const QAbstractItemModel  *model = index.model();
 
-    QModelIndex  colindex        = model->index( index.row(), 1, 
-                                                 QModelIndex() );
-    QString      currentmaptheme = (model->data( colindex )).toString();
+    QModelIndex  columnIndex = model->index( index.row(), 1, QModelIndex() );
+    QString currentmaptheme = ( model->data( columnIndex )).toString();
     mDebug() << currentmaptheme;
     emit selectMapTheme( currentmaptheme );
 }
@@ -74,8 +152,27 @@
 {
     QMenu menu;
     menu.addAction( "&Create a New Map...", this, SLOT( mapWizard() ) );
+    if( QFileInfo( MarbleDirs::localPath() + "/maps/" + d->currentThemePath() \
).exists() ) +        menu.addAction( tr( "&Delete Map Theme" ), this, SLOT( \
deleteMap() ) );  menu.addAction( "&Upload Map...", this, SLOT( uploadDialog() ) );
     menu.exec( mapToGlobal( pos ) );
 }
 
+void MarbleThemeSelectView::deleteMap()
+{
+    if(QMessageBox::warning( this, 
+                             tr( "" ), 
+                             tr( "Are you sure that you want to delete \"%1\"?" \
).arg( d->currentThemeName() ), +                             QMessageBox::Yes | \
QMessageBox::No) == QMessageBox::Yes ) +    {
+        QDir mapthemedir( QFileInfo( MarbleDirs::localPath() + "/maps/" + \
d->currentThemePath()).path()); +        d->deleteDirectory( mapthemedir.path() + \
"/legend/" ); +        d->deleteDataDirectories( mapthemedir.path() + "/" );
+	d->deletePreview( mapthemedir.path() + "/" );
+        QFile( MarbleDirs::localPath() + "/maps/" + d->currentThemePath()).remove();
+        QFile( mapthemedir.path() + "/legend.html" ).remove();
+        QDir().rmdir( mapthemedir.path() );
+    }
+}
+
 #include "MarbleThemeSelectView.moc"
--- trunk/KDE/kdeedu/marble/src/lib/MarbleThemeSelectView.h #1209508:1209509
@@ -34,6 +34,7 @@
 
  public:
     explicit MarbleThemeSelectView(QWidget *parent = 0);
+    ~MarbleThemeSelectView();
     // void setModel( QAbstractItemModel * model );
     
  protected:
@@ -44,6 +45,7 @@
     void uploadDialog();
     void mapWizard();
     void showContextMenu(const QPoint& pos);
+    void deleteMap();
 
  Q_SIGNALS:
     void selectMapTheme( const QString& );


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic