[Xfce4-commits] [panel-plugins/xfce4-verve-plugin] 02/02: Add smart bookmark and DuckDuckGo !bang support (both optional; off by default)

noreply at xfce.org noreply at xfce.org
Sat Jan 31 22:14:42 CET 2015


This is an automated email from the git hooks/post-receive script.

isaacschemm pushed a commit to branch master
in repository panel-plugins/xfce4-verve-plugin.

commit 2dae40888dafd575186e78c30ae8480a16c83aa0
Author: Isaac Schemm <isaacschemm at gmail.com>
Date:   Sat Jan 31 15:14:14 2015 -0600

    Add smart bookmark and DuckDuckGo !bang support (both optional; off by default)
---
 panel-plugin/verve-plugin.c |  272 ++++++++++++++++++++++++++++++++++++++++++-
 panel-plugin/verve.c        |   55 ++++++++-
 2 files changed, 323 insertions(+), 4 deletions(-)

diff --git a/panel-plugin/verve-plugin.c b/panel-plugin/verve-plugin.c
index aa9b23f..4b91056 100644
--- a/panel-plugin/verve-plugin.c
+++ b/panel-plugin/verve-plugin.c
@@ -1,8 +1,8 @@
 /***************************************************************************
  *            verve-plugin.c
  *
- *  Copyright  2006-2007  Jannis Pohlmann
- *  jannis at xfce.org
+ *  Copyright © 2006-2007 Jannis Pohlmann <jannis at xfce.org>
+ *  Copyright © 2015 Isaac Schemm <isaacschemm at gmail.com>
  ****************************************************************************/
 
 /*
@@ -68,6 +68,10 @@ typedef struct
   /* Properties */ 
   gint              size;
   gint              history_length;
+  gboolean          use_bang;
+  gboolean          use_backslash;
+  gboolean          use_smartbookmark;
+  gchar            *smartbookmark_url;
 
   /* Default GTK style - to restore after blinking upon verve-focus */
   GtkStyle         *default_style;
@@ -518,6 +522,10 @@ verve_plugin_new (XfcePanelPlugin *plugin)
   verve->n_complete = 0;
   verve->size = 20;
   verve->history_length = 25;
+  verve->use_bang = FALSE;
+  verve->use_backslash = FALSE;
+  verve->use_smartbookmark = FALSE;
+  verve->smartbookmark_url = "";
 
   /* Initialize label */
   verve->label = gtk_label_new ("");
@@ -662,6 +670,79 @@ verve_plugin_update_history_length (XfcePanelPlugin *plugin,
 
 
 
+static gboolean
+verve_plugin_update_bang (XfcePanelPlugin *plugin,
+                          gboolean         use_bang,
+                          VervePlugin     *verve)
+{
+  g_return_val_if_fail (verve != NULL, FALSE);
+
+  /* Set internal !bang setting variable */
+  verve->use_bang = use_bang;
+
+  /* Update panel */
+  verve_set_bang_setting (use_bang);
+
+  return TRUE;
+}
+
+
+
+
+static gboolean
+verve_plugin_update_backslash (XfcePanelPlugin *plugin,
+                               gboolean         use_backslash,
+                               VervePlugin     *verve)
+{
+  g_return_val_if_fail (verve != NULL, FALSE);
+
+  /* Set internal backslash setting variable */
+  verve->use_backslash = use_backslash;
+
+  /* Update panel */
+  verve_set_backslash_setting (use_backslash);
+
+  return TRUE;
+}
+
+
+
+static gboolean
+verve_plugin_update_smartbookmark (XfcePanelPlugin *plugin,
+                                   gboolean         use_smartbookmark,
+                                   VervePlugin     *verve)
+{
+  g_return_val_if_fail (verve != NULL, FALSE);
+
+  /* Set internal smartbookmark setting variable */
+  verve->use_smartbookmark = use_smartbookmark;
+
+  /* Update panel */
+  verve_set_smartbookmark_setting (use_smartbookmark);
+
+  return TRUE;
+}
+
+
+
+static gboolean
+verve_plugin_update_smartbookmark_url (XfcePanelPlugin *plugin,
+                                       const gchar     *url,
+                                       VervePlugin     *verve)
+{
+  g_return_val_if_fail (verve != NULL, FALSE);
+
+  /* Set internal search engine URL variable */
+  verve->smartbookmark_url = g_strdup(url);
+
+  /* Update panel */
+  verve_set_smartbookmark_url (url);
+
+  return TRUE;
+}
+
+
+
 static void
 verve_plugin_read_rc_file (XfcePanelPlugin *plugin, 
                            VervePlugin *verve)
@@ -678,6 +759,18 @@ verve_plugin_read_rc_file (XfcePanelPlugin *plugin,
   /* Default number of saved history entries */
   gint    history_length = 25;
 
+  /* Default !bang setting */
+  gboolean use_bang = TRUE;
+
+  /* Default backslash setting */
+  gboolean use_backslash = FALSE;
+
+  /* Default smartbookmark setting */
+  gboolean use_smartbookmark = FALSE;
+
+  /* Default search engine URL */
+  gchar *smartbookmark_url = "";
+
   g_return_if_fail (plugin != NULL);
   g_return_if_fail (verve != NULL);
 
@@ -702,6 +795,18 @@ verve_plugin_read_rc_file (XfcePanelPlugin *plugin,
 
       /* Read number of saved history entries */
       history_length = xfce_rc_read_int_entry (rc, "history-length", history_length);
+
+      /* Read !bang setting */
+      use_bang = xfce_rc_read_bool_entry (rc, "use-bang", use_bang);
+
+      /* Read backslash setting */
+      use_backslash = xfce_rc_read_bool_entry (rc, "use-backslash", use_backslash);
+
+      /* Read smartbookmark setting */
+      use_smartbookmark = xfce_rc_read_bool_entry (rc, "use-smartbookmark", use_smartbookmark);
+
+      /* Read smartbookmark URL */
+      smartbookmark_url = xfce_rc_read_entry (rc, "smartbookmark-url", smartbookmark_url);
     
       /* Update plugin size */
       verve_plugin_update_size (NULL, size, verve);
@@ -711,6 +816,18 @@ verve_plugin_read_rc_file (XfcePanelPlugin *plugin,
 
       /* Update history length */
       verve_plugin_update_history_length (NULL, history_length, verve);
+
+      /* Update !bang setting */
+      verve_plugin_update_bang (NULL, use_bang, verve);
+
+      /* Update backslash setting */
+      verve_plugin_update_backslash (NULL, use_backslash, verve);
+
+      /* Update smartbookmark setting */
+      verve_plugin_update_smartbookmark (NULL, use_smartbookmark, verve);
+
+      /* Update smartbookmark URL */
+      verve_plugin_update_smartbookmark_url (NULL, smartbookmark_url, verve);
       
       /* Close handle */
       xfce_rc_close (rc);
@@ -752,6 +869,18 @@ verve_plugin_write_rc_file (XfcePanelPlugin *plugin,
 
       /* Write number of saved history entries */
       xfce_rc_write_int_entry (rc, "history-length", verve->history_length);
+
+      /* Write !bang setting */
+      xfce_rc_write_bool_entry (rc, "use-bang", verve->use_bang);
+
+      /* Write backslash setting */
+      xfce_rc_write_bool_entry (rc, "use-backslash", verve->use_backslash);
+
+      /* Write smartbookmark setting */
+      xfce_rc_write_bool_entry (rc, "use-smartbookmark", verve->use_smartbookmark);
+
+      /* Write smartbookmark URL */
+      xfce_rc_write_entry (rc, "smartbookmark-url", verve->smartbookmark_url);
     
       /* Close handle */
       xfce_rc_close (rc);
@@ -803,6 +932,57 @@ verve_plugin_history_length_changed (GtkSpinButton *spin,
 
 
 static void
+verve_plugin_bang_changed (GtkToggleButton *button, 
+                           VervePlugin     *verve)
+{
+  g_return_if_fail (verve != NULL);
+
+  /* Update !bang setting */
+  verve_plugin_update_bang (NULL, gtk_toggle_button_get_active(button), verve);
+}
+
+
+
+static void
+verve_plugin_backslash_changed (GtkToggleButton *button, 
+                                VervePlugin     *verve)
+{
+  g_return_if_fail (verve != NULL);
+
+  /* Update backslash setting */
+  verve_plugin_update_backslash (NULL, gtk_toggle_button_get_active(button), verve);
+}
+
+
+
+static void
+verve_plugin_smartbookmark_changed (GtkToggleButton *button, 
+                                    VervePlugin     *verve)
+{
+  g_return_if_fail (verve != NULL);
+
+  /* Update smartbookmark setting */
+  verve_plugin_update_smartbookmark (NULL, gtk_toggle_button_get_active(button), verve);
+}
+
+
+
+static void
+verve_plugin_smartbookmark_url_changed (GtkEntry    *box, 
+                                        VervePlugin *verve)
+{
+  g_return_if_fail (verve != NULL);
+
+  /* Get the entered URL */
+  const gchar *smartbookmark_url = gtk_entry_get_text(box);
+
+  /* Update search engine ID */
+  verve_plugin_update_smartbookmark_url (NULL, smartbookmark_url, verve);
+}
+
+
+
+static void
 verve_plugin_response (GtkWidget *dialog, 
                        int response, 
                        VervePlugin *verve)
@@ -843,6 +1023,16 @@ verve_plugin_properties (XfcePanelPlugin *plugin,
   GtkWidget *history_length_spin;
   GtkObject *adjustment;
 
+  GtkWidget *bin3;
+  GtkWidget *bin4;
+  GtkWidget *ddg_label;
+  GtkWidget *ddg_buttons;
+  GtkWidget *bang_button;
+  GtkWidget *backslash_button;
+  GtkWidget *smartbookmark_button;
+  GtkWidget *engine_label;
+  GtkWidget *engine_box;
+
   g_return_if_fail (plugin != NULL);
   g_return_if_fail (verve != NULL);
 
@@ -956,6 +1146,84 @@ verve_plugin_properties (XfcePanelPlugin *plugin,
   /* Be notified when the user requests a different history length */
   g_signal_connect (history_length_spin, "value-changed", G_CALLBACK (verve_plugin_history_length_changed), verve);
 
+  /* Frame for DuckDuckGo settings */
+  frame = xfce_gtk_frame_box_new (_("DuckDuckGo"), &bin3);
+  gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
+  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame, TRUE, TRUE, 0);
+  gtk_widget_show (frame);
+
+  /* DuckDuckGo container */
+  hbox = gtk_vbox_new (FALSE, 8);
+  gtk_container_add (GTK_CONTAINER (bin3), hbox);
+  gtk_widget_show (hbox);
+
+  /* DuckDuckGo redirect options label */
+  ddg_label = gtk_label_new(_("Search DuckDuckGo if command starts with:"));
+  gtk_box_pack_start (GTK_BOX (hbox), ddg_label, FALSE, TRUE, 0);
+  gtk_widget_show (ddg_label);
+
+  /* DuckDuckGo buttons container */
+  ddg_buttons = gtk_hbox_new(FALSE, 8);
+  gtk_box_pack_start (GTK_BOX (hbox), ddg_buttons, FALSE, TRUE, 0);
+  gtk_widget_show (ddg_buttons);
+
+  /* !bang check box */
+  bang_button = gtk_check_button_new_with_label("!");
+  gtk_box_pack_start (GTK_BOX (ddg_buttons), bang_button, FALSE, TRUE, 0);
+  gtk_widget_show (bang_button);
+
+  /* Assign current setting to !bang check box */
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bang_button), verve->use_bang);
+
+  /* Be notified when the user requests a different !bang setting */
+  g_signal_connect (bang_button, "toggled", G_CALLBACK (verve_plugin_bang_changed), verve);
+
+  /* backslash check box */
+  backslash_button = gtk_check_button_new_with_label("\\");
+  gtk_box_pack_start (GTK_BOX (ddg_buttons), backslash_button, FALSE, TRUE, 0);
+  gtk_widget_show (backslash_button);
+
+  /* Assign current setting to backslash check box */
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (backslash_button), verve->use_backslash);
+
+  /* Be notified when the user requests a different backslash setting */
+  g_signal_connect (backslash_button, "toggled", G_CALLBACK (verve_plugin_backslash_changed), verve);
+
+  /* Frame for smart bookmark settings */
+  frame = xfce_gtk_frame_box_new (_("Smart Bookmark"), &bin4);
+  gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
+  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), frame, TRUE, TRUE, 0);
+  gtk_widget_show (frame);
+
+  /* Smart bookmark container */
+  hbox = gtk_vbox_new (FALSE, 8);
+  gtk_container_add (GTK_CONTAINER (bin4), hbox);
+  gtk_widget_show (hbox);
+
+  /* smartbookmark check box */
+  smartbookmark_button = gtk_check_button_new_with_label(_("Instead of launching commands,\nuse this smart bookmark URL:"));
+  gtk_box_pack_start (GTK_BOX (hbox), smartbookmark_button, FALSE, TRUE, 0);
+  gtk_widget_show (smartbookmark_button);
+
+  /* Assign current setting to smartbookmark check box */
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (smartbookmark_button), verve->use_smartbookmark);
+
+  /* Be notified when the user requests a different smartbookmark setting */
+  g_signal_connect (smartbookmark_button, "toggled", G_CALLBACK (verve_plugin_smartbookmark_changed), verve);
+
+  /* Smart bookmark entry box */
+  engine_box = gtk_entry_new();
+
+  /* Set text to search engine URL */
+  gtk_entry_set_text(engine_box, verve->smartbookmark_url);
+
+  gtk_widget_add_mnemonic_label (engine_box, engine_label);
+  gtk_box_pack_start (GTK_BOX (hbox), engine_box, FALSE, TRUE, 0);
+  gtk_widget_show (engine_box);
+
+  /* Be notified when the user requests a different search engine setting */
+  g_signal_connect (engine_box, "changed", G_CALLBACK (verve_plugin_smartbookmark_url_changed), verve);
+
   /* Show properties dialog */
   gtk_widget_show (dialog);
 }
