Skip to content
Permalink
Browse files

Move recent document handling (windows "jump list" support)

to native library

Allows other platforms to implement platform specific recent
document handling
  • Loading branch information
nyalldawson committed Aug 6, 2018
1 parent 70ba387 commit 709973a233c27144e21bceaaeb612e7e29d68f68
@@ -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)
@@ -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();

//
@@ -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 )
@@ -63,3 +63,8 @@ QgsNative::NotificationResult QgsNative::showDesktopNotification( const QString
result.successful = false;
return result;
}

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

}
@@ -21,6 +21,7 @@
#include "qgis_native.h"
#include <QImage>
#include <QVariant>
#include <vector>

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 )
@@ -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 )
{
@@ -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 );
}
}
@@ -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:

0 comments on commit 709973a

Please sign in to comment.
You can’t perform that action at this time.