File indexing completed on 2024-12-01 13:37:51

0001 /*
0002 *  Copyright 2019  Michail Vourlakos <mvourlakos@gmail.com>
0003 *
0004 *  This file is part of Latte-Dock
0005 *
0006 *  Latte-Dock is free software; you can redistribute it and/or
0007 *  modify it under the terms of the GNU General Public License as
0008 *  published by the Free Software Foundation; either version 2 of
0009 *  the License, or (at your option) any later version.
0010 *
0011 *  Latte-Dock is distributed in the hope that it will be useful,
0012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 *  GNU General Public License for more details.
0015 *
0016 *  You should have received a copy of the GNU General Public License
0017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 
0020 #ifndef ABSTRACTLAYOUT_H
0021 #define ABSTRACTLAYOUT_H
0022 
0023 // Qt
0024 #include <QObject>
0025 
0026 // KDE
0027 #include <KConfigGroup>
0028 
0029 // Plasma
0030 #include <Plasma>
0031 
0032 namespace Plasma {
0033 class Types;
0034 }
0035 
0036 namespace Latte {
0037 namespace Layout {
0038 Q_NAMESPACE
0039 
0040 enum Type {
0041     Abstract = 0,
0042     Generic,
0043     Central,
0044     Shared
0045 };
0046 Q_ENUM_NS(Type);
0047 
0048 }
0049 }
0050 
0051 namespace Latte {
0052 namespace Layout {
0053 
0054 class AbstractLayout : public QObject
0055 {
0056     Q_OBJECT
0057     Q_PROPERTY(QString name READ name NOTIFY nameChanged)
0058 
0059     Q_PROPERTY(bool preferredForShortcutsTouched READ preferredForShortcutsTouched WRITE setPreferredForShortcutsTouched NOTIFY preferredForShortcutsTouchedChanged)
0060 
0061     Q_PROPERTY(QString background READ background NOTIFY backgroundChanged)
0062     Q_PROPERTY(QString color READ color WRITE setColor NOTIFY colorChanged)
0063     Q_PROPERTY(QString lastUsedActivity READ lastUsedActivity NOTIFY lastUsedActivityChanged)
0064     Q_PROPERTY(QString textColor READ textColor NOTIFY textColorChanged)
0065 
0066     Q_PROPERTY(QStringList launchers READ launchers WRITE setLaunchers NOTIFY launchersChanged)
0067 
0068 public:
0069     AbstractLayout(QObject *parent, QString layoutFile, QString assignedName = QString());
0070     ~AbstractLayout() override;
0071 
0072     static const QString MultipleLayoutsName;
0073 
0074     int version() const;
0075     void setVersion(int ver);
0076 
0077     bool preferredForShortcutsTouched() const;
0078     void setPreferredForShortcutsTouched(bool touched);
0079 
0080     QString lastUsedActivity();
0081     void clearLastUsedActivity(); //!e.g. when we export a layout
0082 
0083     QString name() const;
0084     QString file() const;
0085 
0086     QString background() const;
0087     void setBackground(QString path);
0088 
0089     QString color() const;
0090     void setColor(QString color);
0091 
0092     QString textColor() const;
0093     void setTextColor(QString color);
0094 
0095     QStringList launchers() const;
0096     void setLaunchers(QStringList launcherList);
0097 
0098     virtual Type type() const;
0099 
0100 // STATIC
0101     static QString layoutName(const QString &fileName);
0102     static QList<Plasma::Types::Location> combinedFreeEdges(const QList<Plasma::Types::Location> &edges1,
0103                                                             const QList<Plasma::Types::Location> &edges2);
0104 
0105 signals:
0106     void backgroundChanged();
0107     void colorChanged();
0108     void fileChanged();
0109     void lastUsedActivityChanged();
0110     void launchersChanged();
0111     void nameChanged();
0112     void preferredForShortcutsTouchedChanged();
0113     void textColorChanged();
0114     void versionChanged();
0115 
0116 protected slots:
0117     void loadConfig();
0118     void saveConfig();
0119 
0120 protected:
0121     void init();
0122     void setName(QString name);
0123     void setFile(QString file);
0124 
0125 protected:
0126     bool m_loadedCorrectly{false};
0127     bool m_preferredForShortcutsTouched{false};
0128 
0129     //if version doesn't exist it is and old layout file
0130     int m_version{2};
0131 
0132     QString m_background;
0133     QString m_color;
0134     QString m_lastUsedActivity; //the last used activity for this layout
0135 
0136     QString m_textColor;
0137 
0138     QString m_layoutFile;
0139     QString m_layoutName;
0140 
0141     QStringList m_launchers;
0142 
0143     KConfigGroup m_layoutGroup;
0144 };
0145 
0146 }
0147 }
0148 
0149 #endif