2010-11-02 20:21:32 +01:00
|
|
|
/* mug-query-bar.c */
|
|
|
|
|
|
|
|
/* insert (c)/licensing information) */
|
|
|
|
|
|
|
|
#include "mug-query-bar.h"
|
|
|
|
/* include other impl specific header files */
|
|
|
|
|
|
|
|
/* 'private'/'protected' functions */
|
2010-11-27 12:31:26 +01:00
|
|
|
static void mug_query_bar_class_init(MugQueryBarClass * klass);
|
|
|
|
static void mug_query_bar_init(MugQueryBar * obj);
|
|
|
|
static void mug_query_bar_finalize(GObject * obj);
|
2010-11-02 20:21:32 +01:00
|
|
|
|
|
|
|
/* list my signals */
|
|
|
|
enum {
|
|
|
|
MUG_QUERY_CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _MugQueryBarPrivate MugQueryBarPrivate;
|
|
|
|
struct _MugQueryBarPrivate {
|
|
|
|
GtkWidget *_entry;
|
|
|
|
};
|
|
|
|
#define MUG_QUERY_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
|
|
|
|
MUG_TYPE_QUERY_BAR, \
|
|
|
|
MugQueryBarPrivate))
|
|
|
|
/* globals */
|
|
|
|
static GtkContainerClass *parent_class = NULL;
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2010-11-02 20:21:32 +01:00
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
GType mug_query_bar_get_type(void)
|
2010-11-02 20:21:32 +01:00
|
|
|
{
|
|
|
|
static GType my_type = 0;
|
|
|
|
if (!my_type) {
|
|
|
|
static const GTypeInfo my_info = {
|
|
|
|
sizeof(MugQueryBarClass),
|
2010-11-27 12:31:26 +01:00
|
|
|
NULL, /* base init */
|
|
|
|
NULL, /* base finalize */
|
2010-11-02 20:21:32 +01:00
|
|
|
(GClassInitFunc) mug_query_bar_class_init,
|
2010-11-27 12:31:26 +01:00
|
|
|
NULL, /* class finalize */
|
|
|
|
NULL, /* class data */
|
2010-11-02 20:21:32 +01:00
|
|
|
sizeof(MugQueryBar),
|
2010-11-27 12:31:26 +01:00
|
|
|
0, /* n_preallocs, ignored since 2.10 */
|
2010-11-02 20:21:32 +01:00
|
|
|
(GInstanceInitFunc) mug_query_bar_init,
|
|
|
|
NULL
|
|
|
|
};
|
2010-11-27 12:31:26 +01:00
|
|
|
my_type = g_type_register_static(GTK_TYPE_HBOX,
|
|
|
|
"MugQueryBar", &my_info, 0);
|
2010-11-02 20:21:32 +01:00
|
|
|
}
|
|
|
|
return my_type;
|
|
|
|
}
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
static void mug_query_bar_class_init(MugQueryBarClass * klass)
|
2010-11-02 20:21:32 +01:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
2010-11-27 12:31:26 +01:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
2010-11-02 20:21:32 +01:00
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
parent_class = g_type_class_peek_parent(klass);
|
2010-11-02 20:21:32 +01:00
|
|
|
gobject_class->finalize = mug_query_bar_finalize;
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
g_type_class_add_private(gobject_class, sizeof(MugQueryBarPrivate));
|
2010-11-02 20:21:32 +01:00
|
|
|
|
|
|
|
/* signal definitions go here, e.g.: */
|
|
|
|
signals[MUG_QUERY_CHANGED] =
|
2010-11-27 12:31:26 +01:00
|
|
|
g_signal_new("query_changed",
|
|
|
|
G_TYPE_FROM_CLASS(gobject_class),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET(MugQueryBarClass, query_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__STRING,
|
|
|
|
G_TYPE_NONE, 1, G_TYPE_STRING);
|
2010-11-02 20:21:32 +01:00
|
|
|
}
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
static void on_entry_activated(GtkWidget * w, MugQueryBar * bar)
|
|
|
|
{
|
|
|
|
MugQueryBarPrivate *priv;
|
2010-11-02 20:21:32 +01:00
|
|
|
|
|
|
|
priv = MUG_QUERY_BAR_GET_PRIVATE(bar);
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
g_signal_emit(G_OBJECT(bar), signals[MUG_QUERY_CHANGED], 0,
|
|
|
|
gtk_entry_get_text(GTK_ENTRY(w)));
|
2010-11-02 20:21:32 +01:00
|
|
|
}
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
static void mug_query_bar_init(MugQueryBar * obj)
|
2010-11-02 20:21:32 +01:00
|
|
|
{
|
2010-11-27 12:31:26 +01:00
|
|
|
MugQueryBarPrivate *priv;
|
2010-11-02 20:21:32 +01:00
|
|
|
|
|
|
|
priv = MUG_QUERY_BAR_GET_PRIVATE(obj);
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
priv->_entry = gtk_entry_new();
|
|
|
|
|
|
|
|
g_signal_connect(priv->_entry, "activate",
|
|
|
|
G_CALLBACK(on_entry_activated), obj);
|
2010-11-02 20:21:32 +01:00
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
gtk_box_pack_start(GTK_BOX(obj), priv->_entry, TRUE, TRUE, 0);
|
2010-11-02 20:21:32 +01:00
|
|
|
}
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
static void mug_query_bar_finalize(GObject * obj)
|
2010-11-02 20:21:32 +01:00
|
|
|
{
|
|
|
|
/* free/unref instance resources here */
|
2010-11-27 12:31:26 +01:00
|
|
|
G_OBJECT_CLASS(parent_class)->finalize(obj);
|
2010-11-02 20:21:32 +01:00
|
|
|
}
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
GtkWidget *mug_query_bar_new(void)
|
2010-11-02 20:21:32 +01:00
|
|
|
{
|
|
|
|
return GTK_WIDGET(g_object_new(MUG_TYPE_QUERY_BAR, NULL));
|
|
|
|
}
|
|
|
|
|
2010-11-13 14:18:01 +01:00
|
|
|
void
|
2010-11-27 12:31:26 +01:00
|
|
|
mug_query_bar_set_query(MugQueryBar * self, const char *query, gboolean run)
|
2010-11-13 14:18:01 +01:00
|
|
|
{
|
|
|
|
MugQueryBarPrivate *priv;
|
2010-11-27 12:31:26 +01:00
|
|
|
|
|
|
|
g_return_if_fail(MUG_IS_QUERY_BAR(self));
|
2010-11-13 14:18:01 +01:00
|
|
|
priv = MUG_QUERY_BAR_GET_PRIVATE(self);
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(priv->_entry), query ? query : "");
|
2010-11-13 14:18:01 +01:00
|
|
|
|
|
|
|
if (run)
|
2010-11-27 12:31:26 +01:00
|
|
|
on_entry_activated(priv->_entry, self);
|
2010-11-13 14:18:01 +01:00
|
|
|
}
|
|
|
|
|
2010-11-27 12:31:26 +01:00
|
|
|
void mug_query_bar_grab_focus(MugQueryBar * self)
|
2010-11-02 22:14:29 +01:00
|
|
|
{
|
2010-11-27 12:31:26 +01:00
|
|
|
g_return_if_fail(MUG_IS_QUERY_BAR(self));
|
2010-11-02 22:14:29 +01:00
|
|
|
|
|
|
|
gtk_widget_grab_focus
|
2010-11-27 12:31:26 +01:00
|
|
|
(GTK_WIDGET(MUG_QUERY_BAR_GET_PRIVATE(self)->_entry));
|
2010-11-02 22:14:29 +01:00
|
|
|
}
|