Allow reverting of changes, right mouse -> revert
[gmpc-tagedit.git] / src / gmpc-mpddata-model-tagedit.gob
blobf2825b7dbe45a66034824414da6c5d756f31404a
1 requires 2.0.0
3 %a{
4 #include <gmpc/gmpc-mpddata-model.h>
5 %}
7 %{
8 typedef struct _si {
9     mpd_Song *revert;
10     int changed;
11 }si;
14 /**
15  * This is a Special version of Gmpc:MpdData:Model that is made to show the current playlist, and keep in sync with it.
16  * This is to replace the old playlist-lis backend.
17  * Use this model with Gmpc:MpdData:Treeview
18  */
20 class Gmpc:MpdData:Model:Tagedit from Gmpc:MpdData:Model 
21         (interface Gtk:Tree:Model)
23     public
24     GtkTreeModel *new (void)
25     {
26         Self *self = GET_NEW;
27         return self;
28     }
29      /**
30      * "override" the get_value method, because we need to fetch the value before it's available.
31      * So after we fetch it, let the Gmpc:MpdData:Model handle the hard work again.
32      */
33     interface Gtk:Tree:Model
34     private void 
35     get_value(Gtk:Tree:Model *model(check null type), GtkTreeIter *iter (check null), gint column (check >= 0 < MPDDATA_MODEL_N_COLUMNS), GValue *value (check null))
36     {
37         Self *self = GMPC_MPDDATA_MODEL_TAGEDIT(model);
38         MpdData_real *data = iter->user_data;   
39         if(column == MPDDATA_MODEL_COL_ICON_ID)
40         {
41             si *i = data->userdata;
42             g_value_init(value, GMPC_MPDDATA_MODEL(self)->types[column]);
44             if(i->changed)
45             {
46                 g_value_set_string(value, GTK_STOCK_CANCEL);
47             }
48             else 
49             {
50                 g_value_set_string(value, GTK_STOCK_OK);
51             }
52             
53             return;
54         }
55         /**
56          * Call the parent function again
57          */
58         gmpc_mpddata_model_get_value(model, iter, column, value);
59         //PARENT(self)->get_value(model, iter, column, value);
60         //PARENT_HANDLER(model, iter,column,value);
61     }
62     public
63     void
64     revert_song(Gtk:Tree:Model *model(check null type), GtkTreeIter *iter (check null))
65     {
66         MpdData_real *data = iter->user_data;   
67         if(data->userdata)
68         {
69             GtkTreePath *path;
70             si *i = data->userdata;
71             mpd_freeSong(data->song);
72             data->song = mpd_songDup(i->revert);
73             i->changed = 0;
74             path = gtk_tree_model_get_path(model, iter);
75             gtk_tree_model_row_changed(model, path, iter);
76             gtk_tree_path_free(path);
77         }
78     }