Commit 5335d4a3 authored by Camilo Higuita's avatar Camilo Higuita

work on android folder scanning and a few ui scaling fixes

parent 705c6fbc
......@@ -6,6 +6,7 @@ QT += websockets
QT += network
QT += xml
android: QT += androidextras
unix:linux:!android:
{
include(kde/kde.pri)
......
......@@ -11,6 +11,11 @@
#include <QDesktopWidget>
#include <QDirIterator>
#include <QtQml>
#ifdef Q_OS_ANDROID
#include <QAndroidJniObject>
#endif
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include "kde/notify.h"
#endif
......@@ -65,6 +70,7 @@ void Babe::trackLyrics(const QString &url)
KEYMAP[KEY::URL], url));
if(track.isEmpty()) return;
this->fetchTrackLyrics(track.first());
}
......@@ -433,10 +439,37 @@ QString Babe::moodColor(const int &pos)
}
QString Babe::homeDir()
{
#ifdef Q_OS_ANDROID
QAndroidJniObject mediaDir = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
QAndroidJniObject mediaPath = mediaDir.callObjectMethod( "getAbsolutePath", "()Ljava/lang/String;" );
return mediaPath.toString();
// QAndroidJniObject mediaDir = QAndroidJniObject::callStaticObjectMethod("android.content.Context", "getExternalFilesDir", "()Ljava/io/File;");
// QAndroidJniObject mediaPath = mediaDir.callObjectMethod( "getAbsolutePath", "()Ljava/lang/String;" );
// return mediaPath.toString();
#else
return BAE::HomePath;
#endif
}
QString Babe::musicDir()
{
return BAE::MusicPath;
}
QString Babe::sdDir()
{
#ifdef Q_OS_ANDROID
QAndroidJniObject mediaDir = QAndroidJniObject::callStaticObjectMethod("android/os/Environment", "getExternalStorageDirectory", "()Ljava/io/File;");
QAndroidJniObject mediaPath = mediaDir.callObjectMethod( "getAbsolutePath", "()Ljava/lang/String;" );
return mediaPath.toString();
#else
return homeDir();
#endif
}
QVariantList Babe::getDirs(const QString &pathUrl)
{
auto path = pathUrl;
......@@ -492,9 +525,9 @@ uint Babe::sizeHint(const uint &hint)
QString Babe::icon(const QString &icon, const int &size)
{
auto pix = QIcon::fromTheme(icon).pixmap(QSize(size, size), QIcon::Mode::Normal, QIcon::State::On);
auto pix = QIcon::fromTheme(icon).pixmap(QSize(size, size), QIcon::Mode::Normal, QIcon::State::On);
return "";
return "";
}
QString Babe::loadCover(const QString &url)
......
......@@ -90,6 +90,8 @@ public:
Q_INVOKABLE static QString moodColor(const int &pos);
Q_INVOKABLE static QString homeDir();
Q_INVOKABLE static QString musicDir();
Q_INVOKABLE static QString sdDir();
Q_INVOKABLE static QVariantList getDirs(const QString &pathUrl);
Q_INVOKABLE static QVariantMap getParentDir(const QString &path);
......
......@@ -33,14 +33,14 @@ Kirigami.ApplicationWindow
// property int columnWidth: Kirigami.Units.gridUnit * 13
readonly property bool isMobile: bae.isMobile()
readonly property int maxW : root.maximumWidth
readonly property int maxH : root.maximumHeight
readonly property int wideSize : bae.screenGeometry("width")*0.45
property int columnWidth: Kirigami.Units.gridUnit * 20
property int coverSize: columnWidth*0.65
property int coverSize: isMobile ? Math.sqrt(root.width*root.height)*0.4 : columnWidth * 0.65
// property int columnWidth: Math.sqrt(root.width*root.height)*0.4
property int currentView : 0
property int toolBarIconSize: isMobile ? 24 : 22
readonly property int toolBarIconSize: isMobile ? 24 : 22
property alias mainPlaylist : mainPlaylist
// minimumWidth: columnWidth
......@@ -140,7 +140,8 @@ Kirigami.ApplicationWindow
{
if(!isMobile && pageStack.wideMode)
root.width = columnWidth
else root.width = wideSize
else if(!isMobile && !pageStack.wideMode)
root.width = wideSize
pageStack.currentIndex = 0
......
......@@ -66,9 +66,10 @@ BabeSettings::BabeSettings(QObject *parent) : QObject(parent)
// if(!connection->check_existance(TABLEMAP[TABLE::SOURCES], KEYMAP[KEY::URL], BAE::MusicPath))
if(BAE::isMobile())
this->populateDB({BAE::MusicPath, BAE::DownloadsPath});
this->populateDB(QStringList()<<BAE::MusicPath<<BAE::DownloadsPath<<BAE::MusicPaths<<BAE::DownloadsPaths);
else
checkCollectionBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool());
this->populateDB({BAE::MusicPath});
// checkCollectionBrainz(BAE::loadSettings("BRAINZ", "BABE", false).toBool());
connect(this->brainDeamon, &Brain::finished, [this]()
{
......@@ -212,6 +213,7 @@ void BabeSettings::checkCollectionBrainz(const bool &state)
void BabeSettings::startBrainz(const bool &on, const uint &speed)
{
this->brainDeamon->setInterval(speed);
if(on)
this->brainDeamon->start();
else
......@@ -224,6 +226,7 @@ void BabeSettings::populateDB(const QStringList &paths)
qDebug() << "Function Name: " << Q_FUNC_INFO
<< "new path for database action: " << paths;
auto newPaths = paths;
for(auto path : newPaths)
if(path.startsWith("file://"))
path.replace("file://", "");
......
......@@ -1722,5 +1722,9 @@ var Babe = {
"player-time" : Icon.playBoxOutline,
"media-repeat-track-amarok": Icon.playlistPlay,
"archive-insert": Icon.playlistPlus,
"amarok_clock" : Icon.playlistPlay
"amarok_clock" : Icon.playlistPlay,
/*others*/
"gohome" : Icon.home
}
......@@ -6,15 +6,21 @@ function playTrack(track)
root.mainPlaylist.currentTrack = track
player.source(root.mainPlaylist.currentTrack.url);
player.play()
root.title = root.mainPlaylist.currentTrack.title + " - " +root.mainPlaylist.currentTrack.artist
root.mainPlaylist.playIcon.iconName = "media-playback-pause"
var artwork = root.mainPlaylist.currentTrack.artwork
// root.mainPlaylist.list.currentItem.playingIndicator = true
root.mainPlaylist.currentArtwork = artwork ? artwork : bae.loadCover(root.mainPlaylist.currentTrack.url)
root.mainPlaylist.currentArtwork = artwork && artwork.length>0 && artwork !== "NONE" ? artwork : bae.loadCover(root.mainPlaylist.currentTrack.url)
if(!root.isMobile)
{
root.title = root.mainPlaylist.currentTrack.title + " - " +root.mainPlaylist.currentTrack.artist
if(!root.active)
bae.notifySong(root.mainPlaylist.currentTrack.url)
if(!root.active)
bae.notifySong(root.mainPlaylist.currentTrack.url)
}
root.mainPlaylist.playIcon.iconName = "media-playback-pause"
if(bae.trackBabe(root.mainPlaylist.currentTrack.url))
root.mainPlaylist.babeBtnIcon.iconColor = bae.babeColor()
......@@ -28,9 +34,9 @@ function playTrack(track)
else
root.mainPlaylist.infoView.lyrics = lyrics
root.mainPlaylist.infoView.wikiAlbum = bae.albumWiki(root.mainPlaylist.currentTrack.album,root.mainPlaylist.currentTrack.artist)
root.mainPlaylist.infoView.wikiArtist = bae.artistWiki(root.mainPlaylist.currentTrack.artist)
// root.mainPlaylist.infoView.artistHead = bae.artistArt(root.mainPlaylist.currentTrack.artist)
// root.mainPlaylist.infoView.wikiAlbum = bae.albumWiki(root.mainPlaylist.currentTrack.album,root.mainPlaylist.currentTrack.artist)
// root.mainPlaylist.infoView.wikiArtist = bae.artistWiki(root.mainPlaylist.currentTrack.artist)
// // root.mainPlaylist.infoView.artistHead = bae.artistArt(root.mainPlaylist.currentTrack.artist)
}
......@@ -76,7 +82,7 @@ function previousTrack()
}
function shuffle()
{
{
var pos = Math.floor(Math.random() * root.mainPlaylist.list.count)
return pos
}
......@@ -115,29 +121,39 @@ function appendTracksAt(tracks, at)
function appendTrack(track)
{
if(track)
{
var empty = root.mainPlaylist.list.count
if((empty > 0 && track.url !== root.mainPlaylist.list.model.get(root.mainPlaylist.list.count-1).url) || empty === 0)
{
root.mainPlaylist.list.model.append(track)
root.mainPlaylist.list.model.append(track)
if(empty === 0 && root.mainPlaylist.list.count>0)
playAt(0)
}
}
// if(track)
// {
// var empty = root.mainPlaylist.list.count
// if((empty > 0 && track.url !== root.mainPlaylist.list.model.get(root.mainPlaylist.list.count-1).url) || empty === 0)
// {
// root.mainPlaylist.list.model.append(track)
// if(empty === 0 && root.mainPlaylist.list.count>0)
// playAt(0)
// }
// }
}
function addTrack(track)
{
appendTrack(track)
root.mainPlaylist.list.positionViewAtEnd()
if(track)
{
appendTrack(track)
root.mainPlaylist.list.positionViewAtEnd()
}
}
function appendAll(tracks)
{
for(var i in tracks)
appendTrack(tracks[i])
root.mainPlaylist.list.positionViewAtEnd()
if(tracks)
{
for(var i in tracks)
appendTrack(tracks[i])
root.mainPlaylist.list.positionViewAtEnd()
}
}
function savePlaylist()
......@@ -176,16 +192,21 @@ function cleanPlaylist()
function playAll(tracks)
{
root.mainPlaylist.list.clearTable()
root.pageStack.currentIndex = 0
if(tracks)
{
root.mainPlaylist.list.clearTable()
root.pageStack.currentIndex = 0
for(var i = 0; i< tracks.length; i++)
appendTrack(tracks[i])
for(var i in tracks)
appendTrack(tracks[i])
// root.mainPlaylist.list.currentIndex = 0
// playTrack(root.mainPlaylist.list.model.get(0))
// root.mainPlaylist.list.currentIndex = 0
// playTrack(root.mainPlaylist.list.model.get(0))
root.mainPlaylist.list.positionViewAtBeginning()
playAt(0)
}
root.mainPlaylist.list.positionViewAtBeginning()
}
......
......@@ -238,6 +238,7 @@ namespace BAE
return ret;
}
const QString MusicPath = QStandardPaths::writableLocation(QStandardPaths::MusicLocation);
const QStringList MusicPaths = QStandardPaths::standardLocations(QStandardPaths::MusicLocation);
const QString HomePath = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
const QString SettingPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation)+"/babe/";
const QString ArtworkPath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)+"/babe/artwork/";
......@@ -245,6 +246,7 @@ namespace BAE
const QString CachePath = BAE::isMobile() ? BAE::ArtworkPath : QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)+"/babe/";
const QString YoutubeCachePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation)+"/babe/youtube/";
const QString DownloadsPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
const QStringList DownloadsPaths = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation);
const QString NotifyDir = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
const QString BabePort = "8483";
const QString App = "Babe";
......
......@@ -3,7 +3,8 @@ import QtGraphicalEffects 1.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
Item
ColumnLayout
{
id: babeAlbumRoot
......@@ -17,10 +18,10 @@ Item
property int fontSize : root.isMobile? 12 : 10
property bool hide : false
width: albumSize
height: typeof album === 'undefined' ? parseInt(albumSize+(albumSize*0.3)) : parseInt(albumSize+(albumSize*0.4))
// height: typeof album === 'undefined' ? parseInt(albumSize+(albumSize*0.3)) : parseInt(albumSize+(albumSize*0.4))
visible: !hide
spacing: 0
DropShadow
{
......@@ -43,90 +44,82 @@ Item
radius: borderRadius
}
ColumnLayout
Item
{
Row
height: albumSize
width: albumSize
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter
Image
{
Layout.fillWidth: true
Layout.alignment: Qt.AlignHCenter
Image
{
id: img
width: babeAlbumRoot.width
height: babeAlbumRoot.width
id: img
width: babeAlbumRoot.width
height: babeAlbumRoot.width
fillMode: Image.PreserveAspectFit
cache: false
antialiasing: true
fillMode: Image.PreserveAspectFit
cache: false
antialiasing: true
source:
{
if(artwork)
(artwork.length > 0 && artwork !== "NONE")? "file://"+encodeURIComponent(artwork) : "qrc:/assets/cover.png"
else "qrc:/assets/cover.png"
}
layer.enabled: albumRadius > 0
layer.effect: OpacityMask
source:
{
if(artwork)
(artwork.length > 0 && artwork !== "NONE")? "file://"+encodeURIComponent(artwork) : "qrc:/assets/cover.png"
else "qrc:/assets/cover.png"
}
layer.enabled: albumRadius > 0
layer.effect: OpacityMask
{
maskSource: Item
{
maskSource: Item
width: img.width
height: img.height
Rectangle
{
width: img.width
height: img.height
Rectangle
{
anchors.centerIn: parent
width: img.adapt ? img.width : Math.min(img.width, img.height)
height: img.adapt ? img.height : width
radius: albumRadius
// radius: Math.min(width, height)
}
anchors.centerIn: parent
width: img.adapt ? img.width : Math.min(img.width, img.height)
height: img.adapt ? img.height : width
radius: albumRadius
// radius: Math.min(width, height)
}
}
}
}
}
Column
{
id: albumInfoRow
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 15
spacing: 5
Row
{
Layout.fillWidth: true
Layout.fillHeight: true
Layout.margins: 5
Label
{
width: parent.width
text: typeof album === 'undefined' ? artist : album
visible: true
horizontalAlignment: Qt.AlignHCenter
elide: Text.ElideRight
font.pointSize: fontSize
font.bold: true
color: textColor
lineHeight: 0.7
}
Label
{
width: parent.width
text: typeof album === 'undefined' ? artist : album
visible: true
horizontalAlignment: Qt.AlignHCenter
elide: Text.ElideRight
font.pointSize: fontSize
font.bold: true
color: textColor
}
Row
Label
{
spacing: 0
Layout.fillWidth: true
Layout.fillHeight: true
Layout.leftMargin: 5
Label
{
width: parent.width
text: typeof album === 'undefined' ? "" : artist
visible: typeof album === 'undefined'? false : true
horizontalAlignment: Qt.AlignHCenter
elide: Text.ElideRight
font.pointSize: fontSize-1
color: textColor
}
width: parent.width
text: typeof album === 'undefined' ? "" : artist
visible: typeof album === 'undefined'? false : true
horizontalAlignment: Qt.AlignHCenter
elide: Text.ElideRight
font.pointSize: fontSize-1
color: textColor
}
}
MouseArea
......@@ -140,3 +133,6 @@ Item
}
}
......@@ -6,13 +6,12 @@ Pane
{
id: gridPage
padding: 20
property int hintSize : Math.sqrt(root.width*root.height)*0.25
property int albumSize:
{
var hintSize = Math.sqrt(root.width*root.height)*0.25
if(hintSize > 150)
150
else if (hintSize < 100)
100
else
hintSize
}
......@@ -23,6 +22,7 @@ Pane
property alias grid: grid
signal albumCoverClicked(string album, string artist)
signal bgClicked()
width: 500
height: 400
......@@ -68,9 +68,8 @@ Pane
height: parent.height
anchors.horizontalCenter: parent.horizontalCenter
cellWidth: albumSize + albumSpacing
cellHeight: parseInt(albumSize+(albumSize*0.6))
cellWidth: albumSize +(albumSize*0.2)
cellHeight: albumSize+(albumSize*0.8)
highlightFollowsCurrentItem: false
focus: true
......@@ -108,14 +107,14 @@ Pane
delegate: BabeAlbum
{
id: delegate
id: albumDelegate
albumSize : gridPage.albumSize
albumRadius: gridPage.albumRadius
albumCard: albumCardVisible
Connections
{
target: delegate
target: albumDelegate
onAlbumClicked:
{
var album = grid.model.get(index).album
......
......@@ -7,7 +7,7 @@ Popup
{
// width: parent.width *0.7
// height: parent.height *0.7
id: folderPickerRoot
x: parent.width / 2 - width / 2
y: parent.height / 2 - height / 2
modal: true
......@@ -22,6 +22,7 @@ Popup
signal pathClicked(var path)
signal accepted(var path)
signal goBack(var path)
background: Rectangle
{
anchors.fill: parent
......@@ -41,28 +42,19 @@ Popup
BabeButton
{
Layout.alignment: Qt.AlignLeft
id: goBackBtn
iconName: "arrow-left"
id: homeBtn
iconName: "gohome"
onClicked:
{
var dir = bae.getParentDir(dirList.currentUrl)
dirList.currentUrl = dir.url
dirList.currentName = dir.name
goBack(dirList.currentUrl)
// var dir = bae.getParentDir(dirList.currentUrl)
// dirList.currentUrl = dir.url
// dirList.currentName = dir.name
// goBack(dirList.currentUrl)
load(bae.homeDir())
}
}
Label
{
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
color: bae.foregroundColor()
text: dirList.currentName
elide: Text.ElideRight
horizontalAlignment: Qt.AlignHCenter
}
Button
{
Layout.alignment: Qt.AlignRight
......@@ -94,8 +86,15 @@ Popup
pathClicked(dirList.currentUrl)
}
}
}
}
function load(folderUrl)
{
dirList.clearTable()
var dirs = bae.getDirs(folderUrl)
for(var path in dirs)
dirList.model.append(dirs[path])
}
}
......@@ -6,34 +6,42 @@ ItemDelegate
{
id: delegate
property string textColor: bae.foregroundColor()
width: parent.width
height: 32
// checkable: true
// checkable: true
contentItem: GridLayout
RowLayout
{
id: gridLayout
width: parent.width
rows:1
columns:1
id: rowLayout
anchors.fill: parent
spacing:0
Label
Item
{
id: folderTitle
Layout.fillWidth: true
Layout.fillHeight: true
Layout.row: 1
Layout.column: 1
Layout.alignment: Qt.AlignLeft
Layout.margins: 15
anchors.verticalCenter: parent.verticalCenter
text: name
font.bold: true
elide: Text.ElideRight
font.pointSize: 10
color: textColor
Label
{
id: folderTitle
width: parent.width
height: parent.height
verticalAlignment: Qt.AlignVCenter
text: name
font.bold: true
elide: Text.ElideRight
font.pointSize: 10
color: textColor
}
}
}
}
......@@ -30,10 +30,10 @@ BabeGrid
signal queueTrack(var track)
signal appendAlbum(var tracks)
// transform: Translate
// {
// y: (drawer.position * albumsViewGrid.height * 0.33)*-1
// }
transform: Translate
{
y: (drawer.position * albumsViewGrid.height * 0.33)*-1
}
onBgClicked: if(drawer.visible) drawer.close()
onFocusChanged: drawer.close()
......
......@@ -169,6 +169,7 @@ Item
Layout.row: 2
Layout.column: 1
Layout.fillWidth: true
width: parent.width
height: 48
// anchors.top: cover.bottom
visible: list.count > 0
......@@ -372,6 +373,7 @@ Item
Label
{
id: currentTrackInfo
Layout.maximumWidth: parent.width*0.7
Layout.row: 1
Layout.column: 2
Layout.fillWidth:true
......
......@@ -19,15 +19,7 @@ Drawer
dragMargin :0
signal iconSizeChanged(int size)
function load(folderUrl)
{
folderPicker.dirList.clearTable()
var dirs = bae.getDirs(folderUrl)
for(var path in dirs)
{
folderPicker.dirList.model.append(dirs[path])
}
}
function scanDir(folderUrl)
{
......@@ -61,14 +53,14 @@ Drawer
Connections
{
target: folderPicker
onPathClicked: load(path)
onPathClicked: folderPicker.load(path)
onAccepted:
{
listModel.append({url: path})
scanDir(path)
}
onGoBack: load(path)
onGoBack: folderPicker.load(path)
}
}
......@@ -151,12 +143,14 @@ Drawer
onClicked:
{
if(root.isMobile)
if(bae.isMobile())
{
folderPicker.open()
load(bae.homeDir())
folderPicker.load(bae.homeDir())
}else