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

« back to all changes in this revision

Viewing changes to src/ui/ui_subscription.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 ui_subscription.c  default subscription dialogs for feed subscriptions
3
 
 *
4
 
 * Copyright (C) 2004-2009 Lars Lindner <lars.lindner@gmail.com>
5
 
 * Copyright (C) 2004-2006 Nathan J. Conrad <t98502@users.sourceforge.net>
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or modify
8
 
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; either version 2 of the License, or
10
 
 * (at your option) any later version.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 
 */
21
 
 
22
 
#include "ui/ui_subscription.h"
23
 
 
24
 
#include <libxml/uri.h>
25
 
#include <string.h> 
26
 
 
27
 
#include "common.h"
28
 
#include "conf.h"
29
 
#include "db.h"
30
 
#include "debug.h"
31
 
#include "feed.h"
32
 
#include "feedlist.h"
33
 
#include "node.h"
34
 
#include "update.h"
35
 
#include "ui/liferea_dialog.h"
36
 
#include "ui/ui_common.h"
37
 
#include "ui/ui_node.h"
38
 
 
39
 
/* Note: these update interval literals should be kept in sync with the 
40
 
   ones in ui_prefs.c! */
41
 
    
42
 
static gchar * default_update_interval_unit_options[] = {
43
 
        N_("minutes"),
44
 
        N_("hours"),
45
 
        N_("days"),
46
 
        NULL
47
 
};
48
 
 
49
 
/** common private structure for all subscription dialogs */
50
 
struct SubscriptionDialogPrivate {
51
 
 
52
 
        subscriptionPtr subscription;   /** used only for "properties" dialog */
53
 
 
54
 
        gint selector; /* Desiginates which fileselection dialog box is open.
55
 
                                   Set to 'u' for source
56
 
                                   Set to 'f' for filter */
57
 
                                   
58
 
        GtkWidget *dialog;
59
 
        GtkWidget *feedNameEntry;
60
 
        GtkWidget *refreshInterval;
61
 
        GtkWidget *refreshIntervalUnit;
62
 
        GtkWidget *sourceEntry;
63
 
        GtkWidget *selectFile;
64
 
        GtkWidget *fileRadio;
65
 
        GtkWidget *urlRadio;
66
 
        GtkWidget *cmdRadio;
67
 
        GtkWidget *authcheckbox;
68
 
        GtkWidget *credTable;
69
 
        GtkWidget *username;
70
 
        GtkWidget *password;    
71
 
};
72
 
 
73
 
/* properties dialog */
74
 
 
75
 
static void subscription_prop_dialog_class_init (SubscriptionPropDialogClass *klass);
76
 
static void subscription_prop_dialog_init       (SubscriptionPropDialog *spd);
77
 
 
78
 
#define SUBSCRIPTION_PROP_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), SUBSCRIPTION_PROP_DIALOG_TYPE, SubscriptionDialogPrivate))
79
 
 
80
 
static GObjectClass *parent_class = NULL;
81
 
 
82
 
GType
83
 
subscription_prop_dialog_get_type (void) 
84
 
{
85
 
        static GType type = 0;
86
 
 
87
 
        if (G_UNLIKELY (type == 0)) 
88
 
        {
89
 
                static const GTypeInfo our_info = 
90
 
                {
91
 
                        sizeof (SubscriptionPropDialogClass),
92
 
                        NULL, /* base_init */
93
 
                        NULL, /* base_finalize */
94
 
                        (GClassInitFunc) subscription_prop_dialog_class_init,
95
 
                        NULL,
96
 
                        NULL, /* class_data */
97
 
                        sizeof (SubscriptionPropDialog),
98
 
                        0, /* n_preallocs */
99
 
                        (GInstanceInitFunc) subscription_prop_dialog_init
100
 
                };
101
 
 
102
 
                type = g_type_register_static (G_TYPE_OBJECT,
103
 
                                               "SubscriptionPropDialog",
104
 
                                               &our_info, 0);
105
 
        }
106
 
 
107
 
        return type;
108
 
}
109
 
 
110
 
static void
111
 
subscription_prop_dialog_finalize (GObject *object)
112
 
{
113
 
        SubscriptionPropDialog *spd = SUBSCRIPTION_PROP_DIALOG (object);
114
 
 
115
 
        gtk_widget_destroy (spd->priv->dialog);
116
 
        
117
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
118
 
}
119
 
 
120
 
static void
121
 
subscription_prop_dialog_class_init (SubscriptionPropDialogClass *klass)
122
 
{
123
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
124
 
 
125
 
        parent_class = g_type_class_peek_parent (klass);
126
 
 
127
 
        object_class->finalize = subscription_prop_dialog_finalize;
128
 
 
129
 
        g_type_class_add_private (object_class, sizeof(SubscriptionDialogPrivate));
130
 
}
131
 
 
132
 
static gchar * 
133
 
ui_subscription_create_url (gchar *url,
134
 
                            gboolean auth, 
135
 
                            const gchar *username, 
136
 
                            const gchar *password) 
137
 
