~lubuntu-dev/lxde/libfm-qt-debian-git

« back to all changes in this revision

Viewing changes to src/mountoperationpassworddialog.cpp

  • Committer: Alf Gaida
  • Date: 2015-12-17 15:45:00 UTC
  • Revision ID: git-v1:99d4cf5e0b3761023e2285ffb96a79d050f0bdf4
Tags: upstream/0.10.0+20151214
Adding upstream version 0.10.0+20151214.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 - 2015  Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 *
 
18
 */
 
19
 
 
20
 
 
21
#include "mountoperationpassworddialog_p.h"
 
22
#include "ui_mount-operation-password.h"
 
23
#include "mountoperation.h"
 
24
 
 
25
namespace Fm {
 
26
 
 
27
MountOperationPasswordDialog::MountOperationPasswordDialog(MountOperation* op, GAskPasswordFlags flags):
 
28
  QDialog(),
 
29
  mountOperation(op),
 
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) {
 
35
 
 
36
  ui = new Ui::MountOperationPasswordDialog();
 
37
  ui->setupUi(this);
 
38
 
 
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);
 
42
 
 
43
  if(canAnonymous) {
 
44
    // select ananymous by default if applicable.
 
45
    ui->Anonymous->setChecked(true);
 
46
  }
 
47
  else {
 
48
    ui->Anonymous->setEnabled(false);
 
49
  }
 
50
  if(!needUserName) {
 
51
    ui->username->setEnabled(false);
 
52
  }
 
53
  if(!needPassword) {
 
54
    ui->password->setEnabled(false);
 
55
  }
 
56
  if(!needDomain) {
 
57
    ui->domain->hide();
 
58
    ui->domainLabel->hide();
 
59
  }
 
60
  if(canSavePassword) {
 
61
    ui->sessionPassword->setChecked(true);
 
62
  }
 
63
  else {
 
64
    ui->storePassword->setEnabled(false);
 
65
    ui->sessionPassword->setEnabled(false);
 
66
    ui->forgetPassword->setChecked(true);
 
67
  }
 
68
}
 
69
 
 
70
MountOperationPasswordDialog::~MountOperationPasswordDialog() {
 
71
  delete ui;
 
72
}
 
73
 
 
74
void MountOperationPasswordDialog::onAnonymousToggled(bool checked) {
 
75
  // disable username/password entries if anonymous mode is used
 
76
  bool useUserPassword = !checked;
 
77
  if(needUserName)
 
78
    ui->username->setEnabled(useUserPassword);
 
79
  if(needPassword)
 
80
    ui->password->setEnabled(useUserPassword);
 
81
  if(needDomain)
 
82
    ui->domain->setEnabled(useUserPassword);
 
83
 
 
84
  if(canSavePassword) {
 
85
    ui->forgetPassword->setEnabled(useUserPassword);
 
86
    ui->sessionPassword->setEnabled(useUserPassword);
 
87
    ui->storePassword->setEnabled(useUserPassword);
 
88
  }
 
89
}
 
90
 
 
91
void MountOperationPasswordDialog::setMessage(QString message) {
 
92
  ui->message->setText(message);
 
93
}
 
94
 
 
95
void MountOperationPasswordDialog::setDefaultDomain(QString domain) {
 
96
  ui->domain->setText(domain);
 
97
}
 
98
 
 
99
void MountOperationPasswordDialog::setDefaultUser(QString user) {
 
100
  ui->username->setText(user);
 
101
}
 
102
 
 
103
void MountOperationPasswordDialog::done(int r) {
 
104
  GMountOperation* gmop = mountOperation->mountOperation();
 
105
 
 
106
  if(r == QDialog::Accepted) {
 
107
 
 
108
    if(needUserName)
 
109
      g_mount_operation_set_username(gmop, ui->username->text().toUtf8());
 
110
    if(needDomain)
 
111
      g_mount_operation_set_domain(gmop, ui->domain->text().toUtf8());
 
112
    if(needPassword)
 
113
      g_mount_operation_set_password(gmop, ui->password->text().toUtf8());
 
114
    if(canAnonymous)
 
115
      g_mount_operation_set_anonymous(gmop, ui->Anonymous->isChecked());
 
116
 
 
117
    g_mount_operation_reply(gmop, G_MOUNT_OPERATION_HANDLED);
 
118
  }
 
119
  else {
 
120
    g_mount_operation_reply(gmop, G_MOUNT_OPERATION_ABORTED);
 
121
  }
 
122
  QDialog::done(r);
 
123
}
 
124
 
 
125
} // namespace Fm