~cahr-gr/gloobus-preview/monitors

« back to all changes in this revision

Viewing changes to src/gloobus-preview-interface-music.cpp

  • Committer: Jordi Puigdellívol
  • Date: 2010-05-26 14:35:12 UTC
  • mfrom: (213.1.33 gloobus-preview)
  • Revision ID: jordi@badchoice-20100526143512-bhndzc2y7o8un30v
Merged, now its really good

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "gloobus-preview-interface-music.h"
2
 
 
 
2
/*
3
3
// =========================== ~iMUSIC ======================================== //
 
4
iMusic::iMusic()
 
5
        :playing(false)
 
6
{
 
7
        g_debug("Creating iMusic");
 
8
}
4
9
iMusic::~iMusic()
5
10
{
6
11
        g_debug("Destroying iMusic");
7
 
        g_source_remove(m_timeout_id);
8
 
    g_object_unref(m_pixbuf);
9
 
    g_object_unref(m_reflection);
 
12
        g_source_remove(timeout_id);
 
13
    g_object_unref(cover);
 
14
    g_object_unref(reflection);
 
15
    g_object_unref(pix_play);
 
16
    g_object_unref(pix_pause);
10
17
}
11
18
 
12
19
// =============================== LOAD ======================================= //
14
21
{
15
22
        g_debug("Loading iMusic");
16
23
    GdkPixbuf* temp = get_pixbuf();
17
 
        m_pixbuf = scale_pixbuf(temp,ICON_SIZE,ICON_SIZE);              //Scales the cover to normal 200x200 max
18
 
        m_reflection = pixbuf_reflection(m_pixbuf);                                             //Creates the reflection Pixbuf
19
 
    g_object_unref(temp);
20
 
        m_playing = true;
 
24
        pix_cover = ui->pixbuf_scale(temp,ICON_SIZE,ICON_SIZE, true);
 
25
        pix_reflection = ui->pixbuf_reflect(pix_cover);
 
26
        g_object_unref(temp);
21
27
 
 
28
        string path;
 
29
        path = (string)PACKAGE_DATA_PATH + "/media-play.svg";
 
30
        pix_play = gdk_pixbuf_new_from_file(path.c_str(), NULL);
 
31
        path = (string)PACKAGE_DATA_PATH + "/media-pause.svg";
 
32
        pix_pause = gdk_pixbuf_new_from_file(path.c_str(), NULL);
22
33
        return true;
23
34
}
24
35
// =============================== END ======================================= //
28
39
        stop();
29
40
}
30
41
 
31
 
int     iMusic::get_width               ( void ){return 450;}
32
 
int iMusic::get_height          ( void ){return 280;}
 
42
int     iMusic::get_width( void )
 
43
{
 
44
        return 450;
 
45
}
 
46
int iMusic::get_height( void )
 
47
{
 
48
        return ICON_SIZE*2+TOOLBAR_HEIGHT;
 
49
}
33
50
 
34
51
// ================================== DRAW  =================================== //
35
52
void iMusic::draw (GtkContainer * container)
36
53
{
37
 
        draw_cover              ( GTK_CONTAINER(container ));
38
 
        draw_file_info  ( GTK_CONTAINER(container ));
39
 
        draw_controls   ( GTK_CONTAINER(container ));
 
54
        cover           = gtk_image_new_from_pixbuf (pix_cover);
 
55
        reflection      = gtk_image_new_from_pixbuf (pix_reflection);
 
56
        gtk_fixed_put(GTK_FIXED(container),cover, 25, 50);
 
57
        gtk_fixed_put(GTK_FIXED(container),reflection,25, 50 + ICON_SIZE);
 
58
 
 
59
        string text = get_song_name() + "\n\n" + get_song_artist() + "\n\n" + get_song_album();
 
60
        draw_properties ( container, text, 200 , 75 );
 
61
        
 
62
        draw_controls(container);
 
63
        
 
64
        playing = true;
40
65
        play();
41
 
        m_timeout_id = g_timeout_add (50, &iMusic::trick2, this);                               //Get new position
42
 
}
43
 
 
44
 
// =========================== DRAW IMAGE ================================= //
45
 
void iMusic::draw_cover(GtkContainer * container)
46
 
{
47
 
 
48
 
        GtkWidget *image                                = gtk_image_new_from_pixbuf (m_pixbuf);
49
 
        GtkWidget *image_container              = gtk_fixed_new ();
50
 
        GtkWidget *reflection                   = gtk_image_new_from_pixbuf (m_reflection);
51
 
        GtkWidget *reflection_container = gtk_fixed_new ();
52
 
 
53
 
        int x = SHADOW_WIDTH;                   //Default values are at top left
54
 
        int y = HEADER_HEIGHT + SHADOW_WIDTH;                   //and 20 from top (For the header)
55
 
 
56
 
        if(gdk_pixbuf_get_width(m_pixbuf) < 300)                //Minum width
57
 
        {
58
 
                x = (150 + SHADOW_WIDTH ) - gdk_pixbuf_get_width(m_pixbuf)/2;
59
 
        }
60
 
        if(gdk_pixbuf_get_height(m_pixbuf) < 300)               //Minium height
61
 
        {
62
 
                y = (150 + SHADOW_WIDTH + HEADER_HEIGHT) - gdk_pixbuf_get_height(m_pixbuf)/2;
63
 
        }
64
 
 
65
 
 
66
 
        gtk_fixed_put           (GTK_FIXED(image_container),image,25+SHADOW_WIDTH, 50 + SHADOW_WIDTH + HEADER_HEIGHT);
67
 
        gtk_fixed_put           (GTK_FIXED(reflection_container),reflection,25+SHADOW_WIDTH, 50 + SHADOW_WIDTH + HEADER_HEIGHT + gdk_pixbuf_get_height(m_pixbuf));
68
 
        gtk_container_add       (GTK_CONTAINER(container),image_container);
69
 
        gtk_container_add       (GTK_CONTAINER(container),reflection_container);
70
 
        gtk_widget_show         (image_container);
71
 
        gtk_widget_show         (image);
72
 
        gtk_widget_show         (reflection_container);
73
 
        gtk_widget_show         (reflection);
74
 
 
75
 
};
76
 
 
77
 
 
78
 
// ================================== DRAW FILE INFO =================================== //
79
 
void iMusic::draw_file_info(GtkContainer * container)
80
 
{
81
 
        string text = get_song_name() + "\n\n" + get_song_artist() + "\n\n" + get_song_album();
82
 
        draw_properties ( container, text, 200 , 75 + SHADOW_WIDTH + HEADER_HEIGHT);
83
 
 
84
 
}
 
66
        timeout_id = g_timeout_add (200, &iMusic::draw_position, this);
 
67
 
 
68
        gtk_widget_show_all( GTK_WIDGET(container) );
 
69
}
 
70
 
85
71
// ================================== DRAW CONTROLS =================================== //
86
72
void iMusic::draw_controls(GtkContainer * container)
87
73
{
88
74
                GdkColor color;
89
75
                gdk_color_parse ("white", &color);
90
 
 
91
 
                string buttonstr                = (string)PACKAGE_DATA_PATH + "/media-pause.svg";
92
 
                
93
 
                m_play_pause_button             = gtk_image_new_from_file(buttonstr.c_str());
94
 
                m_event_box                             = gtk_event_box_new();
95
 
                                                                  gtk_event_box_set_visible_window(GTK_EVENT_BOX(m_event_box),false);
96
 
                                                                  gtk_container_add(GTK_CONTAINER(m_event_box),m_play_pause_button);
97
 
 
98
 
                m_duration_label                = gtk_label_new("--:--");
99
 
                m_current_time_label    = gtk_label_new("00:00");
100
 
 
101
 
                //Set white color to labels
102
 
                gtk_widget_modify_fg (m_duration_label, GTK_STATE_NORMAL, &color);
103
 
                gtk_widget_modify_fg (m_current_time_label, GTK_STATE_NORMAL, &color);
104
 
 
105
 
                //m_adjustment = gtk_adjustment_new (0, 0, 101, 1, 5, 25);
106
 
        //m_scale = gtk_hscale_new (GTK_ADJUSTMENT (m_adjustment));
107
 
                m_scale = gtk_hscale_new_with_range             (0, 100, 1);
108
 
                gtk_scale_set_draw_value                                (GTK_SCALE(m_scale), false);                    //Do not draw the numbers
109
 
 
110
 
                GtkWidget * vbox = gtk_vbox_new         (false,3);
111
 
                GtkWidget * hbox = gtk_hbox_new         (false,3);
112
 
                GtkWidget * hbox2 = gtk_hbox_new        (false,3);
113
 
 
114
 
 
115
 
                gtk_box_pack_end        (GTK_BOX (hbox), m_event_box            ,               true,   false,  2);
116
 
                gtk_box_pack_start      (GTK_BOX (hbox2), m_current_time_label,         false,  false,  2);
117
 
                gtk_box_pack_start      (GTK_BOX (hbox2), m_scale,                                      true,   true,   2);
118
 
        gtk_box_pack_end        (GTK_BOX (hbox2), m_duration_label,             false,  false,  2);
119
 
                gtk_box_pack_start      (GTK_BOX (vbox), hbox,                                          false,  false,  2);
120
 
                gtk_box_pack_end        (GTK_BOX (vbox), hbox2,                                         true,   true,   2);
121
 
                
122
 
                
123
 
        
124
 
                gtk_fixed_put                   ( GTK_FIXED(container),vbox, 25 , get_height() -5 );
125
 
            gtk_widget_set_usize        ( hbox, get_width()-20,  35);                   
126
 
                gtk_widget_show_all             ( vbox );
 
76
                
 
77
                button                  = gtk_image_new_from_pixbuf(pix_pause);
 
78
                button_box      = gtk_event_box_new();
 
79
                gtk_event_box_set_visible_window(GTK_EVENT_BOX(button_box),false);
 
80
                gtk_container_add(GTK_CONTAINER(button_box),button);
 
81
 
 
82
                gtk_fixed_put( GTK_FIXED(container),button_box, get_width()/2-16 , get_height()-80 );
 
83
 
 
84
                duration                = gtk_label_new("--:--");
 
85
                current_time    = gtk_label_new("00:00");
 
86
                gtk_widget_modify_fg (duration, GTK_STATE_NORMAL, &color);
 
87
                gtk_widget_modify_fg (current_time, GTK_STATE_NORMAL, &color);
 
88
                seekbar = gtk_hscale_new_with_range             (0, 100, 1);
 
89
                gtk_scale_set_draw_value                                (GTK_SCALE(seekbar), false); //Do not draw the numbers
 
90
 
 
91
                hbox = gtk_hbox_new     (false,3);
 
92
                gtk_widget_set_size_request( hbox, get_width(),  35);
 
93
                gtk_box_pack_start(GTK_BOX (hbox), current_time , false, false, 2);
 
94
                gtk_box_pack_start(GTK_BOX (hbox), seekbar              , true, true, 2);
 
95
                gtk_box_pack_start(GTK_BOX (hbox), duration             , false, false, 2);
 
96
                gtk_fixed_put( GTK_FIXED(container),hbox, 0 , get_height() - 35 );
 
97
                gtk_widget_show_all( hbox );
127
98
 
128
99
                //When the seek bar is moved, change the position
129
 
                g_signal_connect (G_OBJECT (m_scale),           "change-value",                 G_CALLBACK (&iMusic::trick),                    this);
130
 
                g_signal_connect (G_OBJECT (m_event_box),       "button-press-event",   G_CALLBACK (&iMusic::play_pause_trick), this);
131
 
}
132
 
 
133
 
// ================================== DRAW POSITION =================================== //
134
 
// Request the postion to the plugin and puts the range to this new position
135
 
void iMusic::draw_position( void )
136
 
{
137
 
        //g_debug("POSITION => %f\n", get_position());
138
 
        gtk_range_set_value (GTK_RANGE (m_scale), get_position());
139
 
        //g_debug("DURATION => %s\n", get_duration().c_str());
140
 
        gtk_label_set_text (GTK_LABEL(m_duration_label)         ,get_duration().c_str()         );
141
 
        gtk_label_set_text (GTK_LABEL(m_current_time_label)     ,get_current_time().c_str()     );
142
 
}
143
 
 
 
100
                g_signal_connect (G_OBJECT (seekbar), "change-value",
 
101
                        G_CALLBACK (&iMusic::seekbar_change_cb), this);
 
102
                g_signal_connect (G_OBJECT (seekbar), "button-press-event",
 
103
                        G_CALLBACK (&iMusic::seekbar_press_cb), this);
 
104
                g_signal_connect (G_OBJECT (seekbar), "button-release-event",
 
105
                        G_CALLBACK (&iMusic::seekbar_release_cb), this);
 
106
                g_signal_connect (G_OBJECT (button_box), "button-press-event",
 
107
                        G_CALLBACK (&iMusic::button_play_pause), this);
 
108
}
144
109
 
145
110
//============================== PLAY PAUSE ========================= //
146
111
void iMusic::play_pause( void )
147
112
{
148
113
        g_debug("Play Pause clicked");
149
 
        //gtk_button_set_label (GTK_BUTTON(m_play_pause_button) ,"JOJO" );
150
114
                
151
 
        if(m_playing)
152
 
        { 
 
115
        if(playing) {
153
116
                pause();
154
 
                string buttonstr                = (string)PACKAGE_DATA_PATH + "/media-play.svg";
155
 
                gtk_image_set_from_file(GTK_IMAGE(m_play_pause_button),buttonstr.c_str() );
156
 
                m_playing = false;
157
 
        }
158
 
        else            
159
 
        { 
 
117
                gtk_image_set_from_pixbuf(GTK_IMAGE(button) , pix_play );
 
118
                playing = false;
 
119
        } else {
160
120
                play();
161
 
                string buttonstr                = (string)PACKAGE_DATA_PATH + "/media-pause.svg";
162
 
                gtk_image_set_from_file(GTK_IMAGE(m_play_pause_button),buttonstr.c_str() );
163
 
                m_playing = true; 
 
121
                gtk_image_set_from_pixbuf(GTK_IMAGE(button) , pix_pause );
 
122
                playing = true;
164
123
        }
165
 
 
166
124
}
167
125
 
168
 
// ====================== FULLSCREEN ================= //
169
 
bool iMusic::can_fullscreen  ( void ){ return false;}                                           //Returns true if the plugin can do fullscreen
170
126
void iMusic::draw_fullscreen ( GtkContainer * container )
171
127
{
 
128
        int x = ( ui->get_screen_width()-get_width() ) / 2;
 
129
        int y = ( ui->get_screen_height()-get_height() ) / 2;
 
130
        gtk_fixed_move( GTK_FIXED(container),cover, x+25, y+50 );
 
131
        gtk_fixed_move( GTK_FIXED(container),reflection,x+25, y+50 + ICON_SIZE );
 
132
        gtk_fixed_move( GTK_FIXED(container),button_box, x+get_width()/2-16 , y+get_height()-80 );
 
133
        gtk_fixed_move( GTK_FIXED(container),hbox, x , y+get_height() - 35 );
 
134
        gtk_fixed_move( GTK_FIXED(container), m_info , x+200 , y+75 );
172
135
}
 
136
 
173
137
void iMusic::draw_unfullscreen ( GtkContainer * container )
174
138
{
175
 
}
176
 
 
177
 
// ============================ DRAW FLOATING CONTROLS ================================ //
178
 
void iMusic::draw_toolbar       ( GtkWidget * container )
179
 
{
180
 
    g_debug("iMusic toolbar buttons\n");
181
 
 
182
 
        draw_default_toolbar(container);
183
 
}
184
 
 
 
139
        gtk_fixed_move( GTK_FIXED(container),cover, 25, 50 );
 
140
        gtk_fixed_move( GTK_FIXED(container),reflection,25, 50 + ICON_SIZE );
 
141
        gtk_fixed_move( GTK_FIXED(container),button_box, get_width()/2-16 , get_height()-80 );
 
142
        gtk_fixed_move( GTK_FIXED(container),hbox, 0 , get_height() - 35 );
 
143
        gtk_fixed_move( GTK_FIXED(container), m_info , 200 , 75 );
 
144
}
 
145
 
 
146
void iMusic::button_play_pause(GtkWidget *widget,
 
147
        GdkEventButton *event,
 
148
        gpointer data)
 
149
{
 
150
        ((iMusic*)data)->play_pause();
 
151
};
 
152
 
 
153
gboolean iMusic::seekbar_press_cb(GtkWidget *widget,
 
154
        GdkEventButton *event,
 
155
        gpointer data)
 
156
{
 
157
        /* HACK: we want the behaviour you get with the middle button, so we
 
158
         * mangle the event.  clicking with other buttons moves the slider in
 
159
         * step increments, clicking with the middle button moves the slider to
 
160
         * the location of the click.
 
161
         * thanks to totem devs :D
 
162
         *//*
 
163
        event->button = 2;
 
164
        return false;
 
165
};
 
166
 
 
167
gboolean iMusic::seekbar_release_cb(GtkWidget *widget,
 
168
        GdkEventButton *event,
 
169
        gpointer data)
 
170
{
 
171
        event->button = 2;
 
172
        return false;
 
173
};
 
174
 
 
175
gboolean iMusic::seekbar_change_cb(GtkRange * range,
 
176
        GtkScrollType scroll,
 
177
        gdouble value,
 
178
        gpointer data)
 
179
{
 
180
        ((iMusic*)data)->seek(value);
 
181
        return false;
 
182
}
 
183
 
 
184
gboolean iMusic::draw_position( gpointer data )
 
185
{
 
186
        iMusic * music = (iMusic*)data;
 
187
        gtk_range_set_value(GTK_RANGE(music->seekbar) , music->get_position());
 
188
        gtk_label_set_text(GTK_LABEL(music->duration), music->get_duration().c_str());
 
189
        gtk_label_set_text(GTK_LABEL(music->current_time), music->get_current_time().c_str());
 
190
        return true;
 
191
}
 
192
*/