File indexing completed on 2024-04-14 05:24:33

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef SETTINGSLAYOUTSCONTROLLER_H
0007 #define SETTINGSLAYOUTSCONTROLLER_H
0008 
0009 // local
0010 #include <coretypes.h>
0011 #include "layoutsheaderview.h"
0012 #include "layoutsmodel.h"
0013 #include "../../lattecorona.h"
0014 #include "../../data/layoutdata.h"
0015 #include "../../data/layoutstable.h"
0016 #include "../../data/screendata.h"
0017 #include "../../layout/centrallayout.h"
0018 
0019 // Qt
0020 #include <QAbstractItemModel>
0021 #include <QHash>
0022 #include <QSortFilterProxyModel>
0023 #include <QTableView>
0024 
0025 
0026 namespace Latte {
0027 class Corona;
0028 class CentralLayout;
0029 class SettingsDialog;
0030 
0031 namespace Settings {
0032 namespace Handler {
0033 class TabLayouts;
0034 }
0035 namespace Part{
0036 class TemplatesKeeper;
0037 }
0038 }
0039 }
0040 
0041 namespace Latte {
0042 namespace Settings {
0043 namespace Controller {
0044 
0045 class Layouts : public QObject
0046 {
0047     Q_OBJECT
0048 
0049 public:
0050     explicit Layouts(Settings::Handler::TabLayouts *parent);
0051     ~Layouts();
0052 
0053     QAbstractItemModel *proxyModel() const;
0054     QAbstractItemModel *baseModel() const;
0055     QTableView *view() const;
0056     Settings::Part::TemplatesKeeper *templatesKeeper() const;
0057 
0058     bool hasChangedData() const;
0059     bool layoutsAreChanged() const;
0060     bool modeIsChanged() const;
0061 
0062     bool inMultipleMode() const;
0063     void setInMultipleMode(bool inMultiple);
0064     void sortByColumn(int column, Qt::SortOrder order);
0065 
0066     bool hasSelectedLayout() const;
0067     bool isSelectedLayoutOriginal() const;
0068     bool isLayoutOriginal(const QString &currentLayoutId) const;
0069     const Latte::Data::Layout selectedLayoutCurrentData() const;
0070     const Latte::Data::Layout selectedLayoutOriginalData() const;
0071     const Latte::Data::LayoutIcon selectedLayoutIcon() const;
0072     const Latte::Data::ViewsTable selectedLayoutViews();
0073 
0074     const Latte::Data::Layout currentData(const QString &currentLayoutId) const;
0075     const Latte::Data::Layout originalData(const QString &currentLayoutId) const;
0076 
0077     void selectRow(const QString &id);
0078     void setLayoutProperties(const Latte::Data::Layout &layout);
0079 
0080     //! actions
0081     void reset();
0082     void save();
0083     void removeSelected();
0084     void toggleEnabledForSelected();
0085     void toggleLockedForSelected();    
0086 
0087     QString iconsPath() const;
0088     QString colorPath(const QString color) const;
0089 
0090     QString layoutNameForFreeActivities() const;
0091     void setOriginalLayoutForFreeActivities(const QString &id);
0092 
0093     void setOriginalInMultipleMode(const bool &inmultiple);
0094     void setLayoutCurrentErrorsWarnings(const QString &layoutCurrentId, const int &errors, const int &warnings);
0095 
0096     void duplicateSelectedLayout();
0097     const Latte::Data::Layout addLayoutForFile(QString file, QString layoutName = QString(), bool newTempDirectory = true);
0098     const Latte::Data::Layout addLayoutByText(QString rawLayoutText);
0099 
0100     CentralLayout *centralLayout(const QString &currentLayoutId);
0101 
0102     const Latte::Data::ScreensTable screensData();
0103 
0104     //! import layouts from Latte versions <= v0.7.x
0105     bool importLayoutsFromV1ConfigFile(QString file);
0106 
0107 signals:
0108     void dataChanged();
0109 
0110 private slots:
0111     void initLayouts();
0112     void loadConfig();
0113     void saveConfig();
0114     void storeColumnWidths(bool inMultipleMode);
0115     void applyColumnWidths(bool storeValues = false);
0116 
0117     void showInitialErrorWarningMessages();
0118 
0119     void onCurrentRowChanged();
0120     void onNameDuplicatedFrom(const QString &provenId,  const QString &trialId);
0121     void onLayoutAddedExternally(const Data::Layout &layout);
0122     void onLayoutActivitiesChangedExternally(const Data::Layout &layout);  
0123 
0124 private:
0125     void initView();
0126 
0127     int rowForId(QString id) const;
0128     int rowForName(QString layoutName) const;
0129 
0130     QString uniqueTempDirectory();
0131     QString uniqueLayoutName(QString name);
0132 
0133     QList<int> join(const QList<int> &currentRecords, const QList<int> &newRecords);
0134 
0135     void initialMessageForErroredLayouts(const int &count);
0136     void initialMessageForWarningLayouts(const int &count);
0137     void messageForErroredLayout(const Data::Layout &layout);
0138 
0139 private:
0140     Settings::Handler::TabLayouts *m_handler{nullptr};
0141     Settings::Part::TemplatesKeeper *m_templatesKeeper{nullptr};
0142 
0143     bool m_hasShownInitialErrorWarningMessages{false};
0144 
0145     QString m_iconsPath;
0146 
0147     QTableView *m_view{nullptr};
0148     Settings::Layouts::HeaderView *m_headerView{nullptr};
0149 
0150     //! layoutsView ui settings
0151     int m_viewSortColumn;
0152     Qt::SortOrder m_viewSortOrder;
0153     QStringList m_viewColumnWidths;
0154 
0155     KConfigGroup m_storage;
0156 
0157     //! current data
0158     Model::Layouts *m_model{nullptr};
0159     QSortFilterProxyModel *m_proxyModel{nullptr};
0160 
0161     //! temp data
0162     QStringList m_tempDirectories;
0163 };
0164 
0165 }
0166 }
0167 }
0168 
0169 #endif