From 050309749476aaa07afb00e7160abb4e5e693dcb Mon Sep 17 00:00:00 2001 From: Tom Tanner Date: Sat, 18 Jul 2015 10:44:49 +0100 Subject: Allow user to select app icon or mo icon for generated shortcuts Also fixes 'x' for toolbar not disappearing when it should Issue 701 --- src/mainwindow.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/mainwindow.cpp') 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(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; -- cgit v1.3.1