rss-config-factory.c 109 KB
Newer Older
Lucian Langa's avatar
Lucian Langa committed
1
/*  Evoution RSS Reader Plugin
Lucian Langa's avatar
Lucian Langa committed
2 3
 *  Copyright (C) 2007-2009 Lucian Langa <cooly@gnome.eu.org>
 *
Lucian Langa's avatar
Lucian Langa committed
4 5
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
Lucian Langa's avatar
Lucian Langa committed
6
 *  the Free Software Foundation; either version 2 of the License, or
Lucian Langa's avatar
Lucian Langa committed
7
 *  (at your option) any later version.
Lucian Langa's avatar
Lucian Langa committed
8
 *
Lucian Langa's avatar
Lucian Langa committed
9 10 11 12
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
Lucian Langa's avatar
Lucian Langa committed
13
 *
Lucian Langa's avatar
Lucian Langa committed
14 15
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
Lucian Langa's avatar
Lucian Langa committed
16 17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *  02110-1301 USA
Lucian Langa's avatar
Lucian Langa committed
18 19 20 21 22 23
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

24
#include <errno.h>
Lucian Langa's avatar
Lucian Langa committed
25 26
#include <string.h>
#include <stdio.h>
27
#include <glib.h>
28
#include <glib/gi18n-lib.h>
29
#include <gtk/gtk.h>
Lucian Langa's avatar
Lucian Langa committed
30
#if EVOLUTION_VERSION < 30304
31
#include <gconf/gconf-client.h>
Lucian Langa's avatar
Lucian Langa committed
32
#endif
33 34
#include <gdk/gdkkeysyms.h>

Lucian Langa's avatar
Lucian Langa committed
35 36 37
#if (DATASERVER_VERSION >= 2031001)
#include <camel/camel.h>
#else
38 39
#include <camel/camel-store.h>
#include <camel/camel-provider.h>
Lucian Langa's avatar
Lucian Langa committed
40
#endif
41 42 43

#include <mail/em-config.h>

44
#if EVOLUTION_VERSION <  30303
Lucian Langa's avatar
Lucian Langa committed
45
#include <mail/e-mail-local.h>
46
#endif
Lucian Langa's avatar
Lucian Langa committed
47

48
#include <mail/em-folder-selector.h>
49 50 51
#if EVOLUTION_VERSION >= 31102
#include <libemail-engine/libemail-engine.h>
#else
52 53 54
#if EVOLUTION_VERSION >= 30305
#include <libemail-engine/e-mail-folder-utils.h>
#else
Lucian Langa's avatar
Lucian Langa committed
55 56 57
#if EVOLUTION_VERSION >= 30101
#include <mail/e-mail-folder-utils.h>
#endif
58
#endif
59
#endif
Lucian Langa's avatar
Lucian Langa committed
60

61
#include <mail/em-utils.h>
Lucian Langa's avatar
Lucian Langa committed
62
#include <shell/e-shell.h>
63
#include <shell/e-shell-view.h>
Lucian Langa's avatar
Lucian Langa committed
64

Lucian Langa's avatar
Lucian Langa committed
65

66 67 68 69 70
#ifdef HAVE_LIBSOUP_GNOME
#include <libsoup/soup-gnome.h>
#include <libsoup/soup-gnome-features.h>
#endif

Lucian Langa's avatar
Lucian Langa committed
71 72
extern int rss_verbose_debug;

Lucian Langa's avatar
Lucian Langa committed
73
#include "rss.h"
74
#include "rss-formatter.h"
75 76
#include "misc.h"
#include "parser.h"
77
#include "rss-config.h"
78
#include "rss-config-factory.h"
79
#include "rss-evo-common.h"
80
#include "network-soup.h"
Lucian Langa's avatar
Lucian Langa committed
81
#include "notification.h"
82

83
GHashTable *tmphash = NULL;
84 85 86
static guint feed_enabled = 0;
static guint feed_validate = 0;
static guint feed_html = 0;
87
guint ccurrent = 0, ctotal = 0;
Lucian Langa's avatar
Lucian Langa committed
88 89
GList *flist = NULL;
gchar *strbuf;
Lucian Langa's avatar
Lucian Langa committed
90
GString *spacer = NULL;
Lucian Langa's avatar
Lucian Langa committed
91 92
GtkWidget *import_progress;
GtkWidget *import_dialog = NULL;
93

Lucian Langa's avatar
Lucian Langa committed
94
extern guint progress;
95 96
extern rssfeed *rf;
extern guint upgrade;
Lucian Langa's avatar
Lucian Langa committed
97
extern guint count;
98 99
extern gchar *buffer;
extern GSList *rss_list;
Lucian Langa's avatar
Lucian Langa committed
100
extern GHashTable *icons;
101
#if LIBSOUP_VERSION > 2024000
102
extern SoupCookieJar *rss_soup_jar;
103
#endif
104

Lucian Langa's avatar
Lucian Langa committed
105 106
#define RSS_CONTROL_ID  "OAFIID:GNOME_Evolution_RSS:" EVOLUTION_VERSION_STRING
#define FACTORY_ID      "OAFIID:GNOME_Evolution_RSS_Factory:" EVOLUTION_VERSION_STRING
107
#define MAX_TTL		10000
Lucian Langa's avatar
Lucian Langa committed
108

109
typedef struct {
110
	GtkBuilder  *xml;
111
	GtkWidget   *minfont;
112 113 114 115
	GtkWidget   *combobox;
	GtkWidget   *check;
	GtkWidget   *nettimeout;
	GtkWidget   *import;
116 117
} UIData;

Lucian Langa's avatar
Lucian Langa committed
118
void font_cb(GtkWidget *widget, GtkWidget *data);
Lucian Langa's avatar
Lucian Langa committed
119
static void feeds_dialog_edit(GtkDialog *d, gpointer data);
120
void decorate_import_cookies_fs (gpointer data);
121
gboolean store_redrawing = FALSE;
Lucian Langa's avatar
Lucian Langa committed
122 123 124

static void
set_sensitive (GtkCellLayout   *cell_layout,
125 126 127 128
		GtkCellRenderer *cell,
		GtkTreeModel    *tree_model,
		GtkTreeIter     *iter,
		gpointer         data)
Lucian Langa's avatar
Lucian Langa committed
129
{
130 131 132
	GtkTreePath *path;
	gint *indices;
	gboolean sensitive = 1;
Lucian Langa's avatar
Lucian Langa committed
133

134 135
	path = gtk_tree_model_get_path (tree_model, iter);
	indices = gtk_tree_path_get_indices (path);
Lucian Langa's avatar
Lucian Langa committed
136

137
	if (indices[0] == 1)
Lucian Langa's avatar
Lucian Langa committed
138
#ifdef HAVE_WEBKIT
139
		sensitive = 1;
Lucian Langa's avatar
Lucian Langa committed
140
#else
141
		sensitive = 0;
Lucian Langa's avatar
Lucian Langa committed
142 143
#endif

144
	if (indices[0] == 2)
145
#ifdef HAVE_GECKO
146
		sensitive = 1;
Lucian Langa's avatar
Lucian Langa committed
147
#else
148
		sensitive = 0;
Lucian Langa's avatar
Lucian Langa committed
149 150
#endif

151 152
	gtk_tree_path_free (path);
	g_object_set (cell, "sensitive", sensitive, NULL);
Lucian Langa's avatar
Lucian Langa committed
153 154 155
}

static struct {
156 157
	const char *label;
	const int key;
Lucian Langa's avatar
Lucian Langa committed
158
} engines[] = {
159 160 161
	{ N_("GtkHTML"), 0 },
	{ N_("WebKit"), 1 },
	{ N_("Mozilla"), 2 },
Lucian Langa's avatar
Lucian Langa committed
162 163 164 165 166
};

static void
render_engine_changed (GtkComboBox *dropdown, GCallback *user_data)
{
167 168 169
	int id = gtk_combo_box_get_active (dropdown);
	GtkTreeModel *model;
	GtkTreeIter iter;
Lucian Langa's avatar
Lucian Langa committed
170 171 172 173 174
#if EVOLUTION_VERSION < 30304
	GConfClient *client = gconf_client_get_default();
#else
	GSettings *settings = g_settings_new(RSS_CONF_SCHEMA);
#endif
Lucian Langa's avatar
Lucian Langa committed
175

176 177 178 179
	model = gtk_combo_box_get_model (dropdown);
	if (id == -1 || !gtk_tree_model_iter_nth_child (model, &iter, NULL, id))
		return;
	if (!id) id = 10;
180

Lucian Langa's avatar
Lucian Langa committed
181
#if EVOLUTION_VERSION < 30304
182
	gconf_client_set_int(client, GCONF_KEY_HTML_RENDER, id, NULL);
Lucian Langa's avatar
Lucian Langa committed
183 184 185
#else
	g_settings_set_int(settings, CONF_HTML_RENDER, id);
#endif
186
#ifdef HAVE_GECKO
187 188
	if (id == 2)
		rss_mozilla_init();
Lucian Langa's avatar
Lucian Langa committed
189
#endif
Lucian Langa's avatar
Lucian Langa committed
190
#if EVOLUTION_VERSION < 30304
191
	g_object_unref(client);
Lucian Langa's avatar
Lucian Langa committed
192 193 194
#else
	g_object_unref(settings);
#endif
Lucian Langa's avatar
Lucian Langa committed
195 196
}

197
static void
198
start_check_cb(GtkWidget *widget, gpointer data)
199
{
Lucian Langa's avatar
Lucian Langa committed
200 201
#if EVOLUTION_VERSION < 30304
	GConfClient *client = gconf_client_get_default();
202 203
	gboolean active = gtk_toggle_button_get_active (
				GTK_TOGGLE_BUTTON (widget));
204
	/* Save the new setting to gconf */
