Re-add rating.
[gmpc.git] / src / gmpc-mpddata-model-sort.gob
blobf3c9fed89bd6a5d39e0e188f631f83b8932dda1f
1 /* Gnome Music Player Client (GMPC)
2  * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
3  * Project homepage: http://gmpclient.org/
4  
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 requires 2.0.0
22 %ht{
23 #include <config.h>
24 #include <gtk/gtk.h>
25 #include <libmpd/libmpd.h>
26 #include <libmpd/libmpd-internal.h>
27 #include "gmpc-mpddata-model.h"
28 #include "gmpc-mpddata-model-private.h"
34 class Gmpc:MpdData:Model:Sort from Gmpc:MpdData:Model
35                 (interface Gtk:Tree:Drag:Source)
36                 (interface Gtk:Tree:Drag:Dest)
38                 public gchar *playlist = {NULL} destroywith g_free;
40         property STRING playlist 
41                 (nick = "playlist",
42                 blurb = "The current playlist name",
43                 default_value = NULL, 
44                 export,
45                 link);
48                 interface Gtk:Tree:Drag:Source
49                 private 
50                 gboolean row_draggable (Gtk:Tree:Drag:Source *drag_source, Gtk:Tree:Path *path)
51                 {
52                         if(mpd_server_check_version(connection, 0,13,0))
53                         {
54                                 return TRUE;
55                         }
56                         return FALSE;
57                 }
59                 interface Gtk:Tree:Drag:Source
60                         private 
61                 gboolean drag_data_get (Gtk:Tree:Drag:Source *drag_source, Gtk:Tree:Path *path, Gtk:Selection:Data *selection_data)
62                 {
63                         return FALSE;
64                 }
65                 interface Gtk:Tree:Drag:Source
66                         private 
67                 gboolean drag_data_delete (Gtk:Tree:Drag:Source *drag_source, Gtk:Tree:Path *path) 
68                 {
69                         return TRUE;
70                 }
72                 interface Gtk:Tree:Drag:Dest
73                 private gboolean drag_data_received 
74                                 (Gtk:Tree:Drag:Dest *drag_dest, 
75                                  Gtk:Tree:Path *dest,
76                                  Gtk:Selection:Data *selection_data) 
77                 {
78                         GtkTreePath *path=NULL;
79                         GtkTreeModel *model=NULL;
80                         gint *ind = NULL, *ind2 = NULL;
81             printf("Got drop\n");
82                         if(dest == NULL || !gtk_tree_get_row_drag_data(selection_data, &model, &path))
83                         {
84                                 return FALSE;
85                         }
86                         if(GMPC_MPDDATA_MODEL(model)->num_rows < 2)
87                         {
88                                 gtk_tree_path_free(path);
89                                 return FALSE;
90                         }
91                         ind = gtk_tree_path_get_indices(dest);
92                         ind2 = gtk_tree_path_get_indices(path);
93                         if(ind && ind2 && GMPC_MPDDATA_MODEL_SORT(model)->playlist)
94                         {
95                                 MpdData *data = NULL;
96                                 int original = ind2[0];
97                                 int destination = ind[0];
98                                 /*              if(destination >0 && ind[1] != '\0') destination--; */
99                                 if(destination > original) destination--;
100                                 mpd_database_playlist_move(connection, GMPC_MPDDATA_MODEL_SORT(model)->playlist,original,destination);
101                                 data = mpd_database_get_playlist_content(connection, GMPC_MPDDATA_MODEL_SORT(model)->playlist); 
102                                 gmpc_mpddata_model_set_mpd_data(GMPC_MPDDATA_MODEL(model), data);               
103                         }
104                         gtk_tree_path_free(path);
105                         return TRUE;
106                 }
108                 interface Gtk:Tree:Drag:Dest
109                 private gboolean row_drop_possible 
110                                         (Gtk:Tree:Drag:Dest *drag_dest,
111                                          Gtk:Tree:Path          *dest,
112                                          Gtk:Selection:Data *selection_data)
113                 {
114                         return TRUE;
115                 }
119                 public
120                 Gmpc:MpdData:Model:Sort *new (void)
121                 {
122                         return GET_NEW;
123                 }