Ticket #3334: importicons-libmythtv-04102007.2.diff

File importicons-libmythtv-04102007.2.diff, 31.7 KB (added by Matthew Wire <devel@…>, 17 years ago)

Fixed return from dialog

  • libs/libmythtv/channeleditor.cpp

     
    1919#include "sourceutil.h"
    2020
    2121#include "scanwizard.h"
     22#include "importicons.h"
    2223
    2324ChannelWizard::ChannelWizard(int id, int default_sourceid)
    2425    : ConfigurationWizard()
     
    110111        return 0;
    111112}
    112113
    113 void ChannelListSetting::fillSelections(void)
     114int ChannelListSetting::fillSelections(void)
    114115{
    115116    QString currentValue = getValue();
    116117    clearSelections();
    117118    addSelection(QObject::tr("(New Channel)"));
    118119    bool fAllSources = true;
     120    int nCount = 0;
    119121
    120122    QString querystr = "SELECT channel.name,channum,chanid ";
    121123
     
    184186                name += " (" + sourceid  + ")";
    185187
    186188            addSelection(name, chanid, (chanid == currentValue) ? true : false);
     189            nCount++;
    187190        }
    188191    }
     192    return nCount;
    189193}
    190194
    191195class SourceSetting : public ComboBoxSetting, public Storage
     
    266270    buttonScan->setLabel(QObject::tr("Channel Scanner"));
    267271    buttonScan->setHelpText(QObject::tr("Starts the channel scanner."));
    268272    buttonScan->setEnabled(SourceUtil::IsAnySourceScanable());
     273   
     274    buttonImportIcon = new TransButtonSetting();
     275    buttonImportIcon->setLabel(QObject::tr("Icon Import"));
     276    buttonImportIcon->setHelpText(QObject::tr("Starts the icon importer"));
    269277
    270278    buttonTransportEditor = new TransButtonSetting();
    271279    buttonTransportEditor->setLabel(QObject::tr("Transport Editor"));
     
    278286    HorizontalConfigurationGroup *h =
    279287        new HorizontalConfigurationGroup(false, false);
    280288    h->addChild(buttonScan);
     289    h->addChild(buttonImportIcon);
    281290    h->addChild(buttonTransportEditor);
    282291    addChild(h);
    283292
     
    293302            this, SLOT(menu(int)));
    294303    connect(buttonScan, SIGNAL(pressed()),
    295304            this, SLOT(scan()));
     305    connect(buttonImportIcon,  SIGNAL(pressed()),
     306            this, SLOT(channelIconImport()));
    296307    connect(buttonTransportEditor, SIGNAL(pressed()),
    297308            this, SLOT(transportEditor()));
    298309    connect(del,  SIGNAL(pressed()),
     
    459470    list->fillSelections();
    460471    list->setFocus();
    461472}
     473
     474void ChannelEditor::channelIconImport(void)
     475{
     476    if (list->fillSelections() == 0)
     477    {
     478        MythPopupBox::showOkPopup(gContext->GetMainWindow(), "",
     479                                        tr("Add some for channels first!"));
     480        return;
     481    }
     482    QStringList buttons;
     483    buttons.append(tr("Import all icons.."));
     484    buttons.append(tr("Rescan for missing icons.."));
     485//    buttons.append(tr("Import icon for selected channel"));
     486    int val = MythPopupBox::showButtonPopup(gContext->GetMainWindow(),
     487                                             "", "Channel Icon Import", buttons, 0);
     488    ImportIconsWizard *iconwizard;
     489    if (val == 0)
     490        iconwizard = new ImportIconsWizard(false);
     491    else if (val == 1)
     492        iconwizard = new ImportIconsWizard(true);
     493    else if (val == 2) // Import a single channel icon
     494    {
     495        //iconwizard = new ImportIconsWizard(true);
     496        MythPopupBox::showOkPopup(gContext->GetMainWindow(), "",
     497                                        tr("Sorry, not yet implemented!"));
     498        return;
     499    }
     500    iconwizard->exec();
     501    iconwizard->deleteLater();
     502   
     503    list->fillSelections();
     504    list->setFocus();
     505}
  • libs/libmythtv/libmythtv.pro

     
    148148HEADERS += playgroup.h              progdetails.h
    149149HEADERS += channeleditor.h          channelsettings.h
    150150HEADERS += previewgenerator.h       transporteditor.h
     151HEADERS += importicons.h
    151152
    152153SOURCES += programinfo.cpp          proglist.cpp
    153154SOURCES += storagegroup.cpp
     
    170171SOURCES += progdetails.cpp
    171172SOURCES += channeleditor.cpp        channelsettings.cpp
    172173SOURCES += previewgenerator.cpp     transporteditor.cpp
     174SOURCES += importicons.cpp
    173175
    174176# DiSEqC
    175177HEADERS += diseqc.h                 diseqcsettings.h
  • libs/libmythtv/importicons.h

     
     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, Matthew Wire 
     9 *
     10 * Description:
     11 */
     12
     13#ifndef IMPORTICONS_H
     14#define IMPORTICONS_H
     15
     16#include <qsqldatabase.h>
     17#include <qurl.h>
     18
     19#include "settings.h"
     20
     21class ImportIconsWizard : public QObject, public ConfigurationWizard
     22{
     23    Q_OBJECT
     24public:
     25    ImportIconsWizard(bool fRefresh); //!< constructs an ImportIconWizard
     26
     27private:
     28
     29    enum dialogState
     30    {
     31        STATE_NORMAL,
     32        STATE_SEARCHING
     33    };
     34   
     35    struct CSVEntry                  //! describes the TV channel name
     36    {
     37        QString strChanId;           //!< local channel id
     38        QString strName;             //!< channel name
     39        QString strXmlTvId;          //!< the xmltvid
     40        QString strCallsign;         //!< callsign
     41        QString strTransportId;      //!< transport id
     42        QString strAtscMajorChan;    //!< ATSC major number
     43        QString strAtscMinorChan;    //!< ATSC minor number
     44        QString strNetworkId;        //!< network id
     45        QString strServiceId;        //!< service id
     46        QString strIconCSV;          //!< icon name (csv form)
     47        QString strNameCSV;          //!< name (csv form)
     48    }; 
     49    //! List of CSV entries
     50    typedef QValueList<CSVEntry> ListEntries;     
     51    //! iterator over list of CSV entries
     52    typedef QValueListIterator<CSVEntry> ListEntriesIter;
     53
     54    ListEntries m_listEntries;       //!< list of TV channels to search for
     55    ListEntries m_missingEntries;    //!< list of TV channels with no unique icon
     56    ListEntriesIter m_iter;          //!< the current iterator
     57    ListEntriesIter m_missingIter;
     58
     59    struct SearchEntry               //! search entry results
     60    {
     61        QString strID;               //!< the remote channel id
     62        QString strName;             //!< the remote name
     63        QString strLogo;             //!< the actual logo
     64    };
     65    //! List of SearchEntry entries
     66    typedef QValueList<SearchEntry> ListSearchEntries;
     67    //! iterator over list of SearchEntry entries
     68    typedef QValueListIterator<SearchEntry> ListSearchEntriesIter;
     69
     70    ListSearchEntries m_listSearch;  //!< the list of SearchEntry
     71    QString m_strMatches;            //!< the string for the submit() call
     72
     73    static const QString url;        //!< the default url
     74    QString m_strChannelDir;         //!< the location of the channel icon dir
     75
     76    bool m_fRefresh;                 //!< are we doing a refresh or not
     77    int m_nMaxCount;                 //!< the maximum number of TV channels
     78    int m_nCount;                    //!< the current search point (0..m_nMaxCount)
     79    int m_missingMaxCount;           //!< the total number of missing icons
     80    int m_missingCount;              //!< the current search point (0..m_missingCount)
     81
     82    /*! \brief changes a string into csv format
     83     * \param str the string to change
     84     * \return the actual string
     85     */
     86    QString escape_csv(const QString& str);
     87
     88    /*! \brief extracts the csv values out of a string
     89     * \param str the string to work on
     90     * \return the actual QStringList
     91     */
     92    QStringList extract_csv(const QString& strLine);
     93
     94    /*! \brief use the equivalent of wget to fetch the POST command
     95     * \param url the url to send this to
     96     * \param strParam the string to send
     97     * \return the actual string
     98     */
     99    QString wget(QUrl& url,const QString& strParam);
     100 
     101    TransLineEditSetting *m_editName;    //!< name field for the icon
     102    TransListBoxSetting *m_listIcons;    //!< list of potential icons
     103    TransLineEditSetting *m_editManual;  //!< manual edit field
     104    TransButtonSetting *m_buttonManual;  //!< manual button field
     105    TransButtonSetting *m_buttonSkip;    //!< button skip
     106    TransButtonSetting *m_buttonSelect;    //!< button skip
     107
     108    /*! \brief determines if a particular icon is blocked
     109     * \param str the string to work on
     110     * \return true/false
     111     */
     112    bool isBlocked(const QString& strParam);
     113
     114    /*! \brief looks up the string to determine the caller/xmltvid
     115     * \param str the string to work on
     116     * \return true/false
     117     */
     118    bool lookup(const QString& strParam);
     119
     120    /*! \brief search the remote db for icons etc
     121     * \param str the string to work on
     122     * \return true/false
     123     */
     124    bool search(const QString& strParam);
     125
     126    /*! \brief submit the icon information back to the remote db
     127     * \param str the string to work on
     128     * \return true/false
     129     */
     130    bool submit(const QString& strParam);
     131
     132    /*! \brief retrieve the actual logo for the TV channel
     133     * \param str the string to work on
     134     * \return true/false
     135     */
     136    bool findmissing(const QString& strParam);
     137
     138    /*! \brief checks and attempts to download the logo file to the appropriate
     139     *   place
     140     * \param str the string of the downloaded url
     141     * \return true/false
     142     */
     143    bool checkAndDownload(const QString& str);
     144
     145    /*! \brief attempt the inital load of the TV channel information
     146     * \return the number of TV channels
     147     */
     148    unsigned initialLoad();
     149
     150    /*! \brief attempts to move the itaration on one/more than one
     151     * \return true if we can go again or false if we can not
     152     */
     153    bool doLoad();
     154   
     155    bool m_cancelled;
     156   
     157    ~ImportIconsWizard() { };
     158   
     159protected slots:
     160    void enableControls(dialogState state=STATE_NORMAL);         //!< enable/disable the controls
     161    void manualSearch();           //!< process the manual search
     162    void menuSelect();
     163    void menuSelection(int nIndex);//!< process the icon selection
     164    void skip();                   //!< skip this icon
     165    void cancelPressed();
     166
     167};
     168
     169#endif // IMPORTICONS_H
  • libs/libmythtv/channeleditor.h

     
    2222    void edit();
    2323    void edit(int);
    2424    void scan(void);
    25     void transportEditor();
    26     void deleteChannels();
     25    void transportEditor(void);
     26    void channelIconImport(void);
     27    void deleteChannels(void);
    2728
    2829private:
    2930    int                 id;
    3031    SourceSetting      *source;
    3132    ChannelListSetting *list;
    3233    TransButtonSetting *buttonScan;
     34    TransButtonSetting *buttonImportIcon;
    3335    TransButtonSetting *buttonTransportEditor;
    3436};
    3537
     
    6870    bool getHideMode() { return currentHideMode; };
    6971
    7072public slots:
    71     void fillSelections(void);
     73    int fillSelections(void);
    7274    void setSortMode(const QString& sort) {
    7375        if (currentSortMode != sort) {
    7476            currentSortMode = sort;
  • libs/libmythtv/importicons.cpp

     
     1#include <sys/stat.h>
     2#include <qapplication.h>
     3#include <qregexp.h>
     4#include <qbuffer.h>
     5#include <qfileinfo.h>
     6
     7#include "httpcomms.h"
     8#include "importicons.h"
     9#include "util.h"
     10
     11ImportIconsWizard::ImportIconsWizard(bool fRefresh)
     12{
     13    m_fRefresh = fRefresh;   
     14   
     15        VerticalConfigurationGroup *manSearch =
     16        new VerticalConfigurationGroup(false,false,true,true);
     17   
     18    manSearch->addChild(m_editName = new TransLineEditSetting(false));
     19    m_editName->setLabel(QObject::tr("Name"));
     20    m_editName->setHelpText(QObject::tr("Name of the icon file"));
     21
     22    manSearch->addChild(m_listIcons = new TransListBoxSetting());
     23    m_listIcons->setHelpText(QObject::tr("List of possible icon files"));
     24
     25    m_editManual = new TransLineEditSetting();
     26    m_editManual->setHelpText(QObject::tr("Enter text here for the manual search"));
     27
     28    m_buttonManual = new TransButtonSetting();
     29    m_buttonManual->setLabel(QObject::tr("&Search"));
     30    m_buttonManual->setHelpText(QObject::tr("Manually search for the text"));
     31
     32    m_buttonSkip = new TransButtonSetting();
     33    m_buttonSkip->setLabel(QObject::tr("S&kip"));
     34    m_buttonSkip->setHelpText(QObject::tr("Skip this icon"));
     35
     36    m_buttonSelect = new TransButtonSetting();
     37    m_buttonSelect->setLabel(QObject::tr("S&elect"));
     38    m_buttonSelect->setHelpText(QObject::tr("Select this icon"));
     39
     40    HorizontalConfigurationGroup *hrz1 =
     41        new HorizontalConfigurationGroup(false, false, true, true);
     42
     43    hrz1->addChild(m_editManual);
     44    hrz1->addChild(m_buttonManual);
     45    hrz1->addChild(m_buttonSkip);
     46    hrz1->addChild(m_buttonSelect);
     47    manSearch->addChild(hrz1);
     48   
     49    addChild(manSearch);
     50
     51    connect(m_editManual, SIGNAL(valueChanged( const QString&)),
     52            this, SLOT(  enableControls()));
     53    connect(m_buttonManual, SIGNAL(pressed()), this, SLOT(manualSearch()));
     54    connect(m_buttonSkip, SIGNAL(pressed()), this, SLOT(skip()));
     55    connect(m_listIcons,SIGNAL(accepted(int)),this,
     56             SLOT(menuSelection(int)));
     57    connect(m_buttonSelect,SIGNAL(pressed()),this,
     58             SLOT(menuSelect()));
     59
     60    enableControls();
     61   
     62
     63    m_strChannelDir =  MythContext::GetConfDir()+ "/channels";
     64    mkdir(MythContext::GetConfDir(),0776);
     65    mkdir(m_strChannelDir,0776);
     66    m_strChannelDir+="/";
     67    m_cancelled=false;
     68
     69    if (initialLoad() > 0)
     70    {
     71        m_missingIter=m_missingEntries.begin();
     72        m_missingCount=0;
     73        enableControls();
     74        doLoad();
     75    }
     76}
     77
     78const QString ImportIconsWizard::url="http://services.mythtv.org/channel-icon/";
     79
     80void ImportIconsWizard::enableControls(dialogState state)
     81{
     82    switch (state)
     83    {
     84        case STATE_NORMAL:
     85            if (m_editManual->getValue())
     86                m_buttonManual->setEnabled(true);
     87           else
     88           m_buttonManual->setEnabled(false);
     89           if (m_missingCount < m_missingMaxCount)
     90           {
     91               m_buttonSkip->setEnabled(true);
     92               m_editName->setEnabled(true);
     93               m_listIcons->setEnabled(true);
     94               m_editManual->setEnabled(true);
     95               m_buttonSelect->setEnabled(true);
     96//               m_editManual->setValue("");
     97           }
     98           else
     99           {
     100               m_buttonSkip->setEnabled(false);
     101               m_editName->setEnabled(false);
     102               m_listIcons->setEnabled(false);
     103               m_editManual->setEnabled(false);
     104               m_buttonManual->setEnabled(false);
     105               m_buttonSelect->setEnabled(false);
     106           }
     107           break;
     108        case STATE_SEARCHING:
     109               m_buttonSkip->setEnabled(false);
     110               m_buttonSelect->setEnabled(false);
     111               m_buttonManual->setEnabled(false);
     112               m_listIcons->setEnabled(false);
     113               m_listIcons->clearSelections();
     114               m_listIcons->addSelection("Please wait...");
     115        break;
     116    }       
     117}
     118
     119void ImportIconsWizard::manualSearch()
     120{
     121    enableControls(STATE_SEARCHING);
     122    QString str = m_editManual->getValue();
     123    search(escape_csv(str));   
     124    enableControls(STATE_NORMAL);
     125}
     126
     127void ImportIconsWizard::skip()
     128{
     129    enableControls(STATE_SEARCHING);
     130    m_missingCount++;
     131    m_missingIter++;   
     132    doLoad();
     133    enableControls(STATE_NORMAL);
     134}
     135
     136void ImportIconsWizard::menuSelect()
     137{
     138    menuSelection(m_listIcons->currentItem());   
     139}
     140
     141void ImportIconsWizard::menuSelection(int nIndex)
     142{
     143    enableControls(STATE_SEARCHING);
     144    SearchEntry entry = *(m_listSearch.at(nIndex));
     145    if (!isBlocked((*m_iter).strIconCSV) &&
     146         checkAndDownload(entry.strLogo))
     147    {
     148        CSVEntry entry2 = (*m_iter);
     149        m_strMatches += QString("%1,%2,%3,%4,%5,%6,%7,%8,%9\n").
     150                              arg(escape_csv(entry.strID)).
     151                              arg(escape_csv(entry2.strName)).
     152                              arg(escape_csv(entry2.strXmlTvId)).
     153                              arg(escape_csv(entry2.strCallsign)).
     154                              arg(escape_csv(entry2.strTransportId)).
     155                              arg(escape_csv(entry2.strAtscMajorChan)).
     156                              arg(escape_csv(entry2.strAtscMinorChan)).
     157                              arg(escape_csv(entry2.strNetworkId)).
     158                              arg(escape_csv(entry2.strServiceId));
     159        m_missingCount++;
     160        m_missingIter++;
     161        doLoad();
     162        enableControls(STATE_NORMAL);
     163    }
     164    else
     165    {
     166        MythPopupBox::showOkPopup(gContext->GetMainWindow(),
     167                            QObject::tr("Error downloading"),
     168                            QObject::tr("Failed to download the icon file"));       
     169        enableControls(STATE_NORMAL);
     170    }
     171   
     172}
     173
     174unsigned ImportIconsWizard::initialLoad()
     175{
     176    VERBOSE(VB_CHANNEL, "initialLoad");
     177    MSqlQuery query(MSqlQuery::InitCon());
     178    query.prepare("SELECT chanid,name,xmltvid,callsign,"
     179                  "dtv_multiplex.transportid, "
     180                  "atsc_major_chan,atsc_minor_chan,dtv_multiplex.networkid,"
     181                  "channel.serviceid, "
     182                  "channel.mplexid, dtv_multiplex.mplexid,"
     183                  "channel.icon, channel.visible FROM "
     184                  "channel, dtv_multiplex WHERE "
     185                  "channel.visible && "
     186                  "channel.mplexid=dtv_multiplex.mplexid ORDER BY name");
     187       
     188    m_listEntries.clear();           
     189    m_nCount=0;
     190    m_nMaxCount=0;
     191    m_missingMaxCount=0;
     192
     193    if (query.exec() && query.isActive() && query.size() > 0)
     194    {
     195        MythProgressDialog *progressDialog = new MythProgressDialog("Initialising, please wait...", query.size());
     196       
     197        sleep(2); // Ensures dialog is drawn before ping freezes execution
     198       
     199        if (!ping("services.mythtv.org", 3))
     200        {
     201            progressDialog->Close();
     202            MythPopupBox::showOkPopup(gContext->GetMainWindow(),
     203                                  tr("Bad Host"),
     204                                  tr("Failed to connect to the remote server"));
     205            return 0;
     206        }
     207
     208        while(query.next())
     209        {
     210            CSVEntry entry;
     211
     212            if (m_fRefresh)
     213            {
     214                QFileInfo file(query.value(11).toString());
     215                if (file.exists())
     216                    continue;
     217            }
     218           
     219            entry.strChanId=query.value(0).toString();
     220            entry.strName=query.value(1).toString();
     221            entry.strXmlTvId=query.value(2).toString();
     222            entry.strCallsign=query.value(3).toString();
     223            entry.strTransportId=query.value(4).toString();
     224            entry.strAtscMajorChan=query.value(5).toString();
     225            entry.strAtscMinorChan=query.value(6).toString();
     226            entry.strNetworkId=query.value(7).toString();
     227            entry.strServiceId=query.value(8).toString();
     228            entry.strIconCSV= QString("%1,%2,%3,%4,%5,%6,%7,%8,%9\n").
     229                              arg(escape_csv(entry.strChanId)).
     230                              arg(escape_csv(entry.strName)).
     231                              arg(escape_csv(entry.strXmlTvId)).
     232                              arg(escape_csv(entry.strCallsign)).
     233                              arg(escape_csv(entry.strTransportId)).
     234                              arg(escape_csv(entry.strAtscMajorChan)).
     235                              arg(escape_csv(entry.strAtscMinorChan)).
     236                              arg(escape_csv(entry.strNetworkId)).
     237                              arg(escape_csv(entry.strServiceId));
     238            entry.strNameCSV=escape_csv(entry.strName);
     239            VERBOSE(VB_IMPORTANT,QString("chanid %1").arg(entry.strIconCSV));
     240
     241            m_listEntries.append(entry);
     242            m_nMaxCount++;
     243            progressDialog->setProgress(m_nMaxCount);
     244        }
     245        progressDialog->Close();
     246        progressDialog->deleteLater();
     247    }
     248   
     249    m_listIcons->clearSelections();
     250    m_editName->setValue("");
     251    m_iter = m_listEntries.begin();
     252   
     253    MythProgressDialog *progressDialog = new MythProgressDialog("Downloading, please wait...",
     254                                m_listEntries.size()+1, true, this, SLOT(cancelPressed()));
     255    while (!m_cancelled && (m_iter != m_listEntries.end()))
     256    {
     257        progressDialog->setLabel(QString("Downloading %1 / %2 : ").arg(m_nCount+1)
     258                                 .arg(m_listEntries.size()+1) + (*m_iter).strName +
     259                                 QString("\nCould not find %1 icons.").arg(m_missingEntries.size()+1));
     260        if (!findmissing((*m_iter).strIconCSV))
     261            m_missingEntries.append((*m_iter));
     262        m_nCount++;
     263        m_iter++;
     264        m_missingMaxCount++;
     265        progressDialog->setProgress(m_nCount);
     266    }
     267    progressDialog->Close();
     268    progressDialog->deleteLater();
     269   
     270    //Comment below for debugging - cancel button will continue to dialog
     271    if (m_cancelled)
     272        m_nMaxCount=0;
     273    return m_nMaxCount;
     274}
     275
     276bool ImportIconsWizard::doLoad()
     277{
     278    VERBOSE(VB_CHANNEL, QString("%1 / %2").arg(m_missingCount).arg(m_missingMaxCount));
     279    if (m_missingCount >= m_missingMaxCount)
     280    {
     281        VERBOSE(VB_CHANNEL, "doLoad Icon search complete");
     282        if (!m_strMatches.isEmpty())
     283        {
     284            int nVal = MythPopupBox::showOkCancelPopup(
     285                            gContext->GetMainWindow(),
     286                            QObject::tr("Submit information"),
     287                            QObject::tr("You now have the opportunity to "
     288                                        "transmit your choices  back to "
     289                                        "mythtv.org so that others can "
     290                                        "benefit from your selections."),
     291                          true);       
     292             if (nVal == 1)
     293                 submit(m_strMatches);
     294        }
     295        return false;
     296    }
     297    else
     298    {
     299        // Look for the next missing icon
     300        m_editName->setValue((*m_missingIter).strName);
     301        m_buttonSelect->setEnabled(search((*m_missingIter).strNameCSV));
     302        return true;
     303    }
     304}
     305
     306QString ImportIconsWizard::escape_csv(const QString& str)
     307{
     308    VERBOSE(VB_CHANNEL, "escape_csv");
     309    QRegExp rxDblForEscape("\"");
     310    QString str2 = str;
     311    str2.replace(rxDblForEscape,"\\\"");
     312    return "\""+str2+"\"";
     313}
     314
     315QStringList ImportIconsWizard::extract_csv(const QString& strLine)
     316{
     317    VERBOSE(VB_CHANNEL, "extract_csv");
     318    QStringList ret;
     319    //Clean up the line and split out the fields
     320    QString str = strLine;
     321
     322    unsigned int pos = 0;
     323    bool fFinish = false;
     324    while(!fFinish)
     325    {
     326        str=str.stripWhiteSpace();
     327        while(!fFinish)
     328        {
     329            QString strLeft;
     330            switch (str.at(pos).unicode())
     331            {
     332            case '\\':
     333                if (pos>=1)
     334                    str.left(pos-1)+str.mid(pos+1);
     335                else
     336                    str=str.mid(pos+1);
     337                pos+=2;
     338                if (pos > str.length())
     339                {
     340                    strLeft = str.left(pos);
     341                    if (strLeft.startsWith("\"") && strLeft.endsWith("\""))
     342                        strLeft=strLeft.mid(1,strLeft.length()-2);
     343                    ret.append(strLeft);
     344                    fFinish = true;
     345                }
     346                break;
     347            case ',':
     348                strLeft = str.left(pos);
     349                if (strLeft.startsWith("\"") && strLeft.endsWith("\""))
     350                    strLeft=strLeft.mid(1,strLeft.length()-2);
     351                ret.append(strLeft);
     352                if ((pos+1) > str.length())
     353                   fFinish = true;
     354                str=str.mid(pos+1);
     355                pos=0;
     356                break;
     357            default:
     358                pos++;
     359                if (pos > str.length())
     360                {
     361                    strLeft = str.left(pos);
     362                    if (strLeft.startsWith("\"") && strLeft.endsWith("\""))
     363                        strLeft=strLeft.mid(1,strLeft.length()-2);
     364                    ret.append(strLeft);
     365                    fFinish = true;
     366                }
     367            }
     368        }
     369    }
     370    return ret;
     371}
     372
     373
     374QString ImportIconsWizard::wget(QUrl& url,const QString& strParam )
     375{
     376    VERBOSE(VB_CHANNEL, "wget");
     377    QByteArray raw;
     378    QTextStream rawStream(raw,IO_WriteOnly);
     379    rawStream << strParam;
     380
     381    QBuffer data(raw);
     382    QHttpRequestHeader header;
     383
     384    header.setContentType(QString("application/x-www-form-urlencoded"));
     385    header.setContentLength(raw.size());
     386
     387    header.setValue("User-Agent", "MythTV Channel Icon lookup bot");
     388
     389    QString str = HttpComms::postHttp(url,&header,&data);
     390
     391    return str;
     392}
     393
     394bool ImportIconsWizard::checkAndDownload(const QString& str)
     395{
     396    VERBOSE(VB_CHANNEL, "checkAndDownload");
     397    int iIndex = str.findRev('/');
     398    QString str2;
     399    if (iIndex < 0)
     400        str2=str;
     401    else
     402        str2=str.mid(iIndex+1);
     403
     404    QString str3 = str;
     405    QFileInfo file(m_strChannelDir+str2);
     406
     407    bool fRet;
     408    if (!file.exists())
     409        fRet = HttpComms::getHttpFile(m_strChannelDir+str2,str3);   
     410    else
     411        fRet = true;
     412
     413    if (fRet)
     414    {
     415        MSqlQuery query(MSqlQuery::InitCon());
     416        QString  qstr = "UPDATE channel SET icon = :ICON "
     417                        "WHERE chanid = :CHANID";
     418
     419        query.prepare(qstr);
     420        query.bindValue(":ICON", m_strChannelDir+str2);
     421        query.bindValue(":CHANID", (*m_iter).strChanId);
     422
     423        if (!query.exec())
     424        {
     425            MythContext::DBError("Error inserting channel icon", query);
     426            return false;
     427        }
     428 
     429    }
     430    return fRet;
     431}
     432
     433bool ImportIconsWizard::isBlocked(const QString& strParam)
     434{
     435    VERBOSE(VB_CHANNEL, "isBlocked");
     436    QString strParam1 = strParam;
     437    QUrl::encode(strParam1);
     438    QUrl url(ImportIconsWizard::url+"/checkblock");
     439    QString str = wget(url,"csv="+strParam1);
     440    if (str.startsWith("Error",false))
     441    {
     442        VERBOSE(VB_IMPORTANT, QString("Error from isBlocked : %1").arg(str));
     443        return true;
     444    }
     445    else if (str.isEmpty() || str.startsWith("\r\n"))
     446        return false;
     447    else
     448    {
     449        VERBOSE(VB_IMPORTANT, QString("Working isBlocked"));
     450        int nVal = MythPopupBox::showOkCancelPopup(gContext->GetMainWindow(),
     451                            QObject::tr("Icon is blocked"),
     452                            QObject::tr("This combination of channel and icon "
     453                                        "has been blocked by the MythTV "
     454                                        "admins. The most common reason for "
     455                                        "this is that there is a better match "
     456                                        "available.\n "
     457                                        "Are you still sure that you want to "
     458                                        "use this icon?"),
     459                          true);       
     460        if (nVal == 0)
     461            return false;
     462        else
     463            return true;
     464    }
     465}
     466
     467
     468bool ImportIconsWizard::lookup(const QString& strParam)
     469{
     470    QString strParam1 = "callsign="+strParam;
     471    QUrl::encode(strParam1);
     472    QUrl url(ImportIconsWizard::url+"/lookup");
     473
     474    QString str = wget(url,strParam1);
     475    if (str.isEmpty() || str.startsWith("Error",false))
     476    {
     477        VERBOSE(VB_IMPORTANT, QString("Error from lookup : %1").arg(str));
     478        return true;
     479    }
     480    else
     481    {
     482        VERBOSE(VB_IMPORTANT, QString("Working lookup : %1").arg(str));
     483        return false;
     484    }
     485}
     486
     487bool ImportIconsWizard::search(const QString& strParam)
     488{
     489    QString strParam1 = strParam;
     490    QUrl::encode(strParam1);
     491    QUrl url(ImportIconsWizard::url+"/search");
     492
     493    QString str = wget(url,"s="+strParam1);
     494   
     495    m_listSearch.clear();
     496    m_listIcons->clearSelections();
     497
     498    if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error",false))
     499    {
     500        VERBOSE(VB_IMPORTANT, QString("Error from search : %1").arg(str));
     501        return false;
     502    }
     503    else
     504    {
     505        VERBOSE(VB_IMPORTANT, QString("Working search : %1").arg(str));
     506        QStringList strSplit=QStringList::split("\n",str);
     507
     508        for (QStringList::iterator begin=strSplit.begin();
     509             begin!=strSplit.end();begin++)
     510        {
     511            if (*begin != "#" )
     512            {
     513                QStringList ret = extract_csv(*begin);
     514                VERBOSE(VB_IMPORTANT, QString(" search : %1 %2 %3").arg(ret[0]).arg(ret[1]).arg(ret[2]));
     515                SearchEntry entry;
     516                entry.strID=ret[0];
     517                entry.strName=ret[1];
     518                entry.strLogo=ret[2];
     519                m_listSearch.append(entry);
     520                m_listIcons->addSelection(entry.strName);
     521            }
     522        }
     523
     524        return true;
     525    }
     526}
     527
     528bool ImportIconsWizard::findmissing(const QString& strParam)
     529{
     530    QString strParam1 = strParam;
     531    QUrl::encode(strParam1);
     532    QUrl url(ImportIconsWizard::url+"/findmissing");
     533
     534    QString str = wget(url,"csv="+strParam1);
     535    VERBOSE(VB_IMPORTANT, QString("findmissing : strParam1 = %1. str = %2").arg(strParam1).arg(str));   
     536    if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error",false))
     537    {
     538        VERBOSE(VB_IMPORTANT, QString("Error from findmissing : %1").arg(str));
     539        return false;
     540    }
     541    else
     542    {
     543        VERBOSE(VB_IMPORTANT, QString("Working findmissing : %1").arg(str));
     544        QStringList strSplit=QStringList::split("\n",str);
     545        for (QStringList::iterator begin=strSplit.begin();
     546             begin!=strSplit.end();begin++)
     547        {
     548            if (*begin != "#" )
     549            {
     550                QStringList ret = extract_csv(*begin);
     551                VERBOSE(VB_IMPORTANT, QString(" findmissing : %1 %2 %3 %4 %5").arg(ret[0]).arg(ret[1]).arg(ret[2]).arg(ret[3]).arg(ret[4]));
     552                checkAndDownload(ret[4]);
     553            }
     554        }
     555        return true;
     556    }
     557}
     558
     559bool ImportIconsWizard::submit(const QString& strParam)
     560{
     561    QString strParam1 = strParam;
     562    QUrl::encode(strParam1);
     563    QUrl url(ImportIconsWizard::url+"/submit");
     564
     565    QString str = wget(url,"csv="+strParam1);
     566    if (str.isEmpty() || str.startsWith("#") || str.startsWith("Error",false))
     567    {
     568        VERBOSE(VB_IMPORTANT, QString("Error from submit : %1").arg(str));
     569        return false;
     570    }
     571    else
     572    {
     573        VERBOSE(VB_IMPORTANT, QString("Working submit : %1").arg(str));
     574        QStringList strSplit=QStringList::split("\n",str);
     575        unsigned atsc =0, dvb =0, callsign =0, tv =0, xmltvid=0;
     576        for (QStringList::iterator begin=strSplit.begin();
     577             begin!=strSplit.end();begin++)
     578        {
     579            if (*begin != "#" )
     580            {
     581                QStringList strSplit2=QStringList::split(":",*begin);
     582                QString s=strSplit2[0].stripWhiteSpace();
     583                if (s=="a")
     584                     atsc=strSplit2[1].toUInt();
     585                else if (s=="c")
     586                     callsign=strSplit2[1].toUInt();
     587                else if (s=="d")
     588                     dvb=strSplit2[1].toUInt();
     589                else if (s=="t")
     590                     tv=strSplit2[1].toUInt();
     591                else if (s=="x")
     592                     xmltvid=strSplit2[1].toUInt();
     593            }
     594        }
     595        VERBOSE(VB_IMPORTANT, QString("working submit : atsc=%1 callsign=%2 dvb=%3 tv=%4 xmltvid=%5").arg(atsc).arg(callsign).arg(dvb).arg(tv).arg(xmltvid));
     596        return true;
     597    }
     598}
     599
     600void ImportIconsWizard::cancelPressed()
     601{
     602    m_cancelled=true;
     603}