~bstrong-f/fisysmgr/trunk

« back to all changes in this revision

Viewing changes to main/source/credsdialog.cpp

  • Committer: Barry Strong
  • Date: 2015-05-06 00:15:25 UTC
  • Revision ID: barry@softtechok.com-20150506001525-0ub7zp3kbjtrt76v
Fix unable to save credential file when credential directory does not yet exist.

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
    credFile.setFileName(filename);
87
87
    if (! credFile.open(QIODevice::ReadOnly)) {
88
88
        sPlayer->play("qrc:///sounds/Warning.mp3");
89
 
        QMessageBox::warning(this,tr("FiSysMg - Message"), tr("Unable to open credentials file ") + "'" + filename + "'");
 
89
        QMessageBox::warning(this,tr("FiSysMg - Message"), tr("Unable to open credentials file ") + "'" + filename + "'.");
90
90
        close();
91
91
        return;
92
92
    }
128
128
 
129
129
void CredsDialog::on_pbSave_clicked() {
130
130
 
131
 
    QTemporaryFile      tempFile(QDir::homePath() + "/.fisysmgr/Creds-XXXXXX");
 
131
    QTemporaryFile      tempFile;
132
132
    QFile::Permissions  perms = QFile::ReadUser | QFile::WriteUser;
133
133
    QString             domain;
134
134
    QString             username;
135
135
    QString             password;
136
136
    QString             filename;
137
137
    int                 current;
 
138
    QString             path;
 
139
    QDir                directory;
138
140
 
139
141
    domain = ui->leDomain->text().trimmed();
140
142
    username = ui->leUserName->text().trimmed();
157
159
            return;
158
160
        }
159
161
    }
 
162
    path = QDir::homePath() + "/.fisysmgr";
 
163
    if (! directory.mkpath(path)) {
 
164
        sPlayer->play("qrc:///sounds/Warning.mp3");
 
165
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to create crendentials directory."));
 
166
        tempFile.remove();
 
167
        return;
 
168
    }
 
169
    tempFile.setFileTemplate(path + "/Creds-XXXXXX");
160
170
    if (! tempFile.open()) {
161
171
        sPlayer->play("qrc:///sounds/Warning.mp3");
162
 
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to create temporary file"));
 
172
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to create temporary file."));
163
173
        return;
164
174
    }
165
175
    if (! tempFile.setPermissions(perms)) {
166
176
        sPlayer->play("qrc:///sounds/Warning.mp3");
167
 
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to set permissions on temporary file"));
 
177
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to set permissions on temporary file."));
168
178
        tempFile.remove();
169
179
        return;
170
180
    }
171
181
    if (domain != "") {
172
182
        if (! writeline(&tempFile, "domain=" + domain)) {
173
183
            sPlayer->play("qrc:///sounds/Warning.mp3");
174
 
            QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to write to temporary file"));
 
184
            QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to write to temporary file."));
175
185
            tempFile.remove();
176
186
            return;
177
187
        }
178
188
    }
179
189
    if (! writeline(&tempFile, "username=" + username)) {
180
190
        sPlayer->play("qrc:///sounds/Warning.mp3");
181
 
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to write to temporary file"));
 
191
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to write to temporary file."));
182
192
        tempFile.remove();
183
193
        return;
184
194
    }
185
195
    if (! write(&tempFile, "password=" + password)) {
186
196
        sPlayer->play("qrc:///sounds/Warning.mp3");
187
 
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to write to temporary file"));
 
197
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to write to temporary file."));
188
198
        tempFile.remove();
189
199
        return;
190
200
    }
193
203
        current = ui->cbCredentials->currentIndex();
194
204
        filename = ui->cbCredentials->itemText(current);
195
205
    }
196
 
    filename = QDir::homePath() + "/.fisysmgr/" + filename;
 
206
    filename = path + "/" + filename;
197
207
    if (rename(tempFile.fileName().toLocal8Bit().data(), filename.toLocal8Bit().data()) != 0) {
198
208
        sPlayer->play("qrc:///sounds/Warning.mp3");
199
 
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to save crendentials file"));
 
209
        QMessageBox::critical(this,tr("FiSysMg - Message"), tr("Unable to save crendentials file."));
200
210
        tempFile.remove();
201
211
        return;
202
212
    }
308
318
}
309
319
 
310
320
void CredsDialog::on_cbCredentials_currentIndexChanged(int) {
311
 
    loadCreds();
 
321
    if (ui->cbCredentials->count()) {
 
322
        loadCreds();
 
323
    } else {
 
324
        ui->leDomain->setText("");
 
325
        ui->leFilename->setText("");
 
326
        ui->lePassword->setText("");
 
327
        ui->leUserName->setText("");
 
328
    }
312
329
}