Fixup working with startupLaunch value (#477)

* Fixup working with startupLaunch value

This commit fixes problem, when you want to import or export
information about startup.

* Verify if autostart directory exists
This commit is contained in:
greno4ka
2019-03-31 13:43:47 +03:00
committed by Dharkael
parent b42f1cf01d
commit b75ee75f90
2 changed files with 24 additions and 2 deletions

View File

@@ -242,6 +242,21 @@ void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen) {
bool ConfigHandler::startupLaunchValue() {
bool res = false;
if (m_settings.contains(QStringLiteral("startupLaunch"))) {
res = m_settings.value(QStringLiteral("startupLaunch")).toBool();
}
if (res != verifyLaunchFile()) {
setStartupLaunch(res);
}
return res;
}
bool ConfigHandler::verifyLaunchFile() {
bool res = false;
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
QString path = QDir::homePath() + "/.config/autostart/Flameshot.desktop";
res = QFile(path).exists();
@@ -257,8 +272,13 @@ bool ConfigHandler::startupLaunchValue() {
void ConfigHandler::setStartupLaunch(const bool start) {
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
QString path = QDir::homePath() + "/.config/autostart/Flameshot.desktop";
QFile file(path);
QString path = QDir::homePath() + "/.config/autostart/";
QDir autostartDir(path);
if (!autostartDir.exists()) {
autostartDir.mkpath(".");
}
QFile file(path + "Flameshot.desktop");
if (start) {
if (file.open(QIODevice::WriteOnly)) {
QByteArray data("[Desktop Entry]\nName=flameshot\nIcon=flameshot"
@@ -281,6 +301,7 @@ void ConfigHandler::setStartupLaunch(const bool start) {
bootUpSettings.remove("Flameshot");
}
#endif
m_settings.setValue(QStringLiteral("startupLaunch"), start);
}
int ConfigHandler::contrastOpacityValue() {

View File

@@ -61,6 +61,7 @@ public:
bool keepOpenAppLauncherValue();
void setKeepOpenAppLauncher(const bool);
bool verifyLaunchFile();
bool startupLaunchValue();
void setStartupLaunch(const bool);