diff --git a/src/singletons/imageuploader/UploadedImageModel.cpp b/src/singletons/imageuploader/UploadedImageModel.cpp index c382b63c9..a2ff33cc6 100644 --- a/src/singletons/imageuploader/UploadedImageModel.cpp +++ b/src/singletons/imageuploader/UploadedImageModel.cpp @@ -3,8 +3,10 @@ #include "common/SignalVectorModel.hpp" #include "messages/Image.hpp" #include "singletons/imageuploader/ImageUploader.hpp" +#include "singletons/Resources.hpp" +#include "util/LoadPixmap.hpp" +#include "util/PostToThread.hpp" #include "util/StandardItemHelper.hpp" -#include "widgets/listview/ImagePtrItemDelegate.hpp" #include #include @@ -14,13 +16,12 @@ namespace chatterino { UploadedImageModel::UploadedImageModel(QObject *parent) - : SignalVectorModel(4, parent) + : SignalVectorModel(1, parent) { } -// image, path, delete url UploadedImage UploadedImageModel::getItemFromRow( - std::vector &row, const UploadedImage &original) + std::vector & /* row */, const UploadedImage &original) { return original; } @@ -28,34 +29,22 @@ UploadedImage UploadedImageModel::getItemFromRow( void UploadedImageModel::getRowFromItem(const UploadedImage &item, std::vector &row) { - row[0]->setData(item.imageLink, ImagePtrItemDelegate::IMAGE_URL_ROLE); + row[0]->setData(item.imageLink, Qt::DisplayRole); row[0]->setData(item.imageLink, UploadedImageModel::DOUBLE_CLICK_LINK_ROLE); row[0]->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); - auto locale = QLocale::system(); - setStringItem(row[1], - locale.toString(QDateTime::fromSecsSinceEpoch(item.timestamp), - QLocale::ShortFormat), - false); - - if (item.deletionLink.isNull()) - { - setStringItem(row[2], "N/A", false); - } - else - { - setStringItem(row[2], "[Double click to open]", false); - row[2]->setData(item.deletionLink, DOUBLE_CLICK_LINK_ROLE); - } - - if (item.localPath.isNull()) - { - setStringItem(row[3], "n/a", false); - } - else - { - setStringItem(row[3], item.localPath, true); - } + loadPixmapFromUrl({item.imageLink}, + [row](const QPixmap &pixmap) { + postToThread([pixmap, row]() { + row[0]->setData(pixmap, Qt::DecorationRole); + }); + }, + {[row]() { + postToThread([row]() { + row[0]->setData(getResources().imageFailedToLoad, + Qt::DecorationRole); + }); + }}); } } // namespace chatterino diff --git a/src/singletons/imageuploader/UploadedImageModel.hpp b/src/singletons/imageuploader/UploadedImageModel.hpp index e8850337c..775c4e168 100644 --- a/src/singletons/imageuploader/UploadedImageModel.hpp +++ b/src/singletons/imageuploader/UploadedImageModel.hpp @@ -8,6 +8,7 @@ namespace chatterino { +struct UploadedImage; class UploadedImageModel : public SignalVectorModel { explicit UploadedImageModel(QObject *parent);