2 /* Gnome Music Player Client (GMPC)
3 * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
4 * Project homepage: http://gmpclient.org/
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 private const bool use_transition_mb
= Gmpc
.use_transition
;
25 private const string some_unique_name_mb
= Config
.VERSION
;
27 public class Gmpc
.Tools
.DatabaseUpdateTracker
: Gmpc
.Plugin
.Base
29 private Gtk
.Image image
= null;
31 private const int[] version
= {0,0,2};
32 public override unowned
int[] get_version()
37 public override unowned
string get_name()
39 return "Database Update Tracker";
44 /* Mark the plugin as an internal dummy */
45 this
.plugin_type
= 8+4;
46 /* Attach status changed signal */
47 gmpcconn
.status_changed
.connect(status_changed
);
48 gmpcconn
.connection_changed
.connect(connection_changed
);
51 private void start_updating()
53 if(this
.image
!= null) return;
54 this
.image
= new Gtk
.Image
.from_icon_name("gtk-refresh", Gtk
.IconSize
.MENU
);
56 this
.image
.set_tooltip_text(_("MPD is rescanning the database"));
57 Gmpc
.Playlist3
.add_status_icon(this
.image
);
59 private void stop_updating()
61 if(this
.image
== null) return;
63 this
.image
.parent
.remove(this
.image
);
66 private void show_message(int db_time
)
68 time_t r_time
= (time_t
) db_time
;
70 Time tm
= Time
.local(r_time
);
71 message
= "%s %s".printf(_("MPD Database has been updated at:"), tm
.format("%c"));
73 Gmpc
.Messages
.show((string)message
, Gmpc
.Messages
.Level
.INFO
);
75 private void connection_changed(Connection gc
, MPD
.Server server
, int connection
)
79 string id
= Gmpc
.profiles
.get_current();
82 var dut
= Gmpc
.profiles
.get_db_update_time(id
);
83 var serv_dut
= server
.get_database_update_time();
86 show_message(serv_dut
);
87 Gmpc
.profiles
.set_db_update_time(id
, serv_dut
);
90 if(server
.is_updating_database())
97 /* Remove icon on disconnect */
101 private void status_changed(Connection gc
, MPD
.Server server
, MPD
.Status
.Changed what
)
103 if(!this
.get_enabled()) return;
104 if((what
&MPD
.Status
.Changed
.UPDATING
) == MPD
.Status
.Changed
.UPDATING
)
106 if(server
.is_updating_database())
116 if((what
&MPD
.Status
.Changed
.DATABASE
) == MPD
.Status
.Changed
.DATABASE
)
118 string id
= Gmpc
.profiles
.get_current();
121 var dut
= Gmpc
.profiles
.get_db_update_time(id
);
122 var serv_dut
= Gmpc
.server
.get_database_update_time();
125 show_message(serv_dut
);
126 Gmpc
.profiles
.set_db_update_time(id
, serv_dut
);