added server list

This commit is contained in:
Andrei Yankovich 2018-03-04 23:19:15 +03:00
parent 032136bcb7
commit 3646611a90
11 changed files with 95 additions and 111 deletions

View File

@ -2,32 +2,6 @@ import QtQuick 2.4
import QtQuick.Controls 2.0
Item{
function addItem(obj){
model.append(obj);
}
function removeItem(obj){
model.remove(obj);
}
function clear(){
model.clear()
}
function init(){
var listOfSong = [];
listOfSong = syncEngine.curentPlayList(mainPage.curentPlayListName);
for(var i = 0; i < listOfSong.length; i++){
var temp = Qt.createComponent("SongDelegate.qml");
if(temp.status === Component.Ready){
var obj = temp.createObject();
var songName = listOfSong[i];
obj.init(syncEngine.songImageByName(songName), songName);
parent.addItem(obj);
}
}
}
ListView {
id: listView

View File

@ -1,6 +1,5 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import SyncEngine 1.0
Page {
id: mainPage
@ -10,12 +9,6 @@ Page {
property string curentPlayListName: "all"
function onLoaded(){
playListsControl.init();
curentPlayList.init();
}
SyncEngine{
id: syncEngine
}
@ -46,7 +39,6 @@ Page {
PlayListsControl{
id:playListsControl;
}
}

View File

@ -12,43 +12,6 @@ Rectangle {
signal select();
color: Utils.backgroundColor()
function addItem(obj){
model.append(obj);
}
function removeItem(obj){
model.remove(obj);
}
function clear(){
model.clear()
}
function view(curentPlayListName){
name = curentPlayListName;
playListPane.visible = true;
var added = [], all = [];
added = syncEngine.getPlayList(name);
all = syncEngine.getPlayList("");
for(var i = 0; i < all.lenght; i++){
var temp = Qt.createComponent("SongDelegateSelection.qml");
if(temp.status === Component.Ready){
var obj = temp.createObject();
obj.init("/image/res/logo.png", all[i]);
if(added.indexOf(all[i]) >= 0){
obj.isSelected = true;
}
addItem(obj);
}
}
}
Base.BaseText{
id:namePalyList
height: 30

View File

@ -5,33 +5,6 @@ import "./base" as Base
Item {
id: playListsControl
function addItem(obj){
model.append(obj);
}
function removeItem(obj){
model.remove(obj);
}
function clear(){
model.clear()
}
function init(){
var playlists = [];
playlists = syncEngine.allPlayLists();
switch_pane(playListsControlSource);
for(var i = 0; i < playlists.length; i++){
var temp = Qt.createComponent("PlayListDelegate.qml");
if(temp.status === Component.Ready){
var obj = temp.createObject();
obj.init(playlists[i], i);
addItem(obj);
}
}
}
function switch_pane(object){
for(var i = 0; i < playListsControl.children.length; i++){
@ -72,7 +45,6 @@ Item {
onClicked: {
editPlayList.visible = true;
editPlayList.name = model.get(playLists.selectedItem).text;
}
}
@ -128,9 +100,6 @@ Item {
showDotAndDotDot: false
nameFilters: "*.mp3"
onFilesSelected: {
for(var i = 0; i< selectedFiles.length; i++){
syncEngine.play(selectedFiles[i]);
}
switch_pane(editPlayList);
// messageDialog.text = "Cannot open file "+ currentFolder() + "/" + fileName
// messageDialog.open()

View File

@ -1,29 +1,85 @@
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Window 2.0
import "./base" as Base
import "base/utils.js" as Utils
Item {
readonly property real rowHeight: Utils.dp(Screen.pixelDensity, 36)
readonly property real rowWidth: parent.width;
function onItemClick() {
}
Button{
id:listen
width: parent.width
text: qsTr("Add")
text: qsTr("Refresh")
anchors.top:parent.top
anchors.left: parent.left
onClicked: {
syncEngine.scan();
}
}
ListView {
id: listView
model: ListModel {
model: serverListModel;
Component {
id: serverDelegate
Item {
height: rowHeight
width: listView.width
id: item
Rectangle {
color: Qt.rgba(0,0,0,0)
id: rectangle;
anchors.fill: item
MouseArea {
anchors.fill: rectangle
onClicked: {
indicator.active = onItemClick()
}
}
Text {
id: serverNameText
height: width
anchors.left: image.right
anchors.top: rectangle.top
anchors.bottom: rectangle.bottom
anchors.right: rectangle.right
text: serverName !== undefined ? serverName : ""
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
Image {
id: image
height: buttonHeight
width: height
anchors.left: rectangle.left
anchors.leftMargin: textmargin
anchors.verticalCenter: rectangle.verticalCenter
source: "/icons/res/folder.png"
}
}
}
}
delegate: serverDelegate
delegate: ServerDelegate{
ScrollIndicator.horizontal: ScrollIndicator { }
ScrollIndicator.vertical: ScrollIndicator { }
}
anchors.top:listen.bottom
anchors.left: parent.left
anchors.right: parent.right

View File

@ -1,7 +1,10 @@
#include "app.h"
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "syncengine.h"
#include "imageprovider.h"
#include "serverlistmodel.h"
App::App(QObject* ptr):
QObject(ptr)
@ -9,10 +12,18 @@ App::App(QObject* ptr):
qmlEngine = new QQmlApplicationEngine();
syncEngine = new SyncEngine();
imageProvider = new ImageProvider(syncEngine);
serverListModel = new ServerListModel();
serverListModel->setSource(syncEngine);
}
bool App::run(){
qmlRegisterType<SyncEngine>("SyncEngine",1,0,"SyncEngine");
qmlEngine->addImageProvider(QLatin1String("collection"), imageProvider);
QQmlContext *ctxt = qmlEngine->rootContext();
ctxt->setContextProperty("syncEngine", syncEngine);
ctxt->setContextProperty("serverListModel", serverListModel);
qmlEngine->load(QUrl(QStringLiteral("qrc:/main.qml")));
if (qmlEngine->rootObjects().isEmpty())
@ -22,6 +33,7 @@ bool App::run(){
}
App::~App(){
delete serverListModel;
delete syncEngine;
delete qmlEngine;
}

View File

@ -7,6 +7,8 @@
class SyncEngine;
class QQmlApplicationEngine;
class ImageProvider;
class ServerListModel;
/**
* @brief The App class
@ -18,6 +20,7 @@ private:
SyncEngine *syncEngine;
QQmlApplicationEngine *qmlEngine;
ImageProvider *imageProvider;
ServerListModel *serverListModel;
public:
explicit App(QObject *ptr = nullptr);

View File

@ -18,7 +18,7 @@ void ServerListModel::setSource(const SyncEngine *engine){
QHash<int, QByteArray> ServerListModel::roleNames()const{
QHash<int, QByteArray> roles;
roles[nameRole] = "name";
roles[nameRole] = "serverName";
return roles;
}
@ -30,7 +30,7 @@ void ServerListModel::onPlayListsChanged(){
bool ServerListModel::canFetchMore(const QModelIndex & /* index */) const
{
if (itemCount < servers->size())
if (servers && itemCount < servers->size())
return true;
else
return false;

View File

@ -131,11 +131,21 @@ bool SyncEngine::listen(int index){
}
}
const QList<ETcpSocket*>* SyncEngine::getServerList() const{
const QList<ETcpSocket*>* SyncEngine::getServerList() const{
return &sync->getServersList();
}
void SyncEngine::scan(){
try{
sync->scan();
}catch(BaseException e){
_lastError = e.what();
emit error();
}
}
int SyncEngine::repeat()const{
return _repeat;
}

View File

@ -148,6 +148,11 @@ public slots:
*/
const QList<ETcpSocket *> *getServerList() const;
/**
* @brief scan
*/
void scan();
signals:
/**

View File

@ -384,7 +384,7 @@ void Sync::packageRender(ETcpSocket *socket){
void Sync::rescan(bool deep){
package pac;
if(!createPackage(t_what,pac)){
if(!createPackage(t_what, pac)){
throw CreatePackageExaption();
return;
}