Ticket #13632: 0001-Resolve-TODO-in-metadatagrabber-to-initialize-static.patch

File 0001-Resolve-TODO-in-metadatagrabber-to-initialize-static.patch, 4.2 KB (added by Gary Buhrmaster, 3 months ago)

Resolve TODO in metadatagrabber

  • mythtv/libs/libmythmetadata/metadatagrabber.cpp

    From 7d0e9e526f0d62f19cd48799f8a23cf008e00dc9 Mon Sep 17 00:00:00 2001
    From: Gary Buhrmaster <gary.buhrmaster@gmail.com>
    Date: Sat, 13 Jun 2020 00:18:29 +0000
    Subject: [PATCH] Resolve TODO in metadatagrabber to initialize static QMap
    
    ---
     .../libs/libmythmetadata/metadatagrabber.cpp  | 78 +++++--------------
     1 file changed, 21 insertions(+), 57 deletions(-)
    
    diff --git a/mythtv/libs/libmythmetadata/metadatagrabber.cpp b/mythtv/libs/libmythmetadata/metadatagrabber.cpp
    index 50fcf40a51..4ec9fd91eb 100644
    a b struct GrabberOpts { 
    3030    QString     m_def;
    3131};
    3232
    33 // TODO
    34 // it would be nice to statically compile these, but I can't manage to get it
    35 // to compile.  apparently initializer lists are supported in QT5/CPP11 that
    36 // will make this work.  for now, use a lock and initialize on first access.
    37 // https://bugreports.qt-project.org/browse/QTBUG-25679
    38 static QMap<GrabberType, GrabberOpts> grabberTypes;
    39 static QMap<QString, GrabberType> grabberTypeStrings;
    40 static bool initialized = false;
    41 static QMutex typeLock;
    42 
    43 static GrabberOpts GrabberOptsMaker(QString thepath, QString thesetting, QString thedefault)
    44 {
    45     GrabberOpts opts;
    46 
    47     opts.m_path = std::move(thepath);
    48     opts.m_setting = std::move(thesetting);
    49     opts.m_def = std::move(thedefault);
    50 
    51     return opts;
    52 }
    53 
    54 static void InitializeStaticMaps(void)
    55 {
    56     QMutexLocker lock(&typeLock);
    57 
    58     if (!initialized)
    59     {
    60         grabberTypes[kGrabberMovie] =
    61               GrabberOptsMaker ("%1metadata/Movie/",
    62                                 "MovieGrabber",
    63                                 "metadata/Movie/tmdb3.py" );
    64         grabberTypes[kGrabberTelevision] =
    65              GrabberOptsMaker ( "%1metadata/Television/",
    66                                 "TelevisionGrabber",
    67                                 "metadata/Television/ttvdb.py" );
    68         grabberTypes[kGrabberGame]       =
    69              GrabberOptsMaker ( "%1metadata/Game/",
    70                                 "mythgame.MetadataGrabber",
    71                                 "metadata/Game/giantbomb.py" );
    72         grabberTypes[kGrabberMusic]      =
    73              GrabberOptsMaker ( "%1metadata/Music",
    74                                 "",
    75                                 "" );
    76 
    77         grabberTypeStrings["movie"]      = kGrabberMovie;
    78         grabberTypeStrings["television"] = kGrabberTelevision;
    79         grabberTypeStrings["game"]       = kGrabberGame;
    80         grabberTypeStrings["music"]      = kGrabberMusic;
    81 
    82 
    83         initialized = true;
    84     }
    85 }
     33static QMap<GrabberType, GrabberOpts> grabberTypes {
     34    { kGrabberMovie,      { "%1metadata/Movie/",
     35                            "MovieGrabber",
     36                            "metadata/Movie/tmdb3.py" } },
     37    { kGrabberTelevision, { "%1metadata/Television/",
     38                            "TelevisionGrabber",
     39                            "metadata/Television/ttvdb.py" } },
     40    { kGrabberGame,       { "%1metadata/Game/",
     41                            "mythgame.MetadataGrabber",
     42                            "metadata/Game/giantbomb.py" } },
     43    { kGrabberMusic,      { "%1metadata/Music",
     44                            "",
     45                            "" } }
     46};
     47
     48static QMap<QString, GrabberType> grabberTypeStrings {
     49    { "movie",      kGrabberMovie },
     50    { "television", kGrabberTelevision },
     51    { "game",       kGrabberGame },
     52    { "music",      kGrabberMusic }
     53};
    8654
    8755GrabberList MetaGrabberScript::GetList(bool refresh)
    8856{
    GrabberList MetaGrabberScript::GetList(const QString &type, bool refresh) 
    10270GrabberList MetaGrabberScript::GetList(GrabberType type,
    10371                                       bool refresh)
    10472{
    105     InitializeStaticMaps();
    106 
    10773    GrabberList tmpGrabberList;
    10874    GrabberList retGrabberList;
    10975    {
    MetaGrabberScript MetaGrabberScript::GetType(const QString &type) 
    196162
    197163MetaGrabberScript MetaGrabberScript::GetType(const GrabberType type)
    198164{
    199     InitializeStaticMaps();
    200 
    201165    QString cmd = gCoreContext->GetSetting(grabberTypes[type].m_setting,
    202166                                           grabberTypes[type].m_def);
    203167