]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-search-bar.c
Merge branch 'sasl'
[empathy.git] / libempathy-gtk / empathy-search-bar.c
index 42c8716fb5d6f85470d14a22d05588dfe4f1d06f..51a79096aa7eca8c8600e83db28eae6a8456c912 100644 (file)
@@ -20,6 +20,7 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
 
 #include <libempathy/empathy-utils.h>
 
@@ -57,8 +58,9 @@ empathy_search_bar_new (EmpathyChatView *view)
 }
 
 static void
-empathy_search_bar_size_request (GtkWidget *widget,
-    GtkRequisition *requisition)
+empathy_search_bar_get_preferred_height (GtkWidget *widget,
+    gint *minimun_height,
+    gint *natural_height)
 {
   GtkBin *bin;
   GtkWidget *child;
@@ -67,14 +69,7 @@ empathy_search_bar_size_request (GtkWidget *widget,
   child = gtk_bin_get_child (bin);
 
   if (child && gtk_widget_get_visible (child))
-    {
-      GtkRequisition child_requisition;
-
-      gtk_widget_size_request (child, &child_requisition);
-
-      requisition->width = child_requisition.width;
-      requisition->height = child_requisition.height;
-    }
+      gtk_widget_get_preferred_height (child, minimun_height, natural_height);
 }
 
 static void
@@ -103,7 +98,8 @@ empathy_search_bar_size_allocate (GtkWidget *widget,
 
 static void
 empathy_search_bar_update_buttons (EmpathySearchBar *self,
-    gchar *search)
+    gchar *search,
+    gboolean match_case)
 {
   gboolean can_go_forward = FALSE;
   gboolean can_go_backward = FALSE;
@@ -111,7 +107,7 @@ empathy_search_bar_update_buttons (EmpathySearchBar *self,
   EmpathySearchBarPriv* priv = GET_PRIV (self);
 
   /* update previous / next buttons */
-  empathy_chat_view_find_abilities (priv->chat_view, search,
+  empathy_chat_view_find_abilities (priv->chat_view, search, match_case,
       &can_go_backward, &can_go_forward);
 
   gtk_widget_set_sensitive (priv->search_previous,
@@ -120,15 +116,33 @@ empathy_search_bar_update_buttons (EmpathySearchBar *self,
       can_go_forward && !EMP_STR_EMPTY (search));
 }
 
+static void
+empathy_search_bar_update (EmpathySearchBar *self)
+{
+  gchar *search;
+  gboolean match_case;
+  EmpathySearchBarPriv *priv = GET_PRIV (self);
+
+  search = gtk_editable_get_chars (GTK_EDITABLE(priv->search_entry), 0, -1);
+  match_case = gtk_toggle_button_get_active (
+      GTK_TOGGLE_BUTTON (priv->search_match_case));
+
+  /* highlight & search */
+  empathy_chat_view_highlight (priv->chat_view, search, match_case);
+
+  /* update the buttons */
+  empathy_search_bar_update_buttons (self, search, match_case);
+
+  g_free (search);
+}
+
 void
 empathy_search_bar_show (EmpathySearchBar *self)
 {
-  gchar *search;
   EmpathySearchBarPriv *priv = GET_PRIV (self);
 
-  search = gtk_editable_get_chars (GTK_EDITABLE (priv->search_entry), 0, -1);
-  empathy_chat_view_highlight (priv->chat_view, search, TRUE);
-  empathy_search_bar_update_buttons (self, search);
+  /* update the highlighting and buttons */
+  empathy_search_bar_update (self);
 
   /* grab the focus to the search entry */
   gtk_widget_grab_focus (priv->search_entry);
@@ -136,15 +150,13 @@ empathy_search_bar_show (EmpathySearchBar *self)
   gtk_widget_show (GTK_WIDGET (self));
 }
 
-
-static void
-empathy_search_bar_close_cb (GtkButton *button,
-    gpointer user_data)
+void
+empathy_search_bar_hide (EmpathySearchBar *self)
 {
-  EmpathySearchBarPriv *priv = GET_PRIV (user_data);
+  EmpathySearchBarPriv *priv = GET_PRIV (self);
 
   empathy_chat_view_highlight (priv->chat_view, "", FALSE);
-  gtk_widget_hide (GTK_WIDGET (user_data));
+  gtk_widget_hide (GTK_WIDGET (self));
 
   /* give the focus back to the focus-chain with the chat view */
   gtk_widget_grab_focus (GTK_WIDGET (priv->chat_view));
@@ -167,15 +179,20 @@ empathy_search_bar_search (EmpathySearchBar *self,
       GTK_TOGGLE_BUTTON (priv->search_match_case));
 
   /* highlight & search */
-  // TODO: add case parameter
   empathy_chat_view_highlight (priv->chat_view, search, match_case);
   if (next)
     {
-      found = empathy_chat_view_find_next (priv->chat_view, search, new_search);
+      found = empathy_chat_view_find_next (priv->chat_view,
+          search,
+          new_search,
+          match_case);
     }
   else
     {
-      found = empathy_chat_view_find_previous (priv->chat_view, search, new_search);
+      found = empathy_chat_view_find_previous (priv->chat_view,
+          search,
+          new_search,
+          match_case);
     }
 
   /* (don't) display the not found label */
@@ -183,11 +200,18 @@ empathy_search_bar_search (EmpathySearchBar *self,
       !(found || EMP_STR_EMPTY (search)));
 
   /* update the buttons */
-  empathy_search_bar_update_buttons (self, search);
+  empathy_search_bar_update_buttons (self, search, match_case);
 
   g_free (search);
 }
 
+static void
+empathy_search_bar_close_cb (GtkButton *button,
+    gpointer user_data)
+{
+  empathy_search_bar_hide (EMPATHY_SEARCH_BAR (user_data));
+}
+
 static void
 empathy_search_bar_entry_changed (GtkEditable *entry,
     gpointer user_data)
@@ -195,6 +219,19 @@ empathy_search_bar_entry_changed (GtkEditable *entry,
   empathy_search_bar_search (EMPATHY_SEARCH_BAR (user_data), FALSE, TRUE);
 }
 
+static gboolean
+empathy_search_bar_key_pressed (GtkWidget   *widget,
+    GdkEventKey *event,
+    gpointer user_data)
+{
+  if (event->keyval == GDK_KEY_Escape)
+    {
+      empathy_search_bar_hide (EMPATHY_SEARCH_BAR (widget));
+      return TRUE;
+    }
+  return FALSE;
+}
+
 static void
 empathy_search_bar_next_cb (GtkButton *button,
     gpointer user_data)
@@ -209,6 +246,13 @@ empathy_search_bar_previous_cb (GtkButton *button,
   empathy_search_bar_search (EMPATHY_SEARCH_BAR (user_data), FALSE, FALSE);
 }
 
+static void
+empathy_search_bar_match_case_toggled (GtkButton *button,
+    gpointer user_data)
+{
+  empathy_search_bar_update (EMPATHY_SEARCH_BAR (user_data));
+}
+
 static void
 empathy_search_bar_init (EmpathySearchBar * self)
 {
@@ -240,8 +284,12 @@ empathy_search_bar_init (EmpathySearchBar * self)
       "search_entry", "changed", empathy_search_bar_entry_changed,
       "search_previous", "clicked", empathy_search_bar_previous_cb,
       "search_next", "clicked", empathy_search_bar_next_cb,
+      "search_match_case", "toggled", empathy_search_bar_match_case_toggled,
       NULL);
 
+  g_signal_connect (G_OBJECT (self), "key-press-event",
+      G_CALLBACK (empathy_search_bar_key_pressed), NULL);
+
   gtk_container_add (GTK_CONTAINER (self), internal);
   gtk_widget_show_all (internal);
   gtk_widget_hide (priv->search_not_found);
@@ -257,7 +305,14 @@ empathy_search_bar_class_init (EmpathySearchBarClass *class)
   g_type_class_add_private (gobject_class, sizeof (EmpathySearchBarPriv));
 
   /* Neither GtkBin nor GtkContainer seems to do this for us :( */
-  widget_class->size_request = empathy_search_bar_size_request;
+  widget_class->get_preferred_height = empathy_search_bar_get_preferred_height;
   widget_class->size_allocate = empathy_search_bar_size_allocate;
 }
 
+void
+empathy_search_bar_paste_clipboard (EmpathySearchBar *self)
+{
+  EmpathySearchBarPriv *priv = GET_PRIV (self);
+
+  gtk_editable_paste_clipboard (GTK_EDITABLE (priv->search_entry));
+}