{
138
 
        gchar   *source = NULL;
139
 
        gchar *str, *tmp2;
140
 
        
141
 
        /* First, strip leading and trailing whitespace */
142
 
        str = g_strstrip(url);
143
 
 
144
 
        /* Add http:// if needed */
145
 
        if (strstr(str, "://") == NULL) {
146
 
                tmp2 = g_strdup_printf("http://%s",str);
147
 
                g_free(str);
148
 
                str = tmp2;
149
 
        }
150
 
 
151
 
        /* Add trailing / if needed */
152
 
        if (strstr(strstr(str, "://") + 3, "/") == NULL) {
153
 
                tmp2 = g_strdup_printf("%s/", str);
154
 
                g_free(str);
155
 
                str = tmp2;
156
 
        }
157
 
 
158
 
        /* Use the values in the textboxes if also specified in the URL! */
159
 
        if(auth) {
160
 
                xmlURIPtr uri = xmlParseURI(BAD_CAST str);
161
 
                if (uri != NULL) {
162
 
                        xmlChar *sourceUrl;
163
 
                        xmlFree(uri->user);
164
 
                        uri->user = g_strdup_printf("%s:%s", username, password);
165
 
                        sourceUrl = xmlSaveUri(uri);
166
 
                        source = g_strdup(sourceUrl);
167
 
                        g_free(uri->user);
168
 
                        uri->user = NULL;
169
 
                        xmlFree(sourceUrl);
170
 
                        xmlFreeURI(uri);
171
 
                } else
172
 
                        source = g_strdup(str);
173
 
        } else {
174
 
                source = g_strdup(str);
175
 
        }
176
 
        g_free(str);
177
 
        
178
 
        return source;
179
 
}
180
 
 
181
 
static gchar * 
182
 
ui_subscription_dialog_decode_source (SubscriptionDialogPrivate *ui_data) 
183
 
{
184
 
        gchar   *source = NULL;
185
 
 
186
 
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ui_data->fileRadio)))
187
 
                source = g_strdup (gtk_entry_get_text (GTK_ENTRY (ui_data->sourceEntry)));
188
 
                
189
 
        else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ui_data->urlRadio)))
190
 
                source = ui_subscription_create_url (g_strdup (gtk_entry_get_text (GTK_ENTRY (ui_data->sourceEntry))),
191
 
                                                     ui_data->authcheckbox &&
192
 
                                                     gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ui_data->authcheckbox)),
193
 
                                                     ui_data->username?gtk_entry_get_text (GTK_ENTRY (ui_data->username)):NULL,
194
 
                                                     ui_data->password?gtk_entry_get_text (GTK_ENTRY (ui_data->password)):NULL);
195
 
        else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ui_data->cmdRadio)))
196
 
                source = g_strdup_printf ("|%s", gtk_entry_get_text (GTK_ENTRY (ui_data->sourceEntry)));
197
 
 
198
 
        return source;
199
 
}
200
 
 
201
 
static void 
202
 
on_propdialog_response (GtkDialog *dialog,
203
 
                        gint response_id,
204
 
                        gpointer user_data) 
205
 
{
206
 
        SubscriptionPropDialog *spd = (SubscriptionPropDialog *)user_data;
207
 
        
208
 
        if(response_id == GTK_RESPONSE_OK) {
209
 
                gchar           *newSource;
210
 
                const gchar     *newFilter;
211
 
                gboolean        needsUpdate = FALSE;
212
 
                subscriptionPtr subscription = spd->priv->subscription;
213
 
                nodePtr         node = spd->priv->subscription->node;
214
 
                feedPtr         feed = (feedPtr)node->data;
215
 
                
216
 
                /* "General" */
217
 
                node_set_title(node, gtk_entry_get_text(GTK_ENTRY(spd->priv->feedNameEntry)));
218
 
                
219
 
                /* Source */
220
 
                newSource = ui_subscription_dialog_decode_source(spd->priv);
221
 
                
222
 
                /* Filter handling */
223
 
                newFilter = gtk_entry_get_text(GTK_ENTRY(liferea_dialog_lookup(spd->priv->dialog, "filterEntry")));
224
 
                if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "filterCheckbox"))) &&
225
 
                   strcmp(newFilter,"")) { /* Maybe this should be a test to see if the file exists? */
226
 
                        if(subscription_get_filter(subscription) == NULL ||
227
 
                           strcmp(newFilter, subscription_get_filter(subscription))) {
228
 
                                subscription_set_filter(subscription, newFilter);
229
 
                                needsUpdate = TRUE;
230
 
                        }
231
 
                } else {
232
 
                        if(subscription_get_filter(subscription)) {
233
 
                                subscription_set_filter(subscription, NULL);
234
 
                                needsUpdate = TRUE;
235
 
                        }
236
 
                }
237
 
                
238
 
                /* if URL has changed... */
239
 
                if(strcmp(newSource, subscription_get_source(subscription))) {
240
 
                        subscription_set_source(subscription, newSource);
241
 
                        needsUpdate = TRUE;
242
 
                }
243
 
                g_free(newSource);
244
 
 
245
 
                /* Update interval handling */
246
 
                if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (GTK_WIDGET (dialog), "updateIntervalNever"))))
247
 
                        subscription_set_update_interval (subscription, -2);
248
 
                else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (GTK_WIDGET (dialog), "updateIntervalDefault"))))
249
 
                        subscription_set_update_interval (subscription, -1);
250
 
                else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (GTK_WIDGET (dialog), "updateIntervalSpecific")))) {
251
 
                        gint intervalUnit = gtk_combo_box_get_active (GTK_COMBO_BOX (spd->priv->refreshIntervalUnit));
252
 
                        gint updateInterval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spd->priv->refreshInterval));
253
 
                        if (intervalUnit == 1)
254
 
                                updateInterval *= 60;   /* hours */
