summary refs log tree commit diff
path: root/src/GridImagePackModel.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2023-05-19 23:19:04 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2023-05-20 00:57:52 +0200
commit58cfc39ac42633eafb65f17483533ef285b72c38 (patch)
treee44d1607d4056c33a139f17316c650c018ddacf1 /src/GridImagePackModel.cpp
parentPrevent new packs from overwriting the default pack by accident (diff)
downloadnheko-58cfc39ac42633eafb65f17483533ef285b72c38.tar.xz
Fix StickerPicker padding and names of unnamed packs
Diffstat (limited to 'src/GridImagePackModel.cpp')
-rw-r--r--src/GridImagePackModel.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/GridImagePackModel.cpp b/src/GridImagePackModel.cpp
index 59bfae80..59b1725a 100644
--- a/src/GridImagePackModel.cpp
+++ b/src/GridImagePackModel.cpp
@@ -8,6 +8,7 @@
 
 #include <algorithm>
 
+#include "Cache.h"
 #include "Cache_p.h"
 
 Q_DECLARE_METATYPE(StickerImage)
@@ -104,7 +105,7 @@ GridImagePackModel::data(const QModelIndex &index, int role) const
             const auto &pack = packs[rowToPack[index.row()]];
             switch (role) {
             case Roles::PackName:
-                return pack.packname;
+                return nameFromPack(pack);
             case Roles::Row: {
                 std::size_t offset = static_cast<std::size_t>(index.row()) - pack.firstRow;
                 QList<StickerImage> imgs;
@@ -135,7 +136,7 @@ GridImagePackModel::data(const QModelIndex &index, int role) const
 
             switch (role) {
             case Roles::PackName:
-                return pack.packname;
+                return nameFromPack(pack);
             case Roles::Row: {
                 QList<StickerImage> imgs;
                 for (auto img = firstIndex;
@@ -162,6 +163,25 @@ GridImagePackModel::data(const QModelIndex &index, int role) const
     return {};
 }
 
+QString
+GridImagePackModel::nameFromPack(const PackDesc &pack) const
+{
+    if (!pack.packname.isEmpty()) {
+        return pack.packname;
+    }
+
+    if (!pack.state_key.empty()) {
+        return QString::fromStdString(pack.state_key);
+    }
+
+    if (!pack.room_id.empty()) {
+        auto info = cache::singleRoomInfo(pack.room_id);
+        return QString::fromStdString(info.name);
+    }
+
+    return tr("Account Pack");
+}
+
 void
 GridImagePackModel::setSearchString(QString key)
 {