File indexing completed on 2023-10-01 08:41:45

0001 /*
0002     Copyright (C) 2013 David Edmundson <davidedmundson@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Lesser General Public
0006     License as published by the Free Software Foundation; either
0007     version 2.1 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Lesser General Public License for more details.
0013 
0014     You should have received a copy of the GNU Lesser General Public
0015     License along with this library; if not, write to the Free Software
0016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0017 */
0018 
0019 #ifndef KTP_PERSISTENTCONTACT_H
0020 #define KTP_PERSISTENTCONTACT_H
0021 
0022 #include <QObject>
0023 
0024 #include "KTp/contact.h"
0025 
0026 #include <KTp/ktpcommoninternals_export.h>
0027 
0028 namespace KTp {
0029 
0030 /** Object monitors a specific account/contact identifier and will populate it with the most up-to-date contact as connections get destroyed/created
0031  *
0032  */
0033 class KTPCOMMONINTERNALS_EXPORT PersistentContact : public QObject, public Tp::RefCounted
0034 {
0035     Q_OBJECT
0036 public:
0037     static Tp::SharedPtr<KTp::PersistentContact> create(const QString &accountId, const QString &contactId);
0038     ~PersistentContact() override;
0039 
0040     QString contactId() const;
0041     QString accountId() const;
0042 
0043     /**
0044      * This does nothing. Do not use
0045      */
0046     void KTPCOMMONINTERNALS_DEPRECATED setAccountManager(const Tp::AccountManagerPtr &accountManager);
0047 
0048     /** The contact object for these ID
0049       @warning This may be null whilst loading or if you are offline
0050     */
0051     KTp::ContactPtr contact() const;
0052 
0053     /**
0054      * @warning This may be null whilst loading or if the account has been deleted
0055      */
0056     Tp::AccountPtr account() const;
0057 
0058 Q_SIGNALS:
0059     /** Signals that the contact object has been replaced*/
0060     void contactChanged(KTp::ContactPtr);
0061 
0062 private Q_SLOTS:
0063     void onAccountReady(Tp::PendingOperation *op);
0064     void onAccountConnectionChanged(const Tp::ConnectionPtr &connection);
0065     void onPendingContactsFinished(Tp::PendingOperation*);
0066     void onContactInvalid();
0067 
0068 private:
0069     PersistentContact(const QString &accountId, const QString &contactId);
0070 
0071     class Private;
0072     Private *d;
0073 };
0074 
0075 typedef Tp::SharedPtr<KTp::PersistentContact> PersistentContactPtr;
0076 
0077 }
0078 #endif // PERSISTENTCONTACT_H