2021-01-18 12:58:54 +05:30
/* Copyright 2013-2021 MultiMC Contributors
2013-02-02 00:37:36 +05:30
*
* 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
2013-10-06 18:13:46 +05:30
*
2013-02-02 00:37:36 +05:30
* http : //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing , software
* distributed under the License is distributed on an " AS IS " BASIS ,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
* See the License for the specific language governing permissions and
* limitations under the License .
*/
2013-11-04 07:23:05 +05:30
# include "MultiMC.h"
# include "NewInstanceDialog.h"
# include "ui_NewInstanceDialog.h"
2013-02-02 00:37:36 +05:30
2015-02-09 06:21:14 +05:30
# include <BaseVersion.h>
# include <icons/IconList.h>
# include <tasks/Task.h>
# include <InstanceList.h>
2013-04-23 02:09:41 +05:30
2013-11-04 07:23:05 +05:30
# include "VersionSelectDialog.h"
2013-09-18 03:30:35 +05:30
# include "ProgressDialog.h"
2013-08-10 22:04:08 +05:30
# include "IconPickerDialog.h"
2013-04-23 02:09:41 +05:30
2013-02-02 00:37:36 +05:30
# include <QLayout>
2013-04-23 02:09:41 +05:30
# include <QPushButton>
2015-02-13 02:31:20 +05:30
# include <QFileDialog>
# include <QValidator>
2018-03-19 07:06:12 +05:30
# include <QDialogButtonBox>
2015-02-13 02:31:20 +05:30
2018-03-19 07:06:12 +05:30
# include "widgets/PageContainer.h"
# include <pages/modplatform/VanillaPage.h>
2020-08-25 03:43:43 +05:30
# include <pages/modplatform/atlauncher/AtlPage.h>
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
# include <pages/modplatform/ftb/FtbPage.h>
2019-11-04 04:18:12 +05:30
# include <pages/modplatform/legacy_ftb/Page.h>
2021-03-24 05:29:43 +05:30
# include <pages/modplatform/flame/FlamePage.h>
2019-07-10 01:21:19 +05:30
# include <pages/modplatform/ImportPage.h>
2020-06-07 21:16:12 +05:30
# include <pages/modplatform/technic/TechnicPage.h>
2019-07-10 01:34:52 +05:30
2017-04-22 09:41:26 +05:30
NewInstanceDialog : : NewInstanceDialog ( const QString & initialGroup , const QString & url , QWidget * parent )
2018-07-15 18:21:05 +05:30
: QDialog ( parent ) , ui ( new Ui : : NewInstanceDialog )
2013-02-02 00:37:36 +05:30
{
2018-07-15 18:21:05 +05:30
ui - > setupUi ( this ) ;
2015-02-13 02:31:20 +05:30
2018-07-15 18:21:05 +05:30
setWindowIcon ( MMC - > getThemedIcon ( " new " ) ) ;
2017-03-20 05:14:49 +05:30
2018-07-15 18:21:05 +05:30
InstIconKey = " default " ;
ui - > iconButton - > setIcon ( MMC - > icons ( ) - > getIcon ( InstIconKey ) ) ;
2015-02-13 02:31:20 +05:30
2018-07-15 18:21:05 +05:30
auto groups = MMC - > instances ( ) - > getGroups ( ) . toSet ( ) ;
auto groupList = QStringList ( groups . toList ( ) ) ;
groupList . sort ( Qt : : CaseInsensitive ) ;
groupList . removeOne ( " " ) ;
groupList . push_front ( initialGroup ) ;
groupList . push_front ( " " ) ;
ui - > groupBox - > addItems ( groupList ) ;
int index = groupList . indexOf ( initialGroup ) ;
if ( index = = - 1 )
{
index = 0 ;
}
ui - > groupBox - > setCurrentIndex ( index ) ;
ui - > groupBox - > lineEdit ( ) - > setPlaceholderText ( tr ( " No group " ) ) ;
2015-08-21 12:30:35 +05:30
2018-03-01 00:12:30 +05:30
2018-07-31 05:50:04 +05:30
// NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not move this below.
m_buttons = new QDialogButtonBox ( QDialogButtonBox : : Help | QDialogButtonBox : : Ok | QDialogButtonBox : : Cancel ) ;
2018-03-01 00:12:30 +05:30
2018-07-15 18:21:05 +05:30
m_container = new PageContainer ( this ) ;
m_container - > setSizePolicy ( QSizePolicy : : Policy : : Preferred , QSizePolicy : : Policy : : Expanding ) ;
m_container - > layout ( ) - > setContentsMargins ( 0 , 0 , 0 , 0 ) ;
ui - > verticalLayout - > insertWidget ( 2 , m_container ) ;
2018-03-01 00:12:30 +05:30
2018-07-15 18:21:05 +05:30
m_container - > addButtons ( m_buttons ) ;
2018-07-23 04:19:26 +05:30
// Bonk Qt over its stupid head and make sure it understands which button is the default one...
// See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button
auto OkButton = m_buttons - > button ( QDialogButtonBox : : Ok ) ;
OkButton - > setDefault ( true ) ;
OkButton - > setAutoDefault ( true ) ;
connect ( OkButton , & QPushButton : : clicked , this , & NewInstanceDialog : : accept ) ;
auto CancelButton = m_buttons - > button ( QDialogButtonBox : : Cancel ) ;
CancelButton - > setDefault ( false ) ;
CancelButton - > setAutoDefault ( false ) ;
connect ( CancelButton , & QPushButton : : clicked , this , & NewInstanceDialog : : reject ) ;
auto HelpButton = m_buttons - > button ( QDialogButtonBox : : Help ) ;
HelpButton - > setDefault ( false ) ;
HelpButton - > setAutoDefault ( false ) ;
connect ( HelpButton , & QPushButton : : clicked , m_container , & PageContainer : : help ) ;
2018-03-19 07:06:12 +05:30
2018-07-15 18:21:05 +05:30
if ( ! url . isEmpty ( ) )
{
2019-07-10 01:34:52 +05:30
QUrl actualUrl ( url ) ;
2019-11-18 05:08:36 +05:30
m_container - > selectPage ( " import " ) ;
importPage - > setUrl ( url ) ;
2018-07-15 18:21:05 +05:30
}
2018-03-01 00:12:30 +05:30
2018-07-15 18:21:05 +05:30
updateDialogState ( ) ;
2018-03-19 07:06:12 +05:30
2018-07-15 18:21:05 +05:30
restoreGeometry ( QByteArray : : fromBase64 ( MMC - > settings ( ) - > get ( " NewInstanceGeometry " ) . toByteArray ( ) ) ) ;
2013-04-23 02:09:41 +05:30
}
2018-03-28 01:32:57 +05:30
void NewInstanceDialog : : reject ( )
{
2018-07-15 18:21:05 +05:30
MMC - > settings ( ) - > set ( " NewInstanceGeometry " , saveGeometry ( ) . toBase64 ( ) ) ;
QDialog : : reject ( ) ;
2018-03-28 01:32:57 +05:30
}
void NewInstanceDialog : : accept ( )
{
2018-07-15 18:21:05 +05:30
MMC - > settings ( ) - > set ( " NewInstanceGeometry " , saveGeometry ( ) . toBase64 ( ) ) ;
importIconNow ( ) ;
QDialog : : accept ( ) ;
2018-03-28 01:32:57 +05:30
}
2018-03-19 07:06:12 +05:30
QList < BasePage * > NewInstanceDialog : : getPages ( )
2017-03-20 05:14:49 +05:30
{
2019-07-10 01:21:19 +05:30
importPage = new ImportPage ( this ) ;
2021-03-24 05:29:43 +05:30
flamePage = new FlamePage ( this ) ;
2020-06-07 21:16:12 +05:30
auto technicPage = new TechnicPage ( this ) ;
2018-07-15 18:21:05 +05:30
return
{
new VanillaPage ( this ) ,
importPage ,
2020-08-25 03:43:43 +05:30
new AtlPage ( this ) ,
2021-03-24 05:29:43 +05:30
flamePage ,
GH-3095 New FTB platform support
Models are based on the models from my go-modpacksch library.
License:
========
The MIT License (MIT)
Copyright (c) Jamie Mansfield <https://www.jamiemansfield.me/>
Copyright (c) contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2020-06-07 20:44:47 +05:30
new FtbPage ( this ) ,
2019-11-04 04:18:12 +05:30
new LegacyFTB : : Page ( this ) ,
2021-03-24 05:29:43 +05:30
technicPage
2018-07-15 18:21:05 +05:30
} ;
2018-03-19 07:06:12 +05:30
}
QString NewInstanceDialog : : dialogTitle ( )
{
2018-07-15 18:21:05 +05:30
return tr ( " New Instance " ) ;
2017-03-20 05:14:49 +05:30
}
2013-05-04 01:11:37 +05:30
NewInstanceDialog : : ~ NewInstanceDialog ( )
2013-04-23 02:09:41 +05:30
{
2018-07-15 18:21:05 +05:30
delete ui ;
2013-04-23 02:09:41 +05:30
}
2018-03-19 07:06:12 +05:30
void NewInstanceDialog : : setSuggestedPack ( const QString & name , InstanceTask * task )
2013-04-23 02:09:41 +05:30
{
2018-07-15 18:21:05 +05:30
creationTask . reset ( task ) ;
ui - > instNameTextBox - > setPlaceholderText ( name ) ;
2018-03-01 00:12:30 +05:30
2018-08-02 04:22:31 +05:30
if ( ! task )
{
ui - > iconButton - > setIcon ( MMC - > icons ( ) - > getIcon ( " default " ) ) ;
importIcon = false ;
}
2018-07-15 18:21:05 +05:30
auto allowOK = task & & ! instName ( ) . isEmpty ( ) ;
m_buttons - > button ( QDialogButtonBox : : Ok ) - > setEnabled ( allowOK ) ;
2013-04-23 02:09:41 +05:30
}
2018-04-07 19:45:58 +05:30
void NewInstanceDialog : : setSuggestedIconFromFile ( const QString & path , const QString & name )
{
2018-07-15 18:21:05 +05:30
importIcon = true ;
importIconPath = path ;
importIconName = name ;
2018-04-07 19:45:58 +05:30
2018-07-15 18:21:05 +05:30
//Hmm, for some reason they can be to small
ui - > iconButton - > setIcon ( QIcon ( path ) ) ;
2018-04-07 19:45:58 +05:30
}
2021-06-19 19:49:39 +05:30
void NewInstanceDialog : : setSuggestedIcon ( const QString & key )
{
auto icon = MMC - > icons ( ) - > getIcon ( key ) ;
importIcon = false ;
ui - > iconButton - > setIcon ( icon ) ;
}
2018-03-19 07:06:12 +05:30
InstanceTask * NewInstanceDialog : : extractTask ( )
2013-04-23 02:09:41 +05:30
{
2018-07-15 18:21:05 +05:30
InstanceTask * extracted = creationTask . get ( ) ;
creationTask . release ( ) ;
extracted - > setName ( instName ( ) ) ;
extracted - > setGroup ( instGroup ( ) ) ;
extracted - > setIcon ( iconKey ( ) ) ;
return extracted ;
2018-03-19 07:06:12 +05:30
}
2013-10-06 18:13:46 +05:30
2018-03-19 07:06:12 +05:30
void NewInstanceDialog : : updateDialogState ( )
{
2018-07-15 18:21:05 +05:30
auto allowOK = creationTask & & ! instName ( ) . isEmpty ( ) ;
2018-07-23 04:19:26 +05:30
auto OkButton = m_buttons - > button ( QDialogButtonBox : : Ok ) ;
if ( OkButton - > isEnabled ( ) ! = allowOK )
{
OkButton - > setEnabled ( allowOK ) ;
}
2013-04-23 02:09:41 +05:30
}
2013-04-23 03:45:18 +05:30
QString NewInstanceDialog : : instName ( ) const
{
2018-07-29 01:38:09 +05:30
auto result = ui - > instNameTextBox - > text ( ) . trimmed ( ) ;
2018-07-15 18:21:05 +05:30
if ( result . size ( ) )
{
2018-07-29 01:38:09 +05:30
return result ;
2018-07-15 18:21:05 +05:30
}
2018-07-29 01:38:09 +05:30
result = ui - > instNameTextBox - > placeholderText ( ) . trimmed ( ) ;
2018-07-15 18:21:05 +05:30
if ( result . size ( ) )
{
2018-07-29 01:38:09 +05:30
return result ;
2018-07-15 18:21:05 +05:30
}
return QString ( ) ;
2013-04-23 03:45:18 +05:30
}
2015-08-21 12:30:35 +05:30
2014-11-09 01:47:28 +05:30
QString NewInstanceDialog : : instGroup ( ) const
{
2018-07-15 18:21:05 +05:30
return ui - > groupBox - > currentText ( ) ;
2014-11-09 01:47:28 +05:30
}
2013-04-23 03:45:18 +05:30
QString NewInstanceDialog : : iconKey ( ) const
{
2018-07-15 18:21:05 +05:30
return InstIconKey ;
2013-04-23 03:45:18 +05:30
}
2013-05-07 07:58:28 +05:30
2013-08-10 22:04:08 +05:30
void NewInstanceDialog : : on_iconButton_clicked ( )
{
2018-07-15 18:21:05 +05:30
importIconNow ( ) ; //so the user can switch back
IconPickerDialog dlg ( this ) ;
dlg . execWithSelection ( InstIconKey ) ;
2013-10-06 18:13:46 +05:30
2018-07-15 18:21:05 +05:30
if ( dlg . result ( ) = = QDialog : : Accepted )
{
InstIconKey = dlg . selectedIconKey ;
ui - > iconButton - > setIcon ( MMC - > icons ( ) - > getIcon ( InstIconKey ) ) ;
importIcon = false ;
}
2013-08-10 22:04:08 +05:30
}
2013-05-07 07:58:28 +05:30
void NewInstanceDialog : : on_instNameTextBox_textChanged ( const QString & arg1 )
{
2018-07-15 18:21:05 +05:30
updateDialogState ( ) ;
2013-05-07 07:58:28 +05:30
}
2018-04-07 19:45:58 +05:30
void NewInstanceDialog : : importIconNow ( )
{
2018-07-15 18:21:05 +05:30
if ( importIcon ) {
MMC - > icons ( ) - > installIcon ( importIconPath , importIconName ) ;
InstIconKey = importIconName ;
importIcon = false ;
}
MMC - > settings ( ) - > set ( " NewInstanceGeometry " , saveGeometry ( ) . toBase64 ( ) ) ;
2018-04-07 19:45:58 +05:30
}