Ticket #180: 0002-Add-aui_service_dialog_set_service_type_name-and-re.patch

File 0002-Add-aui_service_dialog_set_service_type_name-and-re.patch, 6.1 kB (added by MathiasHasselmann, 1 year ago)
  • a/avahi-ui/avahi-ui.c

    old new  
    7373    GtkWidget *service_progress_bar; 
    7474 
    7575    GtkListStore *service_list_store, *domain_list_store; 
     76    GHashTable *service_type_names; 
    7677 
    7778    guint service_pulse_timeout; 
    7879    guint domain_pulse_timeout; 
     
    410411 
    411412        case AVAHI_BROWSER_NEW: { 
    412413            gchar *ifs; 
    413             const gchar *pretty_type
     414            const gchar *pretty_type = NULL
    414415            char ifname[IFNAMSIZ]; 
    415416            GtkTreeIter iter; 
    416417            GtkTreeSelection *selection; 
     
    420421 
    421422            ifs = g_strdup_printf("%s %s", ifname, protocol == AVAHI_PROTO_INET ? "IPv4" : "IPv6"); 
    422423 
     424            if (d->priv->service_type_names) 
     425                pretty_type = g_hash_table_lookup (d->priv->service_type_names, type); 
     426 
     427            if (!pretty_type) { 
    423428#if defined(HAVE_GDBM) || defined(HAVE_DBM) 
    424             pretty_type = stdb_lookup(type); 
     429                pretty_type = stdb_lookup(type); 
    425430#else 
    426             pretty_type = type; 
    427 #endif             
     431                pretty_type = type; 
     432#endif 
     433            } 
    428434             
    429435            gtk_list_store_append(d->priv->service_list_store, &iter); 
    430436 
     
    817823    if (d->priv->glib_poll) 
    818824        avahi_glib_poll_free(d->priv->glib_poll); 
    819825 
     826    if (d->priv->service_list_store) 
     827        g_object_unref(d->priv->service_list_store); 
     828    if (d->priv->domain_list_store) 
     829        g_object_unref(d->priv->domain_list_store); 
     830    if (d->priv->service_type_names) 
     831        g_hash_table_unref (d->priv->service_type_names); 
     832 
    820833    g_free(d->priv); 
    821834    d->priv = NULL; 
    822835 
     
    10891102    p->forward_response_id = GTK_RESPONSE_NONE; 
    10901103 
    10911104    p->service_list_store = p->domain_list_store = NULL; 
     1105    p->service_type_names = NULL; 
    10921106     
    10931107    gtk_widget_push_composite_child(); 
    10941108 
     
    12361250    return (const char* const*) d->priv->browse_service_types; 
    12371251} 
    12381252 
     1253void aui_service_dialog_set_service_type_name(AuiServiceDialog *d, const gchar *type, const gchar *name) { 
     1254    GtkTreeModel *m = NULL; 
     1255    GtkTreeIter iter; 
     1256 
     1257    g_return_if_fail(AUI_IS_SERVICE_DIALOG(d)); 
     1258    g_return_if_fail(NULL != type); 
     1259    g_return_if_fail(NULL != name); 
     1260 
     1261    if (NULL == d->priv->service_type_names) 
     1262        d->priv->service_type_names = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); 
     1263 
     1264    g_hash_table_insert(d->priv->service_type_names, g_strdup(type), g_strdup(name)); 
     1265 
     1266    if (d->priv->service_list_store) 
     1267        m = GTK_TREE_MODEL(d->priv->service_list_store); 
     1268 
     1269    if (m && gtk_tree_model_get_iter_first(m, &iter)) { 
     1270        do { 
     1271            char *stored_type = NULL; 
     1272 
     1273            gtk_tree_model_get(m, &iter, SERVICE_COLUMN_TYPE, &stored_type, -1); 
     1274 
     1275            if (stored_type && g_str_equal(stored_type, type)) 
     1276                gtk_list_store_set(d->priv->service_list_store, &iter, SERVICE_COLUMN_PRETTY_TYPE, name, -1); 
     1277        } while (gtk_tree_model_iter_next(m, &iter)); 
     1278    } 
     1279} 
     1280 
    12391281void aui_service_dialog_set_domain(AuiServiceDialog *d, const char *domain) { 
    12401282    g_return_if_fail(AUI_IS_SERVICE_DIALOG(d)); 
    12411283    g_return_if_fail(!domain || is_valid_domain_suffix(domain)); 
  • a/avahi-ui/avahi-ui.h

    old new  
    9595void aui_service_dialog_set_browse_service_typesv(AuiServiceDialog *d, const gchar *const*type); 
    9696/** Return the service types currently browsed for. i.e. what was previously set with aui_service_dialog_set_browse_service_types() */ 
    9797const gchar*const* aui_service_dialog_get_browse_service_types(AuiServiceDialog *d); 
     98void aui_service_dialog_set_service_type_name(AuiServiceDialog *d, const gchar *type, const gchar *name); 
    9899 
    99100/** @} */ 
    100101 
  • a/avahi-ui/bssh.c

    old new  
    4141    GtkWidget *d; 
    4242 
    4343    gtk_init(&argc, &argv); 
    44  
    45     if (g_str_has_suffix(argv[0], "bvnc")) { 
     44g_print ("%s\n", argv[0]); 
     45 
     46    if (g_str_has_suffix(argv[0], "bshell")) { 
     47        d = aui_service_dialog_new("Choose shell server", NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL); 
     48        aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", "_ssh._tcp", NULL); 
     49        aui_service_dialog_set_service_type_name(AUI_SERVICE_DIALOG(d), "_rfb._tcp", "Desktop"); 
     50        aui_service_dialog_set_service_type_name(AUI_SERVICE_DIALOG(d), "_ssh._tcp", "Terminal"); 
     51    } else if (g_str_has_suffix(argv[0], "bvnc")) { 
    4652        d = aui_service_dialog_new("Choose VNC server", NULL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_CONNECT, GTK_RESPONSE_ACCEPT, NULL); 
    4753        aui_service_dialog_set_browse_service_types(AUI_SERVICE_DIALOG(d), "_rfb._tcp", NULL); 
    4854    } else { 
     
    5965        char a[AVAHI_ADDRESS_STR_MAX], *u = NULL, *n = NULL; 
    6066        char *h = NULL, *t = NULL; 
    6167        const AvahiStringList *txt; 
    62          
     68 
    6369        t = g_strdup(aui_service_dialog_get_service_type(AUI_SERVICE_DIALOG(d))); 
    6470        n = g_strdup(aui_service_dialog_get_service_name(AUI_SERVICE_DIALOG(d))); 
    6571