Statistics
| Revision:

root / branches / nntpgrab-0.7 / client / gui / auto_shutdown.c @ 1921

History | View | Annotate | Download (2.3 KB)

1
/* 
2
    Copyright (C) 2005-2010  Erik van Pienbroek
3

                
4
    This program is free software; you can redistribute it and/or modify
5
    it under the terms of the GNU General Public License as published by
6
    the Free Software Foundation; either version 2 of the License, or
7
    (at your option) any later version.
8

                
9
    This program is distributed in the hope that it will be useful,
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    GNU General Public License for more details.
13

                
14
    You should have received a copy of the GNU General Public License
15
    along with this program; if not, write to the Free Software
16
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
*/
18

                
19
#include "gui.h"
20

                
21
#if defined(HAVE_POLKIT1) || defined(HAVE_POLKIT_OLD) || defined(WIN32) || defined(DARWIN)
22
static gboolean autoshutdown_enabled = FALSE;
23

                
24
gboolean        perform_shutdown(void);
25

                
26
static void
27
tool_button_clicked(GtkToolItem *item, gpointer data)
28
{
29
    if (autoshutdown_enabled) {
30
        autoshutdown_enabled = FALSE;
31
        //gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), _("Enable automatic shutdown"));
32
    } else {
33
        autoshutdown_enabled = TRUE;
34
        //gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), _("Disable automatic shutdown"));
35
    }
36
}
37

                
38
static void
39
all_downloads_completed(NntpgrabGlue *obj, gpointer data)
40
{
41
    g_print("all downloads completed\n");
42

                
43
    if (autoshutdown_enabled) {
44
        nntpgrab_utils_perform_shutdown();
45
        g_idle_add((GSourceFunc) gtk_main_quit, NULL);
46
    }
47
}
48
#endif
49

                
50
void
51
autoshutdown_initialize(void)
52
{
53
    if (!nntpgrab_glue_get_is_standalone(glue)) {
54
        return;
55
    }
56

                
57
#if defined(HAVE_POLKIT1) || defined(HAVE_POLKIT_OLD) || defined(WIN32) || defined(DARWIN)
58
    GtkWidget *toolbarMain = nntpgrab_gui_base_get_widget("toolbarMain");
59
    GtkToolItem *item = gtk_toggle_tool_button_new();
60
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(item), _("Automatic shutdown"));
61
    gtk_tool_button_set_stock_id(GTK_TOOL_BUTTON(item), "gtk-disconnect");
62
    gtk_widget_show(GTK_WIDGET(item));
63

                
64
    gtk_toolbar_insert(GTK_TOOLBAR(toolbarMain), item, -1);
65

                
66
    g_signal_connect(item, "clicked", G_CALLBACK(tool_button_clicked), NULL);
67
    g_signal_connect(glue, "all_downloads_completed", G_CALLBACK(all_downloads_completed), NULL);
68
#endif
69
}
70