[ekiga] Reworked searching in Ekiga::Book instances



commit 765e249b03968d81ed4c82181fa65d619dd76183
Author: Julien Puydt <jpuydt gnome org>
Date:   Tue Sep 29 16:51:50 2009 +0200

    Reworked searching in Ekiga::Book instances
    
    Here is what happened :
    - I made search support optional (ie: removed it from the base class) ;
    - I added an abstract capability class to expose an object is able to do
    filtering (Ekiga::Filterable, with const-correctness fixes) ;
    - I made the book view code detect if the book is filterable, and if so
    (and only then!), show an entry+button, which get updated when the book
    is updated -- it fixes a bug with the previous code where a view could set
    a search string and other views weren't notified about it (only knew about
    the new list of contacts, but had no way to know why) ;
    - finally, I removed the dummy implementations (kab and call history), and
    completed the serious ones (ldap and evolution).

 lib/engine/addressbook/book.h                      |    9 ---
 .../components/call-history/history-book.cpp       |    5 --
 lib/engine/components/call-history/history-book.h  |    2 -
 lib/engine/framework/filterable.h                  |   59 ++++++++++++++++++++
 lib/engine/gui/gtk-frontend/book-view-gtk.cpp      |   45 +++++++++++----
 plugins/evolution/evolution-book.cpp               |    8 ++-
 plugins/evolution/evolution-book.h                 |    6 ++-
 plugins/kab/kab-book.h                             |    3 -
 plugins/ldap/ldap-book.cpp                         |    8 ++-
 plugins/ldap/ldap-book.h                           |    6 ++-
 10 files changed, 115 insertions(+), 36 deletions(-)
