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

File 00-12-channeleditor-dialogs.patch, 16.9 KB (added by Matthew Wire <devel@…>, 11 years ago)
  • 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_iconWizardRunning = 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_iconWizardRunning)
     245            {
     246                iconWizard->Close();
     247                m_iconWizardRunning = false;
     248            }
     249            else
     250                handled = false;
     251        }
    241252        else
    242253            handled = false;
    243254    }
     
    399410    }
    400411}
    401412
    402 void ChannelEditor::deleteChannels(void)
     413void ChannelEditor::deleteChannelsMenu(void)
    403414{
    404     const QString currentLabel = m_sourceList->GetValue();
     415    QString chan_msg;
     416   
     417    if (!m_selectedChannelName.isEmpty())
     418    {
     419        chan_msg = tr("Are you sure you would like to delete channel %1?")
     420                       .arg(m_selectedChannelName);
     421    }
     422    else if (m_sourceFilter == FILTER_ALL)
     423    {
     424        chan_msg = tr("Are you sure you would like to delete ALL channels?");
     425    }
     426    else if (m_sourceFilter == FILTER_UNASSIGNED)
     427    {
     428        chan_msg = tr("Are you sure you would like to delete all unassigned channels?");
     429    }
     430    else
     431    {
     432        chan_msg = tr("Are you sure you would like to delete the channels on %1?")
     433                       .arg(m_sourceList->GetValue());
     434    }
    405435
    406     bool del_all = m_sourceFilter == FILTER_ALL;
    407     bool del_nul = m_sourceFilter == FILTER_UNASSIGNED;
     436    MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
     437    MythDialogBox *delChanMenu = new MythDialogBox(chan_msg, popupStack, "deletechannelsmenu");
     438    if (delChanMenu->Create())
     439    {
     440        delChanMenu->SetReturnEvent(this, "deletechannelsmenu");
     441 
     442        delChanMenu->AddButton(tr("Yes, delete the channel(s)"));
     443        delChanMenu->AddButton(tr("No, don't"));
     444 
     445        popupStack->AddScreen(delChanMenu);
     446    }
     447    else
     448        delete delChanMenu;
     449}
    408450
    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 
     451void ChannelEditor::deleteChannels(void)
     452{
    424453    MSqlQuery query(MSqlQuery::InitCon());
    425     if (del_all)
     454    if (!m_selectedChannelName.isEmpty())
    426455    {
     456        MythUIButtonListItem *item = m_channelList->GetItemCurrent();
     457        if (!item)
     458            return;
     459        m_id = item->GetData().toInt();
     460
     461        query.prepare("DELETE FROM channel WHERE chanid = :CHID ;");
     462        query.bindValue(":CHID", m_id);
     463    }
     464    else if (m_sourceFilter == FILTER_ALL)
     465    {
    427466        query.prepare("TRUNCATE TABLE channel");
    428467    }
    429     else if (del_nul)
     468    else if (m_sourceFilter == FILTER_UNASSIGNED)
    430469    {
    431470        query.prepare("SELECT sourceid "
    432471                      "FROM videosource "
     
    463502    if (!query.exec())
    464503        MythDB::DBError("ChannelEditor Delete Channels", query);
    465504
     505    m_selectedChannelName = "";
     506
    466507    fillList();
    467508}
    468509
     
    478519    fillList();
    479520}
    480521
    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 
    508522void ChannelEditor::menu()
    509523{
    510524    MythUIButtonListItem *item = m_channelList->GetItemCurrent();
     
    517531       edit(item);
    518532    else
    519533    {
     534        GetSelectedChannelName(m_id);
     535       
    520536        QString label = tr("Channel Options");
    521537
    522538        MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
     
    527543        {
    528544            menu->SetReturnEvent(this, "channelopts");
    529545
    530             menu->AddButton(tr("Edit"));
    531             menu->AddButton(tr("Delete"));
     546            menu->AddButton(tr("Edit channel %1").arg(m_selectedChannelName));
     547            menu->AddButton(tr("Delete channel %1").arg(m_selectedChannelName));
     548            menu->AddButton(tr("Download channel icon for %1").arg(m_selectedChannelName));
     549            QString filter = "";
     550            if (m_sourceFilter == FILTER_ALL)
     551                filter = "ALL";
     552            else if (m_sourceFilter == FILTER_UNASSIGNED)
     553                filter = "UNASSIGNED";
     554            else
     555                filter = m_sourceList->GetValue();
    532556
     557            menu->AddButton(tr("Rescan for missing channel icons"));
     558            menu->AddButton(tr("Download all channel icons"));
     559
     560            menu->AddButton(tr("Delete %1 channels").arg(filter));
     561
    533562            popupStack->AddScreen(menu);
    534563        }
    535564        else
     
    563592    fillList();
    564593}
    565594
    566 void ChannelEditor::channelIconImport(void)
     595void ChannelEditor::channelIconDownload(bool refresh, const QString &channelname)
    567596{
    568     if (m_channelList->GetCount() == 0)
     597    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
     598
     599    iconWizard = new ImportIconsWizard(mainStack, refresh, channelname);
     600    m_iconWizardRunning = true;
     601
     602    if (!iconWizard->Create())
    569603    {
    570         ShowOkPopup(tr("Add some channels first!"));
     604        m_iconWizardRunning = false;
     605        delete iconWizard;
     606    }
     607
     608    m_selectedChannelName = "";
     609}
     610
     611/**
     612 * \brief Get selected channel name from database.
     613*/
     614void ChannelEditor::GetSelectedChannelName(int chanid)
     615{
     616    if (chanid == 0)
     617    {   // If no channel selected
     618        m_selectedChannelName = "";
    571619        return;
    572620    }
    573621
    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
    580622    QString querystr = QString("SELECT channel.name FROM channel "
    581                                "WHERE chanid='%1'").arg(channelID);
    582     QString channelname;
     623                               "WHERE chanid='%1'").arg(chanid);
     624   
    583625    MSqlQuery query(MSqlQuery::InitCon());
    584626    query.prepare(querystr);
    585627
    586628    if (query.exec() && query.next())
    587629    {
    588         channelname = query.value(0).toString();
     630        m_selectedChannelName = query.value(0).toString();
    589631    }
    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;
    622632}
    623633
    624634void ChannelEditor::customEvent(QEvent *event)
     
    635645        {
    636646            switch (buttonnum)
    637647            {
    638                 case 0 :
     648                case 0 : // Edit Channel
    639649                    edit(m_channelList->GetItemCurrent());
    640650                    break;
    641                 case 1 :
    642                     del();
     651                case 1 : // Delete single channel
     652                    deleteChannelsMenu();
    643653                    break;
     654                case 2 : // Download specific icon
     655                    channelIconDownload(true, m_selectedChannelName);
     656                    break;
     657                case 3 : // Download missing icons
     658                    channelIconDownload(true, "");
     659                    break;
     660                case 4 : // Download all icons
     661                    channelIconDownload(false, "");
     662                    break;
     663                case 5 : // Delete channels from source
     664                    m_selectedChannelName = "";
     665                    deleteChannelsMenu();
     666                    break;
    644667            }
    645668        }
     669        else if (resultid == "deletechannelsmenu")
     670        {
     671            switch (buttonnum)
     672            {
     673                case 0 : // Confirm channel(s) delete
     674                    deleteChannels();
     675                    break;
     676                case 1 : // Cancel channel(s) deleteChannels
     677                    m_selectedChannelName = "";
     678                    break;
     679            }
     680        }
    646681    }
    647682}
  • 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_iconWizardRunning;
     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())
     
    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
  • 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>