[gnote] Port panel applet to libpanelapplet-4



commit 0a9aa541392193bc0268bd17b3b02c6b2847e9e1
Author: Aurimas Ä?ernius <aurisc4 gmail com>
Date:   Sun Jun 5 16:56:09 2011 +0300

    Port panel applet to libpanelapplet-4
    
    Allow Gnote to be used as panel applet in GNOME 3 fallback mode.
    Fixes bug 639779.

 configure.ac                                       |   24 +---
 data/GNOME_GnoteApplet.server.in.in                |   33 -----
 data/GNOME_GnoteApplet.xml                         |   15 +--
 data/Makefile.am                                   |   37 ++++--
 data/org.gnome.gnote.panel-applet.in.in            |   16 ++
 ...nome.panel.applet.GnoteAppletFactory.service.in |    3 +
 src/Makefile.am                                    |    6 +-
 src/applet.cpp                                     |  146 ++++++++------------
 src/gnote.cpp                                      |   14 +-
 9 files changed, 119 insertions(+), 175 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2f580b0..b6330b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,7 +27,7 @@ GTK_VERSION=3.0
 LIBGLIBMM_VERSION=2.18
 LIBGTKMM_VERSION=3.0
 LIBGCONF_VERSION=2.0.0
-LIBPANELAPPLETMM_VERSION=2.22.0
+LIBPANELAPPLET_VERSION=3.0
 GTKSPELL_VERSION=2.0.9
 BOOST_VERSION=1.34
 DBUSCPP_VERSION=0.5.0
@@ -77,33 +77,19 @@ AC_ARG_ENABLE([applet],
 	[],[enable_applet=yes])
 
 if test $enable_applet = "yes"; then