205 206
	gconf_client_set_bool (client, data, active, NULL);
	g_object_unref(client);
Lucian Langa's avatar
Lucian Langa committed
207 208 209 210 211 212 213 214
#else
	GSettings *settings = g_settings_new(RSS_CONF_SCHEMA);
	gboolean active = gtk_toggle_button_get_active (
				GTK_TOGGLE_BUTTON (widget));
	/* Save the new setting */
	g_settings_set_boolean (settings, data, active);
	g_object_unref(settings);
#endif
215 216
}

217 218 219
void
accept_cookies_cb(GtkWidget *widget, GtkWidget *data)
{
Lucian Langa's avatar
Lucian Langa committed
220 221
#if EVOLUTION_VERSION < 30304
	GConfClient *client = gconf_client_get_default();
222 223
	gboolean active = gtk_toggle_button_get_active (
				GTK_TOGGLE_BUTTON (widget));
224
	/* Save the new setting to gconf */
225
	gconf_client_set_bool (
226
		client,
227
		GCONF_KEY_ACCEPT_COOKIES, active, NULL);
228
	gtk_widget_set_sensitive(data, active);
229
	g_object_unref(client);
Lucian Langa's avatar
Lucian Langa committed
230 231 232 233 234 235 236 237 238
#else
	GSettings *settings = g_settings_new(RSS_CONF_SCHEMA);
	gboolean active = gtk_toggle_button_get_active (
				GTK_TOGGLE_BUTTON (widget));
	/* Save the new setting */
	g_settings_set_boolean (settings, CONF_ACCEPT_COOKIES, active);
	gtk_widget_set_sensitive(data, active);
	g_object_unref(settings);
#endif
239 240
}

Lucian Langa's avatar
Lucian Langa committed
241 242
static void
enable_toggle_cb(GtkCellRendererToggle *cell,
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
		gchar *path_str,
		gpointer data)
{
	GtkTreeModel *model = (GtkTreeModel *)data;
	GtkTreeIter  iter;
	GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
	gchar *name;
	gboolean fixed;

	g_print("enable_toggle_cb()\n");
	gtk_tree_model_get_iter (model, &iter, path);
	gtk_tree_model_get (model, &iter, 0, &fixed, -1);
	gtk_tree_model_get (model, &iter, 3, &name, -1);
	fixed ^= 1;
	g_hash_table_replace(rf->hre,
		g_strdup(lookup_key(name)),
		GINT_TO_POINTER(fixed));
	gtk_list_store_set (
		GTK_LIST_STORE (model),
		&iter,
		0,
		fixed,
		-1);
	gtk_tree_path_free (path);
	save_gconf_feed();
	g_free(name);
Lucian Langa's avatar
Lucian Langa committed
269 270 271 272 273
}


static void
treeview_row_activated(GtkTreeView *treeview,
274 275
			GtkTreePath *path,
			GtkTreeViewColumn *column)
Lucian Langa's avatar
Lucian Langa committed
276
{
277
	feeds_dialog_edit((GtkDialog *)treeview, treeview);
Lucian Langa's avatar
Lucian Langa committed
278 279 280 281 282
}

static void
rep_check_cb (GtkWidget *widget, gpointer data)
{
Lucian Langa's avatar
Lucian Langa committed
283 284 285 286 287
#if EVOLUTION_VERSION < 30304
	GConfClient *client = gconf_client_get_default();
#else
	GSettings *settings = g_settings_new(RSS_CONF_SCHEMA);
#endif
Lucian Langa's avatar
Lucian Langa committed
288
	gboolean active =
289 290
		gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
	/* Save the new setting to gconf */
Lucian Langa's avatar
Lucian Langa committed
291
#if EVOLUTION_VERSION < 30304
292
	gconf_client_set_bool (client,
Lucian Langa's avatar
Lucian Langa committed
293 294 295 296 297
		GCONF_KEY_REP_CHECK, active, NULL);
#else
	g_settings_set_boolean (settings,
		CONF_REP_CHECK, active);
#endif
298 299 300
	//if we already have a timeout set destroy it first
	if (rf->rc_id && !active)
		g_source_remove(rf->rc_id);
301
	if (active) {
302 303
			gtk_spin_button_update((GtkSpinButton *)data);
			//we have to make sure we have a timeout value
Lucian Langa's avatar
Lucian Langa committed
304
#if EVOLUTION_VERSION < 30304
305 306
			if (!gconf_client_get_float(client, GCONF_KEY_REP_CHECK_TIMEOUT, NULL))
				gconf_client_set_float (client,
307 308 309
					GCONF_KEY_REP_CHECK_TIMEOUT,
					gtk_spin_button_get_value((GtkSpinButton *)data),
					NULL);
Lucian Langa's avatar
Lucian Langa committed
310 311 312 313 314 315
#else
			if (!g_settings_get_double(settings, CONF_REP_CHECK_TIMEOUT))
				g_settings_set_double (settings,
					CONF_REP_CHECK_TIMEOUT,
					gtk_spin_button_get_value((GtkSpinButton *)data));
#endif
316 317 318 319
		if (rf->rc_id)
			g_source_remove(rf->rc_id);
		rf->rc_id = g_timeout_add (
				60 * 1000 * gtk_spin_button_get_value((GtkSpinButton *)data),
Lucian Langa's avatar
Lucian Langa committed
320
				(GSourceFunc) update_articles,
321
				(gpointer)1);
322
	}
Lucian Langa's avatar
Lucian Langa committed
323
#if EVOLUTION_VERSION < 30304
324
	g_object_unref(client);
Lucian Langa's avatar
Lucian Langa committed
325 326 327
#else
	g_object_unref(settings);
#endif
328 329 330 331 332
}

static void
enclosure_limit_cb (GtkWidget *widget, gpointer data)
{
Lucian Langa's avatar
Lucian Langa committed
333 334 335 336 337
#if EVOLUTION_VERSION < 30304
	GConfClient *client = gconf_client_get_default();
#else
	GSettings *settings = g_settings_new(RSS_CONF_SCHEMA);
#endif
338 339 340
	gboolean active =
		gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
	/* Save the new setting to gconf */
Lucian Langa's avatar
Lucian Langa committed
341
#if EVOLUTION_VERSION < 30304
342
	gconf_client_set_bool (client,
343 344 345
		GCONF_KEY_ENCLOSURE_LIMIT,
		active,
		NULL);
Lucian Langa's avatar
Lucian Langa committed
346 347 348
#else
	g_settings_set_boolean (settings, CONF_ENCLOSURE_LIMIT, active);
#endif
349 350
	if (active) {
		//we have to make sure we have a timeout value
Lucian Langa's avatar
Lucian Langa committed
351
#if EVOLUTION_VERSION < 30304
352 353
		if (!gconf_client_get_float(client, GCONF_KEY_ENCLOSURE_SIZE, NULL))
				gconf_client_set_float (client,
354 355 356
					GCONF_KEY_ENCLOSURE_SIZE,
					gtk_spin_button_get_value((GtkSpinButton *)data),
					NULL);
Lucian Langa's avatar
Lucian Langa committed
357 358 359 360 361 362
#else
		if (!g_settings_get_double(settings, CONF_ENCLOSURE_SIZE))
				g_settings_set_double (settings,
					CONF_ENCLOSURE_SIZE,
					gtk_spin_button_get_value((GtkSpinButton *)data));
#endif
363
	}
Lucian Langa's avatar
Lucian Langa committed
364
#if EVOLUTION_VERSION < 30304
365
	g_object_unref(client);
Lucian Langa's avatar
Lucian Langa committed
366 367 368
#else
	g_object_unref(settings);
#endif
369 370 371 372 373
}

