From 1b1e48aa11c4518e100004dac594540e6024fa68 Mon Sep 17 00:00:00 2001 From: am Date: Thu, 16 Jul 2009 19:34:57 +0000 Subject: -Fixed extractor... Just look at the examples for QProcess :) -Beautified extractor output for unrar -Added User interface configuration options -So, there are Usability fixes git-svn-id: file:///var/svn/repos2/shemov/trunk@388 f440f766-f032-0410-8965-dc7d17de2ca0 --- configurationdialog.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ configurationdialog.h | 11 +++++++ extractordialog.cpp | 78 ++++++++++++++++++++++++----------------------- extractordialog.h | 4 +-- filesystemwidget.cpp | 39 ++++++++++++++++-------- filesystemwidget.h | 1 + shemoviconprovider.cpp | 11 +++++-- 7 files changed, 169 insertions(+), 55 deletions(-) diff --git a/configurationdialog.cpp b/configurationdialog.cpp index 34e5d10..32fc197 100644 --- a/configurationdialog.cpp +++ b/configurationdialog.cpp @@ -84,6 +84,40 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : Q pathWidget->setLayout(pathGrid); mTab->addTab(pathWidget, tr("Paths")); + //ui tab + QWidget *uiWidget = new QWidget; + QGridLayout *uiGrid = new QGridLayout; + QLabel *ui1 = new QLabel(tr("Select icon for &folders")); + mIconForFolder = new QComboBox; + ui1->setBuddy(mIconForFolder); + QStringList icons = QStringList() << tr("Dildo") << tr("Normal"); + mIconForFolder->addItems(icons); + uiGrid->addWidget(ui1, 0, 0); + uiGrid->addWidget(mIconForFolder, 0, 1); + QLabel *ui2 = new QLabel(tr("Expand paths in directory tree")); + mExpandPaths = new QComboBox; + uiGrid->addWidget(ui2, 1, 0); + uiGrid->addWidget(mExpandPaths, 1, 1); + mSelect = new QPushButton(tr("Open directory at Startup")); + connect(mSelect, SIGNAL(clicked()), this, SLOT(selectStartup())); + uiGrid->addWidget(mSelect, 2, 1); + QLabel *ui3 = new QLabel(tr("Add &new path to expand")); + mExpandPath = new QLineEdit; + mExpandPath->setCompleter(fsCompleter); + ui3->setBuddy(mExpandPath); + uiGrid->addWidget(ui3, 3, 0); + uiGrid->addWidget(mExpandPath, 3, 1); + mAddExpandPath = new QPushButton(tr("Add path")); + connect(mAddExpandPath, SIGNAL(clicked()), this, SLOT(addExpandPath())); + mRemoveExpandPath = new QPushButton(tr("Remove path")); + connect(mRemoveExpandPath, SIGNAL(clicked()), this, SLOT(removeExpandPath())); + QHBoxLayout *expandButtons = new QHBoxLayout; + expandButtons->addWidget(mAddExpandPath); + expandButtons->addWidget(mRemoveExpandPath); + uiGrid->addLayout(expandButtons, 4, 1); + uiWidget->setLayout(uiGrid); + mTab->addTab(uiWidget, tr("User interface")); + //main layout mOk = new QPushButton(tr("Ok")); connect(mOk, SIGNAL(clicked()), this, SLOT(accept())); @@ -126,8 +160,36 @@ void ConfigurationDialog::removePath(){ } } +void ConfigurationDialog::addExpandPath(){ + QString newPath = mExpandPath->text(); + if(!newPath.isEmpty() && !mEPaths.contains(newPath)){ + mExpandPaths->addItem(newPath); + mEPaths.append(newPath); + } +} + +void ConfigurationDialog::removeExpandPath(){ + QString removePath = mExpandPaths->currentText(); + int current = mExpandPaths->currentIndex(); + if(!removePath.isEmpty()){ + if(mEPaths.contains(removePath)){ + mEPaths.removeOne(removePath); + mExpandPaths->removeItem(current); + } + } +} + +void ConfigurationDialog::selectStartup(){ + QString startup = mExpandPaths->currentText(); + if(!startup.isEmpty()){ + mSelectStartup = startup; + } +} + void ConfigurationDialog::readSettings(){ QSettings s; + + //read paths mPictureViewer->setText(s.value("paths/pictureviewer", "/usr/bin/gwenview").toString()); QStringList pvArgs = s.value("paths/pictureviewerargs").toStringList(); mPictureViewerArgs->setText(pvArgs.join(" ")); @@ -140,10 +202,23 @@ void ConfigurationDialog::readSettings(){ QStringList extractPaths = s.value("paths/extractpaths").toStringList(); mArchivePaths->addItems(extractPaths); mPaths = extractPaths; + + //read ui + QStringList expandPaths = s.value("ui/expandpaths").toStringList(); + mExpandPaths->addItems(expandPaths); + mEPaths = expandPaths; + QString icon = s.value("ui/foldericon", "Normal").toString(); + int pos = mIconForFolder->findText(icon); + if(pos != -1){ + mIconForFolder->setCurrentIndex(pos); + } + } void ConfigurationDialog::writeSettings(){ QSettings s; + + //write paths QRegExp splitAt("\\s+"); s.setValue("paths/pictureviewer", mPictureViewer->text()); QStringList pvArgs = mPictureViewerArgs->text().split(splitAt, QString::SkipEmptyParts); @@ -155,5 +230,10 @@ void ConfigurationDialog::writeSettings(){ QStringList aArgs = mArchiverArgs->text().split(splitAt, QString::SkipEmptyParts); s.setValue("paths/archiverargs", aArgs); s.setValue("paths/extractpaths", mPaths); + + //write ui + s.setValue("ui/expandpaths", mEPaths); + s.setValue("ui/folderIcon", mIconForFolder->currentText()); + s.setValue("ui/selectstartup", mSelectStartup); } diff --git a/configurationdialog.h b/configurationdialog.h index 3876fb6..3f28f5c 100644 --- a/configurationdialog.h +++ b/configurationdialog.h @@ -27,6 +27,9 @@ class ConfigurationDialog : public QDialog { private slots: void addPath(); void removePath(); + void addExpandPath(); + void removeExpandPath(); + void selectStartup(); private: void readSettings(); @@ -35,6 +38,9 @@ class ConfigurationDialog : public QDialog { QPushButton *mCancel; QPushButton *mAddPath; QPushButton *mRemovePath; + QPushButton *mAddExpandPath; + QPushButton *mRemoveExpandPath; + QPushButton *mSelect; QTabWidget *mTab; QLineEdit *mPictureViewer; QLineEdit *mPictureViewerArgs; @@ -43,8 +49,13 @@ class ConfigurationDialog : public QDialog { QLineEdit *mArchiver; QLineEdit *mArchiverArgs; QLineEdit *mExtractPath; + QLineEdit *mExpandPath; QComboBox *mArchivePaths; + QComboBox *mExpandPaths; + QComboBox *mIconForFolder; QStringList mPaths; + QStringList mEPaths; + QString mSelectStartup; }; #endif diff --git a/extractordialog.cpp b/extractordialog.cpp index cf2c18d..7bb2f81 100644 --- a/extractordialog.cpp +++ b/extractordialog.cpp @@ -12,18 +12,17 @@ #include #include #include +#include +#include #include -#include - #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); + mOutput->setFont(QFont("Courier new", 10)); mCancelClose = new QPushButton(tr("Close")); connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); mainLayout->addWidget(mOutput); @@ -31,35 +30,12 @@ ExtractorDialog::ExtractorDialog(const QString &archive, const QString &extractT setLayout(mainLayout); mExtractor = new QProcess(this); - 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); + setMinimumWidth(500); 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())); - mCancelClose->setText(tr("Cancel")); - } - if(newState == QProcess::NotRunning){ - mCancelClose->disconnect(SIGNAL(clicked())); - connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); - mCancelClose->setText(tr("Close")); - } -} - -void ExtractorDialog::extractionStarted(){ - mCancelClose->disconnect(SIGNAL(clicked())); - connect(mCancelClose, SIGNAL(clicked()), this, SLOT(killProcess())); - mCancelClose->setText(tr("Cancel")); } void ExtractorDialog::extractionFinished(){ @@ -69,16 +45,26 @@ void ExtractorDialog::extractionFinished(){ } void ExtractorDialog::killProcess(){ - mExtractor->terminate(); - mCancelClose->disconnect(SIGNAL(clicked())); - connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); - mCancelClose->setText(tr("Close")); + mExtractor->kill(); + setClose(); } void ExtractorDialog::writeOutput(){ - qDebug() << "writing" << mExtractor->state(); - QByteArray output = mExtractor->read(mExtractor->bytesAvailable()); - mOutput->append(output); + if(mExtractor->canReadLine()){ + QString line = mExtractor->readLine(); + QRegExp dots("^...\\s+"); + if(dots.indexIn(line) != -1){ + line.replace(dots, "File: "); + mOutput->append(line); + return; + } + QRegExp extracting("/.*/"); + if(extracting.indexIn(line) != -1){ + line.replace(extracting, ""); + mOutput->append(line); + } + + } } void ExtractorDialog::start(){ @@ -98,10 +84,28 @@ void ExtractorDialog::start(){ args << mArchive; mExtractor = new QProcess(this); mExtractor->setWorkingDirectory(mExtractTo); - connect(mExtractor, SIGNAL(readyRead()), this, SLOT(writeOutput())); + mExtractor->setReadChannel(QProcess::StandardOutput); QString startmessage = QString("Starting %1 %2\n").arg(exe).arg(args.join(" ")); mOutput->append(startmessage); mExtractor->start(exe, args); - mExtractor->waitForStarted(); + if(!mExtractor->waitForStarted()){ + mOutput->append(tr("Failed to start extraction!\n")); + return; + } + connect(mExtractor, SIGNAL(readyRead()), this, SLOT(writeOutput())); + connect(mExtractor, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(extractionFinished())); + setCancel(); +} + +void ExtractorDialog::setClose(){ + mCancelClose->disconnect(SIGNAL(clicked())); + connect(mCancelClose, SIGNAL(clicked()), this, SLOT(accept())); + mCancelClose->setText(tr("Close")); +} + +void ExtractorDialog::setCancel(){ + mCancelClose->disconnect(SIGNAL(clicked())); + connect(mCancelClose, SIGNAL(clicked()), this, SLOT(killProcess())); + mCancelClose->setText(tr("Cancel")); } diff --git a/extractordialog.h b/extractordialog.h index 63be971..b5033fd 100644 --- a/extractordialog.h +++ b/extractordialog.h @@ -21,14 +21,14 @@ class ExtractorDialog : public QDialog { ~ExtractorDialog() {}; private slots: - void processStatusChanged(QProcess::ProcessState newState); void killProcess(); void writeOutput(); - void extractionStarted(); void extractionFinished(); private: void start(); + void setClose(); + void setCancel(); QString mArchive; QString mExtractTo; QPushButton *mCancelClose; diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index e02e564..349176b 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -87,22 +87,24 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { connect(mDirEdit, SIGNAL(returnPressed()), this, SLOT(directoryEdited())); QSettings s; - QString startDir = s.value("paths/start", QDir::homePath()).toString(); - windowTitle(startDir); - QModelIndex startIndex = mModel->index(startDir); - if(startIndex.isValid()){ - QModelIndex proxyIndex = mDirProxy->mapFromSource(startIndex); - mDirView->setCurrentIndex(proxyIndex); - mDirView->setExpanded(proxyIndex, true); - QModelIndex parent = proxyIndex.parent(); - do { - mDirView->setExpanded(parent, true); - parent = parent.parent(); - }while(parent.isValid()); + QStringList expandPaths = s.value("ui/expandpaths").toStringList(); + QString last; + foreach(QString p, expandPaths){ + QModelIndex idx = mModel->index(p); + last = p; + if(idx.isValid()){ + QModelIndex proxy = mDirProxy->mapFromSource(idx); + mDirView->setExpanded(proxy, true); + expandParents(proxy); + } } + QString select = s.value("ui/selectstartup").toString(); + windowTitle(select); + setWindowTitle(select); + QModelIndex sel = mModel->index(select); + mDirView->setCurrentIndex(mDirProxy->mapFromSource(sel)); mFileView->resizeColumnToContents(0); - setWindowTitle(startDir); QVBoxLayout *mainLayout = new QVBoxLayout; QSplitter *splitter = new QSplitter; @@ -423,6 +425,17 @@ void FilesystemWidget::doRenameFile(){ emit newTemplate(mTemplate); } +void FilesystemWidget::expandParents(const QModelIndex &idx){ + if(idx.isValid()){ + QModelIndex parent = idx.parent(); + do{ + mDirView->setExpanded(parent, true); + parent = parent.parent(); + + }while(parent.isValid()); + } +} + QAction * FilesystemWidget::action(QWidget *widget, const QVariant &data) const{ QAction *retval = 0; foreach(QAction *a, widget->actions()){ diff --git a/filesystemwidget.h b/filesystemwidget.h index 32a3e9b..2c41390 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -55,6 +55,7 @@ class FilesystemWidget : public QWidget { void setWindowTitle(const QString &dir); void deleteRecursive(const QFileInfo &start); void copyRecursive(const QFileInfo &start, const QString &destdir); + void expandParents(const QModelIndex &idx); QAction *action(QWidget *widget, const QVariant &data) const; QDirModel *mModel; QTreeView *mDirView; diff --git a/shemoviconprovider.cpp b/shemoviconprovider.cpp index ed3febb..daea4c0 100644 --- a/shemoviconprovider.cpp +++ b/shemoviconprovider.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "shemoviconprovider.h" #include "helper.h" @@ -14,9 +15,13 @@ SheMovIconProvider::SheMovIconProvider() {}; QIcon SheMovIconProvider::icon(const QFileInfo &info) const { - /*if(info.isDir()){ - return QIcon(":/dildo.png"); - }*/ + if(info.isDir()){ + QSettings s; + QString fi(s.value("ui/foldericon").toString()); + if(fi == "Dildo"){ + return QIcon(":/dildo.png"); + } + } QString type = Helper::mimeType(info.absoluteFilePath()); if(type.toLower().startsWith("video")){ return QIcon(":/movie.svg"); -- cgit v1.2.3-70-g09d2