~mhr3/libunity/fix-937464

« back to all changes in this revision

Viewing changes to protocol/protocol-previews.vala

  • Committer: Tarmac
  • Author(s): Ken VanDine
  • Date: 2012-09-17 20:29:09 UTC
  • mfrom: (175.1.3 libunity)
  • Revision ID: tarmac-20120917202909-5j9gvlu1rs73r2sv
Added SocialPreview. Fixes: https://bugs.launchpad.net/bugs/1049127. Approved by Pawel Stolowski.

Show diffs side-by-side

added added

removed removed

Lines of Context:
279
279
    typeof (ApplicationPreview).class_ref ();
280
280
    typeof (MusicPreview).class_ref ();
281
281
    typeof (MoviePreview).class_ref ();
 
282
    typeof (SocialPreview).class_ref ();
282
283
    typeof (SeriesPreview).class_ref ();
283
284
  }
284
285
 
306
307
      case MoviePreview.RENDERER_NAME:
307
308
        result_obj = Dee.Serializable.parse (data, typeof (MoviePreview));
308
309
        break;
 
310
      case SocialPreview.RENDERER_NAME:
 
311
        result_obj = Dee.Serializable.parse (data, typeof (SocialPreview));
 
312
        break;
309
313
      case SeriesPreview.RENDERER_NAME:
310
314
        result_obj = Dee.Serializable.parse (data, typeof (SeriesPreview));
311
315
        break;
580
584
  }
581
585
}
582
586
 
 
587
public class SocialPreview : Preview
 
588
{
 
589
  internal const string RENDERER_NAME = "preview-social";
 
590
 
 
591
  public Icon avatar { get; set; }
 
592
  public string content { get; set; }
 
593
  public string sender { get; set; }
 
594
  public CommentRaw[] comments;
 
595
  private CommentRaw[] _comments = null;
 
596
 
 
597
  public struct CommentRaw
 
598
  {
 
599
    public string id;
 
600
    public string display_name;
 
601
    public string content;
 
602
    public string time;
 
603
  }
 
604
 
 
605
  public SocialPreview ()
 
606
  {
 
607
    Object ();
 
608
  }
 
609
 
 
610
  internal override unowned string get_renderer_name ()
 
611
  {
 
612
    return RENDERER_NAME;
 
613
  }
 
614
 
 
615
  internal override void add_properties (HashTable<string, Variant> properties)
 
616
  {
 
617
    base.add_properties (properties);
 
618
 
 
619
    if (_comments.length > 0)
 
620
      properties["comments"] = _comments;
 
621
    if (avatar != null)
 
622
      properties["avatar"] = avatar.to_string ();
 
623
    if (content != null)
 
624
      properties["content"] = content;
 
625
    if (sender != null)
 
626
      properties["sender"] = sender;
 
627
  }
 
628
 
 
629
  static construct
 
630
  {
 
631
    Dee.Serializable.register_parser (typeof (SocialPreview),
 
632
                                      new VariantType (PreviewRaw.SIGNATURE),
 
633
                                      (data) =>
 
634
    {
 
635
      unowned string renderer = data.get_child_value (0).get_string ();
 
636
      warn_if_fail (renderer == RENDERER_NAME);
 
637
 
 
638
      HashTable<string, Variant> properties;
 
639
      SocialPreview result = Preview.deserialize<SocialPreview> (
 
640
        data, out properties);
 
641
 
 
642
      Preview.checked_set (properties["avatar"],
 
643
        (v) => { result.avatar = Preview.variant_to_icon (v); });
 
644
      Preview.checked_set (properties["content"],
 
645
        (v) => { result.content = v.get_string (); });
 
646
      Preview.checked_set (properties["sender"],
 
647
        (v) => { result.sender = v.get_string (); });
 
648
 
 
649
      Preview.checked_set (properties["comments"], (v) =>
 
650
      {
 
651
        CommentRaw[] comments = (CommentRaw[]) v;
 
652
        result._comments = (owned) comments;
 
653
      });
 
654
 
 
655
      return result;
 
656
    });
 
657
  }
 
658
 
 
659
  public void add_comment (string id,
 
660
                             string display_name,
 
661
                             string content,
 
662
                             string time)
 
663
  {
 
664
    CommentRaw? comment = CommentRaw ();
 
665
    comment.id = id;
 
666
    comment.display_name = display_name;
 
667
    comment.content = content;
 
668
    comment.time = time;
 
669
 
 
670
    _comments += (owned) comment;
 
671
  }
 
672
 
 
673
  public unowned CommentRaw[] get_comments ()
 
674
  {
 
675
    return _comments;
 
676
  }
 
677
}
 
678
 
583
679
public struct SeriesItemRaw
584
680
{
585
681
  public string uri;