gif size decreased, error message added for gif errors, enable many gifs playing at the same time

This commit is contained in:
John Preston 2015-12-16 18:04:02 +03:00
parent fdb93f700d
commit ae78d13284
8 changed files with 44 additions and 26 deletions

View File

@ -108,6 +108,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
"lng_server_error" = "Internal server error.";
"lng_flood_error" = "Too many tries. Please try again later.";
"lng_gif_error" = "An error has occured while reading GIF animation :(";
"lng_deleted" = "Unknown";
"lng_deleted_message" = "Deleted message";

View File

@ -2191,6 +2191,7 @@ mediaviewLoaderSkip: 9px;
minPhotoSize: 104px;
maxMediaSize: 420px;
maxStickerSize: 256px;
maxGifSize: 256px;
downloadPathSkip: 10px;

View File

@ -2444,7 +2444,7 @@ namespace App {
if (!::gifItems.isEmpty()) {
if (HistoryItem *playing = ::gifItems.begin().value()) {
if (playing->getMedia() && playing->getMedia()->type() == MediaTypeGif) {
static_cast<HistoryGif*>(playing->getMedia())->stop(playing);
// static_cast<HistoryGif*>(playing->getMedia())->stop(playing);
}
}
}

View File

@ -550,7 +550,7 @@ void Application::startUpdateCheck(bool forceWait) {
if (updateRequestId || updateThread || updateReply || !cAutoUpdate()) return;
int32 constDelay = cBetaVersion() ? 600 : UpdateDelayConstPart, randDelay = cBetaVersion() ? 300 : UpdateDelayRandPart;
int32 updateInSecs = cLastUpdateCheck() + constDelay + (rand() % randDelay) - unixtime();
int32 updateInSecs = cLastUpdateCheck() + constDelay + int32(MTP::nonce<uint32>() % randDelay) - unixtime();
bool sendRequest = (updateInSecs <= 0 || updateInSecs > (constDelay + randDelay));
if (!sendRequest && !forceWait) {
QDir updates(cWorkingDir() + "tupdates");

View File

@ -51,7 +51,7 @@ void UpdateDownloader::initOutput() {
fileName = m.captured(1).replace(QRegularExpression(qsl("[^a-zA-Z0-9_\\-]")), QString());
}
if (fileName.isEmpty()) {
fileName = qsl("tupdate-%1").arg(rand());
fileName = qsl("tupdate-%1").arg(MTP::nonce<uint32>() % 1000000);
}
QString dirStr = cWorkingDir() + qsl("tupdates/");
fileName = dirStr + fileName;

View File

@ -79,7 +79,11 @@ namespace Ui {
}
void showLayer(LayeredWidget *box, ShowLayerOptions options) {
if (Window *w = App::wnd()) w->ui_showLayer(box, options);
if (Window *w = App::wnd()) {
w->ui_showLayer(box, options);
} else {
delete box;
}
}
void hideLayer(bool fast) {

View File

@ -122,10 +122,12 @@ void AnimationManager::clipReinit(ClipReader *reader) {
const GifItems &items(App::gifItems());
GifItems::const_iterator it = items.constFind(reader);
if (it != items.cend()) {
it.value()->initDimensions();
if (App::main()) emit App::main()->itemResized(it.value(), true);
HistoryItem *item = it.value();
Notify::historyItemLayoutChanged(it.value());
item->initDimensions(); // can delete reader and items entry it
if (App::main()) emit App::main()->itemResized(item, true);
Notify::historyItemLayoutChanged(item);
}
}
@ -339,7 +341,7 @@ ClipReader::ClipReader(const FileLocation &location, const QByteArray &data) : _
_clipManagers.push_back(new ClipReadManager(_clipThreads.back()));
_clipThreads.back()->start();
} else {
_threadIndex = rand() % _clipThreads.size();
_threadIndex = int32(MTP::nonce<uint32>() % _clipThreads.size());
int32 loadLevel = 0x7FFFFFFF;
for (int32 i = 0, l = _clipThreads.size(); i < l; ++i) {
int32 level = _clipManagers.at(i)->loadLevel();
@ -690,6 +692,8 @@ bool ClipReadManager::handleProcessResult(ClipReaderPrivate *reader, ClipProcess
if (result == ClipProcessError) {
if (it != _readerPointers.cend()) {
it.key()->error();
emit reinit(it.key());
_readerPointers.erase(it);
it = _readerPointers.end();
}

View File

@ -30,6 +30,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
#include "gui/filedialog.h"
#include "boxes/addcontactbox.h"
#include "boxes/confirmbox.h"
#include "audio.h"
#include "localstorage.h"
@ -4557,6 +4558,13 @@ HistoryGif::HistoryGif(DocumentData *document) : HistoryFileMedia()
void HistoryGif::initDimensions(const HistoryItem *parent) {
bool bubble = parent->hasBubble();
int32 tw = 0, th = 0;
if (_gif && _gif->state() == ClipError) {
Ui::showLayer(new InformBox(lang(lng_gif_error)));
App::unregGifItem(_gif);
delete _gif;
_gif = 0;
}
if (_gif && _gif->ready()) {
tw = convertScale(_gif->width());
th = convertScale(_gif->height());
@ -4567,13 +4575,13 @@ void HistoryGif::initDimensions(const HistoryItem *parent) {
th = convertScale(_data->thumb->height());
}
}
if (tw > st::maxMediaSize) {
th = (st::maxMediaSize * th) / tw;
tw = st::maxMediaSize;
if (tw > st::maxGifSize) {
th = (st::maxGifSize * th) / tw;
tw = st::maxGifSize;
}
if (th > st::maxMediaSize) {
tw = (st::maxMediaSize * tw) / th;
th = st::maxMediaSize;
if (th > st::maxGifSize) {
tw = (st::maxGifSize * tw) / th;
th = st::maxGifSize;
}
if (!tw || !th) {
tw = th = 1;
@ -4737,13 +4745,13 @@ int32 HistoryGif::resize(int32 width, const HistoryItem *parent) {
th = convertScale(_data->thumb->height());
}
}
if (tw > st::maxMediaSize) {
th = (st::maxMediaSize * th) / tw;
tw = st::maxMediaSize;
if (tw > st::maxGifSize) {
th = (st::maxGifSize * th) / tw;
tw = st::maxGifSize;
}
if (th > st::maxMediaSize) {
tw = (st::maxMediaSize * tw) / th;
th = st::maxMediaSize;
if (th > st::maxGifSize) {
tw = (st::maxGifSize * tw) / th;
th = st::maxGifSize;
}
if (!tw || !th) {
tw = th = 1;
@ -4809,13 +4817,13 @@ int32 HistoryGif::countHeight(const HistoryItem *parent, int32 width) const {
th = convertScale(_data->thumb->height());
}
}
if (tw > st::maxMediaSize) {
th = (st::maxMediaSize * th) / tw;
tw = st::maxMediaSize;
if (tw > st::maxGifSize) {
th = (st::maxGifSize * th) / tw;
tw = st::maxGifSize;
}
if (th > st::maxMediaSize) {
tw = (st::maxMediaSize * tw) / th;
th = st::maxMediaSize;
if (th > st::maxGifSize) {
tw = (st::maxGifSize * tw) / th;
th = st::maxGifSize;
}
if (!tw || !th) {
tw = th = 1;