diff options
author | Arno <am@disconnect.de> | 2010-11-28 11:58:57 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2010-11-28 11:58:57 +0100 |
commit | d1837c9c92c9f38a464f0473001db4e9a57d44e7 (patch) | |
tree | 9d815a4c1e1c550871565c92d7e0c8f312f05f72 | |
parent | eb4139c5c525c03d4c75c0a47acc92157008ca06 (diff) | |
download | SheMov-d1837c9c92c9f38a464f0473001db4e9a57d44e7.tar.gz SheMov-d1837c9c92c9f38a464f0473001db4e9a57d44e7.tar.bz2 SheMov-d1837c9c92c9f38a464f0473001db4e9a57d44e7.zip |
Added action to copy file path to clipboard
4 new actions to copy the file path to clipboard. It's either the unix
full path, the unix dir, the windows full path or the windows dir. For
the latter '/' is replaced with '\' and a drive letter is prepended.
The drive letter is configurable in the ConfigurationDialog. While at it
I revamped it and added another tab to make it more user friendly.
-rw-r--r-- | archivetreeview.cpp | 38 | ||||
-rw-r--r-- | archivetreeview.h | 3 | ||||
-rw-r--r-- | configurationdialog.cpp | 93 | ||||
-rw-r--r-- | configurationdialog.h | 4 | ||||
-rw-r--r-- | shemov.cpp | 28 | ||||
-rw-r--r-- | shemov.h | 4 |
6 files changed, 139 insertions, 31 deletions
diff --git a/archivetreeview.cpp b/archivetreeview.cpp index 8e55058..2260052 100644 --- a/archivetreeview.cpp +++ b/archivetreeview.cpp @@ -174,6 +174,34 @@ void ArchiveTreeView::selectMovie(const QModelIndex &idx){ mNoCoverDialog->hide(); } +void ArchiveTreeView::copyPath(int type){ + QModelIndexList selected = mFilesWidget->filesTree()->selectionModel()->selectedRows(); + if(selected.isEmpty()){ + return; + } + QString fullPath = selected.at(0).data(FilesTreeModel::FullPathRole).toString(); + QFileInfo fi(fullPath); + if(!fi.exists()){ + int dvdNo = selected.at(0).data(FilesTreeModel::DvdNoRole).toInt(); + QString msg = QString(tr("File not found. File is archived on DVD #%1")).arg(QString::number(dvdNo)); + QMessageBox::critical(this, tr("Error"), msg); + return; + } + QClipboard *clipBoard = QApplication::clipboard(); + if(type == UnixFullPath){ + clipBoard->setText(fi.absoluteFilePath()); + } + if(type == UnixDir){ + clipBoard->setText(fi.absolutePath()); + } + if(type == WindowsFullPath){ + clipBoard->setText(createWindowsPath(fi.absoluteFilePath())); + } + if(type == WindowsDir){ + clipBoard->setText(createWindowsPath(fi.absolutePath())); + } +} + void ArchiveTreeView::currentChanged(const QItemSelection &selected, const QItemSelection &deselected){ Q_UNUSED(selected); Q_UNUSED(deselected); @@ -267,6 +295,16 @@ void ArchiveTreeView::constructWindowTitle(){ emit needWindowTitleChange(mWindowTitle); } +const QString ArchiveTreeView::createWindowsPath(const QString &path) const{ + QString retval = path; + QSettings s; + const QString strip = s.value("paths/strippath").toString(); + retval.remove(strip); + retval.replace('/', '\\'); + retval = QString("%1\\%2").arg(s.value("paths/windowsdrive").toString()).arg(retval); + return retval; +} + //NoCoverMovieModel NoCoverMovieModel::NoCoverMovieModel(const QStringList &headers, QObject *parent) : SmTreeModel(headers, parent){ diff --git a/archivetreeview.h b/archivetreeview.h index a9d2266..7b0cd47 100644 --- a/archivetreeview.h +++ b/archivetreeview.h @@ -34,6 +34,7 @@ class ArchiveTreeView : public QWidget { Q_OBJECT public: + enum CopyType { WindowsDir, WindowsFullPath, UnixDir, UnixFullPath }; explicit ArchiveTreeView(QWidget *parent = 0); SeriesTreeWidget *seriesWidget() { return mSeriesWidget; } FilesTreeWidget *filesWidget() { return mFilesWidget; } @@ -47,6 +48,7 @@ class ArchiveTreeView : public QWidget void cleanDatabase(const QString &table); void showNoCoverDialog(); void selectMovie(const QModelIndex &idx); + void copyPath(int type); private slots: void currentChanged(const QItemSelection &selected, const QItemSelection &deselected); @@ -56,6 +58,7 @@ class ArchiveTreeView : public QWidget private: //functions void constructWindowTitle(); + const QString createWindowsPath(const QString &path) const; //widgets SeriesTreeWidget *mSeriesWidget; diff --git a/configurationdialog.cpp b/configurationdialog.cpp index be6fea8..c8e7197 100644 --- a/configurationdialog.cpp +++ b/configurationdialog.cpp @@ -26,6 +26,7 @@ #include <QMessageBox> #include <QFile> #include <QTextStream> +#include <QRegExpValidator> #include "configurationdialog.h" #include "programconfigurator.h" @@ -38,43 +39,69 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : Q fsCompleter->setModel(model); fsCompleter->setCompletionMode(QCompleter::PopupCompletion); - //misc tab - QWidget *miscWidget = new QWidget; - QVBoxLayout *miscLayout = new QVBoxLayout; - miscLayout->setAlignment(Qt::AlignTop); - - //misc - icons - QGroupBox *iconBox = new QGroupBox(tr("Icon for folders")); - QHBoxLayout *iconLayout = new QHBoxLayout; - mIconForFolder = new QComboBox; - QStringList icons = QStringList() << tr("Dildo") << tr("Normal"); - mIconForFolder->addItems(icons); - iconLayout->addWidget(mIconForFolder); - iconBox->setLayout(iconLayout); - - //misc - directories - QGroupBox *pathBox = new QGroupBox(tr("Directories")); + //directories tab + //directories + QWidget *pathWidget = new QWidget; + QGroupBox *pathBox = new QGroupBox(tr("Paths")); QGridLayout *pathGrid = new QGridLayout; - QLabel *miscl2 = new QLabel(tr("Archive directory")); + QLabel *pathl1 = new QLabel(tr("Archive directory")); mArchiveDir = new QLineEdit; mArchiveDir->setCompleter(fsCompleter); - pathGrid->addWidget(miscl2, 0, 0); + pathGrid->addWidget(pathl1, 0, 0); pathGrid->addWidget(mArchiveDir, 0, 1); - QLabel *miscl3 = new QLabel(tr("Burn Directory")); + QLabel *pathl2 = new QLabel(tr("Burn Directory")); mBurnDir = new QLineEdit; mBurnDir->setCompleter(fsCompleter); - pathGrid->addWidget(miscl3, 1, 0); + pathGrid->addWidget(pathl2, 1, 0); pathGrid->addWidget(mBurnDir, 1, 1); - QLabel *miscl4 = new QLabel(tr("Path to ffprobe")); + QLabel *pathl3 = new QLabel(tr("Path to ffprobe")); mFfProbePath = new QLineEdit; mFfProbePath->setCompleter(fsCompleter); - pathGrid->addWidget(miscl4, 2, 0); + pathGrid->addWidget(pathl3, 2, 0); pathGrid->addWidget(mFfProbePath, 2, 1); - QLabel *miscl5 = new QLabel(tr("DVD mount directory")); + QLabel *pathl4 = new QLabel(tr("DVD mount directory")); mDvdMountPath = new QLineEdit; - pathGrid->addWidget(miscl5, 3, 0); + pathGrid->addWidget(pathl4, 3, 0); pathGrid->addWidget(mDvdMountPath, 3, 1); + pathGrid->setAlignment(Qt::AlignTop); pathBox->setLayout(pathGrid); + QVBoxLayout *pathLayout = new QVBoxLayout; + pathLayout->addWidget(pathBox); + pathWidget->setLayout(pathLayout); + + //copy path options + QGroupBox *copyBox = new QGroupBox(tr("Copy path options")); + QGridLayout *copyGrid = new QGridLayout; + QLabel *pathl5 = new QLabel(tr("Windows drive")); + mWindowsDrive = new QLineEdit; + QRegExp pathValid("[a-z]{1}:"); + pathValid.setCaseSensitivity(Qt::CaseInsensitive); + QRegExpValidator *pathValidator = new QRegExpValidator(pathValid, this); + mWindowsDrive->setValidator(pathValidator); + copyGrid->addWidget(pathl5, 0, 0); + copyGrid->addWidget(mWindowsDrive, 0, 1); + QLabel *pathl6 = new QLabel(tr("Strip from path")); + mStripPath = new QLineEdit; + copyGrid->addWidget(pathl6, 1, 0); + copyGrid->addWidget(mStripPath, 1, 1); + copyGrid->setAlignment(Qt::AlignTop); + copyBox->setLayout(copyGrid); + pathLayout->addWidget(copyBox); + mTab->addTab(pathWidget, tr("Directories")); + + //misc tab + QWidget *miscWidget = new QWidget; + QVBoxLayout *miscLayout = new QVBoxLayout; + miscLayout->setAlignment(Qt::AlignTop); + + //misc - icons + QGroupBox *iconBox = new QGroupBox(tr("Icon for folders")); + QHBoxLayout *iconLayout = new QHBoxLayout; + mIconForFolder = new QComboBox; + QStringList icons = QStringList() << tr("Dildo") << tr("Normal"); + mIconForFolder->addItems(icons); + iconLayout->addWidget(mIconForFolder); + iconBox->setLayout(iconLayout); //misc - hover QGroupBox *hoverBox = new QGroupBox(tr("Hover options")); @@ -95,7 +122,6 @@ ConfigurationDialog::ConfigurationDialog(QWidget *parent, Qt::WindowFlags f) : Q //misc - assemble miscLayout->addWidget(iconBox); - miscLayout->addWidget(pathBox); miscLayout->addWidget(hoverBox); miscWidget->setLayout(miscLayout); mTab->addTab(miscWidget, tr("Misc. settings")); @@ -168,13 +194,17 @@ void ConfigurationDialog::readSettings(){ if(pos != -1){ mIconForFolder->setCurrentIndex(pos); } + mHoverPics->setChecked(s.value("ui/hoverpics", false).toBool()); + mHoverArchive->setChecked(s.value("ui/hoverarchive", false).toBool()); + mHoverOpacity->setValue(s.value("ui/hoveropacity", 10).toInt()); + + //read paths mArchiveDir->setText(s.value("paths/archivedir").toString()); mBurnDir->setText(s.value("paths/burn").toString()); mFfProbePath->setText(s.value("paths/ffprobe").toString()); mDvdMountPath->setText(s.value("paths/dvdmount").toString()); - mHoverPics->setChecked(s.value("ui/hoverpics", false).toBool()); - mHoverArchive->setChecked(s.value("ui/hoverarchive", false).toBool()); - mHoverOpacity->setValue(s.value("ui/hoveropacity", 10).toInt()); + mWindowsDrive->setText(s.value("paths/windowsdrive").toString()); + mStripPath->setText(s.value("paths/strippath").toString()); //read database mDatabaseHost->setText(s.value("database/hostname").toString()); @@ -187,8 +217,7 @@ void ConfigurationDialog::readSettings(){ void ConfigurationDialog::writeSettings(){ QSettings s; - //write misc - s.setValue("ui/folderIcon", mIconForFolder->currentText()); + //write paths s.setValue("paths/archivedir", mArchiveDir->text()); s.setValue("paths/burn", mBurnDir->text()); QString ffprobe = mFfProbePath->text(); @@ -199,6 +228,10 @@ void ConfigurationDialog::writeSettings(){ if(checkDvdPath()){ s.setValue("paths/dvdmount", mDvdMountPath->text()); } + s.setValue("paths/windowsdrive", mWindowsDrive->text()); + s.setValue("paths/strippath", mStripPath->text()); + + s.setValue("ui/folderIcon", mIconForFolder->currentText()); s.setValue("ui/hoverpics", (mHoverPics->checkState() == Qt::Checked)); s.setValue("ui/hoverarchive", (mHoverArchive->checkState() == Qt::Checked)); s.setValue("ui/hoveropacity", mHoverOpacity->value()); diff --git a/configurationdialog.h b/configurationdialog.h index f97a2d9..edbe219 100644 --- a/configurationdialog.h +++ b/configurationdialog.h @@ -23,7 +23,7 @@ class ConfigurationDialog : public QDialog { Q_OBJECT public: ConfigurationDialog(QWidget *parent = 0, Qt::WindowFlags f = 0); - ~ConfigurationDialog() {}; + ~ConfigurationDialog() {} public slots: void accept(); @@ -46,6 +46,8 @@ class ConfigurationDialog : public QDialog { QLineEdit *mDatabaseName; QLineEdit *mDatabaseUsername; QLineEdit *mDatabasePassword; + QLineEdit *mWindowsDrive; + QLineEdit *mStripPath; QComboBox *mIconForFolder; QCheckBox *mHoverPics; QCheckBox *mHoverArchive; @@ -433,6 +433,20 @@ void SheMov::createActions(){ connect(mDeleteFilesFromTreeA, SIGNAL(triggered()), mATree->filesWidget(), SLOT(removeFiles())); mFilePropertiesA = new QAction(tr("Properties..."), this); connect(mFilePropertiesA, SIGNAL(triggered()), mATree->filesWidget(), SLOT(fileProperties())); + QSignalMapper *copyMapper = new QSignalMapper(this); + mCopyUnixFullPathA = new QAction(tr("Copy unix file"), this); + copyMapper->setMapping(mCopyUnixFullPathA, ArchiveTreeView::UnixFullPath); + connect(mCopyUnixFullPathA, SIGNAL(triggered()), copyMapper, SLOT(map())); + mCopyUnixDirA = new QAction(tr("Copy unix directory"), this); + copyMapper->setMapping(mCopyUnixDirA, ArchiveTreeView::UnixDir); + connect(mCopyUnixDirA, SIGNAL(triggered()), copyMapper, SLOT(map())); + mCopyWindowsFullPathA = new QAction(tr("Copy windows file"), this); + copyMapper->setMapping(mCopyWindowsFullPathA, ArchiveTreeView::WindowsFullPath); + connect(mCopyWindowsFullPathA, SIGNAL(triggered()), copyMapper, SLOT(map())); + mCopyWindowsDirA = new QAction(tr("Copy windows directory"), this); + copyMapper->setMapping(mCopyWindowsDirA, ArchiveTreeView::WindowsDir); + connect(mCopyWindowsDirA, SIGNAL(triggered()), copyMapper, SLOT(map())); + connect(copyMapper, SIGNAL(mapped(int)), mATree, SLOT(copyPath(int))); // misc mOpenWithMapperFS = new QSignalMapper(this); @@ -583,6 +597,20 @@ void SheMov::createMenus(){ QAction *sep9 = new QAction(this); sep9->setSeparator(true); mATree->filesWidget()->filesTree()->addAction(sep9); + QMenu *copyMenu = new QMenu(this); + copyMenu->addAction(mCopyUnixFullPathA); + copyMenu->addAction(mCopyUnixDirA); + QAction *sep13 = new QAction(this); + sep13->setSeparator(true); + copyMenu->addAction(sep13); + copyMenu->addAction(mCopyWindowsFullPathA); + copyMenu->addAction(mCopyWindowsDirA); + QAction *copyAction = new QAction(tr("Copy to clipboard"), this); + copyAction->setMenu(copyMenu); + mATree->filesWidget()->filesTree()->addAction(copyAction); + QAction *sep12 = new QAction(this); + sep12->setSeparator(true); + mATree->filesWidget()->filesTree()->addAction(sep12); mATree->filesWidget()->filesTree()->addAction(mFilePropertiesA); } @@ -126,6 +126,10 @@ class SheMov : public QMainWindow { QAction *mSetPartNoA; QAction *mDeleteFilesFromTreeA; QAction *mFilePropertiesA; + QAction *mCopyUnixFullPathA; + QAction *mCopyUnixDirA; + QAction *mCopyWindowsFullPathA; + QAction *mCopyWindowsDirA; QActionGroup *mOpenWithGroupFS; QActionGroup *mOpenWithGroupAV; |