aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/gncal-full-day.c
diff options
context:
space:
mode:
authorRussell Steinthal <rms39@columbia.edu>2000-02-16 22:27:38 +0800
committerSeth Alves <alves@src.gnome.org>2000-02-16 22:27:38 +0800
commit08f2b4e43ff25f5be620bfb3a3e3786b57849ad5 (patch)
treec0bf25e53209065c401325d27580982ac30c6e87 /calendar/gui/gncal-full-day.c
parentf926f10e86aee8df632613d9c5b5022e6b8597ca (diff)
downloadgsoc2013-evolution-08f2b4e43ff25f5be620bfb3a3e3786b57849ad5.tar.gz
gsoc2013-evolution-08f2b4e43ff25f5be620bfb3a3e3786b57849ad5.tar.zst
gsoc2013-evolution-08f2b4e43ff25f5be620bfb3a3e3786b57849ad5.zip
Change iCalObject.organizer from char* to iCalPerson*
2000-02-16 Russell Steinthal <rms39@columbia.edu> * calobj.[ch], eventedit.c, main.c: Change iCalObject.organizer from char* to iCalPerson* * calobj.[ch]: Change iCalObject.related from list of char* to list of iCalRelation*; assorted related fixes * icalendar.c: interface between libical and the gnomecal internal representation svn path=/trunk/; revision=1791
Diffstat (limited to 'calendar/gui/gncal-full-day.c')
0 files changed, 0 insertions, 0 deletions
a> 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
/*
 * e-data-capture.c
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 */

/**
 * SECTION: e-data-capture
 * @include: e-util/e-util.h
 * @short_description: Capture data from streams
 *
 * #EDataCapture is a #GConverter that captures data until the end of
 * the input data is seen, then emits a #EDataCapture:finished signal
 * with the captured data in a #GBytes instance.
 *
 * When used with #GConverterInputStream or #GConverterOutputStream,
 * an #EDataCapture can discreetly capture the stream content for the
 * purpose of caching.
 **/

#include "e-data-capture.h"

#include <string.h>

#define E_DATA_CAPTURE_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_DATA_CAPTURE, EDataCapturePrivate))

typedef struct _SignalClosure SignalClosure;

struct _EDataCapturePrivate {
    GMainContext *main_context;
    GByteArray *byte_array;
    GMutex byte_array_lock;
};

struct _SignalClosure {
    GWeakRef data_capture;
    GBytes *data;
};

enum {
    PROP_0,
    PROP_MAIN_CONTEXT
};

enum {
    FINISHED,
    LAST_SIGNAL
};

static guint signals[LAST_SIGNAL];

/* Forward Declarations */
static void e_data_capture_converter_init   (GConverterIface *interface);

G_DEFINE_TYPE_WITH_CODE (
    EDataCapture,
    e_data_capture,
    G_TYPE_OBJECT,
    G_IMPLEMENT_INTERFACE (
        G_TYPE_CONVERTER,
        e_data_capture_converter_init))

static void
signal_closure_free (SignalClosure *signal_closure)
{
    g_weak_ref_set (&signal_closure->data_capture, NULL);
    g_bytes_unref (signal_closure->data);

    g_slice_free (SignalClosure, signal_closure);
}

static gboolean
data_capture_emit_finished_idle_cb (gpointer user_data)
{
    SignalClosure *signal_closure = user_data;
    EDataCapture *data_capture;

    data_capture = g_weak_ref_get (&signal_closure->data_capture);

    if (data_capture != NULL) {
        g_signal_emit (
            data_capture,
            signals[FINISHED], 0,
            signal_closure->data);
        g_object_unref (data_capture);
    }

    return FALSE;
}

static void
data_capture_set_main_context (EDataCapture *data_capture,
                               GMainContext *main_context)
{
    g_return_if_fail (data_capture->priv->main_context == NULL);

    if (main_context != NULL)
        g_main_context_ref (main_context);
    else
        main_context = g_main_context_ref_thread_default ();

    data_capture->priv->main_context = main_context;
}

static void
data_capture_set_property (GObject *object,
                           guint property_id,
                           const GValue *value,
                           GParamSpec *pspec)
{
    switch (property_id) {
        case PROP_MAIN_CONTEXT:
            data_capture_set_main_context (
                E_DATA_CAPTURE (object),
                g_value_get_boxed (value));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
data_capture_get_property (GObject *object,
                           guint property_id,
                           GValue *value,
                           GParamSpec *pspec)
{
    switch (property_id) {
        case PROP_MAIN_CONTEXT:
            g_value_take_boxed (
                value,
                e_data_capture_ref_main_context (
                E_DATA_CAPTURE (object)));
            return;
    }

    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}

static void
data_capture_finalize (GObject *object)
{
    EDataCapturePrivate *priv;

    priv = E_DATA_CAPTURE_GET_PRIVATE (object);

    g_main_context_unref (priv->main_context);

    g_byte_array_free (priv->byte_array, TRUE);
    g_mutex_clear (&priv->byte_array_lock);

    /* Chain up to parent's finalize() method. */
    G_OBJECT_CLASS (e_data_capture_parent_class)->finalize (object);
}

static GConverterResult
data_capture_convert (GConverter *converter,
                      gconstpointer inbuf,
                      gsize inbuf_size,
                      gpointer outbuf,
                      gsize outbuf_size,
                      GConverterFlags flags,
                      gsize *bytes_read,
                      gsize *bytes_written,
                      GError **error)
{
    EDataCapture *data_capture;
    GConverterResult result;

    data_capture = E_DATA_CAPTURE (converter);

    /* Output buffer needs to be at least as large as the input buffer.
     * The error message should never make it to the user interface so
     * no need to translate. */
    if (outbuf_size < inbuf_size) {
        g_set_error_literal (
            error, G_IO_ERROR,
            G_IO_ERROR_NO_SPACE,
            "EDataCapture needs more space");
        return G_CONVERTER_ERROR;
    }

    memcpy (outbuf, inbuf, inbuf_size);
    *bytes_read = *bytes_written = inbuf_size;

    g_mutex_lock (&data_capture->priv->byte_array_lock);

    g_byte_array_append (
        data_capture->priv->byte_array, inbuf, inbuf_size);

    if ((flags & G_CONVERTER_INPUT_AT_END) != 0) {
        GSource *idle_source;
        GMainContext *main_context;
        SignalClosure *signal_closure;

        signal_closure = g_slice_new0 (SignalClosure);
        g_weak_ref_set (&signal_closure->data_capture, data_capture);
        signal_closure->data = g_bytes_new (
            data_capture->priv->byte_array->data,
            data_capture->priv->byte_array->len);

        main_context = e_data_capture_ref_main_context (data_capture);

        idle_source = g_idle_source_new ();
        g_source_set_callback (
            idle_source,
            data_capture_emit_finished_idle_cb,
            signal_closure,
            (GDestroyNotify) signal_closure_free);
        g_source_set_priority (idle_source, G_PRIORITY_HIGH_IDLE);
        g_source_attach (idle_source, main_context);
        g_source_unref (idle_source);

        g_main_context_unref (main_context);
    }

    g_mutex_unlock (&data_capture->priv->byte_array_lock);

    if ((flags & G_CONVERTER_INPUT_AT_END) != 0)
        result = G_CONVERTER_FINISHED;
    else if ((flags & G_CONVERTER_FLUSH) != 0)
        result = G_CONVERTER_FLUSHED;
    else
        result = G_CONVERTER_CONVERTED;

    return result;
}

static void
data_capture_reset (GConverter *converter)
{
    EDataCapture *data_capture;

    data_capture = E_DATA_CAPTURE (converter);

    g_mutex_lock (&data_capture->priv->byte_array_lock);

    g_byte_array_set_size (data_capture->priv->byte_array, 0);

    g_mutex_unlock (&data_capture->priv->byte_array_lock);
}

static void