/* === This file is part of Calamares - === * * Copyright 2014-2015, Teo Mrnjavac * Copyright 2017-2018, Adriaan de Groot * * Calamares is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Calamares is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Calamares. If not, see . */ #ifndef VIEWMANAGER_H #define VIEWMANAGER_H #include "DllMacro.h" #include "viewpages/ViewStep.h" #include #include #include #include namespace Calamares { /** * @brief The ViewManager class handles progression through view pages. * @note Singleton object, only use through ViewManager::instance(). */ class UIDLLEXPORT ViewManager : public QAbstractListModel { Q_OBJECT Q_PROPERTY( int currentStepIndex READ currentStepIndex NOTIFY currentStepChanged FINAL ) Q_PROPERTY( bool nextEnabled READ nextEnabled NOTIFY nextEnabledChanged FINAL ) Q_PROPERTY( QString nextLabel READ nextLabel NOTIFY nextLabelChanged FINAL ) Q_PROPERTY( QString nextIcon READ nextIcon NOTIFY nextIconChanged FINAL ) public: /** * @brief instance access to the ViewManager singleton. * @return pointer to the singleton instance. */ static ViewManager* instance(); static ViewManager* instance( QObject* parent ); /** * @brief centralWidget always returns the central widget in the Calamares main * window. * @return a pointer to the active QWidget (usually a wizard page provided by a * view module). */ QWidget* centralWidget(); /** * @brief addViewStep appends a view step to the roster. * @param step a pointer to the ViewStep object to add. * @note a ViewStep is the active instance of a view module, it aggregates one * or more view pages, plus zero or more jobs which may be created at runtime. */ void addViewStep( ViewStep* step ); /** * @brief viewSteps returns the list of currently present view steps. * @return the ViewStepList. * This should only return an empty list before startup is complete. */ ViewStepList viewSteps() const; /** * @brief currentStep returns the currently active ViewStep, i.e. the ViewStep * which owns the currently visible view page. * @return the active ViewStep. Do not confuse this with centralWidget(). * @see ViewStep::centralWidget */ ViewStep* currentStep() const; /** * @brief currentStepIndex returns the index of the currently active ViewStep. * @return the index. */ int currentStepIndex() const; /** * @ brief Called when "Cancel" is clicked; asks for confirmation. * Other means of closing Calamares also call this method, e.g. alt-F4. * At the end of installation, no confirmation is asked. Returns true * if the user confirms closing the window. */ bool confirmCancelInstallation(); public Q_SLOTS: /** * @brief next moves forward to the next page of the current ViewStep (if any), * or to the first page of the next ViewStep if the current ViewStep doesn't * have any more pages. */ void next(); bool nextEnabled() const { return m_nextEnabled; ///< Is the next-button to be enabled } QString nextLabel() const { return m_nextLabel; ///< What should be displayed on the next-button } QString nextIcon() const { return m_nextIcon; ///< Name of the icon to show } /** * @brief back moves backward to the previous page of the current ViewStep (if any), * or to the last page of the previous ViewStep if the current ViewStep doesn't * have any pages before the current one. */ void back(); /** * @brief Probably quit * * Asks for confirmation if necessary. Terminates the application. */ void quit(); /** * @brief onInstallationFailed displays an error message when a fatal failure * happens in a ViewStep. * @param message the error string. * @param details the details string. */ void onInstallationFailed( const QString& message, const QString& details ); /** @brief Replaces the stack with a view step stating that initialization failed. * * @param modules a list of failed modules. */ void onInitFailed( const QStringList& modules ); signals: void currentStepChanged(); void enlarge( QSize enlarge ) const; // See ViewStep::enlarge() void cancelEnabled( bool enabled ) const; void nextEnabledChanged( bool ) const; void nextLabelChanged( QString ) const; void nextIconChanged( QString ) const; private: explicit ViewManager( QObject* parent = nullptr ); virtual ~ViewManager() override; void insertViewStep( int before, ViewStep* step ); void updateButtonLabels(); void updateCancelEnabled( bool enabled ); static ViewManager* s_instance; ViewStepList m_steps; int m_currentStep; QWidget* m_widget; QStackedWidget* m_stack; QPushButton* m_back; QPushButton* m_quit; bool m_nextEnabled = false; QString m_nextLabel; QString m_nextIcon; ///< Name of icon to show on button public: /** @section Model * * These are the methods and enums used for the as-a-model part * of the ViewManager. */ enum Role { ProgressTreeItemCurrentIndex = Qt::UserRole + 13 ///< Index (row) of the current step }; QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override; int rowCount( const QModelIndex& parent = QModelIndex() ) const override; }; } // namespace Calamares #endif // VIEWMANAGER_H