2
* @file search_engine_dialog.c Search engine subscription dialog
4
* Copyright (C) 2007-2008 Lars Lindner <lars.lindner@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include "ui/search_engine_dialog.h"
26
#include "ui/liferea_dialog.h"
28
static void search_engine_dialog_class_init (SearchEngineDialogClass *klass);
29
static void search_engine_dialog_init (SearchEngineDialog *ld);
31
#define SEARCH_ENGINE_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), SEARCH_ENGINE_DIALOG_TYPE, SearchEngineDialogPrivate))
33
struct SearchEngineDialogPrivate {
34
GtkWidget *dialog; /**< the dialog widget */
35
GtkWidget *query; /**< entry widget for the search query */
36
GtkWidget *resultCount; /**< adjustment widget for search result count limit */
38
const gchar *uriFmt; /**< URI format of the search engine feed to be created */
39
gboolean limitSupported; /**< TRUE if search result count limit is supported in uriFmt */
42
static GObjectClass *parent_class = NULL;
45
search_engine_dialog_get_type (void)
47
static GType type = 0;
49
if (G_UNLIKELY (type == 0))
51
static const GTypeInfo our_info =
53
sizeof (SearchEngineDialogClass),
55
NULL, /* base_finalize */
56
(GClassInitFunc) search_engine_dialog_class_init,
58
NULL, /* class_data */
59
sizeof (SearchEngineDialog),
61
(GInstanceInitFunc) search_engine_dialog_init
64
type = g_type_register_static (G_TYPE_OBJECT,
73
search_engine_dialog_finalize (GObject *object)
75
SearchEngineDialog *sed = SEARCH_ENGINE_DIALOG (object);
77
gtk_widget_destroy (sed->priv->dialog);
79
G_OBJECT_CLASS (parent_class)->finalize (object);
83
search_engine_dialog_class_init (SearchEngineDialogClass *klass)
85
GObjectClass *object_class = G_OBJECT_CLASS (klass);
87
parent_class = g_type_class_peek_parent (klass);
89
object_class->finalize = search_engine_dialog_finalize;
91
g_type_class_add_private (object_class, sizeof(SearchEngineDialogPrivate));
95
search_engine_dialog_init (SearchEngineDialog *sed)
97
sed->priv = SEARCH_ENGINE_DIALOG_GET_PRIVATE (sed);
101
on_search_engine_dialog_response (GtkDialog *dialog, gint responseId, gpointer user_data)
103
SearchEngineDialog *sed = (SearchEngineDialog *)user_data;
104
GtkAdjustment *resultCountAdjust;
105
gchar *searchtext, *searchUri;
107
if (GTK_RESPONSE_OK == responseId) {
108
resultCountAdjust = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (sed->priv->resultCount));
109
searchtext = g_uri_escape_string (gtk_entry_get_text (GTK_ENTRY (sed->priv->query)), NULL, TRUE);
110
if (sed->priv->limitSupported)
111
searchUri = g_strdup_printf (sed->priv->uriFmt, searchtext, (int)gtk_adjustment_get_value (resultCountAdjust));
113
searchUri = g_strdup_printf (sed->priv->uriFmt, searchtext);
115
feedlist_add_subscription (searchUri,
118
FEED_REQ_RESET_TITLE |
119
FEED_REQ_PRIORITY_HIGH);
124
g_object_unref (sed);
128
search_engine_dialog_new (const gchar *uriFmt, gboolean limitSupported)
130
SearchEngineDialog *sed;
132
sed = SEARCH_ENGINE_DIALOG (g_object_new (SEARCH_ENGINE_DIALOG_TYPE, NULL));
133
sed->priv->dialog = liferea_dialog_new (NULL, "searchenginedialog");
134
sed->priv->query = liferea_dialog_lookup (sed->priv->dialog, "searchkeywords");
135
sed->priv->resultCount = liferea_dialog_lookup (sed->priv->dialog, "resultcount");
136
sed->priv->limitSupported = limitSupported;
137
sed->priv->uriFmt = uriFmt;
139
gtk_window_set_focus (GTK_WINDOW (sed->priv->dialog), sed->priv->query);
140
gtk_entry_set_text (GTK_ENTRY (sed->priv->query), "");
141
gtk_widget_set_sensitive (sed->priv->resultCount, limitSupported);
143
g_signal_connect (G_OBJECT (sed->priv->dialog), "response", G_CALLBACK(on_search_engine_dialog_response), sed);
145
gtk_widget_show_all (sed->priv->dialog);