|
17 | 17 | #include <QShortcut> |
18 | 18 | #include <QToolTip> |
19 | 19 | #include <QCursor> |
| 20 | +#include <QCheckBox> |
20 | 21 | #include <QWheelEvent> |
21 | 22 |
|
22 | 23 | ScreenshotDisplay::ScreenshotDisplay(const QPixmap& pixmap, QWidget* parent, ConfigManager* configManager) |
@@ -429,22 +430,46 @@ void ScreenshotDisplay::onPublishRequested() { |
429 | 430 | qDebug() << "Network Error:" << reply->errorString(); |
430 | 431 | }); |
431 | 432 |
|
432 | | - connect(reply, &QNetworkReply::finished, this, [reply, file, tempFilePath, this, progressDialog, screenGeometry]() { |
| 433 | + connect(reply, &QNetworkReply::finished, this, [reply, file, tempFilePath, this, progressDialog, screenGeometry, loginInfo]() { |
433 | 434 | progressDialog->close(); |
434 | 435 |
|
435 | 436 | if (reply->error() == QNetworkReply::NoError) { |
436 | 437 | QByteArray response = reply->readAll(); |
437 | 438 | QJsonDocument jsonResponse = QJsonDocument::fromJson(response); |
438 | 439 | QJsonObject jsonObject = jsonResponse.object(); |
439 | 440 | QString url = jsonObject["url"].toString(); |
| 441 | + QString id = QString::number(jsonObject["id"].toInt()); |
440 | 442 | QString link = SCREEN_ME_HOST + "/" + url; |
441 | 443 |
|
442 | 444 | QMessageBox msgBox(this); |
443 | 445 | msgBox.setWindowTitle("Screenshot Uploaded"); |
444 | | - msgBox.setText("Screenshot uploaded successfully! Link: " + link); |
| 446 | + msgBox.setText("Screenshot uploaded successfully ! Link: " + link); |
445 | 447 | QPushButton* copyButton = msgBox.addButton(tr("Copy"), QMessageBox::ActionRole); |
446 | 448 | msgBox.addButton(QMessageBox::Ok); |
447 | 449 |
|
| 450 | + QCheckBox* privateCheckBox = nullptr; |
| 451 | + if (!loginInfo["token"].toString().isEmpty()) { |
| 452 | + privateCheckBox = new QCheckBox("Private", &msgBox); |
| 453 | + msgBox.setCheckBox(privateCheckBox); |
| 454 | + |
| 455 | + connect(privateCheckBox, &QCheckBox::toggled, this, [id, loginInfo](bool checked) { |
| 456 | + QNetworkAccessManager* manager = new QNetworkAccessManager(); |
| 457 | + QUrl url(SCREEN_ME_HOST + "/api/screenshot/" + id); |
| 458 | + QNetworkRequest request(url); |
| 459 | + |
| 460 | + request.setRawHeader("Authorization", "Bearer " + loginInfo["token"].toString().toUtf8()); |
| 461 | + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); |
| 462 | + |
| 463 | + QJsonObject json; |
| 464 | + json["privacy"] = checked ? "private" : "public"; |
| 465 | + QJsonDocument doc(json); |
| 466 | + QByteArray data = doc.toJson(); |
| 467 | + |
| 468 | + QNetworkReply* reply = manager->sendCustomRequest(request, "PATCH", data); |
| 469 | + connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); |
| 470 | + }); |
| 471 | + } |
| 472 | + |
448 | 473 | connect(copyButton, &QPushButton::clicked, [link]() { |
449 | 474 | QClipboard* clipboard = QGuiApplication::clipboard(); |
450 | 475 | clipboard->setText(link); |
@@ -475,9 +500,9 @@ void ScreenshotDisplay::onPublishRequested() { |
475 | 500 | emit screenshotClosed(); |
476 | 501 | }); |
477 | 502 | } |
478 | | - |
479 | 503 | } |
480 | 504 |
|
| 505 | + |
481 | 506 | void ScreenshotDisplay::onCloseRequested() { |
482 | 507 | close(); |
483 | 508 | } |
|
0 commit comments