Skip to content

Commit

Permalink
Move windows app icon progress report API to QgsNative
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 6, 2018
1 parent 51b63e6 commit a81555a
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/app/qgisapp.cpp
Expand Up @@ -98,11 +98,6 @@
#include <QNetworkProxy>
#include <QAuthenticator>

#ifdef Q_OS_WIN
#include <QWinTaskbarButton>
#include <QWinTaskbarProgress>
#endif

#ifdef Q_OS_WIN
#include <QtWinExtras/QWinJumpList>
#include <QtWinExtras/QWinJumpListItem>
Expand Down Expand Up @@ -1307,18 +1302,21 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh

connect( QgsApplication::taskManager(), &QgsTaskManager::statusChanged, this, &QgisApp::onTaskCompleteShowNotify );

#ifdef Q_OS_WIN
QWinTaskbarButton *taskButton = new QWinTaskbarButton( this );
taskButton->setWindow( windowHandle() );
QgsGui::instance()->nativePlatformInterface()->initializeMainWindow( windowHandle() );

QWinTaskbarProgress *taskProgress = taskButton->progress();
taskProgress->setVisible( false );
connect( QgsApplication::taskManager(), &QgsTaskManager::taskAdded, taskProgress, [taskProgress] { taskProgress->setMaximum( 0 ); taskProgress->show(); }
);
connect( QgsApplication::taskManager(), &QgsTaskManager::finalTaskProgressChanged, taskProgress, [taskProgress]( double val ) { taskProgress->setMaximum( 100 ); taskProgress->show(); taskProgress->setValue( val ); }
);
connect( QgsApplication::taskManager(), &QgsTaskManager::allTasksFinished, taskProgress, &QWinTaskbarProgress::hide );
#endif
// setup application progress reports from task manager
connect( QgsApplication::taskManager(), &QgsTaskManager::taskAdded, this, []
{
QgsGui::instance()->nativePlatformInterface()->showUndefinedApplicationProgress();
} );
connect( QgsApplication::taskManager(), &QgsTaskManager::finalTaskProgressChanged, this, []( double val )
{
QgsGui::instance()->nativePlatformInterface()->setApplicationProgress( val );
} );
connect( QgsApplication::taskManager(), &QgsTaskManager::allTasksFinished, this, []
{
QgsGui::instance()->nativePlatformInterface()->hideApplicationProgress();
} );

// supposedly all actions have been added, now register them to the shortcut manager
QgsGui::shortcutsManager()->registerAllChildren( this );
Expand Down
4 changes: 4 additions & 0 deletions src/native/CMakeLists.txt
Expand Up @@ -142,7 +142,11 @@ IF (UNIX)
ENDIF (UNIX)

IF (WIN32)
FIND_PACKAGE(Qt5WinExtras)

TARGET_LINK_LIBRARIES(qgis_native shell32)
TARGET_LINK_LIBRARIES(qgis_native ${Qt5Widget_LIBRARIES} ${QT_QTMAIN_LIBRARY})
TARGET_LINK_LIBRARIES(qgis_native Qt5::WinExtras)
ENDIF (WIN32)
# install

Expand Down
20 changes: 20 additions & 0 deletions src/native/qgsnative.cpp
Expand Up @@ -21,6 +21,11 @@
#include <QUrl>
#include <QFileInfo>

void QgsNative::initializeMainWindow( QWindow * )
{

}

void QgsNative::currentAppActivateIgnoringOtherApps()
{
}
Expand All @@ -31,3 +36,18 @@ void QgsNative::openFileExplorerAndSelectFile( const QString &path )
QString folder = fi.path();
QDesktopServices::openUrl( QUrl::fromLocalFile( folder ) );
}

void QgsNative::showUndefinedApplicationProgress()
{

}

void QgsNative::setApplicationProgress( double progress )
{

}

void QgsNative::hideApplicationProgress()
{

}
47 changes: 47 additions & 0 deletions src/native/qgsnative.h
Expand Up @@ -21,6 +21,7 @@
#include "qgis_native.h"

class QString;
class QWindow;

/**
* \class QgsNative
Expand All @@ -35,6 +36,15 @@ class NATIVE_EXPORT QgsNative

virtual ~QgsNative() = default;

/**
* Initializes the native interface, using the specified \a window.
*
* The default implementation does nothing.
*
* \since QGIS 3.4
*/
virtual void initializeMainWindow( QWindow *window );

/**
* Brings the QGIS app to front. The default implementation does nothing.
*/
Expand All @@ -50,6 +60,43 @@ class NATIVE_EXPORT QgsNative
* \since QGIS 3.4
*/
virtual void openFileExplorerAndSelectFile( const QString &path );

/**
* Shows the application progress report, using an "undefined" total
* type progress (i.e. the platform's way of showing that a task
* is occurring with an unknown progress).
*
* The default implementation does nothing.
*
* \see setApplicationProgress()
* \see hideApplicationProgress()
* \since QGIS 3.4
*/
virtual void showUndefinedApplicationProgress();

/**
* Shows the application progress report, with the
* specified \a progress (in percent).
*
* The default implementation does nothing.
*
* \see showUndefinedApplicationProgress()
* \see hideApplicationProgress()
* \since QGIS 3.4
*/
virtual void setApplicationProgress( double progress );

/**
* Hides the application progress report.
*
* The default implementation does nothing.
*
* \see showUndefinedApplicationProgress()
* \see setApplicationProgress()
* \since QGIS 3.4
*/
virtual void hideApplicationProgress();

};

#endif // QGSNATIVE_H
32 changes: 32 additions & 0 deletions src/native/win/qgswinnative.cpp
Expand Up @@ -18,6 +18,20 @@
#include "qgswinnative.h"
#include <QString>
#include <QDir>
#include <QWindow>
#include <QtWinExtras/QWinTaskbarButton>
#include <QtWinExtras/QWinTaskbarProgress>

void QgsWinNative::initializeMainWindow( QWindow *window )
{
if ( mTaskButton )
return; // already initialized!

mTaskButton = new QWinTaskbarButton( window );
mTaskButton->setWindow( window );
mTaskProgress = mTaskButton->progress();
mTaskProgress->setVisible( false );
}

void QgsWinNative::openFileExplorerAndSelectFile( const QString &path )
{
Expand All @@ -29,3 +43,21 @@ void QgsWinNative::openFileExplorerAndSelectFile( const QString &path )
ILFree( pidl );
}
}

void QgsWinNative::showUndefinedApplicationProgress()
{
mTaskProgress->setMaximum( 0 );
mTaskProgress->show();
}

void QgsWinNative::setApplicationProgress( double progress )
{
mTaskProgress->setMaximum( 100 );
mTaskProgress->show();
mTaskProgress->setValue( progress );
}

void QgsWinNative::hideApplicationProgress()
{
mTaskProgress->hide();
}
13 changes: 13 additions & 0 deletions src/native/win/qgswinnative.h
Expand Up @@ -23,10 +23,23 @@
#include <shlobj.h>
#pragma comment(lib,"Shell32.lib")

class QWinTaskbarButton;
class QWinTaskbarProgress;
class QWindow;

class NATIVE_EXPORT QgsWinNative : public QgsNative
{
public:
void initializeMainWindow( QWindow *window ) override;
void openFileExplorerAndSelectFile( const QString &path ) override;
void showUndefinedApplicationProgress() override;
void setApplicationProgress( double progress ) override;
void hideApplicationProgress() override;

private:

QWinTaskbarButton *mTaskButton = nullptr;
QWinTaskbarProgress *mTaskProgress = nullptr;
};

#endif // QGSMACNATIVE_H

0 comments on commit a81555a

Please sign in to comment.