* src/modest-defs.h: Define MODEST_MCC1_VOLUMEPATH and MODEST_MCC1_VOLUMEPATH_URI.
* src/modest-init.h:
* src/modest-init.c: Made modest_init_local_folders() take a
path and be public so we can iniitialize maildir folders on
arbitrary volumes.
* src/modest-local-folder-info.h:
* src/modest-local-folder-info.c:
(modest_local_folder_info_get_maildir_path): Add a path parameter.
* src/modest-tny-account.c:
(modest_tny_account_new_for_local_folders): Take a path parameter, though NULL
still means the standard local-folders path on the local volume.
* src/modest-tny-account-store.c:
(modest_tny_account_store_instance_init): Connect to GnomeVfsVolumeMonitor
signal so we can detect mount/unmount of the MMC1 card, and do an update of
all accounts when that happens.
(get_server_accounts): If the MMC1 card is mounted, create a store account for
this too, so it shows up in the treeview.
pmo-trunk-r1995
+2007-05-30 Murray Cumming <murrayc@murrayc.com>
+
+ * src/modest-defs.h: Define MODEST_MCC1_VOLUMEPATH and MODEST_MCC1_VOLUMEPATH_URI.
+
+ * src/modest-init.h:
+ * src/modest-init.c: Made modest_init_local_folders() take a
+ path and be public so we can iniitialize maildir folders on
+ arbitrary volumes.
+
+ * src/modest-local-folder-info.h:
+ * src/modest-local-folder-info.c:
+ (modest_local_folder_info_get_maildir_path): Add a path parameter.
+
+ * src/modest-tny-account.c:
+ (modest_tny_account_new_for_local_folders): Take a path parameter, though NULL
+ still means the standard local-folders path on the local volume.
+
+ * src/modest-tny-account-store.c:
+ (modest_tny_account_store_instance_init): Connect to GnomeVfsVolumeMonitor
+ signal so we can detect mount/unmount of the MMC1 card, and do an update of
+ all accounts when that happens.
+ (get_server_accounts): If the MMC1 card is mounted, create a store account for
+ this too, so it shows up in the treeview.
+
2007-05-28 Murray Cumming <murrayc@murrayc.com>
* src/maemo/modest-maemo-global-settings-dialog.c:
#define MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDERS_MAILDIR MODEST_PER_ACCOUNT_LOCAL_OUTBOX_FOLDER_ACCOUNT_ID_PREFIX
#define MODEST_MMC_ACCOUNT_ID "mcc"
-#define MODEST_MCC_ACCOUNT_MAILDIR "/media/mmc1/.Maildir"
+
+/* Without the trailing / because gnome-vfs reports mounted
+ * volume URIs without the trailing, and we want to match them: */
+#define MODEST_MCC1_VOLUMEPATH "/media/mmc1"
+#define MODEST_MCC1_VOLUMEPATH_URI "file://" MODEST_MCC1_VOLUMEPATH
/* configuration key definitions for modest */
#define MODEST_CONF_NAMESPACE "/apps/modest"
#include "modest-tny-msg.h"
static gboolean init_header_columns (ModestConf *conf, gboolean overwrite);
-static gboolean init_local_folders (void);
static gboolean init_default_account_maybe (ModestAccountMgr *acc_mgr);
static void init_i18n (void);
static void init_stock_icons (void);
init_default_settings (modest_runtime_get_conf ());
- if (!init_local_folders()) {
+ if (!modest_init_local_folders(NULL /* means $HOME */)) {
modest_init_uninit ();
g_printerr ("modest: failed to init local folders\n");
return FALSE;
}
/**
- * init_local_folders:
+ * modest_init_local_folders:
+ * @location_filepath: The location at which the local-folders directory should be created,
+ * or NULL to specify $HOME.
*
* create the Local Folders folder under cache, if they
* do not exist yet.
* Returns: TRUE if the folder were already there, or
* they were created, FALSE otherwise
*/
-static gboolean
-init_local_folders (void)
+gboolean
+modest_init_local_folders (const gchar* location_filepath)
{
- gchar *maildir_path = modest_local_folder_info_get_maildir_path ();
+ gchar *maildir_path = modest_local_folder_info_get_maildir_path (location_filepath);
/* Create each of the standard on-disk folders.
* Per-account outbox folders will be created when first needed. */
gboolean modest_init_uninit (void);
/**
+ * modest_init_local_folders:
+ * @location_filepath: The location at which the local-folders directory should be created,
+ * or NULL to specify $HOME.
+ *
+ * create the Local Folders folder under cache, if they
+ * do not exist yet.
+ *
+ * Returns: TRUE if the folder were already there, or
+ * they were created, FALSE otherwise
+ */
+gboolean modest_init_local_folders (const gchar* location_filepath);
+
+/**
* modest_init_one_local_folder:
*
* Create the directory structure for a maildir folder,
*/
gboolean modest_init_one_local_folder (gchar *maildir_path);
+
G_END_DECLS
#endif /*__MODEST_INIT_H__*/
gchar *
-modest_local_folder_info_get_maildir_path (void)
+modest_local_folder_info_get_maildir_path (const gchar* location_filepath)
{
- return g_build_filename (g_get_home_dir(),
+ return g_build_filename (location_filepath ? location_filepath : g_get_home_dir(),
MODEST_DIR,
MODEST_LOCAL_FOLDERS_MAILDIR,
NULL);
/**
* modest_local_folder_info_get_maildir_path
+ * @location_filepath: The path at which the local-folders directory exists,
+ * or NULL to specify $HOME
*
* Get the path to the Maildir where the local folders are stored.
*
* string, which must be freed by the caller.
*
*/
-gchar *modest_local_folder_info_get_maildir_path (void);
+gchar *modest_local_folder_info_get_maildir_path (const gchar* location_filepath);
/**
* modest_per_account_local_outbox_folder_info_get_maildir_path
#endif
#endif
+#include <libgnomevfs/gnome-vfs-volume-monitor.h>
+
/* 'private'/'protected' functions */
static void modest_tny_account_store_class_init (ModestTnyAccountStoreClass *klass);
//static void modest_tny_account_store_init (ModestTnyAccountStore *obj);
}
+
+static void
+on_vfs_volume_mounted(GnomeVFSVolumeMonitor *volume_monitor,
+ GnomeVFSVolume *volume, gpointer user_data);
+
+static void
+on_vfs_volume_unmounted(GnomeVFSVolumeMonitor *volume_monitor,
+ GnomeVFSVolume *volume, gpointer user_data);
+
static void
modest_tny_account_store_instance_init (ModestTnyAccountStore *obj)
{
*/
priv->password_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
+
+ /* Respond to volume mounts and unmounts, such
+ * as the insertion/removal of the memory card: */
+ GnomeVFSVolumeMonitor* monitor =
+ gnome_vfs_get_volume_monitor();
+ g_signal_connect (G_OBJECT(monitor), "volume-mounted",
+ G_CALLBACK(on_vfs_volume_mounted),
+ obj);
+ g_signal_connect (G_OBJECT(monitor), "volume-unmounted",
+ G_CALLBACK(on_vfs_volume_unmounted),
+ obj);
}
-
-
static void
account_list_free (GSList *accounts)
{
g_slist_free (accounts);
}
+static void
+recreate_all_accounts (ModestTnyAccountStore *self)
+{
+ ModestTnyAccountStorePrivate *priv =
+ MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
+
+ if (priv->store_accounts) {
+ account_list_free (priv->store_accounts);
+ priv->store_accounts = NULL;
+ get_server_accounts (TNY_ACCOUNT_STORE(self),
+ NULL, TNY_ACCOUNT_TYPE_STORE);
+ }
+
+ if (priv->transport_accounts) {
+ account_list_free (priv->transport_accounts);
+ priv->transport_accounts = NULL;
+ get_server_accounts (TNY_ACCOUNT_STORE(self), NULL,
+ TNY_ACCOUNT_TYPE_TRANSPORT);
+ }
+}
+
+static void
+on_vfs_volume_mounted(GnomeVFSVolumeMonitor *volume_monitor,
+ GnomeVFSVolume *volume, gpointer user_data)
+{
+ ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
+
+ /* Check whether this was the external MMC1 card: */
+ gchar *uri = gnome_vfs_volume_get_activation_uri (volume);
+ if (uri && (strcmp (uri, MODEST_MCC1_VOLUMEPATH_URI) == 0)) {
+ printf ("DEBUG: %s: MMC1 card mounted.\n", __FUNCTION__);
+
+ /* TODO: Just add an account and emit (and respond to)
+ * TnyAccountStore::accountinserted signal?
+ */
+ recreate_all_accounts (self);
+
+ g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
+ NULL);
+ }
+
+ g_free (uri);
+}
+
+static void
+on_vfs_volume_unmounted(GnomeVFSVolumeMonitor *volume_monitor,
+ GnomeVFSVolume *volume, gpointer user_data)
+{
+ ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
+
+ /* Check whether this was the external MMC1 card: */
+ gchar *uri = gnome_vfs_volume_get_activation_uri (volume);
+ if (uri && (strcmp (uri, MODEST_MCC1_VOLUMEPATH_URI) == 0)) {
+ printf ("DEBUG: %s: MMC1 card unmounted.\n", __FUNCTION__);
+
+ /* TODO: Just add an account and emit (and respond to)
+ * TnyAccountStore::accountinserted signal?
+ */
+ recreate_all_accounts (self);
+
+ g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
+ NULL);
+ }
+
+ g_free (uri);
+}
static void
on_account_removed (ModestAccountMgr *acc_mgr, const gchar *account, gboolean server_account,
gpointer user_data)
{
- ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
- ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
-
+ ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
+
/* FIXME: make this more finegrained; changes do not really affect _all_
* accounts, and some do not affect tny accounts at all (such as 'last_update')
*/
-
- account_list_free (priv->store_accounts);
- get_server_accounts (TNY_ACCOUNT_STORE(self), NULL, TNY_ACCOUNT_TYPE_STORE);
-
- account_list_free (priv->transport_accounts);
- get_server_accounts (TNY_ACCOUNT_STORE(self), NULL,
- TNY_ACCOUNT_TYPE_TRANSPORT);
-
- /* TODO: Ref these when we add them? */
- g_slist_free (priv->store_accounts_outboxes);
- priv->store_accounts_outboxes = NULL;
+ if (server_account)
+ recreate_all_accounts (self);
g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
account);
}
-
static void
on_account_changed (ModestAccountMgr *acc_mgr, const gchar *account,
const gchar *key, gboolean server_account, gpointer user_data)
{
ModestTnyAccountStore *self = MODEST_TNY_ACCOUNT_STORE(user_data);
- ModestTnyAccountStorePrivate *priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
/* Ignore the change if it's a change in the last_updated value */
if (g_str_has_suffix (key, MODEST_ACCOUNT_LAST_UPDATED))
/* FIXME: make this more finegrained; changes do not really affect _all_
* accounts, and some do not affect tny accounts at all (such as 'last_update')
*/
- if (server_account) {
- if (priv->store_accounts) {
- account_list_free (priv->store_accounts);
- priv->store_accounts = NULL;
- get_server_accounts (TNY_ACCOUNT_STORE(self),
- NULL, TNY_ACCOUNT_TYPE_STORE);
- }
-
- if (priv->transport_accounts) {
- account_list_free (priv->transport_accounts);
- priv->transport_accounts = NULL;
- get_server_accounts (TNY_ACCOUNT_STORE(self), NULL,
- TNY_ACCOUNT_TYPE_TRANSPORT);
- }
- }
+ if (server_account)
+ recreate_all_accounts (self);
g_signal_emit (G_OBJECT(self), signals[ACCOUNT_UPDATE_SIGNAL], 0,
account);
if (type == TNY_ACCOUNT_TYPE_STORE) {
/* Also add the local folder pseudo-account: */
TnyAccount *tny_account =
- modest_tny_account_new_for_local_folders (priv->account_mgr, priv->session);
+ modest_tny_account_new_for_local_folders (priv->account_mgr,
+ priv->session, NULL);
if (list)
tny_list_prepend (list, G_OBJECT(tny_account));
accounts = g_slist_append (accounts, tny_account); /* cache it */
+
+
+ /* Also add the Memory card account if it is mounted: */
+ gboolean mmc_is_mounted = FALSE;
+ GnomeVFSVolumeMonitor* monitor =
+ gnome_vfs_get_volume_monitor();
+ GList* list_volumes = gnome_vfs_volume_monitor_get_mounted_volumes (monitor);
+ GList *iter = list_volumes;
+ while (iter) {
+ GnomeVFSVolume *volume = (GnomeVFSVolume*)iter->data;
+ if (volume) {
+ if (!mmc_is_mounted) {
+ gchar *uri = gnome_vfs_volume_get_activation_uri (volume);
+ if (uri && (strcmp (uri, MODEST_MCC1_VOLUMEPATH_URI) == 0)) {
+ mmc_is_mounted = TRUE;
+ }
+ g_free (uri);
+ }
+
+ gnome_vfs_volume_unref(volume);
+ }
+
+ iter = g_list_next (iter);
+ }
+ g_list_free (list_volumes);
+
+ if (mmc_is_mounted) {
+ TnyAccount *tny_account =
+ modest_tny_account_new_for_local_folders (priv->account_mgr,
+ priv->session, MODEST_MCC1_VOLUMEPATH);
+ if (list)
+ tny_list_prepend (list, G_OBJECT(tny_account));
+ accounts = g_slist_append (accounts, tny_account); /* cache it */
+ }
}
/* And add the connection-specific transport accounts, if any.
if (!account)
g_printerr ("modest: could not get tny %s account for %s (id=%s)\n",
- type == TNY_ACCOUNT_TYPE_STORE? "store" : "transport",
+ type == TNY_ACCOUNT_TYPE_STORE ? "store" : "transport",
account_name, id ? id : "<none>");
return account;
#include <tny-camel-imap-store-account.h>
#include <tny-camel-pop-store-account.h>
#include <tny-folder-stats.h>
+#include <string.h>
TnyFolder *
return tny_account;
}
+#if 0
+static void
+on_modest_file_system_info(HildonFileSystemInfoHandle *handle,
+ HildonFileSystemInfo *info,
+ const GError *error, gpointer data)
+{
+ if (info) {
+ printf("DEBUG: %s: display name=%s\n", __FUNCTION__,
+ hildon_file_system_info_get_display_name(info));
+ }
+ else {
+ printf("DEBUG: %s: info is NULL.\n", __FUNCTION__);
+ }
+
+ if (error) {
+ printf (" DEBUG: error=%s\n", error->message);
+ }
+}
+#endif
+
TnyAccount*
-modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySessionCamel *session)
+modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr, TnySessionCamel *session, const gchar* location_filepath)
{
+ /* Make sure that the directories exist: */
+ modest_init_local_folders (location_filepath);
+
TnyStoreAccount *tny_account;
CamelURL *url;
gchar *maildir, *url_string;
/* This path contains directories for each local folder.
* We have created them so that TnyCamelStoreAccount can find them
* and report a folder for each directory: */
- maildir = modest_local_folder_info_get_maildir_path ();
+ maildir = modest_local_folder_info_get_maildir_path (location_filepath);
url = camel_url_new ("maildir:", NULL);
camel_url_set_path (url, maildir);
/* Needed by tinymail's DBC assertions */
tny_account_set_url_string (TNY_ACCOUNT(tny_account), url_string);
printf("DEBUG: %s:\n url=%s\n", __FUNCTION__, url_string);
- tny_account_set_name (TNY_ACCOUNT(tny_account), MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME);
- tny_account_set_id (TNY_ACCOUNT(tny_account), MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID);
- tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_pass_dummy);
+ /* TODO: Use a more generic way of identifying memory card paths,
+ * and of marking accounts as memory card accounts, maybe
+ * via a derived TnyCamelStoreAccount ? */
+ const gboolean is_mmc =
+ location_filepath &&
+ (strcmp (location_filepath, MODEST_MCC1_VOLUMEPATH) == 0);
+
+ /* TODO: Use hildon_file_system_info_async_new() to get the display name? */
+#if 0
+ const gchar *uri = "file:///media/mmc1";
+ /* HildonFileSystemInfoHandle *async_handle = */
+ hildon_file_system_info_async_new(uri,
+ on_modest_file_system_info, NULL /* user_data */);
+#endif
+
+ const gchar *name = is_mmc ? _("Memory Card") :
+ MODEST_LOCAL_FOLDERS_DEFAULT_DISPLAY_NAME;
+ tny_account_set_name (TNY_ACCOUNT(tny_account), name);
+
+ const gchar* id = is_mmc ? MODEST_MMC_ACCOUNT_ID :
+ MODEST_ACTUAL_LOCAL_FOLDERS_ACCOUNT_ID;
+ tny_account_set_id (TNY_ACCOUNT(tny_account), id);
+
+ tny_account_set_forget_pass_func (TNY_ACCOUNT(tny_account), forget_pass_dummy);
tny_account_set_pass_func (TNY_ACCOUNT(tny_account), get_pass_dummy);
modest_tny_account_set_parent_modest_account_name_for_server_account (
* modest_tny_account_new_for_local_folders:
* @account_mgr: a valid account mgr instance
* @session: a tny camel session
+ * @location_filepath: The location at which the local-folders directory exists, or NULL to specify $HOME.
*
* get the local folders (pseudo) account; you should only need one such account.
*
* Returns: a new local folders TnyAccount or NULL in case of error.
*/
TnyAccount* modest_tny_account_new_for_local_folders (ModestAccountMgr *account_mgr,
- TnySessionCamel *session);
+ TnySessionCamel *session,
+ const gchar* location_filepath);
/**
* modest_tny_account_new_for_per_account_local_outbox_folder: