[gnote] * Applet support.



commit 37f53af48cd4259659d477c93614afba5955b00b
Author: Hubert Figuiere <hub figuiere net>
Date:   Tue Apr 28 01:14:27 2009 -0400

      * Applet support.
      * Reference bugzilla component in server file (Closes #579198)
---
 .gitignore                                         |    3 +
 NEWS                                               |    5 +
 configure.ac                                       |   13 +
 ...server.in.in => GNOME_GnoteApplet.server.in.in} |    8 +-
 ...GNOME_GNoteApplet.xml => GNOME_GnoteApplet.xml} |    8 +-
 data/Makefile.am                                   |   24 +-
 po/POTFILES.in                                     |    4 +-
 po/POTFILES.skip                                   |    2 +
 src/Makefile.am                                    |   11 +
 src/applet.cpp                                     |  468 ++++++++++++++++++++
 src/applet.hpp                                     |   37 ++
 src/gnote-applet.in                                |    3 +
 src/gnote.cpp                                      |   52 ++-
 src/gnote.hpp                                      |   13 +-
 src/prefskeybinder.hpp                             |    3 +
 src/tray.cpp                                       |    3 -
 src/tray.hpp                                       |    4 +
 17 files changed, 622 insertions(+), 39 deletions(-)

diff --git a/.gitignore b/.gitignore
index 8b06d74..5547ac7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,7 +29,10 @@ gnome-doc-utils.make
 help/gnote-C.omf
 data/gnote.desktop
 data/gnote.schemas
+data/GNOME_GnoteApplet.server
+data/GNOME_GnoteApplet.server.in
 src/gnote
+src/gnote-applet
 src/trietest
 src/stringtest
 src/notetest
