From 709973a233c27144e21bceaaeb612e7e29d68f68 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 7 Aug 2018 09:40:57 +1000 Subject: [PATCH] Move recent document handling (windows "jump list" support) to native library Allows other platforms to implement platform specific recent document handling --- src/app/CMakeLists.txt | 4 +--- src/app/qgisapp.cpp | 29 ++++++++++------------------- src/native/qgsnative.cpp | 5 +++++ src/native/qgsnative.h | 31 +++++++++++++++++++++++++++++++ src/native/win/qgswinnative.cpp | 19 +++++++++++++++++++ src/native/win/qgswinnative.h | 1 + 6 files changed, 67 insertions(+), 22 deletions(-) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 98db66a74a5e..2e72df815ee7 100755 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -537,8 +537,6 @@ QT5_ADD_RESOURCES(TEST_RCC_SRCS ${TEST_RCCS}) QT5_WRAP_CPP(QGIS_APP_MOC_SRCS ${QGIS_APP_MOC_HDRS}) IF (WIN32) - FIND_PACKAGE(Qt5WinExtras) - SET (QGIS_APP_SRCS ${QGIS_APP_SRCS} main.cpp ${IMAGE_RCC_SRCS} ${TEST_RCC_SRCS}) SET (QGIS_APPMAIN_SRCS mainwin.cpp) @@ -810,7 +808,7 @@ IF(WIN32) ADD_DEFINITIONS(-DQWT_DLL) ADD_DEFINITIONS(-DQSCINTILLA_DLL) TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} dbghelp) - TARGET_LINK_LIBRARIES(qgis_app dbghelp Qt5::WinExtras) + TARGET_LINK_LIBRARIES(qgis_app dbghelp) ENDIF(WIN32) TARGET_LINK_LIBRARIES(${QGIS_APP_NAME} qgis_native) diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index a3f0b02c1e1b..f1d21c87d146 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -101,12 +101,6 @@ #include #include -#ifdef Q_OS_WIN -#include -#include -#include -#endif - Q_GUI_EXPORT extern int qt_defaultDpiX(); // @@ -4047,21 +4041,18 @@ void QgisApp::updateRecentProjectPaths() } } -#if defined(Q_OS_WIN) - QWinJumpList jumplist; - jumplist.recent()->clear(); - Q_FOREACH ( const QgsWelcomePageItemsModel::RecentProjectData &recentProject, mRecentProjects ) + std::vector< QgsNative::RecentProjectProperties > recentProjects; + for ( const QgsWelcomePageItemsModel::RecentProjectData &recentProject : qgis::as_const( mRecentProjects ) ) { - QString name = recentProject.title != recentProject.path ? recentProject.title : QFileInfo( recentProject.path ).baseName(); - QWinJumpListItem *newProject = new QWinJumpListItem( QWinJumpListItem::Link ); - newProject->setTitle( name ); - newProject->setFilePath( QDir::toNativeSeparators( QCoreApplication::applicationFilePath() ) ); - newProject->setArguments( QStringList( recentProject.path ) ); - jumplist.recent()->addItem( newProject ); + QgsNative::RecentProjectProperties project; + project.title = recentProject.title; + project.fileName = QFileInfo( recentProject.path ).baseName(); + project.path = recentProject.path; + project.name = project.title != project.path ? project.title : project.fileName; + recentProjects.emplace_back( project ); } -#endif - -} // QgisApp::updateRecentProjectPaths + QgsGui::instance()->nativePlatformInterface()->onRecentProjectsChanged( recentProjects ); +} // add this file to the recently opened/saved projects list void QgisApp::saveRecentProjectPath( bool savePreviewImage ) diff --git a/src/native/qgsnative.cpp b/src/native/qgsnative.cpp index dcdf5e9e3519..8b5f783a9eb2 100644 --- a/src/native/qgsnative.cpp +++ b/src/native/qgsnative.cpp @@ -63,3 +63,8 @@ QgsNative::NotificationResult QgsNative::showDesktopNotification( const QString result.successful = false; return result; } + +void QgsNative::onRecentProjectsChanged( const std::vector & ) +{ + +} diff --git a/src/native/qgsnative.h b/src/native/qgsnative.h index 3abf6eb35432..6d93c0471f18 100644 --- a/src/native/qgsnative.h +++ b/src/native/qgsnative.h @@ -21,6 +21,7 @@ #include "qgis_native.h" #include #include +#include class QString; class QWindow; @@ -162,6 +163,36 @@ class NATIVE_EXPORT QgsNative * Returns true if notification was successfully sent. */ virtual NotificationResult showDesktopNotification( const QString &summary, const QString &body, const NotificationSettings &settings = NotificationSettings() ); + + /** + * Contains properties of a recently used project. + */ + struct RecentProjectProperties + { + //! Project name (will be project title if set, otherwise project filename) + QString name; + + //! Project title, if set + QString title; + + //! Project filename + QString fileName; + + //! Full project path + QString path; + }; + + /** + * Called whenever the list of recently used projects is modified. + * + * The \a recentProjects list contains a list of recently used projects, with the + * most recently used listed first. + * + * The default implementation does nothing. + * + * \since QGIS 3.4 + */ + virtual void onRecentProjectsChanged( const std::vector< RecentProjectProperties > &recentProjects ); }; Q_DECLARE_OPERATORS_FOR_FLAGS( QgsNative::Capabilities ) diff --git a/src/native/win/qgswinnative.cpp b/src/native/win/qgswinnative.cpp index c47766b91a04..c64b672faf45 100644 --- a/src/native/win/qgswinnative.cpp +++ b/src/native/win/qgswinnative.cpp @@ -16,11 +16,15 @@ ***************************************************************************/ #include "qgswinnative.h" +#include #include #include #include #include #include +#include +#include +#include void QgsWinNative::initializeMainWindow( QWindow *window ) { @@ -61,3 +65,18 @@ void QgsWinNative::hideApplicationProgress() { mTaskProgress->hide(); } + +void QgsWinNative::onRecentProjectsChanged( const std::vector &recentProjects ) +{ + QWinJumpList jumplist; + jumplist.recent()->clear(); + for ( const RecentProjectProperties &recentProject : recentProjects ) + { + QString name = recentProject.title != recentProject.path ? recentProject.title : QFileInfo( recentProject.path ).baseName(); + QWinJumpListItem *newProject = new QWinJumpListItem( QWinJumpListItem::Link ); + newProject->setTitle( name ); + newProject->setFilePath( QDir::toNativeSeparators( QCoreApplication::applicationFilePath() ) ); + newProject->setArguments( QStringList( recentProject.path ) ); + jumplist.recent()->addItem( newProject ); + } +} diff --git a/src/native/win/qgswinnative.h b/src/native/win/qgswinnative.h index f18a0392b4a3..9bb9dbb0ea37 100644 --- a/src/native/win/qgswinnative.h +++ b/src/native/win/qgswinnative.h @@ -35,6 +35,7 @@ class NATIVE_EXPORT QgsWinNative : public QgsNative void showUndefinedApplicationProgress() override; void setApplicationProgress( double progress ) override; void hideApplicationProgress() override; + void onRecentProjectsChanged( const std::vector< RecentProjectProperties > &recentProjects ) override; private: