summaryrefslogtreecommitdiffstats
path: root/copydialog.cpp
blob: da7149478be2b00a2366dae596979a7995826217 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <QGridLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QGroupBox>
#include <QLabel>
#include <QSettings>
#include <QCloseEvent>
#include <QFileDialog>

#include "copydialog.h"

CopyDialog::CopyDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) {
    setAttribute(Qt::WA_DeleteOnClose);
    setWindowTitle(tr("Copy files"));
    QGridLayout *dirGrid = new QGridLayout;
    QLabel *srcL = new QLabel(tr("Source"));
    dirGrid->addWidget(srcL, 0, 0);
    mSrcE = new QLineEdit;
    mSrcE->setReadOnly(true);
    dirGrid->addWidget(mSrcE, 0, 1);
    QLabel *dstL = new QLabel(tr("Destination"));
    dirGrid->addWidget(dstL, 1, 0);
    mDstE = new QLineEdit;
    mDstE->setReadOnly(true);
    dirGrid->addWidget(mDstE, 1, 1);
    QPushButton *dstB = new QPushButton(QIcon::fromTheme("folder"), tr("..."));
    connect(dstB, &QPushButton::clicked, this, &CopyDialog::getDestination);
    dirGrid->addWidget(dstB, 1, 2);
    QLabel *folderL = new QLabel(tr("Folder Name"));
    dirGrid->addWidget(folderL, 2, 0);
    mFolderE = new QLineEdit;
    dirGrid->addWidget(mFolderE, 2, 1);
    QPushButton *refreshB = new QPushButton(QIcon::fromTheme("view-refresh"), QString());
    dirGrid->addWidget(refreshB, 2, 2);
    QGroupBox *dirGB = new QGroupBox("Directories");
    dirGB->setLayout(dirGrid);
    QHBoxLayout *resultL = new QHBoxLayout;
    mResultL = new QLabel;
    resultL->addWidget(mResultL);
    QGroupBox *resultGB = new QGroupBox(tr("Result"));
    resultGB->setLayout(resultL);
    QHBoxLayout *buttonL = new QHBoxLayout;
    QPushButton *copyB = new QPushButton(tr("Copy!"));
    buttonL->addStretch();
    buttonL->addWidget(copyB);
    QPushButton *closeB = new QPushButton(tr("Close"));
    connect(closeB, &QPushButton::clicked, this, &CopyDialog::close);
    buttonL->addWidget(closeB);
    buttonL->addStretch();
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(dirGB, Qt::AlignTop);
    mainLayout->addWidget(resultGB, Qt::AlignVCenter);
    mainLayout->addLayout(buttonL, Qt::AlignBottom);
    setLayout(mainLayout);
    readSettings();
}

void CopyDialog::readSettings(){
    QSettings s;
    resize(s.value("copydlgsize").toSize());
    QString dst = s.value("copydlgdst").toString();
    QFileInfo fi(dst);
    if(fi.exists()){
        mDstE->setText(dst);
    }
}

void CopyDialog::getDestination(){
    QString dir = QFileDialog::getExistingDirectory(this, tr("Select destination Folder"));
    mDstE->setText(dir);
}

void CopyDialog::closeEvent(QCloseEvent *e){
    QSettings s;
    s.setValue("copydlgsize", size());
    s.setValue("copydlgdst", mDstE->text());
    e->accept();
}