atraczyk | b724d33 | 2016-08-30 15:25:59 -0400 | [diff] [blame] | 1 | /***************************************************************************
|
| 2 | * Copyright (C) 2016 by Savoir-faire Linux *
|
| 3 | * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
|
| 4 | * Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com> *
|
| 5 | * *
|
| 6 | * This program is free software; you can redistribute it and/or modify *
|
| 7 | * it under the terms of the GNU General Public License as published by *
|
| 8 | * the Free Software Foundation; either version 3 of the License, or *
|
| 9 | * (at your option) any later version. *
|
| 10 | * *
|
| 11 | * This program is distributed in the hope that it will be useful, *
|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 14 | * GNU General Public License for more details. *
|
| 15 | * *
|
| 16 | * You should have received a copy of the GNU General Public License *
|
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 18 | **************************************************************************/
|
| 19 |
|
| 20 | #pragma once
|
| 21 |
|
| 22 | using namespace Platform::Collections;
|
| 23 | using namespace Concurrency;
|
| 24 |
|
| 25 | namespace RingClientUWP
|
| 26 | {
|
| 27 |
|
Nicolas Jager | 0788e96 | 2016-08-26 15:41:06 -0400 | [diff] [blame^] | 28 | /* delegates */
|
atraczyk | b724d33 | 2016-08-30 15:25:59 -0400 | [diff] [blame] | 29 | delegate void NewContactSelected();
|
| 30 | delegate void NoContactSelected();
|
Nicolas Jager | 0788e96 | 2016-08-26 15:41:06 -0400 | [diff] [blame^] | 31 | delegate void ScreenConversationMessage(String^ accountId, String^ from, String^ payload);
|
| 32 | delegate void NotifyNewConversationMessage();
|
atraczyk | b724d33 | 2016-08-30 15:25:59 -0400 | [diff] [blame] | 33 |
|
| 34 | namespace ViewModel {
|
| 35 | public ref class ContactsViewModel sealed
|
| 36 | {
|
| 37 | internal:
|
| 38 | /* singleton */
|
| 39 | static property ContactsViewModel^ instance
|
| 40 | {
|
| 41 | ContactsViewModel^ get()
|
| 42 | {
|
| 43 | static ContactsViewModel^ instance_ = ref new ContactsViewModel();
|
| 44 | return instance_;
|
| 45 | }
|
| 46 | }
|
| 47 |
|
| 48 | /* functions */
|
| 49 | Contact^ findContactByName(String^ name);
|
| 50 | Contact^ addNewContact(String^ name, String^ ringId);
|
| 51 | void saveContactsToFile();
|
| 52 | void openContactsFromFile();
|
| 53 | String^ Stringify();
|
| 54 | void Destringify(String^ data);
|
| 55 |
|
| 56 | /* properties */
|
| 57 | property Contact^ selectedContact
|
| 58 | {
|
| 59 | Contact^ get()
|
| 60 | {
|
| 61 | return currentItem_;
|
| 62 | }
|
| 63 | void set(Contact^ value)
|
| 64 | {
|
| 65 | oldItem_ = currentItem_;
|
| 66 | currentItem_ = value;
|
| 67 | if (value)
|
| 68 | newContactSelected();
|
| 69 | else
|
| 70 | noContactSelected();
|
| 71 | }
|
| 72 | }
|
| 73 |
|
| 74 | property Vector<Contact^>^ contactsList
|
| 75 | {
|
| 76 | Vector<Contact^>^ get()
|
| 77 | {
|
| 78 | return contactsList_;
|
| 79 | }
|
| 80 | }
|
| 81 |
|
| 82 | /* events */
|
| 83 | event NewContactSelected^ newContactSelected;
|
| 84 | event NoContactSelected^ noContactSelected;
|
Nicolas Jager | 0788e96 | 2016-08-26 15:41:06 -0400 | [diff] [blame^] | 85 | event ScreenConversationMessage^ screenConversationMessage;
|
| 86 | event NotifyNewConversationMessage^ notifyNewConversationMessage;
|
atraczyk | b724d33 | 2016-08-30 15:25:59 -0400 | [diff] [blame] | 87 |
|
| 88 | private:
|
| 89 | ContactsViewModel(); // singleton
|
| 90 | Vector<Contact^>^ contactsList_;
|
| 91 | Contact^ currentItem_;
|
| 92 | Contact^ oldItem_;
|
| 93 |
|
| 94 | };
|
| 95 | }
|
| 96 | }
|