[longomatch] Fail gracefully when the file format is not supported
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Fail gracefully when the file format is not supported
- Date: Tue, 14 Oct 2014 15:47:46 +0000 (UTC)
commit 29a7bd226caf54abdcbfad93398c8a2a362188a9
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Mon Oct 13 20:47:26 2014 +0200
Fail gracefully when the file format is not supported
LongoMatch.GUI.Helpers/Misc.cs | 32 +++++++++++++++++++-------------
1 files changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/LongoMatch.GUI.Helpers/Misc.cs b/LongoMatch.GUI.Helpers/Misc.cs
index dfce65f..975008e 100644
--- a/LongoMatch.GUI.Helpers/Misc.cs
+++ b/LongoMatch.GUI.Helpers/Misc.cs
@@ -49,33 +49,39 @@ namespace LongoMatch.Gui.Helpers
return filter;
}
- public static Pixbuf OpenImage(Widget widget) {
+ public static Pixbuf OpenImage (Widget widget)
+ {
Gtk.Window toplevel = widget.Toplevel as Gtk.Window;
Pixbuf pimage = null;
StreamReader file;
FileChooserDialog fChooser;
string lastDir;
- if (lastFilename != null) {
+ if (lastFilename != null) {
lastDir = Path.GetDirectoryName (lastFilename);
- } else {
+ } else {
lastDir = Config.HomeDir;
- }
+ }
- fChooser = new FileChooserDialog(Catalog.GetString("Choose an image"),
+ fChooser = new FileChooserDialog (Catalog.GetString ("Choose an image"),
toplevel, FileChooserAction.Open,
- "gtk-cancel",ResponseType.Cancel,
- "gtk-open",ResponseType.Accept);
- fChooser.AddFilter(GetFileFilter());
+ "gtk-cancel", ResponseType.Cancel,
+ "gtk-open", ResponseType.Accept);
+ fChooser.AddFilter (GetFileFilter ());
fChooser.SetCurrentFolder (lastDir);
- if(fChooser.Run() == (int)ResponseType.Accept) {
+ if (fChooser.Run () == (int)ResponseType.Accept) {
// For Win32 compatibility we need to open the image file
// using a StreamReader. Gdk.Pixbuf(string filePath) uses GLib to open the
// input file and doesn't support Win32 files path encoding
- lastFilename = fChooser.Filename;
- file = new StreamReader(fChooser.Filename);
- pimage= new Gdk.Pixbuf(file.BaseStream);
- file.Close();
+ try {
+ lastFilename = fChooser.Filename;
+ file = new StreamReader (fChooser.Filename);
+ pimage = new Gdk.Pixbuf (file.BaseStream);
+ file.Close ();
+ } catch (Exception ex) {
+ Log.Exception (ex);
+ Config.GUIToolkit.ErrorMessage (Catalog.GetString ("Image file format
not supported"), widget);
+ }
}
fChooser.Destroy();
return pimage;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]