/* Generated by GOB (v2.0.15)   (do not edit directly) */

/* End world hunger, donate to the World Food Programme, http://www.wfp.org */

#define GOB_VERSION_MAJOR 2
#define GOB_VERSION_MINOR 0
#define GOB_VERSION_PATCHLEVEL 15

#define selfp (self->_priv)

#include <string.h> /* memset() */

#include "mn-system-vfs-mailbox.h"

#include "mn-system-vfs-mailbox-private.h"

#ifdef G_LIKELY
#define ___GOB_LIKELY(expr) G_LIKELY(expr)
#define ___GOB_UNLIKELY(expr) G_UNLIKELY(expr)
#else /* ! G_LIKELY */
#define ___GOB_LIKELY(expr) (expr)
#define ___GOB_UNLIKELY(expr) (expr)
#endif /* G_LIKELY */

#line 24 "src/mn-system-vfs-mailbox.gob"

#include <glib/gi18n.h>
#include "mn-stock.h"
#include "mn-mailbox-private.h"

#line 32 "mn-system-vfs-mailbox.c"
/* self casting macros */
#define SELF(x) MN_SYSTEM_VFS_MAILBOX(x)
#define SELF_CONST(x) MN_SYSTEM_VFS_MAILBOX_CONST(x)
#define IS_SELF(x) MN_IS_SYSTEM_VFS_MAILBOX(x)
#define TYPE_SELF MN_TYPE_SYSTEM_VFS_MAILBOX
#define SELF_CLASS(x) MN_SYSTEM_VFS_MAILBOX_CLASS(x)

#define SELF_GET_CLASS(x) MN_SYSTEM_VFS_MAILBOX_GET_CLASS(x)

/* self typedefs */
typedef MNSystemVFSMailbox Self;
typedef MNSystemVFSMailboxClass SelfClass;

/* here are local prototypes */
#line 0 "src/mn-system-vfs-mailbox.gob"
static void mn_system_vfs_mailbox_init (MNSystemVFSMailbox * o);
#line 49 "mn-system-vfs-mailbox.c"
#line 32 "src/mn-system-vfs-mailbox.gob"
static void mn_system_vfs_mailbox_class_init (MNSystemVFSMailboxClass * class);
#line 52 "mn-system-vfs-mailbox.c"
#line 37 "src/mn-system-vfs-mailbox.gob"
static void ___2_mn_system_vfs_mailbox_seal (MNMailbox * mailbox);
#line 55 "mn-system-vfs-mailbox.c"
#line 49 "src/mn-system-vfs-mailbox.gob"
static MNMailbox * ___3_mn_system_vfs_mailbox_parse_uri (MNMailbox * dummy, const char * uri);
#line 58 "mn-system-vfs-mailbox.c"
#line 62 "src/mn-system-vfs-mailbox.gob"
static void ___4_mn_system_vfs_mailbox_check (MNMailbox * mailbox);
#line 61 "mn-system-vfs-mailbox.c"

/* pointer to the class of our parent */
static MNVFSMailboxClass *parent_class = NULL;

/* Short form macros */
#define self_get_uri mn_system_vfs_mailbox_get_uri
GType
mn_system_vfs_mailbox_get_type (void)
{
	static GType type = 0;

	if ___GOB_UNLIKELY(type == 0) {
		static const GTypeInfo info = {
			sizeof (MNSystemVFSMailboxClass),
			(GBaseInitFunc) NULL,
			(GBaseFinalizeFunc) NULL,
			(GClassInitFunc) mn_system_vfs_mailbox_class_init,
			(GClassFinalizeFunc) NULL,
			NULL /* class_data */,
			sizeof (MNSystemVFSMailbox),
			0 /* n_preallocs */,
			(GInstanceInitFunc) mn_system_vfs_mailbox_init,
			NULL
		};

		type = g_type_register_static (MN_TYPE_VFS_MAILBOX, "MNSystemVFSMailbox", &info, (GTypeFlags)0);
	}

	return type;
}

/* a macro for creating a new object of our type */
#define GET_NEW ((MNSystemVFSMailbox *)g_object_new(mn_system_vfs_mailbox_get_type(), NULL))

/* a function for creating a new object of our type */
#include <stdarg.h>
static MNSystemVFSMailbox * GET_NEW_VARG (const char *first, ...) G_GNUC_UNUSED;
static MNSystemVFSMailbox *
GET_NEW_VARG (const char *first, ...)
{
	MNSystemVFSMailbox *ret;
	va_list ap;
	va_start (ap, first);
	ret = (MNSystemVFSMailbox *)g_object_new_valist (mn_system_vfs_mailbox_get_type (), first, ap);
	va_end (ap);
	return ret;
}

static void 
mn_system_vfs_mailbox_init (MNSystemVFSMailbox * o G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "MN:System:VFS:Mailbox::init"
}
#undef __GOB_FUNCTION__
#line 32 "src/mn-system-vfs-mailbox.gob"
static void 
mn_system_vfs_mailbox_class_init (MNSystemVFSMailboxClass * class G_GNUC_UNUSED)
{
#line 120 "mn-system-vfs-mailbox.c"
#define __GOB_FUNCTION__ "MN:System:VFS:Mailbox::class_init"
	MNMailboxClass *mn_mailbox_class = (MNMailboxClass *)class;

	parent_class = g_type_class_ref (MN_TYPE_VFS_MAILBOX);

#line 37 "src/mn-system-vfs-mailbox.gob"
	mn_mailbox_class->seal = ___2_mn_system_vfs_mailbox_seal;
#line 49 "src/mn-system-vfs-mailbox.gob"
	mn_mailbox_class->parse_uri = ___3_mn_system_vfs_mailbox_parse_uri;
#line 62 "src/mn-system-vfs-mailbox.gob"
	mn_mailbox_class->check = ___4_mn_system_vfs_mailbox_check;
#line 132 "mn-system-vfs-mailbox.c"
 {
#line 33 "src/mn-system-vfs-mailbox.gob"

    MN_MAILBOX_CLASS(class)->type = "system-vfs";
  
#line 138 "mn-system-vfs-mailbox.c"
 }
}
#undef __GOB_FUNCTION__



