-
Notifications
You must be signed in to change notification settings - Fork 668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display Avatar pictures in the Settingsdialog #5482
Changes from all commits
b49dd02
e05d6bf
d466a05
2a12610
c00e3e8
e95b73d
5e33898
554d1b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+1 −0 | src/macpreferenceswindow.h | |
+10 −0 | src/macpreferenceswindow.mm |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,8 @@ | |
#include <QPixmap> | ||
#include <QImage> | ||
#include <QWidgetAction> | ||
#include <QPainter> | ||
#include <QPainterPath> | ||
|
||
namespace { | ||
const char TOOLBAR_CSS[] = | ||
|
@@ -54,6 +56,23 @@ namespace { | |
|
||
namespace OCC { | ||
|
||
static QIcon circleMask( const QImage& avatar ) | ||
{ | ||
int dim = avatar.width(); | ||
|
||
QPixmap fixedImage(dim, dim); | ||
fixedImage.fill(Qt::transparent); | ||
|
||
QPainter imgPainter(&fixedImage); | ||
QPainterPath clip; | ||
clip.addEllipse(0, 0, dim, dim); | ||
imgPainter.setClipPath(clip); | ||
imgPainter.drawImage(0, 0, avatar); | ||
imgPainter.end(); | ||
|
||
return QIcon(fixedImage); | ||
} | ||
|
||
// | ||
// Whenever you change something here check both settingsdialog.cpp and settingsdialogmac.cpp ! | ||
// | ||
|
@@ -196,8 +215,17 @@ void SettingsDialog::accountAdded(AccountState *s) | |
|
||
bool brandingSingleAccount = !Theme::instance()->multiAccount(); | ||
|
||
auto accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"), | ||
brandingSingleAccount ? tr("Account") : s->account()->displayName()); | ||
QAction *accountAction; | ||
QImage avatar = s->account()->avatar(); | ||
const QString actionText = brandingSingleAccount ? tr("Account") : s->account()->displayName(); | ||
if(avatar.isNull()) { | ||
accountAction = createColorAwareAction(QLatin1String(":/client/resources/account.png"), | ||
actionText); | ||
} else { | ||
QIcon icon = circleMask(avatar); | ||
accountAction = createActionWithIcon(icon, actionText); | ||
} | ||
|
||
if (!brandingSingleAccount) { | ||
accountAction->setToolTip(s->account()->displayName()); | ||
accountAction->setIconText(s->shortDisplayNameForSettings(height * buttonSizeRatio)); | ||
|
@@ -207,14 +235,30 @@ void SettingsDialog::accountAdded(AccountState *s) | |
_ui->stack->insertWidget(0 , accountSettings); | ||
_actionGroup->addAction(accountAction); | ||
_actionGroupWidgets.insert(accountAction, accountSettings); | ||
_actionForAccount.insert(s->account().data(), accountAction); | ||
|
||
connect( accountSettings, SIGNAL(folderChanged()), _gui, SLOT(slotFoldersChanged())); | ||
connect( accountSettings, SIGNAL(openFolderAlias(const QString&)), | ||
_gui, SLOT(slotFolderOpenAction(QString))); | ||
connect(s->account().data(), SIGNAL(accountChangedAvatar()), SLOT(slotAccountAvatarChanged())); | ||
|
||
slotRefreshActivity(s); | ||
} | ||
|
||
void SettingsDialog::slotAccountAvatarChanged() | ||
{ | ||
Account *account = static_cast<Account*>(sender()); | ||
if( account && _actionForAccount.contains(account)) { | ||
QAction *action = _actionForAccount[account]; | ||
if( action ) { | ||
QImage pix = account->avatar(); | ||
if( !pix.isNull() ) { | ||
action->setIcon( circleMask(pix) ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void SettingsDialog::accountRemoved(AccountState *s) | ||
{ | ||
for (auto it = _actionGroupWidgets.begin(); it != _actionGroupWidgets.end(); ++it) { | ||
|
@@ -236,6 +280,9 @@ void SettingsDialog::accountRemoved(AccountState *s) | |
} | ||
} | ||
|
||
if( _actionForAccount.contains(s->account().data()) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small detail: No need of the if here. remove does nothing if it is not there. |
||
_actionForAccount.remove(s->account().data()); | ||
} | ||
_activitySettings->slotRemoveAccount(s); | ||
|
||
// Hide when the last account is deleted. We want to enter the same | ||
|
@@ -306,14 +353,22 @@ class ToolButtonAction : public QWidgetAction | |
} | ||
}; | ||
|
||
QAction *SettingsDialog::createActionWithIcon(const QIcon& icon, const QString& text, const QString& iconPath) | ||
{ | ||
QAction *action = new ToolButtonAction(icon, text, this); | ||
action->setCheckable(true); | ||
if(!iconPath.isEmpty()) { | ||
action->setProperty("iconPath", iconPath); | ||
} | ||
return action; | ||
|
||
} | ||
|
||
QAction *SettingsDialog::createColorAwareAction(const QString &iconPath, const QString &text) | ||
{ | ||
// all buttons must have the same size in order to keep a good layout | ||
QIcon coloredIcon = createColorAwareIcon(iconPath); | ||
QAction *action = new ToolButtonAction(coloredIcon, text, this); | ||
action->setCheckable(true); | ||
action->setProperty("iconPath", iconPath); | ||
return action; | ||
return createActionWithIcon(coloredIcon, text, iconPath); | ||
} | ||
|
||
void SettingsDialog::slotRefreshActivity( AccountState* accountState ) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include <QtCore> | ||
#include <QNetworkReply> | ||
#include <QNetworkProxyFactory> | ||
#include <QPixmap> | ||
|
||
#include "connectionvalidator.h" | ||
#include "account.h" | ||
|
@@ -252,7 +253,18 @@ void ConnectionValidator::slotUserFetched(const QVariantMap &json) | |
QString user = json.value("ocs").toMap().value("data").toMap().value("id").toString(); | ||
if (!user.isEmpty()) { | ||
_account->setDavUser(user); | ||
|
||
AvatarJob *job = new AvatarJob(_account, this); | ||
job->setTimeout(20*1000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (I think it should use the same timeout as all the other jobs in this file, for consistency) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ogoffart wouldn''t it make more sense to set it in the constructor of AvatarJob anyway? |
||
QObject::connect(job, SIGNAL(avatarPixmap(QImage)), this, SLOT(slotAvatarImage(QImage))); | ||
|
||
job->start(); | ||
} | ||
} | ||
|
||
void ConnectionValidator::slotAvatarImage(const QImage& img) | ||
{ | ||
_account->setAvatar(img); | ||
reportResult(Connected); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
#include <QMutex> | ||
#include <QDebug> | ||
#include <QCoreApplication> | ||
#include <QPixmap> | ||
|
||
#include "json.h" | ||
|
||
|
@@ -589,6 +590,42 @@ bool PropfindJob::finished() | |
|
||
/*********************************************************************************************/ | ||
|
||
AvatarJob::AvatarJob(AccountPtr account, QObject *parent) | ||
: AbstractNetworkJob(account, QString(), parent) | ||
{ | ||
_avatarUrl = Utility::concatUrlPath(account->url(), QString("remote.php/dav/avatars/%1/128.png").arg(account->davUser())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does not work for me with this URL. (owncloud master) @DeepDiver1975 What's the exact URL of the avatars? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think the pull request that is implementing the avatar images is not yet merged in core: owncloud/core#26872 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then let's delay this PR to master/2.4? sorry for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, sure. |
||
} | ||
|
||
void AvatarJob::start() | ||
{ | ||
QNetworkRequest req; | ||
setReply(davRequest("GET", _avatarUrl, req)); | ||
setupConnections(reply()); | ||
AbstractNetworkJob::start(); | ||
} | ||
|
||
bool AvatarJob::finished() | ||
{ | ||
int http_result_code = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); | ||
|
||
QImage avImage; | ||
|
||
if (http_result_code == 200) { | ||
|
||
QByteArray pngData = reply()->readAll(); | ||
if( pngData.size() ) { | ||
|
||
if( avImage.loadFromData(pngData) ) { | ||
qDebug() << "Retrieved Avatar pixmap!"; | ||
} | ||
} | ||
} | ||
emit(avatarPixmap(avImage)); | ||
return true; | ||
} | ||
|
||
/*********************************************************************************************/ | ||
|
||
ProppatchJob::ProppatchJob(AccountPtr account, const QString &path, QObject *parent) | ||
: AbstractNetworkJob(account, path, parent) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will never be called since accountAdded is called before the ConnectionValidator can run?