static void
enclosure_size_cb (GtkWidget *widget, gpointer data)
{
Lucian Langa's avatar
Lucian Langa committed
374
#if EVOLUTION_VERSION < 30304
375 376
	GConfClient *client = gconf_client_get_default();
	gconf_client_set_float (client,
377 378 379
		GCONF_KEY_ENCLOSURE_SIZE,
		gtk_spin_button_get_value((GtkSpinButton*)widget),
		NULL);
380
	g_object_unref(client);
Lucian Langa's avatar
Lucian Langa committed
381 382 383 384 385 386
#else
	GSettings *settings = g_settings_new(RSS_CONF_SCHEMA);
	g_settings_set_double (settings, CONF_ENCLOSURE_SIZE,
		gtk_spin_button_get_value((GtkSpinButton*)widget));
	g_object_unref(settings);
#endif
Lucian Langa's avatar
Lucian Langa committed
387 388 389 390 391
}

static void
rep_check_timeout_cb (GtkWidget *widget, gpointer data)
{
Lucian Langa's avatar
Lucian Langa committed
392
#if EVOLUTION_VERSION < 30304
393
	GConfClient *client = gconf_client_get_default();
Lucian Langa's avatar
Lucian Langa committed
394 395 396
#else
	GSettings *settings = g_settings_new(RSS_CONF_SCHEMA);
#endif
397
	gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (data));
Lucian Langa's avatar
Lucian Langa committed
398
#if EVOLUTION_VERSION < 30304
399
	gconf_client_set_float (client,
400 401 402
		GCONF_KEY_REP_CHECK_TIMEOUT,
		gtk_spin_button_get_value((GtkSpinButton*)widget),
		NULL);
Lucian Langa's avatar
Lucian Langa committed
403 404 405 406
#else
	g_settings_set_double (settings, CONF_REP_CHECK_TIMEOUT,
		gtk_spin_button_get_value((GtkSpinButton*)widget));
#endif
407 408 409 410 411
	if (active) {
		if (rf->rc_id)
			g_source_remove(rf->rc_id);
		rf->rc_id = g_timeout_add (
			60 * 1000 * gtk_spin_button_get_value((GtkSpinButton *)widget),
Lucian Langa's avatar
Lucian Langa committed
412
			(GSourceFunc) update_articles,
413 414
			(gpointer)1);
	}
Lucian Langa's avatar
Lucian Langa committed
415
#if EVOLUTION_VERSION < 30304
416
	g_object_unref(client);
Lucian Langa's avatar
Lucian Langa committed
417 418 419
#else
	g_object_unref(settings);
#endif
Lucian Langa's avatar
Lucian Langa committed
420 421 422 423 424
}

static void
construct_list(gpointer key, gpointer value, gpointer user_data)
{
425 426
	GtkListStore  *store = user_data;
	GtkTreeIter    iter;
427
	gchar *full_name, *name, *full_path;
Lucian Langa's avatar
Lucian Langa committed
428

429
	gchar *tip = g_markup_escape_text(key, strlen(key));
430
	gtk_list_store_append (store, &iter);
Lucian Langa's avatar
Lucian Langa committed
431
	full_name = lookup_feed_folder_raw(key);
432
	name = g_path_get_basename(full_name);
433
	full_path = g_build_filename(
434 435 436 437 438 439 440
			lookup_main_folder(),
			full_name,
			NULL);
	gtk_list_store_set (
		store,
		&iter,
		0, g_hash_table_lookup(rf->hre, lookup_key(key)),
441
		1, name,
442
		2, g_hash_table_lookup(rf->hrt, lookup_key(key)),
443
		3, tip,
444
		4, full_path,
445
		-1);
446
	g_free(name);
447
	g_free(full_path);
Lucian Langa's avatar
Lucian Langa committed
448
	g_free(full_name);
Lucian Langa's avatar
Lucian Langa committed
449 450
}

451 452 453
static void
ttl_multiply_cb (GtkWidget *widget, add_feed *data)
{
454
	guint active = gtk_combo_box_get_active((GtkComboBox*)widget);
455 456 457
	data->ttl_multiply = active;
}

Lucian Langa's avatar
Lucian Langa committed
458 459 460
static void
ttl_cb (GtkWidget *widget, add_feed *data)
{
461 462
	guint adj = gtk_spin_button_get_value((GtkSpinButton*)widget);
	data->ttl = adj;
Lucian Langa's avatar
Lucian Langa committed
463 464
}

465
void
Lucian Langa's avatar
Lucian Langa committed
466 467
del_days_cb (GtkWidget *widget, add_feed *data)
{
468 469
	guint adj = gtk_spin_button_get_value((GtkSpinButton*)widget);
	data->del_days = adj;
Lucian Langa's avatar
Lucian Langa committed
470 471
}

472 473 474 475 476 477 478 479
void
update_days_label_cb (GtkWidget *widget, GtkLabel *data)
{
	guint val = gtk_spin_button_get_value((GtkSpinButton*)widget);
	gtk_label_set_text(data,
		ngettext("day", "days", val));
}

480
void
Lucian Langa's avatar
Lucian Langa committed
481 482
del_messages_cb (GtkWidget *widget, add_feed *data)
{
483 484
	guint adj = gtk_spin_button_get_value((GtkSpinButton*)widget);
	data->del_messages = adj;
Lucian Langa's avatar
Lucian Langa committed
485 486
}

487 488 489 490 491 492 493 494
void
update_messages_label_cb (GtkWidget *widget, GtkLabel *data)
{
	guint val = gtk_spin_button_get_value((GtkSpinButton*)widget);
	gtk_label_set_text(data,
		ngettext("message", "messages", val));
}

