From fc67c0d76c4193216d0bda61adb2be87bdbc1db2 Mon Sep 17 00:00:00 2001 From: Adam Lamar Date: Fri, 8 Mar 2024 04:24:31 +0000 Subject: [PATCH] Fix warnings and enable Werror --- kiwix-desktop.pro | 2 +- src/contentmanager.cpp | 7 ++++++- src/contentmanagerdelegate.cpp | 4 ++++ src/kiwixapp.cpp | 29 ++++++++++++++++------------- src/kiwixapp.h | 1 + src/kiwixlineedit.cpp | 2 ++ src/kiwixloader.cpp | 2 ++ src/library.cpp | 2 +- 8 files changed, 33 insertions(+), 16 deletions(-) diff --git a/kiwix-desktop.pro b/kiwix-desktop.pro index 74ec467..7e184f6 100644 --- a/kiwix-desktop.pro +++ b/kiwix-desktop.pro @@ -15,7 +15,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = kiwix-desktop TEMPLATE = app -QMAKE_CXXFLAGS += -std=c++17 +QMAKE_CXXFLAGS += -std=c++17 -Werror QMAKE_LFLAGS += -std=c++17 # Also change resources/org.kiwix.desktop.appdata.xml diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 6e1a7e4..ddfdf13 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -543,6 +543,9 @@ void ContentManager::downloadBook(const QString &id) void ContentManager::eraseBookFilesFromComputer(const QString dirPath, const QString fileName, const bool moveToTrash) { +#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) + Q_UNUSED(moveToTrash); +#endif if (fileName == "*") { return; } @@ -638,6 +641,8 @@ void ContentManager::resumeBook(const QString& id) void ContentManager::cancelBook(const QString& id, QModelIndex index) { + Q_UNUSED(index); + auto text = gt("cancel-download-text"); text = text.replace("{{ZIM}}", QString::fromStdString(mp_library->getBookById(id).getTitle())); showConfirmBox(gt("cancel-download"), text, mp_view, [=]() { @@ -738,7 +743,7 @@ QString makeHttpUrl(QString host, int port) } // unnamed namespace void ContentManager::updateRemoteLibrary(const QString& content) { - QtConcurrent::run([=]() { + (void) QtConcurrent::run([=]() { QMutexLocker locker(&remoteLibraryLocker); mp_remoteLibrary = kiwix::Library::create(); kiwix::Manager manager(mp_remoteLibrary); diff --git a/src/contentmanagerdelegate.cpp b/src/contentmanagerdelegate.cpp index b1fb12d..c143946 100644 --- a/src/contentmanagerdelegate.cpp +++ b/src/contentmanagerdelegate.cpp @@ -210,6 +210,8 @@ void ContentManagerDelegate::paint(QPainter *painter, const QStyleOptionViewItem bool ContentManagerDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { + Q_UNUSED(model); + if(event->type() == QEvent::MouseButtonRelease ) { QMouseEvent * e = (QMouseEvent *)event; @@ -270,6 +272,8 @@ void ContentManagerDelegate::handleLastColumnClicked(const QModelIndex& index, Q QSize ContentManagerDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { + Q_UNUSED(option); + if (index.parent().isValid()) { return QSize(300, 70); } diff --git a/src/kiwixapp.cpp b/src/kiwixapp.cpp index cdbac48..761e23d 100644 --- a/src/kiwixapp.cpp +++ b/src/kiwixapp.cpp @@ -41,17 +41,14 @@ KiwixApp::KiwixApp(int& argc, char *argv[]) QMessageBox::critical(nullptr, "Translation error", e.what()); return; } -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - m_qtTranslator.load(QLocale(), "qt", "_", - QLibraryInfo::location(QLibraryInfo::TranslationsPath)); -#else - m_qtTranslator.load(QLocale(), "qt", "_", - QLibraryInfo::path(QLibraryInfo::TranslationsPath)); -#endif - installTranslator(&m_qtTranslator); - m_appTranslator.load(QLocale(), "kiwix-desktop", "_", ":/i18n/"); - installTranslator(&m_appTranslator); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QString path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); +#else + QString path = QLibraryInfo::path(QLibraryInfo::TranslationsPath); +#endif + loadAndInstallTranslations(m_qtTranslator, "qt", path); + loadAndInstallTranslations(m_appTranslator, "kiwix-desktop", ":/i18n/"); QFontDatabase::addApplicationFont(":/fonts/Selawik/selawkb.ttf"); QFontDatabase::addApplicationFont(":/fonts/Selawik/selawkl.ttf"); @@ -61,6 +58,12 @@ KiwixApp::KiwixApp(int& argc, char *argv[]) setFont(QFont("Selawik")); } +void KiwixApp::loadAndInstallTranslations(QTranslator& translator, const QString& filename, const QString& directory) { + if (translator.load(QLocale(), filename, "_", directory)) { + installTranslator(&translator); + } +} + void KiwixApp::init() { try { @@ -441,10 +444,10 @@ void KiwixApp::createActions() mpa_actions[FindInPageAction]->setShortcuts({QKeySequence::Find, Qt::Key_F3}); connect(mpa_actions[FindInPageAction], &QAction::triggered, this, [=]() { getTabWidget()->openFindInPageBar(); }); - + const auto fullScreenKeySeq = QKeySequence(QKeySequence::FullScreen).isEmpty() - ? Qt::Key_F11 - : QKeySequence::FullScreen; + ? (int) Qt::Key_F11 + : (int) QKeySequence::FullScreen; CREATE_ACTION_ICON_SHORTCUT(ToggleFullscreenAction, "full-screen-enter", gt("set-fullscreen"), fullScreenKeySeq); connect(mpa_actions[ToggleFullscreenAction], &QAction::toggled, this, [=](bool checked) { diff --git a/src/kiwixapp.h b/src/kiwixapp.h index 0daece6..ee7901e 100644 --- a/src/kiwixapp.h +++ b/src/kiwixapp.h @@ -123,6 +123,7 @@ private: QString findLibraryDirectory(); void restoreTabs(); + void loadAndInstallTranslations(QTranslator& translator, const QString& filename, const QString& directory); }; QString gt(const QString &key); diff --git a/src/kiwixlineedit.cpp b/src/kiwixlineedit.cpp index ca5ca1e..1f03ced 100644 --- a/src/kiwixlineedit.cpp +++ b/src/kiwixlineedit.cpp @@ -16,6 +16,8 @@ void KiwixLineEdit::resizeEvent(QResizeEvent *event) } bool KiwixLineEdit::eventFilter(QObject* object, QEvent* event) { + Q_UNUSED(object); + if (event->type() == QEvent::MouseButtonPress) { emit(clicked()); } else if (event->type() == QEvent::FocusIn) { diff --git a/src/kiwixloader.cpp b/src/kiwixloader.cpp index d6aaeb9..b4c5063 100644 --- a/src/kiwixloader.cpp +++ b/src/kiwixloader.cpp @@ -41,6 +41,8 @@ void createArc(QPainter &painter, int startAngle, int spanAngle, QRect rectangle void KiwixLoader::paintEvent(QPaintEvent *event) { + Q_UNUSED(event); + QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); diff --git a/src/library.cpp b/src/library.cpp index 5937f1b..94ff105 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -170,7 +170,7 @@ void Library::updateFromDir(QString monitorDir) void Library::asyncUpdateFromDir(QString dir) { - QtConcurrent::run( [=]() { + (void) QtConcurrent::run([=]() { updateFromDir(dir); }); }