255
 
                        if (intervalUnit == 2)
256
 
                                updateInterval *= 1440; /* days */
257
 
                        
258
 
                        subscription_set_update_interval (subscription, updateInterval);
259
 
                        db_subscription_update (subscription);
260
 
                }
261
 
                        
262
 
                /* "Archive" handling */
263
 
                if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(GTK_WIDGET(dialog), "feedCacheDefault"))))
264
 
                        feed->cacheLimit = CACHE_DEFAULT;
265
 
                else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(GTK_WIDGET(dialog), "feedCacheDisable"))))
266
 
                        feed->cacheLimit = CACHE_DISABLE;
267
 
                else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(GTK_WIDGET(dialog), "feedCacheUnlimited"))))
268
 
                        feed->cacheLimit = CACHE_UNLIMITED;
269
 
                else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(GTK_WIDGET(dialog), "feedCacheLimited"))))
270
 
                        feed->cacheLimit = gtk_spin_button_get_value(GTK_SPIN_BUTTON(liferea_dialog_lookup(GTK_WIDGET(dialog), "cacheItemLimit")));
271
 
 
272
 
                /* "Download" Options */
273
 
                subscription->updateOptions->dontUseProxy = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(GTK_WIDGET(dialog), "dontUseProxyCheck")));
274
 
 
275
 
                /* "Advanced" options */
276
 
                feed->encAutoDownload = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (GTK_WIDGET (dialog), "enclosureDownloadCheck")));
277
 
                feed->loadItemLink = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (GTK_WIDGET (dialog), "loadItemLinkCheck")));
278
 
                feed->ignoreComments = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (GTK_WIDGET (dialog), "ignoreCommentFeeds")));
279
 
                feed->enforcePopup = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (GTK_WIDGET (dialog), "enforcePopupCheck")));
280
 
                feed->preventPopup = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (GTK_WIDGET (dialog), "preventPopupCheck")));
281
 
                feed->markAsRead = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (GTK_WIDGET (dialog), "markAsReadCheck")));
282
 
                
283
 
                if (feed->enforcePopup && feed->preventPopup)
284
 
                        feed->enforcePopup = FALSE;
285
 
 
286
 
                ui_node_update (node->id);
287
 
                feedlist_schedule_save ();
288
 
                db_subscription_update (subscription);
289
 
                if (needsUpdate)
290
 
                        subscription_update (subscription, FEED_REQ_PRIORITY_HIGH);
291
 
        }
292
 
 
293
 
        g_object_unref(spd);
294
 
}
295
 
 
296
 
static void
297
 
on_feed_prop_filtercheck (GtkToggleButton *button,
298
 
                          gpointer user_data) 
299
 
{
300
 
        SubscriptionDialogPrivate *ui_data = (SubscriptionDialogPrivate *)user_data;
301
 
        
302
 
        gboolean filter = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(ui_data->dialog, "filterCheckbox")));
303
 
        if(filter)
304
 
                gtk_widget_show(liferea_dialog_lookup(ui_data->dialog, "innerfiltervbox"));
305
 
        else
306
 
                gtk_widget_hide(liferea_dialog_lookup(ui_data->dialog, "innerfiltervbox"));
307
 
}
308
 
 
309
 
static void
310
 
ui_subscription_prop_enable_httpauth (SubscriptionDialogPrivate *ui_data,
311
 
                                      gboolean enable) 
312
 
{
313
 
        gboolean on;
314
 
 
315
 
        if(ui_data->authcheckbox) {
316
 
                on = enable && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui_data->authcheckbox));
317
 
                gtk_widget_set_sensitive(ui_data->authcheckbox,enable);
318
 
                gtk_widget_set_sensitive(ui_data->credTable,on);
319
 
        }
320
 
}
321
 
 
322
 
static void
323
 
on_feed_prop_authcheck (GtkToggleButton *button,
324
 
                        gpointer user_data) 
325
 
{
326
 
        SubscriptionDialogPrivate *ui_data = (SubscriptionDialogPrivate *)user_data;
327
 
        gboolean url = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui_data->urlRadio));
328
 
 
329
 
        ui_subscription_prop_enable_httpauth(ui_data, url);
330
 
}
331
 
 
332
 
static void
333
 
on_feed_prop_url_radio (GtkToggleButton *button,
334
 
                        gpointer user_data) 
335
 
{
336
 
        SubscriptionDialogPrivate *ui_data = (SubscriptionDialogPrivate *)user_data;
337
 
        gboolean url = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui_data->urlRadio));
338
 
        gboolean file = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui_data->fileRadio));
339
 
        gboolean cmd = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ui_data->cmdRadio));
340
 
        
341
 
        ui_subscription_prop_enable_httpauth(ui_data, url);
342
 
        gtk_widget_set_sensitive(ui_data->selectFile, file || cmd);
343
 
}
344
 
 
345
 
static void
346
 
on_selectfileok_clicked (const gchar *filename,
347
 
                         gpointer user_data) 
348
 
{
349
 
        SubscriptionDialogPrivate *ui_data = (SubscriptionDialogPrivate *)user_data;
350
 
        gchar *utfname;
351
 
        
352
 
        if (!filename)
353
 
                return;
354
 
        
355
 
        utfname = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
356
 
 
357
 
        if (utfname) {
358
 
                if (ui_data->selector == 'u')
359
 
                        gtk_entry_set_text (GTK_ENTRY (ui_data->sourceEntry), utfname);
360
 
                else
361
 
                        gtk_entry_set_text (GTK_ENTRY (liferea_dialog_lookup (ui_data->dialog, "filterEntry")), utfname);
362
 
        }
363
 
        
364
 
        g_free (utfname);
365
 
}
366
 
 
367
 
