2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-03 16:05:57 +00:00

Moved file click handlers to separated file.

This commit is contained in:
23rd
2021-06-18 02:28:09 +03:00
parent 8834ec8bf2
commit 3fd772ce17
29 changed files with 421 additions and 398 deletions

View File

@@ -76,59 +76,6 @@ QString JoinStringList(const QStringList &list, const QString &separator) {
return result;
}
void LaunchWithWarning(
not_null<Main::Session*> session,
const QString &name,
HistoryItem *item) {
const auto isExecutable = Data::IsExecutableName(name);
const auto isIpReveal = Data::IsIpRevealingName(name);
auto &app = Core::App();
const auto warn = [&] {
if (item && item->history()->peer->isVerified()) {
return false;
}
return (isExecutable && app.settings().exeLaunchWarning())
|| (isIpReveal && app.settings().ipRevealWarning());
}();
const auto extension = '.' + Data::FileExtension(name);
if (Platform::IsWindows() && extension == u"."_q) {
// If you launch a file without extension, like "test", in case
// there is an executable file with the same name in this folder,
// like "test.bat", the executable file will be launched.
//
// Now we always force an Open With dialog box for such files.
crl::on_main([=] {
Platform::File::UnsafeShowOpenWith(name);
});
return;
} else if (!warn) {
File::Launch(name);
return;
}
const auto callback = [=, &app](bool checked) {
if (checked) {
if (isExecutable) {
app.settings().setExeLaunchWarning(false);
} else if (isIpReveal) {
app.settings().setIpRevealWarning(false);
}
app.saveSettingsDelayed();
}
File::Launch(name);
};
auto text = isExecutable
? tr::lng_launch_exe_warning(
lt_extension,
rpl::single(Ui::Text::Bold(extension)),
Ui::Text::WithEntities)
: tr::lng_launch_svg_warning(Ui::Text::WithEntities);
Ui::show(Box<ConfirmDontWarnBox>(
std::move(text),
tr::lng_launch_exe_dont_ask(tr::now),
(isExecutable ? tr::lng_launch_exe_sure : tr::lng_continue)(),
callback));
}
} // namespace
QString FileNameUnsafe(
@@ -309,104 +256,6 @@ QString DocumentFileNameForSave(
dir);
}
DocumentClickHandler::DocumentClickHandler(
not_null<DocumentData*> document,
FullMsgId context)
: FileClickHandler(&document->session(), context)
, _document(document) {
}
DocumentOpenClickHandler::DocumentOpenClickHandler(
not_null<DocumentData*> document,
Fn<void()> &&callback)
: DocumentClickHandler(document)
, _handler(std::move(callback)) {
}
void DocumentOpenClickHandler::onClickImpl() const {
if (_handler) {
_handler();
}
}
void DocumentSaveClickHandler::Save(
Data::FileOrigin origin,
not_null<DocumentData*> data,
Mode mode) {
if (!data->date) {
return;
}
auto savename = QString();
if (mode != Mode::ToCacheOrFile || !data->saveToCache()) {
if (mode != Mode::ToNewFile && data->saveFromData()) {
return;
}
const auto filepath = data->filepath(true);
const auto fileinfo = QFileInfo(
);
const auto filedir = filepath.isEmpty()
? QDir()
: fileinfo.dir();
const auto filename = filepath.isEmpty()
? QString()
: fileinfo.fileName();
savename = DocumentFileNameForSave(
data,
(mode == Mode::ToNewFile),
filename,
filedir);
if (savename.isEmpty()) {
return;
}
}
data->save(origin, savename);
}
void DocumentSaveClickHandler::onClickImpl() const {
Save(context(), document());
}
void DocumentCancelClickHandler::onClickImpl() const {
const auto data = document();
if (!data->date) {
return;
} else if (data->uploading()) {
if (const auto item = data->owner().message(context())) {
if (const auto m = App::main()) { // multi good
if (&m->session() == &data->session()) {
m->cancelUploadLayer(item);
}
}
}
} else {
data->cancel();
}
}
void DocumentOpenWithClickHandler::Open(
Data::FileOrigin origin,
not_null<DocumentData*> data) {
if (!data->date) {
return;
}
data->saveFromDataSilent();
const auto path = data->filepath(true);
if (!path.isEmpty()) {
File::OpenWith(path, QCursor::pos());
} else {
DocumentSaveClickHandler::Save(
origin,
data,
DocumentSaveClickHandler::Mode::ToFile);
}
}
void DocumentOpenWithClickHandler::onClickImpl() const {
Open(context(), document());
}
Data::FileOrigin StickerData::setOrigin() const {
return set.match([&](const MTPDinputStickerSetID &data) {
return Data::FileOrigin(