35
35
FakeSemanticInfoBackEnd::FakeSemanticInfoBackEnd(QObject* parent, InitializeMode mode)
36
36
: AbstractSemanticInfoBackEnd(parent)
37
, mInitializeMode(mode) {
39
<< tagForLabel("beach")
40
<< tagForLabel("mountains")
41
<< tagForLabel("wallpaper")
46
void FakeSemanticInfoBackEnd::storeSemanticInfo(const KUrl& url, const SemanticInfo& semanticInfo) {
47
mSemanticInfoForUrl[url] = semanticInfo;
48
mergeTagsWithAllTags(semanticInfo.mTags);
52
void FakeSemanticInfoBackEnd::mergeTagsWithAllTags(const TagSet& set) {
53
int size = mAllTags.size();
55
if (mAllTags.size() > size) {
56
//emit allTagsUpdated();
61
TagSet FakeSemanticInfoBackEnd::allTags() const {
66
void FakeSemanticInfoBackEnd::refreshAllTags() {
70
void FakeSemanticInfoBackEnd::retrieveSemanticInfo(const KUrl& url) {
71
if (!mSemanticInfoForUrl.contains(url)) {
72
QString urlString = url.url();
73
SemanticInfo semanticInfo;
74
if (mInitializeMode == InitializeRandom) {
75
semanticInfo.mRating = int(urlString.length()) % 6;
76
semanticInfo.mDescription = url.fileName();
77
QStringList lst = url.path().split('/');
78
Q_FOREACH(const QString& token, lst) {
79
if (!token.isEmpty()) {
80
semanticInfo.mTags << '#' + token.toLower();
83
semanticInfo.mTags << QString("#length-%1").arg(url.fileName().length());
85
mergeTagsWithAllTags(semanticInfo.mTags);
87
semanticInfo.mRating = 0;
89
mSemanticInfoForUrl[url] = semanticInfo;
91
emit semanticInfoRetrieved(url, mSemanticInfoForUrl.value(url));
95
QString FakeSemanticInfoBackEnd::labelForTag(const SemanticInfoTag& tag) const {
96
return tag[1].toUpper() + tag.mid(2);
100
SemanticInfoTag FakeSemanticInfoBackEnd::tagForLabel(const QString& label) {
101
return '#' + label.toLower();
37
, mInitializeMode(mode)
40
<< tagForLabel("beach")
41
<< tagForLabel("mountains")
42
<< tagForLabel("wallpaper")
46
void FakeSemanticInfoBackEnd::storeSemanticInfo(const KUrl& url, const SemanticInfo& semanticInfo)
48
mSemanticInfoForUrl[url] = semanticInfo;
49
mergeTagsWithAllTags(semanticInfo.mTags);
52
void FakeSemanticInfoBackEnd::mergeTagsWithAllTags(const TagSet& set)
54
int size = mAllTags.size();
56
if (mAllTags.size() > size) {
57
//emit allTagsUpdated();
61
TagSet FakeSemanticInfoBackEnd::allTags() const
66
void FakeSemanticInfoBackEnd::refreshAllTags()
70
void FakeSemanticInfoBackEnd::retrieveSemanticInfo(const KUrl& url)
72
if (!mSemanticInfoForUrl.contains(url)) {
73
QString urlString = url.url();
74
SemanticInfo semanticInfo;
75
if (mInitializeMode == InitializeRandom) {
76
semanticInfo.mRating = int(urlString.length()) % 6;
77
semanticInfo.mDescription = url.fileName();
78
QStringList lst = url.path().split('/');
79
Q_FOREACH(const QString & token, lst) {
80
if (!token.isEmpty()) {
81
semanticInfo.mTags << '#' + token.toLower();
84
semanticInfo.mTags << QString("#length-%1").arg(url.fileName().length());
86
mergeTagsWithAllTags(semanticInfo.mTags);
88
semanticInfo.mRating = 0;
90
mSemanticInfoForUrl[url] = semanticInfo;
92
emit semanticInfoRetrieved(url, mSemanticInfoForUrl.value(url));
95
QString FakeSemanticInfoBackEnd::labelForTag(const SemanticInfoTag& tag) const
97
return tag[1].toUpper() + tag.mid(2);
100
SemanticInfoTag FakeSemanticInfoBackEnd::tagForLabel(const QString& label)
102
return '#' + label.toLower();