diff --git a/containments/homescreen/contents/config/main.xml b/containments/homescreen/contents/config/main.xml
index 61a525b9..1f27dcef 100644
--- a/containments/homescreen/contents/config/main.xml
+++ b/containments/homescreen/contents/config/main.xml
@@ -9,6 +9,9 @@
+
+
+
diff --git a/containments/homescreen/contents/ui/main.qml b/containments/homescreen/contents/ui/main.qml
index d52dfdf0..6582cac6 100644
--- a/containments/homescreen/contents/ui/main.qml
+++ b/containments/homescreen/contents/ui/main.qml
@@ -92,10 +92,16 @@ Item {
LayoutManager.lastSpacer = appletsSpace.lastSpacer;
LayoutManager.restore();
applicationsView.contentY = -root.height;
+
+ appListModel.appOrder = plasmoid.configuration.AppOrder;
+ appListModel.loadApplications();
}
SatelliteComponents.ApplicationListModel {
id: appListModel
+ onAppOrderChanged: {
+ plasmoid.configuration.AppOrder = appListModel.appOrder;
+ }
}
Timer {
diff --git a/qmlcomponents/applicationlistmodel.cpp b/qmlcomponents/applicationlistmodel.cpp
index 9cd69bd7..f8627c86 100644
--- a/qmlcomponents/applicationlistmodel.cpp
+++ b/qmlcomponents/applicationlistmodel.cpp
@@ -36,7 +36,6 @@
ApplicationListModel::ApplicationListModel(QObject *parent)
: QAbstractListModel(parent)
{
- loadApplications();
}
ApplicationListModel::~ApplicationListModel()
@@ -55,6 +54,10 @@ QHash ApplicationListModel::roleNames() const
return roleNames;
}
+bool appNameLessThan(const ApplicationData &a1, const ApplicationData &a2)
+{
+ return a1.name.toLower() < a2.name.toLower();
+}
void ApplicationListModel::loadApplications()
{
@@ -64,6 +67,9 @@ void ApplicationListModel::loadApplications()
if (!group || !group->isValid()) return;
KServiceGroup::List subGroupList = group->entries(true);
+ QMap orderedList;
+ QList unorderedList;
+
// Iterate over all entries in the group
for(KServiceGroup::List::ConstIterator it = subGroupList.begin();it != subGroupList.end(); it++) {
KSycocaEntry::Ptr groupEntry = (*it);
@@ -85,7 +91,12 @@ void ApplicationListModel::loadApplications()
data.icon = service->icon();
data.storageId = service->storageId();
data.entryPath = service->exec();
- m_applicationList << data;
+
+ if (m_appPositions.contains(service->storageId())) {
+ orderedList[m_appPositions.value(service->storageId())] = data;
+ } else {
+ unorderedList << data;
+ }
}
}
}
@@ -93,6 +104,10 @@ void ApplicationListModel::loadApplications()
}
}
+ std::sort(unorderedList.begin(), unorderedList.end(), appNameLessThan);
+ m_applicationList << orderedList.values();
+ m_applicationList << unorderedList;
+
endResetModel();
emit countChanged();
}
@@ -143,6 +158,19 @@ Q_INVOKABLE void ApplicationListModel::moveItem(int row, int destination)
beginMoveRows(QModelIndex(), row, row, QModelIndex(), destination);
ApplicationData data = m_applicationList.takeAt(row);
m_applicationList.insert(destination, data);
+
+
+ m_appOrder.clear();
+ m_appPositions.clear();
+ int i = 0;
+ for (auto app : m_applicationList) {
+ m_appOrder << app.storageId;
+ m_appPositions[app.storageId] = i;
+ ++i;
+ }
+
+
+ emit appOrderChanged();
endMoveRows();
}
@@ -157,4 +185,25 @@ void ApplicationListModel::runApplication(const QString &storageId)
QProcess::startDetached(service->exec());
}
+QStringList ApplicationListModel::appOrder() const
+{
+ 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();
+}
+
#include "applicationlistmodel.moc"
diff --git a/qmlcomponents/applicationlistmodel.h b/qmlcomponents/applicationlistmodel.h
index 8e4f82ee..5c508888 100644
--- a/qmlcomponents/applicationlistmodel.h
+++ b/qmlcomponents/applicationlistmodel.h
@@ -38,6 +38,7 @@ class ApplicationListModel : public QAbstractListModel {
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
+ Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
public:
ApplicationListModel(QObject *parent = 0);
@@ -59,16 +60,24 @@ public:
ApplicationOriginalRowRole = Qt::UserRole + 6
};
+ QStringList appOrder() const;
+ void setAppOrder(const QStringList &order);
+
Q_INVOKABLE void moveItem(int row, int order);
Q_INVOKABLE void runApplication(const QString &storageId);
+ Q_INVOKABLE void loadApplications();
+
Q_SIGNALS:
void countChanged();
+ void appOrderChanged();
private:
QList m_applicationList;
- void loadApplications();
+
+ QStringList m_appOrder;
+ QHash m_appPositions;
};
#endif // APPLICATIONLISTMODEL_H