mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-13 05:37:42 +02:00
Add basic shortcut creation integration
Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
@ -54,6 +54,10 @@ void createInstanceShortcut(const Shortcut& shortcut, const QString& filePath)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QString appPath = QApplication::applicationFilePath();
|
QString appPath = QApplication::applicationFilePath();
|
||||||
|
auto icon = APPLICATION->icons()->icon(shortcut.iconKey.isEmpty() ? shortcut.instance->iconKey() : shortcut.iconKey);
|
||||||
|
if (icon == nullptr) {
|
||||||
|
icon = APPLICATION->icons()->icon("grass");
|
||||||
|
}
|
||||||
QString iconPath;
|
QString iconPath;
|
||||||
QStringList args;
|
QStringList args;
|
||||||
#if defined(Q_OS_MACOS)
|
#if defined(Q_OS_MACOS)
|
||||||
@ -63,11 +67,6 @@ void createInstanceShortcut(const Shortcut& shortcut, const QString& filePath)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pIcon = APPLICATION->icons()->icon(shortcut.instance->iconKey());
|
|
||||||
if (pIcon == nullptr) {
|
|
||||||
pIcon = APPLICATION->icons()->icon("grass");
|
|
||||||
}
|
|
||||||
|
|
||||||
iconPath = FS::PathCombine(shortcut.instance->instanceRoot(), "Icon.icns");
|
iconPath = FS::PathCombine(shortcut.instance->instanceRoot(), "Icon.icns");
|
||||||
|
|
||||||
QFile iconFile(iconPath);
|
QFile iconFile(iconPath);
|
||||||
@ -76,9 +75,8 @@ void createInstanceShortcut(const Shortcut& shortcut, const QString& filePath)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon icon = pIcon->icon();
|
QIcon iconObj = icon->icon();
|
||||||
|
bool success = iconObj.pixmap(1024, 1024).save(iconPath, "ICNS");
|
||||||
bool success = icon.pixmap(1024, 1024).save(iconPath, "ICNS");
|
|
||||||
iconFile.close();
|
iconFile.close();
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
@ -99,11 +97,6 @@ void createInstanceShortcut(const Shortcut& shortcut, const QString& filePath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto icon = APPLICATION->icons()->icon(shortcut.instance->iconKey());
|
|
||||||
if (icon == nullptr) {
|
|
||||||
icon = APPLICATION->icons()->icon("grass");
|
|
||||||
}
|
|
||||||
|
|
||||||
iconPath = FS::PathCombine(shortcut.instance->instanceRoot(), "icon.png");
|
iconPath = FS::PathCombine(shortcut.instance->instanceRoot(), "icon.png");
|
||||||
|
|
||||||
QFile iconFile(iconPath);
|
QFile iconFile(iconPath);
|
||||||
@ -126,11 +119,6 @@ void createInstanceShortcut(const Shortcut& shortcut, const QString& filePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(Q_OS_WIN)
|
#elif defined(Q_OS_WIN)
|
||||||
auto icon = APPLICATION->icons()->icon(shortcut.instance->iconKey());
|
|
||||||
if (icon == nullptr) {
|
|
||||||
icon = APPLICATION->icons()->icon("grass");
|
|
||||||
}
|
|
||||||
|
|
||||||
iconPath = FS::PathCombine(shortcut.instance->instanceRoot(), "icon.ico");
|
iconPath = FS::PathCombine(shortcut.instance->instanceRoot(), "icon.ico");
|
||||||
|
|
||||||
// part of fix for weird bug involving the window icon being replaced
|
// part of fix for weird bug involving the window icon being replaced
|
||||||
|
@ -48,6 +48,7 @@ struct Shortcut {
|
|||||||
QString targetString;
|
QString targetString;
|
||||||
QWidget* parent = nullptr;
|
QWidget* parent = nullptr;
|
||||||
QStringList extraArgs = {};
|
QStringList extraArgs = {};
|
||||||
|
QString iconKey = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Create an instance shortcut on the specified file path
|
/// Create an instance shortcut on the specified file path
|
||||||
|
@ -63,8 +63,22 @@ CreateShortcutDialog::CreateShortcutDialog(InstancePtr instance, QWidget* parent
|
|||||||
|
|
||||||
m_QuickJoinSupported = instance->traits().contains("feature:is_quick_play_singleplayer");
|
m_QuickJoinSupported = instance->traits().contains("feature:is_quick_play_singleplayer");
|
||||||
if (!m_QuickJoinSupported) {
|
if (!m_QuickJoinSupported) {
|
||||||
// TODO: Remove radio box and add a single server address textbox instead
|
ui->worldTarget->hide();
|
||||||
|
ui->worldSelectionBox->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Populate save targets
|
||||||
|
if (!DesktopServices::isFlatpak()) {
|
||||||
|
QString desktopDir = FS::getDesktopDir();
|
||||||
|
QString applicationDir = FS::getApplicationsDir();
|
||||||
|
|
||||||
|
if (!desktopDir.isEmpty())
|
||||||
|
ui->saveTargetSelectionBox->addItem("Desktop", QVariant::fromValue(SaveTarget::Desktop));
|
||||||
|
|
||||||
|
if (!applicationDir.isEmpty())
|
||||||
|
ui->saveTargetSelectionBox->addItem("Applications", QVariant::fromValue(SaveTarget::Applications));
|
||||||
|
}
|
||||||
|
ui->saveTargetSelectionBox->addItem("Other...", QVariant::fromValue(SaveTarget::Other));
|
||||||
}
|
}
|
||||||
|
|
||||||
CreateShortcutDialog::~CreateShortcutDialog()
|
CreateShortcutDialog::~CreateShortcutDialog()
|
||||||
@ -83,15 +97,17 @@ void CreateShortcutDialog::on_iconButton_clicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateShortcutDialog::on_saveTargetSelectionBox_currentIndexChanged(int index) {}
|
void CreateShortcutDialog::on_overrideAccountCheckbox_stateChanged(int state)
|
||||||
|
{
|
||||||
void CreateShortcutDialog::on_instNameTextBox_textChanged(const QString& arg1) {}
|
ui->accountOptionsGroup->setEnabled(state == Qt::Checked);
|
||||||
|
}
|
||||||
void CreateShortcutDialog::on_overrideAccountCheckbox_stateChanged(int state) {}
|
|
||||||
|
|
||||||
void CreateShortcutDialog::on_accountSelectionBox_currentIndexChanged(int index) {}
|
void CreateShortcutDialog::on_accountSelectionBox_currentIndexChanged(int index) {}
|
||||||
|
|
||||||
void CreateShortcutDialog::on_targetCheckbox_stateChanged(int state) {}
|
void CreateShortcutDialog::on_targetCheckbox_stateChanged(int state)
|
||||||
|
{
|
||||||
|
ui->targetOptionsGroup->setEnabled(state == Qt::Checked);
|
||||||
|
}
|
||||||
|
|
||||||
void CreateShortcutDialog::on_worldSelectionBox_currentIndexChanged(int index) {}
|
void CreateShortcutDialog::on_worldSelectionBox_currentIndexChanged(int index) {}
|
||||||
|
|
||||||
@ -113,5 +129,13 @@ void CreateShortcutDialog::createShortcut()
|
|||||||
extraArgs = { "--server", /* server address */ };
|
extraArgs = { "--server", /* server address */ };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ShortcutUtils::createInstanceShortcutOnDesktop({ m_instance.get(), m_instance->name(), targetString, this, extraArgs });
|
|
||||||
|
auto target = ui->saveTargetSelectionBox->currentData().value<SaveTarget>();
|
||||||
|
auto name = ui->instNameTextBox->text();
|
||||||
|
if (target == SaveTarget::Desktop)
|
||||||
|
ShortcutUtils::createInstanceShortcutOnDesktop({ m_instance.get(), name, targetString, this, extraArgs, InstIconKey });
|
||||||
|
else if (target == SaveTarget::Applications)
|
||||||
|
ShortcutUtils::createInstanceShortcutInApplications({ m_instance.get(), name, targetString, this, extraArgs, InstIconKey });
|
||||||
|
else
|
||||||
|
ShortcutUtils::createInstanceShortcutInOther({ m_instance.get(), m_instance->name(), targetString, this, extraArgs, InstIconKey });
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,6 @@ class CreateShortcutDialog : public QDialog {
|
|||||||
private slots:
|
private slots:
|
||||||
// Icon, target and name
|
// Icon, target and name
|
||||||
void on_iconButton_clicked();
|
void on_iconButton_clicked();
|
||||||
void on_saveTargetSelectionBox_currentIndexChanged(int index);
|
|
||||||
void on_instNameTextBox_textChanged(const QString& arg1);
|
|
||||||
|
|
||||||
// Override account
|
// Override account
|
||||||
void on_overrideAccountCheckbox_stateChanged(int state);
|
void on_overrideAccountCheckbox_stateChanged(int state);
|
||||||
@ -57,4 +55,5 @@ class CreateShortcutDialog : public QDialog {
|
|||||||
bool m_QuickJoinSupported = false;
|
bool m_QuickJoinSupported = false;
|
||||||
|
|
||||||
// Index representations
|
// Index representations
|
||||||
|
enum class SaveTarget { Desktop, Applications, Other };
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user