static void
368
 
on_selectfile_pressed (GtkButton *button,
369
 
                       gpointer user_data) 
370
 
{
371
 
        SubscriptionDialogPrivate *ui_data = (SubscriptionDialogPrivate *)user_data;
372
 
        const gchar *utfname;
373
 
        gchar *name;
374
 
 
375
 
        if (GTK_WIDGET (button) == ui_data->selectFile) {
376
 
                ui_data->selector = 'u';
377
 
                utfname = gtk_entry_get_text (GTK_ENTRY (ui_data->sourceEntry));
378
 
        } else {
379
 
                ui_data->selector = 'f';
380
 
                utfname = gtk_entry_get_text (GTK_ENTRY (liferea_dialog_lookup (ui_data->dialog, "filterEntry")));
381
 
        }
382
 
        
383
 
        name = g_filename_from_utf8 (utfname, -1, NULL, NULL, NULL);
384
 
        ui_choose_file (_("Choose File"), GTK_STOCK_OPEN, FALSE, on_selectfileok_clicked, name, NULL, ui_data);
385
 
        g_free (name);
386
 
}
387
 
 
388
 
static void
389
 
on_feed_prop_cache_radio (GtkToggleButton *button,
390
 
                          gpointer user_data) 
391
 
{
392
 
        SubscriptionDialogPrivate *ui_data = (SubscriptionDialogPrivate *)user_data;
393
 
        gboolean limited = gtk_toggle_button_get_active(button);
394
 
        
395
 
        gtk_widget_set_sensitive(liferea_dialog_lookup(GTK_WIDGET(ui_data->dialog), "cacheItemLimit"), limited);
396
 
}
397
 
 
398
 
static void
399
 
on_feed_prop_update_radio (GtkToggleButton *button,
400
 
                           gpointer user_data) 
401
 
{
402
 
        SubscriptionDialogPrivate *priv = (SubscriptionDialogPrivate *) user_data;
403
 
        gboolean limited = gtk_toggle_button_get_active (button);
404
 
        
405
 
        gtk_widget_set_sensitive (priv->refreshInterval, limited);
406
 
        gtk_widget_set_sensitive (priv->refreshIntervalUnit, limited);
407
 
}
408
 
 
409
 
static void
410
 
ui_subscription_prop_dialog_load (SubscriptionPropDialog *spd, 
411
 
                                  subscriptionPtr subscription) 
412
 
{
413
 
        gint            interval;
414
 
        gint            defaultInterval, spinSetInterval;
415
 
        gchar           *defaultIntervalStr;
416
 
        nodePtr         node = subscription->node;
417
 
        feedPtr         feed = (feedPtr)node->data;
418
 
 
419
 
        spd->priv->subscription = subscription;
420
 
 
421
 
        /* General */
422
 
        gtk_entry_set_text(GTK_ENTRY(spd->priv->feedNameEntry), node_get_title(node));
423
 
 
424
 
        spd->priv->refreshInterval = liferea_dialog_lookup(spd->priv->dialog,"refreshIntervalSpinButton");
425
 
        
426
 
        interval = subscription_get_update_interval(subscription);
427
 
        defaultInterval = subscription_get_default_update_interval(subscription);
428
 
        spinSetInterval = defaultInterval > 0 ? defaultInterval : conf_get_int_value (DEFAULT_UPDATE_INTERVAL);
429
 
        
430
 
        if (-2 >= interval) {
431
 
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup(spd->priv->dialog, "updateIntervalNever")), TRUE);
432
 
        } else if (-1 == interval) {
433
 
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup(spd->priv->dialog, "updateIntervalDefault")), TRUE);
434
 
        } else {
435
 
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup(spd->priv->dialog, "updateIntervalSpecific")), TRUE);
436
 
                spinSetInterval = interval;
437
 
        }
438
 
        
439
 
        /* Set refresh interval spin button and combo box */
440
 
        if (spinSetInterval % 1440 == 0) {      /* days */
441
 
                gtk_combo_box_set_active (GTK_COMBO_BOX (spd->priv->refreshIntervalUnit), 2);
442
 
                spinSetInterval /= 1440;
443
 
        } else if (spinSetInterval % 60 == 0) { /* hours */
444
 
                gtk_combo_box_set_active (GTK_COMBO_BOX (spd->priv->refreshIntervalUnit), 1);
445
 
                spinSetInterval /= 60;
446
 
        } else {
447
 
                gtk_combo_box_set_active (GTK_COMBO_BOX (spd->priv->refreshIntervalUnit), 0);
448
 
        }
449
 
        gtk_spin_button_set_value (GTK_SPIN_BUTTON (spd->priv->refreshInterval), spinSetInterval);
450
 
 
451
 
        gtk_widget_set_sensitive (spd->priv->refreshInterval, interval > 0);
452
 
        gtk_widget_set_sensitive (spd->priv->refreshIntervalUnit, interval > 0);
453
 
        
454
 
        /* setup info label about default update interval */
455
 
        if(-1 != defaultInterval)
