2016-05-31 19:27:11 +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_shared_media_widget.h"
|
|
|
|
|
|
|
|
#include "styles/style_profile.h"
|
2016-06-02 13:02:55 +00:00
|
|
|
#include "observer_peer.h"
|
2016-11-16 16:04:25 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2016-06-02 13:02:55 +00:00
|
|
|
#include "mainwidget.h"
|
2016-05-31 19:27:11 +00:00
|
|
|
#include "lang.h"
|
|
|
|
|
|
|
|
namespace Profile {
|
2016-06-02 13:02:55 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
QString getButtonText(MediaOverviewType type, int count) {
|
|
|
|
if (count <= 0) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case OverviewPhotos: return lng_profile_photos(lt_count, count);
|
|
|
|
case OverviewVideos: return lng_profile_videos(lt_count, count);
|
|
|
|
case OverviewMusicFiles: return lng_profile_songs(lt_count, count);
|
|
|
|
case OverviewFiles: return lng_profile_files(lt_count, count);
|
|
|
|
case OverviewVoiceFiles: return lng_profile_audios(lt_count, count);
|
|
|
|
case OverviewLinks: return lng_profile_shared_links(lt_count, count);
|
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2016-05-31 19:27:11 +00:00
|
|
|
|
|
|
|
SharedMediaWidget::SharedMediaWidget(QWidget *parent, PeerData *peer) : BlockWidget(parent, peer, lang(lng_profile_shared_media))
|
2016-06-02 13:02:55 +00:00
|
|
|
, _history(App::history(peer))
|
|
|
|
, _migrated(peer->migrateFrom() ? App::history(peer->migrateFrom()) : nullptr) {
|
2016-09-26 18:33:34 +00:00
|
|
|
auto observeEvents = Notify::PeerUpdate::Flag::SharedMediaChanged;
|
|
|
|
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-06-02 13:02:55 +00:00
|
|
|
|
|
|
|
App::main()->preloadOverviews(peer);
|
|
|
|
if (_migrated) {
|
|
|
|
App::main()->preloadOverviews(_migrated->peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshButtons();
|
|
|
|
refreshVisibility();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SharedMediaWidget::notifyPeerUpdated(const Notify::PeerUpdate &update) {
|
|
|
|
if (update.peer != peer() && (!_migrated || update.peer != _migrated->peer)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool updated = false;
|
|
|
|
for (int i = 0; i < OverviewCount; ++i) {
|
|
|
|
if (update.mediaTypesMask & (1 << i)) {
|
|
|
|
refreshButton(static_cast<MediaOverviewType>(i));
|
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (updated) {
|
|
|
|
refreshVisibility();
|
|
|
|
|
|
|
|
contentSizeUpdated();
|
|
|
|
}
|
2016-05-31 19:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SharedMediaWidget::resizeGetHeight(int newWidth) {
|
|
|
|
int newHeight = contentTop();
|
|
|
|
|
2016-09-02 01:37:30 +00:00
|
|
|
resizeButtons(newWidth, &newHeight);
|
2016-06-02 13:02:55 +00:00
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
return newHeight;
|
|
|
|
}
|
|
|
|
|
2016-06-02 13:02:55 +00:00
|
|
|
void SharedMediaWidget::refreshButtons() {
|
|
|
|
for (int typeIndex = 0; typeIndex < OverviewCount; ++typeIndex) {
|
|
|
|
refreshButton(static_cast<MediaOverviewType>(typeIndex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SharedMediaWidget::refreshButton(MediaOverviewType type) {
|
|
|
|
int count = _history->overviewCount(type), migrated = _migrated ? _migrated->overviewCount(type) : 0;
|
|
|
|
int finalCount = (count >= 0 && migrated >= 0) ? (count + migrated) : -1;
|
|
|
|
auto text = getButtonText(type, finalCount);
|
|
|
|
if (text.isEmpty()) {
|
|
|
|
if (_mediaButtons[type]) {
|
|
|
|
delete _mediaButtons[type];
|
|
|
|
_mediaButtons[type] = nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_mediaButtons[type]) {
|
|
|
|
_mediaButtons[type]->setText(text);
|
|
|
|
} else {
|
2016-06-07 19:59:39 +00:00
|
|
|
_mediaButtons[type] = new Ui::LeftOutlineButton(this, text, st::defaultLeftOutlineButton);
|
2016-06-02 13:02:55 +00:00
|
|
|
_mediaButtons[type]->show();
|
|
|
|
connect(_mediaButtons[type], SIGNAL(clicked()), this, SLOT(onMediaChosen()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SharedMediaWidget::refreshVisibility() {
|
|
|
|
for_const (auto button, _mediaButtons) {
|
|
|
|
if (button) {
|
|
|
|
show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SharedMediaWidget::onMediaChosen() {
|
|
|
|
for (int i = 0; i < OverviewCount; ++i) {
|
|
|
|
auto button = _mediaButtons[i];
|
|
|
|
if (button && button == sender()) {
|
|
|
|
App::main()->showMediaOverview(peer(), static_cast<MediaOverviewType>(i));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-02 01:37:30 +00:00
|
|
|
void SharedMediaWidget::resizeButtons(int newWidth, int *top) {
|
2016-06-02 13:02:55 +00:00
|
|
|
t_assert(top != nullptr);
|
|
|
|
|
|
|
|
int left = defaultOutlineButtonLeft();
|
2016-09-02 01:37:30 +00:00
|
|
|
int availableWidth = newWidth - left - st::profileBlockMarginRight;
|
2016-06-02 13:02:55 +00:00
|
|
|
accumulate_min(availableWidth, st::profileBlockOneLineWidthMax);
|
|
|
|
for_const (auto button, _mediaButtons) {
|
|
|
|
if (!button) continue;
|
|
|
|
|
|
|
|
button->resizeToWidth(availableWidth);
|
|
|
|
button->moveToLeft(left, *top);
|
|
|
|
*top += button->height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 19:27:11 +00:00
|
|
|
} // namespace Profile
|