File indexing completed on 2022-09-20 12:32:08

0001 /*
0002     main part of Parley
0003     SPDX-FileCopyrightText: 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
0004     SPDX-FileCopyrightText: 2004-2007 Peter Hedlund <peter.hedlund@kdemail.net>
0005     SPDX-FileCopyrightText: 2007-2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0006     SPDX-FileCopyrightText: 2008 Daniel Laidig <d.laidig@gmx.de>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef PARLEYMAINWINDOW_H
0011 #define PARLEYMAINWINDOW_H
0012 
0013 #include "parleydocument.h"
0014 
0015 #include "practice/sessionmanagercontinuous.h"
0016 #include "practice/sessionmanagerfixed.h"
0017 #include <KXmlGuiWindow>
0018 
0019 #include <QPointer>
0020 
0021 class KRecentFilesAction;
0022 
0023 class ParleyMainWindow : public KXmlGuiWindow
0024 {
0025     Q_OBJECT
0026 
0027 public:
0028     static ParleyMainWindow *instance();
0029 
0030     ~ParleyMainWindow() override;
0031 
0032     /** enum for the different components that can be displayed */
0033     enum Component {
0034         NoComponent,
0035         DashboardComponent,
0036         EditorComponent,
0037         ConfigurePracticeComponent,
0038         PracticeComponent,
0039         PracticeSummary,
0040     };
0041 
0042     /**
0043      * setup the action (menus etc)
0044      */
0045     void initActions();
0046 
0047     /** add a new entry to the list of recent files */
0048     void addRecentFile(const QUrl &url, const QString &name);
0049 
0050     /** save the app-specific options on slotAppExit or by an Options dialog */
0051     void saveOptions();
0052 
0053     /** This will look at the lesson list and also the combo box to determine what should be displayed in the table. */
0054     void updateTableFilter();
0055 
0056     /** update the list of recent files in the dashboard */
0057     void updateRecentFilesModel();
0058 
0059     /**
0060      * Return the ParleyDocument member object
0061      * @return member m_document
0062      */
0063     ParleyDocument *parleyDocument();
0064 
0065     Component currentComponent();
0066 
0067     QSize sizeHint() const override;
0068 
0069 public Q_SLOTS:
0070     /** Updates connections when the ParleyDocument pointer is changed to @p doc **/
0071     void documentUpdated(const std::shared_ptr<KEduVocDocument> &doc);
0072 
0073     /** Opens a dialog for a new collection. **/
0074     void slotFileNew();
0075 
0076     /** Update the title bar of the main window with the current document */
0077     void slotUpdateWindowCaption();
0078 
0079     /** When quitting, ask for confirmation if the doc has not been saved */
0080     bool queryClose() override;
0081 
0082     /** remove an entry from the list of recent files */
0083     void removeRecentFile(const QUrl &url);
0084 
0085     /** set up options */
0086     void slotGeneralOptions();
0087     void slotApplyPreferences();
0088 
0089     void slotCloseDocument();
0090 
0091     void configurePractice();
0092 
0093     void startPractice();
0094     void showPracticeSummary();
0095     void practiceFinished();
0096 
0097     void showDashboard();
0098     void showEditor();
0099     void showPractice();
0100     void showPracticeConfiguration();
0101 
0102     void switchComponent(ParleyMainWindow::Component component);
0103 
0104     /**
0105      * Shows or hides actions that are only relevant when a document is opened
0106      */
0107     void showDocumentActions(bool open, bool edit);
0108 
0109     void setVisibleToolbar(const QString &name);
0110 
0111 Q_SIGNALS:
0112     void recentFilesChanged();
0113     void preferencesChanged();
0114 
0115 private:
0116     ParleyMainWindow(const QUrl &filename = QUrl());
0117     static ParleyMainWindow *s_instance;
0118 
0119     Component m_currentComponent;
0120     KXmlGuiWindow *m_currentComponentWindow{nullptr};
0121 
0122     KRecentFilesAction *m_recentFilesAction{nullptr};
0123 
0124     /** m_document is the current vocabulary document. */
0125     ParleyDocument *m_document{nullptr};
0126 
0127     Component m_componentBeforePractice;
0128 
0129     // Practice::SessionManagerContinuous m_sessionManager;
0130     Practice::SessionManagerFixed m_sessionManager;
0131 
0132     friend int main(int argc, char *argv[]);
0133 };
0134 
0135 #endif // PARLEYMAINWINDOW_H