MythTV  0.25-pre
schedulecommon.cpp
Go to the documentation of this file.
00001 
00002 #include "schedulecommon.h"
00003 
00004 // QT
00005 #include <QCoreApplication>
00006 
00007 // libmyth
00008 #include "mythcorecontext.h"
00009 #include "programinfo.h"
00010 #include "remoteutil.h"
00011 
00012 // libmythtv 
00013 #include "recordinginfo.h"
00014 #include "tvremoteutil.h"
00015 
00016 // libmythui
00017 #include "mythscreentype.h"
00018 #include "mythdialogbox.h"
00019 #include "mythmainwindow.h"
00020 
00021 // mythfrontend
00022 #include "scheduleeditor.h"
00023 #include "progdetails.h"
00024 #include "proglist.h"
00025 #include "customedit.h"
00026 
00030 void ScheduleCommon::ShowDetails(ProgramInfo *pginfo) const
00031 {
00032     if (!pginfo)
00033         return;
00034     
00035     MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00036     ProgDetails *details_dialog  = new ProgDetails(mainStack, pginfo);
00037     
00038     if (!details_dialog->Create())
00039     {
00040         delete details_dialog;
00041         return;
00042     }
00043     
00044     mainStack->AddScreen(details_dialog);
00045 }
00046 
00050 void ScheduleCommon::ShowUpcoming(const QString &title, 
00051                                   const QString &seriesid) const
00052 {
00053     if (title.isEmpty())
00054         return;
00055 
00056     MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00057     ProgLister *pl = new ProgLister(mainStack, plTitle, title, seriesid);
00058     if (pl->Create())
00059     {
00060         mainStack->AddScreen(pl);
00061     }
00062     else
00063         delete pl;
00064 }
00065 
00069 void ScheduleCommon::ShowUpcoming(ProgramInfo *pginfo) const
00070 {
00071     if (!pginfo)
00072         return;
00073 
00074     ShowUpcoming(pginfo->GetTitle(), pginfo->GetSeriesID());
00075 }
00076 
00080 void ScheduleCommon::ShowUpcomingScheduled(ProgramInfo *pginfo) const
00081 {
00082     if (!pginfo)
00083         return;
00084 
00085     RecordingInfo ri(*pginfo);
00086     uint id;
00087 
00088     if ((id = ri.GetRecordingRuleID()) <= 0)
00089         return ShowUpcoming(pginfo->GetTitle(), pginfo->GetSeriesID());
00090 
00091     MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00092     ProgLister *pl = new ProgLister(mainStack, plRecordid,
00093                                     QString::number(id), "");
00094 
00095     if (pl->Create())
00096         mainStack->AddScreen(pl);
00097     else
00098         delete pl;
00099 }
00100 
00105 void ScheduleCommon::EditRecording(ProgramInfo *pginfo)
00106 {
00107     if (!pginfo)
00108         return;
00109     
00110     RecordingInfo ri(*pginfo);
00111 
00112     if (!ri.GetRecordingRuleID())
00113         EditScheduled(&ri);
00114     else if (ri.GetRecordingStatus() <= rsWillRecord)
00115         ShowRecordingDialog(ri);
00116     else
00117         ShowNotRecordingDialog(ri);
00118 }
00119 
00123 void ScheduleCommon::EditScheduled(ProgramInfo *pginfo)
00124 {
00125     if (!pginfo)
00126         return;
00127     
00128     RecordingInfo ri(*pginfo);
00129     EditScheduled(&ri);
00130 }
00131 
00135 void ScheduleCommon::EditScheduled(RecordingInfo *recinfo)
00136 {
00137     MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00138     ScheduleEditor *schededit = new ScheduleEditor(mainStack, recinfo);
00139     if (schededit->Create())
00140         mainStack->AddScreen(schededit);
00141     else
00142         delete schededit;
00143 }
00144 
00148 void ScheduleCommon::EditCustom(ProgramInfo *pginfo)
00149 {
00150     if (!pginfo)
00151         return;
00152 
00153     MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00154     CustomEdit *ce = new CustomEdit(mainStack, pginfo);
00155     if (ce->Create())
00156         mainStack->AddScreen(ce);
00157     else
00158         delete ce;
00159 }
00160 
00164 void ScheduleCommon::MakeOverride(RecordingInfo *recinfo, bool startActive)
00165 {
00166     if (!recinfo || !recinfo->GetRecordingRuleID())
00167         return;
00168 
00169     RecordingRule *recrule = new RecordingRule();
00170     
00171     if (!recrule->LoadByProgram(static_cast<ProgramInfo*>(recinfo)))
00172         LOG(VB_GENERAL, LOG_ERR, "Failed to load by program info");
00173     
00174     if (!recrule->MakeOverride())
00175     {
00176         LOG(VB_GENERAL, LOG_ERR, "Failed to make Override");
00177         delete recrule;
00178         return;
00179     }
00180     if (startActive)
00181         recrule->m_type = kOverrideRecord;
00182 
00183     MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00184     ScheduleEditor *schededit = new ScheduleEditor(mainStack, recrule);
00185     if (schededit->Create())
00186         mainStack->AddScreen(schededit);
00187     else
00188         delete schededit;
00189 }
00190 
00195 void ScheduleCommon::ShowRecordingDialog(const RecordingInfo& recinfo)
00196 {
00197     QString message = recinfo.toString(ProgramInfo::kTitleSubtitle, " - ");
00198     
00199     message += "\n\n";
00200     message += toDescription(
00201         recinfo.GetRecordingStatus(), recinfo.GetRecordingStartTime());
00202     
00203     MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
00204     MythDialogBox *menuPopup = new MythDialogBox(message, popupStack,
00205                                                  "recOptionPopup", true);
00206     
00207     if (menuPopup->Create())
00208     {
00209         menuPopup->SetReturnEvent(this, "schedulerecording");
00210 
00211         QDateTime now = QDateTime::currentDateTime();
00212         
00213         if (recinfo.GetRecordingStartTime() < now &&
00214             recinfo.GetRecordingEndTime() > now)
00215         {
00216             if (recinfo.GetRecordingStatus() != rsRecording)
00217                 menuPopup->AddButton(tr("Reactivate"),
00218                                      qVariantFromValue(recinfo));
00219             else
00220                 menuPopup->AddButton(tr("Stop recording"),
00221                                      qVariantFromValue(recinfo));
00222         }
00223 
00224         if (recinfo.GetRecordingEndTime() > now)
00225         {
00226             if (recinfo.GetRecordingRuleType() != kSingleRecord &&
00227                 recinfo.GetRecordingRuleType() != kOverrideRecord)
00228             {
00229                 if (recinfo.GetRecordingStartTime() > now)
00230                 {
00231                     menuPopup->AddButton(tr("Don't record"),
00232                                          qVariantFromValue(recinfo));
00233                 }
00234 
00235                 const RecordingDupMethodType dupmethod =
00236                     recinfo.GetDuplicateCheckMethod();
00237 
00238                 if (recinfo.GetRecordingStatus() != rsRecording &&
00239                     recinfo.GetRecordingRuleType() != kFindOneRecord &&
00240                     !((recinfo.GetFindID() == 0 ||
00241                        !IsFindApplicable(recinfo)) &&
00242                       recinfo.GetCategoryType() == "series" &&
00243                       recinfo.GetProgramID().contains(QRegExp("0000$"))) &&
00244                     ((!(dupmethod & kDupCheckNone) &&
00245                       !recinfo.GetProgramID().isEmpty() &&
00246                       (recinfo.GetFindID() != 0 ||
00247                        !IsFindApplicable(recinfo))) ||
00248                      ((dupmethod & kDupCheckSub) &&
00249                       !recinfo.GetSubtitle().isEmpty()) ||
00250                      ((dupmethod & kDupCheckDesc) &&
00251                       !recinfo.GetDescription().isEmpty()) ||
00252                      ((dupmethod & kDupCheckSubThenDesc) &&
00253                       (!recinfo.GetSubtitle().isEmpty() ||
00254                        !recinfo.GetDescription().isEmpty())) ))
00255                     {
00256                         menuPopup->AddButton(tr("Never record"),
00257                                              qVariantFromValue(recinfo));
00258                     }
00259             }
00260             
00261             if (recinfo.GetRecordingRuleType() != kOverrideRecord &&
00262                 recinfo.GetRecordingRuleType() != kDontRecord)
00263             {
00264                 if (recinfo.GetRecordingStatus() == rsRecording)
00265                 {
00266                     menuPopup->AddButton(tr("Modify Recording Options"),
00267                                          qVariantFromValue(recinfo));
00268                 }
00269                 else
00270                 {
00271                     menuPopup->AddButton(tr("Edit Options"),
00272                                          qVariantFromValue(recinfo));
00273                     
00274                     if (recinfo.GetRecordingRuleType() != kSingleRecord &&
00275                         recinfo.GetRecordingRuleType() != kFindOneRecord)
00276                     {
00277                         menuPopup->AddButton(tr("Add Override"),
00278                                              qVariantFromValue(recinfo));
00279                     }
00280                 }
00281             }
00282             
00283             if (recinfo.GetRecordingRuleType() == kOverrideRecord ||
00284                 recinfo.GetRecordingRuleType() == kDontRecord)
00285             {
00286                 if (recinfo.GetRecordingStatus() == rsRecording)
00287                 {
00288                     menuPopup->AddButton(tr("Modify Recording Options"),
00289                                          qVariantFromValue(recinfo));
00290                 }
00291                 else
00292                 {
00293                     menuPopup->AddButton(tr("Edit Override"),
00294                                          qVariantFromValue(recinfo));
00295                     menuPopup->AddButton(tr("Clear Override"),
00296                                          qVariantFromValue(recinfo));
00297                 }
00298             }
00299         }        
00300         
00301         popupStack->AddScreen(menuPopup);
00302     }
00303     else
00304         delete menuPopup;
00305 }
00306 
00311 void ScheduleCommon::ShowNotRecordingDialog(const RecordingInfo& recinfo)
00312 {
00313     QString timeFormat = gCoreContext->GetSetting("TimeFormat", "h:mm AP");
00314 
00315     QString message = recinfo.toString(ProgramInfo::kTitleSubtitle, " - ");
00316 
00317     message += "\n\n";
00318     message += toDescription(
00319         recinfo.GetRecordingStatus(), recinfo.GetRecordingStartTime());
00320 
00321     if (recinfo.GetRecordingStatus() == rsConflict ||
00322         recinfo.GetRecordingStatus() == rsLaterShowing)
00323     {
00324         vector<ProgramInfo *> *confList = RemoteGetConflictList(&recinfo);
00325 
00326         if (!confList->empty())
00327         {
00328             message += " ";
00329             message += tr("The following programs will be recorded instead:");
00330             message += "\n";
00331         }
00332 
00333         uint maxi = 0;
00334         for (; confList->begin() != confList->end() && maxi < 4; maxi++)
00335         {
00336             ProgramInfo *p = *confList->begin();
00337             message += QString("%1 - %2  %3\n")
00338                 .arg(p->GetRecordingStartTime().toString(timeFormat))
00339                 .arg(p->GetRecordingEndTime().toString(timeFormat))
00340                 .arg(p->toString(ProgramInfo::kTitleSubtitle, " - "));
00341             delete p;
00342             confList->erase(confList->begin());
00343         }
00344         message += "\n";
00345         while (!confList->empty())
00346         {
00347             delete confList->back();
00348             confList->pop_back();
00349         }
00350         delete confList;
00351     }
00352 
00353     MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
00354     MythDialogBox *menuPopup = new MythDialogBox(message, popupStack,
00355                                                  "notRecOptionPopup", true);
00356 
00357     if (menuPopup->Create())
00358     {
00359         menuPopup->SetReturnEvent(this, "schedulenotrecording");
00360 
00361         QDateTime now = QDateTime::currentDateTime();
00362 
00363         if ((recinfo.GetRecordingStartTime() < now) &&
00364             (recinfo.GetRecordingEndTime() > now) &&
00365             (recinfo.GetRecordingStatus() != rsDontRecord) &&
00366             (recinfo.GetRecordingStatus() != rsNotListed))
00367         {
00368             menuPopup->AddButton(tr("Reactivate"),
00369                                  qVariantFromValue(recinfo));
00370         }
00371 
00372         if (recinfo.GetRecordingEndTime() > now)
00373         {
00374             if ((recinfo.GetRecordingRuleType() != kSingleRecord &&
00375                 recinfo.GetRecordingRuleType() != kOverrideRecord) &&
00376                 (recinfo.GetRecordingStatus() == rsDontRecord ||
00377                 recinfo.GetRecordingStatus() == rsPreviousRecording ||
00378                 recinfo.GetRecordingStatus() == rsCurrentRecording ||
00379                 recinfo.GetRecordingStatus() == rsEarlierShowing ||
00380                 recinfo.GetRecordingStatus() == rsOtherShowing ||
00381                 recinfo.GetRecordingStatus() == rsNeverRecord ||
00382                 recinfo.GetRecordingStatus() == rsRepeat ||
00383                 recinfo.GetRecordingStatus() == rsInactive ||
00384                 recinfo.GetRecordingStatus() == rsLaterShowing))
00385             {
00386                 menuPopup->AddButton(tr("Record anyway"),
00387                                     qVariantFromValue(recinfo));
00388                 if (recinfo.GetRecordingStatus() == rsPreviousRecording ||
00389                     recinfo.GetRecordingStatus() == rsNeverRecord)
00390                 {
00391                     menuPopup->AddButton(tr("Forget Previous"),
00392                                         qVariantFromValue(recinfo));
00393                 }
00394             }
00395 
00396             if (recinfo.GetRecordingRuleType() != kOverrideRecord &&
00397                 recinfo.GetRecordingRuleType() != kDontRecord)
00398             {
00399                 if (recinfo.GetRecordingRuleType() != kSingleRecord &&
00400                     recinfo.GetRecordingStatus() != rsPreviousRecording &&
00401                     recinfo.GetRecordingStatus() != rsCurrentRecording &&
00402                     recinfo.GetRecordingStatus() != rsNeverRecord &&
00403                     recinfo.GetRecordingStatus() != rsNotListed)
00404                 {
00405                     if (recinfo.GetRecordingStartTime() > now)
00406                     {
00407                         menuPopup->AddButton(tr("Don't record"),
00408                                             qVariantFromValue(recinfo));
00409                     }
00410 
00411                     const RecordingDupMethodType dupmethod =
00412                         recinfo.GetDuplicateCheckMethod();
00413 
00414                     if (recinfo.GetRecordingRuleType() != kFindOneRecord &&
00415                         !((recinfo.GetFindID() == 0 ||
00416                            !IsFindApplicable(recinfo)) &&
00417                           recinfo.GetCategoryType() == "series" &&
00418                           recinfo.GetProgramID().contains(QRegExp("0000$"))) &&
00419                         ((!(dupmethod & kDupCheckNone) &&
00420                           !recinfo.GetProgramID().isEmpty() &&
00421                           (recinfo.GetFindID() != 0 ||
00422                            !IsFindApplicable(recinfo))) ||
00423                          ((dupmethod & kDupCheckSub) &&
00424                           !recinfo.GetSubtitle().isEmpty()) ||
00425                          ((dupmethod & kDupCheckDesc) &&
00426                           !recinfo.GetDescription().isEmpty()) ||
00427                          ((dupmethod & kDupCheckSubThenDesc) &&
00428                           (!recinfo.GetSubtitle().isEmpty() ||
00429                            !recinfo.GetDescription().isEmpty())) ))
00430                         {
00431                             menuPopup->AddButton(tr("Never record"),
00432                                                  qVariantFromValue(recinfo));
00433                         }
00434                 }
00435 
00436                 menuPopup->AddButton(tr("Edit Options"),
00437                                      qVariantFromValue(recinfo));
00438 
00439                 if (recinfo.GetRecordingRuleType() != kSingleRecord &&
00440                     recinfo.GetRecordingRuleType() != kFindOneRecord &&
00441                     recinfo.GetRecordingStatus() != rsNotListed)
00442                 {
00443                     menuPopup->AddButton(tr("Add Override"),
00444                                         qVariantFromValue(recinfo));
00445                 }
00446             }
00447 
00448             if (recinfo.GetRecordingRuleType() == kOverrideRecord ||
00449                 recinfo.GetRecordingRuleType() == kDontRecord)
00450             {
00451                 menuPopup->AddButton(tr("Edit Override"),
00452                                     qVariantFromValue(recinfo));
00453                 menuPopup->AddButton(tr("Clear Override"),
00454                                     qVariantFromValue(recinfo));
00455             }
00456         }
00457         
00458         popupStack->AddScreen(menuPopup);
00459     }
00460     else
00461         delete menuPopup;
00462 }
00463 
00464 void ScheduleCommon::customEvent(QEvent *event)
00465 {
00466     if (event->type() == DialogCompletionEvent::kEventType)
00467     {
00468         DialogCompletionEvent *dce = (DialogCompletionEvent*)(event);
00469 
00470         QString resultid   = dce->GetId();
00471         QString resulttext = dce->GetResultText();
00472 
00473         if (resultid == "schedulenotrecording")
00474         {
00475             if (!qVariantCanConvert<RecordingInfo>(dce->GetData()))
00476                 return;
00477 
00478             RecordingInfo recInfo = qVariantValue<RecordingInfo>
00479                 (dce->GetData());
00480 
00481             if (resulttext == tr("Reactivate"))
00482                 recInfo.ReactivateRecording();
00483             else if (resulttext == tr("Record anyway"))
00484             {
00485                 recInfo.ApplyRecordStateChange(kOverrideRecord);
00486                 if (recInfo.GetRecordingStartTime() < QDateTime::currentDateTime())
00487                     recInfo.ReactivateRecording();
00488             }
00489             else if (resulttext == tr("Forget Previous"))
00490                 recInfo.ForgetHistory();
00491             else if (resulttext == tr("Don't record"))
00492                 recInfo.ApplyRecordStateChange(kDontRecord);
00493             else if (resulttext == tr("Never record"))
00494             {
00495                 recInfo.SetRecordingStatus(rsNeverRecord);
00496                 recInfo.SetScheduledStartTime(QDateTime::currentDateTime());
00497                 recInfo.SetScheduledEndTime(recInfo.GetRecordingStartTime());
00498                 recInfo.AddHistory(true, true);
00499             }
00500             else if (resulttext == tr("Clear Override"))
00501                 recInfo.ApplyRecordStateChange(kNotRecording);
00502             else if (resulttext == tr("Edit Override") ||
00503                      resulttext == tr("Edit Options"))
00504             {
00505                 EditScheduled(&recInfo);
00506             }
00507             else if (resulttext == tr("Add Override"))
00508             {
00509                 MakeOverride(&recInfo);
00510             }
00511         }
00512         else if (resultid == "schedulerecording")
00513         {
00514             if (!qVariantCanConvert<RecordingInfo>(dce->GetData()))
00515                 return;
00516             
00517             RecordingInfo recInfo = qVariantValue<RecordingInfo>
00518                                                             (dce->GetData());
00519             
00520             if (resulttext == tr("Reactivate"))
00521                 recInfo.ReactivateRecording();
00522             else if (resulttext == tr("Stop recording"))
00523             {
00524                 ProgramInfo pginfo(
00525                     recInfo.GetChanID(), recInfo.GetRecordingStartTime());
00526                 if (pginfo.GetChanID())
00527                     RemoteStopRecording(&pginfo);
00528             }
00529             else if (resulttext == tr("Don't record"))
00530                 recInfo.ApplyRecordStateChange(kDontRecord);
00531             else if (resulttext == tr("Never record"))
00532             {
00533                 recInfo.SetRecordingStatus(rsNeverRecord);
00534                 recInfo.SetScheduledStartTime(QDateTime::currentDateTime());
00535                 recInfo.SetScheduledEndTime(recInfo.GetRecordingStartTime());
00536                 recInfo.AddHistory(true, true);
00537             }
00538             else if (resulttext == tr("Clear Override"))
00539                 recInfo.ApplyRecordStateChange(kNotRecording);
00540             else if (resulttext == tr("Modify Recording Options"))
00541             {
00542                 if (recInfo.GetRecordingRuleType() == kSingleRecord ||
00543                     recInfo.GetRecordingRuleType() == kOverrideRecord ||
00544                     recInfo.GetRecordingRuleType() == kFindOneRecord)
00545                     EditScheduled(&recInfo);
00546                 else
00547                     MakeOverride(&recInfo, true);
00548             }
00549             else if (resulttext == tr("Edit Override") ||
00550                      resulttext == tr("Edit Options"))
00551             {
00552                 EditScheduled(&recInfo);
00553             }
00554             else if (resulttext == tr("Add Override"))
00555             {
00556                 MakeOverride(&recInfo);
00557             }
00558         }
00559     }
00560 }
00561 
00566 bool ScheduleCommon::IsFindApplicable(const RecordingInfo& recInfo) const
00567 {
00568     return recInfo.GetRecordingRuleType() == kFindDailyRecord ||
00569            recInfo.GetRecordingRuleType() == kFindWeeklyRecord;
00570 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends