| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | 
| 4 | ** Contact: http://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the QtContacts module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | 
| 9 | ** Commercial License Usage | 
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | 
| 11 | ** accordance with the commercial license agreement provided with the | 
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | 
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | 
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | 
| 16 | ** | 
| 17 | ** GNU Lesser General Public License Usage | 
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | 
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | 
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | 
| 22 | ** following information to ensure the GNU Lesser General Public License | 
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | 
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
| 25 | ** | 
| 26 | ** As a special exception, The Qt Company gives you certain additional | 
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | 
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | 
| 29 | ** | 
| 30 | ** $QT_END_LICENSE$ | 
| 31 | ** | 
| 32 | ****************************************************************************/ | 
| 33 |  | 
| 34 | #ifndef QDECLARATIVECONTACTPRESENCE_H | 
| 35 | #define QDECLARATIVECONTACTPRESENCE_H | 
| 36 |  | 
| 37 | #include <QtContacts/qcontactpresence.h> | 
| 38 |  | 
| 39 | #include "qdeclarativecontactdetail_p.h" | 
| 40 |  | 
| 41 | QTCONTACTS_USE_NAMESPACE | 
| 42 |  | 
| 43 | QT_BEGIN_NAMESPACE | 
| 44 |  | 
| 45 | class QDeclarativeContactPresence : public QDeclarativeContactDetail | 
| 46 | { | 
| 47 |     Q_OBJECT | 
| 48 |     Q_PROPERTY(QDateTime timestamp READ timestamp WRITE setTimestamp NOTIFY valueChanged) | 
| 49 |     Q_PROPERTY(QString nickname READ nickname WRITE setNickname NOTIFY valueChanged) | 
| 50 |     Q_PROPERTY(PresenceStateType state READ presenceState WRITE setPresenceState NOTIFY valueChanged) | 
| 51 |     Q_PROPERTY(QString stateText READ presenceStateText WRITE setPresenceStateText NOTIFY valueChanged) | 
| 52 |     Q_PROPERTY(QUrl imageUrl READ presenceStateImageUrl WRITE setPresenceStateImageUrl NOTIFY valueChanged) | 
| 53 |     Q_PROPERTY(QString customMessage READ customMessage WRITE setCustomMessage NOTIFY valueChanged) | 
| 54 |     Q_ENUMS(FieldType) | 
| 55 |     Q_ENUMS(PresenceStateType) | 
| 56 |     Q_CLASSINFO("DefaultProperty" , "state" ) | 
| 57 | public: | 
| 58 |     enum FieldType { | 
| 59 |         Timestamp = QContactPresence::FieldTimestamp, | 
| 60 |         Nickname = QContactPresence::FieldNickname, | 
| 61 |         State = QContactPresence::FieldPresenceState, | 
| 62 |         StateText = QContactPresence::FieldPresenceStateText, | 
| 63 |         ImageUrl = QContactPresence::FieldPresenceStateImageUrl, | 
| 64 |         CustomMessage = QContactPresence::FieldCustomMessage | 
| 65 |     }; | 
| 66 |  | 
| 67 |     enum PresenceStateType { | 
| 68 |         Unknown = QContactPresence::PresenceUnknown, | 
| 69 |         Available = QContactPresence::PresenceAvailable, | 
| 70 |         Hidden = QContactPresence::PresenceHidden, | 
| 71 |         Busy = QContactPresence::PresenceBusy, | 
| 72 |         Away = QContactPresence::PresenceAway, | 
| 73 |         ExtendedAway = QContactPresence::PresenceExtendedAway, | 
| 74 |         Offline = QContactPresence::PresenceOffline | 
| 75 |     }; | 
| 76 |  | 
| 77 |     QDeclarativeContactPresence(QObject* parent = Q_NULLPTR) | 
| 78 |         :QDeclarativeContactDetail(parent) | 
| 79 |     { | 
| 80 |         setDetail(QContactPresence()); | 
| 81 |         connect(asender: this, SIGNAL(valueChanged()), SIGNAL(detailChanged())); | 
| 82 |     } | 
| 83 |     DetailType detailType() const | 
| 84 |     { | 
| 85 |         return QDeclarativeContactDetail::Presence; | 
| 86 |     } | 
| 87 |  | 
| 88 |     void setTimestamp(const QDateTime& v) | 
| 89 |     { | 
| 90 |         if (!readOnly() && v != timestamp()) { | 
| 91 |             detail().setValue(field: QContactPresence::FieldTimestamp, value: v); | 
| 92 |             emit valueChanged(); | 
| 93 |         } | 
| 94 |     } | 
| 95 |     QDateTime timestamp() const {return detail().value<QDateTime>(field: QContactPresence::FieldTimestamp);} | 
| 96 |     void setNickname(const QString& v) | 
| 97 |     { | 
| 98 |         if (!readOnly() && v != nickname()) { | 
| 99 |             detail().setValue(field: QContactPresence::FieldNickname, value: v); | 
| 100 |             emit valueChanged(); | 
| 101 |         } | 
| 102 |     } | 
| 103 |     QString nickname() const {return detail().value(field: QContactPresence::FieldNickname).toString();} | 
| 104 |  | 
| 105 |     void setPresenceState(PresenceStateType v) | 
| 106 |     { | 
| 107 |         if (!readOnly() && v != presenceState()) { | 
| 108 |             detail().setValue(field: QContactPresence::FieldPresenceState, value: static_cast<int>(v)); | 
| 109 |             emit valueChanged(); | 
| 110 |         } | 
| 111 |     } | 
| 112 |  | 
| 113 |     PresenceStateType presenceState() const | 
| 114 |     { | 
| 115 |         return static_cast<PresenceStateType>(detail().value<int>(field: QContactPresence::FieldPresenceState)); | 
| 116 |  | 
| 117 |     } | 
| 118 |  | 
| 119 |     void setPresenceStateText(const QString& v) | 
| 120 |     { | 
| 121 |         if (!readOnly() && v != presenceStateText()) { | 
| 122 |             detail().setValue(field: QContactPresence::FieldPresenceStateText, value: v); | 
| 123 |             emit valueChanged(); | 
| 124 |         } | 
| 125 |     } | 
| 126 |     QString presenceStateText() const {return detail().value(field: QContactPresence::FieldPresenceStateText).toString();} | 
| 127 |     void setPresenceStateImageUrl(const QUrl& v) | 
| 128 |     { | 
| 129 |         if (!readOnly() && v != presenceStateImageUrl())  { | 
| 130 |             detail().setValue(field: QContactPresence::FieldPresenceStateImageUrl, value: v); | 
| 131 |             emit valueChanged(); | 
| 132 |         } | 
| 133 |     } | 
| 134 |     QUrl presenceStateImageUrl() const {return detail().value<QUrl>(field: QContactPresence::FieldPresenceStateImageUrl);} | 
| 135 |     void setCustomMessage(const QString& v) | 
| 136 |     { | 
| 137 |         if (!readOnly() && v != customMessage()) { | 
| 138 |             detail().setValue(field: QContactPresence::FieldCustomMessage, value: v); | 
| 139 |             emit valueChanged(); | 
| 140 |         } | 
| 141 |     } | 
| 142 |     QString customMessage() const {return detail().value(field: QContactPresence::FieldCustomMessage).toString();} | 
| 143 | signals: | 
| 144 |     void valueChanged(); | 
| 145 | }; | 
| 146 |  | 
| 147 | QT_END_NAMESPACE | 
| 148 |  | 
| 149 | QML_DECLARE_TYPE(QDeclarativeContactPresence) | 
| 150 |  | 
| 151 | #endif // QDECLARATIVECONTACTPRESENCE_H | 
| 152 |  |