diff options
author | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-07-15 19:16:26 +0000 |
---|---|---|
committer | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-07-15 19:16:26 +0000 |
commit | 95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df (patch) | |
tree | 59dec9ad30bbb5457ae66eddbe59b3348dd1feec | |
parent | 440f3fe87e9adc95f6155b924162e335f2b434e0 (diff) | |
download | SheMov-95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df.tar.gz SheMov-95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df.tar.bz2 SheMov-95bd97d4f5dc4d0ee91cfeeff89b88ff3d8f26df.zip |
-finished calling extractor
-QProcess doesn't work as promised in the docs, dunno how to do it yet, but we need a thread to keep the GUI responsive...
-fixed some bugs with the extractionpaths
git-svn-id: file:///var/svn/repos2/shemov/trunk@387 f440f766-f032-0410-8965-dc7d17de2ca0
-rw-r--r-- | configurationdialog.cpp | 3 | ||||
-rw-r--r-- | extractordialog.cpp | 31 | ||||
-rw-r--r-- | extractordialog.h | 2 | ||||
-rw-r--r-- | filesystemwidget.cpp | 17 | ||||
-rw-r--r-- | filesystemwidget.h | 1 | ||||
-rw-r--r-- | fileview.cpp | 5 | ||||
-rw-r--r-- | shemov.cpp | 23 |
7 files changed, 76 insertions, 6 deletions
diff --git a/configurationdialog.cpp b/configurationdialog.cpp index 0a94134..34e5d10 100644 --- a/configurationdialog.cpp +++ b/configurationdialog.cpp @@ -135,7 +135,7 @@ void ConfigurationDialog::readSettings(){ QStringList mvArgs = s.value("paths/movieviewerargs").toStringList(); mMovieViewerArgs->setText(mvArgs.join(" ")); mArchiver->setText(s.value("paths/archiver", "/usr/bin/7z").toString()); - QStringList arArgs = s.value("paths/archiveargs").toStringList(); + QStringList arArgs = s.value("paths/archiverargs").toStringList(); mArchiverArgs->setText(arArgs.join(" ")); QStringList extractPaths = s.value("paths/extractpaths").toStringList(); mArchivePaths->addItems(extractPaths); @@ -156,3 +156,4 @@ void ConfigurationDialog::writeSettings(){ s.setValue("paths/archiverargs", aArgs); s.setValue("paths/extractpaths", mPaths); } + diff --git a/extractordialog.cpp b/extractordialog.cpp index 7897bf4..cf2c18d 100644 --- a/extractordialog.cpp +++ b/extractordialog.cpp @@ -14,11 +14,16 @@ #include <QByteArray> #include <QApplication> +#include <QDebug> + #include "extractordialog.h" +//Well, f**king doc of QProcess... The extraction has to be a Thread, otherwise GUI will block + ExtractorDialog::ExtractorDialog(const QString &archive, const QString &extractTo, QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), mArchive(archive), mExtractTo(extractTo){ QVBoxLayout *mainLayout = new QVBoxLayout; mOutput = new QTextEdit; + mOutput->setReadOnly(true); mCancelClose = new QPushButton(tr("Close")); connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); mainLayout->addWidget(mOutput); @@ -26,16 +31,19 @@ ExtractorDialog::ExtractorDialog(const QString &archive, const QString &extractT setLayout(mainLayout); mExtractor = new QProcess(this); - connect(mExtractor, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStatusChanged(QProcess::ProcessState))); + connect(mExtractor, SIGNAL(started()), this, SLOT(extractionStarted())); + connect(mExtractor, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(extractionFinished())); + //connect(mExtractor, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(processStatusChanged(QProcess::ProcessState))); QString wTitle = QString(tr("%1 - extracting from %2")).arg(qApp->applicationName()).arg(archive); setWindowTitle(wTitle); start(); - + qDebug() << "state" << mExtractor->state(); } void ExtractorDialog::processStatusChanged(QProcess::ProcessState newState){ + qDebug() << "State changed to" << newState; if((newState == QProcess::Running) || (newState == QProcess::Starting)){ mCancelClose->disconnect(SIGNAL(clicked())); connect(mCancelClose, SIGNAL(clicked()), this, SLOT(killProcess())); @@ -48,6 +56,18 @@ void ExtractorDialog::processStatusChanged(QProcess::ProcessState newState){ } } +void ExtractorDialog::extractionStarted(){ + mCancelClose->disconnect(SIGNAL(clicked())); + connect(mCancelClose, SIGNAL(clicked()), this, SLOT(killProcess())); + mCancelClose->setText(tr("Cancel")); +} + +void ExtractorDialog::extractionFinished(){ + mCancelClose->disconnect(SIGNAL(clicked())); + connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); + mCancelClose->setText(tr("Close")); +} + void ExtractorDialog::killProcess(){ mExtractor->terminate(); mCancelClose->disconnect(SIGNAL(clicked())); @@ -56,6 +76,7 @@ void ExtractorDialog::killProcess(){ } void ExtractorDialog::writeOutput(){ + qDebug() << "writing" << mExtractor->state(); QByteArray output = mExtractor->read(mExtractor->bytesAvailable()); mOutput->append(output); } @@ -73,12 +94,14 @@ void ExtractorDialog::start(){ mOutput->append(msg); return; } - QStringList args = s.value("paths/archiveargs").toStringList(); + QStringList args = s.value("paths/archiverargs").toStringList(); + args << mArchive; mExtractor = new QProcess(this); mExtractor->setWorkingDirectory(mExtractTo); connect(mExtractor, SIGNAL(readyRead()), this, SLOT(writeOutput())); - QString startmessage = QString("Starting %1 %2 %3\n").arg(exe).arg(args.join(" ")).arg(mArchive); + QString startmessage = QString("Starting %1 %2\n").arg(exe).arg(args.join(" ")); mOutput->append(startmessage); mExtractor->start(exe, args); + mExtractor->waitForStarted(); } diff --git a/extractordialog.h b/extractordialog.h index 80c7e2c..63be971 100644 --- a/extractordialog.h +++ b/extractordialog.h @@ -24,6 +24,8 @@ class ExtractorDialog : public QDialog { void processStatusChanged(QProcess::ProcessState newState); void killProcess(); void writeOutput(); + void extractionStarted(); + void extractionFinished(); private: void start(); diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 317fbad..e02e564 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -31,6 +31,7 @@ #include "filesystemfileproxy.h" #include "helper.h" #include "messagedialog.h" +#include "extractordialog.h" FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { mModel = new QDirModel; @@ -342,11 +343,27 @@ void FilesystemWidget::setTemplate(){ if(idx.column() != 0){ idx = mFileView->model()->index(idx.row(), 0); } + //since we only need the filename, no need to map it to anything! QFileInfo info(idx.data().toString()); mTemplate = info.completeBaseName().toLower(); emit newTemplate(mTemplate); } +void FilesystemWidget::extract(const QString &destDir){ + QModelIndex idx = mFileView->currentIndex(); + if(idx.column() != 0){ + idx = mFileView->model()->index(idx.row(), 0); + } + QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(mFileView->model()); + QModelIndex real = proxy->mapToSource(idx); + QFileInfo info = mModel->fileInfo(real); + if(info.isDir()){ + return; + } + ExtractorDialog dlg(info.absoluteFilePath(), destDir, this); + dlg.exec(); +} + void FilesystemWidget::setWindowTitle(const QString &dir){ mWindowTitle = QString("%1 - %2").arg(qApp->applicationName()).arg(dir); emit windowTitle(mWindowTitle); diff --git a/filesystemwidget.h b/filesystemwidget.h index 04957f2..32a3e9b 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -46,6 +46,7 @@ class FilesystemWidget : public QWidget { void renameFile(); void renameCover(const QString &infix); void setTemplate(); + void extract(const QString &destDir); private slots: void doRenameFile(); diff --git a/fileview.cpp b/fileview.cpp index 3c9f8fc..88cc15c 100644 --- a/fileview.cpp +++ b/fileview.cpp @@ -111,10 +111,13 @@ void FileView::doCreateFolder(){ void FileView::contextMenuEvent(QContextMenuEvent *e){ QMenu contextMenu(this); QMenu renameMenu(tr("Rename...")); + QMenu extractMenu(tr("Extract To...")); int ctr(0); foreach(QAction *a, actions()){ if(a->data() == "RenameMenu"){ renameMenu.addAction(a); + }else if(a->data() == "ExtractMenu"){ + extractMenu.addAction(a); }else{ contextMenu.addAction(a); if((ctr == 0) || (ctr == 1) || (ctr == 3)){ @@ -122,6 +125,8 @@ void FileView::contextMenuEvent(QContextMenuEvent *e){ } if(ctr == 8){ contextMenu.addMenu(&renameMenu); + contextMenu.addSeparator(); + contextMenu.addMenu(&extractMenu); } ++ctr; } @@ -71,6 +71,7 @@ void SheMov::setTemplate(const QString &newTemplate){ void SheMov::configure(){ ConfigurationDialog dlg(this); dlg.exec(); + createExtractMenu(); } void SheMov::createStatusbar(){ @@ -162,6 +163,7 @@ void SheMov::createActions(){ //Edit menu extract submenu mExtractMapper = new QSignalMapper(this); + connect(mExtractMapper, SIGNAL(mapped(const QString &)), mFSWidget, SLOT(extract(const QString &))); mExtractMenu = new QMenu(tr("E&xtract to..."), this); createExtractMenu(); } @@ -188,6 +190,8 @@ void SheMov::createMenus(){ renameMenu->addAction(mRenameCoverCA); editMenu->addMenu(renameMenu); editMenu->addSeparator(); + editMenu->addMenu(mExtractMenu); + editMenu->addSeparator(); editMenu->addAction(mRefreshA); editMenu->addSeparator(); editMenu->addAction(mConfigA); @@ -197,5 +201,22 @@ void SheMov::createMenus(){ } void SheMov::createExtractMenu(){ - + foreach(QAction *a, mExtractToA){ + mFSWidget->fileView()->removeAction(a); + delete a; + } + mExtractToA.clear(); + mExtractMenu->clear(); + QSettings s; + QStringList locations = s.value("paths/extractpaths").toStringList(); + foreach(QString p, locations){ + QAction *a = new QAction(p, this); + a->setData("ExtractMenu"); + mFSWidget->fileView()->addAction(a); + mExtractMenu->addAction(a); + mExtractMapper->setMapping(a, p); + connect(a, SIGNAL(triggered()), mExtractMapper, SLOT(map())); + mExtractToA << a; + } } + |