~ubuntu-branches/ubuntu/natty/indicator-sound/natty

« back to all changes in this revision

Viewing changes to src/transport-widget.c

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2011-03-23 12:03:02 UTC
  • mfrom: (67.1.23 indicator-sound-ubuntu)
  • Revision ID: james.westby@ubuntu.com-20110323120302-7dv2px8v6pa72a69
Tags: 0.6.5-0ubuntu1
* New upstream release.
  - Media player should be automatically started up when play button is 
    pressed (LP: #714750)
  - volume goes to zero when using some players like banshee or 
    rhythmbox (LP: #730925)
  - handle banshee id change (LP: #737447)
  - filter out video playlists (LP: #739273)

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
  gboolean            has_focus;
86
86
  gint                hold_timer;
87
87
  gint                skip_frequency;
 
88
  gint                launching_timer;
 
89
  gdouble             launching_transparency;
 
90
  gboolean            fade_out;
88
91
};
89
92
 
90
93
// TODO refactor the UI handlers, consolidate functionality between key press /release
136
139
static void transport_widget_start_timing (TransportWidget* widget);
137
140
static gboolean transport_widget_trigger_seek (gpointer userdata);
138
141
static gboolean transport_widget_seek (gpointer userdata);
 
142
static gboolean transport_widget_fade_playbutton (gpointer userdata);
139
143
 
140
144
 
141
145
/// Init functions //////////////////////////////////////////////////////////
168
172
  priv->has_focus = FALSE;
169
173
  priv->hold_timer = 0;
170
174
  priv->skip_frequency = 0;
 
175
  priv->launching_timer = 0;
 
176
  priv->launching_transparency = 1.0f;
 
177
  priv->fade_out = TRUE;
171
178
  priv->command_coordinates =  g_hash_table_new_full(g_direct_hash,
172
179
                                                      g_direct_equal,
173
180
                                                      NULL,
1733
1740
           FALSE);
1734
1741
    _finalize (cr, &cr_surf, &surf, PAUSE_X-0.5f, PAUSE_Y);
1735
1742
  }
 
1743
  else if(priv->current_state == TRANSPORT_STATE_LAUNCHING)
 
1744
  {
 
1745
/*
 
1746
    g_debug ("launching in draw");
 
1747
*/
 
1748
    _setup (&cr_surf, &surf, PLAY_WIDTH+6, PLAY_HEIGHT+6);
 
1749
    _mask_play (cr_surf,
 
1750
                PLAY_PADDING,
 
1751
                PLAY_PADDING,
 
1752
                PLAY_WIDTH - (2*PLAY_PADDING),
 
1753
                PLAY_HEIGHT - (2*PLAY_PADDING));
 
1754
 
 
1755
    double BUTTON_SHADOW_LAUNCHING[] = {color_button[3].r,
 
1756
                                        color_button[3].g,
 
1757
                                        color_button[3].b,
 
1758
                                        priv->launching_transparency};
 
1759
    double BUTTON_LAUNCHING_END[] = {color_button[0].r,
 
1760
                                     color_button[0].g,
 
1761
                                     color_button[0].b,
 
1762
                                     priv->launching_transparency};
 
1763
    double BUTTON_LAUNCHING_START[] = {color_button[1].r,
 
1764
                                       color_button[1].g,
 
1765
                                       color_button[1].b,
 
1766
                                       priv->launching_transparency};
 
1767
    _fill (cr_surf,
 
1768
           PLAY_PADDING,
 
1769
           PLAY_PADDING,
 
1770
           PLAY_WIDTH - (2*PLAY_PADDING),
 
1771
           PLAY_HEIGHT - (2*PLAY_PADDING),
 
1772
           BUTTON_SHADOW_LAUNCHING,
 
1773
           BUTTON_SHADOW_LAUNCHING,
 
1774
           FALSE);
 
1775
    _surface_blur (surf, 3);
 
1776
    _finalize_repaint (cr, &cr_surf, &surf, PAUSE_X-0.5f, PAUSE_Y + 0.5f, 3);
 
1777
    
 
1778
    // draw play-button
 
1779
    _setup (&cr_surf, &surf, PLAY_WIDTH, PLAY_HEIGHT);
 
1780
    cairo_set_line_width (cr, 10.5);
 
1781
    cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
 
1782
    cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND);
 
1783
    _mask_play (cr_surf,
 
1784
                PLAY_PADDING,
 
1785
                PLAY_PADDING,
 
1786
                PLAY_WIDTH - (2*PLAY_PADDING),
 
1787
                PLAY_HEIGHT - (2*PLAY_PADDING));
 
1788
    _fill (cr_surf,
 
1789
           PLAY_PADDING,
 
1790
           PLAY_PADDING,
 
1791
           PLAY_WIDTH - (2*PLAY_PADDING),
 
1792
           PLAY_HEIGHT - (2*PLAY_PADDING),
 
1793
           BUTTON_LAUNCHING_START,
 
1794
           BUTTON_LAUNCHING_END,
 
1795
           FALSE);
 
1796
    _finalize (cr, &cr_surf, &surf, PAUSE_X-0.5f, PAUSE_Y);
 
1797
  }
1736
1798
}
1737
1799
 
