📄 gui.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 "conf.h"#include "player.h"#include "gui.h"extern GladeXML *guixml, *configxml, *plxml, *addxml, *streamxml;extern GlurpState *glurp;/* this should only be called at startup */gboolean glurp_init_gui() { GtkWidget *window_main = NULL;/* PangoFontDescription *time_font; time_font = pango_font_description_from_string("Sans 14");*/ glurp->progress_dragging = FALSE; glurp->gui_playlist = NULL; debug("Trying to load glurp.glade from installed directory first"); if( !(guixml = glade_xml_new( glade_path(), NULL, NULL )) ) { debug("Could not load glade file, giving up. Goodnight."); } glade_xml_signal_autoconnect( guixml ); create_playlist_liststore(); gtk_tree_view_set_reorderable(GTK_TREE_VIEW(glade_xml_get_widget(guixml, "treeview_playlist")), TRUE); gtk_combo_box_set_active(GTK_COMBO_BOX(glade_xml_get_widget(guixml, "combobox_qsearch_type")), GLURP_QSEARCH_ALL);/* gtk_widget_modify_font(glade_xml_get_widget(guixml, "button_time"), time_font); */ /* put correct icons to player control buttons */ /* prev */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "button_prev")), gtk_image_new_from_file(DATADIR "pixmaps/player-prev.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "button_prev")); /* play */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "button_play")), gtk_image_new_from_file(DATADIR "pixmaps/player-play.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "button_play")); /* pause */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "button_pause")), gtk_image_new_from_file(DATADIR "pixmaps/player-pause.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "button_pause")); /* stop */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "button_stop")), gtk_image_new_from_file(DATADIR "pixmaps/player-stop.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "button_stop")); /* next */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "button_next")), gtk_image_new_from_file(DATADIR "pixmaps/player-next.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "button_next")); /* connect/disconnect */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "button_server_disconnect")), gtk_image_new_from_file(DATADIR "pixmaps/offline.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "button_server_disconnect")); gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "button_server_connect")), gtk_image_new_from_file(DATADIR "pixmaps/online.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "button_server_connect")); /* config */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "button_config")), gtk_image_new_from_file(DATADIR "pixmaps/config.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "button_config")); /* playlist show/hide */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "togglebutton_playlist")), gtk_image_new_from_file(DATADIR "pixmaps/playlist.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "togglebutton_playlist")); /* repeat */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "togglebutton_repeat")), gtk_image_new_from_file(DATADIR "pixmaps/player-repeat.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "togglebutton_repeat")); /* random */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "togglebutton_random")), gtk_image_new_from_file(DATADIR "pixmaps/player-random.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "togglebutton_random")); /* add */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "togglebutton_pl_add")), gtk_image_new_from_file(DATADIR "pixmaps/add.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "togglebutton_pl_add")); /* remove */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "togglebutton_pl_remove")), gtk_image_new_from_file(DATADIR "pixmaps/remove.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "togglebutton_pl_remove")); /* playlists */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "button_playlists")), gtk_image_new_from_file(DATADIR "pixmaps/playlists.png")); gtk_widget_show_all(glade_xml_get_widget(guixml, "button_playlists")); /* outputs */ gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(guixml, "togglebutton_outputs")), gtk_image_new_from_file(DATADIR "pixmaps/outputs.png")); /* optionally show playlist */ show_gui_playlist(); if(glurp->config->playlist_vis_on_start) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_playlist")), TRUE); } else { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_playlist")), FALSE); hide_gui_playlist(); } gui_set_disconnected(); window_main = glade_xml_get_widget( guixml, "glurp_window_main" ); title_print(window_main, NULL); gui_refresh_playlist_columns();/* a futile attempt to restore saved position if( glurp->config->pos_x != -11000 && glurp->config->pos_y != -11000 ) gtk_window_move(GTK_WINDOW(window_main), glurp->config->pos_x, glurp->config->pos_y);*/ /* restore window size if requested */ if( glurp->config->width >= 0 && glurp->config->height >= 0 && glurp->config->save_size ) gtk_window_resize(GTK_WINDOW(window_main), glurp->config->width, glurp->config->height); gtk_window_set_icon(GTK_WINDOW(window_main), gdk_pixbuf_new_from_file(DATADIR "pixmaps/media-audiofile.png", NULL)); debug("Showing main window..."); gtk_widget_show(window_main); return TRUE;}void populate_config() { GtkWidget *w; w = glade_xml_get_widget(configxml, "entry_hostname"); if(glurp->config->server_host) gtk_entry_set_text(GTK_ENTRY(w), glurp->config->server_host); w = glade_xml_get_widget(configxml, "entry_port"); if(glurp->config->server_port) gtk_entry_set_text(GTK_ENTRY(w), g_strdup_printf("%d", glurp->config->server_port)); w = glade_xml_get_widget(configxml, "entry_password"); if(glurp->config->server_pass) gtk_entry_set_text(GTK_ENTRY(w), glurp->config->server_pass); w = glade_xml_get_widget(configxml, "checkbutton_autoconnect"); if(glurp->config->autoconnect) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); w = glade_xml_get_widget(configxml, "checkbutton_save_size"); if(glurp->config->autoconnect) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); w = glade_xml_get_widget(configxml, "checkbutton_playlist_vis"); if(glurp->config->playlist_vis_on_start) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); w = glade_xml_get_widget(configxml, "spinbutton_refresh_rate"); gtk_spin_button_set_value(GTK_SPIN_BUTTON(w), glurp->config->refresh_rate); w = glade_xml_get_widget(configxml, "checkbutton_col_filename"); if(glurp->config->playlist_columns[PL_FILENAME]) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); w = glade_xml_get_widget(configxml, "checkbutton_col_artist"); if(glurp->config->playlist_columns[PL_ARTIST]) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); w = glade_xml_get_widget(configxml, "checkbutton_col_title"); if(glurp->config->playlist_columns[PL_TITLE]) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); w = glade_xml_get_widget(configxml, "checkbutton_col_album"); if(glurp->config->playlist_columns[PL_ALBUM]) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); w = glade_xml_get_widget(configxml, "checkbutton_col_name"); if(glurp->config->playlist_columns[PL_NAME]) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); w = glade_xml_get_widget(configxml, "checkbutton_col_pos"); if(glurp->config->playlist_columns[PL_POS]) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0); w = glade_xml_get_widget(configxml, "checkbutton_col_id"); if(glurp->config->playlist_columns[PL_ID]) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 1); else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w), 0);} void store_config() { GtkWidget *w; long nr; g_free(glurp->config->server_host); w = glade_xml_get_widget(configxml, "entry_hostname"); glurp->config->server_host = g_strdup(gtk_entry_get_text(GTK_ENTRY(w))); w = glade_xml_get_widget(configxml, "entry_port"); glurp->config->server_port = atoi(gtk_entry_get_text(GTK_ENTRY(w))); g_free(glurp->config->server_pass); w = glade_xml_get_widget(configxml, "entry_password"); glurp->config->server_pass = g_strdup(gtk_entry_get_text(GTK_ENTRY(w))); w = glade_xml_get_widget(configxml, "checkbutton_autoconnect"); glurp->config->autoconnect = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); w = glade_xml_get_widget(configxml, "checkbutton_playlist_vis"); glurp->config->playlist_vis_on_start = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); w = glade_xml_get_widget(configxml, "spinbutton_refresh_rate"); nr = gtk_spin_button_get_value(GTK_SPIN_BUTTON(w)); if( nr != glurp->config->refresh_rate ) { debug("Refresh rate changed, setting timeout to %dms", nr); glurp->refresh_rate_status++; /* a safety check to keep the counter in loop */ if( glurp->refresh_rate_status > 30000 ) glurp->refresh_rate_status = 0; g_timeout_add(nr, gui_update_cb, GINT_TO_POINTER(glurp->refresh_rate_status)); glurp->config->refresh_rate = nr; } w = glade_xml_get_widget(configxml, "checkbutton_save_size"); glurp->config->save_size = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); w = glade_xml_get_widget(configxml, "checkbutton_col_filename"); glurp->config->playlist_columns[PL_FILENAME] = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); w = glade_xml_get_widget(configxml, "checkbutton_col_artist"); glurp->config->playlist_columns[PL_ARTIST] = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); w = glade_xml_get_widget(configxml, "checkbutton_col_title"); glurp->config->playlist_columns[PL_TITLE] = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); w = glade_xml_get_widget(configxml, "checkbutton_col_album"); glurp->config->playlist_columns[PL_ALBUM] = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); w = glade_xml_get_widget(configxml, "checkbutton_col_name"); glurp->config->playlist_columns[PL_NAME] = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); w = glade_xml_get_widget(configxml, "checkbutton_col_pos"); glurp->config->playlist_columns[PL_POS] = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))); w = glade_xml_get_widget(configxml, "checkbutton_col_id"); glurp->config->playlist_columns[PL_ID] = yesno(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)));} void create_playlist_liststore() { GtkListStore *liststore; GtkTreeViewColumn *column; GtkCellRenderer *rend; GtkWidget *tv; if(glurp->gui_playlist) return; liststore = gtk_list_store_new( NUM_PL, G_TYPE_STRING, /* filename */ G_TYPE_STRING, /* artist */ G_TYPE_STRING, /* title */ G_TYPE_STRING, /* album */ G_TYPE_STRING, /* track */ G_TYPE_STRING, /* name */ G_TYPE_INT, /* pos */ G_TYPE_INT, /* id */ G_TYPE_INT, /* bold */ G_TYPE_BOOLEAN /* bold-set */ ); debug("playlist liststore created"); tv = glade_xml_get_widget(guixml, "treeview_playlist"); gtk_tree_view_set_model(GTK_TREE_VIEW(tv), GTK_TREE_MODEL(liststore)); gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(tv)), GTK_SELECTION_MULTIPLE); rend = gtk_cell_renderer_text_new(); column = gtk_tree_view_column_new_with_attributes("Filename", rend, "text", PL_FILENAME, "weight", PL_BOLD, "weight-set", PL_BOLD_SET, NULL); gtk_tree_view_column_set_resizable(column, TRUE); column = gtk_tree_view_column_new_with_attributes("Artist", rend, "text", PL_ARTIST, "weight", PL_BOLD, "weight-set", PL_BOLD_SET, NULL); gtk_tree_view_column_set_resizable(column, TRUE); column = gtk_tree_view_column_new_with_attributes("Title", rend, "text", PL_TITLE, "weight", PL_BOLD, "weight-set", PL_BOLD_SET, NULL); gtk_tree_view_column_set_resizable(column, TRUE); column = gtk_tree_view_column_new_with_attributes("Album", rend, "text", PL_ALBUM, "weight", PL_BOLD, "weight-set", PL_BOLD_SET, NULL); gtk_tree_view_column_set_resizable(column, TRUE); column = gtk_tree_view_column_new_with_attributes("Track", rend, "text", PL_TRACK, "weight", PL_BOLD, "weight-set", PL_BOLD_SET, NULL); gtk_tree_view_column_set_resizable(column, FALSE); column = gtk_tree_view_column_new_with_attributes("#", rend, "text", PL_POS, "weight", PL_BOLD, "weight-set", PL_BOLD_SET, NULL); gtk_tree_view_column_set_resizable(column, TRUE); column = gtk_tree_view_column_new_with_attributes("Id", rend, "text", PL_ID, "weight", PL_BOLD, "weight-set", PL_BOLD_SET, NULL); gtk_tree_view_column_set_resizable(column, TRUE); gtk_widget_show(tv); glurp->gui_playlist = liststore;}void add_song_to_gui_playlist(GlurpSong *song, gint pos) { GtkTreeIter iter; if( !glurp->gui_playlist ) { debug("No playlist liststore!"); return; } if( !song ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -