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-27 10:57:11 +00:00
|
|
|
#include "profile/profile_cover_drop_area.h"
|
|
|
|
#include "profile/profile_userpic_button.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-06-24 16:58:41 +00:00
|
|
|
#include "ui/flatlabel.h"
|
|
|
|
#include "ui/flatbutton.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-06-24 16:58:41 +00:00
|
|
|
#include "application.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-06-01 20:05:37 +00:00
|
|
|
using UpdateFlag = Notify::PeerUpdate::Flag;
|
|
|
|
const auto ButtonsUpdateFlags = UpdateFlag::UserCanShareContact
|
2016-06-20 15:40:36 +00:00
|
|
|
| UpdateFlag::BotCanAddToGroups
|
2016-06-01 20:05:37 +00:00
|
|
|
| UpdateFlag::ChatCanEdit
|
|
|
|
| UpdateFlag::ChannelCanEditPhoto
|
|
|
|
| UpdateFlag::ChannelCanAddMembers
|
|
|
|
| UpdateFlag::ChannelAmIn;
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2016-05-14 16:57:06 +00:00
|
|
|
} // namespace
|
|
|
|
|
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-27 10:57:11 +00:00
|
|
|
, _userpicButton(this, peer)
|
2016-05-31 19:27:11 +00:00
|
|
|
, _name(this, 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-06-24 16:58:41 +00:00
|
|
|
_name->setSelectable(true);
|
|
|
|
_name->setContextCopyText(lang(lng_profile_copy_fullname));
|
2016-05-26 15:31:20 +00:00
|
|
|
|
2016-06-04 20:29:16 +00:00
|
|
|
auto observeEvents = ButtonsUpdateFlags
|
|
|
|
| UpdateFlag::NameChanged
|
|
|
|
| UpdateFlag::UserOnlineChanged;
|
2016-09-26 18:33:34 +00:00
|
|
|
subscribe(Notify::PeerUpdated(), Notify::PeerUpdatedHandler(observeEvents, [this](const Notify::PeerUpdate &update) {
|
2016-09-26 13:57:08 +00:00
|
|
|
notifyPeerUpdated(update);
|
2016-09-26 18:33:34 +00:00
|
|
|
}));
|
2016-09-26 13:57:08 +00:00
|
|
|
subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) {
|
|
|
|
notifyFileQueryUpdated(update);
|
|
|
|
});
|
2016-05-24 16:13:07 +00:00
|
|
|
|
2016-06-24 16:58:41 +00:00
|
|
|
connect(App::app(), SIGNAL(peerPhotoDone(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
|
|
|
connect(App::app(), SIGNAL(peerPhotoFail(PeerId)), this, SLOT(onPhotoUploadStatusChanged(PeerId)));
|
|
|
|
|
2016-05-27 10:57:11 +00:00
|
|
|
connect(_userpicButton, SIGNAL(clicked()), this, SLOT(onPhotoShow()));
|
2016-06-01 20:05:37 +00:00
|
|
|
validatePhoto();
|
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-06-01 20:05:37 +00:00
|
|
|
PhotoData *CoverWidget::validatePhoto() const {
|
2016-05-14 16:57:06 +00:00
|
|
|
PhotoData *photo = (_peer->photoId && _peer->photoId != UnknownPeerPhotoId) ? App::photo(_peer->photoId) : nullptr;
|
2016-06-01 20:05:37 +00:00
|
|
|
if ((_peer->photoId == UnknownPeerPhotoId) || (_peer->photoId && (!photo || !photo->date))) {
|
2016-05-14 16:57:06 +00:00
|
|
|
App::api()->requestFullPeer(_peer);
|
2016-06-01 20:05:37 +00:00
|
|
|
return nullptr;
|
2016-05-14 16:57:06 +00:00
|
|
|
}
|
2016-06-01 20:05:37 +00:00
|
|
|
return photo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::onPhotoShow() {
|
|
|
|
if (auto photo = validatePhoto()) {
|
2016-05-14 16:57:06 +00:00
|
|
|
App::wnd()->showPhoto(photo, _peer);
|
|
|
|
}
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 16:58:41 +00:00
|
|
|
void CoverWidget::onCancelPhotoUpload() {
|
|
|
|
if (auto app = App::app()) {
|
|
|
|
app->cancelPhotoUpdate(_peer->id);
|
|
|
|
refreshStatusText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
int CoverWidget::countPhotoLeft(int newWidth) const {
|
|
|
|
int result = st::profilePhotoLeftMin;
|
|
|
|
result += (newWidth - st::wndMinWidth) / 2;
|
|
|
|
return qMin(result, st::profilePhotoLeftMax);
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
int CoverWidget::resizeGetHeight(int newWidth) {
|
2016-05-12 16:05:20 +00:00
|
|
|
int newHeight = 0;
|
|
|
|
|
|
|
|
newHeight += st::profileMarginTop;
|
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
_photoLeft = countPhotoLeft(newWidth);
|
|
|
|
_userpicButton->moveToLeft(_photoLeft, newHeight);
|
|
|
|
|
|
|
|
refreshNameGeometry(newWidth);
|
2016-05-26 15:31:20 +00:00
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
int infoLeft = _userpicButton->x() + _userpicButton->width();
|
2016-05-27 10:57:11 +00:00
|
|
|
_statusPosition = QPoint(infoLeft + st::profileStatusLeft, _userpicButton->y() + st::profileStatusTop);
|
2016-06-24 16:58:41 +00:00
|
|
|
if (_cancelPhotoUpload) {
|
|
|
|
_cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::profileStatusFont->width(_statusText) + st::profileStatusFont->spacew, _statusPosition.y());
|
|
|
|
}
|
2016-05-12 16:05:20 +00:00
|
|
|
|
2016-05-27 13:56:35 +00:00
|
|
|
moveAndToggleButtons(newWidth);
|
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;
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
resizeDropArea(newWidth);
|
|
|
|
return newHeight;
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
void CoverWidget::refreshNameGeometry(int newWidth) {
|
|
|
|
int infoLeft = _userpicButton->x() + _userpicButton->width();
|
|
|
|
int nameLeft = infoLeft + st::profileNameLeft - st::profileNameLabel.margin.left();
|
|
|
|
int nameTop = _userpicButton->y() + st::profileNameTop - st::profileNameLabel.margin.top();
|
2016-06-07 19:59:39 +00:00
|
|
|
int nameWidth = newWidth - infoLeft - st::profileNameLeft;
|
|
|
|
if (_peer->isVerified()) {
|
|
|
|
nameWidth -= st::profileVerifiedCheckPosition.x() + st::profileVerifiedCheck.width();
|
|
|
|
}
|
2016-05-31 19:27:11 +00:00
|
|
|
int marginsAdd = st::profileNameLabel.margin.left() + st::profileNameLabel.margin.right();
|
2016-06-24 16:58:41 +00:00
|
|
|
_name->resizeToWidth(qMin(nameWidth - marginsAdd, _name->naturalWidth()) + marginsAdd);
|
|
|
|
_name->moveToLeft(nameLeft, nameTop);
|
2016-05-31 19:27:11 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 13:56:35 +00:00
|
|
|
// A more generic solution would be allowing an optional icon button
|
|
|
|
// for each text button. But currently we use only one, so it is done easily:
|
|
|
|
// There can be primary + secondary + icon buttons. If primary + secondary fit,
|
|
|
|
// then icon is hidden, otherwise secondary is hidden and icon is shown.
|
2016-08-19 17:26:31 +00:00
|
|
|
void CoverWidget::moveAndToggleButtons(int newWidth) {
|
2016-05-31 19:27:11 +00:00
|
|
|
int buttonLeft = _userpicButton->x() + _userpicButton->width() + st::profileButtonLeft;
|
2016-08-19 17:26:31 +00:00
|
|
|
int buttonsRight = newWidth - st::profileButtonSkip;
|
2016-05-27 13:56:35 +00:00
|
|
|
for (int i = 0, count = _buttons.size(); i < count; ++i) {
|
2016-05-31 19:27:11 +00:00
|
|
|
auto &button = _buttons.at(i);
|
|
|
|
button.widget->moveToLeft(buttonLeft, st::profileButtonTop);
|
|
|
|
if (button.replacement) {
|
|
|
|
button.replacement->moveToLeft(buttonLeft, st::profileButtonTop);
|
|
|
|
if (buttonLeft + button.widget->width() > buttonsRight) {
|
|
|
|
button.widget->hide();
|
|
|
|
button.replacement->show();
|
|
|
|
buttonLeft += button.replacement->width() + st::profileButtonSkip;
|
2016-05-27 13:56:35 +00:00
|
|
|
} else {
|
2016-05-31 19:27:11 +00:00
|
|
|
button.widget->show();
|
|
|
|
button.replacement->hide();
|
|
|
|
buttonLeft += button.widget->width() + st::profileButtonSkip;
|
2016-05-27 13:56:35 +00:00
|
|
|
}
|
2016-05-31 19:27:11 +00:00
|
|
|
} else if (i == 1 && (buttonLeft + button.widget->width() > buttonsRight)) {
|
|
|
|
// If second button is not fitting.
|
|
|
|
button.widget->hide();
|
2016-05-27 13:56:35 +00:00
|
|
|
} else {
|
2016-05-31 19:27:11 +00:00
|
|
|
button.widget->show();
|
|
|
|
buttonLeft += button.widget->width() + st::profileButtonSkip;
|
2016-05-27 13:56:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-27 10:57:11 +00:00
|
|
|
void CoverWidget::showFinished() {
|
|
|
|
_userpicButton->showFinished();
|
|
|
|
}
|
|
|
|
|
2016-05-27 13:56:35 +00:00
|
|
|
bool CoverWidget::shareContactButtonShown() const {
|
2016-05-31 19:27:11 +00:00
|
|
|
return _peerUser && (_buttons.size() > 1) && !(_buttons.at(1).widget->isHidden());
|
2016-05-27 13:56:35 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 16:05:20 +00:00
|
|
|
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);
|
2016-06-04 20:29:16 +00:00
|
|
|
p.setPen(_statusTextIsOnline ? st::profileStatusFgActive : st::profileStatusFg);
|
2016-05-12 16:05:20 +00:00
|
|
|
p.drawTextLeft(_statusPosition.x(), _statusPosition.y(), width(), _statusText);
|
2016-05-20 15:35:58 +00:00
|
|
|
|
2016-06-07 19:59:39 +00:00
|
|
|
if (_peer->isVerified()) {
|
2016-06-24 16:58:41 +00:00
|
|
|
st::profileVerifiedCheck.paint(p, QPoint(_name->x() + _name->width(), _name->y()) + st::profileVerifiedCheckPosition, width());
|
2016-06-07 19:59:39 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 15:35:58 +00:00
|
|
|
paintDivider(p);
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void CoverWidget::resizeDropArea(int newWidth) {
|
2016-05-27 10:57:11 +00:00
|
|
|
if (_dropArea) {
|
2016-08-22 17:16:21 +00:00
|
|
|
_dropArea->setGeometry(0, 0, newWidth, _dividerTop);
|
2016-05-27 10:57:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::dropAreaHidden(CoverDropArea *dropArea) {
|
|
|
|
if (_dropArea == dropArea) {
|
2016-05-31 19:27:11 +00:00
|
|
|
_dropArea.destroyDelayed();
|
2016-05-27 10:57:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CoverWidget::canEditPhoto() const {
|
|
|
|
if (_peerChat && _peerChat->canEdit()) {
|
|
|
|
return true;
|
|
|
|
} else if (_peerMegagroup && _peerMegagroup->canEditPhoto()) {
|
|
|
|
return true;
|
|
|
|
} else if (_peerChannel && _peerChannel->canEditPhoto()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CoverWidget::mimeDataHasImage(const QMimeData *mimeData) const {
|
|
|
|
if (!mimeData) return false;
|
|
|
|
|
|
|
|
if (mimeData->hasImage()) return true;
|
|
|
|
|
|
|
|
auto uriListFormat = qsl("text/uri-list");
|
|
|
|
if (!mimeData->hasFormat(uriListFormat)) return false;
|
|
|
|
|
2016-06-06 11:35:49 +00:00
|
|
|
const auto &urls = mimeData->urls();
|
2016-05-27 10:57:11 +00:00
|
|
|
if (urls.size() != 1) return false;
|
|
|
|
|
|
|
|
auto &url = urls.at(0);
|
|
|
|
if (!url.isLocalFile()) return false;
|
|
|
|
|
|
|
|
auto file = psConvertFileUrl(url);
|
|
|
|
|
|
|
|
QFileInfo info(file);
|
|
|
|
if (info.isDir()) return false;
|
|
|
|
|
|
|
|
quint64 s = info.size();
|
|
|
|
if (s >= MaxUploadDocumentSize) return false;
|
|
|
|
|
|
|
|
for (auto &ext : cImgExtensions()) {
|
|
|
|
if (file.endsWith(ext, Qt::CaseInsensitive)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-26 16:05:39 +00:00
|
|
|
void CoverWidget::dragEnterEvent(QDragEnterEvent *e) {
|
2016-05-27 10:57:11 +00:00
|
|
|
if (!canEditPhoto() || !mimeDataHasImage(e->mimeData())) {
|
|
|
|
e->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_dropArea) {
|
|
|
|
auto title = lang(lng_profile_drop_area_title);
|
|
|
|
QString subtitle;
|
|
|
|
if (_peerChat || _peerMegagroup) {
|
|
|
|
subtitle = lang(lng_profile_drop_area_subtitle);
|
|
|
|
} else {
|
|
|
|
subtitle = lang(lng_profile_drop_area_subtitle_channel);
|
|
|
|
}
|
|
|
|
_dropArea = new CoverDropArea(this, title, subtitle);
|
2016-08-22 17:16:21 +00:00
|
|
|
resizeDropArea(width());
|
2016-05-27 10:57:11 +00:00
|
|
|
}
|
2016-05-26 16:05:39 +00:00
|
|
|
_dropArea->showAnimated();
|
2016-05-27 10:57:11 +00:00
|
|
|
e->setDropAction(Qt::CopyAction);
|
2016-05-26 16:05:39 +00:00
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::dragLeaveEvent(QDragLeaveEvent *e) {
|
2016-05-27 10:57:11 +00:00
|
|
|
if (_dropArea && !_dropArea->hiding()) {
|
2016-09-26 12:09:59 +00:00
|
|
|
_dropArea->hideAnimated([this](CoverDropArea *area) { dropAreaHidden(area); });
|
2016-05-27 10:57:11 +00:00
|
|
|
}
|
2016-05-26 16:05:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::dropEvent(QDropEvent *e) {
|
2016-05-27 10:57:11 +00:00
|
|
|
auto mimeData = e->mimeData();
|
|
|
|
|
|
|
|
QImage img;
|
|
|
|
if (mimeData->hasImage()) {
|
|
|
|
img = qvariant_cast<QImage>(mimeData->imageData());
|
|
|
|
} else {
|
2016-06-06 11:35:49 +00:00
|
|
|
const auto &urls = mimeData->urls();
|
2016-05-27 10:57:11 +00:00
|
|
|
if (urls.size() == 1) {
|
|
|
|
auto &url = urls.at(0);
|
|
|
|
if (url.isLocalFile()) {
|
|
|
|
img = App::readImage(psConvertFileUrl(url));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_dropArea->hiding()) {
|
2016-09-26 12:09:59 +00:00
|
|
|
_dropArea->hideAnimated([this](CoverDropArea *area) { dropAreaHidden(area); });
|
2016-05-27 10:57:11 +00:00
|
|
|
}
|
|
|
|
e->acceptProposedAction();
|
|
|
|
|
|
|
|
showSetPhotoBox(img);
|
2016-05-26 16:05:39 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 15:35:58 +00:00
|
|
|
void CoverWidget::paintDivider(Painter &p) {
|
2016-08-19 17:26:31 +00:00
|
|
|
auto dividerLeft = (Adaptive::OneColumn() ? 0 : st::lineWidth);
|
|
|
|
st::profileDividerLeft.paint(p, QPoint(dividerLeft, _dividerTop), width());
|
2016-05-20 15:35:58 +00:00
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
int toFillLeft = dividerLeft + st::profileDividerLeft.width();
|
2016-05-20 15:35:58 +00:00
|
|
|
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();
|
|
|
|
}
|
2016-06-01 20:05:37 +00:00
|
|
|
if (update.flags & UpdateFlag::NameChanged) {
|
2016-05-25 17:59:21 +00:00
|
|
|
refreshNameText();
|
2016-05-25 12:09:05 +00:00
|
|
|
}
|
2016-06-04 20:29:16 +00:00
|
|
|
if (update.flags & UpdateFlag::UserOnlineChanged) {
|
|
|
|
refreshStatusText();
|
|
|
|
}
|
2016-05-25 12:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::refreshNameText() {
|
2016-06-24 16:58:41 +00:00
|
|
|
_name->setText(App::peerName(_peer));
|
2016-05-31 19:27:11 +00:00
|
|
|
refreshNameGeometry(width());
|
2016-05-25 12:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::refreshStatusText() {
|
2016-06-24 16:58:41 +00:00
|
|
|
if (auto app = App::app()) {
|
|
|
|
if (app->isPhotoUpdating(_peer->id)) {
|
|
|
|
_statusText = lang(lng_settings_uploading_photo);
|
2016-08-19 17:26:31 +00:00
|
|
|
_statusTextIsOnline = false;
|
2016-06-24 16:58:41 +00:00
|
|
|
if (!_cancelPhotoUpload) {
|
|
|
|
_cancelPhotoUpload = new LinkButton(this, lang(lng_cancel), st::btnDefLink);
|
|
|
|
connect(_cancelPhotoUpload, SIGNAL(clicked()), this, SLOT(onCancelPhotoUpload()));
|
|
|
|
_cancelPhotoUpload->show();
|
|
|
|
_cancelPhotoUpload->moveToLeft(_statusPosition.x() + st::profileStatusFont->width(_statusText) + st::profileStatusFont->spacew, _statusPosition.y());
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_cancelPhotoUpload.destroy();
|
2016-05-12 16:05:20 +00:00
|
|
|
int currentTime = unixtime();
|
|
|
|
if (_peerUser) {
|
|
|
|
_statusText = App::onlineText(_peerUser, currentTime, true);
|
2016-06-04 20:29:16 +00:00
|
|
|
_statusTextIsOnline = App::onlineColorUse(_peerUser, currentTime);
|
2016-05-12 16:05:20 +00:00
|
|
|
} else if (_peerChat && _peerChat->amIn()) {
|
2016-06-03 07:20:24 +00:00
|
|
|
int fullCount = qMax(_peerChat->count, _peerChat->participants.size());
|
|
|
|
if (_onlineCount > 0 && _onlineCount <= fullCount) {
|
|
|
|
_statusText = lng_chat_status_members_online(lt_count, fullCount, lt_count_online, _onlineCount);
|
2016-05-12 16:05:20 +00:00
|
|
|
} else {
|
2016-06-03 07:20:24 +00:00
|
|
|
_statusText = lng_chat_status_members(lt_count, _peerChat->count);
|
2016-05-12 16:05:20 +00:00
|
|
|
}
|
|
|
|
} else if (_peerChannel) {
|
2016-06-03 07:20:24 +00:00
|
|
|
int fullCount = _peerChannel->membersCount();
|
|
|
|
if (_onlineCount > 0 && _onlineCount <= fullCount) {
|
|
|
|
_statusText = lng_chat_status_members_online(lt_count, fullCount, lt_count_online, _onlineCount);
|
|
|
|
} else if (fullCount > 0 ) {
|
2016-06-02 13:02:55 +00:00
|
|
|
_statusText = lng_chat_status_members(lt_count, _peerChannel->membersCount());
|
2016-05-12 16:05:20 +00:00
|
|
|
} 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
|
|
|
}
|
|
|
|
|
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-06-20 15:40:36 +00:00
|
|
|
if (_peerUser->botInfo && !_peerUser->botInfo->cantJoinGroups) {
|
|
|
|
addButton(lang(lng_profile_invite_to_group), SLOT(onAddBotToGroup()), &st::profileAddMemberButton);
|
|
|
|
} else 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()));
|
2016-05-31 19:27:11 +00:00
|
|
|
addButton(lang(lng_profile_add_participant), SLOT(onAddMember()), &st::profileAddMemberButton);
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::setMegagroupButtons() {
|
2016-06-03 07:20:24 +00:00
|
|
|
if (_peerMegagroup->amIn()) {
|
|
|
|
if (_peerMegagroup->canEditPhoto()) {
|
|
|
|
addButton(lang(lng_profile_set_group_photo), SLOT(onSetPhoto()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addButton(lang(lng_profile_join_channel), SLOT(onJoin()));
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
2016-06-02 13:02:55 +00:00
|
|
|
if (_peerMegagroup->canAddMembers()) {
|
2016-05-31 19:27:11 +00:00
|
|
|
addButton(lang(lng_profile_add_participant), SLOT(onAddMember()), &st::profileAddMemberButton);
|
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) {
|
2016-05-31 19:27:11 +00:00
|
|
|
delete button.widget;
|
|
|
|
delete button.replacement;
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-22 17:11:35 +00:00
|
|
|
void CoverWidget::addButton(const QString &text, const char *slot, const style::RoundButton *replacementStyle) {
|
2016-05-27 13:56:35 +00:00
|
|
|
auto &buttonStyle = _buttons.isEmpty() ? st::profilePrimaryButton : st::profileSecondaryButton;
|
2016-05-31 19:27:11 +00:00
|
|
|
auto button = new Ui::RoundButton(this, text, buttonStyle);
|
2016-06-07 19:59:39 +00:00
|
|
|
button->setTextTransform(Ui::RoundButton::TextTransform::ToUpper);
|
2016-05-31 19:27:11 +00:00
|
|
|
connect(button, SIGNAL(clicked()), this, slot);
|
|
|
|
button->show();
|
|
|
|
|
|
|
|
auto replacement = replacementStyle ? new Ui::RoundButton(this, QString(), *replacementStyle) : nullptr;
|
|
|
|
if (replacement) {
|
|
|
|
connect(replacement, SIGNAL(clicked()), this, slot);
|
|
|
|
replacement->hide();
|
|
|
|
}
|
2016-05-27 13:56:35 +00:00
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
_buttons.push_back({ button, replacement });
|
2016-05-24 16:13:07 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 07:20:24 +00:00
|
|
|
void CoverWidget::onOnlineCountUpdated(int onlineCount) {
|
|
|
|
_onlineCount = onlineCount;
|
|
|
|
refreshStatusText();
|
|
|
|
}
|
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
void CoverWidget::onSendMessage() {
|
2016-07-05 14:48:36 +00:00
|
|
|
Ui::showPeerHistory(_peer, ShowAtUnreadMsgId, Ui::ShowWay::Forward);
|
2016-05-25 12:09:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::onShareContact() {
|
|
|
|
App::main()->shareContactLayer(_peerUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::onSetPhoto() {
|
2016-05-25 17:59:21 +00:00
|
|
|
QStringList imgExtensions(cImgExtensions());
|
2016-08-05 09:18:02 +00:00
|
|
|
QString filter(qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter());
|
2016-05-25 17:59:21 +00:00
|
|
|
|
|
|
|
_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());
|
|
|
|
}
|
|
|
|
|
2016-05-27 10:57:11 +00:00
|
|
|
showSetPhotoBox(img);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoverWidget::showSetPhotoBox(const QImage &img) {
|
2016-05-25 17:59:21 +00:00
|
|
|
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);
|
2016-08-16 16:53:10 +00:00
|
|
|
connect(box, SIGNAL(closed(LayerWidget*)), this, SLOT(onPhotoUploadStatusChanged()));
|
2016-05-25 17:59:21 +00:00
|
|
|
Ui::showLayer(box);
|
2016-05-25 12:09:05 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 16:58:41 +00:00
|
|
|
void CoverWidget::onPhotoUploadStatusChanged(PeerId peerId) {
|
|
|
|
if (!peerId || peerId == _peer->id) {
|
|
|
|
refreshStatusText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
void CoverWidget::onAddMember() {
|
|
|
|
if (_peerChat) {
|
2016-06-03 21:46:45 +00:00
|
|
|
if (_peerChat->count >= Global::ChatSizeMax() && _peerChat->amCreator()) {
|
|
|
|
Ui::showLayer(new ConvertToSupergroupBox(_peerChat));
|
|
|
|
} else {
|
|
|
|
Ui::showLayer(new ContactsBox(_peerChat, MembersFilterRecent));
|
|
|
|
}
|
2016-05-25 12:09:05 +00:00
|
|
|
} 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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-20 15:40:36 +00:00
|
|
|
void CoverWidget::onAddBotToGroup() {
|
|
|
|
if (_peerUser && _peerUser->botInfo) {
|
|
|
|
Ui::showLayer(new ContactsBox(_peerUser));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 12:09:05 +00:00
|
|
|
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
|