From a3dd54389f7b28431fc9853cd57af231bd6a3c9c Mon Sep 17 00:00:00 2001 From: am Date: Sun, 12 Jul 2009 16:04:04 +0000 Subject: -implemented cover rename and templates -started on configurationdialog git-svn-id: file:///var/svn/repos2/shemov/trunk@385 f440f766-f032-0410-8965-dc7d17de2ca0 --- configurationdialog.cpp | 131 ++++++++++++++++++++++++++++++++++++++++++++++++ configurationdialog.h | 44 ++++++++++++++++ filesystemwidget.cpp | 40 +++++++++++++++ filesystemwidget.h | 2 + fileview.cpp | 16 ++++-- shemov.cpp | 42 ++++++++++++++++ shemov.h | 8 +++ shemov.pro | 6 ++- 8 files changed, 283 insertions(+), 6 deletions(-) create mode 100644 configurationdialog.cpp create mode 100644 configurationdialog.h diff --git a/configurationdialog.cpp b/configurationdialog.cpp new file mode 100644 index 0000000..d10050a --- /dev/null +++ b/configurationdialog.cpp @@ -0,0 +1,131 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "configurationdialog.h" + +ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ + //paths tab + QWidget *pathWidget = new QWidget; + QGridLayout *pathGrid = new QGridLayout; + QDirModel *model = new QDirModel(this); + QCompleter *fsCompleter = new QCompleter(this); + fsCompleter->setModel(model); + fsCompleter->setCompletionMode(QCompleter::PopupCompletion); + QLabel *l1 = new QLabel(tr("Path to &picture viewer")); + mPictureViewer = new QLineEdit; + mPictureViewer->setCompleter(fsCompleter); + l1->setBuddy(mPictureViewer); + pathGrid->addWidget(l1, 0, 0); + pathGrid->addWidget(mPictureViewer, 0, 1); + QLabel *l2 = new QLabel(tr("Arguments for picture viewer")); + mPictureViewerArgs = new QLineEdit; + pathGrid->addWidget(l2, 1, 0); + pathGrid->addWidget(mPictureViewerArgs, 1, 1); + QLabel *l3 = new QLabel(tr("Path to &movie viewer")); + mMovieViewer = new QLineEdit; + mMovieViewer->setCompleter(fsCompleter); + l2->setBuddy(mMovieViewer); + pathGrid->addWidget(l3, 2, 0); + pathGrid->addWidget(mMovieViewer, 2, 1); + QLabel *l4 = new QLabel(tr("Arguments for movie viewer")); + mMovieViewerArgs = new QLineEdit; + pathGrid->addWidget(l4, 3, 0); + pathGrid->addWidget(mMovieViewerArgs, 3, 1); + QLabel *l5 = new QLabel(tr("Path to &archive program")); + mArchiver = new QLineEdit; + mArchiver->setCompleter(fsCompleter); + l5->setBuddy(mArchiver); + pathGrid->addWidget(l5, 4, 0); + pathGrid->addWidget(mArchiver, 4, 1); + QLabel *l6 = new QLabel(tr("Arguments for archive program")); + mArchiverArgs = new QLineEdit; + l6->setBuddy(mArchiverArgs); + pathGrid->addWidget(l6, 5, 0); + pathGrid->addWidget(mArchiverArgs, 5, 1); + QLabel *l7 = new QLabel(tr("Extraction paths")); + mArchivePaths = new QComboBox; + pathGrid->addWidget(l7, 6, 0); + pathGrid->addWidget(mArchivePaths); + QLabel *l8 = new QLabel(tr("Enter new &extraction path")); + mExtractPath = new QLineEdit; + l8->setBuddy(mExtractPath); + pathGrid->addWidget(l8, 7, 0); + pathGrid->addWidget(mExtractPath, 7, 1); + mAddPath = new QPushButton(tr("Add path")); + connect(mAddPath, SIGNAL(clicked()), this, SLOT(addPath())); + mRemovePath = new QPushButton(tr("Remove path")); + connect(mRemovePath, SIGNAL(clicked()), this, SLOT(removePath())); + QHBoxLayout *pathButtonLayout = new QHBoxLayout; + pathButtonLayout->addStretch(); + pathButtonLayout->addWidget(mAddPath); + pathButtonLayout->addWidget(mRemovePath); + pathGrid->addLayout(pathButtonLayout, 8, 1); + pathWidget->setLayout(pathGrid); + mTab->addTab(pathWidget, tr("Paths")); + + //main layout + mOk = new QPushButton(tr("Ok")); + connect(mOk, SIGNAL(clicked()), this, SLOT(accpet())); + mCancel = new QPushButton(tr("Cancel")); + connect(mCancel, SIGNAL(clicked()), this, SLOT(reject())); + QHBoxLayout *mainButtonLayout = new QHBoxLayout; + mainButtonLayout->addStretch(); + mainButtonLayout->addWidget(mOk); + mainButtonLayout->addWidget(mCancel); + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(mTab); + mainLayout->addLayout(mainButtonLayout); + setLayout(mainLayout); + QString winTitle = QString(tr("%1 - Configure")).arg(qApp->applicationName()); + setWindowTitle(winTitle); + readSettings(); +} + +void ConfigurationDialog::readSettings(){ + QSettings s; + mPictureViewer->setText(s.value("paths/pictureviewer", "/usr/bin/gwenview").toString()); + QStringList pvArgs = s.value("paths/pictureviewerargs").toStringList(); + mPictureViewerArgs->setText(pvArgs.join(" ")); + mMovieViewer->setText(s.value("paths/movieviewer", "/usr/bin/mplayer").toString()); + 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(); + mArchiverArgs->setText(arArgs.join(" ")); + QStringList extractPaths = s.value("paths/extractpaths").toStringList(); + mArchivePaths->addItems(extractPaths); + mPaths = extractPaths; +} + +void ConfigurationDialog::writeSettings(){ + QSettings s; + QRegExp splitAt("\\s+"); + s.setValue("paths/pictureviewer", mPictureViewer->text()); + QStringList pvArgs = mPictureViewerArgs->text().split(splitAt, QString::SkipEmptyParts); + s.setValue("paths/pictureviewerargs", pvArgs); + s.setValue("paths/movieviewer", mMovieViewer->text()); + QStringList mvArgs = mMovieViewerArgs->text().split(splitAt, QString::SkipEmptyParts); + s.setValue("paths/movievieverargs", mvArgs); + s.setValue("paths/archiver", mArchiver->text()); + QStringList aArgs = mArchiverArgs->text().split(splitAt, QString::SkipEmptyParts); + s.setValue("paths/archiverargs", aArgs); + s.setValue("paths/extractpaths", mPaths); +} diff --git a/configurationdialog.h b/configurationdialog.h new file mode 100644 index 0000000..fa91667 --- /dev/null +++ b/configurationdialog.h @@ -0,0 +1,44 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef CONFIGURATIONDIALOG_H +#define CONFIGURATIONDIALOG_H + +#include + +class QPushButton; +class QTabWidget; +class QLineEdit; +class QComboBox; + +class ConfigurationDialog : public QDialog { + Q_OBJECT + public: + ConfigurationDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); + ~ConfigurationDialog() {}; + + private: + void readSettings(); + void writeSettings(); + QPushButton *mOk; + QPushButton *mCancel; + QPushButton *mAddPath; + QPushButton *mRemovePath; + QTabWidget *mTab; + QLineEdit *mPictureViewer; + QLineEdit *mPictureViewerArgs; + QLineEdit *mMovieViewer; + QLineEdit *mMovieViewerArgs; + QLineEdit *mArchiver; + QLineEdit *mArchiverArgs; + QLineEdit *mExtractPath; + QComboBox *mArchivePaths; + QStringList mPaths; +}; + +#endif + diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index aafcd6d..edb842c 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -306,6 +306,46 @@ void FilesystemWidget::renameFile(){ mRenameDialog->exec(); } +void FilesystemWidget::renameCover(const QString &infix){ + if(mTemplate.isEmpty()){ + emit statusbarMessage(tr("No template set!")); + return; + } + QModelIndex idx = mFileView->currentIndex(); + QSortFilterProxyModel *proxy = static_cast(mFileView->model()); + QModelIndex real = proxy->mapToSource(idx); + QFileInfo info = mModel->fileInfo(real); + QString newFilename = QString("%1/%2.%3.%4").arg(info.absolutePath()).arg(mTemplate).arg(infix).arg(info.suffix()); + QFileInfo nf(newFilename); + if(nf.exists()){ + QString message = QString(tr("New file %1 already exists!")).arg(newFilename); + statusbarMessage(message); + return; + } + QString question = QString(tr("Really rename %1 to %2?")).arg(info.absoluteFilePath()).arg(nf.fileName()); + int retval = QMessageBox::question(this, tr("Question"), question, QMessageBox::Yes | QMessageBox::No); + if(retval == QMessageBox::Yes){ + if(QFile::rename(info.absoluteFilePath(), newFilename)){ + QString message = QString(tr("Successfully renamed %1 to %2")).arg(info.fileName()).arg(nf.fileName()); + emit statusbarMessage(message); + mModel->refresh(real.parent()); + }else{ + QString message = QString(tr("Failed to rename %1 to %2")).arg(info.fileName()).arg(nf.fileName()); + emit statusbarMessage(message); + } + } +} + +void FilesystemWidget::setTemplate(){ + QModelIndex idx = mFileView->currentIndex(); + if(idx.column() != 0){ + idx = mFileView->model()->index(idx.row(), 0); + } + QFileInfo info(idx.data().toString()); + mTemplate = info.completeBaseName().toLower(); + emit newTemplate(mTemplate); +} + 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 18cc17a..04957f2 100644 --- a/filesystemwidget.h +++ b/filesystemwidget.h @@ -44,6 +44,8 @@ class FilesystemWidget : public QWidget { void copyFiles(); void moveFiles(); void renameFile(); + void renameCover(const QString &infix); + void setTemplate(); private slots: void doRenameFile(); diff --git a/fileview.cpp b/fileview.cpp index adc8eeb..3c9f8fc 100644 --- a/fileview.cpp +++ b/fileview.cpp @@ -110,13 +110,21 @@ void FileView::doCreateFolder(){ void FileView::contextMenuEvent(QContextMenuEvent *e){ QMenu contextMenu(this); + QMenu renameMenu(tr("Rename...")); int ctr(0); foreach(QAction *a, actions()){ - contextMenu.addAction(a); - if((ctr == 1) || (ctr == 2)){ - contextMenu.addSeparator(); + if(a->data() == "RenameMenu"){ + renameMenu.addAction(a); + }else{ + contextMenu.addAction(a); + if((ctr == 0) || (ctr == 1) || (ctr == 3)){ + contextMenu.addSeparator(); + } + if(ctr == 8){ + contextMenu.addMenu(&renameMenu); + } + ++ctr; } - ++ctr; } contextMenu.exec(e->globalPos()); } diff --git a/shemov.cpp b/shemov.cpp index 56ce0df..f5d9e61 100644 --- a/shemov.cpp +++ b/shemov.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "shemov.h" @@ -79,8 +80,14 @@ void SheMov::createStatusbar(){ } void SheMov::createActions(){ + //File menu mQuitA = new QAction(tr("Quit"), this); mQuitA->setShortcut(tr("CTRL+q")); + + //Edit menu + mCdupA = new QAction(tr("Go up"), this); + connect(mCdupA, SIGNAL(triggered()), mFSWidget, SLOT(parentDir())); + mFSWidget->fileView()->addAction(mCdupA); connect(mQuitA, SIGNAL(triggered()), qApp, SLOT(quit())); mMarkFilesA = new QAction(tr("Select files..."), this); mMarkFilesA->setShortcut(tr("CTRL++")); @@ -116,12 +123,41 @@ void SheMov::createActions(){ mRenameA->setShortcut(tr("CTRL+r")); connect(mRenameA, SIGNAL(triggered()), mFSWidget, SLOT(renameFile())); mFSWidget->fileView()->addAction(mRenameA); + + //Edit menu rename submenu + mTemplateA = new QAction(tr("Set as template"), this); + mTemplateA->setShortcut(tr("CTRL+t")); + connect(mTemplateA, SIGNAL(triggered()), mFSWidget, SLOT(setTemplate())); + mTemplateA->setData("RenameMenu"); + mFSWidget->fileView()->addAction(mTemplateA); + mRenameMapper = new QSignalMapper(this); + mRenameCoverFA = new QAction(tr("Rename to front cover"), this); + mRenameCoverFA->setShortcut(tr("CTRL+f")); + connect(mRenameCoverFA, SIGNAL(triggered()), mRenameMapper, SLOT(map())); + mRenameMapper->setMapping(mRenameCoverFA, tr("front")); + mRenameCoverFA->setData("RenameMenu"); + mFSWidget->fileView()->addAction(mRenameCoverFA); + mRenameCoverBA = new QAction(tr("Rename to back cover"), this); + mRenameCoverBA->setShortcut(tr("CTRL+b")); + connect(mRenameCoverBA, SIGNAL(triggered()), mRenameMapper, SLOT(map())); + mRenameMapper->setMapping(mRenameCoverBA, tr("back")); + mRenameCoverBA->setData("RenameMenu"); + mFSWidget->fileView()->addAction(mRenameCoverBA); + mRenameCoverCA = new QAction(tr("Rename to cover"), this); + mRenameCoverCA->setShortcut(tr("CTRL+c")); + connect(mRenameCoverCA, SIGNAL(triggered()), mRenameMapper, SLOT(map())); + mRenameMapper->setMapping(mRenameCoverCA, tr("cover")); + mRenameCoverCA->setData("RenameMenu"); + mFSWidget->fileView()->addAction(mRenameCoverCA); + connect(mRenameMapper, SIGNAL(mapped(const QString &)), mFSWidget, SLOT(renameCover(const QString &))); } void SheMov::createMenus(){ QMenu *fileMenu = new QMenu(tr("&File"), this); fileMenu->addAction(mQuitA); QMenu *editMenu = new QMenu(tr("&Edit"), this); + editMenu->addAction(mCdupA); + editMenu->addSeparator(); editMenu->addAction(mMarkFilesA); editMenu->addAction(mUnmarkFilesA); editMenu->addSeparator(); @@ -131,6 +167,12 @@ void SheMov::createMenus(){ editMenu->addAction(mCopyA); editMenu->addAction(mMoveA); editMenu->addAction(mRenameA); + QMenu *renameMenu = new QMenu(tr("&Rename..."), this); + renameMenu->addAction(mTemplateA); + renameMenu->addAction(mRenameCoverFA); + renameMenu->addAction(mRenameCoverBA); + renameMenu->addAction(mRenameCoverCA); + editMenu->addMenu(renameMenu); editMenu->addSeparator(); editMenu->addAction(mRefreshA); diff --git a/shemov.h b/shemov.h index a098c27..3c2cb1b 100644 --- a/shemov.h +++ b/shemov.h @@ -15,6 +15,7 @@ class FilesystemWidget; class QAction; class QLabel; class QItemSelection; +class QSignalMapper; class SheMov : public QMainWindow { Q_OBJECT @@ -47,7 +48,14 @@ class SheMov : public QMainWindow { QAction *mCopyA; QAction *mMoveA; QAction *mRenameA; + QAction *mCdupA; + QAction *mRenameCoverFA; + QAction *mRenameCoverBA; + QAction *mRenameCoverCA; + QAction *mTemplateA; //EndActions + + QSignalMapper *mRenameMapper; QTabWidget *mTab; FilesystemWidget *mFSWidget; diff --git a/shemov.pro b/shemov.pro index 36a93fd..fc1120e 100644 --- a/shemov.pro +++ b/shemov.pro @@ -14,7 +14,8 @@ shemov.cpp \ filesystemfileproxy.cpp \ helper.cpp \ shemoviconprovider.cpp \ -messagedialog.cpp +messagedialog.cpp \ +configurationdialog.cpp HEADERS = listitem.h \ listmodel.h \ movieitem.h \ @@ -27,6 +28,7 @@ shemov.h \ filesystemfileproxy.h \ helper.h \ shemoviconprovider.h \ -messagedialog.h +messagedialog.h \ +configurationdialog.h LIBS += -lmagic RESOURCES = shemov.qrc -- cgit v1.2.3-70-g09d2