00001
00002
00003 #ifndef PLAYBACKBOX_H_
00004 #define PLAYBACKBOX_H_
00005
00006
00007 #include <vector>
00008 using namespace std;
00009
00010 #include <qdatetime.h>
00011 #include <qdom.h>
00012 #include <qmutex.h>
00013
00014 #include "mythwidgets.h"
00015 #include "mythdialogs.h"
00016 #include "uitypes.h"
00017 #include "xmlparse.h"
00018 #include "programinfo.h"
00019 #include "jobqueue.h"
00020 #include "tv_play.h"
00021
00022 #include <qvaluelist.h>
00023 #include <pthread.h>
00024
00025 class QListViewItem;
00026 class QLabel;
00027 class QProgressBar;
00028 class NuppelVideoPlayer;
00029 class RingBuffer;
00030 class QTimer;
00031 class ProgramInfo;
00032 class PreviewGenerator;
00033
00034 class LayerSet;
00035
00036 class PreviewGenState
00037 {
00038 public:
00039 PreviewGenState() :
00040 gen(NULL), genStarted(false), ready(false),
00041 attempts(0), lastBlockTime(0) {}
00042 PreviewGenerator *gen;
00043 bool genStarted;
00044 bool ready;
00045 uint attempts;
00046 uint lastBlockTime;
00047 QDateTime blockRetryUntil;
00048
00049 static const uint maxAttempts;
00050 static const uint minBlockSeconds;
00051 };
00052
00053 typedef QMap<QString,ProgramList> ProgramMap;
00054 typedef QMap<QString,QString> Str2StrMap;
00055 typedef QMap<QString,PreviewGenState> PreviewMap;
00056 typedef QMap<QString,MythTimer> LastCheckedMap;
00057
00058 class PlaybackBox : public MythDialog
00059 {
00060 Q_OBJECT
00061 public:
00062 typedef enum
00063 {
00064 Play,
00065 Delete,
00066 } BoxType;
00067
00068
00069 typedef enum {
00070 TitlesOnly = 0,
00071 TitlesCategories = 1,
00072 TitlesCategoriesRecGroups = 2,
00073 TitlesRecGroups = 3,
00074 Categories = 4,
00075 CategoriesRecGroups = 5,
00076 RecGroups = 6,
00077 ViewTypes,
00078 } ViewType;
00079
00080
00081 typedef enum {
00082 TitleSortAlphabetical = 0,
00083 TitleSortRecPriority = 1,
00084 TitleSortMethods,
00085 } ViewTitleSort;
00086
00087 typedef enum {
00088 VIEW_NONE = 0x00,
00089 VIEW_TITLES = 0x01,
00090 VIEW_CATEGORIES = 0x02,
00091 VIEW_RECGROUPS = 0x04,
00092 VIEW_WATCHLIST = 0x08,
00093 VIEW_SEARCHES = 0x10,
00094 VIEW_LIVETVGRP = 0x20,
00095 } ViewMask;
00096
00097 typedef enum
00098 {
00099 DeleteRecording,
00100 StopRecording,
00101 ForceDeleteRecording,
00102 } deletePopupType;
00103
00104 typedef enum
00105 {
00106 kStarting,
00107 kPlaying,
00108 kKilling,
00109 kKilled,
00110 kStopping,
00111 kStopped,
00112 kChanging,
00113 } playerStateType;
00114
00115 typedef enum
00116 {
00117 kNvpToPlay,
00118 kNvpToStop,
00119 kDone
00120 } killStateType;
00121
00122
00123 PlaybackBox(BoxType ltype, MythMainWindow *parent, const char *name = 0,
00124 TV *player = NULL, bool showTV = false);
00125 ~PlaybackBox(void);
00126
00127 void customEvent(QCustomEvent *e);
00128 static ProgramInfo *RunPlaybackBox(void *player, bool);
00129
00130 public slots:
00131 DialogCode exec();
00132
00133 protected slots:
00134 void timeout(void);
00135
00136 void cursorLeft();
00137 void cursorRight();
00138 void cursorDown(bool page = false, bool newview = false);
00139 void cursorUp(bool page = false, bool newview = false);
00140 void pageDown() { cursorDown(true); }
00141 void pageUp() { cursorUp(true); }
00142 void pageTop();
00143 void pageMiddle();
00144 void pageBottom();
00145 void customEdit();
00146 void upcoming();
00147 void details();
00148 void selected();
00149 void playSelected();
00150 void stopSelected();
00151 void deleteSelected();
00152 void showMenu();
00153 void showActionsSelected();
00154 void showRecGroupChanger();
00155 void showPlayGroupChanger();
00156 void showRecTitleChanger();
00157 void showRecGroupChooser();
00158 void showRecGroupPasswordChanger();
00159 void showPlayFromPopup();
00160 void showRecordingPopup();
00161 void showJobPopup();
00162 void showTranscodingProfiles();
00163 void changeProfileAndTranscode(QString profile);
00164 void changeProfileAndTranscodeAuto()
00165 { changeProfileAndTranscode("Autodetect"); }
00166 void changeProfileAndTranscodeHigh()
00167 { changeProfileAndTranscode("High Quality"); }
00168 void changeProfileAndTranscodeMedium()
00169 { changeProfileAndTranscode("Medium Quality"); }
00170 void changeProfileAndTranscodeLow()
00171 { changeProfileAndTranscode("Low Quality"); }
00172 void showStoragePopup();
00173 void showPlaylistPopup();
00174 void showPlaylistJobPopup();
00175 void showProgramDetails();
00176 void showIconHelp();
00177
00178 void doPlay();
00179 void doPlayFromBeg();
00180 void doPlayListRandom();
00181
00182 void askStop();
00183 void doStop();
00184 void noStop();
00185
00186 void doEditScheduled();
00187 void doAllowRerecord();
00188
00189 void askDelete();
00190 void doUndelete();
00191 void doDelete();
00192 void doDeleteForgetHistory();
00193 void doForceDelete();
00194 void noDelete();
00195
00196 void setWatched();
00197 void setUnwatched();
00198
00199 void toggleAutoExpire(bool turnOn);
00200 void togglePreserveEpisode(bool turnOn);
00201
00202 void PopupDone(int r);
00203 void toggleView(ViewMask itemMask, bool setOn);
00204 void toggleTitleView(bool setOn) { toggleView(VIEW_TITLES, setOn); }
00205 void toggleCategoryView(bool setOn) { toggleView(VIEW_CATEGORIES, setOn); }
00206 void toggleRecGroupView(bool setOn) { toggleView(VIEW_RECGROUPS, setOn); }
00207 void toggleWatchListView(bool setOn) { toggleView(VIEW_WATCHLIST, setOn); }
00208 void toggleSearchView(bool setOn) { toggleView(VIEW_SEARCHES, setOn); }
00209 void toggleLiveTVView(bool setOn) { toggleView(VIEW_LIVETVGRP, setOn); }
00210
00211 void exitWin();
00212
00213 void listChanged(void);
00214 void setUpdateFreeSpace() { freeSpaceNeedsUpdate = true; }
00215
00216 void initRecGroupPopup(QString title, QString name);
00217 void closeRecGroupPopup(bool refreshList = true);
00218 void setGroupFilter(void);
00219 void recGroupChangerListBoxChanged(void);
00220 void recGroupChooserListBoxChanged(void);
00221 void setRecGroup(void);
00222 void setPlayGroup(void);
00223 void setRecTitle(void);
00224 void recGroupOldPasswordChanged(const QString &newText);
00225
00226 void doJobQueueJob(int jobType, int jobFlags = 0);
00227 void doPlaylistJobQueueJob(int jobType, int jobFlags = 0);
00228 void stopPlaylistJobQueueJob(int jobType);
00229 void doBeginFlagging();
00230 void doBeginTranscoding() { doJobQueueJob(JOB_TRANSCODE,
00231 JOB_USE_CUTLIST); }
00232 void doBeginUserJob1() { doJobQueueJob(JOB_USERJOB1); }
00233 void doBeginUserJob2() { doJobQueueJob(JOB_USERJOB2); }
00234 void doBeginUserJob3() { doJobQueueJob(JOB_USERJOB3); }
00235 void doBeginUserJob4() { doJobQueueJob(JOB_USERJOB4); }
00236 void doPlaylistBeginTranscoding() { doPlaylistJobQueueJob(JOB_TRANSCODE,
00237 JOB_USE_CUTLIST); }
00238 void stopPlaylistTranscoding() { stopPlaylistJobQueueJob(JOB_TRANSCODE);}
00239 void doPlaylistBeginFlagging() { doPlaylistJobQueueJob(JOB_COMMFLAG); }
00240 void stopPlaylistFlagging() { stopPlaylistJobQueueJob(JOB_COMMFLAG); }
00241 void doPlaylistBeginUserJob1() { doPlaylistJobQueueJob(JOB_USERJOB1); }
00242 void stopPlaylistUserJob1() { stopPlaylistJobQueueJob(JOB_USERJOB1); }
00243 void doPlaylistBeginUserJob2() { doPlaylistJobQueueJob(JOB_USERJOB2); }
00244 void stopPlaylistUserJob2() { stopPlaylistJobQueueJob(JOB_USERJOB2); }
00245 void doPlaylistBeginUserJob3() { doPlaylistJobQueueJob(JOB_USERJOB3); }
00246 void stopPlaylistUserJob3() { stopPlaylistJobQueueJob(JOB_USERJOB3); }
00247 void doPlaylistBeginUserJob4() { doPlaylistJobQueueJob(JOB_USERJOB4); }
00248 void stopPlaylistUserJob4() { stopPlaylistJobQueueJob(JOB_USERJOB4); }
00249 void doClearPlaylist();
00250 void doPlaylistDelete();
00251 void doPlaylistDeleteForgetHistory();
00252 void doPlaylistChangeRecGroup();
00253 void doPlaylistChangePlayGroup();
00254 void togglePlayListTitle(void);
00255 void togglePlayListItem(void);
00256 void playSelectedPlaylist(bool random);
00257 void doPlayList(void);
00258 void showViewChanger(void);
00259
00260 void previewThreadDone(const QString &fn, bool &success);
00261 void previewReady(const ProgramInfo *pginfo);
00262
00263 protected:
00264 void paintEvent(QPaintEvent *);
00265 void keyPressEvent(QKeyEvent *e);
00266
00267 bool SetPreviewGenerator(const QString &fn, PreviewGenerator *g);
00268 void IncPreviewGeneratorPriority(const QString &fn);
00269 void UpdatePreviewGeneratorThreads(void);
00270 bool IsGeneratingPreview(const QString &fn, bool really = false) const;
00271 uint IncPreviewGeneratorAttempts(const QString &fn);
00272
00273 void SetRecGroupPassword(const QString &oldPasswd,
00274 const QString &newPasswd);
00275 bool IsRecGroupPasswordCorrect(const QString &passwd) const;
00276
00277 private:
00278 bool FillList(bool useCachedData = false);
00279 void UpdateProgressBar(void);
00280
00281 QString cutDown(QString, QFont *, int);
00282 QDateTime getPreviewLastModified(ProgramInfo *);
00283 QPixmap getPixmap(ProgramInfo *);
00284 QPainter backup;
00285 bool play(ProgramInfo *rec, bool inPlaylist = false);
00286 void stop(ProgramInfo *);
00287 void remove(ProgramInfo *);
00288 void showActions(ProgramInfo *);
00289 ProgramInfo *getSelected(void){ return curitem; }
00290
00291 void playlistDelete(bool forgetHistory = false);
00292
00293 void togglePlayListItem(ProgramInfo *pginfo);
00294 void randomizePlayList(void);
00295
00296 void processNetworkControlCommands(void);
00297 void processNetworkControlCommand(QString command);
00298
00299 void LoadWindow(QDomElement &);
00300
00301 void parsePopup(QDomElement &);
00302 void parseContainer(QDomElement &);
00303
00304 ProgramInfo *findMatchingProg(ProgramInfo *);
00305 ProgramInfo *findMatchingProg(QString key);
00306 ProgramInfo *findMatchingProg(QString chanid, QString recstartts);
00307
00308 bool killPlayer(void);
00309 void killPlayerSafe(void);
00310 void startPlayer(ProgramInfo *rec);
00311
00312 bool doRemove(ProgramInfo *, bool forgetHistory, bool forceMetadataDelete);
00313 void showDeletePopup(ProgramInfo *, deletePopupType);
00314 void showActionPopup(ProgramInfo *program);
00315 void showFileNotFoundActionPopup(ProgramInfo *program);
00316 void initPopup(MythPopupBox *popup, ProgramInfo *program,
00317 QString message, QString message2);
00318 void cancelPopup();
00319
00320 void showAvailablePopup(ProgramInfo *rec);
00321
00322 bool fileExists(ProgramInfo *pginfo);
00323
00324
00325 QString getRecGroupPassword(QString recGroup);
00326 void fillRecGroupPasswordCache(void);
00327
00328 void grayOut(QPainter *);
00329 void updateBackground(void);
00330 void updateVideo(QPainter *);
00331 void drawVideo(QPainter *);
00332 void updateShowTitles(QPainter *);
00333 void updateInfo(QPainter *);
00334 void updateUsage(QPainter *);
00335 void updateProgramInfo(QPainter *p, QRect& pr, QPixmap& pix);
00336 void updateCurGroup(QPainter *p);
00337 void updateGroupInfo(QPainter *p, QRect& pr, QPixmap& pix,
00338 QString cont_name = "group_info");
00339
00340 void clearProgramCache(void);
00341 void EmbedTVWindow(void);
00342
00345 BoxType type;
00346
00347 QString formatShortDate;
00348 QString formatLongDate;
00349 QString formatTime;
00351 bool titleView;
00353 bool useCategories;
00355 bool useRecGroups;
00357 bool watchListStart;
00359 bool watchListAutoExpire;
00361 int watchListMaxAge;
00363 int watchListBlackOut;
00365 bool groupnameAsAllProg;
00367 bool arrowAccel;
00369 bool ignoreKeyPressEvents;
00371 int allOrder;
00373 int listOrder;
00375 int listsize;
00376
00377
00378 QString groupDisplayName;
00379 QString recGroup;
00380 QString recGroupPassword;
00381 QString curGroupPassword;
00382 QString watchGroupName;
00383 QString watchGroupLabel;
00384 ViewMask viewMask;
00385
00386
00387 XMLParse *theme;
00388 QDomElement xmldata;
00389
00390
00391 QPixmap *drawTransPixmap;
00392 bool drawPopupSolid;
00393 QColor drawPopupFgColor;
00394 QColor drawPopupBgColor;
00395 QColor drawPopupSelColor;
00396 QRect drawTotalBounds;
00397 QRect drawListBounds;
00398 QRect drawInfoBounds;
00399 QRect drawGroupBounds;
00400 QRect drawUsageBounds;
00401 QRect drawVideoBounds;
00402 QRect blackholeBounds;
00403 QRect drawCurGroupBounds;
00404
00405
00406
00407 MythPopupBox *popup;
00408 bool expectingPopup;
00409
00410
00411 int recGroupLastItem;
00412 QString recGroupChooserPassword;
00413 Str2StrMap recGroupType;
00414 Str2StrMap recGroupPwCache;
00415 MythPopupBox *recGroupPopup;
00416 MythListBox *recGroupListBox;
00417 MythLineEdit *recGroupLineEdit;
00418 MythLineEdit *recGroupLineEdit1;
00419 MythLineEdit *recGroupOldPassword;
00420 MythLineEdit *recGroupNewPassword;
00421 MythPushButton *recGroupOkButton;
00422
00423
00424
00425 QTimer *fillListTimer;
00426 bool fillListFromCache;
00427 bool connected;
00428 int titleIndex;
00429 int progIndex;
00430 QStringList titleList;
00431 ProgramMap progLists;
00432 int progsInDB;
00433
00434
00435 QStringList playList;
00436
00437
00439 ProgramInfo *curitem;
00441 ProgramInfo *delitem;
00443 mutable QMutex progCacheLock;
00444 vector<ProgramInfo *> *progCache;
00446 bool playingSomething;
00447
00448
00449 bool haveGroupInfoSet;
00450 bool inTitle;
00452 bool leftRight;
00453
00454 bool playbackVideoContainer;
00455
00456
00457 bool freeSpaceNeedsUpdate;
00458 QTimer *freeSpaceTimer;
00459 int freeSpaceTotal;
00460 int freeSpaceUsed;
00461
00462
00463 int paintSkipCount;
00464 bool paintSkipUpdate;
00465 QPixmap paintBackgroundPixmap;
00466
00467
00468 NuppelVideoPlayer *previewVideoNVP;
00469 RingBuffer *previewVideoRingBuf;
00470 QTimer *previewVideoRefreshTimer;
00471 MythTimer previewVideoStartTimer;
00472 MythTimer previewVideoPlayingTimer;
00473 int previewVideoBrokenRecId;
00474 playerStateType previewVideoState;
00475 bool previewVideoStartTimerOn;
00476 bool previewVideoEnabled;
00477 bool previewVideoPlaying;
00478 bool previewVideoThreadRunning;
00479 pthread_t previewVideoThread;
00480
00481 mutable QMutex previewVideoKillLock;
00482 mutable QMutex previewVideoUnsafeKillLock;
00483 killStateType previewVideoKillState;
00484 MythTimer previewVideoKillTimeout;
00485
00486
00487 bool previewPixmapEnabled;
00488 bool previewFromBookmark;
00489 QPixmap *previewPixmap;
00490 QDateTime previewLastModified;
00491 LastCheckedMap previewLastModifyCheck;
00492 QDateTime previewFilets;
00493 QDateTime previewStartts;
00494 bool previewSuspend;
00495 QString previewChanid;
00496 mutable QMutex previewGeneratorLock;
00497 PreviewMap previewGenerator;
00498 vector<QString> previewGeneratorQueue;
00499 uint previewGeneratorRunning;
00500 static const uint previewGeneratorMaxRunning;
00501
00502
00503 mutable QMutex ncLock;
00504 QValueList<QString> networkControlCommands;
00505 bool underNetworkControl;
00506
00507 TV *m_player;
00508 };
00509
00510 #endif
00511