Ticket #3334: importicons.h

File importicons.h, 6.4 KB (added by anonymous, 17 years ago)
Line 
1/* -*- Mode: c++ -*-
2 * vim: set expandtab tabstop=4 shiftwidth=4:
3 *
4 * Original Project
5 *      MythTV      http://www.mythtv.org
6 *
7 * Author(s):
8 *      John Pullan 
9 *
10 * Description:
11 */
12
13#ifndef _IMPORTICONS_H
14#define _IMPORTICONS_H
15
16#include <qsqldatabase.h>
17#include <qurl.h>
18#include "settings.h"
19
20/** \class ImportIcons
21 *  \brief class which attempts to import icons for channels
22 *
23 *  This is a set of classes and structures which attempts to download
24 *  the icon files for a particular TV channel.
25 */
26class ImportIcons : public VerticalConfigurationGroup
27{
28    Q_OBJECT
29protected:
30    struct CSVEntry                  //! describes the TV channel name
31    {
32        QString strChanId;           //!< local channel id
33        QString strName;             //!< channel name
34        QString strXmlTvId;          //!< the xmltvid
35        QString strCallsign;         //!< callsign
36        QString strTransportId;      //!< transport id
37        QString strAtscMajorChan;    //!< ATSC major number
38        QString strAtscMinorChan;    //!< ATSC minor number
39        QString strNetworkId;        //!< network id
40        QString strServiceId;        //!< service id
41        QString strIconCSV;          //!< icon name (csv form)
42        QString strNameCSV;          //!< name (csv form)
43    }; 
44    //! List of CSV entries
45    typedef QValueList<CSVEntry> ListEntries;     
46    //! iterator over list of CSV entries
47    typedef QValueListIterator<CSVEntry> ListEntriesIter;
48
49    ListEntries m_listEntries;       //!< list of TV channels to search for
50    ListEntriesIter m_iter;          //!< the current iterator
51
52    struct SearchEntry               //! search entry results
53    {
54        QString strID;               //!< the remote channel id
55        QString strName;             //!< the remote name
56        QString strLogo;             //!< the actual logo
57    };
58    //! List of SearchEntry entries
59    typedef QValueList<SearchEntry> ListSearchEntries;
60    //! iterator over list of SearchEntry entries
61    typedef QValueListIterator<SearchEntry> ListSearchEntriesIter;
62
63    ListSearchEntries m_listSearch;  //!< the list of SearchEntry
64    QString m_strMatches;            //!< the string for the submit() call
65
66    static const QString url;        //!< the default url
67    QString m_strChannelDir;         //!< the location of the channel icon dir
68
69    bool m_fRefresh;                 //!< are we doing a refresh or not
70    int m_nMaxCount;                 //!< the maximum number of TV channels
71    int m_nCount;                    //!< the current search point (0..m_nMaxCount)
72
73    /*! \brief changes a string into csv format
74     * \param str the string to change
75     * \return the actual string
76     */
77    QString escape_csv(const QString& str);
78
79    /*! \brief extracts the csv values out of a string
80     * \param str the string to work on
81     * \return the actual QStringList
82     */
83    QStringList extract_csv(const QString& strLine);
84
85    /*! \brief use the equivalent of wget to fetch the POST command
86     * \param url the url to send this to
87     * \param strParam the string to send
88     * \return the actual string
89     */
90    QString wget(QUrl& url,const QString& strParam);
91 
92    TransLineEditSetting *m_editName;    //!< name field for the icon
93    TransListBoxSetting *m_listIcons;    //!< list of potential icons
94    TransLineEditSetting *m_editManual;  //!< manual edit field
95    TransButtonSetting *m_buttonManual;  //!< manual button field
96    TransButtonSetting *m_buttonSkip;    //!< button skip
97
98    /*! \brief detemines if you can actually reach the net
99     * \return true/false
100     */
101    bool ping();                       
102
103    /*! \brief determines if a particular icon is blocked
104     * \param str the string to work on
105     * \return true/false
106     */
107    bool isBlocked(const QString& strParam);
108
109    /*! \brief looks up the string to determine the caller/xmltvid
110     * \param str the string to work on
111     * \return true/false
112     */
113    bool lookup(const QString& strParam);
114
115    /*! \brief search the remote db for icons etc
116     * \param str the string to work on
117     * \return true/false
118     */
119    bool search(const QString& strParam);
120
121    /*! \brief submit the icon information back to the remote db
122     * \param str the string to work on
123     * \return true/false
124     */
125    bool submit(const QString& strParam);
126
127    /*! \brief retrieve the actual logo for the TV channel
128     * \param str the string to work on
129     * \return true/false
130     */
131    bool findmissing(const QString& strParam);
132
133    /*! \brief checks and attempts to download the logo file to the appropriate
134     *   place
135     * \param str the string of the downloaded url
136     * \return true/false
137     */
138    bool checkAndDownload(const QString& str);
139
140    /*! \brief attempt the inital load of the TV channel information
141     * \return the number of TV channels
142     */
143    unsigned initialLoad();
144
145    /*! \brief attempts to move the itaration on one/more than one
146     * \return true if we can go again or false if we can not
147     */
148    bool doLoad();
149
150public:
151    ImportIcons(bool fRefresh);    //!< constructs an icon import page
152
153    bool initialise();             //!< returns true if the net is pingable etc.
154
155protected slots:
156    void enableControls();         //!< enable/disable the controls
157    void manualSearch();           //!< process the manual search
158    void menuSelection(int nIndex);//!< process the icon selection
159    void skip();                   //!< skip this icon
160};
161
162/** \class ImportIconsWizard
163 *  \brief class which constructs an ImportIconsWizard, with an appropriate
164 *         ImportIcons child in it.
165 */
166class ImportIconsWizard : public QObject, public ConfigurationWizard
167{
168    Q_OBJECT
169protected:
170    ImportIcons *m_ImportIcons;      //!< pointer to the ImportIcons class
171    //! \brief result to be used in exec() and finishButtonPressed()
172    bool m_fResult;               
173
174public:
175    ImportIconsWizard(bool fRefresh); //!< constructs an ImportIconWizard
176
177    /*! \brief go through each of the sheets to determine if anything fails
178     * return true/false
179     */
180    bool initialise();
181
182    virtual int exec();               //!< executes the wizard
183    virtual MythDialog *dialogWidget(MythMainWindow *parent,
184                         const char *widgetName); //!< returns the MythDialog
185protected slots:
186    void finishButtonPressed();       //!< was the finish button pressed
187};
188
189#endif // _IMPORTICONS_H