[gtkmm] Demos: Catch Glib::FileError from demo_find_file().
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] Demos: Catch Glib::FileError from demo_find_file().
- Date: Mon, 22 Jul 2013 14:59:00 +0000 (UTC)
commit b55a57c480a0866f1d53676034ca6c7294b9cc64
Author: Kjell Ahlstedt <kjell ahlstedt bredband net>
Date: Mon Jul 22 16:46:12 2013 +0200
Demos: Catch Glib::FileError from demo_find_file().
* demos/gtk-demo/demo-common.cc: Fix description of demo_find_file().
* demos/gtk-demo/demowindow.cc: Put the call to demo_find_file() in a
try block, and catch Glib::FileError.
demos/gtk-demo/demo-common.cc | 5 ++---
demos/gtk-demo/demowindow.cc | 13 +++++++++++--
2 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/demos/gtk-demo/demo-common.cc b/demos/gtk-demo/demo-common.cc
index 83e4bc7..0c86ebc 100644
--- a/demos/gtk-demo/demo-common.cc
+++ b/demos/gtk-demo/demo-common.cc
@@ -32,13 +32,12 @@ get_democodedir(void)
/**
* demo_find_file:
* @base: base filename
- * @err: location to store error, or %NULL.
*
* Looks for @base first in the current directory, then in the
- * location GTK+ where it will be installed on make install,
+ * location where gtkmm will be installed on make install,
* returns the first file found.
*
- * Return value: the filename, if found or %NULL
+ * Return value: the filename, if found, else throws a Glib::FileError.
**/
std::string demo_find_file(const std::string& base)
{
diff --git a/demos/gtk-demo/demowindow.cc b/demos/gtk-demo/demowindow.cc
index 6763ad2..061746e 100644
--- a/demos/gtk-demo/demowindow.cc
+++ b/demos/gtk-demo/demowindow.cc
@@ -26,6 +26,7 @@
#include <gtkmm/treeviewcolumn.h>
#include <gtkmm/box.h>
#include <glibmm/convert.h>
+#include <glibmm/fileutils.h>
#include "demowindow.h"
#include "textwidget.h"
#include "demos.h"
@@ -268,8 +269,16 @@ void DemoWindow::load_file(const std::string& filename)
FILE* file = fopen (filename.c_str(), "r");
if (!file)
{
- std::string installed = demo_find_file(filename);
- file = fopen (installed.c_str(), "r");
+ try
+ {
+ std::string installed = demo_find_file(filename);
+ file = fopen (installed.c_str(), "r");
+ }
+ catch (const Glib::FileError& ex)
+ {
+ g_warning ("%s\n", ex.what().c_str());
+ return;
+ }
}
if (!file)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]