diff --git a/NEWS b/NEWS
index d36bb06..12d283d 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+  * Applet support.
+
+Fixes
+  * Reference bugzilla component in server file (Closes #579198)
+
 0.3.0 -
 
 New features:
diff --git a/configure.ac b/configure.ac
index cd2844e..548c8a0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,6 +30,7 @@ dnl LIBGLADEMM_VERSION=2.6.0
 dnl LIBGCONFMM_VERSION=2.6.0
 LIBGCONF_VERSION=2.0.0
 LIBGNOMEUI_VERSION=2.0.0
+LIBPANELAPPLETMM_VERSION=2.22.0
 GTKSPELL_VERSION=2.0.9
 BOOST_VERSION=1.34
 
@@ -85,6 +86,17 @@ dnl check for the ext2 uuid library. TODO replace it with something more portabl
 AC_CHECK_HEADER(uuid/uuid.h,,[AC_MSG_ERROR("uuid header is missing")])
 AC_CHECK_LIB(uuid,uuid_unparse_lower, ,[AC_MSG_ERROR("libuuid library is missing")])
 
+PKG_CHECK_EXISTS(libpanelappletmm-2.6 >= $LIBPANELAPPLETMM_VERSION,
+    [
+     AC_DEFINE(HAVE_PANELAPPLETMM, 1, [Define to 1 if panelapplet is available])
+     have_panelapplet=1
+     PKG_CHECK_MODULES(LIBPANELAPPLETMM, [libpanelappletmm-2.6 >= $LIBPANELAPPLETMM_VERSION])
+    ],
+    [have_panelapplet=0]
+)
+
+AM_CONDITIONAL(HAVE_PANELAPPLETMM, test $have_panelapplet == "1")
+
 #
 # If libpanelapplet available, use it to find .server install location.
 #
@@ -196,6 +208,7 @@ src/addins/bugzilla/Makefile
 src/addins/fixedwidth/Makefile
 src/addins/inserttimestamp/Makefile
 src/addins/printnotes/Makefile
+src/gnote-applet
 po/Makefile.in
 po/Makefile
 help/Makefile
diff --git a/data/GNOME_GNoteApplet.server.in.in b/data/GNOME_GnoteApplet.server.in.in
similarity index 84%
rename from data/GNOME_GNoteApplet.server.in.in
rename to data/GNOME_GnoteApplet.server.in.in
index 941a92f..9612c1a 100644
--- a/data/GNOME_GNoteApplet.server.in.in
+++ b/data/GNOME_GnoteApplet.server.in.in
@@ -1,5 +1,5 @@
 <oaf_info>
-<oaf_server iid="OAFIID:TomboyApplet_Factory" 
+<oaf_server iid="OAFIID:GnoteApplet_Factory" 
 	    type="exe"
             location="@bindir@/@wrapper@">
 
@@ -11,9 +11,9 @@
 	<oaf_attribute name="description" type="string" _value="Gnote Applet Factory"/>
 </oaf_server>
 
-<oaf_server iid="OAFIID:TomboyApplet" 
+<oaf_server iid="OAFIID:GnoteApplet" 
 	    type="factory"
-            location="OAFIID:TomboyApplet_Factory">
+            location="OAFIID:GnoteApplet_Factory">
 
         <oaf_attribute name="repo_ids" type="stringv">
                 <item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/>
@@ -25,7 +25,7 @@
         <oaf_attribute name="panel:category" type="string" _value="Accessories"/>
         <oaf_attribute name="panel:icon" type="string" value="gnote.png"/>
 
-	<oaf_attribute name="bugzilla:bugzilla" type="string" value="!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FIXME?"/>
+	<oaf_attribute name="bugzilla:bugzilla" type="string" value="gnote"/>
         <oaf_attribute name="bugzilla:product" type="string" value="Gnote"/>
         <oaf_attribute name="bugzilla:component" type="string" value="General"/>
         <oaf_attribute name="bugzilla:other_binaries" type="string" value="gnote"/>
diff --git a/data/GNOME_GNoteApplet.xml b/data/GNOME_GnoteApplet.xml
similarity index 80%
rename from data/GNOME_GNoteApplet.xml
rename to data/GNOME_GnoteApplet.xml
index 072be72..73006ca 100644
--- a/data/GNOME_GNoteApplet.xml
+++ b/data/GNOME_GnoteApplet.xml
@@ -1,8 +1,12 @@
-<popup name="button3">
+<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>
+    </popup>
+  </popups>
+</Root>
diff --git a/data/Makefile.am b/data/Makefile.am
index ef3e19d..9e6a9c6 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -35,19 +35,19 @@ dbusservice_DATA     = $(dbusservice_in_files:.service.in=.service)
 
 $(dbusservice_DATA): $(dbusservice_in_files) Makefile
 	sed -e "s|\ bindir\@|$(bindir)|g"	\
-	    -e "s|\ wrapper\@|gnote|g"		\
+	    -e "s|\ wrapper\@|gnote-applet|g"		\
 	    < $< > $@
 endif
 
 
-#serverdir       = $(PANELAPPLET_SERVER_DIR)
-#server_in_files = GNOME_GNoteApplet.server.in
-#server_DATA     = $(server_in_files:.server.in=.server)
+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|\ bindir\@|$(bindir)|g"	\
-#	    -e "s|\ wrapper\@|gnote-panel|g"		\
-#	    < $< > $@
+$(server_in_files): $(server_in_files:.server.in=.server.in.in) Makefile
+	sed -e "s|\ bindir\@|$(bindir)|g"	\
+	    -e "s|\ wrapper\@|gnote-applet|g"		\
+	    < $< > $@
 
 @INTLTOOL_SERVER_RULE@
 
@@ -55,10 +55,10 @@ endif
 man_MANS = gnote.1
 
 gnotedatadir = @datadir@/gnote
-gnotedata_DATA = UIManagerLayout.xml
+gnotedata_DATA = UIManagerLayout.xml \
+	GNOME_GnoteApplet.xml
 
-noinst_DATA = 			\
-	GNOME_GNoteApplet.xml
+noinst_DATA = 			
 
 
 EXTRA_DIST = 					\
@@ -68,7 +68,7 @@ EXTRA_DIST = 					\
 	$(schemas_in_files)     		\
 	$(man_MANS)				\
 	$(noinst_DATA)				\
-	GNOME_GNoteApplet.server.in.in		\
+	GNOME_GnoteApplet.server.in.in		\
 	$(dbusservice_in_files)
 
 DISTCLEANFILES = 				\
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1728dc5..db7be6c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,5 +1,5 @@
-data/GNOME_GNoteApplet.server.in.in
-data/GNOME_GNoteApplet.xml
+data/GNOME_GnoteApplet.server.in.in
+data/GNOME_GnoteApplet.xml
 data/gnote.desktop.in
 data/gnote.schemas.in
 src/sharp/addinstreemodel.cpp
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
new file mode 100644
index 0000000..9f73dd2
--- /dev/null
+++ b/po/POTFILES.skip
@@ -0,0 +1,2 @@
+data/GNOME_GnoteApplet.server.in
+
diff --git a/src/Makefile.am b/src/Makefile.am
index fd63cdb..f5ea4ae 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,6 +2,7 @@
 
 SUBDIRS = addins
 
+EXTRA_DIST = gnote-applet
 
 INCLUDES = -I$(top_srcdir)
 AM_CPPFLAGS= LIBGTKMM_CFLAGS@ @LIBGLIBMM_CFLAGS@ \
@@ -40,6 +41,15 @@ notetest_LDADD =  $(GNOTE_LIBS)
 
 gnote_SOURCES = main.cpp
 
+
+if HAVE_PANELAPPLETMM
+APPLET_SOURCES=applet.hpp applet.cpp
+AM_CPPFLAGS+= LIBPANELAPPLETMM_CFLAGS@
+GNOTE_LIBS+= LIBPANELAPPLETMM_LIBS@
+
+bin_SCRIPTS=gnote-applet
+endif
+
 libgnote_a_SOURCES = \
 	base/singleton.hpp \
 	sharp/addinstreemodel.hpp sharp/addinstreemodel.cpp \
@@ -97,6 +107,7 @@ libgnote_a_SOURCES = \
 	notebooks/notebooknewnotemenuitem.hpp notebooks/notebooknewnotemenuitem.cpp \
 	notebooks/notebooknoteaddin.hpp notebooks/notebooknoteaddin.cpp \
 	notebooks/notebookstreeview.hpp notebooks/notebookstreeview.cpp \
+	$(APPLET_SOURCES)
 	$(NULL)
 
 gnote_LDADD = $(GNOTE_LIBS)
diff --git a/src/applet.cpp b/src/applet.cpp
new file mode 100644
index 0000000..8f14505
--- /dev/null
+++ b/src/applet.cpp
@@ -0,0 +1,468 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "config.h"
+
+#include <boost/format.hpp>
+
+#include <gdkmm/dragcontext.h>
+#include <gtkmm/eventbox.h>
+#include <gtkmm/selectiondata.h>
+
+#include <libpanelappletmm/applet.h>
+#include <libpanelappletmm/enums.h>
+#include <libpanelappletmm/factory.h>
+
+#include "sharp/string.hpp"
+#include "sharp/uri.hpp"
+#include "gnote.hpp"
+#include "notemanager.hpp"
+#include "notewindow.hpp"
+#include "prefskeybinder.hpp"
+#include "tray.hpp"
+#include "undo.hpp"
+#include "utils.hpp"
+
+#include "applet.hpp"
+
+namespace gnote {
+namespace panel {
+
+
+#define IID "OAFIID:GnoteApplet"
+#define FACTORY_IID "OAFIID:GnoteApplet_Factory"
+
+enum PanelOrientation
+{
+  HORIZONTAL,
+  VERTICAL
+};
+
+class GnotePanelAppletEventBox
+  : public Gtk::EventBox
+  , public gnote::IGnoteTray
+{
+public:
+  GnotePanelAppletEventBox(NoteManager & manager);
+  virtual ~GnotePanelAppletEventBox();
+
+  const Tray::Ptr & get_tray() const
+    {
+      return m_tray;
+    }
+  Gtk::Image & get_image()
+    {
+      return m_image;
+    }
+
+  virtual void show_menu(bool select_first_item);
+  virtual bool menu_opens_upward();
+
+protected:
+  virtual void on_size_allocate(Gtk::Allocation& allocation);
+
+private:
+  bool button_press(GdkEventButton *);
+  void prepend_timestamped_text(const Note::Ptr & note,
+                                const sharp::DateTime & timestamp,
+                                const std::string & text);
+  bool paste_primary_clipboard();
+  void setup_drag_and_drop();
+  void on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>&,int,int,
+                             const Gtk::SelectionData&,guint,guint);
+  void init_pixbuf();
+  PanelOrientation get_panel_orientation();
+
+  NoteManager & m_manager;
+  Tray::Ptr     m_tray;
+  int           m_panel_size;
+  Gtk::Image    m_image;
+};
+
+
+GnotePanelAppletEventBox::GnotePanelAppletEventBox(NoteManager & manager)
+  : m_manager(manager)
+  , m_tray(new Tray(manager, *this))
+  , m_panel_size(16)
+  , m_image(utils::get_icon("gnote", m_panel_size))
+{
+  property_can_focus() = true;
+  signal_button_press_event().connect(sigc::mem_fun(
+                                        *this, &GnotePanelAppletEventBox::button_press));
+  add(m_image);
+  show_all();
+  set_tooltip_text(tray_util_get_tooltip_text());
+}
+
+
+GnotePanelAppletEventBox::~GnotePanelAppletEventBox()
+{
+}
+
+
+bool GnotePanelAppletEventBox::button_press(GdkEventButton *ev)
+{
+  Gtk::Widget * parent = get_parent();
+  switch (ev->button) 
+  {
+  case 1:
+    m_tray->update_tray_menu(parent);
+
+    utils::popup_menu(*m_tray->tray_menu(), ev);
+
+    return true;
+    break;
+  case 2:
+    if (Preferences::obj().get<bool>(Preferences::ENABLE_ICON_PASTE)) {
+      // Give some visual feedback
+      drag_highlight();
+      bool retval = paste_primary_clipboard ();
+      drag_unhighlight();
+      return retval;
+    }
+    break;
+  }
+  return false;
+}
+
+
+void GnotePanelAppletEventBox::prepend_timestamped_text(const Note::Ptr & note,
+                                                        const sharp::DateTime & timestamp,
+                                                        const std::string & text)
+{
+  NoteBuffer::Ptr buffer = note->get_buffer();
+  std::string insert_text =
+    str(boost::format("\n%1%\n%2%\n") % timestamp.to_string("%c") % text);
+
+  buffer->undoer().freeze_undo();
+
+  // Insert the date and list of links...
+  Gtk::TextIter cursor = buffer->begin();
+  cursor.forward_lines (1); // skip title
+
+  cursor = buffer->insert (cursor, insert_text);
+
+  // Make the date string a small font...
+  cursor = buffer->begin();
+  cursor.forward_lines (2); // skip title & leading newline
+
+  Gtk::TextIter end = cursor;
+  end.forward_to_line_end (); // end of date
+
+  buffer->apply_tag_by_name ("datetime", cursor, end);
+
+  // Select the text we've inserted (avoid trailing newline)...
+  end = cursor;
+  end.forward_chars (insert_text.length() - 1);
+
+  buffer->move_mark(buffer->get_selection_bound(), cursor);
+  buffer->move_mark(buffer->get_insert(), end);
+
+  buffer->undoer().thaw_undo();
+}
+
+
+
+bool GnotePanelAppletEventBox::paste_primary_clipboard()
+{
+  Glib::RefPtr<Gtk::Clipboard> clip = get_clipboard ("PRIMARY");
+  Glib::ustring text = clip->wait_for_text ();
+
+  if (text.empty() || sharp::string_trim(text).empty()) {
+    return false;
+  }
+
+  Note::Ptr link_note = m_manager.find_by_uri(m_manager.start_note_uri());
+  if (!link_note) {
+    return false;
+  }
+
+  link_note->get_window()->present();
+  prepend_timestamped_text (link_note, sharp::DateTime::now(), text);
+
+  return true;
+}
+
+void GnotePanelAppletEventBox::show_menu(bool select_first_item)
+{
+  m_tray->update_tray_menu(this);
+  if(select_first_item) {
+    m_tray->tray_menu()->select_first(false);
+  }
+  utils::popup_menu(*m_tray->tray_menu(), NULL);
+}
+
+
+// Support dropping text/uri-lists and _NETSCAPE_URLs currently.
+void GnotePanelAppletEventBox::setup_drag_and_drop()
+{
+  std::list<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));
+
+  drag_dest_set(targets, Gtk::DEST_DEFAULT_ALL, Gdk::ACTION_COPY);
+
+  signal_drag_data_received().connect(
+    sigc::mem_fun(*this, &GnotePanelAppletEventBox::on_drag_data_received));
+}
+
+void GnotePanelAppletEventBox::on_drag_data_received(const Glib::RefPtr<Gdk::DragContext>&,
+                                                     int,int,
+                                                     const Gtk::SelectionData & data,
+                                                     guint,guint)
+{
+  utils::UriList uri_list(data);
+  if (uri_list.empty()) {
+    return;
+  }
+
+  std::string insert_text;
+  bool more_than_one = false;
+
+  for(utils::UriList::const_iterator iter = uri_list.begin();
+      iter != uri_list.end(); ++iter) {
+
+    const sharp::Uri & uri(*iter);
+
+    if (more_than_one) {
+      insert_text += "\n";
+    }
+
+    if (uri.is_file()) {
+      insert_text += uri.local_path();
+    }
+    else {
+      insert_text += uri.to_string();
+    }
+
+    more_than_one = true;
+  }
+
+  Note::Ptr link_note = m_manager.find_by_uri (m_manager.start_note_uri());
+  if (link_note) {
+    link_note->get_window()->present();
+    prepend_timestamped_text(link_note, sharp::DateTime::now(),
+                              insert_text);
+  }
+}
+
+
+void GnotePanelAppletEventBox::init_pixbuf()
+{
+  // For some reason, the first time we ask for the allocation,
+  // it's a 1x1 pixel.  Prevent against this by returning a
+  // reasonable default.  Setting the icon causes OnSizeAllocated
+  // to be called again anyhow.
+  int icon_size = m_panel_size;
+  if (icon_size < 16) {
+    icon_size = 16;
+  }
+
+  // Control specifically which icon is used at the smaller sizes
+  // so that no scaling occurs.  In the case of the panel applet,
+  // add a couple extra pixels of padding so it matches the behavior
+  // of the notification area tray icon.  See bug #403500 for more
+  // info.
+  if (Gnote::obj().is_panel_applet())
+    icon_size = icon_size - 2; // padding
+  if (icon_size <= 21)
+    icon_size = 16;
+  else if (icon_size <= 31)
+    icon_size = 22;
+  else if (icon_size <= 47)
+    icon_size = 32;
+
+  Glib::RefPtr<Gdk::Pixbuf> new_icon = utils::get_icon("tomboy", icon_size);
+  m_image.property_pixbuf() = new_icon;
+}
+
+
+PanelOrientation GnotePanelAppletEventBox::get_panel_orientation()
+{
+  if (!get_parent_window()) {
+    return HORIZONTAL;
+  }
+
+  Glib::RefPtr<Gdk::Window> top_level_window = get_parent_window()->get_toplevel();
+
+  Gdk::Rectangle rect;
+  top_level_window->get_frame_extents(rect);
+  if (rect.get_width() < rect.get_height()) {
+    return HORIZONTAL;
+  }
+
+  return VERTICAL;
+}
+
+
+
+void GnotePanelAppletEventBox::on_size_allocate(Gtk::Allocation& allocation)
+{
+  Gtk::EventBox::on_size_allocate(allocation);
+
+  // Determine the orientation
+  if (get_panel_orientation () == HORIZONTAL) {
+    if (m_panel_size == get_allocation().get_height()) {
+      return;
+    }
+
+    m_panel_size = get_allocation().get_height();
+  } 
+  else {
+    if (m_panel_size == get_allocation().get_width()) {
+      return;
+    }
+    
+    m_panel_size = get_allocation().get_width();
+  }
+
+  init_pixbuf ();
+}
+
+
+bool GnotePanelAppletEventBox::menu_opens_upward()
+{
+  bool open_upwards = false;
+  int val = 0;
+  Glib::RefPtr<Gdk::Screen> screen;
+
+  int x, y;
+  get_window()->get_origin(x, y);
+  val = y;
+  screen = get_screen();
+
+  Gtk::Requisition req = m_tray->tray_menu()->size_request();
+  if ((val + req.height) >= screen->get_height()) {
+    open_upwards = true;
+  }
+
+  return open_upwards;
+}
+
+
+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*)
+{
+  ActionManager::obj()["ShowPreferencesAction"]->activate();
+}
+
+void GnoteApplet::show_help_verb(BonoboUIComponent*, void* data, const char*)
+{
+  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);
+}
+
+void GnoteApplet::show_about_verb(BonoboUIComponent*, void*, const char*)
+{
+  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;
+  }
+}
+
+
+void GnoteApplet::on_change_size(int size)
+{
+  m_applet_event_box.set_size_request (size, size);
+}
+
+
+int register_applet()
+{
+  int returncode = Gnome::Panel::factory_main<GnoteApplet>(FACTORY_IID);
+  return returncode;
+}
+
+}
+}
+
diff --git a/src/applet.hpp b/src/applet.hpp
new file mode 100644
index 0000000..1e0abf1
--- /dev/null
+++ b/src/applet.hpp
@@ -0,0 +1,37 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+#ifndef __GNOTE_APPLET_HPP_
+#define __GNOTE_APPLET_HPP_
+
+
+namespace gnote {
+namespace panel {
+
+
+int register_applet();
+
+
+}
+}
+
+
+#endif
diff --git a/src/gnote-applet.in b/src/gnote-applet.in
new file mode 100755
index 0000000..6514524
--- /dev/null
+++ b/src/gnote-applet.in
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec @prefix@/@bindir@/gnote --panel-applet $* 
diff --git a/src/gnote.cpp b/src/gnote.cpp
index 275de5e..75554d6 100644
--- a/src/gnote.cpp
+++ b/src/gnote.cpp
@@ -19,14 +19,19 @@
 
 
 
