~ubuntu-branches/debian/squeeze/galeon/squeeze

« back to all changes in this revision

Viewing changes to bookmarks/bookmarks-site-tb-widget.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Howard
  • Date: 2004-06-06 09:02:01 UTC
  • Revision ID: james.westby@ubuntu.com-20040606090201-yhx6ruhq8um7ggs2
Tags: upstream-1.3.15
Import upstream version 1.3.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2002  Ricardo Fern�ndez Pascual
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2, or (at your option)
 
7
 *  any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not, write to the Free Software
 
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#ifdef HAVE_CONFIG_H
 
20
#include "config.h"
 
21
#endif
 
22
 
 
23
#include "bookmarks-site-tb-widget.h"
 
24
#include "galeon-marshal.h"
 
25
#include "gul-gobject-misc.h"
 
26
#include "bookmarks-widgets-private.h"
 
27
#include "bookmarks-dnd.h"
 
28
 
 
29
#include <gtk/gtkbutton.h>
 
30
 
 
31
/**
 
32
 * Private data
 
33
 */
 
34
struct _GbSiteTbWidgetPrivate 
 
35
{
 
36
        GtkWidget *mainwid;
 
37
};
 
38
 
 
39
/**
 
40
 * Private functions, only availble from this file
 
41
 */
 
42
static void             gb_site_tb_widget_class_init    (GbSiteTbWidgetClass *klass);
 
43
static void             gb_site_tb_widget_init          (GbSiteTbWidget *w);
 
44
static void             gb_site_tb_widget_finalize_impl (GObject *o);
 
45
static void             gb_site_tb_widget_rebuild_impl  (GbTbWidget *w);
 
46
static void             gb_site_tb_widget_clicked_cb    (GtkButton *button, GbSiteTbWidget *w);
 
47
 
 
48
static gpointer gb_tb_widget_class;
 
49
 
 
50
/**
 
51
 * GbSiteTbWidget object
 
52
 */
 
53
 
 
54
MAKE_GET_TYPE (gb_site_tb_widget, "GbSiteTbWidget", GbSiteTbWidget, gb_site_tb_widget_class_init, 
 
55
               gb_site_tb_widget_init, GB_TYPE_TB_WIDGET);
 
56
 
 
57
static void
 
58
gb_site_tb_widget_class_init (GbSiteTbWidgetClass *klass)
 
59
{
 
60
        G_OBJECT_CLASS (klass)->finalize = gb_site_tb_widget_finalize_impl;
 
61
        GB_TB_WIDGET_CLASS (klass)->rebuild = gb_site_tb_widget_rebuild_impl;
 
62
        gb_tb_widget_class = g_type_class_peek_parent (klass);
 
63
}
 
64
 
 
65
static void 
 
66
gb_site_tb_widget_init (GbSiteTbWidget *w)
 
67
{
 
68
        GbSiteTbWidgetPrivate *p = g_new0 (GbSiteTbWidgetPrivate, 1);
 
69
        w->priv = p;
 
70
}
 
71
 
 
72
static void
 
73
gb_site_tb_widget_finalize_impl (GObject *o)
 
74
{
 
75
        GbSiteTbWidget *w = GB_SITE_TB_WIDGET (o);
 
76
        GbSiteTbWidgetPrivate *p = w->priv;
 
77
        
 
78
        g_free (p);
 
79
        
 
80
        G_OBJECT_CLASS (gb_tb_widget_class)->finalize (o);
 
81
}
 
82
 
 
83
GbSiteTbWidget *
 
84
gb_site_tb_widget_new (GbSite *site)
 
85
{
 
86
        GbSiteTbWidget *ret = g_object_new (GB_TYPE_SITE_TB_WIDGET, "bookmark", site, NULL);
 
87
        return ret;
 
88
}
 
89
 
 
90
static void
 
91
gb_site_tb_widget_rebuild_impl (GbTbWidget *gtw)
 
92
{
 
93
        GbSite *site = GB_SITE (gb_tb_widget_get_bookmark (gtw));
 
94
        GbSiteTbWidgetPrivate *p = GB_SITE_TB_WIDGET (gtw)->priv;
 
95
 
 
96
        if (!p->mainwid)
 
97
        {
 
98
                p->mainwid = gtk_button_new ();
 
99
                gtk_widget_show (p->mainwid);
 
100
                gtk_box_pack_start (GTK_BOX (gtw), p->mainwid, FALSE, FALSE, 0);
 
101
 
 
102
                g_signal_connect (p->mainwid, "clicked", 
 
103
                                  G_CALLBACK (gb_site_tb_widget_clicked_cb), gtw);
 
104
        }
 
105
 
 
106
        if (gtk_bin_get_child (GTK_BIN (p->mainwid)))
 
107
        {
 
108
                gtk_container_remove (GTK_CONTAINER (p->mainwid),
 
109
                                      gtk_bin_get_child (GTK_BIN (p->mainwid)));
 
110
        }
 
111
        
 
112
        gb_widgets_fill_tb_item (GTK_CONTAINER (p->mainwid), GB_BOOKMARK (site), site->url);
 
113
 
 
114
        gtk_button_set_relief (GTK_BUTTON (p->mainwid), GTK_RELIEF_NONE);
 
115
        GTK_WIDGET_SET_FLAGS (GTK_BUTTON (p->mainwid), GTK_CAN_FOCUS);
 
116
 
 
117
        gb_tb_widget_setup_context_menu (gtw, p->mainwid);
 
118
        gb_bookmark_dnd_drag_source_set (p->mainwid, GB_BOOKMARK (site));
 
119
}
 
120
 
 
121
static void
 
122
gb_site_tb_widget_clicked_cb (GtkButton *button, GbSiteTbWidget *w)
 
123
{
 
124
        GbBookmark *b = gb_tb_widget_get_bookmark (GB_TB_WIDGET (w));
 
125
        if (b)
 
126
        {
 
127
                gb_activated_activate (w, b, GB_SITE (b)->url, GB_BAF_DEFAULT);
 
128
        }
 
129
}
 
130