[SCM] ktp-kded-integration-module packaging branch, master, updated. debian/15.12.1-2-382-gbd961c2

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:14:18 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-kded-module.git;a=commitdiff;h=cc65c8b

The following commit has been merged in the master branch:
commit cc65c8b9cf823a9e3011c2bc1e235618bddd3fe3
Author: Dominik Cermak <d.cermak at arcor.de>
Date:   Tue Apr 17 18:53:44 2012 +0200

    Make it possible to restore presence on login
    
    It uses the ConnectsAutomatically property and the AutomaticPresence.
    In the kcm you can enable/disable this feature (ConnectsAutomatically
    is set) and on every presence change the new presence is set as the
    AutomaticPresence.
    This way mission-control cares for setting the saved presence as soon as
    possible.
    
    If you want to manage this manually you can change the setting in
    ktelepathyrc:
    
    [KDED]
    autoConnect=manual
    
    BUG: 281929
    BUG: 295842
    REVIEW: 104363
---
 CMakeLists.txt                   |  1 +
 autoconnect.cpp                  | 75 +++++++++++++++++++++++++++++++
 autoconnect.h                    | 97 ++++++++++++++++++++++++++++++++++++++++
 config/telepathy-kded-config.cpp | 38 +++++++++++++++-
 config/telepathy-kded-config.ui  | 69 ++++++++++++++++++++++------
 telepathy-module.cpp             | 11 ++++-
 telepathy-module.h               |  2 +
 7 files changed, 277 insertions(+), 16 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c55fa84..a87b51b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,6 +34,7 @@ set (kded_ktp_integration_module_SRCS
      telepathy-module.cpp
      autoaway.cpp
      telepathy-mpris.cpp
+     autoconnect.cpp
      error-handler.cpp
 )
 
