コード例 #1
0
ファイル: actionhandler.cpp プロジェクト: Ack0/CopyQ
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);
}
コード例 #2
0
ファイル: scriptableproxy.cpp プロジェクト: DINKIN/CopyQ
bool ScriptableProxyHelper::saveTab(const QString &arg1)
{
    INVOKE(saveTab(arg1));
    ClipboardBrowser *c = fetchBrowser();
    if (!c)
        return false;

    const int i = m_wnd->findTabIndex( c->tabName() );
    return m_wnd->saveTab(arg1, i);
}
コード例 #3
0
ファイル: actionhandler.cpp プロジェクト: Ack0/CopyQ
void ActionHandler::addItem(const QByteArray &data, const QString &format, const QString &tabName)
{
    ClipboardBrowser *c = tabName.isEmpty() ? m_wnd->browser() : m_wnd->tab(tabName);
    c->add( createDataMap(format, data) );

    if (m_lastAction) {
        if (m_lastAction == sender())
            c->setCurrent(0);
        m_lastAction = NULL;
    }
}
コード例 #4
0
ファイル: scriptableproxy.cpp プロジェクト: DINKIN/CopyQ
void ScriptableProxyHelper::browserRemoveRows(QList<int> rows)
{
    ClipboardBrowser *c = fetchBrowser();
    if (!c)
        return;

    qSort( rows.begin(), rows.end(), qGreater<int>() );

    ClipboardBrowser::Lock lock(c);
    foreach (int row, rows)
        c->removeRow(row);
}
コード例 #5
0
ファイル: actionhandler.cpp プロジェクト: Ack0/CopyQ
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);
}
コード例 #6
0
ファイル: actionhandler.cpp プロジェクト: Ack0/CopyQ
void ActionHandler::addItems(const QStringList &items, const QString &tabName)
{
    ClipboardBrowser *c = tabName.isEmpty() ? m_wnd->browser() : m_wnd->tab(tabName);
    ClipboardBrowser::Lock lock(c);
    foreach (const QString &item, items)
        c->add(item);

    if (m_lastAction) {
        if (m_lastAction == sender())
            c->setCurrent(items.size() - 1);
        m_lastAction = NULL;
    }
}
コード例 #7
0
ファイル: scriptableproxy.cpp プロジェクト: DINKIN/CopyQ
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);
}
コード例 #8
0
ファイル: scriptableproxy.cpp プロジェクト: DINKIN/CopyQ
bool ScriptableProxyHelper::browserAdd(const QStringList &texts)
{
    INVOKE(browserAdd(texts));
    ClipboardBrowser *c = fetchBrowser();
    if (!c)
        return false;

    ClipboardBrowser::Lock lock(c);
    foreach (const QString &text, texts) {
        if ( !c->add(text) )
            return false;
    }

    return true;
}
コード例 #9
0
ファイル: scriptableproxy.cpp プロジェクト: DINKIN/CopyQ
QVariantMap ScriptableProxyHelper::nextItem(int where)
{
    INVOKE(nextItem(where));
    ClipboardBrowser *c = fetchBrowser();
    if (!c)
        return QVariantMap();

    const int row = qMax(0, c->currentIndex().row()) + where;
    const QModelIndex index = c->index(row);

    if (!index.isValid())
        return QVariantMap();

    c->setCurrentIndex(index);
    return ::itemData(index);
}
コード例 #10
0
ファイル: scriptableproxy.cpp プロジェクト: DINKIN/CopyQ
bool ScriptableProxyHelper::selectItems(const QList<int> &items)
{
    INVOKE(selectItems(items));
    ClipboardBrowser *c = fetchBrowser();
    if (!c)
        return false;

    c->clearSelection();

    if ( !items.isEmpty() ) {
        c->setCurrent(items.last());

        foreach (int i, items) {
            const QModelIndex index = c->index(i);
            if (index.isValid())
                c->selectionModel()->select(index, QItemSelectionModel::Select);
        }
    }
コード例 #11
0
ファイル: actionhandler.cpp プロジェクト: Ack0/CopyQ
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();
}
コード例 #12
0
ファイル: actionhandler.cpp プロジェクト: lmbrt/CopyQ
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();
}
コード例 #13
0
ファイル: scriptableproxy.cpp プロジェクト: DINKIN/CopyQ
void ScriptableProxyHelper::browserMoveToClipboard(int arg1)
{
    ClipboardBrowser *c = fetchBrowser();
    if (c)
        c->moveToClipboard(c->index(arg1));
}
コード例 #14
0
ConfigurationManager::ConfigurationManager()
    : QDialog()
    , ui(new Ui::ConfigurationManager)
    , m_datfilename()
    , m_options()
    , m_theme()
    , m_commands()
{
    ui->setupUi(this);

    ui->scrollAreaCommand->hide();

    ClipboardBrowser *c = ui->clipboardBrowserPreview;
    c->addItems( QStringList()
                 << tr("Search string is \"item\".")
                 << tr("Select an item and\n"
                       "press F2 to edit.")
                 << tr("Select items and move them with\n"
                       "CTRL and up or down key.")
                 << tr("Remove item with Delete key.")
                 << tr("Example item %1").arg(1)
                 << tr("Example item %1").arg(2)
                 << tr("Example item %1").arg(3) );
    c->filterItems( tr("item") );

#ifdef NO_GLOBAL_SHORTCUTS
    ui->tabShortcuts->deleteLater();
#endif

    Command cmd;
    int i = 0;
    QMenu *menu = new QMenu(ui->toolButtonAddCommand);
    ui->toolButtonAddCommand->setMenu(menu);
    while ( defaultCommand(++i, &cmd) ) {
        menu->addAction( IconFactory::iconFromFile(cmd.icon), cmd.name.remove('&') )
                ->setProperty("COMMAND", i);
    }

    /* general options */
    m_options["maxitems"] = Option(200, "value", ui->spinBoxItems);
    m_options["editor"] = Option(DEFAULT_EDITOR, "text", ui->lineEditEditor);
    m_options["edit_ctrl_return"] = Option(true, "checked", ui->checkBoxEditCtrlReturn);
    m_options["check_clipboard"] = Option(true, "checked", ui->checkBoxClip);
    m_options["confirm_exit"] = Option(true, "checked", ui->checkBoxConfirmExit);
    m_options["vi"] = Option(false, "checked", ui->checkBoxViMode);
    m_options["always_on_top"] = Option(false, "checked", ui->checkBoxAlwaysOnTop);
    m_options["tab_position"] = Option(0, "currentIndex", ui->comboBoxTabPosition);
    m_options["text_wrap"] = Option(true, "checked", ui->checkBoxTextWrap);

    m_options["tray_items"] = Option(5, "value", ui->spinBoxTrayItems);
    m_options["tray_commands"] = Option(true, "checked", ui->checkBoxTrayShowCommands);
    m_options["tray_tab_is_current"] = Option(true, "checked", ui->checkBoxMenuTabIsCurrent);
    m_options["tray_images"] = Option(true, "checked", ui->checkBoxTrayImages);
    m_options["tray_tab"] = Option("", "text", ui->comboBoxMenuTab->lineEdit());

    // Tooltip to show on command line.
    ui->comboBoxMenuTab->lineEdit()->setToolTip( ui->comboBoxMenuTab->toolTip() );

    /* other options */
    m_options["tabs"] = Option(QStringList());
    m_options["command_history_size"] = Option(100);
    m_options["_last_hash"] = Option(0);
#ifndef NO_GLOBAL_SHORTCUTS
    /* shortcuts */
    m_options["toggle_shortcut"] = Option("", "text", ui->pushButton);
    m_options["menu_shortcut"] = Option("", "text", ui->pushButton_2);
    m_options["edit_clipboard_shortcut"] = Option("", "text", ui->pushButton_3);
    m_options["edit_shortcut"] = Option("", "text", ui->pushButton_4);
    m_options["second_shortcut"] = Option("", "text", ui->pushButton_5);
    m_options["show_action_dialog"] = Option("", "text", ui->pushButton_6);
    m_options["new_item_shortcut"] = Option("", "text", ui->pushButton_7);
#endif
#ifdef COPYQ_WS_X11
    /* X11 clipboard selection monitoring and synchronization */
    m_options["check_selection"] = Option(true, "checked", ui->checkBoxSel);
    m_options["copy_clipboard"] = Option(true, "checked", ui->checkBoxCopyClip);
    m_options["copy_selection"] = Option(true, "checked", ui->checkBoxCopySel);
#else
    ui->checkBoxCopySel->hide();
    ui->checkBoxSel->hide();
    ui->checkBoxCopyClip->hide();
#endif

    // values of last submitted action
    m_options["action_has_input"]  = Option(false);
    m_options["action_has_output"] = Option(false);
    m_options["action_separator"]  = Option("\\n");
    m_options["action_output_tab"] = Option("");

    /* appearance options */
    QString name;
    QPalette p;
    name = p.color(QPalette::Base).name();
    m_theme["bg"]          = Option(name, "VALUE", ui->pushButtonColorBg);
    m_theme["edit_bg"]     = Option(name, "VALUE", ui->pushButtonColorEditorBg);
    name = p.color(QPalette::Text).name();
    m_theme["fg"]          = Option(name, "VALUE", ui->pushButtonColorFg);
    m_theme["edit_fg"]     = Option(name, "VALUE", ui->pushButtonColorEditorFg);
    name = p.color(QPalette::Text).lighter(400).name();
    m_theme["num_fg"]      = Option(name, "VALUE", ui->pushButtonColorNumberFg);
    name = p.color(QPalette::AlternateBase).name();
    m_theme["alt_bg"]      = Option(name, "VALUE", ui->pushButtonColorAltBg);
    name = p.color(QPalette::Highlight).name();
    m_theme["sel_bg"]      = Option(name, "VALUE", ui->pushButtonColorSelBg);
    name = p.color(QPalette::HighlightedText).name();
    m_theme["sel_fg"]      = Option(name, "VALUE", ui->pushButtonColorSelFg);
    m_theme["find_bg"]     = Option("#ff0", "VALUE", ui->pushButtonColorFindBg);
    m_theme["find_fg"]     = Option("#000", "VALUE", ui->pushButtonColorFindFg);
    m_theme["font"]        = Option("", "VALUE", ui->pushButtonFont);
    m_theme["edit_font"]   = Option("", "VALUE", ui->pushButtonEditorFont);
    m_theme["find_font"]   = Option("", "VALUE", ui->pushButtonFoundFont);
    m_theme["num_font"]    = Option("", "VALUE", ui->pushButtonNumberFont);
    m_theme["show_number"] = Option(true, "checked", ui->checkBoxShowNumber);
    m_theme["show_scrollbars"] = Option(true, "checked", ui->checkBoxScrollbars);

    m_options["use_system_icons"] = Option(false, "checked", ui->checkBoxSystemIcons);

    /* datafile for items */
    QSettings settings(QSettings::IniFormat, QSettings::UserScope,
                       QCoreApplication::organizationName(),
                       QCoreApplication::applicationName());
    const QString settingsFileName = settings.fileName();
    m_datfilename = settingsFileName;
    m_datfilename.replace( QRegExp(".ini$"), QString("_tab_") );

    // Create directory to save items (otherwise it may not exist at time of saving).
    QDir settingsDir(settingsFileName + "/..");
    if ( settingsDir.mkdir(".") ) {
        log( tr("Cannot create directory for settings \"%1\"!").arg(settingsDir.path()),
             LogError );
    }

    connect(this, SIGNAL(finished(int)), SLOT(onFinished(int)));

    // Tab icons
    QTabWidget *tw = ui->tabWidget;
    tw->setTabIcon( tw->indexOf(ui->tabClipboard), getIcon("", IconPaste) );
    tw->setTabIcon( tw->indexOf(ui->tabGeneral), getIcon("", IconListOl) );
    tw->setTabIcon( tw->indexOf(ui->tabTray), getIcon("", IconInbox) );
    tw->setTabIcon( tw->indexOf(ui->tabCommands), getIcon("", IconCogs) );
    tw->setTabIcon( tw->indexOf(ui->tabShortcuts), getIcon("", IconHandUp) );
    tw->setTabIcon( tw->indexOf(ui->tabAppearance), getIcon("", IconPicture) );

    loadSettings();
}