Re: [evolution-patches] Exchange : Fix for 72104
- From: Sushma Rai <rsushma novell com>
- To: Sarfraaz Ahmed <asarfraaz novell com>
- Cc: asdf <evolution-patches lists ximian com>
- Subject: Re: [evolution-patches] Exchange : Fix for 72104
- Date: Fri, 25 Feb 2005 18:46:52 +0530
In finalize() model needs to be unrefed.
In the folder size heading unit "KB" is a part or trasnlatable string.
Rest looks fine.
-Sushma.
On Thu, 2005-02-24 at 12:27 +0530, Sarfraaz Ahmed wrote:
> On Mon, 2005-02-21 at 08:50 +0800, Not Zed wrote:
> >
> > This is a really bad api: you should not be passing an allocated
> > string to the function, it should be passed as a const char and
> > allocated internally if needed.
>
> Yeah, this was wrong. I have updated the patch now. I was actually not
> using that string itself. So now removed it from the API.
>
> >
> > You should also be using evolution for email, not thunderbird.
> :-) .. Done it now :)
>
>
> text/plain attachment (ex-folder-size-72104-new.patch), ""
> Index: storage/exchange-hierarchy-webdav.c
> ===================================================================
> RCS file: /cvs/gnome/evolution-exchange/storage/exchange-hierarchy-webdav.c,v
> retrieving revision 1.22
> diff -u -p -u -r1.22 exchange-hierarchy-webdav.c
> --- storage/exchange-hierarchy-webdav.c 4 Feb 2005 11:29:45 -0000 1.22
> +++ storage/exchange-hierarchy-webdav.c 24 Feb 2005 06:57:20 -0000
> @@ -473,16 +473,25 @@ add_href (gpointer path, gpointer folder
> g_ptr_array_add (hrefs, path);
> }
>
> +static const char *rescan_props[] = {
> + E2K_PR_EXCHANGE_FOLDER_SIZE,
> + E2K_PR_HTTPMAIL_UNREAD_COUNT
> +};
> +static const int n_rescan_props = sizeof (rescan_props) / sizeof (rescan_props[0]);
> +
> static void
> rescan (ExchangeHierarchy *hier)
> {
> ExchangeHierarchyWebDAV *hwd = EXCHANGE_HIERARCHY_WEBDAV (hier);
> const char *prop = E2K_PR_HTTPMAIL_UNREAD_COUNT;
> + const char *folder_size, *folder_name;
> GPtrArray *hrefs;
> E2kResultIter *iter;
> E2kResult *result;
> EFolder *folder;
> int unread;
> + gboolean personal = ( hier->type == EXCHANGE_HIERARCHY_PERSONAL );
> + gdouble fsize_d;
>
> if ( exchange_account_is_offline (hier->account) ||
> hier->type == EXCHANGE_HIERARCHY_PUBLIC)
> @@ -500,7 +509,7 @@ rescan (ExchangeHierarchy *hier)
> iter = e_folder_exchange_bpropfind_start (hier->toplevel, NULL,
> (const char **)hrefs->pdata,
> hrefs->len,
> - &prop, 1);
> + rescan_props, n_rescan_props);
> g_ptr_array_free (hrefs, TRUE);
>
> while ((result = e2k_result_iter_next (iter))) {
> @@ -517,6 +526,17 @@ rescan (ExchangeHierarchy *hier)
>
> if (unread != e_folder_get_unread_count (folder))
> e_folder_set_unread_count (folder, unread);
> +
> + folder_size = e2k_properties_get_prop (result->props,
> + E2K_PR_EXCHANGE_FOLDER_SIZE);
> + if (folder_size && personal) {
> + if (e_folder_exchange_get_permanent_uri (folder)) {
> + folder_name = e_folder_get_name (folder);
> + fsize_d = g_ascii_strtod (folder_size, NULL)/1024;
> + exchange_folder_size_update (hwd->priv->foldersize,
> + folder_name, fsize_d);
> + }
> + }
> }
> e2k_result_iter_free (iter);
> g_object_unref (hier);
> @@ -538,6 +558,8 @@ exchange_hierarchy_webdav_status_to_fold
> ExchangeFolderSize *
> exchange_hierarchy_webdav_get_folder_size (ExchangeHierarchyWebDAV *hwd)
> {
> + g_return_val_if_fail (EXCHANGE_IS_HIERARCHY_WEBDAV (hwd), NULL);
> +
> return hwd->priv->foldersize;
> }
>
> @@ -551,6 +573,7 @@ exchange_hierarchy_webdav_parse_folder (
> const char *name, *prop, *outlook_class, *permanenturl, *folder_size;
> int unread;
> gboolean hassubs;
> + gdouble fsize_d;
>
> g_return_val_if_fail (EXCHANGE_IS_HIERARCHY_WEBDAV (hwd), NULL);
> g_return_val_if_fail (E_IS_FOLDER (parent), NULL);
> @@ -606,7 +629,10 @@ exchange_hierarchy_webdav_parse_folder (
> e_folder_exchange_set_has_subfolders (folder, TRUE);
> if (permanenturl) {
> e_folder_exchange_set_permanent_uri (folder, permanenturl);
> - exchange_folder_size_update (hwd->priv->foldersize, permanenturl, name, folder_size);
> + /* FIXME : Find a better way of doing this */
> + fsize_d = g_ascii_strtod (folder_size, NULL)/1024 ;
> + exchange_folder_size_update (hwd->priv->foldersize,
> + name, fsize_d);
> }
>
> return folder;
> Index: storage/exchange-folder-size.c
> ===================================================================
> RCS file: /cvs/gnome/evolution-exchange/storage/exchange-folder-size.c,v
> retrieving revision 1.7
> diff -u -p -u -r1.7 exchange-folder-size.c
> --- storage/exchange-folder-size.c 10 Jan 2005 20:13:55 -0000 1.7
> +++ storage/exchange-folder-size.c 24 Feb 2005 06:57:20 -0000
> @@ -43,13 +43,15 @@ static GObjectClass *parent_class = NULL
>
> typedef struct {
> char *folder_name;
> - char *folder_size;
> + gdouble folder_size;
> } folder_info;
>
>
> struct _ExchangeFolderSizePrivate {
>
> GHashTable *table;
> + GtkListStore *model;
> + GHashTable *row_refs;
> };
>
> enum {
> @@ -59,11 +61,10 @@ enum {
> };
>
> static void
> -free_table (gpointer key, gpointer value, gpointer data)
> +free_fsize_table (gpointer key, gpointer value, gpointer data)
> {
> folder_info *f_info = (folder_info *) value;
> g_free (f_info->folder_name);
> - g_free (f_info->folder_size);
> g_free (f_info);
> }
>
> @@ -73,6 +74,7 @@ finalize (GObject *object)
> ExchangeFolderSize *fsize = EXCHANGE_FOLDER_SIZE (object);
>
> g_hash_table_destroy (fsize->priv->table);
> + g_hash_table_destroy (fsize->priv->row_refs);
>
> G_OBJECT_CLASS (parent_class)->finalize (object);
> }
> @@ -101,7 +103,9 @@ init (GObject *object)
>
> fsize->priv = g_new0 (ExchangeFolderSizePrivate, 1);
> fsize->priv->table = g_hash_table_new_full (g_str_hash, g_str_equal,
> - g_free, (GDestroyNotify)free_table);
> + NULL, (GDestroyNotify)free_fsize_table);
> + fsize->priv->model = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_DOUBLE);
> + fsize->priv->row_refs = g_hash_table_new (g_str_hash, g_str_equal);
> }
>
> E2K_MAKE_TYPE (exchange_folder_size, ExchangeFolderSize, class_init, init, PARENT_TYPE)
> @@ -124,39 +128,84 @@ exchange_folder_size_new (void)
>
> void
> exchange_folder_size_update (ExchangeFolderSize *fsize,
> - const char *permanent_uri,
> const char *folder_name,
> - const char *folder_size)
> + gdouble folder_size)
> {
> - folder_info *f_info;
> + folder_info *f_info, *cached_info;
> ExchangeFolderSizePrivate *priv;
> GHashTable *folder_size_table;
> + GtkTreeRowReference *row;
> + GtkTreeIter iter;
> + GtkTreePath *path;
>
> g_return_if_fail (EXCHANGE_IS_FOLDER_SIZE (fsize));
>
> priv = fsize->priv;
> folder_size_table = priv->table;
>
> - /*FIXME : Check if value is already present */
> + cached_info = g_hash_table_lookup (folder_size_table, folder_name);
> + if (cached_info) {
> + if (cached_info->folder_size == folder_size) {
> + return;
> + } else {
> + cached_info->folder_size = folder_size;
> + row = g_hash_table_lookup (priv->row_refs, folder_name);
> + path = gtk_tree_row_reference_get_path (row);
> + if (gtk_tree_model_get_iter (GTK_TREE_MODEL (fsize->priv->model), &iter, path)) {
> + gtk_list_store_set (fsize->priv->model, &iter,
> + COLUMN_NAME, cached_info->folder_name,
> + COLUMN_SIZE, cached_info->folder_size,
> + -1);
> + }
> + gtk_tree_path_free (path);
> + return;
> + }
> + } else {
> + f_info = g_new0(folder_info, 1);
> + f_info->folder_name = g_strdup (folder_name);
> + f_info->folder_size = folder_size;
> + g_hash_table_insert (folder_size_table, f_info->folder_name, f_info);
> +
> + gtk_list_store_append (fsize->priv->model, &iter);
> + gtk_list_store_set (fsize->priv->model, &iter,
> + COLUMN_NAME, f_info->folder_name,
> + COLUMN_SIZE, f_info->folder_size,
> + -1);
> +
> + path = gtk_tree_model_get_path (GTK_TREE_MODEL (fsize->priv->model), &iter);
> + row = gtk_tree_row_reference_new (GTK_TREE_MODEL (fsize->priv->model), path);
> + gtk_tree_path_free (path);
> +
> + g_hash_table_insert (fsize->priv->row_refs, f_info->folder_name, row);
> + }
> +}
> +
> +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");
>
> - f_info = g_new0(folder_info, 1);
> - f_info->folder_name = g_strdup (folder_name);
> - f_info->folder_size = g_strdup (folder_size);
> - g_hash_table_insert (folder_size_table, g_strdup (permanent_uri), f_info);
> + g_object_set (cell, "text", new_text, NULL);
> + g_free (new_text);
> }
>
> static void
> -add_entry (gpointer key, gpointer value, gpointer data)
> +parent_destroyed (gpointer dialog, GObject *ex_parent)
> {
> - folder_info *f_info = value;
> - GtkListStore *store = data;
> - GtkTreeIter iter;
> -
> - gtk_list_store_append (store, &iter);
> - gtk_list_store_set (store, &iter,
> - COLUMN_NAME, f_info->folder_name,
> - COLUMN_SIZE, f_info->folder_size,
> - -1);
> + gtk_dialog_response (dialog, GTK_RESPONSE_CANCEL);
> }
>
> void
> @@ -166,14 +215,15 @@ exchange_folder_size_display (EFolder *f
> ExchangeFolderSize *fsize;
> ExchangeHierarchy *hier;
> GtkTreeViewColumn *column;
> + GtkTreeSortable *sortable;
> + GtkCellRenderer *cell;
> GHashTable *folder_size_table;
> GladeXML *xml;
> GtkWidget *dialog, *table;
> - GtkListStore *model;
> + GList *l;
> int response;
>
> g_return_if_fail (GTK_IS_WIDGET (parent));
> - g_return_if_fail (E_IS_FOLDER (folder));
>
> hier = e_folder_exchange_get_hierarchy (folder);
> if (!hier)
> @@ -186,30 +236,39 @@ exchange_folder_size_display (EFolder *f
> priv = fsize->priv;
> folder_size_table = priv->table;
>
> + if (!g_hash_table_size (folder_size_table))
> + return;
> +
> 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");
>
> e_dialog_set_transient_for (GTK_WINDOW (dialog), parent);
> - /* fsize->parent = parent;
> - g_object_weak_ref (G_OBJECT (parent), parent_destroyed, fsize); */
> + /* fsize->parent = parent; */
> + g_object_weak_ref (G_OBJECT (parent), parent_destroyed, dialog);
>
> /* Set up the table */
> - model = gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
> - if (folder_size_table)
> - g_hash_table_foreach (folder_size_table, add_entry, model);
> + sortable = GTK_TREE_SORTABLE (priv->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);
> +
> column = gtk_tree_view_column_new_with_attributes (
> - _("Folder Size"), gtk_cell_renderer_text_new (), "text", COLUMN_SIZE, NULL);
> + _("Folder Size (KB)"), gtk_cell_renderer_text_new (), "text", COLUMN_SIZE, NULL);
> +
> + 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));
> + GTK_TREE_MODEL (priv->model));
> response = gtk_dialog_run (GTK_DIALOG (dialog));
> gtk_widget_destroy (dialog);
> g_object_unref (xml);
> Index: storage/exchange-folder-size.h
> ===================================================================
> RCS file: /cvs/gnome/evolution-exchange/storage/exchange-folder-size.h,v
> retrieving revision 1.2
> diff -u -p -u -r1.2 exchange-folder-size.h
> --- storage/exchange-folder-size.h 8 Nov 2004 13:10:52 -0000 1.2
> +++ storage/exchange-folder-size.h 24 Feb 2005 06:57:20 -0000
> @@ -40,9 +40,8 @@ GType exchange_folder_size_get_type (
> ExchangeFolderSize *exchange_folder_size_new (void);
>
> void exchange_folder_size_update (ExchangeFolderSize *fsize,
> - const char *permanent_uri,
> const char *folder_name,
> - const char *folder_size);
> + gdouble folder_size);
>
> void exchange_folder_size_display (EFolder *folder, GtkWidget *parent);
>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]