~ubuntu-branches/ubuntu/quantal/epiphany-extensions/quantal

« back to all changes in this revision

Viewing changes to extensions/tab-groups/ephy-tab-grouper.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2011-04-14 19:04:24 UTC
  • mfrom: (1.1.43 upstream) (2.3.16 experimental)
  • Revision ID: james.westby@ubuntu.com-20110414190424-df2o8wz2pei97hbd
Tags: 3.0.0-2
debian/control.in: bump build-dep on epiphany.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright © 2003 Marco Pesenti Gritti
3
 
 *  Copyright © 2003, 2004 Christian Persch
4
 
 *  Copyright © 2004 Justin Wake
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2, or (at your option)
9
 
 *  any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 
 *
20
 
 *  $Id$
21
 
 */
22
 
 
23
 
#include "config.h"
24
 
 
25
 
#include "ephy-tab-grouper.h"
26
 
#include "ephy-debug.h"
27
 
 
28
 
#include <epiphany/epiphany.h>
29
 
 
30
 
#define EPHY_TAB_GROUPER_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_TAB_GROUPER, EphyTabGrouperPrivate))
31
 
 
32
 
struct _EphyTabGrouperPrivate
33
 
{
34
 
        GtkWidget *notebook;
35
 
        int last_pos;
36
 
};
37
 
 
38
 
static void ephy_tab_grouper_class_init (EphyTabGrouperClass *klass);
39
 
static void ephy_tab_grouper_init       (EphyTabGrouper *grouper);
40
 
 
41
 
enum
42
 
{
43
 
        PROP_0,
44
 
        PROP_NOTEBOOK
45
 
};
46
 
 
47
 
static GObjectClass *parent_class = NULL;
48
 
 
49
 
static GType type = 0;
50
 
 
51
 
GType
52
 
ephy_tab_grouper_get_type (void)
53
 
{
54
 
        return type;
55
 
}
56
 
 
57
 
GType
58
 
ephy_tab_grouper_register_type (GTypeModule *module)
59
 
{
60
 
        const GTypeInfo our_info =
61
 
        {
62
 
                sizeof (EphyTabGrouperClass),
63
 
                NULL, /* base_init */
64
 
                NULL, /* base_finalize */
65
 
                (GClassInitFunc) ephy_tab_grouper_class_init,
66
 
                NULL,
67
 
                NULL, /* class_data */
68
 
                sizeof (EphyTabGrouper),
69
 
                0, /* n_preallocs */
70
 
                (GInstanceInitFunc) ephy_tab_grouper_init
71
 
        };
72
 
 
73
 
        type = g_type_module_register_type (module,
74
 
                                            G_TYPE_OBJECT,
75
 
                                            "EphyTabGrouper",
76
 
                                            &our_info, 0);
77
 
        
78
 
        return type;
79
 
}
80
 
 
81
 
/**
82
 
 * Clear the recently opened tab spot.
83
 
 */
84
 
static void
85
 
reset_last_tab (EphyTabGrouper *grouper)
86
 
{
87
 
        EphyTabGrouperPrivate *priv = grouper->priv;
88
 
 
89
 
        priv->last_pos = -1;
90
 
}
91
 
 
92
 
static void
93
 
notebook_page_added_cb (GtkNotebook *notebook,
94
 
                        GtkWidget *tab,
95
 
                        guint page,
96
 
                        EphyTabGrouper *grouper)
97
 
{
98
 
        EphyTabGrouperPrivate *priv = grouper->priv;
99
 
        int position;
100
 
 
101
 
        /* Calculate the appropriate position for the tab */
102
 
        if (priv->last_pos != -1)
103
 
        {
104
 
                position = priv->last_pos + 1;
105
 
        }
106
 
        else
107
 
        {
108
 
                position = gtk_notebook_get_current_page (notebook) + 1;
109
 
        }
110
 
 
111
 
        gtk_notebook_reorder_child (notebook, tab, position);
112
 
 
113
 
        priv->last_pos = position;
114
 
}
115
 
 
116
 
static void
117
 
ephy_tab_grouper_set_notebook (EphyTabGrouper *grouper,
118
 
                               GtkWidget *notebook)
119
 
{
120
 
        EphyTabGrouperPrivate *priv = grouper->priv;
121
 
 
122
 
        g_return_if_fail (GTK_IS_NOTEBOOK (notebook));
123
 
 
124
 
        priv->notebook = notebook;
125
 
 
126
 
        /* Hook up the signals */
127
 
        g_signal_connect (notebook, "page-added",
128
 
                          G_CALLBACK (notebook_page_added_cb), grouper);
129
 
        g_signal_connect_swapped (notebook, "page-removed", 
130
 
                                  G_CALLBACK (reset_last_tab), grouper);
131
 
        g_signal_connect_swapped (notebook, "page-reordered", 
132
 
                                  G_CALLBACK (reset_last_tab), grouper);
133
 
        g_signal_connect_swapped (notebook, "switch-page", 
134
 
                                  G_CALLBACK (reset_last_tab), grouper);
135
 
}
136
 
 
137
 
static void
138
 
ephy_tab_grouper_init (EphyTabGrouper *grouper)
139
 
{
140
 
        grouper->priv = EPHY_TAB_GROUPER_GET_PRIVATE (grouper);
141
 
 
142
 
        LOG ("EphyTabGrouper initialised");
143
 
}
144
 
 
145
 
static void
146
 
ephy_tab_grouper_finalize (GObject *object)
147
 
{
148
 
        EphyTabGrouper *grouper = EPHY_TAB_GROUPER (object);
149
 
 
150
 
        /* Disconnect the signal handlers */
151
 
        g_signal_handlers_disconnect_matched
152
 
                (grouper->priv->notebook, G_SIGNAL_MATCH_DATA,
153
 
                 0, 0, NULL, NULL, grouper);
154
 
 
155
 
        LOG ("EphyTabGrouper finalised");
156
 
 
157
 
        parent_class->finalize (object);
158
 
}
159
 
 
160
 
static void
161
 
ephy_tab_grouper_set_property (GObject *object,
162
 
                               guint prop_id,
163
 
                               const GValue *value,
164
 
                               GParamSpec *pspec)
165
 
{
166
 
        EphyTabGrouper *grouper = EPHY_TAB_GROUPER (object);
167
 
 
168
 
        switch (prop_id)
169
 
        {
170
 
                case PROP_NOTEBOOK:
171
 
                        ephy_tab_grouper_set_notebook (grouper, g_value_get_object (value));
172
 
                        break;
173
 
        }
174
 
}
175
 
 
176
 
static void
177
 
ephy_tab_grouper_get_property (GObject *object,
178
 
                               guint prop_id,
179
 
                               GValue *value,
180
 
                               GParamSpec *pspec)
181
 
{
182
 
        EphyTabGrouper *grouper = EPHY_TAB_GROUPER (object);
183
 
 
184
 
        switch (prop_id)
185
 
        {
186
 
                case PROP_NOTEBOOK:
187
 
                        g_value_set_object (value, grouper->priv->notebook);
188
 
                        break;
189
 
        }
190
 
}
191
 
 
192
 
static void
193
 
ephy_tab_grouper_class_init (EphyTabGrouperClass *klass)
194
 
{
195
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
196
 
 
197
 
        parent_class = g_type_class_peek_parent (klass);
198
 
 
199
 
        object_class->finalize = ephy_tab_grouper_finalize;
200
 
        object_class->set_property = ephy_tab_grouper_set_property;
201
 
        object_class->get_property = ephy_tab_grouper_get_property;
202
 
 
203
 
        g_object_class_install_property (object_class,
204
 
                                         PROP_NOTEBOOK,
205
 
                                         g_param_spec_object ("notebook",
206
 
                                                              "Notebook",
207
 
                                                              "Notebook",
208
 
                                                              GTK_TYPE_NOTEBOOK,
209
 
                                                              G_PARAM_READWRITE |
210
 
                                                              G_PARAM_CONSTRUCT_ONLY));
211
 
        
212
 
        g_type_class_add_private (object_class, sizeof (EphyTabGrouperPrivate));
213
 
}
214
 
 
215
 
EphyTabGrouper *
216
 
ephy_tab_grouper_new (GtkWidget *notebook)
217
 
{
218
 
        g_return_val_if_fail (notebook != NULL, NULL);
219
 
 
220
 
        return EPHY_TAB_GROUPER (g_object_new (EPHY_TYPE_TAB_GROUPER,
221
 
                                               "notebook", notebook,
222
 
                                               NULL));
223
 
}