diff options
author | David Robillard <d@drobilla.net> | 2011-05-20 03:27:08 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2011-05-20 03:27:08 +0000 |
commit | e86465f6b554033be89e7e0a0b8c50fd1105c80a (patch) | |
tree | 420700bdd5d63ffb2972e05ea558186ed0f6a7b1 /src/gui/WidgetFactory.hpp | |
parent | 4735eba0accf93893930abaf0a117e6bad77e0d0 (diff) | |
download | machina-e86465f6b554033be89e7e0a0b8c50fd1105c80a.tar.gz machina-e86465f6b554033be89e7e0a0b8c50fd1105c80a.tar.bz2 machina-e86465f6b554033be89e7e0a0b8c50fd1105c80a.zip |
Remove dependency on glade and glademm (migrate to GtkBuilder).
git-svn-id: http://svn.drobilla.net/lad/trunk/machina@3295 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/gui/WidgetFactory.hpp')
-rw-r--r-- | src/gui/WidgetFactory.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/gui/WidgetFactory.hpp b/src/gui/WidgetFactory.hpp new file mode 100644 index 0000000..79d7412 --- /dev/null +++ b/src/gui/WidgetFactory.hpp @@ -0,0 +1,59 @@ +/* This file is part of Machina. + * Copyright 2007-2011 David Robillard <http://drobilla.net> + * + * Machina is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Machina is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Machina. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <fstream> +#include <iostream> +#include <string> + +#include <gtkmm.h> + +#include "machina-config.h" + +class WidgetFactory +{ +public: + static Glib::RefPtr<Gtk::Builder> create() { + Glib::RefPtr<Gtk::Builder> xml; + + // Check for the .ui file in current directory + std::string ui_filename = "./machina.ui"; + std::ifstream fs(ui_filename.c_str()); + if (fs.fail()) { // didn't find it, check MACHINA_DATA_DIR + fs.clear(); + ui_filename = MACHINA_DATA_DIR; + ui_filename += "/machina.ui"; + + fs.open(ui_filename.c_str()); + if (fs.fail()) { + std::cerr << "Unable to find machina.ui in current directory or " + << MACHINA_DATA_DIR << "." << std::endl; + exit(EXIT_FAILURE); + } + fs.close(); + } + + try { + xml = Gtk::Builder::create_from_file(ui_filename); + } catch(const Gtk::BuilderError& ex) { + std::cerr << ex.what() << std::endl; + throw ex; + } + + return xml; + } +}; + |