495
void
Lucian Langa's avatar
Lucian Langa committed
496
disable_widget_cb(GtkWidget *widget, GtkBuilder *data)
497
{
Lucian Langa's avatar
Lucian Langa committed
498 499 500
	GtkWidget *authuser = GTK_WIDGET (gtk_builder_get_object(data, "auth_user"));
	GtkWidget *authpass = GTK_WIDGET (gtk_builder_get_object(data, "auth_pass"));
	GtkToggleButton *useauth = (GtkToggleButton*)gtk_builder_get_object(data, "use_auth");
501 502 503 504 505
	gboolean auth_enabled = gtk_toggle_button_get_active(useauth);

	gtk_widget_set_sensitive(authuser, auth_enabled);
	gtk_widget_set_sensitive(authpass, auth_enabled);
}
506

507 508 509 510 511 512 513 514
void
folder_cb (GtkWidget *widget, gpointer data);

void
folder_cb (GtkWidget *widget, gpointer data)
{
	EMailBackend *backend;
	EMailSession *session;
515
	EShellView *shell_view;
Lucian Langa's avatar
Lucian Langa committed
516
#if EVOLUTION_VERSION >= 30101
Lucian Langa's avatar
Lucian Langa committed
517 518
	CamelStore *store = NULL;
	gchar *folder_name = NULL;
Lucian Langa's avatar
Lucian Langa committed
519 520
	const gchar *folderinfo;
#else
521
	CamelFolderInfo *folderinfo;
Lucian Langa's avatar
Lucian Langa committed
522
#endif
523 524 525 526
	GtkWidget *dialog;
	GtkWindow *window;
	const gchar *uri;
	struct _copy_folder_data *cfd;
Lucian Langa's avatar
Lucian Langa committed
527
#if EVOLUTION_VERSION >= 30101
Lucian Langa's avatar
Lucian Langa committed
528
	GError *error = NULL;
529 530
	EMFolderSelector *selector;
	EMFolderTree *folder_tree;
Lucian Langa's avatar
Lucian Langa committed
531
#if EVOLUTION_VERSION >= 30105
532 533
	EMFolderTreeModel *model;
#endif
534 535
#else
	GtkWidget *folder_tree;
Lucian Langa's avatar
Lucian Langa committed
536
#endif
537 538 539 540 541 542

	EMailReader *reader;
	EShellContent *shell_content;

	gchar *text = (gchar *)gtk_label_get_text(GTK_LABEL(data));

543 544
	shell_view = rss_get_mail_shell_view (TRUE);
	shell_content = e_shell_view_get_shell_content (shell_view);
545 546 547 548 549 550 551
	reader = E_MAIL_READER (shell_content);
	backend = e_mail_reader_get_backend (reader);

	session = e_mail_backend_get_session (backend);

	window = e_mail_reader_get_window (reader);

Lucian Langa's avatar
Lucian Langa committed
552
#if EVOLUTION_VERSION >= 30105
553 554
	model = em_folder_tree_model_get_default ();
#endif
555
#if EVOLUTION_VERSION >= 30303
556 557 558 559 560 561
#if EVOLUTION_VERSION >= 31301
	dialog = em_folder_selector_new (window, model);
	em_folder_selector_set_can_create (EM_FOLDER_SELECTOR (dialog), TRUE);
	em_folder_selector_set_caption (EM_FOLDER_SELECTOR (dialog), _("Move to Folder"));
	em_folder_selector_set_default_button_label (EM_FOLDER_SELECTOR (dialog), _("M_ove"));
#else
562 563 564 565 566
	dialog = em_folder_selector_new (
			window,
			model,
			EM_FOLDER_SELECTOR_CAN_CREATE,
			_("Move to Folder"), NULL, _("M_ove"));
567
#endif
568
#else
569 570 571 572
	dialog = em_folder_selector_new (
			window,
#if EVOLUTION_VERSION >= 30101
			backend,
Lucian Langa's avatar
Lucian Langa committed
573
#if EVOLUTION_VERSION >= 30105
574 575
			model,
#endif
576 577 578 579 580
#else
			EM_FOLDER_TREE (folder_tree),
#endif
			EM_FOLDER_SELECTOR_CAN_CREATE,
			_("Move to Folder"), NULL, _("M_ove"));
581
#endif
582 583 584 585 586

#if EVOLUTION_VERSION >= 30101
	selector = EM_FOLDER_SELECTOR (dialog);
	folder_tree = em_folder_selector_get_folder_tree (selector);
#else
587 588
	folder_tree = em_folder_tree_new (session);
	emu_restore_folder_tree_state (EM_FOLDER_TREE (folder_tree));
589
#endif
590 591

	em_folder_tree_set_excluded (
592 593 594 595 596
#if EVOLUTION_VERSION >= 30101
		folder_tree,
		EMFT_EXCLUDE_NOSELECT |
		EMFT_EXCLUDE_VIRTUAL |
#else
597 598
		EM_FOLDER_TREE (folder_tree),
		EMFT_EXCLUDE_NOSELECT | EMFT_EXCLUDE_VIRTUAL |
599
#endif
600 601 602
		EMFT_EXCLUDE_VTRASH);

	if ((uri = lookup_uri_by_folder_name(text)))
603 604 605 606
#if EVOLUTION_VERSION >= 30101
		em_folder_tree_set_selected (
			folder_tree, uri, FALSE);
#else
607 608 609
		em_folder_selector_set_selected (
			EM_FOLDER_SELECTOR (dialog),
			uri);
610
#endif
611

Lucian Langa's avatar
Lucian Langa committed
612 613 614
#if EVOLUTION_VERSION >= 30101
	folderinfo = em_folder_tree_get_selected_uri ((EMFolderTree *)folder_tree);
#else
615
	folderinfo = em_folder_tree_get_selected_folder_info ((EMFolderTree *)folder_tree);
Lucian Langa's avatar
Lucian Langa committed
616
#endif
617 618

	cfd = g_malloc (sizeof (*cfd));
Lucian Langa's avatar
Lucian Langa committed
619
#if EVOLUTION_VERSION < 30101
620
	cfd->fi = folderinfo;
Lucian Langa's avatar
Lucian Langa committed
621
#endif
622 623
	cfd->delete = 1;

Lucian Langa's avatar
Lucian Langa committed
624
#if EVOLUTION_VERSION >= 30101
Lucian Langa's avatar
Lucian Langa committed
625
	e_mail_folder_uri_parse (
Lucian Langa's avatar
Lucian Langa committed
626 627 628 629 630 631 632 633 634 635
		CAMEL_SESSION (session), folderinfo,
		&cfd->source_store, &cfd->source_folder_name, &error);

	if (error != NULL) {
		g_warning ("%s", error->message);
		g_error_free (error);
		g_free (cfd);
		return;
	}
#endif
Lucian Langa's avatar
Lucian Langa committed
636

637 638 639 640 641 642
	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
		gchar *tmp;
		gchar *name = g_path_get_basename(text);
		uri = em_folder_selector_get_selected_uri (
			EM_FOLDER_SELECTOR (dialog));
		rss_emfu_copy_folder_selected (backend, uri, cfd);
Lucian Langa's avatar
Lucian Langa committed
643 644 645 646 647
#if EVOLUTION_VERSION >= 30101
		e_mail_folder_uri_parse (
			CAMEL_SESSION(session), uri,
			&store, &folder_name, NULL);
#endif
648
		tmp = g_build_path(G_DIR_SEPARATOR_S,
Lucian Langa's avatar
Lucian Langa committed
649 650 651 652 653 654
#if EVOLUTION_VERSION >= 30101
			folder_name,
#else
			em_utils_folder_name_from_uri(uri),
#endif
			name, NULL);
655 656 657 658 659 660 661 662 663
		g_free(name);
		gtk_label_set_text(GTK_LABEL(data), tmp);
		g_free(tmp);
	}

	gtk_widget_destroy (dialog);
}


