UnityProgressBar.vala 2.06 KB
Newer Older
1
/* Copyright 2016 Software Freedom Conservancy Inc.
2 3 4 5 6
 *
 * This software is licensed under the GNU Lesser General Public License
 * (version 2.1 or later).  See the COPYING file in this distribution.
 */

7
#if UNITY_SUPPORT
8
public class UnityProgressBar : Object {
9

10 11
    private static Unity.LauncherEntry l = Unity.LauncherEntry.get_for_desktop_id("shotwell.desktop");
    private static UnityProgressBar? visible_uniprobar;
12

13 14
    private double progress;
    private bool visible;
15 16 17 18 19 20 21 22 23 24

    public static UnityProgressBar get_instance() {
        if (visible_uniprobar == null) {
            visible_uniprobar = new UnityProgressBar();
        }

        return visible_uniprobar;
    }

    private UnityProgressBar() {
25 26 27
        progress = 0.0;
        visible = false;
    }
28

29
    ~UnityProgressBar () {
30
        reset_progress_bar();
31 32 33 34 35 36 37 38 39 40
    }
    
    public double get_progress () {
        return progress;
    }
    
    public void set_progress (double percent) {
        progress = percent;
        update_visibility();
    }
41

42
    private void update_visibility () {
43
        set_progress_bar(this, progress);
44 45 46 47 48 49 50 51
    }
    
    public bool get_visible () {
        return visible;
    }
    
    public void set_visible (bool visible) {
        this.visible = visible;
52 53 54

        if (!visible) {
            //if not visible and currently displayed, remove Unity progress bar
55
            reset_progress_bar();
56 57 58 59
        } else {
            //update_visibility if this progress bar wants to be drawn
            update_visibility();            
        }
60
    }
61

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    public void reset () {
        set_visible(false);
        progress = 0.0;
    }
    
    private static void set_progress_bar (UnityProgressBar uniprobar, double percent) {
        //set new visible ProgressBar
        visible_uniprobar = uniprobar;
        if (!l.progress_visible)
            l.progress_visible = true;
        l.progress = percent;
    }
    
    private static void reset_progress_bar () {
        //reset to default values
        visible_uniprobar = null;
        l.progress = 0.0;
        l.progress_visible = false;
    }
}

83
#endif