-	PKG_CHECK_EXISTS(libpanelappletmm-2.6 >= $LIBPANELAPPLETMM_VERSION,
+	PKG_CHECK_EXISTS(libpanelapplet-4.0 >= $LIBPANELAPPLET_VERSION,
 	  [
-		AC_DEFINE(HAVE_PANELAPPLETMM, 1, [Define to 1 if panelapplet is available])
+		AC_DEFINE(HAVE_PANELAPPLET, 1, [Define to 1 if panelapplet is available])
 		have_panelapplet="yes"
-		PKG_CHECK_MODULES(LIBPANELAPPLETMM, [libpanelappletmm-2.6 >= $LIBPANELAPPLETMM_VERSION])
+		PKG_CHECK_MODULES(LIBPANELAPPLET, [libpanelapplet-4.0 >= $LIBPANELAPPLET_VERSION])
 	  ], [
 		have_panelapplet="no"]
 	)
-
-	#
-	# If libpanelapplet available, use it to find .server install location.
-	#
-	if test "x$prefix" = "x$ac_default_prefix"; then
-		PANELAPPLET_LIBDIR=`$PKG_CONFIG --variable=libdir libpanelapplet-2.0`
-	fi
-	if test "x$PANELAPPLET_LIBDIR" != "x"; then
-		PANELAPPLET_SERVER_DIR="$PANELAPPLET_LIBDIR/bonobo/servers"
-	fi
-	# Set PANELAPPLET_SERVER_DIR default if it's not already set
-	if test "x$PANELAPPLET_SERVER_DIR" = "x" ; then
-		PANELAPPLET_SERVER_DIR="$libdir/bonobo/servers"
-	fi
 else
 	have_panelapplet="no"
 fi
 
-AM_CONDITIONAL(HAVE_PANELAPPLETMM, test $have_panelapplet = "yes")
+AM_CONDITIONAL(HAVE_PANELAPPLET, test $have_panelapplet = "yes")
 AC_SUBST(PANELAPPLET_SERVER_DIR)
 
 #GtkSpell disabled until GTK 3.0 is supported
diff --git a/data/GNOME_GnoteApplet.xml b/data/GNOME_GnoteApplet.xml
index 73006ca..7abaaa9 100644
--- a/data/GNOME_GnoteApplet.xml
+++ b/data/GNOME_GnoteApplet.xml
@@ -1,12 +1,3 @@
-<Root>
-  <popups>
-    <popup name="button3">
-      <menuitem name="Props" verb="Props" _label="_Preferences"
-    		pixtype="stock" pixname="gtk-preferences"/>
-      <menuitem name="Help" verb="Help" _label="_Help"
-    		pixtype="stock" pixname="gtk-help"/>
-      <menuitem name="About" verb="About" _label="_About"
-    		pixtype="stock" pixname="gtk-about"/>
-    </popup>
-  </popups>
-</Root>
+<menuitem name="Props" action="Props"/>
+<menuitem name="Help" action="Help"/>
+<menuitem name="About" action="About"/>
diff --git a/data/Makefile.am b/data/Makefile.am
index c84589f..d07925f 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -39,15 +39,26 @@ $(dbusservice_DATA): $(dbusservice_in_files) Makefile
 	    < $< > $@
 endif
 
-if HAVE_PANELAPPLETMM
-serverdir       = $(PANELAPPLET_SERVER_DIR)
-server_in_files = GNOME_GnoteApplet.server.in
-server_DATA     = $(server_in_files:.server.in=.server)
-
-$(server_in_files): $(server_in_files:.server.in=.server.in.in) Makefile
-	sed -e "s|\ libexecdir\@|$(libexecdir)|g"	\
-	    -e "s|\ wrapper\@|gnote-applet|g"		\
-	    < $< > $@
+if HAVE_PANELAPPLET
+appletdir       = $(datadir)/gnome-panel/4.0/applets
+applet_in_files = org.gnome.gnote.panel-applet.in
+applet_in_in_files = $(applet_in_files).in
+applet_DATA     = $(applet_in_files:.panel-applet.in=.panel-applet)
+
+$(applet_in_files): $(applet_in_files).in Makefile
+	$(AM_V_GEN)sed -e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
+	               -e "s|\ VERSION\@|$(PACKAGE_VERSION)|" \
+	               $< > $@
+ 
+ INTLTOOL_SERVER_RULE@
+%.panel-applet: %.panel-applet.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+
+servicedir       = $(datadir)/dbus-1/services
+service_in_files = org.gnome.panel.applet.GnoteAppletFactory.service.in
+service_DATA     = $(service_in_files:.service.in=.service)
+
+org.gnome.panel.applet.GnoteAppletFactory.service: $(service_in_files)
+	$(AM_V_GEN)sed -e "s|\ LIBEXECDIR\@|$(libexecdir)|" $< > $@
 endif
 
 @INTLTOOL_SERVER_RULE@
@@ -70,13 +81,15 @@ EXTRA_DIST = 					\
 	$(schemas_in_files)     		\
 	$(man_MANS)				\
 	$(noinst_DATA)				\
-	GNOME_GnoteApplet.server.in.in		\
+	$(service_in_files)                     \
+	$(applet_in_in_files)                   \
 	$(dbusservice_in_files)
 
 DISTCLEANFILES = 				\
 	$(desktop_files)       			\
 	$(pkgconfig_DATA)			\
 	$(schemas_DATA)				\
-	$(server_in_files) 			\
-	$(server_DATA)				\
+	$(applet_DATA)                          \
+	$(applet_DATA).in                       \
+	$(service_DATA)                         \
 	$(dbusservice_DATA)
diff --git a/data/org.gnome.gnote.panel-applet.in.in b/data/org.gnome.gnote.panel-applet.in.in
new file mode 100644
index 0000000..6bced79
--- /dev/null
+++ b/data/org.gnome.gnote.panel-applet.in.in
@@ -0,0 +1,16 @@
+[Applet Factory]
+Id=GnoteAppletFactory
+InProcess=false
+Location= LIBEXECDIR@
+_Name=Gnote Applet Factory
+_Description=Gnote Applet Factory
+
+[GnoteApplet]
+_Name=Gnote
+_Description=Simple and easy to use note-taking
+Icon=gnote.png
+X-GNOME-Bugzilla-Bugzilla=GNOME
+X-GNOME-Bugzilla-Product=Gnote
+X-GNOME-Bugzilla-Component=gnote
+X-GNOME-Bugzilla-Version= VERSION@
+X-GNOME-Bugzilla-OtherBinaries=gnote-applet
diff --git a/data/org.gnome.panel.applet.GnoteAppletFactory.service.in b/data/org.gnome.panel.applet.GnoteAppletFactory.service.in
new file mode 100644
index 0000000..7256258
--- /dev/null
+++ b/data/org.gnome.panel.applet.GnoteAppletFactory.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.panel.applet.GnoteAppletFactory
+Exec= LIBEXECDIR@/gnote-applet
diff --git a/src/Makefile.am b/src/Makefile.am
index d94b502..de30a32 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -69,10 +69,10 @@ notetest_LDADD =  $(GNOTE_LIBS) -lX11
 gnote_SOURCES = main.cpp
 
 
-if HAVE_PANELAPPLETMM
+if HAVE_PANELAPPLET
 APPLET_SOURCES=applet.hpp applet.cpp
-AM_CPPFLAGS+= LIBPANELAPPLETMM_CFLAGS@
-GNOTE_LIBS+= LIBPANELAPPLETMM_LIBS@
+AM_CPPFLAGS+= LIBPANELAPPLET_CFLAGS@
+GNOTE_LIBS+= LIBPANELAPPLET_LIBS@
 
 libexec_SCRIPTS=gnote-applet
 gnote-applet: gnote-applet.in Makefile
diff --git a/src/applet.cpp b/src/applet.cpp
index 1015fef..6132bf5 100644
--- a/src/applet.cpp
+++ b/src/applet.cpp
@@ -1,6 +1,7 @@
 /*
  * gnote
  *
+ * Copyright (C) 2011 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -26,9 +27,8 @@
 #include <gtkmm/eventbox.h>
 #include <gtkmm/selectiondata.h>
 
-#include <libpanelappletmm/applet.h>
-#include <libpanelappletmm/enums.h>
-#include <libpanelappletmm/factory.h>
+#include <panel-applet.h>
+#include <glibmm/i18n.h>
 
 #include "sharp/string.hpp"
 #include "sharp/uri.hpp"
@@ -46,8 +46,8 @@ namespace gnote {
 namespace panel {
 
 
-#define IID "OAFIID:GnoteApplet"
-#define FACTORY_IID "OAFIID:GnoteApplet_Factory"
+#define IID "GnoteApplet"
+#define FACTORY_IID "GnoteAppletFactory"
 
 enum PanelOrientation
 {
@@ -120,7 +120,7 @@ GnotePanelAppletEventBox::~GnotePanelAppletEventBox()
 bool GnotePanelAppletEventBox::button_press(GdkEventButton *ev)
 {
   Gtk::Widget * parent = get_parent();
-  switch (ev->button) 
+  switch (ev->button)
   {
   case 1:
     m_tray->update_tray_menu(parent);
@@ -213,7 +213,7 @@ void GnotePanelAppletEventBox::show_menu(bool select_first_item)
 // Support dropping text/uri-lists and _NETSCAPE_URLs currently.
 void GnotePanelAppletEventBox::setup_drag_and_drop()
 {
-  std::list<Gtk::TargetEntry> targets;
+  std::vector<Gtk::TargetEntry> targets;
 
   targets.push_back(Gtk::TargetEntry ("text/uri-list", (Gtk::TargetFlags)0, 0));
   targets.push_back(Gtk::TargetEntry ("_NETSCAPE_URL", (Gtk::TargetFlags)0, 0));
@@ -325,12 +325,12 @@ void GnotePanelAppletEventBox::on_size_allocate(Gtk::Allocation& allocation)
     }
 
     m_panel_size = get_allocation().get_height();
-  } 
+  }
   else {
     if (m_panel_size == get_allocation().get_width()) {
       return;
     }
-    
+
     m_panel_size = get_allocation().get_width();
   }
 
@@ -349,7 +349,8 @@ bool GnotePanelAppletEventBox::menu_opens_upward()
   val = y;
   screen = get_screen();
 
-  Gtk::Requisition req = m_tray->tray_menu()->size_request();
+  Gtk::Requisition req, unused;
+  m_tray->tray_menu()->get_preferred_size(unused, req);
   if ((val + req.height) >= screen->get_height()) {
     open_upwards = true;
   }
@@ -358,108 +359,75 @@ bool GnotePanelAppletEventBox::menu_opens_upward()
 }
 
 
-class GnoteApplet
-  : public Gnome::Panel::Applet
-{
-public:
-  explicit GnoteApplet(PanelApplet *);
-  virtual ~GnoteApplet();
-
-protected:
-  virtual void on_change_background(Gnome::Panel::AppletBackgroundType type, const Gdk::Color & color, const Glib::RefPtr<const Gdk::Pixmap>& pixmap);
-  virtual void on_change_size(int size);
-private:
-  static void show_preferences_verb(BonoboUIComponent*, void*, const char*);
-  static void show_help_verb(BonoboUIComponent*, void*, const char*);
-  static void show_about_verb(BonoboUIComponent*, void*, const char*);
-
-
-  NoteManager & m_manager;
-  GnotePanelAppletEventBox m_applet_event_box;
-  PrefsKeybinder *m_keybinder;
-};
-
-
-GnoteApplet::GnoteApplet(PanelApplet *castitem)
-  : Gnome::Panel::Applet(castitem)
-  , m_manager(Gnote::obj().default_note_manager())
-  , m_applet_event_box(m_manager)
-  , m_keybinder(new GnotePrefsKeybinder(m_manager, m_applet_event_box))
-{
-  static const BonoboUIVerb menu_verbs[] = {
-    BONOBO_UI_VERB("Props", &GnoteApplet::show_preferences_verb),
-    BONOBO_UI_VERB("Help", &GnoteApplet::show_help_verb),
-    BONOBO_UI_VERB("About", &GnoteApplet::show_about_verb),
-    BONOBO_UI_VERB_END
-  };
-
-  setup_menu(DATADIR"/gnote", "GNOME_GnoteApplet.xml", "", menu_verbs, this);
-
-  add (m_applet_event_box);
-  Gnote::obj().set_tray(m_applet_event_box.get_tray());
-  on_change_size (get_size());
-
-  set_flags(Gnome::Panel::APPLET_EXPAND_MINOR);
-
-  show_all ();
-}
-
-
-GnoteApplet::~GnoteApplet()
-{
-  delete m_keybinder;
-}
-
-void GnoteApplet::show_preferences_verb(BonoboUIComponent*, void*, const char*)
+static void show_preferences_action(GtkAction*, gpointer)
 {
   ActionManager::obj()["ShowPreferencesAction"]->activate();
 }
 
-void GnoteApplet::show_help_verb(BonoboUIComponent*, void* data, const char*)
+
+static void show_help_action(GtkAction*, gpointer data)
 {
-  GnoteApplet* applet = static_cast<GnoteApplet*>(data);
   // Don't use the ActionManager in this case because
   // the handler won't know about the Screen.
-  utils::show_help("gnote", "", applet->get_screen()->gobj(), NULL);
+  utils::show_help("gnote", "", gtk_widget_get_screen(GTK_WIDGET(data)), NULL);
 }
 
-void GnoteApplet::show_about_verb(BonoboUIComponent*, void*, const char*)
+static void show_about_action(GtkAction*, gpointer)
 {
   ActionManager::obj()["ShowAboutAction"]->activate();
 }
 
-  void GnoteApplet::on_change_background(Gnome::Panel::AppletBackgroundType type, 
-                                       const Gdk::Color & color, 
-                                       const Glib::RefPtr<const Gdk::Pixmap>& pixmap)
-{
-  Glib::RefPtr<Gtk::RcStyle> rcstyle(Gtk::RcStyle::create());
-  m_applet_event_box.unset_style();
-  m_applet_event_box.modify_style (rcstyle);
 
-  switch (type) {
-  case Gnome::Panel::COLOR_BACKGROUND:
-    m_applet_event_box.modify_bg(Gtk::STATE_NORMAL, color);
-    break;
-  case Gnome::Panel::NO_BACKGROUND:
-    break;
-  case Gnome::Panel::PIXMAP_BACKGROUND:
-    Glib::RefPtr<Gtk::Style> copy = m_applet_event_box.get_style()->copy();
-    copy->set_bg_pixmap(Gtk::STATE_NORMAL, pixmap);
-    m_applet_event_box.set_style(copy);
-    break;
-  }
+static const GtkActionEntry applet_menu_actions[] = {
+  { "Props", GTK_STOCK_PREFERENCES, N_("_Preferences"), NULL, NULL, G_CALLBACK(show_preferences_action) },
+  { "Help", GTK_STOCK_HELP, N_("_Help"), NULL, NULL, G_CALLBACK(show_help_action) },
+  { "About", GTK_STOCK_ABOUT, N_("_About"), NULL, NULL, G_CALLBACK(show_about_action) }
+};
+
+
+
+static void on_applet_change_size(PanelApplet*, gint size, gpointer data)
+{
+  static_cast<GnotePanelAppletEventBox*>(data)->set_size_request(size, size);
 }
 
 
-void GnoteApplet::on_change_size(int size)
+gboolean gnote_applet_fill(PanelApplet *applet, const gchar *iid, gpointer data)
 {
-  m_applet_event_box.set_size_request (size, size);
+  if(strcmp(iid, IID) != 0)
+    return FALSE;
+
+  GnotePanelAppletEventBox *applet_event_box = static_cast<GnotePanelAppletEventBox*>(data);
+  gtk_container_add(GTK_CONTAINER(applet), GTK_WIDGET(applet_event_box->gobj()));
+  Gnote::obj().set_tray(applet_event_box->get_tray());
+  g_signal_connect(G_OBJECT(applet), "change-size",
+                   G_CALLBACK(on_applet_change_size), applet_event_box);
+  Gdk::RGBA color;
+  color.set_alpha(1.0);
+  applet_event_box->override_background_color(color);
+
+  GtkActionGroup *action_group = gtk_action_group_new("Gnote Applet Actions");
+  gtk_action_group_set_translation_domain(action_group, GETTEXT_PACKAGE);
+  gtk_action_group_add_actions(action_group, applet_menu_actions,
+                               G_N_ELEMENTS(applet_menu_actions), applet);
+  std::string ui_path = Glib::build_filename(DATADIR"/gnote", "GNOME_GnoteApplet.xml");
+  panel_applet_setup_menu_from_file(applet, ui_path.c_str(), action_group);
+  g_object_unref(action_group);
+
+  gtk_widget_show_all(GTK_WIDGET(applet));
+  // Set initial icon size according current panel size
+  g_signal_emit_by_name(applet, "change-size", panel_applet_get_size(applet));
+  return TRUE;
 }
 
 
 int register_applet()
 {
-  int returncode = Gnome::Panel::factory_main<GnoteApplet>(FACTORY_IID);
+  NoteManager &manager = Gnote::obj().default_note_manager();
+  GnotePanelAppletEventBox applet_event_box(manager);
+  GnotePrefsKeybinder key_binder(manager, applet_event_box);
+  int returncode = panel_applet_factory_main(FACTORY_IID, PANEL_TYPE_APPLET,
+                                             gnote_applet_fill, &applet_event_box);
   return returncode;
 }
 
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 00fd799..0bb128b 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -35,8 +35,8 @@
 #include <gtkmm/main.h>
 #include <gtkmm/aboutdialog.h>
 
-#if HAVE_PANELAPPLETMM
-#include <libpanelappletmm/init.h>
+#if HAVE_PANELAPPLET
+#include <panel-applet.h>
 #endif
 
 #include "gnote.hpp"
@@ -53,7 +53,7 @@
 #include "sharp/streamreader.hpp"
 #include "sharp/files.hpp"
 
-#if HAVE_PANELAPPLETMM
+#if HAVE_PANELAPPLET
 #include "applet.hpp"
 #endif
 
@@ -129,10 +129,10 @@ namespace gnote {
       am["QuitGNoteAction"]->set_visible(false);
       
       // register panel applet factory
-#if HAVE_PANELAPPLETMM
-      Gnome::Panel::init("gnote", VERSION, argc, argv);
-
-      panel::register_applet();
+#if HAVE_PANELAPPLET
+      return panel::register_applet();
+#else
+      return 0;
 #endif
     }
     else {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]