00001
00002
00003 #include "programrecpriority.h"
00004
00005
00006 #include <vector>
00007 using namespace std;
00008
00009
00010 #include <QDateTime>
00011 #include <QRegExp>
00012
00013
00014 #include "recordingrule.h"
00015 #include "scheduledrecording.h"
00016
00017
00018 #include "mythdb.h"
00019 #include "mythlogging.h"
00020 #include "remoteutil.h"
00021
00022
00023 #include "mythuihelper.h"
00024 #include "mythuibuttonlist.h"
00025 #include "mythuitext.h"
00026 #include "mythuistatetype.h"
00027 #include "mythdialogbox.h"
00028
00029
00030 #include "customedit.h"
00031 #include "proglist.h"
00032 #include "scheduleeditor.h"
00033
00034
00035
00036
00037 ProgramRecPriorityInfo::ProgramRecPriorityInfo(void) :
00038 RecordingInfo(),
00039 recTypeRecPriority(0), recType(kNotRecording),
00040 matchCount(0), recCount(0),
00041 last_record(QDateTime()),
00042 avg_delay(0), autoRecPriority(0),
00043 profile("")
00044 {
00045 }
00046
00047 ProgramRecPriorityInfo::ProgramRecPriorityInfo(
00048 const ProgramRecPriorityInfo &other) :
00049 RecordingInfo(other),
00050 recTypeRecPriority(other.recTypeRecPriority),
00051 recType(other.recType),
00052 matchCount(other.matchCount),
00053 recCount(other.recCount),
00054 last_record(other.last_record),
00055 avg_delay(other.avg_delay),
00056 autoRecPriority(other.autoRecPriority),
00057 profile(other.profile)
00058 {
00059 }
00060
00061 ProgramRecPriorityInfo &ProgramRecPriorityInfo::operator=(
00062 const ProgramInfo &other)
00063 {
00064 return clone(other);
00065 }
00066
00067 ProgramRecPriorityInfo &ProgramRecPriorityInfo::operator=(
00068 const ProgramRecPriorityInfo &other)
00069 {
00070 return clone(other);
00071 }
00072
00073 ProgramRecPriorityInfo &ProgramRecPriorityInfo::operator=(
00074 const RecordingInfo &other)
00075 {
00076 return clone((ProgramInfo&)other);
00077 }
00078
00079 ProgramRecPriorityInfo &ProgramRecPriorityInfo::clone(
00080 const ProgramRecPriorityInfo &other)
00081 {
00082 RecordingInfo::clone(other);
00083
00084 recTypeRecPriority = other.recTypeRecPriority;
00085 recType = other.recType;
00086 matchCount = other.matchCount;
00087 recCount = other.recCount;
00088 last_record = other.last_record;
00089 avg_delay = other.avg_delay;
00090 autoRecPriority = other.autoRecPriority;
00091 profile = other.profile;
00092
00093 return *this;
00094 }
00095
00096 ProgramRecPriorityInfo &ProgramRecPriorityInfo::clone(const ProgramInfo &other)
00097 {
00098 RecordingInfo::clone(other);
00099
00100 recTypeRecPriority = 0;
00101 recType = kNotRecording;
00102 matchCount = 0;
00103 recCount = 0;
00104 last_record = QDateTime();
00105 avg_delay = 0;
00106 autoRecPriority = 0;
00107 profile.clear();
00108
00109 return *this;
00110 }
00111
00112 void ProgramRecPriorityInfo::clear(void)
00113 {
00114 RecordingInfo::clear();
00115
00116 recTypeRecPriority = 0;
00117 recType = kNotRecording;
00118 matchCount = 0;
00119 recCount = 0;
00120 last_record = QDateTime();
00121 avg_delay = 0;
00122 autoRecPriority = 0;
00123 profile.clear();
00124 }
00125
00126 void ProgramRecPriorityInfo::ToMap(QHash<QString, QString> &progMap,
00127 bool showrerecord, uint star_range) const
00128 {
00129 RecordingInfo::ToMap(progMap, showrerecord, star_range);
00130 progMap["title"] = (title == "Default (Template)") ?
00131 QObject::tr("Default (Template)") : title;;
00132 progMap["category"] = (category == "Default") ?
00133 QObject::tr("Default") : category;
00134 }
00135
00136 class TitleSort
00137 {
00138 public:
00139 TitleSort(bool reverse) : m_reverse(reverse) {}
00140
00141 bool operator()(const ProgramRecPriorityInfo *a,
00142 const ProgramRecPriorityInfo *b) const
00143 {
00144 if (a->sortTitle != b->sortTitle)
00145 {
00146 if (m_reverse)
00147 return (a->sortTitle > b->sortTitle);
00148 else
00149 return (a->sortTitle < b->sortTitle);
00150 }
00151
00152 int finalA = a->GetRecordingPriority() +
00153 a->recTypeRecPriority;
00154 int finalB = b->GetRecordingPriority() +
00155 b->recTypeRecPriority;
00156 if (finalA != finalB)
00157 {
00158 if (m_reverse)
00159 return finalA < finalB;
00160 else
00161 return finalA > finalB;
00162 }
00163
00164 int typeA = RecTypePriority(a->recType);
00165 int typeB = RecTypePriority(b->recType);
00166
00167 if (typeA != typeB)
00168 {
00169 if (m_reverse)
00170 return typeA > typeB;
00171 else
00172 return typeA < typeB;
00173 }
00174
00175 if (m_reverse)
00176 return (a->GetRecordingRuleID() >
00177 b->GetRecordingRuleID());
00178 else
00179 return (a->GetRecordingRuleID() <
00180 b->GetRecordingRuleID());
00181 }
00182
00183 private:
00184 bool m_reverse;
00185 };
00186
00187 class ProgramRecPrioritySort
00188 {
00189 public:
00190 ProgramRecPrioritySort(bool reverse) : m_reverse(reverse) {}
00191
00192 bool operator()(const ProgramRecPriorityInfo *a,
00193 const ProgramRecPriorityInfo *b) const
00194 {
00195 int finalA = (a->GetRecordingPriority() +
00196 a->autoRecPriority +
00197 a->recTypeRecPriority);
00198 int finalB = (b->GetRecordingPriority() +
00199 b->autoRecPriority +
00200 b->recTypeRecPriority);
00201
00202 if (finalA != finalB)
00203 {
00204 if (m_reverse)
00205 return finalA < finalB;
00206 else
00207 return finalA > finalB;
00208 }
00209
00210 int typeA = RecTypePriority(a->recType);
00211 int typeB = RecTypePriority(b->recType);
00212
00213 if (typeA != typeB)
00214 {
00215 if (m_reverse)
00216 return typeA > typeB;
00217 else
00218 return typeA < typeB;
00219 }
00220
00221 if (m_reverse)
00222 return (a->GetRecordingRuleID() >
00223 b->GetRecordingRuleID());
00224 else
00225 return (a->GetRecordingRuleID() <
00226 b->GetRecordingRuleID());
00227 }
00228
00229 private:
00230 bool m_reverse;
00231 };
00232
00233 class ProgramRecTypeSort
00234 {
00235 public:
00236 ProgramRecTypeSort(bool reverse) : m_reverse(reverse) {}
00237
00238 bool operator()(const ProgramRecPriorityInfo *a,
00239 const ProgramRecPriorityInfo *b) const
00240 {
00241 int typeA = RecTypePriority(a->recType);
00242 int typeB = RecTypePriority(b->recType);
00243
00244 if (typeA != typeB)
00245 {
00246 if (m_reverse)
00247 return (typeA > typeB);
00248 else
00249 return (typeA < typeB);
00250 }
00251
00252 int finalA = (a->GetRecordingPriority() +
00253 a->recTypeRecPriority);
00254 int finalB = (b->GetRecordingPriority() +
00255 b->recTypeRecPriority);
00256
00257 if (finalA != finalB)
00258 {
00259 if (m_reverse)
00260 return finalA < finalB;
00261 else
00262 return finalA > finalB;
00263 }
00264
00265 if (m_reverse)
00266 return (a->GetRecordingRuleID() >
00267 b->GetRecordingRuleID());
00268 else
00269 return (a->GetRecordingRuleID() <
00270 b->GetRecordingRuleID());
00271 }
00272
00273 private:
00274 bool m_reverse;
00275 };
00276
00277 class ProgramCountSort
00278 {
00279 public:
00280 ProgramCountSort(bool reverse) : m_reverse(reverse) {}
00281
00282 bool operator()(const ProgramRecPriorityInfo *a,
00283 const ProgramRecPriorityInfo *b) const
00284 {
00285 int countA = a->matchCount;
00286 int countB = b->matchCount;
00287 int recCountA = a->recCount;
00288 int recCountB = b->recCount;
00289
00290 if (countA != countB)
00291 {
00292 if (m_reverse)
00293 return countA < countB;
00294 else
00295 return countA > countB;
00296 }
00297
00298 if (recCountA != recCountB)
00299 {
00300 if (m_reverse)
00301 return recCountA < recCountB;
00302 else
00303 return recCountA > recCountB;
00304 }
00305
00306 if (m_reverse)
00307 return (a->sortTitle > b->sortTitle);
00308 else
00309 return (a->sortTitle < b->sortTitle);
00310 }
00311
00312 private:
00313 bool m_reverse;
00314 };
00315
00316 class ProgramRecCountSort
00317 {
00318 public:
00319 ProgramRecCountSort(bool reverse) : m_reverse(reverse) {}
00320
00321 bool operator()(const ProgramRecPriorityInfo *a,
00322 const ProgramRecPriorityInfo *b) const
00323 {
00324 int countA = a->matchCount;
00325 int countB = b->matchCount;
00326 int recCountA = a->recCount;
00327 int recCountB = b->recCount;
00328
00329 if (recCountA != recCountB)
00330 {
00331 if (m_reverse)
00332 return recCountA < recCountB;
00333 else
00334 return recCountA > recCountB;
00335 }
00336
00337 if (countA != countB)
00338 {
00339 if (m_reverse)
00340 return countA < countB;
00341 else
00342 return countA > countB;
00343 }
00344
00345 if (m_reverse)
00346 return (a->sortTitle > b->sortTitle);
00347 else
00348 return (a->sortTitle < b->sortTitle);
00349 }
00350
00351 private:
00352 bool m_reverse;
00353 };
00354
00355 class ProgramLastRecordSort
00356 {
00357 public:
00358 ProgramLastRecordSort(bool reverse) : m_reverse(reverse) {}
00359
00360 bool operator()(const ProgramRecPriorityInfo *a,
00361 const ProgramRecPriorityInfo *b) const
00362 {
00363 QDateTime lastRecA = a->last_record;
00364 QDateTime lastRecB = b->last_record;
00365
00366 if (lastRecA != lastRecB)
00367 {
00368 if (m_reverse)
00369 return lastRecA < lastRecB;
00370 else
00371 return lastRecA > lastRecB;
00372 }
00373
00374 if (m_reverse)
00375 return (a->sortTitle > b->sortTitle);
00376 else
00377 return (a->sortTitle < b->sortTitle);
00378 }
00379
00380 private:
00381 bool m_reverse;
00382 };
00383
00384 class ProgramAvgDelaySort
00385 {
00386 public:
00387 ProgramAvgDelaySort(bool reverse) : m_reverse(reverse) {}
00388
00389 bool operator()(const ProgramRecPriorityInfo *a,
00390 const ProgramRecPriorityInfo *b) const
00391 {
00392 int avgA = a->avg_delay;
00393 int avgB = b->avg_delay;
00394
00395 if (avgA != avgB)
00396 {
00397 if (m_reverse)
00398 return avgA > avgB;
00399 else
00400 return avgA < avgB;
00401 }
00402
00403 if (m_reverse)
00404 return (a->sortTitle > b->sortTitle);
00405 else
00406 return (a->sortTitle < b->sortTitle);
00407 }
00408
00409 private:
00410 bool m_reverse;
00411 };
00412
00414
00415 ProgramRecPriority::ProgramRecPriority(MythScreenStack *parent,
00416 const QString &name)
00417 : ScheduleCommon(parent, name),
00418 m_programList(NULL), m_schedInfoText(NULL),
00419 m_rectypePriorityText(NULL), m_recPriorityText(NULL),
00420 m_recPriorityBText(NULL), m_finalPriorityText(NULL),
00421 m_lastRecordedText(NULL), m_lastRecordedDateText(NULL),
00422 m_lastRecordedTimeText(NULL), m_channameText(NULL),
00423 m_channumText(NULL), m_callsignText(NULL),
00424 m_recProfileText(NULL), m_currentItem(NULL)
00425 {
00426 m_sortType = (SortType)gCoreContext->GetNumSetting("ProgramRecPrioritySorting",
00427 (int)byTitle);
00428 m_reverseSort = gCoreContext->GetNumSetting("ProgramRecPriorityReverse", 0);
00429 }
00430
00431 ProgramRecPriority::~ProgramRecPriority()
00432 {
00433 }
00434
00435 bool ProgramRecPriority::Create()
00436 {
00437 QString window_name = "programrecpriority";
00438 if (objectName() == "ManageRecRules")
00439 window_name = "managerecrules";
00440
00441 if (!LoadWindowFromXML("schedule-ui.xml", window_name, this))
00442 return false;
00443
00444 m_programList = dynamic_cast<MythUIButtonList *> (GetChild("programs"));
00445
00446 m_schedInfoText = dynamic_cast<MythUIText *> (GetChild("scheduleinfo"));
00447 m_rectypePriorityText = dynamic_cast<MythUIText *>
00448 (GetChild("rectypepriority"));
00449 m_recPriorityText = dynamic_cast<MythUIText *> (GetChild("recpriority"));
00450 m_recPriorityBText = dynamic_cast<MythUIText *> (GetChild("recpriorityB"));
00451 m_finalPriorityText = dynamic_cast<MythUIText *> (GetChild("finalpriority"));
00452 m_lastRecordedText = dynamic_cast<MythUIText *> (GetChild("lastrecorded"));
00453 m_lastRecordedDateText = dynamic_cast<MythUIText *> (GetChild("lastrecordeddate"));
00454 m_lastRecordedTimeText = dynamic_cast<MythUIText *> (GetChild("lastrecordedtime"));
00455 m_channameText = dynamic_cast<MythUIText *> (GetChild("channel"));
00456 m_channumText = dynamic_cast<MythUIText *> (GetChild("channum"));
00457 m_callsignText = dynamic_cast<MythUIText *> (GetChild("callsign"));
00458 m_recProfileText = dynamic_cast<MythUIText *> (GetChild("recordingprofile"));
00459
00460 if (!m_programList)
00461 {
00462 LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical theme elements.");
00463 return false;
00464 }
00465
00466 connect(m_programList, SIGNAL(itemSelected(MythUIButtonListItem*)),
00467 SLOT(updateInfo(MythUIButtonListItem*)));
00468 connect(m_programList, SIGNAL(itemClicked(MythUIButtonListItem*)),
00469 SLOT(edit(MythUIButtonListItem*)));
00470
00471 m_programList->SetLCDTitles(tr("Schedule Priorities"),
00472 "rec_type|titlesubtitle|progpriority|finalpriority");
00473 m_programList->SetSearchFields("titlesubtitle");
00474
00475 BuildFocusList();
00476 LoadInBackground();
00477
00478 return true;
00479 }
00480
00481 void ProgramRecPriority::Load(void)
00482 {
00483 FillList();
00484 }
00485
00486 void ProgramRecPriority::Init(void)
00487 {
00488 SortList();
00489 }
00490
00491 bool ProgramRecPriority::keyPressEvent(QKeyEvent *event)
00492 {
00493 if (GetFocusWidget()->keyPressEvent(event))
00494 return true;
00495
00496 bool handled = false;
00497 QStringList actions;
00498 handled = GetMythMainWindow()->TranslateKeyPress("TV Frontend", event, actions);
00499
00500 for (int i = 0; i < actions.size() && !handled; i++)
00501 {
00502 QString action = actions[i];
00503 handled = true;
00504
00505 if (action == "RANKINC")
00506 changeRecPriority(1);
00507 else if (action == "RANKDEC")
00508 changeRecPriority(-1);
00509 else if (action == "ESCAPE")
00510 {
00511 saveRecPriority();
00512 gCoreContext->SaveSetting("ProgramRecPrioritySorting",
00513 (int)m_sortType);
00514 gCoreContext->SaveSetting("ProgramRecPriorityReverse",
00515 (int)m_reverseSort);
00516 Close();
00517 }
00518 else if (action == "1")
00519 {
00520 if (m_sortType != byTitle)
00521 {
00522 m_sortType = byTitle;
00523 m_reverseSort = false;
00524 }
00525 else
00526 m_reverseSort = !m_reverseSort;
00527 SortList();
00528 }
00529 else if (action == "2")
00530 {
00531 if (m_sortType != byRecPriority)
00532 {
00533 m_sortType = byRecPriority;
00534 m_reverseSort = false;
00535 }
00536 else
00537 m_reverseSort = !m_reverseSort;
00538 SortList();
00539 }
00540 else if (action == "4")
00541 {
00542 if (m_sortType != byRecType)
00543 {
00544 m_sortType = byRecType;
00545 m_reverseSort = false;
00546 }
00547 else
00548 m_reverseSort = !m_reverseSort;
00549 SortList();
00550 }
00551 else if (action == "5")
00552 {
00553 if (m_sortType != byCount)
00554 {
00555 m_sortType = byCount;
00556 m_reverseSort = false;
00557 }
00558 else
00559 {
00560 m_reverseSort = !m_reverseSort;
00561 }
00562 SortList();
00563 }
00564 else if (action == "6")
00565 {
00566 if (m_sortType != byRecCount)
00567 {
00568 m_sortType = byRecCount;
00569 m_reverseSort = false;
00570 }
00571 else
00572 m_reverseSort = !m_reverseSort;
00573 SortList();
00574 }
00575 else if (action == "7")
00576 {
00577 if (m_sortType != byLastRecord)
00578 {
00579 m_sortType = byLastRecord;
00580 m_reverseSort = false;
00581 }
00582 else
00583 m_reverseSort = !m_reverseSort;
00584 SortList();
00585 }
00586 else if (action == "8")
00587 {
00588 if (m_sortType != byAvgDelay)
00589 {
00590 m_sortType = byAvgDelay;
00591 m_reverseSort = false;
00592 }
00593 else
00594 m_reverseSort = !m_reverseSort;
00595 SortList();
00596 }
00597 else if (action == "PREVVIEW" || action == "NEXTVIEW")
00598 {
00599 m_reverseSort = false;
00600 if (m_sortType == byTitle)
00601 m_sortType = byRecPriority;
00602 else if (m_sortType == byRecPriority)
00603 m_sortType = byRecType;
00604 else
00605 m_sortType = byTitle;
00606 SortList();
00607 }
00608 else if (action == "SELECT" || action == "EDIT")
00609 {
00610 saveRecPriority();
00611 edit(m_programList->GetItemCurrent());
00612 }
00613 else if (action == "MENU")
00614 {
00615 showMenu();
00616 }
00617 else if (action == "CUSTOMEDIT")
00618 {
00619 saveRecPriority();
00620 customEdit();
00621 }
00622 else if (action == "DELETE")
00623 {
00624 saveRecPriority();
00625 remove();
00626 }
00627 else if (action == "UPCOMING")
00628 {
00629 saveRecPriority();
00630 upcoming();
00631 }
00632 else if (action == "INFO" || action == "DETAILS")
00633 details();
00634 else
00635 handled = false;
00636 }
00637
00638 if (!handled && MythScreenType::keyPressEvent(event))
00639 handled = true;
00640
00641 return handled;
00642 }
00643
00644 void ProgramRecPriority::showMenu(void)
00645 {
00646 QString label = tr("Options");
00647
00648 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
00649 MythDialogBox *menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
00650
00651 if (menuPopup->Create())
00652 {
00653 menuPopup->SetReturnEvent(this, "menu");
00654
00655 menuPopup->AddButton(tr("Increase Priority"));
00656 menuPopup->AddButton(tr("Decrease Priority"));
00657 menuPopup->AddButton(tr("Sort"), NULL, true);
00658 menuPopup->AddButton(tr("Program Details"));
00659 menuPopup->AddButton(tr("Upcoming"));
00660 menuPopup->AddButton(tr("Custom Edit"));
00661 menuPopup->AddButton(tr("Delete Rule"));
00662 menuPopup->AddButton(tr("New Template"));
00663
00664 popupStack->AddScreen(menuPopup);
00665 }
00666 else
00667 {
00668 delete menuPopup;
00669 }
00670 }
00671
00672 void ProgramRecPriority::showSortMenu(void)
00673 {
00674 QString label = tr("Sort Options");
00675
00676 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
00677 MythDialogBox *menuPopup = new MythDialogBox(label, popupStack, "menuPopup");
00678
00679 if (menuPopup->Create())
00680 {
00681 menuPopup->SetReturnEvent(this, "sortmenu");
00682
00683 menuPopup->AddButton(tr("Reverse Sort Order"));
00684 menuPopup->AddButton(tr("Sort By Title"));
00685 menuPopup->AddButton(tr("Sort By Priority"));
00686 menuPopup->AddButton(tr("Sort By Type"));
00687 menuPopup->AddButton(tr("Sort By Count"));
00688 menuPopup->AddButton(tr("Sort By Record Count"));
00689 menuPopup->AddButton(tr("Sort By Last Recorded"));
00690 menuPopup->AddButton(tr("Sort By Average Delay"));
00691
00692 popupStack->AddScreen(menuPopup);
00693 }
00694 else
00695 {
00696 delete menuPopup;
00697 }
00698 }
00699
00700 void ProgramRecPriority::customEvent(QEvent *event)
00701 {
00702 if (event->type() == DialogCompletionEvent::kEventType)
00703 {
00704 DialogCompletionEvent *dce = (DialogCompletionEvent*)(event);
00705
00706 QString resultid = dce->GetId();
00707 QString resulttext = dce->GetResultText();
00708 int buttonnum = dce->GetResult();
00709
00710 if (resultid == "menu")
00711 {
00712 if (resulttext == tr("Increase Priority"))
00713 {
00714 changeRecPriority(1);
00715 }
00716 else if (resulttext == tr("Decrease Priority"))
00717 {
00718 changeRecPriority(-1);
00719 }
00720 else if (resulttext == tr("Sort"))
00721 {
00722 showSortMenu();
00723 }
00724 else if (resulttext == tr("Program Details"))
00725 {
00726 details();
00727 }
00728 else if (resulttext == tr("Upcoming"))
00729 {
00730 saveRecPriority();
00731 upcoming();
00732 }
00733 else if (resulttext == tr("Custom Edit"))
00734 {
00735 saveRecPriority();
00736 customEdit();
00737 }
00738 else if (resulttext == tr("Delete Rule"))
00739 {
00740 saveRecPriority();
00741 remove();
00742 }
00743 else if (resulttext == tr("New Template"))
00744 {
00745 MythScreenStack *popupStack =
00746 GetMythMainWindow()->GetStack("popup stack");
00747 MythTextInputDialog *textInput =
00748 new MythTextInputDialog(popupStack,
00749 tr("Template Name"));
00750 if (textInput->Create())
00751 {
00752 textInput->SetReturnEvent(this, "templatecat");
00753 popupStack->AddScreen(textInput);
00754 }
00755 }
00756 }
00757 else if (resultid == "sortmenu")
00758 {
00759 if (resulttext == tr("Reverse Sort Order"))
00760 {
00761 m_reverseSort = !m_reverseSort;
00762 SortList();
00763 }
00764 else if (resulttext == tr("Sort By Title"))
00765 {
00766 if (m_sortType != byTitle)
00767 {
00768 m_sortType = byTitle;
00769 m_reverseSort = false;
00770 }
00771 else
00772 m_reverseSort = !m_reverseSort;
00773 SortList();
00774 }
00775 else if (resulttext == tr("Sort By Priority"))
00776 {
00777 if (m_sortType != byRecPriority)
00778 {
00779 m_sortType = byRecPriority;
00780 m_reverseSort = false;
00781 }
00782 else
00783 m_reverseSort = !m_reverseSort;
00784 SortList();
00785 }
00786 else if (resulttext == tr("Sort By Type"))
00787 {
00788 if (m_sortType != byRecType)
00789 {
00790 m_sortType = byRecType;
00791 m_reverseSort = false;
00792 }
00793 else
00794 m_reverseSort = !m_reverseSort;
00795 SortList();
00796 }
00797 else if (resulttext == tr("Sort By Count"))
00798 {
00799 if (m_sortType != byCount)
00800 {
00801 m_sortType = byCount;
00802 m_reverseSort = false;
00803 }
00804 else
00805 {
00806 m_reverseSort = !m_reverseSort;
00807 }
00808 SortList();
00809 }
00810 else if (resulttext == tr("Sort By Record Count"))
00811 {
00812 if (m_sortType != byRecCount)
00813 {
00814 m_sortType = byRecCount;
00815 m_reverseSort = false;
00816 }
00817 else
00818 m_reverseSort = !m_reverseSort;
00819 SortList();
00820 }
00821 else if (resulttext == tr("Sort By Last Recorded"))
00822 {
00823 if (m_sortType != byLastRecord)
00824 {
00825 m_sortType = byLastRecord;
00826 m_reverseSort = false;
00827 }
00828 else
00829 m_reverseSort = !m_reverseSort;
00830 SortList();
00831 }
00832 else if (resulttext == tr("Sort By Average Delay"))
00833 {
00834 if (m_sortType != byAvgDelay)
00835 {
00836 m_sortType = byAvgDelay;
00837 m_reverseSort = false;
00838 }
00839 else
00840 m_reverseSort = !m_reverseSort;
00841 SortList();
00842 }
00843 }
00844 else if (resultid == "deleterule")
00845 {
00846 RecordingRule *record =
00847 qVariantValue<RecordingRule *>(dce->GetData());
00848 if (record)
00849 {
00850 if (buttonnum > 0)
00851 {
00852 MythUIButtonListItem *item =
00853 m_programList->GetItemCurrent();
00854
00855 if (record->Delete() && item)
00856 RemoveItemFromList(item);
00857 else
00858 LOG(VB_GENERAL, LOG_ERR,
00859 "Failed to delete recording rule");
00860 }
00861 delete record;
00862 }
00863 }
00864 else if (resultid == "templatecat")
00865 {
00866 newTemplate(resulttext);
00867 }
00868 else
00869 ScheduleCommon::customEvent(event);
00870 }
00871 }
00872
00873 void ProgramRecPriority::edit(MythUIButtonListItem *item)
00874 {
00875 if (!item)
00876 return;
00877
00878 ProgramRecPriorityInfo *pgRecInfo =
00879 qVariantValue<ProgramRecPriorityInfo*>(item->GetData());
00880
00881 if (!pgRecInfo)
00882 return;
00883
00884 RecordingRule *record = new RecordingRule();
00885 record->m_recordID = pgRecInfo->GetRecordingRuleID();
00886 if (record->m_searchType == kNoSearch)
00887 record->LoadByProgram(pgRecInfo);
00888
00889 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00890 ScheduleEditor *schededit = new ScheduleEditor(mainStack, record);
00891 if (schededit->Create())
00892 {
00893 mainStack->AddScreen(schededit);
00894 connect(schededit, SIGNAL(ruleSaved(int)), SLOT(scheduleChanged(int)));
00895 connect(schededit, SIGNAL(ruleDeleted(int)), SLOT(scheduleChanged(int)));
00896 }
00897 else
00898 delete schededit;
00899 }
00900
00901 void ProgramRecPriority::newTemplate(QString category)
00902 {
00903 category = category.trimmed();
00904 if (category.isEmpty())
00905 return;
00906
00907
00908 QMap<int, ProgramRecPriorityInfo>::Iterator it;
00909 for (it = m_programData.begin(); it != m_programData.end(); ++it)
00910 {
00911 ProgramRecPriorityInfo *progInfo = &(*it);
00912 if (progInfo->GetRecordingRuleType() == kTemplateRecord &&
00913 category.compare(progInfo->GetCategory(),
00914 Qt::CaseInsensitive) == 0)
00915 {
00916 m_programList->SetValueByData(qVariantFromValue(progInfo));
00917 edit(m_programList->GetItemCurrent());
00918 return;
00919 }
00920 }
00921
00922 RecordingRule *record = new RecordingRule();
00923 if (!record)
00924 return;
00925 record->MakeTemplate(category);
00926
00927 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00928 ScheduleEditor *schededit = new ScheduleEditor(mainStack, record);
00929 if (schededit->Create())
00930 {
00931 mainStack->AddScreen(schededit);
00932 connect(schededit, SIGNAL(ruleSaved(int)), SLOT(scheduleChanged(int)));
00933 connect(schededit, SIGNAL(ruleDeleted(int)), SLOT(scheduleChanged(int)));
00934 }
00935 else
00936 delete schededit;
00937 }
00938
00939 void ProgramRecPriority::scheduleChanged(int recid)
00940 {
00941 int rtRecPriors[12];
00942 rtRecPriors[kNotRecording] = 0;
00943 rtRecPriors[kSingleRecord] =
00944 gCoreContext->GetNumSetting("SingleRecordRecPriority", 1);
00945 rtRecPriors[kTimeslotRecord] =
00946 gCoreContext->GetNumSetting("TimeslotRecordRecPriority", 0);
00947 rtRecPriors[kChannelRecord] =
00948 gCoreContext->GetNumSetting("ChannelRecordRecPriority", 0);
00949 rtRecPriors[kAllRecord] =
00950 gCoreContext->GetNumSetting("AllRecordRecPriority", 0);
00951 rtRecPriors[kWeekslotRecord] =
00952 gCoreContext->GetNumSetting("WeekslotRecordRecPriority", 0);
00953 rtRecPriors[kFindOneRecord] =
00954 gCoreContext->GetNumSetting("FindOneRecordRecPriority", -1);
00955 rtRecPriors[kOverrideRecord] =
00956 gCoreContext->GetNumSetting("OverrideRecordRecPriority", 0);
00957 rtRecPriors[kDontRecord] =
00958 gCoreContext->GetNumSetting("OverrideRecordRecPriority", 0);
00959 rtRecPriors[kFindDailyRecord] =
00960 gCoreContext->GetNumSetting("FindOneRecordRecPriority", -1);
00961 rtRecPriors[kFindWeeklyRecord] =
00962 gCoreContext->GetNumSetting("FindOneRecordRecPriority", -1);
00963 rtRecPriors[kTemplateRecord] = 0;
00964
00965
00966 MythUIButtonListItem *item = m_programList->GetItemCurrent();
00967 ProgramRecPriorityInfo *pgRecInfo = NULL;
00968 if (item)
00969 pgRecInfo = qVariantValue<ProgramRecPriorityInfo*>(item->GetData());
00970
00971
00972
00973 if (!pgRecInfo || recid != pgRecInfo->getRecordID())
00974 {
00975 RecordingRule record;
00976 record.m_recordID = recid;
00977 if (!record.Load() || record.m_type == kNotRecording)
00978 return;
00979
00980 ProgramRecPriorityInfo progInfo;
00981 progInfo.SetRecordingRuleID(record.m_recordID);
00982 progInfo.SetRecordingRuleType(record.m_type);
00983 progInfo.SetTitle(record.m_title);
00984 progInfo.SetCategory(record.m_category);
00985 progInfo.SetRecordingPriority(record.m_recPriority);
00986 progInfo.recType = record.m_type;
00987 progInfo.sortTitle = record.m_title;
00988 progInfo.recTypeRecPriority = rtRecPriors[progInfo.recType];
00989 progInfo.recstatus = record.m_isInactive ?
00990 rsInactive : rsUnknown;
00991 progInfo.profile = record.m_recProfile;
00992 progInfo.last_record = record.m_lastRecorded;
00993
00994 m_programData[recid] = progInfo;
00995 m_origRecPriorityData[record.m_recordID] =
00996 record.m_recPriority;
00997 SortList(&m_programData[recid]);
00998
00999 return;
01000 }
01001
01002
01003
01004
01005 MSqlQuery query(MSqlQuery::InitCon());
01006 query.prepare("SELECT recpriority, type, inactive "
01007 "FROM record "
01008 "WHERE recordid = :RECORDID");
01009 query.bindValue(":RECORDID", recid);
01010 if (!query.exec())
01011 {
01012 MythDB::DBError("Get new recording priority query", query);
01013 }
01014 else if (query.next())
01015 {
01016 int recPriority = query.value(0).toInt();
01017 int rectype = query.value(1).toInt();
01018 int inactive = query.value(2).toInt();
01019
01020
01021 pgRecInfo->SetRecordingPriority(recPriority);
01022 pgRecInfo->recType = (RecordingType)rectype;
01023 pgRecInfo->recTypeRecPriority = rtRecPriors[pgRecInfo->recType];
01024
01025
01026 m_origRecPriorityData[pgRecInfo->GetRecordingRuleID()] =
01027 pgRecInfo->GetRecordingPriority();
01028
01029 pgRecInfo->recstatus = inactive ? rsInactive : rsUnknown;
01030
01031 SortList();
01032 }
01033 else
01034 {
01035 RemoveItemFromList(item);
01036 }
01037
01038 countMatches();
01039 }
01040
01041 void ProgramRecPriority::customEdit(void)
01042 {
01043 MythUIButtonListItem *item = m_programList->GetItemCurrent();
01044 if (!item)
01045 return;
01046
01047 ProgramRecPriorityInfo *pgRecInfo =
01048 qVariantValue<ProgramRecPriorityInfo*>(item->GetData());
01049
01050 EditCustom(pgRecInfo);
01051 }
01052
01053 void ProgramRecPriority::remove(void)
01054 {
01055 MythUIButtonListItem *item = m_programList->GetItemCurrent();
01056 if (!item)
01057 return;
01058
01059 ProgramRecPriorityInfo *pgRecInfo =
01060 qVariantValue<ProgramRecPriorityInfo*>(item->GetData());
01061
01062 if (!pgRecInfo ||
01063 (pgRecInfo->recType == kTemplateRecord &&
01064 pgRecInfo->GetCategory()
01065 .compare("Default", Qt::CaseInsensitive) == 0))
01066 {
01067 return;
01068 }
01069
01070 RecordingRule *record = new RecordingRule();
01071 record->m_recordID = pgRecInfo->GetRecordingRuleID();
01072 if (!record->Load())
01073 {
01074 delete record;
01075 return;
01076 }
01077
01078 QString message = tr("Delete '%1' %2 rule?").arg(record->m_title)
01079 .arg(toString(pgRecInfo->GetRecordingRuleType()));
01080
01081 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
01082
01083 MythConfirmationDialog *okPopup = new MythConfirmationDialog(popupStack,
01084 message, true);
01085
01086 okPopup->SetReturnEvent(this, "deleterule");
01087 okPopup->SetData(qVariantFromValue(record));
01088
01089 if (okPopup->Create())
01090 popupStack->AddScreen(okPopup);
01091 else
01092 delete okPopup;
01093 }
01094
01095 void ProgramRecPriority::deactivate(void)
01096 {
01097 MythUIButtonListItem *item = m_programList->GetItemCurrent();
01098 if (!item)
01099 return;
01100
01101 ProgramRecPriorityInfo *pgRecInfo =
01102 qVariantValue<ProgramRecPriorityInfo*>(item->GetData());
01103
01104 if (pgRecInfo)
01105 {
01106 MSqlQuery query(MSqlQuery::InitCon());
01107
01108 query.prepare("SELECT inactive "
01109 "FROM record "
01110 "WHERE recordid = :RECID");
01111 query.bindValue(":RECID", pgRecInfo->GetRecordingRuleID());
01112
01113
01114 if (!query.exec())
01115 {
01116 MythDB::DBError("ProgramRecPriority::deactivate()", query);
01117 }
01118 else if (query.next())
01119 {
01120 int inactive = query.value(0).toInt();
01121 if (inactive)
01122 inactive = 0;
01123 else
01124 inactive = 1;
01125
01126 query.prepare("UPDATE record "
01127 "SET inactive = :INACTIVE "
01128 "WHERE recordid = :RECID");
01129 query.bindValue(":INACTIVE", inactive);
01130 query.bindValue(":RECID", pgRecInfo->GetRecordingRuleID());
01131
01132 if (!query.exec())
01133 {
01134 MythDB::DBError(
01135 "Update recording schedule inactive query", query);
01136 }
01137 else
01138 {
01139 ScheduledRecording::ReschedulePlace(
01140 QString("DeactivateRule %1 %2")
01141 .arg(pgRecInfo->GetRecordingRuleID())
01142 .arg(pgRecInfo->GetTitle()));
01143 pgRecInfo->recstatus = inactive ? rsInactive : rsUnknown;
01144 item->DisplayState("disabled", "status");
01145 }
01146 }
01147 }
01148 }
01149
01150 void ProgramRecPriority::upcoming(void)
01151 {
01152 MythUIButtonListItem *item = m_programList->GetItemCurrent();
01153 if (!item)
01154 return;
01155
01156 ProgramRecPriorityInfo *pgRecInfo =
01157 qVariantValue<ProgramRecPriorityInfo*>(item->GetData());
01158
01159 if (!pgRecInfo)
01160 return;
01161
01162 if (m_listMatch[pgRecInfo->GetRecordingRuleID()] > 0)
01163 {
01164 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
01165 ProgLister *pl = new ProgLister(
01166 mainStack, plRecordid,
01167 QString::number(pgRecInfo->GetRecordingRuleID()), "");
01168
01169 if (pl->Create())
01170 mainStack->AddScreen(pl);
01171 else
01172 delete pl;
01173 }
01174 else
01175 {
01176 ProgLister *pl = NULL;
01177 QString trimTitle = pgRecInfo->title;
01178 trimTitle.remove(QRegExp(" \\(.*\\)$"));
01179 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
01180 pl = new ProgLister(mainStack, plTitle, trimTitle,
01181 pgRecInfo->GetSeriesID());
01182 if (pl->Create())
01183 mainStack->AddScreen(pl);
01184 else
01185 delete pl;
01186 }
01187 }
01188
01189 void ProgramRecPriority::details(void)
01190 {
01191 MythUIButtonListItem *item = m_programList->GetItemCurrent();
01192 if (!item)
01193 return;
01194
01195 ProgramRecPriorityInfo *pgRecInfo = qVariantValue<ProgramRecPriorityInfo *>
01196 (item->GetData());
01197
01198 ShowDetails(pgRecInfo);
01199 }
01200
01201 void ProgramRecPriority::changeRecPriority(int howMuch)
01202 {
01203 MythUIButtonListItem *item = m_programList->GetItemCurrent();
01204 if (!item)
01205 return;
01206
01207 ProgramRecPriorityInfo *pgRecInfo =
01208 qVariantValue<ProgramRecPriorityInfo*>(item->GetData());
01209
01210 if (!pgRecInfo)
01211 return;
01212
01213 int tempRecPriority;
01214
01215 tempRecPriority = pgRecInfo->GetRecordingPriority() + howMuch;
01216 if (tempRecPriority > -100 && tempRecPriority < 100)
01217 {
01218 pgRecInfo->recpriority = tempRecPriority;
01219
01220
01221 if (m_sortType == byRecPriority)
01222 SortList();
01223 else
01224 {
01225
01226 int progRecPriority = pgRecInfo->GetRecordingPriority();
01227 int autorecpri = pgRecInfo->autoRecPriority;
01228 int finalRecPriority = progRecPriority +
01229 autorecpri +
01230 pgRecInfo->recTypeRecPriority;
01231
01232 item->SetText(QString::number(progRecPriority), "progpriority");
01233
01234 QString msg = QString::number(progRecPriority);
01235 if(autorecpri != 0)
01236 msg += tr(" + %1 automatic priority (%2hr)")
01237 .arg(autorecpri).arg(pgRecInfo->avg_delay);
01238 item->SetText(msg, "recpriority");
01239 if (m_recPriorityText)
01240 m_recPriorityText->SetText(msg);
01241
01242 item->SetText(QString::number(progRecPriority +
01243 autorecpri), "recpriorityB");
01244 if (m_recPriorityBText)
01245 m_recPriorityBText->SetText(QString::number(progRecPriority +
01246 autorecpri));
01247
01248 item->SetText(QString::number(finalRecPriority), "finalpriority");
01249 if (m_finalPriorityText)
01250 m_finalPriorityText->SetText(QString::number(finalRecPriority));
01251 }
01252 }
01253 }
01254
01255 void ProgramRecPriority::saveRecPriority(void)
01256 {
01257 QMap<int, ProgramRecPriorityInfo>::Iterator it;
01258
01259 for (it = m_programData.begin(); it != m_programData.end(); ++it)
01260 {
01261 ProgramRecPriorityInfo *progInfo = &(*it);
01262 int key = progInfo->GetRecordingRuleID();
01263
01264
01265
01266 if (progInfo->GetRecordingPriority() != m_origRecPriorityData[key])
01267 progInfo->ApplyRecordRecPriorityChange(
01268 progInfo->GetRecordingPriority());
01269 }
01270 }
01271
01272 void ProgramRecPriority::FillList(void)
01273 {
01274 int rtRecPriors[12];
01275 vector<ProgramInfo *> recordinglist;
01276
01277 int autopriority = gCoreContext->GetNumSetting("AutoRecPriority", 0);
01278
01279 m_programData.clear();
01280
01281 RemoteGetAllScheduledRecordings(recordinglist);
01282
01283 vector<ProgramInfo *>::iterator pgiter = recordinglist.begin();
01284
01285 for (; pgiter != recordinglist.end(); ++pgiter)
01286 {
01287 ProgramInfo *progInfo = *pgiter;
01288 m_programData[(*pgiter)->GetRecordingRuleID()] =
01289 (*progInfo);
01290
01291
01292
01293 m_origRecPriorityData[(*pgiter)->GetRecordingRuleID()] =
01294 (*pgiter)->GetRecordingPriority();
01295
01296 delete (*pgiter);
01297 }
01298
01299
01300 rtRecPriors[kNotRecording] = 0;
01301 rtRecPriors[kSingleRecord] =
01302 gCoreContext->GetNumSetting("SingleRecordRecPriority", 1);
01303 rtRecPriors[kTimeslotRecord] =
01304 gCoreContext->GetNumSetting("TimeslotRecordRecPriority", 0);
01305 rtRecPriors[kChannelRecord] =
01306 gCoreContext->GetNumSetting("ChannelRecordRecPriority", 0);
01307 rtRecPriors[kAllRecord] =
01308 gCoreContext->GetNumSetting("AllRecordRecPriority", 0);
01309 rtRecPriors[kWeekslotRecord] =
01310 gCoreContext->GetNumSetting("WeekslotRecordRecPriority", 0);
01311 rtRecPriors[kFindOneRecord] =
01312 gCoreContext->GetNumSetting("FindOneRecordRecPriority", -1);
01313 rtRecPriors[kOverrideRecord] =
01314 gCoreContext->GetNumSetting("OverrideRecordRecPriority", 0);
01315 rtRecPriors[kDontRecord] =
01316 gCoreContext->GetNumSetting("OverrideRecordRecPriority", 0);
01317 rtRecPriors[kFindDailyRecord] =
01318 gCoreContext->GetNumSetting("FindOneRecordRecPriority", -1);
01319 rtRecPriors[kFindWeeklyRecord] =
01320 gCoreContext->GetNumSetting("FindOneRecordRecPriority", -1);
01321 rtRecPriors[kTemplateRecord] = 0;
01322
01323
01324
01325
01326
01327 MSqlQuery result(MSqlQuery::InitCon());
01328 result.prepare("SELECT recordid, title, chanid, starttime, startdate, "
01329 "type, inactive, last_record, avg_delay, profile "
01330 "FROM record;");
01331
01332 if (!result.exec())
01333 {
01334 MythDB::DBError("Get program recording priorities query", result);
01335 }
01336 else if (result.next())
01337 {
01338 countMatches();
01339 do {
01340 uint recordid = result.value(0).toUInt();
01341 QString title = result.value(1).toString();
01342 QString chanid = result.value(2).toString();
01343 QString tempTime = result.value(3).toString();
01344 QString tempDate = result.value(4).toString();
01345 RecordingType recType = (RecordingType)result.value(5).toInt();
01346 int recTypeRecPriority = rtRecPriors[recType];
01347 int inactive = result.value(6).toInt();
01348 QDateTime lastrec = result.value(7).toDateTime();
01349 int avgd = result.value(8).toInt();
01350 QString profile = result.value(9).toString();
01351
01352
01353
01354 QMap<int, ProgramRecPriorityInfo>::Iterator it;
01355 it = m_programData.find(recordid);
01356 if (it != m_programData.end())
01357 {
01358 ProgramRecPriorityInfo *progInfo = &(*it);
01359
01360 progInfo->sortTitle = progInfo->title;
01361 progInfo->sortTitle.remove(QRegExp(tr("^(The |A |An )")));
01362
01363 progInfo->recTypeRecPriority = recTypeRecPriority;
01364 progInfo->recType = recType;
01365 progInfo->matchCount =
01366 m_listMatch[progInfo->GetRecordingRuleID()];
01367 progInfo->recCount =
01368 m_recMatch[progInfo->GetRecordingRuleID()];
01369 progInfo->last_record = lastrec;
01370 progInfo->avg_delay = avgd;
01371 progInfo->profile = profile;
01372
01373 if (autopriority)
01374 progInfo->autoRecPriority =
01375 autopriority - (progInfo->avg_delay *
01376 (autopriority * 2 + 1) / 200);
01377 else
01378 progInfo->autoRecPriority = 0;
01379
01380 if (inactive)
01381 progInfo->recstatus = rsInactive;
01382 else if (m_conMatch[progInfo->GetRecordingRuleID()] > 0)
01383 progInfo->recstatus = rsConflict;
01384 else if (m_nowMatch[progInfo->GetRecordingRuleID()] > 0)
01385 progInfo->recstatus = rsRecording;
01386 else if (m_recMatch[progInfo->GetRecordingRuleID()] > 0)
01387 progInfo->recstatus = rsWillRecord;
01388 else
01389 progInfo->recstatus = rsUnknown;
01390 }
01391 } while (result.next());
01392 }
01393 }
01394
01395 void ProgramRecPriority::countMatches()
01396 {
01397 m_listMatch.clear();
01398 m_conMatch.clear();
01399 m_nowMatch.clear();
01400 m_recMatch.clear();
01401 ProgramList schedList;
01402 LoadFromScheduler(schedList);
01403 QDateTime now = QDateTime::currentDateTime();
01404
01405 ProgramList::const_iterator it = schedList.begin();
01406 for (; it != schedList.end(); ++it)
01407 {
01408 const RecStatusType recstatus = (**it).GetRecordingStatus();
01409 const uint recordid = (**it).GetRecordingRuleID();
01410 if ((**it).GetRecordingEndTime() > now && recstatus != rsNotListed)
01411 {
01412 m_listMatch[recordid]++;
01413 if (recstatus == rsConflict || recstatus == rsOffLine)
01414 m_conMatch[recordid]++;
01415 else if (recstatus == rsWillRecord)
01416 m_recMatch[recordid]++;
01417 else if (recstatus == rsRecording)
01418 {
01419 m_nowMatch[recordid]++;
01420 m_recMatch[recordid]++;
01421 }
01422 }
01423 }
01424 }
01425
01426 void ProgramRecPriority::SortList(ProgramRecPriorityInfo *newCurrentItem)
01427 {
01428 if (newCurrentItem)
01429 m_currentItem = newCurrentItem;
01430 else
01431 {
01432 MythUIButtonListItem *item = m_programList->GetItemCurrent();
01433 if (item)
01434 m_currentItem =
01435 qVariantValue<ProgramRecPriorityInfo*>(item->GetData());
01436 }
01437
01438 QMap<int, ProgramRecPriorityInfo>::Iterator pit;
01439 vector<ProgramRecPriorityInfo *>::iterator sit;
01440
01441
01442 m_sortedProgram.clear();
01443 for (pit = m_programData.begin(); pit != m_programData.end(); ++pit)
01444 {
01445 ProgramRecPriorityInfo *progInfo = &(*pit);
01446 m_sortedProgram.push_back(progInfo);
01447 }
01448
01449
01450 switch (m_sortType)
01451 {
01452 case byTitle :
01453 sort(m_sortedProgram.begin(), m_sortedProgram.end(),
01454 TitleSort(m_reverseSort));
01455 break;
01456 case byRecPriority :
01457 sort(m_sortedProgram.begin(), m_sortedProgram.end(),
01458 ProgramRecPrioritySort(m_reverseSort));
01459 break;
01460 case byRecType :
01461 sort(m_sortedProgram.begin(), m_sortedProgram.end(),
01462 ProgramRecTypeSort(m_reverseSort));
01463 break;
01464 case byCount :
01465 sort(m_sortedProgram.begin(), m_sortedProgram.end(),
01466 ProgramCountSort(m_reverseSort));
01467 break;
01468 case byRecCount :
01469 sort(m_sortedProgram.begin(), m_sortedProgram.end(),
01470 ProgramRecCountSort(m_reverseSort));
01471 break;
01472 case byLastRecord :
01473 sort(m_sortedProgram.begin(), m_sortedProgram.end(),
01474 ProgramLastRecordSort(m_reverseSort));
01475 break;
01476 case byAvgDelay :
01477 sort(m_sortedProgram.begin(), m_sortedProgram.end(),
01478 ProgramAvgDelaySort(m_reverseSort));
01479 break;
01480 }
01481
01482 UpdateList();
01483 }
01484
01485 void ProgramRecPriority::UpdateList()
01486 {
01487 if (!m_currentItem && !m_programList->IsEmpty())
01488 m_currentItem = qVariantValue<ProgramRecPriorityInfo*>
01489 (m_programList->GetItemCurrent()->GetData());
01490
01491 m_programList->Reset();
01492
01493 vector<ProgramRecPriorityInfo*>::iterator it;
01494 MythUIButtonListItem *item;
01495 for (it = m_sortedProgram.begin(); it != m_sortedProgram.end(); ++it)
01496 {
01497 ProgramRecPriorityInfo *progInfo = *it;
01498
01499 item = new MythUIButtonListItem(m_programList, "",
01500 qVariantFromValue(progInfo));
01501
01502 int progRecPriority = progInfo->GetRecordingPriority();
01503 int autorecpri = progInfo->autoRecPriority;
01504 int finalRecPriority = progRecPriority +
01505 autorecpri +
01506 progInfo->recTypeRecPriority;
01507
01508 if ((progInfo->rectype == kSingleRecord ||
01509 progInfo->rectype == kOverrideRecord ||
01510 progInfo->rectype == kDontRecord) &&
01511 !(progInfo->GetSubtitle()).trimmed().isEmpty())
01512 {
01513 QString rating = QString::number(progInfo->GetStars(10));
01514
01515 item->DisplayState(rating, "ratingstate");
01516 }
01517 else
01518 progInfo->subtitle.clear();
01519
01520 QString state;
01521 if (progInfo->recType == kDontRecord ||
01522 (progInfo->recType != kTemplateRecord &&
01523 progInfo->recstatus == rsInactive))
01524 state = "disabled";
01525 else if (m_conMatch[progInfo->GetRecordingRuleID()] > 0)
01526 state = "error";
01527 else if (m_recMatch[progInfo->GetRecordingRuleID()] > 0 ||
01528 progInfo->recType == kTemplateRecord)
01529 state = "normal";
01530 else if (m_nowMatch[progInfo->GetRecordingRuleID()] > 0)
01531 state = "running";
01532 else
01533 state = "warning";
01534
01535 InfoMap infoMap;
01536 progInfo->ToMap(infoMap);
01537 item->SetTextFromMap(infoMap, state);
01538
01539 QString subtitle;
01540 if (progInfo->subtitle != "(null)" &&
01541 (progInfo->rectype == kSingleRecord ||
01542 progInfo->rectype == kOverrideRecord ||
01543 progInfo->rectype == kDontRecord))
01544 {
01545 subtitle = progInfo->subtitle;
01546 }
01547
01548 QString matchInfo;
01549 if (progInfo->GetRecordingStatus() == rsInactive)
01550 {
01551 matchInfo = QString("%1 %2")
01552 .arg(m_listMatch[progInfo->GetRecordingRuleID()])
01553 .arg(toString(progInfo->GetRecordingStatus(),
01554 progInfo->GetRecordingRuleType()));
01555 }
01556 else
01557 matchInfo = QString(tr("Recording %1 of %2"))
01558 .arg(m_recMatch[progInfo->GetRecordingRuleID()])
01559 .arg(m_listMatch[progInfo->GetRecordingRuleID()]);
01560
01561 subtitle = QString("(%1) %2").arg(matchInfo).arg(subtitle);
01562 item->SetText(subtitle, "scheduleinfo", state);
01563
01564 item->SetText(QString::number(progRecPriority), "progpriority", state);
01565 item->SetText(QString::number(finalRecPriority),
01566 "finalpriority", state);
01567
01568 QString msg = QString::number(progRecPriority);
01569 if(autorecpri != 0)
01570 msg += tr(" + %1 automatic priority (%2hr)")
01571 .arg(autorecpri).arg(progInfo->avg_delay);
01572 item->SetText(msg, "recpriority", state);
01573 item->SetText(QString::number(progRecPriority + autorecpri),
01574 "recpriorityB", state);
01575 item->SetText(QString::number(progInfo->recTypeRecPriority),
01576 "rectypepriority", state);
01577
01578 QString tempDateTime = MythDateTimeToString(progInfo->last_record,
01579 kDateTimeFull | kSimplify |
01580 kAddYear);
01581 item->SetText(tempDateTime, "lastrecorded", state);
01582 QString tempDate = MythDateTimeToString(progInfo->last_record,
01583 kDateFull | kSimplify |
01584 kAddYear);
01585 item->SetText(tempDate, "lastrecordeddate", state);
01586 QString tempTime = MythDateTimeToString(progInfo->last_record, kTime);
01587 item->SetText(tempTime, "lastrecordedtime", state);
01588
01589 QString channame = progInfo->channame;
01590 if ((progInfo->recType == kAllRecord) ||
01591 (progInfo->recType == kFindOneRecord) ||
01592 (progInfo->recType == kFindDailyRecord) ||
01593 (progInfo->recType == kFindWeeklyRecord))
01594 channame = tr("Any");
01595 item->SetText(channame, "channel", state);
01596 QString channum = progInfo->chanstr;
01597 if ((progInfo->recType == kAllRecord) ||
01598 (progInfo->recType == kFindOneRecord) ||
01599 (progInfo->recType == kFindDailyRecord) ||
01600 (progInfo->recType == kFindWeeklyRecord))
01601 channum = tr("Any");
01602 item->SetText(channum, "channum", state);
01603 QString callsign = progInfo->chansign;
01604 if ((progInfo->recType == kAllRecord) ||
01605 (progInfo->recType == kFindOneRecord) ||
01606 (progInfo->recType == kFindDailyRecord) ||
01607 (progInfo->recType == kFindWeeklyRecord))
01608 callsign = tr("Any");
01609 item->SetText(callsign, "callsign", state);
01610
01611 QString profile = progInfo->profile;
01612 if ((profile == "Default") || (profile == "Live TV") ||
01613 (profile == "High Quality") || (profile == "Low Quality"))
01614 profile = tr(profile.toUtf8().constData());
01615 item->SetText(profile, "recordingprofile", state);
01616 item->DisplayState(state, "status");
01617
01618 if (m_currentItem == progInfo)
01619 m_programList->SetItemCurrent(item);
01620 }
01621
01622 m_currentItem = NULL;
01623
01624 MythUIText *norecordingText = dynamic_cast<MythUIText*>
01625 (GetChild("norecordings_info"));
01626
01627 if (norecordingText)
01628 norecordingText->SetVisible(m_programData.isEmpty());
01629 }
01630
01631 void ProgramRecPriority::updateInfo(MythUIButtonListItem *item)
01632 {
01633 if (!item)
01634 return;
01635
01636 ProgramRecPriorityInfo *pgRecInfo = qVariantValue<ProgramRecPriorityInfo *>
01637 (item->GetData());
01638
01639 if (!pgRecInfo)
01640 return;
01641
01642 int progRecPriority, autorecpri, rectyperecpriority, finalRecPriority;
01643
01644 progRecPriority = pgRecInfo->GetRecordingPriority();
01645 autorecpri = pgRecInfo->autoRecPriority;
01646 rectyperecpriority = pgRecInfo->recTypeRecPriority;
01647 finalRecPriority = progRecPriority + autorecpri + rectyperecpriority;
01648
01649 QString subtitle;
01650 if (pgRecInfo->subtitle != "(null)" &&
01651 (pgRecInfo->rectype == kSingleRecord ||
01652 pgRecInfo->rectype == kOverrideRecord ||
01653 pgRecInfo->rectype == kDontRecord))
01654 {
01655 subtitle = pgRecInfo->subtitle;
01656 }
01657
01658 QString matchInfo;
01659 if (pgRecInfo->GetRecordingStatus() == rsInactive)
01660 {
01661 matchInfo = QString("%1 %2")
01662 .arg(m_listMatch[pgRecInfo->GetRecordingRuleID()])
01663 .arg(toString(pgRecInfo->GetRecordingStatus(),
01664 pgRecInfo->GetRecordingRuleType()));
01665 }
01666 else
01667 matchInfo = QString(tr("Recording %1 of %2"))
01668 .arg(m_recMatch[pgRecInfo->GetRecordingRuleID()])
01669 .arg(m_listMatch[pgRecInfo->GetRecordingRuleID()]);
01670
01671 subtitle = QString("(%1) %2").arg(matchInfo).arg(subtitle);
01672
01673 InfoMap infoMap;
01674 pgRecInfo->ToMap(infoMap);
01675 SetTextFromMap(infoMap);
01676
01677 if (m_schedInfoText)
01678 m_schedInfoText->SetText(subtitle);
01679
01680 if (m_rectypePriorityText)
01681 m_rectypePriorityText->SetText(QString::number(rectyperecpriority));
01682
01683 if (m_recPriorityText)
01684 {
01685 QString msg = QString::number(pgRecInfo->GetRecordingPriority());
01686
01687 if(autorecpri != 0)
01688 msg += tr(" + %1 automatic priority (%2hr)")
01689 .arg(autorecpri).arg(pgRecInfo->avg_delay);
01690 m_recPriorityText->SetText(msg);
01691 }
01692
01693 if (m_recPriorityBText)
01694 m_recPriorityBText->SetText(QString::number(progRecPriority +
01695 autorecpri));
01696
01697 if (m_finalPriorityText)
01698 m_finalPriorityText->SetText(QString::number(finalRecPriority));
01699
01700 if (m_lastRecordedText)
01701 {
01702 QString tempDateTime = MythDateTimeToString(pgRecInfo->last_record,
01703 kDateTimeFull | kSimplify |
01704 kAddYear);
01705 m_lastRecordedText->SetText(tempDateTime);
01706 }
01707
01708 if (m_lastRecordedDateText)
01709 {
01710 QString tempDate = MythDateTimeToString(pgRecInfo->last_record,
01711 kDateFull | kSimplify |
01712 kAddYear);
01713 m_lastRecordedDateText->SetText(tempDate);
01714 }
01715
01716 if (m_lastRecordedTimeText)
01717 {
01718 QString tempTime = MythDateTimeToString(pgRecInfo->last_record, kTime);
01719 m_lastRecordedTimeText->SetText(tempTime);
01720 }
01721
01722 if (m_channameText)
01723 {
01724 QString channame = pgRecInfo->channame;
01725 if ((pgRecInfo->rectype == kAllRecord) ||
01726 (pgRecInfo->rectype == kFindOneRecord) ||
01727 (pgRecInfo->rectype == kFindDailyRecord) ||
01728 (pgRecInfo->rectype == kFindWeeklyRecord))
01729 channame = tr("Any");
01730 m_channameText->SetText(channame);
01731 }
01732
01733 if (m_channumText)
01734 {
01735 QString channum = pgRecInfo->chanstr;
01736 if ((pgRecInfo->rectype == kAllRecord) ||
01737 (pgRecInfo->rectype == kFindOneRecord) ||
01738 (pgRecInfo->rectype == kFindDailyRecord) ||
01739 (pgRecInfo->rectype == kFindWeeklyRecord))
01740 channum = tr("Any");
01741 m_channumText->SetText(channum);
01742 }
01743
01744 if (m_callsignText)
01745 {
01746 QString callsign = pgRecInfo->chansign;
01747 if ((pgRecInfo->rectype == kAllRecord) ||
01748 (pgRecInfo->rectype == kFindOneRecord) ||
01749 (pgRecInfo->rectype == kFindDailyRecord) ||
01750 (pgRecInfo->rectype == kFindWeeklyRecord))
01751 callsign = tr("Any");
01752 m_callsignText->SetText(callsign);
01753 }
01754
01755 if (m_recProfileText)
01756 {
01757 QString profile = pgRecInfo->profile;
01758 if ((profile == "Default") || (profile == "Live TV") ||
01759 (profile == "High Quality") || (profile == "Low Quality"))
01760 profile = tr(profile.toUtf8().constData());
01761 m_recProfileText->SetText(profile);
01762 }
01763
01764 }
01765
01766 void ProgramRecPriority::RemoveItemFromList(MythUIButtonListItem *item)
01767 {
01768 if (!item)
01769 return;
01770
01771 ProgramRecPriorityInfo *pgRecInfo = qVariantValue<ProgramRecPriorityInfo *>
01772 (item->GetData());
01773
01774 if (!pgRecInfo)
01775 return;
01776
01777 QMap<int, ProgramRecPriorityInfo>::iterator it;
01778 it = m_programData.find(pgRecInfo->GetRecordingRuleID());
01779 if (it != m_programData.end())
01780 m_programData.erase(it);
01781
01782 m_programList->RemoveItem(item);
01783 }
01784
01785