| 72 | } |
| 73 | |
| 74 | void DocumentSaveClickHandler::Save( |
| 75 | Data::FileOrigin origin, |
| 76 | not_null<DocumentData*> data, |
| 77 | Mode mode, |
| 78 | Fn<void()> started) { |
| 79 | if (data->isNull()) { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | auto savename = QString(); |
| 84 | if (mode == Mode::ToCacheOrFile && data->saveToCache()) { |
| 85 | data->save(origin, savename); |
| 86 | return; |
| 87 | } |
| 88 | InvokeQueued(qApp, crl::guard(&data->session(), [=] { |
| 89 | // If we call file dialog synchronously, it will stop |
| 90 | // background thread timers from working which would |
| 91 | // stop audio playback in voice chats / live streams. |
| 92 | if (mode != Mode::ToNewFile && data->saveFromData()) { |
| 93 | if (started) { |
| 94 | started(); |
| 95 | } |
| 96 | return; |
| 97 | } |
| 98 | const auto filepath = data->filepath(true); |
| 99 | const auto fileinfo = QFileInfo(filepath); |
| 100 | const auto filedir = filepath.isEmpty() |
| 101 | ? QDir() |
| 102 | : fileinfo.dir(); |
| 103 | const auto filename = filepath.isEmpty() |
| 104 | ? QString() |
| 105 | : fileinfo.fileName(); |
| 106 | const auto savename = DocumentFileNameForSave( |
| 107 | data, |
| 108 | (mode == Mode::ToNewFile), |
| 109 | filename, |
| 110 | filedir); |
| 111 | if (!savename.isEmpty()) { |
| 112 | data->save(origin, savename); |
| 113 | if (started) { |
| 114 | started(); |
| 115 | } |
| 116 | } |
| 117 | })); |
| 118 | } |
| 119 | |
| 120 | void DocumentSaveClickHandler::SaveAndTrack( |
| 121 | FullMsgId itemId, |