Working screenshot upload

This commit is contained in:
Jan Dalheimer
2014-02-24 10:34:51 +01:00
parent 226c1bdae5
commit a8811a27f7
7 changed files with 84 additions and 69 deletions

View File

@ -1,4 +1,5 @@
#include "ScreenshotList.h"
#include <QDir>
#include <QIcon>
@ -22,9 +23,9 @@ QVariant ScreenshotList::data(const QModelIndex &index, int role) const
case Qt::DecorationRole:
return QIcon(m_screenshots.at(index.row())->file);
case Qt::DisplayRole:
return m_screenshots.at(index.row())->timestamp;
return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
case Qt::ToolTipRole:
return m_screenshots.at(index.row())->timestamp;
return m_screenshots.at(index.row())->timestamp.toString("yyyy-MM-dd HH:mm:ss");
case Qt::TextAlignmentRole:
return (int)(Qt::AlignHCenter | Qt::AlignVCenter);
default:
@ -68,7 +69,7 @@ void ScreenshotLoadTask::executeTask()
for (auto file : dir.entryList())
{
ScreenShot *shot = new ScreenShot();
shot->timestamp = file.left(file.length() - 4);
shot->timestamp = QDateTime::fromString(file, "yyyy-MM-dd_HH.mm.ss.png");
shot->file = dir.absoluteFilePath(file);
m_results.append(shot);
}

View File

@ -7,10 +7,10 @@
class ScreenShot
{
public:
QString timestamp;
QDateTime timestamp;
QString file;
QString url;
int imgurIndex;
QString imgurIndex;
};
class ScreenshotList : public QAbstractListModel

View File

@ -24,7 +24,6 @@ void ScreenShotUpload::start()
m_status = Job_InProgress;
QNetworkRequest request(m_url);
request.setHeader(QNetworkRequest::UserAgentHeader, "MultiMC/5.0 (Uncached)");
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request.setRawHeader("Authorization", "Client-ID 5b97b0713fba4a3");
request.setRawHeader("Accept", "application/json");
@ -47,7 +46,7 @@ void ScreenShotUpload::start()
multipart->append(typePart);
QHttpPart namePart;
namePart.setHeader(QNetworkRequest::ContentDispositionHeader, "form-data; name=\"name\"");
namePart.setBody(m_shot->timestamp.toUtf8());
namePart.setBody(m_shot->timestamp.toString(Qt::ISODate).toUtf8());
multipart->append(namePart);
auto worker = MMC->qnam();
@ -85,8 +84,8 @@ void ScreenShotUpload::downloadFinished()
emit failed(m_index_within_job);
return;
}
m_shot->imgurIndex = object.value("data").toObject().value("id").toVariant().toInt();
m_shot->url = "https://imgur.com/gallery/" + QString::number(m_shot->imgurIndex);
m_shot->imgurIndex = object.value("data").toObject().value("id").toString();
m_shot->url = object.value("data").toObject().value("link").toString();
m_status = Job_Finished;
emit succeeded(m_index_within_job);
return;