4c75f9e
/*
4c75f9e
    Copyright (c) 2017, Lukas Holecek <hluk@email.cz>
4c75f9e
4c75f9e
    This file is part of CopyQ.
4c75f9e
4c75f9e
    CopyQ is free software: you can redistribute it and/or modify
4c75f9e
    it under the terms of the GNU General Public License as published by
4c75f9e
    the Free Software Foundation, either version 3 of the License, or
4c75f9e
    (at your option) any later version.
4c75f9e
4c75f9e
    CopyQ is distributed in the hope that it will be useful,
4c75f9e
    but WITHOUT ANY WARRANTY; without even the implied warranty of
4c75f9e
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c75f9e
    GNU General Public License for more details.
4c75f9e
4c75f9e
    You should have received a copy of the GNU General Public License
4c75f9e
    along with CopyQ.  If not, see <http://www.gnu.org/licenses/>.
4c75f9e
*/
4c75f9e
4c75f9e
#ifndef COMMANDDIALOG_H
4c75f9e
#define COMMANDDIALOG_H
4c75f9e
4c75f9e
#include "common/command.h"
4c75f9e
#include "common/commandstore.h"
4c75f9e
4c75f9e
#include <QDialog>
4c75f9e
4c75f9e
namespace Ui {
4c75f9e
class CommandDialog;
4c75f9e
}
4c75f9e
4c75f9e
class QAbstractButton;
4c75f9e
4c75f9e
class CommandDialog : public QDialog
4c75f9e
{
4c75f9e
    Q_OBJECT
4c75f9e
4c75f9e
public:
4c75f9e
    CommandDialog(
4c75f9e
            const Commands &pluginCommands, const QStringList &formats,
4c75f9e
            QWidget *parent = nullptr);
4c75f9e
    ~CommandDialog();
4c75f9e
4c75f9e
    /** Create new commands. */
4c75f9e
    void addCommands(const Commands &commands);
4c75f9e
4c75f9e
    void apply();
4c75f9e
4c75f9e
    bool maybeClose(QWidget *saveMessageBoxParent);
4c75f9e
4c75f9e
public slots:
4c75f9e
    void reject() override;
4c75f9e
4c75f9e
signals:
4c75f9e
    void commandsSaved();
4c75f9e
4c75f9e
private slots:
4c75f9e
    void tryPasteCommandFromClipboard();
4c75f9e
    void copySelectedCommandsToClipboard();
4c75f9e
    void onCommandDropped(const QString &text, int row);
4c75f9e
4c75f9e
    void onCurrentCommandWidgetIconChanged(const QString &iconString);
4c75f9e
    void onCurrentCommandWidgetNameChanged(const QString &name);
4c75f9e
    void onCurrentCommandWidgetAutomaticChanged(bool automatic);
4c75f9e
4c75f9e
    void onFinished(int result);
4c75f9e
4c75f9e
    void on_itemOrderListCommands_addButtonClicked();
4c75f9e
    void on_itemOrderListCommands_itemSelectionChanged();
4c75f9e
    void on_pushButtonLoadCommands_clicked();
4c75f9e
    void on_pushButtonSaveCommands_clicked();
4c75f9e
    void on_pushButtonCopyCommands_clicked();
4c75f9e
    void on_pushButtonPasteCommands_clicked();
4c75f9e
    void on_lineEditFilterCommands_textChanged(const QString &text);
4c75f9e
    void on_buttonBox_clicked(QAbstractButton* button);
4c75f9e
4c75f9e
    void onAddCommands(const QList<Command> &commands);
4c75f9e
4c75f9e
    void onClipboardChanged();
4c75f9e
4c75f9e
private:
4c75f9e
    Commands currentCommands() const;
4c75f9e
4c75f9e
    void addCommandsWithoutSave(const Commands &commands, int targetRow);
4c75f9e
    Commands selectedCommands() const;
4c75f9e
    QString serializeSelectedCommands();
4c75f9e
    bool hasUnsavedChanges() const;
4c75f9e
4c75f9e
    Ui::CommandDialog *ui;
4c75f9e
    Commands m_savedCommands;
4c75f9e
4c75f9e
    Commands m_pluginCommands;
4c75f9e
    QStringList m_formats;
4c75f9e
};
4c75f9e
4c75f9e
#endif // COMMANDDIALOG_H