~xapantu/pantheon-plugs/gnomecc

« back to all changes in this revision

Viewing changes to src/wallpapers-settings.vala

  • Committer: xapantu
  • Date: 2011-12-10 14:53:00 UTC
  • Revision ID: xapantu@gmail.com-20111210145300-6bownuajahlxkx9x
Plug sample, works now

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  
 
2
//  Copyright (C) 2011 Maxwell Barvian
 
3
// 
 
4
//  This program is free software: you can redistribute it and/or modify
 
5
//  it under the terms of the GNU General Public License as published by
 
6
//  the Free Software Foundation, either version 3 of the License, or
 
7
//  (at your option) any later version.
 
8
// 
 
9
//  This program is distributed in the hope that it will be useful,
 
10
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
//  GNU General Public License for more details.
 
13
// 
 
14
//  You should have received a copy of the GNU General Public License
 
15
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
// 
 
17
 
 
18
namespace Wallpaper {
 
19
 
 
20
    public enum PictureMode {
 
21
        TILED = 0,
 
22
        CENTERED = 1,
 
23
        SCALED = 2,
 
24
        STRETCHED = 3,
 
25
        ZOOMED = 4;
 
26
        
 
27
        public void get_options (out bool stretch_x, out bool stretch_y, out bool center_x, out bool center_y) {
 
28
                        
 
29
            switch (this) {
 
30
                
 
31
                case PictureMode.CENTERED:
 
32
                    stretch_x = false;
 
33
                    stretch_y = false;
 
34
                    center_x = true;
 
35
                    center_y = true;
 
36
                    break;
 
37
                case PictureMode.SCALED:
 
38
                    stretch_x = false;
 
39
                    stretch_y = true;
 
40
                    center_x = true;
 
41
                    center_y = false;
 
42
                    break;
 
43
                case PictureMode.STRETCHED:
 
44
                    stretch_x = true;
 
45
                    stretch_y = true;
 
46
                    center_x = false;
 
47
                    center_y = false;
 
48
                    break;
 
49
                case PictureMode.ZOOMED:
 
50
                    stretch_x = true;
 
51
                    stretch_y = false;
 
52
                    center_x = false;
 
53
                    center_y = true;
 
54
                    break;
 
55
                default:
 
56
                    stretch_x = false;
 
57
                    stretch_y = false;
 
58
                    center_x = false;
 
59
                    center_y = false;
 
60
                    break;
 
61
            }
 
62
        }
 
63
    }
 
64
 
 
65
    // Class to interface with GSettings for pantheon-wallpaper
 
66
    public class WallpaperSettings : Granite.Services.Settings {
 
67
 
 
68
        public PictureMode picture_mode { get; set; }
 
69
    
 
70
        public string picture_path { get; set; }
 
71
        
 
72
        public string background_color { get; set; }
 
73
        
 
74
        public WallpaperSettings () {
 
75
            base ("desktop.Wallpaper");
 
76
        }
 
77
        
 
78
        protected override void verify (string key) {
 
79
        
 
80
            switch (key) {
 
81
            
 
82
                case "background-color":
 
83
                    Gdk.Color bg;
 
84
                    if (!Gdk.Color.parse (background_color, out bg))
 
85
                        background_color = "#000000";
 
86
                    break;
 
87
            }
 
88
        }
 
89
 
 
90
        // Helper function to make life easier.
 
91
        public void set_picture_mode_from_name (string name) {
 
92
 
 
93
            if (name == "Tiled") {
 
94
                picture_mode = PictureMode.TILED;
 
95
            }
 
96
            else if (name == "Centered") {
 
97
                picture_mode = PictureMode.CENTERED;
 
98
            }
 
99
            else if (name == "Scaled") {
 
100
                picture_mode = PictureMode.SCALED;
 
101
            }
 
102
            else if (name == "Stretched") {
 
103
                picture_mode = PictureMode.STRETCHED;
 
104
            }
 
105
            else if (name == "Zoomed") {
 
106
                picture_mode = PictureMode.ZOOMED;
 
107
            }
 
108
        }
 
109
    
 
110
    }
 
111
    
 
112
}
 
113