implement desktop shortcut creation. windows code not tested.
This commit is contained in:
parent
c755195b97
commit
369b1c55c9
@ -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
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -64,6 +64,8 @@ private slots:
|
||||
|
||||
void on_actionLaunchInstance_triggered();
|
||||
|
||||
|
||||
void on_actionMakeDesktopShortcut_triggered();
|
||||
|
||||
void doLogin(const QString& errorMsg = "");
|
||||
|
||||
|
113
util/userutil.cpp
Normal file
113
util/userutil.cpp
Normal file
@ -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
|
||||
}
|
17
util/userutil.h
Normal file
17
util/userutil.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user