Blame theme-viewer/theme-viewer-main.c

Packit 5e0819
/*
Packit 5e0819
 * Copyright (C) 2016 Alberts Muktupāvels
Packit 5e0819
 *
Packit 5e0819
 * This program is free software: you can redistribute it and/or modify
Packit 5e0819
 * it under the terms of the GNU General Public License as published by
Packit 5e0819
 * the Free Software Foundation, either version 2 of the License, or
Packit 5e0819
 * (at your option) any later version.
Packit 5e0819
 *
Packit 5e0819
 * This program is distributed in the hope that it will be useful,
Packit 5e0819
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 5e0819
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Packit 5e0819
 * GNU General Public License for more details.
Packit 5e0819
 *
Packit 5e0819
 * You should have received a copy of the GNU General Public License
Packit 5e0819
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Packit 5e0819
 */
Packit 5e0819
Packit 5e0819
#include "config.h"
Packit 5e0819
Packit 5e0819
#include <glib/gi18n.h>
Packit 5e0819
#include <stdlib.h>
Packit 5e0819
Packit 5e0819
#include "theme-viewer-window.h"
Packit 5e0819
Packit 5e0819
static gchar *theme_type = NULL;
Packit 5e0819
static gchar *theme_name = NULL;
Packit 5e0819
Packit 5e0819
static GOptionEntry entries[] =
Packit 5e0819
{
Packit 5e0819
  {
Packit 5e0819
    "theme-type", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &theme_type,
Packit 5e0819
    N_("Theme type to use (\"gtk\" or \"metacity\")"), N_("TYPE")
Packit 5e0819
  },
Packit 5e0819
  {
Packit 5e0819
    "theme-name", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &theme_name,
Packit 5e0819
    N_("Theme name to use"), N_("NAME")
Packit 5e0819
  },
Packit 5e0819
  {
Packit 5e0819
    NULL
Packit 5e0819
  }
Packit 5e0819
};
Packit 5e0819
Packit 5e0819
static gboolean
Packit 5e0819
parse_arguments (gint    *argc,
Packit 5e0819
                 gchar ***argv)
Packit 5e0819
{
Packit 5e0819
  GOptionContext *context;
Packit 5e0819
  GOptionGroup *gtk_group;
Packit 5e0819
  GError *error;
Packit 5e0819
Packit 5e0819
  context = g_option_context_new (NULL);
Packit 5e0819
  gtk_group = gtk_get_option_group (FALSE);
Packit 5e0819
Packit 5e0819
  g_option_context_add_main_entries (context, entries, NULL);
Packit 5e0819
  g_option_context_add_group (context, gtk_group);
Packit 5e0819
Packit 5e0819
  error = NULL;
Packit 5e0819
  if (g_option_context_parse (context, argc, argv, &error) == FALSE)
Packit 5e0819
    {
Packit 5e0819
      g_warning ("Failed to parse command line arguments: %s", error->message);
Packit 5e0819
      g_error_free (error);
Packit 5e0819
Packit 5e0819
      g_option_context_free (context);
Packit 5e0819
Packit 5e0819
      g_clear_pointer (&theme_type, g_free);
Packit 5e0819
      g_clear_pointer (&theme_name, g_free);
Packit 5e0819
Packit 5e0819
      return FALSE;
Packit 5e0819
    }
Packit 5e0819
Packit 5e0819
  g_option_context_free (context);
Packit 5e0819
Packit 5e0819
  return TRUE;
Packit 5e0819
}
Packit 5e0819
Packit 5e0819
static void
Packit 5e0819
destroy_cb (GtkWidget *widget)
Packit 5e0819
{
Packit 5e0819
  gtk_main_quit ();
Packit 5e0819
}
Packit 5e0819
Packit 5e0819
int
Packit 5e0819
main (int argc, char **argv)
Packit 5e0819
{
Packit 5e0819
  GtkWidget *window;
Packit 5e0819
Packit 5e0819
  bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
Packit 5e0819
  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
Packit 5e0819
  textdomain(GETTEXT_PACKAGE);
Packit 5e0819
Packit 5e0819
  gtk_init (&argc, &argv);
Packit 5e0819
Packit 5e0819
  if (!parse_arguments (&argc, &argv))
Packit 5e0819
    return EXIT_FAILURE;
Packit 5e0819
Packit 5e0819
  window = theme_viewer_window_new ();
Packit 5e0819
Packit 5e0819
  if (theme_type != NULL)
Packit 5e0819
    {
Packit 5e0819
      MetaThemeType type;
Packit 5e0819
Packit 5e0819
      type = META_THEME_TYPE_GTK;
Packit 5e0819
      if (g_strcmp0 (theme_type, "metacity") == 0)
Packit 5e0819
        type = META_THEME_TYPE_METACITY;
Packit 5e0819
Packit 5e0819
      theme_viewer_window_set_theme_type (THEME_VIEWER_WINDOW (window), type);
Packit 5e0819
    }
Packit 5e0819
Packit 5e0819
  if (theme_name != NULL)
Packit 5e0819
    {
Packit 5e0819
      theme_viewer_window_set_theme_name (THEME_VIEWER_WINDOW (window),
Packit 5e0819
                                          theme_name);
Packit 5e0819
    }
Packit 5e0819
Packit 5e0819
  g_signal_connect (window, "destroy", G_CALLBACK (destroy_cb), NULL);
Packit 5e0819
  gtk_window_present (GTK_WINDOW (window));
Packit 5e0819
Packit 5e0819
  gtk_main ();
Packit 5e0819
Packit 5e0819
  g_clear_pointer (&theme_type, g_free);
Packit 5e0819
  g_clear_pointer (&theme_name, g_free);
Packit 5e0819
Packit 5e0819
  return 0;
Packit 5e0819
}