Improve the new item logic
This commit is contained in:
parent
357e4dd3ab
commit
06922de9c9
5 changed files with 35 additions and 11 deletions
|
@ -131,9 +131,23 @@ void ApplicationModel::removeItem(const QString &desktopFile)
|
|||
|
||||
bool ApplicationModel::desktopContains(const QString &desktopFile)
|
||||
{
|
||||
if (desktopFile.isEmpty())
|
||||
return false;
|
||||
|
||||
return findItemByDesktop(desktopFile) != nullptr;
|
||||
}
|
||||
|
||||
bool ApplicationModel::isDesktopPinned(const QString &desktopFile)
|
||||
{
|
||||
ApplicationItem *item = findItemByDesktop(desktopFile);
|
||||
|
||||
if (item) {
|
||||
return item->isPinned;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ApplicationModel::clicked(const QString &id)
|
||||
{
|
||||
ApplicationItem *item = findItemById(id);
|
||||
|
@ -433,7 +447,19 @@ void ApplicationModel::onWindowAdded(quint64 wid)
|
|||
if (id == "cutefish-launcher")
|
||||
return;
|
||||
|
||||
if (contains(id)) {
|
||||
QString desktopPath = m_iface->desktopFilePath(wid);
|
||||
ApplicationItem *desktopItem = findItemByDesktop(desktopPath);
|
||||
|
||||
// Use desktop find
|
||||
if (!desktopPath.isEmpty() && desktopItem != nullptr) {
|
||||
desktopItem->id = id;
|
||||
desktopItem->wids.append(wid);
|
||||
// Need to update application active status.
|
||||
desktopItem->isActive = info.value("active").toBool();
|
||||
handleDataChangedFromItem(desktopItem);
|
||||
}
|
||||
// Find from id
|
||||
else if (contains(id)) {
|
||||
for (ApplicationItem *item : m_appItems) {
|
||||
if (item->id == id) {
|
||||
item->wids.append(wid);
|
||||
|
@ -442,7 +468,9 @@ void ApplicationModel::onWindowAdded(quint64 wid)
|
|||
handleDataChangedFromItem(item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
// New item needs to be added.
|
||||
else {
|
||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||
ApplicationItem *item = new ApplicationItem;
|
||||
item->id = id;
|
||||
|
@ -451,8 +479,6 @@ void ApplicationModel::onWindowAdded(quint64 wid)
|
|||
item->isActive = info.value("active").toBool();
|
||||
item->wids.append(wid);
|
||||
|
||||
QString desktopPath = m_iface->desktopFilePath(wid);
|
||||
|
||||
if (!desktopPath.isEmpty()) {
|
||||
QMap<QString, QString> desktopInfo = Utils::instance()->readInfoFromDesktop(desktopPath);
|
||||
item->iconName = desktopInfo.value("Icon");
|
||||
|
|
|
@ -50,6 +50,7 @@ public:
|
|||
void addItem(const QString &desktopFile);
|
||||
void removeItem(const QString &desktopFile);
|
||||
bool desktopContains(const QString &desktopFile);
|
||||
bool isDesktopPinned(const QString &desktopFile);
|
||||
|
||||
Q_INVOKABLE void save() { savePinAndUnPinList(); }
|
||||
|
||||
|
|
|
@ -104,12 +104,9 @@ void MainWindow::remove(const QString &desktop)
|
|||
m_appModel->removeItem(desktop);
|
||||
}
|
||||
|
||||
bool MainWindow::contains(const QString &desktop)
|
||||
bool MainWindow::pinned(const QString &desktop)
|
||||
{
|
||||
if (desktop.isEmpty())
|
||||
return false;
|
||||
|
||||
return m_appModel->desktopContains(desktop);
|
||||
return m_appModel->isDesktopPinned(desktop);
|
||||
}
|
||||
|
||||
void MainWindow::updateSize()
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
// DBus interface
|
||||
void add(const QString &desktop);
|
||||
void remove(const QString &desktop);
|
||||
bool contains(const QString &desktop);
|
||||
bool pinned(const QString &desktop);
|
||||
|
||||
Q_INVOKABLE void updateSize();
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<interface name="org.cutefish.Dock">
|
||||
<method name="add"><arg name="desktopFile" type="s" direction="in"/></method>
|
||||
<method name="remove"><arg name="desktopFile" type="s" direction="in"/></method>
|
||||
<method name="contains">
|
||||
<method name="pinned">
|
||||
<arg name="desktopFile" type="s" direction="in"/>
|
||||
<arg type="b" direction="out"/>
|
||||
</method>
|
||||
|
|
Loading…
Reference in a new issue