Changed: Create all profiles shortcuts at once, see #279

This commit is contained in:
kervala 2016-07-25 18:31:11 +02:00
parent 6f9a9f66dd
commit 6e169732a1
5 changed files with 86 additions and 84 deletions

View file

@ -60,24 +60,84 @@ QString CProfile::getClientFullPath() const
return s.getClientFullPath();
}
QString CProfile::getClientDesktopLinkFullPath() const
QString CProfile::getClientDesktopShortcutFullPath() const
{
#ifdef Q_OS_WIN32
return CConfigFile::getInstance()->getDesktopDirectory() + "/" + name + ".lnk";
#else
#elif defined(Q_OS_MAC)
return "";
#else
return CConfigFile::getInstance()->getDesktopDirectory() + "/" + name + ".desktop";
#endif
}
QString CProfile::getClientMenuLinkFullPath() const
QString CProfile::getClientMenuShortcutFullPath() const
{
#ifdef Q_OS_WIN32
return CConfigFile::getInstance()->getMenuDirectory() + "/" + name + ".lnk";
#else
#elif defined(Q_OS_MAC)
return "";
#else
return CConfigFile::getInstance()->getMenuDirectory() + "/" + name + ".desktop";
#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(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;
#ifdef Q_OS_WIN32
return !NLMISC::CFile::isExists(qToUtf8(profile.getClientDesktopLinkFullPath()));
#else
return false;
#endif
QString shortcut = profile.getClientDesktopShortcutFullPath();
return !shortcut.isEmpty() && !NLMISC::CFile::isExists(qToUtf8(shortcut));
}
bool CConfigFile::shouldCreateMenuShortcut() const
@ -705,11 +763,9 @@ bool CConfigFile::shouldCreateMenuShortcut() const
if (!profile.menuShortcut) return false;
#ifdef Q_OS_WIN32
return !NLMISC::CFile::isExists(qToUtf8(profile.getClientMenuLinkFullPath()));
#else
return false;
#endif
QString shortcut = profile.getClientMenuShortcutFullPath();
return !shortcut.isEmpty() && !NLMISC::CFile::isExists(qToUtf8(shortcut));
}
QString CConfigFile::getInstallerFullPath() const
@ -876,14 +932,9 @@ OperationStep CConfigFile::getInstallNextStep() const
return CopyProfileFiles;
}
if (shouldCreateDesktopShortcut())
if (shouldCreateDesktopShortcut() || shouldCreateMenuShortcut())
{
return CreateDesktopShortcut;
}
if (shouldCreateMenuShortcut())
{
return CreateMenuShortcut;
return CreateProfileShortcuts;
}
#ifdef Q_OS_WIN

View file

@ -74,8 +74,12 @@ public:
// helpers
QString getDirectory() const;
QString getClientFullPath() const;
QString getClientDesktopLinkFullPath() const;
QString getClientMenuLinkFullPath() const;
QString getClientDesktopShortcutFullPath() const;
QString getClientMenuShortcutFullPath() const;
void createShortcuts() const;
void deleteShortcuts() const;
void updateShortcuts() const;
};
extern const CProfile NoProfile;

View file

@ -64,8 +64,7 @@ enum OperationStep
CopyInstaller,
UninstallOldClient,
CreateProfile,
CreateDesktopShortcut,
CreateMenuShortcut,
CreateProfileShortcuts,
CreateAddRemoveEntry,
Done
};

View file

@ -175,12 +175,8 @@ void COperationDialog::processInstallNextStep()
createDefaultProfile();
break;
case CreateDesktopShortcut:
createClientDesktopShortcut(0);
break;
case CreateMenuShortcut:
createClientMenuShortcut(0);
case CreateProfileShortcuts:
createProfileShortcuts(0);
break;
case CreateAddRemoveEntry:
@ -869,60 +865,15 @@ bool COperationDialog::createDefaultProfile()
return true;
}
bool COperationDialog::createClientDesktopShortcut(const QString &profileId)
bool COperationDialog::createProfileShortcuts(const QString &profileId)
{
CConfigFile *config = CConfigFile::getInstance();
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
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
profile.createShortcuts();
emit done();
@ -1080,9 +1031,7 @@ void COperationDialog::addComponentsProfiles()
{
const CProfile &profile = config->getProfile(profileId);
if (profile.desktopShortcut) createClientDesktopShortcut(profile.id);
if (profile.menuShortcut) createClientMenuShortcut(profile.id);
profile.createShortcuts();
}
}

View file

@ -103,8 +103,7 @@ protected:
void uninstallOldClient();
bool createDefaultProfile();
bool createClientDesktopShortcut(const QString &profileId);
bool createClientMenuShortcut(const QString &profileId);
bool createProfileShortcuts(const QString &profileId);
bool createAddRemoveEntry();
bool updateAddRemoveEntry();