ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
autorun.cpp
Go to the documentation of this file.
1 #include <QApplication>
2 #include <QDir>
3 #include <QSettings>
4 #include <QStandardPaths>
5 #include "autorun.h"
6 #include "ckbsettings.h"
7 
8 // Paths
9 #ifdef Q_OS_LINUX
10 static QDir path(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/.config/autostart");
11 static const QString file = "ckb.desktop";
12 static const QString internalFile(":/txt/ckb.desktop");
13 #elif defined(Q_OS_MACX)
14 static QDir path(QStandardPaths::writableLocation(QStandardPaths::HomeLocation) + "/Library/LaunchAgents");
15 static const QString file = "com.ckb.ckb.plist";
16 static const QString internalFile(":/txt/com.ckb.ckb.plist");
17 #endif
18 static const QString settingPath = "Program/DidLoginItem";
19 
21  // Allow autostart if the program is located in a system path
22 #ifdef Q_OS_LINUX
23  return QDir::root().absoluteFilePath(QStandardPaths::findExecutable("ckb")) == qApp->applicationFilePath();
24 #elif defined(Q_OS_MACX)
25  return qApp->applicationFilePath().startsWith("/Applications/ckb.app", Qt::CaseInsensitive);
26 #endif
27 }
28 
30  return CkbSettings::get(settingPath).toBool();
31 }
32 
34  // Check if the file exists. If not, autostart is disabled.
35  if(!path.exists() || !path.exists(file))
36  return false;
37  // If autostart is enabled, set the flag from once() (in case it hasn't been done yet)
38  CkbSettings::set(settingPath, true);
39  return true;
40 }
41 
43  if(!available())
44  return;
45  // Copy file into place
46  if(!path.exists())
47  QDir::home().mkpath(path.absolutePath());
48  QFile::copy(internalFile, path.absoluteFilePath(file));
49  // Mark once() as done
50  CkbSettings::set(settingPath, true);
51 }
52 
54  if(!available())
55  return;
56  // Remove file
57  QFile::remove(path.absoluteFilePath(file));
58 }
static bool available()
Definition: autorun.cpp:20
static void set(const QString &key, const QVariant &value)
static void disable()
Definition: autorun.cpp:53
static QVariant get(const QString &key, const QVariant &defaultValue=QVariant())
static bool isEnabled()
Definition: autorun.cpp:33
static void enable()
Definition: autorun.cpp:42
static const QString settingPath
Definition: autorun.cpp:18
static bool once()
Definition: autorun.cpp:29