456
 
                defaultIntervalStr = g_strdup_printf(ngettext("The provider of this feed suggests an update interval of %d minute.", 
457
 
                                                              "The provider of this feed suggests an update interval of %d minutes.",
458
 
                                                              defaultInterval), defaultInterval);
459
 
        else
460
 
                defaultIntervalStr = g_strdup(_("This feed specifies no default update interval."));
461
 
 
462
 
        gtk_label_set_text(GTK_LABEL(liferea_dialog_lookup(spd->priv->dialog, "feedUpdateInfo")), defaultIntervalStr);
463
 
        g_free(defaultIntervalStr);
464
 
 
465
 
        /* Source */
466
 
        if(subscription_get_source(subscription)[0] == '|') {
467
 
                gtk_entry_set_text(GTK_ENTRY(spd->priv->sourceEntry), &(subscription_get_source(subscription)[1]));
468
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(spd->priv->cmdRadio), TRUE);
469
 
                ui_subscription_prop_enable_httpauth(spd->priv, FALSE);
470
 
                gtk_widget_set_sensitive(spd->priv->selectFile, TRUE);
471
 
        } else if(strstr(subscription_get_source(subscription), "://") != NULL) {
472
 
                xmlURIPtr uri = xmlParseURI(BAD_CAST subscription_get_source(subscription));
473
 
                xmlChar *parsedUrl;
474
 
                if(uri) {
475
 
                        if(uri->user) {
476
 
                                gchar *user = uri->user;
477
 
                                gchar *pass = strstr(user, ":");
478
 
                                if(pass) {
479
 
                                        pass[0] = '\0';
480
 
                                        pass++;
481
 
                                        gtk_entry_set_text(GTK_ENTRY(spd->priv->password), pass);
482
 
                                }
483
 
                                gtk_entry_set_text(GTK_ENTRY(spd->priv->username), user);
484
 
                                xmlFree(uri->user);
485
 
                                uri->user = NULL;
486
 
                                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(spd->priv->authcheckbox), TRUE);
487
 
                        }
488
 
                        parsedUrl = xmlSaveUri(uri);
489
 
                        gtk_entry_set_text(GTK_ENTRY(spd->priv->sourceEntry), parsedUrl);
490
 
                        xmlFree(parsedUrl);
491
 
                        xmlFreeURI(uri);
492
 
                } else {
493
 
                        gtk_entry_set_text(GTK_ENTRY(spd->priv->sourceEntry), subscription_get_source(subscription));
494
 
                }
495
 
                ui_subscription_prop_enable_httpauth(spd->priv, TRUE);
496
 
                gtk_widget_set_sensitive(spd->priv->selectFile, FALSE);
497
 
        } else {
498
 
                /* File */
499
 
                gtk_entry_set_text(GTK_ENTRY(spd->priv->sourceEntry), subscription_get_source(subscription));
500
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(spd->priv->fileRadio), TRUE);
501
 
                ui_subscription_prop_enable_httpauth(spd->priv, FALSE);
502
 
                gtk_widget_set_sensitive(spd->priv->selectFile, TRUE);
503
 
        }
504
 
 
505
 
        if(subscription_get_filter(subscription)) {
506
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "filterCheckbox")), TRUE);
507
 
                gtk_entry_set_text(GTK_ENTRY(liferea_dialog_lookup(spd->priv->dialog, "filterEntry")), subscription_get_filter(subscription));
508
 
        }
509
 
 
510
 
        /* Archive */
511
 
        if(feed->cacheLimit == CACHE_DISABLE) {
512
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "feedCacheDisable")), TRUE);
513
 
        } else if(feed->cacheLimit == CACHE_DEFAULT) {
514
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "feedCacheDefault")), TRUE);
515
 
        } else if(feed->cacheLimit == CACHE_UNLIMITED) {
516
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "feedCacheUnlimited")), TRUE);
517
 
        } else {
518
 
                gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "feedCacheLimited")), TRUE);
519
 
                gtk_spin_button_set_value(GTK_SPIN_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "cacheItemLimit")), feed->cacheLimit);
520
 
        }
521
 
 
522
 
        gtk_widget_set_sensitive(liferea_dialog_lookup(spd->priv->dialog, "cacheItemLimit"), feed->cacheLimit > 0);
523
 
 
524
 
        on_feed_prop_filtercheck(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "filterCheckbox")), spd->priv);
525
 
        
526
 
        /* Download */
527
 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(liferea_dialog_lookup(spd->priv->dialog, "dontUseProxyCheck")), subscription->updateOptions->dontUseProxy);
528
 
 
529
 
        /* Advanced */  
530
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "enclosureDownloadCheck")), feed->encAutoDownload);
531
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "loadItemLinkCheck")), feed->loadItemLink);
532
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "ignoreCommentFeeds")), feed->ignoreComments);
533
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "enforcePopupCheck")), feed->enforcePopup);
534
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "preventPopupCheck")), feed->preventPopup);
535
 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (spd->priv->dialog, "markAsReadCheck")), feed->markAsRead);
536
 
 
537
 
}
538
 
 
539
 
static void
540
 
subscription_prop_dialog_init (SubscriptionPropDialog *spd)
541
 
