/*
    SPDX-FileCopyrightText: 2009 Grégory Oestreicher <greg@kamago.net>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include "ui_configwidget.h"

#include "settings.h"
#include <KDAV/Enums>
#include <QList>
#include <QPair>
#include <QString>

class KConfigDialogManager;
class QStandardItemModel;

class ConfigWidget : public QWidget
{
    Q_OBJECT

public:
    /**
     * Constructor
     * @param settings The settings
     * @param parent The parent widget
     */
    explicit ConfigWidget(Settings &settings, QWidget *parent = nullptr);
    ~ConfigWidget() override;

    void setPassword(const QString &password);

    void loadSettings();
    void saveSettings() const;

Q_SIGNALS:
    void okEnabled(bool enabled);

private:
    void onSyncRangeStartTypeChanged();
    void checkUserInput();
    void onAddButtonClicked();
    void onSearchButtonClicked();
    void onRemoveButtonClicked();
    void onEditButtonClicked();
    void checkConfiguredUrlsButtonsState();

    void addModelRow(KDAV::Protocol protocol, const QString &url);
    void insertModelRow(int index, KDAV::Protocol protocol, const QString &url);

    Settings &mSettings;
    Ui::ConfigWidget mUi;
    KConfigDialogManager *mManager = nullptr;
    QList<QPair<QString, KDAV::Protocol>> mAddedUrls;
    QList<QPair<QString, KDAV::Protocol>> mRemovedUrls;
    QStandardItemModel *const mModel;
};
