"Fossies" - the Fresh Open Source Software Archive

Member "evolution-mapi-3.46.1/src/camel/camel-mapi-message-info.c" (2 Dec 2022, 7893 Bytes) of package /linux/misc/evolution-mapi-3.46.1.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "camel-mapi-message-info.c" see the Fossies "Dox" file reference documentation.

    1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
    2 /*
    3  * Copyright (C) 2016 Red Hat, Inc. (www.redhat.com)
    4  *
    5  * This library is free software: you can redistribute it and/or modify it
    6  * under the terms of the GNU Lesser General Public License as published by
    7  * the Free Software Foundation.
    8  *
    9  * This library is distributed in the hope that it will be useful, but
   10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
   12  * for more details.
   13  *
   14  * You should have received a copy of the GNU Lesser General Public License
   15  * along with this library. If not, see <http://www.gnu.org/licenses/>.
   16  */
   17 
   18 #ifdef HAVE_CONFIG_H
   19 #include "config.h"
   20 #endif
   21 
   22 #include <stdio.h>
   23 
   24 #include "camel/camel.h"
   25 #include "camel-mapi-folder-summary.h"
   26 
   27 #include "camel-mapi-message-info.h"
   28 
   29 struct _CamelMapiMessageInfoPrivate {
   30     guint32 server_flags;
   31     gint64 last_modified; /* like time_t */
   32 };
   33 
   34 enum {
   35     PROP_0,
   36     PROP_SERVER_FLAGS,
   37     PROP_LAST_MODIFIED
   38 };
   39 
   40 G_DEFINE_TYPE_WITH_PRIVATE (CamelMapiMessageInfo, camel_mapi_message_info, CAMEL_TYPE_MESSAGE_INFO_BASE)
   41 
   42 static CamelMessageInfo *
   43 mapi_message_info_clone (const CamelMessageInfo *mi,
   44              CamelFolderSummary *assign_summary)
   45 {
   46     CamelMessageInfo *result;
   47 
   48     g_return_val_if_fail (CAMEL_IS_MAPI_MESSAGE_INFO (mi), NULL);
   49 
   50     result = CAMEL_MESSAGE_INFO_CLASS (camel_mapi_message_info_parent_class)->clone (mi, assign_summary);
   51     if (!result)
   52         return NULL;
   53 
   54     if (CAMEL_IS_MAPI_MESSAGE_INFO (result)) {
   55         CamelMapiMessageInfo *mmi, *mmi_result;
   56 
   57         mmi = CAMEL_MAPI_MESSAGE_INFO (mi);
   58         mmi_result = CAMEL_MAPI_MESSAGE_INFO (result);
   59 
   60         /* safe-guard that the mmi's filename doesn't change before it's copied to mmi_result */
   61         camel_message_info_property_lock (mi);
   62 
   63         camel_mapi_message_info_set_server_flags (mmi_result, camel_mapi_message_info_get_server_flags (mmi));
   64         camel_mapi_message_info_set_last_modified (mmi_result, camel_mapi_message_info_get_last_modified (mmi));
   65 
   66         camel_message_info_property_unlock (mi);
   67     }
   68 
   69     return result;
   70 }
   71 
   72 static gboolean
   73 mapi_message_info_load (CamelMessageInfo *mi,
   74             const CamelMIRecord *record,
   75             /* const */ gchar **bdata_ptr)
   76 {
   77     CamelMapiMessageInfo *mmi;
   78 
   79     g_return_val_if_fail (CAMEL_IS_MAPI_MESSAGE_INFO (mi), FALSE);
   80     g_return_val_if_fail (record != NULL, FALSE);
   81     g_return_val_if_fail (bdata_ptr != NULL, FALSE);
   82 
   83     if (!CAMEL_MESSAGE_INFO_CLASS (camel_mapi_message_info_parent_class)->load ||
   84         !CAMEL_MESSAGE_INFO_CLASS (camel_mapi_message_info_parent_class)->load (mi, record, bdata_ptr))
   85         return FALSE;
   86 
   87     mmi = CAMEL_MAPI_MESSAGE_INFO (mi);
   88 
   89     camel_mapi_message_info_set_server_flags (mmi, camel_util_bdata_get_number (bdata_ptr, 0));
   90     camel_mapi_message_info_set_last_modified (mmi, camel_util_bdata_get_number (bdata_ptr, 0));
   91 
   92     return TRUE;
   93 }
   94 
   95 static gboolean
   96 mapi_message_info_save (const CamelMessageInfo *mi,
   97             CamelMIRecord *record,
   98             GString *bdata_str)
   99 {
  100     CamelMapiMessageInfo *mmi;
  101 
  102     g_return_val_if_fail (CAMEL_IS_MAPI_MESSAGE_INFO (mi), FALSE);
  103     g_return_val_if_fail (record != NULL, FALSE);
  104     g_return_val_if_fail (bdata_str != NULL, FALSE);
  105 
  106     if (!CAMEL_MESSAGE_INFO_CLASS (camel_mapi_message_info_parent_class)->save ||
  107         !CAMEL_MESSAGE_INFO_CLASS (camel_mapi_message_info_parent_class)->save (mi, record, bdata_str))
  108         return FALSE;
  109 
  110     mmi = CAMEL_MAPI_MESSAGE_INFO (mi);
  111 
  112     camel_util_bdata_put_number (bdata_str, camel_mapi_message_info_get_server_flags (mmi));
  113     camel_util_bdata_put_number (bdata_str, camel_mapi_message_info_get_last_modified (mmi));
  114 
  115     return TRUE;
  116 }
  117 
  118 static void
  119 mapi_message_info_set_property (GObject *object,
  120                 guint property_id,
  121                 const GValue *value,
  122                 GParamSpec *pspec)
  123 {
  124     CamelMapiMessageInfo *mmi = CAMEL_MAPI_MESSAGE_INFO (object);
  125 
  126     switch (property_id) {
  127     case PROP_SERVER_FLAGS:
  128         camel_mapi_message_info_set_server_flags (mmi, g_value_get_uint (value));
  129         return;
  130 
  131     case PROP_LAST_MODIFIED:
  132         camel_mapi_message_info_set_last_modified (mmi, g_value_get_int64 (value));
  133         return;
  134     }
  135 
  136     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  137 }
  138 
  139 static void
  140 mapi_message_info_get_property (GObject *object,
  141                    guint property_id,
  142                    GValue *value,
  143                    GParamSpec *pspec)
  144 {
  145     CamelMapiMessageInfo *mmi = CAMEL_MAPI_MESSAGE_INFO (object);
  146 
  147     switch (property_id) {
  148     case PROP_SERVER_FLAGS:
  149         g_value_set_uint (value, camel_mapi_message_info_get_server_flags (mmi));
  150         return;
  151 
  152     case PROP_LAST_MODIFIED:
  153         g_value_set_int64 (value, camel_mapi_message_info_get_last_modified (mmi));
  154         return;
  155     }
  156 
  157     G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  158 }
  159 
  160 static void
  161 camel_mapi_message_info_class_init (CamelMapiMessageInfoClass *class)
  162 {
  163     CamelMessageInfoClass *mi_class;
  164     GObjectClass *object_class;
  165 
  166     mi_class = CAMEL_MESSAGE_INFO_CLASS (class);
  167     mi_class->clone = mapi_message_info_clone;
  168     mi_class->load = mapi_message_info_load;
  169     mi_class->save = mapi_message_info_save;
  170 
  171     object_class = G_OBJECT_CLASS (class);
  172     object_class->set_property = mapi_message_info_set_property;
  173     object_class->get_property = mapi_message_info_get_property;
  174 
  175     /**
  176      * CamelMapiMessageInfo:server-flags
  177      *
  178      * Flags of the message on the server.
  179      *
  180      * Since: 3.24
  181      **/
  182     g_object_class_install_property (
  183         object_class,
  184         PROP_SERVER_FLAGS,
  185         g_param_spec_uint (
  186             "server-flags",
  187             "Server Flags",
  188             NULL,
  189             0, G_MAXUINT32, 0,
  190             G_PARAM_READWRITE));
  191 
  192     /**
  193      * CamelMapiMessageInfo:last-modified
  194      *
  195      * PidTagLastModificationTime of this message.
  196      *
  197      * Since: 3.24
  198      **/
  199     g_object_class_install_property (
  200         object_class,
  201         PROP_LAST_MODIFIED,
  202         g_param_spec_int64 (
  203             "last-modified",
  204             "Last Modified",
  205             NULL,
  206             G_MININT64, G_MAXINT64, 0,
  207             G_PARAM_READWRITE));
  208 }
  209 
  210 static void
  211 camel_mapi_message_info_init (CamelMapiMessageInfo *mmi)
  212 {
  213     mmi->priv = camel_mapi_message_info_get_instance_private (mmi);
  214 }
  215 
  216 guint32
  217 camel_mapi_message_info_get_server_flags (const CamelMapiMessageInfo *mmi)
  218 {
  219     CamelMessageInfo *mi;
  220     guint32 result;
  221 
  222     g_return_val_if_fail (CAMEL_IS_MAPI_MESSAGE_INFO (mmi), 0);
  223 
  224     mi = CAMEL_MESSAGE_INFO (mmi);
  225 
  226     camel_message_info_property_lock (mi);
  227     result = mmi->priv->server_flags;
  228     camel_message_info_property_unlock (mi);
  229 
  230     return result;
  231 }
  232 
  233 gboolean
  234 camel_mapi_message_info_set_server_flags (CamelMapiMessageInfo *mmi,
  235                       guint32 server_flags)
  236 {
  237     CamelMessageInfo *mi;
  238     gboolean changed;
  239 
  240     g_return_val_if_fail (CAMEL_IS_MAPI_MESSAGE_INFO (mmi), FALSE);
  241 
  242     mi = CAMEL_MESSAGE_INFO (mmi);
  243 
  244     camel_message_info_property_lock (mi);
  245 
  246     changed = mmi->priv->server_flags != server_flags;
  247 
  248     if (changed)
  249         mmi->priv->server_flags = server_flags;
  250 
  251     camel_message_info_property_unlock (mi);
  252 
  253     if (changed && !camel_message_info_get_abort_notifications (mi)) {
  254         g_object_notify (G_OBJECT (mmi), "server-flags");
  255         camel_message_info_set_dirty (mi, TRUE);
  256     }
  257 
  258     return changed;
  259 }
  260 
  261 gint64
  262 camel_mapi_message_info_get_last_modified (const CamelMapiMessageInfo *mmi)
  263 {
  264     CamelMessageInfo *mi;
  265     gint64 result;
  266 
  267     g_return_val_if_fail (CAMEL_IS_MAPI_MESSAGE_INFO (mmi), 0);
  268 
  269     mi = CAMEL_MESSAGE_INFO (mmi);
  270 
  271     camel_message_info_property_lock (mi);
  272     result = mmi->priv->last_modified;
  273     camel_message_info_property_unlock (mi);
  274 
  275     return result;
  276 }
  277 
  278 gboolean
  279 camel_mapi_message_info_set_last_modified (CamelMapiMessageInfo *mmi,
  280                        gint64 last_modified)
  281 {
  282     CamelMessageInfo *mi;
  283     gboolean changed;
  284 
  285     g_return_val_if_fail (CAMEL_IS_MAPI_MESSAGE_INFO (mmi), FALSE);
  286 
  287     mi = CAMEL_MESSAGE_INFO (mmi);
  288 
  289     camel_message_info_property_lock (mi);
  290 
  291     changed = mmi->priv->last_modified != last_modified;
  292 
  293     if (changed)
  294         mmi->priv->last_modified = last_modified;
  295 
  296     camel_message_info_property_unlock (mi);
  297 
  298     if (changed && !camel_message_info_get_abort_notifications (mi)) {
  299         g_object_notify (G_OBJECT (mmi), "last-modified");
  300         camel_message_info_set_dirty (mi, TRUE);
  301     }
  302 
  303     return changed;
  304 }