Refactoring
This commit is contained in:
@@ -44,9 +44,10 @@
|
||||
#include "fancytabwidget.h"
|
||||
#include "fancytabbar.h"
|
||||
#include "fancytabdata.h"
|
||||
#include "utilities/colorutils.h"
|
||||
#include "core/stylehelper.h"
|
||||
#include "core/settings.h"
|
||||
#include "settings/appearancesettingspage.h"
|
||||
#include "constants/appearancesettings.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
@@ -160,15 +161,15 @@ void FancyTabWidget::SaveSettings(const QString &settings_group) {
|
||||
void FancyTabWidget::ReloadSettings() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(AppearanceSettingsPage::kSettingsGroup);
|
||||
bg_color_system_ = s.value(AppearanceSettingsPage::kTabBarSystemColor, false).toBool();
|
||||
bg_gradient_ = s.value(AppearanceSettingsPage::kTabBarGradient, true).toBool();
|
||||
bg_color_ = AppearanceSettingsPage::DefaultTabbarBgColor();
|
||||
s.beginGroup(AppearanceSettings::kSettingsGroup);
|
||||
bg_color_system_ = s.value(AppearanceSettings::kTabBarSystemColor, false).toBool();
|
||||
bg_gradient_ = s.value(AppearanceSettings::kTabBarGradient, true).toBool();
|
||||
bg_color_ = DefaultTabbarBgColor();
|
||||
if (!bg_color_system_) {
|
||||
bg_color_ = s.value(AppearanceSettingsPage::kTabBarColor, bg_color_).value<QColor>();
|
||||
bg_color_ = s.value(AppearanceSettings::kTabBarColor, bg_color_).value<QColor>();
|
||||
}
|
||||
iconsize_smallsidebar_ = s.value(AppearanceSettingsPage::kIconSizeTabbarSmallMode, IconSize_SmallSidebar).toInt();
|
||||
iconsize_largesidebar_ = s.value(AppearanceSettingsPage::kIconSizeTabbarLargeMode, IconSize_LargeSidebar).toInt();
|
||||
iconsize_smallsidebar_ = s.value(AppearanceSettings::kIconSizeTabbarSmallMode, IconSize_SmallSidebar).toInt();
|
||||
iconsize_largesidebar_ = s.value(AppearanceSettings::kIconSizeTabbarLargeMode, IconSize_LargeSidebar).toInt();
|
||||
s.endGroup();
|
||||
|
||||
#ifndef Q_OS_MACOS
|
||||
@@ -396,3 +397,13 @@ void FancyTabWidget::contextMenuEvent(QContextMenuEvent *e) {
|
||||
menu_->popup(e->globalPos());
|
||||
|
||||
}
|
||||
|
||||
QColor FancyTabWidget::DefaultTabbarBgColor() {
|
||||
|
||||
QColor color = StyleHelper::highlightColor();
|
||||
if (Utilities::IsColorDark(color)) {
|
||||
color = color.lighter(130);
|
||||
}
|
||||
return color;
|
||||
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ class FancyTabWidget : public QTabWidget {
|
||||
void SetBackgroundPixmap(const QPixmap &pixmap);
|
||||
int IndexOfTab(QWidget *widget);
|
||||
|
||||
static QColor DefaultTabbarBgColor();
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetMode(const Mode mode);
|
||||
void SetCurrentIndex(int idx);
|
||||
|
||||
@@ -1,306 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QUndoStack>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QFileSystemModel>
|
||||
#include <QFileIconProvider>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
#include <QSettings>
|
||||
#include <QMessageBox>
|
||||
#include <QScrollBar>
|
||||
#include <QLineEdit>
|
||||
#include <QToolButton>
|
||||
#include <QtEvents>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/deletefiles.h"
|
||||
#include "core/filesystemmusicstorage.h"
|
||||
#include "core/iconloader.h"
|
||||
#include "core/mimedata.h"
|
||||
#include "core/settings.h"
|
||||
#include "dialogs/deleteconfirmationdialog.h"
|
||||
#include "fileview.h"
|
||||
#include "fileviewlist.h"
|
||||
#include "ui_fileview.h"
|
||||
#include "organize/organizeerrordialog.h"
|
||||
#include "settings/appearancesettingspage.h"
|
||||
|
||||
using std::make_unique;
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
const char *FileView::kFileFilter =
|
||||
"*.wav *.flac *.wv *.ogg *.oga *.opus *.spx *.ape *.mpc "
|
||||
"*.mp2 *.mp3 *.m4a *.mp4 *.aac *.asf *.asx *.wma "
|
||||
"*.aif *.aiff *.mka *.tta *.dsf *.dsd "
|
||||
"*.cue *.m3u *.m3u8 *.pls *.xspf *.asxini "
|
||||
"*.ac3 *.dts "
|
||||
"*.mod *.s3m *.xm *.it"
|
||||
"*.spc *.vgm";
|
||||
|
||||
FileView::FileView(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
ui_(new Ui_FileView),
|
||||
model_(nullptr),
|
||||
undo_stack_(new QUndoStack(this)),
|
||||
task_manager_(nullptr),
|
||||
storage_(new FilesystemMusicStorage(Song::Source::LocalFile, u"/"_s)) {
|
||||
|
||||
ui_->setupUi(this);
|
||||
|
||||
// Icons
|
||||
ui_->back->setIcon(IconLoader::Load(u"go-previous"_s));
|
||||
ui_->forward->setIcon(IconLoader::Load(u"go-next"_s));
|
||||
ui_->home->setIcon(IconLoader::Load(u"go-home"_s));
|
||||
ui_->up->setIcon(IconLoader::Load(u"go-up"_s));
|
||||
|
||||
QObject::connect(ui_->back, &QToolButton::clicked, undo_stack_, &QUndoStack::undo);
|
||||
QObject::connect(ui_->forward, &QToolButton::clicked, undo_stack_, &QUndoStack::redo);
|
||||
QObject::connect(ui_->home, &QToolButton::clicked, this, &FileView::FileHome);
|
||||
QObject::connect(ui_->up, &QToolButton::clicked, this, &FileView::FileUp);
|
||||
QObject::connect(ui_->path, &QLineEdit::textChanged, this, &FileView::ChangeFilePath);
|
||||
|
||||
QObject::connect(undo_stack_, &QUndoStack::canUndoChanged, ui_->back, &FileView::setEnabled);
|
||||
QObject::connect(undo_stack_, &QUndoStack::canRedoChanged, ui_->forward, &FileView::setEnabled);
|
||||
|
||||
QObject::connect(ui_->list, &FileViewList::activated, this, &FileView::ItemActivated);
|
||||
QObject::connect(ui_->list, &FileViewList::doubleClicked, this, &FileView::ItemDoubleClick);
|
||||
QObject::connect(ui_->list, &FileViewList::AddToPlaylist, this, &FileView::AddToPlaylist);
|
||||
QObject::connect(ui_->list, &FileViewList::CopyToCollection, this, &FileView::CopyToCollection);
|
||||
QObject::connect(ui_->list, &FileViewList::MoveToCollection, this, &FileView::MoveToCollection);
|
||||
QObject::connect(ui_->list, &FileViewList::CopyToDevice, this, &FileView::CopyToDevice);
|
||||
QObject::connect(ui_->list, &FileViewList::Delete, this, &FileView::Delete);
|
||||
QObject::connect(ui_->list, &FileViewList::EditTags, this, &FileView::EditTags);
|
||||
|
||||
QString filter = QLatin1String(FileView::kFileFilter);
|
||||
filter_list_ << filter.split(u' ');
|
||||
|
||||
ReloadSettings();
|
||||
|
||||
}
|
||||
|
||||
FileView::~FileView() {
|
||||
delete ui_;
|
||||
}
|
||||
|
||||
void FileView::ReloadSettings() {
|
||||
|
||||
Settings s;
|
||||
s.beginGroup(AppearanceSettingsPage::kSettingsGroup);
|
||||
int iconsize = s.value(AppearanceSettingsPage::kIconSizeLeftPanelButtons, 22).toInt();
|
||||
s.endGroup();
|
||||
|
||||
ui_->back->setIconSize(QSize(iconsize, iconsize));
|
||||
ui_->forward->setIconSize(QSize(iconsize, iconsize));
|
||||
ui_->home->setIconSize(QSize(iconsize, iconsize));
|
||||
ui_->up->setIconSize(QSize(iconsize, iconsize));
|
||||
|
||||
}
|
||||
|
||||
void FileView::SetPath(const QString &path) {
|
||||
|
||||
if (model_) {
|
||||
ChangeFilePathWithoutUndo(path);
|
||||
}
|
||||
else {
|
||||
lazy_set_path_ = path;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FileView::SetTaskManager(SharedPtr<TaskManager> task_manager) {
|
||||
task_manager_ = task_manager;
|
||||
}
|
||||
|
||||
void FileView::FileUp() {
|
||||
|
||||
QDir dir(model_->rootDirectory());
|
||||
dir.cdUp();
|
||||
|
||||
// Is this the same as going back? If so just go back, so we can keep the view scroll position.
|
||||
if (undo_stack_->canUndo()) {
|
||||
const UndoCommand *last_dir = static_cast<const UndoCommand*>(undo_stack_->command(undo_stack_->index() - 1));
|
||||
if (last_dir->undo_path() == dir.path()) {
|
||||
undo_stack_->undo();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ChangeFilePath(dir.path());
|
||||
|
||||
}
|
||||
|
||||
void FileView::FileHome() {
|
||||
ChangeFilePath(QDir::homePath());
|
||||
}
|
||||
|
||||
void FileView::ChangeFilePath(const QString &new_path_native) {
|
||||
|
||||
QString new_path = QDir::fromNativeSeparators(new_path_native);
|
||||
|
||||
QFileInfo info(new_path);
|
||||
if (!info.exists() || !info.isDir()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString old_path(model_->rootPath());
|
||||
if (old_path == new_path) {
|
||||
return;
|
||||
}
|
||||
|
||||
undo_stack_->push(new UndoCommand(this, new_path));
|
||||
|
||||
}
|
||||
|
||||
void FileView::ChangeFilePathWithoutUndo(const QString &new_path) {
|
||||
|
||||
ui_->list->setRootIndex(model_->setRootPath(new_path));
|
||||
ui_->path->setText(QDir::toNativeSeparators(new_path));
|
||||
|
||||
QDir dir(new_path);
|
||||
ui_->up->setEnabled(dir.cdUp());
|
||||
|
||||
Q_EMIT PathChanged(new_path);
|
||||
|
||||
}
|
||||
|
||||
void FileView::ItemActivated(const QModelIndex &idx) {
|
||||
if (model_->isDir(idx))
|
||||
ChangeFilePath(model_->filePath(idx));
|
||||
}
|
||||
|
||||
void FileView::ItemDoubleClick(const QModelIndex &idx) {
|
||||
|
||||
if (model_->isDir(idx)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString file_path = model_->filePath(idx);
|
||||
|
||||
MimeData *mimedata = new MimeData;
|
||||
mimedata->from_doubleclick_ = true;
|
||||
mimedata->setUrls(QList<QUrl>() << QUrl::fromLocalFile(file_path));
|
||||
mimedata->name_for_new_playlist_ = file_path;
|
||||
|
||||
Q_EMIT AddToPlaylist(mimedata);
|
||||
|
||||
}
|
||||
|
||||
|
||||
FileView::UndoCommand::UndoCommand(FileView *view, const QString &new_path) : view_(view) {
|
||||
|
||||
old_state_.path = view->model_->rootPath();
|
||||
old_state_.scroll_pos = view_->ui_->list->verticalScrollBar()->value();
|
||||
old_state_.index = view_->ui_->list->currentIndex();
|
||||
|
||||
new_state_.path = new_path;
|
||||
|
||||
}
|
||||
|
||||
void FileView::UndoCommand::redo() {
|
||||
|
||||
view_->ChangeFilePathWithoutUndo(new_state_.path);
|
||||
if (new_state_.scroll_pos != -1) {
|
||||
view_->ui_->list->setCurrentIndex(new_state_.index);
|
||||
view_->ui_->list->verticalScrollBar()->setValue(new_state_.scroll_pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FileView::UndoCommand::undo() {
|
||||
|
||||
new_state_.scroll_pos = view_->ui_->list->verticalScrollBar()->value();
|
||||
new_state_.index = view_->ui_->list->currentIndex();
|
||||
|
||||
view_->ChangeFilePathWithoutUndo(old_state_.path);
|
||||
view_->ui_->list->setCurrentIndex(old_state_.index);
|
||||
view_->ui_->list->verticalScrollBar()->setValue(old_state_.scroll_pos);
|
||||
|
||||
}
|
||||
|
||||
void FileView::Delete(const QStringList &filenames) {
|
||||
|
||||
if (filenames.isEmpty()) return;
|
||||
|
||||
if (DeleteConfirmationDialog::warning(filenames) != QDialogButtonBox::Yes) return;
|
||||
|
||||
DeleteFiles *delete_files = new DeleteFiles(task_manager_, storage_, true);
|
||||
QObject::connect(delete_files, &DeleteFiles::Finished, this, &FileView::DeleteFinished);
|
||||
delete_files->Start(filenames);
|
||||
|
||||
}
|
||||
|
||||
void FileView::DeleteFinished(const SongList &songs_with_errors) {
|
||||
|
||||
if (songs_with_errors.isEmpty()) return;
|
||||
|
||||
OrganizeErrorDialog *dialog = new OrganizeErrorDialog(this);
|
||||
dialog->Show(OrganizeErrorDialog::OperationType::Delete, songs_with_errors);
|
||||
// It deletes itself when the user closes it
|
||||
|
||||
}
|
||||
|
||||
void FileView::showEvent(QShowEvent *e) {
|
||||
|
||||
QWidget::showEvent(e);
|
||||
|
||||
if (model_) return;
|
||||
|
||||
model_ = new QFileSystemModel(this);
|
||||
if (!model_->iconProvider() || model_->iconProvider()->icon(QFileIconProvider::Folder).isNull()) {
|
||||
file_icon_provider_ = make_unique<QFileIconProvider>();
|
||||
model_->setIconProvider(&*file_icon_provider_);
|
||||
}
|
||||
|
||||
model_->setNameFilters(filter_list_);
|
||||
// if an item fails the filter, hide it
|
||||
model_->setNameFilterDisables(false);
|
||||
|
||||
ui_->list->setModel(model_);
|
||||
ChangeFilePathWithoutUndo(QDir::homePath());
|
||||
|
||||
if (!lazy_set_path_.isEmpty()) ChangeFilePathWithoutUndo(lazy_set_path_);
|
||||
|
||||
}
|
||||
|
||||
void FileView::keyPressEvent(QKeyEvent *e) {
|
||||
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Back:
|
||||
case Qt::Key_Backspace:
|
||||
ui_->up->click();
|
||||
break;
|
||||
case Qt::Key_Enter:
|
||||
case Qt::Key_Return:
|
||||
ItemDoubleClick(ui_->list->currentIndex());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
QWidget::keyPressEvent(e);
|
||||
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FILEVIEW_H
|
||||
#define FILEVIEW_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
#include <QUndoCommand>
|
||||
|
||||
#include "core/scoped_ptr.h"
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/song.h"
|
||||
|
||||
class QMimeData;
|
||||
class QFileSystemModel;
|
||||
class QFileIconProvider;
|
||||
class QUndoStack;
|
||||
class QKeyEvent;
|
||||
class QShowEvent;
|
||||
|
||||
class MusicStorage;
|
||||
class TaskManager;
|
||||
class Ui_FileView;
|
||||
|
||||
class FileView : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FileView(QWidget *parent = nullptr);
|
||||
~FileView() override;
|
||||
|
||||
static const char *kFileFilter;
|
||||
|
||||
void ReloadSettings();
|
||||
|
||||
void SetPath(const QString &path);
|
||||
void SetTaskManager(SharedPtr<TaskManager> task_manager);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent*) override;
|
||||
void keyPressEvent(QKeyEvent *e) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void PathChanged(const QString &path);
|
||||
|
||||
void AddToPlaylist(QMimeData *data);
|
||||
void CopyToCollection(const QList<QUrl> &urls);
|
||||
void MoveToCollection(const QList<QUrl> &urls);
|
||||
void CopyToDevice(const QList<QUrl> &urls);
|
||||
void EditTags(const QList<QUrl> &urls);
|
||||
|
||||
private Q_SLOTS:
|
||||
void FileUp();
|
||||
void FileHome();
|
||||
void ChangeFilePath(const QString &new_path);
|
||||
void ItemActivated(const QModelIndex &idx);
|
||||
void ItemDoubleClick(const QModelIndex &idx);
|
||||
|
||||
void Delete(const QStringList &filenames);
|
||||
void DeleteFinished(const SongList &songs_with_errors);
|
||||
|
||||
private:
|
||||
void ChangeFilePathWithoutUndo(const QString &new_path);
|
||||
|
||||
private:
|
||||
class UndoCommand : public QUndoCommand {
|
||||
public:
|
||||
UndoCommand(FileView *view, const QString &new_path);
|
||||
|
||||
QString undo_path() const { return old_state_.path; }
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
private:
|
||||
struct State {
|
||||
State() : scroll_pos(-1) {}
|
||||
|
||||
QString path;
|
||||
QModelIndex index;
|
||||
int scroll_pos;
|
||||
};
|
||||
|
||||
FileView *view_;
|
||||
State old_state_;
|
||||
State new_state_;
|
||||
};
|
||||
|
||||
Ui_FileView *ui_;
|
||||
|
||||
QFileSystemModel *model_;
|
||||
QUndoStack *undo_stack_;
|
||||
|
||||
SharedPtr<TaskManager> task_manager_;
|
||||
SharedPtr<MusicStorage> storage_;
|
||||
|
||||
QString lazy_set_path_;
|
||||
|
||||
QStringList filter_list_;
|
||||
|
||||
ScopedPtr<QFileIconProvider> file_icon_provider_;
|
||||
};
|
||||
|
||||
#endif // FILEVIEW_H
|
||||
@@ -1,133 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FileView</class>
|
||||
<widget class="QWidget" name="FileView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="back">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>22</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="forward">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>22</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="up">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>22</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="home">
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>22</width>
|
||||
<height>22</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="path"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="FileViewList" name="list">
|
||||
<property name="dragEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::DragOnly</enum>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>FileViewList</class>
|
||||
<extends>QListView</extends>
|
||||
<header>widgets/fileviewlist.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -1,221 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include <QWidget>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QFileInfo>
|
||||
#include <QFileSystemModel>
|
||||
#include <QDir>
|
||||
#include <QMenu>
|
||||
#include <QUrl>
|
||||
#include <QCollator>
|
||||
#include <QtEvents>
|
||||
|
||||
#include "core/iconloader.h"
|
||||
#include "core/mimedata.h"
|
||||
#include "utilities/filemanagerutils.h"
|
||||
#include "fileviewlist.h"
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
FileViewList::FileViewList(QWidget *parent)
|
||||
: QListView(parent),
|
||||
menu_(new QMenu(this)) {
|
||||
|
||||
menu_->addAction(IconLoader::Load(u"media-playback-start"_s), tr("Append to current playlist"), this, &FileViewList::AddToPlaylistSlot);
|
||||
menu_->addAction(IconLoader::Load(u"media-playback-start"_s), tr("Replace current playlist"), this, &FileViewList::LoadSlot);
|
||||
menu_->addAction(IconLoader::Load(u"document-new"_s), tr("Open in new playlist"), this, &FileViewList::OpenInNewPlaylistSlot);
|
||||
menu_->addSeparator();
|
||||
menu_->addAction(IconLoader::Load(u"edit-copy"_s), tr("Copy to collection..."), this, &FileViewList::CopyToCollectionSlot);
|
||||
menu_->addAction(IconLoader::Load(u"go-jump"_s), tr("Move to collection..."), this, &FileViewList::MoveToCollectionSlot);
|
||||
menu_->addAction(IconLoader::Load(u"device"_s), tr("Copy to device..."), this, &FileViewList::CopyToDeviceSlot);
|
||||
menu_->addAction(IconLoader::Load(u"edit-delete"_s), tr("Delete from disk..."), this, &FileViewList::DeleteSlot);
|
||||
|
||||
menu_->addSeparator();
|
||||
menu_->addAction(IconLoader::Load(u"edit-rename"_s), tr("Edit track information..."), this, &FileViewList::EditTagsSlot);
|
||||
menu_->addAction(IconLoader::Load(u"document-open-folder"_s), tr("Show in file browser..."), this, &FileViewList::ShowInBrowser);
|
||||
|
||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
|
||||
}
|
||||
|
||||
void FileViewList::contextMenuEvent(QContextMenuEvent *e) {
|
||||
|
||||
menu_selection_ = selectionModel()->selection();
|
||||
|
||||
menu_->popup(e->globalPos());
|
||||
e->accept();
|
||||
|
||||
}
|
||||
|
||||
QList<QUrl> FileViewList::UrlListFromSelection() const {
|
||||
|
||||
QStringList filenames;
|
||||
const QModelIndexList indexes = menu_selection_.indexes();
|
||||
for (const QModelIndex &index : indexes) {
|
||||
if (index.column() == 0) {
|
||||
filenames << QDir::cleanPath(qobject_cast<QFileSystemModel*>(model())->fileInfo(index).filePath());
|
||||
}
|
||||
}
|
||||
|
||||
QCollator collator;
|
||||
collator.setNumericMode(true);
|
||||
std::sort(filenames.begin(), filenames.end(), collator);
|
||||
|
||||
QList<QUrl> urls;
|
||||
urls.reserve(filenames.count());
|
||||
for (const QString &filename : std::as_const(filenames)) {
|
||||
urls << QUrl::fromLocalFile(filename);
|
||||
}
|
||||
|
||||
return urls;
|
||||
|
||||
}
|
||||
|
||||
MimeData *FileViewList::MimeDataFromSelection() const {
|
||||
|
||||
MimeData *mimedata = new MimeData;
|
||||
mimedata->setUrls(UrlListFromSelection());
|
||||
|
||||
const QStringList filenames = FilenamesFromSelection();
|
||||
|
||||
// if just one folder selected - use its path as the new playlist's name
|
||||
if (filenames.size() == 1 && QFileInfo(filenames.first()).isDir()) {
|
||||
if (filenames.first().length() > 20) {
|
||||
mimedata->name_for_new_playlist_ = QDir(filenames.first()).dirName();
|
||||
}
|
||||
else {
|
||||
mimedata->name_for_new_playlist_ = filenames.first();
|
||||
}
|
||||
}
|
||||
// otherwise, use the current root path
|
||||
else {
|
||||
QString path = qobject_cast<QFileSystemModel*>(model())->rootPath();
|
||||
if (path.length() > 20) {
|
||||
QFileInfo info(path);
|
||||
if (info.isDir()) {
|
||||
mimedata->name_for_new_playlist_ = QDir(info.filePath()).dirName();
|
||||
}
|
||||
else {
|
||||
mimedata->name_for_new_playlist_ = info.completeBaseName();
|
||||
}
|
||||
}
|
||||
else {
|
||||
mimedata->name_for_new_playlist_ = path;
|
||||
}
|
||||
}
|
||||
|
||||
return mimedata;
|
||||
|
||||
}
|
||||
|
||||
QStringList FileViewList::FilenamesFromSelection() const {
|
||||
|
||||
QStringList filenames;
|
||||
const QModelIndexList indexes = menu_selection_.indexes();
|
||||
for (const QModelIndex &index : indexes) {
|
||||
if (index.column() == 0) {
|
||||
filenames << qobject_cast<QFileSystemModel*>(model())->filePath(index);
|
||||
}
|
||||
}
|
||||
|
||||
QCollator collator;
|
||||
collator.setNumericMode(true);
|
||||
std::sort(filenames.begin(), filenames.end(), collator);
|
||||
|
||||
return filenames;
|
||||
|
||||
}
|
||||
|
||||
void FileViewList::LoadSlot() {
|
||||
|
||||
MimeData *mimedata = MimeDataFromSelection();
|
||||
mimedata->clear_first_ = true;
|
||||
Q_EMIT AddToPlaylist(mimedata);
|
||||
|
||||
}
|
||||
|
||||
void FileViewList::AddToPlaylistSlot() {
|
||||
Q_EMIT AddToPlaylist(MimeDataFromSelection());
|
||||
}
|
||||
|
||||
void FileViewList::OpenInNewPlaylistSlot() {
|
||||
|
||||
MimeData *mimedata = MimeDataFromSelection();
|
||||
mimedata->open_in_new_playlist_ = true;
|
||||
Q_EMIT AddToPlaylist(mimedata);
|
||||
|
||||
}
|
||||
|
||||
void FileViewList::CopyToCollectionSlot() {
|
||||
Q_EMIT CopyToCollection(UrlListFromSelection());
|
||||
}
|
||||
|
||||
void FileViewList::MoveToCollectionSlot() {
|
||||
Q_EMIT MoveToCollection(UrlListFromSelection());
|
||||
}
|
||||
|
||||
void FileViewList::CopyToDeviceSlot() {
|
||||
Q_EMIT CopyToDevice(UrlListFromSelection());
|
||||
}
|
||||
|
||||
void FileViewList::DeleteSlot() {
|
||||
Q_EMIT Delete(FilenamesFromSelection());
|
||||
}
|
||||
|
||||
void FileViewList::EditTagsSlot() {
|
||||
Q_EMIT EditTags(UrlListFromSelection());
|
||||
}
|
||||
|
||||
void FileViewList::mousePressEvent(QMouseEvent *e) {
|
||||
|
||||
switch (e->button()) {
|
||||
case Qt::XButton1:
|
||||
Q_EMIT Back();
|
||||
break;
|
||||
case Qt::XButton2:
|
||||
Q_EMIT Forward();
|
||||
break;
|
||||
// enqueue to playlist with middleClick
|
||||
case Qt::MiddleButton:{
|
||||
QListView::mousePressEvent(e);
|
||||
|
||||
// we need to update the menu selection
|
||||
menu_selection_ = selectionModel()->selection();
|
||||
|
||||
MimeData *mimedata = new MimeData;
|
||||
mimedata->setUrls(UrlListFromSelection());
|
||||
mimedata->enqueue_now_ = true;
|
||||
Q_EMIT AddToPlaylist(mimedata);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
QListView::mousePressEvent(e);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void FileViewList::ShowInBrowser() {
|
||||
Utilities::OpenInFileBrowser(UrlListFromSelection());
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef FILEVIEWLIST_H
|
||||
#define FILEVIEWLIST_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QListView>
|
||||
#include <QItemSelectionModel>
|
||||
#include <QList>
|
||||
#include <QUrl>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
class QWidget;
|
||||
class QMimeData;
|
||||
class QMenu;
|
||||
class QMouseEvent;
|
||||
class QContextMenuEvent;
|
||||
|
||||
class MimeData;
|
||||
|
||||
class FileViewList : public QListView {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FileViewList(QWidget *parent = nullptr);
|
||||
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void AddToPlaylist(QMimeData *data);
|
||||
void CopyToCollection(const QList<QUrl> &urls);
|
||||
void MoveToCollection(const QList<QUrl> &urls);
|
||||
void CopyToDevice(const QList<QUrl> &urls);
|
||||
void Delete(const QStringList &filenames);
|
||||
void EditTags(const QList<QUrl> &urls);
|
||||
void Back();
|
||||
void Forward();
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *e) override;
|
||||
|
||||
private:
|
||||
QStringList FilenamesFromSelection() const;
|
||||
QList<QUrl> UrlListFromSelection() const;
|
||||
MimeData *MimeDataFromSelection() const;
|
||||
|
||||
private Q_SLOTS:
|
||||
void LoadSlot();
|
||||
void AddToPlaylistSlot();
|
||||
void OpenInNewPlaylistSlot();
|
||||
void CopyToCollectionSlot();
|
||||
void MoveToCollectionSlot();
|
||||
void CopyToDeviceSlot();
|
||||
void DeleteSlot();
|
||||
void EditTagsSlot();
|
||||
void ShowInBrowser();
|
||||
|
||||
private:
|
||||
QMenu *menu_;
|
||||
QItemSelection menu_selection_;
|
||||
};
|
||||
|
||||
#endif // FILEVIEWLIST_H
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <QSizePolicy>
|
||||
#include <QPaintEvent>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
#include "core/taskmanager.h"
|
||||
#include "multiloadingindicator.h"
|
||||
#include "widgets/busyindicator.h"
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <QSize>
|
||||
#include <QString>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "includes/shared_ptr.h"
|
||||
|
||||
class QPaintEvent;
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#include <QSettings>
|
||||
#include <QtEvents>
|
||||
|
||||
#include "core/application.h"
|
||||
#include "core/settings.h"
|
||||
#include "utilities/imageutils.h"
|
||||
#include "covermanager/albumcoverchoicecontroller.h"
|
||||
@@ -66,7 +65,6 @@ constexpr int kTopBorder = 4;
|
||||
|
||||
PlayingWidget::PlayingWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
app_(nullptr),
|
||||
album_cover_choice_controller_(nullptr),
|
||||
mode_(Mode::LargeSongDetails),
|
||||
menu_(new QMenu(this)),
|
||||
@@ -127,12 +125,10 @@ PlayingWidget::PlayingWidget(QWidget *parent)
|
||||
|
||||
}
|
||||
|
||||
void PlayingWidget::Init(Application *app, AlbumCoverChoiceController *album_cover_choice_controller) {
|
||||
|
||||
app_ = app;
|
||||
void PlayingWidget::Init(AlbumCoverChoiceController *album_cover_choice_controller) {
|
||||
|
||||
album_cover_choice_controller_ = album_cover_choice_controller;
|
||||
album_cover_choice_controller_->Init(app_);
|
||||
|
||||
QList<QAction*> cover_actions = album_cover_choice_controller_->GetAllActions();
|
||||
menu_->addActions(cover_actions);
|
||||
menu_->addSeparator();
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <QAction>
|
||||
#include <QMovie>
|
||||
|
||||
#include "core/scoped_ptr.h"
|
||||
#include "includes/scoped_ptr.h"
|
||||
#include "core/song.h"
|
||||
|
||||
class QTimeLine;
|
||||
@@ -48,7 +48,6 @@ class QPaintEvent;
|
||||
class QResizeEvent;
|
||||
|
||||
class AlbumCoverChoiceController;
|
||||
class Application;
|
||||
|
||||
class PlayingWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
@@ -56,7 +55,7 @@ class PlayingWidget : public QWidget {
|
||||
public:
|
||||
explicit PlayingWidget(QWidget *parent = nullptr);
|
||||
|
||||
void Init(Application *app, AlbumCoverChoiceController *album_cover_choice_controller);
|
||||
void Init(AlbumCoverChoiceController *album_cover_choice_controller);
|
||||
bool IsEnabled() { return enabled_; }
|
||||
void SetEnabled(const bool enabled);
|
||||
void SetEnabled();
|
||||
@@ -102,7 +101,6 @@ class PlayingWidget : public QWidget {
|
||||
void FadePreviousTrack(const qreal value);
|
||||
|
||||
private:
|
||||
Application *app_;
|
||||
AlbumCoverChoiceController *album_cover_choice_controller_;
|
||||
Mode mode_;
|
||||
QMenu *menu_;
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
#include "core/settings.h"
|
||||
#include "utilities/timeutils.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "constants/timeconstants.h"
|
||||
#include "trackslider.h"
|
||||
#include "ui_trackslider.h"
|
||||
#include "clickablelabel.h"
|
||||
@@ -51,7 +51,7 @@ TrackSlider::TrackSlider(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
ui_(new Ui_TrackSlider),
|
||||
#ifdef HAVE_MOODBAR
|
||||
moodbar_style_(nullptr),
|
||||
moodbar_proxy_style_(nullptr),
|
||||
#endif
|
||||
setting_value_(false),
|
||||
show_remaining_time_(true),
|
||||
@@ -81,17 +81,15 @@ TrackSlider::~TrackSlider() {
|
||||
|
||||
delete ui_;
|
||||
#ifdef HAVE_MOODBAR
|
||||
if (moodbar_style_) moodbar_style_->deleteLater();
|
||||
if (moodbar_proxy_style_) moodbar_proxy_style_->deleteLater();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void TrackSlider::SetApplication(Application *app) {
|
||||
void TrackSlider::Init() {
|
||||
|
||||
#ifdef HAVE_MOODBAR
|
||||
if (!moodbar_style_) moodbar_style_ = new MoodbarProxyStyle(app, ui_->slider);
|
||||
#else
|
||||
Q_UNUSED(app);
|
||||
if (!moodbar_proxy_style_) moodbar_proxy_style_ = new MoodbarProxyStyle(ui_->slider);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
class QLabel;
|
||||
class QEvent;
|
||||
|
||||
class Application;
|
||||
#ifdef HAVE_MOODBAR
|
||||
class MoodbarProxyStyle;
|
||||
#endif
|
||||
@@ -44,7 +43,7 @@ class TrackSlider : public QWidget {
|
||||
explicit TrackSlider(QWidget *parent = nullptr);
|
||||
~TrackSlider() override;
|
||||
|
||||
void SetApplication(Application *app);
|
||||
void Init();
|
||||
|
||||
// QWidget
|
||||
QSize sizeHint() const override;
|
||||
@@ -53,7 +52,7 @@ class TrackSlider : public QWidget {
|
||||
bool event(QEvent*) override;
|
||||
|
||||
#ifdef HAVE_MOODBAR
|
||||
MoodbarProxyStyle *moodbar_style() const { return moodbar_style_; }
|
||||
MoodbarProxyStyle *moodbar_proxy_style() const { return moodbar_proxy_style_; }
|
||||
#endif
|
||||
|
||||
public Q_SLOTS:
|
||||
@@ -84,7 +83,7 @@ class TrackSlider : public QWidget {
|
||||
Ui_TrackSlider *ui_;
|
||||
|
||||
#ifdef HAVE_MOODBAR
|
||||
MoodbarProxyStyle *moodbar_style_;
|
||||
MoodbarProxyStyle *moodbar_proxy_style_;
|
||||
#endif
|
||||
|
||||
bool setting_value_;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <QPolygon>
|
||||
#include <QPaintEvent>
|
||||
|
||||
#include "core/qt_blurimage.h"
|
||||
#include "includes/qt_blurimage.h"
|
||||
#include "tracksliderpopup.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <QEnterEvent>
|
||||
|
||||
#include "utilities/timeutils.h"
|
||||
#include "utilities/timeconstants.h"
|
||||
#include "constants/timeconstants.h"
|
||||
#ifndef Q_OS_MACOS
|
||||
# include "tracksliderpopup.h"
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user