2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-11-25 20:15:18 +00:00
|
|
|
an official desktop messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
|
|
Copyright (c) 2014 John Preston, https://tdesktop.com
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
|
|
|
#include "downloadpathbox.h"
|
|
|
|
#include "gui/filedialog.h"
|
|
|
|
|
2014-06-16 09:31:10 +00:00
|
|
|
DownloadPathBox::DownloadPathBox() :
|
2014-05-30 08:53:19 +00:00
|
|
|
_path(cDownloadPath()),
|
2014-09-30 14:11:09 +00:00
|
|
|
_defaultRadio(this, qsl("dir_type"), 0, lang(lng_download_path_default_radio), _path.isEmpty()),
|
|
|
|
_tempRadio(this, qsl("dir_type"), 1, lang(lng_download_path_temp_radio), _path == qsl("tmp")),
|
|
|
|
_dirRadio(this, qsl("dir_type"), 2, lang(lng_download_path_dir_radio), !_path.isEmpty() && _path != qsl("tmp")),
|
|
|
|
_dirInput(this, st::inpDownloadDir, QString(), (_path.isEmpty() || _path == qsl("tmp")) ? QString() : QDir::toNativeSeparators(_path)),
|
2014-05-30 08:53:19 +00:00
|
|
|
_saveButton(this, lang(lng_connection_save), st::btnSelectDone),
|
|
|
|
_cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
|
2014-06-16 09:31:10 +00:00
|
|
|
a_opacity(0, 1), _hiding(false) {
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
_width = st::addContactWidth;
|
|
|
|
|
|
|
|
connect(&_saveButton, SIGNAL(clicked()), this, SLOT(onSave()));
|
|
|
|
connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
|
|
|
|
|
2014-09-30 14:11:09 +00:00
|
|
|
connect(&_defaultRadio, SIGNAL(changed()), this, SLOT(onChange()));
|
2014-05-30 08:53:19 +00:00
|
|
|
connect(&_tempRadio, SIGNAL(changed()), this, SLOT(onChange()));
|
|
|
|
connect(&_dirRadio, SIGNAL(changed()), this, SLOT(onChange()));
|
|
|
|
|
|
|
|
connect(&_dirInput, SIGNAL(focused()), this, SLOT(onEditPath()));
|
|
|
|
_dirInput.setCursorPosition(0);
|
|
|
|
|
|
|
|
showAll();
|
2014-06-14 19:32:11 +00:00
|
|
|
_cache = myGrab(this, rect());
|
2014-05-30 08:53:19 +00:00
|
|
|
hideAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::hideAll() {
|
2014-09-30 14:11:09 +00:00
|
|
|
_defaultRadio.hide();
|
2014-05-30 08:53:19 +00:00
|
|
|
_tempRadio.hide();
|
|
|
|
_dirRadio.hide();
|
|
|
|
|
|
|
|
_dirInput.hide();
|
|
|
|
|
|
|
|
_saveButton.hide();
|
|
|
|
_cancelButton.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::showAll() {
|
2014-09-30 14:11:09 +00:00
|
|
|
_defaultRadio.show();
|
2014-05-30 08:53:19 +00:00
|
|
|
_tempRadio.show();
|
|
|
|
_dirRadio.show();
|
|
|
|
|
|
|
|
if (_dirRadio.checked()) {
|
|
|
|
_dirInput.show();
|
|
|
|
} else {
|
|
|
|
_dirInput.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
_saveButton.show();
|
|
|
|
_cancelButton.show();
|
|
|
|
|
2014-09-30 14:11:09 +00:00
|
|
|
_defaultRadio.move(st::boxPadding.left(), st::addContactTitleHeight + st::downloadSkip);
|
|
|
|
_tempRadio.move(st::boxPadding.left(), _defaultRadio.y() + _defaultRadio.height() + st::downloadSkip);
|
2014-05-30 08:53:19 +00:00
|
|
|
_dirRadio.move(st::boxPadding.left(), _tempRadio.y() + _tempRadio.height() + st::downloadSkip);
|
|
|
|
int32 inputy = _dirRadio.y() + _dirRadio.height() + st::boxPadding.top();
|
|
|
|
|
|
|
|
_dirInput.move(st::boxPadding.left() + st::rbDefFlat.textLeft, inputy);
|
|
|
|
|
|
|
|
int32 buttony = (_dirRadio.checked() ? (_dirInput.y() + _dirInput.height()) : (_dirRadio.y() + _dirRadio.height())) + st::downloadSkip;
|
|
|
|
|
|
|
|
_saveButton.move(_width - _saveButton.width(), buttony);
|
|
|
|
_cancelButton.move(0, buttony);
|
|
|
|
|
|
|
|
_height = _saveButton.y() + _saveButton.height();
|
|
|
|
resize(_width, _height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::keyPressEvent(QKeyEvent *e) {
|
|
|
|
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
|
|
|
|
} else if (e->key() == Qt::Key_Escape) {
|
|
|
|
onCancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::parentResized() {
|
|
|
|
QSize s = parentWidget()->size();
|
|
|
|
setGeometry((s.width() - _width) / 2, (s.height() - _height) / 2, _width, _height);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::paintEvent(QPaintEvent *e) {
|
|
|
|
QPainter p(this);
|
|
|
|
if (_cache.isNull()) {
|
|
|
|
if (!_hiding || a_opacity.current() > 0.01) {
|
|
|
|
// fill bg
|
|
|
|
p.fillRect(0, 0, _width, _height, st::boxBG->b);
|
|
|
|
|
|
|
|
// paint shadows
|
|
|
|
p.fillRect(0, st::addContactTitleHeight, _width, st::scrollDef.topsh, st::scrollDef.shColor->b);
|
|
|
|
p.fillRect(0, _height - st::btnSelectCancel.height - st::scrollDef.bottomsh, _width, st::scrollDef.bottomsh, st::scrollDef.shColor->b);
|
|
|
|
|
|
|
|
// paint button sep
|
2014-07-06 03:32:21 +00:00
|
|
|
p.fillRect(st::btnSelectCancel.width, _height - st::btnSelectCancel.height, st::lineWidth, st::btnSelectCancel.height, st::btnSelectSep->b);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
// draw box title / text
|
|
|
|
p.setFont(st::addContactTitleFont->f);
|
|
|
|
p.setPen(st::black->p);
|
|
|
|
p.drawText(st::addContactTitlePos.x(), st::addContactTitlePos.y() + st::addContactTitleFont->ascent, lang(lng_download_path_header));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.setOpacity(a_opacity.current());
|
|
|
|
p.drawPixmap(0, 0, _cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::animStep(float64 dt) {
|
|
|
|
if (dt >= 1) {
|
|
|
|
a_opacity.finish();
|
|
|
|
_cache = QPixmap();
|
|
|
|
if (!_hiding) {
|
|
|
|
showAll();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
a_opacity.update(dt, anim::linear);
|
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::onChange() {
|
|
|
|
if (_dirRadio.checked()) {
|
2014-09-30 14:11:09 +00:00
|
|
|
if (_path.isEmpty() || _path == qsl("tmp")) {
|
|
|
|
(_path.isEmpty() ? _defaultRadio : _tempRadio).setChecked(true);
|
2014-05-30 08:53:19 +00:00
|
|
|
onEditPath();
|
2014-09-30 14:11:09 +00:00
|
|
|
if (!_path.isEmpty() && _path != qsl("tmp")) {
|
2014-05-30 08:53:19 +00:00
|
|
|
_dirRadio.setChecked(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_dirInput.setText(QDir::toNativeSeparators(_path));
|
|
|
|
_dirInput.setCursorPosition(0);
|
|
|
|
}
|
2014-09-30 14:11:09 +00:00
|
|
|
} else if (_tempRadio.checked()) {
|
|
|
|
_path = qsl("tmp");
|
|
|
|
} else {
|
|
|
|
_path = QString();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
showAll();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::onEditPath() {
|
|
|
|
_dirInput.clearFocus();
|
|
|
|
|
|
|
|
filedialogInit();
|
|
|
|
QString path, lastPath = cDialogLastPath();
|
2014-09-22 03:52:37 +00:00
|
|
|
if (!cDownloadPath().isEmpty()) {
|
|
|
|
cSetDialogLastPath(cDownloadPath());
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
if (filedialogGetDir(path, lang(lng_download_path_choose))) {
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
_path = path + '/';
|
|
|
|
_dirInput.setText(QDir::toNativeSeparators(_path));
|
|
|
|
_dirInput.setCursorPosition(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cSetDialogLastPath(lastPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::onSave() {
|
2014-09-30 14:11:09 +00:00
|
|
|
cSetDownloadPath(_defaultRadio.checked() ? QString() : (_tempRadio.checked() ? qsl("tmp") : _path));
|
2014-05-30 08:53:19 +00:00
|
|
|
App::writeUserConfig();
|
|
|
|
emit closed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::onCancel() {
|
|
|
|
emit closed();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::startHide() {
|
|
|
|
_hiding = true;
|
|
|
|
if (_cache.isNull()) {
|
2014-06-14 19:32:11 +00:00
|
|
|
_cache = myGrab(this, rect());
|
2014-05-30 08:53:19 +00:00
|
|
|
hideAll();
|
|
|
|
}
|
|
|
|
a_opacity.start(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
DownloadPathBox::~DownloadPathBox() {
|
|
|
|
}
|