Fix pin & unpin

This commit is contained in:
reionwong 2021-10-03 20:13:00 +08:00
parent 8287222fd8
commit ca9d5be3b8
3 changed files with 55 additions and 21 deletions

View file

@ -60,3 +60,4 @@ add_dependencies(${PROJECT_NAME} translations)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${QM_FILES} DESTINATION /usr/share/${PROJECT_NAME}/translations) install(FILES ${QM_FILES} DESTINATION /usr/share/${PROJECT_NAME}/translations)
install(FILES cutefish-dock-list.conf DESTINATION /etc)

31
cutefish-dock-list.conf Normal file
View file

@ -0,0 +1,31 @@
[cutefish-filemanager]
DesktopPath=/usr/share/applications/cutefish-filemanager.desktop
Index=0
[cutefish-terminal]
DesktopPath=/usr/share/applications/cutefish-terminal.desktop
Index=1
[chromium]
DesktopPath=/usr/share/applications/chromium.desktop
Index=2
[cutefish-settings]
DesktopPath=/usr/share/applications/cutefish-settings.desktop
Index=3
[cutefish-calculator]
DesktopPath=/usr/share/applications/cutefish-calculator.desktop
Index=4
[cutefish-debinstaller]
DesktopPath=/usr/share/applications/cutefish-debinstaller.desktop
Index=5
[cutefish-screenshot]
DesktopPath=/usr/share/applications/cutefish-screenshot.desktop
Index=6
[cutefish-videoplayer]
DesktopPath=/usr/share/applications/cutefish-videoplayer.desktop
Index=7

View file

@ -90,8 +90,12 @@ QVariant ApplicationModel::data(const QModelIndex &index, int role) const
void ApplicationModel::addItem(const QString &desktopFile) void ApplicationModel::addItem(const QString &desktopFile)
{ {
if (findItemByDesktop(desktopFile)) ApplicationItem *existsItem = findItemByDesktop(desktopFile);
if (existsItem) {
existsItem->isPinned = true;
return; return;
}
beginInsertRows(QModelIndex(), rowCount(), rowCount()); beginInsertRows(QModelIndex(), rowCount(), rowCount());
ApplicationItem *item = new ApplicationItem; ApplicationItem *item = new ApplicationItem;
@ -119,17 +123,7 @@ void ApplicationModel::removeItem(const QString &desktopFile)
ApplicationItem *item = findItemByDesktop(desktopFile); ApplicationItem *item = findItemByDesktop(desktopFile);
if (item) { if (item) {
int index = indexOf(item->id); ApplicationModel::unPin(item->id);
if (index != -1) {
beginRemoveRows(QModelIndex(), index, index);
m_appItems.removeAll(item);
endRemoveRows();
savePinAndUnPinList();
emit itemRemoved();
emit countChanged();
}
} }
} }
@ -353,7 +347,10 @@ int ApplicationModel::indexOf(const QString &id)
void ApplicationModel::initPinnedApplications() void ApplicationModel::initPinnedApplications()
{ {
QSettings settings(QSettings::UserScope, "cutefishos", "dock_pinned"); QSettings settings(QSettings::UserScope, "cutefishos", "dock_pinned");
QStringList groups = settings.childGroups(); QSettings systemSettings("/etc/cutefish-dock-list.conf", QSettings::IniFormat);
QSettings *set = (QFile(settings.fileName()).exists()) ? &settings
: &systemSettings;
QStringList groups = set->childGroups();
// Launcher // Launcher
ApplicationItem *item = new ApplicationItem; ApplicationItem *item = new ApplicationItem;
@ -367,17 +364,22 @@ void ApplicationModel::initPinnedApplications()
// Pinned Apps // Pinned Apps
for (int i = 0; i < groups.size(); ++i) { for (int i = 0; i < groups.size(); ++i) {
for (const QString &id : groups) { for (const QString &id : groups) {
settings.beginGroup(id); set->beginGroup(id);
int index = settings.value("Index").toInt(); int index = set->value("Index").toInt();
if (index == i) { if (index == i) {
beginInsertRows(QModelIndex(), rowCount(), rowCount()); beginInsertRows(QModelIndex(), rowCount(), rowCount());
ApplicationItem *item = new ApplicationItem; ApplicationItem *item = new ApplicationItem;
item->desktopPath = settings.value("DesktopPath").toString(); item->desktopPath = set->value("DesktopPath").toString();
item->id = id; item->id = id;
item->isPinned = true; item->isPinned = true;
if (!QFile(item->desktopPath).exists()) {
set->endGroup();
continue;
}
// Read from desktop file. // Read from desktop file.
if (!item->desktopPath.isEmpty()) { if (!item->desktopPath.isEmpty()) {
QMap<QString, QString> desktopInfo = Utils::instance()->readInfoFromDesktop(item->desktopPath); QMap<QString, QString> desktopInfo = Utils::instance()->readInfoFromDesktop(item->desktopPath);
@ -388,13 +390,13 @@ void ApplicationModel::initPinnedApplications()
// Read from config file. // Read from config file.
if (item->iconName.isEmpty()) if (item->iconName.isEmpty())
item->iconName = settings.value("Icon").toString(); item->iconName = set->value("Icon").toString();
if (item->visibleName.isEmpty()) if (item->visibleName.isEmpty())
item->visibleName = settings.value("VisibleName").toString(); item->visibleName = set->value("VisibleName").toString();
if (item->exec.isEmpty()) if (item->exec.isEmpty())
item->exec = settings.value("Exec").toString(); item->exec = set->value("Exec").toString();
m_appItems.append(item); m_appItems.append(item);
endInsertRows(); endInsertRows();
@ -402,10 +404,10 @@ void ApplicationModel::initPinnedApplications()
emit itemAdded(); emit itemAdded();
emit countChanged(); emit countChanged();
settings.endGroup(); set->endGroup();
break; break;
} else { } else {
settings.endGroup(); set->endGroup();
} }
} }
} }