diff --git a/panel-plugin/verve.c b/panel-plugin/verve.c
index a0c1c01..ede2747 100644
--- a/panel-plugin/verve.c
+++ b/panel-plugin/verve.c
@@ -1,8 +1,8 @@
 /***************************************************************************
  *            verve.c
  *
- *  Copyright  2006-2007  Jannis Pohlmann
- *  jannis at xfce.org
+ *  Copyright © 2006-2007 Jannis Pohlmann <jannis at xfce.org>
+ *  Copyright © 2015 Isaac Schemm <isaacschemm at gmail.com>
  ****************************************************************************/
 
 /*
@@ -50,7 +50,44 @@ static gboolean verve_is_directory (const gchar *str);
                     "(/[-A-Za-z0-9_$.+!*(),;:@&=?/~#%]*[^]'.}>) \t\r\n,\\\"])?/?$"
 #define MATCH_EMAIL "^(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+$"
 
+/*********************************************************************
+ *
+ * Smart bookmark and DuckDuckGo settings
+ * -------------------------
+ *
+ * These static variables store the settings for DuckDuckGo and/or smartbookmark functionality.
+ *
+ *********************************************************************/
+
+static gboolean use_bang = TRUE;
+static gboolean use_backslash = FALSE;
+static gboolean use_smartbookmark = FALSE;
+static gchar *smartbookmark_url = NULL;
+
+void
+verve_set_bang_setting (gboolean bang)
+{
+  use_bang = bang;
+}
+
+void
+verve_set_backslash_setting (gboolean backslash)
+{
+  use_backslash = backslash;
+}
 
