Exemplo n.º 1
0
void ActionHandler::addItems(const QStringList &items, const QModelIndex &index)
{
    ClipboardBrowser *c = m_wnd->browserForItem(index);
    if (c == NULL)
        return;

    QVariantMap dataMap;
    dataMap.insert( mimeText, items.join(QString()).toUtf8() );
    c->model()->setData(index, dataMap, contentType::updateData);
}
Exemplo n.º 2
0
void ActionHandler::addItem(const QByteArray &data, const QString &format, const QModelIndex &index)
{
    ClipboardBrowser *c = m_wnd->browserForItem(index);
    if (c == NULL)
        return;

    QVariantMap dataMap;
    if (format == mimeItems)
        deserializeData(&dataMap, data);
    else
        dataMap.insert(format, data);
    c->model()->setData(index, dataMap, contentType::updateData);
}
Exemplo n.º 3
0
bool ScriptableProxyHelper::browserChange(const QVariantMap &data, int row)
{
    INVOKE(browserChange(data, row));
    ClipboardBrowser *c = fetchBrowser();
    if (!c)
        return false;

    const QModelIndex index = c->index(row);
    QVariantMap itemData = index.data(contentType::data).toMap();
    foreach (const QString &mime, data.keys())
        itemData[mime] = data[mime];

    return c->model()->setData(index, itemData, contentType::data);
}
Exemplo n.º 4
0
void ActionHandler::closeAction(Action *action)
{
    QString msg;

    QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information;

    if ( action->actionFailed() ) {
        msg += tr("Error: %1\n").arg(action->errorString()) + action->errorOutput();
        icon = QSystemTrayIcon::Critical;
    } else if ( action->exitCode() != 0 ) {
        msg += tr("Exit code: %1\n").arg(action->exitCode()) + action->errorOutput();
        icon = QSystemTrayIcon::Warning;
    } else if ( !action->inputFormats().isEmpty() ) {
        QModelIndex index = action->index();
        ClipboardBrowser *c = m_wnd->browserForItem(index);
        if (c) {
            QStringList removeFormats = action->inputFormats();
            removeFormats.removeAll( action->outputFormat() );

            if ( !removeFormats.isEmpty() )
                c->model()->setData(index, removeFormats, contentType::removeFormats);
        }
    }

    if ( !msg.isEmpty() ) {
        const int maxWidthPoints =
                ConfigurationManager::instance()->value("notification_maximum_width").toInt();
        const QString command = action->command()
                .replace("copyq eval --", "copyq:");
        const QString name = QString(command).replace('\n', " ");
        const QString format = tr("Command %1").arg(quoteString("%1"));
        const QString title = elideText(name, QFont(), format, pointsToPixels(maxWidthPoints));
        msg.append("\n---\n" + command + "\n---");
        m_wnd->showMessage(title, msg, icon);
    }

    m_activeActionDialog->actionFinished(action);
    Q_ASSERT(m_actionCounter > 0);
    --m_actionCounter;

    emit runningActionsCountChanged();

    action->deleteLater();
}
Exemplo n.º 5
0
void ActionHandler::closeAction(Action *action)
{
    QString msg;

    QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information;

    if ( action->actionFailed() || action->exitStatus() != QProcess::NormalExit ) {
        msg += tr("Error: %1\n").arg(action->errorString()) + action->errorOutput();
        icon = QSystemTrayIcon::Critical;
    } else if ( action->exitCode() != 0 ) {
        msg += tr("Exit code: %1\n").arg(action->exitCode()) + action->errorOutput();
        icon = QSystemTrayIcon::Warning;
    } else if ( !action->inputFormats().isEmpty() ) {
        QModelIndex index = action->index();
        ClipboardBrowser *c = m_wnd->browserForItem(index);
        if (c) {
            QStringList removeFormats;
            if ( action->inputFormats().size() > 1 ) {
                QVariantMap data;
                deserializeData( &data, action->input() );
                removeFormats = data.keys();
            } else {
                removeFormats.append( action->inputFormats()[0] );
            }

            removeFormats.removeAll( action->outputFormat() );
            if ( !removeFormats.isEmpty() )
                c->model()->setData(index, removeFormats, contentType::removeFormats);
        }
    }

    if ( !msg.isEmpty() )
        m_wnd->showMessage( tr("Command %1").arg(quoteString(action->command())), msg, icon );

    m_activeActionDialog->actionFinished(action);
    m_actionData.remove( action->property("COPYQ_ACTION_ID").toByteArray() );
    action->deleteLater();

    if (!hasRunningAction())
        emit hasRunningActionChanged();
}