Advertisement
Guest User

0001 patch

a guest
Mar 24th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.92 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. @@ -36,6 +36,9 @@
  13.  #include "config.h"
  14.  #endif
  15.  
  16. +#define xstr(a) str(a)
  17. +#define str(a) #a
  18. +
  19.  // Constants. These should be moved to a more 'dynamically changeable'
  20.  // place (like an external file loaded through the resources system)
  21.  // Should also be overridable through an optional file.
  22. @@ -58,8 +61,8 @@
  23.  #define PROG_APPCAST_URL ""
  24.  #endif
  25.  
  26. -#if defined(HAVE_X11) && !defined(PSI_DATADIR)
  27. -#define PSI_DATADIR "/usr/local/share/psi"
  28. +#if defined(Q_OS_UNIX) && !defined(PSI_DATADIR)
  29. +#define PSI_DATADIR xstr(APP_PREFIX)"/share/"xstr(APP_BIN_NAME)
  30.  #endif
  31.  
  32.  
  33. @@ -141,7 +144,7 @@ QString ApplicationInfo::getCertificateS
  34.  
  35.  QString ApplicationInfo::resourcesDir()
  36.  {
  37. -#if defined(HAVE_X11)
  38. +#if defined(Q_OS_UNIX)
  39.     return PSI_DATADIR;
  40.  #elif defined(Q_OS_WIN)
  41.     return qApp->applicationDirPath();
  42. @@ -238,10 +241,16 @@ QString ApplicationInfo::homeDir(Applica
  43.             QDir configDir(QDir::homePath() + "/Library/Application Support/" + name());
  44.             QDir cacheDir(QDir::homePath() + "/Library/Caches/" + name());
  45.             QDir dataDir(configDir);
  46. -#elif defined HAVE_X11
  47. +#elif defined HAVE_FREEDESKTOP
  48. +#ifndef HAVE_QT5
  49.             QString XdgConfigHome = QString::fromLocal8Bit(getenv("XDG_CONFIG_HOME"));
  50.             QString XdgDataHome = QString::fromLocal8Bit(getenv("XDG_DATA_HOME"));
  51.             QString XdgCacheHome = QString::fromLocal8Bit(getenv("XDG_CACHE_HOME"));
  52. +#else
  53. +           QString XdgConfigHome(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
  54. +           QString XdgDataHome(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
  55. +           QString XdgCacheHome(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
  56. +#endif
  57.             if (XdgConfigHome.isEmpty()) {
  58.                 XdgConfigHome = QDir::homePath() + "/.config";
  59.             }
  60. @@ -383,3 +392,14 @@ QString ApplicationInfo::currentProfileD
  61.  {
  62.     return pathToProfile(activeProfile, type);
  63.  }
  64. +
  65. +QString ApplicationInfo::desktopFile()
  66. +{
  67. +   QString dFile;
  68. +   const QString _desktopFile(xstr(APP_PREFIX) "/share/applications/" xstr(APP_BIN_NAME) ".desktop");
  69. +   QFile f(_desktopFile);
  70. +   if(f.open(QIODevice::ReadOnly)) {
  71. +       dFile = QString::fromUtf8(f.readAll());
  72. +   }
  73. +   return dFile;
  74. +}
  75. --- git.orig/src/applicationinfo.h
  76. +++ git/src/applicationinfo.h
  77. @@ -44,6 +44,9 @@ public:
  78.     static QString optionsNS();
  79.     static QString storageNS();
  80.     static QString fileCacheNS();
  81. +
  82. +   // Common
  83. +   static QString desktopFile();
  84.  };
  85.  
  86.  #endif
  87. --- git.orig/src/options/opt_application.cpp
  88. +++ git/src/options/opt_application.cpp
  89. @@ -3,14 +3,30 @@
  90.  #include "iconwidget.h"
  91.  #include "psioptions.h"
  92.  #include "proxy.h"
  93. +#include "translationmanager.h"
  94. +#include "varlist.h"
  95. +#include "applicationinfo.h"
  96.  
  97.  #include <QCheckBox>
  98.  #include <QComboBox>
  99.  #include <QLineEdit>
  100. +#include <QSettings>
  101.  #include <QList>
  102. +#include <QMessageBox>
  103. +#include <QDir>
  104. +#ifdef HAVE_QT5
  105. +#include <QStandardPaths>
  106. +#endif
  107.  
  108.  #include "ui_opt_application.h"
  109.  
  110. +#ifdef Q_OS_WIN
  111. +   static const QString regString = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
  112. +#endif
  113. +#ifdef HAVE_FREEDESKTOP
  114. +   static const QString psiAutoStart("/.config/autostart/" APP_BIN_NAME ".desktop");
  115. +#endif
  116. +
  117.  class OptApplicationUI : public QWidget, public Ui::OptApplication
  118.  {
  119.  public:
  120. @@ -53,6 +69,7 @@ QWidget *OptionsTabApplication::widget()
  121.  
  122.  #ifdef Q_OS_MAC
  123.     d->gb_docklet->hide();
  124. +   d->ck_auto_load->hide();
  125.  #endif
  126.  
  127.     if (!haveAutoUpdater_) {
  128. @@ -101,6 +118,51 @@ void OptionsTabApplication::applyOptions
  129.  
  130.     //Proxy
  131.     ProxyManager::instance()->proxyForObject()->save();
  132. +
  133. +   // Language
  134. +   QString curLang = TranslationManager::instance()->currentLanguage();
  135. +   QString lang = d->cb_lang->currentText();
  136. +   QString itemData;
  137. +   foreach(VarListItem it, TranslationManager::instance()->availableTranslations() ) {
  138. +       if(it.data() == lang) {
  139. +           itemData = it.key();
  140. +           break;
  141. +       }
  142. +   }
  143. +   if(curLang != itemData && !itemData.isEmpty()) {
  144. +       TranslationManager::instance()->loadTranslation(itemData);
  145. +       QMessageBox::information(0, tr("Information"), tr("Some of the options you changed will only have full effect upon restart."));
  146. +   }
  147. +   QSettings s(ApplicationInfo::homeDir(ApplicationInfo::ConfigLocation) + "/psirc", QSettings::IniFormat);
  148. +   s.setValue("last_lang", itemData);
  149. +
  150. +   //Auto-load
  151. +#ifdef Q_OS_WIN
  152. +   QSettings set(regString, QSettings::NativeFormat);
  153. +   if(d->ck_auto_load->isChecked()) {
  154. +       set.setValue(ApplicationInfo::name(), QDir::toNativeSeparators(qApp->applicationFilePath()));
  155. +   }
  156. +   else {
  157. +       set.remove(ApplicationInfo::name());
  158. +   }
  159. +#endif
  160. +#ifdef HAVE_FREEDESKTOP
  161. +#ifndef HAVE_QT5
  162. +   QDir home(QString::fromLocal8Bit(getenv("XDG_CONFIG_HOME")));
  163. +#else
  164. +   QDir home(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
  165. +#endif
  166. +
  167. +   if (!home.exists("autostart")) {
  168. +       home.mkpath("autostart");
  169. +   }
  170. +   QFile f(home.absolutePath() + psiAutoStart);
  171. +   if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
  172. +       const QString contents = ApplicationInfo::desktopFile().trimmed();
  173. +       f.write(contents.toUtf8());
  174. +       f.write(QString("\nHidden=%1").arg(d->ck_auto_load->isChecked() ? "false\n" : "true\n").toUtf8());
  175. +   }
  176. +#endif
  177.  }
  178.  
  179.  void OptionsTabApplication::restoreOptions()
  180. @@ -123,6 +185,36 @@ void OptionsTabApplication::restoreOptio
  181.     // data transfer
  182.     d->le_dtPort->setText( QString::number(PsiOptions::instance()->getOption("options.p2p.bytestreams.listen-port").toInt()) );
  183.     d->le_dtExternal->setText( PsiOptions::instance()->getOption("options.p2p.bytestreams.external-address").toString() );
  184. +
  185. +   // Language
  186. +   VarList vList = TranslationManager::instance()->availableTranslations();
  187. +   QStringList lang = vList.varsToStringList();
  188. +   d->cb_lang->addItem(tr("Default"));
  189. +   foreach(QString item, lang) {
  190. +       d->cb_lang->addItem(vList.get(item));
  191. +   }
  192. +   QString curLang = TranslationManager::instance()->currentLanguage();
  193. +   QSettings s(ApplicationInfo::homeDir(ApplicationInfo::ConfigLocation) + "/psirc", QSettings::IniFormat);
  194. +   QString curL = s.value("last_lang", "").toString();
  195. +   if (curL.isEmpty())
  196. +       d->cb_lang->setCurrentIndex( 0 );
  197. +   else if(!curLang.isEmpty() && lang.contains(curLang) )
  198. +       d->cb_lang->setCurrentIndex( d->cb_lang->findText(vList.get(curLang)) );
  199. +
  200. +   //Auto-load
  201. +#ifdef Q_OS_WIN
  202. +   QSettings set(regString, QSettings::NativeFormat);
  203. +   const QString path = set.value(ApplicationInfo::name()).toString();
  204. +   d->ck_auto_load->setChecked( (path == QDir::toNativeSeparators(qApp->applicationFilePath())) );
  205. +#endif
  206. +#ifdef HAVE_FREEDESKTOP
  207. +   QFile desktop(QDir::homePath() + psiAutoStart);
  208. +   if (desktop.open(QIODevice::ReadOnly)
  209. +       && QString(desktop.readAll()).contains(QRegExp("\\bhidden\\s*=\\s*false", Qt::CaseInsensitive)))
  210. +   {
  211. +       d->ck_auto_load->setChecked(true);
  212. +   }
  213. +#endif
  214.  }
  215.  
  216.  void OptionsTabApplication::doEnableQuitOnClose(int state)
  217. --- git.orig/src/options/opt_application.ui
  218. +++ git/src/options/opt_application.ui
  219. @@ -13,6 +13,13 @@
  220.     <string>OptApplicationUI</string>
  221.    </property>
  222.    <layout class="QVBoxLayout" >
  223. +  <item>
  224. +    <widget class="QCheckBox" name="ck_auto_load">
  225. +     <property name="text">
  226. +      <string>Automatically launch application when OS starts</string>
  227. +     </property>
  228. +    </widget>
  229. +   </item>
  230.     <item>
  231.      <widget class="QCheckBox" name="ck_docklet" >
  232.       <property name="text" >
  233. @@ -179,6 +186,33 @@
  234.      </widget>
  235.     </item>
  236.     <item>
  237. +    <layout class="QHBoxLayout" name="horizontalLayout">
  238. +     <item>
  239. +      <widget class="QLabel" name="label_2">
  240. +       <property name="text">
  241. +        <string>Language</string>
  242. +       </property>
  243. +      </widget>
  244. +     </item>
  245. +     <item>
  246. +      <widget class="QComboBox" name="cb_lang"/>
  247. +     </item>
  248. +     <item>
  249. +      <spacer name="horizontalSpacer">
  250. +       <property name="orientation">
  251. +        <enum>Qt::Horizontal</enum>
  252. +       </property>
  253. +       <property name="sizeHint" stdset="0">
  254. +        <size>
  255. +         <width>40</width>
  256. +         <height>20</height>
  257. +        </size>
  258. +       </property>
  259. +      </spacer>
  260. +     </item>
  261. +    </layout>
  262. +   </item>
  263. +   <item>
  264.      <spacer>
  265.       <property name="orientation" >
  266.        <enum>Qt::Vertical</enum>
  267. --- git.orig/src/src.pri
  268. +++ git/src/src.pri
  269. @@ -9,7 +9,10 @@ greaterThan(QT_MAJOR_VERSION, 4) {
  270.     QT += x11extras
  271.    }
  272.  }
  273. -unix:!mac:DEFINES += HAVE_X11
  274. +unix:!mac {
  275. +  DEFINES += HAVE_X11
  276. +  DEFINES += HAVE_FREEDESKTOP
  277. +}
  278.  
  279.  CONFIG(debug, debug|release) {
  280.    mac: DEFINES += DEBUG_POSTFIX=\\\"_debug\\\"
  281. --- git.orig/src/src.pro
  282. +++ git/src/src.pro
  283. @@ -32,6 +32,8 @@ include(../qa/oldtest/unittest.pri)
  284. include($$top_builddir/conf.pri)
  285.  
  286. unix {
  287. +   DEFINES += APP_PREFIX=$$PREFIX
  288. +   DEFINES += APP_BIN_NAME=$$target
  289.     # Target
  290.     target.path = $$BINDIR
  291.     INSTALLS += target
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement