diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2968327..036bada 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,142 +1,86 @@ /* * Copyright 2013-2015 Andreas Cord-Landwehr * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ #include "mainwindow.h" #include "application.h" #include "artikulate_debug.h" #include "core/editorsession.h" #include "core/resourcerepository.h" #include "core/resources/courseresource.h" #include "core/trainingsession.h" #include "liblearnerprofile/src/learner.h" #include "liblearnerprofile/src/profilemanager.h" #include "libsound/src/outputdevicecontroller.h" #include "models/languagemodel.h" #include "settings.h" - #include #include -#include #include #include #include -#include #include - #include #include #include #include #include using namespace LearnerProfile; MainWindow::MainWindow() - : m_actionCollection(new KActionCollection(this, QStringLiteral("artikulate"))) - , m_profileManager(new LearnerProfile::ProfileManager(this)) + : m_profileManager(new LearnerProfile::ProfileManager(this)) , m_trainingSession(new TrainingSession(m_profileManager, this)) { rootContext()->setContextObject(new KLocalizedContext(this)); // load saved sound settings OutputDeviceController::self().setVolume(Settings::audioOutputVolume()); - // create menu - setupActions(); - // set view rootContext()->setContextProperty(QStringLiteral("g_trainingSession"), m_trainingSession); rootContext()->setContextProperty(QStringLiteral("g_profileManager"), m_profileManager); rootContext()->setContextProperty(QStringLiteral("g_artikulateAboutData"), QVariant::fromValue(KAboutData::applicationData())); // set starting screen load(QUrl(QStringLiteral("qrc:/artikulate/qml/Main.qml"))); // create training profile if none exists: if (!m_profileManager->activeProfile()) { m_profileManager->addProfile(i18n("Unnamed Identity")); } // connect to QML signals; connect(rootObjects().constFirst(), SIGNAL(ghnsCourseDataStatusChanged()), this, SLOT(updateCourseResources())); - connect(rootObjects().constFirst(), SIGNAL(triggerAction(QString)), this, SLOT(triggerAction(QString))); - - // set font for the phrase in trainer to default from kcfg file - QObject *phraseText = rootObjects().constFirst()->findChild(QStringLiteral("phraseText")); - if (phraseText) { - phraseText->setProperty("font", Settings::trainingPhraseFont()); - } } MainWindow::~MainWindow() { // save current settings for case of closing Settings::self()->save(); m_profileManager->sync(); } -KActionCollection *MainWindow::actionCollection() -{ - return m_actionCollection; -} - -void MainWindow::setupActions() -{ - QAction *configLearnerProfileAction = new QAction(i18nc("@item:inmenu", "Learner Profile"), this); - connect(configLearnerProfileAction, &QAction::triggered, this, &MainWindow::configLearnerProfile); - actionCollection()->addAction(QStringLiteral("config_learner_profile"), configLearnerProfileAction); - configLearnerProfileAction->setIcon(QIcon::fromTheme(QStringLiteral("user-identity"))); - - KStandardAction::quit(qApp, SLOT(quit()), actionCollection()); -} - void MainWindow::updateCourseResources() { artikulateApp->resourceRepository()->reloadCourses(); } -void MainWindow::updateTrainingPhraseFont() -{ - QObject *phraseText = rootObjects().constFirst()->findChild(QStringLiteral("phraseText")); - if (!phraseText) { - qCDebug(ARTIKULATE_LOG) << "no phraseText context object found, aborting"; - return; - } - phraseText->setProperty("font", Settings::trainingPhraseFont()); -} - void MainWindow::updateKcfgUseContributorResources() { rootContext()->setContextProperty(QStringLiteral("kcfg_UseContributorResources"), Settings::useCourseRepository()); } void MainWindow::configLearnerProfile() { qCritical() << "Not implemented"; // FIXME } -void MainWindow::triggerAction(const QString &actionName) -{ - QAction *action = actionCollection()->action(actionName); - if (action) { - action->trigger(); - } else { - qCritical() << "Action is not registered:" << actionName; - } -} - -void MainWindow::switchMenuBarVisibility() -{ - Settings::setShowMenuBar(!Settings::showMenuBar()); - rootContext()->setContextProperty(QStringLiteral("kcfg_ShowMenuBar"), Settings::showMenuBar()); -} - bool MainWindow::queryClose() { Settings::self()->save(); // FIXME make sure all learner data is written to database return true; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 2997dab..9b4816b 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -1,58 +1,52 @@ /* * Copyright 2013-2015 Andreas Cord-Landwehr * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include "core/resourcerepository.h" #include #include class TrainingSession; class KHelpMenu; namespace LearnerProfile { class ProfileManager; } class MainWindow : public QQmlApplicationEngine { Q_OBJECT public: /** * Default Constructor */ MainWindow(); /** * Default Destructor */ ~MainWindow() override; const IResourceRepository *resourceRepository() const; - KActionCollection *actionCollection(); void setupActions(); bool queryClose(); public Q_SLOTS: void updateCourseResources(); - void updateTrainingPhraseFont(); void updateKcfgUseContributorResources(); void configLearnerProfile(); - void switchMenuBarVisibility(); - void triggerAction(const QString &); private: - KActionCollection *m_actionCollection; - KHelpMenu *m_helpMenu; LearnerProfile::ProfileManager *m_profileManager; TrainingSession *m_trainingSession; }; #endif