2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram 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.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "lang.h"
|
|
|
|
|
2015-03-02 12:34:16 +00:00
|
|
|
#include "localstorage.h"
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
#include "downloadpathbox.h"
|
|
|
|
#include "gui/filedialog.h"
|
2015-11-26 17:34:52 +00:00
|
|
|
#include "pspecific.h"
|
|
|
|
|
|
|
|
DownloadPathBox::DownloadPathBox() : AbstractBox()
|
|
|
|
, _path(cDownloadPath())
|
|
|
|
, _pathBookmark(cDownloadPathBookmark())
|
|
|
|
, _default(this, qsl("dir_type"), 0, lang(lng_download_path_default_radio), _path.isEmpty())
|
|
|
|
, _temp(this, qsl("dir_type"), 1, lang(lng_download_path_temp_radio), _path == qsl("tmp"))
|
|
|
|
, _dir(this, qsl("dir_type"), 2, lang(lng_download_path_dir_radio), !_path.isEmpty() && _path != qsl("tmp"))
|
|
|
|
, _pathLink(this, QString(), st::defaultBoxLinkButton)
|
|
|
|
, _save(this, lang(lng_connection_save), st::defaultBoxButton)
|
|
|
|
, _cancel(this, lang(lng_cancel), st::cancelBoxButton) {
|
2015-10-06 19:49:23 +00:00
|
|
|
|
|
|
|
connect(&_save, SIGNAL(clicked()), this, SLOT(onSave()));
|
|
|
|
connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
|
|
|
|
|
|
|
|
connect(&_default, SIGNAL(changed()), this, SLOT(onChange()));
|
|
|
|
connect(&_temp, SIGNAL(changed()), this, SLOT(onChange()));
|
|
|
|
connect(&_dir, SIGNAL(changed()), this, SLOT(onChange()));
|
|
|
|
|
|
|
|
connect(&_pathLink, SIGNAL(clicked()), this, SLOT(onEditPath()));
|
|
|
|
if (!_path.isEmpty() && _path != qsl("tmp")) {
|
|
|
|
setPathText(QDir::toNativeSeparators(_path));
|
|
|
|
}
|
2015-04-02 10:33:19 +00:00
|
|
|
prepare();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::hideAll() {
|
2015-10-06 19:49:23 +00:00
|
|
|
_default.hide();
|
|
|
|
_temp.hide();
|
|
|
|
_dir.hide();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
_pathLink.hide();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
_save.hide();
|
|
|
|
_cancel.hide();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::showAll() {
|
2015-10-06 19:49:23 +00:00
|
|
|
_default.show();
|
|
|
|
_temp.show();
|
|
|
|
_dir.show();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
if (_dir.checked()) {
|
|
|
|
_pathLink.show();
|
2014-05-30 08:53:19 +00:00
|
|
|
} else {
|
2015-10-06 19:49:23 +00:00
|
|
|
_pathLink.hide();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
_save.show();
|
|
|
|
_cancel.show();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
int32 h = st::boxTitleHeight + st::boxOptionListPadding.top() + _default.height() + st::boxOptionListPadding.top() + _temp.height() + st::boxOptionListPadding.top() + _dir.height();
|
|
|
|
if (_dir.checked()) h += st::downloadPathSkip + _pathLink.height();
|
|
|
|
h += st::boxOptionListPadding.bottom() + st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom();
|
2015-04-02 10:33:19 +00:00
|
|
|
|
|
|
|
setMaxHeight(h);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void DownloadPathBox::paintEvent(QPaintEvent *e) {
|
2015-04-04 20:01:34 +00:00
|
|
|
Painter p(this);
|
2015-04-02 10:33:19 +00:00
|
|
|
if (paint(p)) return;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
paintTitle(p, lang(lng_download_path_header));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 10:33:19 +00:00
|
|
|
void DownloadPathBox::resizeEvent(QResizeEvent *e) {
|
2015-10-06 19:49:23 +00:00
|
|
|
_default.moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), st::boxTitleHeight + st::boxOptionListPadding.top());
|
|
|
|
_temp.moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _default.y() + _default.height() + st::boxOptionListPadding.top());
|
|
|
|
_dir.moveToLeft(st::boxPadding.left() + st::boxOptionListPadding.left(), _temp.y() + _temp.height() + st::boxOptionListPadding.top());
|
|
|
|
int32 inputx = st::boxPadding.left() + st::boxOptionListPadding.left() + st::defaultRadiobutton.textPosition.x();
|
|
|
|
int32 inputy = _dir.y() + _dir.height() + st::downloadPathSkip;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
_pathLink.moveToLeft(inputx, inputy);
|
2015-04-02 10:33:19 +00:00
|
|
|
|
2015-10-06 19:49:23 +00:00
|
|
|
_save.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _save.height());
|
|
|
|
_cancel.moveToRight(st::boxButtonPadding.right() + _save.width() + st::boxButtonPadding.left(), _save.y());
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::onChange() {
|
2015-10-06 19:49:23 +00:00
|
|
|
if (_dir.checked()) {
|
2014-09-30 14:11:09 +00:00
|
|
|
if (_path.isEmpty() || _path == qsl("tmp")) {
|
2015-10-06 19:49:23 +00:00
|
|
|
(_path.isEmpty() ? _default : _temp).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")) {
|
2015-10-06 19:49:23 +00:00
|
|
|
_dir.setChecked(true);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
} else {
|
2015-10-06 19:49:23 +00:00
|
|
|
setPathText(QDir::toNativeSeparators(_path));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
} else if (_temp.checked()) {
|
2014-09-30 14:11:09 +00:00
|
|
|
_path = qsl("tmp");
|
|
|
|
} else {
|
|
|
|
_path = QString();
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
showAll();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::onEditPath() {
|
|
|
|
filedialogInit();
|
|
|
|
QString path, lastPath = cDialogLastPath();
|
2015-11-26 17:34:52 +00:00
|
|
|
if (!cDownloadPath().isEmpty() && cDownloadPath() != qstr("tmp")) {
|
|
|
|
cSetDialogLastPath(cDownloadPath().left(cDownloadPath().size() - (cDownloadPath().endsWith('/') ? 1 : 0)));
|
2014-09-22 03:52:37 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
if (filedialogGetDir(path, lang(lng_download_path_choose))) {
|
|
|
|
if (!path.isEmpty()) {
|
|
|
|
_path = path + '/';
|
2015-11-26 17:34:52 +00:00
|
|
|
_pathBookmark = psDownloadPathBookmark(_path);
|
2015-10-06 19:49:23 +00:00
|
|
|
setPathText(QDir::toNativeSeparators(_path));
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cSetDialogLastPath(lastPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DownloadPathBox::onSave() {
|
2015-10-06 19:49:23 +00:00
|
|
|
cSetDownloadPath(_default.checked() ? QString() : (_temp.checked() ? qsl("tmp") : _path));
|
2015-11-26 17:34:52 +00:00
|
|
|
cSetDownloadPathBookmark((_default.checked() || _temp.checked()) ? QByteArray() : _pathBookmark);
|
2015-03-02 12:34:16 +00:00
|
|
|
Local::writeUserSettings();
|
2014-05-30 08:53:19 +00:00
|
|
|
emit closed();
|
|
|
|
}
|
2015-10-06 19:49:23 +00:00
|
|
|
|
|
|
|
void DownloadPathBox::setPathText(const QString &text) {
|
2015-10-11 08:37:24 +00:00
|
|
|
int32 availw = st::boxWideWidth - st::boxPadding.left() - st::defaultRadiobutton.textPosition.x() - st::boxPadding.right();
|
2015-10-06 19:49:23 +00:00
|
|
|
_pathLink.setText(st::boxTextFont->elided(text, availw));
|
|
|
|
}
|