aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/MainWindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'launcher/ui/MainWindow.cpp')
-rw-r--r--launcher/ui/MainWindow.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp
index 85b00b67..419bb9bd 100644
--- a/launcher/ui/MainWindow.cpp
+++ b/launcher/ui/MainWindow.cpp
@@ -237,6 +237,7 @@ public:
TranslatedAction actionLaunchInstanceOffline;
TranslatedAction actionLaunchInstanceDemo;
TranslatedAction actionExportInstance;
+ TranslatedAction actionCreateInstanceShortcut;
QVector<TranslatedAction *> all_actions;
LabeledToolButton *renameButton = nullptr;
@@ -597,6 +598,7 @@ public:
actionExportInstance->setEnabled(enabled);
actionDeleteInstance->setEnabled(enabled);
actionCopyInstance->setEnabled(enabled);
+ actionCreateInstanceShortcut->setEnabled(enabled);
}
void createStatusBar(QMainWindow *MainWindow)
@@ -735,6 +737,14 @@ public:
actionCopyInstance->setIcon(APPLICATION->getThemedIcon("copy"));
all_actions.append(&actionCopyInstance);
+ actionCreateInstanceShortcut = TranslatedAction(MainWindow);
+ actionCreateInstanceShortcut->setObjectName(QStringLiteral("actionCreateInstanceShortcut"));
+ actionCreateInstanceShortcut.setTextId(QT_TRANSLATE_NOOP("MainWindow", "Create shortcut"));
+ actionCreateInstanceShortcut.setTooltipId(QT_TRANSLATE_NOOP("MainWindow", "Creates a shortcut on your desktop to launch the selected instance."));
+ actionCreateInstanceShortcut->setShortcut(QKeySequence(tr("Ctrl+D")));
+ //actionCreateInstanceShortcut->setIcon(APPLICATION->getThemedIcon("copy")); // TODO
+ all_actions.append(&actionCreateInstanceShortcut);
+
setInstanceActionsEnabled(false);
}
@@ -783,6 +793,8 @@ public:
}
}
+ instanceToolBar->addAction(actionCreateInstanceShortcut);
+
all_toolbars.append(&instanceToolBar);
MainWindow->addToolBar(Qt::RightToolBarArea, instanceToolBar);
}
@@ -2075,6 +2087,80 @@ void MainWindow::on_actionKillInstance_triggered()
}
}
+#ifdef Q_OS_WIN
+#define WIN32_LEAN_AND_MEAN
+#include "windows.h"
+#include "winnls.h"
+#include "shobjidl.h"
+#include "objbase.h"
+#include "objidl.h"
+#include "shlguid.h"
+#endif
+
+void MainWindow::on_actionCreateInstanceShortcut_triggered()
+{
+ if (m_selectedInstance)
+ {
+ auto desktopDir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
+ if (desktopDir.isEmpty()) {
+ // TODO come up with an alternative solution (open "save file" dialog)
+ QMessageBox::critical(this, tr("Create instance shortcut"), tr("Couldn't find desktop!"));
+ return;
+ }
+
+#if defined(Q_OS_WIN)
+ // Windows
+ WCHAR wsz[MAX_PATH];
+
+ // ...yes, you need to initialize the entire COM stack to make a shortcut in Windows.
+ // I hate it.
+ CoInitialize(nullptr);
+
+ HRESULT hres;
+ IShellLink* psl;
+
+ hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
+ if (SUCCEEDED(hres))
+ {
+ IPersistFile* ppf;
+
+ QApplication::applicationFilePath().left(MAX_PATH - 1).toWCharArray(wsz);
+ psl->SetPath(wsz);
+
+ wmemset(wsz, 0, MAX_PATH);
+ QStringLiteral("--launch %1").arg(m_selectedInstance->id()).left(MAX_PATH - 1).toWCharArray(wsz);
+ psl->SetArguments(wsz);
+
+ // TODO set icon
+
+ hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
+
+ if (SUCCEEDED(hres))
+ {
+ wmemset(wsz, 0, MAX_PATH);
+
+ desktopDir
+ .append('/')
+ .append(QStringLiteral("%1.lnk").arg(m_selectedInstance->name()))
+ .left(MAX_PATH - 1).toWCharArray(wsz);
+
+ hres = ppf->Save(wsz, TRUE);
+ ppf->Release();
+ }
+ psl->Release();
+ }
+
+ CoUninitialize();
+#elif defined(Q_OS_LINUX)
+ // Linux
+#elif defined(Q_OS_MACOS)
+ // macOSX
+ // TODO actually write this path
+ QMessageBox::critical(this, tr("Create instance shortcut"), tr("Not supported on macOSX yet!"));
+#endif
+ }
+}
+
void MainWindow::taskEnd()
{
QObject *sender = QObject::sender();