1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
Copyright (C) 2005-2010 Jesper K. Pedersen <blackie@kde.org>
Copyright (C) 2006-2010 Tuomas Suutari <thsuut@utu.fi>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (see the file COPYING); if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301 USA.
*/
#include "SQLTagCategory.h"
#include "QueryHelper.h"
#include <QList>
SQLDB::SQLTagCategory::SQLTagCategory(QueryHelper* queryHelper,
int categoryId):
_qh(queryHelper),
_categoryId(categoryId)
{
}
QString SQLDB::SQLTagCategory::name() const
{
if (_name.isNull())
_name = _qh->categoryName(_categoryId);
return _name;
}
QString SQLDB::SQLTagCategory::iconName() const
{
return _qh->categoryIcon(_categoryId);
}
void SQLDB::SQLTagCategory::setIconName(const QString& name)
{
_qh->changeCategoryIcon(_categoryId, name);
emit changed();
}
DB::Category::ViewType SQLDB::SQLTagCategory::viewType() const
{
return _qh->categoryViewType(_categoryId);
}
void SQLDB::SQLTagCategory::setViewType(ViewType type)
{
_qh->changeCategoryViewType(_categoryId, type);
emit changed();
}
bool SQLDB::SQLTagCategory::doShow() const
{
return _qh->categoryVisible(_categoryId);
}
void SQLDB::SQLTagCategory::setDoShow(bool b)
{
_qh->changeCategoryVisible(_categoryId, b);
emit changed();
}
QStringList SQLDB::SQLTagCategory::items() const
{
return _qh->tagNamesOfCategory(_categoryId);
}
void SQLDB::SQLTagCategory::setItems(const QStringList& items)
{
_qh->executeStatement("DELETE FROM tag "
"WHERE category_id=? AND name NOT IN (?)",
QueryHelper::Bindings() <<
_categoryId << QVariant(toVariantList(items)));
addOrReorderItems(items);
}
void SQLDB::SQLTagCategory::addOrReorderItems(const QStringList& items)
{
uint position = items.count();
for (QStringList::const_iterator it = items.begin();
it != items.end(); ++it ) {
if (_qh->executeQuery("SELECT COUNT(*) FROM tag "
"WHERE category_id=? AND name=?",
QueryHelper::Bindings() << _categoryId << *it
).firstItem().toUInt() == 0) {
_qh->executeStatement("INSERT INTO tag (name, category_id, position) "
"VALUES (?, ?, ?)",
QueryHelper::Bindings() << *it <<
_categoryId << position);
}
else {
_qh->executeStatement("UPDATE tag SET position=? "
"WHERE name=? AND category_id=?",
QueryHelper::Bindings() <<
position << *it << _categoryId);
}
--position;
}
}
void SQLDB::SQLTagCategory::addItem(const QString& item)
{
_qh->insertTagFirst(_categoryId, item);
}
void SQLDB::SQLTagCategory::removeItem(const QString& item)
{
_qh->removeTag(_categoryId, item);
emit itemRemoved(item);
}
void SQLDB::SQLTagCategory::renameItem(const QString& oldValue,
const QString& newValue)
{
_qh->executeStatement("UPDATE tag SET name=? "
"WHERE name=? AND category_id=?",
QueryHelper::Bindings() <<
newValue << oldValue << _categoryId);
emit itemRenamed(oldValue, newValue);
}
int SQLDB::SQLTagCategory::thumbnailSize() const
{
return _qh->executeQuery("SELECT thumbsize FROM category WHERE id=?",
QueryHelper::Bindings() <<
_categoryId).firstItem().toInt();
}
void SQLDB::SQLTagCategory::setThumbnailSize(int size)
{
_qh->executeStatement("UPDATE category SET thumbsize=? WHERE id=?",
QueryHelper::Bindings() << size << _categoryId);
}
QMap<QString, uint>
SQLDB::SQLTagCategory::classify(const DB::ImageSearchInfo& scope,
DB::MediaType typemask) const
{
QList<DB::RawId>* scopePointer;
QList<DB::RawId> includedFiles;
if (scope.isNull())
scopePointer = 0;
else {
includedFiles = _qh->searchMediaItems(scope, typemask);
scopePointer = &includedFiles;
}
return _qh->classify(name(), typemask, scopePointer);
}
#include "SQLTagCategory.moc"
|