~ubuntu-branches/ubuntu/maverick/kdebase/maverick-updates

« back to all changes in this revision

Viewing changes to apps/dolphin/src/dolphinmodel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Debian Qt/KDE Maintainers, Martin Alfke, Modestas Vainius
  • Date: 2010-05-01 23:37:50 UTC
  • mfrom: (0.7.4 upstream) (0.4.4 experimental)
  • mto: This revision was merged to the branch mainline in revision 285.
  • Revision ID: james.westby@ubuntu.com-20100501233750-maq4i4sh8ymjbneb
Tags: 4:4.4.3-1
* New upstream release:
  - Konsole does not crash when closing a broken restored session.
    (Closes: #555831)
  - Konqueror does not crash when closing fast a tab. (Closes: #441298)

[Martin Alfke]
* Update of debian/copyright for kde 4.4

[ Modestas Vainius ]
* Bump kde-sc-dev-latest build dependency to 4.4.3.
* Confirm symbol files for 4.4.2 on hurd-i386 i386 ia64 kfreebsd-amd64
  kfreebsd-i386 mips powerpc s390 sparc.
* Release KDE SC 4.4.3 to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "kcategorizedview.h"
26
26
 
27
 
#include <config-nepomuk.h>
28
 
#ifdef HAVE_NEPOMUK
29
 
#include <nepomuk/global.h>
30
 
#include <nepomuk/resource.h>
31
 
#include <nepomuk/tag.h>
32
 
#include <Soprano/Vocabulary/Xesam>
33
 
#endif
34
 
 
35
27
#include <kdatetime.h>
36
28
#include <kdirmodel.h>
37
29
#include <kfileitem.h>
45
37
#include <QList>
46
38
#include <QSortFilterProxyModel>
47
39
#include <QPainter>
 
40
#include <QPersistentModelIndex>
48
41
#include <QDir>
49
42
#include <QFileInfo>
50
43
 
51
44
const char* DolphinModel::m_others = I18N_NOOP2("@title:group Name", "Others");
52
45
 
53
 
DolphinModel::DolphinModel(QObject* parent)
54
 
    : KDirModel(parent)
 
46
DolphinModel::DolphinModel(QObject* parent) :
 
47
    KDirModel(parent),
 
48
    m_hasVersionData(false),
 
49
    m_revisionHash()
55
50
{
56
51
}
57
52
 
59
54
{
60
55
}
61
56
 
 
57
bool DolphinModel::setData(const QModelIndex& index, const QVariant& value, int role)
 
58
{
 
59
    if ((index.column() == DolphinModel::Version) && (role == Qt::DecorationRole)) {
 
60
        // TODO: remove data again when items are deleted...
 
61
 
 
62
        const QPersistentModelIndex key = index;
 
63
        const KVersionControlPlugin::VersionState state = static_cast<KVersionControlPlugin::VersionState>(value.toInt());
 
64
        if (m_revisionHash.value(key, KVersionControlPlugin::UnversionedVersion) != state) {
 
65
            if (!m_hasVersionData) {
 
66
                connect(this, SIGNAL(rowsRemoved (const QModelIndex&, int, int)),
 
67
                        this, SLOT(slotRowsRemoved(const QModelIndex&, int, int)));
 
68
                m_hasVersionData = true;
 
69
            }
 
70
 
 
71
            m_revisionHash.insert(key, state);
 
72
            emit dataChanged(index, index);
 
73
            return true;
 
74
        }
 
75
    }
 
76
 
 
77
    return KDirModel::setData(index, value, role);
 
78
}
 
79
 
62
80
QVariant DolphinModel::data(const QModelIndex& index, int role) const
63
81
{
64
82
    switch (role) {
65
83
    case KCategorizedSortFilterProxyModel::CategoryDisplayRole:
66
84
        return displayRoleData(index);
 
85
 
67
86
    case KCategorizedSortFilterProxyModel::CategorySortRole:
68
87
        return sortRoleData(index);
 
88
 
 
89
    case Qt::DecorationRole:
 
90
        if (index.column() == DolphinModel::Version) {
 
91
            return m_revisionHash.value(index, KVersionControlPlugin::UnversionedVersion);
 
92
        }
 
93
        break;
 
94
 
 
95
    case Qt::DisplayRole:
 
96
        if (index.column() == DolphinModel::Version) {
 
97
            switch (m_revisionHash.value(index, KVersionControlPlugin::UnversionedVersion)) {
 
98
            case KVersionControlPlugin::NormalVersion:
 
99
                return i18nc("@item::intable", "Normal");
 
100
            case KVersionControlPlugin::UpdateRequiredVersion:
 
101
                return i18nc("@item::intable", "Update required");
 
102
            case KVersionControlPlugin::LocallyModifiedVersion:
 
103
                return i18nc("@item::intable", "Locally modified");
 
104
            case KVersionControlPlugin::AddedVersion:
 
105
                return i18nc("@item::intable", "Added");
 
106
            case KVersionControlPlugin::RemovedVersion:
 
107
                return i18nc("@item::intable", "Removed");
 
108
            case KVersionControlPlugin::ConflictingVersion:
 
109
                return i18nc("@item::intable", "Conflicting");
 
110
            case KVersionControlPlugin::UnversionedVersion:
 
111
            default:
 
112
                return i18nc("@item::intable", "Unversioned");
 
113
            }
 
114
        }
 
115
        break;
 
116
 
69
117
    default:
70
 
        return KDirModel::data(index, role);
71
 
    }
72
 
}
73
 
 
74
 
int DolphinModel::columnCount(const QModelIndex &parent) const
 
118
        break;
 
119
    }
 
120
 
 
121
    return KDirModel::data(index, role);
 
122
}
 
