summaryrefslogtreecommitdiff
path: root/src/editexecutablesdialog.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-07-17 22:02:15 +0200
committerTannin <devnull@localhost>2014-07-17 22:02:15 +0200
commitcc9827cdda5776a4fd540a2ab0fb8a08ec9f75a7 (patch)
tree570a4a3bea9457d82de2cf44aa440e4a4cec4271 /src/editexecutablesdialog.cpp
parent4e5a67fc063243c4c10e04b5f601108dd01357f3 (diff)
normalized eol style (all files should now have windows line endings)
Diffstat (limited to 'src/editexecutablesdialog.cpp')
-rw-r--r--src/editexecutablesdialog.cpp578
1 files changed, 289 insertions, 289 deletions
diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp
index 13223b68..02abf30e 100644
--- a/src/editexecutablesdialog.cpp
+++ b/src/editexecutablesdialog.cpp
@@ -1,289 +1,289 @@
-/*
-Copyright (C) 2012 Sebastian Herbord. All rights reserved.
-
-This file is part of Mod Organizer.
-
-Mod Organizer is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Mod Organizer is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "editexecutablesdialog.h"
-#include "ui_editexecutablesdialog.h"
-#include "filedialogmemory.h"
-#include <QMessageBox>
-#include <Shellapi.h>
-#include <utility.h>
-
-
-using namespace MOBase;
-using namespace MOShared;
-
-EditExecutablesDialog::EditExecutablesDialog(const ExecutablesList &executablesList, QWidget *parent)
- : TutorableDialog("EditExecutables", parent),
- ui(new Ui::EditExecutablesDialog), m_CurrentItem(NULL), m_ExecutablesList(executablesList)
-{
- ui->setupUi(this);
-
- refreshExecutablesWidget();
-}
-
-EditExecutablesDialog::~EditExecutablesDialog()
-{
- delete ui;
-}
-
-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>());
- }
- return newList;
-}
-
-void EditExecutablesDialog::refreshExecutablesWidget()
-{
- QListWidget *executablesWidget = findChild<QListWidget*>("executablesListBox");
-
- executablesWidget->clear();
- std::vector<Executable>::const_iterator current, end;
- m_ExecutablesList.getExecutables(current, end);
-
- 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));
- executablesWidget->addItem(newItem);
- }
-
- ui->addButton->setEnabled(false);
- ui->removeButton->setEnabled(false);
-}
-
-
-void EditExecutablesDialog::on_binaryEdit_textChanged(const QString &arg1)
-{
- QFileInfo fileInfo(arg1);
- ui->addButton->setEnabled(fileInfo.exists() && fileInfo.isFile());
-}
-
-void EditExecutablesDialog::resetInput()
-{
- ui->binaryEdit->setText("");
- ui->titleEdit->setText("");
- ui->workingDirEdit->clear();
- ui->argumentsEdit->setText("");
- ui->appIDOverwriteEdit->clear();
- ui->overwriteAppIDBox->setChecked(false);
- ui->closeCheckBox->setChecked(false);
- m_CurrentItem = NULL;
-}
-
-
-void EditExecutablesDialog::saveExecutable()
-{
- m_ExecutablesList.addExecutable(ui->titleEdit->text(), QDir::fromNativeSeparators(ui->binaryEdit->text()),
- ui->argumentsEdit->text(), QDir::fromNativeSeparators(ui->workingDirEdit->text()),
- (ui->closeCheckBox->checkState() == Qt::Checked) ? DEFAULT_CLOSE : DEFAULT_STAY,
- ui->overwriteAppIDBox->isChecked() ? ui->appIDOverwriteEdit->text() : "",
- true, false);
-}
-
-
-void EditExecutablesDialog::delayedRefresh()
-{
- int index = ui->executablesListBox->currentIndex().row();
- resetInput();
- refreshExecutablesWidget();
- ui->executablesListBox->setCurrentRow(index);
-}
-
-
-void EditExecutablesDialog::on_addButton_clicked()
-{
- saveExecutable();
-
- resetInput();
- refreshExecutablesWidget();
-}
-
-void EditExecutablesDialog::on_browseButton_clicked()
-{
- QString binaryName = FileDialogMemory::getOpenFileName("editExecutableBinary", this,
- tr("Select a binary"), QString(), tr("Executable (%1)").arg("*.exe *.bat *.jar"));
-
- if (binaryName.endsWith(".jar", Qt::CaseInsensitive)) {
- QString binaryPath;
- { // try to find java automatically
- std::wstring binaryNameW = ToWString(binaryName);
- WCHAR buffer[MAX_PATH];
- if (::FindExecutableW(binaryNameW.c_str(), NULL, buffer) > (HINSTANCE)32) {
- DWORD binaryType = 0UL;
- if (!::GetBinaryTypeW(binaryNameW.c_str(), &binaryType)) {
- qDebug("failed to determine binary type: %lu", ::GetLastError());
- } else if (binaryType == SCS_32BIT_BINARY) {
- binaryPath = ToQString(buffer);
- }
- }
- }
- if (binaryPath.isEmpty()) {
- QSettings javaReg("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment", QSettings::NativeFormat);
- if (javaReg.contains("CurrentVersion")) {
- QString currentVersion = javaReg.value("CurrentVersion").toString();
- binaryPath = javaReg.value(QString("%1/JavaHome").arg(currentVersion)).toString().append("\\bin\\javaw.exe");
- }
- }
- if (binaryPath.isEmpty()) {
- QMessageBox::information(this, tr("Java (32-bit) required"),
- tr("MO requires 32-bit java to run this application. If you already have it installed, select javaw.exe "
- "from that installation as the binary."));
- } else {
- ui->binaryEdit->setText(binaryPath);
- }
-
- ui->workingDirEdit->setText(QDir::toNativeSeparators(QFileInfo(binaryName).absolutePath()));
- ui->argumentsEdit->setText("-jar \"" + QDir::toNativeSeparators(binaryName) + "\"");
- } else {
- ui->binaryEdit->setText(QDir::toNativeSeparators(binaryName));
- }
-}
-
-void EditExecutablesDialog::on_browseDirButton_clicked()
-{
- QString dirName = FileDialogMemory::getExistingDirectory("editExecutableDirectory", this,
- tr("Select a directory"));
-
- ui->workingDirEdit->setText(dirName);
-}
-
-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());
- }
-
- resetInput();
- refreshExecutablesWidget();
-}
-
-void EditExecutablesDialog::on_titleEdit_textChanged(const QString &arg1)
-{
- QPushButton *addButton = findChild<QPushButton*>("addButton");
- QPushButton *removeButton = findChild<QPushButton*>("removeButton");
-
- QListWidget *executablesWidget = findChild<QListWidget*>("executablesListBox");
-
- QList<QListWidgetItem*> existingItems = executablesWidget->findItems(arg1, Qt::MatchFixedString);
-
- addButton->setEnabled(arg1.length() != 0);
-
- if (existingItems.count() == 0) {
- addButton->setText(tr("Add"));
- removeButton->setEnabled(false);
- } else {
- // existing item. is it a custom one?
- addButton->setText(tr("Modify"));
- removeButton->setEnabled(true);
- }
-}
-
-
-bool EditExecutablesDialog::executableChanged()
-{
- if (m_CurrentItem != NULL) {
- const Executable &selectedExecutable = m_CurrentItem->data(Qt::UserRole).value<Executable>();
-
- return selectedExecutable.m_Arguments != ui->argumentsEdit->text()
- || selectedExecutable.m_SteamAppID != ui->appIDOverwriteEdit->text()
- || selectedExecutable.m_WorkingDirectory != QDir::fromNativeSeparators(ui->workingDirEdit->text())
- || selectedExecutable.m_BinaryInfo.absoluteFilePath() != QDir::fromNativeSeparators(ui->binaryEdit->text())
- || (selectedExecutable.m_CloseMO == DEFAULT_CLOSE) != ui->closeCheckBox->isChecked();
- } else {
- return false;
- }
-}
-
-
-void EditExecutablesDialog::on_executablesListBox_currentItemChanged(QListWidgetItem *current, QListWidgetItem*)
-{
- if (current == NULL) {
- resetInput();
- return;
- }
-
- if (executableChanged()) {
- QMessageBox::StandardButton res = QMessageBox::question(this, tr("Save Changes?"),
- tr("You made changes to the current executable, do you want to save them?"),
- QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
- if (res == QMessageBox::Cancel) {
- return;
- } else if (res == QMessageBox::Yes) {
- // this invalidates the item passed as a a parameter
- saveExecutable();
-
- QTimer::singleShot(50, this, SLOT(delayedRefresh()));
- return;
- }
- }
-
- m_CurrentItem = current;
-
- const Executable &selectedExecutable = current->data(Qt::UserRole).value<Executable>();
-
- ui->titleEdit->setText(selectedExecutable.m_Title);
- ui->binaryEdit->setText(QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath()));
- ui->argumentsEdit->setText(selectedExecutable.m_Arguments);
- ui->workingDirEdit->setText(QDir::toNativeSeparators(selectedExecutable.m_WorkingDirectory));
- ui->closeCheckBox->setChecked(selectedExecutable.m_CloseMO == DEFAULT_CLOSE);
- if (selectedExecutable.m_CloseMO == NEVER_CLOSE) {
- ui->closeCheckBox->setEnabled(false);
- ui->closeCheckBox->setToolTip(tr("MO must be kept running or this application will not work correctly."));
- } else {
- ui->closeCheckBox->setEnabled(true);
- ui->closeCheckBox->setToolTip(tr("If checked, MO will be closed once the specified executable is run."));
- }
- ui->removeButton->setEnabled(selectedExecutable.m_Custom);
- ui->overwriteAppIDBox->setChecked(selectedExecutable.m_SteamAppID != 0);
- if (selectedExecutable.m_SteamAppID != 0) {
- ui->appIDOverwriteEdit->setText(selectedExecutable.m_SteamAppID);
- } else {
- ui->appIDOverwriteEdit->clear();
- }
-}
-
-
-void EditExecutablesDialog::on_overwriteAppIDBox_toggled(bool checked)
-{
- ui->appIDOverwriteEdit->setEnabled(checked);
-}
-
-void EditExecutablesDialog::on_closeButton_clicked()
-{
- if (executableChanged()) {
- QMessageBox::StandardButton res = QMessageBox::question(this, tr("Save Changes?"),
- tr("You made changes to the current executable, do you want to save them?"),
- QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
- if (res == QMessageBox::Cancel) {
- return;
- } else if (res == QMessageBox::Yes) {
- saveExecutable();
- }
- }
- this->accept();
-}
-
+/*
+Copyright (C) 2012 Sebastian Herbord. All rights reserved.
+
+This file is part of Mod Organizer.
+
+Mod Organizer is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Mod Organizer is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "editexecutablesdialog.h"
+#include "ui_editexecutablesdialog.h"
+#include "filedialogmemory.h"
+#include <QMessageBox>
+#include <Shellapi.h>
+#include <utility.h>
+
+
+using namespace MOBase;
+using namespace MOShared;
+
+EditExecutablesDialog::EditExecutablesDialog(const ExecutablesList &executablesList, QWidget *parent)
+ : TutorableDialog("EditExecutables", parent),
+ ui(new Ui::EditExecutablesDialog), m_CurrentItem(NULL), m_ExecutablesList(executablesList)
+{
+ ui->setupUi(this);
+
+ refreshExecutablesWidget();
+}
+
+EditExecutablesDialog::~EditExecutablesDialog()
+{
+ delete ui;
+}
+
+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>());
+ }
+ return newList;
+}
+
+void EditExecutablesDialog::refreshExecutablesWidget()
+{
+ QListWidget *executablesWidget = findChild<QListWidget*>("executablesListBox");
+
+ executablesWidget->clear();
+ std::vector<Executable>::const_iterator current, end;
+ m_ExecutablesList.getExecutables(current, end);
+
+ 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));
+ executablesWidget->addItem(newItem);
+ }
+
+ ui->addButton->setEnabled(false);
+ ui->removeButton->setEnabled(false);
+}
+
+
+void EditExecutablesDialog::on_binaryEdit_textChanged(const QString &arg1)
+{
+ QFileInfo fileInfo(arg1);
+ ui->addButton->setEnabled(fileInfo.exists() && fileInfo.isFile());
+}
+
+void EditExecutablesDialog::resetInput()
+{
+ ui->binaryEdit->setText("");
+ ui->titleEdit->setText("");
+ ui->workingDirEdit->clear();
+ ui->argumentsEdit->setText("");
+ ui->appIDOverwriteEdit->clear();
+ ui->overwriteAppIDBox->setChecked(false);
+ ui->closeCheckBox->setChecked(false);
+ m_CurrentItem = NULL;
+}
+
+
+void EditExecutablesDialog::saveExecutable()
+{
+ m_ExecutablesList.addExecutable(ui->titleEdit->text(), QDir::fromNativeSeparators(ui->binaryEdit->text()),
+ ui->argumentsEdit->text(), QDir::fromNativeSeparators(ui->workingDirEdit->text()),
+ (ui->closeCheckBox->checkState() == Qt::Checked) ? DEFAULT_CLOSE : DEFAULT_STAY,
+ ui->overwriteAppIDBox->isChecked() ? ui->appIDOverwriteEdit->text() : "",
+ true, false);
+}
+
+
+void EditExecutablesDialog::delayedRefresh()
+{
+ int index = ui->executablesListBox->currentIndex().row();
+ resetInput();
+ refreshExecutablesWidget();
+ ui->executablesListBox->setCurrentRow(index);
+}
+
+
+void EditExecutablesDialog::on_addButton_clicked()
+{
+ saveExecutable();
+
+ resetInput();
+ refreshExecutablesWidget();
+}
+
+void EditExecutablesDialog::on_browseButton_clicked()
+{
+ QString binaryName = FileDialogMemory::getOpenFileName("editExecutableBinary", this,
+ tr("Select a binary"), QString(), tr("Executable (%1)").arg("*.exe *.bat *.jar"));
+
+ if (binaryName.endsWith(".jar", Qt::CaseInsensitive)) {
+ QString binaryPath;
+ { // try to find java automatically
+ std::wstring binaryNameW = ToWString(binaryName);
+ WCHAR buffer[MAX_PATH];
+ if (::FindExecutableW(binaryNameW.c_str(), NULL, buffer) > (HINSTANCE)32) {
+ DWORD binaryType = 0UL;
+ if (!::GetBinaryTypeW(binaryNameW.c_str(), &binaryType)) {
+ qDebug("failed to determine binary type: %lu", ::GetLastError());
+ } else if (binaryType == SCS_32BIT_BINARY) {
+ binaryPath = ToQString(buffer);
+ }
+ }
+ }
+ if (binaryPath.isEmpty()) {
+ QSettings javaReg("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment", QSettings::NativeFormat);
+ if (javaReg.contains("CurrentVersion")) {
+ QString currentVersion = javaReg.value("CurrentVersion").toString();
+ binaryPath = javaReg.value(QString("%1/JavaHome").arg(currentVersion)).toString().append("\\bin\\javaw.exe");
+ }
+ }
+ if (binaryPath.isEmpty()) {
+ QMessageBox::information(this, tr("Java (32-bit) required"),
+ tr("MO requires 32-bit java to run this application. If you already have it installed, select javaw.exe "
+ "from that installation as the binary."));
+ } else {
+ ui->binaryEdit->setText(binaryPath);
+ }
+
+ ui->workingDirEdit->setText(QDir::toNativeSeparators(QFileInfo(binaryName).absolutePath()));
+ ui->argumentsEdit->setText("-jar \"" + QDir::toNativeSeparators(binaryName) + "\"");
+ } else {
+ ui->binaryEdit->setText(QDir::toNativeSeparators(binaryName));
+ }
+}
+
+void EditExecutablesDialog::on_browseDirButton_clicked()
+{
+ QString dirName = FileDialogMemory::getExistingDirectory("editExecutableDirectory", this,
+ tr("Select a directory"));
+
+ ui->workingDirEdit->setText(dirName);
+}
+
+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());
+ }
+
+ resetInput();
+ refreshExecutablesWidget();
+}
+
+void EditExecutablesDialog::on_titleEdit_textChanged(const QString &arg1)
+{
+ QPushButton *addButton = findChild<QPushButton*>("addButton");
+ QPushButton *removeButton = findChild<QPushButton*>("removeButton");
+
+ QListWidget *executablesWidget = findChild<QListWidget*>("executablesListBox");
+
+ QList<QListWidgetItem*> existingItems = executablesWidget->findItems(arg1, Qt::MatchFixedString);
+
+ addButton->setEnabled(arg1.length() != 0);
+
+ if (existingItems.count() == 0) {
+ addButton->setText(tr("Add"));
+ removeButton->setEnabled(false);
+ } else {
+ // existing item. is it a custom one?
+ addButton->setText(tr("Modify"));
+ removeButton->setEnabled(true);
+ }
+}
+
+
+bool EditExecutablesDialog::executableChanged()
+{
+ if (m_CurrentItem != NULL) {
+ const Executable &selectedExecutable = m_CurrentItem->data(Qt::UserRole).value<Executable>();
+
+ return selectedExecutable.m_Arguments != ui->argumentsEdit->text()
+ || selectedExecutable.m_SteamAppID != ui->appIDOverwriteEdit->text()
+ || selectedExecutable.m_WorkingDirectory != QDir::fromNativeSeparators(ui->workingDirEdit->text())
+ || selectedExecutable.m_BinaryInfo.absoluteFilePath() != QDir::fromNativeSeparators(ui->binaryEdit->text())
+ || (selectedExecutable.m_CloseMO == DEFAULT_CLOSE) != ui->closeCheckBox->isChecked();
+ } else {
+ return false;
+ }
+}
+
+
+void EditExecutablesDialog::on_executablesListBox_currentItemChanged(QListWidgetItem *current, QListWidgetItem*)
+{
+ if (current == NULL) {
+ resetInput();
+ return;
+ }
+
+ if (executableChanged()) {
+ QMessageBox::StandardButton res = QMessageBox::question(this, tr("Save Changes?"),
+ tr("You made changes to the current executable, do you want to save them?"),
+ QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
+ if (res == QMessageBox::Cancel) {
+ return;
+ } else if (res == QMessageBox::Yes) {
+ // this invalidates the item passed as a a parameter
+ saveExecutable();
+
+ QTimer::singleShot(50, this, SLOT(delayedRefresh()));
+ return;
+ }
+ }
+
+ m_CurrentItem = current;
+
+ const Executable &selectedExecutable = current->data(Qt::UserRole).value<Executable>();
+
+ ui->titleEdit->setText(selectedExecutable.m_Title);
+ ui->binaryEdit->setText(QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath()));
+ ui->argumentsEdit->setText(selectedExecutable.m_Arguments);
+ ui->workingDirEdit->setText(QDir::toNativeSeparators(selectedExecutable.m_WorkingDirectory));
+ ui->closeCheckBox->setChecked(selectedExecutable.m_CloseMO == DEFAULT_CLOSE);
+ if (selectedExecutable.m_CloseMO == NEVER_CLOSE) {
+ ui->closeCheckBox->setEnabled(false);
+ ui->closeCheckBox->setToolTip(tr("MO must be kept running or this application will not work correctly."));
+ } else {
+ ui->closeCheckBox->setEnabled(true);
+ ui->closeCheckBox->setToolTip(tr("If checked, MO will be closed once the specified executable is run."));
+ }
+ ui->removeButton->setEnabled(selectedExecutable.m_Custom);
+ ui->overwriteAppIDBox->setChecked(selectedExecutable.m_SteamAppID != 0);
+ if (selectedExecutable.m_SteamAppID != 0) {
+ ui->appIDOverwriteEdit->setText(selectedExecutable.m_SteamAppID);
+ } else {
+ ui->appIDOverwriteEdit->clear();
+ }
+}
+
+
+void EditExecutablesDialog::on_overwriteAppIDBox_toggled(bool checked)
+{
+ ui->appIDOverwriteEdit->setEnabled(checked);
+}
+
+void EditExecutablesDialog::on_closeButton_clicked()
+{
+ if (executableChanged()) {
+ QMessageBox::StandardButton res = QMessageBox::question(this, tr("Save Changes?"),
+ tr("You made changes to the current executable, do you want to save them?"),
+ QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
+ if (res == QMessageBox::Cancel) {
+ return;
+ } else if (res == QMessageBox::Yes) {
+ saveExecutable();
+ }
+ }
+ this->accept();
+}
+