mirror of https://github.com/procxx/kepka.git
				
				
				
			Added button to add new files in SendFilesBox to album only.
This commit is contained in:
		
							parent
							
								
									abc7b8364c
								
							
						
					
					
						commit
						5f8c2f90ff
					
				| 
						 | 
					@ -499,7 +499,7 @@ void EditCaptionBox::createEditMediaButton() {
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		auto list = Storage::PreparedList::EditedPreparedFile(
 | 
							auto list = Storage::PreparedList::PreparedFileFromFileDialog(
 | 
				
			||||||
			std::move(result),
 | 
								std::move(result),
 | 
				
			||||||
			_isAlbum,
 | 
								_isAlbum,
 | 
				
			||||||
			[] {
 | 
								[] {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -126,6 +126,40 @@ void PaintAlbumThumbButtons(
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void FileDialogCallback(
 | 
				
			||||||
 | 
						FileDialog::OpenResult &&result,
 | 
				
			||||||
 | 
						bool isAlbum,
 | 
				
			||||||
 | 
						Fn<void(Storage::PreparedList)> callback) {
 | 
				
			||||||
 | 
						auto isValidFile = [](QString mimeType) {
 | 
				
			||||||
 | 
							if (mimeType != qstr("image/webp")) {
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							Ui::show(
 | 
				
			||||||
 | 
								Box<InformBox>(tr::lng_edit_media_invalid_file(tr::now)),
 | 
				
			||||||
 | 
								Ui::LayerOption::KeepOther);
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						auto errorCallback = [] {
 | 
				
			||||||
 | 
							Ui::show(
 | 
				
			||||||
 | 
								Box<InformBox>(tr::lng_edit_media_album_error(tr::now)),
 | 
				
			||||||
 | 
								Ui::LayerOption::KeepOther);
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						auto list = Storage::PreparedList::PreparedFileFromFileDialog(
 | 
				
			||||||
 | 
							std::move(result),
 | 
				
			||||||
 | 
							isAlbum,
 | 
				
			||||||
 | 
							std::move(errorCallback),
 | 
				
			||||||
 | 
							std::move(isValidFile),
 | 
				
			||||||
 | 
							st::sendMediaPreviewSize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!list) {
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						callback(std::move(*list));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SingleMediaPreview : public Ui::RpWidget {
 | 
					class SingleMediaPreview : public Ui::RpWidget {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	static SingleMediaPreview *Create(
 | 
						static SingleMediaPreview *Create(
 | 
				
			||||||
| 
						 | 
					@ -1631,9 +1665,7 @@ void SendFilesBox::addThumbButtonHandlers() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		_compressConfirm = _compressConfirmInitial;
 | 
							_compressConfirm = _compressConfirmInitial;
 | 
				
			||||||
		refreshAlbumMediaCount();
 | 
							refreshAllAfterAlbumChanges();
 | 
				
			||||||
		preparePreview();
 | 
					 | 
				
			||||||
		captionResized();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}, _albumPreview->lifetime());
 | 
						}, _albumPreview->lifetime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1641,44 +1673,20 @@ void SendFilesBox::addThumbButtonHandlers() {
 | 
				
			||||||
	) | rpl::start_with_next([=](auto index) {
 | 
						) | rpl::start_with_next([=](auto index) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const auto callback = [=](FileDialog::OpenResult &&result) {
 | 
							const auto callback = [=](FileDialog::OpenResult &&result) {
 | 
				
			||||||
			auto isValidFile = [](QString mimeType) {
 | 
								FileDialogCallback(
 | 
				
			||||||
				if (mimeType != qstr("image/webp")) {
 | 
					 | 
				
			||||||
					return true;
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
				Ui::show(
 | 
					 | 
				
			||||||
					Box<InformBox>(tr::lng_edit_media_invalid_file(tr::now)),
 | 
					 | 
				
			||||||
					Ui::LayerOption::KeepOther);
 | 
					 | 
				
			||||||
				return false;
 | 
					 | 
				
			||||||
			};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			auto errorCallback = [] {
 | 
					 | 
				
			||||||
				Ui::show(
 | 
					 | 
				
			||||||
					Box<InformBox>(tr::lng_edit_media_album_error(tr::now)),
 | 
					 | 
				
			||||||
					Ui::LayerOption::KeepOther);
 | 
					 | 
				
			||||||
			};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			auto list = Storage::PreparedList::EditedPreparedFile(
 | 
					 | 
				
			||||||
				std::move(result),
 | 
									std::move(result),
 | 
				
			||||||
				true,
 | 
									true,
 | 
				
			||||||
				std::move(errorCallback),
 | 
									[=] (auto list) {
 | 
				
			||||||
				std::move(isValidFile),
 | 
										_list.files[index] = std::move(list.files.front());
 | 
				
			||||||
				st::sendMediaPreviewSize);
 | 
										applyAlbumOrder();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (!list) {
 | 
										if (_preview) {
 | 
				
			||||||
				return;
 | 
											_preview->deleteLater();
 | 
				
			||||||
			}
 | 
										}
 | 
				
			||||||
 | 
										_albumPreview = nullptr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			_list.files[index] = std::move((*list).files.front());
 | 
										refreshAllAfterAlbumChanges();
 | 
				
			||||||
			applyAlbumOrder();
 | 
									});
 | 
				
			||||||
 | 
					 | 
				
			||||||
			if (_preview) {
 | 
					 | 
				
			||||||
				_preview->deleteLater();
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			_albumPreview = nullptr;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			refreshAlbumMediaCount();
 | 
					 | 
				
			||||||
			preparePreview();
 | 
					 | 
				
			||||||
			captionResized();
 | 
					 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		FileDialog::GetOpenPath(
 | 
							FileDialog::GetOpenPath(
 | 
				
			||||||
| 
						 | 
					@ -1738,6 +1746,49 @@ void SendFilesBox::prepare() {
 | 
				
			||||||
			_cancelledCallback();
 | 
								_cancelledCallback();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}, lifetime());
 | 
						}, lifetime());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const auto title = tr::lng_stickers_featured_add(tr::now) + qsl("...");
 | 
				
			||||||
 | 
						_addFileToAlbum = addLeftButton(
 | 
				
			||||||
 | 
							rpl::single(title),
 | 
				
			||||||
 | 
							App::LambdaDelayed(st::historyAttach.ripple.hideDuration, this, [=] {
 | 
				
			||||||
 | 
								openDialogToAddFileToAlbum();
 | 
				
			||||||
 | 
							}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						updateLeftButtonVisibility();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SendFilesBox::updateLeftButtonVisibility() {
 | 
				
			||||||
 | 
						const auto isAlbum = _list.albumIsPossible
 | 
				
			||||||
 | 
							&& (_list.files.size() < Storage::MaxAlbumItems());
 | 
				
			||||||
 | 
						if (isAlbum || (IsSingleItem(_list) && IsFirstAlbumItem(_list))) {
 | 
				
			||||||
 | 
							_addFileToAlbum->show();
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							_addFileToAlbum->hide();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SendFilesBox::refreshAllAfterAlbumChanges() {
 | 
				
			||||||
 | 
						refreshAlbumMediaCount();
 | 
				
			||||||
 | 
						preparePreview();
 | 
				
			||||||
 | 
						captionResized();
 | 
				
			||||||
 | 
						updateLeftButtonVisibility();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SendFilesBox::openDialogToAddFileToAlbum() {
 | 
				
			||||||
 | 
						const auto callback = [=](FileDialog::OpenResult &&result) {
 | 
				
			||||||
 | 
							FileDialogCallback(
 | 
				
			||||||
 | 
								std::move(result),
 | 
				
			||||||
 | 
								true,
 | 
				
			||||||
 | 
								[=] (auto list) {
 | 
				
			||||||
 | 
									addFiles(std::move(list));
 | 
				
			||||||
 | 
								});
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						FileDialog::GetOpenPath(
 | 
				
			||||||
 | 
							this,
 | 
				
			||||||
 | 
							tr::lng_choose_file(tr::now),
 | 
				
			||||||
 | 
							FileDialog::AlbumFilesFilter(),
 | 
				
			||||||
 | 
							crl::guard(this, callback));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SendFilesBox::initSendWay() {
 | 
					void SendFilesBox::initSendWay() {
 | 
				
			||||||
| 
						 | 
					@ -2054,9 +2105,7 @@ bool SendFilesBox::addFiles(Storage::PreparedList list) {
 | 
				
			||||||
	_list.mergeToEnd(std::move(list));
 | 
						_list.mergeToEnd(std::move(list));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_compressConfirm = _compressConfirmInitial;
 | 
						_compressConfirm = _compressConfirmInitial;
 | 
				
			||||||
	refreshAlbumMediaCount();
 | 
						refreshAllAfterAlbumChanges();
 | 
				
			||||||
	preparePreview();
 | 
					 | 
				
			||||||
	captionResized();
 | 
					 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2094,7 +2143,9 @@ void SendFilesBox::updateBoxSize() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SendFilesBox::keyPressEvent(QKeyEvent *e) {
 | 
					void SendFilesBox::keyPressEvent(QKeyEvent *e) {
 | 
				
			||||||
	if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
 | 
						if (e->matches(QKeySequence::Open) && !_addFileToAlbum->isHidden()) {
 | 
				
			||||||
 | 
							openDialogToAddFileToAlbum();
 | 
				
			||||||
 | 
						} else if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return) {
 | 
				
			||||||
		const auto modifiers = e->modifiers();
 | 
							const auto modifiers = e->modifiers();
 | 
				
			||||||
		const auto ctrl = modifiers.testFlag(Qt::ControlModifier)
 | 
							const auto ctrl = modifiers.testFlag(Qt::ControlModifier)
 | 
				
			||||||
			|| modifiers.testFlag(Qt::MetaModifier);
 | 
								|| modifiers.testFlag(Qt::MetaModifier);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -126,6 +126,10 @@ private:
 | 
				
			||||||
	bool addFiles(not_null<const QMimeData*> data);
 | 
						bool addFiles(not_null<const QMimeData*> data);
 | 
				
			||||||
	bool addFiles(Storage::PreparedList list);
 | 
						bool addFiles(Storage::PreparedList list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void openDialogToAddFileToAlbum();
 | 
				
			||||||
 | 
						void updateLeftButtonVisibility();
 | 
				
			||||||
 | 
						void refreshAllAfterAlbumChanges();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	const not_null<Window::SessionController*> _controller;
 | 
						const not_null<Window::SessionController*> _controller;
 | 
				
			||||||
	const Api::SendType _sendType = Api::SendType();
 | 
						const Api::SendType _sendType = Api::SendType();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -166,5 +170,6 @@ private:
 | 
				
			||||||
	int _albumPhotosCount = 0;
 | 
						int _albumPhotosCount = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QPointer<Ui::RoundButton> _send;
 | 
						QPointer<Ui::RoundButton> _send;
 | 
				
			||||||
 | 
						QPointer<Ui::RoundButton> _addFileToAlbum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -278,7 +278,7 @@ PreparedList PrepareMediaFromImage(
 | 
				
			||||||
	return result;
 | 
						return result;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::optional<PreparedList> PreparedList::EditedPreparedFile(
 | 
					std::optional<PreparedList> PreparedList::PreparedFileFromFileDialog(
 | 
				
			||||||
		FileDialog::OpenResult &&result,
 | 
							FileDialog::OpenResult &&result,
 | 
				
			||||||
		bool isAlbum,
 | 
							bool isAlbum,
 | 
				
			||||||
		Fn<void()> errorCallback,
 | 
							Fn<void()> errorCallback,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -61,7 +61,7 @@ struct PreparedList {
 | 
				
			||||||
	static PreparedList Reordered(
 | 
						static PreparedList Reordered(
 | 
				
			||||||
		PreparedList &&list,
 | 
							PreparedList &&list,
 | 
				
			||||||
		std::vector<int> order);
 | 
							std::vector<int> order);
 | 
				
			||||||
	static std::optional<PreparedList> EditedPreparedFile(
 | 
						static std::optional<PreparedList> PreparedFileFromFileDialog(
 | 
				
			||||||
		FileDialog::OpenResult &&result,
 | 
							FileDialog::OpenResult &&result,
 | 
				
			||||||
		bool isAlbum,
 | 
							bool isAlbum,
 | 
				
			||||||
		Fn<void()> errorCallback,
 | 
							Fn<void()> errorCallback,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue