Commit 1fdbadec authored by Camilo higuita's avatar Camilo higuita

better updating of the cloud model when downloading online images

parent 796e2432
......@@ -13,6 +13,24 @@ Cloud::Cloud(QObject *parent) : BaseList (parent)
this->formatList();
emit this->postListChanged();
});
connect(this->fm, &FM::cloudItemReady, [this](const FMH::MODEL &item, const QString &path)
{
qDebug()<< "REQUESTED CLOUD IMAGE READY << " << item;
Q_UNUSED(path);
auto newItem = item;
auto url = item[FMH::MODEL_KEY::URL];
auto thumbnail = item[FMH::MODEL_KEY::THUMBNAIL];
newItem[FMH::MODEL_KEY::FAV] = QString("0");
newItem[FMH::MODEL_KEY::URL] = FMH::fileExists(thumbnail)? thumbnail : item[FMH::MODEL_KEY::URL];
newItem[FMH::MODEL_KEY::SOURCE] = FMH::fileExists(thumbnail)? thumbnail : item[FMH::MODEL_KEY::PATH];
newItem[FMH::MODEL_KEY::TITLE] = item[FMH::MODEL_KEY::LABEL];
this->update(FM::toMap(newItem), this->pending.take(QString(item[FMH::MODEL_KEY::PATH]).replace(FMH::CloudCachePath+"opendesktop", FMH::PATHTYPE_NAME[FMH::PATHTYPE_KEY::CLOUD_PATH])));
emit this->cloudImageReady(FM::toMap(newItem));
});
}
FMH::MODEL_LIST Cloud::items() const
......@@ -49,8 +67,8 @@ void Cloud::formatList()
auto thumbnail = item[FMH::MODEL_KEY::THUMBNAIL];
item[FMH::MODEL_KEY::FAV] = QString("0");
item[FMH::MODEL_KEY::URL] = FMH::fileExists(thumbnail)? thumbnail : item[FMH::MODEL_KEY::PATH];
item[FMH::MODEL_KEY::SOURCE] = url;
item[FMH::MODEL_KEY::URL] = FMH::fileExists(thumbnail)? thumbnail : item[FMH::MODEL_KEY::URL];
item[FMH::MODEL_KEY::SOURCE] = FMH::fileExists(thumbnail)? thumbnail : item[FMH::MODEL_KEY::PATH];
item[FMH::MODEL_KEY::TITLE] = item[FMH::MODEL_KEY::LABEL];
}
}
......@@ -68,3 +86,35 @@ QVariantMap Cloud::get(const int &index) const
return res;
}
void Cloud::requestImage(const int &index)
{
if(index < 0 || index >= this->list.size())
return;
this->pending.insert(this->list[index][FMH::MODEL_KEY::PATH], index);
qDebug()<< "1-PEDNIGN CLOUD"<< this->pending;
this->fm->getCloudItem(FM::toMap(this->list[index]));
}
bool Cloud::update(const QVariantMap &data, const int &index)
{
if(index < 0 || index >= this->list.size())
return false;
auto newData = this->list[index];
QVector<int> roles;
for(auto key : data.keys())
if(newData[FMH::MODEL_NAME_KEY[key]] != data[key].toString())
{
newData.insert(FMH::MODEL_NAME_KEY[key], data[key].toString());
roles << FMH::MODEL_NAME_KEY[key];
}
this->list[index] = newData;
emit this->updateModel(index, roles);
return true;
}
......@@ -32,14 +32,19 @@ private:
void setList();
void formatList();
QHash<QString, int> pending;
QString account;
FM *fm;
public slots:
QVariantMap get(const int &index) const override;
void requestImage(const int &index);
bool update(const QVariantMap &data, const int &index) override;
signals:
void accountChanged();
void cloudImageReady(QVariantMap item);
};
#endif // CLOUD_H
......@@ -12,6 +12,8 @@ import PixModel 1.0
PixGrid
{
id: control
property alias list : _cloudList
headBarExit: false
visible: true
holder.emojiSize: iconSizes.huge
......@@ -24,13 +26,13 @@ PixGrid
holder.isMask: false
holder.title : if(!_cloudList.contentReady)
qsTr("Loading content!")
else
else
qsTr("Nothing here")
holder.body: if(!_cloudList.contentReady)
qsTr("Almost ready!")
else
qsTr("Make sure you're online and your cloud account is working")
qsTr("Make sure you're online and your cloud account is working")
grid.delegate: PixPic
{
......@@ -62,7 +64,7 @@ PixGrid
control.grid.currentIndex = index
//picClicked(index)
if(!isMobile)
VIEWER.open(_cloudList, index)
VIEWER.open(_cloudList, index)
// else
// selectionBox.append(gridModel.get(index))
......
......@@ -25,8 +25,8 @@ function view(index)
pixViewer.currentPicIndex = index
pixViewer.currentPic = pixViewer.model.list.get(pixViewer.currentPicIndex)
if(Maui.FM.isCloud(pixViewer.currentPic.url))
console.log("IS CLOUD IMAGE")
if(Maui.FM.isCloud(pixViewer.currentPic.source))
cloudView.list.requestImage(pixViewer.currentPicIndex)
console.log("CURRENT PIC FAV", pixViewer.currentPic.fav)
pixViewer.currentPicFav = dba.isFav(pixViewer.currentPic.url)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment