Skip to content

Commit

Permalink
Clean up print duplication and conditional compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Lamar committed Mar 3, 2024
1 parent d842a28 commit e543bbc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
20 changes: 8 additions & 12 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,21 +216,17 @@ void KiwixApp::printPage()
if(!webview)
return;

const auto onPrintFinished = [=](bool success) {
if (!success) {
showMessage(gt("print-page-error"), gt("error-title"), QMessageBox::Critical);
}
delete printer;
};
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
webview->page()->print(printer, [=](bool success) {
if (!success) {
showMessage(gt("print-page-error"), gt("error-title"), QMessageBox::Critical);
}
delete printer;
});
webview->page()->print(printer, onPrintFinished);
#else
webview->print(printer);
connect(webview, &QWebEngineView::printFinished, this, [=](bool success) {
if (!success) {
showMessage(gt("print-page-error"), gt("error-title"), QMessageBox::Critical);
}
delete printer;
});
connect(webview, &QWebEngineView::printFinished, this, onPrintFinished);
#endif
}
}
Expand Down
20 changes: 13 additions & 7 deletions src/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,21 @@ void SettingsManager::initSettings()
m_moveToTrash = m_settings.value("moveToTrash", true).toBool();
QString defaultLang = QLocale::languageToString(QLocale().language()) + '|' + QLocale().name().split("_").at(0);

QList<QString> defaultLangList; // Qt5 QList doesn't support supplying a constructor list, so use append() for Qt5+Qt6 compat
/*
* Qt5 & Qt6 have slightly different behaviors with regards to initializing QVariant.
* The below approach is specifically chosen to work with both versions.
* m_langList initialized with defaultLang should be of the form:
*
* (QVariant(QString, "English|en"))
*
* and not
*
* QList(QVariant(QChar, 'E'), QVariant(QChar, 'n'), QVariant(QChar, 'g'), ...
*/
QList<QString> defaultLangList; // Qt5 QList doesn't support supplying a constructor list
defaultLangList.append(defaultLang);

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QVariant defaultLangVariant(defaultLangList); // Qt5 requires explicit conversion from QList to QVariant
QVariant defaultLangVariant(defaultLangList);
m_langList = m_settings.value("language", defaultLangVariant).toList();
#else
m_langList = m_settings.value("language", defaultLangList).toList();
#endif

m_categoryList = m_settings.value("category", {}).toList();
m_contentTypeList = m_settings.value("contentType", {}).toList();
Expand Down
3 changes: 0 additions & 3 deletions subprojects/QtSingleApplication/src/qtlockedfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ namespace QtLP_Private {

class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile
{
//Q_OBJECT
// TODO: Uncomment Q_OBJECT. Setting Q_OBJECT here causes this error:
// undefined reference to `vtable for QtLP_Private::QtLockedFile'
public:
enum LockMode { NoLock = 0, ReadLock, WriteLock };

Expand Down

0 comments on commit e543bbc

Please sign in to comment.