17
17
* along with this program; if not, write to the Free Software
18
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
* $Date: 2009-05-24 16:26:53 +0200 (Sun, 24 May 2009) $
21
* $Date: 2013-05-14 22:20:52 +0200 (Tue, 14 May 2013) $
26
26
#ifdef HAVE_CONFIG_H
123
* Moves entry identified with iID in the queue
124
* Moves entry in the queue
124
125
* returns true if successful, false if operation is not possible
126
127
void QueueEditor::MoveEntry(DownloadQueue* pDownloadQueue, FileInfo* pFileInfo, int iOffset)
153
* Set priority for entry
154
* returns true if successful, false if operation is not possible
156
void QueueEditor::SetPriorityEntry(FileInfo* pFileInfo, const char* szPriority)
158
debug("Setting priority %s for file %s", szPriority, pFileInfo->GetFilename());
159
int iPriority = atoi(szPriority);
160
pFileInfo->SetPriority(iPriority);
151
163
bool QueueEditor::EditEntry(int ID, bool bSmartOrder, EEditAction eAction, int iOffset, const char* szText)
155
167
cIDList.push_back(ID);
156
return EditList(&cIDList, bSmartOrder, eAction, iOffset, szText);
168
return EditList(&cIDList, NULL, mmID, bSmartOrder, eAction, iOffset, szText);
159
171
bool QueueEditor::LockedEditEntry(DownloadQueue* pDownloadQueue, int ID, bool bSmartOrder, EEditAction eAction, int iOffset, const char* szText)
164
176
return InternEditList(pDownloadQueue, &cIDList, bSmartOrder, eAction, iOffset, szText);
167
bool QueueEditor::EditList(IDList* pIDList, bool bSmartOrder, EEditAction eAction, int iOffset, const char* szText)
179
bool QueueEditor::EditList(IDList* pIDList, NameList* pNameList, EMatchMode eMatchMode, bool bSmartOrder,
180
EEditAction eAction, int iOffset, const char* szText)
169
182
DownloadQueue* pDownloadQueue = g_pQueueCoordinator->LockQueue();
171
bool bOK = InternEditList(pDownloadQueue, pIDList, bSmartOrder, eAction, iOffset, szText);
188
pIDList = new IDList();
189
bOK = BuildIDListFromNameList(pDownloadQueue, pIDList, pNameList, eMatchMode, eAction);
192
bOK = bOK && (InternEditList(pDownloadQueue, pIDList, bSmartOrder, eAction, iOffset, szText) || eMatchMode == mmRegEx);
173
194
if (g_pOptions->GetSaveQueue() && g_pOptions->GetServerMode())
202
228
else if (eAction == eaGroupMerge)
204
MergeGroups(pDownloadQueue, &cItemList);
230
return MergeGroups(pDownloadQueue, &cItemList);
232
else if (eAction == eaFileSplit)
234
return SplitGroup(pDownloadQueue, &cItemList, szText);
236
else if (eAction == eaFileReorder)
238
ReorderFiles(pDownloadQueue, &cItemList);
228
262
DeleteEntry(pItem->m_pFileInfo);
265
case eaFileSetPriority:
266
SetPriorityEntry(pItem->m_pFileInfo, szText);
231
269
case eaGroupSetCategory:
232
270
SetNZBCategory(pItem->m_pFileInfo->GetNZBInfo(), szText);
274
SetNZBName(pItem->m_pFileInfo->GetNZBInfo(), szText);
235
277
case eaGroupSetParameter:
236
278
SetNZBParameter(pItem->m_pFileInfo->GetNZBInfo(), szText);
244
286
case eaGroupMoveOffset:
245
287
case eaGroupPauseAllPars:
246
288
case eaGroupPauseExtraPars:
247
EditGroup(pDownloadQueue, pItem->m_pFileInfo, eAction, iOffset);
289
case eaGroupSetPriority:
290
EditGroup(pDownloadQueue, pItem->m_pFileInfo, eAction, iOffset, szText);
250
293
case eaFilePauseAllPars:
251
294
case eaFilePauseExtraPars:
252
295
case eaGroupMerge:
253
298
// remove compiler warning "enumeration not handled in switch"
368
bool QueueEditor::EditGroup(DownloadQueue* pDownloadQueue, FileInfo* pFileInfo, EEditAction eAction, int iOffset)
413
bool QueueEditor::BuildIDListFromNameList(DownloadQueue* pDownloadQueue, IDList* pIDList, NameList* pNameList, EMatchMode eMatchMode, EEditAction eAction)
416
if (eMatchMode == mmRegEx)
422
std::set<int> uniqueIDs;
424
for (NameList::iterator it = pNameList->begin(); it != pNameList->end(); it++)
426
const char* szName = *it;
428
RegEx *pRegEx = NULL;
429
if (eMatchMode == mmRegEx)
431
pRegEx = new RegEx(szName);
432
if (!pRegEx->IsValid())
441
for (FileQueue::iterator it2 = pDownloadQueue->GetFileQueue()->begin(); it2 != pDownloadQueue->GetFileQueue()->end(); it2++)
443
FileInfo* pFileInfo = *it2;
444
if (eAction < eaGroupMoveOffset)
447
char szFilename[MAX_PATH];
448
snprintf(szFilename, sizeof(szFilename) - 1, "%s/%s", pFileInfo->GetNZBInfo()->GetName(), Util::BaseFileName(pFileInfo->GetFilename()));
449
if (((!pRegEx && !strcmp(szFilename, szName)) || (pRegEx && pRegEx->Match(szFilename))) &&
450
(uniqueIDs.find(pFileInfo->GetID()) == uniqueIDs.end()))
452
uniqueIDs.insert(pFileInfo->GetID());
453
pIDList->push_back(pFileInfo->GetID());
460
const char *szFilename = pFileInfo->GetNZBInfo()->GetName();
461
if (((!pRegEx && !strcmp(szFilename, szName)) || (pRegEx && pRegEx->Match(szFilename))) &&
462
(uniqueIDs.find(pFileInfo->GetNZBInfo()->GetID()) == uniqueIDs.end()))
464
uniqueIDs.insert(pFileInfo->GetNZBInfo()->GetID());
465
pIDList->push_back(pFileInfo->GetID());
476
if (!bFound && (eMatchMode == mmName))
485
bool QueueEditor::EditGroup(DownloadQueue* pDownloadQueue, FileInfo* pFileInfo, EEditAction eAction, int iOffset, const char* szText)
431
548
pFileInfo->GetNZBInfo()->SetCleanupDisk(CanCleanupDisk(pDownloadQueue, pFileInfo->GetNZBInfo()));
434
EEditAction GroupToFileMap[] = { (EEditAction)0, eaFileMoveOffset, eaFileMoveTop, eaFileMoveBottom, eaFilePause, eaFileResume, eaFileDelete, eaFilePauseAllPars, eaFilePauseExtraPars,
435
eaFileMoveOffset, eaFileMoveTop, eaFileMoveBottom, eaFilePause, eaFileResume, eaFileDelete, eaFilePauseAllPars, eaFilePauseExtraPars, (EEditAction)0, (EEditAction)0, (EEditAction)0 };
551
EEditAction GroupToFileMap[] = { (EEditAction)0, eaFileMoveOffset, eaFileMoveTop, eaFileMoveBottom, eaFilePause,
552
eaFileResume, eaFileDelete, eaFilePauseAllPars, eaFilePauseExtraPars, eaFileSetPriority, eaFileReorder, eaFileSplit,
553
eaFileMoveOffset, eaFileMoveTop, eaFileMoveBottom, eaFilePause, eaFileResume, eaFileDelete,
554
eaFilePauseAllPars, eaFilePauseExtraPars, eaFileSetPriority,
555
(EEditAction)0, (EEditAction)0, (EEditAction)0 };
437
return InternEditList(pDownloadQueue, &cIDList, true, GroupToFileMap[eAction], iOffset, NULL);
557
return InternEditList(pDownloadQueue, &cIDList, true, GroupToFileMap[eAction], iOffset, szText);
440
560
void QueueEditor::BuildGroupList(DownloadQueue* pDownloadQueue, FileList* pGroupList)
533
653
for (FileList::iterator it = cAffectedGroupList.begin(); it != cAffectedGroupList.end(); it++)
535
655
FileInfo* pFileInfo = *it;
536
AlignGroup(pDownloadQueue, pFileInfo);
656
AlignGroup(pDownloadQueue, pFileInfo->GetNZBInfo());
540
void QueueEditor::AlignGroup(DownloadQueue* pDownloadQueue, FileInfo* pFirstFileInfo)
660
void QueueEditor::AlignGroup(DownloadQueue* pDownloadQueue, NZBInfo* pNZBInfo)
542
662
FileInfo* pLastFileInfo = NULL;
543
663
unsigned int iLastNum = 0;
687
807
g_pQueueCoordinator->SetQueueEntryNZBCategory(pNZBInfo, szCategory);
810
void QueueEditor::SetNZBName(NZBInfo* pNZBInfo, const char* szName)
812
debug("QueueEditor: renaming '%s' to '%s'", Util::BaseFileName(pNZBInfo->GetFilename()), szName);
814
g_pQueueCoordinator->SetQueueEntryNZBName(pNZBInfo, szName);
691
818
* Check if deletion of already downloaded files is possible (when nzb id deleted from queue).
692
819
* The deletion is most always possible, except the case if all remaining files in queue
715
void QueueEditor::MergeGroups(DownloadQueue* pDownloadQueue, ItemList* pItemList)
842
bool QueueEditor::MergeGroups(DownloadQueue* pDownloadQueue, ItemList* pItemList)
717
844
if (pItemList->size() == 0)
722
851
EditItem* pDestItem = pItemList->front();
724
853
for (ItemList::iterator it = pItemList->begin() + 1; it != pItemList->end(); it++)
727
856
if (pItem->m_pFileInfo->GetNZBInfo() != pDestItem->m_pFileInfo->GetNZBInfo())
729
858
debug("merge %s to %s", pItem->m_pFileInfo->GetNZBInfo()->GetFilename(), pDestItem->m_pFileInfo->GetNZBInfo()->GetFilename());
730
g_pQueueCoordinator->MergeQueueEntries(pDestItem->m_pFileInfo->GetNZBInfo(), pItem->m_pFileInfo->GetNZBInfo());
859
if (g_pQueueCoordinator->MergeQueueEntries(pDestItem->m_pFileInfo->GetNZBInfo(), pItem->m_pFileInfo->GetNZBInfo()))
735
// align group ("AlignGroup" needs the first file item as parameter)
736
for (FileQueue::iterator it = pDownloadQueue->GetFileQueue()->begin(); it != pDownloadQueue->GetFileQueue()->end(); it++)
738
FileInfo* pFileInfo = *it;
739
if (pFileInfo->GetNZBInfo() == pDestItem->m_pFileInfo->GetNZBInfo())
741
AlignGroup(pDownloadQueue, pFileInfo);
867
AlignGroup(pDownloadQueue, pDestItem->m_pFileInfo->GetNZBInfo());
746
869
delete pDestItem;
873
bool QueueEditor::SplitGroup(DownloadQueue* pDownloadQueue, ItemList* pItemList, const char* szName)
875
if (pItemList->size() == 0)
880
FileQueue* pFileList = new FileQueue();
882
for (ItemList::iterator it = pItemList->begin(); it != pItemList->end(); it++)
884
EditItem* pItem = *it;
885
pFileList->push_back(pItem->m_pFileInfo);
889
NZBInfo* pNewNZBInfo = NULL;
890
bool bOK = g_pQueueCoordinator->SplitQueueEntries(pFileList, szName, &pNewNZBInfo);
893
AlignGroup(pDownloadQueue, pNewNZBInfo);
900
void QueueEditor::ReorderFiles(DownloadQueue* pDownloadQueue, ItemList* pItemList)
902
if (pItemList->size() == 0)
907
EditItem* pFirstItem = pItemList->front();
908
NZBInfo* pNZBInfo = pFirstItem->m_pFileInfo->GetNZBInfo();
909
unsigned int iInsertPos = 0;
911
// find first file of the group
912
for (FileQueue::iterator it = pDownloadQueue->GetFileQueue()->begin(); it != pDownloadQueue->GetFileQueue()->end(); it++)
914
FileInfo* pFileInfo = *it;
915
if (pFileInfo->GetNZBInfo() == pNZBInfo)
923
for (ItemList::iterator it = pItemList->begin(); it != pItemList->end(); it++)
925
EditItem* pItem = *it;
926
FileInfo* pFileInfo = pItem->m_pFileInfo;
929
for (FileQueue::iterator it = pDownloadQueue->GetFileQueue()->begin(); it != pDownloadQueue->GetFileQueue()->end(); it++)
931
FileInfo* pFileInfo1 = *it;
932
if (pFileInfo1 == pFileInfo)
934
pDownloadQueue->GetFileQueue()->erase(it);
935
pDownloadQueue->GetFileQueue()->insert(pDownloadQueue->GetFileQueue()->begin() + iInsertPos, pFileInfo);
749
945
void QueueEditor::SetNZBParameter(NZBInfo* pNZBInfo, const char* szParamString)