[glom/gtkapplication] Add a Gtk::Application subclass, used by main().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/gtkapplication] Add a Gtk::Application subclass, used by main().
- Date: Fri, 10 Feb 2012 09:10:14 +0000 (UTC)
commit 9bd0cf1a898d667bb27af721a4dcb471a902a569
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Feb 10 10:09:50 2012 +0100
Add a Gtk::Application subclass, used by main().
* Makefile.am:
* main.cc:
* glom/application.[h|cc]: Use a derived Gtk::Application which instantiates
the Glom::AppWindow via its on_open(). Some command-line option handling is
temporarily commented out.
ChangeLog | 10 +++++
Makefile_glom.am | 2 +
glom/application.cc | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++
glom/application.h | 52 +++++++++++++++++++++++++++
glom/main.cc | 30 ++++++----------
5 files changed, 172 insertions(+), 19 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 68412ae..6612fb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2012-02-10 Murray Cumming <murrayc murrayc com>
+
+ Add a Gtk::Application subclass, used by main().
+
+ * Makefile.am:
+ * main.cc:
+ * glom/application.[h|cc]: Use a derived Gtk::Application which instantiates
+ the Glom::AppWindow via its on_open(). Some command-line option handling is
+ temporarily commented out.
+
2012-02-09 Murray Cumming <murrayc murrayc com>
Rename Application to AppWindow.
diff --git a/Makefile_glom.am b/Makefile_glom.am
index f9b9721..ce41894 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -67,6 +67,8 @@ glom_canvas_files = \
glom/utility_widgets/canvas/canvas_text_movable.h
glom_source_files = \
+ glom/application.cc \
+ glom/application.h \
glom/appwindow.cc \
glom/appwindow.h \
glom/base_db.cc \
diff --git a/glom/application.cc b/glom/application.cc
new file mode 100644
index 0000000..7ae44a7
--- /dev/null
+++ b/glom/application.cc
@@ -0,0 +1,97 @@
+/* Glom
+ *
+ * Copyright (C) 2012 Murray Cumming
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "application.h"
+#include "appwindow.h"
+#include <glom/glade_utils.h>
+#include <iostream>
+
+namespace Glom
+{
+
+Application::Application()
+: Gtk::Application("org.glom.application", Gio::APPLICATION_HANDLES_OPEN)
+{
+}
+
+Glib::RefPtr<Application> Application::create()
+{
+ return Glib::RefPtr<Application>( new Application() );
+}
+
+void Application::create_window(const Glib::RefPtr<Gio::File>& file)
+{
+ AppWindow* window = 0;
+ Glom::Utils::get_glade_widget_derived_with_warning(window);
+ g_assert(window);
+
+ //Make sure that the application runs for as long this window is still open:
+ add_window(*window);
+
+ //Delete the window when it is hidden:
+ window->signal_hide().connect(sigc::bind<Gtk::Window*>(sigc::mem_fun(*this,
+ &Application::on_window_hide), window));
+
+ Glib::ustring input_uri;
+ if(file) //If it's empty then this is a new empty file, as a result of an activation rather than an open.
+ {
+ input_uri = file->get_uri();
+ }
+
+ const bool test = window->init(input_uri, false /* TODO: group.m_arg_restore */); //Sets it up and shows it.
+ if(!test) //The user could cancel the offer of a new or existing database.
+ {
+ window->hide(); //This will cause it to be deleted by on_window_hide.
+ }
+}
+
+void Application::on_window_hide(Gtk::Window* window)
+{
+ delete window;
+}
+
+void Application::on_activate()
+{
+ //std::cout << "debug1: " << G_STRFUNC << std::endl;
+ // The application has been started, so let's show a window:
+ create_window();
+}
+
+void Application::on_open(const Gio::Application::type_vec_files& files,
+ const Glib::ustring& hint)
+{
+ // The application has been asked to open some files,
+ // so let's open a new window for each one.
+ //std::cout << "debug: files.size()=" << files.size() << std::endl;
+ for(guint i = 0; i < files.size(); i++)
+ {
+ Glib::RefPtr<Gio::File> file = files[i];
+ if(!file)
+ {
+ std::cerr << G_STRFUNC << ": file is null." << std::endl;
+ }
+ else
+ create_window(file);
+ }
+
+ Application::on_open(files, hint);
+}
+
+} //namespace Glom
diff --git a/glom/application.h b/glom/application.h
new file mode 100644
index 0000000..3f4ed97
--- /dev/null
+++ b/glom/application.h
@@ -0,0 +1,52 @@
+/* Glom
+ *
+ * Copyright (C) 2012 Murray Cumming
+ *
+ * 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GLOM_APPLICATION_H
+#define GLOM_APPLICATION_H
+
+
+#include <gtkmm/application.h>
+
+namespace Glom
+{
+
+class Application: public Gtk::Application
+{
+protected:
+ Application();
+
+public:
+ static Glib::RefPtr<Application> create();
+
+protected:
+ //Overrides of default signal handlers:
+ virtual void on_activate();
+ virtual void on_open(const Gio::Application::type_vec_files& files,
+ const Glib::ustring& hint);
+
+private:
+ void create_window(const Glib::RefPtr<Gio::File>& file = Glib::RefPtr<Gio::File>());
+
+ void on_window_hide(Gtk::Window* window);
+};
+
+} //namespace Glom
+
+#endif /* GTKMM_APPLICATION_H */
diff --git a/glom/main.cc b/glom/main.cc
index e4822f9..9ce4a81 100644
--- a/glom/main.cc
+++ b/glom/main.cc
@@ -27,7 +27,8 @@
//#include <gnome.h>
#include <gtkmm/messagedialog.h>
#include <glom/libglom/init.h>
-#include <glom/glade_utils.h>
+#include <glom/libglom/connectionpool.h>
+#include <glom/libglom/utils.h>
#include <gtkmm/main.h>
#include <giomm/file.h>
@@ -52,8 +53,7 @@
#include <goocanvasmm/init.h>
#endif // !GLOM_ENABLE_CLIENT_ONLY
-#include <glom/appwindow.h>
-#include <glom/glade_utils.h>
+#include <glom/application.h>
#include <glom/utils_ui.h>
#include <evince-view.h>
@@ -614,23 +614,15 @@ main(int argc, char* argv[])
return date_check_ok ? EXIT_SUCCESS : EXIT_FAILURE; //This command-line option is documented as stopping afterwards.
}
- Glom::AppWindow* pAppWindow = 0;
- Glom::Utils::get_glade_widget_derived_with_warning(pAppWindow);
- g_assert(pAppWindow);
+ Glib::RefPtr<Glom::Application> application =
+ Glom::Application::create();
+ //TODO: application->set_show_sql_debug(group.m_arg_debug_sql);
+ //TODO: application->set_stop_auto_server_shutdown(group.m_arg_stop_auto_server_shutdown);
+ Glom::ConnectionPool::get_instance()->set_show_debug_output(group.m_arg_debug_sql); //TODO: Put this in Application::set_show_sql_debug().
- pAppWindow->set_command_line_args(argc, argv);
- pAppWindow->set_show_sql_debug(group.m_arg_debug_sql);
- pAppWindow->set_stop_auto_server_shutdown(group.m_arg_stop_auto_server_shutdown);
- Glom::ConnectionPool::get_instance()->set_show_debug_output(group.m_arg_debug_sql);
-
- const bool test = pAppWindow->init(input_uri, group.m_arg_restore); //Sets it up and shows it.
-
- if(test) //The user could cancel the offer of a new or existing database.
- Gtk::Main::run(*pAppWindow); //Quit when the window is closed.
-
- //Cleanup:
- delete pAppWindow;
- pAppWindow = 0;
+ const int status = application->run(argc, argv);
+ if(status != EXIT_SUCCESS) //TODO: Is this right?
+ return status;
}
catch(const Glib::Exception& ex)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]