2
This file is part of the Nepomuk KDE project.
3
Copyright (C) 2010 Vishesh Handa <handa.vish@gmail.com>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) version 3, or any
9
later version accepted by the membership of KDE e.V. (or its
10
successor approved by the membership of KDE e.V.), which shall
11
act as a proxy defined in Section 6 of version 3 of the license.
13
This library is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
Lesser General Public License for more details.
18
You should have received a copy of the GNU Lesser General Public
19
License along with this library. If not, see <http://www.gnu.org/licenses/>.
23
#include "identifiermodel.h"
24
#include "identifiermodeltree.h"
26
#include <Nepomuk/Vocabulary/NIE>
27
#include <Nepomuk/Vocabulary/NFO>
28
#include <Soprano/Vocabulary/RDF>
30
#include <Soprano/QueryResultIterator>
31
#include <Soprano/Model>
32
#include <Soprano/Statement>
34
#include <Nepomuk/ResourceManager>
40
Nepomuk::IdentifierModel::IdentifierModel(QObject* parent): QAbstractItemModel(parent)
42
m_tree = new IdentifierModelTree();
46
Nepomuk::IdentifierModel::~IdentifierModel()
52
QVariant Nepomuk::IdentifierModel::data(const QModelIndex& index, int role) const
54
IdentifierModelTreeItem *item = static_cast<IdentifierModelTreeItem *> (m_tree->root());
56
item = static_cast<IdentifierModelTreeItem *>(index.internalPointer());
61
//FIXME: Make this look good
62
return QString::fromLatin1("Text for item %1").arg( item->prettyString() );
65
//FIXME: How am I supposed to get the size?
66
return KRandom::random();
72
return QUrl( item->resourceUri() );
74
case IdentifiedResourceRole:
76
return QUrl( item->resourceUri() );
81
//return m_discardedResource.contains(data(index,ResourceRole).toUrl());
88
int Nepomuk::IdentifierModel::columnCount(const QModelIndex& parent) const
91
// It is always 1 for now
96
int Nepomuk::IdentifierModel::rowCount(const QModelIndex& parent) const
98
if( parent.column() > 0 )
101
if( !parent.isValid() ) {
102
//kDebug() << "NOT VALID - Probably root";
103
int r = m_tree->root()->isEmpty() ? 0 : 1;
108
IdentifierModelTreeItem * parentItem;
110
//kDebug() << "Else cluase !!";
111
parentItem = static_cast<IdentifierModelTreeItem *>(parent.internalPointer());
112
//if( parentItem == m_tree->root() )
113
// kDebug() << "ROOT!! :-D";
115
int r = parentItem->numChildren();
121
QModelIndex Nepomuk::IdentifierModel::parent(const QModelIndex& index) const
123
if( !index.isValid() )
124
return QModelIndex();
126
IdentifierModelTreeItem *childItem = static_cast<IdentifierModelTreeItem*>( index.internalPointer() );
127
if( childItem == m_tree->root() )
128
return QModelIndex();
130
FileSystemTreeItem<IdentificationData> *parentItem = static_cast<FileSystemTreeItem<IdentificationData>*>( childItem->parent() );
132
return QModelIndex();
134
if( parentItem == m_tree->root() )
135
return createIndex( 0, 0, m_tree->root() );
137
return createIndex( parentItem->parentRowNum(), 0, parentItem );
141
QModelIndex Nepomuk::IdentifierModel::index(int row, int column, const QModelIndex& parent) const
143
if (!parent.isValid()) {
144
// IdentifierModelTreeItem * root = dynamic_cast<IdentifierModelTreeItem*>( );
146
if( m_tree->root()->isEmpty() )
147
return QModelIndex();
149
return createIndex( row, column, m_tree->root() );
152
IdentifierModelTreeItem *parentItem = static_cast<IdentifierModelTreeItem *>( parent.internalPointer() );
153
FileSystemTreeItem<IdentificationData> *childItem = static_cast<FileSystemTreeItem<IdentificationData>*>( parentItem->child(row) );
154
return createIndex(row, column, childItem);
159
void Nepomuk::IdentifierModel::identified(int id, const QString& oldUri, const QString& newUri)
162
kDebug() << oldUri << " -----> " << newUri;
164
emit layoutAboutToBeChanged();
166
m_tree->remove( oldUri );
168
emit layoutChanged();
172
void Nepomuk::IdentifierModel::notIdentified(int id, const QList< Soprano::Statement >& sts)
175
emit layoutAboutToBeChanged();
177
IdentifierModelTreeItem* item = IdentifierModelTreeItem::fromStatementList(id, sts);
178
item->setUnidentified();;
181
emit layoutChanged();
185
void Nepomuk::IdentifierModel::debug_identified(int id, const QString& nieUrl)
188
emit layoutAboutToBeChanged();
189
m_tree->remove( nieUrl );
190
emit layoutChanged();*/
194
void Nepomuk::IdentifierModel::debug_notIdentified(int id, const QString& resUri, const QString& nieUrl, bool folder)
197
emit layoutAboutToBeChanged();
199
Soprano::Statement st( Soprano::Node( QUrl(resUri) ),
200
Soprano::Node( Nepomuk::Vocabulary::NIE::url() ),
201
Soprano::Node( QUrl(nieUrl) ) );
202
QList<Soprano::Statement> stList;
205
stList << Soprano::Statement( QUrl(resUri), Soprano::Vocabulary::RDF::type(), Nepomuk::Vocabulary::NFO::Folder() );
208
//kDebug() << m_tree->toList();
209
m_tree->add( IdentifierModelTreeItem::fromStatementList( id, stList ) );
210
kDebug() << m_tree->toList();
211
emit layoutChanged();
214
Qt::ItemFlags Nepomuk::IdentifierModel::flags(const QModelIndex& index) const
217
//return QAbstractItemModel::flags(index);
218
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
221
#include "identifiermodel.moc"