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
8797a2e0
Commit
8797a2e0
authored
May 04, 2017
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(src/components/contact/VcardModel): handle correctly the clean algorithm of avatars
parent
c5ad9251
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
50 deletions
+45
-50
VcardModel.cpp
linphone-desktop/src/components/contact/VcardModel.cpp
+36
-48
ContactEdit.js
linphone-desktop/ui/views/App/Main/ContactEdit.js
+9
-2
No files found.
linphone-desktop/src/components/contact/VcardModel.cpp
View file @
8797a2e0
...
...
@@ -71,7 +71,7 @@ inline shared_ptr<belcard::BelCardPhoto> findBelcardPhoto (const shared_ptr<belc
return
nullptr
;
}
inline
void
removeBelcardPhoto
(
const
shared_ptr
<
belcard
::
BelCard
>
&
belcard
)
{
inline
void
removeBelcardPhoto
(
const
shared_ptr
<
belcard
::
BelCard
>
&
belcard
,
bool
cleanPathsOnly
=
false
)
{
list
<
shared_ptr
<
belcard
::
BelCardPhoto
>
>
photos
;
for
(
const
auto
photo
:
belcard
->
getPhotos
())
{
if
(
isLinphoneDesktopPhoto
(
photo
))
...
...
@@ -85,8 +85,13 @@ inline void removeBelcardPhoto (const shared_ptr<belcard::BelCard> &belcard) {
)
);
if
(
!
QFile
::
remove
(
imagePath
))
qWarning
()
<<
QStringLiteral
(
"Unable to remove `%1`."
).
arg
(
imagePath
);
if
(
!
cleanPathsOnly
)
{
if
(
!
QFile
::
remove
(
imagePath
))
qWarning
()
<<
QStringLiteral
(
"Unable to remove `%1`."
).
arg
(
imagePath
);
else
qInfo
()
<<
QStringLiteral
(
"Remove `%1`."
).
arg
(
imagePath
);
}
belcard
->
removePhoto
(
photo
);
}
}
...
...
@@ -101,24 +106,8 @@ VcardModel::VcardModel (shared_ptr<linphone::Vcard> vcard) {
VcardModel
::~
VcardModel
()
{
if
(
!
mIsReadOnly
)
{
qInfo
()
<<
QStringLiteral
(
"Destroy detached vcard:"
)
<<
this
;
// If it's a detached Vcard and if necessary the linked photo must be destroyed from fs.
if
(
mAvatarIsReadOnly
)
return
;
shared_ptr
<
belcard
::
BelCardPhoto
>
photo
(
findBelcardPhoto
(
mVcard
->
getVcard
()));
if
(
!
photo
)
return
;
QString
imagePath
(
::
Utils
::
linphoneStringToQString
(
Paths
::
getAvatarsDirPath
()
+
photo
->
getValue
().
substr
(
sizeof
(
VCARD_SCHEME
)
-
1
)
)
);
if
(
!
QFile
::
remove
(
imagePath
))
qWarning
()
<<
QStringLiteral
(
"Unable to remove `%1`."
).
arg
(
imagePath
);
if
(
!
mAvatarIsReadOnly
)
removeBelcardPhoto
(
mVcard
->
getVcard
());
}
else
qInfo
()
<<
QStringLiteral
(
"Destroy attached vcard:"
)
<<
this
;
}
...
...
@@ -143,48 +132,47 @@ bool VcardModel::setAvatar (const QString &path) {
CHECK_VCARD_IS_WRITABLE
(
this
);
shared_ptr
<
belcard
::
BelCard
>
belcard
=
mVcard
->
getVcard
();
// Remove avatar if path is empty.
if
(
path
.
isEmpty
())
{
removeBelcardPhoto
(
belcard
);
emit
vcardUpdated
();
return
true
;
}
QString
fileId
;
QFile
file
;
// 1. Try to copy photo in avatars folder.
QFile
file
(
path
);
if
(
!
path
.
isEmpty
())
{
file
.
setFileName
(
path
);
if
(
!
file
.
exists
()
||
QImageReader
::
imageFormat
(
path
).
size
()
==
0
)
return
false
;
if
(
!
file
.
exists
()
||
QImageReader
::
imageFormat
(
path
).
size
()
==
0
)
return
false
;
QFileInfo
info
(
file
);
QString
uuid
=
QUuid
::
createUuid
().
toString
();
QString
fileId
=
QStringLiteral
(
"%1.%2"
)
.
arg
(
uuid
.
mid
(
1
,
uuid
.
length
()
-
2
))
// Remove `{}`.
.
arg
(
info
.
suffix
());
QFileInfo
info
(
file
);
QString
uuid
=
QUuid
::
createUuid
().
toString
();
fileId
=
QStringLiteral
(
"%1.%2"
)
.
arg
(
uuid
.
mid
(
1
,
uuid
.
length
()
-
2
))
// Remove `{}`.
.
arg
(
info
.
suffix
());
QString
dest
=
::
Utils
::
linphoneStringToQString
(
Paths
::
getAvatarsDirPath
())
+
fileId
;
QString
dest
=
::
Utils
::
linphoneStringToQString
(
Paths
::
getAvatarsDirPath
())
+
fileId
;
if
(
!
file
.
copy
(
dest
))
return
false
;
if
(
!
file
.
copy
(
dest
))
return
false
;
qInfo
()
<<
QStringLiteral
(
"Update avatar of `%1`. (path=%2)"
).
arg
(
getUsername
()).
arg
(
dest
);
qInfo
()
<<
QStringLiteral
(
"Update avatar of `%1`. (path=%2)"
).
arg
(
getUsername
()).
arg
(
dest
);
}
// 2. Remove oldest photo.
if
(
!
mAvatarIsReadOnly
)
removeBelcardPhoto
(
belcard
);
removeBelcardPhoto
(
belcard
,
mAvatarIsReadOnly
);
mAvatarIsReadOnly
=
false
;
// 3. Update new photo.
shared_ptr
<
belcard
::
BelCardPhoto
>
photo
=
belcard
::
BelCardGeneric
::
create
<
belcard
::
BelCardPhoto
>
();
photo
->
setValue
(
VCARD_SCHEME
+
::
Utils
::
qStringToLinphoneString
(
fileId
));
if
(
!
path
.
isEmpty
())
{
shared_ptr
<
belcard
::
BelCardPhoto
>
photo
=
belcard
::
BelCardGeneric
::
create
<
belcard
::
BelCardPhoto
>
();
photo
->
setValue
(
VCARD_SCHEME
+
::
Utils
::
qStringToLinphoneString
(
fileId
));
if
(
!
belcard
->
addPhoto
(
photo
))
{
file
.
remove
();
return
false
;
}
}
emit
vcardUpdated
();
if
(
!
belcard
->
addPhoto
(
photo
))
return
false
;
return
true
;
}
...
...
linphone-desktop/ui/views/App/Main/ContactEdit.js
View file @
8797a2e0
...
...
@@ -12,8 +12,15 @@ function handleContactUpdated () {
var
contact
=
contactEdit
.
_contact
if
(
!
contactEdit
.
_edition
)
{
// Edition ended.
handleVcardChanged
(
contact
.
vcard
)
var
vcard
=
contact
.
vcard
if
(
contactEdit
.
_vcard
!==
vcard
)
{
// Not in edition mode, the contact was updated in other place.
contactEdit
.
_vcard
=
vcard
}
else
{
// Edition ended.
handleVcardChanged
(
contact
.
vcard
)
}
}
else
{
// Edition not ended, the contact was updated in other place.
// Update fields with new data.
...
...
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