• 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
  • cleaner
jobmodel.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 "jobmodel.h"
22 #include "cleaningjob.h"
23 #include "cleaningjobs.h"
24 
25 #include <KIcon>
26 #include <KDebug>
27 #include <QThread>
28 
29 #include "resourcemanager.h"
30 
31 using namespace Nepomuk2;
32 
33 JobModel::JobModel(QObject* parent): QAbstractListModel(parent)
34 {
35  // Forcibly initializing the ResourceManager so that it gets initialized
36  // in the main thread and not in the job thread
37  Nepomuk2::ResourceManager::instance()->init();
38 
39  m_allJobs = allJobs();
40  m_curJob = 0;
41  m_status = NotStarted;
42 
43  m_jobThread = new QThread( this );
44  m_jobThread->start();
45 }
46 
47 JobModel::~JobModel()
48 {
49  if( m_curJob )
50  m_curJob->quit();
51 
52  m_jobThread->quit();
53  m_jobThread->wait();
54 }
55 
56 QVariant JobModel::data(const QModelIndex& index, int role) const
57 {
58  if( !index.isValid() || index.row() >= m_jobs.size() )
59  return QVariant();
60 
61  switch(role) {
62  case Qt::DisplayRole:
63  return m_jobs[ index.row() ];
64 
65  //FIXME: Maybe one should an animated icon for the item that is being processed
66  case Qt::DecorationRole:
67  return KIcon("nepomuk");
68  }
69 
70  return QVariant();
71 }
72 
73 int JobModel::rowCount(const QModelIndex& parent) const
74 {
75  if( parent.isValid() )
76  return 0;
77 
78  return m_jobs.size();
79 }
80 
81 void JobModel::start()
82 {
83  m_status = Running;
84  startNextJob();
85 }
86 
87 void JobModel::pause()
88 {
89  m_status = Paused;
90  if( m_curJob ) {
91  //FIXME: This will leave this job half done
92  m_curJob->quit();
93  m_curJob = 0;
94  }
95 }
96 
97 void JobModel::resume()
98 {
99  m_status = Running;
100  startNextJob();
101 }
102 
103 JobModel::Status JobModel::status()
104 {
105  return m_status;
106 }
107 
108 
109 void JobModel::startNextJob()
110 {
111  if( m_status == Paused )
112  return;
113 
114  if( m_allJobs.isEmpty() || !Nepomuk2::ResourceManager::instance()->initialized() ) {
115  m_status = Finished;
116  m_curJob = 0;
117  emit finished();
118  return;
119  }
120 
121  m_curJob = m_allJobs.takeFirst();
122  m_curJob->moveToThread( m_jobThread );
123 
124  connect(m_curJob, SIGNAL(finished(KJob*)), this, SLOT(slotJobFinished(KJob*)));
125  m_curJob->start();
126 
127  emit beginInsertRows( QModelIndex(), m_jobs.size(), m_jobs.size() + 1 );
128  m_jobs << m_curJob->jobName();
129  emit endInsertRows();
130 }
131 
132 void JobModel::slotJobFinished(KJob*)
133 {
134  m_curJob = 0;
135  startNextJob();
136 }
JobModel::pause
void pause()
Definition: jobmodel.cpp:87
JobModel::Finished
Definition: jobmodel.h:51
Nepomuk2::CleaningJob::jobName
virtual QString jobName()=0
JobModel::finished
void finished()
JobModel::Running
Definition: jobmodel.h:49
QAbstractListModel
Nepomuk2::CleaningJob::start
virtual void start()
Definition: cleaningjob.cpp:39
QObject
JobModel::~JobModel
virtual ~JobModel()
Definition: jobmodel.cpp:47
JobModel::resume
void resume()
Definition: jobmodel.cpp:97
JobModel::JobModel
JobModel(QObject *parent=0)
Definition: jobmodel.cpp:33
JobModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: jobmodel.cpp:73
JobModel::NotStarted
Definition: jobmodel.h:48
JobModel::start
void start()
Definition: jobmodel.cpp:81
Nepomuk2::ResourceManager::initialized
bool initialized() const
Definition: resourcemanager.cpp:306
Nepomuk2::CleaningJob::quit
void quit()
Definition: cleaningjob.cpp:50
Nepomuk2::ResourceManager::instance
static ResourceManager * instance()
Definition: resourcemanager.cpp:270
resourcemanager.h
cleaningjob.h
Nepomuk2::ResourceManager::init
int init()
Initialize the Nepomuk framework.
Definition: resourcemanager.cpp:288
JobModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: jobmodel.cpp:56
JobModel::Status
Status
Definition: jobmodel.h:47
JobModel::Paused
Definition: jobmodel.h:50
cleaningjobs.h
JobModel::status
Status status()
Definition: jobmodel.cpp:103
allJobs
QList< CleaningJob * > allJobs()
Definition: cleaningjobs.cpp:527
KJob
jobmodel.h
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