[WIP] Display all StreamRestore entries in it's own config Tab
Needs ReviewPublic

Authored by Zren on Mar 6 2018, 7:24 AM.

Details

Reviewers
None
Group Reviewers
Plasma
Summary

Was just wondering how difficult it would be to implement this. This was practice than anything else, but if you thinks it's worth cleaning up I can do so. Otherwise, reject it.

Issues:

  • You can filter the streams using a hack that forces PlasmaCore.SortFilterModel to invalidate the filter.
  • I duplicated BaseMap in map.h to use a QString key focused on the info.name property. Code duplication sucks. :/
  • Every stream uses the system notifications icon. Would need to play around with that.
  • I don't believe the "device dropdown" is correct. I think all my streams are set to a "default device index" so it's not selecting the right dropdown option.
    • I need to determine the deviceModel based on the streamRestoreInfo.name for StreamListItem { deviceModel: sinkModel } if I do keep the device dropdown.
  • Double scrollbars sucks, but I'd need to look into why there's a binding loop on AppletConfiguration.height. We need to use ScrollView + ListView so that it only loads 4-5 delegates at a time since I personally had 100+ entries (games) which took a few seconds to load the tab when I removed the filter from the Applications tab.

Diff Detail

Repository
R115 Plasma Audio Volume Applet
Lint
Lint Skipped
Unit
Unit Tests Skipped
Zren created this revision.Mar 6 2018, 7:24 AM
Restricted Application added a project: Plasma. · View Herald TranscriptMar 6 2018, 7:24 AM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
Zren requested review of this revision.Mar 6 2018, 7:24 AM
drosca added a subscriber: drosca.Mar 6 2018, 9:58 AM

You forgot to add StreamRestoreTab.qml to review.

I duplicated BaseMap in map.h to use a QString key focused on the info.name property. Code duplication sucks. :/

Can't you just qHash() the name and use it as integer index for normal MapBase?

Every stream uses the system notifications icon. Would need to play around with that.

I don't think you can get icon name for this from pa.

Double scrollbars sucks, but I'd need to look into why there's a binding loop on AppletConfiguration.height. We need to use ScrollView + ListView so that it only loads 4-5 delegates at a time since I personally had 100+ entries (games) which took a few seconds to load the tab when I removed the filter from the Applications tab.

That should only be bug in Plasma, it should work fine in kcmshell/system settings.

Zren updated this revision to Diff 28854.Mar 6 2018, 6:01 PM
Zren edited the summary of this revision. (Show Details)

Forgot to add StreamRestoreTab.qml

Zren added a comment.Mar 6 2018, 6:03 PM

You forgot to add StreamRestoreTab.qml to review.

Oh woops. Sorry, did a git diff rather than staging stuff.

I duplicated BaseMap in map.h to use a QString key focused on the info.name property. Code duplication sucks. :/

Can't you just qHash() the name and use it as integer index for normal MapBase?

God, I've been using Python/JS so long I forgot about hashing map keys at the lower level.

Hmmm, that means I could break updateEntry into 3 functions (abstract code/ update by index / update by name).

diff --git a/src/maps.h b/src/maps.h
index 0051153..7a440e5 100644
--- a/src/maps.h
+++ b/src/maps.h
@@ -120,31 +120,44 @@ public:
     // Context is passed in as parent because context needs to include the maps
     // so we'd cause a circular dep if we were to try to use the instance here.
     // Plus that's weird separation anyway.
-    void updateEntry(const PAInfo *info, QObject *parent)
+    void updateEntry(const PAInfo *info, QObject *parent, quint32 key)
     {
         Q_ASSERT(info);
 
-        if (m_pendingRemovals.remove(info->index)) {
+        if (m_pendingRemovals.remove(key)) {
             // Was already removed again.
             return;
         }
 
-        const bool isNew = !m_data.contains(info->index);
+        const bool isNew = !m_data.contains(key);
 
-        auto *obj = m_data.value(info->index, nullptr);
+        auto *obj = m_data.value(key, nullptr);
         if (!obj) {
             obj = new Type(parent);
         }
         obj->update(info);
-        m_data.insert(info->index, obj);
+        m_data.insert(key, obj);
 
         if (isNew) {
-            const int modelIndex = m_data.keys().indexOf(info->index);
+            const int modelIndex = m_data.keys().indexOf(key);
             Q_ASSERT(modelIndex >= 0);
             emit added(modelIndex);
         }
     }
 
+    void updateEntryByIndex(const PAInfo *info, QObject *parent)
+    {
+        Q_ASSERT(info);
+        updateEntry(info, parent, info->index);
+    }
+    void updateEntryByName(const PAInfo *info, QObject *parent)
+    {
+        Q_ASSERT(info);
+        QString infoName = QString::fromUtf8(info->name);
+        quint32 nameHash = qHash(...);
+        updateEntry(info, parent, nameHash);
+    }
+
     void removeEntry(quint32 index)
     {
         if (!m_data.contains(index)) {

There's one other reference to object->index() in insert(Type *object), but I think that was only used by StreamRestore to populate the notification stream in Context::streamRestoreCallback. If that's the only use, we could remove that function.

Every stream uses the system notifications icon. Would need to play around with that.

I don't think you can get icon name for this from pa.

Yeah I think so too. I meant more like hiding the icon under the "Stream Restore" tab or using a different icon for everything other than the "notification" stream.