Ticket #92: mythvideo.diff
File mythvideo.diff, 41.2 KB (added by , 20 years ago) |
---|
-
mythvideo/videodlg.h
51 51 virtual void updateBackground(void); 52 52 virtual void parseContainer(QDomElement&) = 0; 53 53 virtual void loadWindow(QDomElement &element); 54 virtual void handleMetaFetch(Metadata*){}55 54 virtual void fetchVideos(); 56 55 virtual void setParentalLevel(int which_level); 57 56 void shiftParental(int amount); -
mythvideo/videolist.h
28 28 29 29 GenericTree *buildVideoList(bool filebrowser, bool flatlist, 30 30 int parental_level); 31 Metadata *getVideoListMetadata(int id); 32 QMap<int, Metadata>& getVideoListMetas(void); 31 Metadata *getVideoListMetadata(int index); 33 32 void wantVideoListUpdirs(bool yes); 34 33 VideoFilterSettings *getCurrentVideoFilter() { return currentVideoFilter; } 34 unsigned int count(void) const { return metas.count(); } 35 35 36 private: 36 37 void buildFsysList(bool flatlist, int parental_level); 37 38 void buildDbList(bool flatlist, int parental_level); … … 50 51 bool has_updirs; // True if tree has updirs 51 52 QStringList browser_mode_files; 52 53 GenericTree *video_tree_root; 53 Q Map<int, Metadata> metas;54 QValueVector<Metadata> metas; // sorted/indexed by current filter 54 55 VideoFilterSettings *currentVideoFilter; 55 56 }; 56 57 57 58 #endif // VIDEOLIST_H 59 60 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
mythvideo/videobrowser.h
14 14 15 15 #include "videodlg.h" 16 16 17 typedef QValueList<Metadata> ValueMetadata;18 19 17 class VideoBrowser : public VideoDialog 20 18 { 21 19 Q_OBJECT … … 29 27 void cursorRight(); 30 28 31 29 virtual void slotParentalLevelChanged(); 32 33 30 34 31 protected: 35 32 virtual void parseContainer(QDomElement &element); … … 37 34 void keyPressEvent(QKeyEvent *e); 38 35 void doMenu(bool info=false); 39 36 virtual void fetchVideos(); 40 virtual void handleMetaFetch(Metadata* meta);41 37 42 38 LayerSet* getContainer(const QString &name); 43 39 44 40 private: 45 41 QPixmap getPixmap(QString &level); 42 void jumpToSelection(int amount); 46 43 void jumpSelection(int amount); 47 void RefreshMovieList(); 48 void SetCurrentItem(); 44 void SetCurrentItem(unsigned int index); 49 45 void updateInfo(QPainter *); 50 46 void updateBrowsing(QPainter *); 51 47 void updatePlayWait(QPainter *); 52 48 void grayOut(QPainter *); 53 49 54 bool updateML;55 bool allowselect;56 57 ValueMetadata m_list;58 59 50 QPixmap *bgTransBackup; 60 61 62 51 QPainter backup; 63 52 64 int inData;53 unsigned int inData; // index of curItem in VideoList.metas 65 54 int m_state; 66 55 67 56 QString m_title; 68 QString curitemMovie;69 57 70 58 QRect infoRect; 71 59 QRect browsingRect; -
mythvideo/videofilter.h
27 27 QString BuildClauseWhere(); 28 28 QString BuildClauseOrderBy(); 29 29 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 }; 30 39 31 40 int getCategory(void){return category;}; 32 41 void setCategory (int lcategory){category = lcategory;}; … … 40 49 void setRuntime (int lruntime){runtime = lruntime;}; 41 50 int getUserrating(void){return userrating;}; 42 51 void setUserrating (int luserrating){userrating = luserrating;}; 43 /*int getShowlevel(void){return showlevel;};44 void setShowlevel (int lshowlevel)45 {showlevel = lshowlevel;};*/46 52 int getBrowse(void){return browse;}; 47 53 void setBrowse(int lbrowse){browse = lbrowse;}; 48 intgetOrderby (void) {return orderby;};49 void setOrderby ( intlorderby) {orderby = lorderby;};54 enum ordering getOrderby (void) {return orderby;}; 55 void setOrderby (enum ordering lorderby) {orderby = lorderby;}; 50 56 51 57 private : 52 58 int category; … … 56 62 int runtime; 57 63 int userrating; 58 64 int browse; 59 intorderby;65 enum ordering orderby; 60 66 QString prefix; 61 67 }; 62 68 … … 95 101 void setCountry(int new_country); 96 102 void setGenre(int new_genre); 97 103 void setRunTime(int new_runtime); 98 // void setShowlevel(int new_showlevel);99 104 void setBrowse(int new_browse); 100 void setOrderby( int new_orderby);105 void setOrderby(/* enum VideoFilterSettings::ordering */ int new_orderby); 101 106 private: 102 107 void update_numvideo(); 103 108 VideoFilterSettings *originalSettings; … … 121 126 122 127 123 128 #endif 129 130 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
mythvideo/videoselected.h
33 33 Q_OBJECT 34 34 public: 35 35 VideoSelected(VideoList *lvideolist, 36 MythMainWindow *parent, const char *name = 0, int i dnum= 0);36 MythMainWindow *parent, const char *name = 0, int index = 0); 37 37 ~VideoSelected(); 38 38 void VideoSelected::processEvents() { qApp->processEvents(); } 39 39 -
mythvideo/main.cpp
73 73 REG_KEY("Video","BROWSE","Change browsable in video manager","B"); 74 74 REG_KEY("Video","INCPARENT","Increase Parental Level","],},F11"); 75 75 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"); 76 79 } 77 80 78 81 -
mythvideo/videogallery.h
28 28 #include "videodlg.h" 29 29 30 30 31 typedef QValueList<Metadata> ValueMetadata;32 33 31 class VideoGallery : public VideoDialog 34 32 { 35 33 Q_OBJECT 36 34 public: 37 35 VideoGallery(MythMainWindow *parent, const char *name = 0); 38 ~VideoGallery();39 36 40 37 void processEvents() { qApp->processEvents(); } 41 38 … … 74 71 75 72 void positionIcon(); 76 73 77 int curView;78 74 bool subtitleOn; 79 75 bool keepAspectRatio; 80 76 QString curPath; … … 103 99 int thumbH; 104 100 105 101 bool allowselect; 106 bool updateML;107 102 108 103 QString prefix; 109 104 110 105 GenericTree *video_tree_root; 111 106 GenericTree *where_we_are; 112 107 113 //typedef void (VideoGallery::*Action)(UIListBtnTypeItem*);108 void computeLastRowCol(int list_count); 114 109 }; 115 110 116 111 #endif -
mythvideo/videodlg.cpp
456 456 457 457 void VideoDialog::fetchVideos() 458 458 { 459 typedef QMap<int, Metadata> metaMap;460 461 metaMap myMetas;462 metaMap::Iterator it;463 464 459 video_tree_root = video_list->buildVideoList(isFileBrowser, isFlatList, 465 460 currentParentalLevel); 466 467 // XXX: This is suboptimal. The classes should not need this. They468 // 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 474 461 } 475 462 476 463 void VideoDialog::slotDoFilter() -
mythvideo/videolist.cpp
20 20 delete currentVideoFilter; 21 21 } 22 22 23 Metadata *VideoList::getVideoListMetadata(int i d)23 Metadata *VideoList::getVideoListMetadata(int index) 24 24 { 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 37 27 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; 41 34 } 42 35 43 36 void VideoList::wantVideoListUpdirs(bool yes) … … 68 61 // If false, the hierarchy present on the filesystem or in the database 69 62 // is preserved. In this mode, both sub-dirs and updirs are present. 70 63 71 GenericTree *VideoList::buildVideoList(bool filebrowser, bool flatlist, int parental_level) 64 GenericTree *VideoList::buildVideoList(bool filebrowser, bool flatlist, 65 int parental_level) 72 66 { 73 67 // Clear out the old stuff 74 68 browser_mode_files.clear(); … … 119 113 120 114 MSqlQuery query(MSqlQuery::InitCon()); 121 115 query.exec(thequery); 122 Metadata *myData;116 unsigned int numrows; 123 117 124 if (!query.isActive())118 if (!query.isActive()) 125 119 { 126 120 cerr << __FILE__ << ": Your database sucks" << endl; 121 return; 127 122 } 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) 129 129 { 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 } 136 133 137 138 134 if (!flatlist) 135 (void)addDirNode(video_tree_root, "videos"); 139 136 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; 143 169 QRegExp prefixes = QObject::tr("^(The |A |An )"); 144 QString sTitle = ""; 145 146 while (query.next()) 170 while (!metaptrs.isEmpty()) 147 171 { 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(); 157 174 sTitle.remove(prefixes); 158 s ortedList[sTitle] = myData;175 stringsort[sTitle] = myData; 159 176 } 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++) 164 185 { 165 GenericTree *where_to_add = video_tree_root->getChildAt(0); 186 metaptrs.append(*it); 187 } 188 } 166 189 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++; 191 203 } 204 else 205 { 206 where_to_add = addFileNode(where_to_add, file_string, count); 207 } 208 metas.append(*myData); 209 delete myData; 192 210 } 193 211 } 194 212 … … 304 322 // XXX: Maybe more... 305 323 } 306 324 307 metas [i] = *myData;325 metas.append(*myData); 308 326 309 327 if (myData->ShowLevel() <= parental_level && myData->ShowLevel() != 0) 310 328 { … … 389 407 } 390 408 391 409 GenericTree *VideoList::addFileNode(GenericTree *where_to_add, 392 const QString& fname, int i d)410 const QString& fname, int index) 393 411 { 394 412 int a_counter = 0; 395 413 GenericTree *sub_node; … … 401 419 if(a_counter + 1 >= (int) list.count()) // video 402 420 { 403 421 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); 405 424 sub_node->setAttribute(0, ORDER_ITEM); 406 425 sub_node->setOrderingIndex(0); 407 426 nitems++; … … 458 477 else browser_mode_files.append(filename); 459 478 } 460 479 } 480 481 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
mythvideo/videobrowser.cpp
24 24 VideoBrowser::VideoBrowser(MythMainWindow *parent, const char *name) 25 25 : VideoDialog(DLG_BROWSER, parent, "browser", name) 26 26 { 27 updateML = false;28 29 27 m_state = 0; 30 curitem = NULL;31 inData = 0;32 28 33 29 setFileBrowser(gContext->GetNumSetting("VideoBrowserNoDB", 0)); 34 30 loadWindow(xmldata); … … 40 36 setNoErase(); 41 37 42 38 fetchVideos(); 43 44 SetCurrentItem();45 39 updateBackground(); 46 40 } 47 41 48 42 VideoBrowser::~VideoBrowser() 49 43 { 50 if (curitem)51 delete curitem;52 53 44 delete bgTransBackup; 54 45 } 55 46 … … 69 60 { 70 61 bool handled = false; 71 62 QStringList actions; 72 gContext->GetMainWindow()->TranslateKeyPress("Video", e, actions);73 63 64 gContext->GetMainWindow()->TranslateKeyPress("Video", e, actions); 74 65 for (unsigned int i = 0; i < actions.size() && !handled; i++) 75 66 { 76 67 QString action = actions[i]; 77 68 handled = true; 78 69 79 if ((action == "SELECT" || action == "PLAY") && allowselect)70 if ((action == "SELECT" || action == "PLAY") && curitem) 80 71 playVideo(curitem); 81 72 else if (action == "INFO") 82 73 doMenu(true); 83 else if (action == "UP")84 jumpSelection(1);85 74 else if (action == "DOWN") 75 jumpSelection(1); 76 else if (action == "UP") 86 77 jumpSelection(-1); 87 78 else if (action == "PAGEDOWN") 88 jumpSelection( (int)(m_list.count() / 5));79 jumpSelection(video_list->count() / 5); 89 80 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)); 95 82 else if (action == "LEFT") 96 83 cursorLeft(); 97 84 else if (action == "RIGHT") 98 85 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") 100 96 setParentalLevel(action.toInt()); 101 97 else if (action == "FILTER") 102 98 slotDoFilter(); … … 120 116 } 121 117 } 122 118 } 123 124 119 125 120 if (!handled) 126 121 MythDialog::keyPressEvent(e); … … 159 154 160 155 void VideoBrowser::fetchVideos() 161 156 { 162 if (updateML == true)163 return;164 165 updateML = true;166 m_list.clear();167 168 157 VideoDialog::fetchVideos(); 169 video_list->wantVideoListUpdirs( true);158 video_list->wantVideoListUpdirs(isFileBrowser); 170 159 171 updateML = false; 172 SetCurrentItem(); 160 SetCurrentItem(0); 173 161 update(infoRect); 174 162 update(browsingRect); 175 163 repaint(); 176 164 } 177 165 178 void VideoBrowser::handleMetaFetch(Metadata* meta)179 {180 m_list.append(*meta);181 }182 183 166 void VideoBrowser::grayOut(QPainter *tmp) 184 167 { 185 168 int transparentFlag = gContext->GetNumSetting("PlayBoxShading", 0); … … 243 226 } 244 227 245 228 246 void VideoBrowser::SetCurrentItem( )229 void VideoBrowser::SetCurrentItem(unsigned int index) 247 230 { 248 ValueMetadata::Iterator it;249 250 if(curitem)251 {252 delete curitem;253 }254 231 curitem = NULL; 255 232 233 unsigned int list_count = video_list->count(); 256 234 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; 262 237 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); 284 240 } 285 241 286 242 void VideoBrowser::updateBrowsing(QPainter *p) … … 289 245 QPixmap pix(pr.size()); 290 246 pix.fill(this, pr.topLeft()); 291 247 QPainter tmp(&pix); 248 unsigned int list_count = video_list->count(); 292 249 293 250 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); 298 253 else 299 {300 254 vidnum = tr("No Videos"); 301 }302 255 303 256 LayerSet *container = NULL; 304 257 container = theme->GetSet("browsing"); … … 334 287 pix.fill(this, pr.topLeft()); 335 288 QPainter tmp(&pix); 336 289 337 if ( m_list.count() > 0 && curitem)290 if (video_list->count() > 0 && curitem) 338 291 { 339 292 QString title = curitem->Title(); 340 293 QString filename = curitem->Filename(); … … 426 379 container->Draw(&tmp, 7, 0); 427 380 container->Draw(&tmp, 8, 0); 428 381 } 429 430 allowselect = true;431 382 } 432 383 else 433 384 { … … 440 391 norec->Draw(&tmp, 7, 0); 441 392 norec->Draw(&tmp, 8, 0); 442 393 } 443 444 allowselect = false;445 394 } 446 395 tmp.end(); 447 396 p->drawPixmap(pr.topLeft(), pix); 448 397 449 398 } 450 399 451 void VideoBrowser::jump Selection(int amount)400 void VideoBrowser::jumpToSelection(int index) 452 401 { 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); 461 403 update(infoRect); 462 404 update(browsingRect); 463 405 } 406 407 void 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 } 464 419 465 420 466 421 void VideoBrowser::cursorLeft() … … 486 441 browsingRect = area; 487 442 } 488 443 444 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
mythvideo/videofilter.cpp
26 26 runtime = gContext->GetNumSetting( QString("%1Runtime").arg(prefix),-2); 27 27 userrating = gContext->GetNumSetting( QString("%1Userrating").arg(prefix),-1); 28 28 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); 30 31 } 31 32 else 32 33 { … … 37 38 runtime = -2; 38 39 userrating = -1; 39 40 browse = -1; 40 orderby = 0;41 orderby = kOrderByTitle; 41 42 } 42 43 43 44 } … … 206 207 { 207 208 switch (orderby) 208 209 { 209 case 0:210 case kOrderByTitle : 210 211 return " ORDER BY title"; 211 case 1:212 case kOrderByYearDescending : 212 213 return " ORDER BY year DESC"; 213 case 2:214 case kOrderByUserRatingDescending : 214 215 return " ORDER BY userrating DESC"; 215 case 3:216 case kOrderByLength : 216 217 return " ORDER BY length"; 217 218 default: 218 219 return ""; … … 493 494 494 495 void VideoFilterDialog::saveAndExit() 495 496 { 496 497 497 if (originalSettings) 498 { 498 499 originalSettings->setCategory(currentSettings->getCategory()); 499 500 originalSettings->setGenre(currentSettings->getGenre()); 500 501 originalSettings->setCountry(currentSettings->getCountry()); … … 557 558 558 559 void VideoFilterDialog::setOrderby(int new_orderby) 559 560 { 560 currentSettings->setOrderby(new_orderby); 561 currentSettings->setOrderby( 562 (enum VideoFilterSettings::ordering)new_orderby); 561 563 update_numvideo(); 562 564 } 563 565 … … 630 632 { 631 633 } 632 634 635 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
mythvideo/videoselected.cpp
33 33 34 34 VideoSelected::VideoSelected(VideoList *lvideo_list, 35 35 MythMainWindow *parent, const char *name, 36 int i dnum)36 int index) 37 37 : MythDialog(parent, name) 38 38 { 39 39 video_list = lvideo_list; 40 40 41 curitem = video_list->getVideoListMetadata(i dnum);41 curitem = video_list->getVideoListMetadata(index); 42 42 curitem->fillDataFromID(); 43 43 44 44 noUpdate = false; -
mythvideo/metadata.h
200 200 QStringList genres; 201 201 QStringList countries; 202 202 QString player; 203 unsigned int id; 203 unsigned int id; // videometadata.intid 204 204 205 205 QString filename; 206 206 QString coverfile; -
mythvideo/videogallery.cpp
27 27 #include <mythtv/mythcontext.h> 28 28 #include <mythtv/util.h> 29 29 30 enum GAL_VIEWS { VIEW_DB, VIEW_FILE };31 32 30 VideoGallery::VideoGallery(MythMainWindow *parent, const char *name) 33 31 : VideoDialog(DLG_GALLERY, parent, "gallery", name) 34 32 { 35 updateML = false; 33 setFileBrowser(gContext->GetNumSetting("VideoGalleryNoDB", 0)); 34 setFlatList(!isFileBrowser); 36 35 37 // load default settings from the database38 39 if (gContext->GetNumSetting("VideoGalleryNoDB", false) == false)40 curView = VIEW_DB;41 else42 curView = VIEW_FILE;43 44 36 nCols = gContext->GetNumSetting("VideoGalleryColsPerPage",4); 45 37 nRows = gContext->GetNumSetting("VideoGalleryRowsPerPage",3); 46 38 subtitleOn = gContext->GetNumSetting("VideoGallerySubtitle",1); 47 39 keepAspectRatio = gContext->GetNumSetting("VideoGalleryAspectRatio",1); 48 40 49 50 41 // XXX Fixme: this is wrong... 51 42 prefix = gContext->GetSetting("VideoStartupDir"); 52 43 53 if (curView == VIEW_DB)54 {55 setFlatList(true);56 setFileBrowser(false);57 }58 else59 {60 setFlatList(false);61 setFileBrowser(true);62 }63 64 65 44 loadWindow(xmldata); 66 45 LoadIconWindow(); // load icon settings 67 46 … … 70 49 setNoErase(); 71 50 } 72 51 73 VideoGallery::~VideoGallery()74 {75 // save current settings as default76 gContext->SaveSetting("VideoDefaultView", curView);77 }78 79 80 81 52 void VideoGallery::keyPressEvent(QKeyEvent *e) 82 53 { 83 84 54 bool handled = false; 85 55 QStringList actions; 86 56 87 gContext->GetMainWindow()->TranslateKeyPress(" Global", e, actions);57 gContext->GetMainWindow()->TranslateKeyPress("Video", e, actions); 88 58 for (unsigned int i = 0; i < actions.size() && !handled; i++) 89 59 { 90 60 QString action = actions[i]; 61 handled = true; 91 62 92 63 if (action == "SELECT") 93 {94 handled = true;95 64 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") 102 72 moveCursor(action); 103 } 73 else if (action == "INCPARENT") 74 shiftParental(1); 75 else if (action == "DECPARENT") 76 shiftParental(-1); 104 77 else if (action == "1" || action == "2" || 105 78 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; 158 88 } 159 89 160 90 if (!handled) … … 180 110 { 181 111 bool handled = false; 182 112 // one dir up 183 if ( (curView == VIEW_FILE)&& !jumping)113 if (isFileBrowser && !jumping) 184 114 { 185 115 GenericTree *parent = where_we_are->getParent(); 186 116 if (parent) … … 205 135 return handled; 206 136 } 207 137 138 void 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 208 144 void VideoGallery::fetchVideos() 209 145 { 210 if (updateML == true)211 return;212 updateML = true;213 214 146 VideoDialog::fetchVideos(); 215 video_ tree_root = VideoDialog::getVideoTreeRoot();147 video_list->wantVideoListUpdirs(isFileBrowser); 216 148 217 video_ list->wantVideoListUpdirs(curView != VIEW_DB);149 video_tree_root = VideoDialog::getVideoTreeRoot(); 218 150 video_tree_root->setOrderingIndex(0); 219 video_tree_root->sortByAttributeThenByString(0);220 151 221 152 // 222 153 // Select initial view … … 228 159 229 160 if (video_tree_root->childCount() > 0) 230 161 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; 232 164 233 165 // Move a node down if there is a single directory item here... 234 166 if (where_we_are->siblingCount() == 1 && where_we_are->getInt() < 0) … … 236 168 // Get rid of the up node, if it's there, it _should_ be the first 237 169 // child... 238 170 GenericTree *upnode = where_we_are->getChildAt(0,0); 239 if ( (upnode != NULL) && (upnode->getInt() == UP_FOLDER))240 171 if (upnode && upnode->getInt() == UP_FOLDER) 172 where_we_are->removeNode(upnode); 241 173 if (where_we_are->childCount() > 1) 242 174 where_we_are = where_we_are->getChildAt(0,0); 243 175 // else { we have an empty tree! } 244 176 } 245 177 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); 248 179 249 allowselect = (bool)(where_we_are->siblingCount() > 0);180 allowselect = list_count > 0; 250 181 251 updateML = false;252 182 update(); // renew the screen 253 183 254 184 if (where_we_are->getInt() >= 0) 255 185 curitem = video_list->getVideoListMetadata(where_we_are->getInt()); 256 else curitem = NULL; 186 else 187 curitem = NULL; 257 188 } 258 189 259 190 void VideoGallery::paintEvent(QPaintEvent *e) … … 350 281 351 282 int list_count = parent->childCount(); 352 283 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 { 357 288 int ypos = y * (spaceH + thumbH); 358 289 359 for (int x = 0; x < nCols ; x++)290 for (int x = 0; x < nCols && curPos < list_count; x++) 360 291 { 361 if (curPos >= list_count)362 continue;363 364 292 int xpos = x * (spaceW + thumbW); 365 293 366 294 GenericTree* curTreePos = parent->getChildAt(curPos,0); … … 414 342 { 415 343 QImage *image = 0; 416 344 int yoffset = 0; 417 bool myImage = true;418 345 Metadata *meta = NULL; 419 346 420 347 if (curTreePos->getInt() < 0) // directory … … 457 384 meta = video_list->getVideoListMetadata(curTreePos->getInt()); 458 385 459 386 image = meta->getCoverImage(); 460 myImage = false;461 387 } 462 388 463 389 int bw = backRegPix.width(); … … 470 396 { 471 397 472 398 QPixmap *pixmap = NULL; 473 if ( !myImage &&meta && meta->haveCoverPixmap())399 if (meta && meta->haveCoverPixmap()) 474 400 pixmap = meta->getCoverPixmap(); 475 401 476 402 if (!pixmap) … … 485 411 (pixmap->height()-bh+yoffset)/2+sh, 486 412 bw-2*sw, bh-2*sh-yoffset); 487 413 488 if (myImage) 489 delete pixmap; 490 else 414 if (meta) 491 415 meta->setCoverPixmap(pixmap); 416 else 417 delete pixmap; 492 418 } 493 419 494 420 … … 546 472 ttype->Draw(p, 3, 0); 547 473 } 548 474 549 if (image && myImage)475 if (image && !meta) 550 476 delete image; 551 477 } 552 478 … … 663 589 664 590 void VideoGallery::moveCursor(const QString& action) 665 591 { 592 // Support wrap-around navigation, but not wrap-around display 593 int lastTopRow = QMAX(lastRow - nRows + 1, 0); 666 594 int prevCol = currCol; 667 595 int prevRow = currRow; 668 596 int oldRow = topRow; 669 597 670 598 if (action == "LEFT") 671 599 { 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 } 681 614 } 682 615 } 683 616 else if (action == "RIGHT") 684 617 { 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 } 694 636 } 695 637 } 696 638 else if (action == "UP") 697 639 { 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--; 703 643 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); 706 649 } 707 650 } 708 651 else if (action == "DOWN") 709 652 { 710 if (currRow == lastRow) { 711 currRow = 0; 712 topRow = 0; 713 } else { 653 if (currRow < lastRow) { 654 if (topRow + nRows - 1 == currRow) 655 topRow++; 714 656 currRow++; 715 716 657 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; 721 663 } 722 664 } 723 665 else if (action == "PAGEUP") 724 666 { 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 } 731 684 } 732 685 else if (action == "PAGEDOWN") 733 686 { 734 if (currRow == lastRow)735 return; // or wrap around: currRow = QMAX(nRows - 1,0);736 else687 // Converge to (lastRow,lastCol), then "flip" to first page 688 if (topRow <= lastTopRow - nRows) { 689 topRow += nRows; 737 690 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) { 740 700 currRow = lastRow; 741 currCol = QMIN(currCol,lastCol); 701 currCol = lastCol; 702 } else { 703 // "Flip" to first page 704 topRow = 0; 705 currRow = 0; 742 706 } 743 744 topRow = QMAX(currRow - nRows + 1,0);745 707 } 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 } 746 720 else 747 721 return; 748 722 749 723 GenericTree *parent = where_we_are->getParent(); 750 724 if (parent) 751 where_we_are = parent->getChildAt(currRow * nCols + currCol, 0);725 where_we_are = parent->getChildAt(currRow * nCols + currCol, 0); 752 726 753 754 727 curitem = video_list->getVideoListMetadata(where_we_are->getInt()); 755 728 756 757 729 if (topRow != oldRow) // renew the whole screen 758 730 { 759 731 update(viewRect); … … 776 748 // menu option to toggle between plain and folder view 777 749 // 778 750 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); 791 753 792 754 fetchVideos(); // reload videos 793 755 } … … 797 759 { 798 760 // determine the x,y position of the current icon anew 799 761 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; 802 764 803 765 // 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)); 808 768 } 809 769 810 770 … … 820 780 821 781 where_we_are = where_we_are->getChildAt(0,0); 822 782 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); 826 784 827 allowselect = (bool)(list_count > 0); 785 allowselect = true; 786 } 787 else 788 { 789 allowselect = false; 790 } 828 791 } 829 792 830 793 void VideoGallery::handleUpDirSelect() … … 901 864 else if (name.lower() == "arrows") 902 865 arrowsRect = area; 903 866 } 867 868 /* vim: set expandtab tabstop=4 shiftwidth=4: */