mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-22 23:26:15 +00:00
Changed: Create all profiles shortcuts at once, see #279
This commit is contained in:
parent
3f398463c7
commit
a4fdeac558
5 changed files with 86 additions and 84 deletions
|
@ -60,24 +60,84 @@ QString CProfile::getClientFullPath() const
|
||||||
return s.getClientFullPath();
|
return s.getClientFullPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CProfile::getClientDesktopLinkFullPath() const
|
QString CProfile::getClientDesktopShortcutFullPath() const
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
return CConfigFile::getInstance()->getDesktopDirectory() + "/" + name + ".lnk";
|
return CConfigFile::getInstance()->getDesktopDirectory() + "/" + name + ".lnk";
|
||||||
#else
|
#elif defined(Q_OS_MAC)
|
||||||
return "";
|
return "";
|
||||||
|
#else
|
||||||
|
return CConfigFile::getInstance()->getDesktopDirectory() + "/" + name + ".desktop";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CProfile::getClientMenuLinkFullPath() const
|
QString CProfile::getClientMenuShortcutFullPath() const
|
||||||
{
|
{
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
return CConfigFile::getInstance()->getMenuDirectory() + "/" + name + ".lnk";
|
return CConfigFile::getInstance()->getMenuDirectory() + "/" + name + ".lnk";
|
||||||
#else
|
#elif defined(Q_OS_MAC)
|
||||||
return "";
|
return "";
|
||||||
|
#else
|
||||||
|
return CConfigFile::getInstance()->getMenuDirectory() + "/" + name + ".desktop";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CProfile::createShortcuts() const
|
||||||
|
{
|
||||||
|
const CServer &s = CConfigFile::getInstance()->getServer(server);
|
||||||
|
|
||||||
|
QString executable = getClientFullPath();
|
||||||
|
QString workingDir = s.getDirectory();
|
||||||
|
|
||||||
|
QString arguments = QString("--profile %1").arg(id);
|
||||||
|
|
||||||
|
// append custom arguments
|
||||||
|
if (!arguments.isEmpty()) arguments += QString(" %1").arg(arguments);
|
||||||
|
|
||||||
|
QString icon;
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
icon = executable;
|
||||||
|
#else
|
||||||
|
// TODO: Linux icon
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (desktopShortcut)
|
||||||
|
{
|
||||||
|
QString shortcut = getClientDesktopShortcutFullPath();
|
||||||
|
|
||||||
|
// create desktop shortcut
|
||||||
|
createLink(shortcut, name, executable, arguments, icon, workingDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menuShortcut)
|
||||||
|
{
|
||||||
|
QString shortcut = getClientMenuShortcutFullPath();
|
||||||
|
|
||||||
|
// create menu shortcut
|
||||||
|
createLink(shortcut, name, executable, arguments, icon, workingDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CProfile::deleteShortcuts() const
|
||||||
|
{
|
||||||
|
// delete desktop shortcut
|
||||||
|
QString link = getClientDesktopShortcutFullPath();
|
||||||
|
|
||||||
|
if (QFile::exists(link)) QFile::remove(link);
|
||||||
|
|
||||||
|
// delete menu shortcut
|
||||||
|
link = getClientMenuShortcutFullPath();
|
||||||
|
|
||||||
|
if (QFile::exists(link)) QFile::remove(link);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CProfile::updateShortcuts() const
|
||||||
|
{
|
||||||
|
deleteShortcuts();
|
||||||
|
createShortcuts();
|
||||||
|
}
|
||||||
|
|
||||||
CConfigFile *CConfigFile::s_instance = NULL;
|
CConfigFile *CConfigFile::s_instance = NULL;
|
||||||
|
|
||||||
CConfigFile::CConfigFile(QObject *parent):QObject(parent), m_defaultServerIndex(0), m_defaultProfileIndex(0), m_use64BitsClient(false), m_shouldUninstallOldClient(true)
|
CConfigFile::CConfigFile(QObject *parent):QObject(parent), m_defaultServerIndex(0), m_defaultProfileIndex(0), m_use64BitsClient(false), m_shouldUninstallOldClient(true)
|
||||||
|
@ -692,11 +752,9 @@ bool CConfigFile::shouldCreateDesktopShortcut() const
|
||||||
|
|
||||||
if (!profile.desktopShortcut) return false;
|
if (!profile.desktopShortcut) return false;
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
QString shortcut = profile.getClientDesktopShortcutFullPath();
|
||||||
return !NLMISC::CFile::isExists(qToUtf8(profile.getClientDesktopLinkFullPath()));
|
|
||||||
#else
|
return !shortcut.isEmpty() && !NLMISC::CFile::isExists(qToUtf8(shortcut));
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CConfigFile::shouldCreateMenuShortcut() const
|
bool CConfigFile::shouldCreateMenuShortcut() const
|
||||||
|
@ -705,11 +763,9 @@ bool CConfigFile::shouldCreateMenuShortcut() const
|
||||||
|
|
||||||
if (!profile.menuShortcut) return false;
|
if (!profile.menuShortcut) return false;
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
QString shortcut = profile.getClientMenuShortcutFullPath();
|
||||||
return !NLMISC::CFile::isExists(qToUtf8(profile.getClientMenuLinkFullPath()));
|
|
||||||
#else
|
return !shortcut.isEmpty() && !NLMISC::CFile::isExists(qToUtf8(shortcut));
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CConfigFile::getInstallerFullPath() const
|
QString CConfigFile::getInstallerFullPath() const
|
||||||
|
@ -876,14 +932,9 @@ OperationStep CConfigFile::getInstallNextStep() const
|
||||||
return CopyProfileFiles;
|
return CopyProfileFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldCreateDesktopShortcut())
|
if (shouldCreateDesktopShortcut() || shouldCreateMenuShortcut())
|
||||||
{
|
{
|
||||||
return CreateDesktopShortcut;
|
return CreateProfileShortcuts;
|
||||||
}
|
|
||||||
|
|
||||||
if (shouldCreateMenuShortcut())
|
|
||||||
{
|
|
||||||
return CreateMenuShortcut;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
|
|
@ -74,8 +74,12 @@ public:
|
||||||
// helpers
|
// helpers
|
||||||
QString getDirectory() const;
|
QString getDirectory() const;
|
||||||
QString getClientFullPath() const;
|
QString getClientFullPath() const;
|
||||||
QString getClientDesktopLinkFullPath() const;
|
QString getClientDesktopShortcutFullPath() const;
|
||||||
QString getClientMenuLinkFullPath() const;
|
QString getClientMenuShortcutFullPath() const;
|
||||||
|
|
||||||
|
void createShortcuts() const;
|
||||||
|
void deleteShortcuts() const;
|
||||||
|
void updateShortcuts() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const CProfile NoProfile;
|
extern const CProfile NoProfile;
|
||||||
|
|
|
@ -64,8 +64,7 @@ enum OperationStep
|
||||||
CopyInstaller,
|
CopyInstaller,
|
||||||
UninstallOldClient,
|
UninstallOldClient,
|
||||||
CreateProfile,
|
CreateProfile,
|
||||||
CreateDesktopShortcut,
|
CreateProfileShortcuts,
|
||||||
CreateMenuShortcut,
|
|
||||||
CreateAddRemoveEntry,
|
CreateAddRemoveEntry,
|
||||||
Done
|
Done
|
||||||
};
|
};
|
||||||
|
|
|
@ -175,12 +175,8 @@ void COperationDialog::processInstallNextStep()
|
||||||
createDefaultProfile();
|
createDefaultProfile();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CreateDesktopShortcut:
|
case CreateProfileShortcuts:
|
||||||
createClientDesktopShortcut(0);
|
createProfileShortcuts(0);
|
||||||
break;
|
|
||||||
|
|
||||||
case CreateMenuShortcut:
|
|
||||||
createClientMenuShortcut(0);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CreateAddRemoveEntry:
|
case CreateAddRemoveEntry:
|
||||||
|
@ -869,60 +865,15 @@ bool COperationDialog::createDefaultProfile()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool COperationDialog::createClientDesktopShortcut(const QString &profileId)
|
bool COperationDialog::createProfileShortcuts(const QString &profileId)
|
||||||
{
|
{
|
||||||
CConfigFile *config = CConfigFile::getInstance();
|
CConfigFile *config = CConfigFile::getInstance();
|
||||||
|
|
||||||
const CProfile &profile = config->getProfile(profileId);
|
const CProfile &profile = config->getProfile(profileId);
|
||||||
const CServer &server = config->getServer(profile.server);
|
|
||||||
|
|
||||||
m_currentOperation = tr("Create desktop shortcut for profile %1").arg(profile.id);
|
m_currentOperation = tr("Create shortcuts for profile %1").arg(profile.id);
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
profile.createShortcuts();
|
||||||
if (profile.desktopShortcut)
|
|
||||||
{
|
|
||||||
QString executable = profile.getClientFullPath();
|
|
||||||
QString shortcut = profile.getClientDesktopLinkFullPath();
|
|
||||||
QString workingDir = server.getDirectory();
|
|
||||||
|
|
||||||
QString arguments = QString("--profile %1").arg(profile.id);
|
|
||||||
|
|
||||||
// append custom arguments
|
|
||||||
if (!profile.arguments.isEmpty()) arguments += QString(" %1").arg(profile.arguments);
|
|
||||||
|
|
||||||
createLink(executable, shortcut, arguments, workingDir, profile.comments);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
emit done();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool COperationDialog::createClientMenuShortcut(const QString &profileId)
|
|
||||||
{
|
|
||||||
CConfigFile *config = CConfigFile::getInstance();
|
|
||||||
|
|
||||||
const CProfile &profile = config->getProfile(profileId);
|
|
||||||
const CServer &server = config->getServer(profile.server);
|
|
||||||
|
|
||||||
m_currentOperation = tr("Create menu shortcut for profile %1").arg(profile.id);
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
if (profile.menuShortcut)
|
|
||||||
{
|
|
||||||
QString executable = profile.getClientFullPath();
|
|
||||||
QString shortcut = profile.getClientMenuLinkFullPath();
|
|
||||||
QString workingDir = server.getDirectory();
|
|
||||||
|
|
||||||
QString arguments = QString("--profile %1").arg(profile.id);
|
|
||||||
|
|
||||||
// append custom arguments
|
|
||||||
if (!profile.arguments.isEmpty()) arguments += QString(" %1").arg(profile.arguments);
|
|
||||||
|
|
||||||
createLink(executable, shortcut, arguments, workingDir, profile.comments);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
emit done();
|
emit done();
|
||||||
|
|
||||||
|
@ -1080,9 +1031,7 @@ void COperationDialog::addComponentsProfiles()
|
||||||
{
|
{
|
||||||
const CProfile &profile = config->getProfile(profileId);
|
const CProfile &profile = config->getProfile(profileId);
|
||||||
|
|
||||||
if (profile.desktopShortcut) createClientDesktopShortcut(profile.id);
|
profile.createShortcuts();
|
||||||
|
|
||||||
if (profile.menuShortcut) createClientMenuShortcut(profile.id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,8 +103,7 @@ protected:
|
||||||
void uninstallOldClient();
|
void uninstallOldClient();
|
||||||
bool createDefaultProfile();
|
bool createDefaultProfile();
|
||||||
|
|
||||||
bool createClientDesktopShortcut(const QString &profileId);
|
bool createProfileShortcuts(const QString &profileId);
|
||||||
bool createClientMenuShortcut(const QString &profileId);
|
|
||||||
|
|
||||||
bool createAddRemoveEntry();
|
bool createAddRemoveEntry();
|
||||||
bool updateAddRemoveEntry();
|
bool updateAddRemoveEntry();
|
||||||
|
|
Loading…
Reference in a new issue