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

« back to all changes in this revision

Viewing changes to src/ui/search_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
1
/**
2
2
 * @file search_dialog.c  Search engine subscription dialog
3
3
 *
4
 
 * Copyright (C) 2007-2009 Lars Lindner <lars.lindner@gmail.com>
 
4
 * Copyright (C) 2007-2011 Lars Lindner <lars.lindner@gmail.com>
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
7
 * it under the terms of the GNU General Public License as published by
31
31
#include "node_view.h"
32
32
#include "rule.h"
33
33
#include "vfolder.h"
 
34
#include "vfolder_loader.h"
 
35
#include "ui/item_list_view.h"
34
36
#include "ui/itemview.h"
35
37
#include "ui/liferea_dialog.h"
36
38
#include "ui/rule_editor.h"
37
 
#include "ui/ui_feedlist.h"
 
39
#include "ui/feed_list_view.h"
38
40
 
39
41
/* shared functions */
40
42
 
41
 
/** 
42
 
 * Loads a search result into the item list and renders
43
 
 * some info text into the HTML view pane.
44
 
 *
45
 
 * @param searchResult          valid search result node
46
 
 * @param searchString          search text (or NULL)
47
 
 */
48
43
static void
49
 
search_load_results (nodePtr searchResult, const gchar *searchString)
 
44
search_load_results (vfolderPtr searchResult)
50
45
{
51
 
        GString *buffer;
52
 
        itemSetPtr itemSet;
53
 
        nodeViewType viewMode;
54
 
        
55
 
        /* Clear feed and item display and load search results */
56
 
        ui_feedlist_select (NULL);
57
 
        itemlist_unload (FALSE);
58
 
        
59
 
        /* Ensure that we are in a useful viewing mode (3 paned) */
60
 
        viewMode = itemlist_get_view_mode ();
61
 
        if ((NODE_VIEW_MODE_NORMAL != viewMode) &&
62
 
            (NODE_VIEW_MODE_WIDE != viewMode))
63
 
                itemview_set_layout (NODE_VIEW_MODE_NORMAL);
 
46
        feed_list_view_select (NULL);
64
47
                
65
 
        itemSet = node_get_itemset (searchResult);
66
 
        itemlist_load_search_result (itemSet);
67
 
        itemset_free (itemSet);
68
 
 
69
 
        buffer = g_string_new (NULL);
70
 
        htmlview_start_output (buffer, NULL, TRUE, FALSE);
71
 
        g_string_append_printf (buffer, "<div class='content'><h2>");
72
 
        
73
 
        if (searchString)
74
 
                g_string_append_printf (buffer, ngettext("%d Search Result for \"%s\"", 
75
 
                                                         "%d Search Results for \"%s\"",
76
 
                                                         searchResult->itemCount),
77
 
                                        searchResult->itemCount, searchString);
78
 
        else 
79
 
                g_string_append_printf (buffer, ngettext("%d Search Result", 
80
 
                                                         "%d Search Results",
81
 
                                                         searchResult->itemCount),
82
 
                                        searchResult->itemCount);
83
 
                                        
84
 
        g_string_append_printf (buffer, "</h2><p>");
85
 
        g_string_append_printf (buffer, _("The item list now contains all items matching the "
86
 
                                        "specified search pattern. If you want to save this search "
87
 
                                        "result permanently you can click the \"Search Folder\" button in "
88
 
                                        "the search dialog and Liferea will add a search folder to your "
89
 
                                        "feed list."));
90
 
        g_string_append_printf (buffer, "</p></div>");
91
 
        htmlview_finish_output (buffer);
92
 
        itemview_display_info (buffer->str);
93
 
        g_string_free (buffer, TRUE);
 
48
        itemlist_add_search_result (vfolder_loader_new (searchResult->node));
94
49
}
95
50
 
96
51
/* complex search dialog */
97
52
 
98
53
static SearchDialog *search = NULL;
99
54
 
100
 
static void search_dialog_class_init    (SearchDialogClass *klass);
101
 
static void search_dialog_init          (SearchDialog *sd);
102
 
 
103
55
#define SEARCH_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), SEARCH_DIALOG_TYPE, SearchDialogPrivate))
104
56
 
105
57
struct SearchDialogPrivate {
106
58
        GtkWidget       *dialog;        /**< the dialog widget */
107
59
        RuleEditor      *re;            /**< search folder rule editor widget set */
108
60
 
109
 
        nodePtr         searchResult;   /**< FIXME: evil no nodePtr should be necessary here! */
110
61
        vfolderPtr      vfolder;        /**< temporary search folder representing the search result */
111
62
};
112
63
 
