pax_global_header00006660000000000000000000000064115031470530014511gustar00rootroot0000000000000052 comment=8a139165146275727874d1baa0de37886a1d26ea gkrellm-gkrellmpc-0.1~beta10/000077500000000000000000000000001150314705300161575ustar00rootroot00000000000000gkrellm-gkrellmpc-0.1~beta10/Changelog000066400000000000000000000060061150314705300177730ustar00rootroot00000000000000$Header: /cvsroot/gkrellmpc/Changelog,v 1.14 2005/03/06 02:29:07 mina Exp $ Changelog for GKrellMPC 0.1_beta10: 2005-03-04 Patch from Sergey Pinaev : Sets wmname/wmclass for "playlist" and "add" windows, so these windows will have decoration (title/buttons) Patch from Sergey Pinaev : Changes horizontal scrollbar policy for these windows to "automatic". users can have REALY long song names in playlists. Patch from Sergey Pinaev : Adds "position" slider to show/set current song position. Added configurable option to dictate whether mouse wheel adjusts volume or position Patch from Sergey Pinaev : Adds "tooltip" showing "artist", "title" and "file" information about current playing song. Patch from Sergey Pinaev : Adds localization and Russian translation Bugfix playlist/addlist height not remembered. Now also remembers width 0.1_beta9: 2005-01-05 Incremental search in the playlist and "Add song" windows now works Fixed panel layout issues that made components overlap under certain fonts/themes 0.1_beta8: Released on 2005-01-03 Added support for drag-and-drop - You can now drag a URL onto the panel Added support for pasting - You can now paste a URL (via middle-click) onto the panel Adding a bad URL in the "Add" dialog now gives an error message Made action taken on middle-click configurable Configuration screen made better looking "Add" window gets destroyed and playlist window refreshes if re-connect to a new server Bugfix "Add URL" allowing adding to playlist bad URLs 0.1_beta7: Released on 2005-01-02 Added support for adding URLs - "does-the-right-thing" with respect to IceCast streams and PLS files Panel now shows playing time Song status (stopped, playing, paused) shown in panel label instead of prefixing scrolling song title 0.1_beta6: Released on 2005-01-01 "Add" dialog implemented Playlist window now has a "Remove" button Playlist window now responds to expected keyboard events (such as Del or Esc) Buttons now have icons 0.1_beta5: Released on 2004-12-31 Pieces in the gkrellm panel are now positioned vertically relative to each other, not hard-coded offsets from the top. This better accomodates custom fonts etc... Several playlist bugfixes, including scrolling and remembering height Compiler warning fixes 0.1_beta4: Released on 2004-12-30 Playlist feature (minimal) Huge internal code re-factorization and breakdown New Makefile targets including a working "install" target 0.1_beta3: Released on 2004-12-21 Configurable mouse wheel adjustment now allowed to go to 100 More real-time effect after applying configuration Bugfix crash in certain scenarios when MPD returns empty fields 0.1_beta2: Released on 2004-12-21 Configurable scrolling speed New volume show/control krell with adjustable mouse wheel control amount New mouse shortcuts to play/pause (middle-click) and open config (right-click) Makefile now respects external CC and CFLAGS variables 0.1_beta1: Released on 2004-12-18 Initial public release gkrellm-gkrellmpc-0.1~beta10/Makefile000066400000000000000000000057451150314705300176320ustar00rootroot00000000000000# # $Header: /cvsroot/gkrellmpc/Makefile,v 1.15 2005/03/05 22:38:44 mina Exp $ # VERSION = $(shell awk '$$1 == "\#define" && $$2 == "VERSION" {gsub("\"", "", $$3); print $$3;}' globals.h) OBJECTS = gkrellmpc.o mpd.o conf.o playlist.o addlist.o url.o CC ?= gcc CFLAGS += -Wall -fPIC `pkg-config gtk+-2.0 --cflags` -DPACKAGE="\"gkrellmpc\"" ifeq ($(enable_nls),1) CFLAGS += -DENABLE_NLS endif LDFLAGS += `curl-config --libs` .PHONY: all clean dist install install_lib install_local_lib install_home install_instructions deinstall uninstall test strip all: gkrellmpc.so gkrellmpc.so: $(OBJECTS) $(CC) $(CFLAGS) $(LDFLAGS) -shared -o gkrellmpc.so $(OBJECTS) ifeq ($(enable_nls),1) (cd po && ${MAKE} all) endif %.o: %.c %.h globals.h $(CC) $(CFLAGS) -c -o $@ $< strip: gkrellmpc.so strip gkrellmpc.so clean: -rm -rf *.o *.so *.tar.gz dist (cd po && ${MAKE} clean) dist: gkrellmpc.c gkrellmpc.h pixmaps Makefile Changelog README.txt -rm -rf dist mkdir dist mkdir dist/gkrellmpc-$(VERSION) cp -r README.txt Changelog Makefile *.c *.h pixmaps po dist/gkrellmpc-$(VERSION)/ -find dist/gkrellmpc-$(VERSION)/ -name CVS -exec rm -rf '{}' ';' -find dist/gkrellmpc-$(VERSION)/ -name .cvsignore -exec rm -rf '{}' ';' -rm gkrellmpc-$(VERSION).tar.gz cd dist && tar czvf ../gkrellmpc-$(VERSION).tar.gz . rm -rf dist install: gkrellmpc.so if [ -d /usr/lib/gkrellm2/plugins/ -a -w /usr/lib/gkrellm2/plugins/ ]; then make install_lib; elif [ -d /usr/local/lib/gkrellm2/plugins/ -a -d /usr/local/lib/gkrellm2/plugins/ ]; then make install_local_lib; elif [ -d ~/.gkrellm2/plugins/ -a -w ~/.gkrellm2/plugins/ ]; then make install_home; else make install_instructions; fi install_lib: gkrellmpc.so cp gkrellmpc.so /usr/lib/gkrellm2/plugins/ ifeq ($(enable_nls),1) (cd po && ${MAKE} install) endif install_local_lib: gkrellmpc.so cp gkrellmpc.so /usr/local/lib/gkrellm2/plugins/ ifeq ($(enable_nls),1) (cd po && ${MAKE} install) endif install_home: gkrellmpc.so cp gkrellmpc.so ~/.gkrellm2/plugins/ ifeq ($(enable_nls),1) @echo @echo Note: NLS .mo files have not been installed @echo endif install_instructions: gkrellmpc.so @echo @echo None of the standard locations for gkrellm plugins exist or are writeable by the current user id. @echo @echo Please manually copy the gkrellmpc.so file to one of your gkrellm plugin directories @echo @echo Typically system-wide plugins are placed in one of: @echo @echo " /usr/lib/gkrellm2/plugins/" @echo " /usr/local/lib/gkrellm2/plugins/" @echo @echo And user-specific plugins are placed in: @echo @echo " ~/.gkrellm2/plugins/" @echo @echo However, your system may have alternate paths. deinstall uninstall: if [ -f /usr/lib/gkrellm2/plugins/gkrellmpc.so ]; then rm -f /usr/lib/gkrellm2/plugins/gkrellmpc.so; fi if [ -f /usr/local/lib/gkrellm2/plugins/gkrellmpc.so ]; then rm -f /usr/local/lib/gkrellm2/plugins/gkrellmpc.so; fi if [ -f ~/.gkrellm2/plugins/gkrellmpc.so ]; then rm -f ~/.gkrellm2/plugins/gkrellmpc.so; fi test: gkrellmpc.so gkrellm2 -p gkrellmpc.so gkrellm-gkrellmpc-0.1~beta10/README.txt000066400000000000000000000036611150314705300176630ustar00rootroot00000000000000$Header: /cvsroot/gkrellmpc/README.txt,v 1.7 2005/03/05 22:27:27 mina Exp $ README.txt for GKrellMPC ------------------------------------------------------------ About: ------ GKrellMPC is a GKrellm plugin that allows you to control your MPD music daemon from within gkrellm. Plugin written by Mina Naguib http://www.topfx.com Requirements: ------------- You will need gkrellm with it's full headers (some distros call this the "dev" package) You will also need GTK with it's headers You will need libcurl with it's headers, including the "curl-config" binary Compiling: ---------- Simply run "make" and you should end up with a gkrellmpc.so To compile with NLS (multi-language) support, run "make enable_nls=1" instead Installation: ------------- 1. Run "make install" (or "make enable_nls=1 install" to enable NLS support) - this will try to install gkrellmpc.so in the most appropriate location found, or instruct you if it cannot for any reason - it will also attempt to install the NLS .mo files 2. Restart gkrellm 3. Right-click on GKrellm's title - go to the "Plugins" tab and make sure "GKrellMPC" is checked Configuration: -------------- 1. Right-click anywhere inside the GKrellMPC area 2. Specify the hostname and port of your MPD server Use: ---- The top-right light tells you whether the plugin is connected to an MPD server or not. The scrolling line tells you the currently-playing song. The volume krell shows you the current volume. You can drag it to adjust the volume. The buttons are standard audio hi-fi functions (prev/play/pause/stop/next/eject - playlist). Mouse shortcuts: ---------------- MOUSE WHEEL UP or DOWN adjusts the volume. RIGHT MOUSE BUTTON opens the configuration dialogue. MIDDLE MOUSE BUTTON plays/pauses. Copyright: ---------- This software is copyright 2004-2005 Mina Naguib http://www.topfx.com Released under the GNU GPL LICENSE version 2.0 gkrellm-gkrellmpc-0.1~beta10/addlist.c000066400000000000000000000256061150314705300177600ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/addlist.c,v 1.12 2005/03/06 02:29:07 mina Exp $ * * Holds all the function for addlist manipulation */ #include "globals.h" #include "addlist.h" #include "mpd.h" #include "url.h" #include GtkWidget * mpc_addlist = NULL; gint mpc_addlist_width = -1; gint mpc_addlist_height = 400; GtkWidget * mpc_addlist_url; GtkTreeStore * mpc_addlist_store = NULL; GtkWidget * mpc_addlist_tree = NULL; enum mpc_addlist_columns { MPC_ADDLIST_COLUMN_ICON = 0 , MPC_ADDLIST_COLUMN_RAWNAME , MPC_ADDLIST_COLUMN_DISPLAYNAME , MPC_ADDLIST_COLUMNS }; /* * Creates (or activates) the addlist window */ void mpc_addlist_create(void) { GtkWidget * scrollwindow; GtkTreeSelection * selection; GtkWidget *hbox; GtkWidget *vbox; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkWidget * buttonbar; GtkWidget * button; GtkWidget * bar; GtkWidget * url_label; GtkWidget * url_add; if (!mpc_addlist) { /* * Create the addlist window */ mpc_addlist = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_wmclass(GTK_WINDOW(mpc_addlist), "playlistadd", "gkrellmpc"); gtk_window_set_title(GTK_WINDOW(mpc_addlist), _("MPD ADD SONGS")); gtk_container_border_width (GTK_CONTAINER(mpc_addlist), 10); gtk_window_set_default_size(GTK_WINDOW(mpc_addlist), mpc_addlist_width, mpc_addlist_height); gtk_window_set_position(GTK_WINDOW(mpc_addlist), GTK_WIN_POS_CENTER); g_signal_connect(GTK_OBJECT(mpc_addlist), "configure_event", G_CALLBACK(mpc_addlist_configure_event), NULL); g_signal_connect(GTK_OBJECT(mpc_addlist), "delete_event", G_CALLBACK(mpc_addlist_delete_event), NULL); g_signal_connect(GTK_OBJECT(mpc_addlist), "destroy", G_CALLBACK(mpc_addlist_destroy_event), NULL); g_signal_connect(mpc_addlist, "key-release-event", G_CALLBACK(mpc_cb_addlist_key), NULL); /* * Create URL label */ url_label = gtk_label_new("URL:"); /* * Create the URL entry box */ mpc_addlist_url = gtk_entry_new(); /* * Create the URL add button */ url_add = gtk_button_new_from_stock(GTK_STOCK_ADD); g_signal_connect(GTK_OBJECT(url_add), "clicked", G_CALLBACK(mpc_cb_addlist_button_add), "url"); /* * Create the bar */ bar = gtk_hseparator_new(); /* * Create the data store */ mpc_addlist_store = gtk_tree_store_new(MPC_ADDLIST_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); /* * Create addlist tree */ mpc_addlist_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(mpc_addlist_store)); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(mpc_addlist_tree), TRUE); // gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(mpc_addlist_tree), FALSE); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mpc_addlist_tree)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); g_signal_connect(mpc_addlist_tree, "row-activated", G_CALLBACK(mpc_cb_addlist_row), NULL); /* * Create the scrollwindow the addlist goes in */ scrollwindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER(scrollwindow), mpc_addlist_tree); /* * Create the visual columns */ renderer = gtk_cell_renderer_pixbuf_new (); column = gtk_tree_view_column_new_with_attributes (NULL, renderer , "stock-id", MPC_ADDLIST_COLUMN_ICON , NULL); gtk_tree_view_column_set_sort_column_id (column, MPC_ADDLIST_COLUMN_ICON); gtk_tree_view_append_column(GTK_TREE_VIEW(mpc_addlist_tree), column); renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes (_("Name"), renderer , "text", MPC_ADDLIST_COLUMN_DISPLAYNAME , NULL); gtk_tree_view_column_set_sort_column_id (column, MPC_ADDLIST_COLUMN_DISPLAYNAME); gtk_tree_view_set_search_column(GTK_TREE_VIEW(mpc_addlist_tree), MPC_ADDLIST_COLUMN_DISPLAYNAME); gtk_tree_view_append_column(GTK_TREE_VIEW(mpc_addlist_tree), column); /* * Create the bottom buttons */ buttonbar = gtk_hbutton_box_new(); button = gtk_button_new_from_stock(GTK_STOCK_ADD); g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(mpc_cb_addlist_button_add), "list"); gtk_container_add(GTK_CONTAINER(buttonbar), button); button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(mpc_cb_addlist_button_close), NULL); gtk_container_add(GTK_CONTAINER(buttonbar), button); /* * And pack everything */ hbox = gtk_hbox_new(FALSE, 8); gtk_box_pack_start(GTK_BOX(hbox), url_label, 0, 0, 0); gtk_box_pack_start(GTK_BOX(hbox), mpc_addlist_url, 1, 1, 0); gtk_box_pack_start(GTK_BOX(hbox), url_add, 0, 0, 0); vbox = gtk_vbox_new(FALSE, 8); gtk_box_pack_start(GTK_BOX(vbox), hbox, 0, 0, 0); gtk_box_pack_start(GTK_BOX(vbox), bar, 0, 0, 0); gtk_box_pack_start(GTK_BOX(vbox), scrollwindow, 1, 1, 0); gtk_box_pack_start(GTK_BOX(vbox), buttonbar, 0, 0, 0); gtk_container_add(GTK_CONTAINER(mpc_addlist), vbox); /* * Update the addlist */ mpc_addlist_update(); /* * Finally show everything */ gtk_widget_show_all(mpc_addlist); } else { /* * Make the addlist window the foreground window */ gtk_window_present(GTK_WINDOW(mpc_addlist)); } } /* * Called when a user presses a key in the addlist window */ gboolean mpc_cb_addlist_key (GtkWidget *widget, GdkEventKey *event, gpointer user_data) { switch (event->keyval) { case GDK_Escape: /* They pressed Escape - destroy the addlist */ gtk_widget_destroy(mpc_addlist); return (TRUE); } /* * If we've reached here tell GTK to send the key upwards */ return (FALSE); } /* * Gets called when the addlist window is about to be destroyed */ void mpc_addlist_destroy_event(GtkWidget *widget, gpointer data) { /* Blow it up :) */ gtk_tree_store_clear(mpc_addlist_store); mpc_addlist = NULL; mpc_addlist_store = NULL; mpc_addlist_tree = NULL; } /* * Gets called when the window manager tries to close the addlist window */ gint mpc_addlist_delete_event(GtkContainer *container, GtkWidget *widget, gpointer user_data) { return(FALSE); } /* * Called when the user double-clicks/hits enter on a addlist row */ void mpc_cb_addlist_row (GtkTreeView *tree, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data) { GtkTreeIter iter; gchar * name; gchar * command; if (gtk_tree_model_get_iter(GTK_TREE_MODEL(mpc_addlist_store), &iter, path)) { gtk_tree_model_get(GTK_TREE_MODEL(mpc_addlist_store), &iter , MPC_ADDLIST_COLUMN_RAWNAME, &name , -1); command = g_strdup_printf("add \"%s\"\n", name); mpc_mpd_do(command); g_free(command); } } /* * Called when the "add" button is clicked in the addlist window */ void mpc_cb_addlist_button_add (GtkButton *button, gpointer user_data) { GtkTreeSelection * selection; const gchar * oldurl = NULL; gchar * newurl = NULL; gchar * command = NULL; GtkWidget * errordialog; if (strcmp(user_data, "url") == 0) { /* * They clicked on the ADD next to the url */ oldurl = gtk_entry_get_text(GTK_ENTRY(mpc_addlist_url)); if (oldurl && strlen(oldurl) > 0) { newurl = mpc_url_parse(oldurl); if (newurl) { command = g_strdup_printf("add \"%s\"\n", newurl); mpc_mpd_do(command); g_free(command); g_free(newurl); } else { /* * Show them an error */ errordialog = gtk_message_dialog_new (GTK_WINDOW(mpc_addlist), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("URL could not be added")); gtk_dialog_run(GTK_DIALOG(errordialog)); gtk_widget_destroy(errordialog); } } } else { /* * They clicked on ADD under the list * loop over selected rows calling mpc_cb_add_foreach for each */ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mpc_addlist_tree)); gtk_tree_selection_selected_foreach(selection, mpc_cb_add_foreach, NULL); } } /* * Gets called from mpc_cb_addlist_button_add for each selected row * It's job is to send the "add" command to mpd for the given row */ void mpc_cb_add_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { gchar * rawname; gchar * command; gtk_tree_model_get(GTK_TREE_MODEL(mpc_addlist_store), iter , MPC_ADDLIST_COLUMN_RAWNAME, &rawname , -1); command = g_strdup_printf("add \"%s\"\n", rawname); mpc_mpd_do(command); g_free(command); } /* * Called when the "close" button is clicked in the addlist window */ void mpc_cb_addlist_button_close (GtkButton *button, gpointer user_data) { gtk_widget_destroy(mpc_addlist); } /* * If the addlist window exists, updates it with the addlist from mpd */ gboolean mpc_addlist_update(void) { GPtrArray * list; GHashTable * hash; gchar * file; gchar * directory; gint i; GtkTreeIter iter; GPtrArray * iterpath; GtkTreeIter * tempiter; GtkTreeIter * parentiter = NULL; gint level = 0; gchar * p; gchar ** parts; gchar ** tempparts; gchar * nicename = NULL; if (!mpc_addlist) { /* Nothing to do */ } else { /* Get list of all files form mpd */ list = mpc_mpd_get_clumps("listall\n", TRUE); if (!list) { return (FALSE); } gtk_tree_store_clear(mpc_addlist_store); iterpath = g_ptr_array_new(); for (i=0; i < list->len; i++) { hash = g_ptr_array_index(list, i); /* Populate local vars file and directory */ file = g_hash_table_lookup(hash, "file"); directory = g_hash_table_lookup(hash, "directory"); /* Update parentiter */ if (directory) { level = 1; p = directory; while (*(p++)) { if (*p == '/') { level++; } } while (iterpath->len >= level) { tempiter = g_ptr_array_index(iterpath, iterpath->len - 1); g_free(tempiter); g_ptr_array_remove_index(iterpath, iterpath->len - 1); } if (iterpath->len) parentiter = g_ptr_array_index(iterpath, iterpath->len - 1); else parentiter = NULL; } /* Set nicename */ parts = g_strsplit((directory ? directory : file), "/", 0); tempparts = parts; while (tempparts[0]) { nicename = tempparts[0]; tempparts++; } /* Add new row to store */ gtk_tree_store_append(mpc_addlist_store, &iter, parentiter); /* Set vars in new row */ gtk_tree_store_set(mpc_addlist_store, &iter , MPC_ADDLIST_COLUMN_ICON, (directory ? GTK_STOCK_OPEN : GTK_STOCK_NEW) , MPC_ADDLIST_COLUMN_RAWNAME, (directory ? directory : file) , MPC_ADDLIST_COLUMN_DISPLAYNAME, nicename , -1); g_strfreev(parts); /* Update parentiter */ if (directory) { tempiter = g_malloc(sizeof(iter)); memcpy(tempiter, &iter, sizeof(iter)); g_ptr_array_add(iterpath, tempiter); parentiter = tempiter; } g_hash_table_destroy(hash); } g_ptr_array_free(iterpath, TRUE); g_ptr_array_free(list, FALSE); } return (TRUE); } gboolean mpc_addlist_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data) { /* Remember width & height */ mpc_addlist_width = event->width; mpc_addlist_height = event->height; return(FALSE); } gkrellm-gkrellmpc-0.1~beta10/addlist.h000066400000000000000000000013651150314705300177610ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/addlist.h,v 1.4 2005/03/06 02:29:07 mina Exp $ */ #ifndef _ADDLIST_H #define _ADDLIST_H void mpc_addlist_create(void); gboolean mpc_cb_addlist_key (GtkWidget *, GdkEventKey *, gpointer); gboolean mpc_addlist_configure_event(GtkWidget *, GdkEventConfigure *, gpointer); void mpc_addlist_destroy_event(GtkWidget *, gpointer); gint mpc_addlist_delete_event(GtkContainer *, GtkWidget *, gpointer); void mpc_cb_addlist_row (GtkTreeView *, GtkTreePath *, GtkTreeViewColumn *, gpointer); void mpc_cb_addlist_button_add (GtkButton *, gpointer); void mpc_cb_addlist_button_close (GtkButton *, gpointer); gboolean mpc_addlist_update(void); void mpc_cb_add_foreach (GtkTreeModel *, GtkTreePath *, GtkTreeIter *, gpointer); #endif gkrellm-gkrellmpc-0.1~beta10/conf.c000066400000000000000000000212731150314705300172550ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/conf.c,v 1.9 2005/03/05 22:27:27 mina Exp $ * * Holds all the functions for the configuration tab */ #include "globals.h" #include "conf.h" #include "mpd.h" #include "gkrellmpc.h" GtkWidget * mpc_confwidget_hostname = NULL; GtkWidget * mpc_confwidget_port = NULL; GtkWidget * mpc_confwidget_scrollspeed = NULL; GtkWidget * mpc_confwidget_wheelaction = NULL; GtkWidget * mpc_confwidget_wheelamount = NULL; GtkWidget * mpc_confwidget_rightclick = NULL; GtkWidget * mpc_confwidget_middleclick = NULL; GtkWidget * mpc_confwidget_drop = NULL; gint mpc_conf_scrollspeed = 3; MPC_WHEEL_ACTIONS mpc_conf_wheelaction = MPC_WHEEL_ACTION_VOLUME; gint mpc_conf_wheelamount = 10; gchar * mpc_conf_hostname = NULL; gint mpc_conf_port = 6600; MPC_RIGHTCLICK_ACTIONS mpc_conf_rightclick = MPC_RIGHTCLICK_ACTION_CONFIG; MPC_MIDDLECLICK_ACTIONS mpc_conf_middleclick = MPC_MIDDLECLICK_ACTION_PAUSE; MPC_DROP_ACTIONS mpc_conf_drop = MPC_DROP_ACTION_ADDPLAY; /* * Gets called when it's time to create the configuration tab */ void mpc_create_plugin_tab (GtkWidget *tab) { GtkWidget *notebook; GtkWidget *table; GtkWidget *vbox; gchar *tmpstr; notebook = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP); gtk_box_pack_start(GTK_BOX(tab), notebook, TRUE, TRUE, 0); /* Config tab */ table = gtk_table_new(7, 2, FALSE); vbox = gkrellm_gtk_framed_notebook_page(notebook, _("Configuration")); gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("MPD hostname:")), 0, 1, 0, 1); gtk_table_attach_defaults(GTK_TABLE(table), (mpc_confwidget_hostname = gtk_entry_new()), 1, 2, 0, 1); if (mpc_conf_hostname) { gtk_entry_set_text(GTK_ENTRY(mpc_confwidget_hostname), mpc_conf_hostname); } gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("MPD port:")), 0, 1, 1, 2); gtk_table_attach_defaults(GTK_TABLE(table), (mpc_confwidget_port = gtk_spin_button_new_with_range(1,65535,1)), 1, 2, 1, 2); if (mpc_conf_port) { gtk_spin_button_set_value(GTK_SPIN_BUTTON(mpc_confwidget_port), mpc_conf_port); } gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("Scrolling speed:")), 0, 1, 2, 3); gtk_table_attach_defaults(GTK_TABLE(table), (mpc_confwidget_scrollspeed = gtk_spin_button_new_with_range(1,25,1)), 1, 2, 2, 3); gtk_spin_button_set_value(GTK_SPIN_BUTTON(mpc_confwidget_scrollspeed), mpc_conf_scrollspeed); gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("Mouse wheel:")), 0, 1, 3, 4); mpc_confwidget_wheelaction = gtk_combo_box_new_text(); gtk_combo_box_append_text(GTK_COMBO_BOX(mpc_confwidget_wheelaction), _("Adjusts volume")); gtk_combo_box_append_text(GTK_COMBO_BOX(mpc_confwidget_wheelaction), _("Adjusts position")); gtk_table_attach_defaults(GTK_TABLE(table), mpc_confwidget_wheelaction, 1, 2, 3, 4); gtk_combo_box_set_active(GTK_COMBO_BOX(mpc_confwidget_wheelaction), mpc_conf_wheelaction); gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("Mouse wheel adjustment:")), 0, 1, 4, 5); gtk_table_attach_defaults(GTK_TABLE(table), (mpc_confwidget_wheelamount = gtk_spin_button_new_with_range(0,100,1)), 1, 2, 4, 5); gtk_spin_button_set_value(GTK_SPIN_BUTTON(mpc_confwidget_wheelamount), mpc_conf_wheelamount); gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("Right click:")), 0, 1, 5, 6); mpc_confwidget_rightclick = gtk_combo_box_new_text(); gtk_combo_box_append_text(GTK_COMBO_BOX(mpc_confwidget_rightclick), _("Opens configuration")); gtk_combo_box_append_text(GTK_COMBO_BOX(mpc_confwidget_rightclick), _("Opens playlist")); gtk_table_attach_defaults(GTK_TABLE(table), mpc_confwidget_rightclick, 1, 2, 5, 6); gtk_combo_box_set_active(GTK_COMBO_BOX(mpc_confwidget_rightclick), mpc_conf_rightclick); gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("Middle click:")), 0, 1, 6, 7); mpc_confwidget_middleclick = gtk_combo_box_new_text(); gtk_combo_box_append_text(GTK_COMBO_BOX(mpc_confwidget_middleclick), _("Pauses")); gtk_combo_box_append_text(GTK_COMBO_BOX(mpc_confwidget_middleclick), _("Simulates drop from clipboard")); gtk_table_attach_defaults(GTK_TABLE(table), mpc_confwidget_middleclick, 1, 2, 6, 7); gtk_combo_box_set_active(GTK_COMBO_BOX(mpc_confwidget_middleclick), mpc_conf_middleclick); gtk_table_attach_defaults(GTK_TABLE(table), gtk_label_new(_("Drag-drop URL into panel will:")), 0, 1, 7, 8); mpc_confwidget_drop = gtk_combo_box_new_text(); gtk_combo_box_append_text(GTK_COMBO_BOX(mpc_confwidget_drop), _("Clear playlist, add URL and play it")); gtk_combo_box_append_text(GTK_COMBO_BOX(mpc_confwidget_drop), _("Add URL and play it")); gtk_combo_box_append_text(GTK_COMBO_BOX(mpc_confwidget_drop), _("Just add URL")); gtk_table_attach_defaults(GTK_TABLE(table), mpc_confwidget_drop, 1, 2, 7, 8); gtk_combo_box_set_active(GTK_COMBO_BOX(mpc_confwidget_drop), mpc_conf_drop); gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0); /* Help tab */ vbox = gkrellm_gtk_framed_notebook_page(notebook, _("Help")); gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new(_("For help please visit the support forums at the MPD web site:\nhttp://www.musicpd.org\n\nAlternatively email the author at webmaster@topfx.com")), TRUE, TRUE, 0); /* About tab */ tmpstr = g_strdup_printf(_("About %s"), PLUGIN_NAME); vbox = gkrellm_gtk_framed_notebook_page(notebook, tmpstr); g_free(tmpstr); tmpstr = g_strdup_printf(_("Plugin version %s\n\nWritten by Mina Naguib \nhttp://www.topfx.com\n\nCopyright (C) 2004-2005 Mina Naguib\nReleased under the GPL license version 2"), VERSION); gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new(tmpstr), TRUE, TRUE, 0); g_free(tmpstr); } /* * Gets called to apply the plugin config */ void mpc_apply_plugin_config () { gboolean needdisconnect = FALSE; gchar * newhostname; gint newport; newhostname = g_strdup(gtk_entry_get_text(GTK_ENTRY(mpc_confwidget_hostname))); newport = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mpc_confwidget_port)); if (strcmp(newhostname, mpc_conf_hostname) != 0 || newport != mpc_conf_port) { needdisconnect = TRUE; } if (mpc_conf_hostname) { g_free(mpc_conf_hostname); } mpc_conf_hostname = newhostname; mpc_conf_port = newport; if (needdisconnect) { if (mpc_addlist) gtk_widget_destroy(mpc_addlist); mpc_playlistversion = -1; mpc_mpd_disconnect(); mpc_sync_with_mpd(); } mpc_conf_scrollspeed = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mpc_confwidget_scrollspeed)); mpc_conf_wheelaction = gtk_combo_box_get_active(GTK_COMBO_BOX(mpc_confwidget_wheelaction)); mpc_conf_wheelamount = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mpc_confwidget_wheelamount)); mpc_conf_rightclick = gtk_combo_box_get_active(GTK_COMBO_BOX(mpc_confwidget_rightclick)); mpc_conf_middleclick = gtk_combo_box_get_active(GTK_COMBO_BOX(mpc_confwidget_middleclick)); mpc_conf_drop = gtk_combo_box_get_active(GTK_COMBO_BOX(mpc_confwidget_drop)); } /* * Gets called to save the plugin config to a filehandle */ void mpc_save_plugin_config (FILE * fh) { fprintf(fh, "%s hostname %s\n", PLUGIN_NAME, mpc_conf_hostname); fprintf(fh, "%s port %d\n", PLUGIN_NAME, mpc_conf_port); fprintf(fh, "%s scrollspeed %d\n", PLUGIN_NAME, mpc_conf_scrollspeed); fprintf(fh, "%s wheelaction %d\n", PLUGIN_NAME, mpc_conf_wheelaction); fprintf(fh, "%s wheelamount %d\n", PLUGIN_NAME, mpc_conf_wheelamount); fprintf(fh, "%s rightclick %d\n", PLUGIN_NAME, mpc_conf_rightclick); fprintf(fh, "%s middleclick %d\n", PLUGIN_NAME, mpc_conf_middleclick); fprintf(fh, "%s drop %d\n", PLUGIN_NAME, mpc_conf_drop); } /* * Gets called to load a single config value from a line */ void mpc_load_plugin_config (gchar * line) { gchar * keyword; gchar * value; gint len; len = strlen(line); keyword = g_malloc(len+1); value = g_malloc(len+1); if (sscanf(line, "%31s %[^\n]", keyword, value) == 2) { if (strcmp(keyword, "hostname") == 0) { if (mpc_conf_hostname) free(mpc_conf_hostname); mpc_conf_hostname = g_strdup(value); } else if (strcmp(keyword, "port") == 0) { mpc_conf_port = g_ascii_strtod(value, NULL); } else if (strcmp(keyword, "scrollspeed") == 0) { mpc_conf_scrollspeed = g_ascii_strtod(value, NULL); } else if (strcmp(keyword, "wheelaction") == 0) { mpc_conf_wheelaction = g_ascii_strtod(value, NULL); } else if (strcmp(keyword, "wheelamount") == 0) { mpc_conf_wheelamount = g_ascii_strtod(value, NULL); } else if (strcmp(keyword, "rightclick") == 0) { mpc_conf_rightclick = g_ascii_strtod(value, NULL); } else if (strcmp(keyword, "middleclick") == 0) { mpc_conf_middleclick = g_ascii_strtod(value, NULL); } else if (strcmp(keyword, "drop") == 0) { mpc_conf_drop = g_ascii_strtod(value, NULL); } } free(keyword); free(value); } gkrellm-gkrellmpc-0.1~beta10/conf.h000066400000000000000000000004241150314705300172550ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/conf.h,v 1.1 2004/12/30 20:49:37 mina Exp $ */ #ifndef _CONF_H #define _CONF_H void mpc_create_plugin_tab (GtkWidget *); void mpc_apply_plugin_config (); void mpc_save_plugin_config (FILE *); void mpc_load_plugin_config (gchar *); #endif gkrellm-gkrellmpc-0.1~beta10/gkrellmpc.c000066400000000000000000000605641150314705300203160ustar00rootroot00000000000000 /* * $Header: /cvsroot/gkrellmpc/gkrellmpc.c,v 1.64 2005/03/06 02:39:21 mina Exp $ * * Main functions for GkrellMPC as per the gkrellm API doc */ #include "globals.h" #include "gkrellmpc.h" #include "mpd.h" #include "conf.h" #include "playlist.h" #include "url.h" #include "pixmaps/prev.xpm" #include "pixmaps/prev_clicked.xpm" #include "pixmaps/play_pause.xpm" #include "pixmaps/play_pause_clicked.xpm" #include "pixmaps/stop.xpm" #include "pixmaps/stop_clicked.xpm" #include "pixmaps/next.xpm" #include "pixmaps/next_clicked.xpm" #include "pixmaps/eject.xpm" #include "pixmaps/eject_clicked.xpm" #if !GKRELLM_CHECK_VERSION(2,2,0) #define gkrellm_gdk_string_width gdk_string_width #endif GkrellmMonitor mpc_plugin_mon = { PLUGIN_NAME, /* Name, for config tab. */ 0, /* Id, 0 if a plugin */ mpc_create_plugin, /* The create_plugin() function */ mpc_update_plugin, /* The update_plugin() function */ mpc_create_plugin_tab, /* The create_plugin_tab() config function */ mpc_apply_plugin_config,/* The apply_plugin_config() function */ mpc_save_plugin_config, /* The save_plugin_config() function */ mpc_load_plugin_config, /* The load_plugin_config() function */ PLUGIN_NAME, /* config keyword */ NULL, /* Undefined 2 */ NULL, /* Undefined 1 */ NULL, /* Undefined 0 */ PLUGIN_PLACEMENT, /* Insert plugin before this monitor. */ NULL, /* Handle if a plugin, filled in by GKrellM */ NULL /* path if a plugin, filled in by GKrellM */ }; GkrellmTicks * mpc_ticker = NULL; gint mpc_plugin_style_id = 0; GkrellmDecal * mpc_label_decal = NULL; gchar * mpc_label = NULL; GkrellmDecal * mpc_songname_decal = NULL; gchar * mpc_songname = NULL; gint mpc_id = -1; GkrellmKrell * mpc_volume_krell = NULL; gint mpc_volume = 0; gboolean mpc_volume_inmotion = FALSE; GkrellmPanel * mpc_panel = NULL; GkrellmDecal * mpc_status_decal = NULL; GkrellmKrell * mpc_pos_krell = NULL; gint mpc_pos = 0; gboolean mpc_pos_inmotion = FALSE; GtkTooltips * mpc_tooltip = NULL; /* * Entrance handler gkrellm automatically calls */ GkrellmMonitor * gkrellm_init_plugin() { #ifdef ENABLE_NLS bind_textdomain_codeset(PACKAGE, "UTF8"); #endif /* * Initialize non-constant globals */ mpc_ticker = gkrellm_ticks(); mpc_plugin_style_id = gkrellm_add_chart_style(&mpc_plugin_mon, PLUGIN_STYLE_NAME); mpc_label = g_strdup(_("MPD")); mpc_songname = g_strdup(_("Not connected")); mpc_conf_hostname = g_strdup("localhost"); return &mpc_plugin_mon; } /* * Gets called to create the plugin area */ void mpc_create_plugin (GtkWidget *vbox, gint first_create) { GkrellmStyle * style; GkrellmTextstyle * textstyle; GkrellmStyle * sliderstyle; GtkTargetEntry dragtargets[3]; GkrellmDecal * volume_decal = NULL; GkrellmDecal * pos_decal = NULL; static GkrellmPiximage *prev_image; static GkrellmPiximage *prev_clicked_image; gint prev_image_width; static GkrellmPiximage *play_pause_image; static GkrellmPiximage *play_pause_clicked_image; gint play_pause_image_width; static GkrellmPiximage *stop_image; static GkrellmPiximage *stop_clicked_image; gint stop_image_width; static GkrellmPiximage *next_image; static GkrellmPiximage *next_clicked_image; gint next_image_width; static GkrellmPiximage *eject_image; static GkrellmPiximage *eject_clicked_image; gint eject_image_width; gint t; gint l; gint w; style = gkrellm_meter_style(mpc_plugin_style_id); sliderstyle = gkrellm_krell_slider_style(); textstyle = gkrellm_meter_textstyle(mpc_plugin_style_id); w = gkrellm_chart_width(); if (first_create) { /* Create the global panel var */ mpc_panel = gkrellm_panel_new0(); } t = 3; /* Create the label decal */ mpc_label_decal = gkrellm_create_decal_text(mpc_panel, "NO MPD ERROR PAUSED STOPPED 0123456789:", textstyle, style, -1, t, -1); gkrellm_draw_decal_text(mpc_panel, mpc_label_decal, mpc_label, -1); /* Create the status decal */ mpc_status_decal = gkrellm_create_decal_pixmap(mpc_panel, gkrellm_decal_misc_pixmap(), gkrellm_decal_misc_mask(), N_MISC_DECALS, style, 0, t); mpc_status_decal->x = w - mpc_status_decal->w; gkrellm_draw_decal_pixmap(mpc_panel, mpc_status_decal, (mpc_mpd ? D_MISC_LED1 : D_MISC_LED0)); /* Update t */ t += mpc_label_decal->h > mpc_status_decal->h ? mpc_label_decal->h : mpc_status_decal->h; t += 2; /* Create the song name text decal */ mpc_songname_decal = gkrellm_create_decal_text(mpc_panel, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", textstyle, style, -1, t, -1); gkrellm_draw_decal_text(mpc_panel, mpc_songname_decal, mpc_songname, -1); /* Update t */ t += mpc_songname_decal->h; t += 2; /* Create the vol text decal */ volume_decal = gkrellm_create_decal_text(mpc_panel, _("Vol:"), textstyle, style, -1, t, 0); gkrellm_draw_decal_text(mpc_panel, volume_decal, _("Vol:"), -1); /* Create the volume krell */ gkrellm_set_style_slider_values_default(sliderstyle, t, volume_decal->w + 3, 0); mpc_volume_krell = gkrellm_create_krell(mpc_panel, gkrellm_krell_slider_piximage(), sliderstyle); gkrellm_monotonic_krell_values(mpc_volume_krell, FALSE); gkrellm_set_krell_full_scale(mpc_volume_krell, 100, 1); /* Update t */ t += volume_decal->h > mpc_volume_krell->h_frame ? volume_decal->h : mpc_volume_krell->h_frame; t += 2; /* Create the pos text decal */ pos_decal = gkrellm_create_decal_text(mpc_panel, _("Pos:"), textstyle, style, -1, t, 0); gkrellm_draw_decal_text(mpc_panel, pos_decal, _("Pos:"), -1); /* Create the pos krell */ gkrellm_set_style_slider_values_default(sliderstyle, t, pos_decal->w + 3, 0); mpc_pos_krell = gkrellm_create_krell(mpc_panel, gkrellm_krell_slider_piximage(), sliderstyle); gkrellm_monotonic_krell_values(mpc_pos_krell, FALSE); gkrellm_set_krell_full_scale(mpc_pos_krell, 100, 1); /* Update t */ t += pos_decal->h > mpc_pos_krell->h_frame ? pos_decal->h : mpc_pos_krell->h_frame; t += 2; /* Load the buttons into memory and calculate their widths */ gkrellm_load_piximage("prev", mpc_xpm_prev0, &prev_image, PLUGIN_STYLE_NAME); gkrellm_load_piximage("prev_clicked", mpc_xpm_prev1, &prev_clicked_image, PLUGIN_STYLE_NAME); mpc_stack_images(prev_image, prev_clicked_image); prev_image_width = gdk_pixbuf_get_width(prev_image->pixbuf); gkrellm_load_piximage("play_pause", mpc_xpm_playpause0, &play_pause_image, PLUGIN_STYLE_NAME); gkrellm_load_piximage("play_pause_clicked", mpc_xpm_playpause1, &play_pause_clicked_image, PLUGIN_STYLE_NAME); mpc_stack_images(play_pause_image, play_pause_clicked_image); play_pause_image_width = gdk_pixbuf_get_width(play_pause_image->pixbuf); gkrellm_load_piximage("stop", mpc_xpm_stop0, &stop_image, PLUGIN_STYLE_NAME); gkrellm_load_piximage("stop_clicked", mpc_xpm_stop1, &stop_clicked_image, PLUGIN_STYLE_NAME); mpc_stack_images(stop_image, stop_clicked_image); stop_image_width = gdk_pixbuf_get_width(stop_image->pixbuf); gkrellm_load_piximage("next", mpc_xpm_next0, &next_image, PLUGIN_STYLE_NAME); gkrellm_load_piximage("next_clicked", mpc_xpm_next1, &next_clicked_image, PLUGIN_STYLE_NAME); mpc_stack_images(next_image, next_clicked_image); next_image_width = gdk_pixbuf_get_width(next_image->pixbuf); gkrellm_load_piximage("eject", mpc_xpm_eject0, &eject_image, PLUGIN_STYLE_NAME); gkrellm_load_piximage("eject_clicked", mpc_xpm_eject1, &eject_clicked_image, PLUGIN_STYLE_NAME); mpc_stack_images(eject_image, eject_clicked_image); eject_image_width = gdk_pixbuf_get_width(eject_image->pixbuf); /* Place the buttons in the center */ l = (w - prev_image_width - play_pause_image_width - stop_image_width - next_image_width - (eject_image_width/4) - eject_image_width) / 2; if (l < 0) { /* gkrellm is not wide enough for our buttons - start at 0 anyways then */ l = 0; } gkrellm_make_scaled_button(mpc_panel, prev_image, mpc_cb_button_prev, NULL, FALSE, FALSE, 2, 0, 1, l, t, 12, 9); l += prev_image_width; gkrellm_make_scaled_button(mpc_panel, play_pause_image, mpc_cb_button_play_pause, NULL, FALSE, FALSE, 2, 0, 1, l, t, 12, 9); l += play_pause_image_width; gkrellm_make_scaled_button(mpc_panel, stop_image, mpc_cb_button_stop, NULL, FALSE, FALSE, 2, 0, 1, l, t, 12, 9); l += stop_image_width; gkrellm_make_scaled_button(mpc_panel, next_image, mpc_cb_button_next, NULL, FALSE, FALSE, 2, 0, 1, l, t, 12, 9); l += next_image_width; l += (eject_image_width/4); gkrellm_make_scaled_button(mpc_panel, eject_image, mpc_cb_button_eject, NULL, FALSE, FALSE, 2, 0, 1, l, t, 12, 9); l += next_image_width; /* Create the tooltip */ mpc_tooltip = gtk_tooltips_new(); /* Finalize the panel */ gkrellm_panel_configure(mpc_panel, NULL, style); gkrellm_panel_create(vbox, &mpc_plugin_mon, mpc_panel); if (first_create) { /* * Connect to the panel signals */ g_signal_connect(G_OBJECT(mpc_panel->drawing_area), "expose_event", G_CALLBACK(mpc_panel_expose_event), NULL); g_signal_connect(G_OBJECT(mpc_panel->drawing_area), "button_press_event", G_CALLBACK(mpc_cb_panel_press), NULL); g_signal_connect(G_OBJECT(mpc_panel->drawing_area), "button_release_event", G_CALLBACK(mpc_cb_panel_release), NULL); g_signal_connect(G_OBJECT(mpc_panel->drawing_area), "motion_notify_event", G_CALLBACK(mpc_cb_panel_motion), NULL); g_signal_connect(G_OBJECT(mpc_panel->drawing_area), "scroll_event", G_CALLBACK(mpc_cb_panel_scroll), NULL); /* * Setup the panel to receive drops for URLS */ dragtargets[0].target = "text/plain"; dragtargets[0].flags = 0; dragtargets[0].info = 0; dragtargets[1].target = "text/uri-list"; dragtargets[1].flags = 0; dragtargets[1].info = 1; dragtargets[2].target = "STRING"; dragtargets[2].flags = 0; dragtargets[2].info = 2; gtk_drag_dest_set(vbox, GTK_DEST_DEFAULT_DROP, dragtargets, 3, GDK_ACTION_COPY); g_signal_connect(G_OBJECT(vbox), "drag_motion", G_CALLBACK(mpc_cb_panel_dragmotion), NULL); g_signal_connect(G_OBJECT(vbox), "drag_data_received", G_CALLBACK(mpc_cb_panel_dragdatareceived), NULL); } /* Tell gkrellm to call us back on destruction */ gkrellm_disable_plugin_connect(&mpc_plugin_mon, mpc_disable_plugin); } /* * Gets called to update the plugin area */ void mpc_update_plugin () { gint w_scroll, w_decal; static gint x_scroll; /* Try to connect to mpd */ if (!mpc_mpd && mpc_ticker->ten_second_tick) { mpc_mpd_connect(); } if (mpc_ticker->second_tick) { mpc_sync_with_mpd(); } /* Update the label */ gkrellm_draw_decal_text(mpc_panel, mpc_label_decal, mpc_label, -1); /* Scroll the song name */ w_decal = mpc_songname_decal->w; w_scroll = gkrellm_gdk_string_width(mpc_songname_decal->text_style.font, mpc_songname); x_scroll -= mpc_conf_scrollspeed; if (x_scroll <= -w_scroll) x_scroll = w_decal; mpc_songname_decal->x_off = x_scroll; gkrellm_draw_decal_text(mpc_panel, mpc_songname_decal, mpc_songname, x_scroll); /* Update the volume krell */ gkrellm_update_krell(mpc_panel, mpc_volume_krell, (gint)mpc_volume); /* Update the pos krell */ gkrellm_update_krell(mpc_panel, mpc_pos_krell, (gint)mpc_pos); /* Update the panel */ gkrellm_draw_panel_layers(mpc_panel); } /* * Gets called when the plugin is disabled */ void mpc_disable_plugin () { if (mpc_playlist) gtk_widget_destroy(mpc_playlist); if (mpc_addlist) gtk_widget_destroy(mpc_addlist); mpc_mpd_disconnect(); mpc_url_cleanup(); } /* * Gets called back when the PREV button is pressed */ void mpc_cb_button_prev() { mpc_mpd_do("previous\n"); } /* * Gets called back when the PLAY/PAUSE button is pressed */ void mpc_cb_button_play_pause() { GHashTable * status; gchar * state; status = mpc_mpd_get("status\n"); if (!status) { /* Cannot get status - so cannot issue appropriate command - just try to play */ mpc_mpd_do("play\n"); } else { state = g_hash_table_lookup(status, "state"); if (strcmp(state, "play") == 0) { /* MPD is playing - issue pause command */ mpc_mpd_do("pause\n"); } else { /* MPD is not playing - issue play command */ mpc_mpd_do("play\n"); } g_hash_table_destroy(status); } } /* * Gets called back when the STOP button is pressed */ void mpc_cb_button_stop() { mpc_mpd_do("stop\n"); } /* * Gets called back when the NEXT button is pressed */ void mpc_cb_button_next() { mpc_mpd_do("next\n"); } /* * Gets called back when the EJECT button is pressed */ void mpc_cb_button_eject() { mpc_playlist_create(); } /* * Stolen shamelessly from gkrellmms */ void mpc_stack_images (GkrellmPiximage *out_image, GkrellmPiximage *in_image) { GdkPixbuf *pixbuf, *src_pixbuf; gint w, h; src_pixbuf = out_image->pixbuf; w = gdk_pixbuf_get_width(src_pixbuf); h = gdk_pixbuf_get_height(src_pixbuf); pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, gdk_pixbuf_get_has_alpha(src_pixbuf), 8, w, 2 * h); gdk_pixbuf_copy_area(src_pixbuf, 0, 0, w, h, pixbuf, 0, 0); gdk_pixbuf_copy_area(in_image->pixbuf, 0, 0, w, h, pixbuf, 0, h); g_object_unref(out_image->pixbuf); out_image->pixbuf = pixbuf; } /* * Stolen shamelessly from gkrellm's demo2.c */ gint mpc_panel_expose_event(GtkWidget *widget, GdkEventExpose *ev) { gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE (widget)], mpc_panel->pixmap, ev->area.x, ev->area.y, ev->area.x, ev->area.y, ev->area.width, ev->area.height); return FALSE; } /* * Updates the global label var to the one supplied * taking care of free()ing etcetera */ void mpc_update_label (gchar * newlabel) { if (mpc_label) { free (mpc_label); } if (!newlabel) { newlabel = ""; } mpc_label = g_strdup(newlabel); } /* * Updates the global songname var to the one supplied * taking care of free()ing etcetera */ void mpc_update_songname (gchar * newname) { if (mpc_songname) { free (mpc_songname); } if (!newname) { newname = ""; } mpc_songname = g_strdup(newname); } /* * Queries mpd for status/songname * updates global vars with the results */ void mpc_sync_with_mpd() { GHashTable * status; GHashTable * currentsong; gchar * temp; gchar * state; gchar * time; gchar * artist; gchar * title; gchar * name; gint oldid; gchar * file; gchar * newlabel = NULL; gchar * newsongname = NULL; gint newplaylistversion; gchar ** parts; gint timesec; gchar * tiptext = NULL; status = mpc_mpd_get("status\n"); currentsong = mpc_mpd_get("currentsong\n"); if (!mpc_mpd) { mpc_update_label(_("NO MPD")); mpc_update_songname(""); gtk_tooltips_set_tip(mpc_tooltip, mpc_panel->drawing_area, _("MPD is not running"), NULL); } else if (!status || !currentsong) { mpc_update_label(_("MPD ERROR")); mpc_update_songname(""); mpc_mpd_disconnect(); gtk_tooltips_set_tip(mpc_tooltip, mpc_panel->drawing_area, _("Error communicating with MPD"), NULL); } else { /* Update global volume */ if (!mpc_volume_inmotion) mpc_volume = (gint)g_strtod(g_hash_table_lookup(status, "volume"), NULL); time = g_hash_table_lookup(status, "time"); /* Update pos */ if (!mpc_pos_inmotion) { if (time) { parts = g_strsplit(time, ":", 2); if (g_strtod(parts[1], NULL) == 0) mpc_pos = 100; else mpc_pos = 100 * g_strtod(parts[0], NULL) / g_strtod(parts[1], NULL); g_strfreev(parts); } else { mpc_pos = 0; } } /* Update global id */ oldid = mpc_id; temp = g_hash_table_lookup(currentsong, "id"); if (temp) mpc_id = g_strtod(temp, NULL); else mpc_id = -2; if (oldid != mpc_id) mpc_playlist_update_bold(); /* Update global label and songname */ file = g_hash_table_lookup(currentsong, "file"); artist = g_hash_table_lookup(currentsong, "artist"); title = g_hash_table_lookup(currentsong, "title"); name = g_hash_table_lookup(currentsong, "name"); state = g_hash_table_lookup(status, "state"); if (file) { tiptext = g_strdup_printf( _("Artist: %s\nTitle: %s\nFile: %s") , artist ? artist : _("N/A") , title ? title : _("N/A") , file ); } else { tiptext = g_strdup_printf(_("Empty playlist")); } gtk_tooltips_set_tip(mpc_tooltip, mpc_panel->drawing_area, tiptext, NULL); g_free(tiptext); if (strcmp(state, "stop") == 0) { newlabel = g_strdup(_("MPD STOPPED")); newsongname = g_strdup(""); } else { if (strcmp(state, "play") == 0) { parts = g_strsplit(time, ":", 2); timesec = g_strtod(parts[0], NULL); g_strfreev(parts); newlabel = g_strdup_printf(_("MPD %02d:%02d"), (int)((int)timesec/60), (int)((int)timesec % 60)); } else if (strcmp(state, "pause") == 0) { newlabel = g_strdup(_("MPD PAUSED")); } if (title && *title) { if (artist && *artist) { newsongname = g_strjoin(": ", artist, title, NULL); } else if (name && *name) { newsongname = g_strjoin(": ", name, title, NULL); } else { newsongname = g_strdup(title); } } else { newsongname = g_strdup(file); } } mpc_update_label(newlabel); mpc_update_songname(newsongname); free(newlabel); free(newsongname); /* Update global playlistversion */ newplaylistversion = g_strtod(g_hash_table_lookup(status, "playlist"), NULL); if (newplaylistversion != mpc_playlistversion) { if (mpc_playlist_update()) { mpc_playlistversion = newplaylistversion; } } } /* * Cleanup */ if (status) { g_hash_table_destroy(status); } if (currentsong) { g_hash_table_destroy(currentsong); } } /* * Stolen shamelessly from demo4 */ void mpc_update_volume_position(GkrellmKrell *k, gint x_ev) { gint x; gchar * command; gint newvolume; /* Consider only x_ev values that are inside the dynamic range of the | krell, ie from k->x0 to k->x0 + k->w_scale. The krell left and right | margins determined this range when the slider krell was created. | I also set the krell full_scale to be w_scale so I can simply update | the krell position to the x position within w_scale. */ x = x_ev - mpc_volume_krell->x0; if (x < 0) x = 0; if (x > mpc_volume_krell->w_scale) x = mpc_volume_krell->w_scale; /* * Set newvolume (between 0 and 100) */ newvolume = ((float)x / mpc_volume_krell->w_scale) * 100; /* * Tell mpd */ command = g_strdup_printf("setvol %d\n", newvolume); if (mpc_mpd_do(command)) { /* * Set the volume and update the slider */ mpc_volume = newvolume; gkrellm_update_krell(mpc_panel, mpc_volume_krell, mpc_volume); gkrellm_draw_panel_layers(mpc_panel); } g_free(command); } void mpc_update_pos_position(GkrellmKrell *k, gint x_ev) { gint x; gchar * command; gint newpos, seektime; GHashTable * status; gchar * state; gchar * time; gchar * song; gchar ** parts; status = mpc_mpd_get("status\n"); if (!status) return; state = g_hash_table_lookup(status, "state"); if (strcmp(state, "play") != 0) { /* Do nothing if we're not currently playing */ } else { x = x_ev - mpc_pos_krell->x0; if (x < 0) x = 0; if (x > mpc_pos_krell->w_scale) x = mpc_pos_krell->w_scale; /* * Set newpos (between 0 and 100) */ newpos = ((float)x / mpc_pos_krell->w_scale) * 100; /* * Tell mpd */ time = g_hash_table_lookup(status, "time"); song = g_hash_table_lookup(status, "song"); parts = g_strsplit(time, ":", 2); seektime = g_strtod(parts[1], NULL) * newpos / 100; g_strfreev(parts); command = g_strdup_printf("seek %s %d\n", song, seektime); if (mpc_mpd_do(command)) { /* * Set the pos and update the slider */ mpc_pos = newpos; gkrellm_update_krell(mpc_panel, mpc_pos_krell, mpc_pos); gkrellm_draw_panel_layers(mpc_panel); } g_free(command); } g_hash_table_destroy(status); } /* To make a krell work like a slider, we need to update the krell position | as a function of mouse position. * Stolen shamelessly from demo4 */ gint mpc_cb_panel_motion(GtkWidget *widget, GdkEventMotion *ev, gpointer data) { GdkModifierType state; if (mpc_volume_inmotion) { /* Check if button is still pressed, in case missed button_release */ state = ev->state; if (!(state & GDK_BUTTON1_MASK)) mpc_volume_inmotion = FALSE; else mpc_update_volume_position(mpc_volume_krell, (gint) ev->x); } else if (mpc_pos_inmotion) { /* Check if button is still pressed, in case missed button_release */ state = ev->state; if (!(state & GDK_BUTTON1_MASK)) mpc_pos_inmotion = FALSE; else mpc_update_pos_position(mpc_pos_krell, (gint) ev->x); } return TRUE; } gint mpc_cb_panel_release(GtkWidget *widget, GdkEventButton *ev, gpointer data) { if (mpc_volume_inmotion) mpc_volume_inmotion = FALSE; if (mpc_pos_inmotion) mpc_pos_inmotion = FALSE; return TRUE; } gint mpc_cb_panel_press(GtkWidget *widget, GdkEventButton *ev, gpointer data) { GkrellmKrell *k; gchar *cliptext; GtkClipboard * clipboard; if (ev->button == 2) { if (mpc_conf_middleclick == MPC_MIDDLECLICK_ACTION_DROP) { clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); cliptext = gtk_clipboard_wait_for_text(clipboard); if (cliptext) { mpc_url_drop(cliptext); g_free(cliptext); } } else { mpc_cb_button_play_pause(); } return TRUE; } else if (ev->button == 3) { if (mpc_conf_rightclick == MPC_RIGHTCLICK_ACTION_PLAYLIST) mpc_playlist_create(); else gkrellm_open_config_window(&mpc_plugin_mon); return TRUE; } /* Check if button was pressed within the space taken | up by the slider krell. */ mpc_volume_inmotion = FALSE; k = mpc_volume_krell; if ( ev->x > k->x0 && ev->x <= k->x0 + k->w_scale && ev->y >= k->y0 && ev->y <= k->y0 + k->h_frame ) mpc_volume_inmotion = TRUE; mpc_pos_inmotion = FALSE; k = mpc_pos_krell; if ( ev->x > k->x0 && ev->x <= k->x0 + k->w_scale && ev->y >= k->y0 && ev->y <= k->y0 + k->h_frame ) mpc_pos_inmotion = TRUE; if (mpc_volume_inmotion) mpc_update_volume_position(mpc_volume_krell, (gint) ev->x); if (mpc_pos_inmotion) mpc_update_pos_position(mpc_pos_krell, (gint) ev->x); return TRUE; } gint mpc_cb_panel_scroll(GtkWidget *widget, GdkEventScroll *ev, gpointer data) { gint newvolume = 0; gint newposition = 0; gchar * time; gchar * song; GHashTable * status; gchar ** parts; gchar * command; switch (ev->direction) { case GDK_SCROLL_UP: case GDK_SCROLL_RIGHT: if (mpc_conf_wheelaction == MPC_WHEEL_ACTION_VOLUME) newvolume = mpc_volume + mpc_conf_wheelamount; else newposition = mpc_pos + mpc_conf_wheelamount; break; case GDK_SCROLL_DOWN: case GDK_SCROLL_LEFT: if (mpc_conf_wheelaction == MPC_WHEEL_ACTION_VOLUME) newvolume = mpc_volume - mpc_conf_wheelamount; else newposition = mpc_pos - mpc_conf_wheelamount; break; } if (newvolume < 0) newvolume = 0; if (newvolume > 100) newvolume = 100; if (newposition < 0) newposition = 0; if (newposition > 100) newposition = 100; if (mpc_conf_wheelaction == MPC_WHEEL_ACTION_VOLUME && newvolume != mpc_volume) { /* Volume was changed */ command = g_strdup_printf("setvol %d\n", newvolume); if (mpc_mpd_do(command)) { /* MPD took it - set volume and update panel */ mpc_volume = newvolume; gkrellm_update_krell(mpc_panel, mpc_volume_krell, mpc_volume); gkrellm_draw_panel_layers(mpc_panel); } g_free(command); } else if (mpc_conf_wheelaction == MPC_WHEEL_ACTION_POSITION && newposition != mpc_pos) { /* Position was changed */ /* We need some stats from current song to prepare command */ status = mpc_mpd_get("status\n"); if (!status) return TRUE; time = g_hash_table_lookup(status, "time"); song = g_hash_table_lookup(status, "song"); if (time && song) { parts = g_strsplit(time, ":", 2); command = g_strdup_printf("seek %s %d\n", song, (int)(g_strtod(parts[1], NULL) * newposition / 100)); g_strfreev(parts); if (mpc_mpd_do(command)) { /* MPD took it - set position and update panel */ mpc_pos = newposition; gkrellm_update_krell(mpc_panel, mpc_pos_krell, mpc_pos); gkrellm_draw_panel_layers(mpc_panel); } g_free(command); } g_hash_table_destroy(status); } return TRUE; } /* * Gets called back when a drop happens on the panel */ void mpc_cb_panel_dragdatareceived (GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *data, guint info, guint t, gpointer userdata) { if (data->length) { mpc_url_drop(data->data); } gtk_drag_finish(dc, TRUE, FALSE, t); } /* * Gets called when the drag motion occurs over the panel */ gboolean mpc_cb_panel_dragmotion (GtkWidget *widget, GdkDragContext *dc, gint x, gint y, guint t, gpointer data) { /* * Anywhere in the panel is a viable drop area - don't bother checking coordinates or such */ gdk_drag_status(dc, GDK_ACTION_COPY, t); return(TRUE); } gkrellm-gkrellmpc-0.1~beta10/gkrellmpc.h000066400000000000000000000023241150314705300203110ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/gkrellmpc.h,v 1.17 2005/01/02 20:39:52 mina Exp $ */ #ifndef _GKRELLMPC_H #define _GKRELLMPC_H void mpc_disable_plugin (); void mpc_update_plugin (); void mpc_create_plugin (GtkWidget *, gint); GkrellmMonitor * gkrellm_init_plugin(); void mpc_cb_button_prev(); void mpc_cb_button_play_pause(); void mpc_cb_button_stop(); void mpc_cb_button_next(); void mpc_cb_button_eject(); void mpc_stack_images (GkrellmPiximage *, GkrellmPiximage *); gint mpc_panel_expose_event(GtkWidget *, GdkEventExpose *); void mpc_update_songname (gchar *); void mpc_update_label (gchar *); void mpc_sync_with_mpd(); void mpc_update_volume_position(GkrellmKrell *, gint); gint mpc_cb_panel_motion(GtkWidget *, GdkEventMotion *, gpointer); gint mpc_cb_panel_release(GtkWidget *, GdkEventButton *, gpointer); gint mpc_cb_panel_press(GtkWidget *, GdkEventButton *, gpointer); gint mpc_cb_panel_scroll(GtkWidget *, GdkEventScroll *, gpointer); void mpc_cb_panel_dragdatareceived (GtkWidget *widget, GdkDragContext *dc, gint x, gint y, GtkSelectionData *data, guint info, guint t, gpointer userdata); gboolean mpc_cb_panel_dragmotion (GtkWidget *widget, GdkDragContext *dc, gint x, gint y, guint t, gpointer data); #endif gkrellm-gkrellmpc-0.1~beta10/globals.h000066400000000000000000000030011150314705300177450ustar00rootroot00000000000000 /* * $Header: /cvsroot/gkrellmpc/globals.h,v 1.15 2005/03/04 18:06:58 mina Exp $ * * Holds all the global vars used by GkrellMPC */ #ifndef _GLOBALS_H #define _GLOBALS_H #define VERSION "0.1_beta10" #define PLUGIN_PLACEMENT MON_MAIL #define PLUGIN_NAME "GKrellMPC" #define PLUGIN_STYLE_NAME PLUGIN_NAME #include typedef enum { MPC_WHEEL_ACTION_VOLUME , MPC_WHEEL_ACTION_POSITION } MPC_WHEEL_ACTIONS; typedef enum { MPC_RIGHTCLICK_ACTION_CONFIG , MPC_RIGHTCLICK_ACTION_PLAYLIST } MPC_RIGHTCLICK_ACTIONS; typedef enum { MPC_MIDDLECLICK_ACTION_PAUSE , MPC_MIDDLECLICK_ACTION_DROP } MPC_MIDDLECLICK_ACTIONS; typedef enum { MPC_DROP_ACTION_CLEARADDPLAY , MPC_DROP_ACTION_ADDPLAY , MPC_DROP_ACTION_ADD } MPC_DROP_ACTIONS; /* * Globals from gkrellmpc.c */ extern GkrellmPanel * mpc_panel; extern GkrellmDecal * mpc_status_decal; extern gint mpc_id; /* * Globals from mpd.c */ extern GIOChannel * mpc_mpd; /* * Globals from conf.c */ extern gchar * mpc_conf_hostname; extern gint mpc_conf_port; extern gint mpc_conf_scrollspeed; extern MPC_WHEEL_ACTIONS mpc_conf_wheelaction; extern gint mpc_conf_wheelamount; extern MPC_RIGHTCLICK_ACTIONS mpc_conf_rightclick; extern MPC_MIDDLECLICK_ACTIONS mpc_conf_middleclick; extern MPC_DROP_ACTIONS mpc_conf_drop; /* * Globals from playlist.c */ extern GtkWidget * mpc_playlist; extern gint mpc_playlistversion; /* * Globals from addlist.c */ extern GtkWidget * mpc_addlist; #endif gkrellm-gkrellmpc-0.1~beta10/mpd.c000066400000000000000000000156651150314705300171200ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/mpd.c,v 1.6 2005/03/05 22:27:27 mina Exp $ * * Holds all the functions needed to talk to MPD */ #include "globals.h" #include "mpd.h" #include "gkrellmpc.h" #include #include #include GIOChannel * mpc_mpd = NULL; /* * Connects to the MPD server, sets up the mpd object, sets the status decal to ON */ gboolean mpc_mpd_connect() { int sockfd; struct hostent *server; struct sockaddr_in serv_addr; gchar * line; gchar ** parts; gboolean retval; if (mpc_mpd) { /* * Close existing connection */ mpc_mpd_disconnect(); } if (!mpc_conf_hostname || !mpc_conf_port) { return (FALSE); } if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) return(FALSE); if (!(server = gethostbyname(mpc_conf_hostname))) return(FALSE); bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(mpc_conf_port); if (connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) < 0) return(FALSE); /* Getup the mpd object */ mpc_mpd = g_io_channel_unix_new(sockfd); /* * Find the OK otherwise we connected to something not-MPDish */ if (g_io_channel_read_line(mpc_mpd, &line, NULL, NULL, NULL) == G_IO_STATUS_NORMAL) { g_strchomp(line); parts = g_strsplit(line, " ", 2); if (strcmp(parts[0], "OK") == 0) { retval = TRUE; } else { mpc_mpd_disconnect(); retval = FALSE; } g_strfreev(parts); } else { /* Read failed */ mpc_mpd_disconnect(); retval = FALSE; } if (retval) { gkrellm_draw_decal_pixmap(mpc_panel, mpc_status_decal, D_MISC_LED1); mpc_update_label(_("MPD")); mpc_update_songname(""); } return(retval); } /* * Disconnects from MPD, destroys the mpd object, sets the status decal to off */ gboolean mpc_mpd_disconnect() { if (mpc_mpd) { g_io_channel_shutdown(mpc_mpd, FALSE, NULL); free(mpc_mpd); mpc_mpd = NULL; } gkrellm_draw_decal_pixmap(mpc_panel, mpc_status_decal, D_MISC_LED0); mpc_update_label(_("NO MPD")); mpc_update_songname(""); return (TRUE); } /* * Sends a command to MPD * Returns true if successful, false if not * Use for bool-returning commands. Use mpd_get instead for data-returning commands */ gboolean mpc_mpd_do(gchar * command) { gchar *line; gboolean retval; if (!mpc_mpd && !mpc_mpd_connect()) { return (FALSE); } if (g_io_channel_write_chars(mpc_mpd, command, -1, NULL, NULL) == G_IO_STATUS_NORMAL) { g_io_channel_flush(mpc_mpd, NULL); if (g_io_channel_read_line(mpc_mpd, &line, NULL, NULL, NULL) == G_IO_STATUS_NORMAL) { g_strchomp(line); if (strcmp(line, "OK") == 0) { /* It's a success */ retval = TRUE; } else { /* It's a failure */ retval = FALSE; } } else { /* Read failed */ retval = FALSE; } } else { /* Write Failed */ retval = FALSE; } if (retval) mpc_sync_with_mpd(); return (retval); } /* * Sends a command to MPD * Returns a hashref of the results (needs to be freed with g_hash_table_destroy afterwards), NULL on error * Use for keypair-returning commands. Use mpd_do instead for boolean-returning commands * Note that all key names coming back from MPD are lowercased for consistency before being shoved in the hash */ GHashTable * mpc_mpd_get(gchar * command) { gchar *line; gchar **parts; GHashTable *retval = NULL; gboolean success = TRUE; GIOStatus status; if (!mpc_mpd && !mpc_mpd_connect()) { return (NULL); } if (g_io_channel_write_chars(mpc_mpd, command, -1, NULL, NULL) == G_IO_STATUS_NORMAL) { g_io_channel_flush(mpc_mpd, NULL); retval = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); while (1) { status = g_io_channel_read_line(mpc_mpd, &line, NULL, NULL, NULL); if (status != G_IO_STATUS_NORMAL) { /* Reading failed */ success = FALSE; break; } g_strchomp(line); if (strcmp(line, "OK") == 0) { /* End of resultset with success */ break; } else if (g_str_has_prefix(line, "ACK ")) { /* End of resultset with failure */ success = FALSE; break; } else { /* A resultset entry */ parts = g_strsplit(line, ": ", 2); if (!parts || !parts[0] || !parts[1]) { /* Resultset entry is not proper - ignore it */ } else { /* nice pair - add to hash */ g_hash_table_insert(retval, g_ascii_strdown(parts[0], -1), g_strdup(parts[1])); } g_strfreev(parts); } } if (!success) { g_hash_table_destroy(retval); retval = NULL; } } else { /* Write Failed */ retval = NULL; } /* If we've reached here, all is well */ return (retval); } /* * Sends a command to MPD * Returns an arrayref of hashrefs of the results, NULL on error * Use for keypair-returning commands that require clumping * Each hashref must be freed using g_hash_table_destroy, then the whole array must be freed with g_ptr_array_free * Note that all key names coming back from MPD are lowercased for consistency before being shoved in the hashes */ GPtrArray * mpc_mpd_get_clumps(gchar * command, gboolean clumpsingles) { gchar *line; gchar **parts; GPtrArray *retval = NULL; gboolean success = TRUE; GIOStatus status; int i; if (!mpc_mpd && !mpc_mpd_connect()) { return (NULL); } if (g_io_channel_write_chars(mpc_mpd, command, -1, NULL, NULL) == G_IO_STATUS_NORMAL) { g_io_channel_flush(mpc_mpd, NULL); retval = g_ptr_array_new(); while (1) { status = g_io_channel_read_line(mpc_mpd, &line, NULL, NULL, NULL); if (status != G_IO_STATUS_NORMAL) { /* Reading failed */ success = FALSE; break; } g_strchomp(line); if (strcmp(line, "OK") == 0) { /* End of resultset with success */ break; } else if (g_str_has_prefix(line, "ACK ")) { /* End of resultset with failure */ success = FALSE; break; } else { /* A resultset entry */ parts = g_strsplit(line, ": ", 2); if (!parts || !parts[0] || !parts[1]) { /* Resultset entry is not proper - ignore it */ } else { /* nice pair */ if (clumpsingles || retval->len == 0 || g_hash_table_lookup_extended(g_ptr_array_index(retval, retval->len -1), g_ascii_strdown(parts[0], -1), NULL, NULL)) { /* * Create a new hash and add it at the end of the array * Either because the array is empty, or the last hash already has this key so we need a new clump */ g_ptr_array_add(retval, g_hash_table_new_full(g_str_hash, g_str_equal, free, free)); } /* Add the key to the last hashref in the array */ g_hash_table_insert(g_ptr_array_index(retval, retval->len -1), g_ascii_strdown(parts[0], -1), g_strdup(parts[1])); } g_strfreev(parts); } } if (!success) { for (i=0; i < retval->len; i++) { g_hash_table_destroy(g_ptr_array_index(retval, i)); } g_ptr_array_free(retval, FALSE); retval = NULL; } } else { /* Write Failed */ retval = NULL; } /* If we've reached here, all is well */ return (retval); } gkrellm-gkrellmpc-0.1~beta10/mpd.h000066400000000000000000000004651150314705300171150ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/mpd.h,v 1.2 2005/01/01 19:19:49 mina Exp $ */ #ifndef _MPD_H #define _MPD_H gboolean mpc_mpd_connect(); gboolean mpc_mpd_disconnect(); gboolean mpc_mpd_do(gchar *); GHashTable * mpc_mpd_get(gchar *); GPtrArray * mpc_mpd_get_clumps(gchar *, gboolean); #endif gkrellm-gkrellmpc-0.1~beta10/pixmaps/000077500000000000000000000000001150314705300176405ustar00rootroot00000000000000gkrellm-gkrellmpc-0.1~beta10/pixmaps/eject.xpm000066400000000000000000000017721150314705300214670ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_eject0[] = { "12 9 55 1", " c None", ". c #ECE9E7", "+ c #E5E0DD", "@ c #D5CFCB", "# c #D5CDC9", "$ c #D5CECB", "% c #D6CECA", "& c #CCC5C1", "* c #AFA7A8", "= c #E0DCDA", "- c #D5CFCC", "; c #BAB1AE", "> c #BAB2AE", ", c #BCB2AE", "' c #AFA7A2", ") c #5F5754", "! c #C3BEBC", "~ c #ACA7A4", "{ c #9B9491", "] c #9B928E", "^ c #000000", "/ c #9D9492", "( c #9D9792", "_ c #7F7773", ": c #191818", "< c #C0BBB9", "[ c #A8A19E", "} c #948C89", "| c #938A88", "1 c #8A8481", "2 c #99918E", "3 c #776E6C", "4 c #BCB7B5", "5 c #A29D9A", "6 c #8F8884", "7 c #877F7E", "8 c #736C68", "9 c #AEABA8", "0 c #8F8A89", "a c #787270", "b c #7E7877", "c c #787572", "d c #7A7371", "e c #ABA6A5", "f c #8A8584", "g c #726B6A", "h c #736D6B", "i c #585150", "j c #9E9B9A", "k c #7C7776", "l c #524E4A", "m c #544F4D", "n c #524D4A", "o c #4A4645", "p c #848181", ".+@##$@@@%&*", "=-;>;;>>;,')", "!~{]]^]//(_:", "<[}|^^^1123:", "456^^^^^778:", "90aaabbbcd):", "efg^^^^^hhi:", "jklllmmmnno:", "p)::::::::::"}; gkrellm-gkrellmpc-0.1~beta10/pixmaps/eject_clicked.xpm000066400000000000000000000017531150314705300231440ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_eject1[] = { "12 9 54 1", " c None", ". c #191818", "+ c #5F5754", "@ c #848181", "# c #4A4645", "$ c #524D4A", "% c #544F4D", "& c #524E4A", "* c #7C7776", "= c #9E9B9A", "- c #585150", "; c #736D6B", "> c #726B6A", ", c #000000", "' c #8A8584", ") c #ABA6A5", "! c #7A7371", "~ c #787572", "{ c #787270", "] c #8F8A89", "^ c #AEABA8", "/ c #736C68", "( c #877F7E", "_ c #8D8884", ": c #8F8884", "< c #A29D9A", "[ c #BCB7B5", "} c #776E6C", "| c #99918E", "1 c #8A8481", "2 c #938A88", "3 c #948C89", "4 c #A8A19E", "5 c #C0BBB9", "6 c #7F7773", "7 c #9D9792", "8 c #9B928E", "9 c #9B9491", "0 c #ACA7A4", "a c #C3BEBC", "b c #AFA7A2", "c c #BCB2AE", "d c #BAB1AE", "e c #BAB2AE", "f c #D5CFCC", "g c #E0DCDA", "h c #AFA7A8", "i c #CCC5C1", "j c #D6CECA", "k c #D5CFCB", "l c #D5CECB", "m c #D5CDC9", "n c #E5E0DD", "o c #ECE9E7", "..........+@", ".#$$%%%&&&*=", ".-;;>,>>>>')", ".+!~,,,{{{]^", "./(,,,,,_:<[", ".}|111112345", ".67,,,,,890a", "+bcdeeddedfg", "hijkkklmmkno"}; gkrellm-gkrellmpc-0.1~beta10/pixmaps/next.xpm000066400000000000000000000017521150314705300213510ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_next0[] = { "12 9 54 1", " c None", ". c #ECE9E7", "+ c #E5E0DD", "@ c #D5CFCB", "# c #D5CDC9", "$ c #D5CECB", "% c #D6CECA", "& c #CCC5C1", "* c #AFA7A8", "= c #E0DCDA", "- c #D5CFCC", "; c #BAB1AE", "> c #BAB2AE", ", c #BCB2AE", "' c #AFA7A2", ") c #5F5754", "! c #C3BEBC", "~ c #ACA7A4", "{ c #9B9491", "] c #000000", "^ c #9B928E", "/ c #9D9492", "( c #9D9792", "_ c #7F7773", ": c #191818", "< c #C0BBB9", "[ c #A8A19E", "} c #948C89", "| c #8A8481", "1 c #99918E", "2 c #776E6C", "3 c #BCB7B5", "4 c #A29D9A", "5 c #8F8884", "6 c #877F7E", "7 c #736C68", "8 c #AEABA8", "9 c #8F8A89", "0 c #787270", "a c #7E7877", "b c #787572", "c c #7A7371", "d c #ABA6A5", "e c #8A8584", "f c #726B6A", "g c #736D6B", "h c #585150", "i c #9E9B9A", "j c #7C7776", "k c #524E4A", "l c #544F4D", "m c #524D4A", "n c #4A4645", "o c #848181", ".+@##$@@@%&*", "=-;>;;>>;,')", "!~{]^]^//(_:", "<[}]|]]||12:", "345]|]]]667:", "890]0]]abc):", "def]f]ffggh:", "ijkkklllmmn:", "o)::::::::::"}; gkrellm-gkrellmpc-0.1~beta10/pixmaps/next_clicked.xpm000066400000000000000000000017711150314705300230300ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_next1[] = { "12 9 55 1", " c None", ". c #191818", "+ c #5F5754", "@ c #848181", "# c #4A4645", "$ c #524D4A", "% c #544F4D", "& c #524E4A", "* c #7C7776", "= c #9E9B9A", "- c #585150", "; c #736D6B", "> c #000000", ", c #726B6A", "' c #8A8584", ") c #ABA6A5", "! c #7A7371", "~ c #7E7877", "{ c #787270", "] c #8F8A89", "^ c #AEABA8", "/ c #736C68", "( c #877F7E", "_ c #8A8481", ": c #8D8884", "< c #8F8884", "[ c #A29D9A", "} c #BCB7B5", "| c #776E6C", "1 c #99918E", "2 c #938A88", "3 c #948C89", "4 c #A8A19E", "5 c #C0BBB9", "6 c #7F7773", "7 c #9D9792", "8 c #9D9492", "9 c #9B928E", "0 c #9B9491", "a c #ACA7A4", "b c #C3BEBC", "c c #AFA7A2", "d c #BCB2AE", "e c #BAB1AE", "f c #BAB2AE", "g c #D5CFCC", "h c #E0DCDA", "i c #AFA7A8", "j c #CCC5C1", "k c #D6CECA", "l c #D5CFCB", "m c #D5CECB", "n c #D5CDC9", "o c #E5E0DD", "p c #ECE9E7", "..........+@", ".#$$%%%&&&*=", ".-;>,>,,,,')", ".+!>~>>{{{]^", "./(>_>>>:<[}", ".|1>_>>_2345", ".67>8>9990ab", "+cdeffeefegh", "ijklllmnnlop"}; gkrellm-gkrellmpc-0.1~beta10/pixmaps/play_pause.xpm000066400000000000000000000016631150314705300225360ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_playpause0[] = { "12 9 50 1", " c None", ". c #ECE9E7", "+ c #E5E0DD", "@ c #D5CFCB", "# c #D5CDC9", "$ c #D5CECB", "% c #D6CECA", "& c #CCC5C1", "* c #AFA7A8", "= c #E0DCDA", "- c #D5CFCC", "; c #BAB1AE", "> c #BAB2AE", ", c #BCB2AE", "' c #AFA7A2", ") c #5F5754", "! c #C3BEBC", "~ c #ACA7A4", "{ c #000000", "] c #9B928E", "^ c #9D9492", "/ c #9D9792", "( c #7F7773", "_ c #191818", ": c #C0BBB9", "< c #A8A19E", "[ c #8A8481", "} c #99918E", "| c #776E6C", "1 c #BCB7B5", "2 c #A29D9A", "3 c #877F7E", "4 c #736C68", "5 c #AEABA8", "6 c #8F8A89", "7 c #787270", "8 c #7E7877", "9 c #7A7371", "0 c #ABA6A5", "a c #8A8584", "b c #726B6A", "c c #736D6B", "d c #585150", "e c #9E9B9A", "f c #7C7776", "g c #524E4A", "h c #544F4D", "i c #524D4A", "j c #4A4645", "k c #848181", ".+@##$@@@%&*", "=-;>;;>>;,')", "!~{]]]{^{/(_", ":<{{[[{[{}|_", "12{{{[{[{34_", "56{{78{8{9)_", "0a{bbb{b{cd_", "efggghhhiij_", "k)__________"}; gkrellm-gkrellmpc-0.1~beta10/pixmaps/play_pause_clicked.xpm000066400000000000000000000016441150314705300242130ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_playpause1[] = { "12 9 49 1", " c None", ". c #191818", "+ c #5F5754", "@ c #848181", "# c #4A4645", "$ c #524D4A", "% c #544F4D", "& c #524E4A", "* c #7C7776", "= c #9E9B9A", "- c #585150", "; c #000000", "> c #736D6B", ", c #726B6A", "' c #8A8584", ") c #ABA6A5", "! c #7E7877", "~ c #787270", "{ c #8F8A89", "] c #AEABA8", "^ c #736C68", "/ c #8A8481", "( c #8F8884", "_ c #A29D9A", ": c #BCB7B5", "< c #776E6C", "[ c #948C89", "} c #A8A19E", "| c #C0BBB9", "1 c #7F7773", "2 c #9D9492", "3 c #9B928E", "4 c #9B9491", "5 c #ACA7A4", "6 c #C3BEBC", "7 c #AFA7A2", "8 c #BCB2AE", "9 c #BAB1AE", "0 c #BAB2AE", "a c #D5CFCC", "b c #E0DCDA", "c c #AFA7A8", "d c #CCC5C1", "e c #D6CECA", "f c #D5CFCB", "g c #D5CECB", "h c #D5CDC9", "i c #E5E0DD", "j c #ECE9E7", "..........+@", ".#$$%%%&&&*=", ".-;>,,;,;,')", ".+;;!!;~;~{]", ".^;;;/;/;(_:", ".<;;//;/;[}|", ".1;223;3;456", "+789009909ab", "cdefffghhfij"}; gkrellm-gkrellmpc-0.1~beta10/pixmaps/prev.xpm000066400000000000000000000020101150314705300213330ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_prev0[] = { "12 9 56 1", " c None", ". c #ECE9E7", "+ c #E5E0DD", "@ c #D5CFCB", "# c #D5CDC9", "$ c #D5CECB", "% c #D6CECA", "& c #CCC5C1", "* c #AFA7A8", "= c #E0DCDA", "- c #D5CFCC", "; c #BAB1AE", "> c #BAB2AE", ", c #BCB2AE", "' c #AFA7A2", ") c #5F5754", "! c #C3BEBC", "~ c #ACA7A4", "{ c #9B9491", "] c #99908C", "^ c #9B928E", "/ c #000000", "( c #9D9492", "_ c #9D9792", ": c #7F7773", "< c #191818", "[ c #C0BBB9", "} c #A8A19E", "| c #948C89", "1 c #938A88", "2 c #8A8481", "3 c #99918E", "4 c #776E6C", "5 c #BCB7B5", "6 c #A29D9A", "7 c #8F8884", "8 c #877F7E", "9 c #736C68", "0 c #AEABA8", "a c #8F8A89", "b c #787270", "c c #7E7877", "d c #787572", "e c #7A7371", "f c #ABA6A5", "g c #8A8584", "h c #726B6A", "i c #736D6B", "j c #585150", "k c #9E9B9A", "l c #7C7776", "m c #524E4A", "n c #544F4D", "o c #524D4A", "p c #4A4645", "q c #848181", ".+@##$@@@%&*", "=-;>;;>>;,')", "!~{]^/^/(_:<", "[}|1//2/234<", "567///2/889<", "0abb//c/de)<", "fghhh/h/iij<", "klmmmnnnoop<", "q)<<<<<<<<<<"}; gkrellm-gkrellmpc-0.1~beta10/pixmaps/prev_clicked.xpm000066400000000000000000000020101150314705300230110ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_prev1[] = { "12 9 56 1", " c None", ". c #191818", "+ c #5F5754", "@ c #848181", "# c #4A4645", "$ c #524D4A", "% c #544F4D", "& c #524E4A", "* c #7C7776", "= c #9E9B9A", "- c #585150", "; c #736D6B", "> c #726B6A", ", c #000000", "' c #8A8584", ") c #ABA6A5", "! c #7A7371", "~ c #787572", "{ c #7E7877", "] c #787270", "^ c #8F8A89", "/ c #AEABA8", "( c #736C68", "_ c #877F7E", ": c #8A8481", "< c #8D8884", "[ c #8F8884", "} c #A29D9A", "| c #BCB7B5", "1 c #776E6C", "2 c #99918E", "3 c #938A88", "4 c #948C89", "5 c #A8A19E", "6 c #C0BBB9", "7 c #7F7773", "8 c #9D9792", "9 c #9D9492", "0 c #9B928E", "a c #9B9491", "b c #ACA7A4", "c c #C3BEBC", "d c #AFA7A2", "e c #BCB2AE", "f c #BAB1AE", "g c #BAB2AE", "h c #D5CFCC", "i c #E0DCDA", "j c #AFA7A8", "k c #CCC5C1", "l c #D6CECA", "m c #D5CFCB", "n c #D5CECB", "o c #D5CDC9", "p c #E5E0DD", "q c #ECE9E7", "..........+@", ".#$$%%%&&&*=", ".-;;>,>,>>')", ".+!~,,{,]]^/", ".(_,,,:,<[}|", ".12:,,:,3456", ".7899,0,0abc", "+defggffgfhi", "jklmmmnoompq"}; gkrellm-gkrellmpc-0.1~beta10/pixmaps/stop.xpm000066400000000000000000000017141150314705300213560ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_stop0[] = { "12 9 52 1", " c None", ". c #ECE9E7", "+ c #E5E0DD", "@ c #D5CFCB", "# c #D5CDC9", "$ c #D5CECB", "% c #D6CECA", "& c #CCC5C1", "* c #AFA7A8", "= c #E0DCDA", "- c #D5CFCC", "; c #BAB1AE", "> c #BAB2AE", ", c #BCB2AE", "' c #AFA7A2", ") c #5F5754", "! c #C3BEBC", "~ c #ACA7A4", "{ c #9B9491", "] c #000000", "^ c #9D9492", "/ c #9D9792", "( c #7F7773", "_ c #191818", ": c #C0BBB9", "< c #A8A19E", "[ c #948C89", "} c #8A8481", "| c #99918E", "1 c #776E6C", "2 c #BCB7B5", "3 c #A29D9A", "4 c #8F8884", "5 c #877F7E", "6 c #736C68", "7 c #AEABA8", "8 c #8F8A89", "9 c #787270", "0 c #787572", "a c #7A7371", "b c #ABA6A5", "c c #8A8584", "d c #726B6A", "e c #736D6B", "f c #585150", "g c #9E9B9A", "h c #7C7776", "i c #524E4A", "j c #544F4D", "k c #524D4A", "l c #4A4645", "m c #848181", ".+@##$@@@%&*", "=-;>;;>>;,')", "!~{]]]]]^/(_", ":<[]]]]]}|1_", "234]]]]]556_", "789]]]]]0a)_", "bcd]]]]]eef_", "ghiiijjjkkl_", "m)__________"}; gkrellm-gkrellmpc-0.1~beta10/pixmaps/stop_clicked.xpm000066400000000000000000000017141150314705300230340ustar00rootroot00000000000000/* XPM */ char * mpc_xpm_stop1[] = { "12 9 52 1", " c None", ". c #191818", "+ c #5F5754", "@ c #848181", "# c #4A4645", "$ c #524D4A", "% c #544F4D", "& c #524E4A", "* c #7C7776", "= c #9E9B9A", "- c #585150", "; c #736D6B", "> c #000000", ", c #726B6A", "' c #8A8584", ") c #ABA6A5", "! c #7A7371", "~ c #787270", "{ c #8F8A89", "] c #AEABA8", "^ c #736C68", "/ c #877F7E", "( c #8D8884", "_ c #8F8884", ": c #A29D9A", "< c #BCB7B5", "[ c #776E6C", "} c #99918E", "| c #938A88", "1 c #948C89", "2 c #A8A19E", "3 c #C0BBB9", "4 c #7F7773", "5 c #9D9792", "6 c #9B928E", "7 c #9B9491", "8 c #ACA7A4", "9 c #C3BEBC", "0 c #AFA7A2", "a c #BCB2AE", "b c #BAB1AE", "c c #BAB2AE", "d c #D5CFCC", "e c #E0DCDA", "f c #AFA7A8", "g c #CCC5C1", "h c #D6CECA", "i c #D5CFCB", "j c #D5CECB", "k c #D5CDC9", "l c #E5E0DD", "m c #ECE9E7", "..........+@", ".#$$%%%&&&*=", ".-;>>>>>,,')", ".+!>>>>>~~{]", ".^/>>>>>(_:<", ".[}>>>>>|123", ".45>>>>>6789", "+0abccbbcbde", "fghiiijkkilm"}; gkrellm-gkrellmpc-0.1~beta10/playlist.c000066400000000000000000000257561150314705300202030ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/playlist.c,v 1.22 2005/03/06 02:29:07 mina Exp $ * * Holds all the function for playlist manipulation */ #include "globals.h" #include "playlist.h" #include "mpd.h" #include "addlist.h" #include GtkWidget * mpc_playlist = NULL; gint mpc_playlist_width = -1; gint mpc_playlist_height = 350; gint mpc_playlistversion = -1; GtkListStore * mpc_playlist_store = NULL; GtkWidget * mpc_playlist_tree = NULL; enum mpc_playlist_columns { MPC_PLAYLIST_COLUMN_BOLD = 0 , MPC_PLAYLIST_COLUMN_ID , MPC_PLAYLIST_COLUMN_ARTIST , MPC_PLAYLIST_COLUMN_TITLE , MPC_PLAYLIST_COLUMNS }; /* * Creates (or activates) the playlist window */ void mpc_playlist_create(void) { GtkWidget * scrollwindow; GtkTreeSelection * selection; GtkWidget *vbox; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkWidget * buttonbar; GtkWidget * button; if (!mpc_playlist) { /* * Create the playlist window */ mpc_playlist = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_wmclass(GTK_WINDOW(mpc_playlist), "playlist", "gkrellmpc"); gtk_window_set_title(GTK_WINDOW(mpc_playlist), _("MPD PLAYLIST")); gtk_container_border_width (GTK_CONTAINER(mpc_playlist), 10); gtk_window_set_default_size(GTK_WINDOW(mpc_playlist), mpc_playlist_width, mpc_playlist_height); gtk_window_set_position(GTK_WINDOW(mpc_playlist), GTK_WIN_POS_CENTER); g_signal_connect(GTK_OBJECT(mpc_playlist), "configure_event", G_CALLBACK(mpc_playlist_configure_event), NULL); g_signal_connect(GTK_OBJECT(mpc_playlist), "delete_event", G_CALLBACK(mpc_playlist_delete_event), NULL); g_signal_connect(GTK_OBJECT(mpc_playlist), "destroy", G_CALLBACK(mpc_playlist_destroy_event), NULL); g_signal_connect(mpc_playlist, "key-release-event", G_CALLBACK(mpc_cb_playlist_key), NULL); /* * Create the data store */ mpc_playlist_store = gtk_list_store_new(MPC_PLAYLIST_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING); /* * Create playlist tree */ mpc_playlist_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(mpc_playlist_store)); gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(mpc_playlist_tree), TRUE); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mpc_playlist_tree)); gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); g_signal_connect(mpc_playlist_tree, "row-activated", G_CALLBACK(mpc_cb_playlist_row), NULL); g_signal_connect(mpc_playlist_tree, "key-release-event", G_CALLBACK(mpc_cb_playlist_key), NULL); /* * Create the scrollwindow the playlist goes in */ scrollwindow = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwindow), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER(scrollwindow), mpc_playlist_tree); /* * Create the visual columns */ renderer = gtk_cell_renderer_text_new (); g_object_set(renderer , "weight", 700 , "weight-set", FALSE , NULL ); column = gtk_tree_view_column_new_with_attributes (_("Artist"), renderer , "weight-set", MPC_PLAYLIST_COLUMN_BOLD , "text", MPC_PLAYLIST_COLUMN_ARTIST , NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(mpc_playlist_tree), column); renderer = gtk_cell_renderer_text_new (); g_object_set(renderer , "weight", 700 , "weight-set", FALSE , NULL ); column = gtk_tree_view_column_new_with_attributes (_("Title"), renderer , "weight-set", MPC_PLAYLIST_COLUMN_BOLD , "text", MPC_PLAYLIST_COLUMN_TITLE , NULL); gtk_tree_view_set_search_column(GTK_TREE_VIEW(mpc_playlist_tree), MPC_PLAYLIST_COLUMN_TITLE); gtk_tree_view_append_column(GTK_TREE_VIEW(mpc_playlist_tree), column); /* * Create the bottom buttons */ buttonbar = gtk_hbutton_box_new(); button = gtk_button_new_from_stock(GTK_STOCK_ADD); g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(mpc_cb_playlist_button_add), NULL); gtk_container_add(GTK_CONTAINER(buttonbar), button); button = gtk_button_new_from_stock(GTK_STOCK_REMOVE); g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(mpc_cb_playlist_button_remove), NULL); gtk_container_add(GTK_CONTAINER(buttonbar), button); button = gtk_button_new_from_stock(GTK_STOCK_CLEAR); g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(mpc_cb_playlist_button_clear), NULL); gtk_container_add(GTK_CONTAINER(buttonbar), button); button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); g_signal_connect(GTK_OBJECT(button), "clicked", G_CALLBACK(mpc_cb_playlist_button_close), NULL); gtk_container_add(GTK_CONTAINER(buttonbar), button); /* * And pack everything */ vbox = gtk_vbox_new(FALSE, 8); gtk_box_pack_start(GTK_BOX(vbox), scrollwindow, 1, 1, 0); gtk_box_pack_start(GTK_BOX(vbox), buttonbar, 0, 0, 0); gtk_container_add(GTK_CONTAINER(mpc_playlist), vbox); /* * Update the playlist */ mpc_playlist_update(); /* * Finally show everything */ gtk_widget_show_all(mpc_playlist); } else { /* * Make the playlist window the foreground window */ gtk_window_present(GTK_WINDOW(mpc_playlist)); } } /* * Gets called when the window manager tries to close the playlist window */ gint mpc_playlist_delete_event(GtkContainer *container, GtkWidget *widget, gpointer user_data) { return(FALSE); } /* * Gets called when the playlist window is about to be destroyed */ void mpc_playlist_destroy_event(GtkWidget *widget, gpointer data) { /* Blow it up :) */ gtk_list_store_clear(mpc_playlist_store); mpc_playlist = NULL; mpc_playlist_store = NULL; mpc_playlist_tree = NULL; mpc_id = -1; } /* * If the playlist window exists, updates it with the playlist from mpd */ gboolean mpc_playlist_update(void) { GPtrArray * list; GHashTable * hash; GtkTreeIter iter; int i; gint id; gchar * artist; gchar * name; gchar * title; if (!mpc_playlist) { /* * There's no playlist, so there's nothing to do */ return(TRUE); } else { /* * Get the playlist from mpd */ list = mpc_mpd_get_clumps("playlistinfo\n", FALSE); if (!list) { return (FALSE); } /* * Populate it */ gtk_list_store_clear(mpc_playlist_store); for (i=0; i < list->len; i++) { hash = g_ptr_array_index(list, i); /* Add new row to store */ gtk_list_store_append(mpc_playlist_store, &iter); /* Set local vars id, artist, name and title */ id = g_strtod(g_hash_table_lookup(hash, "id"), NULL); artist = g_hash_table_lookup(hash, "artist"); name = g_hash_table_lookup(hash, "name"); title = g_hash_table_lookup(hash, "title"); if (!title) title = g_hash_table_lookup(hash, "file"); /* Set them in the store */ gtk_list_store_set(mpc_playlist_store, &iter , MPC_PLAYLIST_COLUMN_BOLD, (id == mpc_id ? TRUE : FALSE) , MPC_PLAYLIST_COLUMN_ID, id , MPC_PLAYLIST_COLUMN_ARTIST, (artist ? artist : name ? name : "") , MPC_PLAYLIST_COLUMN_TITLE, title , -1); g_hash_table_destroy(hash); } g_ptr_array_free(list, FALSE); return (TRUE); } } /* * Called when the "clear" button is clicked in the playlist window */ void mpc_cb_playlist_button_clear (GtkButton *button, gpointer user_data) { mpc_mpd_do("clear\n"); } /* * Called when the "remove" button is clicked in the playlist window */ void mpc_cb_playlist_button_remove (GtkButton *button, gpointer user_data) { GtkTreeSelection * selection; GArray * selected; gint i; gchar * command; /* * Populate selected with the id of selected rows */ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(mpc_playlist_tree)); selected = g_array_new(FALSE, TRUE, sizeof(gint)); gtk_tree_selection_selected_foreach(selection, mpc_cb_delete_foreach, selected); for (i=0; i < selected->len; i++) { command = g_strdup_printf("deleteid %d\n", g_array_index(selected, gint, i)); mpc_mpd_do(command); g_free(command); } g_array_free(selected, FALSE); } /* * Gets called from mpc_cb_playlist_button_remove for each selected row * It's job is to add the id of that row's song into the given array */ void mpc_cb_delete_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { gint id; gtk_tree_model_get(GTK_TREE_MODEL(mpc_playlist_store), iter , MPC_PLAYLIST_COLUMN_ID, &id , -1); g_array_append_val(data, id); } /* * Called when the "add" button is clicked in the playlist window */ void mpc_cb_playlist_button_add (GtkButton *button, gpointer user_data) { mpc_addlist_create(); } /* * Called when the "close" button is clicked in the playlist window */ void mpc_cb_playlist_button_close (GtkButton *button, gpointer user_data) { gtk_widget_destroy(mpc_playlist); } /* * Called when the user double-clicks/hits enter on a playlist row */ void mpc_cb_playlist_row (GtkTreeView *tree, GtkTreePath *path, GtkTreeViewColumn *col, gpointer user_data) { GtkTreeIter iter; gint id; gchar * command; if (gtk_tree_model_get_iter(GTK_TREE_MODEL(mpc_playlist_store), &iter, path)) { gtk_tree_model_get(GTK_TREE_MODEL(mpc_playlist_store), &iter , MPC_PLAYLIST_COLUMN_ID, &id , -1); command = g_strdup_printf("playid %d\n", id); mpc_mpd_do(command); g_free(command); } } /* * Called when a user presses a key in the playlist window or tree */ gboolean mpc_cb_playlist_key (GtkWidget *widget, GdkEventKey *event, gpointer user_data) { if (widget == mpc_playlist) { /* * Key pressed in main window */ switch (event->keyval) { case GDK_Escape: /* They pressed Escape - destroy the playlist */ gtk_widget_destroy(mpc_playlist); return (TRUE); } } else if (widget == mpc_playlist_tree) { /* * Key pressed in tree */ switch (event->keyval) { case GDK_Delete: case GDK_KP_Delete: /* They pressed delete - simulate a "Remove" button keypress */ mpc_cb_playlist_button_remove(NULL, NULL); return (TRUE); } } /* * If we've reached here tell GTK to send the key upwards */ return (FALSE); } /* * If the playlist window is open, it makes "bold" the song ID in mpc_id */ void mpc_playlist_update_bold (void) { GtkTreeIter iter; gint id; if (!mpc_playlist) { /* No playlist - nothing to do */ } else { if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mpc_playlist_store), &iter)) { /* Store is empty */ } else { while (1) { /* iter points to an entry * get id */ gtk_tree_model_get(GTK_TREE_MODEL(mpc_playlist_store), &iter , MPC_PLAYLIST_COLUMN_ID, &id , -1); if (id == mpc_id) { /* We found the one that should be bold */ gtk_list_store_set(mpc_playlist_store, &iter, MPC_PLAYLIST_COLUMN_BOLD, TRUE, -1); } else { /* Whatever this is should not be bold */ gtk_list_store_set(mpc_playlist_store, &iter, MPC_PLAYLIST_COLUMN_BOLD, FALSE, -1); } if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(mpc_playlist_store), &iter)) { /* No more entries in store */ break; } } } } } gboolean mpc_playlist_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data) { /* Remember width & height */ mpc_playlist_width = event->width; mpc_playlist_height = event->height; return(FALSE); } gkrellm-gkrellmpc-0.1~beta10/playlist.h000066400000000000000000000016421150314705300201740ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/playlist.h,v 1.10 2005/03/06 02:29:07 mina Exp $ */ #ifndef _PLAYLIST_H #define _PLAYLIST_H void mpc_playlist_create(void); gboolean mpc_playlist_configure_event(GtkWidget *, GdkEventConfigure *, gpointer); gint mpc_playlist_delete_event(GtkContainer *, GtkWidget *, gpointer); gboolean mpc_playlist_update(void); void mpc_cb_playlist_button_clear (GtkButton *, gpointer); void mpc_cb_playlist_button_remove (GtkButton *, gpointer); void mpc_cb_delete_foreach (GtkTreeModel *, GtkTreePath *, GtkTreeIter *, gpointer); void mpc_cb_playlist_button_add (GtkButton *, gpointer); void mpc_cb_playlist_button_close (GtkButton *, gpointer); void mpc_cb_playlist_row (GtkTreeView *, GtkTreePath *, GtkTreeViewColumn *, gpointer); gboolean mpc_cb_playlist_key (GtkWidget *, GdkEventKey *, gpointer); void mpc_playlist_update_bold (void); void mpc_playlist_destroy_event(GtkWidget *, gpointer); #endif gkrellm-gkrellmpc-0.1~beta10/po/000077500000000000000000000000001150314705300165755ustar00rootroot00000000000000gkrellm-gkrellmpc-0.1~beta10/po/Makefile000066400000000000000000000014121150314705300202330ustar00rootroot00000000000000# # $Header: /cvsroot/gkrellmpc/po/Makefile,v 1.1 2005/03/05 22:27:27 mina Exp $ # MSGFMT = msgfmt FILES_PO:=$(wildcard *.po) FILES_MO:=$(FILES_PO:.po=.mo) PREFIX ?= "/usr/share" LOCALEDIR ?= $(PREFIX)/locale PKGNAME ?= gkrellmpc .PHONY: install ifeq ($(enable_nls),1) all: mo-files mo-files: $(FILES_MO) install: $(MAKE) all for f in *.mo ; do mkdir -p \ $(LOCALEDIR)/`basename $$f .mo`/LC_MESSAGES ; \ cp $$f $(LOCALEDIR)/`basename $$f .mo`/LC_MESSAGES/$(PKGNAME).mo ; done uninstall: for f in $(FILES_MO) ; do \ rm $(LOCALEDIR)/`basename $$f .mo`/LC_MESSAGES/$(PKGNAME).mo ; done %.mo: %.po $(MSGFMT) -f -v -o $@ $< else all: install: endif pot: xgettext -d $(PKGNAME) --keyword=_ --keyword=N_ -C -o $(PKGNAME).pot ../*.c clean: $(RM) $(FILES_MO) gkrellm-gkrellmpc-0.1~beta10/po/gkrellmpc.pot000066400000000000000000000061421150314705300213040ustar00rootroot00000000000000# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER # This file is distributed under the same license as the PACKAGE package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2005-03-05 17:18+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: ../addlist.c:48 msgid "MPD ADD SONGS" msgstr "" #: ../addlist.c:110 msgid "Name" msgstr "" #: ../addlist.c:248 msgid "URL could not be added" msgstr "" #: ../conf.c:45 msgid "Configuration" msgstr "" #: ../conf.c:47 msgid "MPD hostname:" msgstr "" #: ../conf.c:53 msgid "MPD port:" msgstr "" #: ../conf.c:59 msgid "Scrolling speed:" msgstr "" #: ../conf.c:63 msgid "Mouse wheel:" msgstr "" #: ../conf.c:65 msgid "Adjusts volume" msgstr "" #: ../conf.c:66 msgid "Adjusts position" msgstr "" #: ../conf.c:70 msgid "Mouse wheel adjustment:" msgstr "" #: ../conf.c:74 msgid "Right click:" msgstr "" #: ../conf.c:76 msgid "Opens configuration" msgstr "" #: ../conf.c:77 msgid "Opens playlist" msgstr "" #: ../conf.c:81 msgid "Middle click:" msgstr "" #: ../conf.c:83 msgid "Pauses" msgstr "" #: ../conf.c:84 msgid "Simulates drop from clipboard" msgstr "" #: ../conf.c:88 msgid "Drag-drop URL into panel will:" msgstr "" #: ../conf.c:90 msgid "Clear playlist, add URL and play it" msgstr "" #: ../conf.c:91 msgid "Add URL and play it" msgstr "" #: ../conf.c:92 msgid "Just add URL" msgstr "" #: ../conf.c:100 msgid "Help" msgstr "" #: ../conf.c:102 msgid "" "For help please visit the support forums at the MPD web site:\n" "http://www.musicpd.org\n" "\n" "Alternatively email the author at webmaster@topfx.com" msgstr "" #: ../conf.c:106 #, c-format msgid "About %s" msgstr "" #: ../conf.c:110 #, c-format msgid "" "Plugin version %s\n" "\n" "Written by Mina Naguib \n" "http://www.topfx.com\n" "\n" "Copyright (C) 2004-2005 Mina Naguib\n" "Released under the GPL license version 2" msgstr "" #: ../gkrellmpc.c:77 ../mpd.c:76 msgid "MPD" msgstr "" #: ../gkrellmpc.c:78 msgid "Not connected" msgstr "" #: ../gkrellmpc.c:155 ../gkrellmpc.c:156 msgid "Vol:" msgstr "" #: ../gkrellmpc.c:169 ../gkrellmpc.c:170 msgid "Pos:" msgstr "" #: ../gkrellmpc.c:460 ../mpd.c:95 msgid "NO MPD" msgstr "" #: ../gkrellmpc.c:462 msgid "MPD is not running" msgstr "" #: ../gkrellmpc.c:465 msgid "MPD ERROR" msgstr "" #: ../gkrellmpc.c:468 msgid "Error communicating with MPD" msgstr "" #: ../gkrellmpc.c:511 #, c-format msgid "" "Artist: %s\n" "Title: %s\n" "File: %s" msgstr "" #: ../gkrellmpc.c:515 msgid "MPD STOPPED" msgstr "" #: ../gkrellmpc.c:524 #, c-format msgid "MPD %02d:%02d" msgstr "" #: ../gkrellmpc.c:527 msgid "MPD PAUSED" msgstr "" #: ../playlist.c:45 msgid "MPD PLAYLIST" msgstr "" #: ../playlist.c:85 msgid "Artist" msgstr "" #: ../playlist.c:97 msgid "Title" msgstr "" #: ../url.c:236 #, c-format msgid "URL (%s) could not be added" msgstr "" gkrellm-gkrellmpc-0.1~beta10/po/ru.po000066400000000000000000000104411150314705300175630ustar00rootroot00000000000000# Russian translations for gkrellmpc package # Copyright (C) 2005 drF_ckoff # This file is distributed under the same license as the gkrellmpc package. # Sergey Pinaev , 2005. # msgid "" msgstr "" "Project-Id-Version: gkrellmpc 0.1_beta10\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2005-03-05 17:18+0300\n" "PO-Revision-Date: 2005-03-05 15:52+0300\n" "Last-Translator: Sergey Pinaev \n" "Language-Team: Russian \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=KOI8-R\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%" "10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" #: ../addlist.c:48 msgid "MPD ADD SONGS" msgstr "Добавление песен" #: ../addlist.c:110 msgid "Name" msgstr "Имя" #: ../addlist.c:248 msgid "URL could not be added" msgstr "URL не может быть добавлен" #: ../conf.c:45 msgid "Configuration" msgstr "Настрока" #: ../conf.c:47 msgid "MPD hostname:" msgstr "Адрес сервера MPD:" #: ../conf.c:53 msgid "MPD port:" msgstr "Порт сервера MPD:" #: ../conf.c:59 msgid "Scrolling speed:" msgstr "Скорость прокрутки:" #: ../conf.c:63 msgid "Mouse wheel:" msgstr "Колесо мыши:" #: ../conf.c:65 msgid "Adjusts volume" msgstr "Регулирует громкость" #: ../conf.c:66 msgid "Adjusts position" msgstr "Перемотка" #: ../conf.c:70 msgid "Mouse wheel adjustment:" msgstr "Подстройка колеса мыши:" #: ../conf.c:74 msgid "Right click:" msgstr "Правая кнопка мыши:" #: ../conf.c:76 msgid "Opens configuration" msgstr "Открывает окно настроек" #: ../conf.c:77 msgid "Opens playlist" msgstr "Открывает список воспроизведения" #: ../conf.c:81 msgid "Middle click:" msgstr "Средняя кнопка мыши:" #: ../conf.c:83 msgid "Pauses" msgstr "Пауза" #: ../conf.c:84 msgid "Simulates drop from clipboard" msgstr "Получить содержимое буфера обмена" #: ../conf.c:88 msgid "Drag-drop URL into panel will:" msgstr "\"Притаскивание\" URL на панель:" #: ../conf.c:90 msgid "Clear playlist, add URL and play it" msgstr "Очищает список воспроизведения, добавляет URL и воспроизводит его" #: ../conf.c:91 msgid "Add URL and play it" msgstr "Добавляет URL и воспроизводит его" #: ../conf.c:92 msgid "Just add URL" msgstr "" #: ../conf.c:100 msgid "Help" msgstr "Помощь" #: ../conf.c:102 msgid "" "For help please visit the support forums at the MPD web site:\n" "http://www.musicpd.org\n" "\n" "Alternatively email the author at webmaster@topfx.com" msgstr "" "Для получения помощи посетите форумы на странице MPD:\n" "http://www.musicpd.org\n" "Или напишите письмо автору по адресу webmaster@topfx.com" #: ../conf.c:106 #, c-format msgid "About %s" msgstr "О %s" #: ../conf.c:110 #, c-format msgid "" "Plugin version %s\n" "\n" "Written by Mina Naguib \n" "http://www.topfx.com\n" "\n" "Copyright (C) 2004-2005 Mina Naguib\n" "Released under the GPL license version 2" msgstr "" "Плагин версии %s\n" "\n" "\n" "Написан Mina Naguib \n" "http://www.topfx.com\n" "\n" "Copyright (C) 2004-2005 Mina Naguib\n" "Распространяется под лицензией GPL версии 2" #: ../gkrellmpc.c:77 ../mpd.c:76 msgid "MPD" msgstr "MPD" #: ../gkrellmpc.c:78 msgid "Not connected" msgstr "Не подключен" #: ../gkrellmpc.c:155 ../gkrellmpc.c:156 msgid "Vol:" msgstr "Ур:" #: ../gkrellmpc.c:169 ../gkrellmpc.c:170 msgid "Pos:" msgstr "Поз:" #: ../gkrellmpc.c:460 ../mpd.c:95 msgid "NO MPD" msgstr "НЕТ MPD" #: ../gkrellmpc.c:462 msgid "MPD is not running" msgstr "MPD не запущен" #: ../gkrellmpc.c:465 msgid "MPD ERROR" msgstr "Ошибка MPD" #: ../gkrellmpc.c:468 msgid "Error communicating with MPD" msgstr "Ошибка при разговоре с MPD" #: ../gkrellmpc.c:511 #, c-format msgid "" "Artist: %s\n" "Title: %s\n" "File: %s" msgstr "" "Исполнитель: %s\n" "Название: %s\n" "Файл: %s" #: ../gkrellmpc.c:515 msgid "MPD STOPPED" msgstr "MPD остановлен" #: ../gkrellmpc.c:524 #, c-format msgid "MPD %02d:%02d" msgstr "MPD %02d:%02d" #: ../gkrellmpc.c:527 msgid "MPD PAUSED" msgstr "MPD приостановлен" #: ../playlist.c:45 msgid "MPD PLAYLIST" msgstr "Список проигрывания MPD" #: ../playlist.c:85 msgid "Artist" msgstr "Исполнитель" #: ../playlist.c:97 msgid "Title" msgstr "Название" #: ../url.c:236 #, c-format msgid "URL (%s) could not be added" msgstr "URL (%s) не может быть добавлен" #~ msgid "Plugin version " #~ msgstr "Плагин версии " gkrellm-gkrellmpc-0.1~beta10/url.c000066400000000000000000000127541150314705300171360ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/url.c,v 1.3 2005/01/03 21:47:27 mina Exp $ * * Holds all the functions for url manpilation in in gkrellmpc */ #include "globals.h" #include "url.h" #include "mpd.h" #include CURL * mpc_curl = NULL; gchar * mpc_url_contenttype = NULL; gchar * mpc_url_content = NULL; /* * Call once to initialize libcurl */ void mpc_url_init (void) { mpc_url_cleanup(); mpc_curl = curl_easy_init(); } /* * Call once to de-initialize libcurl */ void mpc_url_cleanup (void) { if (mpc_curl) { curl_easy_cleanup(mpc_curl); mpc_curl = NULL; } } /* * Give it a URL * It'll reply back with (a possibly different) URL suitable for adding to MPD * or NULL if your original URL was garbage * returned URL should be freed */ gchar * mpc_url_parse (const gchar * url) { gchar * retval = NULL; gchar ** lines = NULL; gchar ** templines = NULL; gchar ** parts = NULL; double bytesin = 0; mpc_url_init(); /* Prepare globals */ if (mpc_url_contenttype) { g_free(mpc_url_contenttype); mpc_url_contenttype = NULL; } if (mpc_url_content) { g_free(mpc_url_content); mpc_url_content = NULL; } /* Fire up curl */ curl_easy_setopt(mpc_curl, CURLOPT_URL, url); curl_easy_setopt(mpc_curl, CURLOPT_HEADERFUNCTION, mpc_url_header); curl_easy_setopt(mpc_curl, CURLOPT_WRITEFUNCTION, mpc_url_data); curl_easy_perform(mpc_curl); curl_easy_getinfo(mpc_curl, CURLINFO_SIZE_DOWNLOAD, &bytesin); if (!mpc_url_contenttype) { /* Cannot determine the content type */ if (bytesin > 0) { /* But we connected ! It looks like an icecase server */ retval = g_strdup(url); } } else if (strcmp(mpc_url_contenttype, "audio/x-scpls") == 0) { /* * We have a shoutcast playlist * * Parse it looking for "fileX" */ lines = g_strsplit_set(mpc_url_content, "\r\n", 0); if (lines) { templines = lines; while (templines[0] && !retval) { parts = g_strsplit(templines[0], "=", 2); if (parts) { if (parts[0] && parts[1]) { if (g_strncasecmp(parts[0], "file", 4) == 0 && strlen(parts[0]) >= 5 && g_ascii_isdigit(parts[0][4])) { /* We found "fileX" - it's value is what we want */ retval = mpc_url_parse(parts[1]); } } g_strfreev(parts); } templines++; } g_strfreev(lines); } } if (mpc_url_contenttype) { g_free(mpc_url_contenttype); mpc_url_contenttype = NULL; } if (mpc_url_content) { g_free(mpc_url_content); mpc_url_content= NULL; } return (retval); } /* * Gets called by curl through mpc_url_parse * It's job is to set mpc_url_contenttype when it matches the content-type header */ size_t mpc_url_header(void *ptr, size_t size, size_t nmemb, void *stream) { gint len; gchar ** parts = NULL; gchar ** parts2 = NULL; parts = g_strsplit(ptr, ": ", 2); if (!parts) parts = g_strsplit(ptr, ":", 2); if (parts) { if (parts[0] && parts[1]) { if (g_strcasecmp(parts[0], "content-type") == 0) { parts2 = g_strsplit_set(parts[1], "; \n\r", 0); if (parts2) { if (parts2[0]) { /* We found the content-type */ if (mpc_url_contenttype) g_free(mpc_url_contenttype); mpc_url_contenttype = g_strdup(parts2[0]); } g_strfreev(parts2); } } } g_strfreev(parts); } len = size * nmemb; return(len); } /* * Gets called by curl through mpc_url_parse * It's job is to set mpc_url_content */ size_t mpc_url_data(void *ptr, size_t size, size_t nmemb, void *stream) { gint len; gchar * data = NULL; gchar * newcontent = NULL; len = size * nmemb; if (!mpc_url_contenttype || strcmp(mpc_url_contenttype, "audio/x-scpls") != 0 ) { /* If the content-type was not caught or is bad, forget about the content */ return (-1); } data = g_strndup(ptr, len); if (mpc_url_content) { newcontent = g_strdup_printf("%s%s", mpc_url_content, data); g_free(mpc_url_content); } else { newcontent = g_strdup(data); } mpc_url_content = newcontent; g_free(data); return(len); } /* * Takes a url that got dropped * Takes appropriate action on it based on user prefs */ void mpc_url_drop (gchar * droppedurl) { gchar * newurl = NULL; gchar * command = NULL; GPtrArray * list; GHashTable * hash; int i; gint id = -1; GtkWidget * errordialog; if (!droppedurl) { // Null url ? Ignore it } else { newurl = mpc_url_parse(droppedurl); if (newurl) { /* * They dropped a good URL */ if (mpc_conf_drop == MPC_DROP_ACTION_CLEARADDPLAY) { /* Clear the playlist */ mpc_mpd_do("clear\n"); } /* Add it to the playlist */ command = g_strdup_printf("add \"%s\"\n", newurl); mpc_mpd_do(command); g_free(command); if (mpc_conf_drop == MPC_DROP_ACTION_CLEARADDPLAY || mpc_conf_drop == MPC_DROP_ACTION_ADDPLAY) { /* Play it */ list = mpc_mpd_get_clumps("playlistinfo\n", FALSE); if (list) { for (i=0; i < list->len; i++) { hash = g_ptr_array_index(list, i); id = g_strtod(g_hash_table_lookup(hash, "id"), NULL); g_hash_table_destroy(hash); } g_ptr_array_free(list, FALSE); } /* Now "id" should have the id of the last entry in the playlist */ if (id >= 0) { command = g_strdup_printf("playid %d\n", id); mpc_mpd_do(command); g_free(command); } } g_free(newurl); } else { /* * They dropped a bad URL */ errordialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "URL (%s) could not be added", droppedurl); gtk_dialog_run(GTK_DIALOG(errordialog)); gtk_widget_destroy(errordialog); } } } gkrellm-gkrellmpc-0.1~beta10/url.h000066400000000000000000000006231150314705300171330ustar00rootroot00000000000000/* * $Header: /cvsroot/gkrellmpc/url.h,v 1.2 2005/01/03 21:47:27 mina Exp $ */ #ifndef _URL_H #define _URL_H void mpc_url_init (void); void mpc_url_cleanup (void); gchar * mpc_url_parse (const gchar *); size_t mpc_url_header(void *ptr, size_t size, size_t nmemb, void *stream); size_t mpc_url_data(void *ptr, size_t size, size_t nmemb, void *stream); void mpc_url_drop (gchar * droppedurl); #endif