Index: youtube.py
===================================================================
--- youtube.py	(revision 5543)
+++ youtube.py	(working copy)
@@ -122,7 +122,20 @@
 				   False)
 		menu_item = ui_manager.get_action ("/ui/totem-video-list-popup/open-in-web-browser")
 		menu_item.connect ("activate", self.on_open_in_web_browser_activated)
+		"""Save as... menu"""
+		action = gtk.Action ("save-as", _("_Save as..."), _("Save the video locally"), "gtk-save-as")
+		action_group.add_action_with_accel (action, None)
 
+		ui_manager.insert_action_group (action_group, 2)
+		ui_manager.add_ui (ui_manager.new_merge_id (),
+				   "/ui/totem-video-list-popup/",
+				   "save-as",
+				   "save-as",
+				   gtk.UI_MANAGER_MENUITEM,
+				   False)
+		menu_item = ui_manager.get_action ("/ui/totem-video-list-popup/save-as")
+		menu_item.connect ("activate", self.on_save_as_activated)
+
 		self.vadjust[treeview_name] = treeview.get_vadjustment ()
 		self.vadjust[treeview_name].connect ("value-changed", self.on_value_changed)
 		vscroll = self.builder.get_object ("yt_scrolled_window_" + treeview_name).get_vscrollbar ()
@@ -182,6 +195,40 @@
 
 		"""Open the video in the browser"""
 		os.spawnlp (os.P_NOWAIT, "xdg-open", "xdg-open", "http://www.youtube.com/watch?v=" + urllib.quote (youtube_id) + self.get_fmt_string ())
+	def on_save_as_activated(self, action):
+		model, rows = self.treeview[self.current_treeview_name].get_selection ().get_selected_rows ()
+		iter = model.get_iter (rows[0])
+		video_title = model.get_value (iter, 1)
+		video_url = model.get_value (iter, 2)
+
+		"""Open the save as dialog"""
+		# create a new dialog 
+		dialog = gtk.FileChooserDialog(title=_("Save as"),action=gtk.FILE_CHOOSER_ACTION_SAVE,
+                                  buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_SAVE,gtk.RESPONSE_OK))
+		dialog.set_current_name(video_title + ".flv")
+		dialog.set_do_overwrite_confirmation(True)
+
+		response = dialog.run()
+		if response == gtk.RESPONSE_OK:
+			filename = dialog.get_filename()
+		else:
+			dialog.destroy()
+			return
+		dialog.destroy()
+
+		"""Download the url, doing it the in the background would be better but
+		thread management is a headacke with pyGtk"""
+		self.progress_bar.set_text (_("Saving video..."))
+		self.progress_bar.set_fraction (0.0)
+		urllib.urlretrieve(video_url, filename, self.download_report_cb)
+		self.progress_bar.set_text ("")
+		self.progress_bar.set_fraction (0.0)
+	def download_report_cb (self, blocks, blck_size, total):
+		fraction = float (blocks * blck_size) / float (total)
+		if fraction > 0.0 and fraction < 1.0:
+			self.progress_bar.set_fraction (fraction)
+		while gtk.events_pending():
+			gtk.main_iteration()
 	def on_button_press_event (self, widget, event):
 		self.button_down = True
 	def on_button_release_event (self, widget, event):
