Added notification support.
This commit is contained in:
parent
619b415d29
commit
0cc5b6af27
10 changed files with 125 additions and 22 deletions
8
Makefile
8
Makefile
|
@ -4,7 +4,7 @@
|
|||
|
||||
include config.mk
|
||||
|
||||
SRC = pipeplayer.c dirname.c player.c playlist.c list.c threads.c pipe.c
|
||||
SRC = pipeplayer.c dirname.c player.c playlist.c list.c threads.c pipe.c $(NOTIFY_SRC)
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
all: options $(NAME)
|
||||
|
@ -19,10 +19,10 @@ options:
|
|||
$(CC) $(CFLAGS) -c $<
|
||||
|
||||
log.h: config.h loglevels.h
|
||||
threads.o: commands.h playlist.h player.h log.h threads.h pipe.h
|
||||
playlist.o: playlist.h dirname.h list.h log.h
|
||||
threads.o: commands.h playlist.h player.h log.h threads.h pipe.h config.h
|
||||
playlist.o: playlist.h dirname.h list.h log.h config.h
|
||||
player.o: player.h config.h log.h
|
||||
pipeplayer.o: player.h playlist.h threads.h pipe.h
|
||||
pipeplayer.o: player.h playlist.h threads.h pipe.h config.h
|
||||
pipe.o: pipe.h
|
||||
list.o: list.h
|
||||
|
||||
|
|
|
@ -86,6 +86,9 @@ sudo make install
|
|||
If you prefer gcc, then run `make CC=gcc` instead of `make`.
|
||||
Also, if you prefer clang, run `make CC=clang.`
|
||||
|
||||
Replace `make` with `make NOTIFICATION=0` if you want to disable notification.
|
||||
Make sure you change NOTIFICATION variable in `config.h`.
|
||||
|
||||
Here some tips for installing dependencies on some distros:
|
||||
|
||||
### Archlinux and arch-based distros
|
||||
|
@ -100,7 +103,7 @@ Guides for other distibutions will appear in future. If you know one, feel free
|
|||
- [x] Add pause command
|
||||
- [x] Add clear playlist command
|
||||
- [ ] Add navigation inside song
|
||||
- [ ] Add notification support
|
||||
- [x] Add notification support
|
||||
|
||||
## Bugs
|
||||
|
||||
|
|
9
config.h
9
config.h
|
@ -13,4 +13,13 @@
|
|||
// Levels (see log.h)
|
||||
#define LOGGING_LEVEL INFO
|
||||
|
||||
/* 0 - don't show notifications
|
||||
* 1 - show notification
|
||||
* You must compile with NOTIFICATION=1 to enable this */
|
||||
#define NOTIFICATION 1
|
||||
|
||||
// Notification information
|
||||
#define APP_NAME "Pipeplayer"
|
||||
#define SUMMARY "Pipeplayer"
|
||||
|
||||
#endif /* __CONFIG_H__ */
|
||||
|
|
18
config.mk
18
config.mk
|
@ -1,9 +1,9 @@
|
|||
# Customize below to fit your system
|
||||
# Customize below to fit your system
|
||||
PREFIX = /usr/local
|
||||
MANPREFIX = $(PREFIX)/share/man
|
||||
|
||||
# Name of program
|
||||
VERSION = 1.3.1
|
||||
VERSION = 1.4.0
|
||||
NAME = pipeplayer
|
||||
|
||||
# Compiler
|
||||
|
@ -13,6 +13,16 @@ PKG_CONFIG = pkg-config
|
|||
|
||||
LIBS = -lpthread `$(PKG_CONFIG) -libs libmpg123 ao`
|
||||
|
||||
# Options
|
||||
NOTIFICATION = 1
|
||||
|
||||
# Notification support
|
||||
ifeq ($(NOTIFICATION),1)
|
||||
NOTIFY_LIBS = `$(PKG_CONFIG) -libs libnotify`
|
||||
NOTIFY_INCS = `$(PKG_CONFIG) -cflags libnotify`
|
||||
NOTIFY_SRC = notify.c
|
||||
endif
|
||||
|
||||
# Flags
|
||||
CFLAGS = -O2 -Wall
|
||||
LDFLAGS = -O2 -s $(LIBS)
|
||||
CFLAGS = -O2 -Wall $(NOTIFY_INCS)
|
||||
LDFLAGS = -O2 -s $(LIBS) $(NOTIFY_LIBS)
|
||||
|
|
16
notify.c
Normal file
16
notify.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "notify.h"
|
||||
#include "config.h"
|
||||
|
||||
void
|
||||
init_notification()
|
||||
{
|
||||
notify_init(APP_NAME);
|
||||
notification = notify_notification_new(SUMMARY, "", NULL);
|
||||
}
|
||||
|
||||
void
|
||||
notify(const char *string)
|
||||
{
|
||||
notify_notification_update(notification, SUMMARY, string, NULL);
|
||||
notify_notification_show(notification, ¬ification_error);
|
||||
}
|
12
notify.h
Normal file
12
notify.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef __NOTIFY_H__
|
||||
#define __NOTIFY_H__
|
||||
|
||||
#include <libnotify/notify.h>
|
||||
|
||||
static NotifyNotification *notification;
|
||||
static GError *notification_error = NULL;
|
||||
|
||||
void init_notification();
|
||||
void notify(const char *string);
|
||||
|
||||
#endif /* __NOTIFY_H__ */
|
10
pipeplayer.c
10
pipeplayer.c
|
@ -11,6 +11,11 @@
|
|||
#include "playlist.h"
|
||||
#include "threads.h"
|
||||
#include "pipe.h"
|
||||
#include "config.h"
|
||||
|
||||
#if NOTIFICATION == 1
|
||||
#include "notify.h"
|
||||
#endif
|
||||
|
||||
// Function on Ctrl-C
|
||||
void
|
||||
|
@ -74,6 +79,11 @@ main(int argc, char *argv[])
|
|||
// Initialize player
|
||||
init_player(player_ptr);
|
||||
|
||||
#if NOTIFICATION == 1
|
||||
// Initialize notification
|
||||
init_notification();
|
||||
#endif
|
||||
|
||||
// Create and join input thread
|
||||
run_threads(player_ptr, playlist_ptr, pipe);
|
||||
|
||||
|
|
51
playlist.c
51
playlist.c
|
@ -7,6 +7,11 @@
|
|||
#include "dirname.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
#include "config.h"
|
||||
|
||||
#if NOTIFICATION == 1
|
||||
#include "notify.h"
|
||||
#endif
|
||||
|
||||
void
|
||||
free_playlist(struct playlist *playlist)
|
||||
|
@ -20,8 +25,11 @@ free_playlist(struct playlist *playlist)
|
|||
for (playlist->index = 0; playlist->index < playlist->length; playlist->index++)
|
||||
free(playlist->array[playlist->index]);
|
||||
|
||||
// Clear array
|
||||
// Clear array(s)
|
||||
free(playlist->array);
|
||||
#if NOTIFICATION == 1
|
||||
free(playlist->names_array);
|
||||
#endif
|
||||
|
||||
// Clear playlist dir
|
||||
free(playlist->dir);
|
||||
|
@ -29,6 +37,19 @@ free_playlist(struct playlist *playlist)
|
|||
playlist->need_free = false;
|
||||
}
|
||||
|
||||
void
|
||||
_copy_list_to_array(node_t **current, char **array, size_t count)
|
||||
{
|
||||
node_t *list = *current;
|
||||
|
||||
for (size_t index = 0; index < count; index++) {
|
||||
*current = (*current)->next;
|
||||
array[index] = (*current)->str;
|
||||
}
|
||||
|
||||
free(list);
|
||||
}
|
||||
|
||||
void
|
||||
load_playlist(struct playlist *playlist)
|
||||
{
|
||||
|
@ -60,14 +81,26 @@ load_playlist(struct playlist *playlist)
|
|||
node_t *list = new_node(NULL),
|
||||
*current = list;
|
||||
|
||||
#if NOTIFICATION == 1
|
||||
node_t *names_list = new_node(NULL),
|
||||
*current_name = names_list;
|
||||
#endif
|
||||
|
||||
// Read lines
|
||||
while ((read = getline(&line, &len, fp)) != EOF) {
|
||||
// "read" is length of string
|
||||
current = new_node(current);
|
||||
line[read - 1] = '\0';
|
||||
|
||||
current->str = (char *) malloc(read + length);
|
||||
strncpy(current->str, playlist->dir, length);
|
||||
strncpy(current->str + length, line, read);
|
||||
|
||||
#if NOTIFICATION == 1
|
||||
current_name = new_node(current_name);
|
||||
current_name->str = (char *) malloc(read - 4);
|
||||
strncpy(current_name->str, line, read - 5);
|
||||
#endif
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -75,18 +108,14 @@ load_playlist(struct playlist *playlist)
|
|||
playlist->need_free = true;
|
||||
playlist->length = count;
|
||||
|
||||
// Allocate array
|
||||
// Allocate array(s) and copy strings
|
||||
playlist->array = (char **) malloc(count * sizeof(char *));
|
||||
_copy_list_to_array(&list, playlist->array, count);
|
||||
|
||||
// Copy strings (pointers) from list to array
|
||||
current = list;
|
||||
for (size_t index = 0; index < count; index++) {
|
||||
current = current->next;
|
||||
playlist->array[index] = current->str;
|
||||
}
|
||||
|
||||
// Clear list
|
||||
free_list(list);
|
||||
#if NOTIFICATION == 1
|
||||
playlist->names_array = (char **) malloc(count * sizeof(char *));
|
||||
_copy_list_to_array(&names_list, playlist->names_array, count);
|
||||
#endif
|
||||
|
||||
// Close file and free line
|
||||
fclose(fp);
|
||||
|
|
|
@ -3,11 +3,15 @@
|
|||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include "config.h"
|
||||
|
||||
struct playlist {
|
||||
char *path, *dir, **array;
|
||||
size_t index, length;
|
||||
bool need_free, need_cancel;
|
||||
#if NOTIFICATION == 1
|
||||
char **names_array;
|
||||
#endif
|
||||
};
|
||||
|
||||
void free_playlist(struct playlist *);
|
||||
|
|
14
threads.c
14
threads.c
|
@ -10,6 +10,11 @@
|
|||
#include "log.h"
|
||||
#include "threads.h"
|
||||
#include "pipe.h"
|
||||
#include "config.h"
|
||||
|
||||
#if NOTIFICATION == 1
|
||||
#include "notify.h"
|
||||
#endif
|
||||
|
||||
void
|
||||
run_threads(struct mpg_player *player, struct playlist *playlist, char *pipe_path)
|
||||
|
@ -33,6 +38,7 @@ play_thread(void *vargp)
|
|||
struct thread_arg *arg = (struct thread_arg *)vargp;
|
||||
struct playlist *playlist = arg->playlist;
|
||||
struct mpg_player *player = arg->player;
|
||||
char *current;
|
||||
|
||||
LOG_DEBUG("Starting player thread");
|
||||
LOG_DEBUG("playlist->path = %s", playlist->path);
|
||||
|
@ -54,8 +60,12 @@ play_thread(void *vargp)
|
|||
playlist->need_cancel = true;
|
||||
|
||||
for (; playlist->index < playlist->length; playlist->index++) {
|
||||
prepare_to_play(player, playlist->array[playlist->index]);
|
||||
LOG_INFO("Playing %s", playlist->array[playlist->index]);
|
||||
current = playlist->array[playlist->index];
|
||||
prepare_to_play(player, current);
|
||||
LOG_INFO("Playing %s", current);
|
||||
#if NOTIFICATION == 1
|
||||
notify(playlist->names_array[playlist->index]);
|
||||
#endif
|
||||
play(player);
|
||||
|
||||
// If paused
|
||||
|
|
Loading…
Reference in a new issue