Git commit 5a74e0604dd116257361899bc58a8d3be958c419 by Dennis Nienh?ser, on behalf of Andrei Duma. Committed on 11/04/2013 at 22:36. Pushed by nienhueser into branch 'master'.
Add a Recent Files menu REVIEW: 109968 FEATURE: 310053 GUI: M +22 -4 src/marble_part.cpp M +2 -0 src/marble_part.h M +1 -0 src/marble_part.rc http://commits.kde.org/marble/5a74e0604dd116257361899bc58a8d3be958c419 diff --git a/src/marble_part.cpp b/src/marble_part.cpp index 90be6af..d68637a 100644 --- a/src/marble_part.cpp +++ b/src/marble_part.cpp @@ -125,6 +125,7 @@ MarblePart::MarblePart( QWidget *parentWidget, QObject *parent, const QVariantLi m_timeControlDialog( 0 ), m_downloadRegionDialog( 0 ), m_externalMapEditorAction( 0 ), + m_recentFilesAction( 0 ), m_configDialog( 0 ), m_position( i18n( NOT_AVAILABLE ) ), m_tileZoomLevel( i18n( NOT_AVAILABLE ) ), @@ -213,9 +214,17 @@ KAboutData *MarblePart::createAboutData() bool MarblePart::openUrl( const KUrl &url ) { - Q_UNUSED( url ); + QFileInfo fileInfo( url.toLocalFile() ); + if ( fileInfo.isReadable() ) { + m_controlView->marbleModel()->addGeoDataFile( url.toLocalFile() ); + m_recentFilesAction->addUrl( url ); + return true; + } - return true; + KMessageBox::error( widget(), + tr( "Sorry, unable to open '%1'. The file is not accessible." ).arg( fileInfo.fileName() ), + tr( "File not accessible" ) ); + return false; } bool MarblePart::openFile() @@ -252,13 +261,12 @@ bool MarblePart::openFile() } foreach( const QString &fileName, fileNames ) { - m_controlView->marbleModel()->addGeoDataFile( fileName ); + openUrl( fileName ); } return true; } - void MarblePart::exportMapScreenShot() { QString fileName = KFileDialog::getSaveFileName( QDir::homePath(), @@ -649,6 +657,10 @@ void MarblePart::writeSettings() writeStatusBarSettings(); + // Store recent files + KSharedConfig::Ptr sharedConfig = KSharedConfig::openConfig( KGlobal::mainComponent() ); + m_recentFilesAction->saveEntries( sharedConfig->group( "RecentFiles" ) ); + // Store current route settings RoutingManager *routingManager = m_controlView->marbleWidget()->model()->routingManager(); routingManager->writeSettings(); @@ -677,6 +689,12 @@ void MarblePart::writeStatusBarSettings() void MarblePart::setupActions() { + // Action: Recent Files + m_recentFilesAction = KStandardAction::openRecent( this, SLOT(openUrl(KUrl)), + actionCollection() ); + KSharedConfig::Ptr sharedConfig = KSharedConfig::openConfig( KGlobal::mainComponent() ); + m_recentFilesAction->loadEntries( sharedConfig->group( "RecentFiles" ) ); + // Action: Download Region m_downloadRegionAction = new KAction( this ); m_downloadRegionAction->setText( i18nc( "Action for downloading an entire region of a map", diff --git a/src/marble_part.h b/src/marble_part.h index 6bc3a1c..2f6752a 100644 --- a/src/marble_part.h +++ b/src/marble_part.h @@ -20,6 +20,7 @@ #include <kmenu.h> #include <kurl.h> #include "MarbleGlobal.h" +#include <krecentfilesaction.h> class KAboutData; class KAction; @@ -210,6 +211,7 @@ class MarblePart: public KParts::ReadOnlyPart KAction *m_lockFloatItemsAct; KAction *m_mapWizardAct; KAction *m_externalMapEditorAction; + KRecentFilesAction *m_recentFilesAction; //Bookmark Menu KAction *m_addBookmarkAction; diff --git a/src/marble_part.rc b/src/marble_part.rc index 26e3c37..52513aa 100644 --- a/src/marble_part.rc +++ b/src/marble_part.rc @@ -5,6 +5,7 @@ <Menu name="file" noMerge="1"> <text>&File</text> <Action name="file_open"/> + <Action name="file_open_recent"/> <Action name="new_stuff"/> <Action name="createMap"/> <Action name="file_download_region"/>
