Cleanup: remove redundant QML registrations

This commit is contained in:
Marco Allegretti 2026-01-25 14:08:33 +01:00
parent a0b95fbf9a
commit 49997ed0cb
3 changed files with 68 additions and 34 deletions

58
CLEANUP_NOTES.md Normal file
View file

@ -0,0 +1,58 @@
# Cleanup Notes
## 2026-01-25
This file tracks cleanup/refactor steps taken during a “deep cleanup” pass, with the goal of reducing dead/duplicate code **without changing application functionality**.
### Applied changes
#### 1) Remove duplicate QML type registration in `src/main.cpp`
- **What changed**
- Removed manual `qmlRegisterSingletonType` / `qmlRegisterType` / `qmlRegisterUncreatableType` calls for types already marked with `QML_ELEMENT` / `QML_SINGLETON`.
- **Why**
- The project uses `ecm_add_qml_module(...)` and the generated QML type registration (based on `QML_ELEMENT` / `QML_SINGLETON`) already registers these types.
- Keeping both mechanisms is redundant and risks divergence.
- **Files**
- `src/main.cpp`
#### 2) Remove dead QML state in `src/qml/SettingsPage.qml`
- **What changed**
- Removed unused `pendingDisableImportDelegate` state.
- Simplified `requestDisableImport(...)` to no longer accept an unused `delegate` parameter.
- **Why**
- The variable was assigned/cleared but never read.
- **Files**
- `src/qml/SettingsPage.qml`
#### 3) Stop shipping `FocusableCard.qml` in the QML module (but keep the file)
- **What changed**
- Removed `qml/components/FocusableCard.qml` from the `QML_FILES` list in `ecm_add_qml_module(...)`.
- **Why**
- The component is not referenced anywhere in QML currently.
- We want to keep the implementation around because it may be useful later (e.g. Desktop/Couch mode), but avoid shipping unused module contents.
- **Files**
- `src/CMakeLists.txt`
- Note: `src/qml/components/FocusableCard.qml` still exists in the repository.
### Verification performed
- Built successfully:
- `cmake --build build-debug`
- Quick run smoke test:
- Launches without QML type registration errors.
- Only the existing Kirigami `StackView has detected conflicting anchors` warning was observed.
### Intentional non-changes (paused items)
- Do **not** delete `src/qml/components/FocusableCard.qml` yet.
- Do **not** remove or migrate any persisted `Config` settings or public QML API fields yet.
### How to revert / resume later
- To re-ship `FocusableCard.qml`:
- Add it back to `ecm_add_qml_module(... QML_FILES ...)` in `src/CMakeLists.txt`.
- To fully remove it:
- `git rm src/qml/components/FocusableCard.qml` (only after confirming it is not needed for future UI modes).

View file

@ -15,13 +15,6 @@
#include <KLocalizedString> #include <KLocalizedString>
#include "alakarte-version.h" #include "alakarte-version.h"
#include "app.h"
#include "config.h"
#include "game.h"
#include "gamepadmanager.h"
#include "gamelauncher.h"
#include "gamemodel.h"
#include "gamesortfiltermodel.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
@ -63,19 +56,6 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
qmlRegisterSingletonType<App>("org.kde.alakarte", 1, 0, "App", [](QQmlEngine *engine, QJSEngine *) -> QObject * {
Q_UNUSED(engine)
return App::instance();
});
qmlRegisterSingletonType<GamepadManager>("org.kde.alakarte", 1, 0, "GamepadManager", &GamepadManager::create);
qmlRegisterType<GameModel>("org.kde.alakarte", 1, 0, "GameModel");
qmlRegisterType<GameSortFilterModel>("org.kde.alakarte", 1, 0, "GameSortFilterModel");
qmlRegisterUncreatableType<Game>("org.kde.alakarte", 1, 0, "Game", QStringLiteral("Game objects are created by GameModel"));
qmlRegisterType<GameLauncher>("org.kde.alakarte", 1, 0, "GameLauncher");
qmlRegisterType<Config>("org.kde.alakarte", 1, 0, "Config");
engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
engine.loadFromModule("org.kde.alakarte", "Main"); engine.loadFromModule("org.kde.alakarte", "Main");

View file

@ -18,11 +18,9 @@ ColumnLayout {
} }
property var pendingDisableImportApply: null property var pendingDisableImportApply: null
property var pendingDisableImportDelegate: null
property string pendingDisableImportName: "" property string pendingDisableImportName: ""
function requestDisableImport(delegate, sourceName, applyFn) { function requestDisableImport(sourceName, applyFn) {
pendingDisableImportDelegate = delegate
pendingDisableImportName = sourceName pendingDisableImportName = sourceName
pendingDisableImportApply = applyFn pendingDisableImportApply = applyFn
disableImportConfirmDialog.open() disableImportConfirmDialog.open()
@ -110,7 +108,7 @@ FormCard.FormHeader {
restoring = true restoring = true
checked = Qt.binding(function() { return App.config.importSteam }) checked = Qt.binding(function() { return App.config.importSteam })
restoring = false restoring = false
settingsPage.requestDisableImport(this, i18n("Steam"), function() { App.config.importSteam = false }) settingsPage.requestDisableImport(i18n("Steam"), function() { App.config.importSteam = false })
return return
} }
@ -141,7 +139,7 @@ FormCard.FormHeader {
restoring = true restoring = true
checked = Qt.binding(function() { return App.config.importLutris }) checked = Qt.binding(function() { return App.config.importLutris })
restoring = false restoring = false
settingsPage.requestDisableImport(this, i18n("Lutris"), function() { App.config.importLutris = false }) settingsPage.requestDisableImport(i18n("Lutris"), function() { App.config.importLutris = false })
return return
} }
@ -173,7 +171,7 @@ FormCard.FormHeader {
restoring = true restoring = true
checked = Qt.binding(function() { return App.config.importHeroic }) checked = Qt.binding(function() { return App.config.importHeroic })
restoring = false restoring = false
settingsPage.requestDisableImport(this, i18n("Heroic Games Launcher"), function() { App.config.importHeroic = false }) settingsPage.requestDisableImport(i18n("Heroic Games Launcher"), function() { App.config.importHeroic = false })
return return
} }
@ -205,7 +203,7 @@ FormCard.FormHeader {
restoring = true restoring = true
checked = Qt.binding(function() { return App.config.importDesktop }) checked = Qt.binding(function() { return App.config.importDesktop })
restoring = false restoring = false
settingsPage.requestDisableImport(this, i18n("Desktop Entries"), function() { App.config.importDesktop = false }) settingsPage.requestDisableImport(i18n("Desktop Entries"), function() { App.config.importDesktop = false })
return return
} }
@ -237,7 +235,7 @@ FormCard.FormHeader {
restoring = true restoring = true
checked = Qt.binding(function() { return App.config.importBottles }) checked = Qt.binding(function() { return App.config.importBottles })
restoring = false restoring = false
settingsPage.requestDisableImport(this, i18n("Bottles"), function() { App.config.importBottles = false }) settingsPage.requestDisableImport(i18n("Bottles"), function() { App.config.importBottles = false })
return return
} }
@ -269,7 +267,7 @@ FormCard.FormHeader {
restoring = true restoring = true
checked = Qt.binding(function() { return App.config.importFlatpak }) checked = Qt.binding(function() { return App.config.importFlatpak })
restoring = false restoring = false
settingsPage.requestDisableImport(this, i18n("Flatpak"), function() { App.config.importFlatpak = false }) settingsPage.requestDisableImport(i18n("Flatpak"), function() { App.config.importFlatpak = false })
return return
} }
@ -302,7 +300,7 @@ FormCard.FormHeader {
restoring = true restoring = true
checked = Qt.binding(function() { return App.config.importItch }) checked = Qt.binding(function() { return App.config.importItch })
restoring = false restoring = false
settingsPage.requestDisableImport(this, i18n("itch.io"), function() { App.config.importItch = false }) settingsPage.requestDisableImport(i18n("itch.io"), function() { App.config.importItch = false })
return return
} }
@ -334,7 +332,7 @@ FormCard.FormHeader {
restoring = true restoring = true
checked = Qt.binding(function() { return App.config.importLegendary }) checked = Qt.binding(function() { return App.config.importLegendary })
restoring = false restoring = false
settingsPage.requestDisableImport(this, i18n("Legendary"), function() { App.config.importLegendary = false }) settingsPage.requestDisableImport(i18n("Legendary"), function() { App.config.importLegendary = false })
return return
} }
@ -367,7 +365,7 @@ FormCard.FormHeader {
restoring = true restoring = true
checked = Qt.binding(function() { return App.config.importRetroArch }) checked = Qt.binding(function() { return App.config.importRetroArch })
restoring = false restoring = false
settingsPage.requestDisableImport(this, i18n("RetroArch"), function() { App.config.importRetroArch = false }) settingsPage.requestDisableImport(i18n("RetroArch"), function() { App.config.importRetroArch = false })
return return
} }
@ -560,12 +558,10 @@ FormCard.FormHeader {
settingsPage.pendingDisableImportApply() settingsPage.pendingDisableImportApply()
} }
settingsPage.pendingDisableImportApply = null settingsPage.pendingDisableImportApply = null
settingsPage.pendingDisableImportDelegate = null
settingsPage.pendingDisableImportName = "" settingsPage.pendingDisableImportName = ""
} }
onRejected: { onRejected: {
settingsPage.pendingDisableImportApply = null settingsPage.pendingDisableImportApply = null
settingsPage.pendingDisableImportDelegate = null
settingsPage.pendingDisableImportName = "" settingsPage.pendingDisableImportName = ""
} }
} }