← Back to team overview

elementary-dev-community team mailing list archive

[Merge] lp:~davysson-s/dropoff/using-lightwindow into lp:dropoff

 

DavyS has proposed merging lp:~davysson-s/dropoff/using-lightwindow into lp:dropoff.

Requested reviews:
  elementary Developer Community (elementary-dev-community)

For more details, see:
https://code.launchpad.net/~davysson-s/dropoff/using-lightwindow/+merge/111142

Using Granite.Widgets.LightWindow instead of Gtk.Window
-- 
https://code.launchpad.net/~davysson-s/dropoff/using-lightwindow/+merge/111142
Your team elementary Developer Community is requested to review the proposed merge of lp:~davysson-s/dropoff/using-lightwindow into lp:dropoff.
=== 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 @@
 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/48x48/dropoff.svg DESTINATION share/icons/hicolor/48x48/apps/)
 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/64x64/dropoff.svg DESTINATION share/icons/hicolor/64x64/apps/)
 install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/icons/apps/128x128/dropoff.svg DESTINATION share/icons/hicolor/128x128/apps/)
-install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/drop_files.png DESTINATION share/${NAME})
+install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/drop_files.png DESTINATION ${PKGDATADIR})
 

=== 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 @@
 using Gtk;
-
-
-namespace Dropoff{
-    public class DropoffApp : Granite.Application{
-    
+using Granite;
+
+namespace Dropoff {
+	
+	public class DropoffApp : Granite.Application {
+		
+		public Granite.Widgets.LightWindow main_window;
+		public Image image;
+		public Box box;
+		public Box hbox;
+        public Granite.Widgets.ContractorView contracts;
+        public ScrolledWindow contractor;
+        public Grid header;
+        public Button close;
+		
         construct{
             application_id = "org.elementary.dropoff";
             program_name = "Dropoff";
@@ -32,164 +42,189 @@
             build_version = Constants.VERSION;
             build_version_info = Constants.VERSION_INFO;
         }
-        
-        public Gtk.Window main_window;
-        public Image image;
-        public Box box;
-        public Granite.Widgets.ContractorView contracts;
-        public Gtk.ScrolledWindow contractor;
-        public Gtk.Grid header;
-        
+		
         public DropoffApp (){
-            this.set_flags (ApplicationFlags.HANDLES_OPEN);
+            this.set_flags (ApplicationFlags.HANDLES_OPEN);			
         }
-        
-        private void build_and_run (){
-            main_window = new Gtk.Window ();
-            main_window.set_application (this);
-            main_window.window_position = Gtk.WindowPosition.CENTER;
-            main_window.set_size_request (380, 380);
-            
-            TargetEntry e = {"text/uri-list", 0, 0};
-            
-            //IMAGE
-            image = new Image.from_file (build_pkg_data_dir+"/drop_files.png");
-            image.drag_data_received.connect (process_drag_data);
-            drag_dest_set (image, DestDefaults.ALL, {e}, Gdk.DragAction.COPY);
-            
-            var label = _("Drag a file here");
-            
-            image.draw.connect ( (ctx) => {
-                Cairo.TextExtents ext;
+		
+        public override void activate (){
+			
+            if (main_window == null)
+				build_and_run ();
+			
+		}
+		
+		public void build_and_run (){
+			
+			main_window = new Granite.Widgets.LightWindow ();
+			main_window.title = "Dropoff";
+			main_window.set_size_request (380,380);
+			main_window.set_application (this);
+			main_window.destroy.connect (Gtk.main_quit);
+			main_window.window_position = WindowPosition.CENTER;
+			
+			var label = _("Drag a file here");
+			
+			TargetEntry e = {"text/uri-list", 0, 0};
+			
+			image = new Image.from_file (build_pkg_data_dir+"/drop_files.png");
+			image.drag_data_received.connect (process_drag_data);
+			drag_dest_set (image, DestDefaults.ALL, {e}, Gdk.DragAction.COPY);
+			
+			image.draw.connect ((ctx) => {
+				Cairo.TextExtents ext;
                 ctx.text_extents (label, out ext);
                 ctx.move_to (image.get_allocated_width  ()/2 - ext.width /2, 
                              image.get_allocated_height ()/2 - ext.height/2 + 80);
                 ctx.show_text (label);
                 return false;
-            });
-            
-            //FILEVIEW
-            box = new Box (Orientation.VERTICAL, 0);
-            box.margin = 12;
-            
-            header = new Gtk.Grid ();
-            
-            var about    = new Gtk.Button.with_label (_("About"));
-            var cancel   = new Gtk.Button.with_label (_("Cancel"));
-            var share    = new Gtk.Button.with_label (_("Share"));
-            
-            share.can_default = true;
-            share.grab_focus ();
-            
-            var b = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
-            
-            b.pack_start (about, false, false, 0);
-            b.pack_end   (share, false, false, 0);
-            b.pack_end   (cancel, false, false, 0);
-            
-            box.pack_start (image, true, true, 0);
-            box.pack_start (b, false, false, 0);
-            
-            main_window.add (box);
-            main_window.show_all ();
-            main_window.set_default (share);
-            
-            share.hide ();
-            /*
-             * events
-             */
-            share.clicked.connect ( ()=>{
-                contracts.run_selected ();
-                main_window.destroy ();
-            });
-            cancel.clicked.connect ( () => {
-                main_window.destroy ();
-            });
-            about.clicked.connect ( () => {
-                this.show_about (this.main_window);
-            });
-        }
-        
-        void process_drag_data (Widget widget, Gdk.DragContext ctx, 
+				});
+			
+			var about = new Button.with_label (_("About"));
+			close = new Button.with_label (_("Close"));
+			
+			hbox = new Box (Orientation.HORIZONTAL, 0);
+			
+			hbox.pack_start (about, false, false, 0);
+			hbox.pack_end (close, false, false, 0);
+			
+			box = new Box (Orientation.VERTICAL, 0);
+			box.margin = 12;
+			
+			box.pack_start (image, true, true, 0);
+			box.pack_end (hbox, false, false, 0);
+			
+			
+			main_window.add (box);
+			main_window.show_all ();
+			
+			about.clicked.connect (() => this.show_about (this.main_window));
+			close.clicked.connect (() => main_window.destroy ());
+		}
+		
+		private void process_drag_data (Widget widget, Gdk.DragContext ctx, 
             int x, int y, SelectionData sel, uint information, uint timestamp){
-            if (sel.get_length () > 0){
-                var file = File.new_for_uri (sel.get_uris ()[0]);
-                
-                open_file (file);
-                
-                Gtk.drag_finish (ctx, true, false, timestamp);
-                
-                return;
-            }
-            Gtk.drag_finish (ctx, false, false, timestamp);
-        }
-        
-        void open_file (File file){
-            FileInfo info = null;
-            try{
-            info = file.query_info (FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME +","+ 
-                                        FILE_ATTRIBUTE_STANDARD_ICON + ","+
-                                        FILE_ATTRIBUTE_STANDARD_SIZE + ","+
-                                        FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, 
+			
+			if (sel.get_length () > 0) {
+				
+				var file = File.new_for_uri (sel.get_uris ()[0]);
+				open_file (file);
+				
+				Gtk.drag_finish (ctx, true, false, timestamp);
+				
+				return;
+			}
+			Gtk.drag_finish (ctx, false, false, timestamp);
+			
+		}
+		
+		private void open_file (File file){
+			
+			FileInfo info = null;
+			
+			try{
+				
+            info = file.query_info (FileAttribute.STANDARD_DISPLAY_NAME +","+ 
+                                        FileAttribute.STANDARD_ICON + ","+
+                                        FileAttribute.STANDARD_SIZE + ","+
+                                        FileAttribute.STANDARD_CONTENT_TYPE, 
                                         FileQueryInfoFlags.NONE, null);
-            }catch (Error e){warning (e.message);}
-            
-            contracts  = new Granite.Widgets.ContractorView (file.get_uri (), info.get_content_type ());
-            contractor = new Gtk.ScrolledWindow (null, null);
-            contractor.add (contracts);
-            contractor.margin_bottom = 12;
-            
-            /*load as image or filetype image*/
-            Gtk.Image img;
-            try{
-                var pix = new Gdk.Pixbuf.from_file (file.get_path ());
-                pix = pix.scale_simple ((int)(1.0 * pix.get_width () / pix.get_height () * 48.0), 48, Gdk.InterpType.HYPER);
-                img = new Gtk.Image.from_pixbuf (pix);
-            }catch (Error e){
-                try{
-                    img = new Gtk.Image.from_pixbuf (Gtk.IconTheme.get_default ().lookup_by_gicon (info.get_icon (), 48, 0).load_icon ());
-                }catch (Error e){
-                    warning (e.message);
-                    img=new Gtk.Image.from_stock (Gtk.Stock.CLOSE, Gtk.IconSize.BUTTON);}
-            }
-            img.set_size_request (48, 48);
-            img.set_pixel_size (48);
-            
-            var lbl = new Gtk.Label ("<span color='#aaaaaa'>"+
-                info.get_size ().to_string ()+" "+_("KB")+"</span>");
-            lbl.use_markup = true;
-            lbl.halign = Gtk.Align.START;
-            
+            } catch (Error e)
+            {
+				warning (e.message);	
+			}
+            
+			contracts = new Granite.Widgets.ContractorView (file.get_uri (), info.get_content_type ());
+			contractor = new ScrolledWindow (null, null);
+			contractor.add (contracts);
+			contractor.margin_bottom = 12;
+			contractor.shadow_type = ShadowType.OUT;
+			
+			Image img;
+			
+			try{
+				
+				var pix = new Gdk.Pixbuf.from_file (file.get_path ());
+				pix = pix.scale_simple ((int)(1.0 * pix.get_width () / pix.get_height () * 48.0), 48, Gdk.InterpType.HYPER);
+				img = new Image.from_pixbuf (pix);
+				
+			} catch (Error e){
+				try{
+					img = new Gtk.Image.from_pixbuf (Gtk.IconTheme.get_default ().lookup_by_gicon (info.get_icon (), 48, 0).load_icon ());
+				} catch (Error e){
+					warning (e.message);
+					img = new Gtk.Image.from_stock (Gtk.Stock.CLOSE, Gtk.IconSize.BUTTON);
+				}
+			}
+			img.set_size_request (48, 48);
+			img.set_pixel_size (48);
+			
+			var lbl = new Label ("<span color='#aaaaaa'>"+human_size(info.get_size ())+"</span>");
+			
+			lbl.use_markup = true;
+			lbl.halign = Align.START;
+			
+			header = new Grid ();
+			
             header.attach (img,                                      0, 0, 1, 2);
             header.attach (new Gtk.Label (info.get_display_name ()), 1, 0, 1, 1);
             header.attach (lbl,                                      1, 1 ,1, 1);
             header.margin_bottom = 12;
-            
-            box.remove (image);
-            box.pack_start (header, false, true, 0);
-            box.pack_start (contractor, true, true, 0);
-            box.reorder_child (header,     0);
-            box.reorder_child (contractor, 1);
-            box.show_all ();
-        }
-        
-        public override void activate (){
-            build_and_run ();
-        }
-        
+			
+			var share = new Button.with_label (_("Share"));
+			share.clicked.connect (() => contracts.run_selected ());
+			
+			var cancel = new Button.with_label (_("Cancel"));
+			cancel.clicked.connect (() => {
+				box.remove (header);
+				box.remove (contractor);
+				box.pack_start (image, true, true, 0);
+				
+				hbox.remove (cancel);
+				hbox.remove (share);
+				hbox.pack_end (close, false, false, 0);
+				main_window.resize (380, 380);
+				});
+			
+			hbox.remove (close);
+			hbox.pack_end (share, false, false, 0);
+			hbox.pack_end (cancel, false, false, 0);
+			
+			box.remove (image);
+			box.pack_start (header, false, false, 0);
+			box.pack_start (contractor, true, true, 0);
+			box.reorder_child (header, 0);
+			box.reorder_child (contractor, 1);
+			main_window.show_all ();
+			
+		}
+
         public override void open (File [] files, string hint){
             if (main_window == null)
                 build_and_run ();
             open_file (files[0]);
         }
-    }
-}
-
-public static int main (string [] args){
-    Gtk.init (ref args);
-    
-    var d = new Dropoff.DropoffApp ();
-    
-    return d.run (args);
-}
-
+		
+		private string human_size (double size){
+			
+			string[] units = {"KB", "MB", "GB", "TB"};
+			string size_str = size.to_string ()+" "+(size <= 1 ? "Byte" : "Bytes");
+			for (int i = 0; (int) size > 1024; i++){
+				size = size / 1024;
+				size_str = "%.2f %s".printf(size, units[i]);
+			}
+			return size_str;
+		}
+		
+		public static int main (string[] args){
+			
+			Gtk.init (ref args);
+			var r = new DropoffApp ();
+			
+			return r.run (args);
+			
+		}
+		
+	}
+		
+}


Follow ups