Fix insert-after current, and drag'n'drop of folders
- NEed to expand list of files before adding
This commit is contained in:
committed by
Craig Drummond
parent
2d97b3bdc0
commit
7a48379c61
@@ -164,7 +164,6 @@ QStringList FolderPage::selectedFiles(bool allowPlaylists) const
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
void FolderPage::addSelectionToPlaylist(const QString &name, int action, quint8 priorty)
|
||||
{
|
||||
QModelIndexList selected=view->selectedIndexes();
|
||||
@@ -173,7 +172,7 @@ void FolderPage::addSelectionToPlaylist(const QString &name, int action, quint8
|
||||
|
||||
foreach (const QModelIndex &idx, selected) {
|
||||
if (static_cast<BrowseModel::Item *>(idx.internalPointer())->isFolder()) {
|
||||
dirs.append(static_cast<BrowseModel::FolderItem *>(idx.internalPointer())->getPath());
|
||||
files+=static_cast<BrowseModel::FolderItem *>(idx.internalPointer())->allEntries();
|
||||
} else {
|
||||
files.append(static_cast<BrowseModel::TrackItem *>(idx.internalPointer())->getSong().file);
|
||||
}
|
||||
@@ -186,12 +185,6 @@ void FolderPage::addSelectionToPlaylist(const QString &name, int action, quint8
|
||||
emit addSongsToPlaylist(name, files);
|
||||
}
|
||||
view->clearSelection();
|
||||
} else if (!dirs.isEmpty()) {
|
||||
if (name.isEmpty()) {
|
||||
emit add(dirs, action, priorty);
|
||||
} else {
|
||||
emit addSongsToPlaylist(name, dirs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,23 @@ void BrowseModel::FolderItem::add(Item *i)
|
||||
children.append(i);
|
||||
}
|
||||
|
||||
QStringList BrowseModel::FolderItem::allEntries() const
|
||||
{
|
||||
QStringList entries;
|
||||
if (children.isEmpty()) {
|
||||
entries << MPDConnection::constDirPrefix+path;
|
||||
} else {
|
||||
foreach (Item *i, children) {
|
||||
if (i->isFolder()) {
|
||||
entries+=static_cast<FolderItem *>(i)->allEntries();
|
||||
} else {
|
||||
entries+=static_cast<TrackItem *>(i)->getSong().file;
|
||||
}
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
BrowseModel::BrowseModel(QObject *p)
|
||||
: ActionModel(p)
|
||||
, root(new FolderItem("/", 0))
|
||||
@@ -93,9 +110,6 @@ void BrowseModel::setEnabled(bool e)
|
||||
Qt::ItemFlags BrowseModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid()) {
|
||||
if (static_cast<Item *>(index.internalPointer())->isFolder()) {
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||
}
|
||||
return Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled;
|
||||
}
|
||||
return Qt::ItemIsDropEnabled;
|
||||
@@ -230,8 +244,12 @@ QMimeData * BrowseModel::mimeData(const QModelIndexList &indexes) const
|
||||
QStringList files;
|
||||
foreach (const QModelIndex &idx, indexes) {
|
||||
Item *item=toItem(idx);
|
||||
if (item && !item->isFolder()) {
|
||||
files.append(static_cast<TrackItem *>(item)->getSong().file);
|
||||
if (item) {
|
||||
if (item->isFolder()) {
|
||||
files+=static_cast<FolderItem *>(item)->allEntries();
|
||||
} else {
|
||||
files.append(static_cast<TrackItem *>(item)->getSong().file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ public:
|
||||
const QString & getPath() const { return path; }
|
||||
bool isFetching() const { return fetching; }
|
||||
void setFetching(bool f) { fetching=f; }
|
||||
QStringList allEntries() const;
|
||||
|
||||
private:
|
||||
QString name;
|
||||
|
||||
@@ -108,9 +108,10 @@ static QByteArray log(const QByteArray &data)
|
||||
|
||||
GLOBAL_STATIC(MPDConnection, instance)
|
||||
|
||||
QString MPDConnection::constModifiedSince=QLatin1String("modified-since");
|
||||
const QString MPDConnection::constModifiedSince=QLatin1String("modified-since");
|
||||
const int MPDConnection::constMaxPqChanges=1000;
|
||||
const QString MPDConnection::constStreamsPlayListName=QLatin1String("[Radio Streams]");
|
||||
const QString MPDConnection::constDirPrefix=QLatin1String("dir:");
|
||||
|
||||
QByteArray MPDConnection::quote(int val)
|
||||
{
|
||||
@@ -744,21 +745,30 @@ void MPDConnection::add(const QStringList &origList, quint32 pos, quint32 size,
|
||||
getStatus();
|
||||
}
|
||||
|
||||
QStringList files;
|
||||
foreach (const QString &file, origList) {
|
||||
if (file.startsWith(constDirPrefix)) {
|
||||
files+=getAllFiles(file.mid(constDirPrefix.length()));
|
||||
} else {
|
||||
files.append(file);
|
||||
}
|
||||
}
|
||||
|
||||
QList<QStringList> fileLists;
|
||||
if (priority.count()<=1 && origList.count()>maxFilesPerAddCommand) {
|
||||
int numChunks=(origList.count()/maxFilesPerAddCommand)+(origList.count()%maxFilesPerAddCommand ? 1 : 0);
|
||||
if (priority.count()<=1 && files.count()>maxFilesPerAddCommand) {
|
||||
int numChunks=(files.count()/maxFilesPerAddCommand)+(files.count()%maxFilesPerAddCommand ? 1 : 0);
|
||||
for (int i=0; i<numChunks; ++i) {
|
||||
fileLists.append(origList.mid(i*maxFilesPerAddCommand, maxFilesPerAddCommand));
|
||||
fileLists.append(files.mid(i*maxFilesPerAddCommand, maxFilesPerAddCommand));
|
||||
}
|
||||
} else {
|
||||
fileLists.append(origList);
|
||||
fileLists.append(files);
|
||||
}
|
||||
|
||||
int curSize = size;
|
||||
int curPos = pos;
|
||||
// bool addedFile=false;
|
||||
bool havePlaylist=false;
|
||||
bool usePrio=!priority.isEmpty() && canUsePriority() && (1==priority.count() || priority.count()==origList.count());
|
||||
bool usePrio=!priority.isEmpty() && canUsePriority() && (1==priority.count() || priority.count()==files.count());
|
||||
quint8 singlePrio=usePrio && 1==priority.count() ? priority.at(0) : 0;
|
||||
QStringList cStreamFiles;
|
||||
bool sentOk=false;
|
||||
@@ -811,7 +821,7 @@ void MPDConnection::add(const QStringList &origList, quint32 pos, quint32 size,
|
||||
emit cantataStreams(cStreamFiles);
|
||||
}
|
||||
|
||||
if ((ReplaceAndplay==action || AddAndPlay==action) /*&& addedFile */&& !origList.isEmpty()) {
|
||||
if ((ReplaceAndplay==action || AddAndPlay==action) /*&& addedFile */&& !files.isEmpty()) {
|
||||
// Dont emit error if play fails, might be that playlist was not loaded...
|
||||
playFirstTrack(false);
|
||||
}
|
||||
@@ -819,7 +829,7 @@ void MPDConnection::add(const QStringList &origList, quint32 pos, quint32 size,
|
||||
if (AppendAndPlay==action) {
|
||||
startPlayingSong(playPos);
|
||||
}
|
||||
emit added(origList);
|
||||
emit added(files);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1917,6 +1927,25 @@ bool MPDConnection::recursivelyListDir(const QString &dir)
|
||||
}
|
||||
}
|
||||
|
||||
QStringList MPDConnection::getAllFiles(const QString &dir)
|
||||
{
|
||||
QStringList files;
|
||||
Response response=sendCommand("lsinfo "+encodeName(dir));
|
||||
if (response.ok) {
|
||||
QStringList subDirs;
|
||||
QList<Song> songs;
|
||||
MPDParseUtils::parseDirItems(response.data, details.dir, ver, songs, dir, subDirs, MPDParseUtils::Loc_Browse);
|
||||
foreach (const Song &song, songs) {
|
||||
files.append(song.file);
|
||||
}
|
||||
foreach (const QString &sub, subDirs) {
|
||||
files+=getAllFiles(sub);
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
#ifndef CANTATA_WEB
|
||||
bool MPDConnection::checkRemoteDynamicSupport()
|
||||
{
|
||||
|
||||
@@ -187,9 +187,10 @@ public:
|
||||
DefaultFade = MinFade // disable volume fade by default. prev:2000
|
||||
};
|
||||
|
||||
static QString constModifiedSince;
|
||||
static const QString constModifiedSince;
|
||||
static const int constMaxPqChanges;
|
||||
static const QString constStreamsPlayListName;
|
||||
static const QString constDirPrefix;
|
||||
|
||||
static MPDConnection * self();
|
||||
static QByteArray quote(int val);
|
||||
@@ -401,6 +402,7 @@ private:
|
||||
bool doMoveInPlaylist(const QString &name, const QList<quint32> &items, quint32 pos, quint32 size);
|
||||
void toggleStopAfterCurrent(bool afterCurrent);
|
||||
bool recursivelyListDir(const QString &dir);
|
||||
QStringList getAllFiles(const QString &dir);
|
||||
#ifndef CANTATA_WEB
|
||||
bool checkRemoteDynamicSupport();
|
||||
bool subscribe(const QByteArray &channel);
|
||||
|
||||
Reference in New Issue
Block a user