Ticket #1678: mythplugins-mythvideo-titlesortkey_in_database.patch

File mythplugins-mythvideo-titlesortkey_in_database.patch, 15.0 KB (added by sphery <mtdean@…>, 20 years ago)
  • mythvideo/mythvideo/video-ui.xml

     
    11021102                <value>Unique Player Command:</value>
    11031103            </textarea>
    11041104
     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
    11051111            <!--
    11061112                    Widgets
    11071113            -->
     
    11671173                <area>310,445,300,40</area>
    11681174            </blackhole>
    11691175
     1176            <blackhole name="title_sort_key_hack" draworder="0">
     1177                <area>310,490,300,40</area>
     1178            </blackhole>
     1179
    11701180            <textbutton name="done_button" draworder="0">
    1171                 <position>310,505</position>
     1181                <position>310,550</position>
    11721182                <font>display</font>
    11731183                <image function="on" filename="mv_large_text_button_on.png"></image>
    11741184                <image function="off" filename="mv_large_text_button_off.png"></image>
  • mythvideo/mythvideo/metadata.cpp

     
    204204    MSqlQuery query(MSqlQuery::InitCon());
    205205    query.prepare("SELECT title,director,plot,rating,year,userrating,"
    206206                  "length,filename,showlevel,coverfile,inetref,childid,"
    207                   "browse,playcommand, videocategory.category "
     207                  "browse,playcommand, videocategory.category,titlesortkey "
    208208                  " FROM videometadata LEFT JOIN videocategory"
    209209                  " ON videometadata.category = videocategory.intid"
    210210                  "  WHERE videometadata.intid= :ID ;");
     
    232232        browse = query.value(12).toBool();
    233233        playcommand = query.value(13).toString();
    234234        category = query.value(14).toString();
     235        titleSortKey = query.value(15).toString();
    235236
    236237        // Genres
    237238        fillGenres();
     
    276277        userrating = 0.0;
    277278
    278279    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, "
    283284                    ":FILENAME, :SHOWLEVEL, :COVERFILE, :INETREF, "
    284285                    ":BROWSE );");
    285286    a_query.bindValue(":TITLE", title.utf8());
     287    a_query.bindValue(":TITLESORTKEY", titleSortKey.utf8());
    286288    a_query.bindValue(":DIRECTOR", director.utf8());
    287289    a_query.bindValue(":PLOT", plot.utf8());
    288290    a_query.bindValue(":RATING", rating.utf8());
     
    379381    }
    380382}
    381383
     384void 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
    382395void Metadata::updateDatabase()
    383396{
    384397    if (title == "")
    385398        guessTitle();
     399    if (titleSortKey == "")
     400        guessTitleSortKey();
    386401    if (director == "")
    387402        director = QObject::tr("Unknown");
    388403    if (plot == "")
     
    398413
    399414    MSqlQuery query(MSqlQuery::InitCon());
    400415    query.prepare("UPDATE videometadata SET title = :TITLE, "
     416                  "titlesortkey = :TITLESORTKEY, "
    401417                  "director = :DIRECTOR, plot = :PLOT, rating= :RATING, "
    402418                  "year = :YEAR, userrating = :USERRATING, length = :LENGTH, "
    403419                  "filename = :FILENAME, showlevel = :SHOWLEVEL, "
     
    406422                  "childid = :CHILDID, category = :CATEGORY "
    407423                  "WHERE intid = :INTID");
    408424    query.bindValue(":TITLE", title.utf8());
     425    query.bindValue(":TITLESORTKEY", titleSortKey.utf8());
    409426    query.bindValue(":DIRECTOR", director.utf8());
    410427    query.bindValue(":PLOT", plot.utf8());
    411428    query.bindValue(":RATING", rating.utf8());
  • mythvideo/mythvideo/dbcheck.cpp

     
    88#include "mythtv/mythcontext.h"
    99#include "mythtv/mythdbcon.h"
    1010
    11 const QString currentDatabaseVersion = "1008";
     11const QString currentDatabaseVersion = "1009";
    1212
    1313static void UpdateDBVersionNumber(const QString &newnumber)
    1414{
     
    216216        performActualUpdate(updates, "1008", dbver);
    217217    }
    218218
     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
    219232}
  • mythvideo/mythvideo/editmetadata.h

     
    4545    void takeFocusAwayFromEditor(bool up_or_down);
    4646    void saveAndExit();
    4747    void setTitle(QString new_title);
     48    void setTitleSortKey(QString new_title_sort_key);
    4849    void setCategory(int new_category);
    4950    void setPlayer(QString new_player);
    5051    void setLevel(int new_level);
     
    6465    MythRemoteLineEdit  *title_editor;
    6566    UIBlackHoleType     *title_hack;
    6667
     68    MythRemoteLineEdit  *title_sort_key_editor;
     69    UIBlackHoleType     *title_sort_key_hack;
     70
    6771    MythRemoteLineEdit  *player_editor;
    6872    UIBlackHoleType     *player_hack;
    6973
  • mythvideo/mythvideo/videomanager.cpp

     
    437437        curitem->setUserRating(data["UserRating"].toFloat());
    438438        curitem->setRating(data["MovieRating"]);
    439439        curitem->setLength(data["Runtime"].toInt());
     440        curitem->guessTitleSortKey();
    440441       
    441442        //movieGenres
    442443        movieGenres.clear();
     
    14791480    QString coverFile = tr("No Cover");
    14801481
    14811482    curitem->guessTitle();
     1483    curitem->guessTitleSortKey();
    14821484    curitem->setCoverFile(coverFile);
    14831485    curitem->setYear(1895);
    14841486    curitem->setInetRef("00000000");
  • mythvideo/mythvideo/videolist.cpp

     
    175175    }
    176176
    177177    //
    178     //  If sorting by title, re-sort by hand because the SQL sort doesn't
    179     //  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" will
    181     //  be incorrectly alphabetized, because the "A" is actually significant.
    182     //  The set of ignored prefixes should be a database option, or each
    183     //  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 the
    189         //  "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 title
    200             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 the
    206         //  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     //
    217178    //  Build list of videos.
    218179    //
    219180    for (unsigned int count = 0; !metaptrs.isEmpty(); count++)
  • mythvideo/mythvideo/videoscan.cpp

     
    103103    {
    104104        if (*iter == kFileSystem)
    105105        {
    106             Metadata newFile(iter.key(), QObject::tr("No Cover"), "", 1895,
     106            Metadata newFile(iter.key(), QObject::tr("No Cover"), "", "", 1895,
    107107                             "00000000", QObject::tr("Unknown"),
    108108                             QObject::tr("None"), 0.0, QObject::tr("NR"),
    109109                             0, 0, 1);
    110110           
    111111            newFile.guessTitle();
     112            newFile.guessTitleSortKey();
    112113            newFile.dumpToDatabase();
    113114        }
    114115       
  • mythvideo/mythvideo/videofilter.cpp

     
    179179    switch (orderby)
    180180    {
    181181        case kOrderByTitle :
    182             return " ORDER BY title";
     182            return " ORDER BY titlesortkey";
    183183        case kOrderByYearDescending :
    184184            return " ORDER BY year DESC";
    185185        case kOrderByUserRatingDescending :
  • mythvideo/mythvideo/metadata.h

     
    1212{
    1313  public:
    1414    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 = "",
    1617             const QString& ldirector = "", const QString& lplot = "",
    1718             float luserrating = 0.0, const QString& lrating = "", int llength = 0,
    1819             int lid = 0, int lshowlevel = 1, int lchildID = -1,
     
    2627        filename = lfilename;
    2728        coverfile = lcoverfile;
    2829        title = ltitle;
     30        titleSortKey = ltitleSortKey;
    2931        year = lyear;
    3032        inetref = linetref;
    3133        director = ldirector;
     
    5254        filename = other.filename;
    5355        coverfile = other.coverfile;
    5456        title = other.title;
     57        titleSortKey = other.titleSortKey;
    5558        year = other.year;
    5659        inetref = other.inetref;
    5760        director = other.director;
     
    8386        filename    = "";
    8487        coverfile   = "";
    8588        title       = "";
     89        titleSortKey= "";
    8690        inetref     = "";
    8791        director    = "";
    8892        plot        = "";
     
    113117    const QString& Title() const { return title; }
    114118    void setTitle(const QString& _title) { title = _title; }
    115119   
     120    const QString& TitleSortKey() const { return titleSortKey; }
     121    void setTitleSortKey(const QString& _titleSortKey)
     122        { titleSortKey = _titleSortKey; }
     123
    116124    int Year() const { return year; }
    117125    void setYear(int _year) { year = _year; }
    118126
     
    179187    void guessTitle();
    180188    void eatBraces(const QString& left_brace, const QString& right_brace);
    181189
     190    void guessTitleSortKey();
     191
    182192    void dumpToDatabase();
    183193    void updateDatabase();
    184194    bool fillDataFromID();
     
    202212   
    203213
    204214    QString title;
     215    QString titleSortKey;
    205216    QString inetref;
    206217    QString director;
    207218    QString plot;
  • mythvideo/mythvideo/editmetadata.cpp

     
    3737   
    3838
    3939    title_hack = NULL;
     40    title_sort_key_hack = NULL;
    4041    player_hack = NULL;
    4142    category_select = NULL;
    4243    level_select = NULL;
     
    4748    coverart_text = NULL;
    4849    done_button = NULL;
    4950    title_editor = NULL;
     51    title_sort_key_editor = NULL;
    5052    player_editor = NULL;
    5153   
    5254    wireUpTheme();
     
    6062    {
    6163        title_editor->setText(working_metadata->Title());
    6264    }
     65
     66    if(title_sort_key_editor)
     67    {
     68        title_sort_key_editor->setText(working_metadata->TitleSortKey());
     69    }
    6370   
    6471    if (category_select)
    6572    {
     
    102109        child_select->addItem(0, tr("None"));
    103110
    104111        QString q_string = QString("SELECT intid, title FROM videometadata "
    105                                    "ORDER BY title ;");
     112                                   "ORDER BY titlesortkey ;");
    106113        MSqlQuery a_query(MSqlQuery::InitCon());
    107114        a_query.exec(q_string);
    108115
     
    366373    working_metadata->setTitle(new_title);
    367374}
    368375
     376void EditMetadataDialog::setTitleSortKey(QString new_title_sort_key)
     377{
     378    working_metadata->setTitleSortKey(new_title_sort_key);
     379}
     380
    369381void EditMetadataDialog::setCategory(int new_category)
    370382{
    371383    working_metadata->setCategoryID(new_category);
     
    453465                this, SLOT(setTitle(QString)));
    454466    }
    455467
     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
    456484    category_select = getUISelectorType("category_select");
    457485    if(category_select)
    458486    {
     
    529557    {
    530558        delete title_editor;
    531559    }
     560    if(title_sort_key_editor)
     561    {
     562        delete title_sort_key_editor;
     563    }
    532564    if(player_editor)
    533565    {
    534566        delete player_editor;