]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-search-bar.c
Updated Swedish translation
[empathy.git] / libempathy-gtk / empathy-search-bar.c
index 51a79096aa7eca8c8600e83db28eae6a8456c912..3383b9a12b2bb545a0898df54baaa6dae940a53d 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <glib.h>
-#include <glib-object.h>
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
+#include "config.h"
+#include "empathy-search-bar.h"
 
-#include <libempathy/empathy-utils.h>
+#include <glib/gi18n-lib.h>
+#include <tp-account-widgets/tpaw-builder.h>
+#include <tp-account-widgets/tpaw-utils.h>
 
-#include "empathy-chat-view.h"
-#include "empathy-search-bar.h"
 #include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathySearchBar)
 
-G_DEFINE_TYPE (EmpathySearchBar, empathy_search_bar, GTK_TYPE_BIN);
+G_DEFINE_TYPE (EmpathySearchBar, empathy_search_bar, GTK_TYPE_BOX);
 
 typedef struct _EmpathySearchBarPriv EmpathySearchBarPriv;
 struct _EmpathySearchBarPriv
 {
-  EmpathyChatView *chat_view;
+  EmpathyThemeAdium *chat_view;
 
   GtkWidget *search_entry;
 
   GtkWidget *search_match_case;
 
+  GtkWidget *search_match_case_toolitem;
+
   GtkWidget *search_close;
   GtkWidget *search_previous;
   GtkWidget *search_next;
@@ -48,7 +49,7 @@ struct _EmpathySearchBarPriv
 };
 
 GtkWidget *
-empathy_search_bar_new (EmpathyChatView *view)
+empathy_search_bar_new (EmpathyThemeAdium *view)
 {
   EmpathySearchBar *self = g_object_new (EMPATHY_TYPE_SEARCH_BAR, NULL);
 
@@ -57,45 +58,6 @@ empathy_search_bar_new (EmpathyChatView *view)
   return GTK_WIDGET (self);
 }
 
-static void
-empathy_search_bar_get_preferred_height (GtkWidget *widget,
-    gint *minimun_height,
-    gint *natural_height)
-{
-  GtkBin *bin;
-  GtkWidget *child;
-
-  bin = GTK_BIN (widget);
-  child = gtk_bin_get_child (bin);
-
-  if (child && gtk_widget_get_visible (child))
-      gtk_widget_get_preferred_height (child, minimun_height, natural_height);
-}
-
-static void
-empathy_search_bar_size_allocate (GtkWidget *widget,
-    GtkAllocation *allocation)
-{
-  GtkBin *bin;
-  GtkWidget *child;
-  GtkAllocation child_allocation;
-
-  bin = GTK_BIN (widget);
-  child = gtk_bin_get_child (bin);
-
-  gtk_widget_set_allocation (widget, allocation);
-
-  if (child && gtk_widget_get_visible (child))
-    {
-      child_allocation.x = allocation->x;
-      child_allocation.y = allocation->y;
-      child_allocation.width = MAX (allocation->width, 0);
-      child_allocation.height = MAX (allocation->height, 0);
-
-      gtk_widget_size_allocate (child, &child_allocation);
-    }
-}
-
 static void
 empathy_search_bar_update_buttons (EmpathySearchBar *self,
     gchar *search,
@@ -107,13 +69,13 @@ 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, match_case,
+  empathy_theme_adium_find_abilities (priv->chat_view, search, match_case,
       &can_go_backward, &can_go_forward);
 
   gtk_widget_set_sensitive (priv->search_previous,
-      can_go_backward && !EMP_STR_EMPTY (search));
+      can_go_backward && !TPAW_STR_EMPTY (search));
   gtk_widget_set_sensitive (priv->search_next,
-      can_go_forward && !EMP_STR_EMPTY (search));
+      can_go_forward && !TPAW_STR_EMPTY (search));
 }
 
 static void
@@ -128,7 +90,7 @@ empathy_search_bar_update (EmpathySearchBar *self)
       GTK_TOGGLE_BUTTON (priv->search_match_case));
 
   /* highlight & search */
-  empathy_chat_view_highlight (priv->chat_view, search, match_case);
+  empathy_theme_adium_highlight (priv->chat_view, search, match_case);
 
   /* update the buttons */
   empathy_search_bar_update_buttons (self, search, match_case);