+void
+verve_set_smartbookmark_setting (gboolean smartbookmark)
+{
+  use_smartbookmark = smartbookmark;
+}
+
+void
+verve_set_smartbookmark_url (gchar* engine)
+{
+  g_free(smartbookmark_url);
+  smartbookmark_url = g_strdup(engine);
+}
 
 /*********************************************************************
  *
@@ -161,6 +198,20 @@ verve_execute (const gchar *input,
     /* Build exo-open command */
     command = g_strconcat ("exo-open ", input, NULL);
   }
+  else if ((use_bang && input[0] == '!') || (use_backslash && input[0] == '\\'))
+  {
+    /* Launch DuckDuckGo */
+    gchar *esc_input = g_uri_escape_string(input, NULL, TRUE);
+    command = g_strconcat ("exo-open https://duckduckgo.com/?q=", esc_input, NULL);
+    g_free(esc_input);
+  }
+  else if (use_smartbookmark)
+  {
+    /* Launch user-defined search engine */
+    gchar *esc_input = g_uri_escape_string(input, NULL, TRUE);
+    command = g_strconcat ("exo-open ", smartbookmark_url, esc_input, NULL);
+    g_free(esc_input);
+  }
   else
   {
     /* Run command using the xfterm4 wrapper if the terminal flag was set */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list