Simplification of new code -- eliminate member lastact_elem
This commit is contained in:
parent
ae83679e93
commit
2af44e02bf
@ -128,58 +128,31 @@ pxProxyFactory *libproxy_factory;
|
|||||||
void
|
void
|
||||||
lastact_update(session *sess)
|
lastact_update(session *sess)
|
||||||
{
|
{
|
||||||
int newidx;
|
int oldidx = sess->lastact_idx;
|
||||||
|
int newidx = LACT_NONE;
|
||||||
|
int dia = (sess->type == SESS_DIALOG);
|
||||||
|
|
||||||
/* Find the priority (for the order see before) */
|
if (sess->nick_said)
|
||||||
if (sess->type == SESS_DIALOG)
|
newidx = dia? LACT_QUERY_HI: LACT_CHAN_HI;
|
||||||
{
|
else if (sess->msg_said)
|
||||||
if (sess->nick_said)
|
newidx = dia? LACT_QUERY: LACT_CHAN;
|
||||||
newidx = LACT_QUERY_HI;
|
else if (sess->new_data)
|
||||||
else if (sess->msg_said)
|
newidx = dia? LACT_QUERY: LACT_CHAN_DATA;
|
||||||
newidx = LACT_QUERY;
|
|
||||||
else if (sess->new_data)
|
|
||||||
newidx = LACT_QUERY;
|
|
||||||
else
|
|
||||||
newidx = LACT_NONE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (sess->nick_said)
|
|
||||||
newidx = LACT_CHAN_HI;
|
|
||||||
else if (sess->msg_said)
|
|
||||||
newidx = LACT_CHAN;
|
|
||||||
else if (sess->new_data)
|
|
||||||
newidx = LACT_CHAN_DATA;
|
|
||||||
else
|
|
||||||
newidx = LACT_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if this update is a no-op */
|
/* If already first at the right position, just return */
|
||||||
if (sess->lastact_idx == newidx &&
|
if (oldidx == newidx &&
|
||||||
((newidx != LACT_NONE && sess->lastact_elem == sess_list_by_lastact[newidx]) ||
|
(newidx == LACT_NONE || g_list_index(sess_list_by_lastact[newidx], sess) == 0))
|
||||||
(newidx == LACT_NONE)))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Remove from the old position (and, if no new position, return */
|
/* Remove from the old position */
|
||||||
else if (sess->lastact_idx != LACT_NONE && sess->lastact_elem)
|
if (oldidx != LACT_NONE)
|
||||||
{
|
sess_list_by_lastact[oldidx] = g_list_remove(sess_list_by_lastact[oldidx], sess);
|
||||||
sess_list_by_lastact[sess->lastact_idx] = g_list_remove_link(
|
|
||||||
sess_list_by_lastact[sess->lastact_idx],
|
|
||||||
sess->lastact_elem);
|
|
||||||
if (newidx == LACT_NONE)
|
|
||||||
{
|
|
||||||
sess->lastact_idx = newidx;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* No previous position, allocate new */
|
|
||||||
else if (!sess->lastact_elem)
|
|
||||||
sess->lastact_elem = g_list_prepend(sess->lastact_elem, sess);
|
|
||||||
|
|
||||||
|
/* Add at the new position */
|
||||||
sess->lastact_idx = newidx;
|
sess->lastact_idx = newidx;
|
||||||
sess_list_by_lastact[newidx] = g_list_concat(
|
if (newidx != LACT_NONE)
|
||||||
sess->lastact_elem, sess_list_by_lastact[newidx]);
|
sess_list_by_lastact[newidx] = g_list_prepend(sess_list_by_lastact[newidx], sess);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -213,7 +186,7 @@ lastact_getfirst(int (*filter) (session *sess))
|
|||||||
|
|
||||||
if (sess)
|
if (sess)
|
||||||
{
|
{
|
||||||
sess_list_by_lastact[i] = g_list_remove_link(sess_list_by_lastact[i], curitem);
|
sess_list_by_lastact[i] = g_list_remove(sess_list_by_lastact[i], sess);
|
||||||
sess->lastact_idx = LACT_NONE;
|
sess->lastact_idx = LACT_NONE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -490,7 +463,6 @@ session_new (server *serv, char *from, int type, int focus)
|
|||||||
sess->text_logging = SET_DEFAULT;
|
sess->text_logging = SET_DEFAULT;
|
||||||
sess->text_scrollback = SET_DEFAULT;
|
sess->text_scrollback = SET_DEFAULT;
|
||||||
|
|
||||||
sess->lastact_elem = NULL;
|
|
||||||
sess->lastact_idx = LACT_NONE;
|
sess->lastact_idx = LACT_NONE;
|
||||||
|
|
||||||
if (from != NULL)
|
if (from != NULL)
|
||||||
@ -610,6 +582,7 @@ session_free (session *killsess)
|
|||||||
server *killserv = killsess->server;
|
server *killserv = killsess->server;
|
||||||
session *sess;
|
session *sess;
|
||||||
GSList *list;
|
GSList *list;
|
||||||
|
int oldidx;
|
||||||
|
|
||||||
plugin_emit_dummy_print (killsess, "Close Context");
|
plugin_emit_dummy_print (killsess, "Close Context");
|
||||||
|
|
||||||
@ -646,15 +619,9 @@ session_free (session *killsess)
|
|||||||
if (killsess->type == SESS_CHANNEL)
|
if (killsess->type == SESS_CHANNEL)
|
||||||
userlist_free (killsess);
|
userlist_free (killsess);
|
||||||
|
|
||||||
if (killsess->lastact_elem)
|
oldidx = killsess->lastact_idx;
|
||||||
{
|
if (oldidx != LACT_NONE)
|
||||||
if (killsess->lastact_idx != LACT_NONE)
|
sess_list_by_lastact[oldidx] = g_list_remove(sess_list_by_lastact[oldidx], killsess);
|
||||||
sess_list_by_lastact[killsess->lastact_idx] = g_list_delete_link(
|
|
||||||
sess_list_by_lastact[killsess->lastact_idx],
|
|
||||||
killsess->lastact_elem);
|
|
||||||
else
|
|
||||||
g_list_free_1(killsess->lastact_elem);
|
|
||||||
}
|
|
||||||
|
|
||||||
exec_notify_kill (killsess);
|
exec_notify_kill (killsess);
|
||||||
|
|
||||||
|
@ -415,7 +415,6 @@ typedef struct session
|
|||||||
|
|
||||||
int type; /* SESS_* */
|
int type; /* SESS_* */
|
||||||
|
|
||||||
GList *lastact_elem; /* our GList element in sess_list_by_lastact */
|
|
||||||
int lastact_idx; /* the sess_list_by_lastact[] index of the list we're in.
|
int lastact_idx; /* the sess_list_by_lastact[] index of the list we're in.
|
||||||
* For valid values, see defines of LACT_*. */
|
* For valid values, see defines of LACT_*. */
|
||||||
|
|
||||||
|
@ -1202,7 +1202,7 @@ key_action_handle_command (GtkWidget * wid, GdkEventKey * evt, char *d1,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if the given session is inside the main window. This predicate
|
* Check if the given session is inside the main window. This predicate
|
||||||
* is passed to lastact_pop as a way to filter out detached sessions.
|
* is passed to lastact_getfirst() as a way to filter out detached sessions.
|
||||||
* XXX: Consider moving this in a different file?
|
* XXX: Consider moving this in a different file?
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
|
Loading…
Reference in New Issue
Block a user