GtkWidget *
org_gnome_exchange_show_folder_size_factory (EPlugin *epl, EConfigHookItemFactoryData *data)
{
    EMConfigTargetFolder *target=  (EMConfigTargetFolder *)data->config->target;
    CamelFolder *cml_folder = target->folder;
    CamelService *service;
    CamelProvider *provider;
    ExchangeAccount *account;
    GtkWidget *lbl_size, *lbl_size_val;
    GtkListStore *model;
    GtkVBox *vbx;
    GtkHBox *hbx_size;
    char *folder_name, *folder_size;
    int mode;

    service = CAMEL_SERVICE (camel_folder_get_parent_store (cml_folder));
    if (!service)
        return NULL;

    provider = camel_service_get_provider (service);
    if (!provider)
        return NULL;

    if (g_ascii_strcasecmp (provider->protocol, "exchange"))
        return NULL;

    account = exchange_operations_get_exchange_account ();
    exchange_account_is_offline (account, &mode);
    if (mode == OFFLINE_MODE)
        return NULL;

    folder_name = (char*) camel_folder_get_name (cml_folder);
    if (!folder_name)
        folder_name = g_strdup ("name");

    model = exchange_account_folder_size_get_model (account);
    if (model)
        folder_size = g_strdup_printf (_("%s KB"), exchange_folder_size_get_val (model, folder_name));
    else
        folder_size = g_strdup (_("0 KB"));

    hbx_size = (GtkHBox*) gtk_hbox_new (FALSE, 0);
    vbx = (GtkVBox *)gtk_notebook_get_nth_page (GTK_NOTEBOOK (data->parent), 0);

    lbl_size = gtk_label_new_with_mnemonic (_("Size:"));
    lbl_size_val = gtk_label_new_with_mnemonic (_(folder_size));
    gtk_widget_show (lbl_size);
    gtk_widget_show (lbl_size_val);
    gtk_misc_set_alignment (GTK_MISC (lbl_size), 0.0, 0.5);
    gtk_misc_set_alignment (GTK_MISC (lbl_size_val), 0.0, 0.5);
    gtk_box_pack_start (GTK_BOX (hbx_size), lbl_size, FALSE, TRUE, 12);
    gtk_box_pack_start (GTK_BOX (hbx_size), lbl_size_val, FALSE, TRUE, 10);
    gtk_widget_show_all (GTK_WIDGET (hbx_size));

    gtk_box_pack_start (GTK_BOX (vbx), GTK_WIDGET (hbx_size), FALSE, FALSE, 0);
    g_free (folder_size);

    return GTK_WIDGET (hbx_size);
}
static gboolean
is_eex_source_selected (EShellView *shell_view,
                        gchar **puri)
{
	gint mode;
	ExchangeAccount *account = NULL;
	ESource *source = NULL;
	gchar *uri = NULL;
	EShellSidebar *shell_sidebar;
	ESourceSelector *selector = NULL;

	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
	g_return_val_if_fail (shell_sidebar != NULL, FALSE);

	g_object_get (shell_sidebar, "selector", &selector, NULL);
	g_return_val_if_fail (selector != NULL, FALSE);

	source = e_source_selector_ref_primary_selection (selector);
	if (source != NULL) {
		uri = e_source_get_uri (source);
		g_object_unref (source);
	}

	g_object_unref (selector);

	if (!uri || !g_strrstr (uri, "exchange://")) {
		g_free (uri);
		return FALSE;
	}

	account = exchange_operations_get_exchange_account ();
	if (!account) {
		g_free (uri);
		return FALSE;
	}

	exchange_account_is_offline (account, &mode);
	if (mode == OFFLINE_MODE) {
		g_free (uri);
		return FALSE;
	}

	if (!exchange_account_get_folder (account, uri)) {
		g_free (uri);
		return FALSE;
	}

	if (puri)
		*puri = uri;
	else
		g_free (uri);

	return TRUE;
}
static gboolean
is_eex_folder_selected (EShellView *shell_view,
                        gchar **puri)
{
	ExchangeAccount *account = NULL;
	EShellSidebar *shell_sidebar;
	EMFolderTree *folder_tree = NULL;
	GtkTreeSelection *selection;
	GtkTreeModel *model = NULL;
	GtkTreeIter iter;
	CamelStore *store;
	gchar *folder_name;
	gboolean is_store = FALSE, res = FALSE;
	gboolean is_exchange_store = FALSE;

	g_return_val_if_fail (shell_view != NULL, FALSE);

	shell_sidebar = e_shell_view_get_shell_sidebar (shell_view);
	g_object_get (shell_sidebar, "folder-tree", &folder_tree, NULL);
	g_return_val_if_fail (folder_tree != NULL, FALSE);

	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_tree));
	g_return_val_if_fail (selection != NULL, FALSE);

	if (!gtk_tree_selection_get_selected (selection, &model, &iter))
		return FALSE;

	gtk_tree_model_get (
		model, &iter,
		COL_POINTER_CAMEL_STORE, &store,
		COL_STRING_FULL_NAME, &folder_name,
		COL_BOOL_IS_STORE, &is_store,
		-1);

	/* XXX Maybe move CamelExchangeStore to /server/lib so
	 *     we can query its GType directly?  Would probably
	 *     drag all the other CamelExchange classes with it,
	 *     but maybe that's okay? */
	if (CAMEL_IS_STORE (store)) {
		CamelService *service;
		CamelProvider *provider;
		const gchar *protocol;

		service = CAMEL_SERVICE (store);
		provider = camel_service_get_provider (service);
		protocol = (provider != NULL) ? provider->protocol : NULL;
		is_exchange_store = (g_strcmp0 (protocol, "exchange") == 0);
	}

	res = !is_store && is_exchange_store;

	if (res) {
		gint mode;

		/* check for the account later, as it is connecting to the server for the first time */
		account = exchange_operations_get_exchange_account ();
		if (!account) {
			res = FALSE;
		} else {
			exchange_account_is_offline (account, &mode);
			if (mode == OFFLINE_MODE)
				res = FALSE;
		}
	}

	if (folder_name != NULL && puri != NULL) {
		*puri = folder_name;
		folder_name = NULL;
	}

	g_free (folder_name);

	return res;
}
gboolean
create_folder_subscription_dialog (ExchangeAccount *account,
                                   const gchar *fname)
{
	ENameSelector *name_selector;
	GtkWidget *dialog;
	GtkWidget *dialog_vbox1;
	GtkWidget *table1;
	GtkWidget *label1;
	GtkWidget *label3;
	GtkWidget *user_picker_placeholder;
	GtkWidget *button_user;
	GtkWidget *folder_name_combo;
	GtkWidget *server_combobox;
	SubscriptionInfo *subscription_info;
	gint mode;

	exchange_account_is_offline (account, &mode);
	if (mode == OFFLINE_MODE)
		return FALSE;

	subscription_info = g_new0 (SubscriptionInfo, 1);
	subscription_info->account = account;

	dialog = gtk_dialog_new_with_buttons (
		_("Subscribe to folder of other user"),
		NULL,
		GTK_DIALOG_DESTROY_WITH_PARENT,
		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
		GTK_STOCK_OK, GTK_RESPONSE_OK,
		NULL);

	dialog_vbox1 = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
	gtk_widget_show (dialog_vbox1);

	table1 = gtk_table_new (3, 2, FALSE);
	gtk_widget_show (table1);
	gtk_box_pack_start (GTK_BOX (dialog_vbox1), table1, TRUE, TRUE, 2);
	gtk_table_set_row_spacings (GTK_TABLE (table1), 3);
	gtk_table_set_col_spacings (GTK_TABLE (table1), 3);

	label1 = gtk_label_new_with_mnemonic (_("_Account:"));
	gtk_widget_show (label1);
	gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1,
			  (GtkAttachOptions) (GTK_FILL),
			  (GtkAttachOptions) (0), 0, 0);
	gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_CENTER);

	label3 = gtk_label_new_with_mnemonic (_("_Folder Name:"));
	gtk_widget_show (label3);
	gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 2, 3,
			  (GtkAttachOptions) (GTK_FILL),
			  (GtkAttachOptions) (0), 0, 0);
	gtk_label_set_justify (GTK_LABEL (label3), GTK_JUSTIFY_CENTER);

	user_picker_placeholder = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (user_picker_placeholder);
	gtk_table_attach (GTK_TABLE (table1), user_picker_placeholder, 1, 2, 1, 2,
			  (GtkAttachOptions) (GTK_FILL),
			  (GtkAttachOptions) (0), 0, 0);

	button_user = gtk_button_new_with_mnemonic (_("_User:"******"changed",
			  G_CALLBACK (user_name_entry_changed_callback), dialog);

	setup_server_combobox (server_combobox, account->account_name);
	setup_folder_name_combo (folder_name_combo, fname);
	subscription_info->folder_name_entry = gtk_bin_get_child (GTK_BIN (folder_name_combo));
	g_signal_connect (dialog, "response", G_CALLBACK (subscribe_to_folder), subscription_info);
	gtk_widget_show (dialog);

	/* Connect the callback to set the OK button insensitive when there is
	 * no text in the folder_name_entry.  Notice that we put a value there
	 * by default so the OK button is sensitive by default.  */
	g_signal_connect (subscription_info->folder_name_entry, "changed",
			  G_CALLBACK (folder_name_entry_changed_callback), dialog);

	return TRUE;
}