evolution-3.6.4/widgets/misc/e-url-entry.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		JP Rosevear <jpr@novell.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include <gtk/gtk.h>
 28 #include <glib/gi18n.h>
 29 #include "e-url-entry.h"
 30 #include "e-util/e-util.h"
 31 
 32 #define E_URL_ENTRY_GET_PRIVATE(obj) \
 33 	(G_TYPE_INSTANCE_GET_PRIVATE \
 34 	((obj), E_TYPE_URL_ENTRY, EUrlEntryPrivate))
 35 
 36 struct _EUrlEntryPrivate {
 37 	GtkWidget *entry;
 38 	GtkWidget *button;
 39 };
 40 
 41 static void button_clicked_cb (GtkWidget *widget, gpointer data);
 42 static void entry_changed_cb (GtkEditable *editable, gpointer data);
 43 
 44 static gboolean mnemonic_activate (GtkWidget *widget, gboolean group_cycling);
 45 
 46 G_DEFINE_TYPE (
 47 	EUrlEntry,
 48 	e_url_entry,
 49 	GTK_TYPE_HBOX)
 50 
 51 static void
 52 e_url_entry_class_init (EUrlEntryClass *class)
 53 {
 54 	GtkWidgetClass *widget_class;
 55 
 56 	g_type_class_add_private (class, sizeof (EUrlEntryPrivate));
 57 
 58 	widget_class = GTK_WIDGET_CLASS (class);
 59 	widget_class->mnemonic_activate = mnemonic_activate;
 60 }
 61 
 62 static void
 63 e_url_entry_init (EUrlEntry *url_entry)
 64 {
 65 	GtkWidget *pixmap;
 66 
 67 	url_entry->priv = E_URL_ENTRY_GET_PRIVATE (url_entry);
 68 
 69 	url_entry->priv->entry = gtk_entry_new ();
 70 	gtk_box_pack_start (
 71 		GTK_BOX (url_entry), url_entry->priv->entry, TRUE, TRUE, 0);
 72 	url_entry->priv->button = gtk_button_new ();
 73 	gtk_widget_set_sensitive (url_entry->priv->button, FALSE);
 74 	gtk_box_pack_start (
 75 		GTK_BOX (url_entry), url_entry->priv->button, FALSE, FALSE, 0);
 76 	atk_object_set_name (
 77 		gtk_widget_get_accessible (url_entry->priv->button),
 78 		_("Click here to go to URL"));
 79 	pixmap = gtk_image_new_from_icon_name ("go-jump", GTK_ICON_SIZE_BUTTON);
 80 	gtk_container_add (GTK_CONTAINER (url_entry->priv->button), pixmap);
 81 	gtk_widget_show (pixmap);
 82 
 83 	gtk_widget_show (url_entry->priv->button);
 84 	gtk_widget_show (url_entry->priv->entry);
 85 
 86 	g_signal_connect (
 87 		url_entry->priv->button, "clicked",
 88 		G_CALLBACK (button_clicked_cb), url_entry);
 89 	g_signal_connect (
 90 		url_entry->priv->entry, "changed",
 91 		G_CALLBACK (entry_changed_cb), url_entry);
 92 }
 93 
 94 /* GtkWidget::mnemonic_activate() handler for the EUrlEntry */
 95 static gboolean
 96 mnemonic_activate (GtkWidget *widget,
 97                    gboolean group_cycling)
 98 {
 99 	EUrlEntry *url_entry;
100 	EUrlEntryPrivate *priv;
101 
102 	url_entry = E_URL_ENTRY (widget);
103 	priv = url_entry->priv;
104 
105 	return gtk_widget_mnemonic_activate (priv->entry, group_cycling);
106 }
107 
108 GtkWidget *
109 e_url_entry_new (void)
110 {
111 	return g_object_new (E_TYPE_URL_ENTRY, NULL);
112 }
113 
114 GtkWidget *
115 e_url_entry_get_entry (EUrlEntry *url_entry)
116 {
117 	EUrlEntryPrivate *priv;
118 
119 	g_return_val_if_fail (url_entry != NULL, NULL);
120 	g_return_val_if_fail (E_IS_URL_ENTRY (url_entry), NULL);
121 
122 	priv = url_entry->priv;
123 
124 	return priv->entry;
125 }
126 
127 static void
128 button_clicked_cb (GtkWidget *widget,
129                    gpointer data)
130 {
131 	EUrlEntry *url_entry;
132 	EUrlEntryPrivate *priv;
133 	const gchar *uri;
134 
135 	url_entry = E_URL_ENTRY (data);
136 	priv = url_entry->priv;
137 
138 	uri = gtk_entry_get_text (GTK_ENTRY (priv->entry));
139 
140 	/* FIXME Pass a parent window. */
141 	e_show_uri (NULL, uri);
142 }
143 
144 static void
145 entry_changed_cb (GtkEditable *editable,
146                   gpointer data)
147 {
148 	EUrlEntry *url_entry;
149 	EUrlEntryPrivate *priv;
150 	const gchar *url;
151 
152 	url_entry = E_URL_ENTRY (data);
153 	priv = url_entry->priv;
154 
155 	url = gtk_entry_get_text (GTK_ENTRY (priv->entry));
156 	gtk_widget_set_sensitive (priv->button, url != NULL && *url != '\0');
157 }