Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #48 from kajzersoze/master
Browse files Browse the repository at this point in the history
Add notifications, tray and new tag
  • Loading branch information
haecker-felix authored Aug 14, 2016
2 parents 7cb608b + a4a9a92 commit 9c0eb3f
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pkg_check_modules(DEPS REQUIRED
gio-2.0
gee-0.8
libsoup-2.4
libnotify
)

set(NORMAL_CFLAGS ${DEPS_CFLAGS} ${LIBSOURCE_CFLAGS} ${GCONF_CFLAGS})
Expand Down Expand Up @@ -131,6 +132,7 @@ PACKAGES
gio-2.0
gee-0.8
libsoup-2.4
libnotify
OPTIONS
--thread
--target-glib=2.38
Expand Down
24 changes: 24 additions & 0 deletions data/ui/settings-dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,30 @@
<property name="top_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Close to tray:</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="CloseToTraySwitch">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">3</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="OnlyShowWorkingStationsSwitch">
<property name="visible">True</property>
Expand Down
5 changes: 5 additions & 0 deletions schemas/de.haecker-felix.gradio.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<summary>Show stations icons or not.</summary>
</key>

<key name="close-to-tray" type="b">
<default>true</default>
<summary>Close window to tray</summary>
</key>

<key name="window-height" type="i">
<default>500</default>
<summary>Height of the window</summary>
Expand Down
19 changes: 19 additions & 0 deletions src/AudioPlayer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Gradio{
public signal void tag_changed();

public string tag_title;
public string tag_homepage;
public bool tag_has_crc;
public string tag_audio_codec;
public uint tag_nominal_bitrate;
Expand All @@ -28,6 +29,22 @@ namespace Gradio{
this.notify.connect ((s, p) => stdout.printf ("Property %s changed\n", p.name));
}

private int EndsWithFoo(string s)
{
int ret = 0;
int si = s.length;
if (s != null)
{
if (si >= 4 && s[si-4] == '.' && s[si-3] == 'j' && s[si-2] == 'p' && s[si-1] == 'g')
ret = 1;
if (si >= 4 && s[si-4] == '.' && s[si-3] == 'p' && s[si-2] == 'n' && s[si-1] == 'g')
ret = 1;
if (si >= 4 && s[si-4] == '.' && s[si-3] == 'b' && s[si-2] == 'm' && s[si-1] == 'p')
ret = 1;
}
return ret;
}

private bool bus_callback (Gst.Bus bus, Gst.Message m) {
switch (m.type) {
case MessageType.ERROR:
Expand Down Expand Up @@ -61,6 +78,8 @@ namespace Gradio{
m.parse_tag(out tag_list);

tag_list.get_string("title", out tag_title);
tag_list.get_string("homepage", out tag_homepage);
if (EndsWithFoo(tag_homepage) == 0) tag_homepage = "";

tag_list.get_boolean("has-crc", out tag_has_crc);

Expand Down
42 changes: 40 additions & 2 deletions src/Gradio.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Gradio {
public static StationProvider data_provider;
public static GLib.Settings settings;
public MPRIS mpris;
private Gtk.Menu menuSystem;

public App () {
Object(application_id: "de.haecker-felix.gradio", flags: ApplicationFlags.FLAGS_NONE);
Expand Down Expand Up @@ -89,7 +90,7 @@ namespace Gradio {
this.add_action (action);

action = new GLib.SimpleAction ("quit", null);
action.activate.connect (() => { this.quit (); });
action.activate.connect (() => { this.quit_application (); });
this.add_action (action);

action = new GLib.SimpleAction ("report_an_error", null);
Expand All @@ -109,15 +110,52 @@ namespace Gradio {
});
}

private void restore_window () {
var active_window = get_active_window ();
active_window.present ();
}

private void quit_application(){
restore_window ();
window.save_geometry ();
base.quit ();
}

private void play_and_stop () {
App.player.toggle_play_stop();
}

/* Create menu for right button */
private void create_menuSystem() {
menuSystem = new Gtk.Menu();
var menuPlayStop = new Gtk.MenuItem.with_label("Play / Stop");
menuPlayStop.activate.connect(play_and_stop);
menuSystem.append(menuPlayStop);
var menuQuit = new ImageMenuItem.from_stock(Stock.QUIT, null);
menuQuit.activate.connect(this.quit_application);
menuSystem.append(menuQuit);
menuSystem.show_all();
}

/* Show popup menu on right button */
private void menuSystem_popup(uint button, uint time) {
menuSystem.popup(null, null, null, button, time);
}

public static void main (string [] args){
// Init gstreamer
unowned string[] argv = null;
var app = new App ();
Gst.init (ref argv);

// Init gtk
Gtk.init(ref args);
Notify.init("Gradio");
var trayicon = new Gtk.StatusIcon.from_icon_name("gradio");
trayicon.activate.connect(app.restore_window);
app.create_menuSystem();
trayicon.popup_menu.connect(app.menuSystem_popup);

var app = new App ();
message("Starting Gradio version " + Constants.VERSION + "!");
app.run (args);
}
Expand Down
27 changes: 20 additions & 7 deletions src/Widgets/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ namespace Gradio{
width = App.settings.get_int ("window-width");
height = App.settings.get_int ("window-height");
this.set_default_size(width, height);
pos_x = App.settings.get_int ("window-position-x");
pos_y = App.settings.get_int ("window-position-y");
this.move(pos_x, pos_y);

var gtk_settings = Gtk.Settings.get_default ();
Expand Down Expand Up @@ -91,26 +93,37 @@ namespace Gradio{
ContentStack.set_visible_child_name("no_connection");
}

public void save_geometry (){
this.get_position (out pos_x, out pos_y);
this.get_size (out width, out height);
App.settings.set_int("window-width", width);
App.settings.set_int("window-height", height);
App.settings.set_int("window-position-x", pos_x);
App.settings.set_int("window-position-y", pos_y);
}

private void connect_signals(){
App.player.radio_station_changed.connect((t,a) => {
player_toolbar.set_radio_station(a);
});

this.destroy.connect(() => {
App.settings.set_int("window-width", width);
App.settings.set_int("window-height", height);
save_geometry ();
});

this.delete_event.connect (() => {
save_geometry ();
if (App.settings.get_boolean ("close-to-tray")) {
this.hide_on_delete ();
return true;
} else return false;
});

this.size_allocate.connect((a) => {
width = a.width;
height = a.height;
});

this.drag_motion.connect((c, x, y) => {
App.settings.set_int("window-position-x", x);
App.settings.set_int("window-position-y", y);
return true;
});
}

[GtkCallback]
Expand Down
30 changes: 30 additions & 0 deletions src/Widgets/PlayerToolbar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace Gradio{
private MenuButton InfoMenuButton;

RadioStation station;
private string current_title = null;

public PlayerToolbar(){
this.pack_start(MediaControlBox);
Expand All @@ -52,6 +53,13 @@ namespace Gradio{
this.set_visible(false);
}

private void send_notification(string summary, string body, Gdk.Pixbuf? icon = null){
var noti = new Notify.Notification (summary, body, null);
if (icon != null)
noti.set_image_from_pixbuf(icon);
noti.show();
}

public void set_radio_station (RadioStation s){
station = s;

Expand Down Expand Up @@ -91,6 +99,28 @@ namespace Gradio{
BitrateLabel.set_text(App.player.tag_bitrate.to_string() + " Bit/s");
CodecLabel.set_text(App.player.tag_audio_codec);
ChannelModeLabel.set_text(App.player.tag_channel_mode);
if(current_title != App.player.tag_title && App.player.tag_title != null) {
if (App.player.tag_homepage != "") {
Util.get_image_from_url.begin(App.player.tag_homepage, 48, 48, (obj, res) => {
var icon = Util.get_image_from_url.end(res);
if(icon != null){
send_notification(station.Title, App.player.tag_title, icon);
}else{
send_notification(station.Title, App.player.tag_title, null);
}
});
}else{
Util.get_image_from_url.begin(station.Icon, 48, 48, (obj, res) => {
var icon = Util.get_image_from_url.end(res);
if(icon != null){
send_notification(station.Title, App.player.tag_title, icon);
}else{
send_notification(station.Title, App.player.tag_title, null);
}
});
}
current_title = App.player.tag_title;
}
}

private void refresh_play_stop_button(){
Expand Down
12 changes: 12 additions & 0 deletions src/Widgets/SettingsDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace Gradio{
private Switch UseDarkDesignSwitch;
[GtkChild]
private Switch LoadPicturesSwitch;
[GtkChild]
private Switch CloseToTraySwitch;

private GLib.Settings settings;

Expand Down Expand Up @@ -47,12 +49,22 @@ namespace Gradio{

});

CloseToTraySwitch.notify["active"].connect (() => {
if (CloseToTraySwitch.active) {
settings.set_boolean ("close-to-tray", true);
} else {
settings.set_boolean ("close-to-tray", false);
}

});

}

private void load_settings(GLib.Settings settings){
UseDarkDesignSwitch.set_active(settings.get_boolean ("use-dark-design"));
LoadPicturesSwitch.set_active(settings.get_boolean ("load-pictures"));
OnlyShowWorkingStationsSwitch.set_active(settings.get_boolean ("only-show-working-stations"));
CloseToTraySwitch.set_active(settings.get_boolean ("close-to-tray"));
}

}
Expand Down

0 comments on commit 9c0eb3f

Please sign in to comment.