Advertisement
Guest User

0001 patch v2

a guest
Mar 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.82 KB | None | 0 0
  1. --- git.orig/options/default.xml
  2. +++ git/options/default.xml
  3. @@ -93,6 +93,7 @@
  4.                 <enabled comment="Enable message (i.e. non-chat) functionality" type="bool">true</enabled>
  5.                 <auto-grab-urls-from-clipboard type="bool">false</auto-grab-urls-from-clipboard>
  6.                 <auto-popup type="bool">false</auto-popup>
  7. +               <auto-capitalize type="bool">false</auto-capitalize>
  8.                 <auto-popup-headlines type="bool">false</auto-popup-headlines>
  9.                 <show-character-count type="bool">false</show-character-count>
  10.                 <show-subjects type="bool">true</show-subjects>
  11. @@ -467,6 +468,7 @@
  12.                 <show-messageFirst type="QKeySequence" comment="Show first message" >Alt+End</show-messageFirst>
  13.                 <show-messageNext type="QKeySequence" comment="Show next message" >Ctrl+Down</show-messageNext>
  14.                 <show-messagePrev type="QKeySequence" comment="Show prev message" >Ctrl+Up</show-messagePrev>
  15. +               <change-case type="QKeySequence" comment="Change case of letters in the chat edit" >Ctrl+Alt+x</change-case>
  16.             </chat>
  17.             <contactlist comment="Shortcuts in the contactlist">
  18.                 <assign-custom-avatar type="QKeySequence" comment="Assign a custom avatar to the selected contact"/>
  19. --- git.orig/src/applicationinfo.cpp
  20. +++ git/src/applicationinfo.cpp
  21. @@ -10,7 +10,7 @@
  22.  #include <QStandardPaths>
  23.  #endif
  24.  
  25. -#ifdef HAVE_X11
  26. +#ifdef Q_OS_UNIX
  27.  #include <sys/stat.h> // chmod
  28.  #endif
  29.  
  30. @@ -36,6 +36,9 @@
  31.  #include "config.h"
  32.  #endif
  33.  
  34. +#define xstr(a) str(a)
  35. +#define str(a) #a
  36. +
  37.  // Constants. These should be moved to a more 'dynamically changeable'
  38.  // place (like an external file loaded through the resources system)
  39.  // Should also be overridable through an optional file.
  40. @@ -58,11 +61,6 @@
  41.  #define PROG_APPCAST_URL ""
  42.  #endif
  43.  
  44. -#if defined(HAVE_X11) && !defined(PSI_DATADIR)
  45. -#define PSI_DATADIR "/usr/local/share/psi"
  46. -#endif
  47. -
  48. -
  49.  QString ApplicationInfo::name()
  50.  {
  51.     return PROG_NAME;
  52. @@ -141,7 +139,7 @@ QString ApplicationInfo::getCertificateS
  53.  
  54.  QString ApplicationInfo::resourcesDir()
  55.  {
  56. -#if defined(HAVE_X11)
  57. +#if defined(Q_OS_UNIX)
  58.     return PSI_DATADIR;
  59.  #elif defined(Q_OS_WIN)
  60.     return qApp->applicationDirPath();
  61. @@ -238,10 +236,16 @@ QString ApplicationInfo::homeDir(Applica
  62.             QDir configDir(QDir::homePath() + "/Library/Application Support/" + name());
  63.             QDir cacheDir(QDir::homePath() + "/Library/Caches/" + name());
  64.             QDir dataDir(configDir);
  65. -#elif defined HAVE_X11
  66. +#elif defined HAVE_FREEDESKTOP
  67. +#ifndef HAVE_QT5
  68.             QString XdgConfigHome = QString::fromLocal8Bit(getenv("XDG_CONFIG_HOME"));
  69.             QString XdgDataHome = QString::fromLocal8Bit(getenv("XDG_DATA_HOME"));
  70.             QString XdgCacheHome = QString::fromLocal8Bit(getenv("XDG_CACHE_HOME"));
  71. +#else
  72. +           QString XdgConfigHome(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
  73. +           QString XdgDataHome(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
  74. +           QString XdgCacheHome(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
  75. +#endif
  76.             if (XdgConfigHome.isEmpty()) {
  77.                 XdgConfigHome = QDir::homePath() + "/.config";
  78.             }
  79. @@ -383,3 +387,14 @@ QString ApplicationInfo::currentProfileD
  80.  {
  81.     return pathToProfile(activeProfile, type);
  82.  }
  83. +
  84. +QString ApplicationInfo::desktopFile()
  85. +{
  86. +   QString dFile;
  87. +   const QString _desktopFile(xstr(APP_PREFIX) "/share/applications/" xstr(APP_BIN_NAME) ".desktop");
  88. +   QFile f(_desktopFile);
  89. +   if(f.open(QIODevice::ReadOnly)) {
  90. +       dFile = QString::fromUtf8(f.readAll());
  91. +   }
  92. +   return dFile;
  93. +}
  94. --- git.orig/src/applicationinfo.h
  95. +++ git/src/applicationinfo.h
  96. @@ -44,6 +44,9 @@ public:
  97.     static QString optionsNS();
  98.     static QString storageNS();
  99.     static QString fileCacheNS();
  100. +
  101. +   // Common
  102. +   static QString desktopFile();
  103.  };
  104.  
  105.  #endif
  106. --- git.orig/src/msgmle.cpp
  107. +++ git/src/msgmle.cpp
  108. @@ -40,6 +40,124 @@
  109.  #include "psioptions.h"
  110.  #include "htmltextcontroller.h"
  111.  
  112. +//----------------------------------------------------------------------------
  113. +// CapitalLettersController
  114. +//----------------------------------------------------------------------------
  115. +
  116. +class CapitalLettersController : public QObject
  117. +{
  118. +   Q_OBJECT
  119. +public:
  120. +   CapitalLettersController(QTextEdit* parent)
  121. +       : QObject()
  122. +       , te_(parent)
  123. +       , enabled_(true)
  124. +   {
  125. +       connect(te_->document(), SIGNAL(contentsChange(int,int,int)), SLOT(textChanged(int,int,int)));
  126. +   }
  127. +
  128. +   virtual ~CapitalLettersController() {};
  129. +
  130. +   void setAutoCapitalizeEnabled(bool enabled)
  131. +   {
  132. +       enabled_ = enabled;
  133. +   }
  134. +
  135. +private:
  136. +   void capitalizeChar(int pos, QChar c)
  137. +   {
  138. +       changeChar(pos, c.toUpper());
  139. +   }
  140. +
  141. +   void decapitalizeChar(int pos, QChar c)
  142. +   {
  143. +       changeChar(pos, c.toLower());
  144. +   }
  145. +
  146. +   void changeChar(int pos, QChar c)
  147. +   {
  148. +       QTextCursor cur = te_->textCursor();
  149. +       cur.setPosition(pos+1);
  150. +       const QTextCharFormat cf = cur.charFormat();
  151. +       cur.deletePreviousChar();
  152. +       cur.setCharFormat(cf);
  153. +       cur.insertText(c);
  154. +   }
  155. +
  156. +public slots:
  157. +   void textChanged(int pos, int /*charsRemoved*/, int charsAdded)
  158. +   {
  159. +       if(enabled_) {
  160. +           if(charsAdded == 0) {
  161. +               return;
  162. +           }
  163. +           if(!te_->textCursor().atEnd()) { //Editing the letter in the middle of the text
  164. +               return;
  165. +           }
  166. +           bool capitalizeNext_ = false;
  167. +
  168. +           if(pos == 0 && charsAdded < 3) { //the first letter after the previous message was sent
  169. +               capitalizeNext_ = true;
  170. +           }
  171. +           else if (charsAdded > 1) { //Insert a piece of text
  172. +               return;
  173. +           }
  174. +           else {
  175. +               QString txt = te_->toPlainText();
  176. +               QRegExp capitalizeAfter("(?:^[^.][.]+\\s+)|(?:\\s*[^.]{2,}[.]+\\s+)|(?:[!?]\\s+)");
  177. +               int index = txt.lastIndexOf(capitalizeAfter);
  178. +               if(index != -1 && index == pos-capitalizeAfter.matchedLength()) {
  179. +                   capitalizeNext_ = true;
  180. +               }
  181. +           }
  182. +
  183. +           if(capitalizeNext_) {
  184. +               QChar ch = te_->document()->characterAt(pos);
  185. +               if(!ch.isLetter() || !ch.isLower()) {
  186. +                   return;
  187. +               }
  188. +               else {
  189. +                   capitalizeChar(pos, ch);
  190. +               }
  191. +           }
  192. +       }
  193. +   }
  194. +
  195. +   void changeCase()
  196. +   {
  197. +       bool tmpEnabled = enabled_;
  198. +       enabled_ = false;
  199. +       QTextCursor oldCur = te_->textCursor();
  200. +       int pos = oldCur.position();
  201. +       int begin = 0;
  202. +       int end = te_->document()->characterCount();
  203. +       if(oldCur.hasSelection()) {
  204. +           begin = oldCur.selectionStart();
  205. +           end = oldCur.selectionEnd();
  206. +       }
  207. +       for(; begin < end; begin++) {
  208. +           QChar ch = te_->document()->characterAt(begin);
  209. +           if(!ch.isLetter()) {
  210. +               continue;
  211. +           }
  212. +
  213. +           if(ch.isLower()) {
  214. +               capitalizeChar(begin, ch);
  215. +           }
  216. +           else {
  217. +               decapitalizeChar(begin, ch);
  218. +           }
  219. +       }
  220. +       oldCur.setPosition(pos);
  221. +       te_->setTextCursor(oldCur);
  222. +       enabled_ = tmpEnabled;
  223. +   }
  224. +
  225. +private:
  226. +   QTextEdit* te_;
  227. +   bool enabled_;
  228. +};
  229. +
  230.  
  231.  //----------------------------------------------------------------------------
  232.  // ChatEdit
  233. @@ -53,6 +171,7 @@ ChatEdit::ChatEdit(QWidget *parent)
  234.     , palCorrection(palOriginal)
  235.  {
  236.     controller_ = new HTMLTextController(this);
  237. +   capitalizer_ = new CapitalLettersController(this);
  238.  
  239.     setWordWrapMode(QTextOption::WordWrap);
  240.     setAcceptRichText(false);
  241. @@ -69,6 +188,7 @@ ChatEdit::ChatEdit(QWidget *parent)
  242.     palCorrection.setColor(QPalette::Base, QColor(160, 160, 0));
  243.     initActions();
  244.     setShortcuts();
  245. +   optionsChanged();
  246.  }
  247.  
  248.  ChatEdit::~ChatEdit()
  249. @@ -76,6 +196,12 @@ ChatEdit::~ChatEdit()
  250.     clearMessageHistory();
  251.     delete spellhighlighter_;
  252.     delete controller_;
  253. +   delete capitalizer_;
  254. +}
  255. +
  256. +CapitalLettersController * ChatEdit::capitalizer()
  257. +{
  258. +   return capitalizer_;
  259.  }
  260.  
  261.  void ChatEdit::initActions()
  262. @@ -95,6 +221,10 @@ void ChatEdit::initActions()
  263.     act_showMessageLast= new QAction(this);
  264.     addAction(act_showMessageLast);
  265.     connect(act_showMessageLast, SIGNAL(triggered()), SLOT(showHistoryMessageLast()));
  266. +
  267. +   act_changeCase = new QAction(this);
  268. +   addAction(act_changeCase);
  269. +   connect(act_changeCase, SIGNAL(triggered()), capitalizer_, SLOT(changeCase()));
  270.  }
  271.  
  272.  void ChatEdit::setShortcuts()
  273. @@ -103,6 +233,7 @@ void ChatEdit::setShortcuts()
  274.     act_showMessageNext->setShortcuts(ShortcutManager::instance()->shortcuts("chat.show-messageNext"));
  275.     act_showMessageFirst->setShortcuts(ShortcutManager::instance()->shortcuts("chat.show-messageFirst"));
  276.     act_showMessageLast->setShortcuts(ShortcutManager::instance()->shortcuts("chat.show-messageLast"));
  277. +   act_changeCase->setShortcuts(ShortcutManager::instance()->shortcuts("chat.change-case"));
  278.  }
  279.  
  280.  void ChatEdit::setDialog(QWidget* dialog)
  281. @@ -283,6 +414,7 @@ void ChatEdit::addToDictionary()
  282.  void ChatEdit::optionsChanged()
  283.  {
  284.     setCheckSpelling(checkSpellingGloballyEnabled());
  285. +   capitalizer_->setAutoCapitalizeEnabled(PsiOptions::instance()->getOption("options.ui.chat.auto-capitalize").toBool());
  286.  }
  287.  
  288.  void ChatEdit::showHistoryMessageNext()
  289. --- git.orig/src/msgmle.h
  290. +++ git/src/msgmle.h
  291. @@ -34,6 +34,7 @@ class QResizeEvent;
  292.  class QTimer;
  293.  class SpellHighlighter;
  294.  class HTMLTextController;
  295. +class CapitalLettersController;
  296.  
  297.  
  298.  class ChatEdit : public QTextEdit
  299. @@ -59,6 +60,7 @@ public:
  300.     void setLastMessageId(const QString& id) { lastId = id; }
  301.     const QString& lastMessageId() { return lastId; }
  302.     void resetCorrection() { correction = false; updateBackground(); };
  303. +   CapitalLettersController * capitalizer();
  304.  
  305.  public slots:
  306.     void appendMessageHistory(const QString& text);
  307. @@ -98,8 +100,10 @@ private:
  308.     QAction* act_showMessageNext;
  309.     QAction* act_showMessageFirst;
  310.     QAction* act_showMessageLast;
  311. +   QAction *act_changeCase;
  312.     QString currentText;
  313.     HTMLTextController *controller_;
  314. +   CapitalLettersController *capitalizer_;
  315.     bool correction;
  316.     QString lastId;
  317.     QPalette palOriginal;
  318. --- git.orig/src/options/opt_application.cpp
  319. +++ git/src/options/opt_application.cpp
  320. @@ -3,14 +3,30 @@
  321.  #include "iconwidget.h"
  322.  #include "psioptions.h"
  323.  #include "proxy.h"
  324. +#include "translationmanager.h"
  325. +#include "varlist.h"
  326. +#include "applicationinfo.h"
  327.  
  328.  #include <QCheckBox>
  329.  #include <QComboBox>
  330.  #include <QLineEdit>
  331. +#include <QSettings>
  332.  #include <QList>
  333. +#include <QMessageBox>
  334. +#include <QDir>
  335. +#ifdef HAVE_QT5
  336. +#include <QStandardPaths>
  337. +#endif
  338.  
  339.  #include "ui_opt_application.h"
  340.  
  341. +#ifdef Q_OS_WIN
  342. +   static const QString regString = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
  343. +#endif
  344. +#ifdef HAVE_FREEDESKTOP
  345. +   static const QString psiAutoStart("/.config/autostart/" APP_BIN_NAME ".desktop");
  346. +#endif
  347. +
  348.  class OptApplicationUI : public QWidget, public Ui::OptApplication
  349.  {
  350.  public:
  351. @@ -53,6 +69,7 @@ QWidget *OptionsTabApplication::widget()
  352.  
  353.  #ifdef Q_OS_MAC
  354.     d->gb_docklet->hide();
  355. +   d->ck_auto_load->hide();
  356.  #endif
  357.  
  358.     if (!haveAutoUpdater_) {
  359. @@ -101,6 +118,51 @@ void OptionsTabApplication::applyOptions
  360.  
  361.     //Proxy
  362.     ProxyManager::instance()->proxyForObject()->save();
  363. +
  364. +   // Language
  365. +   QString curLang = TranslationManager::instance()->currentLanguage();
  366. +   QString lang = d->cb_lang->currentText();
  367. +   QString itemData;
  368. +   foreach(VarListItem it, TranslationManager::instance()->availableTranslations() ) {
  369. +       if(it.data() == lang) {
  370. +           itemData = it.key();
  371. +           break;
  372. +       }
  373. +   }
  374. +   if(curLang != itemData && !itemData.isEmpty()) {
  375. +       TranslationManager::instance()->loadTranslation(itemData);
  376. +       QMessageBox::information(0, tr("Information"), tr("Some of the options you changed will only have full effect upon restart."));
  377. +   }
  378. +   QSettings s(ApplicationInfo::homeDir(ApplicationInfo::ConfigLocation) + "/psirc", QSettings::IniFormat);
  379. +   s.setValue("last_lang", itemData);
  380. +
  381. +   //Auto-load
  382. +#ifdef Q_OS_WIN
  383. +   QSettings set(regString, QSettings::NativeFormat);
  384. +   if(d->ck_auto_load->isChecked()) {
  385. +       set.setValue(ApplicationInfo::name(), QDir::toNativeSeparators(qApp->applicationFilePath()));
  386. +   }
  387. +   else {
  388. +       set.remove(ApplicationInfo::name());
  389. +   }
  390. +#endif
  391. +#ifdef HAVE_FREEDESKTOP
  392. +#ifndef HAVE_QT5
  393. +   QDir home(QString::fromLocal8Bit(getenv("XDG_CONFIG_HOME")));
  394. +#else
  395. +   QDir home(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
  396. +#endif
  397. +
  398. +   if (!home.exists("autostart")) {
  399. +       home.mkpath("autostart");
  400. +   }
  401. +   QFile f(home.absolutePath() + psiAutoStart);
  402. +   if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
  403. +       const QString contents = ApplicationInfo::desktopFile().trimmed();
  404. +       f.write(contents.toUtf8());
  405. +       f.write(QString("\nHidden=%1").arg(d->ck_auto_load->isChecked() ? "false\n" : "true\n").toUtf8());
  406. +   }
  407. +#endif
  408.  }
  409.  
  410.  void OptionsTabApplication::restoreOptions()
  411. @@ -123,6 +185,36 @@ void OptionsTabApplication::restoreOptio
  412.     // data transfer
  413.     d->le_dtPort->setText( QString::number(PsiOptions::instance()->getOption("options.p2p.bytestreams.listen-port").toInt()) );
  414.     d->le_dtExternal->setText( PsiOptions::instance()->getOption("options.p2p.bytestreams.external-address").toString() );
  415. +
  416. +   // Language
  417. +   VarList vList = TranslationManager::instance()->availableTranslations();
  418. +   QStringList lang = vList.varsToStringList();
  419. +   d->cb_lang->addItem(tr("Default"));
  420. +   foreach(QString item, lang) {
  421. +       d->cb_lang->addItem(vList.get(item));
  422. +   }
  423. +   QString curLang = TranslationManager::instance()->currentLanguage();
  424. +   QSettings s(ApplicationInfo::homeDir(ApplicationInfo::ConfigLocation) + "/psirc", QSettings::IniFormat);
  425. +   QString curL = s.value("last_lang", "").toString();
  426. +   if (curL.isEmpty())
  427. +       d->cb_lang->setCurrentIndex( 0 );
  428. +   else if(!curLang.isEmpty() && lang.contains(curLang) )
  429. +       d->cb_lang->setCurrentIndex( d->cb_lang->findText(vList.get(curLang)) );
  430. +
  431. +   //Auto-load
  432. +#ifdef Q_OS_WIN
  433. +   QSettings set(regString, QSettings::NativeFormat);
  434. +   const QString path = set.value(ApplicationInfo::name()).toString();
  435. +   d->ck_auto_load->setChecked( (path == QDir::toNativeSeparators(qApp->applicationFilePath())) );
  436. +#endif
  437. +#ifdef HAVE_FREEDESKTOP
  438. +   QFile desktop(QDir::homePath() + psiAutoStart);
  439. +   if (desktop.open(QIODevice::ReadOnly)
  440. +       && QString(desktop.readAll()).contains(QRegExp("\\bhidden\\s*=\\s*false", Qt::CaseInsensitive)))
  441. +   {
  442. +       d->ck_auto_load->setChecked(true);
  443. +   }
  444. +#endif
  445.  }
  446.  
  447.  void OptionsTabApplication::doEnableQuitOnClose(int state)
  448. --- git.orig/src/options/opt_application.ui
  449. +++ git/src/options/opt_application.ui
  450. @@ -13,6 +13,13 @@
  451.     <string>OptApplicationUI</string>
  452.    </property>
  453.    <layout class="QVBoxLayout" >
  454. +  <item>
  455. +    <widget class="QCheckBox" name="ck_auto_load">
  456. +     <property name="text">
  457. +      <string>Automatically launch application when OS starts</string>
  458. +     </property>
  459. +    </widget>
  460. +   </item>
  461.     <item>
  462.      <widget class="QCheckBox" name="ck_docklet" >
  463.       <property name="text" >
  464. @@ -179,6 +186,33 @@
  465.      </widget>
  466.     </item>
  467.     <item>
  468. +    <layout class="QHBoxLayout" name="horizontalLayout">
  469. +     <item>
  470. +      <widget class="QLabel" name="label_2">
  471. +       <property name="text">
  472. +        <string>Language</string>
  473. +       </property>
  474. +      </widget>
  475. +     </item>
  476. +     <item>
  477. +      <widget class="QComboBox" name="cb_lang"/>
  478. +     </item>
  479. +     <item>
  480. +      <spacer name="horizontalSpacer">
  481. +       <property name="orientation">
  482. +        <enum>Qt::Horizontal</enum>
  483. +       </property>
  484. +       <property name="sizeHint" stdset="0">
  485. +        <size>
  486. +         <width>40</width>
  487. +         <height>20</height>
  488. +        </size>
  489. +       </property>
  490. +      </spacer>
  491. +     </item>
  492. +    </layout>
  493. +   </item>
  494. +   <item>
  495.      <spacer>
  496.       <property name="orientation" >
  497.        <enum>Qt::Vertical</enum>
  498. --- git.orig/src/src.pri
  499. +++ git/src/src.pri
  500. @@ -9,7 +9,10 @@ greaterThan(QT_MAJOR_VERSION, 4) {
  501.     QT += x11extras
  502.    }
  503.  }
  504. -unix:!mac:DEFINES += HAVE_X11
  505. +unix:!mac {
  506. +  DEFINES += HAVE_X11
  507. +  DEFINES += HAVE_FREEDESKTOP
  508. +}
  509.  
  510.  CONFIG(debug, debug|release) {
  511.    mac: DEFINES += DEBUG_POSTFIX=\\\"_debug\\\"
  512. --- git.orig/src/src.pro
  513. +++ git/src/src.pro
  514. @@ -32,6 +32,8 @@ include(../qa/oldtest/unittest.pri)
  515. include($$top_builddir/conf.pri)
  516.  
  517. unix {
  518. +   DEFINES += APP_PREFIX=$$PREFIX
  519. +   DEFINES += APP_BIN_NAME=$$target
  520.     # Target
  521.     target.path = $$BINDIR
  522.     INSTALLS += target
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement