예제 #1
0
bool DateFilter::select_date(const Glib::ustring& title, std::string& isodate) {
	Gtk::Dialog dlg(title, true);
	Gtk::Calendar cal;
	cal.show();

	// select date
	if(!isodate.empty()) {
		guint year = atoi(isodate.substr(0,4).c_str());
		guint month = atoi(isodate.substr(4,2).c_str());
		guint day = atoi(isodate.substr(6,2).c_str());
		cal.select_month(month-1, year);
		cal.select_day(day);
	}

	dlg.get_vbox()->pack_start(cal, Gtk::PACK_SHRINK);
	dlg.add_button(Gtk::Stock::OK , Gtk::RESPONSE_OK);
	dlg.add_button(Gtk::Stock::CANCEL , Gtk::RESPONSE_CANCEL);
	
	dlg.show();

	if(dlg.run() == Gtk::RESPONSE_OK) {
		char date[10];
		guint year;
		guint month;
		guint day;
		cal.get_date(year, month, day);
		g_snprintf(date, sizeof(date), "%04i%02i%02i", year, month+1, day);
		isodate = date;

		return true;
	}
	
	return false;
}
예제 #2
0
void ActivityDialog::show_calendar(bool start_cal)
{
  Gtk::Dialog cal_dialog;
  if(start_cal)
    cal_dialog.set_title(_("Start date"));
  else
    cal_dialog.set_title(_("End date"));

  cal_dialog.set_icon_from_file("images/HaPr_high_80x100_ver2.gif");
  cal_dialog.add_button(Gtk::Stock::CANCEL, 0);
  cal_dialog.add_button(Gtk::Stock::OK, 1);

  Gtk::Calendar cal;
  Gtk::Box *cal_box = cal_dialog.get_vbox();
  cal_box->pack_start(cal);

  cal_dialog.show_all_children();

  int response = cal_dialog.run();
  if(response == 1)
  {
    Glib::Date sdate;
    cal.get_date(sdate);
    if(start_cal)
      start_date_entry.set_text(sdate.format_string("%F"));
    else
      end_date_entry.set_text(sdate.format_string("%F"));
  }
}