Merge lp:~davysson/dropoff/using-lightwindow into lp:~elementary-dev-community/dropoff/dropoff

Proposed by DavyS
Status: Merged
Approved by: Brendan William
Approved revision: 9
Merged at revision: 9
Proposed branch: lp:~davysson/dropoff/using-lightwindow
Merge into: lp:~elementary-dev-community/dropoff/dropoff
Diff against target: 372 lines (+184/-149)
2 files modified
CMakeLists.txt (+1/-1)
src/dropoff.vala (+183/-148)
To merge this branch: bzr merge lp:~davysson/dropoff/using-lightwindow
Reviewer Review Type Date Requested Status
Brendan William (community) Approve
Review via email: mp+111142@code.launchpad.net

Description of the change

Using Granite.Widgets.LightWindow instead of Gtk.Window

To post a comment you must log in.
Revision history for this message
Brendan William (bwilliam) :
review: Approve
Revision history for this message
Brendan William (bwilliam) wrote :

Beautiful

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2012-02-13 16:44:21 +0000
3+++ CMakeLists.txt 2012-06-20 04:36:20 +0000
4@@ -78,5 +78,5 @@
5 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/48x48/dropoff.svg DESTINATION share/icons/hicolor/48x48/apps/)
6 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/64x64/dropoff.svg DESTINATION share/icons/hicolor/64x64/apps/)
7 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/128x128/dropoff.svg DESTINATION share/icons/hicolor/128x128/apps/)
8-install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/drop_files.png DESTINATION share/${NAME})
9+install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/drop_files.png DESTINATION ${PKGDATADIR})
10
11
12=== modified file 'src/dropoff.vala'
13--- src/dropoff.vala 2012-02-13 15:04:00 +0000
14+++ src/dropoff.vala 2012-06-20 04:36:20 +0000
15@@ -1,9 +1,19 @@
16 using Gtk;
17-
18-
19-namespace Dropoff{
20- public class DropoffApp : Granite.Application{
21-
22+using Granite;
23+
24+namespace Dropoff {
25+
26+ public class DropoffApp : Granite.Application {
27+
28+ public Granite.Widgets.LightWindow main_window;
29+ public Image image;
30+ public Box box;
31+ public Box hbox;
32+ public Granite.Widgets.ContractorView contracts;
33+ public ScrolledWindow contractor;
34+ public Grid header;
35+ public Button close;
36+
37 construct{
38 application_id = "org.elementary.dropoff";
39 program_name = "Dropoff";
40@@ -32,164 +42,189 @@
41 build_version = Constants.VERSION;
42 build_version_info = Constants.VERSION_INFO;
43 }
44-
45- public Gtk.Window main_window;
46- public Image image;
47- public Box box;
48- public Granite.Widgets.ContractorView contracts;
49- public Gtk.ScrolledWindow contractor;
50- public Gtk.Grid header;
51-
52+
53 public DropoffApp (){
54- this.set_flags (ApplicationFlags.HANDLES_OPEN);
55+ this.set_flags (ApplicationFlags.HANDLES_OPEN);
56 }
57-
58- private void build_and_run (){
59- main_window = new Gtk.Window ();
60- main_window.set_application (this);
61- main_window.window_position = Gtk.WindowPosition.CENTER;
62- main_window.set_size_request (380, 380);
63-
64- TargetEntry e = {"text/uri-list", 0, 0};
65-
66- //IMAGE
67- image = new Image.from_file (build_pkg_data_dir+"/drop_files.png");
68- image.drag_data_received.connect (process_drag_data);
69- drag_dest_set (image, DestDefaults.ALL, {e}, Gdk.DragAction.COPY);
70-
71- var label = _("Drag a file here");
72-
73- image.draw.connect ( (ctx) => {
74- Cairo.TextExtents ext;
75+
76+ public override void activate (){
77+
78+ if (main_window == null)
79+ build_and_run ();
80+
81+ }
82+
83+ public void build_and_run (){
84+
85+ main_window = new Granite.Widgets.LightWindow ();
86+ main_window.title = "Dropoff";
87+ main_window.set_size_request (380,380);
88+ main_window.set_application (this);
89+ main_window.destroy.connect (Gtk.main_quit);
90+ main_window.window_position = WindowPosition.CENTER;
91+
92+ var label = _("Drag a file here");
93+
94+ TargetEntry e = {"text/uri-list", 0, 0};
95+
96+ image = new Image.from_file (build_pkg_data_dir+"/drop_files.png");
97+ image.drag_data_received.connect (process_drag_data);
98+ drag_dest_set (image, DestDefaults.ALL, {e}, Gdk.DragAction.COPY);
99+
100+ image.draw.connect ((ctx) => {
101+ Cairo.TextExtents ext;
102 ctx.text_extents (label, out ext);
103 ctx.move_to (image.get_allocated_width ()/2 - ext.width /2,
104 image.get_allocated_height ()/2 - ext.height/2 + 80);
105 ctx.show_text (label);
106 return false;
107- });
108-
109- //FILEVIEW
110- box = new Box (Orientation.VERTICAL, 0);
111- box.margin = 12;
112-
113- header = new Gtk.Grid ();
114-
115- var about = new Gtk.Button.with_label (_("About"));
116- var cancel = new Gtk.Button.with_label (_("Cancel"));
117- var share = new Gtk.Button.with_label (_("Share"));
118-
119- share.can_default = true;
120- share.grab_focus ();
121-
122- var b = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
123-
124- b.pack_start (about, false, false, 0);
125- b.pack_end (share, false, false, 0);
126- b.pack_end (cancel, false, false, 0);
127-
128- box.pack_start (image, true, true, 0);
129- box.pack_start (b, false, false, 0);
130-
131- main_window.add (box);
132- main_window.show_all ();
133- main_window.set_default (share);
134-
135- share.hide ();
136- /*
137- * events
138- */
139- share.clicked.connect ( ()=>{
140- contracts.run_selected ();
141- main_window.destroy ();
142- });
143- cancel.clicked.connect ( () => {
144- main_window.destroy ();
145- });
146- about.clicked.connect ( () => {
147- this.show_about (this.main_window);
148- });
149- }
150-
151- void process_drag_data (Widget widget, Gdk.DragContext ctx,
152+ });
153+
154+ var about = new Button.with_label (_("About"));
155+ close = new Button.with_label (_("Close"));
156+
157+ hbox = new Box (Orientation.HORIZONTAL, 0);
158+
159+ hbox.pack_start (about, false, false, 0);
160+ hbox.pack_end (close, false, false, 0);
161+
162+ box = new Box (Orientation.VERTICAL, 0);
163+ box.margin = 12;
164+
165+ box.pack_start (image, true, true, 0);
166+ box.pack_end (hbox, false, false, 0);
167+
168+
169+ main_window.add (box);
170+ main_window.show_all ();
171+
172+ about.clicked.connect (() => this.show_about (this.main_window));
173+ close.clicked.connect (() => main_window.destroy ());
174+ }
175+
176+ private void process_drag_data (Widget widget, Gdk.DragContext ctx,
177 int x, int y, SelectionData sel, uint information, uint timestamp){
178- if (sel.get_length () > 0){
179- var file = File.new_for_uri (sel.get_uris ()[0]);
180-
181- open_file (file);
182-
183- Gtk.drag_finish (ctx, true, false, timestamp);
184-
185- return;
186- }
187- Gtk.drag_finish (ctx, false, false, timestamp);
188- }
189-
190- void open_file (File file){
191- FileInfo info = null;
192- try{
193- info = file.query_info (FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME +","+
194- FILE_ATTRIBUTE_STANDARD_ICON + ","+
195- FILE_ATTRIBUTE_STANDARD_SIZE + ","+
196- FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
197+
198+ if (sel.get_length () > 0) {
199+
200+ var file = File.new_for_uri (sel.get_uris ()[0]);
201+ open_file (file);
202+
203+ Gtk.drag_finish (ctx, true, false, timestamp);
204+
205+ return;
206+ }
207+ Gtk.drag_finish (ctx, false, false, timestamp);
208+
209+ }
210+
211+ private void open_file (File file){
212+
213+ FileInfo info = null;
214+
215+ try{
216+
217+ info = file.query_info (FileAttribute.STANDARD_DISPLAY_NAME +","+
218+ FileAttribute.STANDARD_ICON + ","+
219+ FileAttribute.STANDARD_SIZE + ","+
220+ FileAttribute.STANDARD_CONTENT_TYPE,
221 FileQueryInfoFlags.NONE, null);
222- }catch (Error e){warning (e.message);}
223-
224- contracts = new Granite.Widgets.ContractorView (file.get_uri (), info.get_content_type ());
225- contractor = new Gtk.ScrolledWindow (null, null);
226- contractor.add (contracts);
227- contractor.margin_bottom = 12;
228-
229- /*load as image or filetype image*/
230- Gtk.Image img;
231- try{
232- var pix = new Gdk.Pixbuf.from_file (file.get_path ());
233- pix = pix.scale_simple ((int)(1.0 * pix.get_width () / pix.get_height () * 48.0), 48, Gdk.InterpType.HYPER);
234- img = new Gtk.Image.from_pixbuf (pix);
235- }catch (Error e){
236- try{
237- img = new Gtk.Image.from_pixbuf (Gtk.IconTheme.get_default ().lookup_by_gicon (info.get_icon (), 48, 0).load_icon ());
238- }catch (Error e){
239- warning (e.message);
240- img=new Gtk.Image.from_stock (Gtk.Stock.CLOSE, Gtk.IconSize.BUTTON);}
241- }
242- img.set_size_request (48, 48);
243- img.set_pixel_size (48);
244-
245- var lbl = new Gtk.Label ("<span color='#aaaaaa'>"+
246- info.get_size ().to_string ()+" "+_("KB")+"</span>");
247- lbl.use_markup = true;
248- lbl.halign = Gtk.Align.START;
249-
250+ } catch (Error e)
251+ {
252+ warning (e.message);
253+ }
254+
255+ contracts = new Granite.Widgets.ContractorView (file.get_uri (), info.get_content_type ());
256+ contractor = new ScrolledWindow (null, null);
257+ contractor.add (contracts);
258+ contractor.margin_bottom = 12;
259+ contractor.shadow_type = ShadowType.OUT;
260+
261+ Image img;
262+
263+ try{
264+
265+ var pix = new Gdk.Pixbuf.from_file (file.get_path ());
266+ pix = pix.scale_simple ((int)(1.0 * pix.get_width () / pix.get_height () * 48.0), 48, Gdk.InterpType.HYPER);
267+ img = new Image.from_pixbuf (pix);
268+
269+ } catch (Error e){
270+ try{
271+ img = new Gtk.Image.from_pixbuf (Gtk.IconTheme.get_default ().lookup_by_gicon (info.get_icon (), 48, 0).load_icon ());
272+ } catch (Error e){
273+ warning (e.message);
274+ img = new Gtk.Image.from_stock (Gtk.Stock.CLOSE, Gtk.IconSize.BUTTON);
275+ }
276+ }
277+ img.set_size_request (48, 48);
278+ img.set_pixel_size (48);
279+
280+ var lbl = new Label ("<span color='#aaaaaa'>"+human_size(info.get_size ())+"</span>");
281+
282+ lbl.use_markup = true;
283+ lbl.halign = Align.START;
284+
285+ header = new Grid ();
286+
287 header.attach (img, 0, 0, 1, 2);
288 header.attach (new Gtk.Label (info.get_display_name ()), 1, 0, 1, 1);
289 header.attach (lbl, 1, 1 ,1, 1);
290 header.margin_bottom = 12;
291-
292- box.remove (image);
293- box.pack_start (header, false, true, 0);
294- box.pack_start (contractor, true, true, 0);
295- box.reorder_child (header, 0);
296- box.reorder_child (contractor, 1);
297- box.show_all ();
298- }
299-
300- public override void activate (){
301- build_and_run ();
302- }
303-
304+
305+ var share = new Button.with_label (_("Share"));
306+ share.clicked.connect (() => contracts.run_selected ());
307+
308+ var cancel = new Button.with_label (_("Cancel"));
309+ cancel.clicked.connect (() => {
310+ box.remove (header);
311+ box.remove (contractor);
312+ box.pack_start (image, true, true, 0);
313+
314+ hbox.remove (cancel);
315+ hbox.remove (share);
316+ hbox.pack_end (close, false, false, 0);
317+ main_window.resize (380, 380);
318+ });
319+
320+ hbox.remove (close);
321+ hbox.pack_end (share, false, false, 0);
322+ hbox.pack_end (cancel, false, false, 0);
323+
324+ box.remove (image);
325+ box.pack_start (header, false, false, 0);
326+ box.pack_start (contractor, true, true, 0);
327+ box.reorder_child (header, 0);
328+ box.reorder_child (contractor, 1);
329+ main_window.show_all ();
330+
331+ }
332+
333 public override void open (File [] files, string hint){
334 if (main_window == null)
335 build_and_run ();
336 open_file (files[0]);
337 }
338- }
339-}
340-
341-public static int main (string [] args){
342- Gtk.init (ref args);
343-
344- var d = new Dropoff.DropoffApp ();
345-
346- return d.run (args);
347-}
348-
349+
350+ private string human_size (double size){
351+
352+ string[] units = {"KB", "MB", "GB", "TB"};
353+ string size_str = size.to_string ()+" "+(size <= 1 ? "Byte" : "Bytes");
354+ for (int i = 0; (int) size > 1024; i++){
355+ size = size / 1024;
356+ size_str = "%.2f %s".printf(size, units[i]);
357+ }
358+ return size_str;
359+ }
360+
361+ public static int main (string[] args){
362+
363+ Gtk.init (ref args);
364+ var r = new DropoffApp ();
365+
366+ return r.run (args);
367+
368+ }
369+
370+ }
371+
372+}

Subscribers

People subscribed via source and target branches