Commit 472f9a74 authored by Nathaniel Graham's avatar Nathaniel Graham

Fix using avatars from the gallery and from local files

Summary:
BUG: 385151

Use a KIO::copy job to ensure that ~/.face gets created correctly, and delete any temp files once they're no longer needed.

Test Plan: Tested in KDE Neon. With this change, ~/.face gets created properly, both when it did not previously exist (i.e. when the user is setting a picture for the first time), and also when it did previously exist (i.e. when the user is changing their picture). Tested for gallery avatars as well as several local files (.png, .jpg, .webp).

Reviewers: apol, #plasma, mlaurent, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D8793
parent 5c072eab
......@@ -188,11 +188,11 @@ bool AccountInfo::save()
faceFile.append(QLatin1String("/.face"));
QFile::remove(faceFile);
KIO::CopyJob* moveJob = KIO::move(QUrl::fromLocalFile(path), QUrl::fromLocalFile(faceFile), KIO::HideProgressInfo);
connect(moveJob, SIGNAL(finished(KJob*)), SLOT(avatarModelChanged(KJob*)));
moveJob->setUiDelegate(0);
moveJob->setUiDelegateExtension(0);
moveJob->start();
KIO::CopyJob* copyJob = KIO::copy(QUrl::fromLocalFile(path), QUrl::fromLocalFile(faceFile), KIO::HideProgressInfo);
connect(copyJob, SIGNAL(finished(KJob*)), SLOT(avatarModelChanged(KJob*)));
copyJob->setUiDelegate(0);
copyJob->setUiDelegateExtension(0);
copyJob->start();
QString faceFile2 = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
faceFile2.append(QLatin1String("/.face.icon"));
......@@ -456,6 +456,10 @@ void AccountInfo::avatarModelChanged(KJob* job)
KIO::CopyJob* cJob = qobject_cast<KIO::CopyJob*>(job);
m_model->setData(m_index, QVariant(cJob->destUrl().path()), AccountModel::Face);
m_info->face->setIcon(QIcon(m_model->data(m_index, AccountModel::Face).value<QPixmap>()));
// If there is a leftover temp file, remove it
if (cJob->srcUrls().constFirst().path().startsWith(QLatin1String("/tmp/"))) {
QFile::remove(cJob->srcUrls().constFirst().path());
}
}
void AccountInfo::clearAvatar()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment