Esempio n. 1
1
    Glib::Date MALItem::get_date(const std::string& in) const {
        Glib::Date        out;
        Glib::Date::Day   day   = 0;
        Glib::Date::Month month = Glib::Date::BAD_MONTH;
        Glib::Date::Year  year  = 0;

        try {
            year = std::stoi(in.substr(0,4));
            day = std::stoi(in.substr(8,2));
            switch (std::stoi(in.substr(5,2))) {
                case 1:  month = Glib::Date::JANUARY;   break;
                case 2:  month = Glib::Date::FEBRUARY;  break;
                case 3:  month = Glib::Date::MARCH;     break;
                case 4:  month = Glib::Date::APRIL;     break;
                case 5:  month = Glib::Date::MAY;       break;
                case 6:  month = Glib::Date::JUNE;      break;
                case 7:  month = Glib::Date::JULY;      break;
                case 8:  month = Glib::Date::AUGUST;    break;
                case 9:  month = Glib::Date::SEPTEMBER; break;
                case 10: month = Glib::Date::OCTOBER;   break;
                case 11: month = Glib::Date::NOVEMBER;  break;
                case 12: month = Glib::Date::DECEMBER;  break;
                default: month = Glib::Date::BAD_MONTH; break;
            }
        } catch (std::exception e) {
        }

        if (Glib::Date::valid_year(year))
            out.set_year(year);
        if (Glib::Date::valid_month(month))
            out.set_month(month);
        if (Glib::Date::valid_day(day))
            out.set_day(day);

        return out;
    }
