File: identifierwidget.cpp

package info (click to toggle)
kde-runtime 4%3A4.8.4-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 24,712 kB
  • sloc: cpp: 130,244; ansic: 2,447; xml: 1,691; perl: 1,570; sh: 504; python: 455; makefile: 13
file content (136 lines) | stat: -rw-r--r-- 4,257 bytes parent folder | download
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
/*
    This file is part of the Nepomuk KDE project.
    Copyright (C) 2010  Vishesh Handa <handa.vish@gmail.com>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) version 3, or any
   later version accepted by the membership of KDE e.V. (or its
   successor approved by the membership of KDE e.V.), which shall
   act as a proxy defined in Section 6 of version 3 of the license.

   This library 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
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "identifierwidget.h"
#include "identifiermodel.h"
#include "identifiermodeltree.h"

#include <QtGui/QLabel>
#include <QtGui/QVBoxLayout>
#include <KDebug>
#include <KFileDialog>

#include <Soprano/Parser>
#include <Soprano/PluginManager>
#include <Soprano/Statement>
#include <Soprano/StatementIterator>


Nepomuk::IdentifierWidget::IdentifierWidget(int id, QWidget* parent): QWidget(parent), m_id(id)
{
    //registerMetaTypes();
    setupUi(this);

    m_model = new IdentifierModel( this );

    MergeConflictDelegate * delegate = new MergeConflictDelegate( m_viewConflicts, this );
    m_viewConflicts->setModel( m_model );
    m_viewConflicts->setItemDelegate( delegate );

    m_identifier = Identifier::instance();

    connect( m_identifier, SIGNAL(notIdentified(int,QString)),
             this, SLOT(notIdentified(int,QString)) );
    connect( m_identifier, SIGNAL(identified(int,QString,QString)),
             this, SLOT(identified(int,QString,QString)) );
    connect( m_identifier, SIGNAL(completed(int,int)),
             this, SLOT(completed(int,int)) );

    connect( delegate, SIGNAL(requestResourceResolve(QUrl)),
             this, SLOT(identify()) );
    connect( delegate, SIGNAL(requestResourceDiscard(QUrl)),
             this, SLOT(ignore(QUrl)) );

    connect( m_buttonDiscardAll, SIGNAL(clicked(bool)),
             this, SLOT(slotDiscardAll()) );
}

void Nepomuk::IdentifierWidget::ignore(const QUrl& uri)
{
    Q_UNUSED( uri );

    QModelIndex index = m_viewConflicts->currentIndex();
    if( !index.isValid() )
        return;

    IdentifierModelTreeItem * item = static_cast<IdentifierModelTreeItem*>( index.internalPointer() );
    item->setDiscarded( true );

    m_identifier->ignore( m_id, item->resourceUri().toString(), true);
}


void Nepomuk::IdentifierWidget::identify()
{
    QModelIndex index = m_viewConflicts->currentIndex();
    if( !index.isValid() )
        return;

    IdentifierModelTreeItem * treeItem = static_cast<IdentifierModelTreeItem*>( index.internalPointer() );

    KUrl newUrl;
    if( treeItem->isFolder() )
        newUrl = KFileDialog::getExistingDirectoryUrl();
    else
        newUrl = KFileDialog::getOpenUrl();

   if( !newUrl.isEmpty() )
        m_identifier->identify( m_id, treeItem->resourceUri().toString(), newUrl.url() );
}

void Nepomuk::IdentifierWidget::notIdentified(int id, const QString& string)
{
    if( id != m_id )
        return;

    kDebug() << string;
    const Soprano::Parser* parser = Soprano::PluginManager::instance()->discoverParserForSerialization( Soprano::SerializationNQuads );

    QList<Soprano::Statement> stList = parser->parseString( string, QUrl(), Soprano::SerializationNQuads ).allStatements();

    m_model->notIdentified( stList );
}

void Nepomuk::IdentifierWidget::identified(int id, const QString& oldUri, const QString& newUri)
{
    if( id != m_id )
        return;

    m_model->identified( QUrl(oldUri), QUrl(newUri) );
}

void Nepomuk::IdentifierWidget::slotDiscardAll()
{
    m_identifier->ignoreAll( m_id );
    m_model->ignoreAll();
}

void Nepomuk::IdentifierWidget::completed(int id, int progress)
{
    if( id != m_id )
        return;

    kDebug() << progress;
    m_progressBar->setValue( progress );
}

#include "identifierwidget.moc"