diff --git a/Makefile.am b/Makefile.am index 0d22faf..b5c400f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,22 +3,40 @@ SUBDIRS = po doc icons bin_PROGRAMS = gjay -gjay_LDADD = $(GTK_LIBS) $(DBUS_GLIB_LIBS) $(GSL_LIBS) -AM_CFLAGS = -Wall $(GTK_CFLAGS) $(DBUS_GLIB_CFLAGS) $(GSL_CFLAGS) +gjay_LDADD = $(GLIB_LIBS) $(GTK_LIBS) $(DBUS_GLIB_LIBS) $(GSL_LIBS) +AM_CFLAGS = -Wall $(GLIB_CFLAGS) $(GTK_CFLAGS) $(DBUS_GLIB_CFLAGS) $(GSL_CFLAGS) -gjay_SOURCES = gjay.h songs.h prefs.h ui.h rgbhsv.h analysis.h playlist.h \ +extra_DIST = +gjay_SOURCES = gjay.h songs.h prefs.h rgbhsv.h analysis.h playlist.h \ ipc.h constants.h vorbis.h mp3.h flac.h i18n.h \ dbus.h util.h \ - gjay.c dbus.c ipc.c prefs.c songs.c rgbhsv.c ui.c \ - ui_explore_view.c ui_prefs_view.c ui_selection_view.c \ - ui_playlist_view.c ui_colorwheel.c \ - ui_menubar.c analysis.c playlist.c \ + gjay.c dbus.c ipc.c prefs.c songs.c rgbhsv.c \ + analysis.c playlist.c \ vorbis.c mp3.c flac.c util.c \ - play_common.c play_common.h \ - play_audacious.c play_audacious.h \ - play_mpdclient.c play_mpdclient.h + play_common.c play_common.h #play_exaile.h play_exaile.c +if WITH_GUI + gjay_SOURCES += ui.h ui.c ui_menubar.c\ + ui_explore_view.c ui_prefs_view.c ui_selection_view.c \ + ui_playlist_view.c ui_colorwheel.c +else + extra_DIST += ui.c \ + ui_explore_view.c ui_prefs_view.c ui_selection_view.c \ + ui_playlist_view.c ui_colorwheel.c +endif + +if WITH_AUDCLIENT +gjay_SOURCES += play_audacious.c play_audacious.h +else + extra_DIST += play_audacious.c play_audacious.h +endif + +if WITH_MPDCLIENT +gjay_SOURCES += play_mpdclient.c play_mpdclient.h +else + extra_DIST += play_mpdclient.c play_mpdclient.h +endif #ddui_colorbox.c ACLOCAL_AMFLAGS = -I m4 diff --git a/config.h.in b/config.h.in index 143620f..2b3faa2 100644 --- a/config.h.in +++ b/config.h.in @@ -94,5 +94,8 @@ /* Build with dbus-glib */ #undef WITH_DBUSGLIB +/* Enable Gtk graphical interface */ +#undef WITH_GUI + /* Enable mpd music player */ #undef WITH_MPDCLIENT diff --git a/configure.ac b/configure.ac index 72375a0..e161000 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,19 @@ dnl Options # Don't require D-Bus unless building a component that needs it: enable_dbus=no +AC_SUBST([WITH_GUI]) +AC_ARG_ENABLE([gui], + AS_HELP_STRING([--disable-gui], [Disable the Gtk graphical interface]), + [enable_gui=$enableval], + [enable_gui="yes"]) +if test "$enable_gui" = "yes"; then + AC_DEFINE([WITH_GUI], [1], [Enable Gtk graphical interface]) + PKG_CHECK_MODULES([GTK], [gtk+-2.0]) +else + PKG_CHECK_MODULES([GLIB], [glib-2.0]) +fi +AM_CONDITIONAL([WITH_GUI], [test "$enable_gui" = "yes"]) + AC_SUBST([WITH_MPDCLIENT]) AC_ARG_ENABLE([mpdclient], AS_HELP_STRING([--with-mpdclient], [Enable mpd client(default is YES)]), @@ -26,6 +39,7 @@ if test "$enable_mpdclient" = "yes"; then AC_DEFINE([WITH_MPDCLIENT], [1], [Enable mpd music player]) PKG_CHECK_MODULES([MPDCLIENT], [libmpdclient]) fi +AM_CONDITIONAL([WITH_MPDCLIENT], [test "$enable_mpdclient" = "yes"]) AC_SUBST([WITH_AUDCLIENT]) AC_ARG_ENABLE([audclient], @@ -37,13 +51,13 @@ if test "$enable_audclient" = "yes"; then AC_DEFINE([WITH_AUDCLIENT], [1], [Enable Audacious music player]) PKG_CHECK_MODULES([AUDACIOUS], [audacious]) fi +AM_CONDITIONAL([WITH_AUDCLIENT], [test "$enable_audclient" = "yes"]) dnl Check for language stuff AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION([0.18.1]) # Checks for libraries. -PKG_CHECK_MODULES([GTK], [gtk+-2.0]) if test "$enable_dbus" = "yes"; then AC_DEFINE([WITH_DBUSGLIB], [1], [Build with dbus-glib]) diff --git a/gjay.c b/gjay.c index 205065e..0bf392f 100644 --- a/gjay.c +++ b/gjay.c @@ -56,6 +56,7 @@ #include "vorbis.h" #include "flac.h" #include "ui.h" + #include "i18n.h" #include "play_common.h" @@ -75,7 +76,9 @@ static gint ping_daemon ( gpointer data ); static gboolean create_ui_daemon_pipe(void); static gboolean mode_attached ( gjay_mode m ); static void fork_or_connect_to_daemon(void); +#ifdef WITH_GUI static void run_as_ui (int argc, char * argv[]); +#endif /* WITH_GUI */ static void run_as_playlist ( guint playlist_minutes, gboolean m3u_format, gboolean player_autostart ); @@ -247,17 +250,21 @@ int main( int argc, char *argv[] ) { if (verbosity) printf(_("FLAC not supported.\n")); +#ifdef WITH_GUI if (mode == UI) { /* UI needs a daemon */ fork_or_connect_to_daemon(); } +#endif /* WITH_GUI */ switch(mode) { +#ifdef WITH_GUI case UI: read_data_file(); sleep(1); run_as_ui(argc, argv); break; +#endif /* WITH_GUI */ case PLAYLIST: read_data_file(); run_as_playlist(playlist_minutes, m3u_format, player_autostart); @@ -453,6 +460,7 @@ fork_or_connect_to_daemon(void) } } +#ifdef WITH_GUI static void run_as_ui(int argc, char *argv[] ) { @@ -520,6 +528,7 @@ static void run_as_ui(int argc, char *argv[] ) close(daemon_pipe_fd); close(ui_pipe_fd); } +#endif /* WITH_GUI */ /* Playlist mode */ @@ -548,13 +557,16 @@ void gjay_message_log(const gchar *log_domain, const gchar *message, gpointer user_data) { +#ifdef WITH_GUI GtkWidget *msg_window = GTK_WIDGET(user_data); GtkWidget *msg_text_view; GtkTextBuffer *buffer; if (mode != UI) { +#endif /* WITH_GUI */ printf("%s\n", message); return; +#ifdef WITH_GUI } msg_text_view = GTK_WIDGET(g_object_get_data(G_OBJECT(msg_window), "text_view")); @@ -564,5 +576,6 @@ void gjay_message_log(const gchar *log_domain, strlen(message)); gtk_text_buffer_insert_at_cursor(buffer, "\n", 1); gtk_widget_show_all (GTK_WIDGET(msg_window)); +#endif /* WITH_GUI */ } diff --git a/gjay.h b/gjay.h index 4be9e16..b683f66 100644 --- a/gjay.h +++ b/gjay.h @@ -23,12 +23,14 @@ #include "util.h" /* Global definitions */ -#define AUDACIOUS_BIN "/usr/bin/audacious2" +#define AUDACIOUS_BIN "/usr/bin/audacious" #define EXAILE_BIN "/usr/bin/exaile" #include -#include #include +#ifdef WITH_GUI +#include +#endif /* WITH_GUI */ #include #include #include @@ -44,7 +46,6 @@ extern GjayApp *gjay; #include "rgbhsv.h" #include "songs.h" #include "prefs.h" -//#include "ui.h" /* Helper programs */ #define OGG_DECODER_APP "ogg123" @@ -91,11 +92,12 @@ struct _GjayApp { #endif /* WITH_MPDCLIENT */ - //GdkPixbuf * pixbufs[PM_LAST]; +#ifdef WITH_GUI GdkPixbuf * pixbufs[50]; //FIXME GtkTooltips * tips; GtkWidget * explore_view, * selection_view, * playlist_view, * no_root_view, * prefs_view, * about_view; +#endif /* WITH_GUI */ GList * selected_songs, * selected_files; /* We store a list of the directories which contain new songs (ie. lack * rating/color info */ @@ -103,11 +105,13 @@ struct _GjayApp { GHashTable * new_song_dirs_hash; gint tree_depth; /* How deep does the tree go */ +#ifdef WITH_GUI /* Various Windows */ GtkWidget *main_window; GtkWidget *notebook; GtkWidget * prefs_window; GtkWidget * message_window; +#endif /* WITH_GUI */ /* Songs */ diff --git a/play_audacious.c b/play_audacious.c index 93e5f52..d87c67d 100644 --- a/play_audacious.c +++ b/play_audacious.c @@ -31,6 +31,7 @@ #include #include #include +#include #include "gjay.h" #include "songs.h" #include "dbus.h" @@ -57,7 +58,8 @@ audacious_init(void) if ( (lib = dlopen("libaudclient.so.2", RTLD_GLOBAL | RTLD_LAZY)) == NULL) { - gjay_error_dialog(_("Unable to open audcious client library, defaulting to no play.")); + gjay_error_dialog( + _("Unable to open audcious client library, defaulting to no play.")); return FALSE; } if ( (gjaud_get_playlist_pos = gjay_dlsym(lib, "audacious_remote_get_playlist_pos")) == NULL) diff --git a/play_common.c b/play_common.c index 0e842f0..5077577 100644 --- a/play_common.c +++ b/play_common.c @@ -91,6 +91,7 @@ void play_songs (GList *slist) { if (!gjay->player_is_running()) { +#ifdef WITH_GUI GtkWidget *dialog; gint result; gchar *msg; @@ -124,6 +125,14 @@ void play_songs (GList *slist) { } } else /* user clicked no */ return; +#else + /* with no GUI assume you want it started */ + if (gjay->player_start() == FALSE) + { + g_warning(_("Unable to start %s"), gjay->prefs->music_player_name); + return; + } +#endif /* WITH_GUI */ } gjay->player_play_files(list); } diff --git a/play_mpdclient.c b/play_mpdclient.c index 6af22bb..b684505 100644 --- a/play_mpdclient.c +++ b/play_mpdclient.c @@ -56,7 +56,7 @@ mpdclient_init(void) if ( (lib = dlopen("libmpdclient.so.2", RTLD_GLOBAL | RTLD_LAZY)) == NULL) { - gjay_error_dialog(_("Unable to open mpd client library")); + gjay_error_dialog( _("Unable to open mpd client library")); return FALSE; } @@ -144,7 +144,11 @@ mpdclient_play_files ( GList *list) { if ( (*gjmpd_run_stop)(gjay->mpdclient_connection) == FALSE) { errmsg = g_strdup_printf(_("Cannot stop Music Player Daemon: %s"), (*gjmpd_connection_get_error_message)(gjay->mpdclient_connection)); +#ifdef WITH_GUI gjay_error_dialog(errmsg); +#else + g_error(errmsg); +#endif /* WITH_GUI */ g_free(errmsg); } if ( (*gjmpd_run_clear)(gjay->mpdclient_connection) == FALSE) { diff --git a/rgbhsv.h b/rgbhsv.h index 2f5fffa..f03af84 100644 --- a/rgbhsv.h +++ b/rgbhsv.h @@ -19,7 +19,10 @@ #ifndef _RGBHSB_H_ #define _RGBHSB_H_ +#include +#ifdef WITH_GUI #include +#endif /* WITH_GUI */ typedef struct {float R, G, B;} RGB; typedef struct {float H, S, V;} HSV; diff --git a/songs.c b/songs.c index ea95d36..136a347 100644 --- a/songs.c +++ b/songs.c @@ -35,8 +35,8 @@ #include "mp3.h" #include "vorbis.h" #include "flac.h" -#include "ui.h" #include "i18n.h" +#include "ui.h" typedef enum { @@ -139,10 +139,12 @@ song * create_song ( void ) { } void delete_song (song * s) { +#ifdef WITH_GUI if(s->freq_pixbuf) gdk_pixbuf_unref(s->freq_pixbuf); if(s->color_pixbuf) gdk_pixbuf_unref(s->color_pixbuf); +#endif /* WITH_GUI */ g_free(s->path); g_free(s->title); g_free(s->artist); @@ -167,6 +169,7 @@ song * song_set_path ( song * s, } +#ifdef WITH_GUI /** * If the song does not have a pixbuf for its frequency, and it has been * analyzed, create a pixbuf for its frequency. @@ -239,6 +242,7 @@ void song_set_color_pixbuf ( song * s) { } } } +#endif /* WITH_GUI */ /** @@ -267,8 +271,10 @@ void song_set_repeats ( song * s, song * original ) { s->fname = fname; s->repeat_prev = NULL; s->repeat_next = NULL; +#ifdef WITH_GUI s->freq_pixbuf = NULL; s->color_pixbuf = NULL; +#endif /* WITH_GUI */ for (ll = original; ll->repeat_next; ll = ll->repeat_next) ; @@ -933,7 +939,7 @@ gdouble song_force ( song * a, song * b ) { /* Attraction is a value -1...1 for the affinity between A and B, with criteria weighed by prefs */ gdouble song_attraction (song * a, song * b ) { - gdouble a_hue, a_saturation, a_brightness, a_freq, a_bpm, a_path; + gdouble a_hue, a_saturation, a_brightness, a_freq, a_bpm; gdouble d, ba, bb, v_diff, a_max, attraction = 0; gint i; GjayPrefs *prefs = gjay->prefs; @@ -951,7 +957,6 @@ gdouble song_attraction (song * a, song * b ) { a_saturation = prefs->saturation / a_max; a_freq = prefs->freq / a_max; a_bpm = prefs->bpm / a_max; - a_path = prefs->path_weight / a_max; if (!(a->no_color || b->no_color)) { /* Hue is 0...6 */ @@ -1009,7 +1014,10 @@ gdouble song_attraction (song * a, song * b ) { attraction += d * a_freq; } +#ifdef WITH_GUI + /* FIXME - This is not really a GUI thing but a function using Gtk */ if (gjay->tree_depth && a->path && b->path) { + gdouble a_path = prefs->path_weight / a_max; d = explore_files_depth_distance(a->path, b->path); if (d >= 0) { d = 1.0 - 2.0 * (d / gjay->tree_depth); @@ -1017,6 +1025,7 @@ gdouble song_attraction (song * a, song * b ) { attraction += d * a_path; } } +#endif /* WITH_GUI */ return attraction; } diff --git a/songs.h b/songs.h index 77bb92c..9ea9cbc 100644 --- a/songs.h +++ b/songs.h @@ -78,9 +78,11 @@ struct _song { gboolean in_tree; gboolean marked; +#ifdef WITH_GUI /* Transient display pixbuf */ GdkPixbuf * freq_pixbuf; GdkPixbuf * color_pixbuf; +#endif /* WITH_GUI */ /* How to tell if two songs with different paths are the same song (symlinked, most likely) */ @@ -100,8 +102,10 @@ song * create_song ( void ); void delete_song ( song * s ); song * song_set_path ( song * s, char * path ); +#ifdef WITH_GUI void song_set_freq_pixbuf ( song * s); void song_set_color_pixbuf ( song * s); +#endif /* WITH_GUI */ void song_set_repeats ( song * s, song * original ); void song_set_repeat_attrs ( song * s); diff --git a/ui.h b/ui.h index 06aec2b..23ef2f1 100644 --- a/ui.h +++ b/ui.h @@ -20,6 +20,7 @@ #ifndef __UI_H__ #define __UI_H__ + #include "gjay.h" #define APP_WIDTH 620 @@ -74,6 +75,7 @@ typedef enum { #define PM_ABOUT "about.png" +#ifdef WITH_GUI /* UI utils */ GdkPixbuf * load_gjay_pixbuf(const char *filename); GtkWidget * new_button_label_pixbuf ( char * label_text, @@ -144,7 +146,9 @@ void set_playlist_rating_visible ( gboolean is_visible ); /* Menu */ GtkWidget * make_menubar ( void ); +#else +#define gjay_error_dialog(msg) g_error(msg) +#endif /* WITH_GUI */ #endif /* __UI_H__ */ - diff --git a/ui_explore_view.c b/ui_explore_view.c index 413675d..4ecf02e 100644 --- a/ui_explore_view.c +++ b/ui_explore_view.c @@ -644,30 +644,6 @@ static int file_depth ( char * file ) { -/* How many directory steps separate files 1 and 2? */ -gint explore_files_depth_distance ( char * file1, - char * file2 ) { - char buffer[BUFFER_SIZE]; - int f1, f2, shared, k, len; - - len = MIN(MIN(strlen(file1), strlen(file2)), BUFFER_SIZE); - for (k = 0; (k < len) && (file1[k] == file2[k]); k++) - buffer[k] = file1[k]; - /* Work backwards to find forward slash in common */ - while(buffer[k] != '/') - k--; - /* Replace slash with null termination */ - buffer[k] = '\0'; - f1 = file_iter_depth(file1); - f2 = file_iter_depth(file2); - shared = file_iter_depth(buffer) + 1; - - if (f1 && f2 && shared) - return ((f1 - shared) + (f2 - shared)); - else - return -1; -} - void explore_animate_pending ( char * file ) { explore_animate_stop(); @@ -855,4 +831,28 @@ static int gjay_ftw(const char *dir, return retval; } +/* How many directory steps separate files 1 and 2? */ +gint explore_files_depth_distance ( char * file1, + char * file2 ) { + char buffer[BUFFER_SIZE]; + int f1, f2, shared, k, len; + + len = MIN(MIN(strlen(file1), strlen(file2)), BUFFER_SIZE); + for (k = 0; (k < len) && (file1[k] == file2[k]); k++) + buffer[k] = file1[k]; + /* Work backwards to find forward slash in common */ + while(buffer[k] != '/') + k--; + /* Replace slash with null termination */ + buffer[k] = '\0'; + f1 = file_iter_depth(file1); + f2 = file_iter_depth(file2); + shared = file_iter_depth(buffer) + 1; + + if (f1 && f2 && shared) + return ((f1 - shared) + (f2 - shared)); + else + return -1; +} + diff --git a/util.h b/util.h index 0abb075..68ba55b 100644 --- a/util.h +++ b/util.h @@ -32,7 +32,7 @@ gchar * strdup_convert ( const gchar * str, const gchar * enc_to, const gchar * enc_from ); #else -#define strdup_convert(str, enc_to, enc_from) (g_strdup(str)) +#define strdup_convert(str, length, enc_to, enc_from) (g_strdup(str)) #endif /* ASSUME_LATIN1 */ float strtof_gjay ( const char * nptr,