Save send way (album, photos, files) to settings.

This commit is contained in:
John Preston 2017-12-25 14:13:27 +03:00
parent a6c15217c0
commit a8ac18e4fd
9 changed files with 104 additions and 61 deletions

View file

@ -33,6 +33,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "calls/calls_instance.h"
#include "window/section_widget.h"
#include "chat_helpers/tabbed_selector.h"
#include "boxes/send_files_box.h"
namespace {
@ -41,7 +42,8 @@ constexpr auto kAutoLockTimeoutLateMs = TimeMs(3000);
} // namespace
AuthSessionData::Variables::Variables()
: selectorTab(ChatHelpers::SelectorTab::Emoji)
: sendFilesWay(SendFilesWay::Album)
, selectorTab(ChatHelpers::SelectorTab::Emoji)
, floatPlayerColumn(Window::Column::Second)
, floatPlayerCorner(RectPart::TopRight) {
}
@ -80,6 +82,7 @@ QByteArray AuthSessionData::serialize() const {
1000000));
stream << qint32(_variables.thirdColumnWidth.current());
stream << qint32(_variables.thirdSectionExtendedBy);
stream << qint32(_variables.sendFilesWay);
}
return result;
}
@ -104,6 +107,7 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
float64 dialogsWidthRatio = _variables.dialogsWidthRatio.current();
int thirdColumnWidth = _variables.thirdColumnWidth.current();
int thirdSectionExtendedBy = _variables.thirdSectionExtendedBy;
qint32 sendFilesWay = static_cast<qint32>(_variables.sendFilesWay);
stream >> selectorTab;
stream >> lastSeenWarningSeen;
if (!stream.atEnd()) {
@ -189,6 +193,12 @@ void AuthSessionData::constructFromSerialized(const QByteArray &serialized) {
if (_variables.thirdSectionInfoEnabled) {
_variables.tabbedSelectorSectionEnabled = false;
}
auto uncheckedSendFilesWay = static_cast<SendFilesWay>(sendFilesWay);
switch (uncheckedSendFilesWay) {
case SendFilesWay::Album:
case SendFilesWay::Photos:
case SendFilesWay::Files: _variables.sendFilesWay = uncheckedSendFilesWay;
}
}
void AuthSessionData::markItemLayoutChanged(not_null<const HistoryItem*> item) {

View file

@ -26,6 +26,9 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "base/timer.h"
#include "chat_helpers/stickers.h"
class ApiWrap;
enum class SendFilesWay;
namespace Storage {
class Downloader;
class Uploader;
@ -47,8 +50,6 @@ namespace ChatHelpers {
enum class SelectorTab;
} // namespace ChatHelpers
class ApiWrap;
class AuthSessionData final {
public:
base::Variable<bool> &contactsLoaded() {
@ -108,6 +109,12 @@ public:
void setLastSeenWarningSeen(bool lastSeenWarningSeen) {
_variables.lastSeenWarningSeen = lastSeenWarningSeen;
}
void setSendFilesWay(SendFilesWay way) {
_variables.sendFilesWay = way;
}
SendFilesWay sendFilesWay() const {
return _variables.sendFilesWay;
}
ChatHelpers::SelectorTab selectorTab() const {
return _variables.selectorTab;
}
@ -273,6 +280,7 @@ private:
static constexpr auto kDefaultThirdColumnWidth = 0;
bool lastSeenWarningSeen = false;
SendFilesWay sendFilesWay;
ChatHelpers::SelectorTab selectorTab; // per-window
bool tabbedSelectorSectionEnabled = false; // per-window
int tabbedSelectorSectionTooltipShown = 0;

View file

@ -455,9 +455,9 @@ public:
AlbumPreview(
QWidget *parent,
const Storage::PreparedList &list,
SendWay way);
SendFilesWay way);
void setSendWay(SendWay way);
void setSendWay(SendFilesWay way);
protected:
void paintEvent(QPaintEvent *e) override;
@ -474,7 +474,7 @@ private:
void paintFiles(Painter &p, QRect clip) const;
const Storage::PreparedList &_list;
SendWay _sendWay = SendWay::Files;
SendFilesWay _sendWay = SendFilesWay::Files;
std::vector<AlbumThumb> _thumbs;
int _thumbsHeight = 0;
int _photosHeight = 0;
@ -485,7 +485,7 @@ private:
SendFilesBox::AlbumPreview::AlbumPreview(
QWidget *parent,
const Storage::PreparedList &list,
SendWay way)
SendFilesWay way)
: RpWidget(parent)
, _list(list)
, _sendWay(way) {
@ -493,7 +493,7 @@ SendFilesBox::AlbumPreview::AlbumPreview(
updateSize();
}
void SendFilesBox::AlbumPreview::setSendWay(SendWay way) {
void SendFilesBox::AlbumPreview::setSendWay(SendFilesWay way) {
_sendWay = way;
updateSize();
update();
@ -615,9 +615,9 @@ SendFilesBox::AlbumThumb SendFilesBox::AlbumPreview::prepareThumb(
void SendFilesBox::AlbumPreview::updateSize() {
const auto height = [&] {
switch (_sendWay) {
case SendWay::Album: return _thumbsHeight;
case SendWay::Photos: return _photosHeight;
case SendWay::Files: return _filesHeight;
case SendFilesWay::Album: return _thumbsHeight;
case SendFilesWay::Photos: return _photosHeight;
case SendFilesWay::Files: return _filesHeight;
}
Unexpected("Send way in SendFilesBox::AlbumPreview::updateSize");
}();
@ -628,9 +628,9 @@ void SendFilesBox::AlbumPreview::paintEvent(QPaintEvent *e) {
Painter p(this);
switch (_sendWay) {
case SendWay::Album: paintAlbum(p); break;
case SendWay::Photos: paintPhotos(p, e->rect()); break;
case SendWay::Files: paintFiles(p, e->rect()); break;
case SendFilesWay::Album: paintAlbum(p); break;
case SendFilesWay::Photos: paintPhotos(p, e->rect()); break;
case SendFilesWay::Files: paintFiles(p, e->rect()); break;
}
}
@ -832,26 +832,39 @@ void SendFilesBox::prepare() {
}
void SendFilesBox::initSendWay() {
const auto value = (_compressConfirm == CompressConfirm::None)
? SendWay::Files
: (_compressConfirm == CompressConfirm::Auto)
? (cCompressPastedImage()
? (_list.albumIsPossible ? SendWay::Album : SendWay::Photos)
: SendWay::Files)
: (_compressConfirm == CompressConfirm::Yes
? (_list.albumIsPossible ? SendWay::Album : SendWay::Photos)
: SendWay::Files);
_sendWay = std::make_shared<Ui::RadioenumGroup<SendWay>>(value);
}
void SendFilesBox::setupControls() {
_albumVideosCount = ranges::v3::count(
_albumVideosCount = ranges::count(
_list.files,
Storage::PreparedFile::AlbumType::Video,
[](const Storage::PreparedFile &file) { return file.type; });
_albumPhotosCount = _list.albumIsPossible
? (_list.files.size() - _albumVideosCount)
: 0;
const auto value = [&] {
if (_compressConfirm == CompressConfirm::None) {
return SendFilesWay::Files;
} else if (_compressConfirm == CompressConfirm::No) {
return SendFilesWay::Files;
} else if (_compressConfirm == CompressConfirm::Yes) {
return _list.albumIsPossible
? SendFilesWay::Album
: SendFilesWay::Photos;
}
const auto currentWay = Auth().data().sendFilesWay();
if (currentWay == SendFilesWay::Files) {
return currentWay;
} else if (currentWay == SendFilesWay::Album) {
return _list.albumIsPossible
? SendFilesWay::Album
: SendFilesWay::Photos;
}
return (_list.albumIsPossible && !_albumPhotosCount)
? SendFilesWay::Album
: SendFilesWay::Photos;
}();
_sendWay = std::make_shared<Ui::RadioenumGroup<SendFilesWay>>(value);
}
void SendFilesBox::setupControls() {
setupTitleText();
setupSendWayControls();
setupCaption();
@ -862,17 +875,17 @@ void SendFilesBox::setupSendWayControls() {
return;
}
const auto addRadio = [&](
object_ptr<Ui::Radioenum<SendWay>> &button,
SendWay value,
object_ptr<Ui::Radioenum<SendFilesWay>> &button,
SendFilesWay value,
const QString &text) {
const auto &style = st::defaultBoxCheckbox;
button.create(this, _sendWay, value, text, style);
};
if (_list.albumIsPossible) {
addRadio(_sendAlbum, SendWay::Album, lang(lng_send_album));
addRadio(_sendAlbum, SendFilesWay::Album, lang(lng_send_album));
}
if (!_list.albumIsPossible || _albumPhotosCount > 0) {
addRadio(_sendPhotos, SendWay::Photos, (_list.files.size() == 1)
addRadio(_sendPhotos, SendFilesWay::Photos, (_list.files.size() == 1)
? lang(lng_send_photo)
: (_albumVideosCount > 0)
? (_list.albumIsPossible
@ -882,10 +895,10 @@ void SendFilesBox::setupSendWayControls() {
? lang(lng_send_separate_photos)
: lng_send_photos(lt_count, _list.files.size())));
}
addRadio(_sendFiles, SendWay::Files, (_list.files.size() == 1)
addRadio(_sendFiles, SendFilesWay::Files, (_list.files.size() == 1)
? lang(lng_send_file)
: lng_send_files(lt_count, _list.files.size()));
_sendWay->setChangedCallback([this](SendWay value) {
_sendWay->setChangedCallback([this](SendFilesWay value) {
if (_albumPreview) {
_albumPreview->setSendWay(value);
}
@ -1021,14 +1034,25 @@ void SendFilesBox::setInnerFocus() {
}
void SendFilesBox::send(bool ctrlShiftEnter) {
// TODO settings
//if (_compressed && _compressConfirm == CompressConfirm::Auto && _compressed->checked() != cCompressPastedImage()) {
// cSetCompressPastedImage(_compressed->checked());
// Local::writeUserSettings();
//}
using Way = SendFilesWay;
const auto way = _sendWay ? _sendWay->value() : Way::Files;
if (_compressConfirm == CompressConfirm::Auto) {
const auto oldWay = Auth().data().sendFilesWay();
if (way != oldWay) {
// Check if the user _could_ use the old value, but didn't.
if ((oldWay == Way::Album && _sendAlbum)
|| (oldWay == Way::Photos && _sendPhotos)
|| (oldWay == Way::Files && _sendFiles)
|| (way == Way::Files && (_sendAlbum || _sendPhotos))) {
// And in that case save it to settings.
Auth().data().setSendFilesWay(way);
Auth().saveDataDelayed();
}
}
}
_confirmed = true;
if (_confirmedCallback) {
const auto way = _sendWay ? _sendWay->value() : SendWay::Files;
auto caption = _caption
? TextUtilities::PrepareForSending(
_caption->getLastText(),

View file

@ -35,14 +35,14 @@ class InputArea;
struct GroupMediaLayout;
} // namespace Ui
enum class SendFilesWay {
Album,
Photos,
Files,
};
class SendFilesBox : public BoxContent {
public:
enum class SendWay {
Album,
Photos,
Files,
};
SendFilesBox(
QWidget*,
Storage::PreparedList &&list,
@ -51,7 +51,7 @@ public:
void setConfirmedCallback(
base::lambda<void(
Storage::PreparedList &&list,
SendWay way,
SendFilesWay way,
const QString &caption,
bool ctrlShiftEnter)> callback) {
_confirmedCallback = std::move(callback);
@ -103,17 +103,17 @@ private:
base::lambda<void(
Storage::PreparedList &&list,
SendWay way,
SendFilesWay way,
const QString &caption,
bool ctrlShiftEnter)> _confirmedCallback;
base::lambda<void()> _cancelledCallback;
bool _confirmed = false;
object_ptr<Ui::InputArea> _caption = { nullptr };
object_ptr<Ui::Radioenum<SendWay>> _sendAlbum = { nullptr };
object_ptr<Ui::Radioenum<SendWay>> _sendPhotos = { nullptr };
object_ptr<Ui::Radioenum<SendWay>> _sendFiles = { nullptr };
std::shared_ptr<Ui::RadioenumGroup<SendWay>> _sendWay;
object_ptr<Ui::Radioenum<SendFilesWay>> _sendAlbum = { nullptr };
object_ptr<Ui::Radioenum<SendFilesWay>> _sendPhotos = { nullptr };
object_ptr<Ui::Radioenum<SendFilesWay>> _sendFiles = { nullptr };
std::shared_ptr<Ui::RadioenumGroup<SendFilesWay>> _sendWay;
rpl::variable<int> _footerHeight = 0;

View file

@ -3133,7 +3133,7 @@ void HistoryWidget::chooseAttach() {
auto list = Storage::PrepareMediaList(
result.paths,
st::sendMediaPreviewSize);
if (list.allFilesForCompress) {
if (list.allFilesForCompress || list.albumIsPossible) {
confirmSendingFiles(std::move(list), CompressConfirm::Auto);
} else if (!showSendingFilesError(list)) {
uploadFiles(std::move(list), SendMediaType::File);
@ -3979,6 +3979,7 @@ bool HistoryWidget::showSendingFilesError(
if (text.isEmpty()) {
return false;
}
Ui::show(Box<InformBox>(text));
return true;
}
@ -4029,16 +4030,16 @@ bool HistoryWidget::confirmSendingFiles(
auto box = Box<SendFilesBox>(std::move(list), boxCompressConfirm);
box->setConfirmedCallback(base::lambda_guarded(this, [=](
Storage::PreparedList &&list,
SendFilesBox::SendWay way,
SendFilesWay way,
const QString &caption,
bool ctrlShiftEnter) {
if (showSendingFilesError(list)) {
return;
}
const auto type = (way == SendFilesBox::SendWay::Files)
const auto type = (way == SendFilesWay::Files)
? SendMediaType::File
: SendMediaType::Photo;
const auto album = (way == SendFilesBox::SendWay::Album)
const auto album = (way == SendFilesWay::Album)
? std::make_shared<SendingAlbum>()
: nullptr;
uploadFilesAfterConfirmation(

View file

@ -64,7 +64,6 @@ QByteArray gLocalSalt;
DBIScale gRealScale = dbisAuto;
DBIScale gScreenScale = dbisOne;
DBIScale gConfigScale = dbisAuto;
bool gCompressPastedImage = true;
QString gTimeFormat = qsl("hh:mm");

View file

@ -120,7 +120,6 @@ DeclareSetting(QByteArray, LocalSalt);
DeclareSetting(DBIScale, RealScale);
DeclareSetting(DBIScale, ScreenScale);
DeclareSetting(DBIScale, ConfigScale);
DeclareSetting(bool, CompressPastedImage);
DeclareSetting(QString, TimeFormat);
inline void cChangeTimeFormat(const QString &newFormat) {

View file

@ -523,7 +523,7 @@ void FileLoadTask::process() {
isVideo = true;
auto coverWidth = video->thumbnail.width();
auto coverHeight = video->thumbnail.height();
if (video->isGifv) {
if (video->isGifv && !_album) {
attributes.push_back(MTP_documentAttributeAnimated());
}
auto flags = MTPDdocumentAttributeVideo::Flags(0);

View file

@ -24,6 +24,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "storage/serialize_common.h"
#include "chat_helpers/stickers.h"
#include "data/data_drafts.h"
#include "boxes/send_files_box.h"
#include "window/themes/window_theme.h"
#include "observer_peer.h"
#include "mainwidget.h"
@ -1422,7 +1423,9 @@ bool _readSetting(quint32 blockId, QDataStream &stream, int version, ReadSetting
stream >> v;
if (!_checkStreamStatus(stream)) return false;
cSetCompressPastedImage(v == 1);
GetStoredAuthSessionCache().setSendFilesWay((v == 1)
? SendFilesWay::Album
: SendFilesWay::Files);
} break;
case dbiEmojiTabOld: {
@ -1804,7 +1807,6 @@ void _writeUserSettings() {
data.stream << quint32(dbiNotificationsCorner) << qint32(Global::NotificationsCorner());
data.stream << quint32(dbiAskDownloadPath) << qint32(Global::AskDownloadPath());
data.stream << quint32(dbiDownloadPath) << (Global::AskDownloadPath() ? QString() : Global::DownloadPath()) << (Global::AskDownloadPath() ? QByteArray() : Global::DownloadPathBookmark());
data.stream << quint32(dbiCompressPastedImage) << qint32(cCompressPastedImage());
data.stream << quint32(dbiDialogLastPath) << cDialogLastPath();
data.stream << quint32(dbiSongVolume) << qint32(qRound(Global::SongVolume() * 1e6));
data.stream << quint32(dbiVideoVolume) << qint32(qRound(Global::VideoVolume() * 1e6));