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;
426
private SearchRowContainer parent;
428
public SearchRowDate(SearchRowContainer parent) {
429
this.parent = parent;
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);
441
cal_one = new Gtk.Calendar();
442
cal_two = new Gtk.Calendar();
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);
449
and = new Gtk.Label(_("and"));
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);
458
update_date_labels();
462
context.changed.disconnect(on_changed);
465
private void update_date_labels() {
466
SearchConditionDate.Context c = (SearchConditionDate.Context) context.get_active();
468
// Only show "and" and 2nd date label for between mode.
469
if (c == SearchConditionDate.Context.BETWEEN) {
473
} else if (c == SearchConditionDate.Context.IS_NOT_SET) {
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);;
488
public override Gtk.Widget get_widget() {
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);
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);
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();
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();
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(),
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();
529
public override bool is_complete() {
533
private void on_changed() {
534
parent.changed(parent);
535
update_date_labels();
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);
546
d.set_resizable(false);
547
d.set_decorated(false);
549
ulong id_1 = cal.day_selected.connect(()=>{update_date_labels();});
550
ulong id_2 = cal.day_selected_double_click.connect(()=>{d.close();});
553
if (res != Gtk.ResponseType.ACCEPT) {
554
// User hit cancel, restore original date.
556
cal.month = orig_month;
557
cal.year = orig_year;
559
cal.disconnect(id_1);
560
cal.disconnect(id_2);
562
update_date_labels();
565
private void on_one_clicked() {
566
popup_calendar(cal_one);
569
private void on_two_clicked() {
570
popup_calendar(cal_two);
409
574
private Gtk.Builder builder;
410
575
private Gtk.Dialog dialog;
411
576
private Gtk.Button add_criteria;