📄 playlist.c
字号:
/***************************************************************************** * gtk_playlist.c : Interface for the playlist dialog ***************************************************************************** * Copyright (C) 2001 VideoLAN * $Id: playlist.c 10101 2005-03-02 16:47:31Z robux4 $ * * Authors: Pierre Baillet <oct@zoy.org> * St閜hane Borel <stef@via.ecp.fr> * * 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, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <stdlib.h>#include <string.h>#include <vlc/vlc.h>#include <vlc/intf.h>#include <sys/types.h> /* for readdir and stat stuff */#if (!defined( WIN32 ) || defined(__MINGW32__))/* Mingw has its own version of dirent */# include <dirent.h>#endif#include <sys/stat.h>#include <unistd.h>#ifdef MODULE_NAME_IS_gnome# include <gnome.h>#else# include <gtk/gtk.h>#endif#include "gtk_callbacks.h"#include "gtk_interface.h"#include "gtk_support.h"#include "playlist.h"#include "common.h"/**************************************************************************** * Local prototypes ****************************************************************************/static void UrlDecode ( char * );static GList * GtkReadFiles ( intf_thread_t *, gchar * );/**************************************************************************** * Playlist window management ****************************************************************************/gboolean GtkPlaylistShow( GtkWidget *widget, gpointer user_data ){ intf_thread_t * p_intf = GtkGetIntf( widget ); playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return FALSE; } if( GTK_WIDGET_VISIBLE( p_intf->p_sys->p_playwin ) ) { gtk_widget_hide( p_intf->p_sys->p_playwin ); } else { GtkCList * p_clist; p_clist = GTK_CLIST( gtk_object_get_data( GTK_OBJECT( p_intf->p_sys->p_playwin ), "playlist_clist" ) ); GtkRebuildCList( p_clist , p_playlist ); gtk_widget_show( p_intf->p_sys->p_playwin ); gdk_window_raise( p_intf->p_sys->p_playwin->window ); } vlc_object_release( p_playlist ); return TRUE;}void GtkPlaylistOk( GtkButton * button, gpointer user_data ){ gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );}void GtkPlaylistCancel( GtkButton * button, gpointer user_data ){ gtk_widget_hide( gtk_widget_get_toplevel( GTK_WIDGET (button) ) );}gboolean GtkPlaylistPrev( GtkWidget *widget, gpointer user_data ){ intf_thread_t * p_intf = GtkGetIntf( widget ); playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return FALSE; } playlist_Prev( p_playlist ); vlc_object_release( p_playlist ); return TRUE;}gboolean GtkPlaylistNext( GtkWidget *widget, gpointer user_data){ intf_thread_t * p_intf = GtkGetIntf( widget ); playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return FALSE; } playlist_Next( p_playlist ); vlc_object_release( p_playlist ); return TRUE;}/**************************************************************************** * Playlist core functions ****************************************************************************/void GtkPlaylistAddUrl( GtkMenuItem * menuitem, gpointer user_data ){}void GtkPlaylistDeleteAll( GtkMenuItem * menuitem, gpointer user_data ){}void GtkPlaylistDeleteSelected( GtkMenuItem * menuitem, gpointer user_data ){ /* user wants to delete a file in the queue */ GList * p_selection; GtkCList * p_clist; intf_thread_t * p_intf = GtkGetIntf( menuitem); playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return; } /* lock the struct */ vlc_mutex_lock( &p_intf->change_lock ); p_clist = GTK_CLIST( gtk_object_get_data( GTK_OBJECT( p_intf->p_sys->p_playwin ), "playlist_clist" ) ); p_selection = p_clist->selection; if( g_list_length( p_selection ) ) { /* reverse-sort so that we can delete from the furthest * to the closest item to delete... */ p_selection = g_list_sort( p_selection, GtkCompareItems ); g_list_foreach( p_selection, GtkDeleteGListItem, p_playlist ); /* rebuild the CList */ GtkRebuildCList( p_clist, p_playlist ); } vlc_mutex_unlock( &p_intf->change_lock ); vlc_object_release( p_playlist );}void GtkPlaylistCrop( GtkMenuItem * menuitem, gpointer user_data ){ /* Ok, this is a really small thing, but, hey, it works and might be useful, who knows ? */ GtkPlaylistInvert( menuitem, user_data ); GtkPlaylistDeleteSelected( menuitem, user_data );}void GtkPlaylistInvert( GtkMenuItem * menuitem, gpointer user_data ){ GtkCList * p_clist; int * pi_selected; int i_length; int i_dummy; /* catch the thread back */ intf_thread_t *p_intf = GtkGetIntf( menuitem ); /* lock the struct */ vlc_mutex_lock( &p_intf->change_lock ); p_clist = GTK_CLIST( gtk_object_get_data( GTK_OBJECT( p_intf->p_sys->p_playwin ), "playlist_clist" ) ); gtk_clist_freeze( p_clist ); /* have to copy the selection to an int * I wasn't able to copy the g_list to another g_list glib only does pointer copies, not real copies :( */ i_length = g_list_length( p_clist->selection ); pi_selected = malloc( sizeof(int) * i_length ); for( i_dummy = 0 ; i_dummy < i_length ; i_dummy++ ) { pi_selected[i_dummy] = GPOINTER_TO_UINT( g_list_nth_data( p_clist->selection, i_dummy ) ); } gtk_clist_select_all( p_clist ); for( i_dummy = 0; i_dummy < i_length; i_dummy++ ) { gtk_clist_unselect_row( p_clist, pi_selected[i_dummy], 0 ); } gtk_clist_thaw( p_clist ); vlc_mutex_unlock( &p_intf->change_lock ); free( pi_selected );}void GtkPlaylistSelect( GtkMenuItem * menuitem, gpointer user_data){}gboolean GtkPlaylistEvent( GtkWidget * widget, GdkEvent * event, gpointer user_data){ intf_thread_t * p_intf = GtkGetIntf( widget ); playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return FALSE; } if( ( event->button ).type == GDK_2BUTTON_PRESS ) { GtkCList * p_clist; gint i_row; gint i_col; p_clist = GTK_CLIST( gtk_object_get_data( GTK_OBJECT( p_intf->p_sys->p_playwin ), "playlist_clist" ) ); if( gtk_clist_get_selection_info( p_clist, (event->button).x, (event->button).y, &i_row, &i_col ) == 1 ) { playlist_Goto( p_playlist, i_row ); } vlc_object_release( p_playlist ); return TRUE; } vlc_object_release( p_playlist ); return FALSE;}void GtkPlaylistDragData( GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data ){ intf_thread_t * p_intf = GtkGetIntf( widget ); GtkCList * p_clist; gint i_row; gint i_col; p_clist = GTK_CLIST( gtk_object_get_data( GTK_OBJECT( p_intf->p_sys->p_playwin ), "playlist_clist" ) ); if( gtk_clist_get_selection_info( p_clist, x, y, &i_row, &i_col ) == 1 ) { /* we are dropping somewhere into the clist items */ GtkDropDataReceived( p_intf, data, info, i_row - 1 ); } else { /* otherwise, put that at the end of the playlist */ GtkDropDataReceived( p_intf, data, info, PLAYLIST_END ); }}gboolean GtkPlaylistDragMotion( GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, guint time, gpointer user_data ){ GtkCList * p_clist; gint i_row; gint i_col; int i_dummy; GdkColor color; intf_thread_t * p_intf = GtkGetIntf( widget ); playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE ); if( p_playlist == NULL ) { return FALSE; } p_clist = GTK_CLIST( gtk_object_get_data( GTK_OBJECT( p_intf->p_sys->p_playwin ), "playlist_clist" ) ); if( !GTK_WIDGET_TOPLEVEL(widget) ) { gdk_window_raise( p_intf->p_sys->p_playwin->window ); } color.red = 0xffff; color.blue = 0xffff; color.green = 0xffff; gtk_clist_freeze( p_clist ); for( i_dummy = 0; i_dummy < p_clist->rows; i_dummy++) { gtk_clist_set_background( p_clist, i_dummy , &color ); } color.red = 0; color.blue = 0xf000; color.green = 0x9000; if( gtk_clist_get_selection_info( p_clist, x, y, &i_row, &i_col ) == 1 ) { gtk_clist_set_background ( p_clist, i_row - 1, &color ); gtk_clist_set_background ( p_clist, i_row, &color ); } else { gtk_clist_set_background ( p_clist, p_clist->rows - 1, &color ); } color.red = 0xffff; color.blue = 0; color.green = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -