[hotssh] Display connected hostname in tab label
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hotssh] Display connected hostname in tab label
- Date: Sat, 16 Nov 2013 23:40:16 +0000 (UTC)
commit 5b76f6a16057af50c0677a1f29973428d4efb2e7
Author: Colin Walters <walters verbum org>
Date: Sat Nov 16 18:39:44 2013 -0500
Display connected hostname in tab label
src/hotssh-tab.c | 34 ++++++++++++++++++++++++++++++++++
src/hotssh-win.c | 18 ++++++++++++++++--
2 files changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/src/hotssh-tab.c b/src/hotssh-tab.c
index 1fb0b54..cdf9854 100644
--- a/src/hotssh-tab.c
+++ b/src/hotssh-tab.c
@@ -34,6 +34,11 @@ static const GSshConnectionAuthMechanism default_authentication_order[] = {
GSSH_CONNECTION_AUTH_MECHANISM_PASSWORD
};
+enum {
+ PROP_0,
+ PROP_HOSTNAME
+};
+
struct _HotSshTab
{
GtkNotebook parent;
@@ -121,6 +126,7 @@ state_reset_for_new_connection (HotSshTab *self)
HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self);
g_debug ("reset state");
g_clear_pointer (&priv->hostname, g_free);
+ g_object_notify ((GObject*)self, "hostname");
g_clear_object (&priv->address);
g_clear_object (&priv->connection);
g_clear_object (&priv->cancellable);
@@ -445,6 +451,7 @@ on_connect (GtkButton *button,
}
priv->hostname = g_strdup (hostname);
+ g_object_notify ((GObject*)self, "hostname");
g_clear_object (&priv->connection);
priv->connection = gssh_connection_new (priv->address, username);
@@ -659,6 +666,26 @@ hotssh_tab_grab_focus (GtkWidget *widget)
}
static void
+hotssh_tab_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ HotSshTab *self = (HotSshTab*) (object);
+ HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self);
+
+ switch (prop_id)
+ {
+ case PROP_HOSTNAME:
+ g_value_set_string (value, priv->hostname);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
hotssh_tab_init (HotSshTab *self)
{
HotSshTabPrivate *priv = hotssh_tab_get_instance_private (self);
@@ -700,6 +727,7 @@ hotssh_tab_dispose (GObject *object)
static void
hotssh_tab_class_init (HotSshTabClass *class)
{
+ G_OBJECT_CLASS (class)->get_property = hotssh_tab_get_property;
G_OBJECT_CLASS (class)->dispose = hotssh_tab_dispose;
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class),
@@ -722,6 +750,12 @@ hotssh_tab_class_init (HotSshTabClass *class)
GTK_WIDGET_CLASS (class)->grab_focus = hotssh_tab_grab_focus;
GTK_WIDGET_CLASS (class)->style_updated = hotssh_tab_style_updated;
+
+ g_object_class_install_property (G_OBJECT_CLASS (class),
+ PROP_HOSTNAME,
+ g_param_spec_string ("hostname", "Hostname", "",
+ NULL,
+ G_PARAM_READABLE));
}
HotSshTab *
diff --git a/src/hotssh-win.c b/src/hotssh-win.c
index 0712c9c..e564106 100644
--- a/src/hotssh-win.c
+++ b/src/hotssh-win.c
@@ -105,7 +105,7 @@ create_tab_label (HotSshWindow *self,
GtkImage *close_image;
label_box = (GtkContainer*)gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
- label = (GtkLabel*)gtk_label_new ("Unconnected");
+ label = (GtkLabel*)gtk_label_new ("");
gtk_label_set_single_line_mode (label, TRUE);
gtk_misc_set_alignment ((GtkMisc*)label, 0.0, 0.5);
gtk_misc_set_padding ((GtkMisc*)label, 0, 0);
@@ -126,10 +126,23 @@ create_tab_label (HotSshWindow *self,
gtk_box_pack_start ((GtkBox*)label_box, (GtkWidget*)close_button, FALSE, FALSE, 0);
gtk_widget_show_all ((GtkWidget*)label_box);
+ g_object_set_data ((GObject*)label_box, "label-text", label);
return (GtkWidget*)label_box;
}
static void
+on_tab_hostname_changed (HotSshTab *tab,
+ GParamSpec *pspec,
+ HotSshWindow *self)
+{
+ HotSshWindowPrivate *priv = hotssh_window_get_instance_private (self);
+ GtkWidget *label_box = gtk_notebook_get_tab_label ((GtkNotebook*)priv->main_notebook, (GtkWidget*)tab);
+ GtkLabel *real_label = GTK_LABEL (g_object_get_data ((GObject*)label_box, "label-text"));
+ const char *hostname = hotssh_tab_get_hostname (tab);
+ gtk_label_set_text (real_label, hostname ? hostname : "Disconnected");
+}
+
+static void
hotssh_win_append_tab (HotSshWindow *self, gboolean new_channel)
{
HotSshWindowPrivate *priv = hotssh_window_get_instance_private (self);
@@ -150,10 +163,11 @@ hotssh_win_append_tab (HotSshWindow *self, gboolean new_channel)
g_object_set_data ((GObject*)tab, "window", self);
label = create_tab_label (self, tab);
-
+ g_signal_connect ((GObject*)tab, "notify::hostname", G_CALLBACK (on_tab_hostname_changed), self);
idx = gtk_notebook_append_page ((GtkNotebook*)priv->main_notebook,
(GtkWidget*)tab,
(GtkWidget*)label);
+ on_tab_hostname_changed (tab, NULL, self);
gtk_widget_show_all ((GtkWidget*)tab);
gtk_notebook_set_current_page ((GtkNotebook*)priv->main_notebook, idx);
gtk_widget_grab_focus ((GtkWidget*)tab);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]