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