Ejemplo n.º 1
0
static void
g_application_real_activate (GApplication *application)
{
  if (!g_signal_has_handler_pending (application,
                                     g_application_signals[SIGNAL_ACTIVATE],
                                     0, TRUE) &&
      G_APPLICATION_GET_CLASS (application)->activate == g_application_real_activate)
    {
      static gboolean warned;

      if (warned)
        return;

      g_warning ("Your application does not implement "
                 "g_application_activate() and has no handlers connected "
                 "to the 'activate' signal.  It should do one of these.");
      warned = TRUE;
    }
}
Ejemplo n.º 2
0
static void
g_application_real_open (GApplication  *application,
                         GFile        **files,
                         gint           n_files,
                         const gchar   *hint)
{
  if (!g_signal_has_handler_pending (application,
                                     g_application_signals[SIGNAL_OPEN],
                                     0, TRUE) &&
      G_APPLICATION_GET_CLASS (application)->open == g_application_real_open)
    {
      static gboolean warned;

      if (warned)
        return;

      g_warning ("Your application claims to support opening files "
                 "but does not implement g_application_open() and has no "
                 "handlers connected to the 'open' signal.");
      warned = TRUE;
    }
}
Ejemplo n.º 3
0
static int
g_application_real_command_line (GApplication            *application,
                                 GApplicationCommandLine *cmdline)
{
  if (!g_signal_has_handler_pending (application,
                                     g_application_signals[SIGNAL_COMMAND_LINE],
                                     0, TRUE) &&
      G_APPLICATION_GET_CLASS (application)->command_line == g_application_real_command_line)
    {
      static gboolean warned;

      if (warned)
        return 1;

      g_warning ("Your application claims to support custom command line "
                 "handling but does not implement g_application_command_line() "
                 "and has no handlers connected to the 'command-line' signal.");

      warned = TRUE;
    }

    return 1;
}
Ejemplo n.º 4
0
gint
main (gint argc, gchar *argv[])
{
    gtk_init (&argc, &argv);
    g_object_set (gtk_settings_get_default (), "gtk-application-prefer-dark-theme", TRUE, NULL);

    gsize size = DEFAULT_SIZE;
    guint32 target = DEFAULT_TARGET;
    const gchar *theme = DEFAULT_THEME;

    GOptionEntry options[] = {
        { "size",   's',  0, G_OPTION_ARG_INT,    &size,   "The size of the grid", "4"           },
        { "target", '\0', 0, G_OPTION_ARG_INT,    &target, "The tile to reach",    "2048"        },
        { "theme",  't',  0, G_OPTION_ARG_STRING, &theme,  "The theme to use",     DEFAULT_THEME },
        { NULL,     '\0', 0, G_OPTION_ARG_NONE,   NULL,    NULL,                   NULL          }
    };
    G_2048_CLEANUP_OPTIONS_FREE GOptionContext *ctx = g_option_context_new ("foobar");
    g_option_context_add_main_entries (ctx, options, NULL);
    g_option_context_add_group (ctx, gtk_get_option_group (TRUE));
    g_option_context_parse (ctx, &argc, &argv, NULL);

    GtkApplication *app = gtk_application_new ("org.gnome.g2048", G_APPLICATION_FLAGS_NONE);
    GApplication *gapp = G_APPLICATION (app);
    G_2048_CLEANUP_ERROR_FREE GError *error = NULL;
    G_APPLICATION_GET_CLASS (gapp)->activate = show_win;

    g_application_register (gapp, NULL, &error);
    if (error)
    {
        fprintf (stderr, "Failed to register the gtk application: %s\n", error->message);
        return EXIT_FAILURE;
    }
    if (g_application_get_is_remote (gapp))
    {
        g_application_activate (gapp);
        return EXIT_SUCCESS;
    }

    G_2048_CLEANUP_FREE gchar *theme_path = get_theme_path (theme);
    if (!theme_path)
        theme_path = get_theme_path (DEFAULT_THEME);
    if (!theme_path)
    {
        g_critical ("No theme found");
        exit (EXIT_FAILURE);
    }

    GtkWidget *score_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
    GtkBox *hbox = GTK_BOX (score_box);
    gtk_box_pack_start (hbox, gtk_label_new ("Score:"), TRUE, TRUE, 0);

    GtkWidget *score_label = gtk_label_new ("0");
    GtkLabel *label = GTK_LABEL (score_label);
    GdkRGBA color;
    gdk_rgba_parse (&color, "white");
    gtk_widget_override_background_color (score_label, GTK_STATE_FLAG_NORMAL, &color);
    gdk_rgba_parse (&color, "black");
    gtk_widget_override_color (score_label, GTK_STATE_FLAG_NORMAL, &color);
    gtk_label_set_width_chars (GTK_LABEL (score_label), 8);
    gtk_box_pack_end (hbox, score_label, TRUE, FALSE, 0);

    GtkWidget *box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
    GtkBox *vbox = GTK_BOX (box);
    gtk_box_pack_start (vbox, g_2048_grid_new (size, target, theme_path, label), TRUE, TRUE, 0);
    gtk_box_pack_end (vbox, score_box, TRUE, TRUE, 20);

    GtkWidget *win = gtk_widget_new (GTK_TYPE_APPLICATION_WINDOW,
                                     "application",     app,
                                     "type",            GTK_WINDOW_TOPLEVEL,
                                     "window-position", GTK_WIN_POS_CENTER,
                                     "resizable",       FALSE,
                                     NULL);
    gtk_container_add (GTK_CONTAINER (win), box);
    gtk_widget_show_all (win);
    gtk_widget_override_font (win, pango_font_description_from_string("Monospace 18"));
    GTK_WIDGET_GET_CLASS (win)->key_press_event = on_key;

    return g_application_run (gapp, argc, argv);
}