diff --git a/Telegram/SourceFiles/boxes/addcontactbox.cpp b/Telegram/SourceFiles/boxes/addcontactbox.cpp index 2ef31e477..a828db91d 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.cpp +++ b/Telegram/SourceFiles/boxes/addcontactbox.cpp @@ -345,6 +345,10 @@ _creationRequestId(0), _createdChannel(0) { connect(&_next, SIGNAL(clicked()), this, SLOT(onNext())); connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose())); + subscribe(FileDialog::QueryDone(), [this](const FileDialog::QueryUpdate &update) { + notifyFileQueryUpdated(update); + }); + prepare(); } @@ -545,24 +549,23 @@ void GroupInfoBox::updateMaxHeight() { } void GroupInfoBox::onPhoto() { - QStringList imgExtensions(cImgExtensions()); - QString filter(qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter()); + auto imgExtensions = cImgExtensions(); + auto filter = qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;") + filedialogAllFilesFilter(); + _setPhotoFileQueryId = FileDialog::queryReadFile(lang(lng_choose_images), filter); +} - QImage img; - QString file; - QByteArray remoteContent; - if (filedialogGetOpenFile(file, remoteContent, lang(lng_choose_images), filter)) { - if (!remoteContent.isEmpty()) { - img = App::readImage(remoteContent); - } else { - if (!file.isEmpty()) { - img = App::readImage(file); - } - } - } else { +void GroupInfoBox::notifyFileQueryUpdated(const FileDialog::QueryUpdate &update) { + if (_setPhotoFileQueryId != update.queryId) { return; } + _setPhotoFileQueryId = 0; + 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()) { return; } diff --git a/Telegram/SourceFiles/boxes/addcontactbox.h b/Telegram/SourceFiles/boxes/addcontactbox.h index bd60be36f..09a28dc5b 100644 --- a/Telegram/SourceFiles/boxes/addcontactbox.h +++ b/Telegram/SourceFiles/boxes/addcontactbox.h @@ -22,6 +22,7 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org #include "abstractbox.h" #include "core/lambda_wrap.h" +#include "ui/filedialog.h" class FlatLabel; class ConfirmBox; @@ -117,6 +118,8 @@ protected: void doSetInnerFocus() override; private: + void notifyFileQueryUpdated(const FileDialog::QueryUpdate &update); + void step_photoOver(float64 ms, bool timer); QRect photoRect() const; @@ -140,6 +143,8 @@ private: int32 _creationRequestId; ChannelData *_createdChannel; + FileDialog::QueryId _setPhotoFileQueryId = 0; + void creationDone(const MTPUpdates &updates); bool creationFail(const RPCError &e); void exportDone(const MTPExportedChatInvite &result); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 7ce562e00..54f4ace9c 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -543,7 +543,7 @@ void MainWindow::ui_showMediaPreview(DocumentData *document) { if (!document || ((!document->isAnimation() || !document->loaded()) && !document->sticker())) return; if (!_mediaPreview) { _mediaPreview = std_::make_unique(this); - resizeEvent(nullptr); + updateControlsGeometry(); } if (_mediaPreview->isHidden()) { fixOrder(); @@ -555,7 +555,7 @@ void MainWindow::ui_showMediaPreview(PhotoData *photo) { if (!photo) return; if (!_mediaPreview) { _mediaPreview = std_::make_unique(this); - resizeEvent(nullptr); + updateControlsGeometry(); } if (_mediaPreview->isHidden()) { fixOrder(); @@ -583,7 +583,7 @@ void MainWindow::showConnecting(const QString &text, const QString &reconnect) { } else { _connecting.create(this, text, reconnect); _connecting->show(); - resizeEvent(0); + updateControlsGeometry(); fixOrder(); } } @@ -1036,11 +1036,15 @@ void MainWindow::resizeEvent(QResizeEvent *e) { Global::SetAdaptiveLayout(layout); Adaptive::Changed().notify(true); } + updateControlsGeometry(); + emit resized(QSize(width(), height() - st::titleHeight)); +} + +void MainWindow::updateControlsGeometry() { title->setGeometry(0, 0, width(), st::titleHeight); if (layerBg) layerBg->resize(width(), height()); if (_mediaPreview) _mediaPreview->setGeometry(0, title->height(), width(), height() - title->height()); if (_connecting) _connecting->setGeometry(0, height() - _connecting->height(), _connecting->width(), _connecting->height()); - emit resized(QSize(width(), height() - st::titleHeight)); } MainWindow::TempDirState MainWindow::tempDirState() { diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index f969bca01..10031cc83 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -228,6 +228,8 @@ private: void showConnecting(const QString &text, const QString &reconnect = QString()); void hideConnecting(); + void updateControlsGeometry(); + QPixmap grabInner(); void placeSmallCounter(QImage &img, int size, int count, style::color bg, const QPoint &shift, style::color color); diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index 32949bf62..296aa47ac 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -304,7 +304,7 @@ Thread::~Thread() { Connection::Connection() : thread(nullptr), data(nullptr) { } -int32 Connection::start(SessionData *sessionData, int32 dc) { +int32 Connection::prepare(SessionData *sessionData, int32 dc) { t_assert(thread == nullptr && data == nullptr); thread = new Thread(); @@ -318,11 +318,13 @@ int32 Connection::start(SessionData *sessionData, int32 dc) { thread = nullptr; return 0; } - - thread->start(); return dc; } +void Connection::start() { + thread->start(); +} + void Connection::kill() { t_assert(data != nullptr && thread != nullptr); data->stop(); diff --git a/Telegram/SourceFiles/mtproto/connection.h b/Telegram/SourceFiles/mtproto/connection.h index ab2101085..c6fc41ef7 100644 --- a/Telegram/SourceFiles/mtproto/connection.h +++ b/Telegram/SourceFiles/mtproto/connection.h @@ -53,7 +53,10 @@ public: }; Connection(); - int32 start(SessionData *data, int32 dc = 0); // return dc + + int32 prepare(SessionData *data, int32 dc = 0); // return dc + void start(); + void kill(); void waitTillFinish(); ~Connection(); diff --git a/Telegram/SourceFiles/mtproto/session.cpp b/Telegram/SourceFiles/mtproto/session.cpp index 6e80a3619..54cb07a9e 100644 --- a/Telegram/SourceFiles/mtproto/session.cpp +++ b/Telegram/SourceFiles/mtproto/session.cpp @@ -70,7 +70,7 @@ void SessionData::clear() { } -Session::Session(int32 dcenter) : QObject() +Session::Session(int32 requestedDcId) : QObject() , _connection(0) , _killed(false) , _needToReceive(false) @@ -96,35 +96,40 @@ Session::Session(int32 dcenter) : QObject() connect(&sender, SIGNAL(timeout()), this, SLOT(needToResumeAndSend())); - DcenterMap &dcs(DCMap()); - _connection = new Connection(); - dcWithShift = _connection->start(&data, dcenter); + dcWithShift = _connection->prepare(&data, requestedDcId); if (!dcWithShift) { delete _connection; _connection = 0; - DEBUG_LOG(("Session Info: could not start connection to dc %1").arg(dcenter)); + DEBUG_LOG(("Session Info: could not start connection to dc %1").arg(requestedDcId)); return; } - if (!dc) { - dcenter = dcWithShift; - int32 dcId = bareDcId(dcWithShift); - auto dcIndex = dcs.constFind(dcId); - if (dcIndex == dcs.cend()) { - dc = DcenterPtr(new Dcenter(dcId, AuthKeyPtr())); - dcs.insert(dcId, dc); - } else { - dc = dcIndex.value(); - } + createDcData(); + _connection->start(); +} - ReadLockerAttempt lock(keyMutex()); - data.setKey(lock ? dc->getKey() : AuthKeyPtr()); - if (lock && dc->connectionInited()) { - data.setLayerWasInited(true); - } - connect(dc.data(), SIGNAL(authKeyCreated()), this, SLOT(authKeyCreatedForDC()), Qt::QueuedConnection); - connect(dc.data(), SIGNAL(layerWasInited(bool)), this, SLOT(layerWasInitedForDC(bool)), Qt::QueuedConnection); +void Session::createDcData() { + if (dc) { + return; } + int32 dcId = bareDcId(dcWithShift); + + auto &dcs = DCMap(); + auto dcIndex = dcs.constFind(dcId); + if (dcIndex == dcs.cend()) { + dc = DcenterPtr(new Dcenter(dcId, AuthKeyPtr())); + dcs.insert(dcId, dc); + } else { + dc = dcIndex.value(); + } + + ReadLockerAttempt lock(keyMutex()); + data.setKey(lock ? dc->getKey() : AuthKeyPtr()); + if (lock && dc->connectionInited()) { + data.setLayerWasInited(true); + } + connect(dc.data(), SIGNAL(authKeyCreated()), this, SLOT(authKeyCreatedForDC()), Qt::QueuedConnection); + connect(dc.data(), SIGNAL(layerWasInited(bool)), this, SLOT(layerWasInitedForDC(bool)), Qt::QueuedConnection); } void Session::restart() { @@ -200,13 +205,15 @@ void Session::needToResumeAndSend() { DcenterMap &dcs(DCMap()); _connection = new Connection(); - if (!_connection->start(&data, dcWithShift)) { + if (!_connection->prepare(&data, dcWithShift)) { delete _connection; _connection = 0; DEBUG_LOG(("Session Info: could not start connection to dcWithShift %1").arg(dcWithShift)); dcWithShift = 0; return; } + createDcData(); + start(); } if (_ping) { _ping = false; diff --git a/Telegram/SourceFiles/mtproto/session.h b/Telegram/SourceFiles/mtproto/session.h index 4c8b17c69..3ac603fb5 100644 --- a/Telegram/SourceFiles/mtproto/session.h +++ b/Telegram/SourceFiles/mtproto/session.h @@ -281,6 +281,8 @@ public slots: void sendMsgsStateInfo(quint64 msgId, QByteArray data); private: + void createDcData(); + Connection *_connection; bool _killed;