4
Copyright 2011 Jiří Janoušek <janousek.jiri@gmail.com>
6
This program is free software: you can redistribute it and/or modify it
7
under the terms of the GNU General Public License version 3, as published
8
by the Free Software Foundation.
10
This program is distributed in the hope that it will be useful, but
11
WITHOUT ANY WARRANTY; without even the implied warranties of
12
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
13
PURPOSE. See the 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, see <http://www.gnu.org/licenses/>.
20
* Save UI state (window dimensions)
21
* Handle opening links in web browser
33
public class Frame: Window{
34
private const string TITLE = "Google Music Frame";
35
private const string HOME_URL = "http://music.google.com/";
37
private ConfigFile config;
39
private unowned WebFrame info_frame;
41
public bool can_prev {get; private set;}
42
public bool can_next {get; private set;}
43
public string? playback_state {get; private set;}
44
public string? album_art {get; private set;}
45
public string? artist {get; private set;}
46
public string? song {get; private set;}
48
public signal void song_changed(string? art, string? artist, string? title);
49
public signal void playback_state_changed(string state, bool can_prev, bool can_next);
51
public class Frame(Application app){
52
this.config = app.config;
56
private void init_ui(){
57
this.destroy.connect(Gtk.main_quit);
58
this.set_default_size(800, 600);
61
this.view = new WebView();
62
var sw = new ScrolledWindow(null, null);
63
sw.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
68
/* Show page title as window title */
69
this.view.title_changed.connect((source, frame, title) => {
73
/* Save current URI to restore previous view on startup */
74
this.view.notify["uri"].connect((o, p) => {
75
this.config["last_uri"] = (o as WebView).uri;
77
debug("URI: %s\n", (o as WebView).uri);
80
this.view.document_load_finished.connect(this.load_scripts);
84
* Load Google Music and show GUI
87
this.view.open(this.config["last_uri"] ?? this.HOME_URL);
89
this.view.get_inspector().show();
93
private void load_scripts(WebFrame frame){
94
debug("load scripts");
95
if(frame != this.view.get_main_frame()) return;
96
var script = get_data_file(APPNAME + "/scripts/main.js");
98
if(script.load_contents(null, out data)){
99
debug("execute script");
100
this.view.execute_script(data);
101
debug("get info frame");
102
unowned WebFrame info_frame = frame.find_frame("GMF_iframe");
103
if(info_frame != null){
104
debug("got info frame");
105
this.info_frame = info_frame;
106
this.info_frame.title_changed.connect(() => {this.update_info();} );
109
else debug("ERROR: getting frame");
111
else debug("ERROR: loading script");
115
private void update_info(){
116
var title = this.info_frame.title;
117
if(title != null && title != ""){
118
string[] parts = this.info_frame.title.split("#@!@#");
119
this.playback_state = parts[0];
120
this.can_prev = parts[1] == "true";
121
this.can_next = parts[2] == "true";
122
if(parts.length == 6){
123
this.album_art = parts[3];
124
this.artist = parts[4];
125
this.song = parts[5];
129
this.playback_state = "none";
130
this.can_prev = false;
131
this.can_next = false;
132
this.album_art = null;
136
this.playback_state_changed(this.playback_state, this.can_prev, this.can_next);
137
this.song_changed(this.album_art, this.artist, this.song);
140
public void command(string cmd){
141
debug("Frame command %s", cmd);
142
this.view.execute_script("SJBpost('" + cmd + "'); $GMF.update();");