113
64
static GObjectClass *parent_class = NULL;
114
65
 
115
 
GType
116
 
search_dialog_get_type (void) 
117
 
{
118
 
        static GType type = 0;
119
 
 
120
 
        if (G_UNLIKELY (type == 0)) 
121
 
        {
122
 
                static const GTypeInfo our_info = 
123
 
                {
124
 
                        sizeof (SearchDialogClass),
125
 
                        NULL, /* base_init */
126
 
                        NULL, /* base_finalize */
127
 
                        (GClassInitFunc) search_dialog_class_init,
128
 
                        NULL,
129
 
                        NULL, /* class_data */
130
 
                        sizeof (SearchDialog),
131
 
                        0, /* n_preallocs */
132
 
                        (GInstanceInitFunc) search_dialog_init
133
 
                };
134
 
 
135
 
                type = g_type_register_static (G_TYPE_OBJECT,
136
 
                                               "SearchDialog",
137
 
                                               &our_info, 0);
138
 
        }
139
 
 
140
 
        return type;
141
 
}
 
66
G_DEFINE_TYPE (SearchDialog, search_dialog, G_TYPE_OBJECT);
142
67
 
143
68
static void
144
69
search_dialog_finalize (GObject *object)
146
71
        SearchDialog *sd = SEARCH_DIALOG (object);
147
72
        
148
73
        gtk_widget_destroy (sd->priv->dialog);
149
 
        if (sd->priv->searchResult)
150
 
                node_free (sd->priv->searchResult);
 
74
        if (sd->priv->vfolder)
 
75
                node_free (sd->priv->vfolder->node);
151
76
        search = NULL;
152
77
        
153
78
        G_OBJECT_CLASS (parent_class)->finalize (object);
169
94
search_dialog_init (SearchDialog *sd)
170
95
{
171
96
        sd->priv = SEARCH_DIALOG_GET_PRIVATE (sd);
172
 
        sd->priv->searchResult = node_new (vfolder_get_node_type ());
173
 
        sd->priv->vfolder = vfolder_new (sd->priv->searchResult);
174
 
        node_set_title (sd->priv->searchResult, "Saved Search");
 
97
        sd->priv->vfolder = vfolder_new (node_new (vfolder_get_node_type ()));
 
98
        node_set_title (sd->priv->vfolder->node, "Saved Search");
175
99
}
176
100
 
177
101
static void
178
102
on_search_dialog_response (GtkDialog *dialog, gint responseId, gpointer user_data)
179
103
{
180
104
        SearchDialog    *sd = (SearchDialog *)user_data;
 
105
        vfolderPtr      vfolder = sd->priv->vfolder;
181
106
        
182
107
        if (1 == responseId) { /* Search */
183
 
                rule_editor_save (sd->priv->re, sd->priv->vfolder);
184
 
                sd->priv->vfolder->anyMatch = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (sd->priv->dialog, "anyRuleRadioBtn2")));
 
108
                rule_editor_save (sd->priv->re, vfolder->itemset);
 
109
                vfolder->itemset->anyMatch = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (sd->priv->dialog, "anyRuleRadioBtn2")));
185
110
                
186
 
                vfolder_refresh (sd->priv->vfolder);
187
 
                search_load_results (sd->priv->searchResult, NULL);
 
111
                search_load_results (vfolder);
188
112
        }
189
113
        
190
114
        if (2 == responseId) { /* + Search Folder */
191
 
                rule_editor_save (sd->priv->re, sd->priv->vfolder);
192
 
                sd->priv->vfolder->anyMatch = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (sd->priv->dialog, "anyRuleRadioBtn2")));
 
115
                rule_editor_save (sd->priv->re, vfolder->itemset);
 
116
                vfolder->itemset->anyMatch = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (sd->priv->dialog, "anyRuleRadioBtn2")));
193
117
                
194
 
                nodePtr node = sd->priv->searchResult;
195
 
                sd->priv->searchResult = NULL;
 
118
                nodePtr node = vfolder->node;
196
119
                sd->priv->vfolder = NULL;
197
120
                feedlist_node_added (node);
198
121
        }
222
145
        sd->priv->dialog = liferea_dialog_new (NULL, "searchdialog");
223
146
        
224
147
        if (query)
225
 
                vfolder_add_rule (sd->priv->vfolder, "exact", query, TRUE);
 
148
                itemset_add_rule (sd->priv->vfolder->itemset, "exact", query, TRUE);
226
149
 
227
 
        sd->priv->re = rule_editor_new (sd->priv->vfolder);
 
150
        sd->priv->re = rule_editor_new (sd->priv->vfolder->itemset);
