From 877625d070f47cddfb8283351f373879deeda98b Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Sat, 12 Nov 2016 14:33:38 -0500 Subject: New Desktop Utility: lumina-archiver This is a pure Qt5 front-end to the "tar" utility for creating, viewing, and editing archives of various formats. ChangeLog=YES --- .../desktop-utils/lumina-archiver/7ZBackend.cpp | 160 +++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 src-qt5/desktop-utils/lumina-archiver/7ZBackend.cpp (limited to 'src-qt5/desktop-utils/lumina-archiver/7ZBackend.cpp') diff --git a/src-qt5/desktop-utils/lumina-archiver/7ZBackend.cpp b/src-qt5/desktop-utils/lumina-archiver/7ZBackend.cpp new file mode 100644 index 00000000..5d97457f --- /dev/null +++ b/src-qt5/desktop-utils/lumina-archiver/7ZBackend.cpp @@ -0,0 +1,160 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2016, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#include "7ZBackend.h" +#include +#include + +ZBackend::ZBackend(QObject *parent) : QObject(parent){ + //Setup the backend process + PROC.setProcessChannelMode(QProcess::MergedChannels); + PROC.setProgram("7z"); + connect(&PROC, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(procFinished(int, QProcess::ExitStatus)) ); + connect(&PROC, SIGNAL(readyReadStandardOutput()), this, SLOT(processData()) ); + connect(&PROC, SIGNAL(started()), this, SIGNAL(ProcessStarting()) ); + LIST = STARTING = false; +} + +ZBackend::~ZBackend(){ + +} + +//=============== +// PUBLIC +//=============== +void ZBackend::loadFile(QString path, QString pass){ + filepath = path; + flags.clear(); + //contents.clear(); + //Now determine the flags which are used for this type of file (for later use) + if(!pass.isEmpty()){ flags << "-p"+pass; } //add password entry + //Look for some special file extensions which 7z can't seem to detect itself + QStringList ext = path.section("/",-1).section(".",1,-1).split("."); + if(ext.contains("tar")){ + flags << "-ttar"; + } + flags << filepath; //add the actual archive path + if(QFile::exists(path)){ startList(); } + else{ contents.clear(); emit ProcessFinished(); } +} + +QString ZBackend::currentFile(){ + return filepath; +} + +bool ZBackend::isWorking(){ + return (PROC.state() != QProcess::Running); +} + +//Listing routines +QStringList ZBackend::heirarchy(){ + return contents.keys(); +} + +double ZBackend::size(QString file){ + if(!contents.contains(file)){ return -1; } + return contents.value(file)[1].toDouble(); +} + +double ZBackend::csize(QString file){ + if(!contents.contains(file)){ return -1; } + return contents.value(file)[2].toDouble(); +} + +bool ZBackend::isDir(QString file){ + if(!contents.contains(file)){ return false; } + return contents.value(file)[0].startsWith("D"); +} + +//Modification routines +void ZBackend::startAdd(QStringList paths){ + QStringList args; + args << "a" << flags << paths; + STARTING=true; + PROC.start("7z", args); +} + +void ZBackend::startRemove(QStringList paths){ + QStringList args; + args << "d" << flags << paths; + STARTING=true; + PROC.start("7z", args); +} + +void ZBackend::startExtract(QString path, bool preservepaths){ + QStringList args; + args << (preservepaths ? "x" : "e") << flags << "-o"+path; + STARTING=true; + PROC.start("7z", args); +} + +//=============== +// PUBLIC SLOTS +//=============== + +//=============== +// PRIVATE +//=============== +void ZBackend::parseLines(QStringList lines){ + if(STARTING){ + //Ignore all the p7zip header info + while(STARTING && !lines.isEmpty()){ + if(lines[0]=="--"){ STARTING = false; } //found the end of the headers + lines.removeAt(0); + } + } + for(int i=0; i6){ info[5] = info[5]+" "+info[6]; info.removeAt(6); } //Filename has spaces in it + contents.insert(info[5], QStringList() << info[2] << info[3] << info[4]); //Save the + } + } +} + +void ZBackend::startList(){ + contents.clear(); + QStringList args; + args << "l"; //list (lowercase L) + LIST = STARTING=true; + PROC.start("7z", QStringList() << args << flags); +} + +//=============== +// PRIVATE SLOTS +//=============== +void ZBackend::procFinished(int retcode, QProcess::ExitStatus){ + processData(); + //qDebug() << "Process Finished:" << PROC.arguments() << retcode; + LIST = STARTING = false; + if(PROC.arguments().contains("l")){ + emit ProcessFinished(); + }else{ + if(retcode==0){ + QStringList args = PROC.arguments(); + for(int i=0; i