aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/exchange-operations/exchange-folder-size-display.c
blob: ebfa22cacc13131b170f0ea4cb27392a9fd8aeb9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* Copyright (C) 2002-2004 Novell, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/* ExchangeFolderSize: Display the folder tree with the folder sizes */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>

#include <e-util/e-dialog-utils.h>
#include <glade/glade-xml.h>
#include <gtk/gtkbox.h>
#include <gtk/gtkcellrenderertext.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtktreeselection.h>
#include <gtk/gtktreeview.h>
#include "exchange-folder-size-display.h"

enum {
        COLUMN_NAME,
        COLUMN_SIZE,
        NUM_COLUMNS
};


static void
format_size_func (GtkTreeViewColumn *col,
                  GtkCellRenderer   *renderer,
                  GtkTreeModel      *model,
                  GtkTreeIter       *iter,
                 gpointer           user_data)
{
    GtkCellRendererText *cell = (GtkCellRendererText *)renderer;
    gdouble folder_size;
    char * new_text;
    
    gtk_tree_model_get(model, iter, COLUMN_SIZE, &folder_size, -1);
    
    if (folder_size)
        new_text = g_strdup_printf ("%.2f", folder_size);
    else
        new_text = g_strdup ("0");

    g_object_set (cell, "text", new_text, NULL);
    g_free (new_text);
}

void
exchange_folder_size_display (GtkListStore *model, GtkWidget *parent)
{
        GtkTreeViewColumn *column;
    GtkTreeSortable *sortable;
    GtkCellRenderer *cell;
        GladeXML *xml;
        GtkWidget *dialog, *table;
    GList *l;
    char *col_name;
        int response;

    printf ("exchange_folder_size_display called\n");
        g_return_if_fail (GTK_IS_WIDGET (parent));

        xml = glade_xml_new (CONNECTOR_GLADEDIR "/exchange-folder-tree.glade", NULL, NULL);
        g_return_if_fail (xml != NULL);
        dialog = glade_xml_get_widget (xml, "folder_tree");
        table = glade_xml_get_widget (xml, "folder_treeview");
    g_object_unref (xml);

        e_dialog_set_transient_for (GTK_WINDOW (dialog), parent);
    /* fsize->parent = parent; */

        /* Set up the table */
    sortable = GTK_TREE_SORTABLE (model);
    gtk_tree_sortable_set_sort_column_id (sortable, COLUMN_SIZE, GTK_SORT_DESCENDING);

        column = gtk_tree_view_column_new_with_attributes (
                ("Folder Name"), gtk_cell_renderer_text_new (), "text", COLUMN_NAME, NULL);
        gtk_tree_view_append_column (GTK_TREE_VIEW (table),
                                     column);

    col_name = g_strdup_printf ("%s (KB)", ("Folder Size"));
        column = gtk_tree_view_column_new_with_attributes (
                col_name, gtk_cell_renderer_text_new (), "text", COLUMN_SIZE, NULL);
    g_free (col_name);
    
    l = gtk_tree_view_column_get_cell_renderers (column);
    cell = (GtkCellRenderer *)l->data;
    gtk_tree_view_column_set_cell_data_func (column, cell, format_size_func, NULL, NULL );
    g_list_free (l);

        gtk_tree_view_append_column (GTK_TREE_VIEW (table),
                                     column);
        gtk_tree_view_set_model (GTK_TREE_VIEW (table),
                                 GTK_TREE_MODEL (model));
    response = gtk_dialog_run (GTK_DIALOG (dialog));
        gtk_widget_destroy (dialog);
}