@@ -155,7 +117,7 @@ empathy_search_bar_hide (EmpathySearchBar *self)
 {
   EmpathySearchBarPriv *priv = GET_PRIV (self);
 
-  empathy_chat_view_highlight (priv->chat_view, "", FALSE);
+  empathy_theme_adium_highlight (priv->chat_view, "", FALSE);
   gtk_widget_hide (GTK_WIDGET (self));
 
   /* give the focus back to the focus-chain with the chat view */
@@ -179,17 +141,17 @@ empathy_search_bar_search (EmpathySearchBar *self,
       GTK_TOGGLE_BUTTON (priv->search_match_case));
 
   /* highlight & search */
-  empathy_chat_view_highlight (priv->chat_view, search, match_case);
+  empathy_theme_adium_highlight (priv->chat_view, search, match_case);
   if (next)
     {
-      found = empathy_chat_view_find_next (priv->chat_view,
+      found = empathy_theme_adium_find_next (priv->chat_view,
           search,
           new_search,
           match_case);
     }
   else
     {
-      found = empathy_chat_view_find_previous (priv->chat_view,
+      found = empathy_theme_adium_find_previous (priv->chat_view,
           search,
           new_search,
           match_case);
@@ -197,7 +159,7 @@ empathy_search_bar_search (EmpathySearchBar *self,
 
   /* (don't) display the not found label */
   gtk_widget_set_visible (priv->search_not_found,
-      !(found || EMP_STR_EMPTY (search)));
+      !(found || TPAW_STR_EMPTY (search)));
 
   /* update the buttons */
   empathy_search_bar_update_buttons (self, search, match_case);
@@ -253,6 +215,42 @@ empathy_search_bar_match_case_toggled (GtkButton *button,
   empathy_search_bar_update (EMPATHY_SEARCH_BAR (user_data));
 }
 
+static void
+empathy_search_bar_match_case_menu_toggled (GtkWidget *check,
+    gpointer user_data)
+{
+  EmpathySearchBarPriv* priv = GET_PRIV ( EMPATHY_SEARCH_BAR (user_data));
+  gboolean match_case;
+
+  match_case = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (check));
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->search_match_case),
+      match_case);
+}
+
+static gboolean
+empathy_searchbar_create_menu_proxy_cb (GtkToolItem *toolitem,
+    gpointer user_data)
+{
+  EmpathySearchBarPriv* priv = GET_PRIV ( EMPATHY_SEARCH_BAR (user_data));
+  GtkWidget *checkbox_menu;
+  gboolean match_case;
+
+  checkbox_menu = gtk_check_menu_item_new_with_mnemonic (_("_Match case"));
+  match_case = gtk_toggle_button_get_active (
+      GTK_TOGGLE_BUTTON (priv->search_match_case));
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (checkbox_menu),
+      match_case);
+
+  g_signal_connect (checkbox_menu, "toggled",
+      G_CALLBACK (empathy_search_bar_match_case_menu_toggled), user_data);
+
+  gtk_tool_item_set_proxy_menu_item (toolitem, "menu-proxy",
+      checkbox_menu);
+
+  return TRUE;
+}
+
 static void
 empathy_search_bar_init (EmpathySearchBar * self)
 {
@@ -267,7 +265,7 @@ empathy_search_bar_init (EmpathySearchBar * self)
   self->priv = priv;
 
   filename = empathy_file_lookup ("empathy-search-bar.ui", "libempathy-gtk");
-  gui = empathy_builder_get_file (filename,
+  gui = tpaw_builder_get_file (filename,
       "search_widget", &internal,
       "search_close", &priv->search_close,
       "search_entry", &priv->search_entry,
@@ -279,18 +277,19 @@ empathy_search_bar_init (EmpathySearchBar * self)
   g_free (filename);
 
   /* Add the signals */
-  empathy_builder_connect (gui, self,
+  tpaw_builder_connect (gui, self,
       "search_close", "clicked", empathy_search_bar_close_cb,
       "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,
+      "search_match_case_toolitem", "create-menu-proxy", empathy_searchbar_create_menu_proxy_cb,
       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_box_pack_start (GTK_BOX (self), internal, TRUE, TRUE, 0);
   gtk_widget_show_all (internal);
   gtk_widget_hide (priv->search_not_found);
   g_object_unref (gui);
@@ -300,13 +299,8 @@ static void
 empathy_search_bar_class_init (EmpathySearchBarClass *class)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
-  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
   g_type_class_add_private (gobject_class, sizeof (EmpathySearchBarPriv));
-
-  /* Neither GtkBin nor GtkContainer seems to do this for us :( */
-  widget_class->get_preferred_height = empathy_search_bar_get_preferred_height;
-  widget_class->size_allocate = empathy_search_bar_size_allocate;
 }
 
 void