Contact.h 9.13 KB
Newer Older
Nicolas Jager's avatar
Nicolas Jager committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/**************************************************************************
* Copyright (C) 2016 by Savoir-faire Linux                                *
* Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com>              *
* Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com>          *
*                                                                         *
* This program is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU General Public License as published by    *
* the Free Software Foundation; either version 3 of the License, or       *
* (at your option) any later version.                                     *
*                                                                         *
* This program 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 General Public License for more details.                            *
*                                                                         *
* You should have received a copy of the GNU General Public License       *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.   *
**************************************************************************/
19 20 21
#pragma once

#include "VCardUtils.h"
22
#include "Utils.h"
23

Nicolas Jager's avatar
Nicolas Jager committed
24 25
using namespace Platform;
using namespace Windows::Data::Json;
26
using namespace Windows::UI::Xaml;
Nicolas Jager's avatar
Nicolas Jager committed
27 28 29 30
using namespace Windows::UI::Xaml::Data;

/* strings required by Windows::Data::Json. Defined here on puprose */
String^ nameKey = "name";
atraczyk's avatar
atraczyk committed
31
String^ displayNameKey = "displayname";
Nicolas Jager's avatar
Nicolas Jager committed
32
String^ ringIDKey = "ringid";
33
String^ GUIDKey = "id";
34
String^ unreadMessagesKey = "unreadmessages";
35
String^ unreadContactRequestKey = "unreadContactRequest";
Nicolas Jager's avatar
Nicolas Jager committed
36 37
String^ contactKey = "contact";
String^ contactListKey = "contactlist";
38
String^ accountIdAssociatedKey = "accountIdAssociated";
atraczyk's avatar
atraczyk committed
39
String^ vcardUIDKey = "vcardUID";
40
String^ lastTimeKey = "lastTime";
41 42 43
String^ trustStatusKey = "trustStatus";
String^ isIncognitoContactKey = "isIncognitoContact";
String^ avatarColorStringKey = "avatarColorString";
Nicolas Jager's avatar
Nicolas Jager committed
44 45 46 47

