diff options
author | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2016-11-28 19:06:24 +0200 |
---|---|---|
committer | Alberts Muktupāvels <alberts.muktupavels@gmail.com> | 2016-11-28 19:06:24 +0200 |
commit | 03c8dbe789b587dd6a9c6fa6279c4204748be09b (patch) | |
tree | 06047dc3ee58a41949dbcab5a8838f8b17c9450f | |
parent | c54fa264dbbf4cf4df45e049778a95bc609f49b8 (diff) | |
download | metacity-03c8dbe789b587dd6a9c6fa6279c4204748be09b.tar.gz |
theme-viewer: add two command-line options
-rw-r--r-- | theme-viewer/theme-viewer-main.c | 77 | ||||
-rw-r--r-- | theme-viewer/theme-viewer-window.c | 16 | ||||
-rw-r--r-- | theme-viewer/theme-viewer-window.h | 9 |
3 files changed, 99 insertions, 3 deletions
diff --git a/theme-viewer/theme-viewer-main.c b/theme-viewer/theme-viewer-main.c index 08b55f84..1761cda4 100644 --- a/theme-viewer/theme-viewer-main.c +++ b/theme-viewer/theme-viewer-main.c @@ -18,9 +18,61 @@ #include "config.h" #include <glib/gi18n.h> +#include <stdlib.h> #include "theme-viewer-window.h" +static gchar *theme_type = NULL; +static gchar *theme_name = NULL; + +static GOptionEntry entries[] = +{ + { + "theme-type", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &theme_type, + N_("Theme type to use (gtk or metacity)"), N_("TYPE") + }, + { + "theme-name", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &theme_name, + N_("Theme name to use"), N_("NAME") + }, + { + NULL + } +}; + +static gboolean +parse_arguments (gint *argc, + gchar ***argv) +{ + GOptionContext *context; + GOptionGroup *gtk_group; + GError *error; + + context = g_option_context_new (NULL); + gtk_group = gtk_get_option_group (FALSE); + + g_option_context_add_main_entries (context, entries, NULL); + g_option_context_add_group (context, gtk_group); + + error = NULL; + if (g_option_context_parse (context, argc, argv, &error) == FALSE) + { + g_warning ("Failed to parse command line arguments: %s", error->message); + g_error_free (error); + + g_option_context_free (context); + + g_clear_pointer (&theme_type, g_free); + g_clear_pointer (&theme_name, g_free); + + return FALSE; + } + + g_option_context_free (context); + + return TRUE; +} + static void destroy_cb (GtkWidget *widget) { @@ -38,12 +90,35 @@ main (int argc, char **argv) gtk_init (&argc, &argv); + if (!parse_arguments (&argc, &argv)) + return EXIT_FAILURE; + window = theme_viewer_window_new (); - gtk_window_present (GTK_WINDOW (window)); + + if (theme_type != NULL) + { + MetaThemeType type; + + type = META_THEME_TYPE_GTK; + if (g_strcmp0 (theme_type, "metacity") == 0) + type = META_THEME_TYPE_METACITY; + + theme_viewer_window_set_theme_type (THEME_VIEWER_WINDOW (window), type); + } + + if (theme_name != NULL) + { + theme_viewer_window_set_theme_name (THEME_VIEWER_WINDOW (window), + theme_name); + } g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL); + gtk_window_present (GTK_WINDOW (window)); gtk_main (); + g_clear_pointer (&theme_type, g_free); + g_clear_pointer (&theme_name, g_free); + return 0; } diff --git a/theme-viewer/theme-viewer-window.c b/theme-viewer/theme-viewer-window.c index 70f30da0..bbf10b33 100644 --- a/theme-viewer/theme-viewer-window.c +++ b/theme-viewer/theme-viewer-window.c @@ -18,7 +18,6 @@ #include "config.h" #include <glib/gi18n.h> -#include <libmetacity/meta-theme.h> #include <time.h> #include "theme-viewer-window.h" @@ -931,3 +930,18 @@ theme_viewer_window_new (void) "title", _("Metacity Theme Viewer"), NULL); } + +void +theme_viewer_window_set_theme_type (ThemeViewerWindow *window, + MetaThemeType theme_type) +{ + gtk_combo_box_set_active (GTK_COMBO_BOX (window->type_combo_box), theme_type); +} + +void +theme_viewer_window_set_theme_name (ThemeViewerWindow *window, + const gchar *theme_name) +{ + gtk_combo_box_set_active_id (GTK_COMBO_BOX (window->theme_combo_box), + theme_name); +} diff --git a/theme-viewer/theme-viewer-window.h b/theme-viewer/theme-viewer-window.h index 0912b441..e002fdf1 100644 --- a/theme-viewer/theme-viewer-window.h +++ b/theme-viewer/theme-viewer-window.h @@ -19,6 +19,7 @@ #define THEME_VIEWER_WINDOW_H #include <gtk/gtk.h> +#include <libmetacity/meta-theme.h> G_BEGIN_DECLS @@ -26,7 +27,13 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (ThemeViewerWindow, theme_viewer_window, THEME_VIEWER, WINDOW, GtkWindow) -GtkWidget *theme_viewer_window_new (void); +GtkWidget *theme_viewer_window_new (void); + +void theme_viewer_window_set_theme_type (ThemeViewerWindow *window, + MetaThemeType theme_type); + +void theme_viewer_window_set_theme_name (ThemeViewerWindow *window, + const gchar *theme_name); G_END_DECLS |