~stolowski/libunity/libunity.error-state

« back to all changes in this revision

Viewing changes to src/unity-previews.vala

  • Committer: Tarmac
  • Author(s): Michal Hruby
  • Date: 2012-08-16 09:39:51 UTC
  • mfrom: (159.1.4 libunity)
  • Revision ID: tarmac-20120816093951-nznxnzvwf5d0t5up
Switch visibility of AsyncPreview and SeriesPreview, add no-details hint to base preview. Fixes: . Approved by Pawel Stolowski.

Show diffs side-by-side

added added

removed removed

Lines of Context:
91
91
                        info_hint.icon_hint, info_hint.data);
92
92
  }
93
93
 
94
 
  internal virtual HashTable<string, Variant> update_property (HashTable<string, Variant> values)
 
94
  internal virtual async HashTable<string, Variant> update_property (HashTable<string, Variant> values)
95
95
  {
96
96
    _raw.update_property (values);
97
97
 
236
236
            description_markup: description);
237
237
  }
238
238
 
 
239
  internal static GenericPreview empty ()
 
240
  {
 
241
    var preview = new GenericPreview ("", "", null);
 
242
    preview.get_raw ().set_no_details (true);
 
243
 
 
244
    return preview;
 
245
  }
 
246
 
239
247
  internal override Object create_raw ()
240
248
  {
241
249
    return new Protocol.GenericPreview ();
393
401
    }
394
402
  }
395
403
 
396
 
  internal override HashTable<string, Variant> update_property (HashTable<string, Variant> values)
 
404
  internal override async HashTable<string, Variant> update_property (HashTable<string, Variant> values)
397
405
  {
398
406
    Variant? action_v = values["action"];
399
407
    Variant? uri_v = values["uri"];
412
420
          break;
413
421
      }
414
422
    }
415
 
    return base.update_property (values);
 
423
    return yield base.update_property (values);
416
424
  }
417
425
 
418
426
  public signal void play (string uri);
476
484
  }
477
485
}
478
486
 
479
 
 
480
 
public class SeriesItem : Object
 
487
/* No support for SeriesPreview yet */
 
488
internal class SeriesItem : Object
481
489
{
482
490
  public string uri { get; construct; }
483
491
  public string title { get; construct; }
489
497
  }
490
498
}
491
499
 
492
 
public class SeriesPreview : Preview, Dee.Serializable
 
500
internal class SeriesPreview : Preview, Dee.Serializable
493
501
{
494
502
  private string _current_item_uri;
495
503
  public string current_item_uri
520
528
  private void update_child_preview (string uri, int item_index = -1)
521
529
  {
522
530
    var preview = request_item_preview (uri);
 
531
    // FIXME: this needs to handle AsyncPreview
523
532
    if (preview != null)
524
533
    {
525
534
      if (item_index < 0)
551
560
 
552
561
  public signal Preview? request_item_preview (string uri);
553
562
 
554
 
  internal override HashTable<string, Variant> update_property (HashTable<string, Variant> values)
 
563
  internal override async HashTable<string, Variant> update_property (HashTable<string, Variant> values)
555
564
  {
556
 
    var response = base.update_property (values);
 
565
    var response = yield base.update_property (values);
557
566
    int new_selected_item = _raw.selected_item;
558
567
    Preview? preview = null;
559
568
    if (new_selected_item != _selected_item &&
574
583
 
575
584
  private Variant serialize ()
576
585
  {
 
586
    // FIXME: this won't work with AsyncPreview, but we can't really emit
 
587
    // the request_item_preview signal sooner, because the user of this API
 
588
    // needs time to construct the instance and connect to the signal
 
589
    // We seem to need extra init() method.
 
590
 
577
591
    // ensures that we emit selected_item_changed shortly after construction
578
592
    if (_selected_item < 0 && _raw.get_items ().length > 0)
579
593
    {
592
606
}
593
607
 
594
608
 
595
 
// Keeping this internal so far, we'll probably expose it later
596
 
internal class AsyncPreview : Preview
 
609
public class AsyncPreview : Preview
597
610
{
598
611
  public AsyncPreview ()
599
612
  {
600
613
    Object ();
601
614
  }
602
615
 
603
 
  public Cancellable cancellable { get; private set; }
 
616
  public AsyncPreview.with_cancellable (Cancellable cancellable)
 
617
  {
 
618
    Object (cancellable: cancellable);
 
619
  }
 
620
 
 
621
  public Cancellable cancellable { get; construct set; }
604
622
 
605
623
  public signal void preview_ready (Preview preview);
606
 
  // FIXME: also add an emit method, so it's easy to use in C/Python
 
624
 
 
625
  // simple emit method, so it's easy to use in C/Python
 
626
  [CCode (name = "unity_async_preview_preview_ready")]
 
627
  public void emit_preview_ready (Preview? preview)
 
628
    requires (!(preview is AsyncPreview))
 
629
  {
 
630
    preview_ready (preview);
 
631
  }
607
632
 
608
633
  internal override Object create_raw ()
609
634
  {
610
635
    return new Protocol.GenericPreview ();
611
636
  }
 
637
 
 
638
  internal async Preview? wait_for_signal ()
 
639
  {
 
640
    Preview? preview = null;
 
641
    var sig_id = this.preview_ready.connect ((preview_) =>
 
642
    {
 
643
      if (preview_ != null && !(preview_ is AsyncPreview))
 
644
      {
 
645
        preview = preview_;
 
646
      }
 
647
      wait_for_signal.callback ();
 
648
    });
 
649
 
 
650
    ulong canc_id = 0;
 
651
    Cancellable? canc = null;
 
652
    if (cancellable != null)
 
653
    {
 
654
      canc = cancellable;
 
655
      canc_id = canc.connect (() =>
 
656
      {
 
657
        SignalHandler.block (this, sig_id);
 
658
        // the cancellable's lock is held in the callback, we'd deadlock if we
 
659
        // tried to continue the callback and disconnect right away
 
660
        Idle.add (wait_for_signal.callback);
 
661
      });
 
662
    }
 
663
 
 
664
    yield;
 
665
 
 
666
    // cleanup
 
667
    SignalHandler.disconnect (this, sig_id);
 
668
    if (canc != null) canc.disconnect (canc_id);
 
669
 
 
670
    return preview;
 
671
  }
612
672
}
613
673
 
614
674
} /* namespace */