summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorBerke Viktor <bviktor@hexchat.org>2012-10-13 10:03:39 +0200
committerBerke Viktor <bviktor@hexchat.org>2012-10-13 10:03:39 +0200
commitca3fa043f09b0684999f8881e65c22dfde875004 (patch)
tree56e584ea78c8eb4199220c3cf55ff7bb27e2e991 /src
parentd4f3738ca82bf586503a4e1ddae6ff0797beb94a (diff)
Save URLs to disk on-the-fly and provide an option for toggling it
Diffstat (limited to 'src')
-rw-r--r--src/common/cfgfiles.c3
-rw-r--r--src/common/url.c39
-rw-r--r--src/common/url.h3
-rw-r--r--src/common/xchat.c5
-rw-r--r--src/common/xchat.h2
-rw-r--r--src/fe-gtk/setup.c5
-rw-r--r--src/fe-gtk/urlgrab.c4
7 files changed, 43 insertions, 18 deletions
diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c
index f1d48285..1d0dc2a5 100644
--- a/src/common/cfgfiles.c
+++ b/src/common/cfgfiles.c
@@ -393,8 +393,6 @@ default_file (void)
 /* Keep these sorted!! */
 
 const struct prefs vars[] = {
-	{"auto_save_url", P_OFFINT (autosave_url), TYPE_BOOL},
-
 	{"away_auto_unmark", P_OFFINT (auto_unmark_away), TYPE_BOOL},
 	{"away_reason", P_OFFSET (awayreason), TYPE_STR},
 	{"away_show_message", P_OFFINT (show_away_message), TYPE_BOOL},
@@ -616,6 +614,7 @@ const struct prefs vars[] = {
 
 	{"url_grabber", P_OFFINT (url_grabber), TYPE_BOOL},
 	{"url_grabber_limit", P_OFFINT (url_grabber_limit), TYPE_INT},
+	{"url_logging", P_OFFINT (url_logging), TYPE_BOOL},
 	{0, 0, 0},
 };
 
diff --git a/src/common/url.c b/src/common/url.c
index ee29a8a8..e258d5f1 100644
--- a/src/common/url.c
+++ b/src/common/url.c
@@ -59,7 +59,7 @@ url_save_cb (char *url, FILE *fd)
 }
 
 void
-url_save (const char *fname, const char *mode, gboolean fullpath)
+url_save_tree (const char *fname, const char *mode, gboolean fullpath)
 {
 	FILE *fd;
 
@@ -74,10 +74,20 @@ url_save (const char *fname, const char *mode, gboolean fullpath)
 	fclose (fd);
 }
 
-void
-url_autosave (void)
+static void
+url_save_node (char* url)
 {
-	url_save ("url.save", "a", FALSE);
+	FILE *fd;
+
+	/* open <config>/url.log in append mode */
+	fd = xchat_fopen_file ("url.log", "a", 0);
+	if (fd == NULL)
+	{
+		return;
+	}
+
+	fprintf (fd, "%s\n", url);
+	fclose (fd);	
 }
 
 static int
@@ -92,12 +102,17 @@ url_add (char *urltext, int len)
 	char *data;
 	int size;
 
-	if (!prefs.url_grabber)
+	/* we don't need any URLs if we have neither URL grabbing nor URL logging enabled */
+	if (!prefs.url_grabber && !prefs.url_logging)
+	{
 		return;
+	}
 
 	data = malloc (len + 1);
 	if (!data)
+	{
 		return;
+	}
 	memcpy (data, urltext, len);
 	data[len] = 0;
 
@@ -108,7 +123,21 @@ url_add (char *urltext, int len)
 	}
 	/* chop trailing ) but only if there's no counterpart */
 	if (data[len - 1] == ')' && strchr (data, '(') == NULL)
+	{
 		data[len - 1] = 0;
+	}
+
+	if (prefs.url_logging)
+	{
+		url_save_node (data);
+	}
+
+	/* the URL is saved already, only continue if we need the URL grabber too */
+	if (!prefs.url_grabber)
+	{
+		free (data);
+		return;
+	}
 
 	if (!url_tree)
 	{
diff --git a/src/common/url.h b/src/common/url.h
index ab4247e0..8263b61c 100644
--- a/src/common/url.h
+++ b/src/common/url.h
@@ -13,8 +13,7 @@ extern void *url_tree;
 #define WORD_PATH    -2
 
 void url_clear (void);
-void url_save (const char *fname, const char *mode, gboolean fullpath);
-void url_autosave (void);
+void url_save_tree (const char *fname, const char *mode, gboolean fullpath);
 int url_check_word (char *word, int len);
 void url_check_line (char *buf, int len);
 
diff --git a/src/common/xchat.c b/src/common/xchat.c
index 7e9cc8c7..17bad663 100644
--- a/src/common/xchat.c
+++ b/src/common/xchat.c
@@ -854,11 +854,6 @@ xchat_exit (void)
 		pevent_save (NULL);
 	}
 
-	if (prefs.autosave_url)
-	{
-		url_autosave ();
-	}
-
 	sound_save ();
 	notify_save ();
 	ignore_save ();
diff --git a/src/common/xchat.h b/src/common/xchat.h
index ba83c1b1..e9e4f157 100644
--- a/src/common/xchat.h
+++ b/src/common/xchat.h
@@ -209,7 +209,6 @@ struct xchatprefs
 	unsigned int perc_color;
 	unsigned int perc_ascii;
 	unsigned int autodialog;
-	unsigned int autosave_url;
 	unsigned int autoreconnect;
 	unsigned int autoreconnectonfail;
 	unsigned int invisible;
@@ -323,6 +322,7 @@ struct xchatprefs
 
 	unsigned int url_grabber;
 	unsigned int url_grabber_limit;
+	unsigned int url_logging;
 	/* Tells us if we need to save, only when they've been edited.
 		This is so that we continue using internal defaults (which can
 		change in the next release) until the user edits them. */
diff --git a/src/fe-gtk/setup.c b/src/fe-gtk/setup.c
index 907218b7..d773cbdf 100644
--- a/src/fe-gtk/setup.c
+++ b/src/fe-gtk/setup.c
@@ -489,9 +489,10 @@ static const setting logging_settings[] =
 	{ST_LABEL,	N_("See the strftime manpage for details.")},
 #endif
 
-	{ST_HEADER,	N_("URL Grabber"),0,0,0},
+	{ST_HEADER,	N_("URLs"),0,0,0},
+	{ST_TOGGLE,	N_("Enable logging of URLs to disk"), P_OFFINTNL(url_logging), 0, 0, 0},
 	{ST_TOGGLE,	N_("Enable URL grabber"), P_OFFINTNL(url_grabber), 0, 0, 2},
-	{ST_NUMBER,	N_("Maximum number of URLs:"), P_OFFINTNL(url_grabber_limit), 0, 0, 9999},
+	{ST_NUMBER,	N_("Maximum number of URLs to grab:"), P_OFFINTNL(url_grabber_limit), 0, 0, 9999},
 
 	{ST_END, 0, 0, 0, 0, 0}
 };
diff --git a/src/fe-gtk/urlgrab.c b/src/fe-gtk/urlgrab.c
index d9b79670..1cd46d9e 100644
--- a/src/fe-gtk/urlgrab.c
+++ b/src/fe-gtk/urlgrab.c
@@ -138,7 +138,9 @@ static void
 url_save_callback (void *arg1, char *file)
 {
 	if (file)
-		url_save (file, "w", TRUE);
+	{
+		url_save_tree (file, "w", TRUE);
+	}
 }
 
 static void