228
151
 
229
152
        /* Note: the following code is somewhat duplicated from search_folder_dialog.c */
230
153
        
248
171
 
249
172
static SimpleSearchDialog *simpleSearch = NULL;
250
173
 
251
 
static void simple_search_dialog_class_init     (SimpleSearchDialogClass *klass);
252
 
static void simple_search_dialog_init           (SimpleSearchDialog *ssd);
253
 
 
254
174
#define SIMPLE_SEARCH_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), SIMPLE_SEARCH_DIALOG_TYPE, SimpleSearchDialogPrivate))
255
175
 
256
176
struct SimpleSearchDialogPrivate {
257
177
        GtkWidget       *dialog;        /**< the dialog widget */
258
178
        GtkWidget       *query;         /**< entry widget for the search query */
259
179
 
260
 
        nodePtr         searchResult;   /**< FIXME: evil no nodePtr should be necessary here! */
261
180
        vfolderPtr      vfolder;        /**< temporary search folder representing the search result */
262
181
};
263
182
 
264
183
static GObjectClass *parent_class_simple = NULL;
265
184
 
266
 
GType
267
 
simple_search_dialog_get_type (void) 
268
 
{
269
 
        static GType type = 0;
270
 
 
271
 
        if (G_UNLIKELY (type == 0)) 
272
 
        {
273
 
                static const GTypeInfo our_info = 
274
 
                {
275
 
                        sizeof (SimpleSearchDialogClass),
276
 
                        NULL, /* base_init */
277
 
                        NULL, /* base_finalize */
278
 
                        (GClassInitFunc) simple_search_dialog_class_init,
279
 
                        NULL,
280
 
                        NULL, /* class_data */
281
 
                        sizeof (SimpleSearchDialog),
282
 
                        0, /* n_preallocs */
283
 
                        (GInstanceInitFunc) simple_search_dialog_init
284
 
                };
285
 
 
286
 
                type = g_type_register_static (G_TYPE_OBJECT,
287
 
                                               "SimpleSearchDialog",
288
 
                                               &our_info, 0);
289
 
        }
290
 
 
291
 
        return type;
292
 
}
 
185
G_DEFINE_TYPE (SimpleSearchDialog, simple_search_dialog, G_TYPE_OBJECT);
293
186
 
294
187
static void
295
188
simple_search_dialog_finalize (GObject *object)
298
191
        
299
192
        gtk_widget_destroy (ssd->priv->dialog);
300
193
        
301
 
        if (ssd->priv->searchResult)
302
 
                node_free (ssd->priv->searchResult);
 
194
        if (ssd->priv->vfolder)
 
195
                node_free (ssd->priv->vfolder->node);
303
196
                
304
197
        simpleSearch = NULL;
305
198
        
329
222
{
330
223
        SimpleSearchDialog      *ssd = (SimpleSearchDialog *)user_data;
331
224
        const gchar             *searchString;
 
225
        vfolderPtr              vfolder = ssd->priv->vfolder;
332
226
 
333
227
        searchString =  gtk_entry_get_text (GTK_ENTRY (ssd->priv->query));
334
228
        
335
229
        if (1 == responseId) {  /* Search */
336
230
                /* Clean up old search result data and display... */
337
 
                if (ssd->priv->searchResult) {
338
 
                        if (ssd->priv->searchResult == itemlist_get_displayed_node ())
 
231
                if (vfolder) {
 
232
                        if (vfolder->node == itemlist_get_displayed_node ())
339
233
                                itemlist_unload (FALSE);
340
234
                        
341
 
                        node_free (ssd->priv->searchResult);
 
235
                        node_free (vfolder->node);
342
236
                }
343
237
                
344
238
                /* Create new search... */
345
 
                ssd->priv->searchResult = node_new (vfolder_get_node_type ());
346
 
                ssd->priv->vfolder = vfolder_new (ssd->priv->searchResult);
347
 
        
348
 
                node_set_title (ssd->priv->searchResult, searchString);
349
 
                vfolder_add_rule (ssd->priv->vfolder, "exact", searchString, TRUE);
350
 
                vfolder_refresh (ssd->priv->vfolder);
 
239
                ssd->priv->vfolder = vfolder = vfolder_new (node_new (vfolder_get_node_type ()));
 
240
                node_set_title (vfolder->node, searchString);
 
241
                itemset_add_rule (vfolder->itemset, "exact", searchString, TRUE);
351
242
 
352
 
                search_load_results (ssd->priv->searchResult, searchString);
 
243
                search_load_results (vfolder);
353
244
        }
354
245
        
355
246
        if (2 == responseId)    /* Advanced... */