Exemplo n.º 1
0
/* Add a set of files to play list */
bool_t plist_add_set( plist_t *pl, plist_set_t *set )
{
	/* Do nothing if set is empty */
	if (pl == NULL || set == NULL)
		return FALSE;

	int plist_num = 0;

	for ( struct tag_plist_set_t *node = set->m_head; node; node = node->m_next )
	{
		/* glob patterns */
		if (set->m_patterns && !fu_is_prefixed(node->m_name))
		{
			glob_t gl;
			if (glob(node->m_name, GLOB_TILDE, NULL, &gl))
				continue;

			for ( char **path = gl.gl_pathv; *path; ++path )
				plist_num += plist_add_path(pl, *path);

			globfree(&gl);
		}
		/* or just a path */
		else
			plist_num += plist_add_path(pl, node->m_name);
	}

	/* Set info */
	plist_flush_scheduled(pl);
	
	/* Store undo information */
	if (player_store_undo && plist_num)
	{
		struct tag_undo_list_item_t *undo;
		undo = (struct tag_undo_list_item_t *)malloc(sizeof(*undo));
		undo->m_type = UNDO_ADD;
		undo->m_next = undo->m_prev = NULL;
		undo->m_data.m_add.m_num_songs = plist_num;
		undo->m_data.m_add.m_set = plist_set_dup(set);
		undo_add(player_ul, undo);
	}

	/* Sort added songs if need */
	if (cfg_get_var_int(cfg_list, "sort-on-load") && player_store_undo)
	{
		char *type = cfg_get_var(cfg_list, "sort-on-load-type");
		int cr = -1;

		/* Determine criteria */
		if (type == NULL)
			cr = PLIST_SORT_BY_PATH;
		else if (!strcmp(type, "sort-by-path-and-file"))
			cr = PLIST_SORT_BY_PATH;
		else if (!strcmp(type, "sort-by-title"))
			cr = PLIST_SORT_BY_TITLE;
		else if (!strcmp(type, "sort-by-file-name"))
			cr = PLIST_SORT_BY_NAME;
		else if (!strcmp(type, "sort-by-path-and-track"))
			cr = PLIST_SORT_BY_TRACK;
		if (cr >= 0)
		{
			plist_sort_bounds(pl, pl->m_len - plist_num, pl->m_len - 1, cr);
		}
	}

	return TRUE;
} /* End of 'plist_add_set' function */
Exemplo n.º 2
0
/* Search for string */
bool_t plist_search( plist_t *pl, char *pstr, int dir, int criteria )
{
	int i, count = 0;
	bool_t found = FALSE;

	assert(pl);
	if (!pl->m_len)
		return FALSE;

	/* Search */
	for ( i = pl->m_sel_end, count = 0; count < pl->m_len && !found; count ++ )
	{
		char *str;
		song_t *s;
		
		/* Go to next song */
		i += dir;
		if (i < 0 && dir < 0)
			i = pl->m_len - 1;
		else if (i >= pl->m_len && dir > 0)
			i = 0;

		/* Search for specified string */
		s = pl->m_list[i];
		if (criteria != PLIST_SEARCH_TITLE && s->m_info == NULL)
			continue;
		switch (criteria)
		{
		case PLIST_SEARCH_TITLE:
			str = STR_TO_CPTR(s->m_title);
			break;
		case PLIST_SEARCH_NAME:
			str = s->m_info->m_name;
			break;
		case PLIST_SEARCH_ARTIST:
			str = s->m_info->m_artist;
			break;
		case PLIST_SEARCH_ALBUM:
			str = s->m_info->m_album;
			break;
		case PLIST_SEARCH_YEAR:
			str = s->m_info->m_year;
			break;
		case PLIST_SEARCH_GENRE:
			str = s->m_info->m_genre;
			break;
		case PLIST_SEARCH_COMMENT:
			str = s->m_info->m_comments;
			break;
		case PLIST_SEARCH_OWN:
			str = s->m_info->m_own_data;
			break;
		case PLIST_SEARCH_TRACK:
			str = s->m_info->m_track;
			break;
		}
		found = util_search_regexp(pstr, str, 
				cfg_get_var_int(cfg_list, "search-nocase"));
		if (found)
			plist_move(pl, i, FALSE);
	} 

	return found;
} /* End of 'plist_search' function */
Exemplo n.º 3
0
/* Start the server */
bool_t server_start( void )
{
	struct sockaddr_in addr;
	int err, i;

	int server_port = cfg_get_var_int(cfg_list, "server-port");
	if (!server_port)
		server_port = 0x4D50; /* 'MP' / 19792 */

	int server_port_pool_size = cfg_get_var_int(cfg_list, "server-port-pool-size");
	if (!server_port_pool_size)
		server_port_pool_size = 10;

	logger_message(player_log, 0, _("Starting the server at port %d"), server_port);

	/* Create socket */
	server_socket = socket(AF_INET, SOCK_STREAM, 0);
	if (server_socket == -1)
	{
		logger_error(player_log, 0,
				_("Server socket creation failed: %s"),
				strerror(errno));
		goto failed;
	}

	/* Bind */
	for ( int i = 0; i < server_port_pool_size; i++, server_port++ )
	{
		addr.sin_addr.s_addr = INADDR_ANY;
		addr.sin_port = htons(server_port);
		addr.sin_family = AF_INET;
		if (bind(server_socket, (struct sockaddr*)&addr, sizeof(addr)) != -1)
			goto bind_succeeded;
		else
			logger_error(player_log, 0,
					_("Server socket bind at port %d failed: %s"),
					server_port, strerror(errno));
	}

bind_succeeded:

	logger_message(player_log, 0, _("Server listening at port %d"), server_port);

	/* Listen */
	if (listen(server_socket, 5) == -1)
	{
		logger_error(player_log, 0,
				_("Server socket listen failed: %s"),
				strerror(errno));
		goto failed;
	}

	/* Create rdwn */
	server_rdwn = rd_with_notify_new(server_socket);
	if (!server_rdwn)
	{
		logger_error(player_log, 0,
				_("Server notification pipe create failed: %s"),
				strerror(errno));
		goto failed;
	}

	/* Start the main thread */
	err = pthread_create(&server_tid, NULL, server_thread, NULL);
	if (err)
	{
		logger_error(player_log, 0,
				_("Server thread create failed: %s"),
				strerror(err));
		goto failed;
	}

	/* Install hook handler */
	server_hook_id = pmng_add_hook_handler(player_pmng, server_hook_handler);

	return TRUE;

failed:
	if (server_socket != -1)
	{
		close(server_socket);
		server_socket = -1;
	}
	if (server_rdwn)
	{
		rd_with_notify_free(server_rdwn);
		server_rdwn = NULL;
	}
	return FALSE;
} /* End of 'server_start' function */