[Xfce4-commits] [panel-plugins/xfce4-verve-plugin] 01/01: Store settings for DuckDuckGo and smart bookmark in separate struct & pass to execute function (removes use of static variables)
noreply at xfce.org
noreply at xfce.org
Sat Feb 7 17:23:32 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 127094cbe9c332e3b5d52ca68822013c4a3efbd5
Author: Isaac Schemm <isaacschemm at gmail.com>
Date: Sat Feb 7 10:22:37 2015 -0600
Store settings for DuckDuckGo and smart bookmark in separate struct & pass to execute function (removes use of static variables)
---
panel-plugin/verve-plugin.c | 52 ++++++++++++++++---------------------------
panel-plugin/verve.c | 48 +++++----------------------------------
panel-plugin/verve.h | 10 ++++++++-
3 files changed, 33 insertions(+), 77 deletions(-)
diff --git a/panel-plugin/verve-plugin.c b/panel-plugin/verve-plugin.c
index 13be53e..7a0f3c7 100644
--- a/panel-plugin/verve-plugin.c
+++ b/panel-plugin/verve-plugin.c
@@ -68,10 +68,7 @@ typedef struct
/* Properties */
gint size;
gint history_length;
- gboolean use_bang;
- gboolean use_backslash;
- gboolean use_smartbookmark;
- gchar *smartbookmark_url;
+ VerveLaunchParams launch_params;
/* Default GTK style - to restore after blinking upon verve-focus */
GtkStyle *default_style;
@@ -381,7 +378,7 @@ verve_plugin_keypress_cb (GtkWidget *entry,
terminal = FALSE;
/* Try executing the command */
- if (G_LIKELY (verve_execute (command, terminal)))
+ if (G_LIKELY (verve_execute (command, terminal, verve->launch_params)))
{
/* Hide the panel again */
xfce_panel_plugin_set_panel_hidden (verve->plugin, TRUE);
@@ -522,10 +519,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 = "";
+ verve->launch_params.use_bang = FALSE;
+ verve->launch_params.use_backslash = FALSE;
+ verve->launch_params.use_smartbookmark = FALSE;
+ verve->launch_params.smartbookmark_url = g_strdup("");
/* Initialize label */
verve->label = gtk_label_new ("");
@@ -678,10 +675,7 @@ verve_plugin_update_bang (XfcePanelPlugin *plugin,
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);
+ verve->launch_params.use_bang = use_bang;
return TRUE;
}
@@ -697,10 +691,7 @@ verve_plugin_update_backslash (XfcePanelPlugin *plugin,
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);
+ verve->launch_params.use_backslash = use_backslash;
return TRUE;
}
@@ -715,10 +706,7 @@ verve_plugin_update_smartbookmark (XfcePanelPlugin *plugin,
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);
+ verve->launch_params.use_smartbookmark = use_smartbookmark;
return TRUE;
}
@@ -733,10 +721,8 @@ verve_plugin_update_smartbookmark_url (XfcePanelPlugin *plugin,
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);
+ g_free (verve->launch_params.smartbookmark_url);
+ verve->launch_params.smartbookmark_url = g_strdup(url);
return TRUE;
}
@@ -871,16 +857,16 @@ verve_plugin_write_rc_file (XfcePanelPlugin *plugin,
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);
+ xfce_rc_write_bool_entry (rc, "use-bang", verve->launch_params.use_bang);
/* Write backslash setting */
- xfce_rc_write_bool_entry (rc, "use-backslash", verve->use_backslash);
+ xfce_rc_write_bool_entry (rc, "use-backslash", verve->launch_params.use_backslash);
/* Write smartbookmark setting */
- xfce_rc_write_bool_entry (rc, "use-smartbookmark", verve->use_smartbookmark);
+ xfce_rc_write_bool_entry (rc, "use-smartbookmark", verve->launch_params.use_smartbookmark);
/* Write smartbookmark URL */
- xfce_rc_write_entry (rc, "smartbookmark-url", verve->smartbookmark_url);
+ xfce_rc_write_entry (rc, "smartbookmark-url", verve->launch_params.smartbookmark_url);
/* Close handle */
xfce_rc_close (rc);
@@ -1173,7 +1159,7 @@ verve_plugin_properties (XfcePanelPlugin *plugin,
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);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bang_button), verve->launch_params.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);
@@ -1184,7 +1170,7 @@ verve_plugin_properties (XfcePanelPlugin *plugin,
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);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (backslash_button), verve->launch_params.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);
@@ -1206,7 +1192,7 @@ verve_plugin_properties (XfcePanelPlugin *plugin,
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);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (smartbookmark_button), verve->launch_params.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);
@@ -1215,7 +1201,7 @@ verve_plugin_properties (XfcePanelPlugin *plugin,
engine_box = gtk_entry_new();
/* Set text to search engine URL */
- gtk_entry_set_text(engine_box, verve->smartbookmark_url);
+ gtk_entry_set_text(engine_box, verve->launch_params.smartbookmark_url);
gtk_widget_add_mnemonic_label (engine_box, engine_label);
gtk_box_pack_start (GTK_BOX (hbox), engine_box, FALSE, TRUE, 0);
diff --git a/panel-plugin/verve.c b/panel-plugin/verve.c
index a144f78..e8de229 100644
--- a/panel-plugin/verve.c
+++ b/panel-plugin/verve.c
@@ -52,45 +52,6 @@ static gboolean verve_is_directory (const gchar *str);
/*********************************************************************
*
- * 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);
-}
-
-/*********************************************************************
- *
* Initialize/shutdown Verve
* -------------------------
*
@@ -192,7 +153,8 @@ gboolean verve_spawn_command_line (const gchar *cmdline)
gboolean
verve_execute (const gchar *input,
- gboolean terminal)
+ gboolean terminal,
+ VerveLaunchParams launch_params)
{
gchar *command;
gboolean result = FALSE;
@@ -203,18 +165,18 @@ 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] == '\\'))
+ else if ((launch_params.use_bang && input[0] == '!') || (launch_params.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)
+ else if (launch_params.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);
+ command = g_strconcat ("exo-open ", launch_params.smartbookmark_url, esc_input, NULL);
g_free(esc_input);
}
else
diff --git a/panel-plugin/verve.h b/panel-plugin/verve.h
index e862c7e..0a42149 100644
--- a/panel-plugin/verve.h
+++ b/panel-plugin/verve.h
@@ -27,13 +27,21 @@
#include "verve-env.h"
#include "verve-history.h"
+typedef struct
+{
+ gboolean use_bang;
+ gboolean use_backslash;
+ gboolean use_smartbookmark;
+ gchar *smartbookmark_url;
+} VerveLaunchParams;
+
/* Init / Shutdown Verve */
void verve_init (void);
void verve_shutdown (void);
/* Command line methods */
gboolean verve_spawn_command_line (const gchar *cmdline);
-gboolean verve_execute (const gchar *input, gboolean terminal);
+gboolean verve_execute (const gchar *input, gboolean terminal, VerveLaunchParams params);
#endif /* !__VERVE_H__ */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list