Ticket #12: 00-12-channeleditor-dialogs.2.patch

File 00-12-channeleditor-dialogs.2.patch, 20.0 KB (added by Matthew Wire <devel@…>, 11 years ago)

Fixes single icon download. Fixes showing of search dialog.

  • mythtv/themes/default/config-ui.xml

     
    124124            <position>210,430</position>
    125125        </buttonlist>
    126126
    127         <button name="delete" from="basebutton">
    128             <position>620,427</position>
    129             <value>Delete</value>
    130         </button>
    131 
    132127        <textarea name="nochannumlabel" from="basetextarea">
    133128            <area>70,496,500,60</area>
    134129            <value>Hide Channels without channel number.</value>
     
    143138            <value>Channel Scan</value>
    144139        </button>
    145140
    146         <button name="importicons" from="basewidebutton">
    147             <position>325,540</position>
    148             <value>Icon Download</value>
    149         </button>
    150 
    151141        <button name="edittransport" from="basewidebutton">
    152142            <position>585,540</position>
    153143            <value>Edit Transports</value>
  • mythtv/programs/mythtv-setup/channeleditor.cpp

     
    2323#include "sourceutil.h"
    2424
    2525#include "scanwizard.h"
    26 #include "importicons.h"
    2726
    2827ChannelWizard::ChannelWizard(int id, int default_sourceid)
    2928    : ConfigurationWizard()
     
    121120    m_currentSortMode = tr("Channel Name");
    122121    m_sourceFilter = FILTER_ALL; // All
    123122    m_currentHideMode = false;
     123    m_selectedChannelName = "";
     124    m_dialogIsRunning = false;
     125
    124126}
    125127
    126128bool ChannelEditor::Create()
     
    137139    m_sourceList = dynamic_cast<MythUIButtonList *>(GetChild("source"));
    138140    m_channelList = dynamic_cast<MythUIButtonList *>(GetChild("channels"));
    139141
    140     MythUIButton *deleteButton = dynamic_cast<MythUIButton *>(GetChild("delete"));
    141142    MythUIButton *scanButton = dynamic_cast<MythUIButton *>(GetChild("scan"));
    142     MythUIButton *importIconButton = dynamic_cast<MythUIButton *>(GetChild("importicons"));
    143143    MythUIButton *transportEditorButton = dynamic_cast<MythUIButton *>(GetChild("edittransport"));
    144144
    145145    MythUICheckBox *hideCheck = dynamic_cast<MythUICheckBox *>(GetChild("nochannum"));
    146146
    147     if (!sortList || !m_sourceList || !m_channelList || !deleteButton ||
    148         !scanButton || !importIconButton || !transportEditorButton ||
    149         !hideCheck)
     147    if (!sortList || !m_sourceList || !m_channelList || !scanButton ||
     148        !transportEditorButton || !hideCheck)
    150149    {
    151150
    152151        return false;
    153152    }
    154153
    155     // Delete button help text
    156     deleteButton->SetHelpText(tr("Delete all channels on currently selected source(s)."));
    157 
    158154    // Sort List
    159155    new MythUIButtonListItem(sortList, tr("Channel Name"));
    160156    new MythUIButtonListItem(sortList, tr("Channel Number"));
     
    190186    scanButton->SetHelpText(tr("Starts the channel scanner."));
    191187    scanButton->SetEnabled(SourceUtil::IsAnySourceScanable());
    192188
    193     // Import Icons Button
    194     importIconButton->SetHelpText(tr("Starts the icon downloader"));
    195     importIconButton->SetEnabled(SourceUtil::IsAnySourceScanable());
    196     connect(importIconButton,  SIGNAL(Clicked()), SLOT(channelIconImport()));
    197 
    198189    // Transport Editor Button
    199190    transportEditorButton->SetHelpText(
    200191        tr("Allows you to edit the transports directly. "
     
    207198    connect(m_channelList, SIGNAL(itemClicked(MythUIButtonListItem *)),
    208199            SLOT(edit(MythUIButtonListItem *)));
    209200    connect(scanButton, SIGNAL(Clicked()), SLOT(scan()));
    210     connect(deleteButton,  SIGNAL(Clicked()), SLOT(deleteChannels()));
    211201
    212202    fillList();
    213203
     
    236226        }
    237227        else if (action == "DELETE")
    238228        {
    239             del();
     229            int channelID = 0;
     230            MythUIButtonListItem *item = m_channelList->GetItemCurrent();
     231            if (item)
     232                channelID = item->GetData().toInt();
     233
     234            if (channelID > 0)
     235            {
     236                GetSelectedChannelName(channelID);
     237                deleteChannelsMenu();           
     238            }
     239            else
     240                handled = true;
    240241        }
     242        else if (action == "ESCAPE")
     243        {
     244            if (m_dialogIsRunning)
     245            {
     246                iconWizard->Cancel();
     247                m_dialogIsRunning = false;
     248            }
     249            else
     250                handled = false;
     251        }
    241252        else
    242253            handled = false;
    243254    }
     
    250261
    251262void ChannelEditor::fillList(void)
    252263{
     264    m_dialogIsRunning = false;
    253265    QString currentValue = m_channelList->GetValue();
    254266    uint    currentIndex = qMax(m_channelList->GetCurrentPos(), 0);
    255267    m_channelList->Reset();
     
    399411    }
    400412}
    401413
    402 void ChannelEditor::deleteChannels(void)
     414void ChannelEditor::deleteChannelsMenu(void)
    403415{
    404     const QString currentLabel = m_sourceList->GetValue();
     416    QString chan_msg;
     417   
     418    if (!m_selectedChannelName.isEmpty())
     419    {
     420        chan_msg = tr("Are you sure you would like to delete channel %1?")
     421                       .arg(m_selectedChannelName);
     422    }
     423    else if (m_sourceFilter == FILTER_ALL)
     424    {
     425        chan_msg = tr("Are you sure you would like to delete ALL channels?");
     426    }
     427    else if (m_sourceFilter == FILTER_UNASSIGNED)
     428    {
     429        chan_msg = tr("Are you sure you would like to delete all unassigned channels?");
     430    }
     431    else
     432    {
     433        chan_msg = tr("Are you sure you would like to delete the channels on %1?")
     434                       .arg(m_sourceList->GetValue());
     435    }
    405436
    406     bool del_all = m_sourceFilter == FILTER_ALL;
    407     bool del_nul = m_sourceFilter == FILTER_UNASSIGNED;
     437    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
     438    MythDialogBox *delChanMenu = new MythDialogBox(chan_msg, popupStack, "deletechannelsmenu");
     439    if (delChanMenu->Create())
     440    {
     441        delChanMenu->SetReturnEvent(this, "deletechannelsmenu");
     442 
     443        delChanMenu->AddButton(tr("Yes, delete the channel(s)"));
     444        delChanMenu->AddButton(tr("No, don't"));
     445 
     446        popupStack->AddScreen(delChanMenu);
     447    }
     448    else
     449        delete delChanMenu;
     450}
    408451
    409     QString chan_msg =
    410         (del_all) ? tr("Are you sure you would like to delete ALL channels?") :
    411         ((del_nul) ?
    412          tr("Are you sure you would like to delete all unassigned channels?") :
    413          tr("Are you sure you would like to delete the channels on %1?")
    414          .arg(currentLabel));
    415 
    416     DialogCode val = MythPopupBox::Show2ButtonPopup(
    417         gContext->GetMainWindow(), "", chan_msg,
    418         tr("Yes, delete the channels"),
    419         tr("No, don't"), kDialogCodeButton1);
    420 
    421     if (kDialogCodeButton0 != val)
    422         return;
    423 
     452void ChannelEditor::deleteChannels(void)
     453{
    424454    MSqlQuery query(MSqlQuery::InitCon());
    425     if (del_all)
     455    if (!m_selectedChannelName.isEmpty())
    426456    {
     457        MythUIButtonListItem *item = m_channelList->GetItemCurrent();
     458        if (!item)
     459            return;
     460        m_id = item->GetData().toInt();
     461
     462        query.prepare("DELETE FROM channel WHERE chanid = :CHID ;");
     463        query.bindValue(":CHID", m_id);
     464    }
     465    else if (m_sourceFilter == FILTER_ALL)
     466    {
    427467        query.prepare("TRUNCATE TABLE channel");
    428468    }
    429     else if (del_nul)
     469    else if (m_sourceFilter == FILTER_UNASSIGNED)
    430470    {
    431471        query.prepare("SELECT sourceid "
    432472                      "FROM videosource "
     
    463503    if (!query.exec())
    464504        MythDB::DBError("ChannelEditor Delete Channels", query);
    465505
     506    m_selectedChannelName = "";
     507
    466508    fillList();
    467509}
    468510
     
    478520    fillList();
    479521}
    480522
    481 void ChannelEditor::del()
    482 {
    483     MythUIButtonListItem *item = m_channelList->GetItemCurrent();
    484 
    485     if (!item)
    486         return;
    487 
    488     m_id = item->GetData().toInt();
    489 
    490     DialogCode val = MythPopupBox::Show2ButtonPopup(
    491         gContext->GetMainWindow(),
    492         "", tr("Are you sure you would like to delete this channel?"),
    493         tr("Yes, delete the channel"),
    494         tr("No, don't"), kDialogCodeButton1);
    495 
    496     if (kDialogCodeButton0 == val)
    497     {
    498         MSqlQuery query(MSqlQuery::InitCon());
    499         query.prepare("DELETE FROM channel WHERE chanid = :CHID ;");
    500         query.bindValue(":CHID", m_id);
    501         if (!query.exec() || !query.isActive())
    502             MythDB::DBError("ChannelEditor Delete Channel", query);
    503 
    504         fillList();
    505     }
    506 }
    507 
    508523void ChannelEditor::menu()
    509524{
    510525    MythUIButtonListItem *item = m_channelList->GetItemCurrent();
     
    517532       edit(item);
    518533    else
    519534    {
     535        GetSelectedChannelName(m_id);
     536       
    520537        QString label = tr("Channel Options");
    521538
    522539        MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
     
    527544        {
    528545            menu->SetReturnEvent(this, "channelopts");
    529546
    530             menu->AddButton(tr("Edit"));
    531             menu->AddButton(tr("Delete"));
     547            menu->AddButton(tr("Edit channel %1").arg(m_selectedChannelName));
     548            menu->AddButton(tr("Delete channel %1").arg(m_selectedChannelName));
     549            menu->AddButton(tr("Download channel icon for %1").arg(m_selectedChannelName));
     550            QString filter = "";
     551            if (m_sourceFilter == FILTER_ALL)
     552                filter = "ALL";
     553            else if (m_sourceFilter == FILTER_UNASSIGNED)
     554                filter = "UNASSIGNED";
     555            else
     556                filter = m_sourceList->GetValue();
    532557
     558            menu->AddButton(tr("Rescan for missing channel icons"));
     559            menu->AddButton(tr("Download all channel icons"));
     560
     561            menu->AddButton(tr("Delete %1 channels").arg(filter));
     562
    533563            popupStack->AddScreen(menu);
    534564        }
    535565        else
     
    556586
    557587void ChannelEditor::transportEditor(void)
    558588{
    559     TransportListEditor *editor = new TransportListEditor(m_sourceFilter);
    560     editor->exec();
    561     editor->deleteLater();
     589    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
    562590
     591    TransportListEditor *transportedit = new TransportListEditor(mainStack, m_sourceFilter);
     592
     593    if (transportedit->Create())
     594        mainStack->AddScreen(transportedit);
     595    else
     596        delete transportedit;
     597
    563598    fillList();
    564599}
    565600
    566 void ChannelEditor::channelIconImport(void)
     601void ChannelEditor::channelIconDownload(bool refresh, const QString &channelname)
    567602{
    568     if (m_channelList->GetCount() == 0)
     603    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
     604
     605    iconWizard = new ImportIconsWizard(mainStack, refresh, channelname);
     606
     607    if (iconWizard->Create())
    569608    {
    570         ShowOkPopup(tr("Add some channels first!"));
     609        m_dialogIsRunning = true;
     610        connect(iconWizard, SIGNAL(Exiting()), SLOT(fillList()));
     611        iconWizard->Run();
     612    }
     613    else
     614        delete iconWizard;
     615
     616    m_selectedChannelName = "";
     617}
     618
     619/**
     620 * \brief Get selected channel name from database.
     621*/
     622void ChannelEditor::GetSelectedChannelName(int chanid)
     623{
     624    if (chanid == 0)
     625    {   // If no channel selected
     626        m_selectedChannelName = "";
    571627        return;
    572628    }
    573629
    574     int channelID = 0;
    575     MythUIButtonListItem *item = m_channelList->GetItemCurrent();
    576     if (item)
    577         channelID = item->GetData().toInt();
    578 
    579     // Get selected channel name from database
    580630    QString querystr = QString("SELECT channel.name FROM channel "
    581                                "WHERE chanid='%1'").arg(channelID);
    582     QString channelname;
     631                               "WHERE chanid='%1'").arg(chanid);
     632   
    583633    MSqlQuery query(MSqlQuery::InitCon());
    584634    query.prepare(querystr);
    585635
    586636    if (query.exec() && query.next())
    587637    {
    588         channelname = query.value(0).toString();
     638        m_selectedChannelName = query.value(0).toString();
    589639    }
    590 
    591     QStringList buttons;
    592     buttons.append(tr("Cancel"));
    593     buttons.append(tr("Download all icons.."));
    594     buttons.append(tr("Rescan for missing icons.."));
    595     if (!channelname.isEmpty())
    596         buttons.append(tr("Download icon for ") + channelname);
    597 
    598     int val = MythPopupBox::ShowButtonPopup(gContext->GetMainWindow(),
    599                                              "", "Channel Icon Import", buttons, kDialogCodeButton2);
    600 
    601     MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
    602 
    603     ImportIconsWizard *iconwizard;
    604     if (val == kDialogCodeButton0) // Cancel pressed
    605         return;
    606     else if (val == kDialogCodeButton1) // Import all icons pressed
    607         iconwizard = new ImportIconsWizard(mainStack, false);
    608     else if (val == kDialogCodeButton2) // Rescan for missing pressed
    609         iconwizard = new ImportIconsWizard(mainStack, true);
    610     else if (val == kDialogCodeButton3) // Import a single channel icon
    611         iconwizard = new ImportIconsWizard(mainStack, true, channelname);
    612     else
    613         return;
    614 
    615     if (iconwizard->Create())
    616     {
    617         connect(iconwizard, SIGNAL(Exiting()), SLOT(fillList()));
    618         mainStack->AddScreen(iconwizard);
    619     }
    620     else
    621         delete iconwizard;
    622640}
    623641
    624642void ChannelEditor::customEvent(QEvent *event)
     
    635653        {
    636654            switch (buttonnum)
    637655            {
    638                 case 0 :
     656                case 0 : // Edit Channel
    639657                    edit(m_channelList->GetItemCurrent());
    640658                    break;
    641                 case 1 :
    642                     del();
     659                case 1 : // Delete single channel
     660                    deleteChannelsMenu();
    643661                    break;
     662                case 2 : // Download specific icon
     663                    channelIconDownload(false, m_selectedChannelName);
     664                    break;
     665                case 3 : // Download missing icons
     666                    channelIconDownload(true, "");
     667                    break;
     668                case 4 : // Download all icons
     669                    channelIconDownload(false, "");
     670                    break;
     671                case 5 : // Delete channels from source
     672                    m_selectedChannelName = "";
     673                    deleteChannelsMenu();
     674                    break;
    644675            }
    645676        }
     677        else if (resultid == "deletechannelsmenu")
     678        {
     679            switch (buttonnum)
     680            {
     681                case 0 : // Confirm channel(s) delete
     682                    deleteChannels();
     683                    break;
     684                case 1 : // Cancel channel(s) deleteChannels
     685                    m_selectedChannelName = "";
     686                    break;
     687            }
     688        }
    646689    }
    647690}
  • mythtv/programs/mythtv-setup/channeleditor.h

     
    44#include "mythscreentype.h"
    55
    66#include "settings.h"
     7#include "importicons.h"
    78
    89class MythUIButton;
    910class MythUIButtonList;
     
    2223
    2324  protected slots:
    2425    void menu();
    25     void del();
    2626    void edit(MythUIButtonListItem *item);
    2727    void scan(void);
    2828    void transportEditor(void);
    29     void channelIconImport(void);
     29    void channelIconDownload(bool refresh, const QString &channelname);
     30    void GetSelectedChannelName(int chanid);
     31    void deleteChannelsMenu(void);
    3032    void deleteChannels(void);
    3133    void setSortMode(MythUIButtonListItem *item);
    3234    void setSourceID(MythUIButtonListItem *item);
     
    4749
    4850    MythUIButtonList *m_channelList;
    4951    MythUIButtonList *m_sourceList;
     52
     53    bool m_dialogIsRunning;
     54    QString m_selectedChannelName;
     55    ImportIconsWizard *iconWizard;
    5056};
    5157
    5258class ChannelID;
  • mythtv/programs/mythtv-setup/importicons.cpp

     
    3535    m_popupStack = GetMythMainWindow()->GetStack("popup stack");
    3636    m_progressDialog = NULL;
    3737
     38    m_closeDialog = false;
     39
    3840    m_tmpDir = QDir(QString("%1/icontmp").arg(GetConfDir()));
    3941
    4042    if (!m_tmpDir.exists())
     
    9294    connect(m_iconsList, SIGNAL(itemClicked(MythUIButtonListItem *)),
    9395            SLOT(menuSelection(MythUIButtonListItem *)));
    9496
    95     if (!initialLoad(m_strChannelname))
    96         return false;
    97 
    9897    BuildFocusList();
    9998
    10099    enableControls(STATE_NORMAL);
     
    150149    m_missingIter++;
    151150
    152151    if (!doLoad())
    153         Close();
     152        return;
    154153}
    155154
    156155void ImportIconsWizard::menuSelection(MythUIButtonListItem *item)
     
    197196        m_missingCount++;
    198197        m_missingIter++;
    199198        if (!doLoad())
    200             Close();
     199            return;
    201200    }
    202201    else
    203202    {
     
    207206        if (!m_strMatches.isEmpty())
    208207            askSubmit(m_strMatches);
    209208        else
    210             Close();
     209            return;
    211210    }
    212 
    213211}
    214212
    215 bool ImportIconsWizard::initialLoad(QString name)
     213void ImportIconsWizard::Run(void)
    216214{
    217215    QString dirpath = GetConfDir();
    218216    QDir configDir(dirpath);
     
    230228    }
    231229    m_strChannelDir += "/";
    232230
    233     bool closeDialog = false;
    234 
    235231    QString querystring("SELECT chanid, name, xmltvid, callsign,"
    236232                        "dtv_multiplex.transportid, atsc_major_chan, "
    237233                        "atsc_minor_chan, dtv_multiplex.networkid, "
     
    240236                        "FROM channel LEFT JOIN dtv_multiplex "
    241237                        "ON channel.mplexid = dtv_multiplex.mplexid "
    242238                        "WHERE ");
    243     if (!name.isEmpty())
    244         querystring.append("name=\"" + name + "\"");
     239    if (!m_strChannelname.isEmpty())
     240        querystring.append("name=\"" + m_strChannelname + "\"");
    245241    else
    246242        querystring.append("channel.visible");
    247243    querystring.append(" ORDER BY name");
     
    332328        m_progressDialog = NULL;
    333329    }
    334330
    335     while (!closeDialog && (m_iter != m_listEntries.end()))
     331    while (!m_closeDialog && (m_iter != m_listEntries.end()))
    336332    {
    337333        QString message = QString("Downloading %1 / %2 : ").arg(m_nCount+1)
    338334            .arg(m_listEntries.size()) + (*m_iter).strName;
     
    360356        m_progressDialog = NULL;
    361357    }
    362358
    363     if (m_missingEntries.size() == 0 || closeDialog)
    364         return false;
     359    if (m_missingEntries.size() == 0 || m_closeDialog)
     360    {
     361        Close();
     362        return;
     363    }
    365364
    366365    if (m_nMaxCount > 0)
    367366    {
    368367        m_missingIter = m_missingEntries.begin();
     368   
     369        MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
     370        mainStack->AddScreen(this);
     371
    369372        if (!doLoad())
    370             return false;
     373            return;
    371374    }
    372     else
    373         return false;
    374 
    375     return true;
    376375}
    377376
    378377bool ImportIconsWizard::doLoad()
     
    386385        enableControls(STATE_DISABLED);
    387386        if (!m_strMatches.isEmpty())
    388387            askSubmit(m_strMatches);
     388        Close();
    389389        return false;
    390390    }
    391391    else
     
    720720    }
    721721}
    722722
     723void ImportIconsWizard::Cancel()
     724{
     725    m_closeDialog = true;
     726}
     727
    723728void ImportIconsWizard::customEvent(QEvent *event)
    724729{
    725730    if (event->type() == kMythDialogBoxCompletionEventType)
  • mythtv/programs/mythtv-setup/importicons.h

     
    3737   ~ImportIconsWizard();
    3838
    3939    bool Create(void);
     40    void Run(void);
    4041//    bool keyPressEvent(QKeyEvent *);
    4142    void customEvent(QEvent *event);
     43    void Cancel(void);
    4244
    4345    struct SearchEntry               //! search entry results
    4446    {
     
    135137     */
    136138    bool checkAndDownload(const QString& url, const QString& localChanId);
    137139
    138     /*! \brief attempt the inital load of the TV channel information
    139      * \return true if successful
    140      */
    141     bool initialLoad(QString name="");
    142 
    143140    /*! \brief attempts to move the iteration on one/more than one
    144141     * \return true if we can go again or false if we can not
    145142     */
     
    171168
    172169    void startDialog();
    173170
     171    bool m_closeDialog;         //!< Set to true when we want dialog to close
     172
    174173    MythScreenStack    *m_popupStack;
    175174    MythUIProgressDialog *m_progressDialog;
    176175