summaryrefslogtreecommitdiff
path: root/theme-viewer/theme-viewer-main.c
blob: 4f184b8199274d3e39300ae44fb81695a154b72a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 * Copyright (C) 2016 Alberts Muktupāvels
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#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)
{
  gtk_main_quit ();
}

int
main (int argc, char **argv)
{
  GtkWidget *window;

  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
  textdomain(GETTEXT_PACKAGE);

  gtk_init (&argc, &argv);

  if (!parse_arguments (&argc, &argv))
    return EXIT_FAILURE;

  window = theme_viewer_window_new ();

  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;
}