diff --git a/data/copy.png b/data/copy.png new file mode 100644 index 000000000..5cdeb5fc7 Binary files /dev/null and b/data/copy.png differ diff --git a/data/data.qrc b/data/data.qrc index 30431f60c..4354f222f 100644 --- a/data/data.qrc +++ b/data/data.qrc @@ -1,5 +1,5 @@ - + clear.png go-home.png go-next.png @@ -31,5 +31,7 @@ folder.png configure.png exit.png + copy.png + move.png diff --git a/data/move.png b/data/move.png new file mode 100644 index 000000000..dd30bb26b Binary files /dev/null and b/data/move.png differ diff --git a/src/fileview.cpp b/src/fileview.cpp index fb1643108..74aa8e323 100644 --- a/src/fileview.cpp +++ b/src/fileview.cpp @@ -24,6 +24,9 @@ FileView::FileView(QWidget* parent) connect(ui_.list, SIGNAL(activated(QModelIndex)), SLOT(ItemActivated(QModelIndex))); connect(ui_.list, SIGNAL(doubleClicked(QModelIndex)), SLOT(ItemDoubleClick(QModelIndex))); + connect(ui_.list, SIGNAL(AddToPlaylist(QList)), SIGNAL(Queue(QList))); + connect(ui_.list, SIGNAL(CopyToLibrary(QList)), SIGNAL(CopyToLibrary(QList))); + connect(ui_.list, SIGNAL(MoveToLibrary(QList)), SIGNAL(MoveToLibrary(QList))); } void FileView::SetPath(const QString& path) { @@ -83,5 +86,5 @@ void FileView::ItemDoubleClick(const QModelIndex& index) { if (model_->isDir(index)) return; - emit PlayFile(model_->filePath(index)); + emit Queue(QList() << QUrl::fromLocalFile(model_->filePath(index))); } diff --git a/src/fileview.h b/src/fileview.h index 3d50ce711..95cdca596 100644 --- a/src/fileview.h +++ b/src/fileview.h @@ -19,8 +19,9 @@ class FileView : public QWidget { signals: void PathChanged(const QString& path); - void PlayFile(const QString& path); - void PlayDirectory(const QString& path); + void Queue(const QList& urls); + void CopyToLibrary(const QList& urls); + void MoveToLibrary(const QList& urls); private slots: void FileUp(); diff --git a/src/fileview.ui b/src/fileview.ui index 995296d39..fd3d607f5 100644 --- a/src/fileview.ui +++ b/src/fileview.ui @@ -31,7 +31,7 @@ false - + :/go-previous.png:/go-previous.png @@ -48,7 +48,7 @@ ... - + :/go-next.png:/go-next.png @@ -62,7 +62,7 @@ ... - + :/go-up.png:/go-up.png @@ -76,7 +76,7 @@ ... - + :/go-home.png:/go-home.png @@ -90,7 +90,7 @@ - + true @@ -107,6 +107,15 @@ - + + + FileViewList + QListView +
fileviewlist.h
+
+
+ + + diff --git a/src/fileviewlist.cpp b/src/fileviewlist.cpp new file mode 100644 index 000000000..a2dda7f9b --- /dev/null +++ b/src/fileviewlist.cpp @@ -0,0 +1,48 @@ +#include "fileviewlist.h" + +#include +#include +#include +#include + +FileViewList::FileViewList(QWidget* parent) + : QListView(parent), + menu_(new QMenu(this)) +{ + menu_->addAction(QIcon(":media-playback-start.png"), "Add to playlist", + this, SLOT(AddToPlaylistSlot())); + menu_->addSeparator(); + menu_->addAction(QIcon(":copy.png"), "Copy to library...", + this, SLOT(CopyToLibrarySlot())); + menu_->addAction(QIcon(":move.png"),"Move to library...", + this, SLOT(MoveToLibrarySlot())); +} + +void FileViewList::contextMenuEvent(QContextMenuEvent* e) { + menu_selection_ = selectionModel()->selection(); + + menu_->popup(e->globalPos()); + e->accept(); +} + +QList FileViewList::UrlListFromSelection() const { + QList urls; + foreach (const QModelIndex& index, menu_selection_.indexes()) { + if (index.column() == 0) + urls << QUrl::fromLocalFile( + static_cast(model())->filePath(index)); + } + return urls; +} + +void FileViewList::AddToPlaylistSlot() { + emit AddToPlaylist(UrlListFromSelection()); +} + +void FileViewList::CopyToLibrarySlot() { + emit CopyToLibrary(UrlListFromSelection()); +} + +void FileViewList::MoveToLibrarySlot() { + emit MoveToLibrary(UrlListFromSelection()); +} diff --git a/src/fileviewlist.h b/src/fileviewlist.h new file mode 100644 index 000000000..dc6238880 --- /dev/null +++ b/src/fileviewlist.h @@ -0,0 +1,33 @@ +#ifndef FILEVIEWLIST_H +#define FILEVIEWLIST_H + +#include +#include + +class FileViewList : public QListView { + Q_OBJECT + + public: + FileViewList(QWidget* parent = 0); + + signals: + void AddToPlaylist(const QList& urls); + void CopyToLibrary(const QList& urls); + void MoveToLibrary(const QList& urls); + + protected: + void contextMenuEvent(QContextMenuEvent* e); + + private slots: + void AddToPlaylistSlot(); + void CopyToLibrarySlot(); + void MoveToLibrarySlot(); + + QList UrlListFromSelection() const; + + private: + QMenu* menu_; + QItemSelection menu_selection_; +}; + +#endif // FILEVIEWLIST_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3d33851ae..51a263ae4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -48,7 +48,7 @@ MainWindow::MainWindow(QWidget *parent) ui_.library_view->SetLibrary(library_); // File view connections - connect(ui_.file_view, SIGNAL(PlayFile(QString)), SLOT(PlayFile(QString))); + connect(ui_.file_view, SIGNAL(Queue(QList)), SLOT(QueueFiles(QList))); connect(ui_.file_view, SIGNAL(PathChanged(QString)), SLOT(FilePathChanged(QString))); // Action connections @@ -176,14 +176,8 @@ MainWindow::~MainWindow() { SaveGeometry(); } -void MainWindow::PlayFile(const QString& path) { - Song song; - song.InitFromFile(path, -1); - - if (!song.is_valid()) - return; - - QModelIndex playlist_index = playlist_->InsertSongs(SongList() << song); +void MainWindow::QueueFiles(const QList& urls) { + QModelIndex playlist_index = playlist_->InsertPaths(urls); if (playlist_index.isValid() && player_->GetState() != Engine::Playing) player_->PlayAt(playlist_index.row()); diff --git a/src/mainwindow.h b/src/mainwindow.h index 9510349b3..48b6b33fc 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -28,7 +28,7 @@ class MainWindow : public QMainWindow { void closeEvent(QCloseEvent* event); private slots: - void PlayFile(const QString& path); + void QueueFiles(const QList& urls); void FilePathChanged(const QString& path); void ReportError(const QString& message); diff --git a/src/playlist.cpp b/src/playlist.cpp index fa85823fa..e905a14db 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -158,48 +158,52 @@ bool Playlist::dropMimeData(const QMimeData* data, Qt::DropAction action, int ro layoutChanged(); } else if (data->hasUrls()) { - // URL list dragged from some other app probably - SongList songs; - foreach (const QUrl& url, data->urls()) { - if (url.scheme() != "file") - continue; + // URL list dragged from the file list or some other app + InsertPaths(data->urls(), row); + } - QString filename(url.toLocalFile()); - QFileInfo info(filename); + return true; +} - if (!info.exists()) - continue; +QModelIndex Playlist::InsertPaths(const QList& urls, int after) { + SongList songs; + foreach (const QUrl& url, urls) { + if (url.scheme() != "file") + continue; - if (info.isDir()) { - // Add all the songs in the directory - QDirIterator it(filename, - QDir::Files | QDir::NoDotAndDotDot | QDir::Readable, - QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); + QString filename(url.toLocalFile()); + QFileInfo info(filename); - while (it.hasNext()) { - QString path(it.next()); + if (!info.exists()) + continue; - Song song; - song.InitFromFile(path, -1); - if (!song.is_valid()) - continue; + if (info.isDir()) { + // Add all the songs in the directory + QDirIterator it(filename, + QDir::Files | QDir::NoDotAndDotDot | QDir::Readable, + QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); + + while (it.hasNext()) { + QString path(it.next()); - songs << song; - } - } else { Song song; - song.InitFromFile(filename, -1); + song.InitFromFile(path, -1); if (!song.is_valid()) continue; songs << song; } - } + } else { + Song song; + song.InitFromFile(filename, -1); + if (!song.is_valid()) + continue; - InsertSongs(songs, row); + songs << song; + } } - return true; + return InsertSongs(songs, after); } QModelIndex Playlist::InsertItems(const QList& items, int after) { diff --git a/src/playlist.h b/src/playlist.h index 7dd3c78db..7e12c6e6a 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -49,6 +49,7 @@ class Playlist : public QAbstractListModel { // Changing the playlist QModelIndex InsertItems(const QList& items, int after = -1); QModelIndex InsertSongs(const SongList& items, int after = -1); + QModelIndex InsertPaths(const QList& urls, int after = -1); void StopAfter(int row); // QAbstractListModel diff --git a/src/src.pro b/src/src.pro index 4333f3cb1..41fba5f0a 100644 --- a/src/src.pro +++ b/src/src.pro @@ -31,7 +31,8 @@ SOURCES += main.cpp \ libraryconfig.cpp \ systemtrayicon.cpp \ libraryquery.cpp \ - fileview.cpp + fileview.cpp \ + fileviewlist.cpp HEADERS += mainwindow.h \ player.h \ library.h \ @@ -59,7 +60,8 @@ HEADERS += mainwindow.h \ libraryconfig.h \ systemtrayicon.h \ libraryquery.h \ - fileview.h + fileview.h \ + fileviewlist.h FORMS += mainwindow.ui \ libraryconfig.ui \ fileview.ui