~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to lib/semanticinfo/fakesemanticinfobackend.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
Import upstream version 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// vim: set tabstop=4 shiftwidth=4 noexpandtab:
 
1
// vim: set tabstop=4 shiftwidth=4 expandtab:
2
2
/*
3
3
Gwenview: an image viewer
4
4
Copyright 2008 Aurélien Gâteau <agateau@kde.org>
29
29
 
30
30
// Local
31
31
 
32
 
namespace Gwenview {
33
 
 
 
32
namespace Gwenview
 
33
{
34
34
 
35
35
FakeSemanticInfoBackEnd::FakeSemanticInfoBackEnd(QObject* parent, InitializeMode mode)
36
36
: AbstractSemanticInfoBackEnd(parent)
37
 
, mInitializeMode(mode) {
38
 
        mAllTags
39
 
                << tagForLabel("beach")
40
 
                << tagForLabel("mountains")
41
 
                << tagForLabel("wallpaper")
42
 
                ;
43
 
}
44
 
 
45
 
 
46
 
void FakeSemanticInfoBackEnd::storeSemanticInfo(const KUrl& url, const SemanticInfo& semanticInfo) {
47
 
        mSemanticInfoForUrl[url] = semanticInfo;
48
 
        mergeTagsWithAllTags(semanticInfo.mTags);
49
 
}
50
 
 
51
 
 
52
 
void FakeSemanticInfoBackEnd::mergeTagsWithAllTags(const TagSet& set) {
53
 
        int size = mAllTags.size();
54
 
        mAllTags |= set;
55
 
        if (mAllTags.size() > size) {
56
 
                //emit allTagsUpdated();
57
 
        }
58
 
}
59
 
 
60
 
 
61
 
TagSet FakeSemanticInfoBackEnd::allTags() const {
62
 
        return mAllTags;
63
 
}
64
 
 
65
 
 
66
 
void FakeSemanticInfoBackEnd::refreshAllTags() {
67
 
}
68
 
 
69
 
 
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();
81
 
                                }
82
 
                        }
83
 
                        semanticInfo.mTags << QString("#length-%1").arg(url.fileName().length());
84
 
 
85
 
                        mergeTagsWithAllTags(semanticInfo.mTags);
86
 
                } else {
87
 
                        semanticInfo.mRating = 0;
88
 
                }
89
 
                mSemanticInfoForUrl[url] = semanticInfo;
90
 
        }
91
 
        emit semanticInfoRetrieved(url, mSemanticInfoForUrl.value(url));
92
 
}
93
 
 
94
 
 
95
 
QString FakeSemanticInfoBackEnd::labelForTag(const SemanticInfoTag& tag) const {
96
 
        return tag[1].toUpper() + tag.mid(2);
97
 
}
98
 
 
99
 
 
100
 
SemanticInfoTag FakeSemanticInfoBackEnd::tagForLabel(const QString& label) {
101
 
        return '#' + label.toLower();
102
 
}
103
 
 
 
37
, mInitializeMode(mode)
 
38
{
 
39
    mAllTags
 
40
            << tagForLabel("beach")
 
41
            << tagForLabel("mountains")
 
42
            << tagForLabel("wallpaper")
 
43
            ;
 
44
}
 
45
 
 
46
void FakeSemanticInfoBackEnd::storeSemanticInfo(const KUrl& url, const SemanticInfo& semanticInfo)
 
47
{
 
48
    mSemanticInfoForUrl[url] = semanticInfo;
 
49
    mergeTagsWithAllTags(semanticInfo.mTags);
 
50
}
 
51
 
 
52
void FakeSemanticInfoBackEnd::mergeTagsWithAllTags(const TagSet& set)
 
53
{
 
54
    int size = mAllTags.size();
 
55
    mAllTags |= set;
 
56
    if (mAllTags.size() > size) {
 
57
        //emit allTagsUpdated();
 
58
    }
 
59
}
 
60
 
 
61
TagSet FakeSemanticInfoBackEnd::allTags() const
 
62
{
 
63
    return mAllTags;
 
64
}
 
65
 
 
66
void FakeSemanticInfoBackEnd::refreshAllTags()
 
67
{
 
68
}
 
69
 
 
70
void FakeSemanticInfoBackEnd::retrieveSemanticInfo(const KUrl& url)
 
71
{
 
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();
 
82
                }
 
83
            }
 
84
            semanticInfo.mTags << QString("#length-%1").arg(url.fileName().length());
 
85
 
 
86
            mergeTagsWithAllTags(semanticInfo.mTags);
 
87
        } else {
 
88
            semanticInfo.mRating = 0;
 
89
        }
 
90
        mSemanticInfoForUrl[url] = semanticInfo;
 
91
    }
 
92
    emit semanticInfoRetrieved(url, mSemanticInfoForUrl.value(url));
 
93
}
 
94
 
 
95
QString FakeSemanticInfoBackEnd::labelForTag(const SemanticInfoTag& tag) const
 
96
{
 
97
    return tag[1].toUpper() + tag.mid(2);
 
98
}
 
99
 
 
100
SemanticInfoTag FakeSemanticInfoBackEnd::tagForLabel(const QString& label)
 
101
{
 
102
    return '#' + label.toLower();
 
103
}
104
104
 
105
105
} // namespace