File: dnd.c

package info (click to toggle)
gnomp3 0.1.7-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 488 kB
  • ctags: 342
  • sloc: ansic: 3,285; makefile: 74; awk: 33
file content (190 lines) | stat: -rw-r--r-- 5,041 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
 ** dnd.c - drag and drop code
 **
 ** See GNOME documentation for more details.
 **
 ** Copyright (C) 2000 Matthew Pratt <mattpratt@yahoo.com>
 **
 ** This software is licensed under the terms of the GNU General 
 ** Public License (GPL). Please see the file LICENSE for details.
 **/ 

#include "gnomp3.h"
#include "playlist.h"
#include "song_list.h"
#include "utility.h"
#include "mp3info.h"
#include "mp3_control.h"

static GtkTargetEntry target_table[] = {
         { "text/uri-list", 0, 0 }
};


/* 
 * callback executed when a drop is recieved on the mp3 player. If a file is 
 * described then it is played 
*/
static void  
mp3_control_drop_received  (GtkWidget          *widget,
			    GdkDragContext     *context,
			    gint                x,
			    gint                y,
			    GtkSelectionData   *data,
			    guint               info,
			    guint               time)
{
    static MP3 mp3;

    g_print("Got: %s\n", data->data);
  
    if( !strncmp( data->data, "file:", 5) ){
	data->data += 5;
	g_strstrip(data->data);
	mp3.filename = data->data;
	//mp3_control_unhilight_playing();
	//FIXME mp3play_song(&mp3, 0);
  }

}

/* 
 * callback executed when a drop is recieved on the playlist. If a file is 
 * described then it is added to the playlist 
 */
static void  
playlist_drop_received  (GtkWidget          *widget,
			 GdkDragContext     *context,
			 gint                x,
			 gint                y,
			 GtkSelectionData   *data,
			 guint               info,
			 guint               time)
{
  char *ptr;
  char **tokens;
  int i;
  GList *mp3_node;
  
  g_print("Got: %s\n", data->data);

  tokens = g_strsplit( data->data, "\n", 0 ); 
  
  for( i = 0; tokens[i]; i++ ){
    ptr = tokens[i];
    if( !strncmp( ptr, "file:", 5) ){
      ptr += 5;
      g_strstrip(ptr);
      
      mp3_node = mp3list_search(mp3list, ptr);
      if(mp3_node)
	  playlist_add_row(mp3_node->data);

      /* FIXME what to do with song not in mp3list e.g. from GMC*/
    }
  }

  g_strfreev( tokens );
}

/* 
 * callback executed when a drag is started within one of gnomp3's lists. The
 * selected songs in the list are formed into a URI used for the drop 
 */
static void  
gnomp3_darg_data_get (GtkWidget          *widget,
		      GdkDragContext     *context,
		      GtkSelectionData   *selection_data,
		      guint               info,
		      guint               time,
		      gpointer            data)
{
    char *uri, *old_uri;
    GList *selection;
    GtkCListRow *clist_row;
    MP3 *mp3;
    
    uri = g_strdup("");
    selection = GTK_CLIST(widget)->selection;
    
    while(selection){
	
	if( GTK_IS_CTREE(widget)){
	    clist_row = selection->data;
	    mp3 = GTK_CTREE_ROW(clist_row)->row.data;
	}else if( GTK_IS_CLIST(widget) ){
	    mp3 = gtk_clist_get_row_data( GTK_CLIST(widget),
				      (int)selection->data );
	}else{
	    return;
	}
	
	old_uri = uri;
	uri = g_strconcat( old_uri, "file:", mp3->filename, "\n", NULL );
	g_free (old_uri);
	
	selection = selection->next;
    }
    
    gtk_selection_data_set (selection_data,
			    selection_data->target,
			    8, uri, strlen(uri));
}

/* 
 * initialise and connect all the signals needed to make DragNDrop work 
 */
void gnomp3_dnd_setup()
{

  /* play list drops */
  gtk_drag_dest_set (gnomp3.play_clist,
		     GTK_DEST_DEFAULT_ALL,
		     target_table, 1,
		     GDK_ACTION_COPY);
  gtk_signal_connect (GTK_OBJECT (gnomp3.play_clist), "drag_data_received",
		      GTK_SIGNAL_FUNC (playlist_drop_received),
		      NULL);
  /* mp3 player drops */
  gtk_drag_dest_set (gnomp3.mp3_control_frame,
		     GTK_DEST_DEFAULT_ALL,
		     target_table, 1,
		     GDK_ACTION_COPY);
  gtk_signal_connect (GTK_OBJECT (gnomp3.mp3_control_frame), "drag_data_received",
		      GTK_SIGNAL_FUNC (mp3_control_drop_received),
		      NULL);

  /* other list drags */
  gtk_drag_source_set (gnomp3.song_ctree ,GDK_BUTTON2_MASK,
		       target_table, 1, GDK_ACTION_COPY);
  gtk_signal_connect (GTK_OBJECT (gnomp3.song_ctree), "drag_data_get",
		      GTK_SIGNAL_FUNC (gnomp3_darg_data_get),
		      NULL);
  gtk_drag_source_set (gnomp3.search_clist ,GDK_BUTTON2_MASK,
		       target_table, 1, GDK_ACTION_COPY);
  gtk_signal_connect (GTK_OBJECT (gnomp3.search_clist), "drag_data_get",
		      GTK_SIGNAL_FUNC (gnomp3_darg_data_get),
		      NULL);
  gtk_drag_source_set (gnomp3.all_clist ,GDK_BUTTON2_MASK,
		       target_table, 1, GDK_ACTION_COPY);
  gtk_signal_connect (GTK_OBJECT (gnomp3.all_clist), "drag_data_get",
		      GTK_SIGNAL_FUNC (gnomp3_darg_data_get),
		      NULL);
  gtk_drag_source_set (gnomp3.time_clist ,GDK_BUTTON2_MASK,
		       target_table, 1, GDK_ACTION_COPY);
  gtk_signal_connect (GTK_OBJECT (gnomp3.time_clist), "drag_data_get",
		      GTK_SIGNAL_FUNC (gnomp3_darg_data_get),
		      NULL);
  gtk_drag_source_set (gnomp3.dir_clist ,GDK_BUTTON2_MASK,
		       target_table, 1, GDK_ACTION_COPY);
  gtk_signal_connect (GTK_OBJECT (gnomp3.dir_clist), "drag_data_get",
		      GTK_SIGNAL_FUNC (gnomp3_darg_data_get),
		      NULL);
}