📄 gui-callbacks.c
字号:
/* Glurp - A GTK+ client for Music Player Daemon Copyright (C) 2004, 2005 Andrej Kacian This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA http://musicpd.org/glurp.shtml*/#include <glib.h>#include <gtk/gtk.h>#include <glade/glade.h>#include <stdlib.h>#include "structs.h"#include "support.h"#include "comm.h"#include "gui.h"#include "player.h"#include "conf.h"extern GladeXML *guixml, *configxml, *plxml, *addxml, *streamxml;extern GlurpState *glurp;void on_ui_quit(GtkWidget *widget, gpointer user_data) { debug("Quitting Glurp..."); if( glurp->conn ) glurp_disconnect(); config_save(); gtk_main_quit();}gboolean on_window_moved(GtkWidget *widget, GdkEventConfigure *event, gpointer data) { debug("Storing window position and size (%dx%d+%d+%d)", event->width, event->height, event->x, event->y); glurp->config->pos_x = event->x; glurp->config->pos_y = event->y; glurp->config->width = event->width; glurp->config->height = event->height; return FALSE;}/* called when config button is pressed in main window */gboolean on_ui_press_config(GtkWidget *widget, gpointer user_data) { GtkWidget *window_config; if(configxml) { debug("Config window already shown, returning"); return FALSE; } debug("Displaying config window..."); configxml = glade_xml_new(glade_path(), "glurp_window_config", NULL); glade_xml_signal_autoconnect(configxml); populate_config(); window_config = glade_xml_get_widget(configxml, "glurp_window_config"); title_print(window_config, "Config"); gtk_widget_show(window_config); return FALSE;}gboolean on_button_config_cancel_clicked(GtkWidget *widget, gpointer user_data) { GtkWidget *window_config = glade_xml_get_widget(configxml, "glurp_window_config"); debug("Cancel pressed, destroying config window..."); gtk_widget_destroy(window_config); return FALSE;}gboolean on_config_destroy(GtkWidget *widget, gpointer user_data) { debug("freeing configxml"); configxml = NULL; gui_refresh_playlist_columns(); return FALSE;}gboolean on_button_config_ok_clicked(GtkWidget *widget, gpointer user_data) { GtkWidget *window_config; debug("OK pressed, hiding config window..."); debug("Storing variables into GlurpConfig"); store_config(); config_save(); window_config = glade_xml_get_widget(configxml, "glurp_window_config"); gtk_widget_destroy(window_config); statusbar_print("Config saved..."); return FALSE;}gboolean on_ui_press_connect(GtkWidget *widget, gpointer user_data) { glurp_connect(); return FALSE;}gboolean on_ui_press_disconnect(GtkWidget *widget, gpointer user_data) { glurp_disconnect(); return FALSE;}gboolean on_ui_volume_changed(GtkWidget *widget, gpointer user_data) { gint i = gtk_range_get_value(GTK_RANGE(widget)); if( glurp->conn ) { mpd_sendSetvolCommand(glurp->conn, i); mpd_finishCommand(glurp->conn); if( check_mpd_error() ) { glurp_disconnect(); return FALSE; } statusbar_print("Volume: %d%%", i); } return FALSE;}gboolean on_ui_progress_change(GtkWidget *widget, gpointer user_data) { mpd_Status *status = NULL; double sec, pos, tt; gint t_min, t_sec, s_min, s_sec; if(!glurp->progress_dragging) return FALSE; status = get_status(TRUE); tt = status->totalTime; t_min = (int)tt/60; t_sec = (int)tt%60; pos = gtk_range_get_value(GTK_RANGE(widget)); sec = (pos / 100)*tt; s_min = (int)sec/60; s_sec = (int)sec%60; debug("Seeking to %d seconds", (gint)sec); statusbar_print("Seek to %02d:%02d/%02d:%02d", s_min, s_sec, t_min, t_sec); mpd_sendSeekCommand(glurp->conn, status->song, sec); mpd_finishCommand(glurp->conn); if( check_mpd_error() ) { glurp_disconnect(); return FALSE; } debug("setting FALSE"); glurp->progress_dragging = FALSE; return FALSE;}gboolean on_ui_progress_change_start(GtkWidget *widget, gpointer user_data) { debug("setting TRUE"); glurp->progress_dragging = TRUE; return FALSE;}gboolean on_ui_playlist_clicked(GtkWidget *widget, gpointer user_data) { if( !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) ) hide_gui_playlist(); else show_gui_playlist(); return FALSE;}gboolean on_ui_player_play(GtkWidget *widget, gpointer user_data) { mpd_Status *status = get_status(TRUE); GtkTreeView *tv; GtkTreeModel *tm; GtkTreeSelection *sel; GtkTreePath *path; GtkTreeIter iter; gint id, pos, num; GList *selected_rows; if(!status) { debug("status == NULL"); return FALSE; } if(!glurp->playlist) { debug("Nothing loaded in playlist, cannot play"); statusbar_print("Playlist empty"); return FALSE; } if( status->state == MPD_STATUS_STATE_PAUSE ) player_pause(); else { tv = GTK_TREE_VIEW(glade_xml_get_widget(guixml, "treeview_playlist")); tm = gtk_tree_view_get_model(tv); sel = gtk_tree_view_get_selection(tv); if( !(num = gtk_tree_selection_count_selected_rows(sel)) ) { debug("No song selected, letting MPD decide which song to play"); if( !STOPPED ) player_stop(); player_play_song(-1); return FALSE; } if( !(selected_rows = gtk_tree_selection_get_selected_rows(sel, &tm)) ) { debug("Couldn't get selected rows"); return FALSE; } path = (GtkTreePath *)g_list_nth_data(selected_rows, 0); if ( !gtk_tree_model_get_iter(tm, &iter, path) ) { debug("Couldn't get GtkTreeIter, what now?"); return FALSE; } debug("Getting trackno. of selected song"); gtk_tree_model_get(tm, &iter, PL_ID, &id, PL_TRACK, &pos, -1); debug("Song number is %d, id %d", pos, id); if( num > 1 ) gui_playlist_set_cursor(pos - 1); if( !STOPPED ) player_stop(); player_play_song(id); } return FALSE;}gboolean on_ui_player_pause(GtkWidget *widget, gpointer user_data) { player_pause(); return FALSE;}gboolean on_ui_player_stop(GtkWidget *widget, gpointer user_data) { player_stop(); return FALSE;}gboolean on_ui_player_prev(GtkWidget *widget, gpointer user_data) { player_prev(); return FALSE;}gboolean on_ui_player_next(GtkWidget *widget, gpointer user_data) { player_next(); return FALSE;}gboolean on_ui_time_clicked(GtkWidget *widget, gpointer user_data) { if(glurp->config->time_display_left) glurp->config->time_display_left = FALSE; else glurp->config->time_display_left = TRUE; gtk_widget_grab_focus(glade_xml_get_widget(guixml, "treeview_playlist")); return FALSE;}gboolean on_ui_playlist_row_activated(GtkTreeView *treeview, GtkTreePath *tp, GtkTreeViewColumn *col, gpointer user_data) { GtkTreeIter act; GtkTreeModel *model; gint id; debug("Playlist item activated."); if(!glurp->conn) { debug("We're not connected, cannot start playing anything."); return FALSE; } model = gtk_tree_view_get_model(treeview); gtk_tree_model_get_iter(model, &act, tp); gtk_tree_model_get(model, &act, PL_ID, &id, -1); player_stop(); player_play_song(id); return FALSE;}gboolean on_ui_playlists_clicked(GtkWidget *widget, gpointer user_data) { GtkWidget *window_playlist; if(plxml) { debug("Playlists window already displayed, returning"); return FALSE; } if( !glurp->conn ) { debug("we're not connected"); return FALSE; } plxml = glade_xml_new(glade_path(), "glurp_window_playlist_list", NULL); glade_xml_signal_autoconnect(plxml); get_playlist_list(); create_playlist_list_liststore(); populate_gui_playlist_list(); window_playlist = glade_xml_get_widget(plxml, "glurp_window_playlist_list"); title_print(window_playlist, "Playlists"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(plxml, "checkbutton_append_playlist")), FALSE); gtk_widget_show(window_playlist); return FALSE;}gboolean on_ui_playlist_close(GtkWidget *widget, gpointer user_data) { GtkWidget *w = glade_xml_get_widget(plxml, "glurp_window_playlist_list"); debug("Destroying playlist list window."); gtk_widget_destroy(w); return FALSE;}gboolean on_window_playlists_destroy(GtkWidget *widget, gpointer user_data) { playlists_window_destroyed(); return FALSE;}gboolean on_window_add_destroy(GtkWidget *widget, gpointer user_data) { add_window_destroyed(); return FALSE;}gboolean on_ui_playlist_list_row_activated(GtkTreeView *treeview, GtkTreePath *tp, GtkTreeViewColumn *col, gpointer user_data) { GtkTreeIter act; GtkTreeModel *model; gchar *name; debug("playlist activated"); if( !glurp->conn ) { debug("we're not connected, how can this be?"); return FALSE; } model = gtk_tree_view_get_model(treeview); gtk_tree_model_get_iter(model, &act, tp); gtk_tree_model_get(model, &act, 0, &name, -1); load_playlist(name); g_free(name); debug("Destroying playlist list window."); gtk_widget_destroy(glade_xml_get_widget(plxml, "glurp_window_playlist_list")); playlists_window_destroyed(); return FALSE;}gboolean on_ui_playlist_load(GtkWidget *widget, gpointer user_data) { GtkTreeView *tv; GtkTreeModel *tm; GtkTreeSelection *sel; GtkTreeIter iter; gchar *name; if( !glurp->conn ) { debug("We're not connected, how can this be? Just closing the window"); gtk_widget_destroy(glade_xml_get_widget(configxml, "glurp_window_playlist_list")); return FALSE; } tv = GTK_TREE_VIEW(glade_xml_get_widget(plxml, "treeview_playlist_list")); tm = gtk_tree_view_get_model(tv); sel = gtk_tree_view_get_selection(tv); if( !gtk_tree_selection_get_selected(sel, &tm, &iter)) { debug("No playlist selected"); return FALSE; } debug("getting name of selected playlist"); gtk_tree_model_get(tm, &iter, 0, &name, -1); load_playlist(name); g_free(name); debug("Destroying playlist list window."); gtk_widget_destroy(glade_xml_get_widget(plxml, "glurp_window_playlist_list")); playlists_window_destroyed(); return FALSE;}gboolean on_ui_playlist_delete(GtkWidget *widget, gpointer user_data) { GtkTreeView *tv; GtkTreeModel *tm; GtkTreeSelection *sel; GtkTreeIter iter; gchar *name; if( !glurp->conn ) { debug("We're not connected, how can this be? Just closing the window"); gtk_widget_destroy(glade_xml_get_widget(configxml, "glurp_window_playlist_list")); return FALSE; } tv = GTK_TREE_VIEW(glade_xml_get_widget(plxml, "treeview_playlist_list")); tm = gtk_tree_view_get_model(tv);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -