void CPVRChannels::MoveChannel(unsigned int iOldIndex, unsigned int iNewIndex) { if (iNewIndex == iOldIndex || iNewIndex == 0) return; CPVRDatabase *database = g_PVRManager.GetTVDatabase(); database->Open(); CPVRChannels tempChannels(m_bRadio); /* move the channel */ tempChannels.push_back(at(iOldIndex - 1)); erase(begin() + iOldIndex - 1); if (iNewIndex < size()) insert(begin() + iNewIndex - 1, tempChannels[0]); else push_back(tempChannels[0]); /* update the channel numbers */ for (unsigned int ptr = 0; ptr < size(); ptr++) { CPVRChannel *channel = at(ptr); if (channel->ChannelNumber() != (int) ptr + 1) { channel->SetChannelNumber(ptr + 1, true); } } CLog::Log(LOGNOTICE, "%s - %s channel '%d' moved to '%d'", __FUNCTION__, (m_bRadio ? "radio" : "tv"), iOldIndex, iNewIndex); database->Close(); /* update the timers with the new channel numbers */ for (unsigned int ptr = 0; ptr < PVRTimers.size(); ptr++) { CPVRTimerInfoTag timer = PVRTimers[ptr]; CPVRChannel *tag = GetByClient(timer.Number(), timer.ClientID()); if (tag) timer.SetNumber(tag->ChannelNumber()); } m_bIsSorted = false; }