Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
f4c56c99
Commit
f4c56c99
authored
Dec 06, 2016
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(app): supports avatars
parent
a34ca924
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
78 additions
and
43 deletions
+78
-43
AvatarProvider.cpp
tests/src/app/AvatarProvider.cpp
+8
-1
ContactModel.cpp
tests/src/components/contacts/ContactModel.cpp
+53
-18
ContactModel.hpp
tests/src/components/contacts/ContactModel.hpp
+1
-4
RoundedImage.qml
tests/ui/modules/Common/Image/RoundedImage.qml
+1
-1
IncomingMessage.qml
tests/ui/modules/Linphone/Chat/IncomingMessage.qml
+1
-0
Avatar.qml
tests/ui/modules/Linphone/Contact/Avatar.qml
+2
-2
Contact.qml
tests/ui/modules/Linphone/Contact/Contact.qml
+1
-1
ContactEdit.qml
tests/ui/views/App/MainWindow/ContactEdit.qml
+10
-16
Conversation.qml
tests/ui/views/App/MainWindow/Conversation.qml
+1
-0
No files found.
tests/src/app/AvatarProvider.cpp
View file @
f4c56c99
#include <QtDebug>
#include "Database.hpp"
#include "../utils.hpp"
...
...
@@ -20,5 +22,10 @@ QImage AvatarProvider::requestImage (
QSize
*
,
const
QSize
&
)
{
return
QImage
(
m_avatars_path
+
id
);
QImage
image
(
m_avatars_path
+
id
);
if
(
image
.
isNull
())
qWarning
()
<<
QStringLiteral
(
"Unable to load: `%1`."
).
arg
(
id
);
return
image
;
}
tests/src/components/contacts/ContactModel.cpp
View file @
f4c56c99
...
...
@@ -5,24 +5,18 @@
#include <belcard/belcard.hpp>
#include "../../app/AvatarProvider.hpp"
#include "../../app/Database.hpp"
#include "../../utils.hpp"
#include "ContactModel.hpp"
#define VCARD_SCHEME "linphone-desktop:/"
using
namespace
std
;
// ===================================================================
inline
shared_ptr
<
belcard
::
BelCard
>
getBelCard
(
const
shared_ptr
<
linphone
::
Friend
>
&
linphone_friend
)
{
shared_ptr
<
linphone
::
Vcard
>
vcard
=
linphone_friend
->
getVcard
();
return
*
reinterpret_cast
<
shared_ptr
<
belcard
::
BelCard
>
*>
(
vcard
.
get
());
}
// -------------------------------------------------------------------
Presence
::
PresenceStatus
ContactModel
::
getPresenceStatus
()
const
{
return
m_presence_status
;
}
...
...
@@ -37,15 +31,40 @@ QString ContactModel::getUsername () const {
);
}
QString
ContactModel
::
getAvatar
()
const
{
// Find desktop avatar.
list
<
shared_ptr
<
belcard
::
BelCardPhoto
>
>
photos
=
m_linphone_friend
->
getVcard
()
->
getBelcard
()
->
getPhotos
();
auto
it
=
find_if
(
photos
.
begin
(),
photos
.
end
(),
[](
const
shared_ptr
<
belcard
::
BelCardPhoto
>
&
photo
)
{
return
!
photo
->
getValue
().
compare
(
0
,
sizeof
(
VCARD_SCHEME
)
-
1
,
VCARD_SCHEME
);
}
);
// Returns right path.
if
(
it
==
photos
.
end
())
return
""
;
return
QStringLiteral
(
"image://%1/%2"
)
.
arg
(
AvatarProvider
::
PROVIDER_ID
)
.
arg
(
Utils
::
linphoneStringToQString
(
(
*
it
)
->
getValue
().
substr
(
sizeof
(
VCARD_SCHEME
)
-
1
)
));
}
bool
ContactModel
::
setAvatar
(
const
QString
&
path
)
{
// Try to copy photo in avatars folder.
//
1.
Try to copy photo in avatars folder.
QFile
file
(
path
);
if
(
!
file
.
exists
()
||
QImageReader
::
imageFormat
(
path
).
size
()
==
0
)
return
false
;
QFileInfo
info
(
file
);
QString
file_id
=
QUuid
::
createUuid
().
toString
()
+
"."
+
info
.
suffix
();
QString
uuid
=
QUuid
::
createUuid
().
toString
();
QString
file_id
=
QStringLiteral
(
"%1.%2"
)
.
arg
(
uuid
.
mid
(
1
,
uuid
.
length
()
-
2
))
// Remove `{}`.
.
arg
(
info
.
suffix
());
QString
dest
=
Utils
::
linphoneStringToQString
(
Database
::
getAvatarsPath
())
+
file_id
;
...
...
@@ -55,22 +74,38 @@ bool ContactModel::setAvatar (const QString &path) {
qInfo
()
<<
QStringLiteral
(
"Update avatar of `%1`. (path=%2)"
)
.
arg
(
getUsername
()).
arg
(
dest
);
// Remove oldest photos.
shared_ptr
<
belcard
::
BelCard
>
belCard
=
getBelCard
(
m_linphone_friend
);
// 2. Edit vcard.
m_linphone_friend
->
edit
();
shared_ptr
<
belcard
::
BelCard
>
belCard
=
m_linphone_friend
->
getVcard
()
->
getBelcard
();
list
<
shared_ptr
<
belcard
::
BelCardPhoto
>
>
photos
=
belCard
->
getPhotos
();
for
(
const
auto
&
photo
:
belCard
->
getPhotos
())
{
qDebug
()
<<
Utils
::
linphoneStringToQString
(
photo
->
getValue
());
belCard
->
removePhoto
(
photo
);
// 3. Remove oldest photo.
auto
it
=
find_if
(
photos
.
begin
(),
photos
.
end
(),
[](
const
shared_ptr
<
belcard
::
BelCardPhoto
>
&
photo
)
{
return
!
photo
->
getValue
().
compare
(
0
,
sizeof
(
VCARD_SCHEME
)
-
1
,
VCARD_SCHEME
);
}
);
if
(
it
!=
photos
.
end
())
{
QString
image_path
(
Utils
::
linphoneStringToQString
(
Database
::
getAvatarsPath
()
+
(
*
it
)
->
getValue
().
substr
(
sizeof
(
VCARD_SCHEME
)
-
1
)
));
if
(
!
QFile
::
remove
(
image_path
))
qWarning
()
<<
QStringLiteral
(
"Unable to remove `%1`."
).
arg
(
image_path
);
belCard
->
removePhoto
(
*
it
);
}
// Update.
//
4.
Update.
shared_ptr
<
belcard
::
BelCardPhoto
>
photo
=
belcard
::
BelCardGeneric
::
create
<
belcard
::
BelCardPhoto
>
();
photo
->
setValue
(
Utils
::
qStringToLinphoneString
(
file_id
));
photo
->
setValue
(
VCARD_SCHEME
+
Utils
::
qStringToLinphoneString
(
file_id
));
belCard
->
addPhoto
(
photo
);
m_linphone_friend
->
done
();
emit
contactUpdated
();
return
true
;
}
...
...
tests/src/components/contacts/ContactModel.hpp
View file @
f4c56c99
...
...
@@ -57,10 +57,7 @@ signals:
private:
QString
getUsername
()
const
;
QString
getAvatar
()
const
{
return
""
;
}
QString
getAvatar
()
const
;
bool
setAvatar
(
const
QString
&
path
);
Presence
::
PresenceStatus
getPresenceStatus
()
const
;
...
...
tests/ui/modules/Common/Image/RoundedImage.qml
View file @
f4c56c99
...
...
@@ -6,9 +6,9 @@ Item {
id
:
item
property
alias
source
:
image
.
source
property
alias
status
:
image
.
status
// READONLY!!!
property
color
backgroundColor
:
'
#00000000
'
property
color
foregroundColor
:
'
#00000000
'
// vec4(0.812, 0.843, 0.866, 1.0) 0.9
Item
{
id
:
imageContainer
...
...
tests/ui/modules/Linphone/Chat/IncomingMessage.qml
View file @
f4c56c99
...
...
@@ -20,6 +20,7 @@ RowLayout {
Avatar
{
anchors.centerIn
:
parent
height
:
ChatStyle
.
entry
.
message
.
incoming
.
avatarSize
image
:
_contact
.
avatar
username
:
LinphoneUtils
.
getContactUsername
(
_contact
)
width
:
ChatStyle
.
entry
.
message
.
incoming
.
avatarSize
}
...
...
tests/ui/modules/Linphone/Contact/Avatar.qml
View file @
f4c56c99
import
QtQuick
2.7
import
QtGraphicalEffects
1.0
import
Common
1.0
import
Linphone
1.0
...
...
@@ -11,10 +10,10 @@ import Utils 1.0
Item
{
id
:
avatar
property
alias
image
:
roundedImage
.
source
property
alias
presenceLevel
:
presenceLevel
.
level
property
color
backgroundColor
:
AvatarStyle
.
backgroundColor
property
string
username
property
var
image
property
var
_initialsRegex
:
/^
\s
*
([^\s\.]
+
)(?:[\s\.]
+
([^\s\.]
+
))?
/
...
...
@@ -46,6 +45,7 @@ Item {
anchors.fill
:
parent
backgroundColor
:
avatar
.
backgroundColor
source
:
avatar
.
image
||
''
}
Text
{
...
...
tests/ui/modules/Linphone/Contact/Contact.qml
View file @
f4c56c99
...
...
@@ -38,7 +38,7 @@ Rectangle {
Layout.preferredHeight
:
ContactStyle
.
contentHeight
Layout.preferredWidth
:
ContactStyle
.
contentHeight
image
:
contact
.
avatar
||
''
image
:
contact
.
avatar
presenceLevel
:
contact
.
presenceLevel
||
Presence
.
White
username
:
LinphoneUtils
.
getContactUsername
(
contact
)
}
...
...
tests/ui/views/App/MainWindow/ContactEdit.qml
View file @
f4c56c99
...
...
@@ -81,29 +81,23 @@ ColumnLayout {
spacing
:
ContactEditStyle
.
infoBar
.
spacing
Avatar
{
id
:
avatar
height
:
ContactEditStyle
.
infoBar
.
avatarSize
width
:
ContactEditStyle
.
infoBar
.
avatarSize
username
:
LinphoneUtils
.
getContactUsername
(
_contact
)
visible
:
isLoaded
()
MouseArea
{
anchors.fill
:
parent
onClicked
:
avatarChooser
.
open
()
}
}
ActionButton
{
Layout.preferredHeight
:
ContactEditStyle
.
infoBar
.
avatarSize
Layout.preferredWidth
:
ContactEditStyle
.
infoBar
.
avatarSize
icon
:
'
contact_card_photo
'
visible
:
!
avatar
.
isLoaded
()
onClicked
:
avatarChooser
.
open
()
Avatar
{
id
:
avatar
anchors.fill
:
parent
image
:
_contact
.
avatar
username
:
LinphoneUtils
.
getContactUsername
(
_contact
)
visible
:
isLoaded
()
&&
!
parent
.
hovered
}
}
Text
{
...
...
tests/ui/views/App/MainWindow/Conversation.qml
View file @
f4c56c99
...
...
@@ -57,6 +57,7 @@ ColumnLayout {
Layout.preferredHeight
:
ConversationStyle
.
bar
.
avatarSize
Layout.preferredWidth
:
ConversationStyle
.
bar
.
avatarSize
image
:
_contact
.
avatar
presenceLevel
:
_contact
.
presenceLevel
||
Presence
.
White
username
:
LinphoneUtils
.
getContactUsername
(
_contact
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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