~ubuntu-branches/ubuntu/quantal/shotwell/quantal

« back to all changes in this revision

Viewing changes to src/searches/SavedSearchDialog.vala

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-08-24 11:45:16 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110824114516-01cf7d83qvc9nse1
Tags: 0.11.0-0ubuntu1
New upstream version, drop patches which are in the new version

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
                case SearchCondition.SearchType.ANY_TEXT:
80
80
                case SearchCondition.SearchType.EVENT_NAME:
81
81
                case SearchCondition.SearchType.FILE_NAME:
 
82
#if ENABLE_FACES                   
 
83
                case SearchCondition.SearchType.FACE:
 
84
#endif
82
85
                case SearchCondition.SearchType.TAG:
83
86
                case SearchCondition.SearchType.TITLE:
84
87
                    my_row = new SearchRowText(this);
96
99
                    my_row = new SearchRowRating(this);
97
100
                    break;
98
101
                
 
102
                case SearchCondition.SearchType.DATE:
 
103
                    my_row = new SearchRowDate(this);
 
104
                    break;
 
105
                
99
106
                default:
100
107
                    assert(false);
101
108
                    break;
406
413
        }
407
414
    }
408
415
    
 
416
    private class SearchRowDate : SearchRow {
 
417
        private const string DATE_FORMAT = "%x";
 
418
        private Gtk.HBox box;
 
419
        private Gtk.ComboBox context;
 
420
        private Gtk.Button label_one;
 
421
        private Gtk.Button label_two;
 
422
        private Gtk.Calendar cal_one;
 
423
        private Gtk.Calendar cal_two;
 
424
        private Gtk.Label and;
 
425
        
 
426
        private SearchRowContainer parent;
 
427
        
 
428
        public SearchRowDate(SearchRowContainer parent) {
 
429
            this.parent = parent;
 
430
            
 
431
            // Ordering must correspond with Context
 
432
            context = new Gtk.ComboBox.text();
 
433
            context.append_text(_("is exactly"));
 
434
            context.append_text(_("is after"));
 
435
            context.append_text(_("is before"));
 
436
            context.append_text(_("is between"));
 
437
            context.append_text(_("is not set"));
 
438
            context.set_active(0);
 
439
            context.changed.connect(on_changed);
 
440
            
 
441
            cal_one = new Gtk.Calendar();
 
442
            cal_two = new Gtk.Calendar();
 
443
            
 
444
            label_one = new Gtk.Button();
 
445
            label_one.clicked.connect(on_one_clicked);
 
446
            label_two = new Gtk.Button();
 
447
            label_two.clicked.connect(on_two_clicked);
 
448
            
 
449
            and = new Gtk.Label(_("and"));
 
450
            
 
451
            box = new Gtk.HBox(false, 8);
 
452
            box.pack_start(context, false, false, 0);
 
453
            box.pack_start(label_one, false, false, 0);
 
454
            box.pack_start(and, false, false, 0);
 
455
            box.pack_start(label_two, false, false, 0);
 
456
            
 
457
            box.show_all();
 
458
            update_date_labels();
 
459
        }
 
460
        
 
461
        ~SearchRowRating() {
 
462
            context.changed.disconnect(on_changed);
 
463
        }
 
464
        
 
465
        private void update_date_labels() {
 
466
            SearchConditionDate.Context c = (SearchConditionDate.Context) context.get_active();
 
467
            
 
468
            // Only show "and" and 2nd date label for between mode.
 
469
            if (c == SearchConditionDate.Context.BETWEEN) {
 
470
                label_one.show();
 
471
                and.show();
 
472
                label_two.show();
 
473
            } else if (c == SearchConditionDate.Context.IS_NOT_SET) {
 
474
                label_one.hide();
 
475
                and.hide();
 
476
                label_two.hide();
 
477
            } else {
 
478
                label_one.show();
 
479
                and.hide();
 
480
                label_two.hide();
 
481
            }
 
482
            
 
483
            // Set label text to date.
 
484
            label_one.label = get_date_one().format(DATE_FORMAT);
 
485
            label_two.label = get_date_two().format(DATE_FORMAT);;
 
486
        }
 
487
        
 
488
        public override Gtk.Widget get_widget() {
 
489
            return box;
 
490
        }
 
491
        
 
492
        private DateTime get_date_one() {
 
493
            return new DateTime.local(cal_one.year, cal_one.month + 1, cal_one.day, 0, 0, 0.0);
 
494
        }
 
495
        
 
496
        private DateTime get_date_two() {
 
497
            return new DateTime.local(cal_two.year, cal_two.month + 1, cal_two.day, 0, 0, 0.0);
 
498
        }
 
499
        
 
500
        private void set_date_one(DateTime date) {
 
501
            cal_one.day   = date.get_day_of_month();
 
502
            cal_one.month = date.get_month() - 1;
 
503
            cal_one.year  = date.get_year();
 
504
        }
 
505
        
 
506
        private void set_date_two(DateTime date) {
 
507
            cal_two.day   = date.get_day_of_month();
 
508
            cal_two.month = date.get_month() - 1;
 
509
            cal_two.year  = date.get_year();
 
510
        }
 
511
        
 
512
        public override SearchCondition get_search_condition() {
 
513
            SearchCondition.SearchType search_type = parent.get_search_type();
 
514
            SearchConditionDate.Context search_context = (SearchConditionDate.Context) context.get_active();
 
515
            SearchConditionDate c = new SearchConditionDate(search_type, search_context, get_date_one(),
 
516
                get_date_two());
 
517
            return c;
 
518
        }
 
519
        
 
520
        public override void populate(SearchCondition sc) {
 
521
            SearchConditionDate? cond = sc as SearchConditionDate;
 
522
            assert(cond != null);
 
523
            context.set_active(cond.context);
 
524
            set_date_one(cond.date_one);
 
525
            set_date_two(cond.date_two);
 
526
            update_date_labels();
 
527
        }
 
528
        
 
529
        public override bool is_complete() {
 
530
            return true;
 
531
        }
 
532
        
 
533
        private void on_changed() {
 
534
            parent.changed(parent);
 
535
            update_date_labels();
 
536
        }
 
537
        
 
538
        private void popup_calendar(Gtk.Calendar cal) {
 
539
            int orig_day = cal.day;
 
540
            int orig_month = cal.month;
 
541
            int orig_year = cal.year;
 
542
            Gtk.Dialog d = new Gtk.Dialog.with_buttons(null, null, 
 
543
                Gtk.DialogFlags.MODAL, Gtk.Stock.CANCEL, Gtk.ResponseType.REJECT, 
 
544
                Gtk.Stock.OK, Gtk.ResponseType.ACCEPT);
 
545
            d.set_modal(true);
 
546
            d.set_resizable(false);
 
547
            d.set_decorated(false);
 
548
            d.vbox.add(cal);
 
549
            ulong id_1 = cal.day_selected.connect(()=>{update_date_labels();});
 
550
            ulong id_2 = cal.day_selected_double_click.connect(()=>{d.close();});
 
551
            d.show_all();
 
552
            int res = d.run();
 
553
            if (res != Gtk.ResponseType.ACCEPT) {
 
554
                // User hit cancel, restore original date.
 
555
                cal.day = orig_day;
 
556
                cal.month = orig_month;
 
557
                cal.year = orig_year;
 
558
            }
 
559
            cal.disconnect(id_1);
 
560
            cal.disconnect(id_2);
 
561
            d.destroy();
 
562
            update_date_labels();
 
563
        }
 
564
        
 
565
        private void on_one_clicked() {
 
566
            popup_calendar(cal_one);
 
567
        }
 
568
        
 
569
        private void on_two_clicked() {
 
570
            popup_calendar(cal_two);
 
571
        }
 
572
    }
 
