diff options
author | Ken Moore <ken@ixsystems.com> | 2016-11-12 15:24:14 -0500 |
---|---|---|
committer | Ken Moore <ken@ixsystems.com> | 2016-11-12 15:24:14 -0500 |
commit | 966dbb1eb90d820a3385f25ecf474f386e859e6d (patch) | |
tree | 4248a75d5601ff6ce7f9f7c8bbcfa7140ab1873d | |
parent | New Desktop Utility: lumina-archiver (diff) | |
download | lumina-966dbb1eb90d820a3385f25ecf474f386e859e6d.tar.gz lumina-966dbb1eb90d820a3385f25ecf474f386e859e6d.tar.bz2 lumina-966dbb1eb90d820a3385f25ecf474f386e859e6d.zip |
Add support for extracting a single file from an archive for viewing temporarily.
-rw-r--r-- | src-qt5/desktop-utils/lumina-archiver/MainUI.cpp | 25 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-archiver/MainUI.h | 4 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp | 23 | ||||
-rw-r--r-- | src-qt5/desktop-utils/lumina-archiver/TarBackend.h | 2 |
4 files changed, 43 insertions, 11 deletions
diff --git a/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp b/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp index 612c7beb..9710045c 100644 --- a/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-archiver/MainUI.cpp @@ -34,6 +34,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->actionRemove_File, SIGNAL(triggered()), this, SLOT(remFiles()) ); connect(ui->actionExtract_All, SIGNAL(triggered()), this, SLOT(extractFiles()) ); connect(ui->actionAdd_Dirs, SIGNAL(triggered()), this, SLOT(addDirs()) ); + connect(ui->tree_contents, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(ViewFile(QTreeWidgetItem*)) ); ui->progressBar->setVisible(false); ui->label_progress->setVisible(false); ui->actionAdd_File->setEnabled(false); @@ -85,22 +86,26 @@ QTreeWidgetItem* MainUI::findItem(QString path, QTreeWidgetItem *start){ return 0; //nothing found } -void MainUI::cleanItems(QStringList list, QTreeWidgetItem *start){ +bool MainUI::cleanItems(QStringList list, QTreeWidgetItem *start){ + bool changed = false; if(start==0){ for(int i=0; i<ui->tree_contents->topLevelItemCount(); i++){ - cleanItems(list, ui->tree_contents->topLevelItem(i)); + changed = changed || cleanItems(list, ui->tree_contents->topLevelItem(i)); if(!list.contains(ui->tree_contents->topLevelItem(i)->whatsThis(0)) ){ delete ui->tree_contents->topLevelItem(i); + changed = true; } } }else{ for(int i=0; i<start->childCount(); i++){ - cleanItems(list, start->child(i)); + changed = changed || cleanItems(list, start->child(i)); if(!list.contains(start->child(i)->whatsThis(0)) ){ delete start->child(i); + changed = true; } } } + return changed; } //Functions for setting the valid file extensions ("tar" limitations) @@ -190,12 +195,17 @@ void MainUI::extractFiles(){ BACKEND->startExtract(dir, true); } +void MainUI::ViewFile(QTreeWidgetItem *it){ + if(it->childCount()>0){ return; } //directory - not viewable + BACKEND->startViewFile(it->whatsThis(0)); +} + void MainUI::UpdateTree(){ ui->tree_contents->setHeaderLabels( QStringList() << tr("File") << tr("MimeType") << tr("Size") << tr("Compressed")+" " ); QStringList files = BACKEND->heirarchy(); files.sort(); //Remove any entries for file no longer in the archive - cleanItems(files); + bool changed = cleanItems(files); qDebug() << "Found Files:" << files; for(int i=0; i<files.length(); i++){ if(0 != findItem(files[i]) ){ continue; } //already in the tree widget @@ -217,10 +227,13 @@ void MainUI::UpdateTree(){ }else{ ui->tree_contents->addTopLevelItem(it); } + changed = true; } int wid = 0; - for(int i=3; i>0; i--){ui->tree_contents->resizeColumnToContents(i); wid+= ui->tree_contents->columnWidth(i); } - ui->tree_contents->setColumnWidth(0, ui->tree_contents->viewport()->width()-wid); + if(changed){ + for(int i=3; i>0; i--){ui->tree_contents->resizeColumnToContents(i); wid+= ui->tree_contents->columnWidth(i); } + ui->tree_contents->setColumnWidth(0, ui->tree_contents->viewport()->width()-wid); + } } //Backend Handling diff --git a/src-qt5/desktop-utils/lumina-archiver/MainUI.h b/src-qt5/desktop-utils/lumina-archiver/MainUI.h index 802d241b..09207aa3 100644 --- a/src-qt5/desktop-utils/lumina-archiver/MainUI.h +++ b/src-qt5/desktop-utils/lumina-archiver/MainUI.h @@ -31,7 +31,7 @@ private: Backend *BACKEND; QTreeWidgetItem* findItem(QString path, QTreeWidgetItem *start = 0); - void cleanItems(QStringList list, QTreeWidgetItem *start = 0); + bool cleanItems(QStringList list, QTreeWidgetItem *start = 0); //returns true if anything gets cleaned //Functions for setting the valid file extensions ("tar" limitations) QString CreateFileTypes(); @@ -44,7 +44,7 @@ private slots: void addDirs(); void remFiles(); void extractFiles(); - + void ViewFile(QTreeWidgetItem *it); void UpdateTree(); diff --git a/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp b/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp index f6738855..4dee247b 100644 --- a/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp +++ b/src-qt5/desktop-utils/lumina-archiver/TarBackend.cpp @@ -6,12 +6,13 @@ //=========================================== #include "TarBackend.h" #include <QFile> +#include <QDir> #include <QDebug> Backend::Backend(QObject *parent) : QObject(parent){ //Setup the backend process PROC.setProcessChannelMode(QProcess::MergedChannels); - PROC.setProgram("7z"); + PROC.setProgram("tar"); 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()) ); @@ -36,7 +37,7 @@ void Backend::loadFile(QString path){ bool Backend::canModify(){ static QStringList validEXT; - if(validEXT.isEmpty()){ + if( validEXT.isEmpty() ){ validEXT << ".zip" << ".tar.gz" << ".tgz" << ".tar.xz" << ".txz" << ".tar.bz" << ".tbz" << ".tar.bz2" << ".tbz2" << ".tar" \ << ".tar.lzma" << ".tlz" << ".cpio" << ".pax" << ".ar" << ".shar" << ".7z"; } @@ -120,6 +121,15 @@ void Backend::startExtract(QString path, bool overwrite){ if(!overwrite){ args << "-k"; } args << flags << "-C" << path; STARTING=true; + //qDebug() << "Starting command:" << "tar" << args; + PROC.start("tar", args); +} + +void Backend::startViewFile(QString path){ + QStringList args; + args << "-x"; + args << flags <<"--include" << path <<"--strip-components" << QString::number(path.count("/")) << "-C" << QDir::tempPath(); + STARTING=true; qDebug() << "Starting command:" << "tar" << args; PROC.start("tar", args); } @@ -175,7 +185,14 @@ void Backend::procFinished(int retcode, QProcess::ExitStatus){ QStringList args = PROC.arguments(); if(args.contains("-x") && retcode==0){ needupdate=false; - QProcess::startDetached("xdg-open \""+ args.last()+"\""); //just extracted to a dir - open it now + if(args.contains("--include")){ + //Need to find the full path to the extracted file + QString path = args.last() +"/"+ args[ args.indexOf("--include")+1].section("/",-1); + QFile::setPermissions(path, QFileDevice::ReadOwner); + QProcess::startDetached("xdg-open \""+path+"\""); + }else{ + QProcess::startDetached("xdg-open \""+ args.last()+"\""); //just extracted to a dir - open it now + } }else if(args.contains("-c") && QFile::exists(tmpfilepath)){ if(retcode==0){ QFile::remove(filepath); diff --git a/src-qt5/desktop-utils/lumina-archiver/TarBackend.h b/src-qt5/desktop-utils/lumina-archiver/TarBackend.h index 11c61319..f12aae63 100644 --- a/src-qt5/desktop-utils/lumina-archiver/TarBackend.h +++ b/src-qt5/desktop-utils/lumina-archiver/TarBackend.h @@ -35,6 +35,8 @@ public: void startRemove(QStringList paths); void startExtract(QString path, bool overwrite); //path to dir + void startViewFile(QString path); + public slots: private: |