Merge pull request #687 from Mikah89/clear_dcc_list_rebased
Clear button in dcc download manager
This commit is contained in:
commit
e2328e7a91
|
@ -227,6 +227,15 @@ is_dcc (struct DCC *dcc)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
is_dcc_completed (struct DCC *dcc)
|
||||||
|
{
|
||||||
|
if (dcc != NULL)
|
||||||
|
return (dcc->dccstat == STAT_FAILED || dcc->dccstat == STAT_DONE || dcc->dccstat == STAT_ABORTED);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* this is called from hexchat.c:hexchat_misc_checks() every 1 second. */
|
/* this is called from hexchat.c:hexchat_misc_checks() every 1 second. */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -117,6 +117,7 @@ struct dccstat_info
|
||||||
extern struct dccstat_info dccstat[];
|
extern struct dccstat_info dccstat[];
|
||||||
|
|
||||||
gboolean is_dcc (struct DCC *dcc);
|
gboolean is_dcc (struct DCC *dcc);
|
||||||
|
gboolean is_dcc_completed (struct DCC *dcc);
|
||||||
void dcc_abort (session *sess, struct DCC *dcc);
|
void dcc_abort (session *sess, struct DCC *dcc);
|
||||||
void dcc_get (struct DCC *dcc);
|
void dcc_get (struct DCC *dcc);
|
||||||
int dcc_resume (struct DCC *dcc);
|
int dcc_resume (struct DCC *dcc);
|
||||||
|
|
|
@ -78,6 +78,7 @@ struct dccwindow
|
||||||
GtkWidget *accept_button;
|
GtkWidget *accept_button;
|
||||||
GtkWidget *resume_button;
|
GtkWidget *resume_button;
|
||||||
GtkWidget *open_button;
|
GtkWidget *open_button;
|
||||||
|
GtkWidget *clear_button; /* clears aborted and completed requests */
|
||||||
|
|
||||||
GtkWidget *file_label;
|
GtkWidget *file_label;
|
||||||
GtkWidget *address_label;
|
GtkWidget *address_label;
|
||||||
|
@ -380,6 +381,50 @@ dcc_append (struct DCC *dcc, GtkListStore *store, gboolean prepend)
|
||||||
dcc_prepare_row_send (dcc, store, &iter, FALSE);
|
dcc_prepare_row_send (dcc, store, &iter, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns aborted and completed transfers. */
|
||||||
|
static GSList *
|
||||||
|
dcc_get_completed (void)
|
||||||
|
{
|
||||||
|
struct DCC *dcc;
|
||||||
|
GtkTreeIter iter;
|
||||||
|
GtkTreeModel *model;
|
||||||
|
GSList *completed = NULL;
|
||||||
|
|
||||||
|
model = GTK_TREE_MODEL (dccfwin.store);
|
||||||
|
if (gtk_tree_model_get_iter_first (model, &iter))
|
||||||
|
{
|
||||||
|
do
|
||||||
|
{
|
||||||
|
gtk_tree_model_get (model, &iter, COL_DCC, &dcc, -1);
|
||||||
|
if (is_dcc_completed (dcc))
|
||||||
|
completed = g_slist_prepend (completed, dcc);
|
||||||
|
|
||||||
|
} while (gtk_tree_model_iter_next (model, &iter));
|
||||||
|
}
|
||||||
|
|
||||||
|
return completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
dcc_completed_transfer_exists (void)
|
||||||
|
{
|
||||||
|
gboolean exist;
|
||||||
|
GSList *comp_list;
|
||||||
|
|
||||||
|
comp_list = dcc_get_completed ();
|
||||||
|
exist = comp_list != NULL;
|
||||||
|
|
||||||
|
g_slist_free (comp_list);
|
||||||
|
return exist;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_clear_button_sensitivity (void)
|
||||||
|
{
|
||||||
|
gboolean sensitive = dcc_completed_transfer_exists ();
|
||||||
|
gtk_widget_set_sensitive (dccfwin.clear_button, sensitive);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dcc_fill_window (int flags)
|
dcc_fill_window (int flags)
|
||||||
{
|
{
|
||||||
|
@ -426,6 +471,8 @@ dcc_fill_window (int flags)
|
||||||
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dccfwin.store), &iter);
|
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dccfwin.store), &iter);
|
||||||
gtk_tree_selection_select_iter (dccfwin.sel, &iter);
|
gtk_tree_selection_select_iter (dccfwin.sel, &iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_clear_button_sensitivity ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return list of selected DCCs */
|
/* return list of selected DCCs */
|
||||||
|
@ -511,6 +558,9 @@ abort_clicked (GtkWidget * wid, gpointer none)
|
||||||
dcc_abort (dcc->serv->front_session, dcc);
|
dcc_abort (dcc->serv->front_session, dcc);
|
||||||
}
|
}
|
||||||
g_slist_free (start);
|
g_slist_free (start);
|
||||||
|
|
||||||
|
/* Enable the clear button if it wasn't already enabled */
|
||||||
|
update_clear_button_sensitivity ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -529,6 +579,27 @@ accept_clicked (GtkWidget * wid, gpointer none)
|
||||||
g_slist_free (start);
|
g_slist_free (start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clear_completed (GtkWidget * wid, gpointer none)
|
||||||
|
{
|
||||||
|
struct DCC *dcc;
|
||||||
|
GSList *completed;
|
||||||
|
|
||||||
|
/* Make a new list of only the completed items and abort each item.
|
||||||
|
* A new list is made because calling dcc_abort removes items from the original list,
|
||||||
|
* making it impossible to iterate over that list directly.
|
||||||
|
*/
|
||||||
|
for (completed = dcc_get_completed (); completed; completed = completed->next)
|
||||||
|
{
|
||||||
|
dcc = completed->data;
|
||||||
|
dcc_abort (dcc->serv->front_session, dcc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The data was freed by dcc_close */
|
||||||
|
g_slist_free (completed);
|
||||||
|
update_clear_button_sensitivity ();
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
browse_folder (char *dir)
|
browse_folder (char *dir)
|
||||||
{
|
{
|
||||||
|
@ -812,6 +883,7 @@ fe_dcc_open_recv_win (int passive)
|
||||||
dccfwin.abort_button = gtkutil_button (bbox, GTK_STOCK_CANCEL, 0, abort_clicked, 0, _("Abort"));
|
dccfwin.abort_button = gtkutil_button (bbox, GTK_STOCK_CANCEL, 0, abort_clicked, 0, _("Abort"));
|
||||||
dccfwin.accept_button = gtkutil_button (bbox, GTK_STOCK_APPLY, 0, accept_clicked, 0, _("Accept"));
|
dccfwin.accept_button = gtkutil_button (bbox, GTK_STOCK_APPLY, 0, accept_clicked, 0, _("Accept"));
|
||||||
dccfwin.resume_button = gtkutil_button (bbox, GTK_STOCK_REFRESH, 0, resume_clicked, 0, _("Resume"));
|
dccfwin.resume_button = gtkutil_button (bbox, GTK_STOCK_REFRESH, 0, resume_clicked, 0, _("Resume"));
|
||||||
|
dccfwin.clear_button = gtkutil_button (bbox, GTK_STOCK_CLEAR, 0, clear_completed, 0, _("Clear"));
|
||||||
dccfwin.open_button = gtkutil_button (bbox, 0, 0, browse_dcc_folder, 0, _("Open Folder..."));
|
dccfwin.open_button = gtkutil_button (bbox, 0, 0, browse_dcc_folder, 0, _("Open Folder..."));
|
||||||
gtk_widget_set_sensitive (dccfwin.accept_button, FALSE);
|
gtk_widget_set_sensitive (dccfwin.accept_button, FALSE);
|
||||||
gtk_widget_set_sensitive (dccfwin.resume_button, FALSE);
|
gtk_widget_set_sensitive (dccfwin.resume_button, FALSE);
|
||||||
|
@ -1055,6 +1127,8 @@ fe_dcc_update (struct DCC *dcc)
|
||||||
default:
|
default:
|
||||||
dcc_update_chat (dcc);
|
dcc_update_chat (dcc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_clear_button_sensitivity ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue