Ticket #1921: 1921-v1.patch

File 1921-v1.patch, 7.9 KB (added by danielk, 19 years ago)

Possible fix

  • mythgallery/mythgallery/iconview.cpp

     
    132132                SLOT(mediaStatusChanged(MediaStatus, MythMediaDevice*)));
    133133
    134134        loadDirectory(m_currDevice->getMountPath());
    135         m_galleryDir = m_currDevice->getMountPath();
    136135
    137136        mon->Unlock(m_currDevice);
    138137    }
     
    315314           &pix, 0, 0, -1, -1, Qt::CopyROP);
    316315}
    317316
     317static bool has_action(QString action, const QStringList &actions)
     318{
     319    QStringList::const_iterator it;
     320    for (it = actions.begin(); it != actions.end(); ++it)
     321    {
     322        if (action == *it)
     323            return true;
     324    }
     325    return false;
     326}
     327
    318328void IconView::keyPressEvent(QKeyEvent *e)
    319329{
    320330    if (!e) return;
     
    564574    if (!handled && !menuHandled)
    565575    {
    566576        gContext->GetMainWindow()->TranslateKeyPress("Global", e, actions);
    567         for (unsigned int i = 0; i < actions.size() && !handled; i++)
     577        if (has_action("ESCAPE", actions))
     578            handled = HandleEscape();
     579    }
     580
     581    if (handled || menuHandled)
     582        update();
     583    else
     584        MythDialog::keyPressEvent(e);
     585}
     586
     587bool IconView::HandleEscape(void)
     588{
     589    //VERBOSE(VB_IMPORTANT, "ESCAPE: showDevices("<<m_showDevices<<")");
     590
     591    if (m_showDevices)
     592        return false;
     593
     594    MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
     595    if (!mon)
     596        return false;
     597
     598    bool handled = false;
     599    QDir curdir(m_currDir);
     600    QValueList<MythMediaDevice*> removables = mon->GetMedias(MEDIATYPE_DATA);
     601    QValueList<MythMediaDevice*>::iterator it = removables.begin();
     602    for (; !handled && (it != removables.end()); it++)
     603    {
     604        if (!mon->ValidateAndLock(*it))
     605            continue;
     606
     607        if (curdir == QDir((*it)->getMountPath()))
    568608        {
    569             QString action = actions[i];
    570             if (action == "ESCAPE")
     609            actionShowDevices();
     610
     611            // Make sure previous devices are visible and selected
     612            ThumbItem *item = NULL;
     613            if (!(*it)->getVolumeID().isEmpty())
     614                item = m_itemDict.find((*it)->getVolumeID());
     615            else
     616                item = m_itemDict.find((*it)->getDevicePath());
     617
     618            if (item)
    571619            {
    572                 if (m_showDevices)
     620                int pos = m_itemList.find(item);
     621                if (pos != -1)
    573622                {
    574                     loadDirectory(m_galleryDir);
    575                     handled = true;
     623                    m_currRow = pos / m_nCols;
     624                    m_currCol = pos - (m_currRow * m_nCols);
     625                    m_topRow  = max(0, m_currRow + 1 - m_nRows);
    576626                }
    577                 else
    578                 {
    579                     QDir d(m_currDir);
     627            }
    580628
    581 #ifndef _WIN32
    582                     MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
    583                     if (mon)
    584                     {
    585                         QValueList<MythMediaDevice*> removables =
    586                             mon->GetMedias(MEDIATYPE_DATA);
    587                    
    588                         QValueList<MythMediaDevice*>::Iterator it =
    589                             removables.begin();
    590                         for (; it != removables.end(); it++)
    591                         {
    592                             if (mon->ValidateAndLock(*it))
    593                             {
    594                                 if (d == QDir((*it)->getMountPath()))
    595                                 {
    596                                     actionShowDevices();
     629            handled = true;
     630        }
    597631
    598                                     // make sure previous devies is
    599                                     // visible and selected
    600                                     ThumbItem *item;
    601                                     if ((*it)->getVolumeID() != "")
    602                                         item = m_itemDict.find(
    603                                             (*it)->getVolumeID());
    604                                     else
    605                                         item = m_itemDict.find(
    606                                             (*it)->getDevicePath());
     632        mon->Unlock(*it);
     633    }
    607634
    608                                     if (item)
    609                                     {
    610                                         int pos = m_itemList.find(item);
    611                                         if (pos != -1)
    612                                         {
    613                                             m_currRow = pos / m_nCols;
    614                                             m_currCol =
    615                                                 pos - m_currRow*m_nCols;
    616                                             m_topRow =
    617                                                 QMAX(0, (m_currRow -
    618                                                          (m_nRows - 1)));
    619                                         }
    620                                     }
    621                                     handled = true;
    622                                     mon->Unlock(*it);
    623                                     break;
    624                                 }
    625                                 mon->Unlock(*it);
    626                             }
    627                         }
    628                     }
     635    if (!handled && (curdir != QDir(m_galleryDir)))
     636    {
     637        QString oldDirName = curdir.dirName();
     638        curdir.cdUp();
     639        loadDirectory(curdir.absPath());
    629640
    630                     if (!handled)
    631                     {
    632 #endif
    633                         if (d != QDir(m_galleryDir))
    634                         {
    635                             QString oldDirName = d.dirName();
    636                             d.cdUp();
    637                             loadDirectory(d.absPath());
    638 
    639                             // make sure up-directory is visible and selected
    640                             ThumbItem* item = m_itemDict.find(oldDirName);
    641                             if (item)
    642                             {
    643                                 int pos = m_itemList.find(item);
    644                                 if (pos != -1) {
    645                                     m_currRow = pos/m_nCols;
    646                                     m_currCol = pos-m_currRow*m_nCols;
    647                                     m_topRow  = QMAX(0, m_currRow-(m_nRows-1));
    648                                 }
    649                             }
    650                             handled = true;
    651                         }
    652 #ifndef _WIN32
    653                     }
    654                 }
    655 #endif
     641        // Make sure up-directory is visible and selected
     642        ThumbItem *item = m_itemDict.find(oldDirName);
     643        if (item)
     644        {
     645            int pos = m_itemList.find(item);
     646            if (pos != -1)
     647            {
     648                m_currRow = pos / m_nCols;
     649                m_currCol = pos - (m_currRow * m_nCols);
     650                m_topRow  = max(0, m_currRow + 1 - m_nRows);
    656651            }
    657652        }
    658     }
    659653
    660     if (handled || menuHandled) {
    661         update();
     654        handled = true;
    662655    }
    663     else
    664     {
    665         MythDialog::keyPressEvent(e);
    666     }
     656
     657    return handled;
    667658}
    668659
    669660void IconView::customEvent(QCustomEvent *e)
  • mythgallery/mythgallery/iconview.h

     
    7373    void paintEvent(QPaintEvent *e);
    7474    void keyPressEvent(QKeyEvent *e);
    7575    void customEvent(QCustomEvent *e);
    76    
     76    bool HandleEscape(void);
     77
    7778  private:
    7879    void loadTheme(void);
    7980    void loadDirectory(const QString& dir, bool topleft = true);
     
    99100    void actionRandomShow(void);
    100101    void actionSettings(void);
    101102    void actionImport(void);
    102 #ifndef _WIN32
    103103    void actionShowDevices(void);
    104 #endif
    105104    void actionCopyHere(void);
    106105    void actionMoveHere(void);
    107106    void actionDelete(void);