1738
1800
static void 
1750
1812
                                       (TransportState)initial_state);
1751
1813
}
1752
1814
 
 
1815
static gboolean
 
1816
transport_widget_fade_playbutton (gpointer userdata)
 
1817
{
 
1818
  TransportWidget* bar = (TransportWidget*)userdata;
 
1819
  g_return_val_if_fail(IS_TRANSPORT_WIDGET(bar), FALSE);
 
1820
/*
 
1821
  g_debug ("fade in /out timeout");
 
1822
*/
 
1823
  TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(bar);
 
1824
  if (priv->launching_transparency == 1.0f){
 
1825
    priv->fade_out = TRUE;
 
1826
  }
 
1827
  else if (priv->launching_transparency <= 0.3F){
 
1828
    priv->fade_out = FALSE;
 
1829
  }
 
1830
  if (priv->fade_out == TRUE){
 
1831
    priv->launching_transparency -= 0.05f;
 
1832
  }
 
1833
  else{
 
1834
    priv->launching_transparency += 0.05f;
 
1835
  }
 
1836
  gtk_widget_queue_draw (GTK_WIDGET(bar));
 
1837
  return TRUE;
 
1838
}
1753
1839
/**
1754
1840
* transport_widget_update_state()
1755
1841
* Callback for updates from the other side of dbus
1761
1847
  //g_debug("transport_widget_update_state - with property  %s", property);
1762
1848
  TransportWidget* bar = (TransportWidget*)userdata;
1763
1849
  g_return_if_fail(IS_TRANSPORT_WIDGET(bar));
 
1850
  TransportWidgetPrivate* priv = TRANSPORT_WIDGET_GET_PRIVATE(bar);
1764
1851
 
1765
1852
  if(g_ascii_strcasecmp(DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE, property) == 0)
1766
1853
  {
1767
 
    int update_value = g_variant_get_int32(value);
1768
 
    //g_debug("transport_widget_update_state - with value  %i", update_value);  
1769
 
    transport_widget_toggle_play_pause(bar, (TransportState)update_value);
 
1854
    TransportState new_state = (TransportState)g_variant_get_int32(value);
 
1855
    //g_debug("transport_widget_update_state - with value  %i", update_value);
 
1856
    if (new_state == TRANSPORT_STATE_LAUNCHING){
 
1857
      priv->current_state = TRANSPORT_STATE_LAUNCHING;
 
1858
      priv->launching_timer = g_timeout_add (100,
 
1859
                                             transport_widget_fade_playbutton,
 
1860
                                             bar);
 
1861
      //g_debug("TransportWidget::toggle play state : %i", priv->current_state);
 
1862
    }
 
1863
    else{
 
1864
      if (priv->launching_timer != 0){
 
1865
        g_source_remove (priv->launching_timer);
 
1866
        priv->launching_timer = 0;
 
1867
        priv->fade_out = TRUE;
 
1868
        priv->launching_transparency = 1.0f;
 
1869
      }
 
1870
      transport_widget_toggle_play_pause(bar, new_state);
 
1871
    }
1770
1872
  }
1771
1873
}
1772
1874