2
* Copyright (C) 2013 - 2015 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "mountoperationpassworddialog_p.h"
22
#include "ui_mount-operation-password.h"
23
#include "mountoperation.h"
27
MountOperationPasswordDialog::MountOperationPasswordDialog(MountOperation* op, GAskPasswordFlags flags):
30
canAnonymous(flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED ? true : false),
31
canSavePassword(flags & G_ASK_PASSWORD_SAVING_SUPPORTED ? true : false),
32
needUserName(flags & G_ASK_PASSWORD_NEED_USERNAME ? true : false),
33
needPassword(flags & G_ASK_PASSWORD_NEED_PASSWORD ? true : false),
34
needDomain(flags & G_ASK_PASSWORD_NEED_DOMAIN ? true : false) {
36
ui = new Ui::MountOperationPasswordDialog();
39
// change the text of Ok button to Connect
40
ui->buttonBox->buttons().first()->setText(tr("&Connect"));
41
connect(ui->Anonymous, &QAbstractButton::toggled, this, &MountOperationPasswordDialog::onAnonymousToggled);
44
// select ananymous by default if applicable.
45
ui->Anonymous->setChecked(true);
48
ui->Anonymous->setEnabled(false);
51
ui->username->setEnabled(false);
54
ui->password->setEnabled(false);
58
ui->domainLabel->hide();
61
ui->sessionPassword->setChecked(true);
64
ui->storePassword->setEnabled(false);
65
ui->sessionPassword->setEnabled(false);
66
ui->forgetPassword->setChecked(true);
70
MountOperationPasswordDialog::~MountOperationPasswordDialog() {
74
void MountOperationPasswordDialog::onAnonymousToggled(bool checked) {
75
// disable username/password entries if anonymous mode is used
76
bool useUserPassword = !checked;
78
ui->username->setEnabled(useUserPassword);
80
ui->password->setEnabled(useUserPassword);
82
ui->domain->setEnabled(useUserPassword);
85
ui->forgetPassword->setEnabled(useUserPassword);
86
ui->sessionPassword->setEnabled(useUserPassword);
87
ui->storePassword->setEnabled(useUserPassword);
91
void MountOperationPasswordDialog::setMessage(QString message) {
92
ui->message->setText(message);
95
void MountOperationPasswordDialog::setDefaultDomain(QString domain) {
96
ui->domain->setText(domain);
99
void MountOperationPasswordDialog::setDefaultUser(QString user) {
100
ui->username->setText(user);
103
void MountOperationPasswordDialog::done(int r) {
104
GMountOperation* gmop = mountOperation->mountOperation();
106
if(r == QDialog::Accepted) {
109
g_mount_operation_set_username(gmop, ui->username->text().toUtf8());
111
g_mount_operation_set_domain(gmop, ui->domain->text().toUtf8());
113
g_mount_operation_set_password(gmop, ui->password->text().toUtf8());
115
g_mount_operation_set_anonymous(gmop, ui->Anonymous->isChecked());
117
g_mount_operation_reply(gmop, G_MOUNT_OPERATION_HANDLED);
120
g_mount_operation_reply(gmop, G_MOUNT_OPERATION_ABORTED);