Working screenshot upload
This commit is contained in:
		| @@ -1522,8 +1522,8 @@ void MainWindow::on_actionScreenshots_triggered() | ||||
| 		QStringList urls; | ||||
| 		for (ScreenShot *shot : dialog.uploaded()) | ||||
| 		{ | ||||
| 			urls << QString("<a href=\"" + shot->url + "\">Image %s</a>") | ||||
| 						.arg(QString::number(shot->imgurIndex)); | ||||
| 			urls << QString("<a href=\"" + shot->url + "\">Image %1</a>") | ||||
| 						.arg(shot->timestamp.toString()); | ||||
| 		} | ||||
| 		CustomMessageBox::selectable(this, tr("Done uploading!"), urls.join("\n"), | ||||
| 									 QMessageBox::Information)->exec(); | ||||
|   | ||||
| @@ -39,7 +39,7 @@ QList<ScreenShot*> ScreenshotDialog::selected() const | ||||
| 	return list; | ||||
| } | ||||
|  | ||||
| void ScreenshotDialog::on_buttonBox_accepted() | ||||
| void ScreenshotDialog::on_uploadBtn_clicked() | ||||
| { | ||||
| 	QList<ScreenShot *> screenshots = selected(); | ||||
| 	if (screenshots.isEmpty()) | ||||
| @@ -50,17 +50,18 @@ void ScreenshotDialog::on_buttonBox_accepted() | ||||
| 	NetJob *job = new NetJob("Screenshot Upload"); | ||||
| 	for (ScreenShot *shot : screenshots) | ||||
| 	{ | ||||
| 		qDebug() << shot->file; | ||||
| 		job->addNetAction(ScreenShotUpload::make(shot)); | ||||
| 	} | ||||
| 	m_uploaded = screenshots; | ||||
| 	ProgressDialog prog(this); | ||||
| 	prog.exec(job); | ||||
| 	connect(job, &NetJob::failed, [this] | ||||
| 	if (prog.exec(job) == QDialog::Accepted) | ||||
| 	{ | ||||
| 		accept(); | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		CustomMessageBox::selectable(this, tr("Failed to upload screenshots!"), | ||||
| 									 tr("Unknown error"), QMessageBox::Warning)->exec(); | ||||
| 		reject(); | ||||
| 	}); | ||||
| 	m_uploaded = screenshots; | ||||
| 	connect(job, &NetJob::succeeded, this, &ScreenshotDialog::accept); | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -27,7 +27,7 @@ public: | ||||
|  | ||||
| private | ||||
| slots: | ||||
| 	void on_buttonBox_accepted(); | ||||
| 	void on_uploadBtn_clicked(); | ||||
|  | ||||
| private: | ||||
| 	Ui::ScreenshotDialog *ui; | ||||
|   | ||||
| @@ -17,68 +17,82 @@ | ||||
|    <iconset resource="../../resources/multimc/multimc.qrc"> | ||||
|     <normaloff>:/icons/multimc/scalable/apps/multimc.svg</normaloff>:/icons/multimc/scalable/apps/multimc.svg</iconset> | ||||
|   </property> | ||||
|   <widget class="QDialogButtonBox" name="buttonBox"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>10</x> | ||||
|      <y>260</y> | ||||
|      <width>441</width> | ||||
|      <height>31</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="standardButtons"> | ||||
|     <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <widget class="QListView" name="listView"> | ||||
|    <property name="geometry"> | ||||
|     <rect> | ||||
|      <x>10</x> | ||||
|      <y>10</y> | ||||
|      <width>439</width> | ||||
|      <height>241</height> | ||||
|     </rect> | ||||
|    </property> | ||||
|    <property name="selectionMode"> | ||||
|     <enum>QAbstractItemView::ExtendedSelection</enum> | ||||
|    </property> | ||||
|    <property name="selectionBehavior"> | ||||
|     <enum>QAbstractItemView::SelectItems</enum> | ||||
|    </property> | ||||
|    <property name="iconSize"> | ||||
|     <size> | ||||
|      <width>120</width> | ||||
|      <height>90</height> | ||||
|     </size> | ||||
|    </property> | ||||
|    <property name="flow"> | ||||
|     <enum>QListView::LeftToRight</enum> | ||||
|    </property> | ||||
|    <property name="isWrapping" stdset="0"> | ||||
|     <bool>true</bool> | ||||
|    </property> | ||||
|    <property name="viewMode"> | ||||
|     <enum>QListView::IconMode</enum> | ||||
|    </property> | ||||
|   </widget> | ||||
|   <layout class="QVBoxLayout" name="verticalLayout"> | ||||
|    <item> | ||||
|     <widget class="QListView" name="listView"> | ||||
|      <property name="selectionMode"> | ||||
|       <enum>QAbstractItemView::ExtendedSelection</enum> | ||||
|      </property> | ||||
|      <property name="selectionBehavior"> | ||||
|       <enum>QAbstractItemView::SelectItems</enum> | ||||
|      </property> | ||||
|      <property name="iconSize"> | ||||
|       <size> | ||||
|        <width>120</width> | ||||
|        <height>90</height> | ||||
|       </size> | ||||
|      </property> | ||||
|      <property name="flow"> | ||||
|       <enum>QListView::LeftToRight</enum> | ||||
|      </property> | ||||
|      <property name="isWrapping" stdset="0"> | ||||
|       <bool>true</bool> | ||||
|      </property> | ||||
|      <property name="viewMode"> | ||||
|       <enum>QListView::IconMode</enum> | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item> | ||||
|     <layout class="QHBoxLayout" name="horizontalLayout"> | ||||
|      <item> | ||||
|       <spacer name="horizontalSpacer"> | ||||
|        <property name="orientation"> | ||||
|         <enum>Qt::Horizontal</enum> | ||||
|        </property> | ||||
|        <property name="sizeHint" stdset="0"> | ||||
|         <size> | ||||
|          <width>40</width> | ||||
|          <height>20</height> | ||||
|         </size> | ||||
|        </property> | ||||
|       </spacer> | ||||
|      </item> | ||||
|      <item> | ||||
|       <widget class="QPushButton" name="closeBtn"> | ||||
|        <property name="text"> | ||||
|         <string>Close</string> | ||||
|        </property> | ||||
|       </widget> | ||||
|      </item> | ||||
|      <item> | ||||
|       <widget class="QPushButton" name="uploadBtn"> | ||||
|        <property name="text"> | ||||
|         <string>Upload</string> | ||||
|        </property> | ||||
|       </widget> | ||||
|      </item> | ||||
|     </layout> | ||||
|    </item> | ||||
|   </layout> | ||||
|  </widget> | ||||
|  <resources> | ||||
|   <include location="../../resources/multimc/multimc.qrc"/> | ||||
|  </resources> | ||||
|  <connections> | ||||
|   <connection> | ||||
|    <sender>buttonBox</sender> | ||||
|    <signal>rejected()</signal> | ||||
|    <sender>closeBtn</sender> | ||||
|    <signal>clicked()</signal> | ||||
|    <receiver>ScreenshotDialog</receiver> | ||||
|    <slot>reject()</slot> | ||||
|    <hints> | ||||
|     <hint type="sourcelabel"> | ||||
|      <x>316</x> | ||||
|      <y>260</y> | ||||
|      <x>315</x> | ||||
|      <y>272</y> | ||||
|     </hint> | ||||
|     <hint type="destinationlabel"> | ||||
|      <x>286</x> | ||||
|      <y>274</y> | ||||
|      <x>271</x> | ||||
|      <y>258</y> | ||||
|     </hint> | ||||
|    </hints> | ||||
|   </connection> | ||||
|   | ||||
| @@ -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); | ||||
| 	} | ||||
|   | ||||
| @@ -7,10 +7,10 @@ | ||||
| class ScreenShot | ||||
| { | ||||
| public: | ||||
| 	QString timestamp; | ||||
| 	QDateTime timestamp; | ||||
| 	QString file; | ||||
| 	QString url; | ||||
| 	int imgurIndex; | ||||
| 	QString imgurIndex; | ||||
| }; | ||||
|  | ||||
| class ScreenshotList : public QAbstractListModel | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user