123
 
 
124
QVariant DolphinModel::headerData(int section, Qt::Orientation orientation, int role) const
 
125
{
 
126
    if ((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)) {
 
127
        if (section < KDirModel::ColumnCount) {
 
128
            return KDirModel::headerData(section, orientation, role);
 
129
        }
 
130
 
 
131
        Q_ASSERT(section == DolphinModel::Version);
 
132
        return i18nc("@title::column", "Version");
 
133
    }
 
134
    return QVariant();
 
135
}
 
136
 
 
137
int DolphinModel::columnCount(const QModelIndex& parent) const
75
138
{
76
139
    return KDirModel::columnCount(parent) + (ExtraColumnCount - ColumnCount);
77
140
}
78
141
 
79
 
quint32 DolphinModel::ratingForIndex(const QModelIndex& index)
80
 
{
81
 
#ifdef HAVE_NEPOMUK
82
 
    quint32 rating = 0;
83
 
 
84
 
    const DolphinModel* dolphinModel = static_cast<const DolphinModel*>(index.model());
85
 
    KFileItem item = dolphinModel->itemForIndex(index);
86
 
    if (!item.isNull()) {
87
 
        const Nepomuk::Resource resource(item.url().url(), Soprano::Vocabulary::Xesam::File());
88
 
        rating = resource.rating();
89
 
    }
90
 
    return rating;
91
 
#else
92
 
    Q_UNUSED(index);
93
 
    return 0;
94
 
#endif
95
 
}
96
 
 
97
 
QString DolphinModel::tagsForIndex(const QModelIndex& index)
98
 
{
99
 
#ifdef HAVE_NEPOMUK
100
 
    QString tagsString;
101
 
 
102
 
    const DolphinModel* dolphinModel = static_cast<const DolphinModel*>(index.model());
103
 
    KFileItem item = dolphinModel->itemForIndex(index);
104
 
    if (!item.isNull()) {
105
 
        const Nepomuk::Resource resource(item.url().url(), Soprano::Vocabulary::Xesam::File());
106
 
        const QList<Nepomuk::Tag> tags = resource.tags();
107
 
        QStringList stringList;
108
 
        foreach (const Nepomuk::Tag& tag, tags) {
109
 
            stringList.append(tag.label());
110
 
        }
111
 
        stringList.sort();
112
 
 
113
 
        foreach (const QString& str, stringList) {
114
 
            tagsString += str;
115
 
            tagsString += ", ";
116
 
        }
117
 
 
118
 
        if (!tagsString.isEmpty()) {
119
 
            tagsString.resize(tagsString.size() - 2);
120
 
        }
121
 
    }
122
 
 
123
 
    return tagsString;
124
 
#else
125
 
    Q_UNUSED(index);
126
 
    return QString();
127
 
#endif
 
142
void DolphinModel::clearVersionData()
 
143
{
 
144
    m_revisionHash.clear();
 
145
    m_hasVersionData = false;
 
146
}
 
147
 
 
148
bool DolphinModel::hasVersionData() const
 
149
{
 
150
    return m_hasVersionData;
 
151
}
 
152
 
 
153
void DolphinModel::slotRowsRemoved(const QModelIndex& parent, int start, int end)
 
154
{
 
155
    if (m_hasVersionData) {
 
156
        const int column = parent.column();
 
157
        for (int row = start; row <= end; ++row) {
 
158
            m_revisionHash.remove(parent.child(row, column));
 
159
        }
 
160
    }
128
161
}
129
162
 
130
163
QVariant DolphinModel::displayRoleData(const QModelIndex& index) const
218
251
        }
219
252
 
220
253
        if (currentDate.year() == modifiedDate.year() && currentDate.month() == modifiedDate.month()) {
 
254
            if (modifiedWeek > currentWeek) {
 
255
                // use case: modified date = 2010-01-01, current date = 2010-01-22
 
256
                //           modified week = 53,         current week = 3
 
257
                modifiedWeek = 0;
 
258
            }
221
259
            switch (currentWeek - modifiedWeek) {
222
260
            case 0:
223
261
                switch (daysDistance) {
324
362
        retString = item.mimeComment();
325
363
        break;
326
364
 
327
 
#ifdef HAVE_NEPOMUK
328
 
    case DolphinModel::Rating: {
329
 
        const quint32 rating = ratingForIndex(index);
330
 
        retString = QString::number(rating);
331
 
        break;
332
 
    }
333
 
 
334
 
    case DolphinModel::Tags: {
335
 
        retString = tagsForIndex(index);
336
 
        if (retString.isEmpty()) {
337
 
            retString = i18nc("@title:group Tags", "Not yet tagged");
338
 
        }
339
 
        break;
340
 
    }
341
 
#endif
 
365
    case DolphinModel::Version:
 
366
        retString = "test";
 
367
        break;
342
368
    }
343
369
 
344
370
    return retString;
414
440
        }
415
441
        break;
416
442
 
417
 
#ifdef HAVE_NEPOMUK
418
 
    case DolphinModel::Rating: {
419
 
        retVariant = ratingForIndex(index);
420
 
        break;
421
 
    }
422
 
 
423
 
    case DolphinModel::Tags: {
424
 
        retVariant = tagsForIndex(index).count();
425
 
        break;
426
 
    }
427
 
#endif
428
 
 
429
443
    default:
430
444
        break;
431
445
    }