Skip to content

Commit

Permalink
Move recent document handling (windows "jump list" support)
Browse files Browse the repository at this point in the history
to native library

Allows other platforms to implement platform specific recent
document handling
  • Loading branch information
nyalldawson committed Aug 7, 2018
1 parent 70ba387 commit 709973a
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 22 deletions.
4 changes: 1 addition & 3 deletions src/app/CMakeLists.txt
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
29 changes: 10 additions & 19 deletions src/app/qgisapp.cpp
Expand Up @@ -101,12 +101,6 @@
#include <QNetworkProxy>
#include <QAuthenticator>

#ifdef Q_OS_WIN
#include <QtWinExtras/QWinJumpList>
#include <QtWinExtras/QWinJumpListItem>
#include <QtWinExtras/QWinJumpListCategory>
#endif

Q_GUI_EXPORT extern int qt_defaultDpiX();

//
Expand Down Expand Up @@ -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 )
Expand Down
5 changes: 5 additions & 0 deletions src/native/qgsnative.cpp
Expand Up @@ -63,3 +63,8 @@ QgsNative::NotificationResult QgsNative::showDesktopNotification( const QString
result.successful = false;
return result;
}

void QgsNative::onRecentProjectsChanged( const std::vector<QgsNative::RecentProjectProperties> & )
{

}
31 changes: 31 additions & 0 deletions src/native/qgsnative.h
Expand Up @@ -21,6 +21,7 @@
#include "qgis_native.h"
#include <QImage>
#include <QVariant>
#include <vector>

class QString;
class QWindow;
Expand Down Expand Up @@ -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 )
Expand Down
19 changes: 19 additions & 0 deletions src/native/win/qgswinnative.cpp
Expand Up @@ -16,11 +16,15 @@
***************************************************************************/

#include "qgswinnative.h"
#include <QCoreApplication>
#include <QString>
#include <QDir>
#include <QWindow>
#include <QtWinExtras/QWinTaskbarButton>
#include <QtWinExtras/QWinTaskbarProgress>
#include <QtWinExtras/QWinJumpList>
#include <QtWinExtras/QWinJumpListItem>
#include <QtWinExtras/QWinJumpListCategory>

void QgsWinNative::initializeMainWindow( QWindow *window )
{
Expand Down Expand Up @@ -61,3 +65,18 @@ void QgsWinNative::hideApplicationProgress()
{
mTaskProgress->hide();
}

void QgsWinNative::onRecentProjectsChanged( const std::vector<QgsNative::RecentProjectProperties> &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 );
}
}
1 change: 1 addition & 0 deletions src/native/win/qgswinnative.h
Expand Up @@ -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:

Expand Down

0 comments on commit 709973a

Please sign in to comment.