diff --git a/autoconnect.cpp b/autoconnect.cpp
new file mode 100644
index 0000000..526b060
--- /dev/null
+++ b/autoconnect.cpp
@@ -0,0 +1,75 @@
+/*
+    Manage auto-connecting and restoring of the last presence
+    Copyright (C) 2012  Dominik Cermak <d.cermak at arcor.de>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "autoconnect.h"
+
+#include <KConfig>
+
+AutoConnect::AutoConnect(QObject *parent)
+    : QObject(parent)
+{
+    KSharedConfigPtr config = KSharedConfig::openConfig(QLatin1String("ktelepathyrc"));
+    m_kdedConfig = config->group("KDED");
+}
+
+AutoConnect::~AutoConnect()
+{
+}
+
+void AutoConnect::setAccountManager(const Tp::AccountManagerPtr &accountManager)
+{
+    m_accountManager = accountManager;
+    onSettingsChanged();
+}
+
+void AutoConnect::setAutomaticPresence(const Tp::Presence &presence)
+{
+    QString autoConnectString = m_kdedConfig.readEntry(QLatin1String("autoConnect"), modeToString(AutoConnect::Manual));
+    Mode autoConnectMode = stringToMode(autoConnectString);
+
+    // Don't interfere if the user set it to manual.
+    if (autoConnectMode != AutoConnect::Manual) {
+        Q_FOREACH(Tp::AccountPtr account, m_accountManager->allAccounts()) {
+            if ((autoConnectMode == AutoConnect::Enabled) && (account->automaticPresence() != presence)) {
+                account->setAutomaticPresence(presence);
+            } else if ((autoConnectMode == AutoConnect::Disabled) && (account->automaticPresence() != Tp::Presence::available())) {
+                // The user disabled it, so reset the automatic presence to its default value (available).
+                account->setAutomaticPresence(Tp::Presence::available());
+            }
+        }
+    }
+}
+
+void AutoConnect::onSettingsChanged()
+{
+    if (m_accountManager) {
+        QString autoConnect = m_kdedConfig.readEntry(QLatin1String("autoConnect"), modeToString(AutoConnect::Manual));
+
+        // Don't interfere if the user set it to manual.
+        if (autoConnect != modeToString(AutoConnect::Manual)) {
+            Q_FOREACH(Tp::AccountPtr account, m_accountManager->allAccounts()) {
+                if ((autoConnect == modeToString(AutoConnect::Enabled)) && (!account->connectsAutomatically())) {
+                    account->setConnectsAutomatically(true);
+                } else if ((autoConnect == modeToString(AutoConnect::Disabled)) && (account->connectsAutomatically())) {
+                    account->setConnectsAutomatically(false);
+                }
+            }
+        }
+    }
+}
diff --git a/autoconnect.h b/autoconnect.h
new file mode 100644
index 0000000..9fdf06c
--- /dev/null
+++ b/autoconnect.h
@@ -0,0 +1,97 @@
+/*
+    Manage auto-connecting and restoring of the last presence
+    Copyright (C) 2012  Dominik Cermak <d.cermak at arcor.de>
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef AUTOCONNECT_H
+#define AUTOCONNECT_H
+
+#include <TelepathyQt/AccountManager>
+
+#include <KConfigGroup>
+#include <KDebug>
+
+class AutoConnect : public QObject
+{
+
+public:
+    enum Mode {
+        Disabled,
+        Enabled,
+        Manual
+    };
+
+    AutoConnect(QObject *parent = 0 );
+    ~AutoConnect();
+
+    void setAccountManager(const Tp::AccountManagerPtr &accountManager);
+
+    /**
+     * rief Returns a string for the given enum value.
+     *
+     * \param mode The enum value to convert to a string.
+     *
+     * 
eturn The string for the enum value.
+     */
+    static inline QString modeToString(const Mode mode)
+    {
+        switch (mode) {
+        case AutoConnect::Disabled:
+            return QString::fromLatin1("disabled");
+        case AutoConnect::Enabled:
+            return QString::fromLatin1("enabled");
+        case AutoConnect::Manual:
+            return QString::fromLatin1("manual");
+        default:
+            kWarning() << "Got not recognized mode: '" << mode << "'.";
+            kWarning() << "Treat as AutoConnect::Manual (" << AutoConnect::Manual << ").";
+            return QString::fromLatin1("manual");
+        }
+    };
+
+    /**
+     * rief Returns the enum value for the given string.
+     *
+     * \param mode The string to convert to an enum value.
+     *
+     * 
eturn The enum value for the string.
+     */
+    static inline Mode stringToMode(const QString &mode)
+    {
+        if (mode == modeToString(AutoConnect::Disabled)) {
+            return AutoConnect::Disabled;
+        } else if (mode == modeToString(AutoConnect::Enabled)) {
+            return AutoConnect::Enabled;
+        } else if (mode == modeToString(AutoConnect::Manual)) {
+            return AutoConnect::Manual;
+        } else {
+            kWarning() << "Got not recognized string: '" << mode << "'. Treat as 'manual'";
+            return AutoConnect::Manual;
+        }
+    };
+
+public Q_SLOTS:
+    void onSettingsChanged();
+    void setAutomaticPresence(const Tp::Presence &presence);
+
+private:
+    Tp::AccountManagerPtr m_accountManager;
+    Tp::Presence m_presence;
+    KConfigGroup m_kdedConfig;
+};
+
+#endif // AUTOCONNECT_H
diff --git a/config/telepathy-kded-config.cpp b/config/telepathy-kded-config.cpp
index 02ef9b4..bbfc1d5 100644
--- a/config/telepathy-kded-config.cpp
+++ b/config/telepathy-kded-config.cpp
@@ -29,6 +29,7 @@
 #include <QDBusConnection>
 
 #include "column-resizer.h"
+#include "autoconnect.h"
 
 K_PLUGIN_FACTORY(KCMTelepathyKDEDModuleConfigFactory, registerPlugin<TelepathyKDEDConfig>();)
 K_EXPORT_PLUGIN(KCMTelepathyKDEDModuleConfigFactory("kcm_ktp_integration_module", "kded_ktp_integration_module"))
