MythTV  master
videometadatautil.cpp
Go to the documentation of this file.
1 #include <QReadWriteLock>
2 #include <QHash>
3 #include <QUrl>
4 
5 #include "videometadatautil.h"
6 #include "mythlogging.h"
7 #include "mythdb.h"
8 
9 #define LOC QString("VideoMetaDataUtil: ")
10 
11 static QReadWriteLock art_path_map_lock;
12 typedef QPair< QString, QString > ArtPair;
13 static QMultiHash<QString, ArtPair> art_path_map;
14 typedef QList< ArtPair > ArtList;
15 
16 QString VideoMetaDataUtil::GetArtPath(const QString &pathname,
17  const QString &type)
18 {
19  QString basename = pathname.section('/', -1);
20 
21  if (basename == pathname)
22  {
23  LOG(VB_GENERAL, LOG_WARNING, LOC +
24  "Programmer Error: Cannot determine art path\n\t\t\t"
25  "until the ProgramInfo pathname has been fully resolved.");
26  return QString();
27  }
28 
29  art_path_map_lock.lockForRead();
30  ArtList ret(art_path_map.values(basename));
31  art_path_map_lock.unlock();
32  for (ArtList::const_iterator i = ret.begin();
33  i != ret.end(); ++i)
34  {
35  if ((*i).first == type)
36  return (*i).second;
37  }
38 
39  QString fn = basename;
40  fn.prepend("%");
41 
42  QString dbcolumn;
43  if (type == "Coverart")
44  dbcolumn = "coverfile";
45  else if (type == "Fanart")
46  dbcolumn = "fanart";
47  else if (type == "Banners")
48  dbcolumn = "banner";
49  else if (type == "Screenshots")
50  dbcolumn = "screenshot";
51 
52  QString querystr = QString("SELECT %1 "
53  "FROM videometadata WHERE filename "
54  "LIKE :FILENAME").arg(dbcolumn);
55 
57  query.prepare(querystr);
58  query.bindValue(":FILENAME", fn);
59 
60  QString artpath;
61  if (query.exec() && query.next())
62  artpath = query.value(0).toString();
63 
64  if (!artpath.startsWith('/') && pathname.startsWith("myth://"))
65  {
66  const QString& workURL = pathname;
67  QUrl baseURL(workURL);
68  baseURL.setUserName(type);
69  QString finalURL =
70  baseURL.toString(QUrl::RemovePath) + '/' + artpath;
71  artpath = finalURL;
72  }
73 
74  ArtPair ins(type, artpath);
75  art_path_map_lock.lockForWrite();
76  art_path_map.insert(basename, ins);
77  art_path_map_lock.unlock();
78 
79  return artpath;
80 }
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:782
static QReadWriteLock art_path_map_lock
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:863
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
QVariant value(int i) const
Definition: mythdbcon.h:198
QPair< QString, QString > ArtPair
QList< ArtPair > ArtList
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
static QMultiHash< QString, ArtPair > art_path_map
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:807
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
#define LOC
static QString GetArtPath(const QString &pathname, const QString &type)