feat: add ChooseProviderDialog
Allows you to prompt the user for choosing a (mod) provider. This should be fairly independent of the mod updater logic, so it can be used for other ends later down the road :^) Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
		@@ -836,6 +836,8 @@ SET(LAUNCHER_SOURCES
 | 
			
		||||
    ui/dialogs/ModDownloadDialog.h
 | 
			
		||||
    ui/dialogs/ScrollMessageBox.cpp
 | 
			
		||||
    ui/dialogs/ScrollMessageBox.h
 | 
			
		||||
    ui/dialogs/ChooseProviderDialog.h
 | 
			
		||||
    ui/dialogs/ChooseProviderDialog.cpp
 | 
			
		||||
 | 
			
		||||
    # GUI - widgets
 | 
			
		||||
    ui/widgets/Common.cpp
 | 
			
		||||
@@ -941,6 +943,7 @@ qt_wrap_ui(LAUNCHER_UI
 | 
			
		||||
    ui/dialogs/EditAccountDialog.ui
 | 
			
		||||
    ui/dialogs/ReviewMessageBox.ui
 | 
			
		||||
    ui/dialogs/ScrollMessageBox.ui
 | 
			
		||||
    ui/dialogs/ChooseProviderDialog.ui
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
qt_add_resources(LAUNCHER_RESOURCES
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										96
									
								
								launcher/ui/dialogs/ChooseProviderDialog.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								launcher/ui/dialogs/ChooseProviderDialog.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,96 @@
 | 
			
		||||
#include "ChooseProviderDialog.h"
 | 
			
		||||
#include "ui_ChooseProviderDialog.h"
 | 
			
		||||
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
#include <QRadioButton>
 | 
			
		||||
 | 
			
		||||
#include "modplatform/ModIndex.h"
 | 
			
		||||
 | 
			
		||||
static ModPlatform::ProviderCapabilities ProviderCaps;
 | 
			
		||||
 | 
			
		||||
ChooseProviderDialog::ChooseProviderDialog(QWidget* parent, bool single_choice, bool allow_skipping)
 | 
			
		||||
    : QDialog(parent), ui(new Ui::ChooseProviderDialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
    addProviders();
 | 
			
		||||
    m_providers.button(0)->click();
 | 
			
		||||
 | 
			
		||||
    connect(ui->skipOneButton, &QPushButton::clicked, this, &ChooseProviderDialog::skipOne);
 | 
			
		||||
    connect(ui->skipAllButton, &QPushButton::clicked, this, &ChooseProviderDialog::skipAll);
 | 
			
		||||
 | 
			
		||||
    connect(ui->confirmOneButton, &QPushButton::clicked, this, &ChooseProviderDialog::confirmOne);
 | 
			
		||||
    connect(ui->confirmAllButton, &QPushButton::clicked, this, &ChooseProviderDialog::confirmAll);
 | 
			
		||||
 | 
			
		||||
    if (single_choice) {
 | 
			
		||||
        ui->providersLayout->removeWidget(ui->skipAllButton);
 | 
			
		||||
        ui->providersLayout->removeWidget(ui->confirmAllButton);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!allow_skipping) {
 | 
			
		||||
        ui->providersLayout->removeWidget(ui->skipOneButton);
 | 
			
		||||
        ui->providersLayout->removeWidget(ui->skipAllButton);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ChooseProviderDialog::~ChooseProviderDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ChooseProviderDialog::setDescription(QString desc)
 | 
			
		||||
{
 | 
			
		||||
    ui->explanationLabel->setText(desc);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ChooseProviderDialog::skipOne()
 | 
			
		||||
{
 | 
			
		||||
    reject();
 | 
			
		||||
}
 | 
			
		||||
void ChooseProviderDialog::skipAll()
 | 
			
		||||
{
 | 
			
		||||
    m_response.skip_all = true;
 | 
			
		||||
    reject();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ChooseProviderDialog::confirmOne()
 | 
			
		||||
{
 | 
			
		||||
    m_response.chosen = getSelectedProvider();
 | 
			
		||||
    m_response.try_others = ui->tryOthersCheckbox->isChecked();
 | 
			
		||||
    accept();
 | 
			
		||||
}
 | 
			
		||||
void ChooseProviderDialog::confirmAll()
 | 
			
		||||
{
 | 
			
		||||
    m_response.chosen = getSelectedProvider();
 | 
			
		||||
    m_response.confirm_all = true;
 | 
			
		||||
    m_response.try_others = ui->tryOthersCheckbox->isChecked();
 | 
			
		||||
    accept();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
auto ChooseProviderDialog::getSelectedProvider() const -> ModPlatform::Provider
 | 
			
		||||
{
 | 
			
		||||
    return ModPlatform::Provider(m_providers.checkedId());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ChooseProviderDialog::addProviders()
 | 
			
		||||
{
 | 
			
		||||
    int btn_index = 0;
 | 
			
		||||
    QRadioButton* btn;
 | 
			
		||||
 | 
			
		||||
    for (auto& provider : { ModPlatform::Provider::MODRINTH, ModPlatform::Provider::FLAME }) {
 | 
			
		||||
        btn = new QRadioButton(ProviderCaps.readableName(provider), this);
 | 
			
		||||
        m_providers.addButton(btn, btn_index++);
 | 
			
		||||
        ui->providersLayout->addWidget(btn);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ChooseProviderDialog::disableInput()
 | 
			
		||||
{
 | 
			
		||||
    for (auto& btn : m_providers.buttons())
 | 
			
		||||
        btn->setEnabled(false);
 | 
			
		||||
 | 
			
		||||
    ui->skipOneButton->setEnabled(false);
 | 
			
		||||
    ui->skipAllButton->setEnabled(false);
 | 
			
		||||
    ui->confirmOneButton->setEnabled(false);
 | 
			
		||||
    ui->confirmAllButton->setEnabled(false);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										56
									
								
								launcher/ui/dialogs/ChooseProviderDialog.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								launcher/ui/dialogs/ChooseProviderDialog.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <QButtonGroup>
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class ChooseProviderDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace ModPlatform {
 | 
			
		||||
enum class Provider;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Mod;
 | 
			
		||||
class NetJob;
 | 
			
		||||
class ModUpdateDialog;
 | 
			
		||||
 | 
			
		||||
class ChooseProviderDialog : public QDialog {
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
    struct Response {
 | 
			
		||||
        bool skip_all = false;
 | 
			
		||||
        bool confirm_all = false;
 | 
			
		||||
 | 
			
		||||
        bool try_others = false;
 | 
			
		||||
 | 
			
		||||
        ModPlatform::Provider chosen;
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
   public:
 | 
			
		||||
    explicit ChooseProviderDialog(QWidget* parent, bool single_choice = false, bool allow_skipping = true);
 | 
			
		||||
    ~ChooseProviderDialog();
 | 
			
		||||
 | 
			
		||||
    auto getResponse() const -> Response { return m_response; }
 | 
			
		||||
 | 
			
		||||
    void setDescription(QString desc);
 | 
			
		||||
 | 
			
		||||
   private slots:
 | 
			
		||||
    void skipOne();
 | 
			
		||||
    void skipAll();
 | 
			
		||||
    void confirmOne();
 | 
			
		||||
    void confirmAll();
 | 
			
		||||
 | 
			
		||||
   private:
 | 
			
		||||
    void addProviders();
 | 
			
		||||
    void disableInput();
 | 
			
		||||
 | 
			
		||||
    auto getSelectedProvider() const -> ModPlatform::Provider;
 | 
			
		||||
 | 
			
		||||
   private:
 | 
			
		||||
    Ui::ChooseProviderDialog* ui;
 | 
			
		||||
 | 
			
		||||
    QButtonGroup m_providers;
 | 
			
		||||
 | 
			
		||||
    Response m_response;
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										89
									
								
								launcher/ui/dialogs/ChooseProviderDialog.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								launcher/ui/dialogs/ChooseProviderDialog.ui
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,89 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>ChooseProviderDialog</class>
 | 
			
		||||
 <widget class="QDialog" name="ChooseProviderDialog">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>453</width>
 | 
			
		||||
    <height>197</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Choose a mod provider</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QGridLayout" name="gridLayout">
 | 
			
		||||
   <item row="0" column="0" colspan="2">
 | 
			
		||||
    <widget class="QLabel" name="explanationLabel">
 | 
			
		||||
     <property name="alignment">
 | 
			
		||||
      <set>Qt::AlignJustify|Qt::AlignTop</set>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="wordWrap">
 | 
			
		||||
      <bool>true</bool>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="indent">
 | 
			
		||||
      <number>-1</number>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item row="1" column="0" colspan="2">
 | 
			
		||||
    <layout class="QFormLayout" name="providersLayout">
 | 
			
		||||
     <property name="labelAlignment">
 | 
			
		||||
      <set>Qt::AlignHCenter|Qt::AlignTop</set>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="formAlignment">
 | 
			
		||||
      <set>Qt::AlignHCenter|Qt::AlignTop</set>
 | 
			
		||||
     </property>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item row="4" column="0" colspan="2">
 | 
			
		||||
    <layout class="QHBoxLayout" name="buttonsLayout">
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="skipOneButton">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Skip this mod</string>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="skipAllButton">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Skip all</string>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="confirmAllButton">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Confirm for all</string>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
     <item>
 | 
			
		||||
      <widget class="QPushButton" name="confirmOneButton">
 | 
			
		||||
       <property name="text">
 | 
			
		||||
        <string>Confirm</string>
 | 
			
		||||
       </property>
 | 
			
		||||
       <property name="default">
 | 
			
		||||
        <bool>true</bool>
 | 
			
		||||
       </property>
 | 
			
		||||
      </widget>
 | 
			
		||||
     </item>
 | 
			
		||||
    </layout>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item row="3" column="0">
 | 
			
		||||
    <widget class="QCheckBox" name="tryOthersCheckbox">
 | 
			
		||||
     <property name="text">
 | 
			
		||||
      <string>Try to automatically use other providers if the chosen one fails</string>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="checked">
 | 
			
		||||
      <bool>true</bool>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections/>
 | 
			
		||||
</ui>
 | 
			
		||||
		Reference in New Issue
	
	Block a user