Skip to content
Permalink
Browse files

Add Ampache browser plugin based on Róbert Čerňanský's work.

  • Loading branch information...
jlindgren90 committed Jul 19, 2016
1 parent 9e347a3 commit 54c505975455f45b9a6c50367f38aaf4452226eb
Showing with 165 additions and 1 deletion.
  1. +9 −1 configure.ac
  2. +2 −0 extra.mk.in
  3. +20 −0 src/ampache/Makefile
  4. +134 −0 src/ampache/ampache.cc
@@ -101,7 +101,7 @@ check_allowed () {
AC_MSG_ERROR([--enable-$1 cannot be used without --enable-gtk])
fi
;;
qtaudio|qtglspectrum)
ampache|qtaudio|qtglspectrum)
plugin_allowed=$USE_QT
if test $plugin_allowed = no -a $2 = yes ; then
AC_MSG_ERROR([--enable-$1 cannot be used without --enable-qt])
@@ -460,6 +460,13 @@ ENABLE_PLUGIN_WITH_DEP(aosd,
dnl Optional plugins (Qt-only)
dnl ==========================

ENABLE_PLUGIN_WITH_DEP(ampache,
Ampache browser,
auto,
GENERAL,
AMPACHE,
ampache_browser_0)

ENABLE_PLUGIN_WITH_DEP(qtaudio,
QtMultimedia output,
auto,
@@ -756,6 +763,7 @@ echo
echo " General"
echo " -------"
echo " Alarm (requires GTK+): $USE_GTK"
echo " Ampache browser (requires Qt): $have_ampache"
echo " Delete Files: $USE_GTK_OR_QT"
echo " GNOME Shortcuts: $have_gnomeshortcuts"
echo " libnotify OSD: $have_notify"
@@ -21,6 +21,8 @@ USE_QT ?= @USE_QT@

ALSA_CFLAGS ?= @ALSA_CFLAGS@
ALSA_LIBS ?= @ALSA_LIBS@
AMPACHE_CFLAGS ?= @AMPACHE_CFLAGS@
AMPACHE_LIBS ?= @AMPACHE_LIBS@
BS2B_CFLAGS ?= @BS2B_CFLAGS@
BS2B_LIBS ?= @BS2B_LIBS@
CDIO_LIBS ?= @CDIO_LIBS@
@@ -0,0 +1,20 @@
# Makefile
#
# Project: Ampache Browser Audacious Plugin
# License: GNU GPLv3
#
# Copyright (C) 2015 - 2016 Róbert Čerňanský

PLUGIN = ampache${PLUGIN_SUFFIX}

SRCS = ampache.cc

include ../../buildsys.mk
include ../../extra.mk

plugindir := ${plugindir}/${GENERAL_PLUGIN_DIR}

LD = ${CXX}
CPPFLAGS += -I../.. -I. ${QT_CFLAGS} ${AMPACHE_CFLAGS}
CFLAGS += ${PLUGIN_CFLAGS}
LIBS += ${QT_LIBS} ${AMPACHE_LIBS}
@@ -0,0 +1,134 @@
// ampache.cc
//
// Project: Ampache Browser Audacious Plugin
// License: GNU GPLv3
//
// Copyright (C) 2015-2016 Róbert Čerňanský and John Lindgren

#include <libaudcore/audstrings.h>
#include <libaudcore/drct.h>
#include <libaudcore/i18n.h>
#include <libaudcore/runtime.h>
#include <libaudcore/plugin.h>
#include <libaudcore/playlist.h>
#include <libaudcore/vfs_async.h>

#include <ampache_browser/settings.h>
#include <ampache_browser/ampache_browser.h>
#include <ampache_browser/application_qt.h>

#define CFG_SECT "ampache_browser"

using NetworkCb = ampache_browser::ApplicationQt::NetworkRequestCb;
using UrlList = std::vector<std::string>;

class AmpacheBrowserPlugin: public GeneralPlugin
{
public:
static const char about[];

static constexpr PluginInfo pluginInfo = {
N_("Ampache Browser"),
PACKAGE,
about,
nullptr,
PluginQtOnly
};

constexpr AmpacheBrowserPlugin(): GeneralPlugin(pluginInfo, false) {}

bool init() override;
void cleanup() override;
void* get_qt_widget() override;
};

const char AmpacheBrowserPlugin::about[] =
N_("Ampache Browser\n\n"
"Ampache client for Audacious.\n\n"
"License: GNU GPLv3\n"
"Copyright (C) Róbert Čerňanský and John Lindgren\n");

static SmartPtr<ampache_browser::ApplicationQt> s_app;

static void vfsAsyncCb(const char* url, const Index<char>& data, void* callback)
{
if (s_app) // ignore callbacks after cleanup()
(*(NetworkCb*)callback)(url, data.begin(), data.len());
}

static Index<PlaylistAddItem> toAddItems(const UrlList& urls)
{
Index<PlaylistAddItem> addItems;
for (auto& url: urls)
addItems.append(String(url.c_str()));

return addItems;
}

static void initSettings(ampache_browser::Settings &settings)
{
static const std::string bool_settings[] = {
settings.USE_DEMO_SERVER
};

static const std::string str_settings[] = {
settings.SERVER_URL,
settings.USER_NAME,
settings.PASSWORD_HASH
};

auto verbosity = getenv("AMPACHE_BROWSER_PLUGIN_VERBOSITY");
settings.setInt(settings.LOGGING_VERBOSITY, verbosity ? str_to_int(verbosity) : 0);

for (auto& name: bool_settings)
settings.setBool(name, aud_get_bool(CFG_SECT, name.c_str()));
for (auto& name: str_settings)
settings.setString(name, (const char*)aud_get_str(CFG_SECT, name.c_str()));

settings.connectChanged([&settings]() {
for (auto& name: bool_settings)
aud_set_bool(CFG_SECT, name.c_str(), settings.getBool(name));
for (auto& name: str_settings)
aud_set_str(CFG_SECT, name.c_str(), settings.getString(name).c_str());
});
}

bool AmpacheBrowserPlugin::init()
{
s_app.capture(new ampache_browser::ApplicationQt);

s_app->setNetworkRequestFunction([](const std::string& url, NetworkCb& networkCb) {
vfs_async_file_get_contents(url.c_str(), vfsAsyncCb, &networkCb);
});

auto& browser = s_app->getAmpacheBrowser();

browser.connectPlay([](const UrlList& urls) {
aud_drct_pl_open_list(toAddItems(urls));
});

browser.connectCreatePlaylist([](const UrlList& urls) {
aud_playlist_entry_insert_batch(aud_playlist_new(), -1, toAddItems(urls), true);
});

browser.connectAddToPlaylist([](const UrlList& urls) {
aud_playlist_entry_insert_batch(aud_playlist_get_active(), -1, toAddItems(urls), false);
});

initSettings(s_app->getSettings());

return true;
}

void AmpacheBrowserPlugin::cleanup()
{
s_app.clear();
}

void* AmpacheBrowserPlugin::get_qt_widget()
{
s_app->run();
return s_app->getMainWidget();
}

EXPORT AmpacheBrowserPlugin aud_plugin_instance;

0 comments on commit 54c5059

Please sign in to comment.
You can’t perform that action at this time.