void MainWindow::on_cmdArchiveAs_clicked()
{
ui->cmdArchiveAs->setEnabled(false);
ArchiveFirstListItems();
}
void MainWindow::ArchiveFirstListItems()
{
if(ui->lstFiles->count()>0)
{
if (ui->optZip->isChecked())
{
ArchiveType = "zip";
NewEXT = "zip";
}
else if (ui->opt7Zip->isChecked())
{
ArchiveType = "7z";
NewEXT = "7z";
}
else if (ui->optCbz->isChecked())
{
ArchiveType = "zip";
NewEXT = "cbz";
}
QFileInfo CurrentFile
(ui
->lstFiles
->item
(0)->text
());
//process->setReadChannel(QProcess::StandardOutput);
//process->setProcessChannelMode(QProcess::MergedChannels);
//process->setProcessChannelMode(QProcess::ForwardedChannels);
QObject::connect(process,
SIGNAL(readyReadStandardOutput
()),
this,
SLOT(readyReadStandardOutput
()));
QObject::connect(process,
SIGNAL(readyReadStandardError
()),
this,
SLOT(readyReadStandardError
()));
//QObject::connect( process, &QProcess::readyReadStandardOutput, this, &MainWindow::readyReadStandardOutput );
//QObject::connect( process, &QProcess::readyReadStandardError, this, &MainWindow::readyReadStandardError );
QObject::connect(process,
SIGNAL(finished
(int)),
this,
SLOT(processFinished
()));
process->setProgram("7z");
Args << "a";
if (ArchiveType == "7z")
{
Args << "-t7z";
Args << "-m0=LZMA2:d512m:fb273";
Args << "-mx9";
Args << "-myx=9";
Args << "-mtc=off";
Args << "-mtm=off";
}
else
{
Args << "-tzip";
Args << "-mx";
Args << "-mtc=off";
}
if(ui->chkDeleteOriginalFilesOnSuccess->isChecked())
{
Args << "-sdel";
}
Args << """" + CurrentFile.filePath() + "." + NewEXT + """" ;
if(CurrentFile.isDir()){
if(ui->chkAddInfoFileDirOnly->isChecked())
{
QFile file(ui
->lstFiles
->item
(0)->text
() + "/info.txt");
{
stream << CurrentFile.fileName() << endl;
}
}
Args << """" + ui->lstFiles->item(0)->text() + "/*""";
}
else
{
Args << """" + ui->lstFiles->item(0)->text() + """";
}
qDebug() << Args;
process->setArguments(Args);
ui->lstFiles->takeItem(0);
process->start();
}
else
{
ui->cmdArchiveAs->setEnabled(true);
}
}
void MainWindow::readyReadStandardOutput()
{
ui->txtOutput->appendPlainText(process->readAllStandardOutput());
//qDebug()<<process->readAllStandardOutput();
//QObject::disconnect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
}
void MainWindow::readyReadStandardError()
{
ui->txtOutput->appendPlainText(process->readAllStandardError());
//qDebug()<<process->readAllStandardError();
//QObject::disconnect(process, SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
}
void MainWindow::processFinished()
{
ArchiveFirstListItems();
}
static QProcess* process = new QProcess();
void MainWindow::on_cmdArchiveAs_clicked()
{
ui->cmdArchiveAs->setEnabled(false);
ArchiveFirstListItems();
}
void MainWindow::ArchiveFirstListItems()
{
if(ui->lstFiles->count()>0)
{
QString ArchiveType;
QString NewEXT;
if (ui->optZip->isChecked())
{
ArchiveType = "zip";
NewEXT = "zip";
}
else if (ui->opt7Zip->isChecked())
{
ArchiveType = "7z";
NewEXT = "7z";
}
else if (ui->optCbz->isChecked())
{
ArchiveType = "zip";
NewEXT = "cbz";
}
QFileInfo CurrentFile(ui->lstFiles->item(0)->text());
process = new QProcess(this);
//process->setReadChannel(QProcess::StandardOutput);
//process->setProcessChannelMode(QProcess::MergedChannels);
//process->setProcessChannelMode(QProcess::ForwardedChannels);
QObject::connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(readyReadStandardOutput()));
QObject::connect(process, SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
//QObject::connect( process, &QProcess::readyReadStandardOutput, this, &MainWindow::readyReadStandardOutput );
//QObject::connect( process, &QProcess::readyReadStandardError, this, &MainWindow::readyReadStandardError );
QObject::connect(process, SIGNAL(finished(int)), this, SLOT(processFinished()));
process->setProgram("7z");
QStringList Args;
Args << "a";
if (ArchiveType == "7z")
{
Args << "-t7z";
Args << "-m0=LZMA2:d512m:fb273";
Args << "-mx9";
Args << "-myx=9";
Args << "-mtc=off";
Args << "-mtm=off";
}
else
{
Args << "-tzip";
Args << "-mx";
Args << "-mtc=off";
}
if(ui->chkDeleteOriginalFilesOnSuccess->isChecked())
{
Args << "-sdel";
}
Args << """" + CurrentFile.filePath() + "." + NewEXT + """" ;
if(CurrentFile.isDir()){
if(ui->chkAddInfoFileDirOnly->isChecked())
{
QFile file(ui->lstFiles->item(0)->text() + "/info.txt");
if (file.open(QIODevice::ReadWrite))
{
QTextStream stream(&file);
stream << CurrentFile.fileName() << endl;
}
}
Args << """" + ui->lstFiles->item(0)->text() + "/*""";
}
else
{
Args << """" + ui->lstFiles->item(0)->text() + """";
}
qDebug() << Args;
process->setArguments(Args);
ui->lstFiles->takeItem(0);
process->start();
}
else
{
ui->cmdArchiveAs->setEnabled(true);
}
}
void MainWindow::readyReadStandardOutput()
{
ui->txtOutput->appendPlainText(process->readAllStandardOutput());
//qDebug()<<process->readAllStandardOutput();
//QObject::disconnect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
}
void MainWindow::readyReadStandardError()
{
ui->txtOutput->appendPlainText(process->readAllStandardError());
//qDebug()<<process->readAllStandardError();
//QObject::disconnect(process, SIGNAL(readyReadStandardError()), this, SLOT(readyReadStandardError()));
}
void MainWindow::processFinished()
{
ArchiveFirstListItems();
}
To copy to clipboard, switch view to plain text mode
Bookmarks