Commit 62de2cb1 authored by Marco Martin's avatar Marco Martin

working load and save of order and favs

parent a1a8e002
......@@ -37,12 +37,20 @@
#include <KIOWidgets/KRun>
#include <QDebug>
ApplicationListModel::ApplicationListModel(QObject *parent)
: QAbstractListModel(parent)
ApplicationListModel::ApplicationListModel(HomeScreen *parent)
: QAbstractListModel(parent),
m_homeScreen(parent)
{
//can't use the new syntax as this signal is overloaded
connect(KSycoca::self(), SIGNAL(databaseChanged(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?
loadApplications();
}
......@@ -104,8 +112,6 @@ void ApplicationListModel::loadApplications()
int i = 0; // for default bookmarks
m_favoriteCount = 0;
// Iterate over all entries in the group
while (!subGroupList.isEmpty()) {
KSycocaEntry::Ptr groupEntry = subGroupList.first();
......@@ -142,20 +148,16 @@ void ApplicationListModel::loadApplications()
data.storageId = service->storageId();
data.entryPath = service->exec();
if (m_favorites.contains(data.storageId)) {
data.location = Favorites;
}
auto it = m_appPositions.constFind(service->storageId());
if (it != m_appPositions.constEnd()) {
//TODO: proper bookmarks
data.location = (*it) < 6 ? Favorites : Grid;
orderedList[*it] = data;
} else {
//TODO: proper bookmarks
data.location = (++i + m_appPositions.size() < 6) ? Favorites : Grid;
unorderedList << data;
}
if (data.location == Favorites) {
++m_favoriteCount;
}
emit favoriteCountChanged();
}
}
}
......@@ -234,10 +236,12 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
}
if (location == Favorites) {
++m_favoriteCount;
m_favorites.insert(row, data.storageId);
m_homeScreen->config().writeEntry("Favorites", m_favorites);
emit favoriteCountChanged();
} 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();
}
......@@ -276,8 +280,8 @@ void ApplicationListModel::moveItem(int row, int destination)
++i;
}
m_homeScreen->config().writeEntry("AppOrder", m_appOrder);
emit appOrderChanged();
endMoveRows();
}
......@@ -292,23 +296,5 @@ void ApplicationListModel::runApplication(const QString &storageId)
KRun::runService(*service, QList<QUrl>(), nullptr);
}
QStringList ApplicationListModel::appOrder() const
{
return m_appOrder;
}
void ApplicationListModel::setAppOrder(const QStringList &order)
{
if (m_appOrder == order) {
return;
}
#include "moc_applicationlistmodel.cpp"
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 <QList>
#include "homescreen.h"
class QString;
class ApplicationListModel;
......@@ -42,7 +44,6 @@ class ApplicationListModel : public QAbstractListModel {
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(int favoriteCount READ favoriteCount NOTIFY favoriteCountChanged)
Q_PROPERTY(QStringList appOrder READ appOrder WRITE setAppOrder NOTIFY appOrderChanged)
public:
enum LauncherLocation {
......@@ -61,7 +62,7 @@ public:
ApplicationLocationRole
};
ApplicationListModel(QObject *parent = nullptr);
ApplicationListModel(HomeScreen *parent = nullptr);
~ApplicationListModel() 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);
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;
......@@ -77,9 +78,6 @@ public:
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 moveItem(int row, int order);
......@@ -94,14 +92,14 @@ public Q_SLOTS:
Q_SIGNALS:
void countChanged();
void favoriteCountChanged();
void appOrderChanged();
private:
QList<ApplicationData> m_applicationList;
HomeScreen *m_homeScreen = nullptr;
QStringList m_appOrder;
QStringList m_favorites;
QHash<QString, int> m_appPositions;
int m_favoriteCount = 0;
};
#endif // APPLICATIONLISTMODEL_H
......@@ -28,7 +28,7 @@ HomeScreen::HomeScreen(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args)
{
qmlRegisterUncreatableType<ApplicationListModel>("org.kde.phone.homescreen", 1, 0, "ApplicationListModel", QStringLiteral("Cannot create item of type ApplicationListModel"));
m_applicationListModel = new ApplicationListModel(this);
setHasConfigurationInterface(true);
}
......@@ -37,6 +37,9 @@ HomeScreen::~HomeScreen()
ApplicationListModel *HomeScreen::applicationListModel()
{
if (!m_applicationListModel) {
m_applicationListModel = new ApplicationListModel(this);
}
return m_applicationListModel;
}
......
......@@ -42,7 +42,7 @@ public:
Q_INVOKABLE void stackAfter(QQuickItem *item1, QQuickItem *item2);
private:
ApplicationListModel *m_applicationListModel;
ApplicationListModel *m_applicationListModel = nullptr;
};
......
......@@ -6,11 +6,9 @@
<kcfgfile name=""/>
<group name="General">
<entry name="ItemsGeometries" type="String" hidden="true">
<label>Encoded geometries of items (resource categories).</label>
</entry>
<entry name="VerticalItemsGeometries" type="String" hidden="true">
<label>Encoded geometries of items, vertical screen (resource categories).</label>
<entry name="AppOrder" type="StringList">
<label>order of apps</label>
<default>org.kde.phone.dialer.desktop</default>
</entry>
</group>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment