Commit 2a2dd551 authored by Jakob Leben's avatar Jakob Leben

services_discovery: implement SD categories and use in Qt interface

parent d269c768
......@@ -54,15 +54,23 @@ struct services_discovery_t
services_discovery_sys_t *p_sys;
};
enum services_discovery_category_e
{
SD_CAT_DEVICES = 1,
SD_CAT_LAN,
SD_CAT_INTERNET,
SD_CAT_MYCOMPUTER
};
/***********************************************************************
* Service Discovery
***********************************************************************/
/* Get the services discovery modules names to use in Create(), in a null
* terminated string array. Array and string must be freed after use. */
VLC_EXPORT( char **, vlc_sd_GetNames, ( vlc_object_t *, char *** ) );
#define vlc_sd_GetNames(obj, pln) \
vlc_sd_GetNames(VLC_OBJECT(obj), pln)
VLC_EXPORT( char **, vlc_sd_GetNames, ( vlc_object_t *, char ***, int ** ) );
#define vlc_sd_GetNames(obj, pln, pcat ) \
vlc_sd_GetNames(VLC_OBJECT(obj), pln, pcat)
/* Creation of a service_discovery object */
VLC_EXPORT( services_discovery_t *, vlc_sd_Create, ( vlc_object_t *, const char * ) );
......@@ -91,18 +99,19 @@ VLC_EXPORT( void, services_discovery_RemoveItem, ( services_di
/* SD probing */
VLC_EXPORT(int, vlc_sd_probe_Add, (vlc_probe_t *, const char *, const char *));
VLC_EXPORT(int, vlc_sd_probe_Add, (vlc_probe_t *, const char *, const char *, int category));
#define VLC_SD_PROBE_SUBMODULE \
add_submodule() \
set_capability( "services probe", 100 ) \
set_callbacks( vlc_sd_probe_Open, NULL )
#define VLC_SD_PROBE_HELPER(name, longname) \
#define VLC_SD_PROBE_HELPER(name, longname, cat) \
static int vlc_sd_probe_Open (vlc_object_t *obj) \
{ \
return vlc_sd_probe_Add ((struct vlc_probe_t *)obj, \
name "{longname=\"" # longname "\"}", longname); \
name "{longname=\"" # longname "\"}", \
longname, cat); \
}
/** @} */
......
......@@ -413,7 +413,7 @@
o_tc_sortColumn = nil;
char ** ppsz_name;
char ** ppsz_services = vlc_sd_GetNames( VLCIntf, &ppsz_name );
char ** ppsz_services = vlc_sd_GetNames( VLCIntf, &ppsz_name, NULL );
if( !ppsz_services )
return;
......
......@@ -249,46 +249,53 @@ void PLSelector::createItems()
THEPL->p_media_library );
ml->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_ML ) );
QTreeWidgetItem *mfldrs = NULL;
QTreeWidgetItem *shouts = NULL;
QTreeWidgetItem *mycomp = addItem( CATEGORY_TYPE, qtr( "My Computer" ),
false )->treeItem();
QTreeWidgetItem *devices = addItem( CATEGORY_TYPE, qtr( "Devices" ),
false )->treeItem();
QTreeWidgetItem *lan = addItem( CATEGORY_TYPE, qtr( "Local Network" ),
false )->treeItem();
QTreeWidgetItem *internet = addItem( CATEGORY_TYPE, qtr( "Internet" ),
false )->treeItem();;
char **ppsz_longnames;
char **ppsz_names = vlc_sd_GetNames( THEPL, &ppsz_longnames );
int *p_categories;
char **ppsz_names = vlc_sd_GetNames( THEPL, &ppsz_longnames, &p_categories );
if( !ppsz_names )
return;
char **ppsz_name = ppsz_names, **ppsz_longname = ppsz_longnames;
for( ; *ppsz_name; ppsz_name++, ppsz_longname++ )
int *p_category = p_categories;
for( ; *ppsz_name; ppsz_name++, ppsz_longname++, p_category++ )
{
//msg_Dbg( p_intf, "Adding a SD item: %s", *ppsz_longname );
#define SD_IS( name ) ( !strcmp( *ppsz_name, name ) )
if( SD_IS("shoutcast") || SD_IS("shoutcasttv") ||
SD_IS("frenchtv") || SD_IS("freebox") )
if( *p_category == SD_CAT_INTERNET )
{
PLSelItem *selItem = addItem( SD_TYPE, *ppsz_longname, false, internet );
putSDData( selItem, *ppsz_name, *ppsz_longname );
if( !strncmp( *ppsz_name, "podcast", 7 ) )
{
selItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) );
selItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) );
CONNECT( selItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) );
podcastsParent = selItem->treeItem();
}
}
else if( *p_category == SD_CAT_DEVICES )
{
if( !shouts ) shouts = addItem( CATEGORY_TYPE, qtr( "Shoutcast" ),
false )->treeItem();
putSDData( addItem( SD_TYPE, *ppsz_longname, false, shouts ),
putSDData( addItem( SD_TYPE, *ppsz_longname, false, devices ),
*ppsz_name, *ppsz_longname );
}
else if( SD_IS("video_dir") || SD_IS("audio_dir") || SD_IS("picture_dir") )
else if( *p_category == SD_CAT_LAN )
{
if( !mfldrs ) mfldrs = addItem( CATEGORY_TYPE, qtr( "Media Folders" ),
false )->treeItem();
putSDData( addItem( SD_TYPE, *ppsz_longname, false, mfldrs ),
putSDData( addItem( SD_TYPE, *ppsz_longname, false, lan ),
*ppsz_name, *ppsz_longname );
}
else if( !strncmp( *ppsz_name, "podcast", 7 ) )
else if( *p_category == SD_CAT_MYCOMPUTER )
{
PLSelItem *podItem = addItem( SD_TYPE, qtr( "Podcasts" ), false );
putSDData( podItem, *ppsz_name, *ppsz_longname );
podItem->treeItem()->setData( 0, SPECIAL_ROLE, QVariant( IS_PODCAST ) );
podItem->addAction( ADD_ACTION, qtr( "Subscribe to a podcast" ) );
CONNECT( podItem, action( PLSelItem* ), this, podcastAdd( PLSelItem* ) );
podcastsParent = podItem->treeItem();
putSDData( addItem( SD_TYPE, *ppsz_longname, false, mycomp ),
*ppsz_name, *ppsz_longname );
}
else
{
......@@ -296,13 +303,17 @@ void PLSelector::createItems()
*ppsz_name, *ppsz_longname );
}
#undef SD_IS
free( *ppsz_name );
free( *ppsz_longname );
}
free( ppsz_names );
free( ppsz_longnames );
free( p_categories );
if( mycomp->childCount() == 0 ) delete mycomp;
if( devices->childCount() == 0 ) delete devices;
if( lan->childCount() == 0 ) delete lan;
if( internet->childCount() == 0 ) delete internet;
}
QStringList PLSelector::mimeTypes() const
......
......@@ -708,7 +708,7 @@ QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf, QWidget *parent )
menu->setTitle( qtr( I_PL_SD ) );
char **ppsz_longnames;
char **ppsz_names = vlc_sd_GetNames( p_intf, &ppsz_longnames );
char **ppsz_names = vlc_sd_GetNames( p_intf, &ppsz_longnames, NULL );
if( !ppsz_names )
return menu;
......
......@@ -62,7 +62,7 @@ static int vlclua_sd_get_services_names( lua_State *L )
{
playlist_t *p_playlist = vlclua_get_playlist_internal( L );
char **ppsz_longnames;
char **ppsz_names = vlc_sd_GetNames( p_playlist, &ppsz_longnames );
char **ppsz_names = vlc_sd_GetNames( p_playlist, &ppsz_longnames, NULL );
if( !ppsz_names )
return 0;
......
......@@ -632,7 +632,7 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
free( psz_longname );
goto error;
}
vlc_sd_probe_Add( probe, psz_name, psz_longname );
vlc_sd_probe_Add( probe, psz_name, psz_longname, SD_CAT_INTERNET );
free( psz_name );
free( psz_longname );
}
......
......@@ -48,7 +48,7 @@
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
VLC_SD_PROBE_HELPER("bonjour", N_("Bonjour services"))
VLC_SD_PROBE_HELPER("bonjour", N_("Bonjour services"), SD_CAT_LAN)
vlc_module_begin ()
set_shortname( "Bonjour" )
......
......@@ -356,10 +356,10 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
vlc_probe_t *probe = (vlc_probe_t *)obj;
vlc_sd_probe_Add( probe, "video_dir{longname=\"My Videos\"}",
N_("My Videos") );
N_("My Videos"), SD_CAT_MYCOMPUTER );
vlc_sd_probe_Add( probe, "audio_dir{longname=\"My Music\"}",
N_("My Music") );
N_("My Music"), SD_CAT_MYCOMPUTER );
vlc_sd_probe_Add( probe, "picture_dir{longname=\"My Pictures\"}",
N_("My Pictures") );
N_("My Pictures"), SD_CAT_MYCOMPUTER );
return VLC_PROBE_CONTINUE;
}
......@@ -38,7 +38,7 @@
static int Open( vlc_object_t * );
static void Close( vlc_object_t * );
VLC_SD_PROBE_HELPER("mtp", N_("MTP devices"))
VLC_SD_PROBE_HELPER("mtp", N_("MTP devices"), SD_CAT_DEVICES)
vlc_module_begin()
set_shortname( "MTP" )
......
......@@ -53,7 +53,7 @@
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
VLC_SD_PROBE_HELPER("podcast", N_("Podcasts"))
VLC_SD_PROBE_HELPER("podcast", N_("Podcasts"), SD_CAT_INTERNET)
#define URLS_TEXT N_("Podcast URLs list")
#define URLS_LONGTEXT N_("Enter the list of podcasts to retrieve, " \
......
......@@ -114,7 +114,7 @@
static int OpenDemux ( vlc_object_t * );
static void CloseDemux ( vlc_object_t * );
VLC_SD_PROBE_HELPER("sap", N_("Network streams (SAP)"))
VLC_SD_PROBE_HELPER("sap", N_("Network streams (SAP)"), SD_CAT_LAN)
vlc_module_begin ()
set_shortname( N_("SAP"))
......
......@@ -283,10 +283,10 @@ static int vlc_sd_probe_Open( vlc_object_t *obj )
vlc_probe_t *probe = (vlc_probe_t *)obj;
vlc_sd_probe_Add( probe, "shoutcast{longname=\"Shoutcast Radio\"}",
N_("Shoutcast Radio") );
N_("Shoutcast Radio"), SD_CAT_INTERNET );
vlc_sd_probe_Add( probe, "shoutcasttv{longname=\"Shoutcast TV\"}",
N_("Shoutcast TV") );
N_("Shoutcast TV"), SD_CAT_INTERNET );
vlc_sd_probe_Add( probe, "frenchtv{longname=\"French TV\"}",
N_("French TV") );
N_("French TV"), SD_CAT_INTERNET );
return VLC_PROBE_CONTINUE;
}
......@@ -74,8 +74,8 @@ static int vlc_sd_probe_Open (vlc_object_t *obj)
if (mon != NULL)
{
vlc_sd_probe_Add (probe, "v4l{longname=\"Video capture\"}",
N_("Video capture"));
vlc_sd_probe_Add (probe, "disc{longname=\"Discs\"}", N_("Discs"));
N_("Video capture"), SD_CAT_DEVICES);
vlc_sd_probe_Add (probe, "disc{longname=\"Discs\"}", N_("Discs"), SD_CAT_MYCOMPUTER);
udev_monitor_unref (mon);
}
udev_unref (udev);
......
......@@ -58,7 +58,7 @@ using namespace CyberLink;
static int Open ( vlc_object_t * );
static void Close( vlc_object_t * );
VLC_SD_PROBE_HELPER("upnp", N_("Universal Plug'n'Play"))
VLC_SD_PROBE_HELPER("upnp", N_("Universal Plug'n'Play"), SD_CAT_LAN)
vlc_module_begin ()
set_shortname( "UPnP")
......
......@@ -55,7 +55,7 @@ struct services_discovery_sys_t
// VLC callback prototypes
static int Open( vlc_object_t* );
static void Close( vlc_object_t* );
VLC_SD_PROBE_HELPER("upnp", N_("Universal Plug'n'Play"))
VLC_SD_PROBE_HELPER("upnp", N_("Universal Plug'n'Play"), SD_CAT_LAN)
// Module descriptor
......
......@@ -80,7 +80,7 @@ static int vlc_sd_probe_Open (vlc_object_t *obj)
return VLC_PROBE_CONTINUE;
xcb_disconnect (conn);
return vlc_sd_probe_Add (probe, "xcb_apps{longname=\"Screen capture\"}",
N_("Screen capture"));
N_("Screen capture"), SD_CAT_MYCOMPUTER);
}
/**
......
......@@ -37,12 +37,13 @@ typedef struct
{
char *name;
char *longname;
int category;
} vlc_sd_probe_t;
int vlc_sd_probe_Add (vlc_probe_t *probe, const char *name,
const char *longname)
const char *longname, int category)
{
vlc_sd_probe_t names = { strdup(name), strdup(longname) };
vlc_sd_probe_t names = { strdup(name), strdup(longname), category };
if (unlikely (names.name == NULL || names.longname == NULL
|| vlc_probe_add (probe, &names, sizeof (names))))
......@@ -59,7 +60,7 @@ int vlc_sd_probe_Add (vlc_probe_t *probe, const char *name,
/**
* Gets the list of available services discovery plugins.
*/
char **vlc_sd_GetNames (vlc_object_t *obj, char ***pppsz_longnames)
char **vlc_sd_GetNames (vlc_object_t *obj, char ***pppsz_longnames, int **pp_categories)
{
size_t count;
vlc_sd_probe_t *tab = vlc_probe (obj, "services probe", &count);
......@@ -72,17 +73,22 @@ char **vlc_sd_GetNames (vlc_object_t *obj, char ***pppsz_longnames)
char **names = malloc (sizeof(char *) * (count + 1));
char **longnames = malloc (sizeof(char *) * (count + 1));
int *categories = malloc(sizeof(int) * (count + 1));
if (unlikely (names == NULL || longnames == NULL))
if (unlikely (names == NULL || longnames == NULL || categories == NULL))
abort();
for( size_t i = 0; i < count; i++ )
{
names[i] = tab[i].name;
longnames[i] = tab[i].longname;
categories[i] = tab[i].category;
}
free (tab);
names[count] = longnames[count] = NULL;
categories[count] = 0;
*pppsz_longnames = longnames;
if( pp_categories ) *pp_categories = categories;
else free( categories );
return names;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment