Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
savoirfairelinux
jami-client-uwp
Commits
a57d717d
Commit
a57d717d
authored
Nov 29, 2016
by
atraczyk
Committed by
Andreas Traczyk
Jan 30, 2017
Browse files
fixes vcard implementation
Change-Id: I2e7e07eefd6f8a2c7c4c1185e6259a47908fb187 Tuleap: #790
parent
026a84b4
Changes
9
Hide whitespace changes
Inline
Side-by-side
Contact.cpp
View file @
a57d717d
...
...
@@ -70,6 +70,9 @@ Contact::Contact(String^ name,
}
_accountIdAssociated
=
""
;
_vcardUID
=
""
;
_avatarImage
=
ref
new
String
(
L"ms-appx:///Assets/TESTS/contactAvatar.png"
);
_displayName
=
""
;
}
void
...
...
@@ -89,10 +92,12 @@ Contact::ToJsonObject()
{
JsonObject
^
contactObject
=
ref
new
JsonObject
();
contactObject
->
SetNamedValue
(
nameKey
,
JsonValue
::
CreateStringValue
(
name_
));
contactObject
->
SetNamedValue
(
displayNameKey
,
JsonValue
::
CreateStringValue
(
displayName_
));
contactObject
->
SetNamedValue
(
ringIDKey
,
JsonValue
::
CreateStringValue
(
ringID_
));
contactObject
->
SetNamedValue
(
GUIDKey
,
JsonValue
::
CreateStringValue
(
GUID_
));
contactObject
->
SetNamedValue
(
unreadMessagesKey
,
JsonValue
::
CreateNumberValue
(
unreadMessages_
));
contactObject
->
SetNamedValue
(
accountIdAssociatedKey
,
JsonValue
::
CreateStringValue
(
_accountIdAssociated
));
contactObject
->
SetNamedValue
(
vcardUIDKey
,
JsonValue
::
CreateStringValue
(
_vcardUID
));
JsonObject
^
jsonObject
=
ref
new
JsonObject
();
jsonObject
->
SetNamedValue
(
contactKey
,
contactObject
);
...
...
Contact.h
View file @
a57d717d
...
...
@@ -27,12 +27,14 @@ using namespace Windows::UI::Xaml::Data;
/* strings required by Windows::Data::Json. Defined here on puprose */
String
^
nameKey
=
"name"
;
String
^
displayNameKey
=
"displayname"
;
String
^
ringIDKey
=
"ringid"
;
String
^
GUIDKey
=
"id"
;
String
^
unreadMessagesKey
=
"unreadmessages"
;
String
^
contactKey
=
"contact"
;
String
^
contactListKey
=
"contactlist"
;
String
^
accountIdAssociatedKey
=
"accountIdAssociated"
;
String
^
vcardUIDKey
=
"vcardUID"
;
namespace
RingClientUWP
{
...
...
@@ -81,6 +83,18 @@ public:
NotifyPropertyChanged
(
"_unreadMessages"
);
}
}
property
String
^
_avatarImage
{
String
^
get
()
{
return
avatarImage_
;
}
void
set
(
String
^
value
)
{
avatarImage_
=
value
;
NotifyPropertyChanged
(
"_avatarImage"
);
}
}
property
Windows
::
UI
::
Xaml
::
GridLength
_contactBarHeight
{
Windows
::
UI
::
Xaml
::
GridLength
get
()
...
...
@@ -94,6 +108,19 @@ public:
}
}
property
String
^
_accountIdAssociated
;
property
String
^
_vcardUID
;
property
String
^
_displayName
{
String
^
get
()
{
return
displayName_
;
}
void
set
(
String
^
value
)
{
displayName_
=
value
;
NotifyPropertyChanged
(
"_displayName"
);
}
}
VCardUtils
::
VCard
^
getVCard
();
...
...
@@ -112,6 +139,8 @@ private:
Conversation
^
conversation_
;
Visibility
notificationNewMessage_
;
unsigned
int
unreadMessages_
;
String
^
avatarImage_
;
String
^
displayName_
;
Windows
::
UI
::
Xaml
::
GridLength
contactBarHeight_
=
0
;
};
}
...
...
ContactsViewModel.cpp
View file @
a57d717d
...
...
@@ -146,10 +146,12 @@ ContactsViewModel::Destringify(String^ data)
{
JsonObject
^
jsonObject
=
JsonObject
::
Parse
(
data
);
String
^
name
;
String
^
displayname
;
String
^
ringid
;
String
^
guid
;
unsigned
int
unreadmessages
;
String
^
accountIdAssociated
;
String
^
vcardUID
;
JsonArray
^
contactlist
=
jsonObject
->
GetNamedArray
(
contactListKey
,
ref
new
JsonArray
());
for
(
unsigned
int
i
=
0
;
i
<
contactlist
->
Size
;
i
++
)
{
...
...
@@ -159,14 +161,23 @@ ContactsViewModel::Destringify(String^ data)
JsonObject
^
contactObject
=
jsonContactObject
->
GetNamedObject
(
contactKey
,
nullptr
);
if
(
contactObject
!=
nullptr
)
{
name
=
contactObject
->
GetNamedString
(
nameKey
);
displayname
=
contactObject
->
GetNamedString
(
displayNameKey
);
ringid
=
contactObject
->
GetNamedString
(
ringIDKey
);
guid
=
contactObject
->
GetNamedString
(
GUIDKey
);
unreadmessages
=
static_cast
<
uint16_t
>
(
contactObject
->
GetNamedNumber
(
unreadMessagesKey
));
accountIdAssociated
=
contactObject
->
GetNamedString
(
accountIdAssociatedKey
);
vcardUID
=
contactObject
->
GetNamedString
(
vcardUIDKey
);
}
auto
contact
=
ref
new
Contact
(
name
,
ringid
,
guid
,
unreadmessages
);
contact
->
_displayName
=
displayname
;
contact
->
_accountIdAssociated
=
accountIdAssociated
;
// contact image
contact
->
_vcardUID
=
vcardUID
;
std
::
string
contactImageFile
=
RingD
::
instance
->
getLocalFolder
()
+
".vcards
\\
"
+
Utils
::
toString
(
contact
->
_vcardUID
)
+
".png"
;
if
(
Utils
::
fileExists
(
contactImageFile
))
{
contact
->
_avatarImage
=
Utils
::
toPlatformString
(
contactImageFile
);
}
contactsList_
->
Append
(
contact
);
contactAdded
(
contact
);
}
...
...
@@ -213,3 +224,9 @@ void RingClientUWP::ViewModel::ContactsViewModel::OnincomingMessage(Platform::St
}
}
}
void
ContactsViewModel
::
modifyContact
(
Contact
^
contact
)
{
contactDataModified
(
contact
);
}
\ No newline at end of file
ContactsViewModel.h
View file @
a57d717d
...
...
@@ -28,6 +28,7 @@ namespace RingClientUWP
/* delegates */
delegate
void
ContactAdded
(
Contact
^
);
delegate
void
ContactDeleted
(
Contact
^
);
delegate
void
ContactDataModified
(
Contact
^
);
namespace
ViewModel
{
public
ref
class
ContactsViewModel
sealed
...
...
@@ -51,6 +52,7 @@ internal:
String
^
Stringify
();
void
Destringify
(
String
^
data
);
void
deleteContact
(
Contact
^
contact
);
void
modifyContact
(
Contact
^
contact
);
/* properties */
property
Vector
<
Contact
^>^
contactsList
...
...
@@ -64,6 +66,7 @@ internal:
/* events */
event
ContactAdded
^
contactAdded
;
event
ContactDeleted
^
contactDeleted
;
event
ContactDataModified
^
contactDataModified
;
private:
ContactsViewModel
();
// singleton
...
...
SmartPanel.xaml
View file @
a57d717d
...
...
@@ -140,7 +140,7 @@
<ColumnDefinition Width="*"
MinWidth="200"/>
</Grid.ColumnDefinitions>
<Image x:Name="_contactAvatar_"
<Image x:Name="_
X
contactAvatar_"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Grid.Column="0"
...
...
@@ -252,13 +252,17 @@
<ColumnDefinition Width="*"
MinWidth="200"/>
</Grid.ColumnDefinitions>
<Image x:Name="_contactAvatar_"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Grid.Column="0"
Width="55"
Height="55"
Source="Assets\TESTS\contactAvatar.png"/>
<Ellipse Height="50"
Width="50"
Grid.Column="0"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Margin="5">
<Ellipse.Fill>
<ImageBrush x:Name="_contactAvatar_"
ImageSource="{x:Bind _contact._avatarImage, Mode=OneWay}"/>
</Ellipse.Fill>
</Ellipse>
<!-- visual notifications. -->
<Border x:Name="_visualNotificationVideoChat_"
Visibility="Collapsed"
...
...
SmartPanel.xaml.cpp
View file @
a57d717d
...
...
@@ -80,6 +80,9 @@ SmartPanel::SmartPanel()
String
^
image_path
=
localfolder
->
Path
+
"
\\
.profile
\\
profile_image.png"
;
auto
uri
=
ref
new
Windows
::
Foundation
::
Uri
(
image_path
);
_selectedAccountAvatar_
->
ImageSource
=
ref
new
BitmapImage
(
uri
);
});
ContactsViewModel
::
instance
->
contactDataModified
+=
ref
new
ContactDataModified
([
this
](
Contact
^
contact
){
});
AccountsViewModel
::
instance
->
updateScrollView
+=
ref
new
UpdateScrollView
([
this
]()
{
_accountsListScrollView_
->
UpdateLayout
();
...
...
UserPreferences.cpp
View file @
a57d717d
...
...
@@ -112,6 +112,8 @@ UserPreferences::saveProfileToVCard()
std
::
basic_ifstream
<
uint8_t
>
stream
(
imageFile
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
auto
eos
=
std
::
istreambuf_iterator
<
uint8_t
>
();
auto
buffer
=
std
::
vector
<
uint8_t
>
(
std
::
istreambuf_iterator
<
uint8_t
>
(
stream
),
eos
);
auto
accountListItem
=
ViewModel
::
AccountListItemsViewModel
::
instance
->
_selectedItem
;
vcfData
[
VCardUtils
::
Property
::
FN
]
=
accountListItem
?
Utils
::
toString
(
accountListItem
->
_account
->
name_
)
:
"Unknown"
;
vcfData
[
VCardUtils
::
Property
::
PHOTO
]
=
ring
::
base64
::
encode
(
buffer
);
vCard_
->
setData
(
vcfData
);
vCard_
->
saveToFile
();
...
...
@@ -122,6 +124,4 @@ UserPreferences::sendVCard(std::string callID)
{
vCard_
->
send
(
callID
,
(
RingD
::
instance
->
getLocalFolder
()
+
"
\\
.vcards
\\
"
+
std
::
to_string
(
PREF_PROFILE_UID
)
+
".vcard"
).
c_str
());
/*vCard_->send(callID,
(RingD::instance->getLocalFolder() + "\\.vcards\\" + std::to_string(4796040057761) + ".vcard").c_str());*/
}
\ No newline at end of file
VCardUtils.cpp
View file @
a57d717d
...
...
@@ -62,6 +62,12 @@ VCard::receiveChunk(const std::string& args, const std::string& payload)
}
m_mParts
[
Property
::
UID
]
=
_line
.
substr
(
4
);
while
(
std
::
getline
(
_payload
,
_line
))
{
if
(
_line
.
find
(
"FN:"
)
!=
std
::
string
::
npos
)
break
;
}
m_mParts
[
Property
::
FN
]
=
_line
.
substr
(
3
);
while
(
std
::
getline
(
_payload
,
_line
))
{
if
(
_line
.
find
(
"PHOTO;"
)
!=
std
::
string
::
npos
)
break
;
...
...
@@ -76,6 +82,10 @@ VCard::receiveChunk(const std::string& args, const std::string& payload)
m_mParts
[
Property
::
PHOTO
].
append
(
_line
);
saveToFile
();
decodeBase64ToPNGFile
();
if
(
!
m_mParts
[
Property
::
FN
].
empty
())
m_Owner
->
_displayName
=
Utils
::
toPlatformString
(
m_mParts
[
Property
::
FN
]);
m_Owner
->
_vcardUID
=
Utils
::
toPlatformString
(
m_mParts
[
Property
::
UID
]);
ViewModel
::
ContactsViewModel
::
instance
->
saveContactsToFile
();
MSG_
(
"VCARD_COMPLETE"
);
return
VCARD_COMPLETE
;
}
...
...
@@ -100,7 +110,7 @@ VCard::send(std::string callID, const char* vCardFile)
else
vCard
=
asString
();
int
total
=
vCard
.
size
()
/
chunkSize
+
(
vCard
.
size
()
%
chunkSize
?
1
:
0
);
std
::
string
idkey
=
Utils
::
genID
(
0LL
,
99999999
99
LL
);
std
::
string
idkey
=
Utils
::
genID
(
0LL
,
99999999LL
);
while
(
vCard
.
size
()
)
{
std
::
map
<
std
::
string
,
std
::
string
>
chunk
;
std
::
stringstream
key
;
...
...
@@ -137,7 +147,7 @@ VCard::asString()
ret
<<
Property
::
UID
<<
Symbols
::
SEPERATOR2
<<
m_mParts
[
Property
::
UID
]
<<
Symbols
::
END_LINE_TOKEN
;
ret
<<
Property
::
FN
<<
Symbols
::
SEPERATOR2
<<
"Unknown"
ret
<<
Property
::
FN
<<
Symbols
::
SEPERATOR2
<<
m_mParts
[
Property
::
FN
]
<<
Symbols
::
END_LINE_TOKEN
;
ret
<<
Property
::
PHOTO
<<
Symbols
::
SEPERATOR1
<<
Symbols
::
PHOTO_ENC
...
...
@@ -166,7 +176,8 @@ VCard::decodeBase64ToPNGFile()
for
(
auto
i
:
decodedData
)
file
<<
i
;
file
.
close
();
MSG_
(
"Done decodeing and saving VCard Photo to PNG"
);
m_Owner
->
_avatarImage
=
Utils
::
toPlatformString
(
vcardDir
+
pngFile
);
MSG_
(
"Done decoding and saving VCard Photo to PNG"
);
}
}
}
...
...
VCardUtils.h
View file @
a57d717d
...
...
@@ -44,7 +44,7 @@ struct Symbols {
constexpr
static
const
char
*
SEPERATOR1
=
";"
;
constexpr
static
const
char
*
SEPERATOR2
=
":"
;
constexpr
static
const
char
*
PHOTO_ENC
=
"ENDCODING=BASE64"
;
constexpr
static
const
char
*
PHOTO_TYPE
=
"TYPE=
JPE
G"
;
constexpr
static
const
char
*
PHOTO_TYPE
=
"TYPE=
PN
G"
;
};
struct
Property
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment