a draft of player view, debug

This commit is contained in:
Blue 2018-10-29 00:32:44 +03:00 committed by Gitea
parent 46560924ce
commit c8b432fe57
13 changed files with 183 additions and 33 deletions

View File

@ -125,6 +125,7 @@ void Corax::start()
}
commands->enableCommand(W::String(u"clearCache"), true);
commands->enableCommand(W::String(u"givePlayer"), true);
started = true;
cout << "Corax is ready" << endl;
@ -262,7 +263,6 @@ void Corax::onNodeConnected(const W::String& name)
cout << "connected node " << name.toString() << endl;
if (name == u"Perturabo") {
commands->enableCommand(W::String(u"parseDirectory"), true);
commands->enableCommand(W::String(u"givePlayer"), true);
}
}
@ -271,7 +271,6 @@ void Corax::onNodeDisconnected(const W::String& name)
cout << "disconnected node " << name.toString() << endl;
if (name == u"Perturabo") {
commands->enableCommand(W::String(u"parseDirectory"), false);
commands->enableCommand(W::String(u"givePlayer"), false);
}
}

View File

@ -7,7 +7,8 @@ M::Player::Player(const W::Address& address, QObject* parent):
playPauseBtn(new M::Button(address + W::Address{u"play"})),
_queueView(new M::List(address + W::Address{u"queueView"})),
_queue(),
current(0)
current(0),
counter(0)
{
W::Handler* get = W::Handler::create(address + W::Address({u"get"}), this, &M::Player::_h_get);
W::Handler* hqueue = W::Handler::create(address + W::Address({u"queue"}), this, &M::Player::_h_queue);
@ -52,7 +53,6 @@ void M::Player::h_subscribe(const W::Event& ev)
h_get(ev);
}
void M::Player::h_get(const W::Event& ev)
{
W::Vector* ctrls = new W::Vector();
@ -61,8 +61,8 @@ void M::Player::h_get(const W::Event& ev)
for (; citr != cend; ++citr) {
W::Vocabulary* cvc = new W::Vocabulary();
cvc->insert(u"type", new W::Uint64(cend->first));
cvc->insert(u"address", cend->second);
cvc->insert(u"type", new W::Uint64(citr->first));
cvc->insert(u"address", citr->second);
ctrls->push(cvc);
}
@ -73,8 +73,8 @@ void M::Player::h_get(const W::Event& ev)
for (; vitr != vend; ++vitr) {
W::Vocabulary* vvc = new W::Vocabulary();
vvc->insert(u"type", new W::Uint64(vend->first));
vvc->insert(u"address", vend->second);
vvc->insert(u"type", new W::Uint64(vitr->first));
vvc->insert(u"address", vitr->second);
vws->push(vvc);
}
@ -97,7 +97,7 @@ void M::Player::h_queue(const W::Event& ev)
const W::Vocabulary& data = static_cast<const W::Vocabulary&>(ev.getData());
const W::Uint64& id = static_cast<const W::Uint64&>(data.at(u"id"));
ProxySong* song = new ProxySong(id, address + W::Address{u"currentPlayback"});
ProxySong* song = new ProxySong(id, address + W::Address{W::String(W::Uint64(counter++).toString())});
addModel(song);
if (current == 0) {
current = song;

View File

@ -41,7 +41,7 @@ namespace M {
handler(queue);
private:
typedef std::map<ItemType, const W::Address&> ItemMap;
typedef std::map<ItemType, W::Address> ItemMap;
typedef std::deque<ProxySong*> Queue;
ItemMap controls;
@ -50,6 +50,7 @@ namespace M {
M::List* _queueView;
Queue _queue;
ProxySong* current;
uint64_t counter;
private slots:
void onPlayPauseBtn();

View File

@ -23,7 +23,7 @@ var Enum = Class.inherit({
this.additional = Object.create(null);
this._additionals = additional || [];
this._lastId = 0;
this._lastId = -1;
storage[name] = this;
},

View File

@ -34,6 +34,8 @@ var Button = Controller.inherit({
this._h_setLabel(ev);
this._h_setImage(ev);
this._h_setEnabled(ev);
this.initialized = true;
},
"_h_setEnabled": function(ev) {
var data = ev.getData();

View File

@ -4,7 +4,7 @@ var Subscribable = require("../utils/subscribable");
var LocalModel = Subscribable.inherit({
"className": "LocalModel",
"constructor": function(properties) {
"constructor": function(properties, data) {
Subscribable.fn.constructor.call(this);
this.properties = [];
@ -18,6 +18,11 @@ var LocalModel = Subscribable.inherit({
}
}
}
if (data !== undefined) {
this.data = data;
this.initialized = true;
}
},
"setData": function(data) {
this.data = data;

View File

@ -30,6 +30,7 @@ var Player = Controller.inherit({
btn.itemType = t;
this.controls[t] = btn;
this.addController(btn);
this.trigger("newElement", btn, t);
break;
default:
this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to controls of the Player, but it's not qualified to be a control");
@ -55,6 +56,8 @@ var Player = Controller.inherit({
cpb.ItemType = t;
this.views[t] = cpb;
this.addController(cpb);
this.trigger("newElement", cpb, t);
break;
default:
this.trigger("serviceMessage", "An attempt to add ItemType " + ItemType.reversed[t] + " to views of the Player, but it's not qualified to be a view");
}
@ -78,8 +81,11 @@ var Player = Controller.inherit({
size = views.length();
for (i = 0; i < size; ++i) {
vc = views.at(i);
this._addview(vc.at("type"), vc.at("address"));
this._addView(vc.at("type"), vc.at("address"));
}
this.initialized = true;
this.trigger("data");
},
_h_viewsChange: function(ev) {
var data = ev.getData();
@ -96,7 +102,7 @@ var Player = Controller.inherit({
size = add.length();
for (i = 0; i < size; ++i) {
vc = add.at(i);
this._addview(vc.at("type"), vc.at("address"));
this._addView(vc.at("type"), vc.at("address"));
}
},
_removeControl: function(type) {

View File

@ -19,6 +19,7 @@
defineArray.push("lib/wController/pageStorage");
defineArray.push("lib/wController/page");
defineArray.push("lib/wController/localModel");
defineArray.push("lib/wController/player");
defineArray.push("views/view");
defineArray.push("views/layout");
@ -43,6 +44,7 @@
var PageStorage = require("lib/wController/pageStorage");
var PageController = require("lib/wController/page");
var LocalModel = require("lib/wController/localModel");
var PlayerModel = require("lib/wController/player");
var View = require("views/view");
var Layout = require("views/layout");
@ -204,9 +206,20 @@
var node = this._nodes[name];
node.connected = false;
switch (name) {
case "Corax":
if (this._playerCtl) {
this._mainLayout.removePlayer();
this._playerCtl._onSocketDisconnected();
this._playerCtl.uneregister();
this._playerCtl.destructor();
this._playerCtl = undefined;
}
}
for (var id in node.foreigns) {
if (node.foreigns[id].subscribed) {
node.foreigns[id].controller._onSocketDisconnected;
node.foreigns[id].controller._onSocketDisconnected();
}
}
node.state.setData(SocketState.straight.disconnected);
@ -242,14 +255,14 @@
this._nodes[name] = obj;
},
"registerForeignController": function(node, controller) {
var node = this._nodes[node];
"registerForeignController": function(nodeName, controller) {
var node = this._nodes[nodeName];
if (node === undefined) {
throw new Error("An attempt to register controller to an unknown node " + node);
throw new Error("An attempt to register controller to an unknown node " + nodeName);
}
if (node.foreigns[controller.id] !== undefined) {
throw new Error("An attempt to register a controller under node " + node + " for a second time");
throw new Error("An attempt to register a controller under node " + nodeName + " for a second time");
}
var obj = Object.create(null);
obj.controller = controller;
@ -271,43 +284,46 @@
"_responsePlayer": function(ev) {
var data = ev.getData();
console.log('Received player address: ' + data.at("address").toString());
this._playerCtl = new PlayerModel(data.at("address").clone());
this._playerCtl.register(this.dispatcher, this._nodes["Corax"].socket);
this._playerCtl.subscribe();
this._mainLayout.appendPlayer(this._playerCtl);
},
"setTheme": function(theme) {
View.setTheme(theme);
},
"subscribeForeignController": function(node, controller) {
var node = this._nodes[node];
"subscribeForeignController": function(nodeName, controller) {
var node = this._nodes[nodeName];
if (node === undefined) {
throw new Error("An attempt to subscribe a controller to an unknown node " + node);
throw new Error("An attempt to subscribe a controller to an unknown node " + nodeName);
}
if (node.foreigns[controller.id] === undefined) {
throw new Error("An attempt to subscribe not registered controller to node " + node);
throw new Error("An attempt to subscribe not registered controller to node " + nodeName);
}
node.foreigns[controller.id].subscribed = true;
controller.subscribe();
},
"unregisterForeignController": function(node, controller) {
var node = this._nodes[node];
"unregisterForeignController": function(nodeName, controller) {
var node = this._nodes[nodeName];
if (node === undefined) {
throw new Error("An attempt to unregister a controller from an unknown node " + node);
throw new Error("An attempt to unregister a controller from an unknown node " + nodeName);
}
if (node.foreigns[controller.id] === undefined) {
throw new Error("An attempt to unregister not registered controller from node " + node);
throw new Error("An attempt to unregister not registered controller from node " + nodeName);
}
delete node.foreigns[controller.id];
controller.unregister();
},
"unsubscribeForeignController": function(node, controller) {
var node = this._nodes[node];
"unsubscribeForeignController": function(nodeName, controller) {
var node = this._nodes[nodeName];
if (node === undefined) {
throw new Error("An attempt to unsubscribe a controller from an unknown node " + node);
throw new Error("An attempt to unsubscribe a controller from an unknown node " + nodeName);
}
if (node.foreigns[controller.id] === undefined) {
throw new Error("An attempt to unsubscribe not registered controller from node " + node);
throw new Error("An attempt to unsubscribe not registered controller from node " + nodeName);
}
node.foreigns[controller.id].subscribed = false;
controller.unsubscribe();

View File

@ -18,3 +18,4 @@ add_jslib(wController/imagePane.js lib/wController/imagePane ${LORGAR_DIR} brows
add_jslib(wController/file/file.js lib/wController/file/file ${LORGAR_DIR} browser)
add_jslib(wController/image.js lib/wController/image ${LORGAR_DIR} browser)
add_jslib(wController/button.js lib/wController/button ${LORGAR_DIR} browser)
add_jslib(wController/player.js lib/wController/player ${LORGAR_DIR} browser)

View File

@ -13,5 +13,6 @@ configure_file(pane.js pane.js)
configure_file(image.js image.js)
configure_file(button.js button.js)
configure_file(enumeration.js enumeration.js)
configure_file(player.js player.js)
add_subdirectory(helpers)

View File

@ -9,6 +9,7 @@
defineArray.push("views/navigationPanel");
defineArray.push("views/layout");
defineArray.push("views/enumeration");
defineArray.push("views/player");
defineArray.push("lib/wController/localModel");
define(moduleName, defineArray, function mainLayout_module() {
@ -18,6 +19,7 @@
var ViewNavigationPanel = require("views/navigationPanel");
var Layout = require("views/layout");
var Enumeration = require("views/enumeration");
var Player = require("views/player");
var LocalModel = require("lib/wController/localModel");
var MainLayout = GridLayout.inherit({
@ -26,6 +28,7 @@
GridLayout.fn.constructor.call(this, controller, options);
this._statusBarPosition = 2;
this._player = undefined;
this._mainColorHelper = new LocalModel({backgroundColor: "mainColor"});
this._statusBarModel = new LocalModel({backgroundColor: "secondaryColor"});
@ -72,6 +75,21 @@
this._statusBar.append(e, 0, this._statusBarPosition++, 1, 1, Layout.Aligment.LeftCenter);
this._uncyclic.push(lm.destructor.bind(lm));
},
appendPlayer: function(playerModel) {
if (this._player !== undefined) {
throw new Error("An attempt to add player to main layout for the second time");
}
this._player = new Player(playerModel);
this.append(this._player, 2, 0, 1, 3);
},
removePlayer: function() {
if (this._player === undefined) {
throw new Error("An attempt to remove non existing player from mainLayout");
}
this.removeChild(this._player);
this._player.destructor();
this._player = undefined;
}
});

99
lorgar/views/player.js Normal file
View File

@ -0,0 +1,99 @@
"use strict";
(function() {
var moduleName = "views/player"
var deps = [];
deps.push("views/gridLayout");
deps.push("views/button");
deps.push("views/label");
deps.push("lib/wController/localModel");
deps.push("lib/utils/enum");
define(moduleName, deps, function() {
var GridLayout = require("views/gridLayout");
var Button = require("views/button");
var Label = require("views/label");
var Model = require("lib/wController/localModel");
var Enum = require("lib/utils/enum");
var Player = GridLayout.inherit({
className: "Player",
constructor: function(ctrl, options) {
GridLayout.fn.constructor.call(this, ctrl, options);
this._playPause = null;
this._cpbCtrl = null;
this._infoModels = {
artist: new Model(null, "artist: unknown"),
album: new Model(null, "album: unknown"),
song: new Model(null, "song: unknown")
}
ctrl.on("newElement", this._onNewElement, this);
var artist = new Label(this._infoModels.artist);
var album = new Label(this._infoModels.album);
var song = new Label(this._infoModels.song);
this.append(artist, 0, 2, 1, 1)
this.append(song, 1, 2, 1, 1)
this.append(album, 2, 2, 1, 1)
this._uncyclic.push(this._infoModels.artist.destructor.bind(this._infoModels.artist));
this._uncyclic.push(this._infoModels.song.destructor.bind(this._infoModels.song));
this._uncyclic.push(this._infoModels.album.destructor.bind(this._infoModels.album));
},
destructor: function() {
this._f.off("newElement", this._onNewElement, this);
this._clearCpbCtrl();
GridLayout.fn.destructor.call(this);
},
_clearCpbCtrl: function() {
if (this._cpbCtrl !== null) {
this._cpbCtrl.off("newElement", this._onCpbNewElement, this);
this._cpbCtrl.off("removeElement", this._onCpbRemoveElement, this);
this._cpbCtrl = null;
}
},
_onNewElement: function(ctrl, type) {
var ItemType = Enum.storage["ItemType"];
switch (type) {
case ItemType.straight.playPause:
this._playPause = new Button(ctrl);
this.append(this._playPause, 0, 1, 3, 1);
break;
case ItemType.straight.queue:
break;
case ItemType.straight.currentPlayback:
this._clearCpbCtrl();
this._cpbCtrl = ctrl;
this._cpbCtrl.on("newElement", this._onCpbNewElement, this);
this._cpbCtrl.on("removeElement", this._onCpbRemoveElement, this);
break;
}
},
_onCpbNewElement: function(key, value) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": " + value.toString());
}
},
_onCpbRemoveElement: function(key) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": unknown");
}
}
});
return Player;
});
})()

View File

@ -54,7 +54,9 @@
for (var i = 0; i < this._f._controllers.length; ++i) {
this._onNewController(this._f._controllers[i]);
}
this._onData(this._f);
//if (this._f.initialized) {
this._onData(this._f);
//}
View.collection[this._id] = this;
this._applyProperties();