summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--gui/browserdialog.cpp8
-rw-r--r--gui/mainwindow.cpp14
-rw-r--r--gui/mainwindow.h2
-rw-r--r--util/userutil.cpp113
-rw-r--r--util/userutil.h17
6 files changed, 152 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bbac3bdb..95a16f60 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -110,6 +110,7 @@ gui/browserdialog.cpp
util/pathutils.cpp
util/osutils.cpp
+util/userutil.cpp
java/javautils.cpp
java/annotations.cpp
@@ -139,6 +140,7 @@ data/loginresponse.h
util/apputils.h
util/pathutils.h
util/osutils.h
+util/userutil.h
multimc_pragma.h
diff --git a/gui/browserdialog.cpp b/gui/browserdialog.cpp
index 58f185ce..40c50c3f 100644
--- a/gui/browserdialog.cpp
+++ b/gui/browserdialog.cpp
@@ -34,7 +34,7 @@ void BrowserDialog::on_btnForward_clicked()
void BrowserDialog::on_webView_urlChanged(const QUrl &url)
{
Q_UNUSED(url);
- qDebug("urlChanged");
+ //qDebug("urlChanged");
ui->btnBack->setEnabled(ui->webView->history()->canGoBack());
ui->btnForward->setEnabled(ui->webView->history()->canGoForward());
}
@@ -42,7 +42,7 @@ void BrowserDialog::on_webView_urlChanged(const QUrl &url)
// Window Title Magic
void BrowserDialog::refreshWindowTitle()
{
- qDebug("refreshTitle");
+ //qDebug("refreshTitle");
if (m_pageTitleInWindowTitle)
setWindowTitle(m_windowTitleFormat.arg(ui->webView->title()));
else
@@ -63,7 +63,7 @@ void BrowserDialog::setWindowTitleFormat(QString format)
void BrowserDialog::on_webView_titleChanged(const QString &title)
{
- qDebug("titleChanged");
+ //qDebug("titleChanged");
if (m_pageTitleInWindowTitle)
setWindowTitle(m_windowTitleFormat.arg(title));
}
@@ -71,6 +71,6 @@ void BrowserDialog::on_webView_titleChanged(const QString &title)
// Public access Methods
void BrowserDialog::load(const QUrl &url)
{
- qDebug("load");
+ //qDebug("load");
ui->webView->setUrl(url);
}
diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 271a67fb..9bbc4c38 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -18,11 +18,14 @@
#include <QMenu>
#include <QMessageBox>
+#include <QInputDialog>
#include <QDesktopServices>
#include <QUrl>
#include "util/osutils.h"
+#include "util/userutil.h"
+#include "util/pathutils.h"
#include "gui/settingsdialog.h"
#include "gui/newinstancedialog.h"
@@ -159,6 +162,17 @@ void MainWindow::onLoginComplete(LoginResponse response)
arg(response.getUsername(), response.getSessionID()));
}
+// Create A Desktop Shortcut
+void MainWindow::on_actionMakeDesktopShortcut_triggered()
+{
+ QString name("Test");
+ name = QInputDialog::getText(this, tr("MultiMC Shortcut"), tr("Enter a Shortcut Name."), QLineEdit::Normal, name);
+
+ Util::createShortCut(Util::getDesktopDir(), "test", QStringList() << "-d" << "lol", name, "application-x-octet-stream");
+
+ QMessageBox::warning(this, "Stupidness", "A Dummy Shortcut was created. the current instance model doesnt allow for anything more");
+}
+
// BrowserDialog
void MainWindow::openWebPage(QUrl url)
{
diff --git a/gui/mainwindow.h b/gui/mainwindow.h
index cf6a9dbc..f2dfbc70 100644
--- a/gui/mainwindow.h
+++ b/gui/mainwindow.h
@@ -64,6 +64,8 @@ private slots:
void on_actionLaunchInstance_triggered();
+
+ void on_actionMakeDesktopShortcut_triggered();
void doLogin(const QString& errorMsg = "");
diff --git a/util/userutil.cpp b/util/userutil.cpp
new file mode 100644
index 00000000..9a7b2e12
--- /dev/null
+++ b/util/userutil.cpp
@@ -0,0 +1,113 @@
+#include "userutil.h"
+
+#include <QStandardPaths>
+#include <QFile>
+#include <QTextStream>
+
+#include "osutils.h"
+#include "pathutils.h"
+
+// Win32 crap
+#if WINDOWS
+
+#include <windows.h>
+#include <winnls.h>
+#include <shobjidl.h>
+#include <objbase.h>
+#include <objidl.h>
+#include <shlguid.h>
+#include <shlobj.h>
+
+bool called_coinit = false;
+
+HRESULT CreateLink(LPCSTR linkPath, LPCWSTR targetPath, LPCWSTR args)
+{
+ HRESULT hres;
+
+ if (!called_coinit)
+ {
+ hres = CoInitialize(NULL);
+ called_coinit = true;
+
+ if (!SUCCEEDED(hres))
+ {
+ qWarning("Failed to initialize COM. Error 0x%08X", hres);
+ return hres;
+ }
+ }
+
+
+ IShellLink* link;
+ hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&link);
+
+ if (SUCCEEDED(hres))
+ {
+ IPersistFile* persistFile;
+
+ link->SetPath(targetPath);
+ link->SetArguments(args);
+
+ hres = link->QueryInterface(IID_IPersistFile, (LPVOID*)&persistFile);
+ if (SUCCEEDED(hres))
+ {
+ WCHAR wstr[MAX_PATH];
+
+ MultiByteToWideChar(CP_ACP, 0, linkPath, -1, wstr, MAX_PATH);
+
+ hres = persistFile->Save(wstr, TRUE);
+ persistFile->Release();
+ }
+ link->Release();
+ }
+ return hres;
+}
+
+#endif
+
+QString Util::getDesktopDir()
+{
+ return QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
+}
+
+// Cross-platform Shortcut creation
+bool Util::createShortCut(QString location, QString dest, QStringList args, QString name, QString icon)
+{
+#if LINUX
+ location = PathCombine(location, name + ".desktop");
+ qDebug("location: %s", qPrintable(location));
+
+ QFile f(location);
+ f.open(QIODevice::WriteOnly | QIODevice::Text);
+ QTextStream stream(&f);
+
+ QString argstring;
+ if (!args.empty())
+ argstring = " '" + args.join("' '") + "'";
+
+ stream << "[Desktop Entry]" << "\n";
+ stream << "Type=Application" << "\n";
+ stream << "TryExec=" << dest.toLocal8Bit() << "\n";
+ stream << "Exec=" << dest.toLocal8Bit() << argstring.toLocal8Bit() << "\n";
+ stream << "Name=" << name.toLocal8Bit() << "\n";
+ stream << "Icon=" << icon.toLocal8Bit() << "\n";
+
+ stream.flush();
+ f.close();
+
+ f.setPermissions(f.permissions() | QFileDevice::ExeOwner | QFileDevice::ExeGroup | QFileDevice::ExeOther);
+
+ return true;
+#elif WINDOWS
+ QFile file(path, name + ".lnk");
+ WCHAR *file_w;
+ WCHAR *dest_w;
+ WCHAR *args_w;
+ file.fileName().toWCharArray(file_w);
+ dest.toWCharArray(dest_w);
+ args.toWCharArray(args_w);
+ return SUCCEEDED(CreateLink(file_w, dest_w, args_w));
+#else
+ qWarning("Desktop Shortcuts not supported on your platform!");
+ return false;
+#endif
+}
diff --git a/util/userutil.h b/util/userutil.h
new file mode 100644
index 00000000..11c13ed0
--- /dev/null
+++ b/util/userutil.h
@@ -0,0 +1,17 @@
+#ifndef USERUTIL_H
+#define USERUTIL_H
+
+#include <QString>
+
+namespace Util
+{
+ // Get the Directory representing the User's Desktop
+ QString getDesktopDir();
+
+ // Create a shortcut at *location*, pointing to *dest* called with the arguments *args*
+ // call it *name* and assign it the icon *icon*
+ // return true if operation succeeded
+ bool createShortCut(QString location, QString dest, QStringList args, QString name, QString iconLocation);
+}
+
+#endif // USERUTIL_H