⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui.c

📁 Glurp is a GTK+-2.x based graphical client for the Music Player Daemon !
💻 C
📖 第 1 页 / 共 4 页
字号:
    debug("song == NULL, ignoring");    return;  }  gtk_list_store_append(glurp->gui_playlist, &iter);  gtk_list_store_set(glurp->gui_playlist, &iter, PL_POS, pos, -1);  if(song->file && g_utf8_validate(song->file, -1, NULL))    gtk_list_store_set(glurp->gui_playlist, &iter, PL_FILENAME, song->file, -1);  if(song->artist && g_utf8_validate(song->artist, -1, NULL))    gtk_list_store_set(glurp->gui_playlist, &iter, PL_ARTIST, song->artist, -1);      if(song->title && g_utf8_validate(song->title, -1, NULL))    gtk_list_store_set(glurp->gui_playlist, &iter, PL_TITLE, song->title, -1);  if(song->album && g_utf8_validate(song->album, -1, NULL))    gtk_list_store_set(glurp->gui_playlist, &iter, PL_ALBUM, song->album, -1);  if(song->track && g_utf8_validate(song->track, -1, NULL))    gtk_list_store_set(glurp->gui_playlist, &iter, PL_TRACK, song->track, -1);  if(song->name && g_utf8_validate(song->name, -1, NULL))    gtk_list_store_set(glurp->gui_playlist, &iter, PL_NAME, song->name, -1);  if( song->pos )    gtk_list_store_set(glurp->gui_playlist, &iter, PL_POS, song->pos + 1, -1);  if( song->id )    gtk_list_store_set(glurp->gui_playlist, &iter, PL_ID, song->id, -1);}void populate_gui_playlist() {  GlurpSong *s = NULL;  gint i = 1;  gtk_list_store_clear(glurp->gui_playlist);  for( s = glurp->playlist; s; s = s->next ) {    add_song_to_gui_playlist(s, i);    i++;  }  statusbar_print("Playlist updated from server");}void hide_gui_playlist() {  gint width, height;  gtk_widget_hide(glade_xml_get_widget(guixml, "vbox_playlist"));  gtk_window_get_size(GTK_WINDOW(glade_xml_get_widget(guixml, "glurp_window_main")), &width, &height);  gtk_window_resize(GTK_WINDOW(glade_xml_get_widget(guixml, "glurp_window_main")), width, 1);}void show_gui_playlist() {  gtk_widget_show(glade_xml_get_widget(guixml, "vbox_playlist"));}void create_playlist_list_liststore() {  GtkListStore *ls;  GtkTreeViewColumn *col;  GtkCellRenderer *rend;  GtkWidget *tv;  if(glurp->gui_playlist_list) return;  debug("Creating playlist list liststore...");  ls = gtk_list_store_new(1, G_TYPE_STRING);  tv = glade_xml_get_widget(plxml, "treeview_playlist_list");  gtk_tree_view_set_model(GTK_TREE_VIEW(tv), GTK_TREE_MODEL(ls));  rend = gtk_cell_renderer_text_new();  col = gtk_tree_view_column_new_with_attributes("Filename", rend, "text", 0, NULL);  gtk_tree_view_column_set_resizable(col, FALSE);  gtk_tree_view_append_column(GTK_TREE_VIEW(tv), col);  gtk_widget_show(tv);  glurp->gui_playlist_list = ls;  debug("Playlist list liststore created");}void gui_set_connecting() {  gtk_widget_hide(glade_xml_get_widget(guixml, "button_server_disconnect"));  gtk_widget_show(glade_xml_get_widget(guixml, "button_server_connect"));}void gui_set_connected() {  mpd_Status *status = NULL;    if( !(status = get_status(TRUE)) ) {    debug("Couldn't get mpd state, disconnecting");    glurp_disconnect();    return;  }  if( status->repeat ) {    debug("MPD repeat is ON");    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_repeat")), TRUE);  } else {    debug("MPD repeat is OFF");    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_repeat")), FALSE);  }  if( status->random ) {    debug("MPD random is ON");    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_random")), TRUE);  } else {    debug("MPD random is OFF");    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_random")), FALSE);  }  gtk_widget_set_sensitive(glade_xml_get_widget(guixml, "volumebar"), TRUE);  if( OUTPUTS_CAPABLE_MPD )    gtk_widget_show_all(glade_xml_get_widget(guixml, "togglebutton_outputs"));}    void gui_set_disconnected() {  gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(guixml, "entry_trackname")), "Not connected...");  gtk_widget_set_sensitive(glade_xml_get_widget(guixml, "progressbar"), FALSE);  gtk_widget_set_sensitive(glade_xml_get_widget(guixml, "volumebar"), FALSE);  gtk_range_set_value(GTK_RANGE(glade_xml_get_widget(guixml, "progressbar")), 0);  gtk_range_set_value(GTK_RANGE(glade_xml_get_widget(guixml, "volumebar")), 0);  gtk_button_set_label(GTK_BUTTON(glade_xml_get_widget(guixml, "button_time")), "--:--");  gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(guixml, "label_bitrate")), "---");  gtk_widget_hide(glade_xml_get_widget(guixml, "button_server_connect"));  gtk_widget_show(glade_xml_get_widget(guixml, "button_server_disconnect"));  gtk_widget_hide(glade_xml_get_widget(guixml, "button_pause"));  gtk_widget_show(glade_xml_get_widget(guixml, "button_play"));  gtk_widget_hide(glade_xml_get_widget(guixml, "togglebutton_outputs"));  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_repeat")), FALSE);  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_random")), FALSE);  clear_playlist();  gtk_list_store_clear(glurp->gui_playlist);  glurp->playlist_version = -1;  glurp->scroll = 0;  statusbar_print("Disconnected");}gboolean gui_update_cb(gpointer val) {  return gui_update(GPOINTER_TO_INT(val));}gboolean gui_update(gint refresh_rate_status) {  gdouble pos = 0;  GlurpSong *s = NULL;  mpd_Status *status = NULL;  gint tel, e_min, e_sec;  gchar *title;  gboolean changed = FALSE, firstrun = FALSE;  if( DISCONNECTED || DISCONNECTING ) {    debug("Resetting GUI to disconnected state.");    glurp_disconnect();    return FALSE;  }  /* detect first run */  if( !glurp->playlist_version ) firstrun = TRUE;  if( refresh_rate_status != glurp->refresh_rate_status ) {    return FALSE;  }  mpd_sendCommandListOkBegin(glurp->conn);  mpd_sendStatusCommand(glurp->conn);  mpd_sendPlChangesCommand(glurp->conn, glurp->playlist_version);  mpd_sendCommandListEnd(glurp->conn);  if( (status = get_status(FALSE)) ) {    mpd_nextListOkCommand(glurp->conn);    changed = glurp_process_plchanges(status);    mpd_finishCommand(glurp->conn);  } else {    glurp_disconnect();    return FALSE;  }  glurp->play_state = status->state;  /* PERIODIC: unhilight song */  if( !PLAYING && !PAUSED && glurp->prev_song_num != -1 ) {    gui_playlist_hilight(-1);    glurp->scroll = 0;  }/* PERIODIC: update volumebar */  gtk_range_set_value(GTK_RANGE(glade_xml_get_widget(guixml, "volumebar")), status->volume);/* PERIODIC: save number of current song */  glurp->current_song = glurp_get_nth_song(status->song);/* PERIODIC: check to see if we need to update the playlist from MPD */  if( glurp->playlist_version != status->playlist ) {    debug("Playlist version has changed, reloading from server...");    update_playlist();    populate_gui_playlist();    glurp->playlist_version = status->playlist;  }/* PERIODIC: update progressbar if a song is playing or paused */  if(!glurp->progress_dragging) {    if( PLAYING || PAUSED ) {      gtk_widget_set_sensitive(glade_xml_get_widget(guixml, "progressbar"), TRUE);      pos = ((double)status->elapsedTime/(double)status->totalTime)*100;      gtk_range_set_value(GTK_RANGE(glade_xml_get_widget(guixml, "progressbar")), pos);    } else {      gtk_widget_set_sensitive(glade_xml_get_widget(guixml, "progressbar"), FALSE);      gtk_range_set_value(GTK_RANGE(glade_xml_get_widget(guixml, "progressbar")), 0);    }  }/* PERIODIC: update song name */  if( PLAYING || PAUSED ) {    if( !(s = get_nth_song_from_playlist(status->song)) ) {      debug("Could not get song #%d info from playlist", status->song + 1);      statusbar_print("Could not get current song information from server, disconnecting...");      glurp_disconnect();      return FALSE;    }    if( s->artist || s->title ) title = g_strdup_printf("%d. %s - %s", status->song + 1, (s->artist ? s->artist : ""), (s->title ? s->title : ""));    else title = g_strdup_printf("%d. %s", status->song + 1, strip_dirs(s->file));    gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(guixml, "entry_trackname")), title);    g_free(title);  } else {    gtk_entry_set_text(GTK_ENTRY(glade_xml_get_widget(guixml, "entry_trackname")), "Stopped...");  }/* PERIODIC: update time display */  if(glurp->config->time_display_left) tel = status->totalTime - status->elapsedTime;  else tel = status->elapsedTime;  e_min = tel/60;  e_sec = tel%60;  gtk_button_set_label(GTK_BUTTON(glade_xml_get_widget(guixml, "button_time")), (const gchar *)g_strdup_printf("%s%02d:%02d",    (glurp->config->time_display_left ? "-" : ""), e_min, e_sec));/* PERIODIC: update bitrate and mode labels */  if( PLAYING || PAUSED ) {    gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(guixml, "label_bitrate")), g_strdup_printf("%dkbps", status->bitRate));    gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(guixml, "label_mode")), g_strdup_printf("%s", (status->channels > 2 ? "More" : (status->channels == 2 ? "Stereo" : "Mono" ))));  } else {    gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(guixml, "label_bitrate")), g_strdup("---kbps"));    gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(guixml, "label_mode")), g_strdup("---"));  }/* PERIODIC: make display correct button from PLAY and PAUSE duo */  if( PLAYING ) {    gtk_widget_hide(glade_xml_get_widget(guixml, "button_play"));    gtk_widget_show(glade_xml_get_widget(guixml, "button_pause"));  } else {    gtk_widget_hide(glade_xml_get_widget(guixml, "button_pause"));    gtk_widget_show(glade_xml_get_widget(guixml, "button_play"));  }/* PERIODIC: update repeat button */  if( status->repeat ) {    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_repeat")), TRUE);  } else {    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_repeat")), FALSE);  }/* PERIODIC: update random button */  if( status->random ) {    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_random")), TRUE);  } else {    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(glade_xml_get_widget(guixml, "togglebutton_random")), FALSE);  }  if( changed && CONNECTED && (PLAYING || PAUSED) ) {    debug("Moving playlist focus to #%d", status->song);    g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc)gui_playlist_scroll_cb, GINT_TO_POINTER(status->song), NULL);    g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc)gui_playlist_hilight_cb, GINT_TO_POINTER(status->song), NULL);  }/* PERIODIC: update bold row when song changes */  if( PLAYING || PAUSED ) {    if( status->song != glurp->prev_song_num ) {      g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc)gui_playlist_hilight, GINT_TO_POINTER(status->song), NULL);    }  }/* reset scrolling if song is changed */  if( changed ) {    debug("Song changed, stopping titlebar scrolling");    glurp->scroll = 0;  }/* PERIODIC: if appropriate, check that trackname is being scrolled */  if( (PLAYING || PAUSED) && !glurp->scroll && \      g_utf8_strlen(gtk_entry_get_text(GTK_ENTRY(glade_xml_get_widget(guixml, "entry_trackname"))), -1) > TRACKNAME_SCROLL_START ) {    debug("Starting song scroll");    g_timeout_add(200, gui_trackname_scroll, NULL);    glurp->scroll++;  }/* PERIODIC: reenable Add window controls if we just finished updating db (>=0.11.0) */  if( NONBLOCKING_UPDATE_CAPABLE_MPD && !status->updatingDb && glurp->updating_db ) {    statusbar_print("Database updated");    if( addxml ) {      gui_updating_enable_add_controls();      populate_gui_add_tree();    }    glurp->updating_db = FALSE;  }  if( changed ) {    if( CONNECTED && (PLAYING || PAUSED) ) {      if( firstrun ) {        debug("Moving playlist focus");//        g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc)gui_playlist_scroll_cb, GINT_TO_POINTER(status->song), NULL);      }      g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc)gui_playlist_hilight_cb, GINT_TO_POINTER(status->song), NULL);    }  }  mpd_freeStatus(status);  return TRUE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -