~bstrong-f/fisysmgr/trunk

« back to all changes in this revision

Viewing changes to main/source/credsdialog.cpp

  • Committer: Barry Strong
  • Date: 2015-05-10 13:05:49 UTC
  • Revision ID: barry@softtechok.com-20150510130549-xlbzzt5slojawh70
Replaced password dialog with credentials dialog. Added minimal about box. Added change mout option value dialog. modified to compile with Qt4 or Qt5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
  You should have received a copy of the GNU General Public License
15
15
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
16
*/
17
 
#include "include/credsdialog.h"
 
17
#include "credsdialog.h"
18
18
#include "ui_credsdialog.h"
19
19
 
20
 
CredsDialog::CredsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::CredsDialog) {
 
20
CredsDialog::CredsDialog(int mode, QWidget *parent) : QDialog(parent), ui(new Ui::CredsDialog) {
21
21
 
22
22
    QDir        credsDir;
23
23
    QStringList fileList;
 
24
    QModelIndex index;
 
25
    int         count;
24
26
 
 
27
    loading = true;
25
28
    ui->setupUi(this);
 
29
    if (mode == 0) {
 
30
        ui->pbClose->hide();
 
31
    } else {
 
32
        ui->pbOK->hide();
 
33
        ui->pbDlgCancel->hide();
 
34
    }
26
35
    ui->pbOK->setIcon(QIcon::fromTheme("dialog-ok-apply", QIcon(":/icons/dialog-ok-apply.png")));
27
36
    ui->pbDlgCancel->setIcon(QIcon::fromTheme("dialog-cancel", QIcon(":/icons/dialog-ok.png")));
 
37
    ui->pbClose->setIcon(QIcon::fromTheme("application-exit", QIcon(":/icons/application-exit.png")));
28
38
    fnRegExp.setPattern("[^/]*");
29
39
    fnValidator.setRegExp(fnRegExp);
30
40
    sortProxy = new QSortFilterProxyModel(ui->cbCredentials);
38
48
        return;
39
49
    credsDir.setFilter(QDir::Files);
40
50
    fileList = credsDir.entryList();
41
 
    if (fileList.count() == 0)
 
51
    count = fileList.count();
 
52
    if (count == 0)
42
53
        return;
43
54
    ui->pbOK->setEnabled(true);
44
55
    ui->pbEdit->setEnabled(true);
45
56
    ui->pbDelete->setEnabled(true);
46
57
    ui->leFilename->setValidator(&fnValidator);
47
 
    ui->cbCredentials->addItems(fileList);
48
 
    ui->cbCredentials->model()->sort(0);
 
58
    for (int idx = 0; idx < count; idx ++) {
 
59
        ui->cbCredentials->model()->insertRow(0);
 
60
        index = ui->cbCredentials->model()->index(0,0);
 
61
        ui->cbCredentials->model()->setData(index, fileList[idx]);
 
62
    }
 
63
    if (count > 0) {
 
64
        sortProxy->invalidate();
 
65
        ui->cbCredentials->model()->sort(0, Qt::AscendingOrder);
 
66
    }
 
67
    loading = false;
49
68
    editMode = false;
50
69
    QTimer::singleShot(0,this, SLOT(loadCreds()));
51
70
}
62
81
    return dirName + ui->cbCredentials->itemText(current);
63
82
}
64
83
 
 
84
QString CredsDialog::workgroup() {
 
85
    return ui->leDomain->text();
 
86
}
 
87
 
 
88
QString CredsDialog::username() {
 
89
    return ui->leUserName->text();
 
90
}
 
91
 
 
92
QString CredsDialog::password() {
 
93
    return ui->lePassword->text();
 
94
}
 
95
 
