mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 11:35:24 +01:00
In the organise dialog, prompt before connecting a device that hasn't been connected before
This commit is contained in:
parent
c0ea45a9c9
commit
39132c4dcd
@ -30,6 +30,7 @@ public:
|
||||
|
||||
enum Role {
|
||||
Role_Storage = Qt::UserRole + 100,
|
||||
Role_StorageForceConnect,
|
||||
Role_Capacity,
|
||||
Role_FreeSpace,
|
||||
};
|
||||
|
@ -40,7 +40,9 @@
|
||||
#endif
|
||||
|
||||
#include <QIcon>
|
||||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
#include <QPushButton>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QUrl>
|
||||
|
||||
@ -247,12 +249,33 @@ QVariant DeviceManager::data(const QModelIndex& index, int role) const {
|
||||
return info.task_percentage_;
|
||||
|
||||
case MusicStorage::Role_Storage:
|
||||
if (!info.device_)
|
||||
if (!info.device_ && info.database_id_ != -1)
|
||||
const_cast<DeviceManager*>(this)->Connect(index.row());
|
||||
if (!info.device_)
|
||||
return QVariant();
|
||||
return QVariant::fromValue<boost::shared_ptr<MusicStorage> >(info.device_);
|
||||
|
||||
case MusicStorage::Role_StorageForceConnect:
|
||||
if (!info.device_) {
|
||||
if (info.database_id_ == -1) {
|
||||
boost::scoped_ptr<QMessageBox> dialog(new QMessageBox(
|
||||
QMessageBox::Information, tr("Connect device"),
|
||||
tr("This is the first time you have connected this device. Clementine will now scan the device to find music files - this may take some time."),
|
||||
QMessageBox::Cancel));
|
||||
QPushButton* connect =
|
||||
dialog->addButton(tr("Connect device"), QMessageBox::AcceptRole);
|
||||
dialog->exec();
|
||||
|
||||
if (dialog->clickedButton() != connect)
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
const_cast<DeviceManager*>(this)->Connect(index.row());
|
||||
}
|
||||
if (!info.device_)
|
||||
return QVariant();
|
||||
return QVariant::fromValue<boost::shared_ptr<MusicStorage> >(info.device_);
|
||||
|
||||
case Role_MountPath:
|
||||
if (!info.device_)
|
||||
return QVariant();
|
||||
|
@ -21,8 +21,6 @@ DeviceStateFilterModel::DeviceStateFilterModel(QObject *parent,
|
||||
: QSortFilterProxyModel(parent),
|
||||
state_(state)
|
||||
{
|
||||
setDynamicSortFilter(true);
|
||||
|
||||
connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(ProxyRowCountChanged()));
|
||||
connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(ProxyRowCountChanged()));
|
||||
connect(this, SIGNAL(modelReset()), SLOT(ProxyRowCountChanged()));
|
||||
@ -36,3 +34,10 @@ bool DeviceStateFilterModel::filterAcceptsRow(int row, const QModelIndex&) const
|
||||
void DeviceStateFilterModel::ProxyRowCountChanged() {
|
||||
emit IsEmptyChanged(rowCount() == 0);
|
||||
}
|
||||
|
||||
void DeviceStateFilterModel::setSourceModel(QAbstractItemModel* sourceModel) {
|
||||
QSortFilterProxyModel::setSourceModel(sourceModel);
|
||||
setDynamicSortFilter(true);
|
||||
setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
sort(0);
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
DeviceStateFilterModel(QObject* parent,
|
||||
DeviceManager::State state = DeviceManager::State_Remembered);
|
||||
|
||||
void setSourceModel(QAbstractItemModel* sourceModel);
|
||||
|
||||
signals:
|
||||
void IsEmptyChanged(bool is_empty);
|
||||
|
||||
|
@ -159,6 +159,7 @@ void DeviceView::SetDeviceManager(DeviceManager *manager) {
|
||||
sort_model_ = new QSortFilterProxyModel(this);
|
||||
sort_model_->setSourceModel(manager_);
|
||||
sort_model_->setDynamicSortFilter(true);
|
||||
sort_model_->setSortCaseSensitivity(Qt::CaseInsensitive);
|
||||
sort_model_->sort(0);
|
||||
|
||||
merged_model_ = new MergedProxyModel(this);
|
||||
@ -228,22 +229,7 @@ QModelIndex DeviceView::MapToLibrary(const QModelIndex& merged_model_index) cons
|
||||
|
||||
void DeviceView::Connect() {
|
||||
QModelIndex device_idx = MapToDevice(menu_index_);
|
||||
bool first_time = manager_->GetDatabaseId(device_idx.row()) == -1;
|
||||
|
||||
if (first_time) {
|
||||
boost::scoped_ptr<QMessageBox> dialog(new QMessageBox(
|
||||
QMessageBox::Information, tr("Connect device"),
|
||||
tr("This is the first time you have connected this device. Clementine will now scan the device to find music files - this may take some time."),
|
||||
QMessageBox::Cancel, this));
|
||||
QPushButton* connect =
|
||||
dialog->addButton(tr("Connect device"), QMessageBox::AcceptRole);
|
||||
dialog->exec();
|
||||
|
||||
if (dialog->clickedButton() != connect)
|
||||
return;
|
||||
}
|
||||
|
||||
manager_->Connect(device_idx.row());
|
||||
manager_->data(device_idx, MusicStorage::Role_StorageForceConnect);
|
||||
}
|
||||
|
||||
void DeviceView::DeviceConnected(int row) {
|
||||
|
@ -210,7 +210,7 @@ void OrganiseDialog::UpdatePreviews() {
|
||||
const bool format_valid = format_.IsValid();
|
||||
|
||||
// Are we gonna enable the ok button?
|
||||
bool ok = format_valid && storage && !filenames_.isEmpty();
|
||||
bool ok = format_valid && !filenames_.isEmpty();
|
||||
if (capacity != 0 && total_size_ > free)
|
||||
ok = false;
|
||||
|
||||
@ -277,9 +277,12 @@ void OrganiseDialog::accept() {
|
||||
const QModelIndex destination = ui_->destination->model()->index(
|
||||
ui_->destination->currentIndex(), 0);
|
||||
boost::shared_ptr<MusicStorage> storage =
|
||||
destination.data(MusicStorage::Role_Storage)
|
||||
destination.data(MusicStorage::Role_StorageForceConnect)
|
||||
.value<boost::shared_ptr<MusicStorage> >();
|
||||
|
||||
if (!storage)
|
||||
return;
|
||||
|
||||
// It deletes itself when it's finished.
|
||||
const bool copy = ui_->aftercopying->currentIndex() == 0;
|
||||
Organise* organise = new Organise(
|
||||
|
Loading…
x
Reference in New Issue
Block a user