---
diff --git a/lib/engine/addressbook/book.h b/lib/engine/addressbook/book.h
index a5f3cba..0a53c83 100644
--- a/lib/engine/addressbook/book.h
+++ b/lib/engine/addressbook/book.h
@@ -67,15 +67,6 @@ namespace Ekiga {
     virtual void visit_contacts (boost::function1<bool, ContactPtr>) const = 0;
 
 
-    /** Set the search filter.
-     * This function is purely virtual and should be implemented by
-     * the descendant of the Ekiga::Book, ie BookImpl or one
-     * of its descendant.
-     * @param The search filter to respect when refreshing a Book.
-     */
-    virtual void set_search_filter (std::string _filter_string) = 0;
-
-
     /** Get the current status.
      * This function is purely virtual and should be implemented by
      * the descendant of the Ekiga::Book, ie BookImpl or one
diff --git a/lib/engine/components/call-history/history-book.cpp b/lib/engine/components/call-history/history-book.cpp
index d71acf6..40752e5 100644
--- a/lib/engine/components/call-history/history-book.cpp
+++ b/lib/engine/components/call-history/history-book.cpp
@@ -152,11 +152,6 @@ History::Book::get_status () const
 }
 
 void
-History::Book::set_search_filter (std::string /*filter*/)
-{
-}
-
-void
 History::Book::save () const
 {
   xmlChar *buffer = NULL;
diff --git a/lib/engine/components/call-history/history-book.h b/lib/engine/components/call-history/history-book.h
index a85e25c..5286c0f 100644
--- a/lib/engine/components/call-history/history-book.h
+++ b/lib/engine/components/call-history/history-book.h
@@ -74,8 +74,6 @@ namespace History
     const std::string get_icon () const
     { return "local-object"; }
 
-    void set_search_filter (std::string);
-
     /* more specific api */
 
     void add (const std::string & name,
diff --git a/lib/engine/framework/filterable.h b/lib/engine/framework/filterable.h
new file mode 100644
index 0000000..c54e1ab
--- /dev/null
+++ b/lib/engine/framework/filterable.h
@@ -0,0 +1,59 @@
+
+/*
+ * Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+
+ * 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 St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Ekiga is licensed under the GPL license and as a special exception, you
+ * have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination, without
+ * applying the requirements of the GNU GPL to the OPAL, OpenH323 and PWLIB
+ * programs, as long as you do follow the requirements of the GNU GPL for all
+ * the rest of the software thus combined.
+ */
+
+
+/*
+ *                         filterable.h  -  description
+ *                         ------------------------------------------
+ *   begin                : written in 2009 by Julien Puydt
+ *   copyright            : (c) 2009 by Julien Puydt
+ *   description          : declaration of the abstract filterable capability
+ *
+ */
+
+#ifndef __FILTERABLE_H__
+#define __FILTERABLE_H__
+
+#include <string>
+
+namespace Ekiga
+{
+  class Filterable
+  {
+  public:
+
+    /** Set the search filter.
+     * @param The new search filter for that object
+     */
+    virtual void set_search_filter (const std::string filter) = 0;
+
+    /** Get the search filter.
+     * @return The search filter used by that object
+     */
+    virtual const std::string get_search_filter () const = 0;
+  };
+};
+
+#endif
diff --git a/lib/engine/gui/gtk-frontend/book-view-gtk.cpp b/lib/engine/gui/gtk-frontend/book-view-gtk.cpp
index b053341..fc90ada 100644
--- a/lib/engine/gui/gtk-frontend/book-view-gtk.cpp
+++ b/lib/engine/gui/gtk-frontend/book-view-gtk.cpp
@@ -42,6 +42,8 @@
 
 #include "book-view-gtk.h"
 
+#include "filterable.h"
+
 #include "gmstockicons.h"
 #include "menu-builder-tools.h"
 #include "menu-builder-gtk.h"
@@ -242,6 +244,13 @@ on_updated (gpointer data)
 
   if (GDK_IS_WINDOW (GTK_WIDGET (view)->window))
     gdk_window_set_cursor (GTK_WIDGET (view)->window, NULL);
+
+  boost::shared_ptr<Ekiga::Filterable> filtered = boost::dynamic_pointer_cast<Ekiga::Filterable>(view->priv->book);
+  if (filtered) {
+
+    gtk_entry_set_text (GTK_ENTRY (view->priv->entry),
+			filtered->get_search_filter ().c_str ());
+  }
 }
 
 
@@ -276,7 +285,9 @@ on_entry_activated_cb (GtkWidget *entry,
   gdk_window_set_cursor (GTK_WIDGET (data)->window, cursor);
   gdk_cursor_unref (cursor);
 
-  BOOK_VIEW_GTK (data)->priv->book->set_search_filter (entry_text);
+  boost::shared_ptr<Ekiga::Filterable> filtered = boost::dynamic_pointer_cast<Ekiga::Filterable>(BOOK_VIEW_GTK (data)->priv->book);
+
+  filtered->set_search_filter (entry_text);
 }
 
 
@@ -610,18 +621,26 @@ book_view_gtk_new (Ekiga::BookPtr book)
   gtk_tree_view_append_column (GTK_TREE_VIEW (result->priv->tree_view), column);
 
   /* The Search Box */
-  hbox = gtk_hbox_new (FALSE, 0);
-  result->priv->entry = gtk_entry_new ();
-  button = gtk_button_new_from_stock (GTK_STOCK_FIND);
-  label = gtk_label_new_with_mnemonic (_("_Search Filter:"));
-  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);
-  gtk_box_pack_start (GTK_BOX (hbox), result->priv->entry, TRUE, TRUE, 2);
-  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 2);
-  gtk_box_pack_start (GTK_BOX (result->priv->vbox), hbox, FALSE, FALSE, 0);
-  g_signal_connect (result->priv->entry, "activate",
-                    G_CALLBACK (on_entry_activated_cb), result);
-  g_signal_connect (button, "clicked",
-                    G_CALLBACK (on_button_clicked_cb), result);
+  boost::shared_ptr<Ekiga::Filterable> filtered = boost::dynamic_pointer_cast<Ekiga::Filterable> (book);
+
+  if (filtered) {
+
+    hbox = gtk_hbox_new (FALSE, 0);
+    result->priv->entry = gtk_entry_new ();
+    button = gtk_button_new_from_stock (GTK_STOCK_FIND);
+    label = gtk_label_new_with_mnemonic (_("_Search Filter:"));
+    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);
+    gtk_box_pack_start (GTK_BOX (hbox), result->priv->entry, TRUE, TRUE, 2);
+    gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 2);
+    gtk_box_pack_start (GTK_BOX (result->priv->vbox), hbox, FALSE, FALSE, 0);
+    g_signal_connect (result->priv->entry, "activate",
+		      G_CALLBACK (on_entry_activated_cb), result);
+    g_signal_connect (button, "clicked",
+		      G_CALLBACK (on_button_clicked_cb), result);
+  } else {
+
+    result->priv->entry = NULL;
+  }
 
 
   /* The status bar */
