Ticket #12: 00-channeleditor-dialogs.patch

File 00-channeleditor-dialogs.patch, 10.2 KB (added by Matthew Wire <devel@…>, 3 years ago)

Convert deletechannels menu, importicons menu and allow cancel of icon import process

  • 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_currentChannelName = ""; 
     124    m_iconWizardRunning = false; 
     125 
    124126} 
    125127 
    126128bool ChannelEditor::Create() 
     
    207209    connect(m_channelList, SIGNAL(itemClicked(MythUIButtonListItem *)), 
    208210            SLOT(edit(MythUIButtonListItem *))); 
    209211    connect(scanButton, SIGNAL(Clicked()), SLOT(scan())); 
    210     connect(deleteButton,  SIGNAL(Clicked()), SLOT(deleteChannels())); 
     212    connect(deleteButton,  SIGNAL(Clicked()), SLOT(deleteChannelsMenu())); 
    211213 
    212214    fillList(); 
    213215 
     
    238240        { 
    239241            del(); 
    240242        } 
     243        else if (action == "ESCAPE") 
     244        { 
     245            if (m_iconWizardRunning) 
     246            { 
     247                iconWizard->Close(); 
     248                m_iconWizardRunning = false; 
     249            } 
     250            else 
     251                handled = false; 
     252        } 
    241253        else 
    242254            handled = false; 
    243255    } 
     
    374386    } 
    375387} 
    376388 
    377 void ChannelEditor::deleteChannels(void) 
     389void ChannelEditor::deleteChannelsMenu(void) 
    378390{ 
    379     const QString currentLabel = m_sourceList->GetValue(); 
     391    QString chan_msg; 
     392     
     393    if (m_sourceFilter == FILTER_ALL) 
     394    { 
     395        chan_msg = tr("Are you sure you would like to delete ALL channels?"); 
     396    } 
     397    else if (m_sourceFilter == FILTER_UNASSIGNED) 
     398    { 
     399        chan_msg = tr("Are you sure you would like to delete all unassigned channels?"); 
     400    } 
     401    else 
     402    { 
     403        chan_msg = tr("Are you sure you would like to delete the channels on %1?") 
     404                       .arg(m_sourceList->GetValue()); 
     405    } 
    380406 
    381     bool del_all = m_sourceFilter == FILTER_ALL; 
    382     bool del_nul = m_sourceFilter == FILTER_UNASSIGNED; 
     407    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 
     408    MythDialogBox *delChanMenu = new MythDialogBox(chan_msg, popupStack, "deletechannelsmenu"); 
     409    if (delChanMenu->Create()) 
     410    { 
     411        delChanMenu->SetReturnEvent(this, "deletechannelsmenu"); 
     412  
     413        delChanMenu->AddButton(tr("Yes, delete the channels")); 
     414        delChanMenu->AddButton(tr("No, don't")); 
     415  
     416        popupStack->AddScreen(delChanMenu); 
     417    } 
     418    else 
     419        delete delChanMenu; 
     420} 
    383421 
    384     QString chan_msg = 
    385         (del_all) ? tr("Are you sure you would like to delete ALL channels?") : 
    386         ((del_nul) ? 
    387          tr("Are you sure you would like to delete all unassigned channels?") : 
    388          tr("Are you sure you would like to delete the channels on %1?") 
    389          .arg(currentLabel)); 
    390  
    391     DialogCode val = MythPopupBox::Show2ButtonPopup( 
    392         gContext->GetMainWindow(), "", chan_msg, 
    393         tr("Yes, delete the channels"), 
    394         tr("No, don't"), kDialogCodeButton1); 
    395  
    396     if (kDialogCodeButton0 != val) 
    397         return; 
    398  
     422void ChannelEditor::deleteChannels(void) 
     423{ 
    399424    MSqlQuery query(MSqlQuery::InitCon()); 
    400     if (del_all) 
     425    if (m_sourceFilter == FILTER_ALL) 
    401426    { 
    402427        query.prepare("TRUNCATE TABLE channel"); 
    403428    } 
    404     else if (del_nul) 
     429    else if (m_sourceFilter == FILTER_UNASSIGNED) 
    405430    { 
    406431        query.prepare("SELECT sourceid " 
    407432                      "FROM videosource " 
     
    554579    // Get selected channel name from database 
    555580    QString querystr = QString("SELECT channel.name FROM channel " 
    556581                               "WHERE chanid='%1'").arg(channelID); 
    557     QString channelname; 
     582     
    558583    MSqlQuery query(MSqlQuery::InitCon()); 
    559584    query.prepare(querystr); 
    560585 
    561586    if (query.exec() && query.next()) 
    562587    { 
    563         channelname = query.value(0).toString(); 
     588        m_currentChannelName = query.value(0).toString(); 
    564589    } 
    565590 
    566     QStringList buttons; 
    567     buttons.append(tr("Cancel")); 
    568     buttons.append(tr("Download all icons..")); 
    569     buttons.append(tr("Rescan for missing icons..")); 
    570     if (!channelname.isEmpty()) 
    571         buttons.append(tr("Download icon for ") + channelname); 
     591    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 
     592  
     593    MythDialogBox *menuChanIcon = new MythDialogBox("Download Channel Icons", popupStack, "actionmenu"); 
     594  
     595    if (menuChanIcon->Create()) 
     596        popupStack->AddScreen(menuChanIcon); 
    572597 
    573     int val = MythPopupBox::ShowButtonPopup(gContext->GetMainWindow(), 
    574                                              "", "Channel Icon Import", buttons, kDialogCodeButton2); 
     598    menuChanIcon->SetReturnEvent(this, "channelicons"); 
    575599 
     600    menuChanIcon->AddButton(tr("Cancel")); 
     601    menuChanIcon->AddButton(tr("Download all icons..")); 
     602    menuChanIcon->AddButton(tr("Rescan for missing icons..")); 
     603    if (!m_currentChannelName.isEmpty()) 
     604        menuChanIcon->AddButton(tr("Download icon for ") + m_currentChannelName); 
     605} 
     606 
     607void ChannelEditor::channelIconDownload(bool refresh, const QString &channelname) 
     608{ 
    576609    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); 
    577610 
    578     ImportIconsWizard *iconwizard; 
    579     if (val == kDialogCodeButton0) // Cancel pressed 
    580         return; 
    581     else if (val == kDialogCodeButton1) // Import all icons pressed 
    582         iconwizard = new ImportIconsWizard(mainStack, false); 
    583     else if (val == kDialogCodeButton2) // Rescan for missing pressed 
    584         iconwizard = new ImportIconsWizard(mainStack, true); 
    585     else if (val == kDialogCodeButton3) // Import a single channel icon 
    586         iconwizard = new ImportIconsWizard(mainStack, true, channelname); 
    587     else 
    588         return; 
     611    iconWizard = new ImportIconsWizard(mainStack, refresh, channelname); 
     612    m_iconWizardRunning = true; 
    589613 
    590     if (iconwizard->Create()) 
     614    if (!iconWizard->Create()) 
    591615    { 
    592         connect(iconwizard, SIGNAL(Exiting()), SLOT(fillList())); 
    593         mainStack->AddScreen(iconwizard); 
     616        m_iconWizardRunning = false; 
     617        delete iconWizard; 
    594618    } 
    595     else 
    596         delete iconwizard; 
     619 
     620    m_currentChannelName = ""; 
    597621} 
    598622 
    599623void ChannelEditor::customEvent(QEvent *event) 
     
    618642                    break; 
    619643            } 
    620644        } 
     645        else if (resultid == "deletechannelsmenu" && buttonnum == 0) 
     646        { 
     647            deleteChannels(); 
     648        } 
     649        else if (resultid == "channelicons") 
     650        { 
     651            switch (buttonnum) 
     652            { 
     653                case 0 : // Cancel 
     654                    break; 
     655                case 1 : // Download all icons 
     656                    channelIconDownload(false, ""); 
     657                    break; 
     658                case 2 : // Download missing icons 
     659                    channelIconDownload(true, ""); 
     660                    break; 
     661                case 3 : // Download specific icon 
     662                    channelIconDownload(true, m_currentChannelName); 
     663                    break; 
     664            } 
     665        } 
    621666    } 
    622667} 
  • mythtv/programs/mythtv-setup/channeleditor.h

     
    44#include "mythscreentype.h" 
    55 
    66#include "settings.h" 
     7#include "importicons.h" 
    78 
    89class MythUIButton; 
    910class MythUIButtonList; 
     
    2728    void scan(void); 
    2829    void transportEditor(void); 
    2930    void channelIconImport(void); 
     31    void channelIconDownload(bool refresh, const QString &channelname); 
     32    void deleteChannelsMenu(void); 
    3033    void deleteChannels(void); 
    3134    void setSortMode(MythUIButtonListItem *item); 
    3235    void setSourceID(MythUIButtonListItem *item); 
     
    4750 
    4851    MythUIButtonList *m_channelList; 
    4952    MythUIButtonList *m_sourceList; 
     53 
     54    bool m_iconWizardRunning; 
     55    QString m_currentChannelName; 
     56    ImportIconsWizard *iconWizard; 
    5057}; 
    5158 
    5259class 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()) 
     
    230232    } 
    231233    m_strChannelDir += "/"; 
    232234 
    233     bool closeDialog = false; 
    234  
    235235    QString querystring("SELECT chanid, name, xmltvid, callsign," 
    236236                        "dtv_multiplex.transportid, atsc_major_chan, " 
    237237                        "atsc_minor_chan, dtv_multiplex.networkid, " 
     
    332332        m_progressDialog = NULL; 
    333333    } 
    334334 
    335     while (!closeDialog && (m_iter != m_listEntries.end())) 
     335    while (!m_closeDialog && (m_iter != m_listEntries.end())) 
    336336    { 
    337337        QString message = QString("Downloading %1 / %2 : ").arg(m_nCount+1) 
    338338            .arg(m_listEntries.size()) + (*m_iter).strName; 
     
    360360        m_progressDialog = NULL; 
    361361    } 
    362362 
    363     if (m_missingEntries.size() == 0 || closeDialog) 
     363    if (m_missingEntries.size() == 0 || m_closeDialog) 
    364364        return false; 
    365365 
    366366    if (m_nMaxCount > 0) 
     
    720720    } 
    721721} 
    722722 
     723void ImportIconsWizard::Close() 
     724{ 
     725    m_closeDialog = true; 
     726} 
     727 
    723728void ImportIconsWizard::customEvent(QEvent *event) 
    724729{ 
    725730    if (event->type() == kMythDialogBoxCompletionEventType) 
  • mythtv/programs/mythtv-setup/importicons.h

     
    3939    bool Create(void); 
    4040//    bool keyPressEvent(QKeyEvent *); 
    4141    void customEvent(QEvent *event); 
     42    void Close(void); 
    4243 
    4344    struct SearchEntry               //! search entry results 
    4445    { 
     
    171172 
    172173    void startDialog(); 
    173174 
     175    bool m_closeDialog;         //!< Set to true when we want dialog to close 
     176 
    174177    MythScreenStack    *m_popupStack; 
    175178    MythUIProgressDialog *m_progressDialog; 
    176179