summaryrefslogtreecommitdiffstats
path: root/plug-ins/help-browser/gimpthrobberaction.c
blob: 56f617f859432bd2e7f37bf882fc3b9c9f37a3a6 (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
125
126
127
128
129
130
131
132
133
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * GimpThrobberAction
 * Copyright (C) 2005  Sven Neumann <sven@gimp.org>
 *
 * 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 3 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 <https://www.gnu.org/licenses/>.
 */

#include "config.h"

#include <gtk/gtk.h>

#include "gimpthrobberaction.h"
#include "gimpthrobber.h"



static void gimp_throbber_action_class_init    (GimpThrobberActionClass *klass);

static void gimp_throbber_action_connect_proxy (GtkAction  *action,
                                                GtkWidget  *proxy);
static void gimp_throbber_action_sync_property (GtkAction  *action,
                                                GParamSpec *pspec,
                                                GtkWidget  *proxy);


static GtkActionClass *parent_class = NULL;


GType
gimp_throbber_action_get_type (void)
{
  static GType type = 0;

  if (!type)
    {
      static const GTypeInfo type_info =
      {
        sizeof (GtkActionClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) gimp_throbber_action_class_init,
        (GClassFinalizeFunc) NULL,
        NULL,
        sizeof (GtkAction),
        0, /* n_preallocs */
        (GInstanceInitFunc) NULL
      };

      type = g_type_register_static (GTK_TYPE_ACTION,
                                     "GimpThrobberAction",
                                     &type_info, 0);
    }

  return type;
}

static void
gimp_throbber_action_class_init (GimpThrobberActionClass *klass)
{
  GtkActionClass *action_class = GTK_ACTION_CLASS (klass);

  parent_class = g_type_class_peek_parent (klass);

  action_class->connect_proxy     = gimp_throbber_action_connect_proxy;
  action_class->toolbar_item_type = GIMP_TYPE_THROBBER;
}

static void
gimp_throbber_action_connect_proxy (GtkAction *action,
                                    GtkWidget *proxy)
{

  GTK_ACTION_CLASS (parent_class)->connect_proxy (action, proxy);

  if (GIMP_IS_THROBBER (proxy))
    {
      GParamSpec *pspec;

      pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (action),
                                            "icon-name");

      gimp_throbber_action_sync_property (action, pspec, proxy);
      g_signal_connect_object (action, "notify::icon-name",
                               G_CALLBACK (gimp_throbber_action_sync_property),
                               proxy, 0);

      g_signal_connect_object (proxy, "clicked",
                               G_CALLBACK (gtk_action_activate), action,
                               G_CONNECT_SWAPPED);
    }
}

static void
gimp_throbber_action_sync_property (GtkAction  *action,
                                    GParamSpec *pspec,
                                    GtkWidget  *proxy)
{
  const gchar *property = g_param_spec_get_name (pspec);
  GValue       value    = G_VALUE_INIT;

  g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
  g_object_get_property (G_OBJECT (action), property, &value);

  g_object_set_property (G_OBJECT (proxy), property, &value);
  g_value_unset (&value);
}

GtkAction *
gimp_throbber_action_new (const gchar *name,
                          const gchar *label,
                          const gchar *tooltip,
                          const gchar *icon_name)
{
  return g_object_new (GIMP_TYPE_THROBBER_ACTION,
                       "name",      name,
                       "label",     label,
                       "tooltip",   tooltip,
                       "icon-name", icon_name,
                       NULL);
}