@@ -66,6 +67,7 @@ TelepathyKDEDConfig::TelepathyKDEDConfig(QWidget *parent, const QVariantList& ar
     resizer->addWidgetsFromLayout(ui->incomingFilesGroupBox->layout(), 0);
     resizer->addWidgetsFromLayout(ui->autoAwayGroupBox->layout(), 0);
     resizer->addWidgetsFromLayout(ui->nowPlayingGroupBox->layout(), 0);
+    resizer->addWidgetsFromLayout(ui->autoConnectGroupBox->layout(), 0);
 
     //TODO enable this when it is supported by the approver
     ui->m_autoAcceptLabel->setHidden(true);
@@ -102,6 +104,8 @@ TelepathyKDEDConfig::TelepathyKDEDConfig(QWidget *parent, const QVariantList& ar
             this, SLOT(settingsHasChanged()));
     connect(ui->m_xaMessage, SIGNAL(textChanged(QString)),
             this, SLOT(settingsHasChanged()));
+    connect(ui->m_autoConnectCheckBox, SIGNAL(stateChanged(int)),
+            this, SLOT(settingsHasChanged()));
 
     connect(ui->m_awayCheckBox, SIGNAL(clicked(bool)),
             this, SLOT(autoAwayChecked(bool)));
@@ -184,6 +188,26 @@ void TelepathyKDEDConfig::load()
     ui->m_nowPlayingText->setText(nowPlayingText);
     ui->m_nowPlayingText->setEnabled(nowPlayingEnabled);
     ui->m_tagListWidget->setEnabled(nowPlayingEnabled);
+
+    // autoconnect
+    QString autoConnectString = kdedConfig.readEntry(QLatin1String("autoConnect"), AutoConnect::modeToString(AutoConnect::Manual));
+    AutoConnect::Mode autoConnectMode = AutoConnect::stringToMode(autoConnectString);
+
+    switch (autoConnectMode) {
+    case AutoConnect::Disabled:
+        ui->m_autoConnectCheckBox->setTristate(false);
+        ui->m_autoConnectCheckBox->setChecked(false);
+        break;
+    case AutoConnect::Enabled:
+        ui->m_autoConnectCheckBox->setTristate(false);
+        ui->m_autoConnectCheckBox->setChecked(true);
+        break;
+    case AutoConnect::Manual:
+        // AutoConnect::Manual is the default
+    default:
+        ui->m_autoConnectCheckBox->setTristate(true);
+        ui->m_autoConnectCheckBox->setCheckState(Qt::PartiallyChecked);
+    }
 }
 
 void TelepathyKDEDConfig::save()
@@ -215,10 +239,22 @@ void TelepathyKDEDConfig::save()
     }
 
     kdedConfig.writeEntry(QLatin1String("nowPlayingText"), modifiedNowPlayingText);
+
+    switch (ui->m_autoConnectCheckBox->checkState()) {
+    case Qt::Unchecked:
+        kdedConfig.writeEntry(QLatin1String("autoConnect"), AutoConnect::modeToString(AutoConnect::Disabled));
+        break;
+    case Qt::PartiallyChecked:
+        kdedConfig.writeEntry(QLatin1String("autoConnect"), AutoConnect::modeToString(AutoConnect::Manual));
+        break;
+    case Qt::Checked:
+        kdedConfig.writeEntry(QLatin1String("autoConnect"), AutoConnect::modeToString(AutoConnect::Enabled));
+    }
+
     kdedConfig.sync();
 
     QDBusMessage message = QDBusMessage::createSignal(QLatin1String("/Telepathy"),
-                                                      QLatin1String( "org.kde.Telepathy"),
+                                                      QLatin1String("org.kde.Telepathy"),
                                                       QLatin1String("settingsChange"));
     QDBusConnection::sessionBus().send(message);
 }
diff --git a/config/telepathy-kded-config.ui b/config/telepathy-kded-config.ui
index e08e717..11d3bce 100644
--- a/config/telepathy-kded-config.ui
+++ b/config/telepathy-kded-config.ui
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>703</width>
-    <height>560</height>
+    <height>638</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
@@ -313,26 +313,67 @@
         </property>
        </widget>
       </item>
