[gnome-calendar] search: Open event from search results



commit d6c5bf032d462553903a9c149c777f14cfd604a3
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Apr 29 17:06:07 2019 -0300

    search: Open event from search results
    
    And this finally hooks up the last missing bit from the
    search engine: opening events from search results.
    
    All the necessary plumbing is there for extending search
    with other commands or results, such as go to date, etc.

 src/search/gcal-search-button.c    | 14 ++++++++++++++
 src/search/gcal-search-engine.c    |  2 --
 src/search/gcal-search-hit-event.c | 23 +++++++++++++++++++++--
 src/search/gcal-search-hit.c       | 10 ++++++++++
 src/search/gcal-search-hit.h       |  6 ++++++
 5 files changed, 51 insertions(+), 4 deletions(-)
---
diff --git a/src/search/gcal-search-button.c b/src/search/gcal-search-button.c
index 59b19409..33b3b791 100644
--- a/src/search/gcal-search-button.c
+++ b/src/search/gcal-search-button.c
@@ -22,6 +22,7 @@
 
 #include "gcal-context.h"
 #include "gcal-search-button.h"
+#include "gcal-search-hit.h"
 
 #include <math.h>
 
@@ -119,6 +120,14 @@ on_search_entry_changed_cb (GcalSearchButton *self)
                              g_object_ref (self));
 }
 
+static void
+on_search_entry_suggestion_activated_cb (DzlSuggestionEntry *entry,
+                                         GcalSearchHit      *search_hit,
+                                         GcalSearchButton   *self)
+{
+  gcal_search_hit_activate (search_hit, GTK_WIDGET (self));
+}
+
 static void
 on_unfocus_action_activated_cb (GSimpleAction *action,
                                 GVariant      *param,
@@ -257,6 +266,11 @@ gcal_search_button_init (GcalSearchButton *self)
                            G_CALLBACK (on_search_entry_changed_cb),
                            self,
                            G_CONNECT_SWAPPED);
+  g_signal_connect_object (entry,
+                           "suggestion-activated",
+                           G_CALLBACK (on_search_entry_suggestion_activated_cb),
+                           self,
+                           0);
 
   dzl_suggestion_entry_set_position_func (entry,
                                           position_suggestion_popover_func,
diff --git a/src/search/gcal-search-engine.c b/src/search/gcal-search-engine.c
index d25382b6..cd9ad95c 100644
--- a/src/search/gcal-search-engine.c
+++ b/src/search/gcal-search-engine.c
@@ -107,8 +107,6 @@ search_func (GTask        *task,
                               start,
                               end);
 
-  //e_cal_data_model_unsubscribe (self->data_model, E_CAL_DATA_MODEL_SUBSCRIBER (model));
-
   g_task_return_pointer (task, g_steal_pointer (&model), g_object_unref);
 }
 
diff --git a/src/search/gcal-search-hit-event.c b/src/search/gcal-search-hit-event.c
index 35214c2f..9b1699d6 100644
--- a/src/search/gcal-search-hit-event.c
+++ b/src/search/gcal-search-hit-event.c
@@ -62,8 +62,7 @@ set_event (GcalSearchHitEvent *self,
   dzl_suggestion_set_id (suggestion, gcal_event_get_uid (event));
   dzl_suggestion_set_title (suggestion, gcal_event_get_summary (event));
 
-  /* FIXME: use a better date description */
-  date_string = g_date_time_format (gcal_event_get_date_start (event), "%x %X %z");
+  date_string = gcal_event_format_date (event);
   dzl_suggestion_set_subtitle (suggestion, date_string);
 }
 
@@ -98,6 +97,25 @@ gcal_search_hit_event_get_icon_surface (DzlSuggestion *suggestion,
  * GcalSearchHit interface
  */
 
+static void
+gcal_search_hit_event_activate (GcalSearchHit *search_hit,
+                                GtkWidget     *for_widget)
+{
+  GcalSearchHitEvent *self;
+  GApplication *application;
+  const gchar *event_uid;
+
+  self = GCAL_SEARCH_HIT_EVENT (search_hit);
+  event_uid = gcal_event_get_uid (self->event);
+
+  application = g_application_get_default ();
+  g_assert (application != NULL);
+
+  g_action_group_activate_action (G_ACTION_GROUP (application),
+                                  "open-event",
+                                  g_variant_new_string (event_uid));
+}
+
 static gint
 gcal_search_hit_event_get_priority (GcalSearchHit *search_hit)
 {
@@ -125,6 +143,7 @@ gcal_search_hit_event_compare (GcalSearchHit *a,
 static void
 gcal_search_hit_interface_init (GcalSearchHitInterface *iface)
 {
+  iface->activate = gcal_search_hit_event_activate;
   iface->get_priority = gcal_search_hit_event_get_priority;
   iface->compare = gcal_search_hit_event_compare;
 }
diff --git a/src/search/gcal-search-hit.c b/src/search/gcal-search-hit.c
index 519202e3..fe1bc305 100644
--- a/src/search/gcal-search-hit.c
+++ b/src/search/gcal-search-hit.c
@@ -27,6 +27,16 @@ gcal_search_hit_default_init (GcalSearchHitInterface *iface)
 {
 }
 
+void
+gcal_search_hit_activate (GcalSearchHit *self,
+                          GtkWidget     *for_widget)
+{
+  g_return_if_fail (GCAL_IS_SEARCH_HIT (self));
+  g_return_if_fail (GCAL_SEARCH_HIT_GET_IFACE (self)->activate);
+
+  GCAL_SEARCH_HIT_GET_IFACE (self)->activate (self, for_widget);
+}
+
 gint
 gcal_search_hit_get_priority (GcalSearchHit *self)
 {
diff --git a/src/search/gcal-search-hit.h b/src/search/gcal-search-hit.h
index d76be0c5..101b5cb4 100644
--- a/src/search/gcal-search-hit.h
+++ b/src/search/gcal-search-hit.h
@@ -31,12 +31,18 @@ struct _GcalSearchHitInterface
 {
   GTypeInterface parent;
 
+  void               (*activate)                                 (GcalSearchHit      *self,
+                                                                  GtkWidget          *for_widget);
+
   gint               (*get_priority)                             (GcalSearchHit      *self);
 
   gint               (*compare)                                  (GcalSearchHit      *a,
                                                                   GcalSearchHit      *b);
 };
 
+void                 gcal_search_hit_activate                    (GcalSearchHit      *self,
+                                                                  GtkWidget          *for_widget);
+
 gint                 gcal_search_hit_get_priority                (GcalSearchHit      *self);
 
 gint                 gcal_search_hit_compare                     (GcalSearchHit      *a,


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