/+junk/SAPG

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/SAPG

« back to all changes in this revision

Viewing changes to src/main.vala

  • Committer: Gustav Hartvigsson
  • Date: 2015-11-11 17:47:22 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20151111174722-wm7jjqzp5fcgdl40
* Added AppState object to track the state of (the) play(er).
* Added in dep on gstreamer-1.0.
    We have to use the .vapi version, cus' of conflicting names of functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
    Intl.textdomain(GETTEXT_PACKAGE);
12
12
    Intl.bind_textdomain_codeset(GETTEXT_PACKAGE, "utf-8");
13
13
    Intl.bindtextdomain(GETTEXT_PACKAGE, "./locale");
14
 
 
 
14
    
 
15
    
15
16
    GLib.Environment.set_prgname (_("SAPG"));
16
 
 
 
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
    
17
23
    var app = new SAPG.App ();
18
 
 
19
 
    return app.run();
 
24
    
 
25
    var ret_val = app.run();
 
26
    
 
27
    Gst.deinit ();
 
28
    
 
29
    return ret_val;
20
30
  }
21
31
 
22
32
  public
26
36
             flags: GLib.ApplicationFlags.FLAGS_NONE);
27
37
    }
28
38
 
29
 
    protected
30
 
    SAPG.AppWinodw window;
31
 
 
32
 
    protected
33
 
    int standard_height;
34
 
 
35
 
    protected
36
 
    int
37
 
    standard_width;
 
39
    protected SAPG.AppWinodw window;
 
40
 
 
41
    protected int standard_height;
 
42
 
 
43
    protected int standard_width;
38
44
 
39
45
    protected override
40
46
    void activate () {
101
107
    [GtkChild]
102
108
    public Gtk.ToggleButton tgl_btn_show_volume;
103
109
    
 
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]
104
120
    public AppWinodw (Gtk.Application application) {
105
121
      Object (application: application);
106
122
      var icon_image = new Gtk.Image.from_resource ("/org/gego/sapg/icon_32.png");
119
135
      this.set_transient_for (window);
120
136
    }
121
137
  }
122
 
 
 
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
  
123
215
}