2016-08-28 19:16:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-08-28 19:16:23 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-08-28 19:16:23 +00:00
|
|
|
*/
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/local_storage_box.h"
|
2016-08-28 19:16:23 +00:00
|
|
|
|
2016-11-08 14:43:10 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2016-11-11 13:46:04 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2016-08-28 19:16:23 +00:00
|
|
|
#include "mainwindow.h"
|
2017-03-04 19:36:59 +00:00
|
|
|
#include "auth_session.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "layout.h"
|
2016-08-28 19:16:23 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
LocalStorageBox::LocalStorageBox(QWidget *parent)
|
|
|
|
: _clear(this, lang(lng_local_storage_clear), st::boxLinkButton) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalStorageBox::prepare() {
|
2017-05-30 15:21:05 +00:00
|
|
|
setTitle(langFactory(lng_local_storage_title));
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-05-30 15:21:05 +00:00
|
|
|
addButton(langFactory(lng_box_ok), [this] { closeBox(); });
|
2016-11-19 14:47:28 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
_clear->setClickedCallback([this] { clearStorage(); });
|
2016-08-28 19:16:23 +00:00
|
|
|
|
|
|
|
connect(App::wnd(), SIGNAL(tempDirCleared(int)), this, SLOT(onTempDirCleared(int)));
|
|
|
|
connect(App::wnd(), SIGNAL(tempDirClearFailed(int)), this, SLOT(onTempDirClearFailed(int)));
|
|
|
|
|
2017-08-04 14:54:32 +00:00
|
|
|
subscribe(Auth().downloaderTaskFinished(), [this] { update(); });
|
2016-09-26 13:57:08 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
updateControls();
|
|
|
|
|
2016-08-28 19:16:23 +00:00
|
|
|
checkLocalStoredCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalStorageBox::updateControls() {
|
2016-12-13 17:07:56 +00:00
|
|
|
auto rowsHeight = 0;
|
2016-08-28 19:16:23 +00:00
|
|
|
if (_imagesCount > 0 && _audiosCount > 0) {
|
|
|
|
rowsHeight = 2 * (st::linkFont->height + st::localStorageBoxSkip);
|
|
|
|
} else {
|
|
|
|
rowsHeight = st::linkFont->height + st::localStorageBoxSkip;
|
|
|
|
}
|
|
|
|
_clear->setVisible(_imagesCount > 0 || _audiosCount > 0);
|
2016-12-13 17:07:56 +00:00
|
|
|
setDimensions(st::boxWidth, st::localStorageBoxSkip + rowsHeight + _clear->height());
|
|
|
|
_clear->moveToLeft(st::boxPadding.left(), st::localStorageBoxSkip + rowsHeight);
|
2016-08-28 19:16:23 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalStorageBox::checkLocalStoredCounts() {
|
|
|
|
int imagesCount = Local::hasImages() + Local::hasStickers() + Local::hasWebFiles();
|
|
|
|
int audiosCount = Local::hasAudios();
|
|
|
|
if (imagesCount != _imagesCount || audiosCount != _audiosCount) {
|
|
|
|
_imagesCount = imagesCount;
|
|
|
|
_audiosCount = audiosCount;
|
|
|
|
if (_imagesCount > 0 || _audiosCount > 0) {
|
|
|
|
_state = State::Normal;
|
|
|
|
}
|
|
|
|
updateControls();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalStorageBox::paintEvent(QPaintEvent *e) {
|
2016-12-13 17:07:56 +00:00
|
|
|
BoxContent::paintEvent(e);
|
2016-08-28 19:16:23 +00:00
|
|
|
|
2016-11-19 14:47:28 +00:00
|
|
|
Painter p(this);
|
2016-08-28 19:16:23 +00:00
|
|
|
|
|
|
|
p.setFont(st::boxTextFont);
|
2016-11-16 10:44:06 +00:00
|
|
|
p.setPen(st::windowFg);
|
2016-08-28 19:16:23 +00:00
|
|
|
checkLocalStoredCounts();
|
2016-12-13 17:07:56 +00:00
|
|
|
auto top = st::localStorageBoxSkip;
|
2016-08-28 19:16:23 +00:00
|
|
|
if (_imagesCount > 0) {
|
|
|
|
auto text = lng_settings_images_cached(lt_count, _imagesCount, lt_size, formatSizeText(Local::storageImagesSize() + Local::storageStickersSize() + Local::storageWebFilesSize()));
|
|
|
|
p.drawTextLeft(st::boxPadding.left(), top, width(), text);
|
|
|
|
top += st::boxTextFont->height + st::localStorageBoxSkip;
|
|
|
|
}
|
|
|
|
if (_audiosCount > 0) {
|
|
|
|
auto text = lng_settings_audios_cached(lt_count, _audiosCount, lt_size, formatSizeText(Local::storageAudiosSize()));
|
|
|
|
p.drawTextLeft(st::boxPadding.left(), top, width(), text);
|
|
|
|
top += st::boxTextFont->height + st::localStorageBoxSkip;
|
|
|
|
} else if (_imagesCount <= 0) {
|
|
|
|
p.drawTextLeft(st::boxPadding.left(), top, width(), lang(lng_settings_no_data_cached));
|
|
|
|
top += st::boxTextFont->height + st::localStorageBoxSkip;
|
|
|
|
}
|
|
|
|
auto text = ([this]() -> QString {
|
|
|
|
switch (_state) {
|
|
|
|
case State::Clearing: return lang(lng_local_storage_clearing);
|
|
|
|
case State::Cleared: return lang(lng_local_storage_cleared);
|
2017-09-28 20:11:10 +00:00
|
|
|
case State::ClearFailed: return Lang::Hard::ClearPathFailed();
|
2016-08-28 19:16:23 +00:00
|
|
|
}
|
|
|
|
return QString();
|
|
|
|
})();
|
|
|
|
if (!text.isEmpty()) {
|
|
|
|
p.drawTextLeft(st::boxPadding.left(), top, width(), text);
|
|
|
|
top += st::boxTextFont->height + st::localStorageBoxSkip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
void LocalStorageBox::clearStorage() {
|
2016-08-28 19:16:23 +00:00
|
|
|
App::wnd()->tempDirDelete(Local::ClearManagerStorage);
|
|
|
|
_state = State::Clearing;
|
|
|
|
updateControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalStorageBox::onTempDirCleared(int task) {
|
|
|
|
if (task & Local::ClearManagerStorage) {
|
|
|
|
_state = State::Cleared;
|
|
|
|
}
|
|
|
|
updateControls();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalStorageBox::onTempDirClearFailed(int task) {
|
|
|
|
if (task & Local::ClearManagerStorage) {
|
|
|
|
_state = State::ClearFailed;
|
|
|
|
}
|
|
|
|
updateControls();
|
|
|
|
}
|