Fix
[ryzomcore.git] / studio / src / startup_settings_dlg.cpp
blob6d2e14a7e146b6bffeb80aec00e70dcac3030e75
1 // Ryzom Core - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2014 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 // Copyright (C) 2015 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 //
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "startup_settings_dlg.h"
23 #include <QFileDialog>
24 #include <QSettings>
25 #include <QStringList>
27 int findListItem( QListWidget *l, const QString &s )
29 for( int i = 0; i < l->count(); i++ )
31 QListWidgetItem *item = l->item( i );
32 if( item->text() == s )
33 return i;
36 return -1;
39 StartupSettingsDlg::StartupSettingsDlg( QDialog *parent ) :
40 QDialog( parent )
42 setupUi( this );
43 setupConnections();
44 settings = NULL;
47 StartupSettingsDlg::~StartupSettingsDlg()
51 void StartupSettingsDlg::load()
53 pluginsLE->setText( settings->value( "PluginPath" ).toString() );
55 settings->beginGroup( "DataPath" );
57 sheetsLE->setText( settings->value( "LevelDesignPath" ).toString() );
58 assetsLE->setText( settings->value( "AssetsPath" ).toString() );
59 primitivesLE->setText( settings->value( "PrimitivesPath" ).toString() );
60 ligoLE->setText( settings->value( "LigoConfigFile" ).toString() );
62 QStringList l = settings->value( "SearchPaths" ).toStringList();
64 QStringListIterator itr( l );
65 while( itr.hasNext() )
67 QString p = itr.next();
68 if( findListItem( searchLW, p ) == -1 )
69 searchLW->addItem( p );
73 l.clear();
75 l = settings->value( "RecursiveSearchPathes" ).toStringList();
77 QStringListIterator itr( l );
78 while( itr.hasNext() )
80 QString p = itr.next();
81 if( findListItem( recursiveLW, p ) == -1 )
82 recursiveLW->addItem( p );
86 settings->endGroup();
89 void StartupSettingsDlg::saveSearchPaths()
91 QStringList l;
92 for( int i = 0; i < searchLW->count(); i++ )
94 l.push_back( searchLW->item( i )->text() );
97 settings->setValue( "SearchPaths", l );
100 void StartupSettingsDlg::saveRecursivePaths()
102 QStringList l;
103 for( int i = 0; i < recursiveLW->count(); i++ )
105 l.push_back( recursiveLW->item( i )->text() );
108 settings->setValue( "RecursiveSearchPathes", l );
111 void StartupSettingsDlg::save()
113 settings->setValue( "PluginPath", pluginsLE->text() );
115 settings->beginGroup( "DataPath" );
117 settings->setValue( "LevelDesignPath", sheetsLE->text() );
118 settings->setValue( "AssetsPath", assetsLE->text() );
119 settings->setValue( "PrimitivesPath", primitivesLE->text() );
120 settings->setValue( "LigoConfigFile", ligoLE->text() );
122 saveSearchPaths();
123 saveRecursivePaths();
125 settings->endGroup();
127 settings->sync();
130 void StartupSettingsDlg::accept()
132 save();
133 QDialog::accept();
136 void StartupSettingsDlg::reject()
138 QDialog::reject();
141 void StartupSettingsDlg::onOKClicked()
143 accept();
146 void StartupSettingsDlg::onCancelClicked()
148 reject();
151 void StartupSettingsDlg::onPluginBClicked()
153 QString p = QFileDialog::getExistingDirectory( this, tr( "Plugins directory" ), "" );
154 pluginsLE->setText( p );
157 void StartupSettingsDlg::onSheetsBClicked()
159 QString p = QFileDialog::getExistingDirectory( this, tr( "Sheets directory" ), "" );
160 sheetsLE->setText( p );
163 void StartupSettingsDlg::onAssetsBClicked()
165 QString p = QFileDialog::getExistingDirectory( this, tr( "Assets directory" ), "" );
166 assetsLE->setText( p );
169 void StartupSettingsDlg::onPrimitivesBClicked()
171 QString p = QFileDialog::getExistingDirectory( this, tr( "Primitives directory" ), "" );
172 primitivesLE->setText( p );
175 void StartupSettingsDlg::onLigoBClicked()
177 QString p;
178 p = QFileDialog::getOpenFileName( this, tr( "LIGO config file" ), "" );
179 ligoLE->setText( p );
182 void StartupSettingsDlg::onPathAddClicked()
184 QString p = QFileDialog::getExistingDirectory( this, tr( "Search path" ), "" );
185 if( p.isEmpty() )
186 return;
188 if( findListItem( searchLW, p ) != -1 )
189 return;
191 searchLW->addItem( p );
194 void StartupSettingsDlg::onPathRemoveClicked()
196 QListWidgetItem *i = searchLW->currentItem();
197 if( i == NULL )
198 return;
200 delete i;
203 void StartupSettingsDlg::onRecursiveAddClicked()
205 QString p = QFileDialog::getExistingDirectory( this, tr( "Recursive search path" ), "" );
206 if( p.isEmpty() )
207 return;
209 if( findListItem( recursiveLW, p ) != -1 )
210 return;
212 recursiveLW->addItem( p );
215 void StartupSettingsDlg::onRecursiveRemoveClicked()
217 QListWidgetItem *i = recursiveLW->currentItem();
218 if( i == NULL )
219 return;
221 delete i;
225 void StartupSettingsDlg::setupConnections()
227 connect( bb, SIGNAL( accepted() ), this, SLOT( onOKClicked() ) );
228 connect( bb, SIGNAL( rejected() ), this, SLOT( onCancelClicked() ) );
230 connect( pluginsB, SIGNAL( clicked( bool ) ), this, SLOT( onPluginBClicked() ) );
231 connect( sheetsB, SIGNAL( clicked( bool ) ), this, SLOT( onSheetsBClicked() ) );
232 connect( assetsB, SIGNAL( clicked( bool ) ), this, SLOT( onAssetsBClicked() ) );
233 connect( primitivesB, SIGNAL( clicked( bool ) ), this, SLOT( onPrimitivesBClicked() ) );
234 connect( ligoB, SIGNAL( clicked( bool ) ), this, SLOT( onLigoBClicked() ) );
236 connect( pathAddB, SIGNAL( clicked( bool ) ), this, SLOT( onPathAddClicked() ) );
237 connect( pathRemoveB, SIGNAL( clicked( bool ) ), this, SLOT( onPathRemoveClicked() ) );
238 connect( recAddB, SIGNAL( clicked( bool ) ), this, SLOT( onRecursiveAddClicked() ) );
239 connect( recRemoveB, SIGNAL( clicked( bool ) ), this, SLOT( onRecursiveRemoveClicked() ) );