Lucian Langa's avatar
Lucian Langa committed
664
add_feed *
665
build_dialog_add(gchar *url, gchar *feed_text)
Lucian Langa's avatar
Lucian Langa committed
666
{
667
	char *uifile;
668
	add_feed *feed = g_new0(add_feed, 1);
Lucian Langa's avatar
Lucian Langa committed
669
	GtkBuilder  *gui;
Lucian Langa's avatar
Lucian Langa committed
670
	gchar *flabel = NULL;
671 672
	gchar *fname;
	gboolean fhtml = FALSE;
Lucian Langa's avatar
Lucian Langa committed
673
	gboolean del_unread = FALSE,
674
		del_notpresent = FALSE;
675 676
	gboolean auth_enabled;
	guint del_feed = 0;
677
	gpointer key = NULL;
678
	GtkAccelGroup *accel_group = gtk_accel_group_new ();
679
	GtkWidget *ok, *cancel;
680 681 682 683
	GtkWidget *dialog1, *child;
	GtkWidget *authuser, *authpass;
	GtkWidget *adv_options, *entry1, *entry2, *feed_name;
	GtkToggleButton *useauth;
684 685 686 687 688 689 690
	GtkWidget *feed_name_label,
		*location_button,
		*location_label;
	GtkWidget *combobox1,
		*checkbutton1,
		*checkbutton2,
		*checkbutton3,
Lucian Langa's avatar
Lucian Langa committed
691
		*radiobutton1,
692 693 694 695 696 697 698
		*radiobutton2,
		*radiobutton3,
		*radiobutton4,
		*radiobutton5,
		*radiobutton6,
		*radiobutton7,
		*ttl_value;
699
	GtkWidget *label1, *label2;
700 701
	GtkWidget *spinbutton1, *spinbutton2;
	GtkWidget *checkbutton4;
702
	GtkImage *image;
Lucian Langa's avatar
Lucian Langa committed
703 704
	EShellView *shell_view;
	GtkWidget *mainwindow;
Lucian Langa's avatar
Lucian Langa committed
705
	GError* error = NULL;
706

Lucian Langa's avatar
Lucian Langa committed
707
	feed->enabled = TRUE;
708
	uifile = g_build_filename (EVOLUTION_UIDIR,
Lucian Langa's avatar
Lucian Langa committed
709
		"rss-main.ui",
710
		NULL);
Lucian Langa's avatar
Lucian Langa committed
711
	gui = gtk_builder_new ();
712
	if (!gtk_builder_add_from_file (gui, uifile, &error)) {
Lucian Langa's avatar
Lucian Langa committed
713 714 715
		g_warning ("Couldn't load builder file: %s", error->message);
		g_error_free (error);
	}
716
	g_free (uifile);
717

Lucian Langa's avatar
Lucian Langa committed
718 719
	dialog1 = GTK_WIDGET (gtk_builder_get_object(gui, "feed_dialog"));
	child = GTK_WIDGET (gtk_builder_get_object(gui, "dialog-vbox9"));
720
//	gtk_widget_show(dialog1);
Lucian Langa's avatar
Lucian Langa committed
721 722 723 724 725 726 727
//	gtk_window_set_keep_above(GTK_WINDOW(dialog1), FALSE);
	if (url != NULL)
		gtk_window_set_title (GTK_WINDOW (dialog1), _("Edit Feed"));
	else
		gtk_window_set_title (GTK_WINDOW (dialog1), _("Add Feed"));
//	gtk_window_set_modal (GTK_WINDOW (dialog1), FALSE);

728 729
	adv_options = GTK_WIDGET (gtk_builder_get_object(gui, "adv_options"));
	entry1 = GTK_WIDGET (gtk_builder_get_object(gui, "url_entry"));
Lucian Langa's avatar
Lucian Langa committed
730 731 732 733 734
	//editing
	if (url != NULL) {
		key = lookup_key(feed_text);
		gtk_expander_set_expanded(GTK_EXPANDER(adv_options), TRUE);
		gtk_entry_set_text(GTK_ENTRY(entry1), url);
Lucian Langa's avatar
Lucian Langa committed
735
		fhtml = GPOINTER_TO_INT(
Lucian Langa's avatar
Lucian Langa committed
736 737 738 739 740 741 742
			g_hash_table_lookup(rf->hrh, key));
		feed->enabled = GPOINTER_TO_INT(
			g_hash_table_lookup(rf->hre, key));
		del_feed = GPOINTER_TO_INT(
			g_hash_table_lookup(rf->hrdel_feed, key));
		del_unread = GPOINTER_TO_INT(
			g_hash_table_lookup(rf->hrdel_unread, key));
743 744
		del_notpresent = GPOINTER_TO_INT(
			g_hash_table_lookup(rf->hrdel_notpresent, key));
Lucian Langa's avatar
Lucian Langa committed
745 746 747 748 749 750 751 752 753 754 755 756
		feed->del_days = GPOINTER_TO_INT(
			g_hash_table_lookup(rf->hrdel_days, key));
		feed->del_messages = GPOINTER_TO_INT(
			g_hash_table_lookup(rf->hrdel_messages, key));
		feed->update = GPOINTER_TO_INT(
			g_hash_table_lookup(rf->hrupdate, key));
		feed->ttl = GPOINTER_TO_INT(
		g_hash_table_lookup(rf->hrttl, key));
		feed->ttl_multiply = GPOINTER_TO_INT(
			g_hash_table_lookup(rf->hrttl_multiply, key));
	}
	feed->validate = 1;
Lucian Langa's avatar
Lucian Langa committed
757

758 759
	entry2 = GTK_WIDGET (gtk_builder_get_object(gui, "entry2"));
	feed_name = GTK_WIDGET (gtk_builder_get_object(gui, "feed_name"));
760
	if (url != NULL) {
Lucian Langa's avatar
Lucian Langa committed
761
		gchar *folder_name = lookup_feed_folder(feed_text);
762
		flabel = g_build_path(G_DIR_SEPARATOR_S,
763
			lookup_main_folder(),
Lucian Langa's avatar
Lucian Langa committed
764
			folder_name,
765
			NULL);
766
		gtk_label_set_text(GTK_LABEL(entry2), flabel);
Lucian Langa's avatar
Lucian Langa committed
767 768
		fname = g_path_get_basename(folder_name);
		g_free(folder_name);
769 770 771
		gtk_entry_set_text(GTK_ENTRY(feed_name), fname);
		g_free(fname);
		gtk_widget_show(feed_name);
Lucian Langa's avatar
Lucian Langa committed
772
		feed_name_label = GTK_WIDGET (gtk_builder_get_object(gui, "feed_name_label"));
773
		gtk_widget_show(feed_name_label);
Lucian Langa's avatar
Lucian Langa committed
774
		location_button = GTK_WIDGET (gtk_builder_get_object(gui, "location_button"));
Lucian Langa's avatar
Lucian Langa committed
775

776
		gtk_widget_show(location_button);
777 778 779
		g_signal_connect (
			GTK_BUTTON (location_button),
			"clicked", G_CALLBACK (folder_cb), entry2);
780 781 782
		location_label = GTK_WIDGET (
			gtk_builder_get_object(gui,
			"location_label"));
783
		gtk_widget_show(location_label);
Lucian Langa's avatar
Lucian Langa committed
784 785
		gtk_label_set_use_markup(GTK_LABEL(entry2), 1);
	} else
786 787
		gtk_label_set_text(GTK_LABEL(entry2), flabel);

Lucian Langa's avatar
Lucian Langa committed
788
	combobox1 = GTK_WIDGET (gtk_builder_get_object(gui, "combobox1"));
789 790 791
	gtk_combo_box_set_active(
		GTK_COMBO_BOX(combobox1),
		0);
792

Lucian Langa's avatar
Lucian Langa committed
793
	checkbutton1 = GTK_WIDGET (gtk_builder_get_object(gui, "html_check"));
794 795
	gtk_toggle_button_set_active (
		GTK_TOGGLE_BUTTON (checkbutton1),
796
		fhtml);
797

Lucian Langa's avatar
Lucian Langa committed
798
	checkbutton2 = GTK_WIDGET (gtk_builder_get_object(gui, "enabled_check"));
799 800 801
	gtk_toggle_button_set_active (
		GTK_TOGGLE_BUTTON (checkbutton2),
		feed->enabled);
802

Lucian Langa's avatar
Lucian Langa committed
803
	checkbutton3 = GTK_WIDGET (gtk_builder_get_object(gui, "validate_check"));
804
	if (url)
Lucian Langa's avatar
Lucian Langa committed
805
		gtk_widget_set_sensitive(checkbutton3, FALSE);
806 807 808
	gtk_toggle_button_set_active (
		GTK_TOGGLE_BUTTON (checkbutton3),
		feed->validate);
809

Lucian Langa's avatar
Lucian Langa committed
810 811
	spinbutton1 = GTK_WIDGET (gtk_builder_get_object(gui, "storage_sb1"));
	spinbutton2 = GTK_WIDGET (gtk_builder_get_object(gui, "storage_sb2"));
812 813 814 815 816 817
	label1 = GTK_WIDGET(gtk_builder_get_object(gui, "label12"));
	g_signal_connect(
		spinbutton1,
		"value-changed",
		G_CALLBACK(update_messages_label_cb),
		label1);
Lucian Langa's avatar
Lucian Langa committed
818
	if (feed->del_messages)
819 820 821 822 823 824 825 826
		gtk_spin_button_set_value(
			GTK_SPIN_BUTTON(spinbutton1),
			feed->del_messages);
	g_signal_connect(
		spinbutton1,
		"changed",
		G_CALLBACK(del_messages_cb),
		feed);
827

Lucian Langa's avatar
Lucian Langa committed
828 829 830 831 832 833 834 835
	radiobutton1 = GTK_WIDGET (gtk_builder_get_object(gui, "storage_rb1"));
	radiobutton2 = GTK_WIDGET (gtk_builder_get_object(gui, "storage_rb2"));
	radiobutton3 = GTK_WIDGET (gtk_builder_get_object(gui, "storage_rb3"));
	radiobutton7 = GTK_WIDGET (gtk_builder_get_object(gui, "storage_rb4"));
	radiobutton4 = GTK_WIDGET (gtk_builder_get_object(gui, "ttl_global"));
	radiobutton5 = GTK_WIDGET (gtk_builder_get_object(gui, "ttl"));
	radiobutton6 = GTK_WIDGET (gtk_builder_get_object(gui, "ttl_disabled"));
	ttl_value = GTK_WIDGET (gtk_builder_get_object(gui, "ttl_value"));
836
	image = (GtkImage *)gtk_builder_get_object (gui, "image1");
837 838 839 840
	gtk_spin_button_set_range(
		(GtkSpinButton *)ttl_value,
		0,
		(guint)MAX_TTL);
841

Lucian Langa's avatar
Lucian Langa committed
842
	/*set feed icon*/
843
	if (key) {
844 845
		gtk_image_set_from_icon_name(
			image,
846
			g_hash_table_lookup(icons, key) ? key : "rss",
847
			GTK_ICON_SIZE_SMALL_TOOLBAR);
848 849
		gtk_widget_show(GTK_WIDGET(image));
	}
Lucian Langa's avatar
Lucian Langa committed
850

Lucian Langa's avatar
Lucian Langa committed
851
	switch (del_feed) {
852 853 854 855 856 857 858 859 860 861 862 863 864 865
	case 1:         //all but the last
		gtk_toggle_button_set_active(
			GTK_TOGGLE_BUTTON(radiobutton2),
			1);
		break;
	case 2:         //older than days
		gtk_toggle_button_set_active(
			GTK_TOGGLE_BUTTON(radiobutton3),
			1);
		break;
	default:
		gtk_toggle_button_set_active(
			GTK_TOGGLE_BUTTON(radiobutton1),
			1);
Lucian Langa's avatar
Lucian Langa committed
866
	}
867

868 869 870 871 872 873
	label2 = GTK_WIDGET(gtk_builder_get_object(gui, "label13"));
	g_signal_connect(
		spinbutton2,
		"value-changed",
		G_CALLBACK(update_days_label_cb),
		label2);
Lucian Langa's avatar
Lucian Langa committed
874
	if (feed->del_days)
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889
		gtk_spin_button_set_value(
			GTK_SPIN_BUTTON(spinbutton2),
			feed->del_days);
	g_signal_connect(
		spinbutton2,
		"changed",
		G_CALLBACK(del_days_cb),
		feed);

	checkbutton4 = GTK_WIDGET (
		gtk_builder_get_object(gui,
		"storage_unread"));
	gtk_toggle_button_set_active (
		GTK_TOGGLE_BUTTON (checkbutton4),
		del_unread);
890 891 892
	gtk_toggle_button_set_active(
		GTK_TOGGLE_BUTTON(radiobutton7),
		del_notpresent);
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910

	gtk_spin_button_set_value(
		GTK_SPIN_BUTTON(ttl_value),
		feed->ttl);
	g_signal_connect(
		ttl_value,
		"changed",
		G_CALLBACK(ttl_cb),
		feed);

	gtk_combo_box_set_active(
		GTK_COMBO_BOX(combobox1),
		feed->ttl_multiply);
	g_signal_connect(
		combobox1,
		"changed",
		G_CALLBACK(ttl_multiply_cb),
		feed);
911

912
	switch (feed->update) {
Lucian Langa's avatar
Lucian Langa committed
913
	case 2:
914 915 916
		gtk_toggle_button_set_active (
			GTK_TOGGLE_BUTTON (radiobutton5),
			1);
Lucian Langa's avatar
Lucian Langa committed
917 918
		break;
	case 3:
919 920 921
		gtk_toggle_button_set_active (
			GTK_TOGGLE_BUTTON (radiobutton6),
			1);
Lucian Langa's avatar
Lucian Langa committed
922
		break;
923
	default:
924 925 926
		gtk_toggle_button_set_active (
			GTK_TOGGLE_BUTTON (radiobutton4),
			1);
Lucian Langa's avatar
Lucian Langa committed
927 928 929
		break;
	}

Lucian Langa's avatar
Lucian Langa committed
930 931 932
	authuser = GTK_WIDGET (gtk_builder_get_object(gui, "auth_user"));
	authpass = GTK_WIDGET (gtk_builder_get_object(gui, "auth_pass"));
	useauth = (GtkToggleButton*)gtk_builder_get_object(gui, "use_auth");
933

934
	if (url && read_up(url)) {
935 936 937 938 939 940 941 942 943
		gtk_toggle_button_set_active (
			GTK_TOGGLE_BUTTON (useauth),
			1);
		gtk_entry_set_text(
			GTK_ENTRY(authuser),
			g_hash_table_lookup(rf->hruser, url));
		gtk_entry_set_text(
			GTK_ENTRY(authpass),
			g_hash_table_lookup(rf->hrpass, url));
944
	}
945
	auth_enabled = gtk_toggle_button_get_active(useauth);
946 947
	gtk_widget_set_sensitive(authuser, auth_enabled);
	gtk_widget_set_sensitive(authpass, auth_enabled);
948 949 950 951 952 953
	g_signal_connect(
		useauth,
		"toggled",
		G_CALLBACK(disable_widget_cb),
		gui);

Lucian Langa's avatar
Lucian Langa committed
954 955 956
	cancel = gtk_button_new_with_mnemonic("_Cancel");
	gtk_button_set_image(GTK_BUTTON(cancel),
		gtk_image_new_from_icon_name("gtk-cancel", GTK_ICON_SIZE_BUTTON));