Ticket #1678: mythplugins-mythvideo-titlesortkey_in_database.patch
File mythplugins-mythvideo-titlesortkey_in_database.patch, 15.0 KB (added by , 20 years ago) |
---|
-
mythvideo/mythvideo/video-ui.xml
1102 1102 <value>Unique Player Command:</value> 1103 1103 </textarea> 1104 1104 1105 <textarea name="title_sort_key_text" draworder="0" align="right"> 1106 <area>50,490,250,40</area> 1107 <font>display</font> 1108 <value>Title-Sort Key:</value> 1109 </textarea> 1110 1105 1111 <!-- 1106 1112 Widgets 1107 1113 --> … … 1167 1173 <area>310,445,300,40</area> 1168 1174 </blackhole> 1169 1175 1176 <blackhole name="title_sort_key_hack" draworder="0"> 1177 <area>310,490,300,40</area> 1178 </blackhole> 1179 1170 1180 <textbutton name="done_button" draworder="0"> 1171 <position>310,5 05</position>1181 <position>310,550</position> 1172 1182 <font>display</font> 1173 1183 <image function="on" filename="mv_large_text_button_on.png"></image> 1174 1184 <image function="off" filename="mv_large_text_button_off.png"></image> -
mythvideo/mythvideo/metadata.cpp
204 204 MSqlQuery query(MSqlQuery::InitCon()); 205 205 query.prepare("SELECT title,director,plot,rating,year,userrating," 206 206 "length,filename,showlevel,coverfile,inetref,childid," 207 "browse,playcommand, videocategory.category "207 "browse,playcommand, videocategory.category,titlesortkey " 208 208 " FROM videometadata LEFT JOIN videocategory" 209 209 " ON videometadata.category = videocategory.intid" 210 210 " WHERE videometadata.intid= :ID ;"); … … 232 232 browse = query.value(12).toBool(); 233 233 playcommand = query.value(13).toString(); 234 234 category = query.value(14).toString(); 235 titleSortKey = query.value(15).toString(); 235 236 236 237 // Genres 237 238 fillGenres(); … … 276 277 userrating = 0.0; 277 278 278 279 MSqlQuery a_query(MSqlQuery::InitCon()); 279 a_query.prepare("INSERT INTO videometadata (title, director,plot,"280 " rating,year,userrating,length,filename,showlevel,"281 "coverfile,inetref,browse) VALUES (:TITLE, : DIRECTOR, "282 ": PLOT, :RATING, :YEAR, :USERRATING, :LENGTH, "280 a_query.prepare("INSERT INTO videometadata (title,titlesortkey,director," 281 "plot,rating,year,userrating,length,filename,showlevel," 282 "coverfile,inetref,browse) VALUES (:TITLE, :TITLESORTKEY, " 283 ":DIRECTOR, :PLOT, :RATING, :YEAR, :USERRATING, :LENGTH, " 283 284 ":FILENAME, :SHOWLEVEL, :COVERFILE, :INETREF, " 284 285 ":BROWSE );"); 285 286 a_query.bindValue(":TITLE", title.utf8()); 287 a_query.bindValue(":TITLESORTKEY", titleSortKey.utf8()); 286 288 a_query.bindValue(":DIRECTOR", director.utf8()); 287 289 a_query.bindValue(":PLOT", plot.utf8()); 288 290 a_query.bindValue(":RATING", rating.utf8()); … … 379 381 } 380 382 } 381 383 384 void Metadata::guessTitleSortKey() 385 { 386 QRegExp prefixes = QObject::tr("^(The |A |An )"); 387 // Start with the title 388 titleSortKey = title; 389 // Remove indefinite articles from the title 390 titleSortKey.remove(prefixes); 391 // Make the comparison case-insensitive regardless of locale's LC_COLLATE 392 titleSortKey = titleSortKey.lower(); 393 } 394 382 395 void Metadata::updateDatabase() 383 396 { 384 397 if (title == "") 385 398 guessTitle(); 399 if (titleSortKey == "") 400 guessTitleSortKey(); 386 401 if (director == "") 387 402 director = QObject::tr("Unknown"); 388 403 if (plot == "") … … 398 413 399 414 MSqlQuery query(MSqlQuery::InitCon()); 400 415 query.prepare("UPDATE videometadata SET title = :TITLE, " 416 "titlesortkey = :TITLESORTKEY, " 401 417 "director = :DIRECTOR, plot = :PLOT, rating= :RATING, " 402 418 "year = :YEAR, userrating = :USERRATING, length = :LENGTH, " 403 419 "filename = :FILENAME, showlevel = :SHOWLEVEL, " … … 406 422 "childid = :CHILDID, category = :CATEGORY " 407 423 "WHERE intid = :INTID"); 408 424 query.bindValue(":TITLE", title.utf8()); 425 query.bindValue(":TITLESORTKEY", titleSortKey.utf8()); 409 426 query.bindValue(":DIRECTOR", director.utf8()); 410 427 query.bindValue(":PLOT", plot.utf8()); 411 428 query.bindValue(":RATING", rating.utf8()); -
mythvideo/mythvideo/dbcheck.cpp
8 8 #include "mythtv/mythcontext.h" 9 9 #include "mythtv/mythdbcon.h" 10 10 11 const QString currentDatabaseVersion = "100 8";11 const QString currentDatabaseVersion = "1009"; 12 12 13 13 static void UpdateDBVersionNumber(const QString &newnumber) 14 14 { … … 216 216 performActualUpdate(updates, "1008", dbver); 217 217 } 218 218 219 if (dbver == "1008") 220 { 221 const QString updates[] = { 222 "ALTER TABLE videometadata ADD titlesortkey VARCHAR(255);", 223 "UPDATE videometadata SET titlesortkey = TRIM(LEADING ' ' FROM " 224 "(IF(title REGEXP '" + QObject::tr("^(The |A |An )") + "', " 225 "TRIM(LEADING SUBSTRING_INDEX(title,' ',1) FROM title),title)));", 226 "" 227 }; 228 229 performActualUpdate(updates, "1009", dbver); 230 } 231 219 232 } -
mythvideo/mythvideo/editmetadata.h
45 45 void takeFocusAwayFromEditor(bool up_or_down); 46 46 void saveAndExit(); 47 47 void setTitle(QString new_title); 48 void setTitleSortKey(QString new_title_sort_key); 48 49 void setCategory(int new_category); 49 50 void setPlayer(QString new_player); 50 51 void setLevel(int new_level); … … 64 65 MythRemoteLineEdit *title_editor; 65 66 UIBlackHoleType *title_hack; 66 67 68 MythRemoteLineEdit *title_sort_key_editor; 69 UIBlackHoleType *title_sort_key_hack; 70 67 71 MythRemoteLineEdit *player_editor; 68 72 UIBlackHoleType *player_hack; 69 73 -
mythvideo/mythvideo/videomanager.cpp
437 437 curitem->setUserRating(data["UserRating"].toFloat()); 438 438 curitem->setRating(data["MovieRating"]); 439 439 curitem->setLength(data["Runtime"].toInt()); 440 curitem->guessTitleSortKey(); 440 441 441 442 //movieGenres 442 443 movieGenres.clear(); … … 1479 1480 QString coverFile = tr("No Cover"); 1480 1481 1481 1482 curitem->guessTitle(); 1483 curitem->guessTitleSortKey(); 1482 1484 curitem->setCoverFile(coverFile); 1483 1485 curitem->setYear(1895); 1484 1486 curitem->setInetRef("00000000"); -
mythvideo/mythvideo/videolist.cpp
175 175 } 176 176 177 177 // 178 // If sorting by title, re-sort by hand because the SQL sort doesn't179 // ignore articles when sorting. This assumes all titles are in English.180 // This means a movie with a foreign-language title like "A la carte" will181 // be incorrectly alphabetized, because the "A" is actually significant.182 // The set of ignored prefixes should be a database option, or each183 // video's metadata should include a separate sort key.184 //185 if (currentVideoFilter->getOrderby() == VideoFilterSettings::kOrderByTitle)186 {187 //188 // Pull things off the metaptrs list and put them into the189 // "stringsort" qmap (which will automatically sort them by qmap key).190 //191 QMap<QString, Metadata*> stringsort;192 QRegExp prefixes = QObject::tr("^(The |A |An )");193 while (!metaptrs.isEmpty())194 {195 Metadata *myData = metaptrs.take(0);196 QString sTitle = myData->Title();197 sTitle.remove(prefixes);198 199 // Append the video ID to allow multiple videos with the same title200 sTitle += QString().sprintf("%.7d", myData->ID());201 stringsort[sTitle] = myData;202 }203 204 //205 // Now walk through the "stringsort" qmap and put them back on the206 // list (in stringsort order).207 //208 for (QMap<QString, Metadata*>::iterator it = stringsort.begin();209 it != stringsort.end();210 it++)211 {212 metaptrs.append(*it);213 }214 }215 216 //217 178 // Build list of videos. 218 179 // 219 180 for (unsigned int count = 0; !metaptrs.isEmpty(); count++) -
mythvideo/mythvideo/videoscan.cpp
103 103 { 104 104 if (*iter == kFileSystem) 105 105 { 106 Metadata newFile(iter.key(), QObject::tr("No Cover"), "", 1895,106 Metadata newFile(iter.key(), QObject::tr("No Cover"), "", "", 1895, 107 107 "00000000", QObject::tr("Unknown"), 108 108 QObject::tr("None"), 0.0, QObject::tr("NR"), 109 109 0, 0, 1); 110 110 111 111 newFile.guessTitle(); 112 newFile.guessTitleSortKey(); 112 113 newFile.dumpToDatabase(); 113 114 } 114 115 -
mythvideo/mythvideo/videofilter.cpp
179 179 switch (orderby) 180 180 { 181 181 case kOrderByTitle : 182 return " ORDER BY title ";182 return " ORDER BY titlesortkey"; 183 183 case kOrderByYearDescending : 184 184 return " ORDER BY year DESC"; 185 185 case kOrderByUserRatingDescending : -
mythvideo/mythvideo/metadata.h
12 12 { 13 13 public: 14 14 Metadata(const QString& lfilename = "", const QString& lcoverfile = "", 15 const QString& ltitle = "", int lyear = 0, const QString& linetref = "", 15 const QString& ltitle = "", const QString& ltitleSortKey = "", 16 int lyear = 0, const QString& linetref = "", 16 17 const QString& ldirector = "", const QString& lplot = "", 17 18 float luserrating = 0.0, const QString& lrating = "", int llength = 0, 18 19 int lid = 0, int lshowlevel = 1, int lchildID = -1, … … 26 27 filename = lfilename; 27 28 coverfile = lcoverfile; 28 29 title = ltitle; 30 titleSortKey = ltitleSortKey; 29 31 year = lyear; 30 32 inetref = linetref; 31 33 director = ldirector; … … 52 54 filename = other.filename; 53 55 coverfile = other.coverfile; 54 56 title = other.title; 57 titleSortKey = other.titleSortKey; 55 58 year = other.year; 56 59 inetref = other.inetref; 57 60 director = other.director; … … 83 86 filename = ""; 84 87 coverfile = ""; 85 88 title = ""; 89 titleSortKey= ""; 86 90 inetref = ""; 87 91 director = ""; 88 92 plot = ""; … … 113 117 const QString& Title() const { return title; } 114 118 void setTitle(const QString& _title) { title = _title; } 115 119 120 const QString& TitleSortKey() const { return titleSortKey; } 121 void setTitleSortKey(const QString& _titleSortKey) 122 { titleSortKey = _titleSortKey; } 123 116 124 int Year() const { return year; } 117 125 void setYear(int _year) { year = _year; } 118 126 … … 179 187 void guessTitle(); 180 188 void eatBraces(const QString& left_brace, const QString& right_brace); 181 189 190 void guessTitleSortKey(); 191 182 192 void dumpToDatabase(); 183 193 void updateDatabase(); 184 194 bool fillDataFromID(); … … 202 212 203 213 204 214 QString title; 215 QString titleSortKey; 205 216 QString inetref; 206 217 QString director; 207 218 QString plot; -
mythvideo/mythvideo/editmetadata.cpp
37 37 38 38 39 39 title_hack = NULL; 40 title_sort_key_hack = NULL; 40 41 player_hack = NULL; 41 42 category_select = NULL; 42 43 level_select = NULL; … … 47 48 coverart_text = NULL; 48 49 done_button = NULL; 49 50 title_editor = NULL; 51 title_sort_key_editor = NULL; 50 52 player_editor = NULL; 51 53 52 54 wireUpTheme(); … … 60 62 { 61 63 title_editor->setText(working_metadata->Title()); 62 64 } 65 66 if(title_sort_key_editor) 67 { 68 title_sort_key_editor->setText(working_metadata->TitleSortKey()); 69 } 63 70 64 71 if (category_select) 65 72 { … … 102 109 child_select->addItem(0, tr("None")); 103 110 104 111 QString q_string = QString("SELECT intid, title FROM videometadata " 105 "ORDER BY title ;");112 "ORDER BY titlesortkey ;"); 106 113 MSqlQuery a_query(MSqlQuery::InitCon()); 107 114 a_query.exec(q_string); 108 115 … … 366 373 working_metadata->setTitle(new_title); 367 374 } 368 375 376 void EditMetadataDialog::setTitleSortKey(QString new_title_sort_key) 377 { 378 working_metadata->setTitleSortKey(new_title_sort_key); 379 } 380 369 381 void EditMetadataDialog::setCategory(int new_category) 370 382 { 371 383 working_metadata->setCategoryID(new_category); … … 453 465 this, SLOT(setTitle(QString))); 454 466 } 455 467 468 title_sort_key_hack = getUIBlackHoleType("title_sort_key_hack"); 469 if(title_sort_key_hack) 470 { 471 title_sort_key_hack->allowFocus(true); 472 QFont f = gContext->GetMediumFont(); 473 title_sort_key_editor = new MythRemoteLineEdit(&f, this); 474 title_sort_key_editor->setFocusPolicy(QWidget::NoFocus); 475 title_sort_key_editor->setGeometry(title_sort_key_hack->getScreenArea()); 476 connect(title_sort_key_hack, SIGNAL(takingFocus()), 477 title_sort_key_editor, SLOT(setFocus())); 478 connect(title_sort_key_editor, SIGNAL(tryingToLooseFocus(bool)), 479 this, SLOT(takeFocusAwayFromEditor(bool))); 480 connect(title_sort_key_editor, SIGNAL(textChanged(QString)), 481 this, SLOT(setTitleSortKey(QString))); 482 } 483 456 484 category_select = getUISelectorType("category_select"); 457 485 if(category_select) 458 486 { … … 529 557 { 530 558 delete title_editor; 531 559 } 560 if(title_sort_key_editor) 561 { 562 delete title_sort_key_editor; 563 } 532 564 if(player_editor) 533 565 { 534 566 delete player_editor;