Advertisement
Guest User

autostart patch

a guest
Mar 24th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.56 KB | None | 0 0
  1. --- git.orig/src/applicationinfo.cpp
  2. +++ git/src/applicationinfo.cpp
  3. @@ -10,7 +10,7 @@
  4.  #include <QStandardPaths>
  5.  #endif
  6.  
  7. -#ifdef HAVE_X11
  8. +#ifdef Q_OS_UNIX
  9.  #include <sys/stat.h> // chmod
  10.  #endif
  11.  
  12. @@ -58,8 +58,8 @@
  13.  #define PROG_APPCAST_URL ""
  14.  #endif
  15.  
  16. -#if defined(HAVE_X11) && !defined(PSI_DATADIR)
  17. -#define PSI_DATADIR "/usr/local/share/psi"
  18. +#if defined(Q_OS_UNIX) && !defined(PSI_DATADIR)
  19. +#define PSI_DATADIR APP_PREFIX"/share/"APP_BIN_NAME
  20.  #endif
  21.  
  22.  
  23. @@ -141,7 +141,7 @@ QString ApplicationInfo::getCertificateS
  24.  
  25.  QString ApplicationInfo::resourcesDir()
  26.  {
  27. -#if defined(HAVE_X11)
  28. +#if defined(Q_OS_UNIX)
  29.     return PSI_DATADIR;
  30.  #elif defined(Q_OS_WIN)
  31.     return qApp->applicationDirPath();
  32. @@ -238,7 +238,7 @@ QString ApplicationInfo::homeDir(Applica
  33.             QDir configDir(QDir::homePath() + "/Library/Application Support/" + name());
  34.             QDir cacheDir(QDir::homePath() + "/Library/Caches/" + name());
  35.             QDir dataDir(configDir);
  36. -#elif defined HAVE_X11
  37. +#elif defined HAVE_FREEDESKTOP
  38.             QString XdgConfigHome = QString::fromLocal8Bit(getenv("XDG_CONFIG_HOME"));
  39.             QString XdgDataHome = QString::fromLocal8Bit(getenv("XDG_DATA_HOME"));
  40.             QString XdgCacheHome = QString::fromLocal8Bit(getenv("XDG_CACHE_HOME"));
  41. @@ -383,3 +383,14 @@ QString ApplicationInfo::currentProfileD
  42.  {
  43.     return pathToProfile(activeProfile, type);
  44.  }
  45. +
  46. +QString ApplicationInfo::desktopFile()
  47. +{
  48. +   QString dFile;
  49. +   const QString _desktopFile(APP_PREFIX "/share/applications/" APP_BIN_NAME ".desktop");
  50. +   QFile f(_desktopFile);
  51. +   if(f.open(QIODevice::ReadOnly)) {
  52. +       dFile = QString::fromUtf8(f.readAll());
  53. +   }
  54. +   return dFile;
  55. +}
  56. --- git.orig/src/applicationinfo.h
  57. +++ git/src/applicationinfo.h
  58. @@ -44,6 +44,9 @@ public:
  59.     static QString optionsNS();
  60.     static QString storageNS();
  61.     static QString fileCacheNS();
  62. +
  63. +   // Common
  64. +   static QString desktopFile();
  65.  };
  66.  
  67.  #endif
  68. --- git.orig/src/options/opt_application.cpp
  69. +++ git/src/options/opt_application.cpp
  70. @@ -13,9 +13,17 @@
  71.  #include "qsettings.h"
  72.  #include <QList>
  73.  #include <QMessageBox>
  74. +#include <QDir>
  75.  
  76.  #include "ui_opt_application.h"
  77.  
  78. +#ifdef Q_OS_WIN
  79. +   static const QString regString = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
  80. +#endif
  81. +#ifdef HAVE_FREEDESKTOP
  82. +   static const QString psiAutoStart("/.config/autostart/" APP_BIN_NAME ".desktop");
  83. +#endif
  84. +
  85.  class OptApplicationUI : public QWidget, public Ui::OptApplication
  86.  {
  87.  public:
  88. @@ -60,6 +68,7 @@ QWidget *OptionsTabApplication::widget()
  89.  
  90.  #ifdef Q_OS_MAC
  91.     d->gb_docklet->hide();
  92. +   d->ck_auto_load->hide();
  93.  #endif
  94.  
  95.     if (!haveAutoUpdater_) {
  96. @@ -126,6 +135,29 @@ void OptionsTabApplication::applyOptions
  97.     }
  98.     QSettings s(ApplicationInfo::homeDir(ApplicationInfo::ConfigLocation) + "/psirc", QSettings::IniFormat);
  99.     s.setValue("last_lang", itemData);
  100. +
  101. +   //Auto-load
  102. +#ifdef Q_OS_WIN
  103. +   QSettings set(regString, QSettings::NativeFormat);
  104. +   if(d->ck_auto_load->isChecked()) {
  105. +       set.setValue(ApplicationInfo::name(), QDir::toNativeSeparators(qApp->applicationFilePath()));
  106. +   }
  107. +   else {
  108. +       set.remove(ApplicationInfo::name());
  109. +   }
  110. +#endif
  111. +#ifdef HAVE_FREEDESKTOP
  112. +   QDir home = QDir::home();
  113. +   if (!home.exists(".config/autostart")) {
  114. +       home.mkpath(".config/autostart");
  115. +   }
  116. +   QFile f(home.absolutePath() + psiAutoStart);
  117. +   if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
  118. +       const QString contents = ApplicationInfo::desktopFile().trimmed();
  119. +       f.write(contents.toUtf8());
  120. +       f.write(QString("\nHidden=%1").arg(d->ck_auto_load->isChecked() ? "false\n" : "true\n").toUtf8());
  121. +   }
  122. +#endif
  123.  }
  124.  
  125.  void OptionsTabApplication::restoreOptions()
  126. @@ -164,6 +196,21 @@ void OptionsTabApplication::restoreOptio
  127.         d->cb_lang->setCurrentIndex( 0 );
  128.     else if(!curLang.isEmpty() && lang.contains(curLang) )
  129.         d->cb_lang->setCurrentIndex( d->cb_lang->findText(vList.get(curLang)) );
  130. +
  131. +   //Auto-load
  132. +#ifdef Q_OS_WIN
  133. +   QSettings set(regString, QSettings::NativeFormat);
  134. +   const QString path = set.value(ApplicationInfo::name()).toString();
  135. +   d->ck_auto_load->setChecked( (path == QDir::toNativeSeparators(qApp->applicationFilePath())) );
  136. +#endif
  137. +#ifdef HAVE_FREEDESKTOP
  138. +   QFile desktop(QDir::homePath() + psiAutoStart);
  139. +   if (desktop.open(QIODevice::ReadOnly)
  140. +       && QString(desktop.readAll()).contains(QRegExp("\\bhidden\\s*=\\s*false", Qt::CaseInsensitive)))
  141. +   {
  142. +       d->ck_auto_load->setChecked(true);
  143. +   }
  144. +#endif
  145.  }
  146.  
  147.  void OptionsTabApplication::doEnableQuitOnClose(int state)
  148. --- git.orig/src/options/opt_application.ui
  149. +++ git/src/options/opt_application.ui
  150. @@ -14,6 +14,13 @@
  151.    </property>
  152.    <layout class="QVBoxLayout" >
  153.     <item>
  154. +    <widget class="QCheckBox" name="ck_auto_load">
  155. +     <property name="text">
  156. +      <string>Automatically launch application when OS starts</string>
  157. +     </property>
  158. +    </widget>
  159. +   </item>
  160. +   <item>
  161.      <widget class="QCheckBox" name="ck_winDecor" >
  162.       <property name="text" >
  163.        <string>Decorate windows</string>
  164. --- git.orig/src/src.pri
  165. +++ git/src/src.pri
  166. @@ -9,7 +9,10 @@ greaterThan(QT_MAJOR_VERSION, 4) {
  167.     QT += x11extras
  168.    }
  169.  }
  170. -unix:!mac:DEFINES += HAVE_X11
  171. +unix:!mac {
  172. +  DEFINES += HAVE_X11
  173. +  DEFINES += HAVE_FREEDESKTOP
  174. +}
  175.  
  176.  CONFIG(debug, debug|release) {
  177.    mac: DEFINES += DEBUG_POSTFIX=\\\"_debug\\\"
  178. --- git.orig/src/src.pro
  179. +++ git/src/src.pro
  180. @@ -32,6 +32,8 @@ include(../qa/oldtest/unittest.pri)
  181. include($$top_builddir/conf.pri)
  182.  
  183. unix {
  184. +   DEFINES += APP_PREFIX=$$PREFIX
  185. +   DEFINES += APP_BIN_NAME=$$target
  186.     # Target
  187.     target.path = $$BINDIR
  188.     INSTALLS += target
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement