| 1 | /* Copyright (C) 2017 Dan Chapman <[email protected]> |
| 2 | |
| 3 | This file is part of Dekko email client for Ubuntu devices |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU General Public License as |
| 7 | published by the Free Software Foundation; either version 2 of |
| 8 | the License or (at your option) version 3 |
| 9 | |
| 10 | This program 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 |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | #include "PluginIncubator.h" |
| 19 | #include <QQmlContext> |
| 20 | #include <QDebug> |
| 21 | |
| 22 | Q_LOGGING_CATEGORY(PLUGIN_INCUBATOR, "dekko.plugman.incubator") |
| 23 | |
| 24 | PluginIncubator::PluginIncubator(QObject *parent) : QObject(parent), |
| 25 | QQmlIncubator(QQmlIncubator::Asynchronous), m_comp(Q_NULLPTR) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | void PluginIncubator::setSourceUrl(QQmlEngine *engine, const QUrl &source) |
| 30 | { |
| 31 | m_comp = new QQmlComponent(engine, source, this); |
| 32 | if (m_comp->isError()) { |
| 33 | qCDebug(PLUGIN_INCUBATOR) << "Comp failed: " << m_comp->errorString(); |
| 34 | emit error(); |
| 35 | return; |
| 36 | } |
| 37 | QQmlContext *c = engine->contextForObject(parent()); |
| 38 | if (c->isValid()) { |
| 39 | m_comp->create(*this, c); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | void PluginIncubator::statusChanged(QQmlIncubator::Status status) |
| 44 | { |
| 45 | switch (status) { |
| 46 | case QQmlIncubator::Null: |
| 47 | break; |
| 48 | case QQmlIncubator::Ready: |
| 49 | qCDebug(PLUGIN_INCUBATOR) << "Incubator finished and ready to hatch."; |
| 50 | emit objectReady(); |
| 51 | break; |
| 52 | case QQmlIncubator::Loading: |
| 53 | qCDebug(PLUGIN_INCUBATOR) << "Incubating plugin"; |
| 54 | break; |
| 55 | case QQmlIncubator::Error: |
| 56 | qCDebug(PLUGIN_INCUBATOR) << "Incubation Error"; |
| 57 | emit error(); |
| 58 | break; |
| 59 | default: |
| 60 | break; |
| 61 | } |
| 62 | } |