573
    
409
574
    private Gtk.Builder builder;
410
575
    private Gtk.Dialog dialog;
411
576
    private Gtk.Button add_criteria;
429
594
        row_list.get(0).allow_removal(false);
430
595
        
431
596
        // Add buttons for new search.
 
597
        dialog.add_action_widget(new Gtk.Button.from_stock(Gtk.Stock.CANCEL), Gtk.ResponseType.CANCEL);
432
598
        Gtk.Button ok_button = new Gtk.Button.from_stock(Gtk.Stock.OK);
433
599
        ok_button.can_default = true;
434
600
        dialog.add_action_widget(ok_button, Gtk.ResponseType.OK);
435
 
        dialog.add_action_widget(new Gtk.Button.from_stock(Gtk.Stock.CANCEL), Gtk.ResponseType.CANCEL);
436
601
        dialog.set_default_response(Gtk.ResponseType.OK);
437
602
        
438
603
        dialog.show_all();
469
634
        search_title.changed.disconnect(on_title_changed);
470
635
    }
471
636
    
472
 
    // Builds the dialog UI.  Doesn't add buttons to the dialog or call dialog.show_all().
 
637
    // Builds the dialog UI.  Doesn't add buttons to the dialog or call dialog.show().
473
638
    private void setup_dialog() {
474
639
        builder = AppWindow.create_builder();
475
640