namespace RingClientUWP
{
ref class Conversation;
48

Nicolas Jager's avatar
Nicolas Jager committed
49 50 51
public ref class Contact sealed : public INotifyPropertyChanged
{
public:
52 53 54 55 56 57 58 59 60
    Contact(    String^ accountId,
                String^ name,
                String^ ringID,
                String^ GUID,
                uint32 unreadmessages,
                ContactStatus contactStatus,
                TrustStatus trustStatus,
                bool isIncognitoContact,
                String^ avatarColorString);
61

Nicolas Jager's avatar
Nicolas Jager committed
62 63
    JsonObject^ ToJsonObject();

64
    void raiseNotifyPropertyChanged(String^ propertyName);
Nicolas Jager's avatar
Nicolas Jager committed
65 66
    virtual event PropertyChangedEventHandler^ PropertyChanged;

67 68
    property String^ _name {
        String^ get() {
Nicolas Jager's avatar
Nicolas Jager committed
69 70
            return name_;
        }
71
        void set(String^ value) {
Nicolas Jager's avatar
Nicolas Jager committed
72 73
            name_ = value;
            NotifyPropertyChanged("_name");
74 75 76 77
            NotifyPropertyChanged("_bestName");
            NotifyPropertyChanged("_bestName2");
            NotifyPropertyChanged("_bestName3");
            NotifyPropertyChanged("_avatarColorString");
Nicolas Jager's avatar
Nicolas Jager committed
78 79
        }
    }
80

Nicolas Jager's avatar
Nicolas Jager committed
81
    property String^ ringID_;
82
    property String^ GUID_;
83
    property bool subscribed_;
84

85 86
    property Conversation^ _conversation {
        Conversation^ get() {
Nicolas Jager's avatar
Nicolas Jager committed
87 88 89
            return conversation_;
        }
    }
90 91 92

    property Visibility notificationNewMessage {
        Visibility get() {
93 94
            return notificationNewMessage_;
        }
95
        void set(Visibility visibility) {
96
            notificationNewMessage_ = visibility;
97
            NotifyPropertyChanged("notificationNewMessage");
98 99
        }
    }
100 101 102

    property uint32 _unreadMessages {
        uint32 get() {
Nicolas Jager's avatar
Nicolas Jager committed
103
            return unreadMessages_;
104
        }
105
        void set(uint32 value) {
Nicolas Jager's avatar
Nicolas Jager committed
106
            unreadMessages_ = value;
107
            NotifyPropertyChanged("_unreadMessages");
108 109
        }
    }
110 111 112 113 114 115 116 117 118 119 120 121 122

    property bool _unreadContactRequest {
        bool get() {
            return unreadContactRequest_;
        }
        void set(bool value) {
            unreadContactRequest_ = value;
            NotifyPropertyChanged("_unreadContactRequest");
        }
    }

    property String^ _avatarImage {
        String^ get() {
atraczyk's avatar
atraczyk committed
123 124
            return avatarImage_;
        }
125
        void set(String^ value) {
atraczyk's avatar
atraczyk committed
126 127 128 129
            avatarImage_ = value;
            NotifyPropertyChanged("_avatarImage");
        }
    }
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

    property String^ _avatarColorString {
        String^ get() {
            return avatarColorString_;
        }
        void set(String^ value) {
            avatarColorString_ = value;
            NotifyPropertyChanged("_avatarColorString");
            NotifyPropertyChanged("_avatarColorBrush");
        }
    }

    property SolidColorBrush^ _avatarColorBrush {
        SolidColorBrush^ get() {
            return Utils::solidColorBrushFromString(avatarColorString_);
        }
    }

    property Windows::UI::Xaml::GridLength _contactBarHeight {
        GridLength get() {
150 151
            return contactBarHeight_;
        }
152
        void set(GridLength value) {
153
            contactBarHeight_ = value;
154
            NotifyPropertyChanged("_contactBarHeight");
155 156
        }
    }
157 158 159 160 161 162 163 164 165
    property String^ _accountIdAssociated {
        String^ get() {
            return accountIdAssociated_;
        }
        void set(String^ value) {
            accountIdAssociated_ = value;
            NotifyPropertyChanged("_accountIdAssociated");
        }
    }
atraczyk's avatar
atraczyk committed
166
    property String^ _vcardUID;
167 168 169

    property String^ _displayName {
        String^ get() {
atraczyk's avatar
atraczyk committed
170 171
            return displayName_;
        }
172
        void set(String^ value) {
atraczyk's avatar
atraczyk committed
173 174
            displayName_ = value;
            NotifyPropertyChanged("_displayName");
175
            NotifyPropertyChanged("_bestName");
atraczyk's avatar
atraczyk committed
176 177
        }
    }
Nicolas Jager's avatar
Nicolas Jager committed
178

179 180 181 182 183 184 185 186 187 188
    property int _presenceStatus {
        int get() { return presenceStatus_; }
        void set(int value) {
            presenceStatus_ = value;
            NotifyPropertyChanged("_presenceStatus");
        }
    }

    property ContactStatus _contactStatus {
        ContactStatus get() {
Nicolas Jager's avatar
Nicolas Jager committed
189 190
            return contactStatus_;
        }
191
        void set(ContactStatus value) {
Nicolas Jager's avatar
Nicolas Jager committed
192 193 194 195 196
            contactStatus_ = value;
            NotifyPropertyChanged("_contactStatus");
        }
    }

197 198
    property String^ _lastTime {
        String^ get() {
199 200
            return lastTime_;
        }
201
        void set(String^ value) {
202 203 204 205 206
            lastTime_ = value;
            NotifyPropertyChanged("_lastTime");
        }
    }

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
    property bool _isTrusted {
        bool get() {
            return  trustStatus_ == TrustStatus::CONTACT_REQUEST_SENT ||
                    trustStatus_ == TrustStatus::TRUSTED;
        }
    }

    property String^ _bestName {
        String^ get() {
            String^ bestName;
            if (displayName_)
                bestName += displayName_ + " - ";
            if (name_)
                bestName += name_;
            else if (ringID_)
                bestName += ringID_;
            return bestName;
        }
    }

    property String^ _bestName2 {
        String^ get() {
            String^ bestName;
            if (displayName_)
                bestName = displayName_;
            else if (name_)
                bestName = name_;
            else if (ringID_)
                bestName = ringID_;
            return bestName;
        }
    }

    property String^ _bestName3 {
        String^ get() {
            String^ bestName;
            if (_bestName2 == displayName_) {
                if (name_)
                    bestName = name_;
                else if (ringID_)
                    bestName = ringID_;
                else
                    bestName = "";
            }
            else if (_bestName2 == name_)
                bestName = "";
            else if (_bestName2 == ringID_)
                bestName = "";
            return bestName;
        }
    }

    property TrustStatus _trustStatus {
        TrustStatus get() {
            return trustStatus_;
        }
        void set(TrustStatus value) {
            trustStatus_ = value;
        }
    }

    property bool _isIncognitoContact;
269

270 271
    VCardUtils::VCard^ getVCard();

272 273 274 275
internal:
    void        saveConversationToFile();
    String^     StringifyConversation();
    void        DestringifyConversation(String^ data);
276
    void        deleteConversationFile();
277
    void        loadConversation();
278

Nicolas Jager's avatar
Nicolas Jager committed
279 280 281 282
protected:
    void NotifyPropertyChanged(String^ propertyName);

private:
283
    VCardUtils::VCard^ vCard_;
Nicolas Jager's avatar
Nicolas Jager committed
284
    Conversation^ conversation_;
285 286
    Visibility notificationNewMessage_;
    unsigned int unreadMessages_;
287 288 289
    int presenceStatus_;
    bool unreadContactRequest_;
    String^ avatarColorString_;
atraczyk's avatar
atraczyk committed
290 291
    String^ avatarImage_;
    String^ displayName_;
292
    String^ accountIdAssociated_;
293
    Windows::UI::Xaml::GridLength contactBarHeight_ = 0;
Nicolas Jager's avatar
Nicolas Jager committed
294 295
    ContactStatus contactStatus_;
    String^ name_;
296
    String^ lastTime_;
297
    TrustStatus trustStatus_;
Nicolas Jager's avatar
Nicolas Jager committed
298 299 300
};
}