[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_settings_system": "System",
|
||||
"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_profile_copy_id": "Copy 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) {
|
||||
return [=] (QVariant value) -> QVariant {
|
||||
|
|
@ -376,6 +393,10 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
|
|||
.type = SettingType::BoolSetting,
|
||||
.defaultValue = false, }},
|
||||
#endif
|
||||
{ "file_dialog_type", {
|
||||
.type = SettingType::IntSetting,
|
||||
.defaultValue = int(Platform::FileDialog::ImplementationType::Default),
|
||||
.limitHandler = FileDialogLimit(), }},
|
||||
};
|
||||
|
||||
using OldOptionKey = QString;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,20 @@ namespace Settings {
|
|||
|
||||
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) {
|
||||
switch (boost) {
|
||||
|
|
@ -417,6 +431,36 @@ void SetupKotatoSystem(
|
|||
}, container->lifetime());
|
||||
#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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "platform/linux/file_utilities_linux.h"
|
||||
|
||||
#include "kotato/kotato_lang.h"
|
||||
|
||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
#include "platform/linux/linux_xdp_file_dialog.h"
|
||||
#include "platform/linux/linux_xdp_open_with_dialog.h"
|
||||
|
|
@ -83,6 +85,23 @@ void UnsafeLaunch(const QString &filepath) {
|
|||
|
||||
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(
|
||||
QPointer<QWidget> parent,
|
||||
QStringList &files,
|
||||
|
|
|
|||
|
|
@ -27,6 +27,13 @@ inline void PostprocessDownloaded(const QString &filepath) {
|
|||
|
||||
namespace FileDialog {
|
||||
|
||||
enum class ImplementationType {
|
||||
Default,
|
||||
XDP,
|
||||
Qt,
|
||||
Count,
|
||||
};
|
||||
|
||||
inline void InitLastPath() {
|
||||
::FileDialog::internal::InitLastPathDefault();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "platform/linux/linux_xdp_file_dialog.h"
|
||||
|
||||
#include "kotato/kotato_settings.h"
|
||||
#include "platform/platform_file_utilities.h"
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "base/platform/linux/base_linux_glibmm_helper.h"
|
||||
|
|
@ -684,7 +685,9 @@ std::optional<bool> Get(
|
|||
const QString &filter,
|
||||
Type type,
|
||||
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)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,19 @@ inline void PostprocessDownloaded(const QString &filepath) {
|
|||
|
||||
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() {
|
||||
::FileDialog::internal::InitLastPathDefault();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,11 @@ void PostprocessDownloaded(const QString &filepath);
|
|||
|
||||
namespace FileDialog {
|
||||
|
||||
enum class ImplementationType;
|
||||
|
||||
QString ImplementationTypeLabel(ImplementationType value);
|
||||
QString ImplementationTypeDescription(ImplementationType value);
|
||||
|
||||
void InitLastPath();
|
||||
|
||||
bool Get(
|
||||
|
|
|
|||
|
|
@ -21,4 +21,21 @@ inline void UnsafeOpenUrl(const QString &url) {
|
|||
}
|
||||
|
||||
} // 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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue