summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/editexecutablesdialog.cpp39
-rw-r--r--src/editexecutablesdialog.ui39
-rw-r--r--src/executableslist.cpp95
-rw-r--r--src/executableslist.h61
-rw-r--r--src/installationmanager.cpp5
-rw-r--r--src/main.cpp18
-rw-r--r--src/mainwindow.cpp156
-rw-r--r--src/mainwindow.h14
-rw-r--r--src/organizercore.cpp18
9 files changed, 236 insertions, 209 deletions
diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp
index e84e1112..97154789 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,10 +60,7 @@ 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));
+ newItem->setTextColor(current->m_Type == Executable::Type::Custom ? QColor(Qt::black) : QColor(Qt::darkGray));
ui->executablesListBox->addItem(newItem);
}
@@ -87,18 +84,26 @@ void EditExecutablesDialog::resetInput()
ui->appIDOverwriteEdit->clear();
ui->overwriteAppIDBox->setChecked(false);
ui->closeCheckBox->setChecked(false);
+ ui->useAppIconCheckBox->setChecked(false);
m_CurrentItem = nullptr;
}
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) ? ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE
- : ExecutableInfo::CloseMOStyle::DEFAULT_STAY,
- ui->overwriteAppIDBox->isChecked() ? ui->appIDOverwriteEdit->text() : "",
- true, false);
+ m_ExecutablesList.addExecutable(ui->titleEdit->text(),
+ QDir::fromNativeSeparators(ui->binaryEdit->text()),
+ ui->argumentsEdit->text(),
+ QDir::fromNativeSeparators(ui->workingDirEdit->text()),
+ (ui->closeCheckBox->checkState() == Qt::Checked) ?
+ ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE
+ : ExecutableInfo::CloseMOStyle::DEFAULT_STAY,
+ ui->overwriteAppIDBox->isChecked() ?
+ ui->appIDOverwriteEdit->text() : "",
+ Executable::Type::Custom,
+ Executable::Toolbar::Disabled,
+ ui->useAppIconCheckBox->isChecked() ?
+ Executable::Icon::Application : Executable::Icon::MO);
}
@@ -170,8 +175,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,13 +209,14 @@ 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()
|| selectedExecutable.m_WorkingDirectory != QDir::fromNativeSeparators(ui->workingDirEdit->text())
|| selectedExecutable.m_BinaryInfo.absoluteFilePath() != QDir::fromNativeSeparators(ui->binaryEdit->text())
- || (selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE) != ui->closeCheckBox->isChecked();
+ || (selectedExecutable.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE) != ui->closeCheckBox->isChecked()
+ || selectedExecutable.usesOwnIcon() != ui->useAppIconCheckBox->isChecked();
} else {
return false;
}
@@ -272,7 +276,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()));
@@ -286,12 +290,13 @@ void EditExecutablesDialog::on_executablesListBox_clicked(const QModelIndex &cur
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->removeButton->setEnabled(selectedExecutable.isCustom());
ui->overwriteAppIDBox->setChecked(!selectedExecutable.m_SteamAppID.isEmpty());
if (!selectedExecutable.m_SteamAppID.isEmpty()) {
ui->appIDOverwriteEdit->setText(selectedExecutable.m_SteamAppID);
} else {
ui->appIDOverwriteEdit->clear();
}
+ ui->useAppIconCheckBox->setChecked(selectedExecutable.usesOwnIcon());
}
}
diff --git a/src/editexecutablesdialog.ui b/src/editexecutablesdialog.ui
index 5a1137c9..abb6fe68 100644
--- a/src/editexecutablesdialog.ui
+++ b/src/editexecutablesdialog.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>384</width>
- <height>362</height>
+ <height>446</height>
</rect>
</property>
<property name="windowTitle">
@@ -165,21 +165,28 @@ Right now the only case I know of where this needs to be overwritten is for the
</layout>
</item>
<item>
+ <widget class="QCheckBox" name="closeCheckBox">
+ <property name="toolTip">
+ <string>If checked, MO will be closed once the specified executable is run.</string>
+ </property>
+ <property name="whatsThis">
+ <string>If checked, MO will be closed once the specified executable is run.</string>
+ </property>
+ <property name="text">
+ <string>Close MO when started</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="useAppIconCheckBox">
+ <property name="text">
+ <string>Use Application's Icon for shortcuts</string>
+ </property>
+ </widget>
+ </item>
+ <item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
- <widget class="QCheckBox" name="closeCheckBox">
- <property name="toolTip">
- <string>If checked, MO will be closed once the specified executable is run.</string>
- </property>
- <property name="whatsThis">
- <string>If checked, MO will be closed once the specified executable is run.</string>
- </property>
- <property name="text">
- <string>Close MO when started</string>
- </property>
- </widget>
- </item>
- <item>
<widget class="QPushButton" name="addButton">
<property name="toolTip">
<string>Add an executable</string>
@@ -240,6 +247,10 @@ Right now the only case I know of where this needs to be overwritten is for the
</layout>
</item>
</layout>
+ <zorder>executablesListBox</zorder>
+ <zorder>closeButton</zorder>
+ <zorder>closeCheckBox</zorder>
+ <zorder>useAppIconCheckBox</zorder>
</widget>
<resources/>
<connections/>
diff --git a/src/executableslist.cpp b/src/executableslist.cpp
index badf0813..ba2b5616 100644
--- a/src/executableslist.cpp
+++ b/src/executableslist.cpp
@@ -30,39 +30,6 @@ using namespace MOBase;
using namespace MOShared;
-static QDataStream &operator<<(QDataStream &out, const Executable &obj)
-{
- out << obj.m_Title
- << obj.m_BinaryInfo.absoluteFilePath()
- << obj.m_Arguments
- << static_cast<std::underlying_type<ExecutableInfo::CloseMOStyle>::type>(obj.m_CloseMO)
- << obj.m_SteamAppID
- << obj.m_WorkingDirectory
- << obj.m_Custom
- << obj.m_Toolbar;
- return out;
-}
-
-static QDataStream &operator>>(QDataStream &in, Executable &obj)
-{
- QString binaryTemp;
- int closeStyleTemp;
- in >> obj.m_Title >> binaryTemp >> obj.m_Arguments >> closeStyleTemp
- >> obj.m_SteamAppID >> obj.m_WorkingDirectory >> obj.m_Custom >> obj.m_Toolbar;
-
- obj.m_CloseMO = static_cast<ExecutableInfo::CloseMOStyle>(closeStyleTemp);
- obj.m_BinaryInfo.setFile(binaryTemp);
- return in;
-}
-
-
-void registerExecutable()
-{
- qRegisterMetaType<Executable>("Executable");
- qRegisterMetaTypeStreamOperators<Executable>("Executable");
-}
-
-
ExecutablesList::ExecutablesList()
{
}
@@ -102,23 +69,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());
}
@@ -162,41 +129,31 @@ void ExecutablesList::addExecutable(const Executable &executable)
}
-void ExecutablesList::position(const QString &title, bool toolbar, int pos)
-{
- auto existingExe = findExe(title);
- if (existingExe != m_Executables.end()) {
- Executable temp = *existingExe;
- temp.m_Toolbar = toolbar;
- m_Executables.erase(existingExe);
- m_Executables.insert(m_Executables.begin() + pos, temp);
- }
-}
-
-
-void ExecutablesList::addExecutable(const QString &title, const QString &executableName, const QString &arguments,
- const QString &workingDirectory, ExecutableInfo::CloseMOStyle closeMO, const QString &steamAppID,
- bool custom, bool toolbar, int pos)
+void ExecutablesList::addExecutable(const QString &title,
+ const QString &executableName,
+ const QString &arguments,
+ const QString &workingDirectory,
+ ExecutableInfo::CloseMOStyle closeMO,
+ const QString &steamAppID,
+ Executable::Type custom,
+ Executable::Toolbar toolbar,
+ Executable::Icon ownicon)
{
QFileInfo file(executableName);
auto existingExe = findExe(title);
if (existingExe != m_Executables.end()) {
existingExe->m_Title = title;
- existingExe->m_Custom = custom;
+ existingExe->m_Type = custom;
existingExe->m_CloseMO = closeMO;
existingExe->m_Toolbar = toolbar;
- if (custom) {
+ if (custom == Executable::Type::Custom) {
// for pre-configured executables don't overwrite settings we didn't store
existingExe->m_BinaryInfo = file;
existingExe->m_Arguments = arguments;
existingExe->m_WorkingDirectory = workingDirectory;
existingExe->m_SteamAppID = steamAppID;
- }
- if (pos >= 0) {
- Executable temp = *existingExe;
- m_Executables.erase(existingExe);
- m_Executables.insert(m_Executables.begin() + pos, temp);
+ existingExe->m_Icon = ownicon;
}
} else {
Executable newExe;
@@ -206,13 +163,10 @@ void ExecutablesList::addExecutable(const QString &title, const QString &executa
newExe.m_Arguments = arguments;
newExe.m_WorkingDirectory = workingDirectory;
newExe.m_SteamAppID = steamAppID;
- newExe.m_Custom = true;
+ newExe.m_Type = Executable::Type::Custom;
newExe.m_Toolbar = toolbar;
- if ((pos < 0) || (pos >= static_cast<int>(m_Executables.size()))) {
- m_Executables.push_back(newExe);
- } else {
- m_Executables.insert(m_Executables.begin() + pos, newExe);
- }
+ newExe.m_Icon = ownicon;
+ m_Executables.push_back(newExe);
}
}
@@ -220,7 +174,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->isCustom() && iter->m_Title == title) {
m_Executables.erase(iter);
break;
}
@@ -241,8 +195,9 @@ void ExecutablesList::addExecutableInternal(const QString &title, const QString
newExe.m_Arguments = arguments;
newExe.m_WorkingDirectory = workingDirectory;
newExe.m_SteamAppID = steamAppID;
- newExe.m_Custom = false;
- newExe.m_Toolbar = false;
+ newExe.m_Type = Executable::Type::Game;
+ newExe.m_Toolbar = Executable::Toolbar::Disabled;
+ newExe.m_Icon = Executable::Icon::MO;
m_Executables.push_back(newExe);
}
}
diff --git a/src/executableslist.h b/src/executableslist.h
index 888dbfe1..4e1ad644 100644
--- a/src/executableslist.h
+++ b/src/executableslist.h
@@ -39,13 +39,33 @@ struct Executable {
QString m_SteamAppID;
QString m_WorkingDirectory;
- bool m_Custom;
- bool m_Toolbar;
-};
-Q_DECLARE_METATYPE(Executable)
+ enum class Type {
+ Game,
+ Custom
+ };
+
+ enum class Toolbar {
+ Disabled,
+ Enabled
+ };
+
+ enum class Icon {
+ MO,
+ Application
+ };
+
+ Type m_Type;
+ Toolbar m_Toolbar;
+ Icon m_Icon;
+ bool isCustom() const { return m_Type == Type::Custom; }
-void registerExecutable();
+ bool shownOnToolbar() const { return m_Toolbar == Toolbar::Enabled; }
+
+ void showOnToolbar(bool state) { m_Toolbar = state ? Toolbar::Enabled : Toolbar::Disabled; }
+
+ bool usesOwnIcon() const { return m_Icon == Icon::Application; }
+};
/*!
@@ -83,7 +103,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 +112,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
@@ -123,17 +143,15 @@ public:
* @param arguments arguments to pass to the executable
* @param closeMO if true, MO will be closed when the binary is started
**/
- void addExecutable(const QString &title, const QString &executableName, const QString &arguments,
- const QString &workingDirectory, MOBase::ExecutableInfo::CloseMOStyle closeMO, const QString &steamAppID,
- bool custom, bool toolbar, int pos = -1);
-
- /**
- * @brief change position of an executable which is expected to exist
- * @param title title of the executable
- * @param toolbar enable/disable placement on the toolbar
- * @param pos new position for the executable
- */
- void position(const QString &title, bool toolbar, int pos);
+ void addExecutable(const QString &title,
+ const QString &executableName,
+ const QString &arguments,
+ const QString &workingDirectory,
+ MOBase::ExecutableInfo::CloseMOStyle closeMO,
+ const QString &steamAppID,
+ Executable::Type custom,
+ Executable::Toolbar toolbar,
+ Executable::Icon ownicon);
/**
* @brief remove the executable with the specified file name. This needs to be an absolute file path
@@ -159,6 +177,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/installationmanager.cpp b/src/installationmanager.cpp
index 674c4ce7..c036a373 100644
--- a/src/installationmanager.cpp
+++ b/src/installationmanager.cpp
@@ -124,6 +124,11 @@ void InstallationManager::mapToArchive(const DirectoryTree::Node *node, std::wst
}
for (DirectoryTree::const_leaf_iterator iter = node->leafsBegin(); iter != node->leafsEnd(); ++iter) {
+ if (! data[iter->getIndex()]->getSkip()) {
+ std::wstring newp((path + iter->getName().toStdWString()));
+ std::wstring oldp(data[iter->getIndex()]->getOutputFileName());
+ qDebug() << "outputting to " << QString::fromStdWString(newp) << " but already outputting to " << QString::fromStdWString(oldp);
+ }
data[iter->getIndex()]->setSkip(false);
std::wstring temp = path + iter->getName().toStdWString();
data[iter->getIndex()]->setOutputFileName(temp.c_str());
diff --git a/src/main.cpp b/src/main.cpp
index 295fb75a..ae3bbb4c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -170,13 +170,14 @@ void cleanupDir()
"proxy.dll"
};
- qDebug("removing obsolete files");
-
for (const QString &fileName : fileNames) {
QString fullPath = qApp->applicationDirPath() + "/" + fileName;
- if (QFile::exists(fullPath)
- && !shellDelete(QStringList(fullPath), true)) {
- qDebug("failed to remove obsolete %s", qPrintable(fullPath));
+ if (QFile::exists(fullPath)) {
+ if (shellDelete(QStringList(fullPath), true)) {
+ qDebug("removed obsolete file %s", qPrintable(fullPath));
+ } else {
+ qDebug("failed to remove obsolete %s", qPrintable(fullPath));
+ }
}
}
}
@@ -248,11 +249,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 +410,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 869b7d70..2e7797d2 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -486,13 +486,10 @@ void MainWindow::updateToolBar()
std::vector<Executable>::iterator begin, end;
m_OrganizerCore.executablesList()->getExecutables(begin, end);
for (auto iter = begin; iter != end; ++iter) {
- if (iter->m_Toolbar) {
+ if (iter->shownOnToolbar()) {
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?");
@@ -956,7 +953,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,
@@ -1199,10 +1196,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);
}
@@ -1617,9 +1612,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,
@@ -1633,6 +1626,7 @@ void MainWindow::on_startButton_clicked()
static HRESULT CreateShortcut(LPCWSTR targetFileName, LPCWSTR arguments,
LPCSTR linkFileName, LPCWSTR description,
+ LPCTSTR iconFileName, int iconNumber,
LPCWSTR currentDirectory)
{
HRESULT result = E_INVALIDARG;
@@ -1683,6 +1677,15 @@ static HRESULT CreateShortcut(LPCWSTR targetFileName, LPCWSTR arguments,
}
}
+ if (iconFileName != nullptr) {
+ result = shellLink->SetIconLocation(iconFileName, iconNumber);
+ if (!SUCCEEDED(result)) {
+ qCritical("failed to load program icon: %ls %d", iconFileName, iconNumber);
+ shellLink->Release();
+ return result;
+ }
+ }
+
IPersistFile *persistFile;
result = shellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&persistFile);
if (SUCCEEDED(result)) {
@@ -1727,11 +1730,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);
@@ -1746,7 +1748,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);
}
@@ -3254,76 +3255,74 @@ 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);
- exe.m_Toolbar = !exe.m_Toolbar;
- ui->linkButton->menu()->actions().at(2)->setIcon(exe.m_Toolbar ? QIcon(":/MO/gui/remove") : QIcon(":/MO/gui/link"));
+ Executable &exe(getSelectedExecutable());
+ exe.showOnToolbar(!exe.shownOnToolbar());
+ ui->linkButton->menu()->actions().at(static_cast<int>(Shortcut_Type::Toolbar))->setIcon(exe.shownOnToolbar() ? 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
+ QString executable = QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath());
+
std::wstring targetFile = ToWString(exeInfo.absoluteFilePath());
- std::wstring parameter = ToWString(QString("\"%1\" %2").arg(QDir::toNativeSeparators(selectedExecutable.m_BinaryInfo.absoluteFilePath()))
+ std::wstring parameter = ToWString(QString("\"%1\" %2").arg(executable)
.arg(selectedExecutable.m_Arguments));
std::wstring description = ToWString(selectedExecutable.m_BinaryInfo.fileName());
+ std::wstring iconFile = ToWString(executable);
std::wstring currentDirectory = ToWString(QDir::toNativeSeparators(exeInfo.absolutePath()));
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"));
+ , (selectedExecutable.usesOwnIcon() ? iconFile.c_str() : nullptr), 0
+ , 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()
@@ -3542,10 +3541,15 @@ void MainWindow::addAsExecutable()
tr("Please enter a name for the executable"), QLineEdit::Normal,
targetInfo.baseName());
if (!name.isEmpty()) {
- m_OrganizerCore.executablesList()->addExecutable(name, binaryInfo.absoluteFilePath(),
- arguments, targetInfo.absolutePath(),
- ExecutableInfo::CloseMOStyle::DEFAULT_STAY, QString(),
- true, false);
+ m_OrganizerCore.executablesList()->addExecutable(name,
+ binaryInfo.absoluteFilePath(),
+ arguments,
+ targetInfo.absolutePath(),
+ ExecutableInfo::CloseMOStyle::DEFAULT_STAY,
+ QString(),
+ Executable::Type::Custom,
+ Executable::Toolbar::Disabled,
+ Executable::Icon::MO);
refreshExecutablesList();
}
} break;
@@ -4122,7 +4126,7 @@ void MainWindow::removeFromToolbar()
{
try {
Executable &exe = m_OrganizerCore.executablesList()->find(m_ContextAction->text());
- exe.m_Toolbar = false;
+ exe.showOnToolbar(false);
} catch (const std::runtime_error&) {
qDebug("executable doesn't exist any more");
}
@@ -4219,19 +4223,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.shownOnToolbar() ? 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);
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 876fc28a..852abba3 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -222,9 +222,10 @@ QSettings::Status OrganizerCore::storeSettings(const QString &fileName)
const Executable &item = *current;
settings.setArrayIndex(count++);
settings.setValue("title", item.m_Title);
- settings.setValue("custom", item.m_Custom);
- settings.setValue("toolbar", item.m_Toolbar);
- if (item.m_Custom) {
+ settings.setValue("custom", item.isCustom());
+ settings.setValue("toolbar", item.shownOnToolbar());
+ settings.setValue("ownicon", item.usesOwnIcon());
+ if (item.isCustom()) {
settings.setValue("binary", item.m_BinaryInfo.absoluteFilePath());
settings.setValue("arguments", item.m_Arguments);
settings.setValue("workingDirectory", item.m_WorkingDirectory);
@@ -329,14 +330,21 @@ void OrganizerCore::updateExecutablesList(QSettings &settings)
ExecutableInfo::CloseMOStyle closeMO =
settings.value("closeOnStart").toBool() ? ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE
: ExecutableInfo::CloseMOStyle::DEFAULT_STAY;
+ Executable::Type type =
+ settings.value("custom", true).toBool() ? Executable::Type::Custom : Executable::Type::Game;
+ Executable::Toolbar toolbar =
+ settings.value("toolbar", false).toBool() ? Executable::Toolbar::Enabled : Executable::Toolbar::Disabled;
+ Executable::Icon icon =
+ settings.value("ownicon", false).toBool() ? Executable::Icon::Application : Executable::Icon::MO;
m_ExecutablesList.addExecutable(settings.value("title").toString(),
settings.value("binary").toString(),
settings.value("arguments").toString(),
settings.value("workingDirectory", "").toString(),
closeMO,
settings.value("steamAppID", "").toString(),
- settings.value("custom", true).toBool(),
- settings.value("toolbar", false).toBool());
+ type,
+ toolbar,
+ icon);
}
settings.endArray();