Convert paths to native windows seperators in many places throughout the UI
This commit is contained in:
parent
d1173eb0eb
commit
8306ddc90b
|
@ -46,6 +46,7 @@
|
|||
# include "mtpdevice.h"
|
||||
#endif
|
||||
|
||||
#include <QDir>
|
||||
#include <QIcon>
|
||||
#include <QMessageBox>
|
||||
#include <QPainter>
|
||||
|
@ -308,10 +309,17 @@ QVariant DeviceManager::data(const QModelIndex& index, int role) const {
|
|||
return QVariant();
|
||||
return QVariant::fromValue<boost::shared_ptr<MusicStorage> >(info.device_);
|
||||
|
||||
case Role_MountPath:
|
||||
case Role_MountPath: {
|
||||
if (!info.device_)
|
||||
return QVariant();
|
||||
return info.device_->url().path();
|
||||
|
||||
QString ret = info.device_->url().path();
|
||||
# ifdef Q_OS_WIN32
|
||||
if (ret.startsWith('/'))
|
||||
ret.remove(0, 1);
|
||||
# endif
|
||||
return QDir::toNativeSeparators(ret);
|
||||
}
|
||||
|
||||
default:
|
||||
return QVariant();
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "libraryview.h"
|
||||
#include "librarywatcher.h"
|
||||
#include "ui_libraryconfig.h"
|
||||
#include "playlist/playlistdelegates.h"
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
@ -27,12 +28,14 @@
|
|||
|
||||
const char* LibraryConfig::kSettingsGroup = "LibraryConfig";
|
||||
|
||||
|
||||
LibraryConfig::LibraryConfig(QWidget* parent)
|
||||
: QWidget(parent),
|
||||
ui_(new Ui_LibraryConfig),
|
||||
model_(NULL)
|
||||
{
|
||||
ui_->setupUi(this);
|
||||
ui_->list->setItemDelegate(new NativeSeparatorsDelegate(this));
|
||||
|
||||
// Icons
|
||||
ui_->add->setIcon(IconLoader::Load("document-open-folder"));
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "widgets/trackslider.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QLineEdit>
|
||||
#include <QPainter>
|
||||
#include <QToolTip>
|
||||
|
@ -50,8 +51,9 @@ void QueuedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
|
|||
QStyledItemDelegate::paint(painter, option, index);
|
||||
|
||||
if (index.column() == indicator_column_) {
|
||||
const int queue_pos = index.data(Playlist::Role_QueuePosition).toInt();
|
||||
if (queue_pos != -1) {
|
||||
bool ok = false;
|
||||
const int queue_pos = index.data(Playlist::Role_QueuePosition).toInt(&ok);
|
||||
if (ok && queue_pos != -1) {
|
||||
float opacity = kQueueOpacitySteps - qMin(kQueueOpacitySteps, queue_pos);
|
||||
opacity /= kQueueOpacitySteps;
|
||||
opacity *= 1.0 - kQueueOpacityLowerBound;
|
||||
|
@ -70,7 +72,7 @@ void QueuedItemDelegate::DrawBox(
|
|||
QPainter* painter, const QRect& line_rect, const QFont& font,
|
||||
const QString& text, int width) const {
|
||||
QFont smaller = font;
|
||||
smaller.setPointSize(smaller.pointSize() - 2);
|
||||
smaller.setPointSize(smaller.pointSize() - 1);
|
||||
smaller.setBold(true);
|
||||
|
||||
if (width == -1)
|
||||
|
@ -113,9 +115,9 @@ int QueuedItemDelegate::queue_indicator_size(const QModelIndex& index) const {
|
|||
}
|
||||
|
||||
|
||||
PlaylistDelegateBase::PlaylistDelegateBase(QTreeView* view, const QString& suffix)
|
||||
: QueuedItemDelegate(view),
|
||||
view_(view),
|
||||
PlaylistDelegateBase::PlaylistDelegateBase(QObject* parent, const QString& suffix)
|
||||
: QueuedItemDelegate(parent),
|
||||
view_(qobject_cast<QTreeView*>(parent)),
|
||||
suffix_(suffix)
|
||||
{
|
||||
}
|
||||
|
@ -171,6 +173,9 @@ void PlaylistDelegateBase::paint(QPainter* painter, const QStyleOptionViewItem&
|
|||
}
|
||||
|
||||
QStyleOptionViewItemV4 PlaylistDelegateBase::Adjusted(const QStyleOptionViewItem& option, const QModelIndex& index) const {
|
||||
if (!view_)
|
||||
return option;
|
||||
|
||||
QPoint top_left(-view_->horizontalScrollBar()->value(),
|
||||
-view_->verticalScrollBar()->value());
|
||||
|
||||
|
@ -312,3 +317,10 @@ QWidget* TagCompletionItemDelegate::createEditor(
|
|||
|
||||
return editor;
|
||||
}
|
||||
|
||||
QString NativeSeparatorsDelegate::displayText(const QVariant& value, const QLocale&) const {
|
||||
QString str = value.toString();
|
||||
if (str.contains("://"))
|
||||
return str;
|
||||
return QDir::toNativeSeparators(str);
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ private:
|
|||
class PlaylistDelegateBase : public QueuedItemDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PlaylistDelegateBase(QTreeView* view, const QString& suffix = QString());
|
||||
PlaylistDelegateBase(QObject* parent, const QString& suffix = QString());
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
|
||||
QString displayText(const QVariant& value, const QLocale& locale) const;
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
@ -69,31 +69,31 @@ class PlaylistDelegateBase : public QueuedItemDelegate {
|
|||
|
||||
class LengthItemDelegate : public PlaylistDelegateBase {
|
||||
public:
|
||||
LengthItemDelegate(QTreeView* view) : PlaylistDelegateBase(view) {}
|
||||
LengthItemDelegate(QObject* parent) : PlaylistDelegateBase(parent) {}
|
||||
QString displayText(const QVariant& value, const QLocale& locale) const;
|
||||
};
|
||||
|
||||
class SizeItemDelegate : public PlaylistDelegateBase {
|
||||
public:
|
||||
SizeItemDelegate(QTreeView* view) : PlaylistDelegateBase(view) {}
|
||||
SizeItemDelegate(QObject* parent) : PlaylistDelegateBase(parent) {}
|
||||
QString displayText(const QVariant& value, const QLocale& locale) const;
|
||||
};
|
||||
|
||||
class DateItemDelegate : public PlaylistDelegateBase {
|
||||
public:
|
||||
DateItemDelegate(QTreeView* view) : PlaylistDelegateBase(view) {}
|
||||
DateItemDelegate(QObject* parent) : PlaylistDelegateBase(parent) {}
|
||||
QString displayText(const QVariant& value, const QLocale& locale) const;
|
||||
};
|
||||
|
||||
class FileTypeItemDelegate : public PlaylistDelegateBase {
|
||||
public:
|
||||
FileTypeItemDelegate(QTreeView* view) : PlaylistDelegateBase(view) {}
|
||||
FileTypeItemDelegate(QObject* parent) : PlaylistDelegateBase(parent) {}
|
||||
QString displayText(const QVariant& value, const QLocale& locale) const;
|
||||
};
|
||||
|
||||
class TextItemDelegate : public PlaylistDelegateBase {
|
||||
public:
|
||||
TextItemDelegate(QTreeView* view) : PlaylistDelegateBase(view) {};
|
||||
TextItemDelegate(QObject* parent) : PlaylistDelegateBase(parent) {}
|
||||
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
};
|
||||
|
@ -110,8 +110,8 @@ class TagCompleter : public QCompleter {
|
|||
|
||||
class TagCompletionItemDelegate : public PlaylistDelegateBase {
|
||||
public:
|
||||
TagCompletionItemDelegate(QTreeView* view,LibraryBackend* backend, Playlist::Column column) :
|
||||
PlaylistDelegateBase(view), backend_(backend), column_(column) {};
|
||||
TagCompletionItemDelegate(QObject* parent, LibraryBackend* backend, Playlist::Column column) :
|
||||
PlaylistDelegateBase(parent), backend_(backend), column_(column) {};
|
||||
|
||||
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const;
|
||||
|
@ -121,4 +121,10 @@ class TagCompletionItemDelegate : public PlaylistDelegateBase {
|
|||
Playlist::Column column_;
|
||||
};
|
||||
|
||||
class NativeSeparatorsDelegate : public PlaylistDelegateBase {
|
||||
public:
|
||||
NativeSeparatorsDelegate(QObject* parent) : PlaylistDelegateBase(parent) {}
|
||||
QString displayText(const QVariant& value, const QLocale& locale) const;
|
||||
};
|
||||
|
||||
#endif // PLAYLISTDELEGATES_H
|
||||
|
|
|
@ -93,6 +93,7 @@ void PlaylistView::SetItemDelegates(LibraryBackend* backend) {
|
|||
setItemDelegateForColumn(Playlist::Column_BPM, new PlaylistDelegateBase(this, tr("bpm")));
|
||||
setItemDelegateForColumn(Playlist::Column_Samplerate, new PlaylistDelegateBase(this, ("Hz")));
|
||||
setItemDelegateForColumn(Playlist::Column_Bitrate, new PlaylistDelegateBase(this, tr("kbps")));
|
||||
setItemDelegateForColumn(Playlist::Column_Filename, new NativeSeparatorsDelegate(this));
|
||||
}
|
||||
|
||||
void PlaylistView::SetPlaylist(Playlist *playlist) {
|
||||
|
|
|
@ -96,7 +96,9 @@ void FileView::FileHome() {
|
|||
ChangeFilePath(QDir::homePath());
|
||||
}
|
||||
|
||||
void FileView::ChangeFilePath(const QString& new_path) {
|
||||
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;
|
||||
|
@ -110,7 +112,7 @@ void FileView::ChangeFilePath(const QString& new_path) {
|
|||
|
||||
void FileView::ChangeFilePathWithoutUndo(const QString& new_path) {
|
||||
ui_->list->setRootIndex(model_->setRootPath(new_path));
|
||||
ui_->path->setText(new_path);
|
||||
ui_->path->setText(QDir::toNativeSeparators(new_path));
|
||||
|
||||
QDir dir(new_path);
|
||||
ui_->up->setEnabled(dir.cdUp());
|
||||
|
|
Loading…
Reference in New Issue