Support paste.gg, hastebin, and mclo.gs
This commit is contained in:
@ -16,8 +16,9 @@
|
||||
QString GuiUtil::uploadPaste(const QString &text, QWidget *parentWidget)
|
||||
{
|
||||
ProgressDialog dialog(parentWidget);
|
||||
auto pasteUrlSetting = APPLICATION->settings()->get("PastebinURL").toString();
|
||||
std::unique_ptr<PasteUpload> paste(new PasteUpload(parentWidget, text, pasteUrlSetting));
|
||||
auto pasteTypeSetting = static_cast<PasteUpload::PasteType>(APPLICATION->settings()->get("PastebinType").toUInt());
|
||||
auto pasteCustomAPIBaseSetting = APPLICATION->settings()->get("PastebinCustomAPIBase").toString();
|
||||
std::unique_ptr<PasteUpload> paste(new PasteUpload(parentWidget, text, pasteCustomAPIBaseSetting, pasteTypeSetting));
|
||||
|
||||
dialog.execWithTask(paste.get());
|
||||
if (!paste->wasSuccessful())
|
||||
|
@ -3,6 +3,7 @@
|
||||
* PolyMC - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
* Copyright (c) 2022 Lenny McLennington <lenny@sneed.church>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -46,15 +47,34 @@
|
||||
#include "settings/SettingsObject.h"
|
||||
#include "tools/BaseProfiler.h"
|
||||
#include "Application.h"
|
||||
#include "net/PasteUpload.h"
|
||||
|
||||
APIPage::APIPage(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::APIPage)
|
||||
{
|
||||
// this is here so you can reorder the entries in the combobox without messing stuff up
|
||||
unsigned int comboBoxEntries[] = {
|
||||
PasteUpload::PasteType::Mclogs,
|
||||
PasteUpload::PasteType::NullPointer,
|
||||
PasteUpload::PasteType::PasteGG,
|
||||
PasteUpload::PasteType::Hastebin
|
||||
};
|
||||
|
||||
static QRegularExpression validUrlRegExp("https?://.+");
|
||||
|
||||
ui->setupUi(this);
|
||||
ui->urlChoices->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->urlChoices));
|
||||
ui->tabWidget->tabBar()->hide();\
|
||||
|
||||
for (auto pasteType : comboBoxEntries) {
|
||||
ui->pasteTypeComboBox->addItem(PasteUpload::PasteTypes.at(pasteType).name, pasteType);
|
||||
}
|
||||
|
||||
connect(ui->pasteTypeComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &APIPage::updateBaseURLPlaceholder);
|
||||
// This function needs to be called even when the ComboBox's index is still in its default state.
|
||||
updateBaseURLPlaceholder(ui->pasteTypeComboBox->currentIndex());
|
||||
ui->baseURLEntry->setValidator(new QRegularExpressionValidator(validUrlRegExp, ui->baseURLEntry));
|
||||
ui->tabWidget->tabBar()->hide();
|
||||
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
@ -63,11 +83,28 @@ APIPage::~APIPage()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void APIPage::updateBaseURLPlaceholder(int index)
|
||||
{
|
||||
ui->baseURLEntry->setPlaceholderText(PasteUpload::PasteTypes.at(ui->pasteTypeComboBox->itemData(index).toUInt()).defaultBase);
|
||||
}
|
||||
|
||||
void APIPage::loadSettings()
|
||||
{
|
||||
auto s = APPLICATION->settings();
|
||||
QString pastebinURL = s->get("PastebinURL").toString();
|
||||
ui->urlChoices->setCurrentText(pastebinURL);
|
||||
|
||||
unsigned int pasteType = s->get("PastebinType").toUInt();
|
||||
QString pastebinURL = s->get("PastebinCustomAPIBase").toString();
|
||||
|
||||
ui->baseURLEntry->setText(pastebinURL);
|
||||
int pasteTypeIndex = ui->pasteTypeComboBox->findData(pasteType);
|
||||
if (pasteTypeIndex == -1)
|
||||
{
|
||||
pasteTypeIndex = ui->pasteTypeComboBox->findData(PasteUpload::PasteType::Mclogs);
|
||||
ui->baseURLEntry->clear();
|
||||
}
|
||||
|
||||
ui->pasteTypeComboBox->setCurrentIndex(pasteTypeIndex);
|
||||
|
||||
QString msaClientID = s->get("MSAClientIDOverride").toString();
|
||||
ui->msaClientID->setText(msaClientID);
|
||||
QString curseKey = s->get("CFKeyOverride").toString();
|
||||
@ -77,8 +114,10 @@ void APIPage::loadSettings()
|
||||
void APIPage::applySettings()
|
||||
{
|
||||
auto s = APPLICATION->settings();
|
||||
QString pastebinURL = ui->urlChoices->currentText();
|
||||
s->set("PastebinURL", pastebinURL);
|
||||
|
||||
s->set("PastebinType", ui->pasteTypeComboBox->currentData().toUInt());
|
||||
s->set("PastebinCustomAPIBase", ui->baseURLEntry->text());
|
||||
|
||||
QString msaClientID = ui->msaClientID->text();
|
||||
s->set("MSAClientIDOverride", msaClientID);
|
||||
QString curseKey = ui->curseKey->text();
|
||||
|
@ -73,6 +73,7 @@ public:
|
||||
void retranslate() override;
|
||||
|
||||
private:
|
||||
void updateBaseURLPlaceholder(int index);
|
||||
void loadSettings();
|
||||
void applySettings();
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>603</width>
|
||||
<height>530</height>
|
||||
<width>512</width>
|
||||
<height>538</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
@ -36,59 +36,30 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_paste">
|
||||
<property name="title">
|
||||
<string>&Pastebin URL</string>
|
||||
<string>Pastebin Service</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<widget class="QLabel" name="pasteServiceTypeLabel">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>Note: only input that starts with <span style=" font-weight:600;">http://</span> or <span style=" font-weight:600;">https://</span> will be accepted.</p></body></html></string>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>false</bool>
|
||||
<string>Paste Service Type</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="urlChoices">
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="insertPolicy">
|
||||
<enum>QComboBox::NoInsert</enum>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string notr="true">https://0x0.st</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
<widget class="QComboBox" name="pasteTypeComboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QLabel" name="baseURLLabel">
|
||||
<property name="text">
|
||||
<string><html><head/><body><p>Here you can choose from a predefined list of paste services, or input the URL of a different paste service of your choice, provided it supports the same protocol as 0x0.st, that is POST a file parameter to the URL and return a link in the response body.</p></body></html></string>
|
||||
<string>Base URL</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::RichText</enum>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="openExternalLinks">
|
||||
<bool>true</bool>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="baseURLEntry">
|
||||
<property name="placeholderText">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -101,13 +72,6 @@
|
||||
<string>&Microsoft Authentication</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
|
Reference in New Issue
Block a user