{
542
 
        GtkWidget       *propdialog;
543
 
        
544
 
        spd->priv = SUBSCRIPTION_PROP_DIALOG_GET_PRIVATE (spd);
545
 
        spd->priv->dialog = propdialog = liferea_dialog_new (NULL, "propdialog");
546
 
 
547
 
        /* set default update interval spin button and unit combo box */
548
 
        ui_common_setup_combo_menu (liferea_dialog_lookup (propdialog, "refreshIntervalUnitComboBox"),
549
 
                                    default_update_interval_unit_options,
550
 
                                    NULL /* no callback */,
551
 
                                    -1 /* default value */ );   
552
 
 
553
 
        spd->priv->feedNameEntry = liferea_dialog_lookup (propdialog, "feedNameEntry");
554
 
        spd->priv->refreshInterval = liferea_dialog_lookup (propdialog, "refreshIntervalSpinButton");
555
 
        spd->priv->refreshIntervalUnit = liferea_dialog_lookup (propdialog, "refreshIntervalUnitComboBox");
556
 
        spd->priv->sourceEntry = liferea_dialog_lookup (propdialog, "sourceEntry");
557
 
        spd->priv->selectFile = liferea_dialog_lookup (propdialog, "selectSourceFileButton");
558
 
        spd->priv->fileRadio = liferea_dialog_lookup (propdialog, "feed_loc_file");
559
 
        spd->priv->urlRadio = liferea_dialog_lookup (propdialog, "feed_loc_url");
560
 
        spd->priv->cmdRadio = liferea_dialog_lookup (propdialog, "feed_loc_command");
561
 
 
562
 
        spd->priv->authcheckbox = liferea_dialog_lookup (propdialog, "HTTPauthCheck");
563
 
        spd->priv->username = liferea_dialog_lookup (propdialog, "usernameEntry");
564
 
        spd->priv->password = liferea_dialog_lookup (propdialog, "passwordEntry");
565
 
        spd->priv->credTable = liferea_dialog_lookup (propdialog, "table4");
566
 
        
567
 
        g_signal_connect (spd->priv->selectFile, "clicked", G_CALLBACK (on_selectfile_pressed), spd->priv);
568
 
        g_signal_connect (spd->priv->urlRadio, "toggled", G_CALLBACK (on_feed_prop_url_radio), spd->priv);
569
 
        g_signal_connect (spd->priv->fileRadio, "toggled", G_CALLBACK (on_feed_prop_url_radio), spd->priv);
570
 
        g_signal_connect (spd->priv->cmdRadio, "toggled", G_CALLBACK (on_feed_prop_url_radio), spd->priv);
571
 
        g_signal_connect (spd->priv->authcheckbox, "toggled", G_CALLBACK (on_feed_prop_authcheck), spd->priv);
572
 
 
573
 
        g_signal_connect (liferea_dialog_lookup (propdialog, "filterCheckbox"), "toggled", G_CALLBACK (on_feed_prop_filtercheck), spd->priv);
574
 
        g_signal_connect (liferea_dialog_lookup (propdialog, "filterSelectFile"), "clicked", G_CALLBACK (on_selectfile_pressed), spd->priv);
575
 
        g_signal_connect (liferea_dialog_lookup (propdialog, "feedCacheLimited"), "toggled", G_CALLBACK (on_feed_prop_cache_radio), spd->priv);
576
 
        g_signal_connect (liferea_dialog_lookup (propdialog, "updateIntervalSpecific"), "toggled", G_CALLBACK(on_feed_prop_update_radio), spd->priv);
577
 
        
578
 
        g_signal_connect (G_OBJECT (propdialog), "response", G_CALLBACK (on_propdialog_response), spd);
579
 
 
580
 
        gtk_widget_show_all (propdialog);
581
 
}
582
 
 
583
 
SubscriptionPropDialog *
584
 
ui_subscription_prop_dialog_new (subscriptionPtr subscription) 
585
 
{
586
 
        SubscriptionPropDialog *spd;
587
 
        
588
 
        spd = SUBSCRIPTION_PROP_DIALOG (g_object_new (SUBSCRIPTION_PROP_DIALOG_TYPE, NULL));
589
 
        ui_subscription_prop_dialog_load(spd, subscription);
590
 
        return spd;
591
 
}
592
 
 
593
 
/* complex "New" dialog */
594
 
 
595
 
static void new_subscription_dialog_class_init  (NewSubscriptionDialogClass *klass);
596
 
static void new_subscription_dialog_init        (NewSubscriptionDialog *ns);
597
 
 
598
 
#define NEW_SUBSCRIPTION_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), NEW_SUBSCRIPTION_DIALOG_TYPE, SubscriptionDialogPrivate))
599
 
 
600
 
GType
601
 
new_subscription_dialog_get_type (void) 
602
 
{
603
 
        static GType type = 0;
604
 
 
605
 
        if (G_UNLIKELY (type == 0)) 
606
 
        {
607
 
                static const GTypeInfo our_info = 
608
 
                {
609
 
                        sizeof (NewSubscriptionDialogClass),
610
 
                        NULL, /* base_init */
611
 
                        NULL, /* base_finalize */
612
 
                        (GClassInitFunc) new_subscription_dialog_class_init,
613
 
                        NULL,
614
 
                        NULL, /* class_data */
615
 
                        sizeof (NewSubscriptionDialog),
616
 
                        0, /* n_preallocs */
617
 
                        (GInstanceInitFunc) new_subscription_dialog_init
618
 
                };
619
 
 
620
 
                type = g_type_register_static (G_TYPE_OBJECT,
621
 
                                               "NewSubscriptionDialog",
622
 
                                               &our_info, 0);
623
 
        }
624
 
 
625
 
        return type;
626
 
}
627
 
 
628
 