diff --git a/plugins/evolution/evolution-book.cpp b/plugins/evolution/evolution-book.cpp
index 533f1b4..1f454c0 100644
--- a/plugins/evolution/evolution-book.cpp
+++ b/plugins/evolution/evolution-book.cpp
@@ -285,13 +285,19 @@ Evolution::Book::populate_menu (Ekiga::MenuBuilder &builder)
 }
 
 void
-Evolution::Book::set_search_filter (std::string _search_filter)
+Evolution::Book::set_search_filter (const std::string _search_filter)
 {
   search_filter = _search_filter;
   refresh ();
 }
 
 const std::string
+Evolution::Book::get_search_filter () const
+{
+  return search_filter;
+}
+
+const std::string
 Evolution::Book::get_status () const
 {
   return status;
diff --git a/plugins/evolution/evolution-book.h b/plugins/evolution/evolution-book.h
index dbe2d56..a0d1679 100644
--- a/plugins/evolution/evolution-book.h
+++ b/plugins/evolution/evolution-book.h
@@ -40,6 +40,7 @@
 
 #include <libebook/e-book.h>
 
+#include "filterable.h"
 #include "form.h"
 #include "book-impl.h"
 
@@ -55,6 +56,7 @@ namespace Evolution
  */
 
   class Book:
+    public virtual Ekiga::Filterable,
     public Ekiga::BookImpl<Contact>
   {
   public:
@@ -70,7 +72,9 @@ namespace Evolution
 
     bool populate_menu (Ekiga::MenuBuilder &builder);
 
-    void set_search_filter (std::string search_filter);
+    void set_search_filter (const std::string search_filter);
+
+    const std::string get_search_filter () const;
 
     const std::string get_status () const;
 
diff --git a/plugins/kab/kab-book.h b/plugins/kab/kab-book.h
index b59b9de..0275c8e 100644
--- a/plugins/kab/kab-book.h
+++ b/plugins/kab/kab-book.h
@@ -70,9 +70,6 @@ namespace KAB
     const std::string get_icon () const
     { return "local-object"; }
 
-    void set_search_filter (std::string)
-    {}
-
   private:
 
     Ekiga::ContactCore &core;
diff --git a/plugins/ldap/ldap-book.cpp b/plugins/ldap/ldap-book.cpp
index ed49ab2..54250ce 100644
--- a/plugins/ldap/ldap-book.cpp
+++ b/plugins/ldap/ldap-book.cpp
@@ -423,13 +423,19 @@ OPENLDAP::Book::populate_menu (Ekiga::MenuBuilder &builder)
 }
 
 void
-OPENLDAP::Book::set_search_filter (std::string _search_filter)
+OPENLDAP::Book::set_search_filter (const std::string _search_filter)
 {
   search_filter = _search_filter;
   refresh ();
 }
 
 const std::string
+OPENLDAP::Book::get_search_filter () const
+{
+  return search_filter;
+}
+
+const std::string
 OPENLDAP::Book::get_status () const
 {
   return status;
diff --git a/plugins/ldap/ldap-book.h b/plugins/ldap/ldap-book.h
index 7bc8ffc..a0a22a8 100644
--- a/plugins/ldap/ldap-book.h
+++ b/plugins/ldap/ldap-book.h
@@ -44,6 +44,7 @@
 #include <libxml/tree.h>
 #include <glib/gi18n.h>
 
+#include "filterable.h"
 #include "runtime.h"
 #include "book-impl.h"
 #include "form.h"
@@ -84,6 +85,7 @@ namespace OPENLDAP
  */
 
   class Book:
+    public virtual Ekiga::Filterable,
     public Ekiga::BookImpl<Contact>
   {
   public:
@@ -102,7 +104,9 @@ namespace OPENLDAP
 
     bool populate_menu (Ekiga::MenuBuilder &builder);
 
-    void set_search_filter (std::string search_string);
+    void set_search_filter (const std::string search_string);
+
+    const std::string get_search_filter () const;
 
     const std::string get_status () const;
 



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