From: Lennart Poettering Date: Fri, 9 Nov 2007 13:42:35 +0000 (+0000) Subject: Allow overwriting of pretty service names. Add new tool bshell as combination of... X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=48222d53275aad17abaf6102d178ddef5e0fa69f;p=catta Allow overwriting of pretty service names. Add new tool bshell as combination of bssh and bnc. Patch from Mathias Hasselmann. Re #180. (Also fixing a va_copy misuse) git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1570 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/avahi-ui/Makefile.am b/avahi-ui/Makefile.am index 39b9aca..0fd232f 100644 --- a/avahi-ui/Makefile.am +++ b/avahi-ui/Makefile.am @@ -65,8 +65,9 @@ bssh_LDADD = $(AM_LDADD) $(GTK20_LIBS) ../avahi-client/libavahi-client.la ../ava install-exec-local: cd $(DESTDIR)/$(bindir) && \ - rm -f bvnc && \ - $(LN_S) bssh bvnc + rm -f bvnc bshell && \ + $(LN_S) bssh bvnc && \ + $(LN_S) bssh bshell bssh.desktop: bssh.desktop.in sed -e 's,@bindir\@,$(bindir),g' $< > $@ diff --git a/avahi-ui/avahi-ui.c b/avahi-ui/avahi-ui.c index 4bd836b..e7bd7ec 100644 --- a/avahi-ui/avahi-ui.c +++ b/avahi-ui/avahi-ui.c @@ -2,17 +2,17 @@ /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -52,13 +52,13 @@ struct _AuiServiceDialogPrivate { AvahiServiceBrowser **browsers; AvahiServiceResolver *resolver; AvahiDomainBrowser *domain_browser; - + gchar **browse_service_types; gchar *service_type; gchar *domain; gchar *service_name; AvahiProtocol address_family; - + AvahiAddress address; gchar *host_name; AvahiStringList *txt_data; @@ -66,13 +66,14 @@ struct _AuiServiceDialogPrivate { gboolean resolve_service, resolve_service_done; gboolean resolve_host_name, resolve_host_name_done; - + GtkWidget *domain_label; GtkWidget *domain_button; GtkWidget *service_tree_view; GtkWidget *service_progress_bar; GtkListStore *service_list_store, *domain_list_store; + GHashTable *service_type_names; guint service_pulse_timeout; guint domain_pulse_timeout; @@ -136,26 +137,26 @@ static int get_default_response(GtkDialog *dlg) { /* Fall back to finding the first positive response */ GList *children, *t; gint bad = GTK_RESPONSE_NONE; - + t = children = gtk_container_get_children(GTK_CONTAINER(dlg->action_area)); - + while (t) { GtkWidget *child = t->data; - + ret = gtk_dialog_get_response_for_widget(dlg, child); - + if (ret == GTK_RESPONSE_ACCEPT || ret == GTK_RESPONSE_OK || ret == GTK_RESPONSE_YES || ret == GTK_RESPONSE_APPLY) break; - + if (ret != GTK_RESPONSE_NONE && bad == GTK_RESPONSE_NONE) bad = ret; - + t = t->next; } - + g_list_free (children); /* Fall back to finding the first negative response */ @@ -170,7 +171,7 @@ G_DEFINE_TYPE(AuiServiceDialog, aui_service_dialog, GTK_TYPE_DIALOG) static void aui_service_dialog_class_init(AuiServiceDialogClass *klass) { GObjectClass *object_class; - + object_class = (GObjectClass*) klass; object_class->finalize = aui_service_dialog_finalize; @@ -204,7 +205,7 @@ static void aui_service_dialog_class_init(AuiServiceDialogClass *klass) { object_class, PROP_ADDRESS, g_param_spec_pointer("address", "Address", "The address of the resolved service", - G_PARAM_READABLE)); + G_PARAM_READABLE)); g_object_class_install_property( object_class, PROP_PORT, @@ -248,10 +249,10 @@ GtkWidget *aui_service_dialog_new_valist( GtkWindow *parent, const gchar *first_button_text, va_list varargs) { - + const gchar *button_text; gint dr; - + GtkWidget *w = GTK_WIDGET(g_object_new( AUI_TYPE_SERVICE_DIALOG, "has-separator", FALSE, @@ -264,12 +265,12 @@ GtkWidget *aui_service_dialog_new_valist( button_text = first_button_text; while (button_text) { gint response_id; - + response_id = va_arg(varargs, gint); gtk_dialog_add_button(GTK_DIALOG(w), button_text, response_id); button_text = va_arg(varargs, const gchar *); } - + gtk_dialog_set_response_sensitive(GTK_DIALOG(w), GTK_RESPONSE_ACCEPT, FALSE); gtk_dialog_set_response_sensitive(GTK_DIALOG(w), GTK_RESPONSE_OK, FALSE); gtk_dialog_set_response_sensitive(GTK_DIALOG(w), GTK_RESPONSE_YES, FALSE); @@ -288,12 +289,12 @@ GtkWidget* aui_service_dialog_new( ...) { GtkWidget *w; - + va_list varargs; va_start(varargs, first_button_text); w = aui_service_dialog_new_valist(title, parent, first_button_text, varargs); va_end(varargs); - + return w; } @@ -323,7 +324,7 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void *userda avahi_strerror(avahi_client_errno(c))); gtk_dialog_run(GTK_DIALOG(m)); gtk_widget_destroy(m); - + gtk_dialog_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL); } } @@ -366,7 +367,7 @@ static void resolve_callback( avahi_string_list_free(d->priv->txt_data); d->priv->txt_data = avahi_string_list_copy(txt); - + if (a) { d->priv->resolve_host_name_done = 1; d->priv->address = *a; @@ -385,7 +386,7 @@ static void resolve_callback( avahi_strerror(avahi_client_errno(d->priv->client))); gtk_dialog_run(GTK_DIALOG(m)); gtk_widget_destroy(m); - + gtk_dialog_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL); break; } @@ -405,12 +406,12 @@ static void browse_callback( void* userdata) { AuiServiceDialog *d = AUI_SERVICE_DIALOG(userdata); - + switch (event) { case AVAHI_BROWSER_NEW: { gchar *ifs; - const gchar *pretty_type; + const gchar *pretty_type = NULL; char ifname[IFNAMSIZ]; GtkTreeIter iter; GtkTreeSelection *selection; @@ -420,12 +421,17 @@ static void browse_callback( ifs = g_strdup_printf("%s %s", ifname, protocol == AVAHI_PROTO_INET ? "IPv4" : "IPv6"); + if (d->priv->service_type_names) + pretty_type = g_hash_table_lookup (d->priv->service_type_names, type); + + if (!pretty_type) { #if defined(HAVE_GDBM) || defined(HAVE_DBM) - pretty_type = stdb_lookup(type); + pretty_type = stdb_lookup(type); #else - pretty_type = type; -#endif - + pretty_type = type; +#endif + } + gtk_list_store_append(d->priv->service_list_store, &iter); gtk_list_store_set(d->priv->service_list_store, &iter, @@ -438,7 +444,7 @@ static void browse_callback( -1); g_free(ifs); - + if (d->priv->common_protocol == AVAHI_PROTO_UNSPEC) d->priv->common_protocol = protocol; @@ -457,19 +463,19 @@ static void browse_callback( !d->priv->service_name || (avahi_domain_equal(d->priv->service_type, type) && strcasecmp(d->priv->service_name, name) == 0)) { GtkTreePath *path; - + gtk_tree_selection_select_iter(selection, &iter); path = gtk_tree_model_get_path(GTK_TREE_MODEL(d->priv->service_list_store), &iter); gtk_tree_view_set_cursor(GTK_TREE_VIEW(d->priv->service_tree_view), path, NULL, FALSE); gtk_tree_path_free(path); } - + } - + break; } - + case AVAHI_BROWSER_REMOVE: { GtkTreeIter iter; gboolean valid; @@ -479,7 +485,7 @@ static void browse_callback( gint _interface, _protocol; gchar *_name, *_type; gboolean found; - + gtk_tree_model_get(GTK_TREE_MODEL(d->priv->service_list_store), &iter, SERVICE_COLUMN_IFACE, &_interface, SERVICE_COLUMN_PROTO, &_protocol, @@ -494,10 +500,10 @@ static void browse_callback( gtk_list_store_remove(d->priv->service_list_store, &iter); break; } - + valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(d->priv->service_list_store), &iter); } - + break; } @@ -530,20 +536,20 @@ static void browse_callback( static void domain_make_default_selection(AuiServiceDialog *d, const gchar *name, GtkTreeIter *iter) { GtkTreeSelection *selection; - + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(d->priv->domain_tree_view)); if (!gtk_tree_selection_get_selected(selection, NULL, NULL)) { - + if (avahi_domain_equal(gtk_entry_get_text(GTK_ENTRY(d->priv->domain_entry)), name)) { GtkTreePath *path; - + gtk_tree_selection_select_iter(selection, iter); - + path = gtk_tree_model_get_path(GTK_TREE_MODEL(d->priv->domain_list_store), iter); gtk_tree_view_set_cursor(GTK_TREE_VIEW(d->priv->domain_tree_view), path, NULL, FALSE); gtk_tree_path_free(path); } - + } } @@ -557,7 +563,7 @@ static void domain_browse_callback( void* userdata) { AuiServiceDialog *d = AUI_SERVICE_DIALOG(userdata); - + switch (event) { case AVAHI_BROWSER_NEW: { @@ -568,7 +574,7 @@ static void domain_browse_callback( valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(d->priv->domain_list_store), &iter); while (valid) { gchar *_name; - + gtk_tree_model_get(GTK_TREE_MODEL(d->priv->domain_list_store), &iter, DOMAIN_COLUMN_NAME, &_name, DOMAIN_COLUMN_REF, &ref, @@ -579,15 +585,15 @@ static void domain_browse_callback( if (found) break; - + valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(d->priv->domain_list_store), &iter); } - if (found) + if (found) gtk_list_store_set(d->priv->domain_list_store, &iter, DOMAIN_COLUMN_REF, ref + 1, -1); else { gtk_list_store_append(d->priv->domain_list_store, &iter); - + gtk_list_store_set(d->priv->domain_list_store, &iter, DOMAIN_COLUMN_NAME, name, DOMAIN_COLUMN_REF, 1, @@ -595,20 +601,20 @@ static void domain_browse_callback( } domain_make_default_selection(d, name, &iter); - + break; } case AVAHI_BROWSER_REMOVE: { gboolean valid; GtkTreeIter iter; - + valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(d->priv->domain_list_store), &iter); while (valid) { gint ref; gchar *_name; gboolean found; - + gtk_tree_model_get(GTK_TREE_MODEL(d->priv->domain_list_store), &iter, DOMAIN_COLUMN_NAME, &_name, DOMAIN_COLUMN_REF, &ref, @@ -624,13 +630,13 @@ static void domain_browse_callback( gtk_list_store_set(d->priv->domain_list_store, &iter, DOMAIN_COLUMN_REF, ref - 1, -1); break; } - + valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(d->priv->domain_list_store), &iter); } - + break; } - + case AVAHI_BROWSER_FAILURE: { GtkWidget *m = gtk_message_dialog_new(GTK_WINDOW(d), @@ -660,10 +666,10 @@ static void domain_browse_callback( static const gchar *get_domain_name(AuiServiceDialog *d) { const gchar *domain; - + g_return_val_if_fail(d, NULL); g_return_val_if_fail(AUI_IS_SERVICE_DIALOG(d), NULL); - + if (d->priv->domain) return d->priv->domain; @@ -692,7 +698,7 @@ static gboolean start_callback(gpointer data) { const char *domain; d->priv->start_idle = 0; - + if (!d->priv->browse_service_types || !*d->priv->browse_service_types) { g_warning("Browse service type list is empty!"); return FALSE; @@ -700,7 +706,7 @@ static gboolean start_callback(gpointer data) { if (!d->priv->client) { if (!(d->priv->client = avahi_client_new(avahi_glib_poll_get(d->priv->glib_poll), 0, client_callback, d, &error))) { - + GtkWidget *m = gtk_message_dialog_new(GTK_WINDOW(d), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, @@ -709,7 +715,7 @@ static gboolean start_callback(gpointer data) { avahi_strerror(error)); gtk_dialog_run(GTK_DIALOG(m)); gtk_widget_destroy(m); - + gtk_dialog_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL); return FALSE; } @@ -729,7 +735,7 @@ static gboolean start_callback(gpointer data) { gtk_label_set_markup(GTK_LABEL(d->priv->domain_label), t); g_free(t); } - + if (d->priv->browsers) { for (sb = d->priv->browsers; *sb; sb++) avahi_service_browser_free(*sb); @@ -766,7 +772,7 @@ static gboolean start_callback(gpointer data) { avahi_strerror(avahi_client_errno(d->priv->client))); gtk_dialog_run(GTK_DIALOG(m)); gtk_widget_destroy(m); - + gtk_dialog_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL); return FALSE; @@ -787,21 +793,21 @@ static void aui_service_dialog_finalize(GObject *object) { if (d->priv->start_idle > 0) g_source_remove(d->priv->start_idle); - + g_free(d->priv->host_name); g_free(d->priv->domain); g_free(d->priv->service_name); avahi_string_list_free(d->priv->txt_data); - + g_strfreev(d->priv->browse_service_types); if (d->priv->domain_browser) avahi_domain_browser_free(d->priv->domain_browser); - + if (d->priv->resolver) avahi_service_resolver_free(d->priv->resolver); - + if (d->priv->browsers) { AvahiServiceBrowser **sb; @@ -817,6 +823,13 @@ static void aui_service_dialog_finalize(GObject *object) { if (d->priv->glib_poll) avahi_glib_poll_free(d->priv->glib_poll); + if (d->priv->service_list_store) + g_object_unref(d->priv->service_list_store); + if (d->priv->domain_list_store) + g_object_unref(d->priv->domain_list_store); + if (d->priv->service_type_names) + g_hash_table_unref (d->priv->service_type_names); + g_free(d->priv); d->priv = NULL; @@ -849,7 +862,7 @@ static void response_callback(GtkDialog *dialog, gint response, gpointer user_da response == GTK_RESPONSE_APPLY) && ((d->priv->resolve_service && !d->priv->resolve_service_done) || (d->priv->resolve_host_name && !d->priv->resolve_host_name_done))) { - + GtkTreeIter iter; gint interface, protocol; gchar *name, *type; @@ -889,7 +902,7 @@ static void response_callback(GtkDialog *dialog, gint response, gpointer user_da avahi_strerror(avahi_client_errno(d->priv->client))); gtk_dialog_run(GTK_DIALOG(m)); gtk_widget_destroy(m); - + gtk_dialog_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL); return; } @@ -898,7 +911,7 @@ static void response_callback(GtkDialog *dialog, gint response, gpointer user_da static gboolean is_valid_domain_suffix(const gchar *n) { gchar label[AVAHI_LABEL_MAX]; - + if (!avahi_is_valid_domain_name(n)) return FALSE; @@ -906,7 +919,7 @@ static gboolean is_valid_domain_suffix(const gchar *n) { return FALSE; /* At least one label */ - + return !!label[0]; } @@ -963,16 +976,16 @@ static void domain_button_clicked(GtkButton *button G_GNUC_UNUSED, gpointer user avahi_strerror(avahi_client_errno(p->client))); gtk_dialog_run(GTK_DIALOG(m)); gtk_widget_destroy(m); - + gtk_dialog_response(GTK_DIALOG(d), GTK_RESPONSE_CANCEL); return; } - + p->domain_dialog = gtk_dialog_new(); gtk_container_set_border_width(GTK_CONTAINER(p->domain_dialog), 5); gtk_window_set_title(GTK_WINDOW(p->domain_dialog), "Change domain"); gtk_dialog_set_has_separator(GTK_DIALOG(p->domain_dialog), FALSE); - + vbox = gtk_vbox_new(FALSE, 8); gtk_container_set_border_width(GTK_CONTAINER(vbox), 8); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(p->domain_dialog)->vbox), vbox, TRUE, TRUE, 0); @@ -983,7 +996,7 @@ static void domain_button_clicked(GtkButton *button G_GNUC_UNUSED, gpointer user gtk_entry_set_activates_default(GTK_ENTRY(p->domain_entry), TRUE); g_signal_connect(p->domain_entry, "changed", G_CALLBACK(domain_entry_changed_callback), d); gtk_box_pack_start(GTK_BOX(vbox), p->domain_entry, FALSE, FALSE, 0); - + vbox2 = gtk_vbox_new(FALSE, 8); gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0); @@ -1013,7 +1026,7 @@ static void domain_button_clicked(GtkButton *button G_GNUC_UNUSED, gpointer user gtk_progress_bar_set_text(GTK_PROGRESS_BAR(p->domain_progress_bar), "Browsing ..."); gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(p->domain_progress_bar), 0.1); gtk_box_pack_end(GTK_BOX(vbox2), p->domain_progress_bar, FALSE, FALSE, 0); - + gtk_dialog_add_button(GTK_DIALOG(p->domain_dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); p->domain_ok_button = GTK_WIDGET(gtk_dialog_add_button(GTK_DIALOG(p->domain_dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT)); gtk_dialog_set_default_response(GTK_DIALOG(p->domain_dialog), GTK_RESPONSE_ACCEPT); @@ -1023,7 +1036,7 @@ static void domain_button_clicked(GtkButton *button G_GNUC_UNUSED, gpointer user gtk_widget_grab_focus(p->domain_entry); gtk_window_set_default_size(GTK_WINDOW(p->domain_dialog), 300, 300); - + gtk_widget_show_all(vbox); gtk_list_store_append(p->domain_list_store, &iter); @@ -1031,7 +1044,7 @@ static void domain_button_clicked(GtkButton *button G_GNUC_UNUSED, gpointer user domain_make_default_selection(d, "local", &iter); p->domain_pulse_timeout = g_timeout_add(100, domain_pulse_callback, d); - + if (gtk_dialog_run(GTK_DIALOG(p->domain_dialog)) == GTK_RESPONSE_ACCEPT) aui_service_dialog_set_domain(d, gtk_entry_get_text(GTK_ENTRY(p->domain_entry))); @@ -1055,7 +1068,7 @@ static void aui_service_dialog_init(AuiServiceDialog *d) { AuiServiceDialogPrivate *p; p = d->priv = g_new(AuiServiceDialogPrivate, 1); - + p->host_name = NULL; p->domain = NULL; p->service_name = NULL; @@ -1089,7 +1102,8 @@ static void aui_service_dialog_init(AuiServiceDialog *d) { p->forward_response_id = GTK_RESPONSE_NONE; p->service_list_store = p->domain_list_store = NULL; - + p->service_type_names = NULL; + gtk_widget_push_composite_child(); gtk_container_set_border_width(GTK_CONTAINER(d), 5); @@ -1102,7 +1116,7 @@ static void aui_service_dialog_init(AuiServiceDialog *d) { gtk_label_set_ellipsize(GTK_LABEL(p->domain_label), TRUE); gtk_misc_set_alignment(GTK_MISC(p->domain_label), 0, 0.5); gtk_box_pack_start(GTK_BOX(vbox), p->domain_label, FALSE, FALSE, 0); - + vbox2 = gtk_vbox_new(FALSE, 8); gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0); @@ -1120,12 +1134,12 @@ static void aui_service_dialog_init(AuiServiceDialog *d) { selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(p->service_tree_view)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_BROWSE); g_signal_connect(selection, "changed", G_CALLBACK(service_selection_changed_callback), d); - + renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("Location", renderer, "text", SERVICE_COLUMN_PRETTY_IFACE, NULL); gtk_tree_view_column_set_visible(column, FALSE); gtk_tree_view_append_column(GTK_TREE_VIEW(p->service_tree_view), column); - + renderer = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("Name", renderer, "text", SERVICE_COLUMN_NAME, NULL); gtk_tree_view_column_set_expand(column, TRUE); @@ -1144,19 +1158,19 @@ static void aui_service_dialog_init(AuiServiceDialog *d) { gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR(p->service_progress_bar), 0.1); gtk_box_pack_end(GTK_BOX(vbox2), p->service_progress_bar, FALSE, FALSE, 0); - p->domain_button = gtk_button_new_with_mnemonic("_Domain..."); - gtk_button_set_image(GTK_BUTTON(p->domain_button), gtk_image_new_from_stock(GTK_STOCK_NETWORK, GTK_ICON_SIZE_BUTTON)); + p->domain_button = gtk_button_new_with_mnemonic("_Domain..."); + gtk_button_set_image(GTK_BUTTON(p->domain_button), gtk_image_new_from_stock(GTK_STOCK_NETWORK, GTK_ICON_SIZE_BUTTON)); g_signal_connect(p->domain_button, "clicked", G_CALLBACK(domain_button_clicked), d); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(d)->action_area), p->domain_button, FALSE, TRUE, 0); gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(GTK_DIALOG(d)->action_area), p->domain_button, TRUE); - gtk_widget_show(p->domain_button); - + gtk_widget_show(p->domain_button); + gtk_dialog_set_default_response(GTK_DIALOG(d), GTK_RESPONSE_ACCEPT); gtk_widget_grab_focus(p->service_tree_view); gtk_window_set_default_size(GTK_WINDOW(d), 400, 300); - + gtk_widget_show_all(vbox); gtk_widget_pop_composite_child(); @@ -1180,12 +1194,12 @@ void aui_service_dialog_set_browse_service_types(AuiServiceDialog *d, const char va_list ap; const char *t; unsigned u; - + g_return_if_fail(AUI_IS_SERVICE_DIALOG(d)); g_return_if_fail(type); g_strfreev(d->priv->browse_service_types); - + va_start(ap, type); for (u = 1; va_arg(ap, const char *); u++) ; @@ -1193,15 +1207,15 @@ void aui_service_dialog_set_browse_service_types(AuiServiceDialog *d, const char d->priv->browse_service_types = g_new0(gchar*, u+1); d->priv->browse_service_types[0] = g_strdup(type); - + va_start(ap, type); - for (u = 1; (t = va_arg(apcopy, const char*)); u++) + for (u = 1; (t = va_arg(ap, const char*)); u++) d->priv->browse_service_types[u] = g_strdup(t); va_end(ap); if (d->priv->browse_service_types[0] && d->priv->browse_service_types[1]) { /* Multiple service types, enable headers */ - + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(d->priv->service_tree_view), TRUE); gtk_tree_view_column_set_visible(gtk_tree_view_get_column(GTK_TREE_VIEW(d->priv->service_tree_view), 2), TRUE); } @@ -1210,7 +1224,7 @@ void aui_service_dialog_set_browse_service_types(AuiServiceDialog *d, const char } void aui_service_dialog_set_browse_service_typesv(AuiServiceDialog *d, const char *const*types) { - + g_return_if_fail(AUI_IS_SERVICE_DIALOG(d)); g_return_if_fail(types); g_return_if_fail(*types); @@ -1220,7 +1234,7 @@ void aui_service_dialog_set_browse_service_typesv(AuiServiceDialog *d, const cha if (d->priv->browse_service_types[0] && d->priv->browse_service_types[1]) { /* Multiple service types, enable headers */ - + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(d->priv->service_tree_view), TRUE); gtk_tree_view_column_set_visible(gtk_tree_view_get_column(GTK_TREE_VIEW(d->priv->service_tree_view), 2), TRUE); } @@ -1234,19 +1248,47 @@ const gchar*const* aui_service_dialog_get_browse_service_types(AuiServiceDialog return (const char* const*) d->priv->browse_service_types; } +void aui_service_dialog_set_service_type_name(AuiServiceDialog *d, const gchar *type, const gchar *name) { + GtkTreeModel *m = NULL; + GtkTreeIter iter; + + g_return_if_fail(AUI_IS_SERVICE_DIALOG(d)); + g_return_if_fail(NULL != type); + g_return_if_fail(NULL != name); + + if (NULL == d->priv->service_type_names) + d->priv->service_type_names = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + + g_hash_table_insert(d->priv->service_type_names, g_strdup(type), g_strdup(name)); + + if (d->priv->service_list_store) + m = GTK_TREE_MODEL(d->priv->service_list_store); + + if (m && gtk_tree_model_get_iter_first(m, &iter)) { + do { + char *stored_type = NULL; + + gtk_tree_model_get(m, &iter, SERVICE_COLUMN_TYPE, &stored_type, -1); + + if (stored_type && g_str_equal(stored_type, type)) + gtk_list_store_set(d->priv->service_list_store, &iter, SERVICE_COLUMN_PRETTY_TYPE, name, -1); + } while (gtk_tree_model_iter_next(m, &iter)); + } +} + void aui_service_dialog_set_domain(AuiServiceDialog *d, const char *domain) { g_return_if_fail(AUI_IS_SERVICE_DIALOG(d)); g_return_if_fail(!domain || is_valid_domain_suffix(domain)); g_free(d->priv->domain); d->priv->domain = domain ? avahi_normalize_name_strdup(domain) : NULL; - + restart_browsing(d); } const char* aui_service_dialog_get_domain(AuiServiceDialog *d) { g_return_val_if_fail(AUI_IS_SERVICE_DIALOG(d), NULL); - + return d->priv->domain; } @@ -1306,7 +1348,7 @@ const AvahiStringList *aui_service_dialog_get_txt_data(AuiServiceDialog *d) { void aui_service_dialog_set_resolve_service(AuiServiceDialog *d, gboolean resolve) { g_return_if_fail(AUI_IS_SERVICE_DIALOG(d)); - + d->priv->resolve_service = resolve; } @@ -1318,7 +1360,7 @@ gboolean aui_service_dialog_get_resolve_service(AuiServiceDialog *d) { void aui_service_dialog_set_resolve_host_name(AuiServiceDialog *d, gboolean resolve) { g_return_if_fail(AUI_IS_SERVICE_DIALOG(d)); - + d->priv->resolve_host_name = resolve; } @@ -1343,7 +1385,7 @@ AvahiProtocol aui_service_dialog_get_address_family(AuiServiceDialog *d) { static void aui_service_dialog_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { AuiServiceDialog *d = AUI_SERVICE_DIALOG(object); - + switch (prop_id) { case PROP_BROWSE_SERVICE_TYPES: aui_service_dialog_set_browse_service_typesv(d, g_value_get_pointer(value)); @@ -1360,7 +1402,7 @@ static void aui_service_dialog_set_property(GObject *object, guint prop_id, cons case PROP_SERVICE_NAME: aui_service_dialog_set_service_name(d, g_value_get_string(value)); break; - + case PROP_RESOLVE_SERVICE: aui_service_dialog_set_resolve_service(d, g_value_get_boolean(value)); break; @@ -1372,7 +1414,7 @@ static void aui_service_dialog_set_property(GObject *object, guint prop_id, cons case PROP_ADDRESS_FAMILY: aui_service_dialog_set_address_family(d, g_value_get_int(value)); break; - + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -1381,7 +1423,7 @@ static void aui_service_dialog_set_property(GObject *object, guint prop_id, cons static void aui_service_dialog_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { AuiServiceDialog *d = AUI_SERVICE_DIALOG(object); - + switch (prop_id) { case PROP_BROWSE_SERVICE_TYPES: g_value_set_pointer(value, (gpointer) aui_service_dialog_get_browse_service_types(d)); @@ -1410,11 +1452,11 @@ static void aui_service_dialog_get_property(GObject *object, guint prop_id, GVal case PROP_HOST_NAME: g_value_set_string(value, aui_service_dialog_get_host_name(d)); break; - + case PROP_TXT_DATA: g_value_set_pointer(value, (gpointer) aui_service_dialog_get_txt_data(d)); break; - + case PROP_RESOLVE_SERVICE: g_value_set_boolean(value, aui_service_dialog_get_resolve_service(d)); break; @@ -1426,10 +1468,9 @@ static void aui_service_dialog_get_property(GObject *object, guint prop_id, GVal case PROP_ADDRESS_FAMILY: g_value_set_int(value, aui_service_dialog_get_address_family(d)); break; - + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } } - diff --git a/avahi-ui/avahi-ui.h b/avahi-ui/avahi-ui.h index 269f148..eee0b34 100644 --- a/avahi-ui/avahi-ui.h +++ b/avahi-ui/avahi-ui.h @@ -5,17 +5,17 @@ /*** This file is part of avahi. - + avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - + avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -45,7 +45,7 @@ typedef struct _AuiServiceDialogClass AuiServiceDialogClass; struct _AuiServiceDialogClass { GtkDialogClass parent_class; - + /* Padding for future expansion */ void (*_aui_reserved1)(void); void (*_aui_reserved2)(void); @@ -95,6 +95,8 @@ void aui_service_dialog_set_browse_service_types(AuiServiceDialog *d, const gcha void aui_service_dialog_set_browse_service_typesv(AuiServiceDialog *d, const gchar *const*type); /** Return the service types currently browsed for. i.e. what was previously set with aui_service_dialog_set_browse_service_types() */ const gchar*const* aui_service_dialog_get_browse_service_types(AuiServiceDialog *d); +/** Overwrite the pretty name shown in the service type column. \since 0.6.22 */ +void aui_service_dialog_set_service_type_name(AuiServiceDialog *d, const gchar *type, const gchar *name); /** @} */ @@ -180,5 +182,3 @@ AvahiProtocol aui_service_dialog_get_address_family(AuiServiceDialog *d); G_END_DECLS #endif - - diff --git a/avahi-ui/bssh.c b/avahi-ui/bssh.c index 32b0ccb..54c7dd9 100644 --- a/avahi-ui/bssh.c +++ b/avahi-ui/bssh.c @@ -42,7 +42,12 @@ int main(int argc, char*argv[]) { gtk_init(&argc, &argv); - if (g_str_has_suffix(argv[0], "bvnc")) { + if (g_str_has_suffix(argv[0], "bshell")) { + d = aui_service_dialog_new("Choose Shell Server", NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL); + aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", "_ssh._tcp", NULL); + aui_service_dialog_set_service_type_name(AUI_SERVICE_DIALOG(d), "_rfb._tcp", "Desktop"); + aui_service_dialog_set_service_type_name(AUI_SERVICE_DIALOG(d), "_ssh._tcp", "Terminal"); + } else if (g_str_has_suffix(argv[0], "bvnc")) { d = aui_service_dialog_new("Choose VNC server", NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL); aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", NULL); } else { @@ -59,7 +64,7 @@ int main(int argc, char*argv[]) { char a[AVAHI_ADDRESS_STR_MAX], *u = NULL, *n = NULL; char *h = NULL, *t = NULL; const AvahiStringList *txt; - + t = g_strdup(aui_service_dialog_get_service_type(AUI_SERVICE_DIALOG(d))); n = g_strdup(aui_service_dialog_get_service_name(AUI_SERVICE_DIALOG(d))); @@ -136,5 +141,4 @@ int main(int argc, char*argv[]) { } return 1; - }