| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | /*
 | 
					
						
							|  |  |  | This file is part of Telegram Desktop, | 
					
						
							| 
									
										
										
										
											2018-01-03 13:23:14 +03:00
										 |  |  | the official desktop application for the Telegram messaging service. | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 13:23:14 +03:00
										 |  |  | For license and copyright information please follow this link: | 
					
						
							|  |  |  | https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | */ | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 13:51:00 +03:00
										 |  |  | #include "platform/platform_file_utilities.h"
 | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-08 23:15:42 +03:00
										 |  |  | #include <QtGui/QWindow>
 | 
					
						
							|  |  |  | #include <QtWidgets/QFileDialog>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | extern "C" { | 
					
						
							|  |  |  | #undef signals
 | 
					
						
							| 
									
										
										
										
											2017-08-07 17:57:34 +06:00
										 |  |  | #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
 | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | #include <gtk/gtk.h>
 | 
					
						
							|  |  |  | #include <gdk/gdk.h>
 | 
					
						
							| 
									
										
										
										
											2017-08-07 17:57:34 +06:00
										 |  |  | #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
 | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | #define signals public
 | 
					
						
							|  |  |  | } // extern "C"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Platform { | 
					
						
							| 
									
										
										
										
											2017-02-28 13:51:00 +03:00
										 |  |  | namespace File { | 
					
						
							| 
									
										
										
										
											2017-02-28 17:05:30 +03:00
										 |  |  | namespace internal { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray EscapeShell(const QByteArray &content); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace internal
 | 
					
						
							| 
									
										
										
										
											2017-02-28 13:51:00 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | inline QString UrlToLocal(const QUrl &url) { | 
					
						
							| 
									
										
										
										
											2017-02-28 17:05:30 +03:00
										 |  |  | 	return ::File::internal::UrlToLocalDefault(url); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool UnsafeShowOpenWithDropdown(const QString &filepath, QPoint menuPosition) { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool UnsafeShowOpenWith(const QString &filepath) { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline void PostprocessDownloaded(const QString &filepath) { | 
					
						
							| 
									
										
										
										
											2017-02-28 13:51:00 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace File
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | namespace FileDialog { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 17:05:30 +03:00
										 |  |  | inline void InitLastPath() { | 
					
						
							|  |  |  | 	::FileDialog::internal::InitLastPathDefault(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace internal { | 
					
						
							| 
									
										
										
										
											2017-08-07 17:57:34 +06:00
										 |  |  | #ifndef TDESKTOP_DISABLE_GTK_INTEGRATION
 | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | // This is a patched copy of qgtk2 theme plugin.
 | 
					
						
							|  |  |  | // We need to use our own gtk file dialog instead of
 | 
					
						
							|  |  |  | // styling Qt file dialog, because Qt only works with gtk2.
 | 
					
						
							|  |  |  | // We need to be able to work with gtk2 and gtk3, because
 | 
					
						
							|  |  |  | // we use gtk3 to work with appindicator3.
 | 
					
						
							|  |  |  | class QGtkDialog : public QWindow { | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	Q_OBJECT | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	QGtkDialog(GtkWidget *gtkWidget); | 
					
						
							|  |  |  | 	~QGtkDialog(); | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	GtkDialog *gtkDialog() const; | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	void exec(); | 
					
						
							|  |  |  | 	void show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent); | 
					
						
							|  |  |  | 	void hide(); | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | signals: | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	void accept(); | 
					
						
							|  |  |  | 	void reject(); | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	static void onResponse(QGtkDialog *dialog, int response); | 
					
						
							|  |  |  | 	static void onUpdatePreview(QGtkDialog *dialog); | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	void onParentWindowDestroyed(); | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	GtkWidget *gtkWidget; | 
					
						
							|  |  |  | 	GtkWidget *_preview = nullptr; | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class GtkFileDialog : public QDialog { | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	Q_OBJECT | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	GtkFileDialog(QWidget *parent = Q_NULLPTR, | 
					
						
							|  |  |  | 		const QString &caption = QString(), | 
					
						
							|  |  |  | 		const QString &directory = QString(), | 
					
						
							|  |  |  | 		const QString &filter = QString()); | 
					
						
							|  |  |  | 	~GtkFileDialog(); | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void setVisible(bool visible) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void setWindowTitle(const QString &windowTitle) { | 
					
						
							|  |  |  | 		_windowTitle = windowTitle; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	void setAcceptMode(QFileDialog::AcceptMode acceptMode) { | 
					
						
							|  |  |  | 		_acceptMode = acceptMode; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	void setFileMode(QFileDialog::FileMode fileMode) { | 
					
						
							|  |  |  | 		_fileMode = fileMode; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	void setOption(QFileDialog::Option option, bool on = true) { | 
					
						
							|  |  |  | 		if (on) { | 
					
						
							|  |  |  | 			_options |= option; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			_options &= ~option; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	int exec() override; | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	bool defaultNameFilterDisables() const; | 
					
						
							|  |  |  | 	void setDirectory(const QString &directory); | 
					
						
							|  |  |  | 	QDir directory() const; | 
					
						
							|  |  |  | 	void selectFile(const QString &filename); | 
					
						
							|  |  |  | 	QStringList selectedFiles() const; | 
					
						
							|  |  |  | 	void setFilter(); | 
					
						
							|  |  |  | 	void selectNameFilter(const QString &filter); | 
					
						
							|  |  |  | 	QString selectedNameFilter() const; | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | private slots: | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	void onAccepted(); | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 	void onRejected(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	static void onSelectionChanged(GtkDialog *dialog, GtkFileDialog *helper); | 
					
						
							|  |  |  | 	static void onCurrentFolderChanged(GtkFileDialog *helper); | 
					
						
							|  |  |  | 	void applyOptions(); | 
					
						
							|  |  |  | 	void setNameFilters(const QStringList &filters); | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void showHelper(Qt::WindowFlags flags, Qt::WindowModality modality, QWindow *parent); | 
					
						
							|  |  |  | 	void hideHelper(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Options
 | 
					
						
							|  |  |  | 	QFileDialog::Options _options = { 0 }; | 
					
						
							|  |  |  | 	QString _windowTitle = "Choose file"; | 
					
						
							|  |  |  | 	QString _initialDirectory; | 
					
						
							|  |  |  | 	QStringList _initialFiles; | 
					
						
							|  |  |  | 	QStringList _nameFilters; | 
					
						
							|  |  |  | 	QFileDialog::AcceptMode _acceptMode = QFileDialog::AcceptOpen; | 
					
						
							|  |  |  | 	QFileDialog::FileMode _fileMode = QFileDialog::ExistingFile; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-26 22:27:57 +03:00
										 |  |  | 	QString _dir; | 
					
						
							|  |  |  | 	QStringList _selection; | 
					
						
							|  |  |  | 	QHash<QString, GtkFileFilter*> _filters; | 
					
						
							|  |  |  | 	QHash<GtkFileFilter*, QString> _filterNames; | 
					
						
							|  |  |  | 	QScopedPointer<QGtkDialog> d; | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2017-08-07 17:57:34 +06:00
										 |  |  | #endif // !TDESKTOP_DISABLE_GTK_INTEGRATION
 | 
					
						
							| 
									
										
										
										
											2016-07-06 21:30:14 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // namespace internal
 | 
					
						
							|  |  |  | } // namespace FileDialog
 | 
					
						
							|  |  |  | } // namespace Platform
 |