#line 37 "src/mn-system-vfs-mailbox.gob"
static void 
___2_mn_system_vfs_mailbox_seal (MNMailbox * mailbox G_GNUC_UNUSED)
#line 148 "mn-system-vfs-mailbox.c"
#define PARENT_HANDLER(___mailbox) \
	{ if(MN_MAILBOX_CLASS(parent_class)->seal) \
		(* MN_MAILBOX_CLASS(parent_class)->seal)(___mailbox); }
{
#define __GOB_FUNCTION__ "MN:System:VFS:Mailbox::seal"
{
#line 39 "src/mn-system-vfs-mailbox.gob"
	
    mn_mailbox_set_stock_id(mailbox, MN_STOCK_SYSTEM_MAILBOX);

    MN_VFS_MAILBOX(mailbox)->uri = g_strdup(self_get_uri());

    mailbox->runtime_name = g_strdup(_("System mailbox"));

    PARENT_HANDLER(mailbox);
  }}
#line 165 "mn-system-vfs-mailbox.c"
#undef __GOB_FUNCTION__
#undef PARENT_HANDLER

#line 49 "src/mn-system-vfs-mailbox.gob"
static MNMailbox * 
___3_mn_system_vfs_mailbox_parse_uri (MNMailbox * dummy G_GNUC_UNUSED, const char * uri)
#line 172 "mn-system-vfs-mailbox.c"
#define PARENT_HANDLER(___dummy,___uri) \
	((MN_MAILBOX_CLASS(parent_class)->parse_uri)? \
		(* MN_MAILBOX_CLASS(parent_class)->parse_uri)(___dummy,___uri): \
		((MNMailbox * )0))
{
#define __GOB_FUNCTION__ "MN:System:VFS:Mailbox::parse_uri"
{
#line 51 "src/mn-system-vfs-mailbox.gob"
	
    const char *system_uri;
    MNMailbox *mailbox = NULL;

    system_uri = self_get_uri();
    if (system_uri && gnome_vfs_uris_match(uri, system_uri))
      mailbox = mn_mailbox_new("system-vfs", NULL);

    return mailbox;
  }}
#line 191 "mn-system-vfs-mailbox.c"
#undef __GOB_FUNCTION__
#undef PARENT_HANDLER

#line 62 "src/mn-system-vfs-mailbox.gob"
static void 
___4_mn_system_vfs_mailbox_check (MNMailbox * mailbox G_GNUC_UNUSED)
#line 198 "mn-system-vfs-mailbox.c"
#define PARENT_HANDLER(___mailbox) \
	{ if(MN_MAILBOX_CLASS(parent_class)->check) \
		(* MN_MAILBOX_CLASS(parent_class)->check)(___mailbox); }
{
#define __GOB_FUNCTION__ "MN:System:VFS:Mailbox::check"
{
#line 64 "src/mn-system-vfs-mailbox.gob"
	
    if (MN_VFS_MAILBOX(mailbox)->uri)
      {
	PARENT_HANDLER(mailbox);
      }
    else
      {
	mn_mailbox_set_error(mailbox, _("system mailbox not found"));
	mn_mailbox_set_poll(mailbox, FALSE); /* disable the mailbox */
      }
  }}
#line 217 "mn-system-vfs-mailbox.c"
#undef __GOB_FUNCTION__
#undef PARENT_HANDLER

#line 76 "src/mn-system-vfs-mailbox.gob"
const char * 
mn_system_vfs_mailbox_get_uri (void)
{
#line 225 "mn-system-vfs-mailbox.c"
#define __GOB_FUNCTION__ "MN:System:VFS:Mailbox::get_uri"
{
#line 78 "src/mn-system-vfs-mailbox.gob"
	
    static char *global_uri = NULL;
    G_LOCK_DEFINE_STATIC(global_uri);
    const char *uri;

    G_LOCK(global_uri);
    if (! global_uri)
      {
	const char *mail = g_getenv("MAIL");

	if (mail && g_path_is_absolute(mail) && g_file_test(mail, G_FILE_TEST_EXISTS))
	  global_uri = gnome_vfs_get_uri_from_local_path(mail);

	if (! global_uri)	/* no MAIL or invalid contents */
	  {
	    const char *username = g_get_user_name();
	    static const char *spool_paths[] = { "/var/spool/mail", "/var/mail" };
	    int i;

	    for (i = 0; i < G_N_ELEMENTS(spool_paths); i++)
	      {
		char *path;

		path = g_build_filename(spool_paths[i], username, NULL);
		if (g_file_test(path, G_FILE_TEST_EXISTS))
		  global_uri = gnome_vfs_get_uri_from_local_path(path);
		g_free(path);

		if (global_uri)
		  break;
	      }
	  }
      }
    uri = global_uri;
    G_UNLOCK(global_uri);

    return uri;
  }}
#line 267 "mn-system-vfs-mailbox.c"
#undef __GOB_FUNCTION__
