aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2008-04-14 22:59:36 +0800
committerMilan Crha <mcrha@src.gnome.org>2008-04-14 22:59:36 +0800
commit8a6e09d1cfc5ae369b99dc5af13f9d8519fd3f5d (patch)
tree1546f241e42bd6864b8f48e402cb9d2fbfc16029 /mail
parentd6ca198aee8a30d691dfe38d2d86fcf7ee5ab327 (diff)
downloadgsoc2013-evolution-8a6e09d1cfc5ae369b99dc5af13f9d8519fd3f5d.tar
gsoc2013-evolution-8a6e09d1cfc5ae369b99dc5af13f9d8519fd3f5d.tar.gz
gsoc2013-evolution-8a6e09d1cfc5ae369b99dc5af13f9d8519fd3f5d.tar.bz2
gsoc2013-evolution-8a6e09d1cfc5ae369b99dc5af13f9d8519fd3f5d.tar.lz
gsoc2013-evolution-8a6e09d1cfc5ae369b99dc5af13f9d8519fd3f5d.tar.xz
gsoc2013-evolution-8a6e09d1cfc5ae369b99dc5af13f9d8519fd3f5d.tar.zst
gsoc2013-evolution-8a6e09d1cfc5ae369b99dc5af13f9d8519fd3f5d.zip
** Fix for bug #270406
2008-04-14 Milan Crha <mcrha@redhat.com> ** Fix for bug #270406 * em-folder-properties.c: (struct _prop_data), (emfp_free), (add_numbered_row), (emfp_get_folder_item), (emfp_dialog_got_folder_quota), (emfp_dialog_got_folder): Retrieve quota information for a folder and show it in a dialog. * mail-ops.h: (mail_get_folder_quota): * mail-ops.c: (struct _get_quota_msg), (get_quota_desc), (get_quota_exec), (get_quota_done), (get_quota_free), (MailMsgInfo get_quota_info), (mail_get_folder_quota): New operation to get folder's quota information. svn path=/trunk/; revision=35366
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog14
-rw-r--r--mail/em-folder-properties.c96
-rw-r--r--mail/mail-ops.c69
-rw-r--r--mail/mail-ops.h5
4 files changed, 160 insertions, 24 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 5bbc9d0439..c6954caaf2 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,17 @@
+2008-04-14 Milan Crha <mcrha@redhat.com>
+
+ ** Fix for bug #270406
+
+ * em-folder-properties.c: (struct _prop_data), (emfp_free),
+ (add_numbered_row), (emfp_get_folder_item),
+ (emfp_dialog_got_folder_quota), (emfp_dialog_got_folder):
+ Retrieve quota information for a folder and show it in a dialog.
+ * mail-ops.h: (mail_get_folder_quota):
+ * mail-ops.c: (struct _get_quota_msg), (get_quota_desc),
+ (get_quota_exec), (get_quota_done), (get_quota_free),
+ (MailMsgInfo get_quota_info), (mail_get_folder_quota):
+ New operation to get folder's quota information.
+
2008-04-13 Matthew Barnes <mbarnes@redhat.com>
* em-folder-browser.c:
diff --git a/mail/em-folder-properties.c b/mail/em-folder-properties.c
index 8a2875969e..1af52a1f47 100644
--- a/mail/em-folder-properties.c
+++ b/mail/em-folder-properties.c
@@ -65,6 +65,7 @@ struct _prop_data {
int total;
int unread;
EMConfig *config;
+ CamelFolderQuotaInfo *quota;
};
static void
@@ -124,13 +125,41 @@ emfp_free(EConfig *ec, GSList *items, void *data)
camel_object_unref (prop_data->object);
g_free (prop_data->argv);
+ camel_folder_quota_info_free (prop_data->quota);
+
g_free (prop_data);
}
+static int
+add_numbered_row (GtkTable *table, int row, const char *description, const char *format, int num)
+{
+ char *str;
+ GtkWidget *label;
+
+ g_return_val_if_fail (table != NULL, row);
+ g_return_val_if_fail (description != NULL, row);
+ g_return_val_if_fail (format != NULL, row);
+
+ label = gtk_label_new (description);
+ gtk_widget_show (label);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_table_attach (table, label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0);
+
+ str = g_strdup_printf (format, num);
+
+ label = gtk_label_new (str);
+ gtk_widget_show (label);
+ gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5);
+ gtk_table_attach (table, label, 1, 2, row, row+1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
+
+ g_free (str);
+
+ return row + 1;
+}
+
static GtkWidget *
emfp_get_folder_item(EConfig *ec, EConfigItem *item, struct _GtkWidget *parent, struct _GtkWidget *old, void *data)
{
- char countstr[16];
GtkWidget *w, *table, *label;
struct _prop_data *prop_data = data;
int row = 0, i;
@@ -146,31 +175,37 @@ emfp_get_folder_item(EConfig *ec, EConfigItem *item, struct _GtkWidget *parent,
gtk_box_pack_start ((GtkBox *) parent, table, TRUE, TRUE, 0);
/* to be on the safe side, ngettext is used here, see e.g. comment #3 at bug 272567 */
- label = gtk_label_new (ngettext ("Unread messages:", "Unread messages:", prop_data->unread));
- gtk_widget_show (label);
- gtk_misc_set_alignment ((GtkMisc *) label, 0.0, 0.5);
- gtk_table_attach ((GtkTable *) table, label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0);
-
- sprintf(countstr, "%d", prop_data->unread);
- label = gtk_label_new (countstr);
- gtk_widget_show (label);
- gtk_misc_set_alignment ((GtkMisc *) label, 1.0, 0.5);
- gtk_table_attach ((GtkTable *) table, label, 1, 2, row, row+1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
- row++;
+ row = add_numbered_row (GTK_TABLE (table), row, ngettext ("Unread messages:", "Unread messages:", prop_data->unread), "%d", prop_data->unread);
/* TODO: can this be done in a loop? */
/* to be on the safe side, ngettext is used here, see e.g. comment #3 at bug 272567 */
- label = gtk_label_new (ngettext ("Total messages:", "Total messages:", prop_data->total));
- gtk_widget_show (label);
- gtk_misc_set_alignment ((GtkMisc *) label, 0.0, 0.5);
- gtk_table_attach ((GtkTable *) table, label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0);
+ row = add_numbered_row (GTK_TABLE (table), row, ngettext ("Total messages:", "Total messages:", prop_data->total), "%d", prop_data->total);
- sprintf(countstr, "%d", prop_data->total);
- label = gtk_label_new (countstr);
- gtk_widget_show (label);
- gtk_misc_set_alignment ((GtkMisc *) label, 1.0, 0.5);
- gtk_table_attach ((GtkTable *) table, label, 1, 2, row, row+1, GTK_FILL | GTK_EXPAND, 0, 0, 0);
- row++;
+ if (prop_data->quota) {
+ CamelFolderQuotaInfo *info;
+ CamelFolderQuotaInfo *quota = prop_data->quota;
+
+ for (info = quota; info; info = info->next) {
+ char *descr;
+ int procs;
+
+ /* should not happen, but anyway... */
+ if (!info->total)
+ continue;
+
+ /* show quota name only when available and have more than one quota info */
+ if (info->name && quota->next)
+ descr = g_strdup_printf ("%s (%s):", _("Quota usage"), _(info->name));
+ else
+ descr = g_strdup_printf ("%s:", _("Quota usage"));
+
+ procs = (int) ((((double) info->used) / ((double) info->total)) * 100.0 + 0.5);
+
+ row = add_numbered_row (GTK_TABLE (table), row, descr, "%d%%", procs);
+
+ g_free (descr);
+ }
+ }
/* setup the ui with the values retrieved */
l = prop_data->properties;
@@ -226,7 +261,7 @@ static EMConfigItem emfp_items[] = {
static gboolean emfp_items_translated = FALSE;
static void
-emfp_dialog_got_folder (char *uri, CamelFolder *folder, void *data)
+emfp_dialog_got_folder_quota (CamelFolder *folder, CamelFolderQuotaInfo *quota, void *data)
{
GtkWidget *dialog, *w;
struct _prop_data *prop_data;
@@ -239,15 +274,19 @@ emfp_dialog_got_folder (char *uri, CamelFolder *folder, void *data)
gboolean hide_deleted;
GConfClient *gconf;
CamelStore *store;
+ char *uri = (char *)data;
- if (folder == NULL)
+ if (folder == NULL) {
+ g_free (uri);
return;
+ }
store = folder->parent_store;
prop_data = g_malloc0 (sizeof (*prop_data));
prop_data->object = folder;
camel_object_ref (folder);
+ prop_data->quota = camel_folder_quota_info_clone (quota);
/*
Get number of VISIBLE and DELETED messages, instead of TOTAL messages. VISIBLE+DELETED
@@ -354,6 +393,15 @@ emfp_dialog_got_folder (char *uri, CamelFolder *folder, void *data)
g_signal_connect (dialog, "response", G_CALLBACK (emfp_dialog_response), prop_data);
gtk_widget_show (dialog);
+
+ g_free (uri);
+}
+
+static void
+emfp_dialog_got_folder (char *uri, CamelFolder *folder, void *data)
+{
+ /* this should be called in a thread too */
+ mail_get_folder_quota (folder, emfp_dialog_got_folder_quota, g_strdup (uri), mail_msg_unordered_push);
}
/**
diff --git a/mail/mail-ops.c b/mail/mail-ops.c
index 36f45efe6e..d13740570d 100644
--- a/mail/mail-ops.c
+++ b/mail/mail-ops.c
@@ -1253,6 +1253,75 @@ mail_get_folder (const char *uri, guint32 flags,
return id;
}
+/* ** GET FOLDER'S QUOTA ********************************************************* */
+
+struct _get_quota_msg {
+ MailMsg base;
+
+ CamelFolder *folder;
+ CamelFolderQuotaInfo *quota;
+ void (*done) (CamelFolder *folder, CamelFolderQuotaInfo *quota, void *data);
+ void *data;
+};
+
+static gchar *
+get_quota_desc (struct _get_quota_msg *m)
+{
+ return g_strdup_printf(_("Retrieving quota information for folder %s"), camel_folder_get_name (m->folder));
+}
+
+static void
+get_quota_exec (struct _get_quota_msg *m)
+{
+ m->quota = camel_folder_get_quota_info (m->folder);
+}
+
+static void
+get_quota_done (struct _get_quota_msg *m)
+{
+ if (m->done)
+ m->done (m->folder, m->quota, m->data);
+}
+
+static void
+get_quota_free (struct _get_quota_msg *m)
+{
+ if (m->folder)
+ camel_object_unref (m->folder);
+ if (m->quota)
+ camel_folder_quota_info_free (m->quota);
+}
+
+static MailMsgInfo get_quota_info = {
+ sizeof (struct _get_quota_msg),
+ (MailMsgDescFunc) get_quota_desc,
+ (MailMsgExecFunc) get_quota_exec,
+ (MailMsgDoneFunc) get_quota_done,
+ (MailMsgFreeFunc) get_quota_free
+};
+
+int
+mail_get_folder_quota (CamelFolder *folder,
+ void (*done)(CamelFolder *folder, CamelFolderQuotaInfo *quota, void *data),
+ void *data, MailMsgDispatchFunc dispatch)
+{
+ struct _get_quota_msg *m;
+ int id;
+
+ g_return_val_if_fail (folder != NULL, -1);
+
+ m = mail_msg_new (&get_quota_info);
+ m->folder = folder;
+ m->data = data;
+ m->done = done;
+
+ camel_object_ref (m->folder);
+
+ id = m->base.seq;
+ dispatch (m);
+ return id;
+}
+
/* ** GET STORE ******************************************************* */
struct _get_store_msg {
diff --git a/mail/mail-ops.h b/mail/mail-ops.h
index 8b532e896f..e60b8d48bb 100644
--- a/mail/mail-ops.h
+++ b/mail/mail-ops.h
@@ -73,6 +73,11 @@ int mail_get_folder (const char *uri, guint32 flags,
void (*done) (char *uri, CamelFolder *folder, void *data), void *data,
MailMsgDispatchFunc dispatch);
+/* get quota information for a folder */
+int mail_get_folder_quota (CamelFolder *folder,
+ void (*done)(CamelFolder *folder, CamelFolderQuotaInfo *quota, void *data),
+ void *data, MailMsgDispatchFunc dispatch);
+
/* and for a store */
int mail_get_store (const char *uri, CamelOperation *op,
void (*done) (char *uri, CamelStore *store, void *data), void *data);