[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:23:25 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=1b1ea8a

The following commit has been merged in the master branch:
commit 1b1ea8a533f72b3ccfeec554a3657ecaa9a6836e
Author: Stefan Eggers <coloncolonone at gmail.com>
Date:   Mon Mar 4 11:55:18 2013 +0000

    Combining settings in a singleton class so that there is no confusion about the current settings.
    
    Up to now the settings for where new chats open were loaded by
    ktp-text-ui on startup and not re-read anymore. Changing the settings
    in the config dialog had no immediate effect; only after the next
    start of ktp-text-ui it finally changed.
    
    Now whenever the settings get asked for the singleton provides the
    current value. Thus every change to the settings via the config dialog
    will take effect immediately.
    
    Also gives a way to easily add new settings in one place. Will be
    useful for implementing the additional settings required by bug 282201
    (make it configurable if "user is typing" gets show") which needs two
    more bools.
    
    DIGEST:
    
    REVIEW: 109268
    BUG: 316004
---
 app/telepathy-chat-ui.cpp                          |  19 +--
 app/telepathy-chat-ui.h                            |   7 -
 config/behavior-config.cpp                         |  38 ++----
 config/behavior-config.h                           |   4 +-
 lib/CMakeLists.txt                                 |   3 +
 lib/KTp/TextChatConfig                             |   6 +
 lib/text-chat-config.cpp                           | 143 +++++++++++++++++++++
 .../entity-proxy-model.h => lib/text-chat-config.h |  44 ++++---
 8 files changed, 194 insertions(+), 70 deletions(-)

diff --git a/app/telepathy-chat-ui.cpp b/app/telepathy-chat-ui.cpp
index 9202108..b604f1c 100644
--- a/app/telepathy-chat-ui.cpp
+++ b/app/telepathy-chat-ui.cpp
@@ -20,6 +20,7 @@
 #include "telepathy-chat-ui.h"
 #include "chat-tab.h"
 #include "chat-window.h"
+#include "text-chat-config.h"
 
 #include <KDebug>
 #include <KConfigGroup>
@@ -44,18 +45,6 @@ TelepathyChatUi::TelepathyChatUi(const Tp::AccountManagerPtr &accountManager)
       m_accountManager(accountManager)
 {
     kDebug();
-
-    KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
-    KConfigGroup tabConfig = config->group("Behavior");
-
-    // load the settings for new tab "open mode"
-    QString mode = tabConfig.readEntry("tabOpenMode", "FirstWindow");
-    m_openMode = FirstWindow;
-    if (mode == QLatin1String("NewWindow")) {
-        m_openMode = NewWindow;
-    } else if (mode == QLatin1String("FirstWindow")) {
-        m_openMode = FirstWindow;
-    }
 }
 
 void TelepathyChatUi::removeWindow(ChatWindow *window)
@@ -157,11 +146,11 @@ void TelepathyChatUi::handleChannels(const Tp::MethodInvocationContextPtr<> & co
 
     if (!tabFound) {
         ChatWindow* window = 0;
-        switch (m_openMode) {
-            case FirstWindow:
+        switch (TextChatConfig::instance()->openMode()) {
+            case TextChatConfig::FirstWindow:
                 window = m_chatWindows.count()?m_chatWindows[0]:createWindow();
                 break;
-            case NewWindow:
+            case TextChatConfig::NewWindow:
                 window = createWindow();
                 break;
         }
diff --git a/app/telepathy-chat-ui.h b/app/telepathy-chat-ui.h
index 70800f4..735a203 100644
--- a/app/telepathy-chat-ui.h
+++ b/app/telepathy-chat-ui.h
@@ -36,12 +36,6 @@ public:
     TelepathyChatUi(const Tp::AccountManagerPtr &accountManager);
     ~TelepathyChatUi();
 
-    enum TabOpenMode {
-        NewWindow,
-        FirstWindow,
-        LastWindow
-    };
-
     virtual void handleChannels(const Tp::MethodInvocationContextPtr<> & context,
             const Tp::AccountPtr &account,
             const Tp::ConnectionPtr &connection,
@@ -63,7 +57,6 @@ private:
 
     Tp::AccountManagerPtr m_accountManager;
     QList<ChatWindow*> m_chatWindows;
-    TabOpenMode m_openMode;
 };
 
 #endif // TELEPATHYCHATUI_H
diff --git a/config/behavior-config.cpp b/config/behavior-config.cpp
index 214ee3e..357ede0 100644
--- a/config/behavior-config.cpp
+++ b/config/behavior-config.cpp
@@ -40,8 +40,8 @@ BehaviorConfig::BehaviorConfig(QWidget *parent, const QVariantList& args)
 
     ui->setupUi(this);
 
-    ui->newTabButtonGroup->setId(ui->radioNew, TelepathyChatUi::NewWindow);
-    ui->newTabButtonGroup->setId(ui->radioZero, TelepathyChatUi::FirstWindow);
+    ui->newTabButtonGroup->setId(ui->radioNew, TextChatConfig::NewWindow);
+    ui->newTabButtonGroup->setId(ui->radioZero, TextChatConfig::FirstWindow);
 
     ui->newTabButtonGroup->button(m_openMode)->setChecked(true);
     connect(ui->newTabButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(onRadioSelected(int)));
@@ -58,37 +58,15 @@ BehaviorConfig::~BehaviorConfig()
 
 void BehaviorConfig::load()
 {
-    KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
-    KConfigGroup tabConfig = config->group("Behavior");
-
-    QString mode = tabConfig.readEntry("tabOpenMode", "NewWindow");
-    if(mode == QLatin1String("NewWindow")) {
-        m_openMode = TelepathyChatUi::NewWindow;
-    } else if (mode == QLatin1String("FirstWindow")) {
-        m_openMode = TelepathyChatUi::FirstWindow;
-    }
-
-    m_scrollbackLength = tabConfig.readEntry("scrollbackLength", 4);
+    m_openMode = TextChatConfig::instance()->openMode();
+    m_scrollbackLength = TextChatConfig::instance()->scrollbackLength();
 }
 
 void BehaviorConfig::save()
 {
-    KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
-    KConfigGroup tabConfig = config->group("Behavior");
-
-    QString mode;
-    switch (m_openMode) {
-        case TelepathyChatUi::NewWindow :
-            mode = QLatin1String("NewWindow");
-            break;
-        case TelepathyChatUi::FirstWindow :
-            mode = QLatin1String("FirstWindow");
-            break;
-    }
-
-    tabConfig.writeEntry("tabOpenMode", mode);
-    tabConfig.writeEntry("scrollbackLength", m_scrollbackLength);
-    tabConfig.sync();
+    TextChatConfig::instance()->setOpenMode(m_openMode);
+    TextChatConfig::instance()->setScrollbackLength(m_scrollbackLength);
+    TextChatConfig::instance()->sync();
 }
 
 void BehaviorConfig::changeEvent(QEvent* e)
@@ -106,7 +84,7 @@ void BehaviorConfig::changeEvent(QEvent* e)
 void BehaviorConfig::onRadioSelected(int id)
 {
     kDebug() << "BehaviorConfig::m_openMode changed from " << id << " to " << m_openMode;
-    m_openMode = (TelepathyChatUi::TabOpenMode) id;
+    m_openMode = (TextChatConfig::TabOpenMode) id;
     kDebug() << "emitting changed(true)";
     Q_EMIT changed(true);
 }
diff --git a/config/behavior-config.h b/config/behavior-config.h
index 562187e..fa0f686 100644
--- a/config/behavior-config.h
+++ b/config/behavior-config.h
@@ -24,7 +24,7 @@
 #define BEHAVIOR_CONFIG_H
 
 #include <KCModule>
-#include "../app/telepathy-chat-ui.h"
+#include "text-chat-config.h"
 
 namespace Ui {
 class BehaviorConfigUi;
@@ -50,7 +50,7 @@ private Q_SLOTS:
     void onScrollbackLengthChanged();
 
 private:
-    int m_openMode;
+    TextChatConfig::TabOpenMode m_openMode;
     int m_scrollbackLength;
     Ui::BehaviorConfigUi *ui;
 };
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 4e03671..3df62af 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -15,6 +15,7 @@ set(ktpchat_SRCS
         chat-search-bar.cpp
         logmanager.cpp
         notify-filter.cpp
+        text-chat-config.cpp
 )
 
 set(ktpchat_HDRS
@@ -27,6 +28,7 @@ set(ktpchat_HDRS
     chat-widget.h
     chat-window-style.h
     chat-window-style-manager.h
+    text-chat-config.h
 )
 
 set(ktpchat_PRETTY_HDRS
@@ -39,6 +41,7 @@ set(ktpchat_PRETTY_HDRS
     KTp/ChatWidget
     KTp/ChatWindowStyle
     KTp/ChatWindowStyleManager
+    KTp/TextChatConfig
 )
 
 set(ktpchat_UI
diff --git a/lib/KTp/TextChatConfig b/lib/KTp/TextChatConfig
new file mode 100644
index 0000000..bcc64a2
--- /dev/null
+++ b/lib/KTp/TextChatConfig
@@ -0,0 +1,6 @@
+#ifndef KDE_TELEPATHY_TEXT_UI_TEXT_CHAT_CONFIG
+#define KDE_TELEPATHY_TEXT_UI_TEXT_CHAT_CONFIG
+
+#include "text-chat-config.h"
+
+#endif
diff --git a/lib/text-chat-config.cpp b/lib/text-chat-config.cpp
new file mode 100644
index 0000000..70cf368
--- /dev/null
+++ b/lib/text-chat-config.cpp
@@ -0,0 +1,143 @@
+/***************************************************************************
+ *   Copyright (C) 2011 by Lasath Fernando <kde at lasath.org>                *
+ *   Copyright (C) 2011 by David Edmundson <kde at davidedmundson.co.uk>      *
+ *   Copyright (C) 2013 by Stefan Eggers <coloncolonone at gmail.com>         *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+
+#include <KConfigGroup>
+#include <KSharedConfig>
+
+#include "text-chat-config.h"
+
+
+QMutex TextChatConfig::mutex(QMutex::Recursive);
+
+
+class TextChatConfigPrivate
+{
+public:
+    TextChatConfig::TabOpenMode m_openMode;
+    int m_scrollbackLength;
+};
+
+
+TextChatConfig *TextChatConfig::instance()
+{
+    static TextChatConfig *instance = 0;
+
+    mutex.lock();
+
+    if (!instance) {
+        instance = new TextChatConfig();
+    }
+
+    mutex.unlock();
+
+    // if instance was already setup the mutex protected block won't have
+    // changed it; if we were the first and instance was still 0 we set it up
+    // inside the mutex protected block and instance won't ever change again;
+    // thus this is allowed to be outside the mutex protected block
+    return instance;
+}
+
+
+void TextChatConfig::sync()
+{
+    mutex.lock();
+
+    KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
+    KConfigGroup behaviorConfig = config->group("Behavior");
+
+    QString mode;
+    if (d->m_openMode == TextChatConfig::NewWindow) {
+	mode = QLatin1String("NewWindow");
+    } else {
+        mode = QLatin1String("FirstWindow");
+    }
+    behaviorConfig.writeEntry("tabOpenMode", mode);
+
+    behaviorConfig.writeEntry("scrollbackLength", d->m_scrollbackLength);
+
+    behaviorConfig.sync();
+
+    mutex.unlock();
+}
+
+
+TextChatConfig::TabOpenMode TextChatConfig::openMode()
+{
+    TextChatConfig::TabOpenMode result;
+
+    mutex.lock();
+    result = d->m_openMode;
+    mutex.unlock();
+
+    return result;
+}
+
+
+void TextChatConfig::setOpenMode(TextChatConfig::TabOpenMode mode)
+{
+    mutex.lock();
+    d->m_openMode = mode;
+    mutex.unlock();
+}
+
+
+int TextChatConfig::scrollbackLength()
+{
+    int result;
+
+    mutex.lock();
+    result = d->m_scrollbackLength;
+    mutex.unlock();
+
+    return result;
+}
+
+
+void TextChatConfig::setScrollbackLength(int length)
+{
+    mutex.lock();
+    d->m_scrollbackLength = length;
+    mutex.unlock();
+}
+
+
+TextChatConfig::TextChatConfig() :
+    d(new TextChatConfigPrivate())
+{
+    // only ever called from TextChatConfig::instance() while mutex is locked
+    // thus no own mutex use inside the constructor
+
+    KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
+    KConfigGroup behaviorConfig = config->group("Behavior");
+
+    QString mode = behaviorConfig.readEntry("tabOpenMode", "NewWindow");
+    if(mode == QLatin1String("NewWindow")) {
+        d->m_openMode = TextChatConfig::NewWindow;
+    } else {
+        d->m_openMode = TextChatConfig::FirstWindow;
+    }
+
+    d->m_scrollbackLength = behaviorConfig.readEntry("scrollbackLength", 4);
+}
+
+
+#include "text-chat-config.moc"
diff --git a/logviewer/entity-proxy-model.h b/lib/text-chat-config.h
similarity index 62%
copy from logviewer/entity-proxy-model.h
copy to lib/text-chat-config.h
index 78dd071..95c14e1 100644
--- a/logviewer/entity-proxy-model.h
+++ b/lib/text-chat-config.h
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2012 by Dan Vratil <dan at progdan.cz>                     *
+ *   Copyright (C) 2013 by Stefan Eggers <coloncolonone at gmail.com>         *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -17,32 +17,44 @@
  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
  ***************************************************************************/
 
+#ifndef TEXT_CHAT_CONFIG_H
+#define TEXT_CHAT_CONFIG_H
 
-#ifndef ENTITY_PROXY_MODEL_H
-#define ENTITY_PROXY_MODEL_H
+#include <QtCore/QMutex>
+#include <QtCore/QObject>
 
-#include <QSortFilterProxyModel>
-#include <TelepathyLoggerQt4/Types>
+#include "ktpchat_export.h"
 
-typedef QPair< Tp::AccountPtr, Tpl::EntityPtr > AccountEntityPair;
+class TextChatConfigPrivate;
 
-class EntityProxyModel : public QSortFilterProxyModel
+class KDE_TELEPATHY_CHAT_EXPORT TextChatConfig : QObject
 {
     Q_OBJECT
 
-public:
-    explicit EntityProxyModel(QObject *parent = 0);
-    virtual ~EntityProxyModel();
+  public:
+    enum TabOpenMode {
+        NewWindow,
+        FirstWindow
+    };
 
-    void setSearchHits(const Tpl::SearchHitList &searchHits);
-    void clearSearchHits();
+    // settings get loaded when instance gets created
+    static TextChatConfig *instance();
 
-protected:
-    bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
+    // write out current settings to file
+    void sync();
+
+    TabOpenMode openMode();
+    void setOpenMode(TabOpenMode mode);
+
+    int scrollbackLength();
+    void setScrollbackLength(int length);
 
 private:
-    Tpl::SearchHitList m_searchHits;
+    TextChatConfig();
+
+    static QMutex mutex;
 
+    const QScopedPointer<TextChatConfigPrivate> d;
 };
 
-#endif // ENTITY_PROXY_MODEL_H
+#endif // TEXT_CHAT_CONFIG_H

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list