Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- git.orig/options/default.xml
- +++ git/options/default.xml
- @@ -93,6 +93,7 @@
- <enabled comment="Enable message (i.e. non-chat) functionality" type="bool">true</enabled>
- <auto-grab-urls-from-clipboard type="bool">false</auto-grab-urls-from-clipboard>
- <auto-popup type="bool">false</auto-popup>
- + <auto-capitalize type="bool">false</auto-capitalize>
- <auto-popup-headlines type="bool">false</auto-popup-headlines>
- <show-character-count type="bool">false</show-character-count>
- <show-subjects type="bool">true</show-subjects>
- @@ -467,6 +468,7 @@
- <show-messageFirst type="QKeySequence" comment="Show first message" >Alt+End</show-messageFirst>
- <show-messageNext type="QKeySequence" comment="Show next message" >Ctrl+Down</show-messageNext>
- <show-messagePrev type="QKeySequence" comment="Show prev message" >Ctrl+Up</show-messagePrev>
- + <change-case type="QKeySequence" comment="Change case of letters in the chat edit" >Ctrl+Alt+x</change-case>
- </chat>
- <contactlist comment="Shortcuts in the contactlist">
- <assign-custom-avatar type="QKeySequence" comment="Assign a custom avatar to the selected contact"/>
- --- git.orig/src/applicationinfo.cpp
- +++ git/src/applicationinfo.cpp
- @@ -10,7 +10,7 @@
- #include <QStandardPaths>
- #endif
- -#ifdef HAVE_X11
- +#ifdef Q_OS_UNIX
- #include <sys/stat.h> // chmod
- #endif
- @@ -36,6 +36,9 @@
- #include "config.h"
- #endif
- +#define xstr(a) str(a)
- +#define str(a) #a
- +
- // Constants. These should be moved to a more 'dynamically changeable'
- // place (like an external file loaded through the resources system)
- // Should also be overridable through an optional file.
- @@ -58,11 +61,6 @@
- #define PROG_APPCAST_URL ""
- #endif
- -#if defined(HAVE_X11) && !defined(PSI_DATADIR)
- -#define PSI_DATADIR "/usr/local/share/psi"
- -#endif
- -
- -
- QString ApplicationInfo::name()
- {
- return PROG_NAME;
- @@ -141,7 +139,7 @@ QString ApplicationInfo::getCertificateS
- QString ApplicationInfo::resourcesDir()
- {
- -#if defined(HAVE_X11)
- +#if defined(Q_OS_UNIX)
- return PSI_DATADIR;
- #elif defined(Q_OS_WIN)
- return qApp->applicationDirPath();
- @@ -238,10 +236,16 @@ QString ApplicationInfo::homeDir(Applica
- QDir configDir(QDir::homePath() + "/Library/Application Support/" + name());
- QDir cacheDir(QDir::homePath() + "/Library/Caches/" + name());
- QDir dataDir(configDir);
- -#elif defined HAVE_X11
- +#elif defined HAVE_FREEDESKTOP
- +#ifndef HAVE_QT5
- QString XdgConfigHome = QString::fromLocal8Bit(getenv("XDG_CONFIG_HOME"));
- QString XdgDataHome = QString::fromLocal8Bit(getenv("XDG_DATA_HOME"));
- QString XdgCacheHome = QString::fromLocal8Bit(getenv("XDG_CACHE_HOME"));
- +#else
- + QString XdgConfigHome(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
- + QString XdgDataHome(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
- + QString XdgCacheHome(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
- +#endif
- if (XdgConfigHome.isEmpty()) {
- XdgConfigHome = QDir::homePath() + "/.config";
- }
- @@ -383,3 +387,14 @@ QString ApplicationInfo::currentProfileD
- {
- return pathToProfile(activeProfile, type);
- }
- +
- +QString ApplicationInfo::desktopFile()
- +{
- + QString dFile;
- + const QString _desktopFile(xstr(APP_PREFIX) "/share/applications/" xstr(APP_BIN_NAME) ".desktop");
- + QFile f(_desktopFile);
- + if(f.open(QIODevice::ReadOnly)) {
- + dFile = QString::fromUtf8(f.readAll());
- + }
- + return dFile;
- +}
- --- git.orig/src/applicationinfo.h
- +++ git/src/applicationinfo.h
- @@ -44,6 +44,9 @@ public:
- static QString optionsNS();
- static QString storageNS();
- static QString fileCacheNS();
- +
- + // Common
- + static QString desktopFile();
- };
- #endif
- --- git.orig/src/msgmle.cpp
- +++ git/src/msgmle.cpp
- @@ -40,6 +40,124 @@
- #include "psioptions.h"
- #include "htmltextcontroller.h"
- +//----------------------------------------------------------------------------
- +// CapitalLettersController
- +//----------------------------------------------------------------------------
- +
- +class CapitalLettersController : public QObject
- +{
- + Q_OBJECT
- +public:
- + CapitalLettersController(QTextEdit* parent)
- + : QObject()
- + , te_(parent)
- + , enabled_(true)
- + {
- + connect(te_->document(), SIGNAL(contentsChange(int,int,int)), SLOT(textChanged(int,int,int)));
- + }
- +
- + virtual ~CapitalLettersController() {};
- +
- + void setAutoCapitalizeEnabled(bool enabled)
- + {
- + enabled_ = enabled;
- + }
- +
- +private:
- + void capitalizeChar(int pos, QChar c)
- + {
- + changeChar(pos, c.toUpper());
- + }
- +
- + void decapitalizeChar(int pos, QChar c)
- + {
- + changeChar(pos, c.toLower());
- + }
- +
- + void changeChar(int pos, QChar c)
- + {
- + QTextCursor cur = te_->textCursor();
- + cur.setPosition(pos+1);
- + const QTextCharFormat cf = cur.charFormat();
- + cur.deletePreviousChar();
- + cur.setCharFormat(cf);
- + cur.insertText(c);
- + }
- +
- +public slots:
- + void textChanged(int pos, int /*charsRemoved*/, int charsAdded)
- + {
- + if(enabled_) {
- + if(charsAdded == 0) {
- + return;
- + }
- + if(!te_->textCursor().atEnd()) { //Editing the letter in the middle of the text
- + return;
- + }
- + bool capitalizeNext_ = false;
- +
- + if(pos == 0 && charsAdded < 3) { //the first letter after the previous message was sent
- + capitalizeNext_ = true;
- + }
- + else if (charsAdded > 1) { //Insert a piece of text
- + return;
- + }
- + else {
- + QString txt = te_->toPlainText();
- + QRegExp capitalizeAfter("(?:^[^.][.]+\\s+)|(?:\\s*[^.]{2,}[.]+\\s+)|(?:[!?]\\s+)");
- + int index = txt.lastIndexOf(capitalizeAfter);
- + if(index != -1 && index == pos-capitalizeAfter.matchedLength()) {
- + capitalizeNext_ = true;
- + }
- + }
- +
- + if(capitalizeNext_) {
- + QChar ch = te_->document()->characterAt(pos);
- + if(!ch.isLetter() || !ch.isLower()) {
- + return;
- + }
- + else {
- + capitalizeChar(pos, ch);
- + }
- + }
- + }
- + }
- +
- + void changeCase()
- + {
- + bool tmpEnabled = enabled_;
- + enabled_ = false;
- + QTextCursor oldCur = te_->textCursor();
- + int pos = oldCur.position();
- + int begin = 0;
- + int end = te_->document()->characterCount();
- + if(oldCur.hasSelection()) {
- + begin = oldCur.selectionStart();
- + end = oldCur.selectionEnd();
- + }
- + for(; begin < end; begin++) {
- + QChar ch = te_->document()->characterAt(begin);
- + if(!ch.isLetter()) {
- + continue;
- + }
- +
- + if(ch.isLower()) {
- + capitalizeChar(begin, ch);
- + }
- + else {
- + decapitalizeChar(begin, ch);
- + }
- + }
- + oldCur.setPosition(pos);
- + te_->setTextCursor(oldCur);
- + enabled_ = tmpEnabled;
- + }
- +
- +private:
- + QTextEdit* te_;
- + bool enabled_;
- +};
- +
- //----------------------------------------------------------------------------
- // ChatEdit
- @@ -53,6 +171,7 @@ ChatEdit::ChatEdit(QWidget *parent)
- , palCorrection(palOriginal)
- {
- controller_ = new HTMLTextController(this);
- + capitalizer_ = new CapitalLettersController(this);
- setWordWrapMode(QTextOption::WordWrap);
- setAcceptRichText(false);
- @@ -69,6 +188,7 @@ ChatEdit::ChatEdit(QWidget *parent)
- palCorrection.setColor(QPalette::Base, QColor(160, 160, 0));
- initActions();
- setShortcuts();
- + optionsChanged();
- }
- ChatEdit::~ChatEdit()
- @@ -76,6 +196,12 @@ ChatEdit::~ChatEdit()
- clearMessageHistory();
- delete spellhighlighter_;
- delete controller_;
- + delete capitalizer_;
- +}
- +
- +CapitalLettersController * ChatEdit::capitalizer()
- +{
- + return capitalizer_;
- }
- void ChatEdit::initActions()
- @@ -95,6 +221,10 @@ void ChatEdit::initActions()
- act_showMessageLast= new QAction(this);
- addAction(act_showMessageLast);
- connect(act_showMessageLast, SIGNAL(triggered()), SLOT(showHistoryMessageLast()));
- +
- + act_changeCase = new QAction(this);
- + addAction(act_changeCase);
- + connect(act_changeCase, SIGNAL(triggered()), capitalizer_, SLOT(changeCase()));
- }
- void ChatEdit::setShortcuts()
- @@ -103,6 +233,7 @@ void ChatEdit::setShortcuts()
- act_showMessageNext->setShortcuts(ShortcutManager::instance()->shortcuts("chat.show-messageNext"));
- act_showMessageFirst->setShortcuts(ShortcutManager::instance()->shortcuts("chat.show-messageFirst"));
- act_showMessageLast->setShortcuts(ShortcutManager::instance()->shortcuts("chat.show-messageLast"));
- + act_changeCase->setShortcuts(ShortcutManager::instance()->shortcuts("chat.change-case"));
- }
- void ChatEdit::setDialog(QWidget* dialog)
- @@ -283,6 +414,7 @@ void ChatEdit::addToDictionary()
- void ChatEdit::optionsChanged()
- {
- setCheckSpelling(checkSpellingGloballyEnabled());
- + capitalizer_->setAutoCapitalizeEnabled(PsiOptions::instance()->getOption("options.ui.chat.auto-capitalize").toBool());
- }
- void ChatEdit::showHistoryMessageNext()
- --- git.orig/src/msgmle.h
- +++ git/src/msgmle.h
- @@ -34,6 +34,7 @@ class QResizeEvent;
- class QTimer;
- class SpellHighlighter;
- class HTMLTextController;
- +class CapitalLettersController;
- class ChatEdit : public QTextEdit
- @@ -59,6 +60,7 @@ public:
- void setLastMessageId(const QString& id) { lastId = id; }
- const QString& lastMessageId() { return lastId; }
- void resetCorrection() { correction = false; updateBackground(); };
- + CapitalLettersController * capitalizer();
- public slots:
- void appendMessageHistory(const QString& text);
- @@ -98,8 +100,10 @@ private:
- QAction* act_showMessageNext;
- QAction* act_showMessageFirst;
- QAction* act_showMessageLast;
- + QAction *act_changeCase;
- QString currentText;
- HTMLTextController *controller_;
- + CapitalLettersController *capitalizer_;
- bool correction;
- QString lastId;
- QPalette palOriginal;
- --- git.orig/src/options/opt_application.cpp
- +++ git/src/options/opt_application.cpp
- @@ -3,14 +3,30 @@
- #include "iconwidget.h"
- #include "psioptions.h"
- #include "proxy.h"
- +#include "translationmanager.h"
- +#include "varlist.h"
- +#include "applicationinfo.h"
- #include <QCheckBox>
- #include <QComboBox>
- #include <QLineEdit>
- +#include <QSettings>
- #include <QList>
- +#include <QMessageBox>
- +#include <QDir>
- +#ifdef HAVE_QT5
- +#include <QStandardPaths>
- +#endif
- #include "ui_opt_application.h"
- +#ifdef Q_OS_WIN
- + static const QString regString = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run";
- +#endif
- +#ifdef HAVE_FREEDESKTOP
- + static const QString psiAutoStart("/.config/autostart/" APP_BIN_NAME ".desktop");
- +#endif
- +
- class OptApplicationUI : public QWidget, public Ui::OptApplication
- {
- public:
- @@ -53,6 +69,7 @@ QWidget *OptionsTabApplication::widget()
- #ifdef Q_OS_MAC
- d->gb_docklet->hide();
- + d->ck_auto_load->hide();
- #endif
- if (!haveAutoUpdater_) {
- @@ -101,6 +118,51 @@ void OptionsTabApplication::applyOptions
- //Proxy
- ProxyManager::instance()->proxyForObject()->save();
- +
- + // Language
- + QString curLang = TranslationManager::instance()->currentLanguage();
- + QString lang = d->cb_lang->currentText();
- + QString itemData;
- + foreach(VarListItem it, TranslationManager::instance()->availableTranslations() ) {
- + if(it.data() == lang) {
- + itemData = it.key();
- + break;
- + }
- + }
- + if(curLang != itemData && !itemData.isEmpty()) {
- + TranslationManager::instance()->loadTranslation(itemData);
- + QMessageBox::information(0, tr("Information"), tr("Some of the options you changed will only have full effect upon restart."));
- + }
- + QSettings s(ApplicationInfo::homeDir(ApplicationInfo::ConfigLocation) + "/psirc", QSettings::IniFormat);
- + s.setValue("last_lang", itemData);
- +
- + //Auto-load
- +#ifdef Q_OS_WIN
- + QSettings set(regString, QSettings::NativeFormat);
- + if(d->ck_auto_load->isChecked()) {
- + set.setValue(ApplicationInfo::name(), QDir::toNativeSeparators(qApp->applicationFilePath()));
- + }
- + else {
- + set.remove(ApplicationInfo::name());
- + }
- +#endif
- +#ifdef HAVE_FREEDESKTOP
- +#ifndef HAVE_QT5
- + QDir home(QString::fromLocal8Bit(getenv("XDG_CONFIG_HOME")));
- +#else
- + QDir home(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation));
- +#endif
- +
- + if (!home.exists("autostart")) {
- + home.mkpath("autostart");
- + }
- + QFile f(home.absolutePath() + psiAutoStart);
- + if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
- + const QString contents = ApplicationInfo::desktopFile().trimmed();
- + f.write(contents.toUtf8());
- + f.write(QString("\nHidden=%1").arg(d->ck_auto_load->isChecked() ? "false\n" : "true\n").toUtf8());
- + }
- +#endif
- }
- void OptionsTabApplication::restoreOptions()
- @@ -123,6 +185,36 @@ void OptionsTabApplication::restoreOptio
- // data transfer
- d->le_dtPort->setText( QString::number(PsiOptions::instance()->getOption("options.p2p.bytestreams.listen-port").toInt()) );
- d->le_dtExternal->setText( PsiOptions::instance()->getOption("options.p2p.bytestreams.external-address").toString() );
- +
- + // Language
- + VarList vList = TranslationManager::instance()->availableTranslations();
- + QStringList lang = vList.varsToStringList();
- + d->cb_lang->addItem(tr("Default"));
- + foreach(QString item, lang) {
- + d->cb_lang->addItem(vList.get(item));
- + }
- + QString curLang = TranslationManager::instance()->currentLanguage();
- + QSettings s(ApplicationInfo::homeDir(ApplicationInfo::ConfigLocation) + "/psirc", QSettings::IniFormat);
- + QString curL = s.value("last_lang", "").toString();
- + if (curL.isEmpty())
- + d->cb_lang->setCurrentIndex( 0 );
- + else if(!curLang.isEmpty() && lang.contains(curLang) )
- + d->cb_lang->setCurrentIndex( d->cb_lang->findText(vList.get(curLang)) );
- +
- + //Auto-load
- +#ifdef Q_OS_WIN
- + QSettings set(regString, QSettings::NativeFormat);
- + const QString path = set.value(ApplicationInfo::name()).toString();
- + d->ck_auto_load->setChecked( (path == QDir::toNativeSeparators(qApp->applicationFilePath())) );
- +#endif
- +#ifdef HAVE_FREEDESKTOP
- + QFile desktop(QDir::homePath() + psiAutoStart);
- + if (desktop.open(QIODevice::ReadOnly)
- + && QString(desktop.readAll()).contains(QRegExp("\\bhidden\\s*=\\s*false", Qt::CaseInsensitive)))
- + {
- + d->ck_auto_load->setChecked(true);
- + }
- +#endif
- }
- void OptionsTabApplication::doEnableQuitOnClose(int state)
- --- git.orig/src/options/opt_application.ui
- +++ git/src/options/opt_application.ui
- @@ -13,6 +13,13 @@
- <string>OptApplicationUI</string>
- </property>
- <layout class="QVBoxLayout" >
- + <item>
- + <widget class="QCheckBox" name="ck_auto_load">
- + <property name="text">
- + <string>Automatically launch application when OS starts</string>
- + </property>
- + </widget>
- + </item>
- <item>
- <widget class="QCheckBox" name="ck_docklet" >
- <property name="text" >
- @@ -179,6 +186,33 @@
- </widget>
- </item>
- <item>
- + <layout class="QHBoxLayout" name="horizontalLayout">
- + <item>
- + <widget class="QLabel" name="label_2">
- + <property name="text">
- + <string>Language</string>
- + </property>
- + </widget>
- + </item>
- + <item>
- + <widget class="QComboBox" name="cb_lang"/>
- + </item>
- + <item>
- + <spacer name="horizontalSpacer">
- + <property name="orientation">
- + <enum>Qt::Horizontal</enum>
- + </property>
- + <property name="sizeHint" stdset="0">
- + <size>
- + <width>40</width>
- + <height>20</height>
- + </size>
- + </property>
- + </spacer>
- + </item>
- + </layout>
- + </item>
- + <item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Vertical</enum>
- --- git.orig/src/src.pri
- +++ git/src/src.pri
- @@ -9,7 +9,10 @@ greaterThan(QT_MAJOR_VERSION, 4) {
- QT += x11extras
- }
- }
- -unix:!mac:DEFINES += HAVE_X11
- +unix:!mac {
- + DEFINES += HAVE_X11
- + DEFINES += HAVE_FREEDESKTOP
- +}
- CONFIG(debug, debug|release) {
- mac: DEFINES += DEBUG_POSTFIX=\\\"_debug\\\"
- --- git.orig/src/src.pro
- +++ git/src/src.pro
- @@ -32,6 +32,8 @@ include(../qa/oldtest/unittest.pri)
- include($$top_builddir/conf.pri)
- unix {
- + DEFINES += APP_PREFIX=$$PREFIX
- + DEFINES += APP_BIN_NAME=$$target
- # Target
- target.path = $$BINDIR
- INSTALLS += target
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement