Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the Windows build with Qt6 #608

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ if(WIN32)
src/processhandle.cpp)
set(PLATFORM_EXE_SOURCES src/res/birdtray.rc)
set(PLATFORM_HEADERS src/windowtools_win.h src/birdtrayeventfilter.h src/processhandle.h)
find_package(Qt5WinExtras CONFIG REQUIRED)
list(APPEND REQUIRED_MODULES Qt6::WinExtras)
else()
find_library(X11 X11)
list(APPEND REQUIRED_MODULES X11)
set(PLATFORM_SOURCES src/windowtools_x11.cpp)
set(PLATFORM_HEADERS src/windowtools_x11.h)
endif(WIN32)
Expand Down Expand Up @@ -117,7 +115,7 @@ source_group("Resources" FILES ${RESOURCES})
qt6_add_resources(RESOURCES_SOURCES ${RESOURCES})
set_source_files_properties(${RESOURCES_SOURCES} PROPERTIES GENERATED ON)

if(Qt5LinguistTools_FOUND)
if(Qt6LinguistTools_FOUND)
set(MAIN_TRANSLATION_FILES
src/translations/main_en.ts
src/translations/main_fr.ts
Expand Down Expand Up @@ -156,13 +154,13 @@ if(Qt5LinguistTools_FOUND)
set_source_files_properties(${DYN_TRANSLATION_FILES} PROPERTIES OUTPUT_LOCATION
${CMAKE_CURRENT_BINARY_DIR}/translations)

qt5_create_translation(GEN_TRANSLATION_FILES
qt6_create_translation(GEN_TRANSLATION_FILES
${MAIN_TRANSLATION_FILES}
${SOURCES} ${PLATFORM_SOURCES} ${HEADERS} ${PLATFORM_HEADERS}
OPTIONS -locations none)
qt5_add_translation(GEN_DYN_TRANSLATION_FILES ${DYN_TRANSLATION_FILES})
qt6_add_translation(GEN_DYN_TRANSLATION_FILES ${DYN_TRANSLATION_FILES})
list(APPEND GEN_TRANSLATION_FILES ${GEN_DYN_TRANSLATION_FILES})
endif(Qt5LinguistTools_FOUND)
endif(Qt6LinguistTools_FOUND)

add_library(birdtray_lib STATIC
${SOURCES} ${PLATFORM_SOURCES} ${RESOURCES_SOURCES} ${GEN_TRANSLATION_FILES}
Expand All @@ -173,7 +171,7 @@ target_link_libraries(birdtray_lib PUBLIC ${REQUIRED_MODULES})
add_executable(birdtray
${EXECUTABLE_OPTIONS} src/main.cpp ${PLATFORM_EXE_SOURCES} ${RESOURCES_SOURCES}
${HEADERS} ${PLATFORM_HEADERS})
target_link_libraries(birdtray birdtray_lib X11)
target_link_libraries(birdtray birdtray_lib)

if(MSVC)
target_compile_options(birdtray_lib PUBLIC /utf-8)
Expand Down Expand Up @@ -247,13 +245,13 @@ else()
install(FILES src/res/birdtray.svg
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps
RENAME com.ulduzsoft.Birdtray.svg)
if(Qt5LinguistTools_FOUND)
if(Qt6LinguistTools_FOUND)
install(DIRECTORY ${CMAKE_BINARY_DIR}/translations
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/ulduzsoft/birdtray)
endif()
endif()

if(Qt5LinguistTools_FOUND)
if(Qt6LinguistTools_FOUND)
add_custom_target(clean_translations COMMENT "Remove obsolete translation entries")
foreach(TRANSLATION_FILE ${MAIN_TRANSLATION_FILES})
get_filename_component(TRANSLATION_NAME ${TRANSLATION_FILE} NAME)
Expand All @@ -265,7 +263,7 @@ if(Qt5LinguistTools_FOUND)
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${TRANSLATION_NAME}_lst_file")
endif()
add_custom_command(TARGET clean_translations
COMMAND ${Qt5_LUPDATE_EXECUTABLE}
COMMAND ${Qt6_LUPDATE_EXECUTABLE}
ARGS -locations none -no-obsolete "@${TRANSLATION_LST_FILE}"
-ts ${CMAKE_CURRENT_SOURCE_DIR}/${TRANSLATION_FILE}
DEPENDS ${TRANSLATION_LST_FILE})
Expand Down
1 change: 0 additions & 1 deletion src/autoupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ void AutoUpdater::startDownload() {
}
downloadProcessDialog->show();
QNetworkRequest request(downloadUrl);
//request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkReply* reply = networkAccessManager->get(request);
connect(reply, &QNetworkReply::downloadProgress, this,
[=](qint64 bytesReceived, qint64 bytesTotal) {
Expand Down
2 changes: 1 addition & 1 deletion src/birdtrayapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ bool BirdtrayApp::loadTranslations() {
[](QString path) { return path.append("/translations"); });
QLocale locale = QLocale::system();
bool success = loadTranslation(
qtTranslator, locale, "qt", {QLibraryInfo::location(QLibraryInfo::TranslationsPath)});
qtTranslator, locale, "qt", {QLibraryInfo::path(QLibraryInfo::TranslationsPath)});
success &= loadTranslation(dynamicTranslator, locale, "dynamic", locations);
success &= loadTranslation(mainTranslator, locale, "main", locations);
return success;
Expand Down
2 changes: 1 addition & 1 deletion src/birdtrayeventfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


bool BirdtrayEventFilter::nativeEventFilter(
const QByteArray &eventType, void *message, long *result) {
const QByteArray &eventType, void *message, qintptr *result) {
if (eventType == "windows_generic_MSG") {
MSG* messageEvent = static_cast<MSG*>(message);
if (messageEvent->message == WM_CLOSE && QApplication::activeWindow() == nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/birdtrayeventfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
class BirdtrayEventFilter: public QAbstractNativeEventFilter {
public:
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
};


Expand Down
30 changes: 1 addition & 29 deletions src/updatedownloaddialog.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#include "updatedownloaddialog.h"
#include "ui_updatedownloaddialog.h"

#ifdef Q_OS_WIN
# include <QtWinExtras/QWinTaskbarProgress>
#endif

UpdateDownloadDialog::UpdateDownloadDialog(QWidget* parent) :
QDialog(parent),
ui(new Ui::UpdateDownloadDialog) {
#ifdef Q_OS_WIN
taskBarButton = new QWinTaskbarButton(this);
#endif
ui->setupUi(this);
actionButton = new QPushButton(tr("Background"), this);
ui->buttonBox->addButton(actionButton, QDialogButtonBox::ButtonRole::ActionRole);
Expand All @@ -20,9 +13,6 @@ UpdateDownloadDialog::UpdateDownloadDialog(QWidget* parent) :
}

UpdateDownloadDialog::~UpdateDownloadDialog() {
#ifdef Q_OS_WIN
delete taskBarButton;
#endif
delete ui;
actionButton->deleteLater();
}
Expand All @@ -33,20 +23,12 @@ void UpdateDownloadDialog::reset() {
ui->label->setText(tr("Downloading Birdtray installer..."));
ui->progressBar->setValue(0);
ui->progressBar->show();
#ifdef Q_OS_WIN
taskBarButton->progress()->reset();
taskBarButton->progress()->show();
#endif
}

void UpdateDownloadDialog::onDownloadComplete() {
downloadCompleted = true;
ui->progressBar->hide();
#ifdef Q_OS_WIN
taskBarButton->progress()->setRange(0, 100);
taskBarButton->progress()->setValue(100);
#endif
actionButton->setText( QCoreApplication::translate("UpdateDialog", "Update and restart"));
actionButton->setText(QCoreApplication::translate("UpdateDialog", "Update and restart"));
ui->label->setText(tr("Download finished. Restart and update Birdtray?"));
show();
raise();
Expand All @@ -57,9 +39,6 @@ void UpdateDownloadDialog::onDownloadProgress(qint64 bytesReceived, qint64 bytes
if (bytesTotal <= 0) {
ui->label->setText(tr("Downloading Birdtray installer..."));
ui->progressBar->setRange(0, 0);
#ifdef Q_OS_WIN
taskBarButton->progress()->setRange(0, 0);
#endif
return;
}
ui->label->setText(
Expand All @@ -69,10 +48,6 @@ void UpdateDownloadDialog::onDownloadProgress(qint64 bytesReceived, qint64 bytes
int percent = qRound((bytesReceived / (double) bytesTotal) * 100.0);
ui->progressBar->setRange(0, 100);
ui->progressBar->setValue(percent);
#ifdef Q_OS_WIN
taskBarButton->progress()->setRange(0, 100);
taskBarButton->progress()->setValue(percent);
#endif
}

bool UpdateDownloadDialog::wasCanceled() const {
Expand All @@ -89,7 +64,4 @@ void UpdateDownloadDialog::onActionPressed() {

void UpdateDownloadDialog::showEvent(QShowEvent* event) {
QDialog::showEvent(event);
#ifdef Q_OS_WIN
taskBarButton->setWindow(windowHandle());
#endif
}
10 changes: 0 additions & 10 deletions src/updatedownloaddialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <QDialog>
#include <QPushButton>

#ifdef Q_OS_WIN
# include <QtWinExtras/QWinTaskbarButton>
#endif

namespace Ui {
class UpdateDownloadDialog;
Expand Down Expand Up @@ -71,13 +68,6 @@ private Q_SLOTS:
* The first action button.
*/
QPushButton* actionButton;

#ifdef Q_OS_WIN
/**
* The windows task-bar button.
*/
QWinTaskbarButton* taskBarButton = nullptr;
#endif
};

#endif // UPDATE_DOWNLOAD_DIALOG_H
Loading