Commit 902772c3 authored by Camilo higuita's avatar Camilo higuita

add actions to multiple selections

parent 53c0005a
......@@ -35,9 +35,9 @@
class InterfaceConnFailedException : public QException
{
public:
void raise() const { throw *this; }
InterfaceConnFailedException *clone() const { return new InterfaceConnFailedException(*this); }
public:
void raise() const { throw *this; }
InterfaceConnFailedException *clone() const { return new InterfaceConnFailedException(*this); }
};
#elif defined(Q_OS_WINDOWS)
#elif defined(Q_OS_DARWIN)
......@@ -64,9 +64,9 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
{
switch(table)
{
case BAE::TABLE::TRACKS: emit this->refreshTracks(); break;
case BAE::TABLE::ALBUMS: emit this->refreshAlbums(); break;
case BAE::TABLE::ARTISTS: emit this->refreshArtists(); break;
case BAE::TABLE::TRACKS: emit this->refreshTracks(); break;
case BAE::TABLE::ALBUMS: emit this->refreshAlbums(); break;
case BAE::TABLE::ARTISTS: emit this->refreshArtists(); break;
}
});
......@@ -100,7 +100,7 @@ Babe::Babe(QObject *parent) : CollectionDB(parent)
connect(android, &Android::folderPicked, [this](const QString &url)
{
qDebug()<< "Folder picked"<< url;
qDebug()<< "Folder picked"<< url;
});
#endif
......@@ -259,46 +259,46 @@ void Babe::linkDecoder(QString json)
switch(static_cast<LINK::CODE>(code))
{
case LINK::CODE::CONNECTED :
{
this->link.deviceName = msg;
emit this->link.serverConReady(msg);
break;
}
case LINK::CODE::QUERY :
case LINK::CODE::FILTER :
case LINK::CODE::PLAYLISTS :
{
auto res = this->getDBDataQML(msg);
link.sendToClient(link.packResponse(static_cast<LINK::CODE>(code), res));
break;
}
case LINK::CODE::SEARCHFOR :
{
auto res = this->searchFor(msg.split(","));
link.sendToClient(link.packResponse(static_cast<LINK::CODE>(code), res));
break;
}
case LINK::CODE::PLAY :
{
QFile file(msg); // sound dir
file.open(QIODevice::ReadOnly);
QByteArray arr = file.readAll();
qDebug()<<"Preparing track array"<<msg<<arr.size();
link.sendArrayToClient(arr);
break;
}
case LINK::CODE::COLLECT :
{
// auto devices = getDevices();
// qDebug()<<"DEVICES:"<< devices;
// if(!devices.isEmpty())
// sendToDevice(devices.first().toMap().value("name").toString(),
// devices.first().toMap().value("id").toString(), msg);
break;
case LINK::CODE::CONNECTED :
{
this->link.deviceName = msg;
emit this->link.serverConReady(msg);
break;
}
case LINK::CODE::QUERY :
case LINK::CODE::FILTER :
case LINK::CODE::PLAYLISTS :
{
auto res = this->getDBDataQML(msg);
link.sendToClient(link.packResponse(static_cast<LINK::CODE>(code), res));
break;
}
case LINK::CODE::SEARCHFOR :
{
auto res = this->searchFor(msg.split(","));
link.sendToClient(link.packResponse(static_cast<LINK::CODE>(code), res));
break;
}
case LINK::CODE::PLAY :
{
QFile file(msg); // sound dir
file.open(QIODevice::ReadOnly);
QByteArray arr = file.readAll();
qDebug()<<"Preparing track array"<<msg<<arr.size();
link.sendArrayToClient(arr);
break;
}
case LINK::CODE::COLLECT :
{
// auto devices = getDevices();
// qDebug()<<"DEVICES:"<< devices;
// if(!devices.isEmpty())
// sendToDevice(devices.first().toMap().value("name").toString(),
// devices.first().toMap().value("id").toString(), msg);
break;
}
default: break;
}
default: break;
}
}
......@@ -502,10 +502,10 @@ bool Babe::fileExists(const QString &url)
return BAE::fileExists(url);
}
void Babe::showFolder(const QString &url)
void Babe::showFolder(const QStringList &urls)
{
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(url).dir().absolutePath()));
for(auto url : urls)
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(url).dir().absolutePath()));
}
QString Babe::babeColor()
......@@ -527,7 +527,7 @@ void Babe::androidStatusBarColor(const QString &color, const bool &contrast)
if(contrast)
{
QAndroidJniObject decorView = window.callObjectMethod("getDecorView", "()Landroid/view/View;");
decorView.callMethod<void>("setSystemUiVisibility", "(I)V", 0x00002000);
decorView.callMethod<void>("setSystemUiVisibility", "(I)V", 0x00002000);
}
});
......
......@@ -74,7 +74,7 @@ public:
Q_INVOKABLE static int lastPlaylistPos();
Q_INVOKABLE static bool fileExists(const QString &url);
Q_INVOKABLE static void showFolder(const QString &url);
Q_INVOKABLE static void showFolder(const QStringList &urls);
/*COLORS*/
Q_INVOKABLE static QString babeColor();
......
......@@ -528,8 +528,8 @@ DB_LIST CollectionDB::getDBData(const QStringList &urls)
for(auto url : urls)
{
auto queryTxt = QString("SELECT * FROM %1 WHERE %2 = \"%3\"").arg(TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::URL],url);
auto queryTxt = QString("SELECT * FROM %1 t INNER JOIN albums a on a.album = t.album and a.artist = t.artist WHERE t.%2 = \"%3\"").arg(TABLEMAP[TABLE::TRACKS],
KEYMAP[KEY::URL], url);
mapList << this->getDBData(queryTxt);
}
......
......@@ -17,6 +17,7 @@ import "widgets/SearchView"
import "view_models"
import "view_models/BabeDialog"
import "view_models/BabeTable"
import "services/local"
import "services/web"
......@@ -310,9 +311,9 @@ Maui.ApplicationWindow
iconColor: currentBabe ? babeColor : darkTextColor
onClicked: if (!mainlistEmpty)
{
var value = mainPlaylist.contextMenu.babeIt(
currentTrackIndex)
var value = H.faveIt([mainPlaylist.list.model.get(currentTrackIndex).url])
currentBabe = value
mainPlaylist.list.model.get(currentTrackIndex).babe = value ? "1" : "0"
}
},
......@@ -836,6 +837,11 @@ Maui.ApplicationWindow
}
}
PlaylistDialog
{
id: playlistDialog
}
MainPlaylist
{
id: mainPlaylist
......@@ -1069,14 +1075,40 @@ Maui.ApplicationWindow
id: spotifyView
}
}
Maui.SelectionBar
{
id: selectionBar
Layout.fillWidth: true
Layout.margins: space.huge
Layout.topMargin: space.small
// onIconClicked: itemMenu.showMultiple(selectedPaths)
onIconClicked: contextMenu.show(selectedPaths)
onExitClicked: clear()
TableMenu
{
id: contextMenu
onFavClicked: H.faveIt(paths)
onQueueClicked: H.queueIt(paths)
onSaveToClicked:
{
playlistDialog.tracks = paths
playlistDialog.open()
}
onOpenWithClicked: bae.showFolder(paths)
onRemoveClicked:
{
}
onRateClicked: H.rateIt(paths, rate)
onColorClicked: H.moodIt(paths, color)
}
}
}
}
......
.import "../db/Queries.js" as Q
.import "../utils/Player.js" as Player
function rootWidth()
{
......@@ -109,3 +109,53 @@ function addToSelection(item)
})
}
function queueIt(paths)
{
var data = bae.getList(paths)
Player.queueTracks(data)
}
function rateIt(paths, rate)
{
for(var i in paths)
{
var url = paths[i]
if(bae.rateTrack(url, rate))
if(paths.length === 1)
return rate
}
}
function moodIt(paths, color)
{
if(paths.length > 0)
for(var i in paths)
bae.colorTagTrack(paths[i], color)
}
function isFav(url)
{
var data = bae.get(Q.GET.tracksWhere_.arg("t.url = %1").arg(url))
if(data.lenght > 0)
return data[0].babe === 1 ? true : false
}
function faveIt(paths)
{
if(paths.length > 0)
{
for(var i in paths)
{
var url = paths[i]
var value = bae.trackBabe(url) ? false : true
if(bae.babeTrack(url, value))
if(paths.length === 1)
return value
}
}
}
......@@ -72,11 +72,6 @@ BabeList
}
]
PlaylistDialog
{
id: playlistDialog
}
HeaderMenu
{
id: headerMenu
......@@ -95,6 +90,51 @@ BabeList
TableMenu
{
id: contextMenu
menuItem: MenuItem
{
text: qsTr("Select...")
onTriggered:
{
H.addToSelection(list.model.get(list.currentIndex))
contextMenu.close()
}
}
onFavClicked:
{
var value = H.faveIt(paths)
model.get(list.currentIndex).babe = value ? "1" : "0"
}
onQueueClicked: H.queueIt(paths)
onSaveToClicked:
{
playlistDialog.tracks = paths
playlistDialog.open()
}
onOpenWithClicked: bae.showFolder(paths)
onRemoveClicked:
{
listModel.remove(list.currentIndex)
}
onRateClicked:
{
var value = H.rateIt(paths, rate)
list.currentItem.rate(H.setStars(value))
ist.model.get(list.currentIndex).stars = value
}
onColorClicked:
{
H.moodIt(paths, color)
list.currentItem.trackMood = color
list.model.get(list.currentIndex).art = color
}
}
list.highlightFollowsCurrentItem: false
......@@ -159,9 +199,8 @@ BabeList
currentIndex = index
contextMenu.rate = bae.getTrackStars(model.get(currentIndex).url)
contextMenu.babe = bae.trackBabe(model.get(currentIndex).url)
if(root.isMobile) contextMenu.open()
else
contextMenu.popup()
contextMenu.show([model.get(currentIndex).url])
rowPressed(index)
}
......
......@@ -5,13 +5,13 @@ import QtQuick.Layouts 1.3
import "../../view_models/BabeMenu"
import "../../utils"
import ".."
import "../../utils/Player.js" as Player
import "../../utils/Help.js" as H
import org.kde.maui 1.0 as Maui
BabeMenu
{
id: control
property var paths : []
property int rate : 0
property bool babe : false
......@@ -19,74 +19,25 @@ BabeMenu
property string starReg : textColor
property string starIcon: "draw-star"
signal trackRemoved(string url)
signal removeClicked(var paths)
signal favClicked(var paths)
signal queueClicked(var paths)
signal saveToClicked(var paths)
signal openWithClicked(var paths)
signal editClicked(var paths)
signal shareClicked(var paths)
signal selectClicked(var paths)
signal rateClicked(var paths, int rate)
signal colorClicked(var paths, string color)
property alias menuItem : customItems.children
function queueIt(index)
{
Player.queueTracks([list.model.get(index)])
}
function rateIt(rank)
{
rate = rank
if(bae.rateTrack(list.model.get(list.currentIndex).url, rate))
{
babeTableRoot.list.currentItem.rate(H.setStars(rate))
babeTableRoot.ist.model.get(list.currentIndex).stars = rate
}
close()
}
function moodIt(color)
{
if(bae.colorTagTrack(list.model.get(list.currentIndex).url, color))
{
list.currentItem.trackMood = color
list.model.get(list.currentIndex).art = color
}
close()
}
function babeIt(index)
{
if(list.count>0)
{
console.log(index);
var url = listModel.get(index).url
var value = listModel.get(index).babe == "1" ? false : true
if(bae.babeTrack(url, value))
list.model.get(index).babe = value ? "1" : "0"
return value
}
}
Label
{
id: titleLabel
visible: isAndroid
padding: isAndroid ? space.small : 0
font.bold: true
width: parent.width
height: isAndroid ? iconSizes.medium : 0
horizontalAlignment: Qt.AlignHCenter
elide: Text.ElideRight
text: list.currentIndex >= 0 ? list.model.get(list.currentIndex).title : ""
color: textColor
}
MenuItem
{
text: babe == false ? "Babe it" : "UnBabe it"
text: babe == false ? qsTr("Fav it"): qsTr("UnFav it")
onTriggered:
{
babeIt(list.currentIndex)
favClicked(paths)
close()
}
}
......@@ -96,7 +47,7 @@ BabeMenu
text: qsTr("Queue")
onTriggered:
{
queueIt(list.currentIndex)
queueClicked(paths)
close()
}
}
......@@ -106,8 +57,7 @@ BabeMenu
text: qsTr("Save to...")
onTriggered:
{
playlistDialog.tracks = [list.model.get(list.currentIndex).url]
playlistDialog.open()
saveToClicked(paths)
close()
}
}
......@@ -118,9 +68,7 @@ BabeMenu
onTriggered:
{
!isAndroid ?
bae.showFolder(list.model.get(list.currentIndex).url) :
bae.openFile(list.model.get(list.currentIndex).url)
openWithClicked(paths)
close()
}
}
......@@ -128,40 +76,36 @@ BabeMenu
MenuItem
{
text: qsTr("Edit...")
onTriggered: {close()}
}
MenuItem
{
text: qsTr("Share...")
onTriggered:
{
isAndroid ? Maui.Android.shareDialog([list.model.get(list.currentIndex).url]) :
shareDialog.show([list.model.get(list.currentIndex).url])
editClicked(paths)
close()
}
}
MenuItem
{
text: qsTr("Remove")
text: qsTr("Share...")
onTriggered:
{
trackRemoved(list.model.get(list.currentIndex).url)
listModel.remove(list.currentIndex)
shareClicked(paths)
isAndroid ? Maui.Android.shareDialog(paths) :
shareDialog.show(paths)
close()
}
}
MenuItem
{
text: qsTr("Select...")
text: qsTr("Remove")
onTriggered:
{
H.addToSelection(list.model.get(list.currentIndex))
removeClicked(paths)
// listModel.remove(list.currentIndex)
close()
}
}
Column
{
id: customItems
......@@ -184,7 +128,12 @@ BabeMenu
iconName: starIcon
size: iconSizes.small
iconColor: rate >= 1 ? starColor :starReg
onClicked: rateIt(1)
onClicked:
{
rate = 1
rateClicked(paths, rate)
close()
}
}
Maui.ToolButton
......@@ -194,7 +143,12 @@ BabeMenu
size: iconSizes.small
iconName: starIcon
iconColor: rate >= 2 ? starColor :starReg
onClicked: rateIt(2)
onClicked:
{
rate = 2
rateClicked(paths, rate)
close()
}
}
Maui.ToolButton
......@@ -204,8 +158,12 @@ BabeMenu
size: iconSizes.small
iconName: starIcon
iconColor: rate >= 3 ? starColor :starReg
onClicked: rateIt(3)
onClicked:
{
rate = 3
rateClicked(paths, rate)
close()
}
}
Maui.ToolButton
......@@ -215,8 +173,12 @@ BabeMenu
size: iconSizes.small
iconName: starIcon
iconColor: rate >= 4 ? starColor :starReg
onClicked: rateIt(4)
onClicked:
{
rate = 4
rateClicked(paths, rate)
close()
}
}
Maui.ToolButton
......@@ -226,8 +188,12 @@ BabeMenu
size: iconSizes.small
iconName: starIcon
iconColor: rate >= 5 ? starColor :starReg
onClicked: rateIt(5)
onClicked:
{
rate = 5
rateClicked(paths, rate)
close()
}
}
}
......@@ -242,7 +208,16 @@ BabeMenu
ColorTagsBar
{
anchors.fill: parent
onColorClicked: moodIt(color)
onColorClicked: control.colorClicked(paths, color)
}
}
function show(urls)
{
paths = urls
if(root.isMobile)
contextMenu.open()
else
contextMenu.popup()
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment