Esempio n. 1
0
void ClipboardMonitor::readyRead()
{
    m_socket->blockSignals(true);

    while ( m_socket->bytesAvailable() > 0 ) {
        QByteArray msg;
        if( !readMessage(m_socket, &msg) ) {
            log( tr("Cannot read message from server!"), LogError );
            return;
        }

        ClipboardItem item;
        QDataStream in(&msg, QIODevice::ReadOnly);
        in >> item;

        /* Does server send settings for monitor? */
        QByteArray settings_data = item.data()->data("application/x-copyq-settings");
        if ( !settings_data.isEmpty() ) {

            QDataStream settings_in(settings_data);
            QVariantMap settings;
            settings_in >> settings;

#ifdef COPYQ_LOG_DEBUG
            {
                COPYQ_LOG("Loading configuration:");
                foreach (const QString &key, settings.keys()) {
                    QVariant val = settings[key];
                    const QString str = val.canConvert<QStringList>() ? val.toStringList().join(",")
                                                                      : val.toString();
                    COPYQ_LOG( QString("    %1=%2").arg(key).arg(str) );
                }
            }
#endif

            if ( settings.contains("formats") )
                m_formats = settings["formats"].toStringList();
#ifdef COPYQ_WS_X11
            if ( settings.contains("copy_clipboard") )
                m_copyclip = settings["copy_clipboard"].toBool();
            if ( settings.contains("copy_selection") )
                m_copysel = settings["copy_selection"].toBool();
            if ( settings.contains("check_selection") )
                m_checksel = settings["check_selection"].toBool();
#endif

            connect( QApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)),
                     this, SLOT(checkClipboard(QClipboard::Mode)) );

#ifdef COPYQ_WS_X11
            checkClipboard(QClipboard::Selection);
#endif
            checkClipboard(QClipboard::Clipboard);

            COPYQ_LOG("Configured");
        } else {
Esempio n. 2
0
void ClipboardModel::insertItem(const QVariantMap &data, int row)
{
    ClipboardItem item;
    item.setData(data);

    beginInsertRows(QModelIndex(), row, row);

    m_clipboardList.insert(row, item);

    endInsertRows();
}
Esempio n. 3
0
void ClipboardMonitor::clipboardChanged(QClipboard::Mode, QMimeData *data)
{
    ClipboardItem item;

    item.setData(data);

    // send clipboard item
    QByteArray msg;
    QDataStream out(&msg, QIODevice::WriteOnly);
    out << item;
    writeMessage(m_socket, msg);
}
Esempio n. 4
0
bool ClipboardModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
    if ( index.isValid() && (role == Qt::EditRole || role == contentType::notes) ) {
        int row = index.row();
        ClipboardItem *item = m_clipboardList[row];
        if (role == Qt::EditRole)
            item->setData(value);
        else
            item->setData( mimeItemNotes, value.toString().toUtf8() );
        emit dataChanged(index, index);
        return true;
    }
    return false;
}