~indicator-applet-developers/ido/trunk.13.10

« back to all changes in this revision

Viewing changes to src/idoappointmentmenuitem.c

  • Committer: Tarmac
  • Author(s): Charles Kerr
  • Date: 2013-06-17 16:37:33 UTC
  • mfrom: (131.1.5 trunk)
  • Revision ID: tarmac-20130617163733-a6bh99tr3slt3exq
Better handling of IdoMenuItem construction from GMenuItems, better public API documentation.

Approved by PS Jenkins bot, Ted Gould.

Show diffs side-by-side

added added

removed removed

Lines of Context:
236
236
****
237
237
***/
238
238
 
 
239
/* creates a menu-sized pixbuf filled with specified color */
239
240
static GdkPixbuf *
240
241
create_color_icon_pixbuf (const char * color_spec)
241
242
{
283
284
  char * str;
284
285
  priv_t * p = self->priv;
285
286
 
286
 
  str = g_date_time_format (p->date_time, p->format);
 
287
  if (p->date_time && p->format)
 
288
    str = g_date_time_format (p->date_time, p->format);
 
289
  else
 
290
    str = NULL;
 
291
 
287
292
  gtk_label_set_text (GTK_LABEL(p->timestamp_label), str);
288
293
  g_free (str);
289
294
}
292
297
****  Public API
293
298
***/
294
299
 
 
300
/* create  a new IdoAppointmentMenuItem */
295
301
GtkWidget *
296
302
ido_appointment_menu_item_new (void)
297
303
{
298
304
  return GTK_WIDGET (g_object_new (IDO_APPOINTMENT_MENU_ITEM_TYPE, NULL));
299
305
}
300
306
 
 
307
/**
 
308
 * ido_appointment_menu_item_set_color:
 
309
 * @color: parseable color string
 
310
 *
 
311
 * When this is set, the menuitem will include an icon with this color.
 
312
 *
 
313
 * These colors can be set in the end user's calendar app as a quick visual cue
 
314
 * to show what kind of appointment this is.
 
315
 */
301
316
void
302
317
ido_appointment_menu_item_set_color (IdoAppointmentMenuItem * self,
303
318
                                     const char             * color_string)
315
330
  g_object_unref (G_OBJECT(pixbuf));
316
331
}
317
332
 
 
333
/**
 
334
 * ido_appointment_menu_item_set_summary:
 
335
 * @summary: short string describing the appointment.
 
336
 *
 
337
 * Set the menuitem's primary label with a short description of the appointment
 
338
 */
318
339
void
319
340
ido_appointment_menu_item_set_summary (IdoAppointmentMenuItem * self,
320
341
                                       const char             * summary)
329
350
  gtk_label_set_text (GTK_LABEL(p->summary_label), p->summary);
330
351
}
331
352
 
 
353
/**
 
354
 * ido_appointment_menu_item_set_time:
 
355
 * @time: the time to be rendered in the appointment's timestamp label.
 
356
 *
 
357
 * Set the time that will be displayed in the menuitem's
 
358
 * right-justified timestamp label
 
359
 */
332
360
void
333
361
ido_appointment_menu_item_set_time (IdoAppointmentMenuItem * self,
334
362
                                    time_t                   time)
344
372
}
345
373
 
346
374
/**
347
 
 * @strftime_fmt: the format string used to build the appointment's time string
 
375
 * ido_appointment_menu_item_set_format:
 
376
 * @format: the format string used when showing the appointment's time
 
377
 *
 
378
 * Set the format string for rendering the appointment's time
 
379
 * in its right-justified secondary label.
 
380
 *
 
381
 * See strfrtime(3) for more information on the format string.
348
382
 */
349
383
void
350
384
ido_appointment_menu_item_set_format (IdoAppointmentMenuItem * self,
360
394
  update_timestamp_label (self);
361
395
}
362
396
 
 
397
/**
 
398
 * ido_appointment_menu_item_new_from_model:
 
399
 * @menu_item: the corresponding menuitem
 
400
 * @actions: action group to tell when this GtkMenuItem is activated
 
401
 *
 
402
 * Creates a new IdoAppointmentMenuItem with properties initialized from
 
403
 * the menuitem's attributes.
 
404
 *
 
405
 * If the menuitem's 'action' attribute is set, trigger that action
 
406
 * in @actions when this IdoAppointmentMenuItem is activated.
 
407
 */
363
408
GtkMenuItem *
364
409
ido_appointment_menu_item_new_from_model (GMenuItem    * menu_item,
365
410
                                          GActionGroup * actions)
366
411
{
 
412
  guint i;
 
413
  guint n;
367
414
  gint64 i64;
368
415
  gchar * str;
369
416
  IdoAppointmentMenuItem * ido_appointment;
370
 
 
371
 
  ido_appointment = IDO_APPOINTMENT_MENU_ITEM (ido_appointment_menu_item_new());
 
417
  GParameter parameters[8];
 
418
 
 
419
  /* create the ido_appointment */
 
420
 
 
421
  n = 0;
372
422
 
373
423
  if (g_menu_item_get_attribute (menu_item, "label", "s", &str))
374
424
    {
375
 
      ido_appointment_menu_item_set_summary (ido_appointment, str);
376
 
      g_free (str);
 
425
      GParameter p = { "summary", G_VALUE_INIT };
 
426
      g_value_init (&p.value, G_TYPE_STRING);
 
427
      g_value_take_string (&p.value, str);
 
428
      parameters[n++] = p;
377
429
    }
378
430
 
379
431
  if (g_menu_item_get_attribute (menu_item, "x-canonical-color", "s", &str))
380
432
    {
381
 
      ido_appointment_menu_item_set_color (ido_appointment, str);
382
 
      g_free (str);
 
433
      GParameter p = { "color", G_VALUE_INIT };
 
434
      g_value_init (&p.value, G_TYPE_STRING);
 
435
      g_value_take_string (&p.value, str);
 
436
      parameters[n++] = p;
 
437
    }
 
438
 
 
439
  if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str))
 
440
    {
 
441
      GParameter p = { "format", G_VALUE_INIT };
 
442
      g_value_init (&p.value, G_TYPE_STRING);
 
443
      g_value_take_string (&p.value, str);
 
444
      parameters[n++] = p;
383
445
    }
384
446
 
385
447
  if (g_menu_item_get_attribute (menu_item, "x-canonical-time", "x", &i64))
386
448
    {
387
 
      ido_appointment_menu_item_set_time (ido_appointment, (time_t)i64);
388
 
    }
389
 
 
390
 
  if (g_menu_item_get_attribute (menu_item, "x-canonical-time-format", "s", &str))
391
 
    {
392
 
      ido_appointment_menu_item_set_format (ido_appointment, str);
393
 
      g_free (str);
394
 
    }
 
449
      GParameter p = { "time", G_VALUE_INIT };
 
450
      g_value_init (&p.value, G_TYPE_INT64);
 
451
      g_value_set_int64 (&p.value, i64);
 
452
      parameters[n++] = p;
 
453
    }
 
454
 
 
455
  g_assert (n <= G_N_ELEMENTS (parameters));
 
456
  ido_appointment = g_object_newv (IDO_APPOINTMENT_MENU_ITEM_TYPE, n, parameters);
 
457
 
 
458
  for (i=0; i<n; i++)
 
459
    g_value_unset (&parameters[i].value);
 
460
 
 
461
 
 
462
  /* add an ActionHelper */
395
463
 
396
464
  if (g_menu_item_get_attribute (menu_item, "action", "s", &str))
397
465
    {