mirror of
https://github.com/SuperBFG7/ympd
synced 2024-11-26 06:47:17 +00:00
add settings modal dialog
This commit is contained in:
parent
6f8d5ef732
commit
8c49b2a877
@ -14,6 +14,7 @@ set(CPACK_DEBIAN_PACKAGE_MAINTAINER "andy@ndyk.de")
|
|||||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libssl1.0.0,libmpdclient2")
|
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libssl1.0.0,libmpdclient2")
|
||||||
|
|
||||||
option(WITH_STATIC_WEBSOCKETS "Build with static libwebsockets library" ON)
|
option(WITH_STATIC_WEBSOCKETS "Build with static libwebsockets library" ON)
|
||||||
|
option(WITH_MPD_HOST_CHANGE "Let users of the web frontend change the MPD Host" ON)
|
||||||
|
|
||||||
find_package(LibMPDClient REQUIRED)
|
find_package(LibMPDClient REQUIRED)
|
||||||
find_package(LibWebSockets REQUIRED)
|
find_package(LibWebSockets REQUIRED)
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
<li id="playlist"><a href="#/">Playlist</a></li>
|
<li id="playlist"><a href="#/">Playlist</a></li>
|
||||||
<li id="browse"><a href="#/browse/">Browse database</a></li>
|
<li id="browse"><a href="#/browse/">Browse database</a></li>
|
||||||
<li><a href="#" data-toggle="modal" data-target="#about" onclick="getVersion();">About</a></li>
|
<li><a href="#" data-toggle="modal" data-target="#about" onclick="getVersion();">About</a></li>
|
||||||
|
<li><a href="#" data-toggle="modal" data-target="#settings" onclick="getHost();">Settings</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div class="btn-toolbar navbar-btn navbar-right" role="toolbar">
|
<div class="btn-toolbar navbar-btn navbar-right" role="toolbar">
|
||||||
@ -185,6 +186,37 @@
|
|||||||
</div><!-- /.modal-dialog -->
|
</div><!-- /.modal-dialog -->
|
||||||
</div><!-- /.modal -->
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
|
<!-- Modal -->
|
||||||
|
<div class="modal fade" id="settings" tabindex="-1" role="dialog" aria-labelledby="settingsLabel" aria-hidden="true">
|
||||||
|
<div class="modal-dialog">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h2 class="modal-title" id="settingsLabel"><span class="glyphicon glyphicon-wrench"></span> Settings</h2>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form class="form-inline" role="form">
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="col-xs-9">
|
||||||
|
<label class="control-label" for="mpdhost">MPD Host / IP</label>
|
||||||
|
<input type="text" class="form-control" id="mpdhost">
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-3">
|
||||||
|
<label class="control-label" for="mpdport">MPD Port</label>
|
||||||
|
<input type="text" class="form-control" id="mpdport">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||||
|
<button type="button" class="btn btn-default" data-dismiss="modal" onclick="setHost();">Save</button>
|
||||||
|
</div>
|
||||||
|
</div><!-- /.modal-content -->
|
||||||
|
</div><!-- /.modal-dialog -->
|
||||||
|
</div><!-- /.modal -->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- Bootstrap core JavaScript
|
<!-- Bootstrap core JavaScript
|
||||||
================================================== -->
|
================================================== -->
|
||||||
|
@ -311,6 +311,10 @@ function webSocketConnect() {
|
|||||||
type: "info",
|
type: "info",
|
||||||
}).show();
|
}).show();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "mpdhost":
|
||||||
|
$('#mpdhost').val(obj.data.host);
|
||||||
|
$('#mpdport').val(obj.data.port);
|
||||||
break;
|
break;
|
||||||
case "error":
|
case "error":
|
||||||
$('.top-right').notify({
|
$('.top-right').notify({
|
||||||
@ -452,6 +456,23 @@ function getVersion()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHost() {
|
||||||
|
socket.send('MPD_API_GET_MPDHOST');
|
||||||
|
|
||||||
|
function onEnter(event) {
|
||||||
|
if ( event.which == 13 )
|
||||||
|
setHost();
|
||||||
|
$('#settings').modal('hide');
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#mpdhost').keypress(onEnter);
|
||||||
|
$('#mpdport').keypress(onEnter);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setHost() {
|
||||||
|
socket.send('MPD_API_SET_MPDHOST,'+$('#mpdport').val()+','+$('#mpdhost').val());
|
||||||
|
}
|
||||||
|
|
||||||
function notificationsSupported() {
|
function notificationsSupported() {
|
||||||
return "webkitNotifications" in window;
|
return "webkitNotifications" in window;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,6 @@
|
|||||||
#define YMPD_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}
|
#define YMPD_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH}
|
||||||
#define DATADIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}"
|
#define DATADIR "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}"
|
||||||
#define LOCAL_RESOURCE_PATH DATADIR"/htdocs"
|
#define LOCAL_RESOURCE_PATH DATADIR"/htdocs"
|
||||||
|
#cmakedefine WITH_MPD_HOST_CHANGE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include <mpd/tag.h>
|
#include <mpd/tag.h>
|
||||||
|
|
||||||
#include "mpd_client.h"
|
#include "mpd_client.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
struct mpd_connection *conn = NULL;
|
struct mpd_connection *conn = NULL;
|
||||||
enum mpd_conn_states mpd_conn_state = MPD_DISCONNECTED;
|
enum mpd_conn_states mpd_conn_state = MPD_DISCONNECTED;
|
||||||
@ -94,6 +95,12 @@ int callback_ympd(struct libwebsocket_context *context,
|
|||||||
pss->do_send &= ~DO_SEND_BROWSE;
|
pss->do_send &= ~DO_SEND_BROWSE;
|
||||||
free(pss->browse_path);
|
free(pss->browse_path);
|
||||||
}
|
}
|
||||||
|
else if(pss->do_send & DO_SEND_MPDHOST) {
|
||||||
|
n = snprintf(p, MAX_SIZE, "{\"type\":\"mpdhost\", \"data\": "
|
||||||
|
"{\"host\" : \"%s\", \"port\": \"%d\"}"
|
||||||
|
"}", mpd_host, mpd_port);
|
||||||
|
pss->do_send &= ~DO_SEND_MPDHOST;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
/* Default Action */
|
/* Default Action */
|
||||||
int current_song_id;
|
int current_song_id;
|
||||||
@ -209,11 +216,25 @@ int callback_ympd(struct libwebsocket_context *context,
|
|||||||
free(uri);
|
free(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef WITH_MPD_HOST_CHANGE
|
||||||
|
else if(!strncmp((const char *)in, MPD_API_SET_MPDHOST, sizeof(MPD_API_SET_MPDHOST)-1)) {
|
||||||
|
char *host;
|
||||||
|
int port = 0;
|
||||||
|
if(sscanf(in, "MPD_API_SET_MPDHOST,%d,%m[^\t\n ]", &port, &host) && host != NULL && port > 0) {
|
||||||
|
strncpy(mpd_host, host, sizeof(mpd_host));
|
||||||
|
free(host);
|
||||||
|
mpd_port = port;
|
||||||
|
mpd_conn_state = MPD_RECONNECT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(!strncmp((const char *)in, MPD_API_GET_MPDHOST, sizeof(MPD_API_GET_MPDHOST)-1)) {
|
||||||
|
pss->do_send |= DO_SEND_MPDHOST;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if(mpd_conn_state == MPD_CONNECTED && mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
|
||||||
if(mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
|
|
||||||
pss->do_send |= DO_SEND_ERROR;
|
pss->do_send |= DO_SEND_ERROR;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -249,6 +270,7 @@ void mpd_loop()
|
|||||||
case MPD_FAILURE:
|
case MPD_FAILURE:
|
||||||
lwsl_err("MPD connection failed.\n");
|
lwsl_err("MPD connection failed.\n");
|
||||||
|
|
||||||
|
case MPD_RECONNECT:
|
||||||
if(conn != NULL)
|
if(conn != NULL)
|
||||||
mpd_connection_free(conn);
|
mpd_connection_free(conn);
|
||||||
conn = NULL;
|
conn = NULL;
|
||||||
|
@ -38,12 +38,13 @@
|
|||||||
#define DO_SEND_TRACK_INFO (1 << 2)
|
#define DO_SEND_TRACK_INFO (1 << 2)
|
||||||
#define DO_SEND_BROWSE (1 << 3)
|
#define DO_SEND_BROWSE (1 << 3)
|
||||||
#define DO_SEND_ERROR (1 << 4)
|
#define DO_SEND_ERROR (1 << 4)
|
||||||
|
#define DO_SEND_MPDHOST (1 << 5)
|
||||||
|
|
||||||
#define MPD_API_GET_SEEK "MPD_API_GET_SEEK"
|
#define MPD_API_GET_SEEK "MPD_API_GET_SEEK"
|
||||||
#define MPD_API_GET_PLAYLIST "MPD_API_GET_PLAYLIST"
|
#define MPD_API_GET_PLAYLIST "MPD_API_GET_PLAYLIST"
|
||||||
#define MPD_API_GET_TRACK_INFO "MPD_API_GET_TRACK_INFO"
|
#define MPD_API_GET_TRACK_INFO "MPD_API_GET_TRACK_INFO"
|
||||||
#define MPD_API_GET_BROWSE "MPD_API_GET_BROWSE"
|
#define MPD_API_GET_BROWSE "MPD_API_GET_BROWSE"
|
||||||
|
#define MPD_API_GET_MPDHOST "MPD_API_GET_MPDHOST"
|
||||||
#define MPD_API_ADD_TRACK "MPD_API_ADD_TRACK"
|
#define MPD_API_ADD_TRACK "MPD_API_ADD_TRACK"
|
||||||
#define MPD_API_ADD_PLAY_TRACK "MPD_API_ADD_PLAY_TRACK"
|
#define MPD_API_ADD_PLAY_TRACK "MPD_API_ADD_PLAY_TRACK"
|
||||||
#define MPD_API_PLAY_TRACK "MPD_API_PLAY_TRACK"
|
#define MPD_API_PLAY_TRACK "MPD_API_PLAY_TRACK"
|
||||||
@ -56,6 +57,7 @@
|
|||||||
#define MPD_API_SET_SEEK "MPD_API_SET_SEEK"
|
#define MPD_API_SET_SEEK "MPD_API_SET_SEEK"
|
||||||
#define MPD_API_SET_NEXT "MPD_API_SET_PREV"
|
#define MPD_API_SET_NEXT "MPD_API_SET_PREV"
|
||||||
#define MPD_API_SET_PREV "MPD_API_SET_NEXT"
|
#define MPD_API_SET_PREV "MPD_API_SET_NEXT"
|
||||||
|
#define MPD_API_SET_MPDHOST "MPD_API_SET_MPDHOST"
|
||||||
#define MPD_API_UPDATE_DB "MPD_API_UPDATE_DB"
|
#define MPD_API_UPDATE_DB "MPD_API_UPDATE_DB"
|
||||||
#define MPD_API_TOGGLE_RANDOM "MPD_API_TOGGLE_RANDOM"
|
#define MPD_API_TOGGLE_RANDOM "MPD_API_TOGGLE_RANDOM"
|
||||||
#define MPD_API_TOGGLE_CONSUME "MPD_API_TOGGLE_CONSUME"
|
#define MPD_API_TOGGLE_CONSUME "MPD_API_TOGGLE_CONSUME"
|
||||||
@ -72,7 +74,8 @@ struct per_session_data__ympd {
|
|||||||
enum mpd_conn_states {
|
enum mpd_conn_states {
|
||||||
MPD_FAILURE,
|
MPD_FAILURE,
|
||||||
MPD_DISCONNECTED,
|
MPD_DISCONNECTED,
|
||||||
MPD_CONNECTED
|
MPD_CONNECTED,
|
||||||
|
MPD_RECONNECT
|
||||||
};
|
};
|
||||||
|
|
||||||
void *mpd_idle_connection(void *_data);
|
void *mpd_idle_connection(void *_data);
|
||||||
@ -87,7 +90,7 @@ int mpd_put_playlist(char *buffer);
|
|||||||
int mpd_put_browse(char *buffer, char *path);
|
int mpd_put_browse(char *buffer, char *path);
|
||||||
|
|
||||||
int mpd_port;
|
int mpd_port;
|
||||||
const char *mpd_host;
|
char mpd_host[255];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ int main(int argc, char **argv)
|
|||||||
atexit(bye);
|
atexit(bye);
|
||||||
memset(&info, 0, sizeof info);
|
memset(&info, 0, sizeof info);
|
||||||
info.port = 8080;
|
info.port = 8080;
|
||||||
mpd_host = "127.0.0.1";
|
strcpy(mpd_host, "127.0.0.1");
|
||||||
mpd_port = 6600;
|
mpd_port = 6600;
|
||||||
lws_set_log_level(LLL_ERR | LLL_WARN, NULL);
|
lws_set_log_level(LLL_ERR | LLL_WARN, NULL);
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ int main(int argc, char **argv)
|
|||||||
long_options, &option_index)) != -1) {
|
long_options, &option_index)) != -1) {
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 'h':
|
case 'h':
|
||||||
mpd_host = optarg;
|
strncpy(mpd_host, optarg, sizeof(mpd_host));
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
mpd_port = atoi(optarg);
|
mpd_port = atoi(optarg);
|
||||||
|
Loading…
Reference in New Issue
Block a user