static void
629
 
new_subscription_dialog_finalize (GObject *object)
630
 
{
631
 
        NewSubscriptionDialog *nsd = NEW_SUBSCRIPTION_DIALOG (object);
632
 
        
633
 
        gtk_widget_destroy (nsd->priv->dialog);
634
 
 
635
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
636
 
}
637
 
 
638
 
static void
639
 
new_subscription_dialog_class_init (NewSubscriptionDialogClass *klass)
640
 
{
641
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
642
 
 
643
 
        parent_class = g_type_class_peek_parent (klass);
644
 
 
645
 
        object_class->finalize = new_subscription_dialog_finalize;
646
 
 
647
 
        g_type_class_add_private (object_class, sizeof(SubscriptionDialogPrivate));
648
 
}
649
 
 
650
 
static void
651
 
on_newdialog_response (GtkDialog *dialog, gint response_id, gpointer user_data) 
652
 
{
653
 
        NewSubscriptionDialog *nsd = (NewSubscriptionDialog *)user_data;
654
 
        
655
 
        if (response_id == GTK_RESPONSE_OK) {
656
 
                gchar *source = NULL;
657
 
                const gchar *filter = NULL;
658
 
                updateOptionsPtr options;
659
 
 
660
 
                /* Source */
661
 
                source = ui_subscription_dialog_decode_source (nsd->priv);
662
 
 
663
 
                /* Filter handling */
664
 
                filter = gtk_entry_get_text (GTK_ENTRY (liferea_dialog_lookup (nsd->priv->dialog, "filterEntry")));
665
 
                if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (nsd->priv->dialog, "filterCheckbox"))) ||
666
 
                    !strcmp(filter,"")) { /* Maybe this should be a test to see if the file exists? */
667
 
                        filter = NULL;
668
 
                } 
669
 
                
670
 
                options = g_new0 (struct updateOptions, 1);
671
 
                options->dontUseProxy = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (liferea_dialog_lookup(GTK_WIDGET (dialog), "dontUseProxyCheck")));
672
 
                
673
 
                feedlist_add_subscription (source, filter, options,
674
 
                                           FEED_REQ_RESET_TITLE | 
675
 
                                           FEED_REQ_PRIORITY_HIGH);
676
 
                g_free (source);
677
 
        }
678
 
 
679
 
        g_object_unref (nsd);
680
 
}
681
 
 
682
 
static void
683
 
new_subscription_dialog_init (NewSubscriptionDialog *nsd)
684
 
{
685
 
        GtkWidget       *newdialog;
686
 
        
687
 
        nsd->priv = NEW_SUBSCRIPTION_DIALOG_GET_PRIVATE (nsd);
688
 
        nsd->priv->dialog = newdialog = liferea_dialog_new ("new_subscription.glade", "newdialog");
689
 
        
690
 
        /* Setup source entry */
691
 
        nsd->priv->sourceEntry = liferea_dialog_lookup (newdialog,"sourceEntry");
692
 
        gtk_widget_grab_focus (GTK_WIDGET (nsd->priv->sourceEntry));
693
 
        gtk_entry_set_activates_default (GTK_ENTRY (nsd->priv->sourceEntry), TRUE);
694
 
                
695
 
        nsd->priv->selectFile = liferea_dialog_lookup (newdialog,"selectSourceFileButton");
696
 
        g_signal_connect (nsd->priv->selectFile, "clicked", G_CALLBACK (on_selectfile_pressed), nsd->priv);
697
 
        
698
 
        /* Feed location radio buttons */
699
 
        nsd->priv->fileRadio = liferea_dialog_lookup (newdialog, "feed_loc_file");
700
 
        nsd->priv->urlRadio = liferea_dialog_lookup (newdialog, "feed_loc_url");
701
 
        nsd->priv->cmdRadio = liferea_dialog_lookup (newdialog, "feed_loc_command");
702
 
 
703
 
        g_signal_connect (nsd->priv->urlRadio, "toggled", G_CALLBACK (on_feed_prop_url_radio), nsd->priv);
704
 
        g_signal_connect (nsd->priv->fileRadio, "toggled", G_CALLBACK (on_feed_prop_url_radio), nsd->priv);
705
 
        g_signal_connect (nsd->priv->cmdRadio, "toggled", G_CALLBACK (on_feed_prop_url_radio), nsd->priv);
706
 
 
707
 
        g_signal_connect (liferea_dialog_lookup (newdialog, "filterCheckbox"), "toggled", G_CALLBACK (on_feed_prop_filtercheck), nsd->priv);
708
 
        g_signal_connect (liferea_dialog_lookup (newdialog, "filterSelectFile"), "clicked", G_CALLBACK (on_selectfile_pressed), nsd->priv);
709
 
 
710
 
        gtk_widget_grab_default (liferea_dialog_lookup (newdialog, "newfeedbtn"));
711
 
        g_signal_connect (G_OBJECT (newdialog), "response", G_CALLBACK (on_newdialog_response), nsd);
712
 
        
713
 
        on_feed_prop_filtercheck (GTK_TOGGLE_BUTTON (liferea_dialog_lookup (newdialog, "filterCheckbox")), nsd->priv);
714
 
        on_feed_prop_url_radio (GTK_TOGGLE_BUTTON (nsd->priv->urlRadio), nsd->priv);
715
 
        
716
 
        gtk_widget_show_all (newdialog);
717
 
}
718
 
 
719
 
