File indexing completed on 2024-05-26 09:25:00

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef SETTINGSLAYOUTSMODEL_H
0007 #define SETTINGSLAYOUTSMODEL_H
0008 
0009 // local
0010 #include "../../lattecorona.h"
0011 #include "../../data/activitydata.h"
0012 #include "../../data/layoutdata.h"
0013 #include "../../data/layouticondata.h"
0014 #include "../../data/layoutstable.h"
0015 
0016 // Qt
0017 #include <QAbstractTableModel>
0018 #include <QModelIndex>
0019 
0020 
0021 namespace Latte {
0022 namespace Settings {
0023 namespace Model {
0024 
0025 class Layouts : public QAbstractTableModel
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030 
0031     enum Columns
0032     {
0033         IDCOLUMN = 0,
0034         HIDDENTEXTCOLUMN,
0035         BACKGROUNDCOLUMN,
0036         NAMECOLUMN,
0037         MENUCOLUMN,
0038         BORDERSCOLUMN,
0039         ACTIVITYCOLUMN
0040     };
0041 
0042     enum LayoutUserRoles
0043     {
0044         IDROLE = Qt::UserRole + 1,
0045         ISACTIVEROLE,
0046         ISCONSIDEREDACTIVEROLE,
0047         ISLOCKEDROLE,
0048         INMULTIPLELAYOUTSROLE,
0049         BACKGROUNDUSERROLE,
0050         ASSIGNEDACTIVITIESROLE,
0051         ALLACTIVITIESSORTEDROLE,
0052         ALLACTIVITIESDATAROLE,
0053         ALLLAYOUTSROLE,
0054         SORTINGROLE,
0055         ISNEWLAYOUTROLE,
0056         LAYOUTHASCHANGESROLE,
0057         ORIGINALISSHOWNINMENUROLE,
0058         ORIGINALHASBORDERSROLE,
0059         ORIGINALASSIGNEDACTIVITIESROLE,
0060         ERRORSROLE,
0061         WARNINGSROLE
0062     };
0063 
0064     enum SortingPriority
0065     {
0066         NORMALPRIORITY = 8000,
0067         MEDIUMPRIORITY = 6000,
0068         HIGHPRIORITY = 4000,
0069         HIGHESTPRIORITY = 2000
0070     };
0071 
0072     explicit Layouts(QObject *parent, Latte::Corona *corona);
0073     ~Layouts();
0074 
0075     bool containsCurrentName(const QString &name) const;
0076 
0077     bool hasChangedData() const;
0078     bool layoutsAreChanged() const;
0079     bool modeIsChanged() const;
0080 
0081     bool inMultipleMode() const;
0082     void setInMultipleMode(bool inMultiple);
0083 
0084     bool hasEnabledLayout() const;
0085     bool hasEnabledLayoutInAllActitivities() const;
0086     bool hasEnabledLayoutInFreeActivities() const;
0087     bool hasEnabledLayoutInCurrentActivity() const;
0088 
0089     int rowCount() const;
0090     int rowCount(const QModelIndex &parent) const override;
0091     int columnCount(const QModelIndex &parent) const override;
0092 
0093     QString currentActivityId() const;
0094 
0095     QVariant data(const QModelIndex &index, int role) const override;
0096     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0097     Qt::ItemFlags flags(const QModelIndex &index) const override;
0098 
0099     const Latte::Data::Layout &at(const int &row);
0100     const Latte::Data::Layout &currentData(const QString &id);
0101     const Latte::Data::Layout originalData(const QString &id);
0102 
0103     bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0104     bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
0105 
0106     int rowForId(const QString &id) const;
0107 
0108     const Latte::Data::LayoutIcon currentLayoutIcon(const QString &id) const;
0109 
0110     void clear();
0111     //! all current data will become also original
0112     void applyData();
0113     //! all original data will become also current
0114     void resetData();
0115 
0116     void appendOriginalLayout(const Latte::Data::Layout &layout);
0117     void appendLayout(const Latte::Data::Layout &layout);
0118     void removeLayout(const QString &id);
0119     void setLayoutProperties(const Latte::Data::Layout &layout);
0120 
0121     QString layoutNameForFreeActivities() const;
0122     void setCurrentLayoutForFreeActivities(const QString &id);
0123     void setOriginalLayoutForFreeActivities(const QString &id);
0124 
0125     QList<Latte::Data::Layout> alteredLayouts() const;
0126 
0127     const Latte::Data::LayoutsTable &currentLayoutsData();
0128     const Latte::Data::LayoutsTable &originalLayoutsData();
0129 
0130     void setOriginalInMultipleMode(const bool &inmultiple);
0131     void setOriginalData(Latte::Data::LayoutsTable &data);
0132 
0133     void setOriginalActivitiesForLayout(const Latte::Data::Layout &layout);
0134     void setOriginalViewsForLayout(const Latte::Data::Layout &layout);
0135 
0136 signals:
0137     void activitiesStatesChanged();
0138     void inMultipleModeChanged();
0139     void nameDuplicated(const QString &provenId, const QString &trialId);
0140     void rowsInserted();
0141 
0142 private slots:
0143     void updateActiveStates();
0144     void updateConsideredActiveStates();
0145 
0146     void onActivitiesStatesChanged();
0147     void onActivityAdded(const QString &id);
0148     void onActivityRemoved(const QString &id);
0149     void onActivityChanged(const QString &id);
0150     void onRunningActivitiesChanged(const QStringList &runningIds);
0151 
0152 private:
0153     void initActivities();
0154 
0155     void setActivities(const int &row, const QStringList &activities);
0156     void setId(const int &row, const QString &newId);
0157 
0158     bool containsSpecificRunningActivity(const QStringList &runningIds, const Latte::Data::Layout &layout) const;
0159 
0160     QString sortingPriority(const SortingPriority &priority, const int &row) const;
0161     QString sortableText(const int &priority, const int &row) const;
0162 
0163     QStringList cleanStrings(const QStringList &original, const QStringList &occupied);
0164 
0165     Latte::Data::LayoutIcon icon(const int &row) const;
0166 
0167 private:
0168     Latte::Data::ActivitiesTable m_activitiesTable;
0169     QHash<QString, KActivities::Info *> m_activitiesInfo;
0170 
0171     //! original data
0172     bool o_inMultipleMode{false};
0173     Latte::Data::LayoutsTable o_layoutsTable;
0174 
0175     //! current data
0176     bool m_inMultipleMode{false};
0177     Latte::Data::LayoutsTable m_layoutsTable;
0178 
0179     Latte::Corona *m_corona{nullptr};
0180 };
0181 
0182 }
0183 }
0184 }
0185 
0186 #endif