2013-09-22 04:06:29 +00:00
|
|
|
#include "contentselector.hpp"
|
|
|
|
|
|
|
|
#include "../model/esmfile.hpp"
|
2013-10-02 02:29:45 +00:00
|
|
|
#include "lineedit.hpp"
|
2013-09-22 04:06:29 +00:00
|
|
|
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QContextMenuEvent>
|
2013-09-29 17:19:07 +00:00
|
|
|
#include <QGridLayout>
|
2013-10-02 02:29:45 +00:00
|
|
|
#include <QMessageBox>
|
2013-09-29 17:19:07 +00:00
|
|
|
#include <assert.h>
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
#include "filewidget.hpp"
|
|
|
|
#include "adjusterwidget.hpp"
|
2013-09-29 17:19:07 +00:00
|
|
|
|
|
|
|
ContentSelectorView::ContentSelector *ContentSelectorView::ContentSelector::mInstance = 0;
|
|
|
|
QStringList ContentSelectorView::ContentSelector::mFilePaths;
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::configure(QWidget *subject, unsigned char flags)
|
|
|
|
{
|
|
|
|
assert(!mInstance);
|
|
|
|
mInstance = new ContentSelector (subject, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentSelectorView::ContentSelector& ContentSelectorView::ContentSelector::instance()
|
|
|
|
{
|
2013-10-02 02:29:45 +00:00
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
assert(mInstance);
|
|
|
|
return *mInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentSelectorView::ContentSelector::ContentSelector(QWidget *parent, unsigned char flags) :
|
|
|
|
QWidget(parent), mFlags (flags),
|
|
|
|
mAdjusterWidget (0), mFileWidget (0)
|
2013-09-22 04:06:29 +00:00
|
|
|
{
|
2013-10-02 02:29:45 +00:00
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
ui.setupUi (this);
|
|
|
|
|
|
|
|
parent->setLayout(new QGridLayout());
|
|
|
|
parent->layout()->addWidget(this);
|
2013-09-22 04:06:29 +00:00
|
|
|
|
|
|
|
buildContentModel();
|
|
|
|
buildGameFileView();
|
|
|
|
buildAddonView();
|
2013-09-29 17:19:07 +00:00
|
|
|
buildNewAddonView();
|
|
|
|
buildLoadAddonView();
|
2013-10-02 02:29:45 +00:00
|
|
|
buildProfilesView();
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
/*
|
|
|
|
//mContentModel->sort(3); // Sort by date accessed
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
*/
|
|
|
|
}
|
2013-10-02 02:29:45 +00:00
|
|
|
QString ContentSelectorView::ContentSelector::getNewProfileName()
|
|
|
|
{
|
|
|
|
// Create a dialog for the new profile name input
|
|
|
|
//mNewProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this);
|
|
|
|
|
|
|
|
//connect(mNewProfileDialog->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(updateOkButton(QString)));
|
|
|
|
return "";
|
|
|
|
}
|
2013-09-29 17:19:07 +00:00
|
|
|
|
|
|
|
bool ContentSelectorView::ContentSelector::isFlagged(SelectorFlags flag) const
|
|
|
|
{
|
|
|
|
return (mFlags & flag);
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildContentModel()
|
|
|
|
{
|
2013-09-29 17:19:07 +00:00
|
|
|
if (!isFlagged (Flag_Content))
|
|
|
|
return;
|
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
mContentModel = new ContentSelectorModel::ContentModel();
|
2013-09-29 17:19:07 +00:00
|
|
|
|
|
|
|
if (mFilePaths.size()>0)
|
|
|
|
{
|
|
|
|
foreach (const QString &path, mFilePaths)
|
|
|
|
mContentModel->addFiles(path);
|
|
|
|
|
|
|
|
mFilePaths.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.gameFileView->setCurrentIndex(-1);
|
|
|
|
mContentModel->uncheckAll();
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildGameFileView()
|
|
|
|
{
|
2013-09-29 17:19:07 +00:00
|
|
|
if (!isFlagged (Flag_Content))
|
|
|
|
{
|
|
|
|
ui.gameFileView->setVisible(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
mGameFileProxyModel = new QSortFilterProxyModel(this);
|
|
|
|
mGameFileProxyModel->setFilterRegExp(QString::number((int)ContentSelectorModel::ContentType_GameFile));
|
|
|
|
mGameFileProxyModel->setFilterRole (Qt::UserRole);
|
|
|
|
mGameFileProxyModel->setSourceModel (mContentModel);
|
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
ui.gameFileView->setPlaceholderText(QString("Select a game file..."));
|
|
|
|
ui.gameFileView->setModel(mGameFileProxyModel);
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
connect(ui.gameFileView, SIGNAL(currentIndexChanged(int)), this, SLOT (slotCurrentGameFileIndexChanged(int)));
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
ui.gameFileView->setCurrentIndex(-1);
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildAddonView()
|
|
|
|
{
|
2013-09-29 17:19:07 +00:00
|
|
|
if (!isFlagged (Flag_Content))
|
|
|
|
{
|
|
|
|
ui.addonView->setVisible(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
mAddonProxyModel = new QSortFilterProxyModel(this);
|
|
|
|
mAddonProxyModel->setFilterRegExp (QString::number((int)ContentSelectorModel::ContentType_Addon));
|
|
|
|
mAddonProxyModel->setFilterRole (Qt::UserRole);
|
|
|
|
mAddonProxyModel->setDynamicSortFilter (true);
|
|
|
|
mAddonProxyModel->setSourceModel (mContentModel);
|
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
ui.addonView->setModel(mAddonProxyModel);
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
connect(ui.addonView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(slotAddonTableItemClicked(const QModelIndex &)));
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildProfilesView()
|
|
|
|
{
|
2013-09-29 17:19:07 +00:00
|
|
|
if (!isFlagged (Flag_Profile))
|
|
|
|
return;
|
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
// Add the actions to the toolbuttons
|
|
|
|
ui.newProfileButton->setDefaultAction (ui.newProfileAction);
|
|
|
|
ui.deleteProfileButton->setDefaultAction (ui.deleteProfileAction);
|
|
|
|
|
|
|
|
ui.profilesComboBox->addItem ("Default");
|
|
|
|
ui.profilesComboBox->setPlaceholderText (QString("Select a profile..."));
|
|
|
|
|
|
|
|
connect (ui.profilesComboBox, SIGNAL (currentIndexChanged(int)), this, SLOT(slotCurrentProfileIndexChanged(int)));
|
|
|
|
connect (ui.profilesComboBox, SIGNAL (profileRenamed(QString,QString)), this, SIGNAL(signalProfileRenamed(QString,QString)));
|
|
|
|
connect (ui.profilesComboBox, SIGNAL (profileChanged(QString,QString)), this, SIGNAL(signalProfileChanged(QString,QString)));
|
|
|
|
connect (ui.profilesComboBox, SIGNAL (signalProfileTextChanged(QString)), this, SLOT (slotProfileTextChanged (QString)));
|
2013-10-02 03:36:49 +00:00
|
|
|
|
|
|
|
ui.profileGroupBox->setVisible (true);
|
2013-09-29 17:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildLoadAddonView()
|
|
|
|
{
|
|
|
|
if (!isFlagged (Flag_LoadAddon))
|
|
|
|
{
|
|
|
|
ui.projectGroupBox->setVisible (false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.projectCreateButton->setVisible (false);
|
|
|
|
ui.projectGroupBox->setTitle ("");
|
|
|
|
|
|
|
|
connect(ui.projectButtonBox, SIGNAL(accepted()), this, SIGNAL(accepted()));
|
|
|
|
connect(ui.projectButtonBox, SIGNAL(rejected()), this, SIGNAL(rejected()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::buildNewAddonView()
|
|
|
|
{
|
|
|
|
if (!isFlagged (Flag_NewAddon))
|
|
|
|
{
|
|
|
|
ui.profileGroupBox->setVisible (false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFileWidget = new CSVDoc::FileWidget (this);
|
|
|
|
mAdjusterWidget = new CSVDoc::AdjusterWidget (this);
|
|
|
|
|
|
|
|
mFileWidget->setType(true);
|
|
|
|
mFileWidget->extensionLabelIsVisible(false);
|
|
|
|
|
|
|
|
ui.fileWidgetFrame->layout()->addWidget(mFileWidget);
|
|
|
|
ui.adjusterWidgetFrame->layout()->addWidget(mAdjusterWidget);
|
|
|
|
|
|
|
|
ui.projectButtonBox->setStandardButtons(QDialogButtonBox::Cancel);
|
|
|
|
ui.projectButtonBox->addButton(ui.projectCreateButton, QDialogButtonBox::ActionRole);
|
|
|
|
|
|
|
|
connect (mFileWidget, SIGNAL (nameChanged (const QString&, bool)),
|
|
|
|
mAdjusterWidget, SLOT (setName (const QString&, bool)));
|
|
|
|
|
|
|
|
connect (mAdjusterWidget, SIGNAL (stateChanged(bool)), this, SLOT (slotUpdateCreateButton(bool)));
|
|
|
|
|
|
|
|
connect(ui.projectCreateButton, SIGNAL(clicked()), this, SIGNAL(accepted()));
|
|
|
|
connect(ui.projectButtonBox, SIGNAL(rejected()), this, SIGNAL(rejected()));
|
|
|
|
}
|
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
void ContentSelectorView::ContentSelector::setCheckStates(const QStringList &list)
|
|
|
|
{
|
|
|
|
if (list.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
mContentModel->uncheckAll();
|
|
|
|
|
|
|
|
foreach (const QString &file, list)
|
|
|
|
mContentModel->setCheckState(file, Qt::Checked);
|
|
|
|
}
|
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
QString ContentSelectorView::ContentSelector::filename() const
|
|
|
|
{
|
|
|
|
QString filepath = "";
|
|
|
|
|
|
|
|
if (mAdjusterWidget)
|
|
|
|
filepath = QString::fromAscii(mAdjusterWidget->getPath().c_str());
|
|
|
|
|
|
|
|
return filepath;
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
QStringList ContentSelectorView::ContentSelector::selectedFilePaths() const
|
2013-09-22 04:06:29 +00:00
|
|
|
{
|
2013-09-29 17:19:07 +00:00
|
|
|
QStringList filePaths;
|
|
|
|
|
|
|
|
if (mContentModel)
|
|
|
|
{
|
|
|
|
foreach (ContentSelectorModel::EsmFile *file, mContentModel->checkedItems())
|
|
|
|
filePaths.append(file->path());
|
|
|
|
}
|
|
|
|
|
|
|
|
return filePaths;
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
ContentSelectorModel::ContentFileList
|
|
|
|
ContentSelectorView::ContentSelector::selectedFiles() const
|
|
|
|
{
|
|
|
|
if (mContentModel)
|
|
|
|
return mContentModel->checkedItems();
|
|
|
|
|
|
|
|
return ContentSelectorModel::ContentFileList();
|
|
|
|
}
|
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
void ContentSelectorView::ContentSelector::addFiles(const QString &path)
|
|
|
|
{
|
2013-09-29 17:19:07 +00:00
|
|
|
// if the model hasn't been instantiated, queue the path
|
|
|
|
if (!mInstance)
|
|
|
|
mFilePaths.append(path);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mInstance->mContentModel->addFiles(path);
|
|
|
|
mInstance->ui.gameFileView->setCurrentIndex(-1);
|
|
|
|
mInstance->mContentModel->uncheckAll();
|
|
|
|
}
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
void ContentSelectorView::ContentSelector::removeProfile(const QString &item)
|
|
|
|
{
|
|
|
|
int idx = ui.profilesComboBox->findText(item);
|
|
|
|
|
|
|
|
if (idx != -1)
|
|
|
|
ui.profilesComboBox->removeItem(idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ContentSelectorView::ContentSelector::getProfileIndex ( const QString &item) const
|
|
|
|
{
|
|
|
|
return ui.profilesComboBox->findText (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::setProfileIndex(int index)
|
|
|
|
{
|
|
|
|
if (index >=0 && index < ui.profilesComboBox->count())
|
|
|
|
ui.profilesComboBox->setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::addProfile (const QString &item, bool setAsCurrent)
|
|
|
|
{
|
|
|
|
if (item.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ui.profilesComboBox->findText(item) == -1)
|
|
|
|
ui.profilesComboBox->addItem(item);
|
|
|
|
|
|
|
|
if (setAsCurrent)
|
|
|
|
ui.profilesComboBox->setCurrentIndex(ui.profilesComboBox->findText(item));
|
|
|
|
|
|
|
|
enableProfilesComboBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ContentSelectorView::ContentSelector::getProfileText() const
|
|
|
|
{
|
|
|
|
return ui.profilesComboBox->currentText();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::enableProfilesComboBox()
|
|
|
|
{
|
|
|
|
if (!ui.profilesComboBox->isEnabled())
|
|
|
|
ui.profilesComboBox->setEnabled(true);
|
|
|
|
|
|
|
|
if (!ui.deleteProfileAction->isEnabled())
|
|
|
|
ui.deleteProfileAction->setEnabled(true);
|
|
|
|
|
|
|
|
ui.projectButtonBox->button(QDialogButtonBox::Open)->setEnabled (true);
|
|
|
|
}
|
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
QStringList ContentSelectorView::ContentSelector::checkedItemsPaths()
|
|
|
|
{
|
|
|
|
QStringList itemPaths;
|
|
|
|
|
|
|
|
foreach( const ContentSelectorModel::EsmFile *file, mContentModel->checkedItems())
|
|
|
|
itemPaths << file->path();
|
|
|
|
|
|
|
|
return itemPaths;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotCurrentProfileIndexChanged(int index)
|
|
|
|
{
|
2013-10-02 02:29:45 +00:00
|
|
|
//don't allow deleting "Default" profile
|
|
|
|
bool success = (ui.profilesComboBox->itemText(index) == "Default");
|
|
|
|
|
|
|
|
ui.deleteProfileAction->setEnabled(success);
|
|
|
|
ui.profilesComboBox->setEditEnabled(success);
|
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
emit signalProfileChanged(index);
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotCurrentGameFileIndexChanged(int index)
|
|
|
|
{
|
|
|
|
static int oldIndex = -1;
|
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
QAbstractItemModel *const model = ui.gameFileView->model();
|
2013-09-22 04:06:29 +00:00
|
|
|
QSortFilterProxyModel *proxy = dynamic_cast<QSortFilterProxyModel *>(model);
|
|
|
|
|
|
|
|
if (proxy)
|
|
|
|
proxy->setDynamicSortFilter(false);
|
|
|
|
|
|
|
|
if (oldIndex > -1)
|
|
|
|
model->setData(model->index(oldIndex, 0), false, Qt::UserRole + 1);
|
|
|
|
|
|
|
|
oldIndex = index;
|
|
|
|
|
|
|
|
model->setData(model->index(index, 0), true, Qt::UserRole + 1);
|
|
|
|
|
|
|
|
if (proxy)
|
|
|
|
proxy->setDynamicSortFilter(true);
|
2013-09-23 04:52:53 +00:00
|
|
|
|
2013-09-29 17:19:07 +00:00
|
|
|
slotUpdateCreateButton(true);
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
void ContentSelectorView::ContentSelector::slotProfileTextChanged(const QString &text)
|
|
|
|
{
|
|
|
|
QPushButton *opnBtn = ui.projectButtonBox->button(QDialogButtonBox::Open);
|
|
|
|
|
|
|
|
if (opnBtn->isEnabled())
|
|
|
|
opnBtn->setEnabled (false);
|
|
|
|
}
|
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
void ContentSelectorView::ContentSelector::slotAddonTableItemClicked(const QModelIndex &index)
|
|
|
|
{
|
2013-09-29 17:19:07 +00:00
|
|
|
QAbstractItemModel *const model = ui.addonView->model();
|
2013-09-22 04:06:29 +00:00
|
|
|
|
|
|
|
if (model->data(index, Qt::CheckStateRole).toInt() == Qt::Unchecked)
|
|
|
|
model->setData(index, Qt::Checked, Qt::CheckStateRole);
|
|
|
|
else
|
|
|
|
model->setData(index, Qt::Unchecked, Qt::CheckStateRole);
|
|
|
|
}
|
2013-09-29 17:19:07 +00:00
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::slotUpdateCreateButton(bool)
|
|
|
|
{
|
|
|
|
//enable only if a game file is selected and the adjuster widget is non-empty
|
|
|
|
bool validGameFile = (ui.gameFileView->currentIndex() != -1);
|
|
|
|
bool validFilename = false;
|
|
|
|
|
|
|
|
if (mAdjusterWidget)
|
|
|
|
validFilename = mAdjusterWidget->isValid();
|
|
|
|
|
|
|
|
ui.projectCreateButton->setEnabled(validGameFile && validFilename);
|
|
|
|
}
|
2013-10-02 02:29:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::on_newProfileAction_triggered()
|
|
|
|
{
|
|
|
|
emit signalProfileAdded();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentSelectorView::ContentSelector::on_deleteProfileAction_triggered()
|
|
|
|
{
|
|
|
|
QString profile = ui.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));
|
|
|
|
|
|
|
|
QAbstractButton *deleteButton =
|
|
|
|
msgBox.addButton(tr("Delete"), QMessageBox::ActionRole);
|
|
|
|
|
|
|
|
msgBox.exec();
|
|
|
|
|
|
|
|
if (msgBox.clickedButton() != deleteButton)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Remove the profile from the combobox
|
|
|
|
ui.profilesComboBox->removeItem(ui.profilesComboBox->findText(profile));
|
|
|
|
|
|
|
|
//signal for removal from model
|
|
|
|
emit signalProfileDeleted (profile);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
void ContentSelectorView::ContentSelector::slotUpdateOkButton(const QString &text)
|
|
|
|
{
|
|
|
|
bool success = (ui.profilesComboBox->findText(text) == -1);
|
|
|
|
|
|
|
|
mNewDialog->setOkButtonEnabled(success);
|
|
|
|
}*/
|