2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Platform-dependent file methods called async.

Some major platform-dependent file operations refactoring.
All methods like "open file", "open file with", "show in folder"
were moved to core/file_utilities module with platform-dependent
backends. All methods interacting with DesktopServices made async.
This commit is contained in:
John Preston
2017-02-28 17:05:30 +03:00
parent 6f0cf30b12
commit f8318177b9
56 changed files with 1254 additions and 1088 deletions

View File

@@ -30,6 +30,44 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
QStringList qt_make_filter_list(const QString &filter);
namespace Platform {
namespace File {
namespace internal {
QByteArray EscapeShell(const QByteArray &content) {
auto result = QByteArray();
auto b = content.constData(), e = content.constEnd();
for (auto ch = b; ch != e; ++ch) {
if (*ch == ' ' || *ch == '"' || *ch == '\'' || *ch == '\\') {
if (result.isEmpty()) {
result.reserve(content.size() * 2);
}
if (ch > b) {
result.append(b, ch - b);
}
result.append('\\');
b = ch;
}
}
if (result.isEmpty()) {
return content;
}
if (e > b) {
result.append(b, e - b);
}
return result;
}
} // namespace internal
void UnsafeShowInFolder(const QString &filepath) {
Ui::hideLayer(true);
system(("xdg-open " + internal::EscapeShell(QFile::encodeName(QFileInfo(filepath).absoluteDir().absolutePath()))).constData());
}
} // namespace File
namespace FileDialog {
namespace {
@@ -43,11 +81,9 @@ namespace {
constexpr auto kPreviewWidth = 256;
constexpr auto kPreviewHeight = 512;
} // namespace
using Type = ::FileDialog::internal::Type;
bool Supported() {
bool NativeSupported() {
return Platform::internal::GdkHelperLoaded()
&& (Libs::gtk_widget_hide_on_delete != nullptr)
&& (Libs::gtk_clipboard_store != nullptr)
@@ -84,11 +120,11 @@ bool Supported() {
}
bool PreviewSupported() {
return Supported()
return NativeSupported()
&& (Libs::gdk_pixbuf_new_from_file_at_size != nullptr);
}
bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, Type type, QString startFile) {
bool GetNative(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, Type type, QString startFile) {
auto parent = App::wnd() ? App::wnd()->filedialogParent() : nullptr;
internal::GtkFileDialog dialog(parent, caption, QString(), filter);
@@ -131,6 +167,15 @@ bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption,
return false;
}
} // namespace
bool Get(QStringList &files, QByteArray &remoteContent, const QString &caption, const QString &filter, Type type, QString startFile) {
if (NativeSupported()) {
return GetNative(files, remoteContent, caption, filter, type, startFile);
}
return ::FileDialog::internal::GetDefault(files, remoteContent, caption, filter, type, startFile);
}
namespace internal {
QGtkDialog::QGtkDialog(GtkWidget *gtkWidget) : gtkWidget(gtkWidget) {