| 53 | #include "ui/GuiUtil.h" |
| 54 | |
| 55 | APIPage::APIPage(QWidget *parent) : |
| 56 | QWidget(parent), |
| 57 | ui(new Ui::APIPage) |
| 58 | { |
| 59 | // This is here so you can reorder the entries in the combobox without messing stuff up |
| 60 | int comboBoxEntries[] = { |
| 61 | PasteUpload::PasteType::Mclogs, |
| 62 | PasteUpload::PasteType::NullPointer, |
| 63 | PasteUpload::PasteType::PasteGG, |
| 64 | PasteUpload::PasteType::Hastebin |
| 65 | }; |
| 66 | |
| 67 | static QRegularExpression validUrlRegExp("https?://.+"); |
| 68 | static QRegularExpression validMSAClientID(QRegularExpression::anchoredPattern( |
| 69 | "[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")); |
| 70 | static QRegularExpression validFlameKey(QRegularExpression::anchoredPattern( |
| 71 | "\\$2[ayb]\\$.{56}")); |
| 72 | |
| 73 | ui->setupUi(this); |
| 74 | |
| 75 | for (auto pasteType : comboBoxEntries) { |
| 76 | ui->pasteTypeComboBox->addItem(PasteUpload::PasteTypes.at(pasteType).name, pasteType); |
| 77 | } |
| 78 | |
| 79 | void (QComboBox::*currentIndexChangedSignal)(int) (&QComboBox::currentIndexChanged); |
| 80 | connect(ui->pasteTypeComboBox, currentIndexChangedSignal, this, &APIPage::updateBaseURLPlaceholder); |
| 81 | // This function needs to be called even when the ComboBox's index is still in its default state. |
| 82 | updateBaseURLPlaceholder(ui->pasteTypeComboBox->currentIndex()); |
| 83 | ui->baseURLEntry->setValidator(new TrimmedRegExValidator(validUrlRegExp, ui->baseURLEntry)); |
| 84 | ui->msaClientID->setValidator(new TrimmedRegExValidator(validMSAClientID, ui->msaClientID)); |
| 85 | ui->flameKey->setValidator(new TrimmedRegExValidator(validFlameKey, ui->flameKey)); |
| 86 | |
| 87 | ui->metaURL->setPlaceholderText(BuildConfig.META_URL); |
| 88 | ui->userAgentLineEdit->setPlaceholderText(BuildConfig.USER_AGENT); |
| 89 | |
| 90 | if (BuildConfig.FLAME_API_KEY_API_URL.isEmpty()) |
| 91 | ui->fetchKeyButton->hide(); |
| 92 | |
| 93 | loadSettings(); |
| 94 | |
| 95 | resetBaseURLNote(); |
| 96 | connect(ui->pasteTypeComboBox, currentIndexChangedSignal, this, &APIPage::updateBaseURLNote); |
| 97 | connect(ui->baseURLEntry, &QLineEdit::textEdited, this, &APIPage::resetBaseURLNote); |
| 98 | |
| 99 | connect(ui->fetchKeyButton, &QPushButton::clicked, this, &APIPage::fetchKeyButtonPressed); |
| 100 | } |
| 101 | |
| 102 | APIPage::~APIPage() |
| 103 | { |