summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Tanner <thosrtanner2@users.sourceforge.net>2015-07-18 10:44:49 +0100
committerTom Tanner <thosrtanner2@users.sourceforge.net>2015-07-18 10:44:49 +0100
commit050309749476aaa07afb00e7160abb4e5e693dcb (patch)
tree5c392338171c69b231378cfe1a2acbe917744b18 /src
parent3a39f9087099741dd6d2a5c811671e61dcd7174b (diff)
Allow user to select app icon or mo icon for generated shortcuts
Also fixes 'x' for toolbar not disappearing when it should Issue 701
Diffstat (limited to 'src')
-rw-r--r--src/editexecutablesdialog.cpp23
-rw-r--r--src/editexecutablesdialog.ui39
-rw-r--r--src/executableslist.cpp30
-rw-r--r--src/executableslist.h3
-rw-r--r--src/mainwindow.cpp18
-rw-r--r--src/organizercore.cpp4
6 files changed, 77 insertions, 40 deletions
diff --git a/src/editexecutablesdialog.cpp b/src/editexecutablesdialog.cpp
index 48d33c79..4ae0b351 100644
--- a/src/editexecutablesdialog.cpp
+++ b/src/editexecutablesdialog.cpp
@@ -84,18 +84,25 @@ 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() : "",
+ true,
+ false,
+ ui->useAppIconCheckBox->isChecked());
}
@@ -207,7 +214,8 @@ bool EditExecutablesDialog::executableChanged()
|| 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.m_UseOwnIcon != ui->useAppIconCheckBox->isChecked();
} else {
return false;
}
@@ -288,5 +296,6 @@ void EditExecutablesDialog::on_executablesListBox_clicked(const QModelIndex &cur
} else {
ui->appIDOverwriteEdit->clear();
}
+ ui->useAppIconCheckBox->setChecked(selectedExecutable.m_UseOwnIcon);
}
}
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 91bfd39e..1f5fee51 100644
--- a/src/executableslist.cpp
+++ b/src/executableslist.cpp
@@ -39,7 +39,7 @@ static QDataStream &operator<<(QDataStream &out, const Executable &obj)
<< obj.m_SteamAppID
<< obj.m_WorkingDirectory
<< obj.m_Custom
- << obj.m_Toolbar;
+ << obj.m_Toolbar << obj.m_UseOwnIcon;
return out;
}
@@ -48,7 +48,7 @@ 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_SteamAppID >> obj.m_WorkingDirectory >> obj.m_Custom >> obj.m_Toolbar >> obj.m_UseOwnIcon;
obj.m_CloseMO = static_cast<ExecutableInfo::CloseMOStyle>(closeStyleTemp);
obj.m_BinaryInfo.setFile(binaryTemp);
@@ -166,9 +166,15 @@ void ExecutablesList::position(const QString &title, 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,
- 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,
+ bool custom,
+ bool toolbar,
+ bool ownicon)
{
QFileInfo file(executableName);
auto existingExe = findExe(title);
@@ -184,11 +190,7 @@ void ExecutablesList::addExecutable(const QString &title, const QString &executa
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_UseOwnIcon = ownicon;
}
} else {
Executable newExe;
@@ -200,11 +202,8 @@ void ExecutablesList::addExecutable(const QString &title, const QString &executa
newExe.m_SteamAppID = steamAppID;
newExe.m_Custom = true;
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_UseOwnIcon = ownicon;
+ m_Executables.push_back(newExe);
}
}
@@ -235,6 +234,7 @@ void ExecutablesList::addExecutableInternal(const QString &title, const QString
newExe.m_SteamAppID = steamAppID;
newExe.m_Custom = false;
newExe.m_Toolbar = false;
+ newExe.m_UseOwnIcon = false;
m_Executables.push_back(newExe);
}
}
diff --git a/src/executableslist.h b/src/executableslist.h
index cf2fbac3..8eda38f5 100644
--- a/src/executableslist.h
+++ b/src/executableslist.h
@@ -41,6 +41,7 @@ struct Executable {
bool m_Custom;
bool m_Toolbar;
+ bool m_UseOwnIcon;
};
@@ -121,7 +122,7 @@ public:
**/
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);
+ bool custom, bool toolbar, bool ownicon);
/**
* @brief change position of an executable which is expected to exist
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 946f3a73..bd880dac 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -1626,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;
@@ -1676,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)) {
@@ -3283,16 +3293,20 @@ void MainWindow::addWindowsLink(Shortcut_Type const mapping)
} else {
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()
, QDir::toNativeSeparators(linkName).toUtf8().constData()
, description.c_str()
+ , (selectedExecutable.m_UseOwnIcon ? iconFile.c_str() : nullptr), 0
, currentDirectory.c_str()) == 0) {
ui->linkButton->menu()->actions().at(static_cast<int>(mapping))->setIcon(QIcon(":/MO/gui/remove"));
} else {
@@ -3530,7 +3544,7 @@ void MainWindow::addAsExecutable()
m_OrganizerCore.executablesList()->addExecutable(name, binaryInfo.absoluteFilePath(),
arguments, targetInfo.absolutePath(),
ExecutableInfo::CloseMOStyle::DEFAULT_STAY, QString(),
- true, false);
+ true, false, false);
refreshExecutablesList();
}
} break;
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 8b2a755d..01141dd7 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -230,6 +230,7 @@ QSettings::Status OrganizerCore::storeSettings(const QString &fileName)
settings.setValue("workingDirectory", item.m_WorkingDirectory);
settings.setValue("closeOnStart", item.m_CloseMO == ExecutableInfo::CloseMOStyle::DEFAULT_CLOSE);
settings.setValue("steamAppID", item.m_SteamAppID);
+ settings.setValue("ownicon", item.m_UseOwnIcon);
}
}
settings.endArray();
@@ -336,7 +337,8 @@ void OrganizerCore::updateExecutablesList(QSettings &settings)
closeMO,
settings.value("steamAppID", "").toString(),
settings.value("custom", true).toBool(),
- settings.value("toolbar", false).toBool());
+ settings.value("toolbar", false).toBool(),
+ settings.value("ownicon", false).toBool());
}
settings.endArray();