mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
working load and save of order and favs
This commit is contained in:
parent
a1a8e00201
commit
62de2cb1be
5 changed files with 34 additions and 49 deletions
|
|
@ -37,12 +37,20 @@
|
||||||
#include <KIOWidgets/KRun>
|
#include <KIOWidgets/KRun>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
ApplicationListModel::ApplicationListModel(QObject *parent)
|
ApplicationListModel::ApplicationListModel(HomeScreen *parent)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent),
|
||||||
|
m_homeScreen(parent)
|
||||||
{
|
{
|
||||||
//can't use the new syntax as this signal is overloaded
|
//can't use the new syntax as this signal is overloaded
|
||||||
connect(KSycoca::self(), SIGNAL(databaseChanged(const QStringList &)),
|
connect(KSycoca::self(), SIGNAL(databaseChanged(const QStringList &)),
|
||||||
this, SLOT(sycocaDbChanged(const QStringList &)));
|
this, SLOT(sycocaDbChanged(const QStringList &)));
|
||||||
|
m_favorites = m_homeScreen->config().readEntry("Favorites", QStringList());
|
||||||
|
m_appOrder = m_homeScreen->config().readEntry("AppOrder", QStringList());
|
||||||
|
int i = 0;
|
||||||
|
for (auto app : m_appOrder) {
|
||||||
|
m_appPositions[app] = i;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
//here or delayed?
|
//here or delayed?
|
||||||
loadApplications();
|
loadApplications();
|
||||||
}
|
}
|
||||||
|
|
@ -104,8 +112,6 @@ void ApplicationListModel::loadApplications()
|
||||||
|
|
||||||
int i = 0; // for default bookmarks
|
int i = 0; // for default bookmarks
|
||||||
|
|
||||||
m_favoriteCount = 0;
|
|
||||||
|
|
||||||
// Iterate over all entries in the group
|
// Iterate over all entries in the group
|
||||||
while (!subGroupList.isEmpty()) {
|
while (!subGroupList.isEmpty()) {
|
||||||
KSycocaEntry::Ptr groupEntry = subGroupList.first();
|
KSycocaEntry::Ptr groupEntry = subGroupList.first();
|
||||||
|
|
@ -142,20 +148,16 @@ void ApplicationListModel::loadApplications()
|
||||||
data.storageId = service->storageId();
|
data.storageId = service->storageId();
|
||||||
data.entryPath = service->exec();
|
data.entryPath = service->exec();
|
||||||
|
|
||||||
|
if (m_favorites.contains(data.storageId)) {
|
||||||
|
data.location = Favorites;
|
||||||
|
}
|
||||||
|
|
||||||
auto it = m_appPositions.constFind(service->storageId());
|
auto it = m_appPositions.constFind(service->storageId());
|
||||||
if (it != m_appPositions.constEnd()) {
|
if (it != m_appPositions.constEnd()) {
|
||||||
//TODO: proper bookmarks
|
|
||||||
data.location = (*it) < 6 ? Favorites : Grid;
|
|
||||||
orderedList[*it] = data;
|
orderedList[*it] = data;
|
||||||
} else {
|
} else {
|
||||||
//TODO: proper bookmarks
|
|
||||||
data.location = (++i + m_appPositions.size() < 6) ? Favorites : Grid;
|
|
||||||
unorderedList << data;
|
unorderedList << data;
|
||||||
}
|
}
|
||||||
if (data.location == Favorites) {
|
|
||||||
++m_favoriteCount;
|
|
||||||
}
|
|
||||||
emit favoriteCountChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -234,10 +236,12 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (location == Favorites) {
|
if (location == Favorites) {
|
||||||
++m_favoriteCount;
|
m_favorites.insert(row, data.storageId);
|
||||||
|
m_homeScreen->config().writeEntry("Favorites", m_favorites);
|
||||||
emit favoriteCountChanged();
|
emit favoriteCountChanged();
|
||||||
} else if (data.location == Favorites) {
|
} else if (data.location == Favorites) {
|
||||||
m_favoriteCount = qMax(0, m_favoriteCount - 1);
|
m_favorites.removeAll(data.storageId);
|
||||||
|
m_homeScreen->config().writeEntry("Favorites", m_favorites);
|
||||||
emit favoriteCountChanged();
|
emit favoriteCountChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -276,8 +280,8 @@ void ApplicationListModel::moveItem(int row, int destination)
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_homeScreen->config().writeEntry("AppOrder", m_appOrder);
|
||||||
|
|
||||||
emit appOrderChanged();
|
|
||||||
endMoveRows();
|
endMoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -292,23 +296,5 @@ void ApplicationListModel::runApplication(const QString &storageId)
|
||||||
KRun::runService(*service, QList<QUrl>(), nullptr);
|
KRun::runService(*service, QList<QUrl>(), nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ApplicationListModel::appOrder() const
|
#include "moc_applicationlistmodel.cpp"
|
||||||
{
|
|
||||||
return m_appOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationListModel::setAppOrder(const QStringList &order)
|
|
||||||
{
|
|
||||||
if (m_appOrder == order) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_appOrder = order;
|
|
||||||
m_appPositions.clear();
|
|
||||||
int i = 0;
|
|
||||||
for (auto app : m_appOrder) {
|
|
||||||
m_appPositions[app] = i;
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
emit appOrderChanged();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
|
#include "homescreen.h"
|
||||||
|
|
||||||
class QString;
|
class QString;
|
||||||
|
|
||||||
class ApplicationListModel;
|
class ApplicationListModel;
|
||||||
|
|
@ -42,7 +44,6 @@ class ApplicationListModel : public QAbstractListModel {
|
||||||
|
|
||||||
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
||||||
Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged)
|
Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged)
|
||||||
Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum LauncherLocation {
|
enum LauncherLocation {
|
||||||
|
|
@ -61,7 +62,7 @@ public:
|
||||||
ApplicationLocationRole
|
ApplicationLocationRole
|
||||||
};
|
};
|
||||||
|
|
||||||
ApplicationListModel(QObject *parent = nullptr);
|
ApplicationListModel(HomeScreen *parent = nullptr);
|
||||||
~ApplicationListModel() override;
|
~ApplicationListModel() override;
|
||||||
|
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
|
||||||
|
|
@ -69,7 +70,7 @@ public:
|
||||||
void moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild);
|
void moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild);
|
||||||
|
|
||||||
int count() const { return m_applicationList.count(); }
|
int count() const { return m_applicationList.count(); }
|
||||||
int favoriteCount() const { return m_favoriteCount;}
|
int favoriteCount() const { return m_favorites.count();}
|
||||||
|
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
|
@ -77,9 +78,6 @@ public:
|
||||||
|
|
||||||
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
|
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
QStringList appOrder() const;
|
|
||||||
void setAppOrder(const QStringList &order);
|
|
||||||
|
|
||||||
Q_INVOKABLE void setLocation(int row, LauncherLocation location);
|
Q_INVOKABLE void setLocation(int row, LauncherLocation location);
|
||||||
|
|
||||||
Q_INVOKABLE void moveItem(int row, int order);
|
Q_INVOKABLE void moveItem(int row, int order);
|
||||||
|
|
@ -94,14 +92,14 @@ public Q_SLOTS:
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void countChanged();
|
void countChanged();
|
||||||
void favoriteCountChanged();
|
void favoriteCountChanged();
|
||||||
void appOrderChanged();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<ApplicationData> m_applicationList;
|
QList<ApplicationData> m_applicationList;
|
||||||
|
|
||||||
|
HomeScreen *m_homeScreen = nullptr;
|
||||||
QStringList m_appOrder;
|
QStringList m_appOrder;
|
||||||
|
QStringList m_favorites;
|
||||||
QHash<QString, int> m_appPositions;
|
QHash<QString, int> m_appPositions;
|
||||||
int m_favoriteCount = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPLICATIONLISTMODEL_H
|
#endif // APPLICATIONLISTMODEL_H
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ HomeScreen::HomeScreen(QObject *parent, const QVariantList &args)
|
||||||
: Plasma::Containment(parent, args)
|
: Plasma::Containment(parent, args)
|
||||||
{
|
{
|
||||||
qmlRegisterUncreatableType<ApplicationListModel>("org.kde.phone.homescreen", 1, 0, "ApplicationListModel", QStringLiteral("Cannot create item of type ApplicationListModel"));
|
qmlRegisterUncreatableType<ApplicationListModel>("org.kde.phone.homescreen", 1, 0, "ApplicationListModel", QStringLiteral("Cannot create item of type ApplicationListModel"));
|
||||||
m_applicationListModel = new ApplicationListModel(this);
|
|
||||||
setHasConfigurationInterface(true);
|
setHasConfigurationInterface(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,6 +37,9 @@ HomeScreen::~HomeScreen()
|
||||||
|
|
||||||
ApplicationListModel *HomeScreen::applicationListModel()
|
ApplicationListModel *HomeScreen::applicationListModel()
|
||||||
{
|
{
|
||||||
|
if (!m_applicationListModel) {
|
||||||
|
m_applicationListModel = new ApplicationListModel(this);
|
||||||
|
}
|
||||||
return m_applicationListModel;
|
return m_applicationListModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ public:
|
||||||
Q_INVOKABLE void stackAfter(QQuickItem *item1, QQuickItem *item2);
|
Q_INVOKABLE void stackAfter(QQuickItem *item1, QQuickItem *item2);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ApplicationListModel *m_applicationListModel;
|
ApplicationListModel *m_applicationListModel = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,9 @@
|
||||||
<kcfgfile name=""/>
|
<kcfgfile name=""/>
|
||||||
|
|
||||||
<group name="General">
|
<group name="General">
|
||||||
<entry name="ItemsGeometries" type="String" hidden="true">
|
<entry name="AppOrder" type="StringList">
|
||||||
<label>Encoded geometries of items (resource categories).</label>
|
<label>order of apps</label>
|
||||||
</entry>
|
<default>org.kde.phone.dialer.desktop</default>
|
||||||
<entry name="VerticalItemsGeometries" type="String" hidden="true">
|
|
||||||
<label>Encoded geometries of items, vertical screen (resource categories).</label>
|
|
||||||
</entry>
|
</entry>
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue