Add mod website button thing feature widget. It is super effective.
This commit is contained in:
		@@ -24,6 +24,7 @@
 | 
			
		||||
 | 
			
		||||
#include <pathutils.h>
 | 
			
		||||
#include <QFileDialog>
 | 
			
		||||
//#include <QMessageBox>
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QEvent>
 | 
			
		||||
#include <QKeyEvent>
 | 
			
		||||
@@ -342,4 +343,36 @@ void LegacyModEditDialog::on_viewTexPackBtn_clicked()
 | 
			
		||||
void LegacyModEditDialog::on_buttonBox_rejected()
 | 
			
		||||
{
 | 
			
		||||
	close();
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//FIXME: too much copypasta makes peterix a sad hacker. BUT IT'S SO DELICIOUS!
 | 
			
		||||
 | 
			
		||||
void LegacyModEditDialog::on_coreWebsite_clicked()
 | 
			
		||||
{
 | 
			
		||||
	int first, last;
 | 
			
		||||
	auto list = ui->coreModsTreeView->selectionModel()->selectedRows();
 | 
			
		||||
 | 
			
		||||
	if (!lastfirst(list, first, last))
 | 
			
		||||
		return;
 | 
			
		||||
	showWebsiteForMod(this, m_coremods->operator[](first));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LegacyModEditDialog::on_jarWebsite_clicked()
 | 
			
		||||
{
 | 
			
		||||
	int first, last;
 | 
			
		||||
	auto list = ui->jarModsTreeView->selectionModel()->selectedRows();
 | 
			
		||||
 | 
			
		||||
	if (!lastfirst(list, first, last))
 | 
			
		||||
		return;
 | 
			
		||||
	showWebsiteForMod(this, m_jarmods->operator[](first));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void LegacyModEditDialog::on_loaderWebsite_clicked()
 | 
			
		||||
{
 | 
			
		||||
	int first, last;
 | 
			
		||||
	auto list = ui->loaderModTreeView->selectionModel()->selectedRows();
 | 
			
		||||
 | 
			
		||||
	if (!lastfirst(list, first, last))
 | 
			
		||||
		return;
 | 
			
		||||
	showWebsiteForMod(this, m_mods->operator[](first));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,7 +3,7 @@
 | 
			
		||||
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
			
		||||
 * you may not use this file except in compliance with the License.
 | 
			
		||||
 * You may obtain a copy of the License at
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
			
		||||
 *
 | 
			
		||||
 * Unless required by applicable law or agreed to in writing, software
 | 
			
		||||
@@ -19,51 +19,60 @@
 | 
			
		||||
#include "logic/LegacyInstance.h"
 | 
			
		||||
#include <logic/net/DownloadJob.h>
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class LegacyModEditDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class LegacyModEditDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	explicit LegacyModEditDialog(LegacyInstance* inst, QWidget *parent = 0);
 | 
			
		||||
	explicit LegacyModEditDialog(LegacyInstance *inst, QWidget *parent = 0);
 | 
			
		||||
	~LegacyModEditDialog();
 | 
			
		||||
	
 | 
			
		||||
private slots:
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
private
 | 
			
		||||
slots:
 | 
			
		||||
 | 
			
		||||
	void on_addJarBtn_clicked();
 | 
			
		||||
	void on_rmJarBtn_clicked();
 | 
			
		||||
	void on_addForgeBtn_clicked();
 | 
			
		||||
	void on_moveJarUpBtn_clicked();
 | 
			
		||||
	void on_moveJarDownBtn_clicked();
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	void on_addCoreBtn_clicked();
 | 
			
		||||
	void on_rmCoreBtn_clicked();
 | 
			
		||||
	void on_viewCoreBtn_clicked();
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	void on_addModBtn_clicked();
 | 
			
		||||
	void on_rmModBtn_clicked();
 | 
			
		||||
	void on_viewModBtn_clicked();
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	void on_addTexPackBtn_clicked();
 | 
			
		||||
	void on_rmTexPackBtn_clicked();
 | 
			
		||||
	void on_viewTexPackBtn_clicked();
 | 
			
		||||
 | 
			
		||||
	void on_jarWebsite_clicked();
 | 
			
		||||
	void on_loaderWebsite_clicked();
 | 
			
		||||
	void on_coreWebsite_clicked();
 | 
			
		||||
 | 
			
		||||
	// Questionable: SettingsDialog doesn't need this for some reason?
 | 
			
		||||
	void on_buttonBox_rejected();
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	bool eventFilter(QObject *obj, QEvent *ev);
 | 
			
		||||
	bool jarListFilter( QKeyEvent* ev );
 | 
			
		||||
	bool coreListFilter( QKeyEvent* ev );
 | 
			
		||||
	bool loaderListFilter( QKeyEvent* ev );
 | 
			
		||||
	bool texturePackListFilter( QKeyEvent* ev );
 | 
			
		||||
	bool jarListFilter(QKeyEvent *ev);
 | 
			
		||||
	bool coreListFilter(QKeyEvent *ev);
 | 
			
		||||
	bool loaderListFilter(QKeyEvent *ev);
 | 
			
		||||
	bool texturePackListFilter(QKeyEvent *ev);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	Ui::LegacyModEditDialog *ui;
 | 
			
		||||
	std::shared_ptr<ModList> m_mods;
 | 
			
		||||
	std::shared_ptr<ModList> m_coremods;
 | 
			
		||||
	std::shared_ptr<ModList> m_jarmods;
 | 
			
		||||
	std::shared_ptr<ModList> m_texturepacks;
 | 
			
		||||
	LegacyInstance * m_inst;
 | 
			
		||||
	LegacyInstance *m_inst;
 | 
			
		||||
	DownloadJobPtr forgeJob;
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -57,6 +57,13 @@
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <widget class="QPushButton" name="jarWebsite">
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>Website</string>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <spacer name="jarModsButtonSpacer">
 | 
			
		||||
           <property name="orientation">
 | 
			
		||||
@@ -116,6 +123,13 @@
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <widget class="QPushButton" name="coreWebsite">
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>Website</string>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <spacer name="coreModsButtonSpacer">
 | 
			
		||||
           <property name="orientation">
 | 
			
		||||
@@ -171,6 +185,13 @@
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <widget class="QPushButton" name="loaderWebsite">
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>Website</string>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <spacer name="mlModsButtonSpacer">
 | 
			
		||||
           <property name="orientation">
 | 
			
		||||
 
 | 
			
		||||
@@ -1,17 +1,40 @@
 | 
			
		||||
#include "ModEditDialogCommon.h"
 | 
			
		||||
 | 
			
		||||
bool lastfirst (QModelIndexList & list, int & first, int & last)
 | 
			
		||||
#include <QDesktopServices>
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QUrl>
 | 
			
		||||
bool lastfirst(QModelIndexList &list, int &first, int &last)
 | 
			
		||||
{
 | 
			
		||||
	if(!list.size())
 | 
			
		||||
	if (!list.size())
 | 
			
		||||
		return false;
 | 
			
		||||
	first = last = list[0].row();
 | 
			
		||||
	for(auto item: list)
 | 
			
		||||
	for (auto item : list)
 | 
			
		||||
	{
 | 
			
		||||
		int row = item.row();
 | 
			
		||||
		if(row < first)
 | 
			
		||||
		if (row < first)
 | 
			
		||||
			first = row;
 | 
			
		||||
		if(row > last)
 | 
			
		||||
		if (row > last)
 | 
			
		||||
			last = row;
 | 
			
		||||
	}
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void showWebsiteForMod(QWidget *parentDlg, Mod &m)
 | 
			
		||||
{
 | 
			
		||||
	QString url = m.homeurl();
 | 
			
		||||
	if (url.size())
 | 
			
		||||
	{
 | 
			
		||||
		// catch the cases where the protocol is missing
 | 
			
		||||
		if(!url.startsWith("http"))
 | 
			
		||||
		{
 | 
			
		||||
			url = "http://" + url;
 | 
			
		||||
		}
 | 
			
		||||
		QDesktopServices::openUrl(url);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QMessageBox::warning(
 | 
			
		||||
			parentDlg, parentDlg->tr("How sad!"),
 | 
			
		||||
			parentDlg->tr("The mod author didn't provide a website link for this mod."));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <QAbstractItemModel>
 | 
			
		||||
#include <logic/Mod.h>
 | 
			
		||||
 | 
			
		||||
bool lastfirst (QModelIndexList & list, int & first, int & last);
 | 
			
		||||
bool lastfirst (QModelIndexList & list, int & first, int & last);
 | 
			
		||||
 | 
			
		||||
void showWebsiteForMod(QWidget * parentDlg, Mod& m);
 | 
			
		||||
@@ -30,6 +30,7 @@
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
#include <QEvent>
 | 
			
		||||
#include <QKeyEvent>
 | 
			
		||||
#include <QDesktopServices>
 | 
			
		||||
 | 
			
		||||
OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
 | 
			
		||||
	: m_inst(inst), QDialog(parent), ui(new Ui::OneSixModEditDialog)
 | 
			
		||||
@@ -296,3 +297,13 @@ void OneSixModEditDialog::on_viewResPackBtn_clicked()
 | 
			
		||||
{
 | 
			
		||||
	openDirInDefaultProgram(m_inst->resourcePacksDir(), true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void OneSixModEditDialog::on_loaderWebsite_clicked()
 | 
			
		||||
{
 | 
			
		||||
	int first, last;
 | 
			
		||||
	auto list = ui->loaderModTreeView->selectionModel()->selectedRows();
 | 
			
		||||
 | 
			
		||||
	if (!lastfirst(list, first, last))
 | 
			
		||||
		return;
 | 
			
		||||
	showWebsiteForMod(this, m_mods->operator[](first));
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -44,6 +44,7 @@ private slots:
 | 
			
		||||
	void on_forgeBtn_clicked();
 | 
			
		||||
	void on_customizeBtn_clicked();
 | 
			
		||||
	void on_revertBtn_clicked();
 | 
			
		||||
	void on_loaderWebsite_clicked();
 | 
			
		||||
    void updateVersionControls();
 | 
			
		||||
	void disableVersionControls();
 | 
			
		||||
protected:
 | 
			
		||||
 
 | 
			
		||||
@@ -184,6 +184,13 @@
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <widget class="QPushButton" name="loaderWebsite">
 | 
			
		||||
           <property name="text">
 | 
			
		||||
            <string>Website</string>
 | 
			
		||||
           </property>
 | 
			
		||||
          </widget>
 | 
			
		||||
         </item>
 | 
			
		||||
         <item>
 | 
			
		||||
          <spacer name="verticalSpacer">
 | 
			
		||||
           <property name="orientation">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user