[Option][GUI] File dialog chooser
This commit is contained in:
parent
6712cccf21
commit
ed0a2488a7
9 changed files with 134 additions and 1 deletions
|
|
@ -56,6 +56,10 @@
|
||||||
"ktg_net_speed_boost_big": "Big",
|
"ktg_net_speed_boost_big": "Big",
|
||||||
"ktg_settings_system": "System",
|
"ktg_settings_system": "System",
|
||||||
"ktg_settings_qt_scale": "Qt scaling engine",
|
"ktg_settings_qt_scale": "Qt scaling engine",
|
||||||
|
"ktg_settings_file_dialog_type": "File chooser dialog",
|
||||||
|
"ktg_file_dialog_type_default": "Default",
|
||||||
|
"ktg_file_dialog_disabled_on_build": "Disabled on build time",
|
||||||
|
"ktg_file_dialog_disabled_by_option": "Disabled by option",
|
||||||
"ktg_settings_other": "Other",
|
"ktg_settings_other": "Other",
|
||||||
"ktg_profile_copy_id": "Copy ID",
|
"ktg_profile_copy_id": "Copy ID",
|
||||||
"ktg_profile_bot_id": "Bot ID",
|
"ktg_profile_bot_id": "Bot ID",
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,23 @@ CheckHandler ReplacesLimit() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckHandler FileDialogLimit() {
|
||||||
|
return [=] (QVariant value) -> QVariant {
|
||||||
|
using Platform::FileDialog::ImplementationType;
|
||||||
|
auto newValue = int(ImplementationType::Default);
|
||||||
|
if (value.canConvert<int>()) {
|
||||||
|
auto intValue = value.toInt();
|
||||||
|
if (intValue >= int(ImplementationType::Default)
|
||||||
|
&& intValue < int(ImplementationType::Count)) {
|
||||||
|
|
||||||
|
newValue = intValue;
|
||||||
|
} else if (intValue >= int(ImplementationType::Count)) {
|
||||||
|
newValue = int(ImplementationType::Count) - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newValue;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
CheckHandler NetSpeedBoostConv(CheckHandler wrapped = nullptr) {
|
CheckHandler NetSpeedBoostConv(CheckHandler wrapped = nullptr) {
|
||||||
return [=] (QVariant value) -> QVariant {
|
return [=] (QVariant value) -> QVariant {
|
||||||
|
|
@ -376,6 +393,10 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
|
||||||
.type = SettingType::BoolSetting,
|
.type = SettingType::BoolSetting,
|
||||||
.defaultValue = false, }},
|
.defaultValue = false, }},
|
||||||
#endif
|
#endif
|
||||||
|
{ "file_dialog_type", {
|
||||||
|
.type = SettingType::IntSetting,
|
||||||
|
.defaultValue = int(Platform::FileDialog::ImplementationType::Default),
|
||||||
|
.limitHandler = FileDialogLimit(), }},
|
||||||
};
|
};
|
||||||
|
|
||||||
using OldOptionKey = QString;
|
using OldOptionKey = QString;
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,20 @@ namespace Settings {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
QString FileDialogTypeLabel(int value) {
|
||||||
|
const auto typedValue = Platform::FileDialog::ImplementationType(value);
|
||||||
|
switch (typedValue) {
|
||||||
|
case Platform::FileDialog::ImplementationType::Default:
|
||||||
|
return ktr("ktg_file_dialog_type_default");
|
||||||
|
}
|
||||||
|
return Platform::FileDialog::ImplementationTypeLabel(typedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString FileDialogTypeDescription(int value) {
|
||||||
|
const auto typedValue = Platform::FileDialog::ImplementationType(value);
|
||||||
|
return Platform::FileDialog::ImplementationTypeDescription(typedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString NetBoostLabel(int boost) {
|
QString NetBoostLabel(int boost) {
|
||||||
switch (boost) {
|
switch (boost) {
|
||||||
|
|
@ -417,6 +431,36 @@ void SetupKotatoSystem(
|
||||||
}, container->lifetime());
|
}, container->lifetime());
|
||||||
#endif // Qt < 6.0.0
|
#endif // Qt < 6.0.0
|
||||||
|
|
||||||
|
if (Platform::IsLinux()) {
|
||||||
|
auto fileDialogTypeText = rpl::single(
|
||||||
|
FileDialogTypeLabel(::Kotato::JsonSettings::GetInt("file_dialog_type"))
|
||||||
|
) | rpl::then(
|
||||||
|
::Kotato::JsonSettings::Events(
|
||||||
|
"file_dialog_type"
|
||||||
|
) | rpl::map([] {
|
||||||
|
return FileDialogTypeLabel(::Kotato::JsonSettings::GetInt("file_dialog_type"));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
AddButtonWithLabel(
|
||||||
|
container,
|
||||||
|
rktr("ktg_settings_file_dialog_type"),
|
||||||
|
fileDialogTypeText,
|
||||||
|
st::settingsButton
|
||||||
|
)->addClickHandler([=] {
|
||||||
|
Ui::show(Box<::Kotato::RadioBox>(
|
||||||
|
ktr("ktg_settings_file_dialog_type"),
|
||||||
|
::Kotato::JsonSettings::GetInt("file_dialog_type"),
|
||||||
|
int(Platform::FileDialog::ImplementationType::Count),
|
||||||
|
FileDialogTypeLabel,
|
||||||
|
FileDialogTypeDescription,
|
||||||
|
[=](int value) {
|
||||||
|
::Kotato::JsonSettings::Set("file_dialog_type", value);
|
||||||
|
::Kotato::JsonSettings::Write();
|
||||||
|
}, false));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
AddSkip(container);
|
AddSkip(container);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "platform/linux/file_utilities_linux.h"
|
#include "platform/linux/file_utilities_linux.h"
|
||||||
|
|
||||||
|
#include "kotato/kotato_lang.h"
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
#include "platform/linux/linux_xdp_file_dialog.h"
|
#include "platform/linux/linux_xdp_file_dialog.h"
|
||||||
#include "platform/linux/linux_xdp_open_with_dialog.h"
|
#include "platform/linux/linux_xdp_open_with_dialog.h"
|
||||||
|
|
@ -83,6 +85,23 @@ void UnsafeLaunch(const QString &filepath) {
|
||||||
|
|
||||||
namespace FileDialog {
|
namespace FileDialog {
|
||||||
|
|
||||||
|
QString ImplementationTypeLabel(ImplementationType value) {
|
||||||
|
switch (value) {
|
||||||
|
case ImplementationType::XDP: return qsl("XDG Desktop Portal");
|
||||||
|
case ImplementationType::Qt: return qsl("Qt");
|
||||||
|
}
|
||||||
|
Unexpected("Value in Platform::FileDialog::ImplementationTypeLabel.");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ImplementationTypeDescription(ImplementationType value) {
|
||||||
|
switch (value) {
|
||||||
|
#ifdef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
case ImplementationType::XDP: return ktr("ktg_file_dialog_disabled_on_build");
|
||||||
|
#endif // DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||||
|
}
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
bool Get(
|
bool Get(
|
||||||
QPointer<QWidget> parent,
|
QPointer<QWidget> parent,
|
||||||
QStringList &files,
|
QStringList &files,
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,13 @@ inline void PostprocessDownloaded(const QString &filepath) {
|
||||||
|
|
||||||
namespace FileDialog {
|
namespace FileDialog {
|
||||||
|
|
||||||
|
enum class ImplementationType {
|
||||||
|
Default,
|
||||||
|
XDP,
|
||||||
|
Qt,
|
||||||
|
Count,
|
||||||
|
};
|
||||||
|
|
||||||
inline void InitLastPath() {
|
inline void InitLastPath() {
|
||||||
::FileDialog::internal::InitLastPathDefault();
|
::FileDialog::internal::InitLastPathDefault();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "platform/linux/linux_xdp_file_dialog.h"
|
#include "platform/linux/linux_xdp_file_dialog.h"
|
||||||
|
|
||||||
|
#include "kotato/kotato_settings.h"
|
||||||
#include "platform/platform_file_utilities.h"
|
#include "platform/platform_file_utilities.h"
|
||||||
#include "base/platform/base_platform_info.h"
|
#include "base/platform/base_platform_info.h"
|
||||||
#include "base/platform/linux/base_linux_glibmm_helper.h"
|
#include "base/platform/linux/base_linux_glibmm_helper.h"
|
||||||
|
|
@ -684,7 +685,9 @@ std::optional<bool> Get(
|
||||||
const QString &filter,
|
const QString &filter,
|
||||||
Type type,
|
Type type,
|
||||||
QString startFile) {
|
QString startFile) {
|
||||||
if (!FileChooserPortalVersion.has_value()
|
const auto fileDialogType = ImplementationType(::Kotato::JsonSettings::GetInt("file_dialog_type"));
|
||||||
|
if (fileDialogType > ImplementationType::XDP
|
||||||
|
|| !FileChooserPortalVersion.has_value()
|
||||||
|| (type == Type::ReadFolder && *FileChooserPortalVersion < 3)) {
|
|| (type == Type::ReadFolder && *FileChooserPortalVersion < 3)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,19 @@ inline void PostprocessDownloaded(const QString &filepath) {
|
||||||
|
|
||||||
namespace FileDialog {
|
namespace FileDialog {
|
||||||
|
|
||||||
|
enum class ImplementationType {
|
||||||
|
Default,
|
||||||
|
Count,
|
||||||
|
};
|
||||||
|
|
||||||
|
inline QString ImplementationTypeLabel(ImplementationType value) {
|
||||||
|
Unexpected("Value in Platform::FileDialog::ImplementationTypeLabel.");
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QString ImplementationTypeDescription(ImplementationType value) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
inline void InitLastPath() {
|
inline void InitLastPath() {
|
||||||
::FileDialog::internal::InitLastPathDefault();
|
::FileDialog::internal::InitLastPathDefault();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,11 @@ void PostprocessDownloaded(const QString &filepath);
|
||||||
|
|
||||||
namespace FileDialog {
|
namespace FileDialog {
|
||||||
|
|
||||||
|
enum class ImplementationType;
|
||||||
|
|
||||||
|
QString ImplementationTypeLabel(ImplementationType value);
|
||||||
|
QString ImplementationTypeDescription(ImplementationType value);
|
||||||
|
|
||||||
void InitLastPath();
|
void InitLastPath();
|
||||||
|
|
||||||
bool Get(
|
bool Get(
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,21 @@ inline void UnsafeOpenUrl(const QString &url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace File
|
} // namespace File
|
||||||
|
|
||||||
|
namespace FileDialog {
|
||||||
|
|
||||||
|
enum class ImplementationType {
|
||||||
|
Default,
|
||||||
|
Count,
|
||||||
|
};
|
||||||
|
|
||||||
|
inline QString ImplementationTypeLabel(ImplementationType value) {
|
||||||
|
Unexpected("Value in Platform::FileDialog::ImplementationTypeLabel.");
|
||||||
|
}
|
||||||
|
|
||||||
|
inline QString ImplementationTypeDescription(ImplementationType value) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace FileDialog
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue