Logo Search packages:      
Sourcecode: mail-notification version File versions

mn-message.c

/* Generated by GOB (v2.0.11) on Sun Mar  6 22:34:28 2005
   (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 11

#define selfp (self->_priv)

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

#include "mn-message.h"

#include "mn-message-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 26 "mn-message.gob"

#include "config.h"
#include <glib/gi18n.h>
#include "mn-util.h"

#line 33 "mn-message.c"
/* self casting macros */
#define SELF(x) MN_MESSAGE(x)
#define SELF_CONST(x) MN_MESSAGE_CONST(x)
#define IS_SELF(x) MN_IS_MESSAGE(x)
#define TYPE_SELF MN_TYPE_MESSAGE
#define SELF_CLASS(x) MN_MESSAGE_CLASS(x)

#define SELF_GET_CLASS(x) MN_MESSAGE_GET_CLASS(x)

/* self typedefs */
typedef MNMessage Self;
typedef MNMessageClass SelfClass;

/* here are local prototypes */
static void ___object_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void ___object_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void mn_message_init (MNMessage * o) G_GNUC_UNUSED;
static void mn_message_class_init (MNMessageClass * c) G_GNUC_UNUSED;
static GObject * ___1_mn_message_constructor (GType type, unsigned int n_construct_properties, GObjectConstructParam * construct_params) G_GNUC_UNUSED;
static int mn_message_slist_find_by_id_compare_func (gconstpointer a, gconstpointer b) G_GNUC_UNUSED;
static int mn_message_slist_sort_by_sent_time_compare_func (gconstpointer a, gconstpointer b) G_GNUC_UNUSED;

enum {
      PROP_0,
      PROP_MAILBOX_URI,
      PROP_ERROR,
      PROP_SENT_TIME,
      PROP_ID,
      PROP_FROM,
      PROP_SUBJECT
};

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

/* Short form macros */
#define self_format_sent_time mn_message_format_sent_time
#define self_new mn_message_new
#define self_new_from_error mn_message_new_from_error
#define self_slist_find_by_id mn_message_slist_find_by_id
#define self_slist_find_by_id_compare_func mn_message_slist_find_by_id_compare_func
#define self_slist_sort_by_sent_time mn_message_slist_sort_by_sent_time
#define self_slist_sort_by_sent_time_compare_func mn_message_slist_sort_by_sent_time_compare_func
GType
mn_message_get_type (void)
{
      static GType type = 0;

      if ___GOB_UNLIKELY(type == 0) {
            static const GTypeInfo info = {
                  sizeof (MNMessageClass),
                  (GBaseInitFunc) NULL,
                  (GBaseFinalizeFunc) NULL,
                  (GClassInitFunc) mn_message_class_init,
                  (GClassFinalizeFunc) NULL,
                  NULL /* class_data */,
                  sizeof (MNMessage),
                  0 /* n_preallocs */,
                  (GInstanceInitFunc) mn_message_init,
                  NULL
            };

            type = g_type_register_static (G_TYPE_OBJECT, "MNMessage", &info, (GTypeFlags)0);
      }

      return type;
}

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

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


static void
___dispose (GObject *obj_self)
{
#define __GOB_FUNCTION__ "MN:Message::dispose"
      MNMessage *self G_GNUC_UNUSED = MN_MESSAGE (obj_self);
      if (G_OBJECT_CLASS (parent_class)->dispose) \
            (* G_OBJECT_CLASS (parent_class)->dispose) (obj_self);
#line 35 "mn-message.gob"
      if(self->mailbox_uri) { g_object_unref ((gpointer) self->mailbox_uri); self->mailbox_uri = NULL; }
#line 129 "mn-message.c"
}
#undef __GOB_FUNCTION__


static void
___finalize(GObject *obj_self)
{
#define __GOB_FUNCTION__ "MN:Message::finalize"
      MNMessage *self G_GNUC_UNUSED = MN_MESSAGE (obj_self);
      if(G_OBJECT_CLASS(parent_class)->finalize) \
            (* G_OBJECT_CLASS(parent_class)->finalize)(obj_self);
#line 41 "mn-message.gob"
      if(self->error) { g_free ((gpointer) self->error); self->error = NULL; }
#line 143 "mn-message.c"
#line 49 "mn-message.gob"
      if(self->id) { g_free ((gpointer) self->id); self->id = NULL; }
#line 146 "mn-message.c"
#line 53 "mn-message.gob"
      if(self->from) { g_free ((gpointer) self->from); self->from = NULL; }
#line 149 "mn-message.c"
#line 57 "mn-message.gob"
      if(self->subject) { g_free ((gpointer) self->subject); self->subject = NULL; }
#line 152 "mn-message.c"
}
#undef __GOB_FUNCTION__

static void 
mn_message_init (MNMessage * o G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "MN:Message::init"
}
#undef __GOB_FUNCTION__
static void 
mn_message_class_init (MNMessageClass * c G_GNUC_UNUSED)
{
#define __GOB_FUNCTION__ "MN:Message::class_init"
      GObjectClass *g_object_class G_GNUC_UNUSED = (GObjectClass*) c;

      parent_class = g_type_class_ref (G_TYPE_OBJECT);

#line 60 "mn-message.gob"
      g_object_class->constructor = ___1_mn_message_constructor;
#line 172 "mn-message.c"
      g_object_class->dispose = ___dispose;
      g_object_class->finalize = ___finalize;
      g_object_class->get_property = ___object_get_property;
      g_object_class->set_property = ___object_set_property;
    {
      GParamSpec   *param_spec;

      param_spec = g_param_spec_object
            ("mailbox_uri" /* name */,
             NULL /* nick */,
             NULL /* blurb */,
             MN_TYPE_URI /* object_type */,
             (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
      g_object_class_install_property (g_object_class,
            PROP_MAILBOX_URI,
            param_spec);
      param_spec = g_param_spec_string
            ("error" /* name */,
             NULL /* nick */,
             NULL /* blurb */,
             NULL /* default_value */,
             (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
      g_object_class_install_property (g_object_class,
            PROP_ERROR,
            param_spec);
      param_spec = g_param_spec_ulong
            ("sent_time" /* name */,
             NULL /* nick */,
             NULL /* blurb */,
             0 /* minimum */,
             G_MAXULONG /* maximum */,
             0 /* default_value */,
             (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
      g_object_class_install_property (g_object_class,
            PROP_SENT_TIME,
            param_spec);
      param_spec = g_param_spec_string
            ("id" /* name */,
             NULL /* nick */,
             NULL /* blurb */,
             NULL /* default_value */,
             (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
      g_object_class_install_property (g_object_class,
            PROP_ID,
            param_spec);
      param_spec = g_param_spec_string
            ("from" /* name */,
             NULL /* nick */,
             NULL /* blurb */,
             NULL /* default_value */,
             (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
      g_object_class_install_property (g_object_class,
            PROP_FROM,
            param_spec);
      param_spec = g_param_spec_string
            ("subject" /* name */,
             NULL /* nick */,
             NULL /* blurb */,
             NULL /* default_value */,
             (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
      g_object_class_install_property (g_object_class,
            PROP_SUBJECT,
            param_spec);
    }
}
#undef __GOB_FUNCTION__

static void
___object_set_property (GObject *object,
      guint property_id,
      const GValue *VAL G_GNUC_UNUSED,
      GParamSpec *pspec G_GNUC_UNUSED)
#define __GOB_FUNCTION__ "MN:Message::set_property"
{
      MNMessage *self G_GNUC_UNUSED;

      self = MN_MESSAGE (object);

      switch (property_id) {
      case PROP_MAILBOX_URI:
            {
#line 36 "mn-message.gob"
{ GObject *___old = (GObject *)self->mailbox_uri; self->mailbox_uri = (MNURI *)g_value_dup_object (VAL); if (___old != NULL) { g_object_unref (G_OBJECT (___old)); } }
#line 256 "mn-message.c"
            }
            break;
      case PROP_ERROR:
            {
#line 42 "mn-message.gob"
{ char *old = self->error; self->error = g_value_dup_string (VAL); g_free (old); }
#line 263 "mn-message.c"
            }
            break;
      case PROP_SENT_TIME:
            {
#line 46 "mn-message.gob"
self->sent_time = g_value_get_ulong (VAL);
#line 270 "mn-message.c"
            }
            break;
      case PROP_ID:
            {
#line 50 "mn-message.gob"
{ char *old = self->id; self->id = g_value_dup_string (VAL); g_free (old); }
#line 277 "mn-message.c"
            }
            break;
      case PROP_FROM:
            {
#line 54 "mn-message.gob"
{ char *old = self->from; self->from = g_value_dup_string (VAL); g_free (old); }
#line 284 "mn-message.c"
            }
            break;
      case PROP_SUBJECT:
            {
#line 58 "mn-message.gob"
{ char *old = self->subject; self->subject = g_value_dup_string (VAL); g_free (old); }
#line 291 "mn-message.c"
            }
            break;
      default:
/* Apparently in g++ this is needed, glib is b0rk */
#ifndef __PRETTY_FUNCTION__
#  undef G_STRLOC
#  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__)
#endif
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
            break;
      }
}
#undef __GOB_FUNCTION__

static void
___object_get_property (GObject *object,
      guint property_id,
      GValue *VAL G_GNUC_UNUSED,
      GParamSpec *pspec G_GNUC_UNUSED)
#define __GOB_FUNCTION__ "MN:Message::get_property"
{
      MNMessage *self G_GNUC_UNUSED;

      self = MN_MESSAGE (object);

      switch (property_id) {
      case PROP_MAILBOX_URI:
            {
#line 36 "mn-message.gob"
g_value_set_object (VAL, (gpointer)self->mailbox_uri);
#line 322 "mn-message.c"
            }
            break;
      case PROP_ERROR:
            {
#line 42 "mn-message.gob"
g_value_set_string (VAL, self->error);
#line 329 "mn-message.c"
            }
            break;
      case PROP_SENT_TIME:
            {
#line 46 "mn-message.gob"
g_value_set_ulong (VAL, self->sent_time);
#line 336 "mn-message.c"
            }
            break;
      case PROP_ID:
            {
#line 50 "mn-message.gob"
g_value_set_string (VAL, self->id);
#line 343 "mn-message.c"
            }
            break;
      case PROP_FROM:
            {
#line 54 "mn-message.gob"
g_value_set_string (VAL, self->from);
#line 350 "mn-message.c"
            }
            break;
      case PROP_SUBJECT:
            {
#line 58 "mn-message.gob"
g_value_set_string (VAL, self->subject);
#line 357 "mn-message.c"
            }
            break;
      default:
/* Apparently in g++ this is needed, glib is b0rk */
#ifndef __PRETTY_FUNCTION__
#  undef G_STRLOC
#  define G_STRLOC      __FILE__ ":" G_STRINGIFY (__LINE__)
#endif
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
            break;
      }
}
#undef __GOB_FUNCTION__



#line 60 "mn-message.gob"
static GObject * 
___1_mn_message_constructor (GType type G_GNUC_UNUSED, unsigned int n_construct_properties, GObjectConstructParam * construct_params)
#line 377 "mn-message.c"
#define PARENT_HANDLER(___type,___n_construct_properties,___construct_params) \
      ((G_OBJECT_CLASS(parent_class)->constructor)? \
            (* G_OBJECT_CLASS(parent_class)->constructor)(___type,___n_construct_properties,___construct_params): \
            ((GObject * )0))
{
#define __GOB_FUNCTION__ "MN:Message::constructor"
{
#line 62 "mn-message.gob"
      
    GObject *object;
    Self *self;

    object = PARENT_HANDLER(type, n_construct_properties, construct_params);
    self = SELF(object);

    if (! self->id)
      {
      GString *id;

      /*
       * An ID should (not mandatory):
       *
       *    - be unique, application-wise
       *    - persist across checks if the message does not change
       */

      id = g_string_new(NULL);

      if (self->sent_time)
        g_string_append_printf(id, ":sent-time:%u:", self->sent_time);
      if (self->from)
        g_string_append_printf(id, ":from:%s:", self->from);
      if (self->subject)
        g_string_append_printf(id, ":subject:%s:", self->subject);

      if (! *id->str)
        {
          static int unique = 0;
          g_string_append_printf(id, "%i", g_atomic_int_exchange_and_add(&unique, 1));
        }

      self->id = g_string_free(id, FALSE);
      }

    /* these must be filled after we have processed the id */

    if (! self->from)
      self->from = g_strdup(_("Unknown"));
    if (! self->subject)
      self->subject = g_strdup("");

    return object;
  }}
#line 431 "mn-message.c"
#undef __GOB_FUNCTION__
#undef PARENT_HANDLER

#line 108 "mn-message.gob"
char * 
mn_message_format_sent_time (MNMessage * self)
#line 438 "mn-message.c"
{
#define __GOB_FUNCTION__ "MN:Message::format_sent_time"
#line 108 "mn-message.gob"
      g_return_val_if_fail (self != NULL, (char * )0);
#line 108 "mn-message.gob"
      g_return_val_if_fail (MN_IS_MESSAGE (self), (char * )0);
#line 445 "mn-message.c"
{
#line 110 "mn-message.gob"
      
    char *formatted = NULL;

    if (self->sent_time)
      {
      time_t now;
      
      now = mn_time();
      if (now > 0)
        {
          time_t diff;
          
          diff = now - self->sent_time;
          if (diff >= 0)
            {
            if (diff < 60)
              formatted = g_strdup_printf(ngettext("%i second ago", "%i seconds ago", diff), diff);
            else if (diff < 60 * 60)
              {
                int minutes = diff / 60;
                formatted = g_strdup_printf(ngettext("about %i minute ago", "about %i minutes ago", minutes), minutes);
              }
            else if (diff < 60 * 60 * 24)
              {
                int hours = diff / (60 * 60);
                formatted = g_strdup_printf(ngettext("about %i hour ago", "about %i hours ago", hours), hours);
              }
            else if (diff < 60 * 60 * 24 * 7)
              {
                int days = diff / (60 * 60 * 24);
                formatted = g_strdup_printf(ngettext("about %i day ago", "about %i days ago", days), days);
              }
            else
              {
                int weeks = diff / (60 * 60 * 24 * 7);
                formatted = g_strdup_printf(ngettext("about %i week ago", "about %i weeks ago", weeks), weeks);
              }
            }
        }
      }

    return formatted;
  }}
#line 491 "mn-message.c"
#undef __GOB_FUNCTION__

#line 154 "mn-message.gob"
MNMessage * 
mn_message_new (MNURI * mailbox_uri, const char * error, time_t sent_time, const char * id, const char * from, const char * subject)
#line 497 "mn-message.c"
{
#define __GOB_FUNCTION__ "MN:Message::new"
#line 154 "mn-message.gob"
      g_return_val_if_fail (mailbox_uri != NULL, (MNMessage * )0);
#line 154 "mn-message.gob"
      g_return_val_if_fail (MN_IS_URI (mailbox_uri), (MNMessage * )0);
#line 504 "mn-message.c"
{
#line 161 "mn-message.gob"
      
    return GET_NEW_VARG(MN_MESSAGE_PROP_MAILBOX_URI(G_OBJECT(mailbox_uri)),
                  MN_MESSAGE_PROP_ERROR((char *) error),
                  MN_MESSAGE_PROP_SENT_TIME(sent_time),
                  MN_MESSAGE_PROP_ID((char *) id),
                  MN_MESSAGE_PROP_FROM((char *) from),
                  MN_MESSAGE_PROP_SUBJECT((char *) subject),
                  NULL);
  }}
#line 516 "mn-message.c"
#undef __GOB_FUNCTION__

#line 171 "mn-message.gob"
MNMessage * 
mn_message_new_from_error (MNURI * mailbox_uri, const char * error)
#line 522 "mn-message.c"
{
#define __GOB_FUNCTION__ "MN:Message::new_from_error"
#line 171 "mn-message.gob"
      g_return_val_if_fail (mailbox_uri != NULL, (MNMessage * )0);
#line 171 "mn-message.gob"
      g_return_val_if_fail (MN_IS_URI (mailbox_uri), (MNMessage * )0);
#line 171 "mn-message.gob"
      g_return_val_if_fail (error != NULL, (MNMessage * )0);
#line 531 "mn-message.c"
{
#line 174 "mn-message.gob"
      
    return self_new(mailbox_uri, error, 0, NULL, NULL, NULL);
  }}
#line 537 "mn-message.c"
#undef __GOB_FUNCTION__

#line 178 "mn-message.gob"
GSList * 
mn_message_slist_find_by_id (GSList * list, MNMessage * self)
#line 543 "mn-message.c"
{
#define __GOB_FUNCTION__ "MN:Message::slist_find_by_id"
#line 178 "mn-message.gob"
      g_return_val_if_fail (self != NULL, (GSList * )0);
#line 178 "mn-message.gob"
      g_return_val_if_fail (MN_IS_MESSAGE (self), (GSList * )0);
#line 550 "mn-message.c"
{
#line 180 "mn-message.gob"
      
    return g_slist_find_custom(list, self, self_slist_find_by_id_compare_func);
  }}
#line 556 "mn-message.c"
#undef __GOB_FUNCTION__

#line 184 "mn-message.gob"
static int 
mn_message_slist_find_by_id_compare_func (gconstpointer a, gconstpointer b)
#line 562 "mn-message.c"
{
#define __GOB_FUNCTION__ "MN:Message::slist_find_by_id_compare_func"
{
#line 186 "mn-message.gob"
      
    Self *message_a = (Self *) a;
    Self *message_b = (Self *) b;

    return strcmp(message_a->id, message_b->id);
  }}
#line 573 "mn-message.c"
#undef __GOB_FUNCTION__

#line 193 "mn-message.gob"
GSList * 
mn_message_slist_sort_by_sent_time (GSList * list)
#line 579 "mn-message.c"
{
#define __GOB_FUNCTION__ "MN:Message::slist_sort_by_sent_time"
{
#line 195 "mn-message.gob"
      
    return g_slist_sort(list, self_slist_sort_by_sent_time_compare_func);
  }}
#line 587 "mn-message.c"
#undef __GOB_FUNCTION__

#line 199 "mn-message.gob"
static int 
mn_message_slist_sort_by_sent_time_compare_func (gconstpointer a, gconstpointer b)
#line 593 "mn-message.c"
{
#define __GOB_FUNCTION__ "MN:Message::slist_sort_by_sent_time_compare_func"
{
#line 201 "mn-message.gob"
      
    Self *message_a = (Self *) a;
    Self *message_b = (Self *) b;

    return message_a->sent_time - message_b->sent_time;
  }}
#line 604 "mn-message.c"
#undef __GOB_FUNCTION__

Generated by  Doxygen 1.6.0   Back to index