|
|
@ -15,21 +15,29 @@
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Project includes
|
|
|
|
#include "search_paths_settings_page.h"
|
|
|
|
#include "search_paths_settings_page.h"
|
|
|
|
|
|
|
|
#include "core_constants.h"
|
|
|
|
// Qt includes
|
|
|
|
#include "icore.h"
|
|
|
|
#include <QtGui/QWidget>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NeL includes
|
|
|
|
// NeL includes
|
|
|
|
|
|
|
|
#include <nel/misc/path.h>
|
|
|
|
|
|
|
|
|
|
|
|
// Project includes
|
|
|
|
// Qt includes
|
|
|
|
|
|
|
|
#include <QtCore/QSettings>
|
|
|
|
|
|
|
|
#include <QtGui/QWidget>
|
|
|
|
|
|
|
|
#include <QtGui/QFileDialog>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Core
|
|
|
|
namespace Core
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
CSearchPathsSettingsPage::CSearchPathsSettingsPage(QObject *parent)
|
|
|
|
CSearchPathsSettingsPage::CSearchPathsSettingsPage(QObject *parent)
|
|
|
|
: IOptionsPage(parent),
|
|
|
|
: IOptionsPage(parent),
|
|
|
|
_currentPage(0)
|
|
|
|
m_page(0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CSearchPathsSettingsPage::~CSearchPathsSettingsPage()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -55,13 +63,127 @@ QString CSearchPathsSettingsPage::trCategory() const
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *CSearchPathsSettingsPage::createPage(QWidget *parent)
|
|
|
|
QWidget *CSearchPathsSettingsPage::createPage(QWidget *parent)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_currentPage = new QWidget(parent);
|
|
|
|
m_page = new QWidget(parent);
|
|
|
|
_ui.setupUi(_currentPage);
|
|
|
|
m_ui.setupUi(m_page);
|
|
|
|
return _currentPage;
|
|
|
|
|
|
|
|
|
|
|
|
readSettings();
|
|
|
|
|
|
|
|
checkEnabledButton();
|
|
|
|
|
|
|
|
connect(m_ui.addToolButton, SIGNAL(clicked()), this, SLOT(addPath()));
|
|
|
|
|
|
|
|
connect(m_ui.removeToolButton, SIGNAL(clicked()), this, SLOT(delPath()));
|
|
|
|
|
|
|
|
connect(m_ui.upToolButton, SIGNAL(clicked()), this, SLOT(upPath()));
|
|
|
|
|
|
|
|
connect(m_ui.downToolButton, SIGNAL(clicked()), this, SLOT(downPath()));
|
|
|
|
|
|
|
|
return m_page;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::apply()
|
|
|
|
void CSearchPathsSettingsPage::apply()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
writeSettings();
|
|
|
|
|
|
|
|
applySearchPaths();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::finish()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
delete m_page;
|
|
|
|
|
|
|
|
m_page = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::applySearchPaths()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QStringList paths;
|
|
|
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
|
|
|
settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
|
|
|
|
|
|
|
|
paths = settings->value(Core::Constants::SEARCH_PATHS).toStringList();
|
|
|
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
|
|
|
Q_FOREACH(QString path, paths)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
NLMISC::CPath::addSearchPath(path.toStdString(), false, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NLMISC::CPath::remapExtension("png", "tga", true);
|
|
|
|
|
|
|
|
NLMISC::CPath::remapExtension("png", "dds", true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::addPath()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QString newPath = QFileDialog::getExistingDirectory(m_page);
|
|
|
|
|
|
|
|
if (!newPath.isEmpty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QListWidgetItem *newItem = new QListWidgetItem;
|
|
|
|
|
|
|
|
newItem->setText(newPath);
|
|
|
|
|
|
|
|
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
|
|
|
|
|
|
|
m_ui.pathsListWidget->addItem(newItem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkEnabledButton();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::delPath()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QListWidgetItem *removeItem = m_ui.pathsListWidget->takeItem(m_ui.pathsListWidget->currentRow());
|
|
|
|
|
|
|
|
if (!removeItem)
|
|
|
|
|
|
|
|
delete removeItem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkEnabledButton();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::upPath()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int currentRow = m_ui.pathsListWidget->currentRow();
|
|
|
|
|
|
|
|
if (!(currentRow == 0))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QListWidgetItem *item = m_ui.pathsListWidget->takeItem(currentRow);
|
|
|
|
|
|
|
|
m_ui.pathsListWidget->insertItem(--currentRow, item);
|
|
|
|
|
|
|
|
m_ui.pathsListWidget->setCurrentRow(currentRow);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::downPath()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int currentRow = m_ui.pathsListWidget->currentRow();
|
|
|
|
|
|
|
|
if (!(currentRow == m_ui.pathsListWidget->count()-1))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QListWidgetItem *item = m_ui.pathsListWidget->takeItem(currentRow);
|
|
|
|
|
|
|
|
m_ui.pathsListWidget->insertItem(++currentRow, item);
|
|
|
|
|
|
|
|
m_ui.pathsListWidget->setCurrentRow(currentRow);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::readSettings()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QStringList paths;
|
|
|
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
|
|
|
settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
|
|
|
|
|
|
|
|
paths = settings->value(Core::Constants::SEARCH_PATHS).toStringList();
|
|
|
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
|
|
|
Q_FOREACH(QString path, paths)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QListWidgetItem *newItem = new QListWidgetItem;
|
|
|
|
|
|
|
|
newItem->setText(path);
|
|
|
|
|
|
|
|
newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
|
|
|
|
|
|
|
|
m_ui.pathsListWidget->addItem(newItem);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::writeSettings()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QStringList paths;
|
|
|
|
|
|
|
|
for (int i = 0; i < m_ui.pathsListWidget->count(); ++i)
|
|
|
|
|
|
|
|
paths << m_ui.pathsListWidget->item(i)->text();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QSettings *settings = Core::ICore::instance()->settings();
|
|
|
|
|
|
|
|
settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
|
|
|
|
|
|
|
|
settings->setValue(Core::Constants::SEARCH_PATHS, paths);
|
|
|
|
|
|
|
|
settings->endGroup();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CSearchPathsSettingsPage::checkEnabledButton()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool bEnabled = true;
|
|
|
|
|
|
|
|
if (m_ui.pathsListWidget->count() == 0)
|
|
|
|
|
|
|
|
bEnabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_ui.removeToolButton->setEnabled(bEnabled);
|
|
|
|
|
|
|
|
m_ui.upToolButton->setEnabled(bEnabled);
|
|
|
|
|
|
|
|
m_ui.downToolButton->setEnabled(bEnabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} /* namespace Core */
|
|
|
|
} /* namespace Core */
|