Source

gnome-record-screen / GNOME-Record-Screen / src / UI / SaveDialog.cs

Full commit
/**
 * SaveDIalog.cs
 *
 * :copyright: 2008 mitsuhiko.
 * :license: BSD
 */

using System;
using System.IO;
using Gtk;

using Gnome.RecordScreen;
using Gnome.RecordScreen.UI;

namespace Gnome.RecordScreen {
	
	public class SaveDialog : Gtk.FileChooserDialog {
		private ScreenRecorder recorder;
		
		public SaveDialog (MainWindow mainWindow)
			: base ("Save record", mainWindow,
			        FileChooserAction.Save,
			        Gtk.Stock.Cancel, ResponseType.Cancel,
			        Gtk.Stock.Save, ResponseType.Accept)
		{
			recorder = mainWindow.Recorder;
			VideoEncoder enc = recorder.VideoEncoder;
			
			// the filter for the selected container
			FileFilter filter = new FileFilter ();
			foreach (string ext in enc.Container.Extensions)
				filter.AddPattern ("*" + ext);
			filter.Name = recorder.VideoEncoder.Name;
			AddFilter (filter);
			Filter = filter;
			
			// and for all files
			filter = new FileFilter ();
			filter.AddPattern ("*");
			filter.Name = "All files";
			AddFilter (filter);
			
			DoOverwriteConfirmation = true;
			
			CurrentName = Utils.AddDateToFilename ("Recorded Desktop") +
				enc.Container.Extensions[0];
		}
		
		public void MoveOrDelete ()
		{
			if ((ResponseType)Run() == ResponseType.Accept) {
				if (File.Exists (Filename))
					File.Delete (Filename);
				File.Move (recorder.TemporaryFilename, Filename);
			}
			else
				File.Delete (recorder.TemporaryFilename);
			Destroy ();
		}
	}
}