void PVRClientMythTV::PVRtoMythTimer(const PVR_TIMER timer, MythTimer &mt)
{
  CStdString category = m_categories.Category(timer.iGenreType);
  mt.SetCategory(category);
  mt.SetChannelID(timer.iClientChannelUid);
  mt.SetCallsign(m_channels.at(timer.iClientChannelUid).Callsign());
  mt.SetDescription(timer.strSummary);
  mt.SetEndOffset(timer.iMarginEnd);
  mt.SetEndTime(timer.endTime);
  mt.SetInactive(timer.state == PVR_TIMER_STATE_ABORTED ||timer.state ==  PVR_TIMER_STATE_CANCELLED);
  mt.SetPriority(timer.iPriority);
  mt.SetStartOffset(timer.iMarginStart);
  mt.SetStartTime(timer.startTime);
  mt.SetTitle(timer.strTitle,true);
  CStdString title = mt.Title(false);
  mt.SetSearchType(m_db.FindProgram(timer.startTime, timer.iClientChannelUid, title, NULL) ? MythTimer::NoSearch : MythTimer::ManualSearch);
  mt.SetType(timer.bIsRepeating ? (timer.iWeekdays == 127 ? MythTimer::TimeslotRecord : MythTimer::WeekslotRecord) : MythTimer::SingleRecord);
  mt.SetRecordID(timer.iClientIndex);
}
PVR_ERROR PVRClientMythTV::AddTimer(const PVR_TIMER &timer)
{
  if (g_bExtraDebug)
    XBMC->Log(LOG_DEBUG, "%s - title: %s, start: %i, end: %i, chanID: %i", __FUNCTION__, timer.strTitle, timer.startTime, timer.iClientChannelUid);

  MythTimer mt;
  m_con.DefaultTimer(mt);
  CStdString category = m_categories.Category(timer.iGenreType);
  mt.SetCategory(category);
  mt.SetChannelID(timer.iClientChannelUid);
  mt.SetCallsign(m_channels.at(timer.iClientChannelUid).Callsign());
  mt.SetDescription(timer.strSummary);
  mt.SetEndOffset(timer.iMarginEnd);
  mt.SetEndTime(timer.endTime);
  mt.SetInactive(timer.state == PVR_TIMER_STATE_ABORTED ||timer.state ==  PVR_TIMER_STATE_CANCELLED);
  mt.SetPriority(timer.iPriority);
  mt.SetStartOffset(timer.iMarginStart);
  mt.SetStartTime(timer.startTime);
  mt.SetTitle(timer.strTitle, true);
  CStdString title = mt.Title(false);
  mt.SetSearchType(m_db.FindProgram(timer.startTime, timer.iClientChannelUid, title, NULL) ? MythTimer::NoSearch : MythTimer::ManualSearch);
  mt.SetType(timer.bIsRepeating ? (timer.iWeekdays == 127 ? MythTimer::TimeslotRecord : MythTimer::WeekslotRecord) : MythTimer::SingleRecord);

  int id = m_db.AddTimer(mt);
  if (id<0)
    return PVR_ERROR_FAILED;

  if (!m_con.UpdateSchedules(id))
    return PVR_ERROR_FAILED;

  if (g_bExtraDebug)
    XBMC->Log(LOG_DEBUG, "%s - Done - %i", __FUNCTION__, id);

  // Completion of the scheduling will be signaled by a SCHEDULE_CHANGE event.
  // Thus no need to call TriggerTimerUpdate().

  return PVR_ERROR_NO_ERROR;
}