NewSubscriptionDialog *
720
 
ui_complex_subscription_dialog_new (void) 
721
 
{
722
 
        NewSubscriptionDialog *nsd;
723
 
        
724
 
        nsd = NEW_SUBSCRIPTION_DIALOG (g_object_new (NEW_SUBSCRIPTION_DIALOG_TYPE, NULL));
725
 
        return nsd;
726
 
}
727
 
 
728
 
/* simple "New" dialog */
729
 
 
730
 
static void simple_subscription_dialog_class_init       (SimpleSubscriptionDialogClass *klass);
731
 
static void simple_subscription_dialog_init             (SimpleSubscriptionDialog *ssd);
732
 
 
733
 
#define SIMPLE_SUBSCRIPTION_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), SIMPLE_SUBSCRIPTION_DIALOG_TYPE, SubscriptionDialogPrivate))
734
 
 
735
 
GType
736
 
simple_subscription_dialog_get_type (void) 
737
 
{
738
 
        static GType type = 0;
739
 
 
740
 
        if (G_UNLIKELY (type == 0)) 
741
 
        {
742
 
                static const GTypeInfo our_info = 
743
 
                {
744
 
                        sizeof (SimpleSubscriptionDialogClass),
745
 
                        NULL, /* base_init */
746
 
                        NULL, /* base_finalize */
747
 
                        (GClassInitFunc) simple_subscription_dialog_class_init,
748
 
                        NULL,
749
 
                        NULL, /* class_data */
750
 
                        sizeof (SimpleSubscriptionDialog),
751
 
                        0, /* n_preallocs */
752
 
                        (GInstanceInitFunc) simple_subscription_dialog_init
753
 
                };
754
 
 
755
 
                type = g_type_register_static (G_TYPE_OBJECT,
756
 
                                               "SimpleSubscriptionDialog",
757
 
                                               &our_info, 0);
758
 
        }
759
 
 
760
 
        return type;
761
 
}
762
 
 
763
 
static void
764
 
simple_subscription_dialog_finalize (GObject *object)
765
 
{
766
 
        SimpleSubscriptionDialog *ssd = SIMPLE_SUBSCRIPTION_DIALOG (object);
767
 
        
768
 
        gtk_widget_destroy (ssd->priv->dialog);
769
 
 
770
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
771
 
}
772
 
 
773
 
static void
774
 
simple_subscription_dialog_class_init (SimpleSubscriptionDialogClass *klass)
775
 
{
776
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
777
 
 
778
 
        parent_class = g_type_class_peek_parent (klass);
779
 
 
780
 
        object_class->finalize = simple_subscription_dialog_finalize;
781
 
 
782
 
        g_type_class_add_private (object_class, sizeof (SubscriptionDialogPrivate));
783
 
}
784
 
 
785
 
static void
786
 
on_simple_newdialog_response (GtkDialog *dialog, gint response_id, gpointer user_data) 
787
 
{
788
 
        SimpleSubscriptionDialog *ssd = (SimpleSubscriptionDialog *)user_data;
789
 
        gchar *source = NULL;
790
 
        
791
 
        if (response_id == GTK_RESPONSE_OK) {
792
 
                source = ui_subscription_create_url (g_strdup (gtk_entry_get_text (GTK_ENTRY(ssd->priv->sourceEntry))),
793
 
                                                      FALSE /* auth */, NULL /* user */, NULL /* passwd */);
794
 
 
795
 
                feedlist_add_subscription (source, NULL, NULL,
796
 
                                           FEED_REQ_RESET_TITLE | 
797
 
                                           FEED_REQ_PRIORITY_HIGH);
798
 
                g_free (source);
799
 
        }
800
 
        
801
 
        if (response_id == GTK_RESPONSE_APPLY) /* misused for "Advanced" */
802
 
                ui_complex_subscription_dialog_new ();
803
 
                
804
 
        g_object_unref (ssd);
805
 
}
806
 
 
807
 
static void
808
 
simple_subscription_dialog_init (SimpleSubscriptionDialog *ssd)
809
 
{
810
 
        GtkWidget       *newdialog;
811
 
        
812
 
        ssd->priv = SIMPLE_SUBSCRIPTION_DIALOG_GET_PRIVATE (ssd);
813
 
        ssd->priv->dialog = newdialog = liferea_dialog_new ("simple_subscription.glade", "simplenewdialog");
814
 
        
815
 
        /* Setup source entry */
816
 
        ssd->priv->sourceEntry = liferea_dialog_lookup (newdialog, "sourceEntry");
817
 
        gtk_widget_grab_focus (GTK_WIDGET (ssd->priv->sourceEntry));
818
 
        gtk_entry_set_activates_default (GTK_ENTRY (ssd->priv->sourceEntry), TRUE);
819
 
 
820
 
        g_signal_connect (G_OBJECT (newdialog), "response",
821
 
                          G_CALLBACK (on_simple_newdialog_response), ssd);
822
 
        
823
 
        gtk_widget_show_all (newdialog);
824
 
}
825
 
 
826
 
SimpleSubscriptionDialog *
827
 
ui_subscription_dialog_new (void) 
828
 
{
829
 
        SimpleSubscriptionDialog *ssd;
830
 
        
831
 
        ssd = SIMPLE_SUBSCRIPTION_DIALOG (g_object_new (SIMPLE_SUBSCRIPTION_DIALOG_TYPE, NULL));
832
 
        return ssd;
833
 
}