00001
00002
00003 #ifndef _TV_BROWSE_HELPER_H_
00004 #define _TV_BROWSE_HELPER_H_
00005
00006 #include <QWaitCondition>
00007 #include <QMultiMap>
00008 #include <QString>
00009 #include <QHash>
00010
00011 #include "dbchannelinfo.h"
00012 #include "programtypes.h"
00013 #include "mthread.h"
00014 #include "tv.h"
00015
00016 class PlayerContext;
00017 class RemoteEncoder;
00018 class TV;
00019
00020 class BrowseInfo
00021 {
00022 public:
00023 BrowseInfo(BrowseDirection dir) :
00024 m_dir(dir), m_chanid(0), m_sourceid(0)
00025 {
00026 }
00027 BrowseInfo(BrowseDirection dir,
00028 const QString &channum,
00029 uint chanid,
00030 const QString &starttime) :
00031 m_dir(dir), m_channum(channum),
00032 m_chanid(chanid), m_starttime(starttime),
00033 m_sourceid(0)
00034 {
00035 }
00036 BrowseInfo(const QString &channum,
00037 uint sourceid) :
00038 m_dir(BROWSE_SAME), m_channum(channum),
00039 m_chanid(0), m_sourceid(sourceid)
00040 {
00041 }
00042
00043 QString toString() const
00044 {
00045 return QString("%1;%2;%3;%4;%5")
00046 .arg(BROWSE_SAME==m_dir?"SAME":
00047 BROWSE_UP ==m_dir?"UP":
00048 BROWSE_DOWN==m_dir?"DOWN":
00049 QString::number(m_dir))
00050 .arg(m_channum)
00051 .arg(m_chanid)
00052 .arg(m_starttime)
00053 .arg(m_sourceid);
00054 }
00055
00056 BrowseDirection m_dir;
00057 QString m_channum;
00058 uint m_chanid;
00059 QString m_starttime;
00060 uint m_sourceid;
00061 };
00062
00063
00064 class TVBrowseHelper : public MThread
00065 {
00066 public:
00067 TVBrowseHelper(TV *tv,
00068 QString time_format,
00069 QString short_date_format,
00070 uint browse_max_forward,
00071 bool browse_all_tuners,
00072 bool use_channel_groups,
00073 QString db_channel_ordering);
00074
00075 virtual ~TVBrowseHelper()
00076 {
00077 Stop();
00078 Wait();
00079 }
00080
00081 void Stop()
00082 {
00083 QMutexLocker locker(&m_lock);
00084 m_list.clear();
00085 m_run = false;
00086 m_wait.wakeAll();
00087 }
00088
00089 void Wait() { MThread::wait(); }
00090
00091 bool BrowseStart(PlayerContext *ctx, bool skip_browse = false);
00092 void BrowseEnd(PlayerContext *ctx, bool change_channel);
00093 void BrowseDispInfo(PlayerContext *ctx, BrowseInfo &bi);
00094
00095 void BrowseDispInfo(PlayerContext *ctx, BrowseDirection direction)
00096 {
00097 BrowseInfo bi(direction);
00098 if (BROWSE_SAME != direction)
00099 BrowseDispInfo(ctx, bi);
00100 }
00101
00102 void BrowseChannel(PlayerContext *ctx, const QString &channum);
00103
00104 BrowseInfo GetBrowsedInfo(void) const;
00105 bool IsBrowsing(void) const;
00106 uint GetChanId(const QString &channum,
00107 uint pref_cardid, uint pref_sourceid) const;
00108
00109 protected:
00110 void GetNextProgram(BrowseDirection direction, InfoMap &infoMap) const;
00111 void GetNextProgramDB(BrowseDirection direction, InfoMap &infoMap) const;
00112
00113 virtual void run();
00114
00115 TV *m_tv;
00116 DBChanList db_all_channels;
00117 DBChanList db_all_visible_channels;
00118 QString db_time_format;
00119 QString db_short_date_format;
00120 uint db_browse_max_forward;
00121 bool db_browse_all_tuners;
00122 bool db_use_channel_groups;
00123 QHash<uint,QString> db_chanid_to_channum;
00124 QHash<uint,uint> db_chanid_to_sourceid;
00125 QMultiMap<QString,uint> db_channum_to_chanids;
00126
00127 mutable QMutex m_lock;
00128 PlayerContext *m_ctx;
00129 QString m_channum;
00130 uint m_chanid;
00131 QString m_starttime;
00132 bool m_run;
00133 QWaitCondition m_wait;
00134 QList<BrowseInfo> m_list;
00135 };
00136
00137 #endif // _TV_BROWSE_HELPER_H_