Ticket #92: mythvideo.diff

File mythvideo.diff, 41.2 KB (added by Robert Tsai <rtsai1111>, 20 years ago)
  • mythvideo/videodlg.h

     
    5151        virtual void updateBackground(void);
    5252        virtual void parseContainer(QDomElement&) = 0;
    5353        virtual void loadWindow(QDomElement &element);
    54         virtual void handleMetaFetch(Metadata*){}
    5554        virtual void fetchVideos();
    5655        virtual void setParentalLevel(int which_level);
    5756        void shiftParental(int amount);
  • mythvideo/videolist.h

     
    2828
    2929        GenericTree *buildVideoList(bool filebrowser, bool flatlist,
    3030                                                        int parental_level);
    31         Metadata *getVideoListMetadata(int id);
    32         QMap<int, Metadata>& getVideoListMetas(void);
     31        Metadata *getVideoListMetadata(int index);
    3332        void wantVideoListUpdirs(bool yes);
    3433        VideoFilterSettings *getCurrentVideoFilter() { return currentVideoFilter; }
     34        unsigned int count(void) const { return metas.count(); }
     35
    3536    private:
    3637        void buildFsysList(bool flatlist, int parental_level);
    3738        void buildDbList(bool flatlist, int parental_level);
     
    5051        bool has_updirs; // True if tree has updirs
    5152        QStringList  browser_mode_files;
    5253        GenericTree *video_tree_root;
    53         QMap<int, Metadata> metas;
     54        QValueVector<Metadata> metas;   // sorted/indexed by current filter
    5455        VideoFilterSettings *currentVideoFilter;
    5556};
    5657
    5758#endif // VIDEOLIST_H
     59
     60/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • mythvideo/videobrowser.h

     
    1414
    1515#include "videodlg.h"
    1616
    17 typedef QValueList<Metadata>  ValueMetadata;
    18 
    1917class VideoBrowser : public VideoDialog
    2018{
    2119    Q_OBJECT
     
    2927    void cursorRight();
    3028   
    3129    virtual void slotParentalLevelChanged();
    32    
    3330
    3431  protected:
    3532    virtual void parseContainer(QDomElement &element);
     
    3734    void keyPressEvent(QKeyEvent *e);
    3835    void doMenu(bool info=false);
    3936    virtual void fetchVideos();
    40     virtual void handleMetaFetch(Metadata* meta);
    4137   
    4238    LayerSet* getContainer(const QString &name);
    4339   
    4440  private:
    4541    QPixmap getPixmap(QString &level);
     42    void jumpToSelection(int amount);
    4643    void jumpSelection(int amount);
    47     void RefreshMovieList();
    48     void SetCurrentItem();
     44    void SetCurrentItem(unsigned int index);
    4945    void updateInfo(QPainter *);
    5046    void updateBrowsing(QPainter *);
    5147    void updatePlayWait(QPainter *);
    5248    void grayOut(QPainter *);
    5349
    54     bool updateML;
    55     bool allowselect;
    56            
    57     ValueMetadata m_list;
    58    
    5950    QPixmap *bgTransBackup;
    60    
    61 
    6251    QPainter backup;
    6352
    64     int inData;
     53    unsigned int inData;        // index of curItem in VideoList.metas
    6554    int m_state;
    6655
    6756    QString m_title;
    68     QString curitemMovie;
    6957   
    7058    QRect infoRect;
    7159    QRect browsingRect;
  • mythvideo/videofilter.h

     
    2727        QString BuildClauseWhere();
    2828        QString BuildClauseOrderBy();
    2929        void saveAsDefault();
     30
     31        enum ordering {
     32            // These values must be explicitly assigned; they represent
     33            // database values
     34            kOrderByTitle = 0,
     35            kOrderByYearDescending = 1,
     36            kOrderByUserRatingDescending = 2,
     37            kOrderByLength = 3,
     38        };
    3039       
    3140        int getCategory(void){return category;};
    3241        void setCategory (int lcategory){category = lcategory;};
     
    4049        void setRuntime (int lruntime){runtime = lruntime;};
    4150        int getUserrating(void){return userrating;};
    4251        void setUserrating (int luserrating){userrating = luserrating;};
    43         /*int getShowlevel(void){return showlevel;};
    44         void setShowlevel (int lshowlevel)
    45         {showlevel = lshowlevel;};*/
    4652        int getBrowse(void){return browse;};
    4753        void setBrowse(int lbrowse){browse = lbrowse;};
    48         int getOrderby (void) {return orderby;};
    49         void setOrderby (int lorderby) {orderby = lorderby;};
     54        enum ordering getOrderby (void) {return orderby;};
     55        void setOrderby (enum ordering lorderby) {orderby = lorderby;};
    5056   
    5157    private :
    5258        int category;
     
    5662        int runtime;
    5763        int userrating;
    5864        int browse;
    59         int orderby;
     65        enum ordering orderby;
    6066        QString prefix;
    6167};
    6268
     
    95101    void setCountry(int new_country);
    96102    void setGenre(int new_genre);
    97103    void setRunTime(int new_runtime);
    98 //    void setShowlevel(int new_showlevel);
    99104    void setBrowse(int new_browse);
    100     void setOrderby(int new_orderby);
     105    void setOrderby(/* enum VideoFilterSettings::ordering */ int new_orderby);
    101106 private:
    102107    void update_numvideo();
    103108    VideoFilterSettings *originalSettings;
     
    121126
    122127
    123128#endif
     129
     130/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • mythvideo/videoselected.h

     
    3333    Q_OBJECT
    3434  public:
    3535    VideoSelected(VideoList *lvideolist,
    36                  MythMainWindow *parent, const char *name = 0, int idnum = 0);
     36                 MythMainWindow *parent, const char *name = 0, int index = 0);
    3737    ~VideoSelected();
    3838    void VideoSelected::processEvents() { qApp->processEvents(); }
    3939   
  • mythvideo/main.cpp

     
    7373    REG_KEY("Video","BROWSE","Change browsable in video manager","B");
    7474    REG_KEY("Video","INCPARENT","Increase Parental Level","],},F11");
    7575    REG_KEY("Video","DECPARENT","Decrease Parental Level","[,{,F10");
     76
     77    REG_KEY("Video","HOME","Go to the first video","Home");
     78    REG_KEY("Video","END","Go to the last video","End");
    7679}
    7780
    7881
  • mythvideo/videogallery.h

     
    2828#include "videodlg.h"
    2929
    3030
    31 typedef QValueList<Metadata>  ValueMetadata;
    32 
    3331class VideoGallery : public VideoDialog
    3432{
    3533    Q_OBJECT
    3634  public:
    3735    VideoGallery(MythMainWindow *parent, const char *name = 0);
    38     ~VideoGallery();
    3936   
    4037    void processEvents() { qApp->processEvents(); }
    4138   
     
    7471
    7572    void positionIcon();
    7673   
    77     int curView;
    7874    bool subtitleOn;
    7975    bool keepAspectRatio;
    8076    QString curPath;
     
    10399    int thumbH;
    104100
    105101    bool allowselect;
    106     bool updateML;
    107102   
    108103    QString prefix;
    109104   
    110105    GenericTree *video_tree_root;
    111106    GenericTree *where_we_are;
    112107
    113     //typedef void (VideoGallery::*Action)(UIListBtnTypeItem*);
     108    void computeLastRowCol(int list_count);
    114109};
    115110
    116111#endif
  • mythvideo/videodlg.cpp

     
    456456
    457457void VideoDialog::fetchVideos()
    458458{
    459     typedef QMap<int, Metadata> metaMap;
    460    
    461     metaMap myMetas;
    462     metaMap::Iterator it;
    463 
    464459    video_tree_root = video_list->buildVideoList(isFileBrowser, isFlatList,
    465460                                                 currentParentalLevel);
    466 
    467     // XXX: This is suboptimal. The classes should not need this. They
    468     //      can retrieve the data through VideoList::getVideoListMetadata()
    469     myMetas = video_list->getVideoListMetas();
    470     for (it = myMetas.begin(); it != myMetas.end(); ++it) {
    471             handleMetaFetch(&it.data());
    472     }
    473 
    474461}
    475462
    476463void VideoDialog::slotDoFilter()
  • mythvideo/videolist.cpp

     
    2020    delete currentVideoFilter;
    2121}
    2222
    23 Metadata *VideoList::getVideoListMetadata(int id)
     23Metadata *VideoList::getVideoListMetadata(int index)
    2424{
    25     if (id < 0) {
    26         // These are special node types
    27         return NULL;
    28     }
    29     if (metas.contains(id))
    30         return(&metas[id]);
    31     else {
    32         cerr << __FILE__ << ": getVideoListMetadata: unknown key:"
    33                 << id << endl;
    34         return NULL;
    35     }
    36 }
     25    if (index < 0)
     26        return NULL;    // Special node types
    3727
    38 QMap<int, Metadata>& VideoList::getVideoListMetas(void)
    39 {
    40     return(metas);
     28    if ((unsigned int)index < count())
     29        return(&metas[index]);
     30
     31    cerr << __FILE__ << ": getVideoListMetadata: index out of bounds: "
     32        << index << endl;
     33    return NULL;
    4134}
    4235
    4336void VideoList::wantVideoListUpdirs(bool yes)
     
    6861//      If false, the hierarchy present on the filesystem or in the database
    6962//      is preserved. In this mode, both sub-dirs and updirs are present.
    7063
    71 GenericTree *VideoList::buildVideoList(bool filebrowser, bool flatlist, int parental_level)
     64GenericTree *VideoList::buildVideoList(bool filebrowser, bool flatlist,
     65    int parental_level)
    7266{
    7367    // Clear out the old stuff
    7468    browser_mode_files.clear();
     
    119113       
    120114    MSqlQuery query(MSqlQuery::InitCon());
    121115    query.exec(thequery);
    122     Metadata *myData;
     116    unsigned int numrows;
    123117
    124     if(!query.isActive())
     118    if (!query.isActive())
    125119    {
    126120        cerr << __FILE__ << ": Your database sucks" << endl;
     121        return;
    127122    }
    128     else if (query.numRowsAffected() > 0)
     123
     124    if ((numrows = query.numRowsAffected()) <= 0)
     125        return;
     126
     127    QString prefix = gContext->GetSetting("VideoStartupDir");
     128    if (prefix.length() < 1)
    129129    {
    130         QString prefix = gContext->GetSetting("VideoStartupDir");
    131         if(prefix.length() < 1)
    132         {
    133             cerr << __FILE__ <<
    134                          ": Seems unlikely that this is going to work" << endl;
    135         }
     130        cerr << __FILE__ << ": Seems unlikely that this is going to work" <<
     131            endl;
     132    }
    136133
    137         if (!flatlist)
    138             (void)addDirNode(video_tree_root, "videos");
     134    if (!flatlist)
     135        (void)addDirNode(video_tree_root, "videos");
    139136
    140        
    141         // Let's loop over the query and build a sorted list
    142         QMap<QString, Metadata*> sortedList;
     137    //
     138    //  Accumulate query results into the metaptrs list. The "parental_level"
     139    //  filtering really ought to be incorporated into BuildClauseWhere().
     140    //
     141    QPtrList<Metadata> metaptrs;
     142    while (query.next())
     143    {
     144        unsigned int intid = query.value(0).toUInt();
     145        Metadata *myData = new Metadata();
     146        myData->setID(intid);
     147        myData->fillDataFromID();
     148        if (myData->ShowLevel() <= parental_level && myData->ShowLevel() != 0)
     149            metaptrs.append(myData);
     150        else
     151            delete myData;
     152    }
     153
     154    //
     155    //  If sorting by title, re-sort by hand because the SQL sort doesn't
     156    //  ignore articles when sorting. This assumes all titles are in English.
     157    //  This means a movie with a foreign-language title like "A la carte" will
     158    //  be incorrectly alphabetized, because the "A" is actually significant.
     159    //  The set of ignored prefixes should be a database option, or each
     160    //  video's metadata should include a separate sort key.
     161    //
     162    if (currentVideoFilter->getOrderby() == VideoFilterSettings::kOrderByTitle)
     163    {
     164        //
     165        //  Pull things off the metaptrs list and put them into the
     166        //  "stringsort" qmap (which will automatically sort them by qmap key).
     167        //
     168        QMap<QString, Metadata*> stringsort;
    143169        QRegExp prefixes = QObject::tr("^(The |A |An )");
    144         QString sTitle = "";
    145    
    146         while (query.next())
     170        while (!metaptrs.isEmpty())
    147171        {
    148             unsigned int idnum = query.value(0).toUInt();
    149             //
    150             //  Create metadata object and fill it
    151             //
    152        
    153             myData = new Metadata();
    154             myData->setID(idnum);
    155             myData->fillDataFromID();
    156             sTitle = myData->Title();
     172            Metadata *myData = metaptrs.take(0);
     173            QString sTitle = myData->Title();
    157174            sTitle.remove(prefixes);
    158             sortedList[sTitle] = myData;
     175            stringsort[sTitle] = myData;
    159176        }
    160        
    161         QMap<QString, Metadata*>::iterator it = sortedList.begin();
    162        
    163         for ( ; it != sortedList.end(); it++)
     177
     178        //
     179        //  Now walk through the "stringsort" qmap and put them back on the
     180        //  list (in stringsort order).
     181        //
     182        for (QMap<QString, Metadata*>::iterator it = stringsort.begin();
     183                it != stringsort.end();
     184                it++)
    164185        {
    165             GenericTree *where_to_add = video_tree_root->getChildAt(0);
     186            metaptrs.append(*it);
     187        }
     188    }
    166189
    167             //
    168             //  Create metadata object and fill it
    169             //
    170        
    171             myData = *it;
    172             if ((myData->ShowLevel() <= parental_level) &&
    173                 (myData->ShowLevel() != 0))
    174             {
    175                 QString file_string = myData->Filename();
    176                 file_string.remove(0, prefix.length());
    177                 if (!flatlist)
    178                 {
    179 
    180                     where_to_add = addFileNode(where_to_add, file_string, myData->ID());
    181                 }
    182                 else
    183                 {
    184                     video_tree_root->addNode(file_string, myData->ID(), true);
    185                     nitems++;
    186                 }
    187                 metas[myData->ID()] = *myData;
    188             }
    189 
    190             delete myData;
     190    //
     191    //  Build list of videos.
     192    //
     193    for (unsigned int count = 0; !metaptrs.isEmpty(); count++)
     194    {
     195        Metadata *myData = metaptrs.take(0);
     196        GenericTree *where_to_add = video_tree_root->getChildAt(0);
     197        QString file_string = myData->Filename();
     198        file_string.remove(0, prefix.length());
     199        if (flatlist)
     200        {
     201            video_tree_root->addNode(file_string, count, true);
     202            nitems++;
    191203        }
     204        else
     205        {
     206            where_to_add = addFileNode(where_to_add, file_string, count);
     207        }
     208        metas.append(*myData);
     209        delete myData;
    192210    }
    193211}
    194212
     
    304322            // XXX: Maybe more...
    305323        }
    306324
    307         metas[i] = *myData;
     325        metas.append(*myData);
    308326
    309327        if (myData->ShowLevel() <= parental_level && myData->ShowLevel() != 0)
    310328        {
     
    389407}
    390408
    391409GenericTree *VideoList::addFileNode(GenericTree *where_to_add,
    392                                                 const QString& fname, int id)
     410                                                const QString& fname, int index)
    393411{
    394412    int a_counter = 0;
    395413    GenericTree *sub_node;
     
    401419        if(a_counter + 1 >= (int) list.count()) // video
    402420        {
    403421            QString title = (*an_it);
    404             sub_node = where_to_add->addNode(title.section(".",0,-2), id, true);
     422            sub_node = where_to_add->addNode(title.section(".",0,-2),
     423                    index, true);
    405424            sub_node->setAttribute(0, ORDER_ITEM);
    406425            sub_node->setOrderingIndex(0);
    407426            nitems++;
     
    458477        else browser_mode_files.append(filename);
    459478    }
    460479}
     480
     481/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • mythvideo/videobrowser.cpp

     
    2424VideoBrowser::VideoBrowser(MythMainWindow *parent, const char *name)
    2525            : VideoDialog(DLG_BROWSER, parent, "browser", name)
    2626{
    27     updateML = false;
    28    
    2927    m_state = 0;
    30     curitem = NULL;
    31     inData = 0;
    3228   
    3329    setFileBrowser(gContext->GetNumSetting("VideoBrowserNoDB", 0));
    3430    loadWindow(xmldata);       
     
    4036    setNoErase();
    4137
    4238    fetchVideos();
    43 
    44     SetCurrentItem();
    4539    updateBackground();
    4640}
    4741
    4842VideoBrowser::~VideoBrowser()
    4943{
    50     if (curitem)
    51         delete curitem;
    52 
    5344    delete bgTransBackup;
    5445}
    5546
     
    6960{
    7061    bool handled = false;
    7162    QStringList actions;
    72     gContext->GetMainWindow()->TranslateKeyPress("Video", e, actions);
    7363
     64    gContext->GetMainWindow()->TranslateKeyPress("Video", e, actions);
    7465    for (unsigned int i = 0; i < actions.size() && !handled; i++)
    7566    {
    7667        QString action = actions[i];
    7768        handled = true;
    7869
    79         if ((action == "SELECT" || action == "PLAY") && allowselect)
     70        if ((action == "SELECT" || action == "PLAY") && curitem)
    8071            playVideo(curitem);
    8172        else if (action == "INFO")
    8273            doMenu(true);
    83         else if (action == "UP")
    84             jumpSelection(1);
    8574        else if (action == "DOWN")
     75            jumpSelection(1);
     76        else if (action == "UP")
    8677            jumpSelection(-1);
    8778        else if (action == "PAGEDOWN")
    88             jumpSelection((int)(m_list.count() / 5));
     79            jumpSelection(video_list->count() / 5);
    8980        else if (action == "PAGEUP")
    90             jumpSelection(0-(int)(m_list.count() / 5));
    91         else if (action == "INCPARENT")
    92             shiftParental(1);
    93         else if (action == "DECPARENT")
    94             shiftParental(-1);           
     81            jumpSelection(-(video_list->count() / 5));
    9582        else if (action == "LEFT")
    9683            cursorLeft();
    9784        else if (action == "RIGHT")
    9885            cursorRight();
    99         else if (action == "1" || action == "2" || action == "3" || action == "4")
     86        else if (action == "HOME")
     87            jumpToSelection(0);
     88        else if (action == "END")
     89            jumpToSelection(video_list->count() - 1);
     90        else if (action == "INCPARENT")
     91            shiftParental(1);
     92        else if (action == "DECPARENT")
     93            shiftParental(-1);           
     94        else if (action == "1" || action == "2" ||
     95                action == "3" || action == "4")
    10096            setParentalLevel(action.toInt());
    10197        else if (action == "FILTER")
    10298            slotDoFilter();
     
    120116            }
    121117        }           
    122118    }
    123 
    124119   
    125120    if (!handled)
    126121        MythDialog::keyPressEvent(e);
     
    159154
    160155void VideoBrowser::fetchVideos()
    161156{
    162     if (updateML == true)
    163         return;
    164    
    165     updateML = true;
    166     m_list.clear();
    167 
    168157    VideoDialog::fetchVideos();
    169     video_list->wantVideoListUpdirs(true);
     158    video_list->wantVideoListUpdirs(isFileBrowser);
    170159   
    171     updateML = false;
    172     SetCurrentItem();
     160    SetCurrentItem(0);
    173161    update(infoRect);
    174162    update(browsingRect);
    175163    repaint();
    176164}
    177165
    178 void VideoBrowser::handleMetaFetch(Metadata* meta)
    179 {
    180     m_list.append(*meta);
    181 }
    182 
    183166void VideoBrowser::grayOut(QPainter *tmp)
    184167{
    185168   int transparentFlag = gContext->GetNumSetting("PlayBoxShading", 0);
     
    243226}
    244227
    245228
    246 void VideoBrowser::SetCurrentItem()
     229void VideoBrowser::SetCurrentItem(unsigned int index)
    247230{
    248     ValueMetadata::Iterator it;
    249 
    250     if(curitem)
    251     {
    252         delete curitem;
    253     }
    254231    curitem = NULL;
    255232   
     233    unsigned int list_count = video_list->count();
    256234   
    257     //
    258     //  The count may have changed because
    259     //  the Parental Level might have been
    260     //  altered
    261     //
     235    if (list_count == 0)
     236        return;
    262237
    263     int list_count = m_list.count();
    264    
    265     if(list_count == 0)
    266     {
    267         inData = 0;
    268         allowselect = false;
    269     }
    270     else
    271     {
    272         if(inData < list_count)
    273         {
    274             it = m_list.at(inData);
    275         }
    276         else
    277         {
    278             inData = 0;
    279             it = m_list.begin();
    280         }
    281 
    282         curitem = new Metadata(*(it));
    283     }
     238    inData = QMIN(list_count - 1, index);
     239    curitem = video_list->getVideoListMetadata(inData);
    284240}
    285241
    286242void VideoBrowser::updateBrowsing(QPainter *p)
     
    289245    QPixmap pix(pr.size());
    290246    pix.fill(this, pr.topLeft());
    291247    QPainter tmp(&pix);
     248    unsigned int list_count = video_list->count();
    292249
    293250    QString vidnum; 
    294     if(m_list.count() > 0)
    295     {
    296         vidnum = QString(tr("%1 of %2")).arg(inData + 1).arg(m_list.count());
    297     }
     251    if (list_count > 0)
     252        vidnum = QString(tr("%1 of %2")).arg(inData + 1).arg(list_count);
    298253    else
    299     {
    300254        vidnum = tr("No Videos");
    301     }
    302255
    303256    LayerSet *container = NULL;
    304257    container = theme->GetSet("browsing");
     
    334287    pix.fill(this, pr.topLeft());
    335288    QPainter tmp(&pix);
    336289
    337     if (m_list.count() > 0 && curitem)
     290    if (video_list->count() > 0 && curitem)
    338291    {
    339292       QString title = curitem->Title();
    340293       QString filename = curitem->Filename();
     
    426379           container->Draw(&tmp, 7, 0);
    427380           container->Draw(&tmp, 8, 0);
    428381       }
    429 
    430        allowselect = true;
    431382    }
    432383    else
    433384    {
     
    440391           norec->Draw(&tmp, 7, 0);
    441392           norec->Draw(&tmp, 8, 0);
    442393       }
    443 
    444        allowselect = false;
    445394    }
    446395    tmp.end();
    447396    p->drawPixmap(pr.topLeft(), pix);
    448397
    449398}
    450399
    451 void VideoBrowser::jumpSelection(int amount)
     400void VideoBrowser::jumpToSelection(int index)
    452401{
    453     inData += amount;
    454      
    455     if (inData < 0)
    456         inData = m_list.count() + inData;
    457     else if(inData >= (int)m_list.count())
    458         inData = inData - m_list.count();
    459      
    460     SetCurrentItem();
     402    SetCurrentItem(index);
    461403    update(infoRect);
    462404    update(browsingRect);
    463405}
     406
     407void VideoBrowser::jumpSelection(int amount)
     408{
     409    unsigned int list_count = video_list->count();
     410    int index;
     411
     412    if (amount >= 0 || inData >= (unsigned int)-amount)
     413        index = (inData + amount) % list_count;
     414    else
     415        index = list_count + amount + inData;  // unsigned arithmetic
     416
     417    jumpToSelection(index);
     418}
    464419   
    465420
    466421void VideoBrowser::cursorLeft()
     
    486441        browsingRect = area;
    487442}
    488443
     444/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • mythvideo/videofilter.cpp

     
    2626        runtime = gContext->GetNumSetting( QString("%1Runtime").arg(prefix),-2);
    2727        userrating = gContext->GetNumSetting( QString("%1Userrating").arg(prefix),-1);
    2828        browse = gContext->GetNumSetting( QString("%1Browse").arg(prefix),-1);
    29         orderby = gContext->GetNumSetting( QString("%1Orderby").arg(prefix),0);
     29        orderby = (enum ordering)gContext->GetNumSetting(
     30                QString("%1Orderby").arg(prefix),kOrderByTitle);
    3031    }
    3132    else
    3233    {
     
    3738        runtime = -2;
    3839        userrating = -1;
    3940        browse = -1;
    40         orderby = 0;
     41        orderby = kOrderByTitle;
    4142    }
    4243
    4344}
     
    206207{
    207208    switch (orderby)
    208209    {
    209         case 0 :
     210        case kOrderByTitle :
    210211            return " ORDER BY title";
    211         case 1 :
     212        case kOrderByYearDescending :
    212213            return " ORDER BY year DESC";
    213         case 2 :
     214        case kOrderByUserRatingDescending :
    214215            return " ORDER BY userrating DESC";
    215         case 3 :
     216        case kOrderByLength :
    216217            return " ORDER BY length";
    217218        default:
    218219            return "";       
     
    493494
    494495void VideoFilterDialog::saveAndExit()
    495496{
    496      if (originalSettings)
    497      {
     497    if (originalSettings)
     498    {
    498499        originalSettings->setCategory(currentSettings->getCategory());
    499500        originalSettings->setGenre(currentSettings->getGenre());
    500501        originalSettings->setCountry(currentSettings->getCountry());
     
    557558
    558559void VideoFilterDialog::setOrderby(int new_orderby)
    559560{
    560         currentSettings->setOrderby(new_orderby);
     561        currentSettings->setOrderby(
     562                (enum VideoFilterSettings::ordering)new_orderby);
    561563        update_numvideo();
    562564}
    563565
     
    630632{
    631633}
    632634
     635/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • mythvideo/videoselected.cpp

     
    3333
    3434VideoSelected::VideoSelected(VideoList *lvideo_list,
    3535                             MythMainWindow *parent, const char *name,
    36                              int idnum)
     36                             int index)
    3737            : MythDialog(parent, name)
    3838{
    3939    video_list = lvideo_list;
    4040
    41     curitem = video_list->getVideoListMetadata(idnum);
     41    curitem = video_list->getVideoListMetadata(index);
    4242    curitem->fillDataFromID();
    4343
    4444    noUpdate = false;
  • mythvideo/metadata.h

     
    200200    QStringList genres;
    201201    QStringList countries;
    202202    QString player;
    203     unsigned int id;
     203    unsigned int id;    // videometadata.intid
    204204   
    205205    QString filename;
    206206    QString coverfile;
  • mythvideo/videogallery.cpp

     
    2727#include <mythtv/mythcontext.h>
    2828#include <mythtv/util.h>
    2929
    30 enum GAL_VIEWS { VIEW_DB, VIEW_FILE };
    31 
    3230VideoGallery::VideoGallery(MythMainWindow *parent, const char *name)
    3331            : VideoDialog(DLG_GALLERY, parent, "gallery", name)
    3432{
    35     updateML = false;
     33    setFileBrowser(gContext->GetNumSetting("VideoGalleryNoDB", 0));
     34    setFlatList(!isFileBrowser);
    3635
    37     // load default settings from the database
    38    
    39     if (gContext->GetNumSetting("VideoGalleryNoDB", false) == false)
    40         curView = VIEW_DB;
    41     else
    42         curView = VIEW_FILE;
    43        
    4436    nCols                = gContext->GetNumSetting("VideoGalleryColsPerPage",4);
    4537    nRows                = gContext->GetNumSetting("VideoGalleryRowsPerPage",3);
    4638    subtitleOn           = gContext->GetNumSetting("VideoGallerySubtitle",1);
    4739    keepAspectRatio      = gContext->GetNumSetting("VideoGalleryAspectRatio",1);
    4840
    49 
    5041    // XXX Fixme: this is wrong...
    5142    prefix = gContext->GetSetting("VideoStartupDir");
    5243
    53     if (curView == VIEW_DB)
    54     {
    55         setFlatList(true);
    56         setFileBrowser(false);
    57     }
    58     else
    59     {
    60         setFlatList(false);
    61         setFileBrowser(true);
    62     }
    63    
    64    
    6544    loadWindow(xmldata);
    6645    LoadIconWindow(); // load icon settings
    6746
     
    7049    setNoErase();
    7150}
    7251
    73 VideoGallery::~VideoGallery()
    74 {
    75     // save current settings as default
    76     gContext->SaveSetting("VideoDefaultView", curView);
    77 }
    78 
    79 
    80 
    8152void VideoGallery::keyPressEvent(QKeyEvent *e)
    8253{
    83    
    8454    bool handled = false;
    8555    QStringList actions;
    8656   
    87     gContext->GetMainWindow()->TranslateKeyPress("Global", e, actions);
     57    gContext->GetMainWindow()->TranslateKeyPress("Video", e, actions);
    8858    for (unsigned int i = 0; i < actions.size() && !handled; i++)
    8959    {
    9060        QString action = actions[i];
     61        handled = true;
    9162
    9263        if (action == "SELECT")
    93         {
    94             handled = true;
    9564            handled = handleSelect();
    96         }
    97         else if ( (action == "UP")  || (action == "DOWN") ||
    98                   (action == "LEFT") ||(action == "RIGHT") ||
    99                   (action == "PAGEUP") || (action == "PAGEDOWN"))
    100         {
    101             handled = true;
     65        else if (action == "INFO") {
     66            if (where_we_are->getInt() > SUB_FOLDER)
     67                doMenu(true);
     68        } else if (action == "UP" || action == "DOWN" ||
     69                 action == "LEFT" || action == "RIGHT" ||
     70                 action == "PAGEUP" || action == "PAGEDOWN" ||
     71                 action == "HOME" || action == "END")
    10272            moveCursor(action);
    103         }
     73        else if (action == "INCPARENT")
     74            shiftParental(1);
     75        else if (action == "DECPARENT")
     76            shiftParental(-1);           
    10477        else if (action == "1" || action == "2" ||
    10578                 action == "3" || action == "4")
    106         {
    107             handled = true;
    108             setParentalLevel(action.toInt());        // parental control
    109         }
    110        
    111         if (handled)
    112             break;
    113     }   
    114    
    115    
    116     if (!handled)
    117     {
    118         gContext->GetMainWindow()->TranslateKeyPress("Video", e, actions);
    119         for (unsigned int i = 0; i < actions.size() && !handled; i++)
    120         {
    121             QString action = actions[i];
    122             handled = true;
    123    
    124             if (action == "SELECT")
    125             {
    126                 handled = handleSelect();
    127             }
    128             else if (action == "FILTER")
    129             {
    130                 slotDoFilter();
    131             }
    132             else if (action == "INFO")
    133             {
    134                 // pop-up menu with video description
    135                 if ((where_we_are->getInt() > SUB_FOLDER ))
    136                 {
    137                     doMenu(true);
    138                 }
    139             }
    140             else if (action == "INCPARENT")
    141                 shiftParental(1);
    142             else if (action == "DECPARENT")
    143                 shiftParental(-1);           
    144             else if (action == "MENU")
    145             {
    146                 doMenu(false);
    147             }
    148             else if (action == "ESCAPE")
    149             {
    150                  handled = goBack();
    151             }
    152             else
    153                 handled = false;
    154            
    155             if (handled)
    156                 break;
    157         }
     79            setParentalLevel(action.toInt());
     80        else if (action == "FILTER")
     81            slotDoFilter();
     82        else if (action == "MENU")
     83            doMenu(false);
     84        else if (action == "ESCAPE")
     85            handled = goBack();
     86        else
     87            handled = false;
    15888    }
    15989   
    16090    if (!handled)
     
    180110{
    181111    bool handled = false;
    182112    // one dir up
    183     if ((curView == VIEW_FILE) && !jumping)
     113    if (isFileBrowser && !jumping)
    184114    {
    185115        GenericTree *parent = where_we_are->getParent();
    186116        if (parent)
     
    205135     return handled;
    206136}
    207137
     138void VideoGallery::computeLastRowCol(int list_count)
     139{
     140    lastRow = QMAX((int)ceilf((float)list_count / nCols) - 1, 0);
     141    lastCol = (list_count % nCols - 1 + nCols) % nCols;
     142}
     143
    208144void VideoGallery::fetchVideos()
    209145{
    210     if (updateML == true)
    211         return;
    212     updateML = true;
    213    
    214146    VideoDialog::fetchVideos();
    215     video_tree_root = VideoDialog::getVideoTreeRoot();
     147    video_list->wantVideoListUpdirs(isFileBrowser);
    216148
    217     video_list->wantVideoListUpdirs(curView != VIEW_DB);
     149    video_tree_root = VideoDialog::getVideoTreeRoot();
    218150    video_tree_root->setOrderingIndex(0);
    219     video_tree_root->sortByAttributeThenByString(0);
    220151
    221152    //
    222153    // Select initial view
     
    228159
    229160    if (video_tree_root->childCount() > 0)
    230161        where_we_are = video_tree_root->getChildAt(0,0);
    231     else where_we_are = video_tree_root;
     162    else
     163        where_we_are = video_tree_root;
    232164   
    233165    // Move a node down if there is a single directory item here...
    234166    if (where_we_are->siblingCount() == 1 && where_we_are->getInt() < 0)
     
    236168        // Get rid of the up node, if it's there, it _should_ be the first
    237169        // child...
    238170        GenericTree *upnode = where_we_are->getChildAt(0,0);
    239         if ((upnode != NULL) && (upnode->getInt() == UP_FOLDER))
    240                 where_we_are->removeNode(upnode);
     171        if (upnode && upnode->getInt() == UP_FOLDER)
     172            where_we_are->removeNode(upnode);
    241173        if (where_we_are->childCount() > 1)
    242                 where_we_are = where_we_are->getChildAt(0,0);
     174            where_we_are = where_we_are->getChildAt(0,0);
    243175        // else { we have an empty tree! }
    244176    }
    245177    int list_count = where_we_are->siblingCount();
    246     lastRow = QMAX((int)ceilf((float)list_count/(float)nCols)-1,0);
    247     lastCol = QMAX(list_count-lastRow*nCols-1,0);
     178    computeLastRowCol(list_count);
    248179   
    249     allowselect = (bool)(where_we_are->siblingCount() > 0);
     180    allowselect = list_count > 0;
    250181
    251     updateML = false;
    252182    update();         // renew the screen
    253183   
    254184    if (where_we_are->getInt() >= 0)
    255185        curitem = video_list->getVideoListMetadata(where_we_are->getInt());
    256     else curitem = NULL;
     186    else
     187        curitem = NULL;
    257188}
    258189
    259190void VideoGallery::paintEvent(QPaintEvent *e)
     
    350281
    351282    int list_count = parent->childCount();
    352283
    353     int curPos = topRow*nCols;
    354 
    355     for (int y = 0; y < nRows; y++)    {
    356 
     284    for (int y = 0, curPos = topRow * nCols;
     285            y < nRows && curPos < list_count;
     286            y++)
     287    {
    357288        int ypos = y * (spaceH + thumbH);
    358289
    359         for (int x = 0; x < nCols; x++)
     290        for (int x = 0; x < nCols && curPos < list_count; x++)
    360291        {
    361             if (curPos >= list_count)
    362                 continue;
    363 
    364292            int xpos = x * (spaceW + thumbW);
    365293
    366294            GenericTree* curTreePos = parent->getChildAt(curPos,0);
     
    414342{
    415343    QImage *image = 0;
    416344    int yoffset = 0;
    417     bool myImage = true;
    418345    Metadata *meta = NULL;
    419346
    420347    if (curTreePos->getInt() < 0) // directory
     
    457384        meta = video_list->getVideoListMetadata(curTreePos->getInt());
    458385
    459386        image = meta->getCoverImage();
    460         myImage = false;
    461387    }
    462388
    463389    int bw  = backRegPix.width();
     
    470396    {
    471397
    472398        QPixmap *pixmap = NULL;
    473         if (!myImage && meta && meta->haveCoverPixmap())
     399        if (meta && meta->haveCoverPixmap())
    474400            pixmap = meta->getCoverPixmap();
    475401
    476402        if (!pixmap)
     
    485411                          (pixmap->height()-bh+yoffset)/2+sh,
    486412                          bw-2*sw, bh-2*sh-yoffset);
    487413
    488         if (myImage)
    489             delete pixmap;
    490         else
     414        if (meta)
    491415            meta->setCoverPixmap(pixmap);
     416        else
     417            delete pixmap;
    492418    }
    493419
    494420
     
    546472        ttype->Draw(p, 3, 0);
    547473    }
    548474
    549     if (image && myImage)
     475    if (image && !meta)
    550476        delete image;
    551477}
    552478
     
    663589
    664590void VideoGallery::moveCursor(const QString& action)
    665591{
     592    // Support wrap-around navigation, but not wrap-around display
     593    int lastTopRow = QMAX(lastRow - nRows + 1, 0);
    666594    int prevCol = currCol;
    667595    int prevRow = currRow;
    668596    int oldRow  = topRow;
    669597
    670598    if (action == "LEFT")
    671599    {
    672         if (currRow == 0 && currCol == 0)
    673             return;
    674 
    675         currCol--;
    676         if (currCol < 0) {
    677             currCol = nCols - 1;
    678             currRow--;
    679             if (currRow < topRow)
    680                 topRow = currRow;
     600        if (currCol > 0) {
     601            currCol--;
     602        } else {
     603            if (currRow > 0) {
     604                if (topRow == currRow)
     605                    topRow--;
     606                currRow--;
     607                currCol = nCols - 1;
     608            } else {
     609                // "Flip" to last page
     610                topRow = lastTopRow;
     611                currRow = lastRow;
     612                currCol = lastCol;
     613            }
    681614        }
    682615    }
    683616    else if (action == "RIGHT")
    684617    {
    685         if (currRow*nCols+currCol >= (int)(where_we_are->siblingCount())-1)
    686             return;
    687 
    688         currCol++;
    689         if (currCol >= nCols) {
    690             currCol = 0;
    691             currRow++;
    692             if (currRow >= topRow+nRows)
    693                 topRow++;
     618        if (currRow < lastRow) {
     619            if (currCol < nCols - 1) {
     620                currCol++;
     621            } else {
     622                if (topRow + nRows - 1 == currRow)
     623                    topRow++;
     624                currRow++;
     625                currCol = 0;
     626            }
     627        } else {
     628            if (currCol < lastCol) {
     629                currCol++;
     630            } else {
     631                // "Flip" to first page
     632                topRow = 0;
     633                currRow = 0;
     634                currCol = 0;
     635            }
    694636        }
    695637    }
    696638    else if (action == "UP")
    697639    {
    698         if (currRow == 0) {
    699             currRow = lastRow;
    700             currCol = QMIN(currCol,lastCol);
    701             topRow  = QMAX(currRow - nRows + 1,0);
    702         } else {
     640        if (currRow > 0) {
     641            if (topRow == currRow)
     642                topRow--;
    703643            currRow--;
    704             if (currRow < topRow)
    705                 topRow = currRow;
     644        } else {
     645            // "Flip" to last page
     646            topRow = lastTopRow;
     647            currRow = lastRow;
     648            currCol = QMIN(currCol, lastCol);
    706649        }
    707650    }
    708651    else if (action == "DOWN")
    709652    {
    710         if (currRow == lastRow) {
    711             currRow = 0;
    712             topRow = 0;
    713         } else {
     653        if (currRow < lastRow) {
     654            if (topRow + nRows - 1 == currRow)
     655                topRow++;
    714656            currRow++;
    715 
    716657            if (currRow == lastRow)
    717                 currCol = QMIN(currCol,lastCol);
    718 
    719             if (currRow >= topRow+nRows)
    720                 topRow++;
     658                currCol = QMIN(currCol, lastCol);
     659        } else {
     660            // "Flip" to first page
     661            topRow = 0;
     662            currRow = 0;
    721663        }
    722664    }
    723665    else if (action == "PAGEUP")
    724666    {
    725         if (currRow == 0)
    726             return; // or wrap around: currRow = QMAX(lastRow - nRows + 1, 0);
    727         else
    728             currRow = QMAX(currRow - nRows, 0);
    729 
    730         topRow = currRow;
     667        // Converge to (0,0), then "flip" to last page
     668        if (topRow >= nRows) {
     669            topRow -= nRows;
     670            currRow -= nRows;
     671        } else if (topRow > 0) {
     672            unsigned int scrollrows = topRow;
     673            topRow -= scrollrows;
     674            currRow -= scrollrows;
     675        } else if (currRow > 0 || currCol > 0) {
     676            currRow = 0;
     677            currCol = 0;
     678        } else {
     679            // "Flip" to last page
     680            topRow = lastTopRow;
     681            currRow = lastRow;
     682            currCol = QMIN(currCol, lastCol);
     683        }
    731684    }
    732685    else if (action == "PAGEDOWN")
    733686    {
    734         if (currRow == lastRow)
    735             return; // or wrap around: currRow = QMAX(nRows - 1,0);
    736         else
     687        // Converge to (lastRow,lastCol), then "flip" to first page
     688        if (topRow <= lastTopRow - nRows) {
     689            topRow += nRows;
    737690            currRow += nRows;
    738 
    739         if (currRow >= lastRow) {
     691            if (currRow == lastRow)
     692                currCol = QMIN(currCol, lastCol);
     693        } else if (topRow < lastTopRow) {
     694            unsigned int scrollrows = lastTopRow - topRow;
     695            topRow += scrollrows;
     696            currRow += scrollrows;
     697            if (currRow == lastRow)
     698                currCol = QMIN(currCol, lastCol);
     699        } else if (currRow < lastRow || currCol < lastCol) {
    740700            currRow = lastRow;
    741             currCol = QMIN(currCol,lastCol);
     701            currCol = lastCol;
     702        } else {
     703            // "Flip" to first page
     704            topRow = 0;
     705            currRow = 0;
    742706        }
    743 
    744         topRow = QMAX(currRow - nRows + 1,0);
    745707    }
     708    else if (action == "HOME")
     709    {
     710        topRow = 0;
     711        currRow = 0;
     712        currCol = 0;
     713    }
     714    else if (action == "END")
     715    {
     716        topRow = lastTopRow;
     717        currRow = lastRow;
     718        currCol = lastCol;
     719    }
    746720    else
    747721        return;
    748722
    749723    GenericTree *parent = where_we_are->getParent();
    750724    if (parent)
    751         where_we_are = parent->getChildAt(currRow * nCols + currCol,0);
     725        where_we_are = parent->getChildAt(currRow * nCols + currCol, 0);
    752726
    753 
    754727    curitem = video_list->getVideoListMetadata(where_we_are->getInt());
    755728
    756 
    757729    if (topRow != oldRow)     // renew the whole screen
    758730    {
    759731        update(viewRect);
     
    776748    // menu option to toggle between plain and folder view
    777749    //
    778750    cancelPopup();
    779     curView = curView ? VIEW_DB : VIEW_FILE;
    780 
    781     if (curView == VIEW_DB)
    782     {
    783         setFlatList(true);
    784         setFileBrowser(false);
    785     }
    786     else
    787     {
    788         setFlatList(false);
    789         setFileBrowser(true);
    790     }
     751    setFileBrowser(!isFileBrowser);
     752    setFlatList(!isFileBrowser);
    791753   
    792754    fetchVideos(); // reload videos
    793755}
     
    797759{
    798760    // determine the x,y position of the current icon anew
    799761    int inData = where_we_are->getPosition(0);
    800     currRow = (int)floorf((float)inData/(float)nCols);
    801     currCol = (int)(inData-currRow*nCols);
     762    currRow = inData / nCols;
     763    currCol = inData % nCols;
    802764
    803765    // determine which part of the list is shown
    804     int list_count = where_we_are->siblingCount();
    805     lastRow = QMAX((int)ceilf((float)list_count/(float)nCols)-1,0);
    806     lastCol = QMAX(list_count-lastRow*nCols-1,0);
    807     topRow  = QMIN(currRow, QMAX(lastRow - nRows + 1, 0));
     766    computeLastRowCol(where_we_are->siblingCount());
     767    topRow = QMIN(currRow, QMAX(lastRow - nRows + 1, 0));
    808768}
    809769
    810770
     
    820780
    821781        where_we_are = where_we_are->getChildAt(0,0);
    822782
    823         lastRow = QMAX((int)ceilf((float)list_count/(float)nCols)-1,0);
    824         lastCol = QMAX(list_count-lastRow*nCols-1,0);
    825     }
     783        computeLastRowCol(list_count);
    826784
    827     allowselect = (bool)(list_count > 0);
     785        allowselect = true;
     786    }
     787    else
     788    {
     789        allowselect = false;
     790    }
    828791}
    829792
    830793void VideoGallery::handleUpDirSelect()
     
    901864    else if (name.lower() == "arrows")
    902865        arrowsRect = area;
    903866}
     867
     868/* vim: set expandtab tabstop=4 shiftwidth=4: */