Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added kdialog arguments, bumped to version 4.3.1 #935

Merged
merged 1 commit into from
Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.3.1

#### Desktop (Linux)
Adds KDE Plasma's `kdialog` arguments, allowing `filepicker` to invoke `kdialog` for file system manipulation using shell scripts on distributions that use KDE Plasma as their Desktop Environment and don't ship `zenity` or `qarma`.

## 4.3.0

##### Desktop (Windows)
Expand Down
100 changes: 79 additions & 21 deletions lib/src/file_picker_linux.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ class FilePickerLinux extends FilePicker {
type,
allowedExtensions,
);
final List<String> arguments = generateCommandLineArguments(
dialogTitle ?? defaultDialogTitle,
fileFilter: fileFilter,
multipleFiles: allowMultiple,
pickDirectory: false,
);

final List<String> arguments = (executable.contains('kdialog'))
? generateKdialogArguments(
dialogTitle ?? defaultDialogTitle,
fileFilter: fileFilter,
multipleFiles: allowMultiple,
pickDirectory: false,
)
: generateCommandLineArguments(
dialogTitle ?? defaultDialogTitle,
fileFilter: fileFilter,
multipleFiles: allowMultiple,
pickDirectory: false,
);

final String? fileSelectionResult = await runExecutableWithArguments(
executable,
Expand Down Expand Up @@ -55,10 +63,15 @@ class FilePickerLinux extends FilePicker {
bool lockParentWindow = false,
}) async {
final executable = await _getPathToExecutable();
final arguments = generateCommandLineArguments(
dialogTitle ?? defaultDialogTitle,
pickDirectory: true,
);
final List<String> arguments = (executable.contains('kdialog'))
? generateKdialogArguments(
dialogTitle ?? defaultDialogTitle,
pickDirectory: true,
)
: generateCommandLineArguments(
dialogTitle ?? defaultDialogTitle,
pickDirectory: true,
);
return await runExecutableWithArguments(executable, arguments);
}

Expand All @@ -75,25 +88,38 @@ class FilePickerLinux extends FilePicker {
type,
allowedExtensions,
);
final arguments = generateCommandLineArguments(
dialogTitle ?? defaultDialogTitle,
fileFilter: fileFilter,
fileName: fileName ?? '',
saveFile: true,
);
final List<String> arguments = (executable.contains('kdialog'))
? generateKdialogArguments(
dialogTitle ?? defaultDialogTitle,
fileFilter: fileFilter,
fileName: fileName ?? '',
saveFile: true,
)
: generateCommandLineArguments(
dialogTitle ?? defaultDialogTitle,
fileFilter: fileFilter,
fileName: fileName ?? '',
saveFile: true,
);
return await runExecutableWithArguments(executable, arguments);
}

/// Returns the path to the executables `qarma` or `zenity` as a [String].
///
/// Returns the path to the executables `qarma`, `zenity` or `kdialog` as a
/// [String].
/// On Linux, the CLI tools `qarma` or `zenity` can be used to open a native
/// file picker dialog. It seems as if all Linux distributions have at least
/// one of these two tools pre-installed (on Ubuntu `zenity` is pre-installed).
/// The future returns an error, if neither of both executables was found on
/// On distribuitions that use KDE Plasma as their Desktop Environment,
/// `kdialog` is used to achieve these functionalities.
/// The future returns an error, if none of the executables was found on
/// the path.
Future<String> _getPathToExecutable() async {
try {
return await isExecutableOnPath('qarma');
try {
return await isExecutableOnPath('qarma');
} on Exception {
return await isExecutableOnPath('kdialog');
}
} on Exception {
return await isExecutableOnPath('zenity');
}
Expand Down Expand Up @@ -150,7 +176,39 @@ class FilePickerLinux extends FilePicker {
return arguments;
}

/// Transforms the result string (stdout) of `qarma` / `zenity` into a [List]
List<String> generateKdialogArguments(
String dialogTitle, {
String fileFilter = '',
String fileName = '',
bool multipleFiles = false,
bool pickDirectory = false,
bool saveFile = false,
}) {
final arguments = ['--title', dialogTitle];

if (saveFile) {
arguments.add('--getsavefilename');
if (fileName.isNotEmpty) {
arguments.add(fileName);
}
}

if (fileFilter.isNotEmpty) {
arguments.add(fileFilter);
}

if (multipleFiles) {
arguments.add('--multiple');
}

if (pickDirectory) {
arguments.add('--getexistingdirectory');
}

return arguments;
}

/// Transforms the result string (stdout) of `qarma`, `zenity` or `kdialog` into a [List]
/// of file paths.
List<String> resultStringToFilePaths(String fileSelectionResult) {
if (fileSelectionResult.trim().isEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
repository: https://github.com/miguelpruivo/flutter_file_picker
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
version: 4.3.0
version: 4.3.1

dependencies:
flutter:
Expand Down