diff options
| -rw-r--r-- | src/editexecutablesdialog.cpp | 11 | ||||
| -rw-r--r-- | src/executableslist.cpp | 22 | ||||
| -rw-r--r-- | src/executableslist.h | 15 | ||||
| -rw-r--r-- | src/main.cpp | 7 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 121 | ||||
| -rw-r--r-- | src/mainwindow.h | 14 |
6 files changed, 89 insertions, 101 deletions
diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp index e84e1112..48d33c79 100644 --- a/src/editexecutablesdialog.cpp +++ b/src/editexecutablesdialog.cpp @@ -47,7 +47,7 @@ ExecutablesList EditExecutablesDialog::getExecutablesList() const { ExecutablesList newList; for (int i = 0; i < ui->executablesListBox->count(); ++i) { - newList.addExecutable(ui->executablesListBox->item(i)->data(Qt::UserRole).value<Executable>()); + newList.addExecutable(m_ExecutablesList.find(ui->executablesListBox->item(i)->text())); } return newList; } @@ -60,9 +60,6 @@ void EditExecutablesDialog::refreshExecutablesWidget() for(; current != end; ++current) { QListWidgetItem *newItem = new QListWidgetItem(current->m_Title); - QVariant temp; - temp.setValue(*current); - newItem->setData(Qt::UserRole, temp); newItem->setTextColor(current->m_Custom ? QColor(Qt::black) : QColor(Qt::darkGray)); ui->executablesListBox->addItem(newItem); } @@ -170,8 +167,6 @@ void EditExecutablesDialog::on_browseDirButton_clicked() void EditExecutablesDialog::on_removeButton_clicked() { -// QLineEdit *binaryEdit = findChild<QLineEdit*>("binaryEdit"); - if (QMessageBox::question(this, tr("Confirm"), tr("Really remove \"%1\" from executables?").arg(ui->titleEdit->text()), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { m_ExecutablesList.remove(ui->titleEdit->text()); @@ -206,7 +201,7 @@ void EditExecutablesDialog::on_titleEdit_textChanged(const QString &arg1) bool EditExecutablesDialog::executableChanged() { if (m_CurrentItem != nullptr) { - const Executable &selectedExecutable = m_CurrentItem->data(Qt::UserRole).value<Executable>(); + Executable const &selectedExecutable(m_ExecutablesList.find(m_CurrentItem->text())); return selectedExecutable.m_Arguments != ui->argumentsEdit->text() || selectedExecutable.m_SteamAppID != ui->appIDOverwriteEdit->text() @@ -272,7 +267,7 @@ void EditExecutablesDialog::on_executablesListBox_clicked(const QModelIndex &cur m_CurrentItem = ui->executablesListBox->item(current.row()); - const Executable &selectedExecutable = m_CurrentItem->data(Qt::UserRole).value<Executable>(); + Executable const &selectedExecutable(m_ExecutablesList.find(m_CurrentItem->text())); ui->titleEdit->setText(selectedExecutable.m_Title); ui->binaryEdit->setText(QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath())); diff --git a/src/executableslist.cpp b/src/executableslist.cpp index badf0813..91bfd39e 100644 --- a/src/executableslist.cpp +++ b/src/executableslist.cpp @@ -55,14 +55,6 @@ static QDataStream &operator>>(QDataStream &in, Executable &obj) return in;
}
-
-void registerExecutable()
-{
- qRegisterMetaType<Executable>("Executable");
- qRegisterMetaTypeStreamOperators<Executable>("Executable");
-}
-
-
ExecutablesList::ExecutablesList()
{
}
@@ -102,23 +94,23 @@ void ExecutablesList::getExecutables(std::vector<Executable>::const_iterator &be const Executable &ExecutablesList::find(const QString &title) const
{
- for (std::vector<Executable>::const_iterator iter = m_Executables.begin(); iter != m_Executables.end(); ++iter) {
- if (iter->m_Title == title) {
- return *iter;
+ for (Executable const &exe : m_Executables) {
+ if (exe.m_Title == title) {
+ return exe;
}
}
- throw std::runtime_error("invalid name");
+ throw std::runtime_error("invalid name " + title.toStdString());
}
Executable &ExecutablesList::find(const QString &title)
{
for (Executable &exe : m_Executables) {
- if (QString::compare(exe.m_Title, title, Qt::CaseInsensitive) == 0) {
+ if (exe.m_Title == title) {
return exe;
}
}
- throw std::runtime_error("invalid name");
+ throw std::runtime_error("invalid name " + title.toStdString());
}
@@ -220,7 +212,7 @@ void ExecutablesList::addExecutable(const QString &title, const QString &executa void ExecutablesList::remove(const QString &title)
{
for (std::vector<Executable>::iterator iter = m_Executables.begin(); iter != m_Executables.end(); ++iter) {
- if (iter->m_Custom && (iter->m_Title == title)) {
+ if (iter->m_Custom && iter->m_Title == title) {
m_Executables.erase(iter);
break;
}
diff --git a/src/executableslist.h b/src/executableslist.h index 888dbfe1..cf2fbac3 100644 --- a/src/executableslist.h +++ b/src/executableslist.h @@ -42,10 +42,6 @@ struct Executable { bool m_Custom;
bool m_Toolbar;
};
-Q_DECLARE_METATYPE(Executable)
-
-
-void registerExecutable();
/*!
@@ -83,7 +79,7 @@ public: * @return the executable
* @exception runtime_error will throw an exception if the name is not correct
**/
- const Executable &find(const QString &tilte) const;
+ const Executable &find(const QString &title) const;
/**
* @brief find an executable by its name
@@ -92,7 +88,7 @@ public: * @return the executable
* @exception runtime_error will throw an exception if the name is not correct
**/
- Executable &find(const QString &tilte);
+ Executable &find(const QString &title);
/**
* @brief find an executable by a fileinfo structure
@@ -159,6 +155,13 @@ public: **/
void getExecutables(std::vector<Executable>::iterator &begin, std::vector<Executable>::iterator &end);
+ /**
+ * @brief get the number of executables (custom or otherwise)
+ **/
+ size_t size() const {
+ return m_Executables.size();
+ }
+
private:
std::vector<Executable>::iterator findExe(const QString &title);
diff --git a/src/main.cpp b/src/main.cpp index 295fb75a..973ae2a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -248,11 +248,6 @@ static LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS *except return result;
}
-static void registerMetaTypes()
-{
- registerExecutable();
-}
-
static bool HaveWriteAccess(const std::wstring &path)
{
bool writable = false;
@@ -414,8 +409,6 @@ int main(int argc, char *argv[]) ::SetEnvironmentVariableW(L"PATH", newPath.c_str());
}
- registerMetaTypes();
-
QStringList arguments = application.arguments();
bool forcePrimary = false;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4ffa044b..31596fed 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -489,9 +489,6 @@ void MainWindow::updateToolBar() QAction *exeAction = new QAction(iconForExecutable(iter->m_BinaryInfo.filePath()),
iter->m_Title,
ui->toolBar);
- QVariant temp;
- temp.setValue(*iter);
- exeAction->setData(temp);
exeAction->setObjectName(QString("custom__") + iter->m_Title);
if (!connect(exeAction, SIGNAL(triggered()), this, SLOT(startExeAction()))) {
qDebug("failed to connect trigger?");
@@ -955,7 +952,7 @@ void MainWindow::startExeAction() {
QAction *action = qobject_cast<QAction*>(sender());
if (action != nullptr) {
- Executable selectedExecutable = action->data().value<Executable>();
+ Executable const &selectedExecutable(m_OrganizerCore.executablesList()->find(action->text()));
m_OrganizerCore.spawnBinary(
selectedExecutable.m_BinaryInfo,
selectedExecutable.m_Arguments,
@@ -1198,10 +1195,8 @@ void MainWindow::refreshExecutablesList() std::vector<Executable>::const_iterator current, end;
m_OrganizerCore.executablesList()->getExecutables(current, end);
for(int i = 0; current != end; ++current, ++i) {
- QVariant temp;
- temp.setValue(*current);
QIcon icon = iconForExecutable(current->m_BinaryInfo.filePath());
- executablesList->addItem(icon, current->m_Title, temp);
+ executablesList->addItem(icon, current->m_Title);
model->setData(model->index(i, 0), QSize(0, executablesList->iconSize().height() + 4), Qt::SizeHintRole);
}
@@ -1608,9 +1603,7 @@ void MainWindow::installMod(QString fileName) void MainWindow::on_startButton_clicked()
{
- QComboBox* executablesList = findChild<QComboBox*>("executablesListBox");
-
- Executable selectedExecutable = executablesList->itemData(executablesList->currentIndex()).value<Executable>();
+ Executable const &selectedExecutable(getSelectedExecutable());
m_OrganizerCore.spawnBinary(
selectedExecutable.m_BinaryInfo,
@@ -1718,11 +1711,10 @@ void MainWindow::on_executablesListBox_currentIndexChanged(int index) m_OldExecutableIndex = index;
if (executablesList->isEnabled()) {
-
- if (executablesList->itemData(index).isNull()) {
+ //I think the 2nd test is impossible
+ if (index == 0 || index > static_cast<int>(m_OrganizerCore.executablesList()->size())) {
if (modifyExecutablesDialog()) {
setExecutableIndex(previousIndex);
-// executablesList->setCurrentIndex(previousIndex);
}
} else {
setExecutableIndex(index);
@@ -1737,7 +1729,6 @@ void MainWindow::helpTriggered() void MainWindow::wikiTriggered()
{
-// ::ShellExecuteW(nullptr, L"open", L"http://issue.tannin.eu/tbg/wiki/Modorganizer%3AMainPage", nullptr, nullptr, SW_SHOWNORMAL);
::ShellExecuteW(nullptr, L"open", L"http://wiki.step-project.com/Guide:Mod_Organizer", nullptr, nullptr, SW_SHOWNORMAL);
}
@@ -3244,27 +3235,43 @@ void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) void MainWindow::linkToolbar()
{
- const Executable &selectedExecutable = ui->executablesListBox->itemData(ui->executablesListBox->currentIndex()).value<Executable>();
- Executable &exe = m_OrganizerCore.executablesList()->find(selectedExecutable.m_Title);
+ Executable &exe(getSelectedExecutable());
exe.m_Toolbar = !exe.m_Toolbar;
- ui->linkButton->menu()->actions().at(2)->setIcon(exe.m_Toolbar ? QIcon(":/MO/gui/remove") : QIcon(":/MO/gui/link"));
+ ui->linkButton->menu()->actions().at(static_cast<int>(Shortcut_Type::Toolbar))->setIcon(exe.m_Toolbar ? QIcon(":/MO/gui/remove") : QIcon(":/MO/gui/link"));
updateToolBar();
}
-void MainWindow::linkDesktop()
+namespace {
+QString getLinkfile(QString const &dir, Executable const &exec)
+{
+ return QDir::fromNativeSeparators(dir) + "/" + exec.m_Title + ".lnk";
+}
+
+QString getDesktopLinkfile(Executable const &exec)
{
- const Executable &selectedExecutable =
- ui->executablesListBox->itemData(ui->executablesListBox->currentIndex()).value<Executable>();
- QString linkName = getDesktopDirectory() + "\\" + selectedExecutable.m_Title + ".lnk";
+ return getLinkfile(getDesktopDirectory(), exec);
+}
+
+QString getStartMenuLinkfile(Executable const &exec)
+{
+ return getLinkfile(getStartMenuDirectory(), exec);
+}
+}
+
+void MainWindow::addWindowsLink(Shortcut_Type const mapping)
+{
+ Executable const &selectedExecutable(getSelectedExecutable());
+ QString const linkName = getLinkfile(mapping == Shortcut_Type::Windows_Desktop ? getDesktopDirectory() : getStartMenuDirectory(),
+ selectedExecutable);
if (QFile::exists(linkName)) {
if (QFile::remove(linkName)) {
- ui->linkButton->menu()->actions().at(0)->setIcon(QIcon(":/MO/gui/link"));
+ ui->linkButton->menu()->actions().at(static_cast<int>(mapping))->setIcon(QIcon(":/MO/gui/link"));
} else {
reportError(tr("failed to remove %1").arg(linkName));
}
} else {
- QFileInfo exeInfo(qApp->applicationFilePath());
+ QFileInfo const exeInfo(qApp->applicationFilePath());
// create link
std::wstring targetFile = ToWString(exeInfo.absoluteFilePath());
std::wstring parameter = ToWString(QString("\"%1\" %2").arg(QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath()))
@@ -3274,46 +3281,24 @@ void MainWindow::linkDesktop() if (CreateShortcut(targetFile.c_str()
, parameter.c_str()
- , linkName.toUtf8().constData()
+ , QDir::toNativeSeparators(linkName).toUtf8().constData()
, description.c_str()
- , currentDirectory.c_str()) != E_INVALIDARG) {
- ui->linkButton->menu()->actions().at(0)->setIcon(QIcon(":/MO/gui/remove"));
+ , currentDirectory.c_str()) == 0) {
+ ui->linkButton->menu()->actions().at(static_cast<int>(mapping))->setIcon(QIcon(":/MO/gui/remove"));
} else {
reportError(tr("failed to create %1").arg(linkName));
}
}
}
-void MainWindow::linkMenu()
+void MainWindow::linkDesktop()
{
- QComboBox* executablesList = findChild<QComboBox*>("executablesListBox");
-
- const Executable &selectedExecutable = executablesList->itemData(executablesList->currentIndex()).value<Executable>();
- QString linkName = getStartMenuDirectory() + "\\" + selectedExecutable.m_Title + ".lnk";
-
- if (QFile::exists(linkName)) {
- if (QFile::remove(linkName)) {
- ui->linkButton->menu()->actions().at(1)->setIcon(QIcon(":/MO/gui/link"));
- } else {
- reportError(tr("failed to remove %1").arg(linkName));
- }
- } else {
- QFileInfo exeInfo(qApp->applicationFilePath());
- // create link
- std::wstring targetFile = ToWString(exeInfo.absoluteFilePath());
- std::wstring parameter = ToWString(QString("\"%1\" %2").arg(QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath()))
- .arg(selectedExecutable.m_Arguments));
- std::wstring description = ToWString(selectedExecutable.m_BinaryInfo.fileName());
- std::wstring currentDirectory = ToWString(QDir::toNativeSeparators(exeInfo.absolutePath()));
+ addWindowsLink(Shortcut_Type::Windows_Desktop);
+}
- if (CreateShortcut(targetFile.c_str(), parameter.c_str(),
- linkName.toUtf8().constData(),
- description.c_str(), currentDirectory.c_str()) != E_INVALIDARG) {
- ui->linkButton->menu()->actions().at(1)->setIcon(QIcon(":/MO/gui/remove"));
- } else {
- reportError(tr("failed to create %1").arg(linkName));
- }
- }
+void MainWindow::linkMenu()
+{
+ addWindowsLink(Shortcut_Type::Windows_StartMenu);
}
void MainWindow::on_actionSettings_triggered()
@@ -4209,19 +4194,31 @@ void MainWindow::on_groupCombo_currentIndexChanged(int index) modFilterActive(m_ModListSortProxy->isFilterActive());
}
+const Executable &MainWindow::getSelectedExecutable() const
+{
+ QString name = ui->executablesListBox->itemText(ui->executablesListBox->currentIndex());
+ return m_OrganizerCore.executablesList()->find(name);
+}
+
+Executable &MainWindow::getSelectedExecutable()
+{
+ QString name = ui->executablesListBox->itemText(ui->executablesListBox->currentIndex());
+ return m_OrganizerCore.executablesList()->find(name);
+}
+
void MainWindow::on_linkButton_pressed()
{
- const Executable &selectedExecutable = ui->executablesListBox->itemData(ui->executablesListBox->currentIndex()).value<Executable>();
+ Executable const &selectedExecutable(getSelectedExecutable());
- QIcon addIcon(":/MO/gui/link");
- QIcon removeIcon(":/MO/gui/remove");
+ QIcon const addIcon(":/MO/gui/link");
+ QIcon const removeIcon(":/MO/gui/remove");
- QFileInfo linkDesktopFile(QDir::fromNativeSeparators(getDesktopDirectory()) + "/" + selectedExecutable.m_Title + ".lnk");
- QFileInfo linkMenuFile(QDir::fromNativeSeparators(getStartMenuDirectory()) + "/" + selectedExecutable.m_Title + ".lnk");
+ QFileInfo const linkDesktopFile(getDesktopLinkfile(selectedExecutable));
+ QFileInfo const linkMenuFile(getStartMenuLinkfile(selectedExecutable));
- ui->linkButton->menu()->actions().at(0)->setIcon(selectedExecutable.m_Toolbar ? removeIcon : addIcon);
- ui->linkButton->menu()->actions().at(1)->setIcon(linkDesktopFile.exists() ? removeIcon : addIcon);
- ui->linkButton->menu()->actions().at(2)->setIcon(linkMenuFile.exists() ? removeIcon : addIcon);
+ ui->linkButton->menu()->actions().at(static_cast<int>(Shortcut_Type::Toolbar))->setIcon(selectedExecutable.m_Toolbar ? removeIcon : addIcon);
+ ui->linkButton->menu()->actions().at(static_cast<int>(Shortcut_Type::Windows_Desktop))->setIcon(linkDesktopFile.exists() ? removeIcon : addIcon);
+ ui->linkButton->menu()->actions().at(static_cast<int>(Shortcut_Type::Windows_StartMenu))->setIcon(linkMenuFile.exists() ? removeIcon : addIcon);
}
void MainWindow::on_showHiddenBox_toggled(bool checked)
diff --git a/src/mainwindow.h b/src/mainwindow.h index 405a39ef..d60de869 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -30,7 +30,6 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <QProgressBar>
#include <QTranslator>
#include <QPluginLoader>
-#include "executableslist.h"
#include "modlist.h"
#include "pluginlist.h"
#include "plugincontainer.h"
@@ -93,8 +92,6 @@ public: void refreshDataTree();
void refreshSaveList();
- void setExecutablesList(const ExecutablesList &executablesList);
-
void setModListSorting(int index);
void setESPListSorting(int index);
@@ -329,6 +326,17 @@ private: MOBase::DelayedFileWriter m_ArchiveListWriter;
+ enum class Shortcut_Type {
+ Toolbar,
+ Windows_Desktop,
+ Windows_StartMenu
+ };
+
+ void addWindowsLink(Shortcut_Type const);
+
+ Executable const &getSelectedExecutable() const;
+ Executable &getSelectedExecutable();
+
private slots:
void showMessage(const QString &message);
|
