• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • services
  • storage
  • backup
  • gui
fileconflictwidget.cpp
Go to the documentation of this file.
1 /*
2  <one line to give the library's name and an idea of what it does.>
3  Copyright (C) 2012 Vishesh Handa <me@vhanda.in>
4 
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) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 
21 #include "fileconflictwidget.h"
22 #include "resourcemanager.h"
23 #include "datamanagement.h"
24 #include "nie.h"
25 
26 #include <QtGui/QBoxLayout>
27 
28 #include <Soprano/Model>
29 #include <Soprano/QueryResultIterator>
30 
31 #include <KUrl>
32 #include <KLocalizedString>
33 #include <KJob>
34 #include <KFileDialog>
35 #include <KDebug>
36 
37 using namespace Nepomuk2::Vocabulary;
38 
39 Nepomuk2::FileConflictWidget::FileConflictWidget(QWidget* parent, Qt::WindowFlags f): QWidget(parent, f)
40 {
41  // Create the UI
42  m_discardButton = new QPushButton( i18n("Discard"), this );
43  m_identifyButton = new QPushButton( i18n("Resolve"), this );
44 
45  connect( m_discardButton, SIGNAL(clicked(bool)), this, SLOT(slotDiscardButtonClicked()) );
46  connect( m_identifyButton, SIGNAL(clicked(bool)), this, SLOT(slotIdentifyButtonClicked()) );
47 
48  QHBoxLayout* hLayout = new QHBoxLayout();
49  hLayout->addWidget( m_discardButton );
50  hLayout->addWidget( m_identifyButton );
51 
52  m_treeWidget = new QTreeWidget( this );
53 
54  QVBoxLayout* layout = new QVBoxLayout( this );
55  layout->addWidget( m_treeWidget );
56  layout->addItem( hLayout );
57 
58  // Fill with data
59  // TODO: Do this in a separate thread
60  QLatin1String query("select distinct ?r ?url where { ?r a nfo:FileDataObject ; nie:url ?url . }");
61 
62  Soprano::Model* model = ResourceManager::instance()->mainModel();
63  Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
64  while( it.next() ) {
65  const QUrl uri = it[0].uri();
66  const QUrl nieUrl = it[1].uri();
67 
68  if( !QFile::exists(nieUrl.toLocalFile()) ) {
69  kDebug() << uri << nieUrl;
70  add( uri, nieUrl );
71  }
72  }
73 }
74 
75 void Nepomuk2::FileConflictWidget::add(const QUrl& uri, const QUrl& url)
76 {
77  QTreeWidgetItem* item = new QTreeWidgetItem;
78  item->setText( 0, url.path() );
79  item->setData( 0, NepomukUriRole, uri );
80 
81  // Find its parents
82  QString parentString = KUrl(url).directory();
83 
84  QList<QTreeWidgetItem*> parents = m_treeWidget->findItems( parentString, Qt::MatchCaseSensitive );
85  if( parents.isEmpty() ) {
86  // FIXME: Should it really be 0?
87  m_treeWidget->insertTopLevelItem( 0, item );
88  return;
89  }
90 
91  QTreeWidgetItem* parentItem = parents.first();
92  parentItem->addChild( item );
93 }
94 
95 void Nepomuk2::FileConflictWidget::removeUrl(const QUrl& url)
96 {
97  QList<QTreeWidgetItem*> items = m_treeWidget->findItems( url.path(), Qt::MatchCaseSensitive );
98  foreach( QTreeWidgetItem* item, items ) {
99  m_treeWidget->removeItemWidget( item, 0 );
100  }
101 }
102 
103 void Nepomuk2::FileConflictWidget::removeItem(QTreeWidgetItem* item)
104 {
105  if( !item )
106  return;
107 
108  if( item->parent() ) {
109  item->parent()->removeChild( item );
110  delete item;
111  }
112  else {
113  delete m_treeWidget->takeTopLevelItem( m_treeWidget->indexOfTopLevelItem(item) );
114  }
115 }
116 
117 
118 void Nepomuk2::FileConflictWidget::slotDiscardButtonClicked()
119 {
120  QTreeWidgetItem* item = m_treeWidget->currentItem();
121  if( !item )
122  return;
123 
124  QUrl uri = item->data( 0, NepomukUriRole ).toUrl();
125 
126  QList<QUrl> uris;
127  uris << uri;
128 
129  // Error Handling?
130  KJob* job = Nepomuk2::removeResources( uris );
131  job->exec();
132 
133  removeItem( item );
134 }
135 
136 void Nepomuk2::FileConflictWidget::slotIdentifyButtonClicked()
137 {
138  QTreeWidgetItem* item = m_treeWidget->currentItem();
139  if( !item )
140  return;
141 
142  QUrl url = item->text( 0 );
143  QUrl uri = item->data( 0, NepomukUriRole ).toUrl();
144 
145  // Launch a KDialog to select the appropriate file
146  // TODO: Change the dialog based on the type of file? Maybe even apply different filters
147  QUrl newUrl = KFileDialog::getOpenUrl( url, QString(), this, i18n("Find the url") );
148 
149  // Error Handling?
150  KJob* job = Nepomuk2::setProperty( QList<QUrl>() << uri, NIE::url(), QVariantList() << newUrl );
151 
152  job->exec();
153  if( job->error() ) {
154  kDebug() << "AHHHHHHHHHHH!!!";
155  kError() << job->errorString();
156  }
157 
158  removeItem( item );
159 }
160 
161 bool Nepomuk2::FileConflictWidget::isEmpty()
162 {
163  return !m_treeWidget->model()->rowCount();
164 }
165 
fileconflictwidget.h
Nepomuk2::FileConflictWidget::FileConflictWidget
FileConflictWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: fileconflictwidget.cpp:39
Nepomuk2::FileConflictWidget::isEmpty
bool isEmpty()
Definition: fileconflictwidget.cpp:161
QWidget
Nepomuk2::ResourceManager::instance
static ResourceManager * instance()
Definition: resourcemanager.cpp:270
resourcemanager.h
datamanagement.h
Nepomuk2::removeResources
KJob * removeResources(const QList< QUrl > &resources, Nepomuk2::RemovalFlags flags=Nepomuk2::NoRemovalFlags, const KComponentData &component=KGlobal::mainComponent())
Completely remove resources from the database.
Nepomuk2::setProperty
KJob * setProperty(const QList< QUrl > &resources, const QUrl &property, const QVariantList &values, const KComponentData &component=KGlobal::mainComponent())
Set the values of a property for one or more resources.
Definition: datamanagement.cpp:48
Nepomuk2::ResourceManager::mainModel
Soprano::Model * mainModel()
Retrieve the main data storage model.
Definition: resourcemanager.cpp:363
KJob
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal