Account.h 5.9 KB
Newer Older
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: Jger Nicolas <nicolas.jager@savoirfairelinux.com>              *
 * Author: Traczyk Andreas <andreas.traczyk@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/>.   *
 **************************************************************************/
Nicolas Jager's avatar
Nicolas Jager committed
19
#pragma once
20

Nicolas Jager's avatar
Nicolas Jager committed
21 22
using namespace Platform;
using namespace Windows::UI::Xaml::Data;
23
using namespace Platform::Collections;
24
using namespace Windows::Foundation::Collections;
Nicolas Jager's avatar
Nicolas Jager committed
25 26 27

namespace RingClientUWP
{
28 29
ref class Contact;

Nicolas Jager's avatar
Nicolas Jager committed
30 31 32
public ref class Account sealed : public INotifyPropertyChanged
{
public:
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    Account(String^ name,
            String^ ringID,
            String^ accountType,
            String^ accountID,
            String^ deviceId,
            String^ deviceName,
            bool active,
            bool upnpState,
            bool autoAnswer,
            bool dhtPublicInCalls,
            bool turnEnabled,
            String^ turnAddress,
            String^ sipHostname,
            String^ sipUsername,
            String^ sipPassword);
Nicolas Jager's avatar
Nicolas Jager committed
48

49
    void raiseNotifyPropertyChanged(String^ propertyName);
Nicolas Jager's avatar
Nicolas Jager committed
50 51
    virtual event PropertyChangedEventHandler^ PropertyChanged;

52 53 54
    property String^ name_
    {
        String^ get() {
55
            return alias_;
56 57
        }
        void set(String^ value) {
58
            alias_ = value;
59
            NotifyPropertyChanged("name_");
60
            NotifyPropertyChanged("_bestName");
61 62
        }
    }
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

    property String^ _username
    {
        String^ get() {
            return username_;
        }
        void set(String^ value) {
            username_ = value;
            NotifyPropertyChanged("_username");
            NotifyPropertyChanged("_bestName");
        }
    }

    property String^ _bestName {
        String^ get() {
            String^ bestName;
            if (alias_)
                bestName = alias_;
            return bestName;
        }
    }

    property String^ _bestName2 {
        String^ get() {
            String^ bestName;
            if (accountType_ == "RING" && username_)
                bestName += username_;
            return bestName;
        }
    }

    property String^ _bestName3 {
        String^ get() {
            String^ bestName;
            if (alias_)
                bestName += alias_;
            if (accountType_ == "RING" && username_)
                bestName += " (" + username_ + ")";
            return bestName;
        }
    }

105 106 107 108 109 110 111 112 113
    property String^ ringID_ {
        String^ get() {
            return ringID__;
        }
        void set(String^ value) {
            ringID__ = value;
            NotifyPropertyChanged("ringID_");
        }
    }
114
    property String^ accountType_; // refacto : create a enum accountType
115
    property String^ accountID_;
116
    property String^ _deviceId;
117 118 119 120 121
    property String^ _deviceName;

    property RegistrationState _registrationState;

    property bool _active;
122
    property bool _upnpState;
123 124 125 126
    property bool _autoAnswer;
    property bool _dhtPublicInCalls;
    property bool _turnEnabled;
    property String^ _turnAddress;
127 128 129 130 131 132 133 134 135
    property String^ _sipHostname;
    property String^ _sipUsername
    {
        String^ get() {
            return sipUsername_;
        }
        void set(String^ value) {
            sipUsername_ = value;
            NotifyPropertyChanged("_sipUsername");
136
            NotifyPropertyChanged("_bestName");
137 138
        }
    }
139

140
    property unsigned _unreadMessages {
141 142 143 144 145 146
        unsigned get() {
            return unreadMessages_;
        }
        void set(unsigned value) {
            unreadMessages_ = value;
            NotifyPropertyChanged("_unreadMessages");
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
            NotifyPropertyChanged("_allUnread");
        }
    }

    property unsigned _unreadContactRequests {
        unsigned get() {
            return unreadContactRequests_;
        }
        void set(unsigned value) {
            unreadContactRequests_ = value;
            NotifyPropertyChanged("_unreadContactRequests");
            NotifyPropertyChanged("_allUnread");
        }
    }

    property unsigned _allUnread {
        unsigned get() {
            return unreadContactRequests_ + unreadMessages_;
165 166 167
        }
    }

168
    property String^ _sipPassword; // refacto : think to encrypt password in memory
Nicolas Jager's avatar
Nicolas Jager committed
169

170 171 172 173 174 175 176 177 178
    property IVector<Contact^>^ _contactsList {
        IVector<Contact^>^ get() {
            return contactsList_;
        }
        void set(IVector<Contact^>^ value) {
            contactsList_ = value;
        }
    };

Nicolas Jager's avatar
Nicolas Jager committed
179 180 181
protected:
    void NotifyPropertyChanged(String^ propertyName);

182
private:
183 184
    IVector<Contact^>^ contactsList_;

185
    String^ alias_;
186
    String^ username_;
187
    String^ ringID__;
188
    String^ sipUsername_;
189
    unsigned unreadMessages_;
190
    unsigned unreadContactRequests_;
Nicolas Jager's avatar
Nicolas Jager committed
191 192 193
};
}