~lubuntu-software-center-team/lubuntu-software-center/vala-port

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//  Copyright © 2012 Stephen Smally
//      This program is free software; you can redistribute it and/or modify
//      it under the terms of the GNU General Public License as published by
//      the Free Software Foundation; either version 2 of the License, or
//      (at your option) any later version.
//      
//      This program is distributed in the hope that it will be useful,
//      but WITHOUT ANY WARRANTY; without even the implied warranty of
//      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//      GNU General Public License for more details.
//      
//      You should have received a copy of the GNU General Public License
//      along with this program; if not, write to the Free Software
//      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//      MA 02110-1301, USA.
//      

using Gtk;
using PackageKit;
using Lsc.Widgets;
using Lsc.Backend;

namespace Lsc.Pages {
    public class AppsInfo : Box {
        private Separator separator;
        private RoundBox box;
        public RoundBox reviews_box;
        private Image status_icon;
        private Label status_label;
        private Label load_label;
        private Image image;
        private Label pkg_name;
        private Label short_description;
        private Label description;
        private Label id;
        private Label version;
        private Label size;
        private Button action_button;
        
        private void hide_children (Widget c) {
			c.set_visible (false);
		}
		private void show_children (Widget c) {
			c.set_visible (true);
		}
        
        public void set_action (ActionType type) {
			switch (type) {
				case ActionType.INSTALL:
				    action_button.label = "Install";
				    break;
				case ActionType.REMOVE:
				    action_button.label = "Remove";
				    break;
			}
		}
        
        public void set_status (Info data) {
			switch (data) {
				case Info.INSTALLED:
				    status_icon.set_from_stock (Stock.YES, IconSize.MENU);
				    status_label.label = "<i>%s</i>".printf ("Installed");
				    set_action (ActionType.REMOVE);
				    break;
				default:
				    status_icon.set_from_icon_name ("applications-internet", IconSize.MENU);
				    status_label.label = "<i>%s</i>".printf ("Available");
				    set_action (ActionType.INSTALL);
				    break;
			}
		}
        
        public void set_details (LscApp app, Package pkg, Details details) {
			this.foreach (show_children);
			load_label.set_visible (false);
			reviews_box.set_visible (false);
			
			set_status ((Info)pkg.info);
			
            pkg_name.label = "<big><b>"+app.name+"</b></big>";
            short_description.label = "<i>"+app.summary+"</i>";
            
            description.label = details.description;
            
            image.set_from_icon_name (app.icon, IconSize.DIALOG);
            
            id.label = "<b>Id:</b> "+pkg.get_name();
            version.label = "<b>Version:</b> "+pkg.get_version();
            size.label = "<b>Size:</b> "+details.size.to_string();
        }
        
        public void start_load (string comment) {
			this.foreach (hide_children);
			load_label.set_visible (true);
			load_label.label = comment;
		}
        
        public void pack_separator () {
            separator = new Separator(Orientation.HORIZONTAL);
            separator.margin_left = 1;
            separator.margin_right = 1;
            box.pack_start(separator, false, false, 0);
        }
        
        public AppsInfo () {
            orientation = Orientation.VERTICAL;
            spacing = 5;
            border_width = 5;
            
            // Main container
            box = new RoundBox(Orientation.VERTICAL, 0);
            box.expand = false;
            
            // Summary Box (icon, name/short_description and install button)
            Box summary_box = new Box(Orientation.HORIZONTAL, 3);
            Box label_box = new Box(Orientation.VERTICAL, 0);
            label_box.valign = Align.CENTER;
            image = new Image.from_stock(Stock.INFO, IconSize.DIALOG);
            summary_box.border_width = 5;
            summary_box.pack_start(image, false, false, 0);
            
            pkg_name = new Label("<big><b>Application name</b></big>");
            pkg_name.use_markup = true;
            pkg_name.halign = Align.START;
            
            short_description = new Label("<i>Application description</i>");
            short_description.use_markup = true;
            short_description.halign = Align.START;
            
            label_box.pack_start(pkg_name, false, false, 0);
            label_box.pack_start(short_description, false, false, 0);
            
            summary_box.pack_start(label_box, false, false, 0);
            
            // Status box
            Box status_box = new Box(Orientation.HORIZONTAL, 0);
            
            status_label = new Label("");
            status_label.margin_right = 2;
            status_label.use_markup = true;
            
            status_icon = new Image.from_stock(Stock.YES, IconSize.MENU);
            
            status_box.pack_start(status_icon, false, false, 0);
            status_box.pack_start(status_label, false, false, 0);
            
            summary_box.pack_end(status_box, false, false, 0);
            
            // Description
            Box description_box = new Box(Orientation.VERTICAL, 0);
            description_box.border_width = 10;
            description = new Label("Package description");
            description.wrap_mode = Pango.WrapMode.WORD_CHAR;
            description.wrap = true;
            description.halign = Align.CENTER;
            description_box.pack_start(description, false, false, 0);
            
            // Details (version and size)
            Box details_box = new Box(Orientation.VERTICAL, 0);
            details_box.border_width = 5;
            version = new Label("<b>Version:</b> 0.0.1");
            version.use_markup = true;
            version.halign = Align.START;
            size = new Label("<b>Size:</b> 1024 Kb");
            size.use_markup = true;
            size.halign = Align.START;
            id = new Label("<b>Id:</b> package-id");
            id.use_markup = true;
            id.halign = Align.START;
            details_box.pack_start(id, false, false, 0);
            details_box.pack_start(version, false, false, 0);
            details_box.pack_start(size, false, false, 0);
            
            // Adding widgets
            box.pack_start(summary_box, false, false, 0);
            pack_separator();
            box.pack_start(description_box, true, true, 0);
            pack_separator();
            box.pack_start(details_box, false, false, 0);
            
            // Reviews container
            reviews_box = new RoundBox(Orientation.VERTICAL, 0);
            reviews_box.expand = false;
            
            Box container = new Box(Orientation.HORIZONTAL, 3);
            container.border_width = 5;
            
            Label reviews_label = new Label("<big><b>Reviews</b></big>");
            reviews_label.use_markup = true;
            reviews_label.halign = Align.START;
            
            container.pack_start(new Image.from_stock(Stock.HELP, IconSize.DIALOG), false, false, 0);
            container.pack_start(reviews_label, false, false, 0);
            
            reviews_box.pack_start(container, false, false, 0);
            
            pack_start(box, true, true, 0);
            pack_start(reviews_box, false, false, 0);
            
            // Buttons box
            ButtonBox b_container = new ButtonBox(Orientation.HORIZONTAL);
            b_container.layout_style = ButtonBoxStyle.END;
            b_container.homogeneous = false;
            
            Button bt = new Button.with_label("Check for reviews");
            action_button = new Button();
            
            b_container.pack_start(bt, false, false, 0);
            b_container.pack_start(action_button, false, false, 0);
            b_container.foreach((child) => {
                b_container.set_child_non_homogeneous(child, true);
            });
            
            load_label = new Label("");
            
            pack_start(b_container, false, false, 0);
            pack_start(load_label, true, true, 0);
        }
    }
}