return;
key=mkg.getKey();
}
+ //save it
+ exportKey(hname,key);
//set it
- MTSetHost sh=MTSetHost::query(hname,key);
+ MTSetHost sh=MTSetHost::query(hname,key2hash(key));
if(sh.hasError()){
QMessageBox::warning(this,tr("Warning"),tr("Error while creating new host: %1").arg(sh.errorString()));
return;
key=mkg.getKey();
}
//save as mshk file
- QStringList fn;
- QFileDialog fdlg(this,tr("Export Key to File"),QString(),"Magic Smoke Host Key (*.mshk)");
- fdlg.setDefaultSuffix("mshk");
- fdlg.setAcceptMode(QFileDialog::AcceptSave);
- fdlg.setFileMode(QFileDialog::AnyFile);
- fdlg.setDirectory(currentDir());
- if(!fdlg.exec())return;
- fn=fdlg.selectedFiles();
- if(fn.size()!=1)return;
- setCurrentDir(fn[0]);
- QFile fd(fn[0]);
- if(!fd.open(QIODevice::WriteOnly|QIODevice::Truncate)){
- QMessageBox::warning(this,tr("Warning"),tr("Unable to open file %1 for writing: %2").arg(fn[0]).arg(fd.errorString()));
- return;
- }
- QString chk=QCryptographicHash::hash(key.toLatin1(),QCryptographicHash::Md5).toHex();
- QString out="MagicSmokeHostKey\n"+name+"\n"+key+"\n"+chk;
- fd.write(out.toLatin1());
- fd.close();
+ exportKey(name,key);
//convert key to hash
key=key2hash(key);
//set it
updateHosts();
}
+void MHostTab::exportKey(QString name, QString key)
+{
+ QStringList fn;
+ QFileDialog fdlg(this,tr("Export Key to File"),QString(),"Magic Smoke Host Key (*.mshk)");
+ fdlg.setDefaultSuffix("mshk");
+ fdlg.setAcceptMode(QFileDialog::AcceptSave);
+ fdlg.setFileMode(QFileDialog::AnyFile);
+ fdlg.setDirectory(currentDir());
+ fdlg.selectFile(name+".mshk");
+ if(!fdlg.exec())return;
+ fn=fdlg.selectedFiles();
+ if(fn.size()!=1)return;
+ setCurrentDir(fn[0]);
+ QFile fd(fn[0]);
+ if(!fd.open(QIODevice::WriteOnly|QIODevice::Truncate)){
+ QMessageBox::warning(this,tr("Warning"),tr("Unable to open file %1 for writing: %2").arg(fn[0]).arg(fd.errorString()));
+ return;
+ }
+ const QString chk=QCryptographicHash::hash(key.toLatin1(),QCryptographicHash::Md5).toHex();
+ const QString out="MagicSmokeHostKey\n"+name+"\n"+key+"\n"+chk;
+ fd.write(out.toLatin1());
+ fd.close();
+}
+
void MHostTab::importHost()
{
QStringList fn;
//get hname
QString name=hostmodel->data(hostmodel->index(sel.row(),0)).toString();
QString key=hostmodel->data(hostmodel->index(sel.row(),1)).toString();
- if(name[0]=='_' || key==""){
+ if(name.isEmpty() || name[0]=='_' || key==""){
QMessageBox::warning(this,tr("Warning"),tr("This host cannot be exported."));
return;
}
//save
QStringList fn;
- QFileDialog fdlg(this,tr("Export Key to File"),QString(),"Magic Smoke Host Hash (*.mshh)");
+ QFileDialog fdlg(this,tr("Export Hash to File"),QString(),"Magic Smoke Host Hash (*.mshh)");
fdlg.setDefaultSuffix("mshh");
fdlg.setAcceptMode(QFileDialog::AcceptSave);
fdlg.setFileMode(QFileDialog::AnyFile);