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