--- Vago/trunk/Vago/packageWizard/packagepage2.cpp 2013/03/31 19:02:16 771
+++ s10k/Vago/packageWizard/packagepage2.cpp 2017/12/30 13:57:32 1093
@@ -5,12 +5,12 @@ const QString PackagePage2::ZipCacheFile
const QString PackagePage2::PackagesCacheUrl = "http://mods.oni2.net/jsoncache/"+ZipCacheFile;
const QString PackagePage2::CacheFile = "nodes.json";
-PackagePage2::PackagePage2(Logger *myLogger, QWidget *parent) :
+PackagePage2::PackagePage2(QWidget *parent) :
QWizardPage(parent),
ui(new Ui::PackagePage2)
{
ui->setupUi(this);
- this->myLogger=myLogger;
+
this->setTitle("Mandatory Fields");
//Register fields to be accessible in another pages //Not using mandatory field, it would require empty verification too...
@@ -20,6 +20,14 @@ PackagePage2::PackagePage2(Logger *myLog
registerField("ptDescription", ui->ptDescription,"plainText");
registerField("lePackageNumber", ui->lePackageNumber);
registerField("rbReplace", ui->rbReplace);
+
+ ui->lbFieldsReadOnly->setText("* Fields read only by AEI2 when the package "
+ "isn't at the mod depot."); // Don't use rich text in qtdesigner because it generates platform dependent code
+ QString htmlAsterisk="*";
+ ui->lbAsteriscAuthors->setText(htmlAsterisk);
+ ui->lbAsteriscModName->setText(htmlAsterisk);
+ ui->lbAsteriscVersion->setText(htmlAsterisk);
+ ui->lbAsteriscDescription->setText(htmlAsterisk);
}
bool PackagePage2::validatePage(){
@@ -29,21 +37,21 @@ bool PackagePage2::validatePage(){
QString description=ui->ptDescription->toPlainText();
QString number=ui->lePackageNumber->text();
- bool emptyContent=Util::checkEmptySpaces(QStringList()<lePackageNumber->text();
- if(Util::checkEmptySpaces(QStringList(number))){
- Util::showErrorPopUp("Number is empty. Please fill it first.");
+ if(Util::Validation::checkEmptySpaces(QStringList(number))){
+ Util::Dialogs::showError("Number is empty. Please fill it first.");
return;
}
if(number.size()!=5){
- Util::showErrorPopUp("Invalid number format. It should contain 5 numbers.");
+ Util::Dialogs::showError("Invalid number format. It should contain 5 numeric characters.");
return;
}
- if(Util::isStringInteger(number)){
+ if(Util::Validation::isStringInteger(number)){
bool necessaryToRedownload=false;
- QFile *file = new QFile(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile);
+ QFile file(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile);
- if(!file->exists()){
+ if(!file.exists()){
necessaryToRedownload=true; //File doesn't exist yet, necessary to download
}
- else if (QDateTime::currentDateTime().toTime_t()-QFileInfo(*file).lastModified().toTime_t() > 150){ //checks between 2 minutes (give more 30 seconds due to zip extraction)
+ else if (QDateTime::currentDateTime().toTime_t()-QFileInfo(file).lastModified().toTime_t() > 150){ //checks between 2 minutes (give more 30 seconds due to zip extraction)
necessaryToRedownload=true; //File already exists but already expired (+2 mins without update)
}
- delete file;
if(necessaryToRedownload){
//let's start the search in the web, so we make sure it doesn't exists yet
@@ -100,7 +107,7 @@ void PackagePage2::on_pbCheck_clicked()
}
}
else{
- Util::showErrorPopUp("Number is not numeric.");
+ Util::Dialogs::showError("Number is not numeric.");
}
}
@@ -108,43 +115,30 @@ void PackagePage2::downloadPackagesCache
if(result->error()==QNetworkReply::NoError){
- QFile *file = new QFile(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile);
+ QFile file(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile);
// Create temp folder if it doesn't exist
if(!QDir(GlobalVars::VagoTemporaryDir).exists()){
QDir().mkdir(GlobalVars::VagoTemporaryDir);
}
- if(!file->open(QIODevice::WriteOnly)){
- const QString error="Error fetching package data: creating cache file.";
- this->myLogger->writeString(error);
- Util::showErrorPopUp(error);
+ if(!file.open(QIODevice::WriteOnly)){
+ UtilVago::showAndLogErrorPopUp("Error fetching package data: creating cache file.");
return;
}
- file->write(result->readAll());
- file->close();
+ file.write(result->readAll());
+ file.close();
//Let's extract the cache data
- UnZip uz;
- UnZip::ErrorCode ec = uz.openArchive(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile);
- checkForUnzipError(ec);
-
- //Extract the cache files
- ec = uz.extractAll(GlobalVars::VagoTemporaryDir);
- checkForUnzipError(ec);
-
- //Close zip archive
- uz.closeArchive();
-
- delete file;
+ if(JlCompress::extractFile(GlobalVars::VagoTemporaryDir+"/"+this->ZipCacheFile, "/"+this->CacheFile ,GlobalVars::VagoTemporaryDir+"/"+this->CacheFile).isEmpty()){
+ UtilVago::showAndLogErrorPopUp("An error occurred while unzipping the package data.");
+ }
checkForPackagesInCache();
}
else{
- const QString error="An error occurred checking number availability:\n\n"+result->errorString();
- this->myLogger->writeString(error);
- Util::showErrorLogPopUp(error);
+ UtilVago::showAndLogErrorPopUpLogButton("An error occurred checking number availability:\n\n"+result->errorString());
}
result->deleteLater();
@@ -153,15 +147,13 @@ void PackagePage2::downloadPackagesCache
void PackagePage2::checkForPackagesInCache(){
QString packageNumber=ui->lePackageNumber->text();
- QFile *file = new QFile(GlobalVars::VagoTemporaryDir+"/"+this->CacheFile); //let's read the chache unzipped
- if(!file->open(QIODevice::ReadOnly)){
- const QString error="Error reading downloaded package cache data.";
- this->myLogger->writeString(error);
- Util::showErrorPopUp(error);
+ QFile file(GlobalVars::VagoTemporaryDir+"/"+this->CacheFile); //let's read the chache unzipped
+ if(!file.open(QIODevice::ReadOnly)){
+ UtilVago::showAndLogErrorPopUp("Error reading downloaded package cache data.");
return;
}
//Read file cache to ram
- QString data=file->readAll();
+ QString data=file.readAll();
//Let's play with json engine
@@ -184,26 +176,16 @@ void PackagePage2::checkForPackagesInCac
}
if(!existingModName.isEmpty()){
- Util::showRichErrorPopUp("Package "+packageNumber+" is already being used by the following mod:
"+
+ Util::Dialogs::showRichError("Package "+packageNumber+" is already being used by the following mod:
"+
existingModName+"
"+
"More information here.");
}
else{
- Util::showPopUp("Package "+packageNumber+" seems it's not being used yet! :)");
+ Util::Dialogs::showInfo("It seems that the package number " + packageNumber + " is not being used yet! :)");
}
-
- delete file;
}
void PackagePage2::on_cbType_currentIndexChanged(int index)
{
- ui->lePackageNumber->setText(QString().setNum(index+1)+"000X");
-}
-
-void PackagePage2::checkForUnzipError(UnZip::ErrorCode ec){
- if (ec != UnZip::Ok){
- const QString error="Error found while unzipping the package data. Error number = "+QString::number(ec);
- Util::showErrorPopUp(error);
- this->myLogger->writeString(error);
- }
+ ui->lePackageNumber->setText(QString().setNum(index+1)+"XXXX");
}