Esempio n. 2
0
void NoteOfTheDay::cleanup_old(gnote::NoteManager & manager)
{
  gnote::Note::List kill_list;
  const gnote::Note::List & notes = manager.get_notes();

  Glib::Date date;
  date.set_time_current(); // time set to 00:00:00

  for (gnote::Note::List::const_iterator iter = notes.begin();
       notes.end() != iter; iter++) {
    const std::string & title = (*iter)->get_title();
    const sharp::DateTime & date_time = (*iter)->create_date();

    if (true == Glib::str_has_prefix(title, s_title_prefix)
        && s_template_title != title
        && Glib::Date(
             date_time.day(),
             static_cast<Glib::Date::Month>(date_time.month()),
             date_time.year()) != date
        && !has_changed(*iter)) {
      kill_list.push_back(*iter);
    }
  }

  for (gnote::Note::List::const_iterator iter = kill_list.begin();
       kill_list.end() != iter; iter++) {
    DBG_OUT("NoteOfTheDay: Deleting old unmodified '%s'",
            (*iter)->get_title().c_str());
    manager.delete_note(*iter);
  }
}
Esempio n. 3
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"));
  }
}
Esempio n. 4
0
void
Item::ensure_integrity()
{
	if (_ensured) 
		return;
	static const Glib::ustring _empty("Empty title");
	if (_link.empty() && !_guid.empty())
		_link = _guid;
	if (_title.empty())
		_title = _empty;
	const Glib::ustring s = _description;
	remove_markup (s, _description);

    bool rd_is_valid = false;
    if (!_rcvdate.empty())
    {
        Glib::Date my;
        int y, m, d;
        sscanf (_rcvdate.c_str(), "%d-%d-%d", &y, &m, &d);
        my.set_day (d);
        my.set_year (y);
        my.set_month (Glib::Date::JANUARY);
        my.add_months (m-1);
        rd_is_valid = my.valid();
    }
    if (!rd_is_valid)
    {
        g_warning ("Invalid date: %s ... fixing", _rcvdate.c_str());
        Glib::Date now;
        now.set_time_current();
        _rcvdate = now.format_string ("%Y-%m-%d");
    }
	_ensured = true;
}
void NoteOfTheDayApplicationAddin::check_new_day() const
{
  Glib::Date date;
  date.set_time_current();

  if (0 == NoteOfTheDay::get_note_by_date(*m_manager, date)) {
    NoteOfTheDay::cleanup_old(*m_manager);

    // Create a new NotD if the day has changed
    NoteOfTheDay::create(*m_manager, date);
  }
}
Esempio n. 6
0
void CalendarBox::dateBegin(std::string& date)
{
    if (mDialog->run() == Gtk::RESPONSE_OK) {
#if GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION <= 10
        guint year, month, day;
        mCalendar->get_date(year, month, day);
        Glib::Date d((Glib::Date::Day)day, (Glib::Date::Month)month,
                     (Glib::Date::Year)year);
#else
        Glib::Date d;
        mCalendar->get_date(d);
#endif
        Glib::ustring format = "%Y-%m-%d";
        date = d.format_string(format);
    }
    mDialog->hide();
}
Esempio n. 7
0
void GCode::MakeText(string &GcodeTxt,
		     const Settings &settings,
		     ViewProgress * progress)
{
  string GcodeStart = settings.GCode.getStartText();
  string GcodeLayer = settings.GCode.getLayerText();
  string GcodeEnd   = settings.GCode.getEndText();

	double lastE = -10;
	double lastF = 0; // last Feedrate (can be omitted when same)
	Vector3d pos(0,0,0);
	Vector3d LastPos(-10,-10,-10);
	std::stringstream oss;

	Glib::Date date;
	date.set_time_current();
	Glib::TimeVal time;
	time.assign_current_time();
	GcodeTxt += "; GCode by Repsnapper, "+
	  date.format_string("%a, %x") +
	  //time.as_iso8601() +
	  "\n";

	GcodeTxt += "\n; Startcode\n"+GcodeStart + "; End Startcode\n\n";

	layerchanges.clear();
	if (progress) progress->restart(_("Collecting GCode"), commands.size());
	int progress_steps=(int)(commands.size()/100);
	if (progress_steps==0) progress_steps=1;

	for (uint i = 0; i < commands.size(); i++) {
	  char E_letter;
	  if (settings.Slicing.UseTCommand) // use first extruder's code for all extuders
	    E_letter = settings.Extruders[0].GCLetter[0];
	  else
	    E_letter = settings.Extruders[commands[i].extruder_no].GCLetter[0];
	  if (progress && i%progress_steps==0 && !progress->update(i)) break;

	  if ( commands[i].Code == LAYERCHANGE ) {
	    layerchanges.push_back(i);
	    if (GcodeLayer.length()>0)
	      GcodeTxt += "\n; Layerchange GCode\n" + GcodeLayer +
		"; End Layerchange GCode\n\n";
	  }

	  if ( commands[i].where.z() < 0 )  {
	    cerr << i << " Z < 0 "  << commands[i].info() << endl;
	  }
	  else {
	    GcodeTxt += commands[i].GetGCodeText(LastPos, lastE, lastF,
						 settings.Slicing.RelativeEcode,
						 E_letter,
						 settings.Hardware.SpeedAlways) + "\n";
	  }
	}

	GcodeTxt += "\n; End GCode\n" + GcodeEnd + "\n";

	buffer->set_text (GcodeTxt);

	// save zpos line numbers for faster finding
	buffer_zpos_lines.clear();
	uint blines = buffer->get_line_count();
	for (uint i = 0; i < blines; i++) {
	  const string line = getLineAt(buffer, i);
	  if (line.find("Z") != string::npos ||
	      line.find("z") != string::npos)
	    buffer_zpos_lines.push_back(i);
	}

	if (progress) progress->stop();

}
Esempio n. 8
0
std::string NoteOfTheDay::get_title(const Glib::Date & date)
{
  // Format: "Today: Friday, July 01 2005"
  return s_title_prefix + date.format_string(_("%A, %B %d %Y"));
}
Esempio n. 9
0
void GCode::MakeText(string &GcodeTxt, const string &GcodeStart, 
		     const string &GcodeLayer, const string &GcodeEnd,
		     bool RelativeEcode, 
		     ViewProgress * progress)
{
	double lastE = -10;
	double lastF = 0; // last Feedrate (can be omitted when same)
	Vector3d pos(0,0,0);
	Vector3d LastPos(-10,-10,-10);
	std::stringstream oss;

	Glib::Date date;
	date.set_time_current();
	Glib::TimeVal time;
	time.assign_current_time();
	GcodeTxt += "; GCode by Repsnapper, "+
	  date.format_string("%a, %x") +
	  //time.as_iso8601() +
	  "\n";

	GcodeTxt += "\n; Startcode\n"+GcodeStart + "; End Startcode\n\n";

	layerchanges.clear();

	progress->restart(_("Collecting GCode"),commands.size());
	int progress_steps=(int)(commands.size()/100);
	if (progress_steps==0) progress_steps=1;

	for (uint i = 0; i < commands.size(); i++) {
	  if (i%progress_steps==0) if (!progress->update(i)) break;

	  if ( commands[i].Code == LAYERCHANGE ) {
	    layerchanges.push_back(i);
	    if (GcodeLayer.length()>0)
	      GcodeTxt += "\n; Layerchange GCode\n" + GcodeLayer + 
		"; End Layerchange GCode\n\n"; 
	  }
	  
	  if ( commands[i].where.z() < 0 )  {
	    cerr << i << " Z < 0 "  << commands[i].info() << endl;
	  }
	  else {
	    GcodeTxt += commands[i].GetGCodeText(LastPos, lastE, lastF, RelativeEcode) + "\n";
	  }
	}

	GcodeTxt += "\n; End GCode\n" + GcodeEnd + "\n";

	buffer->set_text (GcodeTxt);

	// save zpos line numbers for faster finding
	buffer_zpos_lines.clear();
	uint blines = buffer->get_line_count();
	for (uint i = 0; i < blines; i++) {
	  const string line = getLineAt(buffer, i);
	  if (line.find("Z") != string::npos ||
	      line.find("z") != string::npos)
	    buffer_zpos_lines.push_back(i);
	}


	  // 	oss.str( "" );
	// 	switch(commands[i].Code)
	// 	{
	// 	case SELECTEXTRUDER:
	// 		oss  << "T0\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		break;
	// 	case SETSPEED:
	// 		commands[i].where.z() = LastPos.z();
	// 		commands[i].e = lastE;
	// 	case ZMOVE:
	// 		commands[i].where.x() = LastPos.x();
	// 		commands[i].where.y() = LastPos.y();
	// 	case COORDINATEDMOTION:
	// 		if ((commands[i].where.x() != LastPos.x()) + 
	// 		    (commands[i].where.y() != LastPos.y()) +
	// 		    (commands[i].where.z() != LastPos.z()) != 0 &&
	// 		    AntioozeDistance != 0 && commands[i].e == lastE &&
	// 		    !Use3DGcode && AntioozeDistance != 0)
	// 		{
	// 			if (UseIncrementalEcode)
	// 			{
	// 				oss << "G1 E" << (lastE - AntioozeDistance) << "  F" << AntioozeSpeed << " ;antiooze retract\n";
	// 			}
	// 			else
	// 			{
	// 				oss << "G1 E" << -(AntioozeDistance) << "  F" << AntioozeSpeed << " ;antiooze retract\n";
	// 			}
	// 		}
	// 		oss  << "G1 ";
	// 		if(commands[i].where.x() != LastPos.x())
	// 			oss << "X" << commands[i].where.x() << " ";
	// 		if(commands[i].where.y() != LastPos.y())
	// 			oss << "Y" << commands[i].where.y() << " ";
	// 		if(commands[i].where.z() != LastPos.z())
	// 			oss << "Z" << commands[i].where.z() << " ";
	// 		if(commands[i].e != lastE)
	// 		{
	// 			if(UseIncrementalEcode)	// in incremental mode, the same is nothing
	// 				{
	// 				if(commands[i].e != lastE)
	// 					oss << "E" << commands[i].e << " ";
	// 				}
	// 			else
	// 				{
	// 				if(commands[i].e >= 0.0)
	// 					oss << "E" << commands[i].e << " ";
	// 				}
	// 		}
	// 		oss << "F" << commands[i].f;
	// 		if(commands[i].comment.length() != 0)
	// 			oss << " ;" << commands[i].comment << "\n";
	// 		else
	// 			oss <<  "\n";
	// 		if ((commands[i].where.x() != LastPos.x()) + 
	// 		    (commands[i].where.y() != LastPos.y()) +
	// 		    (commands[i].where.z() != LastPos.z()) != 0 &&
	// 		    AntioozeDistance != 0 &&
	// 		    commands[i].e == lastE  && 
	// 		    !Use3DGcode && AntioozeDistance != 0)
	// 		{
	// 			if (UseIncrementalEcode)
	// 			{
	// 				oss << "G1 E" << lastE << "  F" << AntioozeSpeed << " ;antiooze return\n";
	// 			}
	// 			else
	// 			{
	// 				oss << "G1 E" << AntioozeDistance << "  F" << AntioozeSpeed << " ;antiooze return\n";
	// 			}
	// 		}
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		if(commands[i].Code == ZMOVE && commands[i].where.z() != LastPos.z())
	// 		  add_text_filter_nan(GcodeLayer + "\n", GcodeTxt);
	// 		  //GcodeTxt += GcodeLayer + "\n";

	// 		LastPos = commands[i].where;
	// 		if( commands[i].e >= 0.0)
	// 			lastE = commands[i].e;
	// 		break;
	// 	case EXTRUDERON:
	// 	  // Dont switch extruder on/off right after eachother
	// 		if(i != 0 && commands[i-1].Code == EXTRUDEROFF) continue;
	// 		oss  << "M101\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		break;
	// 	case EXTRUDEROFF:
	// 	  // Dont switch extruder on/off right after eachother
	// 		if(i != 0 && (i+1) < commands.size() && 
	// 		   commands[i+1].Code == EXTRUDERON) continue;	
	// 		// don't switch extruder off twize
	// 		if(i != 0 && (i+1) < commands.size() && 
	// 		   commands[i+1].Code == EXTRUDEROFF) continue;	
	// 		oss  << "M103\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		break;
	// 	case COORDINATEDMOTION3D:
	// 		oss  << "G1 X" << commands[i].where.x() << " Y" << commands[i].where.y() << " Z" << commands[i].where.z();
	// 		oss << " F" << commands[i].f;
	// 		if(commands[i].comment.length() != 0)
	// 			oss << " ;" << commands[i].comment << "\n";
	// 		else
	// 			oss <<  "\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		LastPos = commands[i].where;
	// 		break;
	// 	case RAPIDMOTION:
	// 		oss  << "G0 X" << commands[i].where.x() << " Y" << commands[i].where.y() << " Z" << commands[i].where.z()  << "\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		LastPos = commands[i].where;
	// 		break;
	// 	case GOTO:
	// 		oss  << "G92";
	// 		if(commands[i].where.x() != LastPos.x() && commands[i].where.x() >= 0)
	// 		{
	// 			LastPos.x() = commands[i].where.x();
	// 			oss << " X" << commands[i].where.x();
	// 		}
	// 		if(commands[i].where.y() != LastPos.y() && commands[i].where.y() >= 0)
	// 		{
	// 			LastPos.y() = commands[i].where.y();
	// 			oss << " Y" << commands[i].where.y();
	// 		}
	// 		if(commands[i].where.z() != LastPos.z() && commands[i].where.z() >= 0)
	// 		{
	// 			LastPos.z() = commands[i].where.z();
	// 			oss << " Z" << commands[i].where.z();
	// 		}
	// 		if(commands[i].e != lastE && commands[i].e >= 0.0)
	// 		{
	// 			lastE = commands[i].e;
	// 			oss << " E" << commands[i].e;
	// 		}
	// 		oss <<  "\n";
	// 		add_text_filter_nan(oss.str(), GcodeTxt);
	// 		//GcodeTxt += oss.str();
	// 		break;
	// 	default:
	// 		break; // ignored CGCode
	// 	}
	// 	pos = commands[i].where;
	// cerr<< oss.str()<< endl;
	//}

}
Esempio n. 10
0
void SubVisitWindow::setSubVisitDate(const Glib::Date& val)
{
	m_txtVisitDate->set_text(val.format_string("%Y-%m-%d"));
}