~charlesk/libappindicator/fix-vala-examples

« back to all changes in this revision

Viewing changes to src/app-indicator.c

  • Committer: Ted Gould
  • Date: 2012-03-06 22:54:21 UTC
  • mfrom: (228.2.3 lp875770)
  • Revision ID: ted@gould.cx-20120306225421-i2jubg4lhwsde715
Look for files and don't use those as icon names in the fallback

Show diffs side-by-side

added added

removed removed

Lines of Context:
1582
1582
status_icon_changes (AppIndicator * self, gpointer data)
1583
1583
{
1584
1584
        GtkStatusIcon * icon = GTK_STATUS_ICON(data);
1585
 
        gchar *longname = NULL;
1586
 
 
1587
 
        /* add the icon_theme_path once if needed */
1588
 
        GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
1589
 
        if (self->priv->icon_theme_path != NULL)
1590
 
        {
1591
 
                gchar **path;
1592
 
                gint n_elements, i;
1593
 
                gboolean found=FALSE;
1594
 
                gtk_icon_theme_get_search_path(icon_theme, &path, &n_elements);
1595
 
                for (i=0; i< n_elements || path[i] == NULL; i++)
1596
 
                {
1597
 
                        if(g_strcmp0(path[i], self->priv->icon_theme_path) == 0)
1598
 
                        {
1599
 
                                found=TRUE;
1600
 
                                break;
1601
 
                        }
1602
 
                }
1603
 
                if(!found) 
1604
 
                        gtk_icon_theme_append_search_path(icon_theme, self->priv->icon_theme_path);
1605
 
                g_strfreev (path);
1606
 
        }
1607
 
 
 
1585
 
 
1586
        /* add the icon_theme_path once if needed */
 
1587
        GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
 
1588
        if (self->priv->icon_theme_path != NULL) {
 
1589
                gchar **path;
 
1590
                gint n_elements, i;
 
1591
                gboolean found=FALSE;
 
1592
                gtk_icon_theme_get_search_path(icon_theme, &path, &n_elements);
 
1593
                for (i=0; i< n_elements || path[i] == NULL; i++) {
 
1594
                        if(g_strcmp0(path[i], self->priv->icon_theme_path) == 0) {
 
1595
                                found=TRUE;
 
1596
                                break;
 
1597
                        }
 
1598
                }
 
1599
                if(!found) {
 
1600
                        gtk_icon_theme_append_search_path(icon_theme, self->priv->icon_theme_path);
 
1601
                }
 
1602
                g_strfreev (path);
 
1603
        }
 
1604
 
 
1605
        const gchar * icon_name = NULL;
1608
1606
        switch (app_indicator_get_status(self)) {
1609
1607
        case APP_INDICATOR_STATUS_PASSIVE:
1610
 
                /* hide first to avoid that the change is visible to the user */
1611
 
                gtk_status_icon_set_visible(icon, FALSE);
1612
 
                longname = append_panel_icon_suffix(app_indicator_get_icon(self));
1613
 
                if (gtk_icon_theme_has_icon (icon_theme, longname))
1614
 
                         gtk_status_icon_set_from_icon_name(icon, longname);
1615
 
                else
1616
 
                         gtk_status_icon_set_from_icon_name(icon, app_indicator_get_icon(self));
 
1608
                /* hide first to avoid that the change is visible to the user */
 
1609
                gtk_status_icon_set_visible(icon, FALSE);
 
1610
                icon_name = app_indicator_get_icon(self);
1617
1611
                break;
1618
1612
        case APP_INDICATOR_STATUS_ACTIVE:
1619
 
                longname = append_panel_icon_suffix(app_indicator_get_icon(self));
1620
 
                if (gtk_icon_theme_has_icon (icon_theme, longname))
1621
 
                         gtk_status_icon_set_from_icon_name(icon, longname);
1622
 
                else
1623
 
                         gtk_status_icon_set_from_icon_name(icon, app_indicator_get_icon(self));
 
1613
                icon_name = app_indicator_get_icon(self);
1624
1614
                gtk_status_icon_set_visible(icon, TRUE);
1625
1615
                break;
1626
1616
        case APP_INDICATOR_STATUS_ATTENTION:
1627
 
                /* get the _attention_ icon here */
1628
 
                longname = append_panel_icon_suffix(app_indicator_get_attention_icon(self));
1629
 
                if (gtk_icon_theme_has_icon (icon_theme, longname))
1630
 
                         gtk_status_icon_set_from_icon_name(icon, longname);
1631
 
                else
1632
 
                         gtk_status_icon_set_from_icon_name(icon, app_indicator_get_icon(self));
 
1617
                /* get the _attention_ icon here */
 
1618
                icon_name = app_indicator_get_attention_icon(self);
1633
1619
                gtk_status_icon_set_visible(icon, TRUE);
1634
1620
                break;
1635
1621
        };
1636
1622
 
1637
 
        if (longname) {
1638
 
                g_free(longname);
 
1623
        if (icon_name != NULL) {
 
1624
                if (g_file_test(icon_name, G_FILE_TEST_EXISTS)) {
 
1625
                        gtk_status_icon_set_from_file(icon, icon_name);
 
1626
                } else {
 
1627
                        gchar *longname = append_panel_icon_suffix(icon_name);
 
1628
 
 
1629
                        if (longname != NULL && gtk_icon_theme_has_icon (icon_theme, longname)) {
 
1630
                                gtk_status_icon_set_from_icon_name(icon, longname);
 
1631
                        } else {
 
1632
                                gtk_status_icon_set_from_icon_name(icon, icon_name);
 
1633
                        }
 
1634
 
 
1635
                        g_free(longname);
 
1636
                }
1639
1637
        }
1640
1638
 
1641
1639
        return;