File: sourcemanager.cpp

package info (click to toggle)
dde-store 1.2.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 724 kB
  • sloc: cpp: 2,048; makefile: 5
file content (57 lines) | stat: -rw-r--r-- 1,276 bytes parent folder | download | duplicates (2)
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
#include "sourcemanager.h"
#include "sources/packagekit/packagekitsource.h"
#include <QPluginLoader>
#include <DDialog>
#include <DStyle>

DWIDGET_USE_NAMESPACE

SourceManager *SourceManager::currentInstance = nullptr;

SourceManager *SourceManager::instance()
{
    if (!currentInstance)
        currentInstance = new SourceManager;
    return currentInstance;
}

SourceManager::SourceManager()
{
    QPluginLoader *loader = new QPluginLoader("dde-store/snapplugin");
    if (loader->load())
        m_sources << qobject_cast<Source*>(loader->instance());
    
    m_sources << new PackageKitSource;
}

QList<Source*> SourceManager::sources()
{
    return m_sources;
}

Source *SourceManager::getSource(QString name)
{
    for (Source *source : m_sources) {
        if (source->name() == name)
            return source;
    }
    return nullptr;
}

bool SourceManager::preventingClose()
{
    for (Source *source : m_sources) {
        if (source->preventingClose)
            return true;
    }
    return false;
}

void Source::error(QString text)
{
    qDebug() << "[ ERROR ]" << name() + " - " + text;
    DDialog dialog(name() + " Error", text);
    dialog.setIcon(DStyle().standardIcon(QStyle::SP_MessageBoxCritical));
    dialog.addButton("OK");
    dialog.exec();
}