Commits

Andreas Tscharner committed 45404cf

gui: Added a MainWindow class to handle all the stuff of the main window

Comments (0)

Files changed (5)

 src/example/ShowImage
 src/example/PlaySound
 
+# src/gui/ directory
+src/gui/lrcResourceEditor
+
 # src/strategies/cryptopp/ directory
 src/strategies/cryptopp/libcryptopp.a

src/gui/MainWindow.cxx

+/*
+ * MainWindow.cxx
+ *
+ * Copyright 2012 Andreas Tscharner <andy@vis.ethz.ch>
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+
+#include "MainWindow.hxx"
+
+
+MainWindow::MainWindow(Gtk::Window *p_mainWin, Glib::RefPtr<Gnome::Glade::Xml> p_xmlRef)
+{
+	m_mainWindow = p_mainWin;
+	m_xmlRef = p_xmlRef;
+}
+
+MainWindow::~MainWindow()
+{
+	m_mainWindow = nullptr;
+}

src/gui/MainWindow.hxx

+/*
+ * MainWindow.h
+ *
+ * Copyright 2012 Andreas Tscharner <andy@vis.ethz.ch>
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+
+/*! \file MainWindow.hxx
+ *
+ * This file contains the declaration of the MainWindow class. This class
+ * is responsible for all stuff of the main window.
+ * It may delegate some tasks (like the menu or the list view) to separate
+ * classes
+ *
+ * \author Andreas Tscharner
+ * \date 2012-05-27
+ */
+
+
+#ifndef __MAINWINDOW_HXX__
+#define __MAINWINDOW_HXX__
+
+
+// Include files
+#include <gtkmm.h>
+#include <libglademm/xml.h>
+
+
+/*! \class MainWindow
+ *  \brief Class to handle the main window
+ *
+ * This class handles all the stuff of the main window. It uses other
+ * classes to handle some special tasks (like the menu or the list view)
+ */
+class MainWindow
+{
+	private:
+		Gtk::Window *m_mainWindow;     //!< Reference to main window class
+		Glib::RefPtr<Gnome::Glade::Xml> m_xmlRef;     //!< Reference to XML decribing the GUI of the application
+
+	public:
+		/*! \brief Constructor
+		 *
+		 * The constructor for the MainWindow class. It needs a pointer to
+		 * the window and a reference pointer to the glade file as parameters
+		 *
+		 * \param[in] p_mainWin Pointer to GTK window
+		 * \param[in] p_xmlRef Reference pointer to loaded glade file
+		 */
+		MainWindow(Gtk::Window *, Glib::RefPtr<Gnome::Glade::Xml>);
+		/*! \brief Destructor
+		 *
+		 * The destructor cleans up any used memory from this class
+		 */
+		~MainWindow();
+};
+
+
+#endif /* __MAINWINDOW_HXX__ */

src/gui/Makefile.am

 
 #
 # Define source files for main program
-lrcResourceEditor_SOURCES = lrcResourceEditor.cxx
+lrcResourceEditor_SOURCES = MainWindow.hxx MainWindow.cxx \
+                            lrcResourceEditor.cxx
 
 #
 # Library flags for main program

src/gui/lrcResourceEditor.cxx

 #include <libglademm/xml.h>
 #include <gtkmm/main.h>
 #include <gtkmm/window.h>
+#include <iostream>
+#include "MainWindow.hxx"
 
 int main(int argc, char **argv)
 {
 	Glib::RefPtr<Gnome::Glade::Xml> xmlRef;
 	Gtk::Window *mainWin = nullptr;
+	MainWindow *mainWinTasks;
 
 
 	Gtk::Main mainPrg(argc, argv);
 
-	xmlRef = Gnome::Glade::Xml::create("ResourceEditor.glade");
+	try {
+		xmlRef = Gnome::Glade::Xml::create("ResourceEditor.glade");
+	} catch (Gnome::Glade::XmlError &xmlErr) {
+		std::cout << "Loading the ResourceEditor.glade failed for the following reason: " << xmlErr.what() << std::endl;
+		return -1;
+	};
 	mainWin = xmlRef->get_widget("MainWindow", mainWin);
 
-	//TODO: Create new class to handle GUI
+	mainWinTasks = new MainWindow(mainWin, xmlRef);
 
 	mainPrg.run(*mainWin);
 	mainWin->hide_all();
 
+	delete mainWinTasks;
+
 	return 0;
 }