File indexing completed on 2023-05-30 11:40:28

0001 /*
0002     Status managing and auto connect class
0003     Copyright (C) 2017  James D. Smith <smithjd15@gmail.com>
0004 
0005     This library is free software; you can redistribute it and/or
0006     modify it under the terms of the GNU Lesser General Public
0007     License as published by the Free Software Foundation; either
0008     version 2.1 of the License, or (at your option) any later version.
0009 
0010     This library is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013     Lesser General Public License for more details.
0014 
0015     You should have received a copy of the GNU Lesser General Public
0016     License along with this library; if not, write to the Free Software
0017     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018 */
0019 
0020 #ifndef ACCOUNTSTATUSHELPER_H
0021 #define ACCOUNTSTATUSHELPER_H
0022 
0023 #include <KConfigGroup>
0024 #include <KSharedConfig>
0025 #include <KActivities/kactivities/consumer.h>
0026 
0027 #include <QHash>
0028 #include <QDBusAbstractAdaptor>
0029 
0030 #include <TelepathyQt/AccountSet>
0031 #include <TelepathyQt/Types>
0032 
0033 /* This class contains incoming global and account presence change related
0034  * functionality. Its responsibilities include receiving and exporting
0035  * requested global and account presences, and autoconnect.
0036  */
0037 
0038 class AccountStatusHelper : public QDBusAbstractAdaptor
0039 {
0040     Q_OBJECT
0041 
0042     Q_CLASSINFO("D-Bus Interface", "org.kde.Telepathy.AccountStatusHelper")
0043     Q_PROPERTY(QVariantHash requestedAccountPresences READ requestedAccountPresences)
0044     Q_PROPERTY(Tp::SimplePresence requestedGlobalPresence READ requestedGlobalPresence)
0045 
0046 public:
0047     AccountStatusHelper(QObject *parent = 0);
0048     ~AccountStatusHelper();
0049 
0050     enum PresenceClass
0051     {
0052         Persistent = 0,
0053         Session = 1
0054     };
0055     Q_ENUM(PresenceClass)
0056 
0057     /**
0058      * \brief A hash of the accounts and account presences.
0059      *
0060      * \return A Tp::AccountPtr::uniqueIdentifier() and Tp::SimplePresence QVariantHash.
0061      */
0062     QVariantHash requestedAccountPresences() const;
0063 
0064     /**
0065      * \brief The requested global presence.
0066      *
0067      * \return A Tp::SimplePresence.
0068      */
0069     Tp::SimplePresence requestedGlobalPresence() const;
0070 
0071 public Q_SLOTS:
0072     /**
0073      * \brief Set the user requested global presence.
0074      *
0075      * \param presence A Tp::SimplePresence. A session presence of type unknown
0076      * with a status message will attach the status message to the persistent
0077      * presence. A presence type of unset will clear a presence.
0078      *
0079      * \param presenceClass The PresenceClass, e.g. Persistent or Session.
0080      */
0081     void setRequestedGlobalPresence(const Tp::SimplePresence &presence, uint presenceClass);
0082 
0083     /**
0084      * \brief Set the account user requested presence.
0085      *
0086      * \param accountUID A Tp::AccountPtr::uniqueIdentifier().
0087      *
0088      * \param presence A Tp::SimplePresence. A session presence of type unknown
0089      * with a status message will attach the status message to the persistent
0090      * presence. A presence type of unset will clear a presence.
0091      *
0092      * \param presenceClass The PresenceClass, e.g. Persistent or Session.
0093      */
0094     void setRequestedAccountPresence(const QString &accountUID, const Tp::SimplePresence &presence, uint presenceClass);
0095 
0096     void reloadConfig();
0097 
0098 Q_SIGNALS:
0099     void statusChange(const QString &accountUID = QString());
0100 
0101 private:
0102     void setDiskPresence(const QString &presenceGroup, const Tp::SimplePresence &presence, const QString &activity);
0103     Tp::SimplePresence getDiskPresence(const QString &presenceGroup, const QString &activity) const;
0104 
0105     Tp::AccountSetPtr m_enabledAccounts;
0106     KSharedConfigPtr m_telepathyConfig;
0107     KActivities::Consumer *m_activities;
0108 
0109     QHash<QString, QVariant> m_requestedAccountPresences;
0110     Tp::SimplePresence m_requestedGlobalPresence;
0111 
0112     bool m_autoConnect;
0113 };
0114 
0115 #endif // ACCOUNTSTATUSHELPER_H