bakery r136 - in trunk: . bakery/App examples/WithXmlDoc
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: bakery r136 - in trunk: . bakery/App examples/WithXmlDoc
- Date: Thu, 19 Mar 2009 20:03:26 +0000 (UTC)
Author: murrayc
Date: Thu Mar 19 20:03:26 2009
New Revision: 136
URL: http://svn.gnome.org/viewvc/bakery?rev=136&view=rev
Log:
2009-03-19 Murray Cumming <murrayc murrayc com>
* configure.in: Depend on libunique-1.0
* bakery/App/App_WithDoc_Gtk.[h|cc]: Added set_unique_app(), to make
the app handle UniqueApp messages, to start new instances or open files.
* examples/WithXmlDoc/main.cc: Use the new API. There is still some
libunique code here that I would like to hide.
Modified:
trunk/ChangeLog
trunk/bakery/App/App_WithDoc.cc
trunk/bakery/App/App_WithDoc.h
trunk/bakery/App/App_WithDoc_Gtk.cc
trunk/bakery/App/App_WithDoc_Gtk.h
trunk/configure.in
trunk/examples/WithXmlDoc/main.cc
Modified: trunk/bakery/App/App_WithDoc.cc
==============================================================================
--- trunk/bakery/App/App_WithDoc.cc (original)
+++ trunk/bakery/App/App_WithDoc.cc Thu Mar 19 20:03:26 2009
@@ -37,7 +37,7 @@
: App(appname),
m_pDocument(0),
m_bCloseAfterSave(false)
-{
+{
}
App_WithDoc::~App_WithDoc()
Modified: trunk/bakery/App/App_WithDoc.h
==============================================================================
--- trunk/bakery/App/App_WithDoc.h (original)
+++ trunk/bakery/App/App_WithDoc.h Thu Mar 19 20:03:26 2009
@@ -132,6 +132,7 @@
///override this to show document contents.
virtual bool on_document_load();
+
virtual void offer_to_save_changes();
///Stop the File|Close or the File|Exit.
Modified: trunk/bakery/App/App_WithDoc_Gtk.cc
==============================================================================
--- trunk/bakery/App/App_WithDoc_Gtk.cc (original)
+++ trunk/bakery/App/App_WithDoc_Gtk.cc Thu Mar 19 20:03:26 2009
@@ -321,4 +321,70 @@
#endif // GTKMM_GEQ_2_10
}
+void App_WithDoc_Gtk::set_unique_app(UniqueApp* unique_app)
+{
+ // The UniqueApp instance must "watch" all the top-level windows the application
+ // creates, so that it can terminate the startup notification sequence for us
+ unique_app_watch_window (unique_app, GTK_WINDOW(gobj()));
+
+ // Handle messages from other instances that try to start:
+ g_signal_connect (unique_app, "message-received", G_CALLBACK(&Bakery::App_WithDoc_Gtk::on_unique_app_message_received), this /* user_data */);
+
+}
+
+// This handles messages from other UniqueApp instances,
+// to our single instance,
+// sent to the signal instance before the extra instances quit,
+// soon after they start.
+UniqueResponse App_WithDoc_Gtk::on_unique_app_message_received(UniqueApp* app,
+ UniqueCommand command,
+ UniqueMessageData* message,
+ guint time_,
+ gpointer user_data)
+{
+ App_WithDoc_Gtk* pApp = static_cast<App_WithDoc_Gtk*>(user_data);
+ if(!pApp)
+ return UNIQUE_RESPONSE_FAIL;
+
+ switch(command)
+ {
+ case UNIQUE_ACTIVATE:
+ {
+ Glib::RefPtr<Gdk::Screen> screen = Glib::wrap(unique_message_data_get_screen(message), true);
+ pApp->set_screen(screen);
+ pApp->present();
+
+ return UNIQUE_RESPONSE_OK;
+ }
+
+ case UNIQUE_NEW:
+ {
+ pApp->on_menu_file_new();
+
+ return UNIQUE_RESPONSE_OK;
+ break;
+ }
+
+ case UNIQUE_OPEN:
+ {
+ char* uri = unique_message_data_get_text(message);
+ std::cout << "DEBUG: uri=" << uri << std::endl;
+
+ pApp->open_document(uri);
+ pApp->present();
+
+ g_free(uri);
+
+ return UNIQUE_RESPONSE_OK;
+ break;
+ }
+
+ default:
+ {
+ std::cerr << "Unexpected UniqueApp command: " << command << std::endl;
+ return UNIQUE_RESPONSE_FAIL;
+ }
+ }
+}
+
} //namespace
Modified: trunk/bakery/App/App_WithDoc_Gtk.h
==============================================================================
--- trunk/bakery/App/App_WithDoc_Gtk.h (original)
+++ trunk/bakery/App/App_WithDoc_Gtk.h Thu Mar 19 20:03:26 2009
@@ -24,6 +24,7 @@
#include <bakery/Document/Document.h>
#include <gtkmm/toolbutton.h>
#include <gtkmm/recentmanager.h>
+#include <unique/unique.h>
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" {
@@ -63,6 +64,12 @@
virtual void init(); //Unique final overrider.
+ /** Connect a signal handler for UniqueApp messages,
+ * which handles the default commands, for instance to open new instances
+ * an to open files.
+ */
+ virtual void set_unique_app(UniqueApp* unique_app);
+
protected:
virtual void init_menus_file(); //overridden to add open/save/save as.
virtual void init_menus_file_recentfiles(const Glib::ustring& path); // call this in init_menus_file()
@@ -81,6 +88,8 @@
void on_recent_files_activate(Gtk::RecentChooser& recent_chooser);
+ static UniqueResponse on_unique_app_message_received(UniqueApp* app, UniqueCommand command, UniqueMessageData* message, guint time_, gpointer user_data);
+
//Menu stuff:
Glib::RefPtr<Gtk::Action> m_action_save, m_action_saveas;
};
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Thu Mar 19 20:03:26 2009
@@ -122,7 +122,7 @@
dnl Checks for libraries:
dnl -----------------------------------------------
-REQUIRED_LIBRARIES="gtkmm-2.4 >= 2.10.0 gconfmm-2.6 >= 2.6.0 libglademm-2.4 >= 2.4.0 libxml++-2.6 >= 2.23.3 giomm-2.4 >= 2.16.0"
+REQUIRED_LIBRARIES="gtkmm-2.4 >= 2.10.0 gconfmm-2.6 >= 2.6.0 libglademm-2.4 >= 2.4.0 libxml++-2.6 >= 2.23.3 giomm-2.4 >= 2.16.0 unique-1.0"
AC_ARG_ENABLE([maemo],
AC_HELP_STRING([--enable-maemo],
Modified: trunk/examples/WithXmlDoc/main.cc
==============================================================================
--- trunk/examples/WithXmlDoc/main.cc (original)
+++ trunk/examples/WithXmlDoc/main.cc Thu Mar 19 20:03:26 2009
@@ -24,6 +24,7 @@
#endif
#include "appexample.h"
+#include <unique/unique.h>
int
main(int argc, char* argv[])
@@ -31,12 +32,35 @@
Gtk::Main mainWithoutDoc(argc, argv);
Bakery::init();
+
+ //If an instance is already running then ask that instance to do something instead,
+ //and close this instance.
+ UniqueApp* unique_app = unique_app_new("org.gnome.bakery.examples.WithXmlDoc", NULL /* startup_id */);
+
+ if( unique_app_is_running(unique_app) )
+ {
+ //There is an existing instance:
+
+ //Tell the existing instance to do a File/New:
+ const UniqueResponse response = unique_app_send_message(unique_app, UNIQUE_NEW, NULL);
+ g_object_unref(unique_app);
+ if(response != UNIQUE_RESPONSE_OK)
+ std::cerr << "unique_app_send_message() failed." << std::endl;
+
+ return -1;
+ }
+ //This is the first instance:
+
AppExample* pApp = new AppExample();
+ pApp->set_unique_app(unique_app);
+
AppExample::set_command_line_args(argc, argv);
pApp->init(); //Sets it up and shows it.
mainWithoutDoc.run();
+ g_object_unref(unique_app);
+
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]