[metacity] theme-viewer: add two command-line options
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [metacity] theme-viewer: add two command-line options
- Date: Mon, 28 Nov 2016 17:09:43 +0000 (UTC)
commit 03c8dbe789b587dd6a9c6fa6279c4204748be09b
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Mon Nov 28 19:06:24 2016 +0200
theme-viewer: add two command-line options
theme-viewer/theme-viewer-main.c | 77 +++++++++++++++++++++++++++++++++++-
theme-viewer/theme-viewer-window.c | 16 +++++++-
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 08b55f8..1761cda 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 70f30da..bbf10b3 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 0912b44..e002fdf 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]