aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorStephan Sokolow <http://www.ssokolow.com/ContactMe>2019-10-24 20:36:42 -0400
committerRobin Krahl <robin.krahl@ireas.org>2019-10-25 22:32:45 +0200
commita23de9787bccde4b6244312f04cb7cfc3b528db6 (patch)
tree06bee04d6b347ffec53493fcf8c9bbfc6c7eb93c /src/lib.rs
parent10462c2c9f4ae2ffd3c32dd4628e0052067c15fa (diff)
downloaddialog-rs-a23de9787bccde4b6244312f04cb7cfc3b528db6.tar.gz
dialog-rs-a23de9787bccde4b6244312f04cb7cfc3b528db6.tar.bz2
Add a backend based on KDE's `kdialog`
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f4ac763..61be22b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,6 +15,8 @@
//! These dialog boxes can be displayed using various backends:
//! - [`Dialog`][]: uses `dialog` to display ncurses-based dialog boxes (requires the external
//! `dialog` tool)
+//! - [`KDialog`][]: uses `kdialog` to display Qt-based dialog boxes (requires the external
+//! `kdialog` tool)
//! - [`Stdio`][]: prints messages to the standard output and reads user input form standard input
//! (intended as a fallback backend)
//! - [`Zenity`][]: uses `zenity` to display GTK-based dialog boxes (requires the external `zenity`
@@ -72,6 +74,7 @@
//! [`Message`]: struct.Message.html
//! [`Password`]: struct.Password.html
//! [`Question`]: struct.Question.html
+//! [`KDialog`]: backends/struct.KDialog.html
//! [`Stdio`]: backends/struct.Stdio.html
//! [`Zenity`]: backends/struct.Zenity.html
//! [`default_backend`]: fn.default_backend.html
@@ -345,13 +348,16 @@ impl DialogBox for Question {
/// - If the `DIALOG` environment variable is set to a valid backend name, this backend is used.
/// A valid backend name is the name of a struct in the `backends` module implementing the
/// `Backend` trait in any case.
-/// - If the `DISPLAY` environment variable is set, the first available backend from this list is
-/// used:
-/// - [`Zenity`][]
+/// - If the `DISPLAY` environment variable is set, the following resolution algorithm is used:
+/// - If the `XDG_CURRENT_DESKTOP` environment variable is set to `KDE`, [`KDialog`][] is used.
+/// - Otherwise, the first available backend from this list is used:
+/// - [`Zenity`][]
+/// - [`KDialog`][]
/// - If the [`Dialog`][] backend is available, it is used.
/// - Otherwise, a [`Stdio`][] instance is returned.
///
/// [`Dialog`]: backends/struct.Dialog.html
+/// [`KDialog`]: backends/struct.KDialog.html
/// [`Stdio`]: backends/struct.Stdio.html
/// [`Zenity`]: backends/struct.Zenity.html
pub fn default_backend() -> Box<dyn backends::Backend> {
@@ -363,9 +369,21 @@ pub fn default_backend() -> Box<dyn backends::Backend> {
if let Ok(display) = env::var("DISPLAY") {
if !display.is_empty() {
+ // Prefer KDialog if the user is logged into a KDE session
+ let kdialog_available = backends::KDialog::is_available();
+ if let Ok(desktop) = env::var("XDG_CURRENT_DESKTOP") {
+ if kdialog_available && desktop == "KDE" {
+ return Box::new(backends::KDialog::new());
+ }
+ }
+
if backends::Zenity::is_available() {
return Box::new(backends::Zenity::new());
}
+
+ if kdialog_available {
+ return Box::new(backends::KDialog::new());
+ }
}
}