/+junk/SAPG

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/SAPG
1 by Gustav Hartvigsson
* Initial code
1
[CCode(cname="GETTEXT_PACKAGE")] extern const string GETTEXT_PACKAGE;
2
3
namespace SAPG {
4
5
  const string[] authors = {
6
    "Gustav \"Gego/XAREN\" Hartvigsson (+GustavHartvigsson)",
7
  };
8
9
  int main (string[] args) {
10
    Intl.setlocale(LocaleCategory.MESSAGES, "");
11
    Intl.textdomain(GETTEXT_PACKAGE);
12
    Intl.bind_textdomain_codeset(GETTEXT_PACKAGE, "utf-8");
13
    Intl.bindtextdomain(GETTEXT_PACKAGE, "./locale");
6 by Gustav Hartvigsson
* Added AppState object to track the state of (the) play(er).
14
    
15
    
1 by Gustav Hartvigsson
* Initial code
16
    GLib.Environment.set_prgname (_("SAPG"));
6 by Gustav Hartvigsson
* Added AppState object to track the state of (the) play(er).
17
    
18
    Gst.init (ref args);
19
    
20
    /* main must hold a ref to the state object. */
21
    AppState state = SAPG.AppState.get_app_state ();
22
    
1 by Gustav Hartvigsson
* Initial code
23
    var app = new SAPG.App ();
6 by Gustav Hartvigsson
* Added AppState object to track the state of (the) play(er).
24
    
25
    var ret_val = app.run();
26
    
27
    Gst.deinit ();
28
    
29
    return ret_val;
1 by Gustav Hartvigsson
* Initial code
30
  }
31
32
  public
33
  class App : Gtk.Application {
34
    public App () {
35
      Object (application_id: "org.gego.sapg",
36
             flags: GLib.ApplicationFlags.FLAGS_NONE);
37
    }
38
6 by Gustav Hartvigsson
* Added AppState object to track the state of (the) play(er).
39
    protected SAPG.AppWinodw window;
40
41
    protected int standard_height;
42
43
    protected int standard_width;
1 by Gustav Hartvigsson
* Initial code
44
45
    protected override
46
    void activate () {
47
      this.build_ui ();
48
      this.add_actions ();
49
      this.show_all ();
50
    }
51
52
    void build_ui () {
53
      this.window = new SAPG.AppWinodw (this);
54
      this.window.resizable = false;
55
      this.window.set_size_request (0,0);
56
      this.window.destroy.connect (() => {
57
        this.quit ();
58
      });
59
60
      window.revealer.set_reveal_child (false);
61
62
      this.window.tgl_btn_show_volume.toggled.connect (() => {
63
        this.window.revealer.set_reveal_child (this.window.tgl_btn_show_volume.active);
64
      });
65
66
    }
67
68
    void add_actions () {
69
      var about_action = new GLib.SimpleAction ("about", null);
70
      about_action.activate.connect (() => {
71
        var about_dialogue = new SAPG.About (this.window);
72
        about_dialogue.run ();
73
        about_dialogue.destroy ();
74
      });
75
76
      var quit_action = new GLib.SimpleAction ("quit", null);
77
      quit_action.activate.connect (() => {
78
        this.window.destroy ();
79
        this.quit ();
80
      });
81
82
      this.add_action (about_action);
83
      this.add_action (quit_action);
84
85
      var app_menu = new GLib.Menu ();
86
      app_menu.append ("About", "app.about");
87
      app_menu.append ("Quit", "app.quit");
88
89
      this.set_app_menu (app_menu);
90
    }
91
92
    void show_all () {
93
      this.window.show_all ();
94
    }
95
96
    void quit_ui () {
97
98
    }
99
  }
100
101
  [GtkTemplate(ui = "/org/gego/sapg/window.glade")]
102
  public class AppWinodw : Gtk.ApplicationWindow {
103
104
    [GtkChild ]
105
    public Gtk.Revealer revealer;
106
107
    [GtkChild]
108
    public Gtk.ToggleButton tgl_btn_show_volume;
2 by Gustav Hartvigsson
* Added new icons.
109
    
6 by Gustav Hartvigsson
* Added AppState object to track the state of (the) play(er).
110
    [GtkChild]
111
    public Gtk.Button btn_play_pause;
112
    
113
    [GtkChild]
114
    public Gtk.Button btn_stop;
115
    
116
    [GtkChild]
117
    public Gtk.Button btn_rew;
118
    
119
    [GtkChild]
1 by Gustav Hartvigsson
* Initial code
120
    public AppWinodw (Gtk.Application application) {
121
      Object (application: application);
4 by Gustav Hartvigsson
* Make use of new icons
122
      var icon_image = new Gtk.Image.from_resource ("/org/gego/sapg/icon_32.png");
1 by Gustav Hartvigsson
* Initial code
123
      Gtk.Window.set_default_icon (icon_image.get_pixbuf ());
124
    }
125
126
  }
127
128
  public class About : Gtk.AboutDialog {
129
    public About (Gtk.Window? window) {
130
      this.program_name = GLib.Environment.get_prgname ();
4 by Gustav Hartvigsson
* Make use of new icons
131
      this.logo = (new Gtk.Image.from_resource ("/org/gego/sapg/icon_256.png")).get_pixbuf ();
1 by Gustav Hartvigsson
* Initial code
132
      this.authors = SAPG.authors;
133
134
      this.set_modal (true);
135
      this.set_transient_for (window);
136
    }
137
  }
6 by Gustav Hartvigsson
* Added AppState object to track the state of (the) play(er).
138
  
139
  /**
140
   * Singeltonian stucture to hold the application's state and act uppon
141
   * changes.
142
   */
143
  public class AppState {
144
    public enum State {
145
      STOPPED,
146
      PAUSED,
147
      PLAYING
148
    }
149
    
150
    private static AppState app_state = null;
151
    
152
    private AppState () {
153
      this.is_paused = false;
154
      this.is_playing = false;
155
    }
156
    
157
    public static AppState get_app_state () {
158
      if (SAPG.AppState.app_state == null) {
159
        SAPG.AppState.app_state = new AppState ();
160
      }
161
      return SAPG.AppState.app_state;
162
    }
163
    
164
    private bool is_playing;
165
    private bool is_paused;
166
    
167
    public AppState.State get_state () {
168
      if (this.is_playing) {
169
        return AppState.State.PLAYING;
170
      } else if (!this.is_playing && !this.is_paused) {
171
        return AppState.State.STOPPED;
172
      } else {
173
        return AppState.State.PAUSED;
174
      }
175
    }
176
    
177
    public Callback on_first_play;
178
    public Callback on_start_play;
179
    public Callback on_pause_play;
180
    public Callback on_stop_play; 
181
    public Callback on_rewind;
182
    
183
    public void play_pause_toggle () {
184
      if (this.is_playing) {
185
        /* We are playing... */
186
        this.is_paused = true;
187
        this.is_playing = false;
188
        this.on_pause_play ();
189
      } else if (!this.is_playing && !this.is_paused) {
190
        /* We are stopped... */
191
        this.is_paused = false;
192
        this.is_playing = true;
193
        this.on_first_play ();
194
      } else {
195
        /* We are paused... */
196
        this.is_paused = false;
197
        this.is_playing = true;
198
        this.on_start_play ();
199
      }
200
    }
201
    
202
    public void stop_play () {
203
      this.is_paused = false;
204
      this.is_playing = false;
205
      this.on_stop_play ();
206
    }
207
    
208
    public void rewind () {
209
      this.stop_play ();
210
      this.on_rewind ();
211
    }
212
    
213
  }
214
  
1 by Gustav Hartvigsson
* Initial code
215
}