summary refs log tree commit diff stats
path: root/src/common
diff options
context:
space:
mode:
authorBerke Viktor <bviktor@hexchat.org>2013-05-12 05:44:32 +0200
committerBerke Viktor <bviktor@hexchat.org>2013-05-12 05:44:32 +0200
commit198dc9eb43e6d0e5c1bb44849ce671ebf18cafcd (patch)
tree01443816f0790d3143707c1e8c5494c3f0f769f6 /src/common
parentbb86771425cfdd3d09c91ce3583bb61d55005bc2 (diff)
Fix favorite channels except in inbound.c
Diffstat (limited to 'src/common')
-rw-r--r--src/common/hexchat.h2
-rw-r--r--src/common/inbound.c2
-rw-r--r--src/common/server.c4
-rw-r--r--src/common/servlist.c266
-rw-r--r--src/common/servlist.h20
5 files changed, 131 insertions, 163 deletions
diff --git a/src/common/hexchat.h b/src/common/hexchat.h
index 0a449bfa..060fd082 100644
--- a/src/common/hexchat.h
+++ b/src/common/hexchat.h
@@ -566,7 +566,7 @@ typedef struct server
 	time_t away_time;					/* when we were marked away */
 
 	char *encoding;					/* NULL for system */
-	char *autojoin;			/* list of channels & keys to join */
+	GSList *favlist;			/* list of channels & keys to join */
 
 	unsigned int motd_skipped:1;
 	unsigned int connected:1;
diff --git a/src/common/inbound.c b/src/common/inbound.c
index 4f23403f..926a34ba 100644
--- a/src/common/inbound.c
+++ b/src/common/inbound.c
@@ -1069,6 +1069,7 @@ inbound_nameslist_end (server *serv, char *chan)
 static gboolean
 check_autojoin_channels (server *serv)
 {
+#if 0//FIXME
 	char *po;
 	session *sess;
 	GSList *list = sess_list;
@@ -1137,6 +1138,7 @@ check_autojoin_channels (server *serv)
 
 	serv->joindelay_tag = 0;
 	fe_server_event (serv, FE_SE_LOGGEDIN, i);
+#endif
 	return FALSE;
 }
 
diff --git a/src/common/server.c b/src/common/server.c
index 26d9a7cb..7d48163f 100644
--- a/src/common/server.c
+++ b/src/common/server.c
@@ -2030,8 +2030,8 @@ server_free (server *serv)
 		free (serv->last_away_reason);
 	if (serv->encoding)
 		free (serv->encoding);
-	if (serv->autojoin)
-		free (serv->autojoin);
+	if (serv->favlist)
+		g_slist_free_full (serv->favlist, g_free);
 
 	fe_server_callback (serv);
 
diff --git a/src/common/servlist.c b/src/common/servlist.c
index 79591331..7c1789a9 100644
--- a/src/common/servlist.c
+++ b/src/common/servlist.c
@@ -610,11 +610,13 @@ servlist_connect (session *sess, ircnet *net, gboolean join)
 	{
 		sess->willjoinchannel[0] = 0;
 
-		if (net->autojoin)
+		if (net->favchanlist)
 		{
-			if (serv->autojoin)
-				free (serv->autojoin);
-			serv->autojoin = strdup (net->autojoin);
+			if (serv->favlist)
+			{
+				g_slist_free_full (serv->favlist, g_free);
+			}
+			serv->favlist = g_slist_copy_deep (net->favchanlist, (GCopyFunc) g_strdup, NULL);
 		}
 	}
 
@@ -804,7 +806,9 @@ servlist_server_find (ircnet *net, char *name, int *pos)
 		if (strcmp (serv->hostname, name) == 0)
 		{
 			if (pos)
+			{
 				*pos = i;
+			}
 			return serv;
 		}
 		i++;
@@ -814,6 +818,31 @@ servlist_server_find (ircnet *net, char *name, int *pos)
 	return NULL;
 }
 
+favchannel *
+servlist_favchan_find (ircnet *net, char *channel, int *pos)
+{
+	GSList *list = net->favchanlist;
+	favchannel *favchan;
+	int i = 0;
+
+	while (list)
+	{
+		favchan = list->data;
+		if (strcmp (favchan->name, channel) == 0)
+		{
+			if (pos)
+			{
+				*pos = i;
+			}
+			return favchan;
+		}
+		i++;
+		list = list->next;
+	}
+
+	return NULL;
+}
+
 commandentry *
 servlist_command_find (ircnet *net, char *cmd, int *pos)
 {
@@ -827,7 +856,9 @@ servlist_command_find (ircnet *net, char *cmd, int *pos)
 		if (strcmp (entry->command, cmd) == 0)
 		{
 			if (pos)
+			{
 				*pos = i;
+			}
 			return entry;
 		}
 		i++;
@@ -918,6 +949,32 @@ servlist_command_add (ircnet *net, char *cmd)
 	return entry;
 }
 
+favchannel *
+servlist_favchan_add (ircnet *net, char *channel)
+{
+	int pos;
+	favchannel *chan;
+
+	chan = malloc (sizeof (favchannel));
+	memset (chan, 0, sizeof (favchannel));
+
+	if (strchr (channel, ',') != NULL)
+	{
+		pos = strchr (channel, ',') - channel;
+		chan->name = g_strndup (channel, pos);
+		chan->key = g_strdup (channel + pos + 1);
+	}
+	else
+	{
+		chan->name = g_strdup (channel);
+		chan->key = NULL;
+	}
+
+	net->favchanlist = g_slist_append (net->favchanlist, chan);
+
+	return chan;
+}
+
 void
 servlist_server_remove (ircnet *net, ircserver *serv)
 {
@@ -946,6 +1003,15 @@ servlist_command_remove (ircnet *net, commandentry *entry)
 	net->commandlist = g_slist_remove (net->commandlist, entry);
 }
 
+void
+servlist_favchan_remove (ircnet *net, favchannel *channel)
+{
+	g_free (channel->name);
+	g_free (channel->key);
+	g_free (channel);
+	net->favchanlist = g_slist_remove (net->favchanlist, channel);
+}
+
 static void
 free_and_clear (char *str)
 {
@@ -991,10 +1057,10 @@ servlist_net_remove (ircnet *net)
 	if (net->real)
 		free (net->real);
 	free_and_clear (net->pass);
-	if (net->autojoin)
-		free (net->autojoin);
+	if (net->favchanlist)
+		g_slist_free_full (net->favchanlist, g_free);
 	if (net->commandlist)
-		g_slist_free_full (net->commandlist, (GDestroyNotify) g_free);
+		g_slist_free_full (net->commandlist, g_free);
 	if (net->comment)
 		free (net->comment);
 	if (net->encoding)
@@ -1049,7 +1115,7 @@ servlist_load_defaults (void)
 			net->encoding = strdup (IRC_DEFAULT_CHARSET);
 			if (def[i].channel)
 			{
-				net->autojoin = strdup (def[i].channel);
+				servlist_favchan_add (net, def[i].channel);
 			}
 			if (def[i].charset)
 			{
@@ -1127,7 +1193,7 @@ servlist_load (void)
 				net->pass = strdup (buf + 2);
 				break;
 			case 'J':
-				net->autojoin = strdup (buf + 2);
+				servlist_favchan_add (net, buf + 2);
 				break;
 			case 'C':
 				servlist_command_add (net, buf + 2);
@@ -1205,9 +1271,11 @@ servlist_save (void)
 	ircnet *net;
 	ircserver *serv;
 	commandentry *cmd;
+	favchannel *favchan;
 	GSList *list;
 	GSList *netlist;
 	GSList *cmdlist;
+	GSList *favlist;
 #ifndef WIN32
 	int first = FALSE;
 
@@ -1249,8 +1317,6 @@ servlist_save (void)
 			fprintf (fp, "R=%s\n", net->real);
 		if (net->pass)
 			fprintf (fp, "P=%s\n", net->pass);
-		if (net->autojoin)
-			fprintf (fp, "J=%s\n", net->autojoin);
 		if (net->logintype)
 			fprintf (fp, "L=%d\n", net->logintype);
 		if (net->encoding && g_ascii_strcasecmp (net->encoding, "System") &&
@@ -1284,6 +1350,23 @@ servlist_save (void)
 			cmdlist = cmdlist->next;
 		}
 
+		favlist = net->favchanlist;
+		while (favlist)
+		{
+			favchan = favlist->data;
+
+			if (favchan->key)
+			{
+				fprintf (fp, "J=%s,%s\n", favchan->name, favchan->key);
+			}
+			else
+			{
+				fprintf (fp, "J=%s\n", favchan->name);
+			}
+
+			favlist = favlist->next;
+		}
+
 		if (fprintf (fp, "\n") < 1)
 		{
 			fclose (fp);
@@ -1297,162 +1380,33 @@ servlist_save (void)
 	return TRUE;
 }
 
-static void
-joinlist_free1 (GSList *list)
-{
-	GSList *head = list;
-
-	for (; list; list = list->next)
-		g_free (list->data);
-	g_slist_free (head);
-}
-
-void
-joinlist_free (GSList *channels, GSList *keys)
-{
-	joinlist_free1 (channels);
-	joinlist_free1 (keys);
-}
-
-gboolean
-joinlist_is_in_list (server *serv, char *channel)
-{
-	GSList *channels, *keys;
-	GSList *list;
-
-	if (!serv->network || !((ircnet *)serv->network)->autojoin)
-		return FALSE;
-
-	joinlist_split (((ircnet *)serv->network)->autojoin, &channels, &keys);
-
-	for (list = channels; list; list = list->next)
-	{
-		if (serv->p_cmp (list->data, channel) == 0)
-			return TRUE;
-	}
-
-	joinlist_free (channels, keys);
-
-	return FALSE;
-}
-
-gchar *
-joinlist_merge (GSList *channels, GSList *keys)
+static int
+joinlist_find_chan (favchannel *curr_item, const char *channel)
 {
-	GString *out = g_string_new (NULL);
-	GSList *list;
-	int i, j;
-
-	for (; channels; channels = channels->next)
+	if (!g_ascii_strcasecmp (curr_item->name, channel))
 	{
-		g_string_append (out, channels->data);
-
-		if (channels->next)
-			g_string_append_c (out, ',');
+		return 0;
 	}
-
-	/* count number of REAL keys */
-	for (i = 0, list = keys; list; list = list->next)
-		if (list->data)
-			i++;
-
-	if (i > 0)
+	else
 	{
-		g_string_append_c (out, ' ');
-
-		for (j = 0; keys; keys = keys->next)
-		{
-			if (keys->data)
-			{
-				g_string_append (out, keys->data);
-				j++;
-				if (j == i)
-					break;
-			}
-
-			if (keys->next)
-				g_string_append_c (out, ',');
-		}
+		return 1;
 	}
-
-	return g_string_free (out, FALSE);
 }
 
-void
-joinlist_split (char *autojoin, GSList **channels, GSList **keys)
+gboolean
+joinlist_is_in_list (server *serv, char *channel)
 {
-	char *parta, *partb;
-	char *chan, *key;
-	int len;
-
-	*channels = NULL;
-	*keys = NULL;
-
-	/* after the first space, the keys begin */
-	parta = autojoin;
-	partb = strchr (autojoin, ' ');
-	if (partb)
-		partb++;
-
-	while (1)
+	if (!serv->network || !((ircnet *)serv->network)->favchanlist)
 	{
-		chan = parta;
-		key = partb;
-
-		if (1)
-		{
-			while (parta[0] != 0 && parta[0] != ',' && parta[0] != ' ')
-			{
-				parta++;
-			}
-		}
-
-		if (partb)
-		{
-			while (partb[0] != 0 && partb[0] != ',' && partb[0] != ' ')
-			{
-				partb++;
-			}
-		}
-
-		len = parta - chan;
-		if (len < 1)
-			break;
-		*channels = g_slist_append (*channels, g_strndup (chan, len));
-
-		len = partb - key;
-		*keys = g_slist_append (*keys, len ? g_strndup (key, len) : NULL);
-
-		if (parta[0] == ' ' || parta[0] == 0)
-			break;
-		parta++;
-
-		if (partb)
-		{
-			if (partb[0] == 0 || partb[0] == ' ')
-				partb = NULL;	/* no more keys, but maybe more channels? */
-			else
-				partb++;
-		}
+		return FALSE;
 	}
 
-#if 0
-	GSList *lista, *listb;
-	int i;
-
-	printf("-----\n");
-	i = 0;
-	lista = *channels;
-	listb = *keys;
-	while (lista)
+	if (g_slist_find_custom (((ircnet *)serv->network)->favchanlist, channel, (GCompareFunc) joinlist_find_chan))
 	{
-		printf("%d. |%s| |%s|\n", i, lista->data, listb->data);
-		i++;
-		lista = lista->next;
-		listb = listb->next;
+		return TRUE;
+	}
+	else
+	{
+		return FALSE;
 	}
-	printf("-----\n\n");
-#endif
 }
-
-
diff --git a/src/common/servlist.h b/src/common/servlist.h
index 141df127..350a1558 100644
--- a/src/common/servlist.h
+++ b/src/common/servlist.h
@@ -30,6 +30,12 @@ typedef struct commandentry
 	char *command;
 } commandentry;
 
+typedef struct favchannel
+{
+	char *name;
+	char *key;
+} favchannel;
+
 typedef struct ircnet
 {
 	char *name;
@@ -38,12 +44,12 @@ typedef struct ircnet
 	char *user;
 	char *real;
 	char *pass;
-	char *autojoin;
 	int logintype;
 	char *comment;
 	char *encoding;
 	GSList *servlist;
 	GSList *commandlist;
+	GSList *favchanlist;
 	int selected;
 	guint32 flags;
 } ircnet;
@@ -79,14 +85,20 @@ ircnet *servlist_net_find_from_server (char *server_name);
 
 ircserver *servlist_server_find (ircnet *net, char *name, int *pos);
 commandentry *servlist_command_find (ircnet *net, char *cmd, int *pos);
+favchannel *servlist_favchan_find (ircnet *net, char *channel, int *pos);
+
 ircserver *servlist_server_add (ircnet *net, char *name);
 commandentry *servlist_command_add (ircnet *net, char *command);
+favchannel *servlist_favchan_add (ircnet *net, char *channel);
+
 void servlist_server_remove (ircnet *net, ircserver *serv);
 void servlist_command_remove (ircnet *net, commandentry *entry);
+void servlist_favchan_remove (ircnet *net, favchannel *channel);
 
-void joinlist_split (char *autojoin, GSList **channels, GSList **keys);
 gboolean joinlist_is_in_list (server *serv, char *channel);
-void joinlist_free (GSList *channels, GSList *keys);
-gchar *joinlist_merge (GSList *channels, GSList *keys);
 
+/* FIXME
+void joinlist_split (char *autojoin, GSList **channels, GSList **keys);
+void joinlist_free (GSList *channels, GSList *keys);
+*/
 #endif