[shotwell: 3/3] Add --list-profiles option



commit 38fc2d6caf8038cd96b0f349ceac431f67a942c3
Author: Jens Georg <mail jensge org>
Date:   Sun Jun 16 13:39:15 2019 +0200

    Add --list-profiles option

 src/Profiles.vala | 20 ++++++++++++++++++++
 src/main.vala     | 11 +++++++++++
 2 files changed, 31 insertions(+)
---
diff --git a/src/Profiles.vala b/src/Profiles.vala
index af2fab26..9077b9af 100644
--- a/src/Profiles.vala
+++ b/src/Profiles.vala
@@ -95,5 +95,25 @@ namespace Shotwell {
                 assert_not_reached();
             }
         }
+
+        public void print_profiles() {
+            print("Available profiles:\n");
+            print("-------------------\n");
+            try {
+                foreach (var group in profiles.get_groups()) {
+                    print("Profile name: %s\n", profiles.get_value(group, "Name"));
+                    var id = profiles.get_value(group, "Id");
+                    print("Profile Id: %s\n", id);
+                    if ("DataDir" in profiles.get_keys(group)) {
+                        print("Data dir: %s\n", profiles.get_value(group, "DataDir"));
+                    } else {
+                        print("Data dir: %s\n", Path.build_filename(Environment.get_user_data_dir(), 
"profiles", id));
+                    }
+                    print("\n");
+                }
+            } catch (Error error) {
+                print("Failed to print profiles: %s", error.message);
+            }
+        }
     }
 }
diff --git a/src/main.vala b/src/main.vala
index 6835df04..78611ca6 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -333,6 +333,7 @@ bool no_runtime_monitoring = false;
 bool fullscreen = false;
 bool show_metadata = false;
 string? profile = null;
+bool list_profiles = false;
 
 const OptionEntry[] entries = {
     { "datadir", 'd', 0, OptionArg.FILENAME, ref data_dir, N_("Path to Shotwell’s private data"), 
N_("DIRECTORY") },
@@ -342,6 +343,7 @@ const OptionEntry[] entries = {
     { "fullscreen", 'f', 0, OptionArg.NONE, ref fullscreen, N_("Start the application in fullscreen mode"), 
null },
     { "show-metadata", 'p', 0, OptionArg.NONE, ref show_metadata, N_("Print the metadata of the image 
file"), null },
     { "profile", 'i', 0, OptionArg.STRING, ref profile, N_("Name for a custom profile"), N_("PROFILE") },
+    { "list-profiles", 'l', 0, OptionArg.NONE, ref list_profiles, N_("Show available profiles"), null },
     { null, 0, 0, 0, null, null, null }
 };
 }
@@ -404,6 +406,15 @@ void main(string[] args) {
         return;
     }
 
+    if (CommandlineOptions.list_profiles) {
+        var manager  = Shotwell.ProfileManager.get_instance();
+        manager.print_profiles();
+
+        AppDirs.terminate();
+
+        return;
+    }
+
     // init debug prior to anything else (except Gtk, which it relies on, and AppDirs, which needs
     // to be set ASAP) ... since we need to know what mode we're in, examine the command-line
     // first


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]