#include "dialogsettingnetworkshare.h"
#include "ui_dialogsettingnetworkshare.h"

#include "mainwindow.h"

DialogSettingNetworkShare::DialogSettingNetworkShare(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogSettingNetworkShare)
{
    ui->setupUi(this);

    CommonData* pCommonData = MainWindow::GetCommonData();
    NetworkShareInfo* pNetworkShareInfo = pCommonData->GetNetworkShareInfo();

    QString strIP = pNetworkShareInfo->m_strIP;
    QString strID = pNetworkShareInfo->m_strID;
    QString strPassword = pNetworkShareInfo->m_strPassword;
    QString strShareFolder = pNetworkShareInfo->m_strShareFolder;
    QString strVersion = pNetworkShareInfo->m_strVersion;

    if(strIP=="127.0.0.1")
    {
        strIP.clear();
    }

    if(strID=="Share ID")
    {
        strID.clear();
    }

    if(strPassword=="Share Password")
    {
        strPassword.clear();
    }

    if(strShareFolder=="Share Folder")
    {
        strShareFolder.clear();
    }

    if(strVersion=="SMB Version")
    {
        strVersion.clear();
    }



    ui->plainTextEdit_IP->insertPlainText(strIP);
    ui->plainTextEdit_ID->insertPlainText(strID);
    ui->plainTextEdit_Password->insertPlainText(strPassword);
    ui->plainTextEdit_Share_Folder->insertPlainText(strShareFolder);
    ui->plainTextEdit_SMB_Version->insertPlainText(strVersion);
    ui->checkBox_Enable->setChecked(pNetworkShareInfo->m_bEnable);
    ui->checkBox_AutoSend->setChecked(pNetworkShareInfo->m_bAutoSend);

    SetEnable(pNetworkShareInfo->m_bEnable);

    ui->checkBox_Enable->setFocus();
}

DialogSettingNetworkShare::~DialogSettingNetworkShare()
{
    delete ui;
}

void DialogSettingNetworkShare::on_pushButton_Save_clicked()
{
    QString strIP = ui->plainTextEdit_IP->toPlainText();
    QString strID = ui->plainTextEdit_ID->toPlainText();
    QString strPassword = ui->plainTextEdit_Password->toPlainText();
    QString strShareFolder = ui->plainTextEdit_Share_Folder->toPlainText();

    bool bEnable = ui->checkBox_Enable->isChecked();


    done(QDialog::Accepted);
}

void DialogSettingNetworkShare::on_pushButton_Cancel_clicked()
{
    done(QDialog::Rejected);
}

void DialogSettingNetworkShare::on_checkBox_Enable_stateChanged(int arg1)
{
    bool bEnable = ui->checkBox_Enable->isChecked();

    SetEnable(bEnable);
}

void DialogSettingNetworkShare::SetEnable(bool bEnable)
{
    if(bEnable==true)
    {
        ui->plainTextEdit_IP->setEnabled(true);
        ui->plainTextEdit_Share_Folder->setEnabled(true);
        ui->plainTextEdit_ID->setEnabled(true);
        ui->plainTextEdit_Password->setEnabled(true);
        ui->plainTextEdit_SMB_Version->setEnabled(true);
    }
    else
    {
        ui->plainTextEdit_IP->setDisabled(true);
        ui->plainTextEdit_Share_Folder->setDisabled(true);
        ui->plainTextEdit_ID->setDisabled(true);
        ui->plainTextEdit_Password->setDisabled(true);
        ui->plainTextEdit_SMB_Version->setDisabled(true);
    }
}

QString DialogSettingNetworkShare::GetIP()
{
    return ui->plainTextEdit_IP->toPlainText();
}
QString DialogSettingNetworkShare::GetID()
{
    return ui->plainTextEdit_ID->toPlainText();
}
QString DialogSettingNetworkShare::GetPassword()
{
    return ui->plainTextEdit_Password->toPlainText();
}
QString DialogSettingNetworkShare::GetShareFolder()
{
    return ui->plainTextEdit_Share_Folder->toPlainText();
}

QString DialogSettingNetworkShare::GetSMBVersion()
{
    return ui->plainTextEdit_SMB_Version->toPlainText();
}

bool DialogSettingNetworkShare::IsEnabledNetworkShare()
{
    bool bEnable = ui->checkBox_Enable->isChecked();

    return bEnable;
}

void DialogSettingNetworkShare::on_checkBox_AutoSend_clicked()
{
    bool bEnable = ui->checkBox_Enable->isChecked();

    SetEnable(bEnable);
}

bool DialogSettingNetworkShare::IsNetworkAutoSend()
{
    bool bAutoSend = ui->checkBox_AutoSend->isChecked();

    return bAutoSend;
}
