Commit 10604944 authored by Carlos García Campos's avatar Carlos García Campos Committed by Carlos Garcia Campos

s/strcmp/g_strcasecmp/ added a property to limit the size of the history

2004-06-09  Carlos García Campos <carlosgc@gnome.org>
	* src/callbacks.c (on_finger_activate): s/strcmp/g_strcasecmp/
	* src/gn-combo-history.c ([sg]et_property, history_init,
	history_finalize, history_gconf_load, history_set_popdown_strings,
	gconf_history_changed, history_gconf_register_id, history_clear,
	history_[sg]et_max_history ): added a property to limit the size of
	the history (10 by defualt). Added a callback to update the history in
	real time.
	* src/gn-combo-history.h: added get/set functions to manage the
	max_history property
parent 5a0d9e8f
2004-06-09 Carlos Garca Campos <carlosgc@gnome.org>
* src/callbacks.c (on_finger_activate): s/strcmp/g_strcasecmp/
* src/gn-combo-history.c ([sg]et_property, history_init,
history_finalize, history_gconf_load, history_set_popdown_strings,
gconf_history_changed, history_gconf_register_id, history_clear,
history_[sg]et_max_history ): added a property to limit the size of
the history (10 by defualt). Added a callback to update the history in
real time.
* src/gn-combo-history.h: added get/set functions to manage the
max_history property
2004-06-09 William Jon McCann <mccann@jhu.edu>
* src/callbacks.c (on_finger_activate): Allow blank hostname to finger
......
......@@ -78,22 +78,6 @@ on_traceroute_activate (GtkWidget * widget, gpointer data)
g_return_if_fail (tracer != NULL);
/* entry_host = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (tracer->host)));
completion = gtk_entry_get_completion (entry_host);
model = gtk_entry_completion_get_model (completion);
text = g_strdup (gtk_entry_get_text (entry_host));
if (! nettool_item_is_in_model (model, text)) {
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
0, text,
-1);
}
g_free (text);*/
if (tracer->running) {
traceroute_stop (tracer);
} else {
......@@ -154,22 +138,6 @@ on_scan_activate (GtkWidget * widget, gpointer data)
g_return_if_fail (scan != NULL);
/*entry_host = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (scan->host)));
completion = gtk_entry_get_completion (entry_host);
model = gtk_entry_completion_get_model (completion);
text = g_strdup (gtk_entry_get_text (entry_host));
if (! nettool_item_is_in_model (model, text)) {
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
0, text,
-1);
}
g_free (text);*/
if (scan->running) {
scan_stop (scan);
} else {
......@@ -197,22 +165,6 @@ on_lookup_activate (GtkWidget * widget, gpointer data)
g_return_if_fail (lookup != NULL);
/* entry_host = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (lookup->host)));
completion = gtk_entry_get_completion (entry_host);
model = gtk_entry_completion_get_model (completion);
text = g_strdup (gtk_entry_get_text (entry_host));
if (! nettool_item_is_in_model (model, text)) {
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
0, text,
-1);
}
g_free (text);*/
if (lookup->running) {
lookup_stop (lookup);
} else {
......@@ -240,60 +192,30 @@ on_finger_activate (GtkWidget * widget, gpointer data)
g_return_if_fail (finger != NULL);
/*entry_host = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (finger->user)));
completion = gtk_entry_get_completion (entry_host);
model = gtk_entry_completion_get_model (completion);
text = g_strdup (gtk_entry_get_text (entry_host));
if (! nettool_item_is_in_model (model, text)) {
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
0, text,
-1);
}
g_free (text);
entry_host = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (finger->host)));
completion = gtk_entry_get_completion (entry_host);
model = gtk_entry_completion_get_model (completion);
text = g_strdup (gtk_entry_get_text (entry_host));
if (! nettool_item_is_in_model (model, text)) {
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
0, text,
-1);
}
g_free (text);*/
if (finger->running) {
finger_stop (finger);
} else {
finger_do (finger);
entry_host = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (finger->host)));
entry_host = GTK_ENTRY (
gtk_bin_get_child (GTK_BIN (finger->host)));
text = g_strdup (gtk_entry_get_text (entry_host));
g_strstrip (text);
if (strcmp (text, "") != 0)
if (g_strcasecmp (text, "") != 0)
gn_combo_history_add (finger->history, text);
g_free (text);
entry_host = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (finger->user)));
entry_host = GTK_ENTRY (
gtk_bin_get_child (GTK_BIN (finger->user)));
text = g_strdup (gtk_entry_get_text (entry_host));
g_strstrip (text);
if (strcmp (text, "") != 0)
if (g_strcasecmp (text, "") != 0)
gn_combo_history_add (finger->history_user, text);
g_free (text);
finger_do (finger);
}
}
......@@ -307,22 +229,6 @@ on_whois_activate (GtkWidget * widget, gpointer data)
g_return_if_fail (whois != NULL);
/* entry_host = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (whois->host)));
completion = gtk_entry_get_completion (entry_host);
model = gtk_entry_completion_get_model (completion);
text = g_strdup (gtk_entry_get_text (entry_host));
if (! nettool_item_is_in_model (model, text)) {
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
0, text,
-1);
}
g_free (text);*/
if (whois->running) {
whois_stop (whois);
} else {
......@@ -483,13 +389,13 @@ on_clear_history_activate (GtkWidget *notebook, gpointer data)
/* Pages all share a history id for host entry except whois */
netinfo = g_object_get_data (G_OBJECT (notebook), "pinger");
gn_combo_history_clear (netinfo->history);
/*netinfo = g_object_get_data (G_OBJECT (notebook), "finger");
gnome_entry_clear_history (netinfo->host);
gnome_entry_clear_history (netinfo->user);
netinfo = g_object_get_data (G_OBJECT (notebook), "whois");
gnome_entry_clear_history (netinfo->host);*/
netinfo = g_object_get_data (G_OBJECT (notebook), "finger");
gn_combo_history_clear (netinfo->history);
gn_combo_history_clear (netinfo->history_user);
netinfo = g_object_get_data (G_OBJECT (notebook), "whois");
gn_combo_history_clear (netinfo->history);
}
void
......
......@@ -27,16 +27,19 @@
enum {
PROP_0,
PROP_COMBO,
PROP_ID
PROP_ID,
PROP_MAX_HISTORY
};
struct _GnComboHistoryPrivate {
GtkComboBox *combo;
gchar *id;
guint max_history;
GList *items;
GConfClient *gconf_client;
guint gconf_notify;
};
static void gn_combo_history_init (GnComboHistory *history);
......@@ -90,8 +93,10 @@ gn_combo_history_init (GnComboHistory *history)
history->priv = g_new0 (GnComboHistoryPrivate, 1);
history->priv->combo = NULL;
history->priv->id = NULL;
history->priv->max_history = 10;
history->priv->items = NULL;
history->priv->gconf_client = gconf_client_get_default ();
history->priv->gconf_notify = 0;
}
static void
......@@ -110,6 +115,10 @@ gn_combo_history_class_init (GnComboHistoryClass *klass)
g_object_class_install_property (object_class, PROP_ID,
g_param_spec_string ("id", NULL, NULL,
NULL, G_PARAM_READWRITE));
g_object_class_install_property (object_class, PROP_MAX_HISTORY,
g_param_spec_uint ("max_history", NULL, NULL,
0, G_MAXUINT, 10,
G_PARAM_READWRITE));
object_class->finalize = gn_combo_history_finalize;
}
......@@ -135,6 +144,12 @@ gn_combo_history_finalize (GObject *object)
history->priv->items = NULL;
}
if (history->priv->gconf_notify != 0) {
gconf_client_notify_remove (history->priv->gconf_client,
history->priv->gconf_notify);
history->priv->gconf_notify = 0;
}
if (history->priv->gconf_client) {
g_object_unref (G_OBJECT (history->priv->gconf_client));
history->priv->gconf_client = NULL;
......@@ -163,6 +178,9 @@ gn_combo_history_set_property (GObject *object, guint prop_id, const GValue *va
if (history->priv->id) g_free (history->priv->id);
history->priv->id = g_value_dup_string (value);
break;
case PROP_MAX_HISTORY:
history->priv->max_history = g_value_get_uint (value);
break;
default:
break;
}
......@@ -185,6 +203,9 @@ gn_combo_history_get_property (GObject *object, guint prop_id, GValue *value,
case PROP_ID:
g_value_set_string (value, history->priv->id);
break;
case PROP_MAX_HISTORY:
g_value_set_uint (value, history->priv->max_history);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
}
......@@ -205,6 +226,7 @@ gn_combo_history_gconf_load (GnComboHistory *history)
{
gchar *key;
GSList *gconf_items, *items;
guint i;
g_return_if_fail (GN_IS_COMBO_HISTORY (history));
g_return_if_fail (history->priv->gconf_client != NULL);
......@@ -226,7 +248,9 @@ gn_combo_history_gconf_load (GnComboHistory *history)
key, GCONF_VALUE_STRING, NULL);
g_free (key);
for (items = gconf_items; items; items = items->next) {
for (items = gconf_items, i = 0;
items && i < history->priv->max_history;
items = items->next, i++) {
history->priv->items = g_list_append (history->priv->items, items->data);
}
......@@ -282,10 +306,13 @@ gn_combo_history_set_popdown_strings (GnComboHistory *history)
text_column = gtk_combo_box_entry_get_text_column (
GTK_COMBO_BOX_ENTRY (history->priv->combo));
if (history->priv->items)
gtk_list_store_clear (GTK_LIST_STORE (model));
else
gtk_list_store_clear (GTK_LIST_STORE (model));
if (! history->priv->items) {
gtk_combo_box_set_active (GTK_COMBO_BOX (history->priv->combo), -1);
return;
}
i = 0;
for (items = history->priv->items; items; items = items->next) {
......@@ -337,6 +364,24 @@ gn_combo_history_get_combo (GnComboHistory *history)
return history->priv->combo;
}
static void
gn_on_gconf_history_changed (GConfClient *client, guint cnxn_id,
GConfEntry *entry, gpointer gdata)
{
GnComboHistory *history;
history = GN_COMBO_HISTORY (gdata);
gn_combo_history_gconf_load (history);
gn_combo_history_set_popdown_strings (history);
gtk_combo_box_set_active (GTK_COMBO_BOX (history->priv->combo), -1);
gtk_entry_set_text (
GTK_ENTRY (gtk_bin_get_child (
GTK_BIN (history->priv->combo))), "");
}
static void
gn_combo_history_gconf_register_id (GnComboHistory *history)
{
......@@ -356,6 +401,11 @@ gn_combo_history_gconf_register_id (GnComboHistory *history)
gconf_client_add_dir (history->priv->gconf_client,
key, GCONF_CLIENT_PRELOAD_NONE,
NULL);
history->priv->gconf_notify = gconf_client_notify_add (
history->priv->gconf_client, key,
gn_on_gconf_history_changed,
(gpointer) history, NULL, NULL);
g_free (key);
}
......@@ -400,6 +450,11 @@ gn_combo_history_add (GnComboHistory *history, const gchar *text)
/* item is already in list, remove them */
history->priv->items = g_list_remove (history->priv->items, item->data);
}
if (g_list_length (history->priv->items) >= history->priv->max_history) {
item = g_list_last (history->priv->items);
history->priv->items = g_list_remove (history->priv->items, item->data);
}
history->priv->items = g_list_prepend (history->priv->items,
g_strdup (text));
......@@ -418,8 +473,23 @@ gn_combo_history_clear (GnComboHistory *history)
g_list_free (history->priv->items);
history->priv->items = NULL;
gn_combo_history_set_popdown_strings (history);
gn_combo_history_gconf_save (history);
}
}
guint
gn_combo_history_get_max_history (GnComboHistory *history)
{
g_return_val_if_fail (GN_IS_COMBO_HISTORY (history), 0);
return history->priv->max_history;
}
void
gn_combo_history_set_max_history (GnComboHistory *history,
guint max_history)
{
g_return_if_fail (GN_IS_COMBO_HISTORY (history));
history->priv->max_history = max_history;
}
......@@ -45,18 +45,21 @@ struct _GnComboHistoryClass
GObjectClass parent_class;
};
GType gn_combo_history_get_type (void);
GnComboHistory *gn_combo_history_new (void);
void gn_combo_history_set_combo (GnComboHistory *history,
GtkComboBox *combo);
GtkComboBox *gn_combo_history_get_combo (GnComboHistory *history);
void gn_combo_history_set_id (GnComboHistory *history,
const gchar *history_id);
const gchar *gn_combo_history_get_id (GnComboHistory *history);
void gn_combo_history_add (GnComboHistory *history,
const gchar *text);
void gn_combo_history_clear (GnComboHistory *history);
GType gn_combo_history_get_type (void);
GnComboHistory *gn_combo_history_new (void);
void gn_combo_history_set_combo (GnComboHistory *history,
GtkComboBox *combo);
GtkComboBox *gn_combo_history_get_combo (GnComboHistory *history);
void gn_combo_history_set_id (GnComboHistory *history,
const gchar *history_id);
const gchar *gn_combo_history_get_id (GnComboHistory *history);
void gn_combo_history_add (GnComboHistory *history,
const gchar *text);
void gn_combo_history_clear (GnComboHistory *history);
guint gn_combo_history_get_max_history (GnComboHistory *history);
void gn_combo_history_set_max_history (GnComboHistory *history,
guint max_history);
#endif /* __GN_COMBO_HISTORY_H__ */
This diff is collapsed.
......@@ -531,6 +531,7 @@ load_info_widgets_from_xml (GladeXML * xml)
group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (group, label1);
gtk_size_group_add_widget (group, label2);
g_object_unref (group);
/*
#ifdef IFCONFIG_PROGRAM
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment