~ubuntu-branches/ubuntu/vivid/muon/vivid-proposed

« back to all changes in this revision

Viewing changes to libmuon/resources/ResourcesModel.cpp

  • Committer: Package Import Robot
  • Author(s): Scarlett Clark
  • Date: 2015-03-24 07:36:31 UTC
  • mto: This revision was merged to the branch mainline in revision 86.
  • Revision ID: package-import@ubuntu.com-20150324073631-7nmay5episnfkdlt
Tags: upstream-5.2.2
ImportĀ upstreamĀ versionĀ 5.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <MuonBackendsFactory.h>
29
29
#include <MuonMainWindow.h>
30
30
#include "Transaction/TransactionModel.h"
 
31
#include "Category/CategoryModel.h"
31
32
#include <QDebug>
32
33
#include <QCoreApplication>
33
34
#include <QThread>
 
35
#include <QAction>
34
36
 
35
37
// static const KCatalogLoader loader("libmuon");//FIXME port
36
38
 
46
48
ResourcesModel::ResourcesModel(QObject* parent, bool load)
47
49
    : QAbstractListModel(parent)
48
50
    , m_initializingBackends(0)
49
 
    , m_mainwindow(0)
 
51
    , m_mainwindow(nullptr)
50
52
{
51
53
    init(load);
52
54
    connect(this, SIGNAL(allInitialized()), SIGNAL(fetchingChanged()));
107
109
void ResourcesModel::addResourcesBackend(AbstractResourcesBackend* backend)
108
110
{
109
111
    Q_ASSERT(!m_backends.contains(backend));
 
112
    if(!backend->isValid()) {
 
113
        qWarning() << "Discarding invalid backend" << backend->name();
 
114
        CategoryModel::blacklistPlugin(backend->name());
 
115
        backend->deleteLater();
 
116
        return;
 
117
    }
 
118
 
110
119
    if(!backend->isFetching()) {
111
120
        QVector<AbstractResource*> newResources = backend->allResources();
112
121
        int current = rowCount();
234
243
 
235
244
void ResourcesModel::cleanBackend(AbstractResourcesBackend* backend)
236
245
{
237
 
    m_initializingBackends++;
238
 
    
239
246
    QVector<QVector<AbstractResource*>>::iterator backendsResources;
240
247
    int before = rowsBeforeBackend(backend, backendsResources);
241
248
 
251
258
void ResourcesModel::callerFetchingChanged()
252
259
{
253
260
    AbstractResourcesBackend* backend = qobject_cast<AbstractResourcesBackend*>(sender());
 
261
 
 
262
    if (!backend->isValid()) {
 
263
        qWarning() << "Discarding invalid backend" << backend->name();
 
264
        cleanBackend(backend);
 
265
        int idx = m_backends.indexOf(backend);
 
266
        Q_ASSERT(idx>=0);
 
267
        m_backends.removeAt(idx);
 
268
        m_resources.removeAt(idx);
 
269
        CategoryModel::blacklistPlugin(backend->name());
 
270
        backend->deleteLater();
 
271
        return;
 
272
    }
 
273
 
254
274
    if(backend->isFetching()) {
 
275
        m_initializingBackends++;
255
276
        cleanBackend(backend);
256
277
        emit fetchingChanged();
257
278
    } else {
393
414
    }
394
415
    return false;
395
416
}
 
417
 
 
418
QList<QAction*> ResourcesModel::messageActions() const
 
419
{
 
420
    QList<QAction*> ret;
 
421
    foreach(AbstractResourcesBackend* b, m_backends) {
 
422
        ret += b->messageActions();
 
423
    }
 
424
    Q_ASSERT(!ret.contains(nullptr));
 
425
    return ret;
 
426
}