~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/ui/search_engine_dialog.c

  • Committer: Package Import Robot
  • Author(s): bojo42
  • Date: 2012-03-29 14:17:21 UTC
  • mfrom: (1.3.9) (3.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20120329141721-tbfopcrc5797wxt7
Tags: 1.8.3-0.1ubuntu1
* New upstream release (LP: #290666, #371754, #741543, #716688)
* Merge from Debian unstable (LP: #935147), remaining changes:
* debian/patches:
  - drop gtk-status-icon.patch & notification-append as in upstream
  - drop fix_systray_behavior as mostly upstreamed and rest seems unused
  - 01_ubuntu_feedlists: update & rename, move planets to "Open Source"  
  - add_X-Ubuntu-Gettext-Domain: rebase
  - libunity.patch: rebase, apply before indicator patch (liferea_shell.c)
  - libindicate_increase_version.patch: exclude from libindicate.patch
  - deactivate libindicate.patch, seems partly upstreamed and needs rework
* debian/control: libindicate-dev, libindicate-gtk-dev & libunity-dev
* debian/liferea.indicate & liferea.install: ship indicator desktop file
* debian/rules: enable libindicate

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * @file search_engine_dialog.c  Search engine subscription dialog
3
 
 *
4
 
 * Copyright (C) 2007-2008 Lars Lindner <lars.lindner@gmail.com>
5
 
 *
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. 
10
 
 *
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.
15
 
 *
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
19
 
 */
20
 
 
21
 
#include "ui/search_engine_dialog.h"
22
 
 
23
 
#include "common.h"
24
 
#include "feed.h"
25
 
#include "feedlist.h"
26
 
#include "ui/liferea_dialog.h"
27
 
 
28
 
static void search_engine_dialog_class_init     (SearchEngineDialogClass *klass);
29
 
static void search_engine_dialog_init           (SearchEngineDialog *ld);
30
 
 
31
 
#define SEARCH_ENGINE_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), SEARCH_ENGINE_DIALOG_TYPE, SearchEngineDialogPrivate))
32
 
 
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 */
37
 
        
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 */
40
 
};
41
 
 
42
 
static GObjectClass *parent_class = NULL;
43
 
 
44
 
GType
45
 
search_engine_dialog_get_type (void) 
46
 
{
47
 
        static GType type = 0;
48
 
 
49
 
        if (G_UNLIKELY (type == 0)) 
50
 
        {
51
 
                static const GTypeInfo our_info = 
52
 
                {
53
 
                        sizeof (SearchEngineDialogClass),
54
 
                        NULL, /* base_init */
55
 
                        NULL, /* base_finalize */
56
 
                        (GClassInitFunc) search_engine_dialog_class_init,
57
 
                        NULL,
58
 
                        NULL, /* class_data */
59
 
                        sizeof (SearchEngineDialog),
60
 
                        0, /* n_preallocs */
61
 
                        (GInstanceInitFunc) search_engine_dialog_init
62
 
                };
63
 
 
64
 
                type = g_type_register_static (G_TYPE_OBJECT,
65
 
                                               "SearchEngineDialog",
66
 
                                               &our_info, 0);
67
 
        }
68
 
 
69
 
        return type;
70
 
}
71
 
 
72
 
static void
73
 
search_engine_dialog_finalize (GObject *object)
74
 
{
75
 
        SearchEngineDialog *sed = SEARCH_ENGINE_DIALOG (object);
76
 
        
77
 
        gtk_widget_destroy (sed->priv->dialog);
78
 
        
79
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
80
 
}
81
 
 
82
 
static void
83
 
search_engine_dialog_class_init (SearchEngineDialogClass *klass)
84
 
{
85
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
86
 
 
87
 
        parent_class = g_type_class_peek_parent (klass);
88
 
 
89
 
        object_class->finalize = search_engine_dialog_finalize;
90
 
 
91
 
        g_type_class_add_private (object_class, sizeof(SearchEngineDialogPrivate));
92
 
}
93
 
 
94
 
static void
95
 
search_engine_dialog_init (SearchEngineDialog *sed)
96
 
{
97
 
        sed->priv = SEARCH_ENGINE_DIALOG_GET_PRIVATE (sed);
98
 
}
99
 
 
100
 
static void
101
 
on_search_engine_dialog_response (GtkDialog *dialog, gint responseId, gpointer user_data)
102
 
{
103
 
        SearchEngineDialog      *sed = (SearchEngineDialog *)user_data;
104
 
        GtkAdjustment           *resultCountAdjust;
105
 
        gchar                   *searchtext, *searchUri;
106
 
        
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));
112
 
                else
113
 
                        searchUri = g_strdup_printf (sed->priv->uriFmt, searchtext);
114
 
 
115
 
                feedlist_add_subscription (searchUri, 
116
 
                                           NULL, 
117
 
                                           NULL,
118
 
                                           FEED_REQ_RESET_TITLE |
119
 
                                           FEED_REQ_PRIORITY_HIGH);
120
 
                g_free (searchUri);
121
 
                g_free (searchtext);
122
 
        }
123
 
        
124
 
        g_object_unref (sed);
125
 
}
126
 
 
127
 
SearchEngineDialog *
128
 
search_engine_dialog_new (const gchar *uriFmt, gboolean limitSupported)
129
 
{
130
 
        SearchEngineDialog      *sed;
131
 
 
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;
138
 
 
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);
142
 
        
143
 
        g_signal_connect (G_OBJECT (sed->priv->dialog), "response", G_CALLBACK(on_search_engine_dialog_response), sed);
144
 
        
145
 
        gtk_widget_show_all (sed->priv->dialog);
146
 
        
147
 
        return sed;
148
 
}