-      <item row="5" column="1">
-       <spacer name="verticalSpacer_3">
-        <property name="orientation">
-         <enum>Qt::Vertical</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>20</width>
-          <height>40</height>
-         </size>
+      <item row="4" column="1">
+       <widget class="NowPlayingListWidget" name="m_tagListWidget"/>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <spacer name="verticalSpacer_3">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType">
+      <enum>QSizePolicy::Fixed</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="autoConnectGroupBox">
+     <property name="title">
+      <string>Auto connect</string>
+     </property>
+     <layout class="QFormLayout" name="formLayout_3">
+      <item row="0" column="0">
+       <widget class="QLabel" name="m_autoConnectLabel">
+        <property name="text">
+         <string>Restore last presence on login:</string>
         </property>
-       </spacer>
+       </widget>
       </item>
-      <item row="4" column="1">
-       <widget class="NowPlayingListWidget" name="m_tagListWidget">
+      <item row="0" column="1">
+       <widget class="QCheckBox" name="m_autoConnectCheckBox">
+        <property name="text">
+         <string>Enabled</string>
+        </property>
        </widget>
       </item>
      </layout>
     </widget>
    </item>
+   <item>
+    <spacer name="verticalSpacer_4">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType">
+      <enum>QSizePolicy::MinimumExpanding</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
   </layout>
  </widget>
  <customwidgets>
diff --git a/telepathy-module.cpp b/telepathy-module.cpp
index ec27c98..0216c61 100644
--- a/telepathy-module.cpp
+++ b/telepathy-module.cpp
@@ -31,6 +31,7 @@
 
 #include "telepathy-mpris.h"
 #include "autoaway.h"
+#include "autoconnect.h"
 #include "error-handler.h"
 #include "telepathy-kded-module-plugin.h"
 
@@ -75,7 +76,7 @@ TelepathyModule::TelepathyModule(QObject* parent, const QList<QVariant>& args)
             SLOT(onAccountManagerReady(Tp::PendingOperation*)));
 
     QDBusConnection::sessionBus().connect(QString(), QLatin1String("/Telepathy"), QLatin1String("org.kde.Telepathy"),
-                                          QLatin1String("settingsChange"), this, SIGNAL(settingsChanged()) );
+                                          QLatin1String("settingsChange"), this, SIGNAL(settingsChanged()));
 
 }
 
@@ -108,6 +109,12 @@ void TelepathyModule::onAccountManagerReady(Tp::PendingOperation* op)
     connect(this, SIGNAL(settingsChanged()),
             m_mpris, SLOT(onSettingsChanged()));
 
+    m_autoConnect = new AutoConnect(this);
+    m_autoConnect->setAccountManager(m_accountManager);
+
+    connect(this, SIGNAL(settingsChanged()),
+            m_autoConnect, SLOT(onSettingsChanged()));
+
     //earlier in list = higher priority
     m_pluginStack << m_autoAway << m_mpris;
 
@@ -133,6 +140,8 @@ void TelepathyModule::onRequestedPresenceChanged(const KTp::Presence &presence)
     presenceConfig.writeEntry(QLatin1String("PresenceMessage"), m_globalPresence->currentPresence().statusMessage());
 
     presenceConfig.sync();
+
+    m_autoConnect->setAutomaticPresence(m_globalPresence->currentPresence());
 }
 
 void TelepathyModule::onPluginActivated(bool active)
diff --git a/telepathy-module.h b/telepathy-module.h
index 02cf37c..15666bc 100644
--- a/telepathy-module.h
+++ b/telepathy-module.h
@@ -39,6 +39,7 @@ class TelepathyKDEDModulePlugin;
 class ErrorHandler;
 class TelepathyMPRIS;
 class AutoAway;
+class AutoConnect;
 
 class TelepathyModule : public KDEDModule
 {
@@ -65,6 +66,7 @@ private:
     Tp::AccountManagerPtr    m_accountManager;
     AutoAway                *m_autoAway;
     TelepathyMPRIS          *m_mpris;
+    AutoConnect             *m_autoConnect;
     ErrorHandler            *m_errorHandler;
     KTp::GlobalPresence     *m_globalPresence;
     ContactRequestHandler   *m_contactHandler;

-- 
ktp-kded-integration-module packaging



More information about the pkg-kde-commits mailing list