Exemplo n.º 1
0
void PlayBarJob::start() {
	if ( operationName() == QLatin1String( "ShowSettings" ) )
		m_playbar->showSettings();
		
	if ( operationName() == QLatin1String( "SetSourceMpris2" ) )
		m_playbar->mpris2_source = parameters() ["source"].toString();
		
	emitResult();
}
Exemplo n.º 2
0
QString PlayerActionJob::errorString() const
{
    if (error() == Denied) {
        return i18n("The media player '%1' cannot perform the action '%2'.", m_controller->name(), operationName());
    } else if (error() == Failed) {
        return i18n("Attempting to perform the action '%1' failed with the message '%2'.",
                operationName(), errorText());
    } else if (error() == MissingArgument) {
        return i18n("The argument '%1' for the action '%2' is missing or of the wrong type.", operationName(), errorText());
    } else if (error() == UnknownOperation) {
        return i18n("The operation '%1' is unknown.", operationName());
    }
    return i18n("Unknown error.");
}
void NotificationAction::start()
{
    //qDebug() << "Trying to perform the action " << operationName() << " on " << destination();
    //qDebug() << "actionId: " << parameters()["actionId"].toString();
    //qDebug() << "params: " << parameters();

    if (!m_engine) {
        setErrorText(i18n("The notification dataEngine is not set."));
        setError(-1);
        emitResult();
        return;
    }

    const QStringList dest = destination().split(' ');

    uint id = 0;
    if (dest.count() >  1 && !dest[1].toInt()) {
        setErrorText(i18n("Invalid destination: %1", destination()));
        setError(-2);
        emitResult();
        return;
    } else if (dest.count() >  1) {
        id = dest[1].toUInt();
    }

    if (operationName() == QLatin1String("invokeAction")) {
        //qDebug() << "invoking action on " << id;
        emit m_engine->ActionInvoked(id, parameters()[QStringLiteral("actionId")].toString());
    } else if (operationName() == QLatin1String("userClosed")) {
        //userClosedNotification deletes the job, so we have to invoke it queued, in this case emitResult() can be called
        m_engine->metaObject()->invokeMethod(m_engine, "removeNotification", Qt::QueuedConnection, Q_ARG(uint, id), Q_ARG(uint, 2));
    } else if (operationName() == QLatin1String("expireNotification")) {
        //expireNotification deletes the job, so we have to invoke it queued, in this case emitResult() can be called
        m_engine->metaObject()->invokeMethod(m_engine, "removeNotification", Qt::QueuedConnection, Q_ARG(uint, id), Q_ARG(uint, 1));
    } else if (operationName() == QLatin1String("createNotification")) {
        int rv = m_engine->createNotification(parameters().value(QStringLiteral("appName")).toString(),
                                              parameters().value(QStringLiteral("appIcon")).toString(),
                                              parameters().value(QStringLiteral("summary")).toString(),
                                              parameters().value(QStringLiteral("body")).toString(),
                                              parameters().value(QStringLiteral("expireTimeout")).toInt(),
                                              QString(),
                                              parameters().value(QStringLiteral("actions")).toStringList()
                                             );
        setResult(rv);
    } else if (operationName() == QLatin1String("configureNotification")) {
        m_engine->configureNotification(parameters()[QStringLiteral("appRealName")].toString());
    }

    emitResult();
}
Exemplo n.º 4
0
void SolidDeviceJob::start()
{
    Solid::Device device (m_dest);
    QString operation = operationName();
    
    if (operation == QLatin1String("mount")) {
        if (device.is<Solid::StorageAccess>()) {
            Solid::StorageAccess *access = device.as<Solid::StorageAccess>();
            if (access && !access->isAccessible()) {
                access->setup();
            }
        }
    }
    else if (operation == QLatin1String("unmount")) {
        if (device.is<Solid::OpticalDisc>()) {
            Solid::OpticalDrive *drive = device.as<Solid::OpticalDrive>();
            if (!drive) {
                drive = device.parent().as<Solid::OpticalDrive>();
            }
            if (drive) {
                drive->eject();
            }
        }
        else if (device.is<Solid::StorageAccess>()) {
            Solid::StorageAccess *access = device.as<Solid::StorageAccess>();
            if (access && access->isAccessible()) {
                access->teardown();
            }
        }
    }

    emitResult();
}
Exemplo n.º 5
0
std::wstring Writer::operator ()(const Term &term, const Dictionary &dictionary, SymbolType *symbolType) const
{
    if (symbolType) {
        *symbolType = term.type();
    }

    std::wstring result = dictionary(term.symbol());

    if (result.empty()) {
        switch (term.type()) {
        case NONE_SYMBOL:
            return symbolic.noneSymbol;

            break;

        case VARIABLE:
            return variableName(term.symbol().id);

            break;
        case CONSTANT:
            return constantName(term.symbol().id);

            break;
        case OPERATION:
            result = operationName(term.symbol().id);

            break;

        default:
            throw(1);

            break;
        }
    }

    if (term.type()!=OPERATION) {
        return result;
    }

    result += symbolic.leftTermBracket;

    if (term.arity()) {
        result += operator ()(term.args()[0], dictionary);

        for (size_t i = 1; i < term.arity(); ++i) {
            result += symbolic.operationSeparatorSymbol;
            result += operator ()(term.args()[i], dictionary);
        }
    }

    result += symbolic.rightTermBracket;

    return result;
}
Exemplo n.º 6
0
void StorageJob::start()
{
    //FIXME: QHASH
    QVariantMap params = parameters();

    QString valueGroup = params["group"].toString();
    if (valueGroup.isEmpty()) {
        valueGroup = "default";
    }

    QWeakPointer<StorageJob> me(this);
    if (operationName() == "save") {
        QMetaObject::invokeMethod(Plasma::StorageThread::self(), "save", Qt::QueuedConnection, Q_ARG(QWeakPointer<StorageJob>, me), Q_ARG(const QVariantMap &, params));
    } else if (operationName() == "retrieve") {
Exemplo n.º 7
0
void RemoteServiceJob::checkValidity()
{
    if (!m_service->isOperationEnabled(operationName())) {
        setError(-1);
        setErrorText(i18n("Job no longer valid, operation is not enabled."));
    } else if (m_delayedDesc) {
        d->parameters = m_service->parametersFromDescription(*m_delayedDesc);
    } else {
        KConfigGroup description = m_service->operationDescription(operationName());
        QMapIterator<QString, QVariant> param(parameters());
        while (param.hasNext()) {
            param.next();
            if (!description.hasKey(param.key())) {
                setError(-1);
                setErrorText(i18n("Job no longer valid, invalid parameters."));
                break;
            }
        }
    }

    delete m_delayedDesc;
    m_delayedDesc = 0;
}
Exemplo n.º 8
0
void HotplugJob::start()
{
    QString udi (m_dest);
    QString operation = operationName();
    
    if (operation == "invokeAction") {
        QString action = parameters()["predicate"].toString();

        QStringList desktopFiles;
        desktopFiles << action;
        QDBusInterface soliduiserver("org.kde.kded5", "/modules/soliduiserver", "org.kde.SolidUiServer");
        QDBusReply<void> reply = soliduiserver.call("showActionsDialog", udi, desktopFiles);
    }

    emitResult();
}
Exemplo n.º 9
0
void TaskWindowJob::start()
{
    const QString operation = operationName();
    if (operation == "cascade") {
        QDBusInterface  *kwinInterface = new QDBusInterface("org.kde.kwin", "/KWin", "org.kde.KWin");
        QDBusPendingCall pcall = kwinInterface->asyncCall("cascadeDesktop");
       // kDebug() << " connected to kwin interface! ";
        setResult(true);
        return;
    } else if (operation == "unclutter") {
        QDBusInterface  *kwinInterface = new QDBusInterface("org.kde.kwin", "/KWin", "org.kde.KWin");
        QDBusPendingCall pcall = kwinInterface->asyncCall("unclutterDesktop");
      //  kDebug() << "connected to kwin interface! ";
        setResult(true);
        return;
    } 
}
Exemplo n.º 10
0
void ClipboardJob::start()
{
    const QString operation = operationName();
    // first check for operations not needing an item
    if (operation == QLatin1String("clearHistory")) {
        m_klipper->slotAskClearHistory();
        setResult(true);
        emitResult();
        return;
    } else if (operation == QLatin1String("configureKlipper")) {
        m_klipper->slotConfigure();
        setResult(true);
        emitResult();
        return;
    }

    // other operations need the item
    HistoryItemConstPtr item = m_klipper->history()->find(QByteArray::fromBase64(destination().toUtf8()));
    if (item.isNull()) {
        setResult(false);
        emitResult();
        return;
    }
    if (operation == QLatin1String("select")) {
        m_klipper->history()->slotMoveToTop(item->uuid());
        setResult(true);
    } else if (operation == QLatin1String("remove")) {
        m_klipper->history()->remove(item);
        setResult(true);
    } else if (operation == QLatin1String("edit")) {
        connect(m_klipper, &Klipper::editFinished, this,
            [this, item](HistoryItemConstPtr editedItem, int result) {
                if (item != editedItem) {
                    // not our item
                    return;
                }
                setResult(result);
                emitResult();
            }
        );
        m_klipper->editData(item);
        return;
    } else if (operation == QLatin1String("barcode")) {
#ifdef HAVE_PRISON
        int pixelWidth = parameters().value(QStringLiteral("width")).toInt();
        int pixelHeight = parameters().value(QStringLiteral("height")).toInt();
        Prison::AbstractBarcode *code = nullptr;
        switch (parameters().value(QStringLiteral("barcodeType")).toInt()) {
        case 1: {
            code = Prison::createBarcode(Prison::DataMatrix);
            const int size = qMin(pixelWidth, pixelHeight);
            pixelWidth = size;
            pixelHeight = size;
            break;
        }
        case 2: {
            code = Prison::createBarcode(Prison::Code39);
            break;
        }
        case 3: {
            code = Prison::createBarcode(Prison::Code93);
            break;
        }
        case 0:
        default: {
            code = Prison::createBarcode(Prison::QRCode);
            const int size = qMin(pixelWidth, pixelHeight);
            pixelWidth = size;
            pixelHeight = size;
            break;
        }
        }
        if (code) {
            code->setData(item->text());
            QFutureWatcher<QImage> *watcher = new QFutureWatcher<QImage>(this);
            connect(watcher, &QFutureWatcher<QImage>::finished, this,
                [this, watcher, code] {
                    setResult(watcher->result());
                    watcher->deleteLater();
                    delete code;
                    emitResult();
                }
            );
            auto future = QtConcurrent::run(code, &Prison::AbstractBarcode::toImage, QSizeF(pixelWidth, pixelHeight));
            watcher->setFuture(future);
            return;
        } else {
            setResult(false);
        }
#else
        setResult(false);
#endif
    } else if (operation == QLatin1String("action")) {
        m_klipper->urlGrabber()->invokeAction(item);
        setResult(true);

    } else if (operation == s_previewKey) {
        const int pixelWidth = parameters().value(s_previewWidthKey).toInt();
        const int pixelHeight = parameters().value(s_previewHeightKey).toInt();
        QUrl url = parameters().value(s_urlKey).toUrl();
        qCDebug(KLIPPER_LOG) << "URL: " << url;
        KFileItem item(url);

        if (pixelWidth <= 0 || pixelHeight <= 0) {
            qCWarning(KLIPPER_LOG) << "Preview size invalid: " << pixelWidth << "x" << pixelHeight;
            iconResult(item);
            return;
        }

        if (!url.isValid() || !url.isLocalFile()) { // no remote files
            qCWarning(KLIPPER_LOG) << "Invalid or non-local url for preview: " << url;
            iconResult(item);
            return;
        }

        KFileItemList urls;
        urls << item;

        KIO::PreviewJob* job = KIO::filePreview(urls, QSize(pixelWidth, pixelHeight));
        job->setIgnoreMaximumSize(true);
        connect(job, &KIO::PreviewJob::gotPreview, this,
            [this](const KFileItem &item, const QPixmap &preview) {
                QVariantMap res;
                res.insert(s_urlKey, item.url());
                res.insert(s_previewKey, preview);
                res.insert(s_iconKey, false);
                res.insert(s_previewWidthKey, preview.size().width());
                res.insert(s_previewHeightKey, preview.size().height());
                setResult(res);
                emitResult();
            }
        );
        connect(job, &KIO::PreviewJob::failed, this,
            [this](const KFileItem &item) {
                iconResult(item);
            }
        );

        job->start();

        return;
    } else {
        setResult(false);
    }
    emitResult();
}
Exemplo n.º 11
0
void TaskJob::start()
{
    LegacyTaskManager::AbstractGroupableItem* item = m_groupManager->rootGroup()->getMemberById(parameters().value(QStringLiteral("Id")).toInt());

    if (!item) {
        return;
    }

    LegacyTaskManager::TaskItem* taskItem = static_cast<LegacyTaskManager::TaskItem*>(item);

    // only a subset of task operations are exported
    const QString operation = operationName();
    if (operation == QLatin1String("setMaximized")) {
        taskItem->task()->setMaximized(parameters().value(QStringLiteral("maximized")).toBool());
        setResult(true);
        return;
    } else if (operation == QLatin1String("setMinimized")) {
        taskItem->task()->setIconified(parameters().value(QStringLiteral("minimized")).toBool());
        setResult(true);
        return;
    } else if (operation == QLatin1String("setShaded")) {
        taskItem->task()->setShaded(parameters().value(QStringLiteral("shaded")).toBool());
        setResult(true);
        return;
    } else if (operation == QLatin1String("setFullScreen")) {
        taskItem->task()->setFullScreen(parameters().value(QStringLiteral("fullScreen")).toBool());
        setResult(true);
        return;
    } else if (operation == QLatin1String("setAlwaysOnTop")) {
        taskItem->task()->setAlwaysOnTop(parameters().value(QStringLiteral("alwaysOnTop")).toBool());
        setResult(true);
        return;
    } else if (operation == QLatin1String("setKeptBelowOthers")) {
        taskItem->task()->setKeptBelowOthers(parameters().value(QStringLiteral("keptBelowOthers")).toBool());
        setResult(true);
        return;
    } else if (operation == QLatin1String("toggleMaximized")) {
        taskItem->task()->toggleMaximized();
        setResult(true);
        return;
    } else if (operation == QLatin1String("toggleMinimized")) {
        taskItem->task()->toggleIconified();
        setResult(true);
        return;
    } else if (operation == QLatin1String("toggleShaded")) {
        taskItem->task()->toggleShaded();
        setResult(true);
        return;
    } else if (operation == QLatin1String("toggleFullScreen")) {
        taskItem->task()->toggleFullScreen();
        setResult(true);
        return;
    } else if (operation == QLatin1String("toggleAlwaysOnTop")) {
        taskItem->task()->toggleAlwaysOnTop();
        setResult(true);
        return;
    } else if (operation == QLatin1String("toggleKeptBelowOthers")) {
        taskItem->task()->toggleKeptBelowOthers();
        setResult(true);
        return;
    } else if (operation == QLatin1String("restore")) {
        taskItem->task()->restore();
        setResult(true);
        return;
    } else if (operation == QLatin1String("resize")) {
        taskItem->task()->resize();
        setResult(true);
        return;
    } else if (operation == QLatin1String("move")) {
        taskItem->task()->move();
        setResult(true);
        return;
    } else if (operation == QLatin1String("raise")) {
        taskItem->task()->raise();
        setResult(true);
        return;
    } else if (operation == QLatin1String("lower")) {
        taskItem->task()->lower();
        setResult(true);
        return;
    } else if (operation == QLatin1String("activate")) {
        taskItem->task()->activate();
        setResult(true);
        return;
    } else if (operation == QLatin1String("activateRaiseOrIconify")) {
        taskItem->task()->activateRaiseOrIconify();
        setResult(true);
        return;
    } else if (operation == QLatin1String("close")) {
        taskItem->task()->close();
        setResult(true);
        return;
    } else if (operation == QLatin1String("toDesktop")) {
        taskItem->task()->toDesktop(parameters().value(QStringLiteral("desktop")).toInt());
        setResult(true);
        return;
    } else if (operation == QLatin1String("toCurrentDesktop")) {
        taskItem->task()->toCurrentDesktop();
        setResult(true);
        return;
    } else if (operation == QLatin1String("publishIconGeometry")) {
        taskItem->task()->publishIconGeometry(parameters().value(QStringLiteral("geometry")).toRect());
        setResult(true);
        return;
    }

    setResult(false);
}
Exemplo n.º 12
0
void ActivityJob::start()
{
    const QString operation = operationName();
    if (operation == "add") {
        //I wonder how well plasma will handle this...
        QString name = parameters()["Name"].toString();
        if (name.isEmpty()) {
            name = i18n("unnamed");
        }
        const QString activityId = m_activityController->addActivity(name);
        setResult(activityId);
        return;
    }
    if (operation == "remove") {
        QString id = parameters()["Id"].toString();
        m_activityController->removeActivity(id);
        setResult(true);
        return;
    }

    //m_id is needed for the rest
    if (m_id.isEmpty()) {
        setResult(false);
        return;
    }
    if (operation == "setCurrent") {
        m_activityController->setCurrentActivity(m_id);
        setResult(true);
        return;
    }
    if (operation == "stop") {
        m_activityController->stopActivity(m_id);
        setResult(true);
        return;
    }
    if (operation == "start") {
        m_activityController->startActivity(m_id);
        setResult(true);
        return;
    }
    if (operation == "setName") {
        m_activityController->setActivityName(m_id, parameters()["Name"].toString());
        setResult(true);
        return;
    }
    if (operation == "setIcon") {
        m_activityController->setActivityIcon(m_id, parameters()["Icon"].toString());
        setResult(true);
        return;
    }
    if (operation == "setEncrypted") {
        m_activityController->setActivityEncrypted(m_id, parameters()["Encrypted"].toBool());
        setResult(true);
        return;
    }
    if (operation == "toggleActivityManager") {
        QDBusMessage message = QDBusMessage::createMethodCall("org.kde.plasma-desktop",
                                                          "/App",
                                                          QString(),
                                                          "toggleActivityManager");
        QDBusConnection::sessionBus().call(message, QDBus::NoBlock);
        setResult(true);
        return;
    }
    setResult(false);
}
Exemplo n.º 13
0
void PowerManagementJob::start()
{
    const QString operation = operationName();
    //qDebug() << "starting operation  ... " << operation;

    if (operation == QLatin1String("lockScreen")) {
        if (KAuthorized::authorizeKAction(QStringLiteral("lock_screen"))) {
            const QString interface(QStringLiteral("org.freedesktop.ScreenSaver"));
            QDBusInterface screensaver(interface, QStringLiteral("/ScreenSaver"));
            screensaver.asyncCall(QStringLiteral("Lock"));
            setResult(true);
            return;
        }
        qDebug() << "operation denied " << operation;
        setResult(false);
        return;
    } else if (operation == QLatin1String("suspend") || operation == QLatin1String("suspendToRam")) {
        Solid::PowerManagement::requestSleep(Solid::PowerManagement::SuspendState, 0, 0);
        setResult(Solid::PowerManagement::supportedSleepStates().contains(Solid::PowerManagement::SuspendState));
        return;
    } else if (operation == QLatin1String("suspendToDisk")) {
        Solid::PowerManagement::requestSleep(Solid::PowerManagement::HibernateState, 0, 0);
        setResult(Solid::PowerManagement::supportedSleepStates().contains(Solid::PowerManagement::HibernateState));
        return;
    } else if (operation == QLatin1String("suspendHybrid")) {
        Solid::PowerManagement::requestSleep(Solid::PowerManagement::HybridSuspendState, 0, 0);
        setResult(Solid::PowerManagement::supportedSleepStates().contains(Solid::PowerManagement::HybridSuspendState));
        return;
    } else if (operation == QLatin1String("requestShutDown")) {
        requestShutDown();
        setResult(true);
        return;
    } else if (operation == QLatin1String("switchUser")) {
        // Taken from kickoff/core/itemhandlers.cpp
        org::kde::krunner::App krunner(QStringLiteral("org.kde.krunner"), QStringLiteral("/App"), QDBusConnection::sessionBus());
        krunner.switchUser();
        setResult(true);
        return;
    } else if (operation == QLatin1String("beginSuppressingSleep")) {
        setResult(Solid::PowerManagement::beginSuppressingSleep(parameters().value(QStringLiteral("reason")).toString()));
        return;
    } else if (operation == QLatin1String("stopSuppressingSleep")) {
        setResult(Solid::PowerManagement::stopSuppressingSleep(parameters().value(QStringLiteral("cookie")).toInt()));
        return;
    } else if (operation == QLatin1String("beginSuppressingScreenPowerManagement")) {
        setResult(Solid::PowerManagement::beginSuppressingScreenPowerManagement(parameters().value(QStringLiteral("reason")).toString()));
        return;
    } else if (operation == QLatin1String("stopSuppressingScreenPowerManagement")) {
        setResult(Solid::PowerManagement::stopSuppressingScreenPowerManagement(parameters().value(QStringLiteral("cookie")).toInt()));
        return;
    } else if (operation == QLatin1String("setBrightness")) {
        setScreenBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool());
        setResult(true);
        return;
    } else if (operation == QLatin1String("setKeyboardBrightness")) {
        setKeyboardBrightness(parameters().value(QStringLiteral("brightness")).toInt(), parameters().value(QStringLiteral("silent")).toBool());
        setResult(true);
        return;
    }

    qDebug() << "don't know what to do with " << operation;
    setResult(false);
}
Exemplo n.º 14
0
void PlayerActionJob::start()
{
    const QString operation(operationName());

    kDebug() << "Trying to perform the action" << operationName();
    if (!m_controller->isOperationEnabled(operation)) {
        setError(Denied);
        emitResult();
        return;
    }

    if (operation == QLatin1String("Quit") || operation == QLatin1String("Raise")
                                           || operation == QLatin1String("SetFullscreen")) {
        listenToCall(m_controller->rootInterface()->asyncCall(operation));
    } else if (operation == QLatin1String("Play")
               || operation == QLatin1String("Pause")
               || operation == QLatin1String("PlayPause")
               || operation == QLatin1String("Stop")
               || operation == QLatin1String("Next")
               || operation == QLatin1String("Previous")) {
        listenToCall(m_controller->playerInterface()->asyncCall(operation));
    } else if (operation == "Seek") {
        if (parameters().value("microseconds").type() == QVariant::LongLong) {
            listenToCall(m_controller->playerInterface()->asyncCall(operation, parameters()["microseconds"]));
        } else {
            setErrorText("microseconds");
            setError(MissingArgument);
            emitResult();
        }
    } else if (operation == "SetPosition") {
        if (parameters().value("microseconds").type() == QVariant::LongLong) {
            listenToCall(m_controller->playerInterface()->asyncCall(operation,
                         m_controller->trackId(),
                         parameters()["microseconds"]));
        } else {
            setErrorText("microseconds");
            setError(MissingArgument);
            emitResult();
        }
    } else if (operation == "OpenUri") {
        if (parameters().value("uri").canConvert<KUrl>()) {
            listenToCall(m_controller->playerInterface()->asyncCall(operation,
                         QString::fromLatin1(parameters()["uri"].toUrl().toEncoded())));
        } else {
            kDebug() << "uri was of type" << parameters().value("uri").userType();
            setErrorText("uri");
            setError(MissingArgument);
            emitResult();
        }
    } else if (operation == "SetLoopStatus") {
        if (parameters().value("status").type() == QVariant::String) {
            setDBusProperty(m_controller->playerInterface()->interface(),
                    "LoopStatus", QDBusVariant(parameters()["status"]));
        } else {
            setErrorText("status");
            setError(MissingArgument);
            emitResult();
        }
    } else if (operation == "SetShuffle") {
        if (parameters().value("on").type() == QVariant::Bool) {
            setDBusProperty(m_controller->playerInterface()->interface(),
                    "Shuffle", QDBusVariant(parameters()["on"]));
        } else {
            setErrorText("on");
            setError(MissingArgument);
            emitResult();
        }
    } else if (operation == "SetRate") {
        if (parameters().value("rate").type() == QVariant::Double) {
            setDBusProperty(m_controller->playerInterface()->interface(),
                    "Rate", QDBusVariant(parameters()["rate"]));
        } else {
            setErrorText("rate");
            setError(MissingArgument);
            emitResult();
        }
    } else if (operation == "SetVolume") {
        if (parameters().value("level").type() == QVariant::Double) {
            setDBusProperty(m_controller->playerInterface()->interface(),
                    "Volume", QDBusVariant(parameters()["level"]));
        } else {
            setErrorText("level");
            setError(MissingArgument);
            emitResult();
        }
    } else {
        setError(UnknownOperation);
        emitResult();
    }
}