aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/fileencryptionwidget.cpp
blob: b225a336611092d2f5d56c27b4f2413ea1d24b35 (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
#include "fileencryptionwidget.h"

FileEncryptionWidget::FileEncryptionWidget(GpgME::GpgContext *ctx, KeyList *keyList, QWidget *parent)
    : QWidget(parent), mCtx(ctx), mKeyList(keyList)
{
    QDeclarativeView *qmlView = new QDeclarativeView;
    qmlView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
    qmlView->setSource(QUrl("qrc:/qml/fileencryption.qml"));

    qmlRoot = qmlView->rootObject();
    connect( qmlRoot, SIGNAL(okClicked()), this, SLOT(slotEncryptFile()));
    connect( qmlRoot, SIGNAL(fileChooserClicked()), this, SLOT(slotChooseFile()));

    QHBoxLayout *mainLayout = new QHBoxLayout(this);
    mainLayout->setSpacing(0);
    mainLayout->setContentsMargins(0,0,0,0);
    mainLayout->addWidget(qmlView);

    connect(mKeyList, SIGNAL(keySelectionChanged()), this, SLOT(slotKeySelectionChanged()));
}

void FileEncryptionWidget::slotKeySelectionChanged() {
    qDebug() << "keySelChanges Signal received in fileencwidget";
     qmlRoot->setProperty("showNoKeySelected", (mKeyList->getSelected()->size() < 1));
}

void FileEncryptionWidget::slotEncryptFile() {

    if(mKeyList->getSelected()->size() < 1) {
        qmlRoot->setProperty("showNoKeySelected", true);
    } else {
        qDebug() << "fine, fine";
    }

}

void FileEncryptionWidget::slotChooseFile() {
    QString path = "";
    if (qmlRoot->property("inputFilePath").toString().size() > 0) {
        path = QFileInfo(qmlRoot->property("inputFilePath").toString()).absolutePath();
    }

    //QString infileName = QFileDialog::getOpenFileName(this, tr("Open File"), path, tr("Files") + tr("All Files (*)"));
    QString infileName = QFileDialog::getOpenFileName(this, tr("Open File"), path);
    qmlRoot->setProperty("inputFilePath", infileName);
}