Remove sqlite3 build dep.
[gmpc.git] / src / Tools / gmpc-liststore-sort.vala
blob91206f78406b1d852b8b1a4c1b6ed55c262bef0e
1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
3 * Project homepage: http://gmpclient.org/
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 /**
21 * This gob file provides a hack, so rows in a gtk_list_store can be moved, (with gtk_tree_reorderable enabled)
22 * While the gtk_tree_row_reference stays in tracked.
25 using Gtk;
27 namespace Gmpc
29 namespace Tools
31 public class ListstoreSort : Gtk.ListStore, Gtk.TreeDragSource ,Gtk.TreeDragDest
33 private const bool use_transition = Gmpc.use_transition;
35 private
36 bool row_draggable (Gtk.TreePath path)
38 return true;
40 private
41 bool drag_data_get (Gtk.TreePath path, Gtk.SelectionData selection_data)
43 return false;
46 private
47 bool drag_data_delete (Gtk.TreePath path)
49 return true;
51 private
52 bool drag_data_received(Gtk.TreePath dest, Gtk.SelectionData selection_data)
54 Gtk.TreeModel model;
55 Gtk.TreePath path = null;
57 if(dest == null )
59 return false;
61 if(Gtk.tree_get_row_drag_data(selection_data, out model, out path))
63 Gtk.TreeIter dest_iter, source_iter;
64 var dest_v = model.get_iter(out dest_iter, dest);
65 var source_v = model.get_iter(out source_iter, path);
66 if(source_v)
68 if(dest_v)
69 this.move_before(ref source_iter, dest_iter);
70 else
71 this.move_before(ref source_iter, null);
73 return true;
75 return false;
77 private
78 bool row_drop_possible (Gtk.TreePath dest_path, Gtk.SelectionData data)
80 if(dest_path != null)
82 Gtk.TreePath path = null;
83 Gtk.TreeModel model = null;
84 if(Gtk.tree_get_row_drag_data(data, out model, out path))
86 Gtk.TreeIter iter;
87 int source = -1;
88 int dest = -1;
89 if(model.get_iter(out iter, path))
91 model.get(iter, 4, out source);
92 if(model.get_iter(out iter, dest_path))
94 model.get(iter, 4, out dest);
95 // only in current category, and not above the separator!!!
96 if(source/1000 == dest/1000 && dest%1000 != 0)
98 return true;
105 return false;