2016-05-12 16:05:20 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "profile/profile_cover.h"
|
|
|
|
|
|
|
|
#include "styles/style_profile.h"
|
2016-05-23 12:41:09 +00:00
|
|
|
#include "ui/buttons/round_button.h"
|
2016-05-25 17:59:21 +00:00
|
|
|
#include "ui/filedialog.h"
|
2016-05-24 16:13:07 +00:00
|
|
|
#include "observer_peer.h"
|
2016-05-25 17:59:21 +00:00
|
|
|
#include "boxes/confirmbox.h"
|
2016-05-25 12:09:05 +00:00
|
|
|
#include "boxes/contactsbox.h"
|
2016-05-25 17:59:21 +00:00
|
|
|
#include "boxes/photocropbox.h"
|
2016-05-12 16:05:20 +00:00
|
|
|
#include "lang.h"
|
|
|
|
#include "apiwrap.h"
|
|
|
|
#include "mainwidget.h"
|
2016-05-14 16:57:06 +00:00
|
|
|
#include "mainwindow.h"
|
2016-05-12 16:05:20 +00:00
|
|
|
|
|
|
|
namespace Profile {
|
2016-05-14 16:57:06 +00:00
|
|
|
namespace {
|
2016-05-12 16:05:20 +00:00
|
|
|
|
2016-05-14 16:57:06 +00:00
|
|
|
class OnlineCounter {
|
2016-05-12 16:05:20 +00:00
|
|
|
public:
|
2016-05-14 16:57:06 +00:00
|
|
|
OnlineCounter() : _currentTime(unixtime()), _self(App::self()) {
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
2016-05-14 16:57:06 +00:00
|
|
|
void feedUser(UserData *user) {
|
|
|
|
if (App::onlineForSort(user, _currentTime) > _currentTime) {
|
|
|
|
++_result;
|
|
|
|
if (user != _self) {
|
|
|
|
_onlyMe = false;
|
|
|
|
}
|
|
|
|
}
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
2016-05-14 16:57:06 +00:00
|
|
|
QString result(int fullCount) const {
|
|
|
|
if (_result > 0 && !_onlyMe) {
|
|
|
|
return lng_chat_status_members_online(lt_count, fullCount, lt_count_online, _result);
|
|
|
|
}
|
|
|
|
return lng_chat_status_members(lt_count, fullCount);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-05-14 16:57:06 +00:00
|
|
|
bool _onlyMe = true;
|
|
|
|
int _result = 0;
|
|
|
|
int _currentTime;
|
|
|
|
UserData *_self;
|
2016-05-12 16:05:20 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-05-24 16:13:07 +00:00
|
|
|
const Notify::PeerUpdateFlags ButtonsUpdateFlags = Notify::PeerUpdateFlag::UserCanShareContact
|
|
|
|
| Notify::PeerUpdateFlag::ChatCanEdit
|
2016-05-25 17:59:21 +00:00
|
|
|
| Notify::PeerUpdateFlag::ChannelCanEditPhoto
|
|
|
|
| Notify::PeerUpdateFlag::ChannelCanAddMembers
|
2016-05-24 16:13:07 +00:00
|
|
|
| Notify::PeerUpdateFlag::ChannelAmIn;
|
|
|
|
|
2016-05-14 16:57:06 +00:00
|
|
|
} // namespace
|
|
|
|
|
2016-05-25 17:59:21 +00:00
|
|
|
class PhotoButton final : public Button, public Notify::Observer {
|
2016-05-12 16:05:20 +00:00
|
|
|
public:
|
|
|
|
PhotoButton(QWidget *parent, PeerData *peer) : Button(parent), _peer(peer) {
|
|
|
|
resize(st::profilePhotoSize, st::profilePhotoSize);
|
2016-05-25 17:59:21 +00:00
|
|
|
|
|
|
|
processNewPeerPhoto();
|
|
|
|
|
|
|
|
Notify::registerPeerObserver(Notify::PeerUpdateFlag::PhotoChanged, this, &PhotoButton::notifyPeerUpdated);
|
|
|
|
FileDownload::registerImageLoadedObserver(this, &PhotoButton::notifyImageLoaded);
|
2016-05-14 16:57:06 +00:00
|
|
|
}
|
2016-05-12 16:05:20 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
2016-05-25 17:59:21 +00:00
|
|
|
p.drawPixmap(0, 0, _userpic);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-05-25 17:59:21 +00:00
|
|
|
void notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer != _peer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
processNewPeerPhoto();
|
|
|
|
this->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void notifyImageLoaded() {
|
|
|
|
if (_waiting && _peer->userpicLoaded()) {
|
|
|
|
_waiting = false;
|
|
|
|
_userpic = _peer->genUserpic(st::profilePhotoSize);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void processNewPeerPhoto() {
|
|
|
|
bool hasPhoto = (_peer->photoId && _peer->photoId != UnknownPeerPhotoId);
|
|
|
|
setCursor(hasPhoto ? style::cur_pointer : style::cur_default);
|
|
|
|
_waiting = !_peer->userpicLoaded();
|
|
|
|
if (_waiting) {
|
|
|
|
_peer->loadUserpic(true);
|
|
|
|
} else {
|
|
|
|
_userpic = _peer->genUserpic(st::profilePhotoSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
PeerData *_peer;
|
2016-05-25 17:59:21 +00:00
|
|
|
bool _waiting = false;
|
|
|
|
QPixmap _userpic;
|
2016-05-12 16:05:20 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-05-26 16:05:39 +00:00
|
|
|
class DropArea : public TWidget {
|
|
|
|
public:
|
|
|
|
DropArea(QWidget *parent) : TWidget(parent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void showAnimated() {
|
|
|
|
show();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override {
|
|
|
|
Painter p(this);
|
|
|
|
p.fillRect(e->rect(), st::profileDropAreaBg);
|
|
|
|
|
|
|
|
if (width() < st::profileDropAreaPadding.left() + st::profileDropAreaPadding.right()) return;
|
|
|
|
if (height() < st::profileDropAreaPadding.top() + st::profileDropAreaPadding.bottom()) return;
|
|
|
|
|
|
|
|
auto border = st::profileDropAreaBorderWidth;
|
|
|
|
auto &borderFg = st::profileDropAreaBorderFg;
|
|
|
|
auto inner = rect().marginsRemoved(st::profileDropAreaPadding);
|
|
|
|
p.fillRect(inner.x(), inner.y(), inner.width(), border, borderFg);
|
|
|
|
p.fillRect(inner.x(), inner.y() + inner.height() - border, inner.width(), border, borderFg);
|
|
|
|
p.fillRect(inner.x(), inner.y() + border, border, inner.height() - 2 * border, borderFg);
|
|
|
|
p.fillRect(inner.x() + inner.width() - border, inner.y() + border, border, inner.height() - 2 * border, borderFg);
|
|
|
|
|
|
|
|
auto title = lang(lng_profile_drop_area_title);
|
|
|
|
int titleWidth = st::profileDropAreaTitleFont->width(title);
|
|
|
|
int titleLeft = inner.x() + (inner.width() - titleWidth) / 2;
|
|
|
|
int titleTop = inner.y() + st::profileDropAreaTitleTop + st::profileDropAreaTitleFont->ascent;
|
|
|
|
p.setFont(st::profileDropAreaTitleFont);
|
|
|
|
p.setPen(st::profileDropAreaFg);
|
|
|
|
p.drawText(titleLeft, titleTop, title);
|
|
|
|
|
|
|
|
auto subtitle = lang(lng_profile_drop_area_subtitle);
|
|
|
|
int subtitleWidth = st::profileDropAreaSubtitleFont->width(subtitle);
|
|
|
|
int subtitleLeft = inner.x() + (inner.width() - subtitleWidth) / 2;
|
|
|
|
int subtitleTop = inner.y() + st::profileDropAreaSubtitleTop + st::profileDropAreaSubtitleFont->ascent;
|
|
|
|
p.setFont(st::profileDropAreaSubtitleFont);
|
|
|
|
p.setPen(st::profileDropAreaFg);
|
|
|
|
p.drawText(subtitleLeft, subtitleTop, subtitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
CoverWidget::CoverWidget(QWidget *parent, PeerData *peer) : TWidget(parent)
|
|
|
|
, _peer(peer)
|
|
|
|
, _peerUser(peer->asUser())
|
|
|
|
, _peerChat(peer->asChat())
|
|
|
|
, _peerChannel(peer->asChannel())
|
|
|
|
, _peerMegagroup(peer->isMegagroup() ? _peerChannel : nullptr)
|
2016-05-26 15:31:20 +00:00
|
|
|
, _photoButton(this, peer)
|
|
|
|
, _name(this, QString(), st::profileNameLabel) {
|
2016-05-12 16:05:20 +00:00
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
2016-05-26 16:05:39 +00:00
|
|
|
setAcceptDrops(true);
|
2016-05-12 16:05:20 +00:00
|
|
|
|
2016-05-26 15:31:20 +00:00
|
|
|
_name.setSelectable(true);
|
|
|
|
_name.setContextCopyText(lang(lng_profile_copy_fullname));
|
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
auto observeEvents = ButtonsUpdateFlags | Notify::PeerUpdateFlag::NameChanged;
|
2016-05-24 16:13:07 +00:00
|
|
|
Notify::registerPeerObserver(observeEvents, this, &CoverWidget::notifyPeerUpdated);
|
2016-05-25 17:59:21 +00:00
|
|
|
FileDialog::registerObserver(this, &CoverWidget::notifyFileQueryUpdated);
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2016-05-14 16:57:06 +00:00
|
|
|
connect(_photoButton, SIGNAL(clicked()), this, SLOT(onPhotoShow()));
|
2016-05-12 16:05:20 +00:00
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
refreshNameText();
|
|
|
|
refreshStatusText();
|
2016-05-23 12:41:09 +00:00
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
refreshButtons();
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 16:57:06 +00:00
|
|
|
void CoverWidget::onPhotoShow() {
|
|
|
|
PhotoData *photo = (_peer->photoId && _peer->photoId != UnknownPeerPhotoId) ? App::photo(_peer->photoId) : nullptr;
|
|
|
|
if ((_peer->photoId == UnknownPeerPhotoId) || (_peer->photoId && !photo->date)) {
|
|
|
|
App::api()->requestFullPeer(_peer);
|
|
|
|
}
|
|
|
|
if (photo && photo->date) {
|
|
|
|
App::wnd()->showPhoto(photo, _peer);
|
|
|
|
}
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::resizeToWidth(int newWidth) {
|
|
|
|
int newHeight = 0;
|
|
|
|
|
|
|
|
newHeight += st::profileMarginTop;
|
|
|
|
_photoButton->moveToLeft(st::profilePhotoLeft, newHeight);
|
|
|
|
|
|
|
|
int infoLeft = _photoButton->x() + _photoButton->width();
|
2016-05-26 15:31:20 +00:00
|
|
|
int nameLeft = infoLeft + st::profileNameLeft - st::profileNameLabel.margin.left();
|
|
|
|
int nameTop = _photoButton->y() + st::profileNameTop - st::profileNameLabel.margin.top();
|
|
|
|
_name.moveToLeft(nameLeft, nameTop);
|
|
|
|
int nameWidth = width() - infoLeft - st::profileNameLeft - st::profileButtonSkip;
|
|
|
|
nameWidth += st::profileNameLabel.margin.left() + st::profileNameLabel.margin.right();
|
|
|
|
_name.resizeToWidth(nameWidth);
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
_statusPosition = QPoint(infoLeft + st::profileStatusLeft, _photoButton->y() + st::profileStatusTop);
|
|
|
|
|
2016-05-23 12:41:09 +00:00
|
|
|
int buttonLeft = st::profilePhotoLeft + _photoButton->width() + st::profileButtonLeft;
|
2016-05-25 17:59:21 +00:00
|
|
|
for_const (auto button, _buttons) {
|
|
|
|
button->moveToLeft(buttonLeft, st::profileButtonTop);
|
|
|
|
buttonLeft += button->width() + st::profileButtonSkip;
|
2016-05-23 12:41:09 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
newHeight += st::profilePhotoSize;
|
|
|
|
newHeight += st::profileMarginBottom;
|
2016-05-20 15:35:58 +00:00
|
|
|
|
|
|
|
_dividerTop = newHeight;
|
|
|
|
newHeight += st::profileDividerFill.height();
|
2016-05-12 16:05:20 +00:00
|
|
|
|
|
|
|
newHeight += st::profileBlocksTop;
|
|
|
|
|
|
|
|
resize(newWidth, newHeight);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::paintEvent(QPaintEvent *e) {
|
|
|
|
Painter p(this);
|
|
|
|
|
2016-05-20 15:35:58 +00:00
|
|
|
p.fillRect(e->rect(), st::profileBg);
|
2016-05-12 16:05:20 +00:00
|
|
|
|
|
|
|
p.setFont(st::profileStatusFont);
|
|
|
|
p.setPen(st::profileStatusFg);
|
|
|
|
p.drawTextLeft(_statusPosition.x(), _statusPosition.y(), width(), _statusText);
|
2016-05-20 15:35:58 +00:00
|
|
|
|
|
|
|
paintDivider(p);
|
|
|
|
}
|
|
|
|
|
2016-05-26 16:05:39 +00:00
|
|
|
void CoverWidget::dragEnterEvent(QDragEnterEvent *e) {
|
|
|
|
_dropArea = new DropArea(this);
|
|
|
|
_dropArea->setGeometry(0, 0, width(), _dividerTop);
|
|
|
|
_dropArea->showAnimated();
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::dragLeaveEvent(QDragLeaveEvent *e) {
|
|
|
|
delete _dropArea;
|
|
|
|
_dropArea = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::dropEvent(QDropEvent *e) {
|
|
|
|
delete _dropArea;
|
|
|
|
_dropArea = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-05-20 15:35:58 +00:00
|
|
|
void CoverWidget::paintDivider(Painter &p) {
|
|
|
|
st::profileDividerLeft.paint(p, QPoint(st::lineWidth, _dividerTop), width());
|
|
|
|
|
|
|
|
int toFillLeft = st::lineWidth + st::profileDividerLeft.width();
|
|
|
|
QRect toFill = rtlrect(toFillLeft, _dividerTop, width() - toFillLeft, st::profileDividerFill.height(), width());
|
|
|
|
st::profileDividerFill.fill(p, toFill);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
void CoverWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
2016-05-25 17:59:21 +00:00
|
|
|
if (update.peer != _peer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((update.flags & ButtonsUpdateFlags) != 0) {
|
|
|
|
refreshButtons();
|
|
|
|
}
|
|
|
|
if (update.flags & Notify::PeerUpdateFlag::NameChanged) {
|
|
|
|
refreshNameText();
|
2016-05-25 12:09:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::refreshNameText() {
|
2016-05-26 15:31:20 +00:00
|
|
|
_name.setText(App::peerName(_peer));
|
2016-05-25 12:09:05 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::refreshStatusText() {
|
2016-05-12 16:05:20 +00:00
|
|
|
int currentTime = unixtime();
|
|
|
|
if (_peerUser) {
|
|
|
|
_statusText = App::onlineText(_peerUser, currentTime, true);
|
|
|
|
} else if (_peerChat && _peerChat->amIn()) {
|
|
|
|
if (_peerChat->noParticipantInfo()) {
|
|
|
|
App::api()->requestFullPeer(_peer);
|
|
|
|
if (_statusText.isEmpty()) {
|
|
|
|
_statusText = lng_chat_status_members(lt_count, _peerChat->count);
|
|
|
|
}
|
|
|
|
} else {
|
2016-05-14 16:57:06 +00:00
|
|
|
OnlineCounter counter;
|
|
|
|
auto &participants = _peerChat->participants;
|
|
|
|
for (auto i = participants.cbegin(), e = participants.cend(); i != e; ++i) {
|
|
|
|
counter.feedUser(i.key());
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
2016-05-14 16:57:06 +00:00
|
|
|
_statusText = counter.result(participants.size());
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
} else if (isUsingMegagroupOnlineCount()) {
|
2016-05-14 16:57:06 +00:00
|
|
|
OnlineCounter counter;
|
|
|
|
for_const (auto user, _peerMegagroup->mgInfo->lastParticipants) {
|
|
|
|
counter.feedUser(user);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
2016-05-14 16:57:06 +00:00
|
|
|
_statusText = counter.result(_peerMegagroup->count);
|
2016-05-12 16:05:20 +00:00
|
|
|
} else if (_peerChannel) {
|
|
|
|
if (_peerChannel->count > 0) {
|
|
|
|
_statusText = lng_chat_status_members(lt_count, _peerChannel->count);
|
|
|
|
} else {
|
|
|
|
_statusText = lang(_peerChannel->isMegagroup() ? lng_group_status : lng_channel_status);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_statusText = lang(lng_chat_status_unaccessible);
|
|
|
|
}
|
2016-05-25 12:09:05 +00:00
|
|
|
update();
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CoverWidget::isUsingMegagroupOnlineCount() const {
|
|
|
|
if (!_peerMegagroup || !_peerMegagroup->amIn()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_peerMegagroup->count <= 0 || _peerMegagroup->count > Global::ChatSizeMax()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_peerMegagroup->mgInfo->lastParticipants.isEmpty() || _peerMegagroup->lastParticipantsCountOutdated()) {
|
|
|
|
App::api()->requestLastParticipants(_peerMegagroup);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
void CoverWidget::refreshButtons() {
|
2016-05-25 17:59:21 +00:00
|
|
|
clearButtons();
|
2016-05-24 16:13:07 +00:00
|
|
|
if (_peerUser) {
|
|
|
|
setUserButtons();
|
|
|
|
} else if (_peerChat) {
|
|
|
|
setChatButtons();
|
|
|
|
} else if (_peerMegagroup) {
|
|
|
|
setMegagroupButtons();
|
|
|
|
} else if (_peerChannel) {
|
|
|
|
setChannelButtons();
|
|
|
|
}
|
|
|
|
resizeToWidth(width());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::setUserButtons() {
|
2016-05-25 17:59:21 +00:00
|
|
|
addButton(lang(lng_profile_send_message), SLOT(onSendMessage()));
|
2016-05-24 16:13:07 +00:00
|
|
|
if (_peerUser->canShareThisContact()) {
|
2016-05-25 17:59:21 +00:00
|
|
|
addButton(lang(lng_profile_share_contact), SLOT(onShareContact()));
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::setChatButtons() {
|
|
|
|
if (_peerChat->canEdit()) {
|
2016-05-25 17:59:21 +00:00
|
|
|
addButton(lang(lng_profile_set_group_photo), SLOT(onSetPhoto()));
|
|
|
|
addButton(lang(lng_profile_add_participant), SLOT(onAddMember()));
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::setMegagroupButtons() {
|
|
|
|
if (_peerMegagroup->canEditPhoto()) {
|
2016-05-25 17:59:21 +00:00
|
|
|
addButton(lang(lng_profile_set_group_photo), SLOT(onSetPhoto()));
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
if (_peerMegagroup->canAddParticipants()) {
|
2016-05-25 17:59:21 +00:00
|
|
|
addButton(lang(lng_profile_add_participant), SLOT(onAddMember()));
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::setChannelButtons() {
|
|
|
|
if (_peerChannel->amCreator()) {
|
2016-05-25 17:59:21 +00:00
|
|
|
addButton(lang(lng_profile_set_group_photo), SLOT(onSetPhoto()));
|
2016-05-24 16:13:07 +00:00
|
|
|
} else if (_peerChannel->amIn()) {
|
2016-05-25 17:59:21 +00:00
|
|
|
addButton(lang(lng_profile_view_channel), SLOT(onViewChannel()));
|
2016-05-24 16:13:07 +00:00
|
|
|
} else {
|
2016-05-25 17:59:21 +00:00
|
|
|
addButton(lang(lng_profile_join_channel), SLOT(onJoin()));
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 17:59:21 +00:00
|
|
|
void CoverWidget::clearButtons() {
|
|
|
|
auto buttons = createAndSwap(_buttons);
|
|
|
|
for_const (auto button, buttons) {
|
|
|
|
delete button;
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 17:59:21 +00:00
|
|
|
void CoverWidget::addButton(const QString &text, const char *slot) {
|
2016-05-24 16:13:07 +00:00
|
|
|
if (!text.isEmpty()) {
|
2016-05-25 17:59:21 +00:00
|
|
|
auto &buttonStyle = _buttons.isEmpty() ? st::profilePrimaryButton : st::profileSecondaryButton;
|
|
|
|
_buttons.push_back(new Ui::RoundButton(this, text, buttonStyle));
|
|
|
|
connect(_buttons.back(), SIGNAL(clicked()), this, slot);
|
|
|
|
_buttons.back()->show();
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
void CoverWidget::onSendMessage() {
|
|
|
|
Ui::showPeerHistory(_peer, ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::onShareContact() {
|
|
|
|
App::main()->shareContactLayer(_peerUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::onSetPhoto() {
|
2016-05-25 17:59:21 +00:00
|
|
|
QStringList imgExtensions(cImgExtensions());
|
|
|
|
QString filter(qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;All files (*.*)"));
|
|
|
|
|
|
|
|
_setPhotoFileQueryId = FileDialog::queryReadFile(lang(lng_choose_images), filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) {
|
|
|
|
if (_setPhotoFileQueryId != update.queryId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_setPhotoFileQueryId = 0;
|
|
|
|
|
|
|
|
if (update.filePaths.isEmpty() && update.remoteContent.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage img;
|
|
|
|
if (!update.remoteContent.isEmpty()) {
|
|
|
|
img = App::readImage(update.remoteContent);
|
|
|
|
} else {
|
|
|
|
img = App::readImage(update.filePaths.front());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) {
|
|
|
|
Ui::showLayer(new InformBox(lang(lng_bad_photo)));
|
|
|
|
return;
|
|
|
|
}
|
2016-05-25 12:09:05 +00:00
|
|
|
|
2016-05-25 17:59:21 +00:00
|
|
|
auto box = new PhotoCropBox(img, _peer);
|
|
|
|
connect(box, SIGNAL(closed()), this, SLOT(onPhotoUpdateStart()));
|
|
|
|
Ui::showLayer(box);
|
2016-05-25 12:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::onAddMember() {
|
|
|
|
if (_peerChat) {
|
|
|
|
Ui::showLayer(new ContactsBox(_peerChat, MembersFilterRecent));
|
|
|
|
} else if (_peerChannel && _peerChannel->mgInfo) {
|
|
|
|
MembersAlreadyIn already;
|
2016-05-25 17:59:21 +00:00
|
|
|
for_const (auto user, _peerChannel->mgInfo->lastParticipants) {
|
|
|
|
already.insert(user);
|
2016-05-25 12:09:05 +00:00
|
|
|
}
|
|
|
|
Ui::showLayer(new ContactsBox(_peerChannel, MembersFilterRecent, already));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::onJoin() {
|
2016-05-25 17:59:21 +00:00
|
|
|
if (!_peerChannel) return;
|
2016-05-25 12:09:05 +00:00
|
|
|
|
2016-05-25 17:59:21 +00:00
|
|
|
App::api()->joinChannel(_peerChannel);
|
2016-05-25 12:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::onViewChannel() {
|
|
|
|
Ui::showPeerHistory(_peer, ShowAtUnreadMsgId);
|
|
|
|
}
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
} // namespace Profile
|