65
96
void CredsDialog::setValue(QString val) {
66
97
 
67
98
    int idx;
81
112
    QString     inLine;
82
113
    QStringList fields;
83
114
 
 
115
    if(loading)
 
116
        return;
84
117
    current = ui->cbCredentials->currentIndex();
85
118
    filename = dirName + ui->cbCredentials->itemText(current);
86
119
    credFile.setFileName(filename);
87
120
    if (! credFile.open(QIODevice::ReadOnly)) {
88
 
        sPlayer->play("qrc:///sounds/Warning.mp3");
 
121
        sPlayer->play("qrc:///sounds/Warning.ogg");
89
122
        QMessageBox::warning(this,tr("FiSysMg - Message"), tr("Unable to open credentials file ") + "'" + filename + "'.");
90
123
        close();
91
124
        return;
137
170
    int                 current;
138
171
    QString             path;
139
172
    QDir                directory;
 
173
    QModelIndex         index;
140
174
 
141
175
    domain = ui->leDomain->text().trimmed();
142
176
    username = ui->leUserName->text().trimmed();
161
195
    }
162
196
    path = QDir::homePath() + "/.fisysmgr";
163
197
    if (! directory.mkpath(path)) {
164
 
        sPlayer->play("qrc:///sounds/Warning.mp3");
 
198
        sPlayer->play("qrc:///sounds/Warning.ogg");
165
199
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to create crendentials directory."));
166
200
        tempFile.remove();
167
201
        return;
168
202
    }
169
203
    tempFile.setFileTemplate(path + "/Creds-XXXXXX");
170
204
    if (! tempFile.open()) {
171
 
        sPlayer->play("qrc:///sounds/Warning.mp3");
 
205
        sPlayer->play("qrc:///sounds/Warning.ogg");
172
206
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to create temporary file."));
173
207
        return;
174
208
    }
175
209
    if (! tempFile.setPermissions(perms)) {
176
 
        sPlayer->play("qrc:///sounds/Warning.mp3");
 
210
        sPlayer->play("qrc:///sounds/Warning.ogg");
177
211
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to set permissions on temporary file."));
178
212
        tempFile.remove();
179
213
        return;
180
214
    }
181
215
    if (domain != "") {
182
216
        if (! writeline(&tempFile, "domain=" + domain)) {
183
 
            sPlayer->play("qrc:///sounds/Warning.mp3");
 
217
            sPlayer->play("qrc:///sounds/Warning.ogg");
184
218
            QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to write to temporary file."));
185
219
            tempFile.remove();
186
220
            return;
187
221
        }
188
222
    }
189
223
    if (! writeline(&tempFile, "username=" + username)) {
190
 
        sPlayer->play("qrc:///sounds/Warning.mp3");
 
224
        sPlayer->play("qrc:///sounds/Warning.ogg");
191
225
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to write to temporary file."));
192
226
        tempFile.remove();
193
227
        return;
194
228
    }
195
229
    if (! write(&tempFile, "password=" + password)) {
196
 
        sPlayer->play("qrc:///sounds/Warning.mp3");
 
230
        sPlayer->play("qrc:///sounds/Warning.ogg");
197
231
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to write to temporary file."));
198
232
        tempFile.remove();
199
233
        return;
205
239
    }
206
240
    filename = path + "/" + filename;
207
241
    if (rename(tempFile.fileName().toLocal8Bit().data(), filename.toLocal8Bit().data()) != 0) {
208
 
        sPlayer->play("qrc:///sounds/Warning.mp3");
 
242
        sPlayer->play("qrc:///sounds/Warning.ogg");
209
243
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to save crendentials file."));
210
244
        tempFile.remove();
211
245
        return;
212
246
    }
213
247
    if (! editMode) {
214
 
        ui->cbCredentials->addItem(ui->leFilename->text());
215
 
        ui->cbCredentials->model()->sort(0);
 
248
        loading = true;
 
249
        ui->cbCredentials->model()->insertRow(0);
 
250
        index = ui->cbCredentials->model()->index(0,0);
 
251
        ui->cbCredentials->model()->setData(index, ui->leFilename->text());
 
252
        sortProxy->invalidate();
 
253
        ui->cbCredentials->model()->sort(0, Qt::AscendingOrder);
 
254
        loading = false;
216
255
        current = ui->cbCredentials->findText(ui->leFilename->text());
217
256
        if (current >= 0)
218
257
            ui->cbCredentials->setCurrentIndex(current);
300
339
        return;
301
340
    filename = dirName + name;
302
341
    if (! QFile::remove(filename)) {
303
 
        sPlayer->play("qrc:///sounds/Warning.mp3");
 
342
        sPlayer->play("qrc:///sounds/Warning.ogg");
304
343
        QMessageBox::critical(this,tr("FiSysMg - Message"),
305
344
                              tr("Unable to remove crendentials file '") + name + "'");
306
345
    }
307
 
    ui->cbCredentials->removeItem(current);
308
 
    ui->cbCredentials->model()->sort(0);
 
346
    ui->cbCredentials->model()->removeRow(current);
 
347
    if (ui->cbCredentials->count() == 0) {
 
348
        ui->pbDelete->setEnabled(false);
 
349
        ui->pbOK->setEnabled(false);
 
350
        return;
 
351
    }
309
352
}
310
353
 
311
354
void CredsDialog::on_leDomain_editingFinished() {
327
370
        ui->leUserName->setText("");
328
371
    }
329
372
}
 
373
 
 
374
void CredsDialog::on_pbClose_clicked() {
 
375
    close();
 
376
}