@ -4,548 +4,307 @@
# include <QMessageBox>
# include <QCheckBox>
# include <QMenu>
# include <QSortFilterProxyModel>
# include <components/files/configurationmanager.hpp>
# include <components/fileorderlist/model/datafilesmodel.hpp>
# include <components/fileorderlist/model/pluginsproxymodel.hpp>
# include <components/fileorderlist/model/esm/esmfile.hpp>
# include <components/contentselector/model/esmfile.hpp>
# include <components/fileorderlist/utils/lineedit.hpp>
# include <components/fileorderlist/utils/naturalsort.hpp>
# include <components/fileorderlist/utils/profilescombobox.hpp>
# include <components/contentselector/model/naturalsort.hpp>
# include "utils/textinputdialog.hpp"
# include "utils/profilescombobox.hpp"
# include "settings/gamesettings.hpp"
# include "settings/launchersettings.hpp"
# include " utils/textinputdialog .hpp"
# include " components/contentselector/view/contentselector .hpp"
DataFilesPage : : DataFilesPage ( Files : : ConfigurationManager & cfg , GameSettings & gameSettings , LauncherSettings & launcherSettings , QWidget * parent )
Launcher : : DataFilesPage : : DataFilesPage ( Files : : ConfigurationManager & cfg , GameSettings & gameSettings , LauncherSettings & launcherSettings , QWidget * parent )
: mCfgMgr ( cfg )
, mGameSettings ( gameSettings )
, mLauncherSettings ( launcherSettings )
, QWidget ( parent )
{
setupUi ( this ) ;
// Models
mDataFilesModel = new DataFilesModel ( this ) ;
mMastersProxyModel = new QSortFilterProxyModel ( ) ;
mMastersProxyModel - > setFilterRegExp ( QString ( " ^.* \\ .esm " ) ) ;
mMastersProxyModel - > setFilterCaseSensitivity ( Qt : : CaseInsensitive ) ;
mMastersProxyModel - > setSourceModel ( mDataFilesModel ) ;
mPluginsProxyModel = new PluginsProxyModel ( ) ;
mPluginsProxyModel - > setFilterRegExp ( QString ( " ^.* \\ .esp " ) ) ;
mPluginsProxyModel - > setFilterCaseSensitivity ( Qt : : CaseInsensitive ) ;
mPluginsProxyModel - > setSourceModel ( mDataFilesModel ) ;
mFilterProxyModel = new QSortFilterProxyModel ( ) ;
mFilterProxyModel - > setDynamicSortFilter ( true ) ;
mFilterProxyModel - > setSourceModel ( mPluginsProxyModel ) ;
QCheckBox checkBox ;
unsigned int height = checkBox . sizeHint ( ) . height ( ) + 4 ;
mastersTable - > setModel ( mMastersProxyModel ) ;
mastersTable - > setObjectName ( " MastersTable " ) ;
mastersTable - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
mastersTable - > setSortingEnabled ( false ) ;
mastersTable - > setSelectionBehavior ( QAbstractItemView : : SelectRows ) ;
mastersTable - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
mastersTable - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ;
mastersTable - > setAlternatingRowColors ( true ) ;
mastersTable - > horizontalHeader ( ) - > setStretchLastSection ( true ) ;
mastersTable - > horizontalHeader ( ) - > hide ( ) ;
// Set the row height to the size of the checkboxes
mastersTable - > verticalHeader ( ) - > setDefaultSectionSize ( height ) ;
mastersTable - > verticalHeader ( ) - > setResizeMode ( QHeaderView : : Fixed ) ;
mastersTable - > verticalHeader ( ) - > hide ( ) ;
pluginsTable - > setModel ( mFilterProxyModel ) ;
pluginsTable - > setObjectName ( " PluginsTable " ) ;
pluginsTable - > setContextMenuPolicy ( Qt : : CustomContextMenu ) ;
pluginsTable - > setSortingEnabled ( false ) ;
pluginsTable - > setSelectionBehavior ( QAbstractItemView : : SelectRows ) ;
pluginsTable - > setSelectionMode ( QAbstractItemView : : ExtendedSelection ) ;
pluginsTable - > setEditTriggers ( QAbstractItemView : : NoEditTriggers ) ;
pluginsTable - > setAlternatingRowColors ( true ) ;
pluginsTable - > setVerticalScrollMode ( QAbstractItemView : : ScrollPerItem ) ;
pluginsTable - > horizontalHeader ( ) - > setStretchLastSection ( true ) ;
pluginsTable - > horizontalHeader ( ) - > hide ( ) ;
pluginsTable - > verticalHeader ( ) - > setDefaultSectionSize ( height ) ;
pluginsTable - > verticalHeader ( ) - > setResizeMode ( QHeaderView : : Fixed ) ;
// Adjust the tableview widths inside the splitter
QList < int > sizeList ;
sizeList < < mLauncherSettings . value ( QString ( " General/MastersTable/width " ) , QString ( " 200 " ) ) . toInt ( ) ;
sizeList < < mLauncherSettings . value ( QString ( " General/PluginTable/width " ) , QString ( " 340 " ) ) . toInt ( ) ;
splitter - > setSizes ( sizeList ) ;
// Create a dialog for the new profile name input
mNewProfileDialog = new TextInputDialog ( tr ( " New Profile " ) , tr ( " Profile name: " ) , this ) ;
connect ( profilesComboBox , SIGNAL ( currentIndexChanged ( int ) ) , this , SLOT ( slotCurrentIndexChanged ( int ) ) ) ;
connect ( mNewProfileDialog - > lineEdit ( ) , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( updateOkButton ( QString ) ) ) ;
connect ( pluginsTable , SIGNAL ( doubleClicked ( QModelIndex ) ) , this , SLOT ( setCheckState ( QModelIndex ) ) ) ;
connect ( mastersTable , SIGNAL ( doubleClicked ( QModelIndex ) ) , this , SLOT ( setCheckState ( QModelIndex ) ) ) ;
connect ( pluginsTable , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( showContextMenu ( QPoint ) ) ) ;
connect ( mastersTable , SIGNAL ( customContextMenuRequested ( QPoint ) ) , this , SLOT ( showContextMenu ( QPoint ) ) ) ;
connect ( mDataFilesModel , SIGNAL ( layoutChanged ( ) ) , this , SLOT ( updateViews ( ) ) ) ;
connect ( filterLineEdit , SIGNAL ( textChanged ( QString ) ) , this , SLOT ( filterChanged ( QString ) ) ) ;
ui . setupUi ( this ) ;
setObjectName ( " DataFilesPage " ) ;
mSelector = new ContentSelectorView : : ContentSelector ( ui . contentSelectorWidget ) ;
connect ( splitter , SIGNAL ( splitterMoved ( int , int ) ) , this , SLOT ( updateSplitter ( ) ) ) ;
createActions ( ) ;
buildView ( ) ;
setupDataFiles ( ) ;
}
void DataFilesPage : : createActions ( )
{
// Add the actions to the toolbuttons
newProfileButton - > setDefaultAction ( newProfileAction ) ;
deleteProfileButton - > setDefaultAction ( deleteProfileAction ) ;
// Context menu actions
mContextMenu = new QMenu ( this ) ;
mContextMenu - > addAction ( checkAction ) ;
mContextMenu - > addAction ( uncheckAction ) ;
}
void DataFilesPage : : setupDataFiles ( )
void Launcher : : DataFilesPage : : loadSettings ( )
{
// Set the encoding to the one found in openmw.cfg or the default
mDataFilesModel - > setEncoding ( mGameSettings . value ( QString ( " encoding " ) , QString ( " win1252 " ) ) ) ;
QStringList paths = mGameSettings . getDataDirs ( ) ;
paths . insert ( 0 , mDataLocal ) ;
PathIterator pathIterator ( paths ) ;
foreach ( const QString & path , paths ) {
mDataFilesModel - > addFiles ( path ) ;
}
QString dataLocal = mGameSettings . getDataLocal ( ) ;
if ( ! dataLocal . isEmpty ( ) )
mDataFilesModel - > addFiles ( dataLocal ) ;
QString profileName = ui . profilesComboBox - > currentText ( ) ;
// Sort by date accessed for now
mDataFilesModel - > sort ( 3 ) ;
QStringList files = mLauncherSettings . values ( QString ( " Profiles/ " ) + profileName , Qt : : MatchExactly ) ;
QStringList profiles = mLauncherSettings . subKeys ( QString ( " Profiles/ " ) ) ;
QString profile = mLauncherSettings . value ( QString ( " Profiles/currentprofile " ) ) ;
if ( ! profiles . isEmpty ( ) )
profilesComboBox - > addItems ( profiles ) ;
// Add the current profile if empty
if ( profilesComboBox - > findText ( profile ) = = - 1 & & ! profile . isEmpty ( ) )
profilesComboBox - > addItem ( profile ) ;
if ( profilesComboBox - > findText ( QString ( " Default " ) ) = = - 1 )
profilesComboBox - > addItem ( QString ( " Default " ) ) ;
if ( profile . isEmpty ( ) | | profile = = QLatin1String ( " Default " ) ) {
deleteProfileAction - > setEnabled ( false ) ;
profilesComboBox - > setEditEnabled ( false ) ;
profilesComboBox - > setCurrentIndex ( profilesComboBox - > findText ( QString ( " Default " ) ) ) ;
} else {
profilesComboBox - > setEditEnabled ( true ) ;
profilesComboBox - > setCurrentIndex ( profilesComboBox - > findText ( profile ) ) ;
}
// We do this here to prevent deletion of profiles when initializing the combobox
connect ( profilesComboBox , SIGNAL ( profileRenamed ( QString , QString ) ) , this , SLOT ( profileRenamed ( QString , QString ) ) ) ;
connect ( profilesComboBox , SIGNAL ( profileChanged ( QString , QString ) ) , this , SLOT ( profileChanged ( QString , QString ) ) ) ;
loadSettings ( ) ;
}
QStringList filepaths ;
void DataFilesPage : : loadSettings ( )
{
QString profile = mLauncherSettings . value ( QString ( " Profiles/currentprofile " ) ) ;
if ( profile . isEmpty ( ) )
return ;
mDataFilesModel - > uncheckAll ( ) ;
QStringList masters = mLauncherSettings . values ( QString ( " Profiles/ " ) + profile + QString ( " /master " ) , Qt : : MatchExactly ) ;
QStringList plugins = mLauncherSettings . values ( QString ( " Profiles/ " ) + profile + QString ( " /plugin " ) , Qt : : MatchExactly ) ;
foreach ( const QString & file , files )
{
QString filepath = pathIterator . findFirstPath ( file ) ;
foreach ( const QString & master , masters ) {
QModelIndex index = mDataFilesModel - > indexFromItem ( mDataFilesModel - > findItem ( master ) ) ;
if ( index . isValid ( ) )
mDataFilesModel - > setCheckState ( index , Qt : : Checked ) ;
if ( ! filepath . isEmpty ( ) )
filepaths < < filepath ;
}
foreach ( const QString & plugin , plugins ) {
QModelIndex index = mDataFilesModel - > indexFromItem ( mDataFilesModel - > findItem ( plugin ) ) ;
if ( index . isValid ( ) )
mDataFilesModel - > setCheckState ( index , Qt : : Checked ) ;
}
mSelector - > setProfileContent ( filepaths ) ;
}
void DataFilesPage: : saveSettings ( )
void Launcher : : DataFilesPage : : saveSettings ( const QString & profile )
{
if ( mDataFilesModel - > rowCount ( ) < 1 )
return ;
QString profile = mLauncherSettings . value ( QString ( " Profiles/currentprofile " ) ) ;
QString profileName = profile ;
if ( profile . isEmpty ( ) ) {
profile = profilesComboBox - > currentText ( ) ;
mLauncherSettings . setValue ( QString ( " Profiles/currentprofile " ) , profile ) ;
}
if ( profileName . isEmpty ( ) )
profileName = ui . profilesComboBox - > currentText ( ) ;
mLauncherSettings . remove ( QString ( " Profiles/ " ) + profile + QString ( " /master " ) ) ;
mLauncherSettings . remove ( QString ( " Profiles/ " ) + profile + QString ( " /plugin " ) ) ;
//retrieve the files selected for the profile
ContentSelectorModel : : ContentFileList items = mSelector - > selectedFiles ( ) ;
mGameSettings . remove ( QString ( " master " ) ) ;
mGameSettings . remove ( QString ( " plugin " ) ) ;
removeProfile ( profileName ) ;
QStringList items = mDataFilesModel - > checkedItems ( ) ;
mGameSettings . remove ( QString ( " content " ) ) ;
foreach ( const QString & item , items ) {
//set the value of the current profile (not necessarily the profile being saved!)
mLauncherSettings . setValue ( QString ( " Profiles/currentprofile " ) , ui . profilesComboBox - > currentText ( ) ) ;
if ( item . endsWith ( QString ( " .esm " ) , Qt : : CaseInsensitive ) ) {
mLauncherSettings . setMultiValue ( QString ( " Profiles/ " ) + profile + QString ( " /master " ) , item ) ;
mGameSettings . setMultiValue ( QString ( " master " ) , item ) ;
foreach ( const ContentSelectorModel : : EsmFile * item , items ) {
} else if ( item . endsWith ( QString ( " .esp " ) , Qt : : CaseInsensitive ) ) {
mLauncherSettings . setMultiValue ( QString ( " Profiles/ " ) + profile + QString ( " /plugin " ) , item ) ;
mGameSettings . setMultiValue ( QString ( " plugin " ) , item ) ;
if ( item - > gameFiles ( ) . size ( ) = = 0 ) {
mLauncherSettings . setMultiValue ( QString ( " Profiles/ " ) + profileName , item - > fileName ( ) ) ;
mGameSettings . setMultiValue ( QString ( " content " ) , item - > fileName ( ) ) ;
} else {
mLauncherSettings . setMultiValue ( QString ( " Profiles/ " ) + profileName , item - > fileName ( ) ) ;
mGameSettings . setMultiValue ( QString ( " content " ) , item - > fileName ( ) ) ;
}
}
}
void DataFilesPage: : updateOkButton ( const QString & text )
void Launcher : : DataFilesPage : : buildView ( )
{
// We do this here because we need the profiles combobox text
if ( text . isEmpty ( ) ) {
mNewProfileDialog - > setOkButtonEnabled ( false ) ;
return ;
}
ui . verticalLayout - > insertWidget ( 0 , mSelector - > uiWidget ( ) ) ;
( profilesComboBox - > findText ( text ) = = - 1 )
? mNewProfileDialog - > setOkButtonEnabled ( true )
: mNewProfileDialog - > setOkButtonEnabled ( false ) ;
}
//tool buttons
ui . newProfileButton - > setToolTip ( " Create a new profile " ) ;
ui . deleteProfileButton - > setToolTip ( " Delete an existing profile " ) ;
void DataFilesPage : : updateSplitter ( )
{
// Sigh, update the saved splitter size in settings only when moved
// Since getting mSplitter->sizes() if page is hidden returns invalid values
QList < int > sizes = splitter - > sizes ( ) ;
//combo box
ui . profilesComboBox - > addItem ( " Default " ) ;
ui . profilesComboBox - > setPlaceholderText ( QString ( " Select a profile... " ) ) ;
mLauncherSettings . setValue ( QString ( " General/MastersTable/width " ) , QString : : number ( sizes . at ( 0 ) ) ) ;
mLauncherSettings. setValue ( QString ( " General/PluginsTable/width " ) , QString : : number ( sizes . at ( 1 ) ) ) ;
}
// Add the actions to the toolbuttons
ui . newProfileButton - > setDefaultAction ( ui . newProfileAction ) ;
ui . deleteProfileButton - > setDefaultAction ( ui . deleteProfileAction ) ;
void DataFilesPage : : updateViews ( )
{
// Ensure the columns are hidden because sort() re-enables them
mastersTable - > setColumnHidden ( 1 , true ) ;
mastersTable - > setColumnHidden ( 2 , true ) ;
mastersTable - > setColumnHidden ( 3 , true ) ;
mastersTable - > setColumnHidden ( 4 , true ) ;
mastersTable - > setColumnHidden ( 5 , true ) ;
mastersTable - > setColumnHidden ( 6 , true ) ;
mastersTable - > setColumnHidden ( 7 , true ) ;
mastersTable - > setColumnHidden ( 8 , true ) ;
pluginsTable - > setColumnHidden ( 1 , true ) ;
pluginsTable - > setColumnHidden ( 2 , true ) ;
pluginsTable - > setColumnHidden ( 3 , true ) ;
pluginsTable - > setColumnHidden ( 4 , true ) ;
pluginsTable - > setColumnHidden ( 5 , true ) ;
pluginsTable - > setColumnHidden ( 6 , true ) ;
pluginsTable - > setColumnHidden ( 7 , true ) ;
pluginsTable - > setColumnHidden ( 8 , true ) ;
}
//establish connections
connect ( ui . profilesComboBox , SIGNAL ( currentIndexChanged ( int ) ) ,
this , SLOT ( slotProfileChanged ( int ) ) ) ;
void DataFilesPage : : setProfilesComboBoxIndex ( int index )
{
profilesComboBox - > setCurrentIndex ( index ) ;
connect ( ui . profilesComboBox , SIGNAL ( profileRenamed ( QString , QString ) ) ,
this , SLOT ( slotProfileRenamed ( QString , QString ) ) ) ;
connect ( ui . profilesComboBox , SIGNAL ( signalProfileChanged ( QString , QString ) ) ,
this , SLOT ( slotProfileChangedByUser ( QString , QString ) ) ) ;
}
void DataFilesPage: : slotCurrentIndexChanged ( int index )
void Launcher : : DataFilesPage : : removeProfile ( const QString & profile )
{
emit profileChanged ( index ) ;
mLauncherSettings . remove ( QString ( " Profiles/ " ) + profile + QString ( " /game " ) ) ;
mLauncherSettings . remove ( QString ( " Profiles/ " ) + profile + QString ( " /addon " ) ) ;
}
QAbstractItemModel * DataFilesPage : : profiles ComboBox Model( )
QAbstractItemModel * Launcher : : DataFilesPage : : profilesModel ( ) const
{
return profilesComboBox- > model ( ) ;
return ui . profilesComboBox - > model ( ) ;
}
int DataFilesPage: : profiles ComboBox Index( )
int Launcher: : DataFilesPage: : profiles Index( ) const
{
return profilesComboBox- > currentIndex ( ) ;
return ui. profilesComboBox- > currentIndex ( ) ;
}
void DataFilesPage: : on_newProfileAction_triggered ( )
void Launcher: : DataFilesPage : : setProfile ( int index , bool savePrevious )
{
if ( mNewProfileDialog - > exec ( ) = = QDialog : : Accepted ) {
QString profile = mNewProfileDialog - > lineEdit ( ) - > text ( ) ;
profilesComboBox - > addItem ( profile ) ;
profilesComboBox - > setCurrentIndex ( profilesComboBox - > findText ( profile ) ) ;
if ( index > = - 1 & & index < ui . profilesComboBox - > count ( ) )
{
QString previous = ui . profilesComboBox - > itemText ( ui . profilesComboBox - > currentIndex ( ) ) ;
QString current = ui . profilesComboBox - > itemText ( index ) ;
setProfile ( previous , current , savePrevious ) ;
}
}
void DataFilesPage: : on_deleteProfileAction_triggered ( )
void Launcher: : DataFilesPage : : setProfile ( const QString & previous , const QString & current , bool savePrevious )
{
QString profile = profilesComboBox - > currentText ( ) ;
if ( profile . isEmpty ( ) )
return ;
QMessageBox msgBox ( this ) ;
msgBox . setWindowTitle ( tr ( " Delete Profile " ) ) ;
msgBox . setIcon ( QMessageBox : : Warning ) ;
msgBox . setStandardButtons ( QMessageBox : : Cancel ) ;
msgBox . setText ( tr ( " Are you sure you want to delete <b>%0</b>? " ) . arg ( profile ) ) ;
//abort if no change (poss. duplicate signal)
if ( previous = = current )
return ;
QAbstractButton * deleteButton =
msgBox . addButton ( tr ( " Delete " ) , QMessageBox : : ActionRole ) ;
if ( ! previous . isEmpty ( ) & & savePrevious )
saveSettings ( previous ) ;
msgBox. exec ( ) ;
ui . profilesComboBox - > setCurrentProfile ( ui . profilesComboBox - > findText ( current ) ) ;
if ( msgBox . clickedButton ( ) = = deleteButton ) {
mLauncherSettings . remove ( QString ( " Profiles/ " ) + profile + QString ( " /master " ) ) ;
mLauncherSettings . remove ( QString ( " Profiles/ " ) + profile + QString ( " /plugin " ) ) ;
loadSettings ( ) ;
// Remove the profile from the combobox
profilesComboBox - > removeItem ( profilesComboBox - > findText ( profile ) ) ;
}
checkForDefaultProfile ( ) ;
}
void DataFilesPage: : on_checkAction_triggered ( )
void Launcher: : DataFilesPage : : slotProfileDeleted ( const QString & item )
{
if ( pluginsTable - > hasFocus ( ) )
setPluginsCheckstates ( Qt : : Checked ) ;
if ( mastersTable - > hasFocus ( ) )
setMastersCheckstates ( Qt : : Checked ) ;
removeProfile ( item ) ;
}
void DataFilesPage: : on_uncheckAction_triggered ( )
void Launcher : : DataFilesPage : : slotProfileChangedByUser ( const QString & previous , const QString & current )
{
if ( pluginsTable - > hasFocus ( ) )
setPluginsCheckstates ( Qt : : Unchecked ) ;
if ( mastersTable - > hasFocus ( ) )
setMastersCheckstates ( Qt : : Unchecked ) ;
setProfile ( previous , current , true ) ;
emit signalProfileChanged ( ui . profilesComboBox - > findText ( current ) ) ;
}
void DataFilesPage: : setMastersCheckstates ( Qt : : CheckState state )
void Launcher : : DataFilesPage : : slotProfileRenamed ( const QString & previous , const QString & current )
{
if ( ! mastersTable - > selectionModel ( ) - > hasSelection ( ) ) {
if ( previous . isEmpty ( ) )
return ;
}
QModelIndexList indexes = mastersTable - > selectionModel ( ) - > selectedIndexes ( ) ;
foreach ( const QModelIndex & index , indexes )
{
if ( ! index . isValid ( ) )
return ;
QModelIndex sourceIndex = mMastersProxyModel - > mapToSource ( index ) ;
// Save the new profile name
saveSettings ( ) ;
if ( ! sourceIndex . isValid ( ) )
return ;
// Remove the old one
removeProfile ( previous ) ;
mDataFilesModel - > setCheckState ( sourceIndex , state ) ;
}
loadSettings ( ) ;
}
void DataFilesPage: : setPluginsCheckstates ( Qt : : CheckState state )
void Launcher: : DataFilesPage : : slotProfileChanged ( int index )
{
if ( ! pluginsTable - > selectionModel ( ) - > hasSelection ( ) ) {
return ;
}
QModelIndexList indexes = pluginsTable - > selectionModel ( ) - > selectedIndexes ( ) ;
foreach ( const QModelIndex & index , indexes )
{
if ( ! index . isValid ( ) )
return ;
QModelIndex sourceIndex = mPluginsProxyModel - > mapToSource (
mFilterProxyModel - > mapToSource ( index ) ) ;
if ( ! sourceIndex . isValid ( ) )
return ;
mDataFilesModel - > setCheckState ( sourceIndex , state ) ;
}
setProfile ( index , true ) ;
}
void DataFilesPage: : setCheckState ( QModelIndex index )
void Launcher : : DataFilesPage : : setupDataFiles ( )
{
if ( ! index . isValid ( ) )
return ;
QStringList paths = mGameSettings . getDataDirs ( ) ;
QObject * object = QObject : : sender ( ) ;
foreach ( const QString & path , paths )
mSelector - > addFiles ( path ) ;
// Not a signal-slot call
if ( ! object )
return ;
mDataLocal = mGameSettings . getDataLocal ( ) ;
if ( ! mDataLocal . isEmpty ( ) )
mSelector - > addFiles ( mDataLocal ) ;
if ( object - > objectName ( ) = = QLatin1String ( " PluginsTable " ) ) {
QModelIndex sourceIndex = mPluginsProxyModel - > mapToSource (
mFilterProxyModel - > mapToSource ( index ) ) ;
QStringList profiles ;
QString currentProfile = mLauncherSettings . getSettings ( ) . value ( " Profiles/currentprofile " ) ;
if ( sourceIndex . isValid ( ) ) {
( mDataFilesModel - > checkState ( sourceIndex ) = = Qt : : Checked )
? mDataFilesModel - > setCheckState ( sourceIndex , Qt : : Unchecked )
: mDataFilesModel - > setCheckState ( sourceIndex , Qt : : Checked ) ;
foreach ( QString key , mLauncherSettings . getSettings ( ) . keys ( ) )
{
if ( key . contains ( " Profiles/ " ) )
{
QString profile = key . mid ( 9 ) ;
if ( profile ! = " currentprofile " )
{
if ( ! profiles . contains ( profile ) )
profiles < < profile ;
}
}
}
if ( object - > objectName ( ) = = QLatin1String ( " MastersTable " ) ) {
QModelIndex sourceIndex = mMastersProxyModel - > mapToSource ( index ) ;
if ( sourceIndex . isValid ( ) ) {
( mDataFilesModel - > checkState ( sourceIndex ) = = Qt : : Checked )
? mDataFilesModel - > setCheckState ( sourceIndex , Qt : : Unchecked )
: mDataFilesModel - > setCheckState ( sourceIndex , Qt : : Checked ) ;
}
}
foreach ( const QString & item , profiles )
addProfile ( item , false ) ;
return ;
}
setProfile ( ui . profilesComboBox - > findText ( currentProfile ) , false ) ;
void DataFilesPage : : filterChanged ( const QString filter )
{
QRegExp regExp ( filter , Qt : : CaseInsensitive , QRegExp : : FixedString ) ;
mFilterProxyModel - > setFilterRegExp ( regExp ) ;
loadSettings ( ) ;
}
void DataFilesPage: : profileChanged ( const QString & previous , const QString & current )
void Launcher : : DataFilesPage : : on_newProfileAction_triggered ( )
{
// Prevent the deletion of the default profile
if ( current = = QLatin1String ( " Default " ) ) {
deleteProfileAction - > setEnabled ( false ) ;
profilesComboBox - > setEditEnabled ( false ) ;
} else {
deleteProfileAction - > setEnabled ( true ) ;
profilesComboBox - > setEditEnabled ( true ) ;
}
TextInputDialog newDialog ( tr ( " New Profile " ) , tr ( " Profile name: " ) , this ) ;
if ( previous. isEmpty ( ) )
if ( newDialog . exec ( ) ! = QDialog : : Accepted )
return ;
if ( profilesComboBox - > findText ( previous ) = = - 1 )
return ; // Profile was deleted
// Store the previous profile
mLauncherSettings . setValue ( QString ( " Profiles/currentprofile " ) , previous ) ;
saveSettings ( ) ;
mLauncherSettings . setValue ( QString ( " Profiles/currentprofile " ) , current ) ;
loadSettings ( ) ;
}
QString profile = newDialog . getText ( ) ;
void DataFilesPage : : profileRenamed ( const QString & previous , const QString & current )
{
if ( previous . isEmpty ( ) )
return ;
if ( profile . isEmpty ( ) )
return ;
// Save the new profile name
mLauncherSettings . setValue ( QString ( " Profiles/currentprofile " ) , current ) ;
saveSettings ( ) ;
// Remove the old one
mLauncherSettings . remove ( QString ( " Profiles/ " ) + previous + QString ( " /master " ) ) ;
mLauncherSettings . remove ( QString ( " Profiles/ " ) + previous + QString ( " /plugin " ) ) ;
mSelector - > clearCheckStates ( ) ;
// Remove the profile from the combobox
profilesComboBox - > removeItem ( profilesComboBox - > findText ( previous ) ) ;
addProfile ( profile , true ) ;
loadSettings ( ) ;
mSelector - > setGameFile ( ) ;
saveSettings ( ) ;
emit signalProfileChanged ( ui . profilesComboBox - > findText ( profile ) ) ;
}
void DataFilesPage: : showContextMenu ( const QPoint & poi nt)
void Launcher: : DataFilesPage : : addProfile ( const QString & profile , bool setAsCurre nt)
{
QObject * object = QObject : : sender ( ) ;
if ( profile . isEmpty ( ) )
return ;
// Not a signal-slot call
if ( ! object )
if ( ui . profilesComboBox - > findText ( profile ) ! = - 1 )
return ;
if ( object - > objectName ( ) = = QLatin1String ( " PluginsTable " ) ) {
if ( ! pluginsTable - > selectionModel ( ) - > hasSelection ( ) )
return ;
ui . profilesComboBox - > addItem ( profile ) ;
QPoint globalPos = pluginsTable - > mapToGlobal ( point ) ;
QModelIndexList indexes = pluginsTable - > selectionModel ( ) - > selectedIndexes ( ) ;
if ( setAsCurrent )
setProfile ( ui . profilesComboBox - > findText ( profile ) , false ) ;
}
// Show the check/uncheck actions depending on the state of the selected items
uncheckAction - > setEnabled ( false ) ;
checkAction - > setEnabled ( false ) ;
void Launcher : : DataFilesPage : : on_deleteProfileAction_triggered ( )
{
QString profile = ui . profilesComboBox - > currentText ( ) ;
foreach ( const QModelIndex & index , indexes )
{
if ( ! index . isValid ( ) )
return ;
if ( profile . isEmpty ( ) )
return ;
QModelIndex sourceIndex = mPluginsProxyModel - > mapToSource (
mFilterProxyModel - > mapToSource ( index ) ) ;
if ( ! showDeleteMessageBox ( profile ) )
return ;
if ( ! sourceIndex . isValid ( ) )
return ;
// Remove the profile from the combobox
ui . profilesComboBox - > removeItem ( ui . profilesComboBox - > findText ( profile ) ) ;
( mDataFilesModel - > checkState ( sourceIndex ) = = Qt : : Checked )
? uncheckAction - > setEnabled ( true )
: checkAction - > setEnabled ( true ) ;
}
removeProfile ( profile ) ;
// Show menu
mContextMenu - > exec ( globalPos ) ;
}
saveSettings ( ) ;
if ( object - > objectName ( ) = = QLatin1String ( " MastersTable " ) ) {
if ( ! mastersTable - > selectionModel ( ) - > hasSelection ( ) )
return ;
loadSettings ( ) ;
QPoint globalPos = mastersTable - > mapToGlobal ( point ) ;
QModelIndexList indexes = mastersTable - > selectionModel ( ) - > selectedIndexes ( ) ;
checkForDefaultProfile ( ) ;
}
// Show the check/uncheck actions depending on the state of the selected items
uncheckAction - > setEnabled ( false ) ;
checkAction - > setEnabled ( false ) ;
void Launcher : : DataFilesPage : : checkForDefaultProfile ( )
{
//don't allow deleting "Default" profile
bool success = ( ui . profilesComboBox - > currentText ( ) ! = " Default " ) ;
foreach ( const QModelIndex & index , indexes )
{
if ( ! index . isValid ( ) )
return ;
ui . deleteProfileAction - > setEnabled ( success ) ;
ui . profilesComboBox - > setEditEnabled ( success ) ;
}
QModelIndex sourceIndex = mMastersProxyModel - > mapToSource ( index ) ;
bool Launcher : : DataFilesPage : : showDeleteMessageBox ( const QString & text )
{
QMessageBox msgBox ( this ) ;
msgBox . setWindowTitle ( tr ( " Delete Profile " ) ) ;
msgBox . setIcon ( QMessageBox : : Warning ) ;
msgBox . setStandardButtons ( QMessageBox : : Cancel ) ;
msgBox . setText ( tr ( " Are you sure you want to delete <b>%0</b>? " ) . arg ( text ) ) ;
if ( ! sourceIndex . isValid ( ) )
return ;
QAbstractButton * deleteButton =
msgBox . addButton ( tr ( " Delete " ) , QMessageBox : : ActionRole ) ;
( mDataFilesModel - > checkState ( sourceIndex ) = = Qt : : Checked )
? uncheckAction - > setEnabled ( true )
: checkAction - > setEnabled ( true ) ;
}
msgBox . exec ( ) ;
mContextMenu - > exec ( globalPos ) ;
}
return ( msgBox . clickedButton ( ) = = deleteButton ) ;
}