2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 23:26:58 +01:00
|
|
|
#include "fileviewlist.h"
|
2011-01-10 23:26:13 +01:00
|
|
|
#include "core/mimedata.h"
|
2012-01-29 19:44:00 +01:00
|
|
|
#include "core/utilities.h"
|
2010-05-19 17:45:29 +02:00
|
|
|
#include "ui/iconloader.h"
|
2009-12-24 23:26:58 +01:00
|
|
|
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QFileSystemModel>
|
2011-02-15 18:38:45 +01:00
|
|
|
#include <QMenu>
|
2009-12-24 23:26:58 +01:00
|
|
|
#include <QtDebug>
|
|
|
|
|
|
|
|
FileViewList::FileViewList(QWidget* parent)
|
|
|
|
: QListView(parent),
|
|
|
|
menu_(new QMenu(this))
|
|
|
|
{
|
2011-02-08 23:42:09 +01:00
|
|
|
menu_->addAction(IconLoader::Load("media-playback-start"), tr("Append to current playlist"),
|
2009-12-24 23:26:58 +01:00
|
|
|
this, SLOT(AddToPlaylistSlot()));
|
2011-02-08 23:42:09 +01:00
|
|
|
menu_->addAction(IconLoader::Load("media-playback-start"), tr("Replace current playlist"),
|
|
|
|
this, SLOT(LoadSlot()));
|
2011-02-09 18:51:59 +01:00
|
|
|
menu_->addAction(IconLoader::Load("document-new"), tr("Open in new playlist"),
|
|
|
|
this, SLOT(OpenInNewPlaylistSlot()));
|
2010-06-24 18:26:49 +02:00
|
|
|
menu_->addSeparator();
|
2010-05-19 17:45:29 +02:00
|
|
|
menu_->addAction(IconLoader::Load("edit-copy"), tr("Copy to library..."),
|
2009-12-24 23:26:58 +01:00
|
|
|
this, SLOT(CopyToLibrarySlot()));
|
2010-05-19 17:45:29 +02:00
|
|
|
menu_->addAction(IconLoader::Load("go-jump"), tr("Move to library..."),
|
2010-06-24 18:26:49 +02:00
|
|
|
this, SLOT(MoveToLibrarySlot()));
|
2010-09-18 11:54:33 +02:00
|
|
|
menu_->addAction(IconLoader::Load("multimedia-player-ipod-mini-blue"),
|
|
|
|
tr("Copy to device..."), this, SLOT(CopyToDeviceSlot()));
|
2010-07-31 18:12:16 +02:00
|
|
|
menu_->addAction(IconLoader::Load("edit-delete"), tr("Delete from disk..."),
|
|
|
|
this, SLOT(DeleteSlot()));
|
2012-01-29 19:44:00 +01:00
|
|
|
|
|
|
|
menu_->addSeparator();
|
|
|
|
menu_->addAction(IconLoader::Load("edit-rename"),
|
|
|
|
tr("Edit track information..."), this, SLOT(EditTagsSlot()));
|
|
|
|
menu_->addAction(IconLoader::Load("document-open-folder"),
|
|
|
|
tr("Show in file browser..."), this, SLOT(ShowInBrowser()));
|
|
|
|
|
2010-08-26 14:34:03 +02:00
|
|
|
setAttribute(Qt::WA_MacShowFocusRect, false);
|
2009-12-24 23:26:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void FileViewList::contextMenuEvent(QContextMenuEvent* e) {
|
|
|
|
menu_selection_ = selectionModel()->selection();
|
|
|
|
|
|
|
|
menu_->popup(e->globalPos());
|
|
|
|
e->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QUrl> FileViewList::UrlListFromSelection() const {
|
|
|
|
QList<QUrl> urls;
|
|
|
|
foreach (const QModelIndex& index, menu_selection_.indexes()) {
|
|
|
|
if (index.column() == 0)
|
|
|
|
urls << QUrl::fromLocalFile(
|
2011-03-13 15:43:03 +01:00
|
|
|
static_cast<QFileSystemModel*>(model())->fileInfo(index).canonicalFilePath());
|
2009-12-24 23:26:58 +01:00
|
|
|
}
|
|
|
|
return urls;
|
|
|
|
}
|
|
|
|
|
2011-01-10 23:26:13 +01:00
|
|
|
MimeData* FileViewList::MimeDataFromSelection() const {
|
|
|
|
MimeData* data = new MimeData;
|
|
|
|
data->setUrls(UrlListFromSelection());
|
2011-02-16 19:29:35 +01:00
|
|
|
|
|
|
|
QList<QString> filenames = FilenamesFromSelection();
|
2011-02-20 16:05:05 +01:00
|
|
|
// if just one folder selected - use it's path as the new playlist's name
|
|
|
|
if(filenames.size() == 1 && QFileInfo(filenames.first()).isDir()) {
|
|
|
|
data->name_for_new_playlist_ = filenames.first();
|
2011-02-16 19:29:35 +01:00
|
|
|
// otherwise, use the current root path
|
|
|
|
} else {
|
|
|
|
data->name_for_new_playlist_ = static_cast<QFileSystemModel*>(model())->rootPath();
|
|
|
|
}
|
|
|
|
|
2011-01-10 23:26:13 +01:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2010-07-31 18:12:16 +02:00
|
|
|
QStringList FileViewList::FilenamesFromSelection() const {
|
|
|
|
QStringList filenames;
|
|
|
|
foreach (const QModelIndex& index, menu_selection_.indexes()) {
|
|
|
|
if (index.column() == 0)
|
|
|
|
filenames << static_cast<QFileSystemModel*>(model())->filePath(index);
|
|
|
|
}
|
|
|
|
return filenames;
|
|
|
|
}
|
|
|
|
|
2010-05-15 19:45:04 +02:00
|
|
|
void FileViewList::LoadSlot() {
|
2011-01-10 23:26:13 +01:00
|
|
|
MimeData* data = MimeDataFromSelection();
|
|
|
|
data->clear_first_ = true;
|
|
|
|
emit AddToPlaylist(data);
|
2010-05-15 19:45:04 +02:00
|
|
|
}
|
|
|
|
|
2009-12-24 23:26:58 +01:00
|
|
|
void FileViewList::AddToPlaylistSlot() {
|
2011-01-10 23:26:13 +01:00
|
|
|
emit AddToPlaylist(MimeDataFromSelection());
|
2009-12-24 23:26:58 +01:00
|
|
|
}
|
|
|
|
|
2011-02-09 18:51:59 +01:00
|
|
|
void FileViewList::OpenInNewPlaylistSlot() {
|
|
|
|
MimeData* data = MimeDataFromSelection();
|
2011-02-16 19:29:35 +01:00
|
|
|
data->open_in_new_playlist_ = true;
|
2011-02-09 18:51:59 +01:00
|
|
|
emit AddToPlaylist(data);
|
|
|
|
}
|
|
|
|
|
2009-12-24 23:26:58 +01:00
|
|
|
void FileViewList::CopyToLibrarySlot() {
|
|
|
|
emit CopyToLibrary(UrlListFromSelection());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileViewList::MoveToLibrarySlot() {
|
|
|
|
emit MoveToLibrary(UrlListFromSelection());
|
|
|
|
}
|
2010-07-31 18:12:16 +02:00
|
|
|
|
2010-09-18 11:54:33 +02:00
|
|
|
void FileViewList::CopyToDeviceSlot() {
|
|
|
|
emit CopyToDevice(UrlListFromSelection());
|
|
|
|
}
|
|
|
|
|
2010-07-31 18:12:16 +02:00
|
|
|
void FileViewList::DeleteSlot() {
|
|
|
|
emit Delete(FilenamesFromSelection());
|
|
|
|
}
|
2011-03-10 13:42:35 +01:00
|
|
|
|
2012-01-29 19:44:00 +01:00
|
|
|
void FileViewList::EditTagsSlot() {
|
|
|
|
emit EditTags(UrlListFromSelection());
|
|
|
|
}
|
|
|
|
|
2011-03-10 13:42:35 +01:00
|
|
|
void FileViewList::mousePressEvent(QMouseEvent* e) {
|
|
|
|
QListView::mousePressEvent(e);
|
|
|
|
|
|
|
|
//enqueue to playlist with middleClick
|
|
|
|
if (e->button() == Qt::MidButton) {
|
|
|
|
//we need to update the menu selection
|
|
|
|
menu_selection_ = selectionModel()->selection();
|
|
|
|
|
|
|
|
MimeData* data = new MimeData;
|
|
|
|
data->setUrls(UrlListFromSelection());
|
|
|
|
data->enqueue_now_ = true;
|
|
|
|
emit AddToPlaylist(data);
|
|
|
|
}
|
|
|
|
}
|
2012-01-29 19:44:00 +01:00
|
|
|
|
|
|
|
void FileViewList::ShowInBrowser() {
|
|
|
|
Utilities::OpenInFileBrowser(UrlListFromSelection());
|
|
|
|
}
|