| Home · All Classes · All Namespaces · Modules · Functions · Files

presence.h

    00001
    00023 #ifndef _TelepathyQt_presence_h_HEADER_GUARD_
    00024 #define _TelepathyQt_presence_h_HEADER_GUARD_
    00025
    00026 #ifndef IN_TP_QT_HEADER
    00027 #error IN_TP_QT_HEADER
    00028 #endif
    00029
    00030 #include <TelepathyQt/Constants>
    00031 #include <TelepathyQt/Types>
    00032
    00033 namespace Tp
    00034 {
    00035
    00036 class TP_QT_EXPORT Presence
    00037 {
    00038 public:
    00039     Presence();
    00040     Presence(const SimplePresence &sp);
    00041     Presence(ConnectionPresenceType type, const QString &status, const QString &statusMessage);
    00042     Presence(const Presence &other);
    00043     ~Presence();
    00044
    00045     static Presence available(const QString &statusMessage = QString());
    00046     static Presence chat(const QString &statusMessage = QString());
    00047     static Presence away(const QString &statusMessage = QString());
    00048     static Presence brb(const QString &statusMessage = QString());
    00049     static Presence busy(const QString &statusMessage = QString());
    00050     static Presence dnd(const QString &statusMessage = QString());
    00051     static Presence xa(const QString &statusMessage = QString());
    00052     static Presence hidden(const QString &statusMessage = QString());
    00053     static Presence offline(const QString &statusMessage = QString());
    00054
    00055     bool isValid() const { return mPriv.constData() != 0; }
    00056
    00057     Presence &operator=(const Presence &other);
    00058     bool operator==(const Presence &other) const;
    00059     bool operator!=(const Presence &other) const;
    00060
    00061     ConnectionPresenceType type() const;
    00062     QString status() const;
    00063     QString statusMessage() const;
    00064     void setStatus(const SimplePresence &value);
    00065     void setStatus(ConnectionPresenceType type, const QString &status,
    00066             const QString &statusMessage);
    00067     void setStatusMessage(const QString &statusMessage);
    00068
    00069     SimplePresence barePresence() const;
    00070
    00071 private:
    00072     struct Private;
    00073     friend struct Private;
    00074     QSharedDataPointer<Private> mPriv;
    00075 };
    00076
    00077 class TP_QT_EXPORT PresenceSpec
    00078 {
    00079 public:
    00080     enum SimpleStatusFlag {
    00081         NoFlags = 0,
    00082         MaySetOnSelf = 0x1,
    00083         CanHaveStatusMessage = 0x2,
    00084         AllFlags = MaySetOnSelf | CanHaveStatusMessage
    00085     };
    00086     Q_DECLARE_FLAGS(SimpleStatusFlags, SimpleStatusFlag);
    00087
    00088     PresenceSpec();
    00089     PresenceSpec(const QString &status, const SimpleStatusSpec &spec);
    00090     PresenceSpec(const PresenceSpec &other);
    00091     ~PresenceSpec();
    00092
    00093     static PresenceSpec available(SimpleStatusFlags flags = AllFlags);
    00094     static PresenceSpec chat(SimpleStatusFlags flags = AllFlags);
    00095     static PresenceSpec pstn(SimpleStatusFlags flags = CanHaveStatusMessage);
    00096     static PresenceSpec away(SimpleStatusFlags flags = AllFlags);
    00097     static PresenceSpec brb(SimpleStatusFlags flags = AllFlags);
    00098     static PresenceSpec dnd(SimpleStatusFlags flags = AllFlags);
    00099     static PresenceSpec busy(SimpleStatusFlags flags = AllFlags);
    00100     static PresenceSpec xa(SimpleStatusFlags flags = AllFlags);
    00101     static PresenceSpec hidden(SimpleStatusFlags flags = AllFlags);
    00102     static PresenceSpec offline(SimpleStatusFlags flags = CanHaveStatusMessage);
    00103     static PresenceSpec unknown(SimpleStatusFlags flags = CanHaveStatusMessage);
    00104     static PresenceSpec error(SimpleStatusFlags flags = CanHaveStatusMessage);
    00105
    00106     bool isValid() const { return mPriv.constData() != 0; }
    00107
    00108     PresenceSpec &operator=(const PresenceSpec &other);
    00109     bool operator==(const PresenceSpec &other) const;
    00110     bool operator!=(const PresenceSpec &other) const;
    00111     bool operator<(const PresenceSpec &other) const;
    00112
    00113     Presence presence(const QString &statusMessage = QString()) const;
    00114     bool maySetOnSelf() const;
    00115     bool canHaveStatusMessage() const;
    00116
    00117     SimpleStatusSpec bareSpec() const;
    00118
    00119 private:
    00120     struct Private;
    00121     friend struct Private;
    00122     QSharedDataPointer<Private> mPriv;
    00123 };
    00124
    00125 class TP_QT_EXPORT PresenceSpecList : public QList<PresenceSpec>
    00126 {
    00127 public:
    00128     PresenceSpecList() { }
    00129     PresenceSpecList(const SimpleStatusSpecMap &specMap)
    00130     {
    00131         SimpleStatusSpecMap::const_iterator i = specMap.constBegin();
    00132         SimpleStatusSpecMap::const_iterator end = specMap.end();
    00133         for (; i != end; ++i) {
    00134             QString status = i.key();
    00135             SimpleStatusSpec spec = i.value();
    00136             append(PresenceSpec(status, spec));
    00137         }
    00138     }
    00139     PresenceSpecList(const QList<PresenceSpec> &other)
    00140         : QList<PresenceSpec>(other)
    00141     {
    00142     }
    00143
    00144     QMap<QString, PresenceSpec> toMap() const
    00145     {
    00146         QMap<QString, PresenceSpec> ret;
    00147         Q_FOREACH (const PresenceSpec &spec, *this) {
    00148             ret.insert(spec.presence().status(), spec);
    00149         }
    00150         return ret;
    00151     }
    00152
    00153     SimpleStatusSpecMap bareSpecs() const
    00154     {
    00155         SimpleStatusSpecMap ret;
    00156         Q_FOREACH (const PresenceSpec &spec, *this) {
    00157             ret.insert(spec.presence().status(), spec.bareSpec());
    00158         }
    00159         return ret;
    00160     }
    00161 };
    00162
    00163 Q_DECLARE_OPERATORS_FOR_FLAGS(PresenceSpec::SimpleStatusFlags)
    00164
    00165 } // Tp
    00166
    00167 Q_DECLARE_METATYPE(Tp::Presence);
    00168 Q_DECLARE_METATYPE(Tp::PresenceSpec);
    00169 Q_DECLARE_METATYPE(Tp::PresenceSpecList);
    00170
    00171 #endif