~ted/libdbusmenu/no-spam-for-seb

« back to all changes in this revision

Viewing changes to libdbusmenu-glib/server.c

Adding support to track icon theme directories

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
 
60
60
        DbusmenuTextDirection text_direction;
61
61
        DbusmenuStatus status;
 
62
        GStrv icon_dirs;
62
63
 
63
64
        GArray * prop_array;
64
65
        guint property_idle;
84
85
        PROP_ROOT_NODE,
85
86
        PROP_VERSION,
86
87
        PROP_TEXT_DIRECTION,
87
 
        PROP_STATUS
 
88
        PROP_STATUS,
 
89
        PROP_ICON_THEME_DIRS
88
90
};
89
91
 
90
92
/* Errors */
368
370
 
369
371
        default_text_direction(self);
370
372
        priv->status = DBUSMENU_STATUS_NORMAL;
 
373
        priv->icon_dirs = NULL;
371
374
 
372
375
        return;
373
376
}
425
428
static void
426
429
dbusmenu_server_finalize (GObject *object)
427
430
{
 
431
        DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(object);
 
432
 
 
433
        if (priv->icon_dirs != NULL) {
 
434
                g_strfreev(priv->icon_dirs);
 
435
                priv->icon_dirs = NULL;
 
436
        }
 
437
 
428
438
        G_OBJECT_CLASS (dbusmenu_server_parent_class)->finalize (object);
429
439
        return;
430
440
}
744
754
                return g_variant_new_uint32(DBUSMENU_VERSION_NUMBER);
745
755
        } else if (g_strcmp0(property, "TextDirection") == 0) {
746
756
                return g_variant_new_string(dbusmenu_text_direction_get_nick(priv->text_direction));
 
757
        } else if (g_strcmp0(property, "IconThemePath") == 0) {
 
758
                GVariant * dirs = NULL;
 
759
 
 
760
                if (priv->icon_dirs != NULL) {
 
761
                        dirs = g_variant_new_strv((const gchar * const *)priv->icon_dirs, -1);
 
762
                } else {
 
763
                        dirs = g_variant_new_array(G_VARIANT_TYPE_STRING, NULL, 0);
 
764
                }
 
765
 
 
766
                return dirs;
747
767
        } else if (g_strcmp0(property, "Status") == 0) {
748
768
                return g_variant_new_string(dbusmenu_status_get_nick(priv->status));
749
769
        } else {
1706
1726
 
1707
1727
        return;
1708
1728
}
 
1729
 
 
1730
/**
 
1731
 * dbusmenu_server_get_icon_paths:
 
1732
 * @server: The #DbusmenuServer to get the icon paths from
 
1733
 * 
 
1734
 * Gets the stored and exported icon paths from the server.
 
1735
 * 
 
1736
 * Return value: (transfer none): A NULL-terminated list of icon paths with
 
1737
 *   memory managed by the server.  Duplicate if you want
 
1738
 *   to keep them.
 
1739
 */
 
1740
const GStrv
 
1741
dbusmenu_server_get_icon_paths (DbusmenuServer * server)
 
1742
{
 
1743
        g_return_val_if_fail(DBUSMENU_IS_SERVER(server), NULL);
 
1744
        DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server);
 
1745
        return priv->icon_dirs;
 
1746
}
 
1747
 
 
1748
/**
 
1749
        dbusmenu_server_set_icon_paths:
 
1750
        @server: The #DbusmenuServer to set the icon paths on
 
1751
 
 
1752
        Sets the icon paths for the server.  This will replace previously
 
1753
        set icon theme paths.
 
1754
*/
 
1755
void
 
1756
dbusmenu_server_set_icon_paths (DbusmenuServer * server, GStrv icon_paths)
 
1757
{
 
1758
        g_return_if_fail(DBUSMENU_IS_SERVER(server));
 
1759
        DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server);
 
1760
 
 
1761
        if (priv->icon_dirs != NULL) {
 
1762
                g_strfreev(priv->icon_dirs);
 
1763
                priv->icon_dirs = NULL;
 
1764
        }
 
1765
 
 
1766
        if (icon_paths != NULL) {
 
1767
                priv->icon_dirs = g_strdupv(icon_paths);
 
1768
        }
 
1769
 
 
1770
        if (priv->bus != NULL && priv->dbusobject != NULL) {
 
1771
                GVariantBuilder params;
 
1772
                g_variant_builder_init(&params, G_VARIANT_TYPE_TUPLE);
 
1773
                g_variant_builder_add_value(&params, g_variant_new_string(DBUSMENU_INTERFACE));
 
1774
                GVariant * items = NULL;
 
1775
                if (priv->icon_dirs != NULL) {
 
1776
                        GVariant * dict = g_variant_new_dict_entry(g_variant_new_string("IconThemePath"), g_variant_new_strv((const gchar * const *)priv->icon_dirs, -1));
 
1777
                        items = g_variant_new_array(NULL, &dict, 1);
 
1778
                } else {
 
1779
                        items = g_variant_new_array(G_VARIANT_TYPE("{sv}"), NULL, 0);
 
1780
                }
 
1781
                g_variant_builder_add_value(&params, items);
 
1782
                g_variant_builder_add_value(&params, g_variant_new_array(G_VARIANT_TYPE_STRING, NULL, 0));
 
1783
                GVariant * vparams = g_variant_builder_end(&params);
 
1784
 
 
1785
                g_dbus_connection_emit_signal(priv->bus,
 
1786
                                              NULL,
 
1787
                                              priv->dbusobject,
 
1788
                                              "org.freedesktop.DBus.Properties",
 
1789
                                              "PropertiesChanged",
 
1790
                                              vparams,
 
1791
                                              NULL);
 
1792
        }
 
1793
 
 
1794
        return;
 
1795
}