+#include "config.h"
+
 #include <stdlib.h>
 
 #include <glibmm/thread.h>
 #include <glibmm/i18n.h>
+#include <glibmm/optionentry.h>
 #include <gtkmm/main.h>
 #include <gtkmm/aboutdialog.h>
 
-#include "config.h"
+#if HAVE_PANELAPPLETMM
+#include <libpanelappletmm/init.h>
+#endif
 
 #include "gnote.hpp"
 #include "actionmanager.hpp"
@@ -41,6 +46,10 @@
 #include "xkeybinder.hpp"
 #include "sharp/string.hpp"
 
+#if HAVE_PANELAPPLETMM
+#include "applet.hpp"
+#endif
+
 namespace gnote {
 
   bool Gnote::s_tray_icon_showing = false;
@@ -63,7 +72,18 @@ namespace gnote {
 
   int Gnote::main(int argc, char **argv)
   {
-    GnoteCommandLine cmd_line(argc, argv);
+    GnoteCommandLine cmd_line;
+
+
+    Glib::OptionContext context;
+    context.set_ignore_unknown_options(true);
+    context.set_main_group(cmd_line);
+    try {
+      context.parse(argc, argv);
+    }
+    catch(...)
+    {
+    }
 
     if(cmd_line.needs_execute()) {
       cmd_line.execute();
@@ -93,6 +113,7 @@ namespace gnote {
     }
 
     if(cmd_line.use_panel_applet()) {
+      DBG_OUT("starting applet");
       s_tray_icon_showing = true;
       m_is_panel_applet = true;
 
@@ -100,10 +121,16 @@ namespace gnote {
       am["QuitGNoteAction"]->set_visible(false);
       
       // register panel applet factory
+#if HAVE_PANELAPPLETMM
+      Gnome::Panel::init("gnote", VERSION, argc, argv);
+
+      panel::register_applet();
+#endif
       return 0;
 
     }
     else {
+      DBG_OUT("starting tray icon");
       //register session manager restart
       start_tray_icon();
     }
@@ -312,13 +339,17 @@ namespace gnote {
   }
 
 
-  GnoteCommandLine::GnoteCommandLine(int & argc, char **&argv)
-    :  m_new_note(false)
-    ,  m_open_search(false)
+  GnoteCommandLine::GnoteCommandLine()
+    : Glib::OptionGroup("Gnote", _("A note taking application"))
+    , m_new_note(false)
+    , m_open_search(false)
     , m_open_start_here(false)
     , m_use_panel(false)
   {
-    parse(argc, argv);
+    Glib::OptionEntry entry;
+    entry.set_long_name("panel-applet");
+    entry.set_description(_("Run Gnote as a GNOME panel applet"));
+    add_entry(entry, m_use_panel);
   }
 
   int GnoteCommandLine::execute()
@@ -337,12 +368,5 @@ namespace gnote {
       !m_open_external_note_path.empty();
   }
 
-  void GnoteCommandLine::parse(int & argc, char **& /*argv*/)
-  {
-//    bool quit = false;
-    for(int i = 0; i < argc; i++) {
-//      const char * current = argv[i];
-      // TODO
-    }
-  }
+
 }
diff --git a/src/gnote.hpp b/src/gnote.hpp
index 57ccd62..51ad0a1 100644
--- a/src/gnote.hpp
+++ b/src/gnote.hpp
@@ -25,6 +25,7 @@
 
 #include <string>
 
+#include <glibmm/optioncontext.h>
 #include <gtkmm/icontheme.h>
 #include <gtkmm/statusicon.h>
 
@@ -73,6 +74,14 @@ public:
     {
       return s_tray_icon_showing;
     }
+  bool is_panel_applet()
+    {
+      return m_is_panel_applet;
+    }
+  void set_tray(const Tray::Ptr & tray)
+    {
+      m_tray = tray;
+    }
 private:
   NoteManager *m_manager;
   IKeybinder  *m_keybinder;
@@ -86,9 +95,10 @@ private:
 
 
 class GnoteCommandLine
+  : public Glib::OptionGroup
 {
 public:
-  GnoteCommandLine(int & argc, char **&argv);
+  GnoteCommandLine();
   int execute();
 
   const std::string & note_path() const
@@ -102,7 +112,6 @@ public:
     }
 
 private:
-  void parse(int & argc, char **&argv);
 
   bool        m_new_note;
   bool        m_open_search;
diff --git a/src/prefskeybinder.hpp b/src/prefskeybinder.hpp
index c84888a..9e365ee 100644
--- a/src/prefskeybinder.hpp
+++ b/src/prefskeybinder.hpp
@@ -26,10 +26,13 @@
 #include <sigc++/signal.h>
 #include <sigc++/slot.h>
 
+#include "preferences.hpp"
+
 namespace gnote {
 
 class TrayIcon;
 class NoteManager;
+class IGnoteTray;
 class IKeybinder;
 
 
diff --git a/src/tray.cpp b/src/tray.cpp
index ac550ae..b972df7 100644
--- a/src/tray.cpp
+++ b/src/tray.cpp
@@ -45,8 +45,6 @@
 
 namespace gnote {
 
-  namespace {
-
   std::string tray_util_get_tooltip_text()
   {
     std::string tip_text = _("Gnote Notes");
@@ -62,7 +60,6 @@ namespace gnote {
     return tip_text;
   }
 
-  }
 
 
   bool                      NoteMenuItem::s_static_inited = false;
diff --git a/src/tray.hpp b/src/tray.hpp
index 6c958bc..7e2fa16 100644
--- a/src/tray.hpp
+++ b/src/tray.hpp
@@ -135,5 +135,9 @@ private:
   static Glib::RefPtr<Gtk::AccelGroup> s_accel_group;
 };
 
+
+
+std::string tray_util_get_tooltip_text();
+
 }
 #endif



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