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

Proposed by DavyS on 2012-06-20
Status: Merged
Approved by: Brendan William on 2012-07-01
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 2012-06-20 Approve on 2012-07-01
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.
review: Approve
Brendan William (mamemame187) wrote :

Beautiful

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2012-02-13 16:44:21 +0000
+++ CMakeLists.txt 2012-06-20 04:36:20 +0000
@@ -78,5 +78,5 @@
78install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/48x48/dropoff.svg DESTINATION share/icons/hicolor/48x48/apps/)78install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/48x48/dropoff.svg DESTINATION share/icons/hicolor/48x48/apps/)
79install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/64x64/dropoff.svg DESTINATION share/icons/hicolor/64x64/apps/)79install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/64x64/dropoff.svg DESTINATION share/icons/hicolor/64x64/apps/)
80install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/128x128/dropoff.svg DESTINATION share/icons/hicolor/128x128/apps/)80install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/128x128/dropoff.svg DESTINATION share/icons/hicolor/128x128/apps/)
81install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/drop_files.png DESTINATION share/${NAME})81install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/drop_files.png DESTINATION ${PKGDATADIR})
8282
8383
=== modified file 'src/dropoff.vala'
--- src/dropoff.vala 2012-02-13 15:04:00 +0000
+++ src/dropoff.vala 2012-06-20 04:36:20 +0000
@@ -1,9 +1,19 @@
1using Gtk;1using Gtk;
22using Granite;
33
4namespace Dropoff{4namespace Dropoff {
5 public class DropoffApp : Granite.Application{5
6 6 public class DropoffApp : Granite.Application {
7
8 public Granite.Widgets.LightWindow main_window;
9 public Image image;
10 public Box box;
11 public Box hbox;
12 public Granite.Widgets.ContractorView contracts;
13 public ScrolledWindow contractor;
14 public Grid header;
15 public Button close;
16
7 construct{17 construct{
8 application_id = "org.elementary.dropoff";18 application_id = "org.elementary.dropoff";
9 program_name = "Dropoff";19 program_name = "Dropoff";
@@ -32,164 +42,189 @@
32 build_version = Constants.VERSION;42 build_version = Constants.VERSION;
33 build_version_info = Constants.VERSION_INFO;43 build_version_info = Constants.VERSION_INFO;
34 }44 }
35 45
36 public Gtk.Window main_window;
37 public Image image;
38 public Box box;
39 public Granite.Widgets.ContractorView contracts;
40 public Gtk.ScrolledWindow contractor;
41 public Gtk.Grid header;
42
43 public DropoffApp (){46 public DropoffApp (){
44 this.set_flags (ApplicationFlags.HANDLES_OPEN);47 this.set_flags (ApplicationFlags.HANDLES_OPEN);
45 }48 }
46 49
47 private void build_and_run (){50 public override void activate (){
48 main_window = new Gtk.Window ();51
49 main_window.set_application (this);52 if (main_window == null)
50 main_window.window_position = Gtk.WindowPosition.CENTER;53 build_and_run ();
51 main_window.set_size_request (380, 380);54
52 55 }
53 TargetEntry e = {"text/uri-list", 0, 0};56
54 57 public void build_and_run (){
55 //IMAGE58
56 image = new Image.from_file (build_pkg_data_dir+"/drop_files.png");59 main_window = new Granite.Widgets.LightWindow ();
57 image.drag_data_received.connect (process_drag_data);60 main_window.title = "Dropoff";
58 drag_dest_set (image, DestDefaults.ALL, {e}, Gdk.DragAction.COPY);61 main_window.set_size_request (380,380);
59 62 main_window.set_application (this);
60 var label = _("Drag a file here");63 main_window.destroy.connect (Gtk.main_quit);
61 64 main_window.window_position = WindowPosition.CENTER;
62 image.draw.connect ( (ctx) => {65
63 Cairo.TextExtents ext;66 var label = _("Drag a file here");
67
68 TargetEntry e = {"text/uri-list", 0, 0};
69
70 image = new Image.from_file (build_pkg_data_dir+"/drop_files.png");
71 image.drag_data_received.connect (process_drag_data);
72 drag_dest_set (image, DestDefaults.ALL, {e}, Gdk.DragAction.COPY);
73
74 image.draw.connect ((ctx) => {
75 Cairo.TextExtents ext;
64 ctx.text_extents (label, out ext);76 ctx.text_extents (label, out ext);
65 ctx.move_to (image.get_allocated_width ()/2 - ext.width /2, 77 ctx.move_to (image.get_allocated_width ()/2 - ext.width /2,
66 image.get_allocated_height ()/2 - ext.height/2 + 80);78 image.get_allocated_height ()/2 - ext.height/2 + 80);
67 ctx.show_text (label);79 ctx.show_text (label);
68 return false;80 return false;
69 });81 });
70 82
71 //FILEVIEW83 var about = new Button.with_label (_("About"));
72 box = new Box (Orientation.VERTICAL, 0);84 close = new Button.with_label (_("Close"));
73 box.margin = 12;85
74 86 hbox = new Box (Orientation.HORIZONTAL, 0);
75 header = new Gtk.Grid ();87
76 88 hbox.pack_start (about, false, false, 0);
77 var about = new Gtk.Button.with_label (_("About"));89 hbox.pack_end (close, false, false, 0);
78 var cancel = new Gtk.Button.with_label (_("Cancel"));90
79 var share = new Gtk.Button.with_label (_("Share"));91 box = new Box (Orientation.VERTICAL, 0);
80 92 box.margin = 12;
81 share.can_default = true;93
82 share.grab_focus ();94 box.pack_start (image, true, true, 0);
83 95 box.pack_end (hbox, false, false, 0);
84 var b = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);96
85 97
86 b.pack_start (about, false, false, 0);98 main_window.add (box);
87 b.pack_end (share, false, false, 0);99 main_window.show_all ();
88 b.pack_end (cancel, false, false, 0);100
89 101 about.clicked.connect (() => this.show_about (this.main_window));
90 box.pack_start (image, true, true, 0);102 close.clicked.connect (() => main_window.destroy ());
91 box.pack_start (b, false, false, 0);103 }
92 104
93 main_window.add (box);105 private void process_drag_data (Widget widget, Gdk.DragContext ctx,
94 main_window.show_all ();
95 main_window.set_default (share);
96
97 share.hide ();
98 /*
99 * events
100 */
101 share.clicked.connect ( ()=>{
102 contracts.run_selected ();
103 main_window.destroy ();
104 });
105 cancel.clicked.connect ( () => {
106 main_window.destroy ();
107 });
108 about.clicked.connect ( () => {
109 this.show_about (this.main_window);
110 });
111 }
112
113 void process_drag_data (Widget widget, Gdk.DragContext ctx,
114 int x, int y, SelectionData sel, uint information, uint timestamp){106 int x, int y, SelectionData sel, uint information, uint timestamp){
115 if (sel.get_length () > 0){107
116 var file = File.new_for_uri (sel.get_uris ()[0]);108 if (sel.get_length () > 0) {
117 109
118 open_file (file);110 var file = File.new_for_uri (sel.get_uris ()[0]);
119 111 open_file (file);
120 Gtk.drag_finish (ctx, true, false, timestamp);112
121 113 Gtk.drag_finish (ctx, true, false, timestamp);
122 return;114
123 }115 return;
124 Gtk.drag_finish (ctx, false, false, timestamp);116 }
125 }117 Gtk.drag_finish (ctx, false, false, timestamp);
126 118
127 void open_file (File file){119 }
128 FileInfo info = null;120
129 try{121 private void open_file (File file){
130 info = file.query_info (FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME +","+ 122
131 FILE_ATTRIBUTE_STANDARD_ICON + ","+123 FileInfo info = null;
132 FILE_ATTRIBUTE_STANDARD_SIZE + ","+124
133 FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 125 try{
126
127 info = file.query_info (FileAttribute.STANDARD_DISPLAY_NAME +","+
128 FileAttribute.STANDARD_ICON + ","+
129 FileAttribute.STANDARD_SIZE + ","+
130 FileAttribute.STANDARD_CONTENT_TYPE,
134 FileQueryInfoFlags.NONE, null);131 FileQueryInfoFlags.NONE, null);
135 }catch (Error e){warning (e.message);}132 } catch (Error e)
136 133 {
137 contracts = new Granite.Widgets.ContractorView (file.get_uri (), info.get_content_type ());134 warning (e.message);
138 contractor = new Gtk.ScrolledWindow (null, null);135 }
139 contractor.add (contracts);136
140 contractor.margin_bottom = 12;137 contracts = new Granite.Widgets.ContractorView (file.get_uri (), info.get_content_type ());
141 138 contractor = new ScrolledWindow (null, null);
142 /*load as image or filetype image*/139 contractor.add (contracts);
143 Gtk.Image img;140 contractor.margin_bottom = 12;
144 try{141 contractor.shadow_type = ShadowType.OUT;
145 var pix = new Gdk.Pixbuf.from_file (file.get_path ());142
146 pix = pix.scale_simple ((int)(1.0 * pix.get_width () / pix.get_height () * 48.0), 48, Gdk.InterpType.HYPER);143 Image img;
147 img = new Gtk.Image.from_pixbuf (pix);144
148 }catch (Error e){145 try{
149 try{146
150 img = new Gtk.Image.from_pixbuf (Gtk.IconTheme.get_default ().lookup_by_gicon (info.get_icon (), 48, 0).load_icon ());147 var pix = new Gdk.Pixbuf.from_file (file.get_path ());
151 }catch (Error e){148 pix = pix.scale_simple ((int)(1.0 * pix.get_width () / pix.get_height () * 48.0), 48, Gdk.InterpType.HYPER);
152 warning (e.message);149 img = new Image.from_pixbuf (pix);
153 img=new Gtk.Image.from_stock (Gtk.Stock.CLOSE, Gtk.IconSize.BUTTON);}150
154 }151 } catch (Error e){
155 img.set_size_request (48, 48);152 try{
156 img.set_pixel_size (48);153 img = new Gtk.Image.from_pixbuf (Gtk.IconTheme.get_default ().lookup_by_gicon (info.get_icon (), 48, 0).load_icon ());
157 154 } catch (Error e){
158 var lbl = new Gtk.Label ("<span color='#aaaaaa'>"+155 warning (e.message);
159 info.get_size ().to_string ()+" "+_("KB")+"</span>");156 img = new Gtk.Image.from_stock (Gtk.Stock.CLOSE, Gtk.IconSize.BUTTON);
160 lbl.use_markup = true;157 }
161 lbl.halign = Gtk.Align.START;158 }
162 159 img.set_size_request (48, 48);
160 img.set_pixel_size (48);
161
162 var lbl = new Label ("<span color='#aaaaaa'>"+human_size(info.get_size ())+"</span>");
163
164 lbl.use_markup = true;
165 lbl.halign = Align.START;
166
167 header = new Grid ();
168
163 header.attach (img, 0, 0, 1, 2);169 header.attach (img, 0, 0, 1, 2);
164 header.attach (new Gtk.Label (info.get_display_name ()), 1, 0, 1, 1);170 header.attach (new Gtk.Label (info.get_display_name ()), 1, 0, 1, 1);
165 header.attach (lbl, 1, 1 ,1, 1);171 header.attach (lbl, 1, 1 ,1, 1);
166 header.margin_bottom = 12;172 header.margin_bottom = 12;
167 173
168 box.remove (image);174 var share = new Button.with_label (_("Share"));
169 box.pack_start (header, false, true, 0);175 share.clicked.connect (() => contracts.run_selected ());
170 box.pack_start (contractor, true, true, 0);176
171 box.reorder_child (header, 0);177 var cancel = new Button.with_label (_("Cancel"));
172 box.reorder_child (contractor, 1);178 cancel.clicked.connect (() => {
173 box.show_all ();179 box.remove (header);
174 }180 box.remove (contractor);
175 181 box.pack_start (image, true, true, 0);
176 public override void activate (){182
177 build_and_run ();183 hbox.remove (cancel);
178 }184 hbox.remove (share);
179 185 hbox.pack_end (close, false, false, 0);
186 main_window.resize (380, 380);
187 });
188
189 hbox.remove (close);
190 hbox.pack_end (share, false, false, 0);
191 hbox.pack_end (cancel, false, false, 0);
192
193 box.remove (image);
194 box.pack_start (header, false, false, 0);
195 box.pack_start (contractor, true, true, 0);
196 box.reorder_child (header, 0);
197 box.reorder_child (contractor, 1);
198 main_window.show_all ();
199
200 }
201
180 public override void open (File [] files, string hint){202 public override void open (File [] files, string hint){
181 if (main_window == null)203 if (main_window == null)
182 build_and_run ();204 build_and_run ();
183 open_file (files[0]);205 open_file (files[0]);
184 }206 }
185 }207
186}208 private string human_size (double size){
187209
188public static int main (string [] args){210 string[] units = {"KB", "MB", "GB", "TB"};
189 Gtk.init (ref args);211 string size_str = size.to_string ()+" "+(size <= 1 ? "Byte" : "Bytes");
190 212 for (int i = 0; (int) size > 1024; i++){
191 var d = new Dropoff.DropoffApp ();213 size = size / 1024;
192 214 size_str = "%.2f %s".printf(size, units[i]);
193 return d.run (args);215 }
194}216 return size_str;
195217 }
218
219 public static int main (string[] args){
220
221 Gtk.init (ref args);
222 var r = new DropoffApp ();
223
224 return r.run (args);
225
226 }
227
228 }
229
230}

Subscribers

People subscribed via source and target branches