Go to the documentation of this file.
13 template <
typename T,
typename arg_type>
16 explicit call_sort(T &c) : m_c(c) {}
18 bool operator()(
const arg_type &lhs,
const arg_type &rhs)
20 return m_c.sort(lhs, rhs);
41 m_insertSql = QString(
"INSERT INTO %1 (%2) VALUES (:NAME)")
43 m_fillSql = QString(
"SELECT %1, %2 FROM %3")
45 m_deleteSql = QString(
"DELETE FROM %1 WHERE %2 = :ID")
63 int add(
const QString &name)
74 if (query.
exec(
"SELECT LAST_INSERT_ID()") && query.
next())
76 id = query.
value(0).toInt();
77 m_entries.insert(entry_map::value_type(
id, name));
88 bool get(
int id, QString &value)
120 bool exists(
const QString &name,
int *
id =
nullptr)
144 call_sort<SingleValueImp, entry>(*
this));
164 entry_map::iterator
find(
const QString &name)
168 if (
p->second == name)
184 int id = query.
value(0).toInt();
185 QString val = query.
value(1).toString();
186 m_entries.insert(entry_map::value_type(
id, val));
265 m_insertSql = QString(
"INSERT INTO %1 (%2, %3) VALUES (:ID, :VALUE)")
267 m_fillSql = QString(
"SELECT %1, %2 FROM %3 ORDER BY %4")
289 int add(
int id,
int value)
291 bool db_insert =
false;
296 auto v =
std::find(va.begin(), va.end(), value);
307 e.
values.push_back(value);
308 m_valMap.insert(id_map::value_type(
id, e));
342 p->second.values.end(), value);
343 if (vp !=
p->second.values.end())
346 QString del_query = QString(
"DELETE FROM %1 WHERE %2 = :ID AND "
356 p->second.values.erase(vp);
367 QString del_query = QString(
"DELETE FROM %1 WHERE %2 = :ID")
385 std::find(
p->second.values.begin(),
p->second.values.end(),
387 return vp !=
p->second.values.end();
409 int id = query.
value(0).toInt();
410 int val = query.
value(1).toInt();
420 p =
m_valMap.insert(id_map::value_type(
id, e)).first;
423 p->second.values.push_back(val);
605 query.
prepare(
"UPDATE videotypes SET extension = :EXT, "
606 "playcommand = :PLAYCMD, f_ignore = :IGNORED, "
607 "use_default = :USEDEFAULT WHERE intid = :ID");
612 query.
prepare(
"INSERT INTO videotypes (extension, playcommand, "
613 "f_ignore, use_default) VALUES "
614 "(:EXT, :PLAYCMD, :IGNORED, :USEDEFAULT)");
626 if (query.
exec(
"SELECT LAST_INSERT_ID()") && query.
next())
628 ret_fa.
id = query.
value(0).toUInt();
635 *existing_fa = ret_fa;
672 query.
prepare(
"DELETE FROM videotypes WHERE intid = :ID");
691 ext_ignore.emplace_back(fa.extension, fa.ignore);
716 if (query.
exec(
"SELECT intid, extension, playcommand, f_ignore, "
717 "use_default FROM videotypes"))
722 query.
value(1).toString(),
723 query.
value(2).toString(),
724 query.
value(3).toBool(),
725 query.
value(4).toBool());
731 association_list::iterator
find(
const QString &ext)
736 if (
p->extension.length() == ext.length() &&
737 ext.indexOf(
p->extension) == 0)
745 association_list::iterator
find(
unsigned int id)
750 if (
p->id ==
id)
return p;
755 association_list::const_iterator
cfind(
const QString &ext)
const
760 if (
p->extension.length() == ext.length() &&
761 ext.indexOf(
p->extension) == 0)
769 association_list::const_iterator
cfind(
unsigned int id)
const
774 if (
p->id ==
id)
return p;
bool isActive(void) const
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
QSqlQuery wrapper that fetches a DB connection from the connection pool.
const entry_list & getList()
bool exists(int id, int value)
void getExtensionIgnoreList(ext_ignore_list &ext_ignore) const
int add(const QString &name)
bool naturalSortCompare(const QString &a, const QString &b, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
naturalCompare as a std::sort compatible function (ignoring the third parameter, which is never used)...
void getExtensionIgnoreList(ext_ignore_list &ext_ignore) const
SimpleCleanup< SingleValueImp > m_cleanStub
association_list::const_iterator cfind(unsigned int id) const
QVariant value(int i) const
MultiValueImp(QString table_name, QString id_name, QString value_name)
bool add(file_association &fa)
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
SimpleCleanup< MultiValueImp > m_cleanStub
bool remove(unsigned int id)
const association_list & getList() const
entry_map::iterator find(const QString &name)
SingleValueImp(QString table_name, QString id_name, QString value_name)
std::map< int, QString > entry_map
association_list::iterator find(const QString &ext)
static VideoGenreMap & getGenreMap()
int add(const QString &name)
bool get(int id, QString &value)
static VideoGenre & getGenre()
int add(int id, int value)
bool exists(int id, int value)
std::vector< entry > entry_list
std::vector< std::pair< QString, bool > > ext_ignore_list
bool get(unsigned int id, file_association &val) const
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
std::vector< file_association > association_list
static void DBError(const QString &where, const MSqlQuery &query)
FileAssociationsImp()=default
static VideoCountry & getCountry()
bool get(const QString &ext, file_association &val) const
association_list::iterator find(unsigned int id)
static VideoCategory & GetCategory()
association_list m_fileAssociations
FileAssociations::association_list association_list
std::vector< long > values_type
std::pair< int, QString > entry
association_list::const_iterator cfind(const QString &ext) const
static VideoCountryMap & getCountryMap()
bool exists(const QString &name, int *id=nullptr)
static FileAssociations & getFileAssociation()
FileAssociations::ext_ignore_list ext_ignore_list
void remove(int id, int value)
const entry_list & getList()
virtual ~SingleValueImp()=default
static VideoCast & GetCast()
bool get(int id, entry &values)
virtual bool sort(const entry &lhs, const entry &rhs)
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
bool get(int id, entry &values)
void remove(int id, int value)
class FileAssociationsImp * m_imp
bool remove(unsigned int id)
int add(int id, int value)
bool get(unsigned int id, file_association &val) const
std::vector< entry > entry_list
static VideoCastMap & getCastMap()
const association_list & getList() const
bool add(file_association &fa)
std::map< int, entry > id_map
bool get(int id, QString &category)
static pid_list_t::iterator find(const PIDInfoMap &map, pid_list_t &list, pid_list_t::iterator begin, pid_list_t::iterator end, bool find_open)
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.