?? pda_callbacks.c
字號:
/***************************************************************************** * pda_callbacks.c : Callbacks for the pda Linux Gtk+ plugin. ***************************************************************************** * Copyright (C) 2000, 2001 the VideoLAN team * $Id$ * * Authors: Jean-Paul Saman <jpsaman _at_ videolan _dot_ org> * * 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include <sys/types.h> /* off_t */#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_input.h>#include <vlc_interface.h>#include <vlc_playlist.h>#include <vlc_vout.h>#include <dirent.h>#include <sys/stat.h>#include <unistd.h>#include <pwd.h>#include <grp.h>#include <gtk/gtk.h>#include "pda_callbacks.h"#include "pda_interface.h"#include "pda_support.h"#include "pda.h"#define VLC_MAX_MRL 256static char *get_file_perms(struct stat st);/***************************************************************************** * Useful function to retrieve p_intf ****************************************************************************/void * __GtkGetIntf( GtkWidget * widget ){ void *p_data; if( GTK_IS_MENU_ITEM( widget ) ) { /* Look for a GTK_MENU */ while( widget->parent && !GTK_IS_MENU( widget ) ) { widget = widget->parent; } /* Maybe this one has the data */ p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" ); if( p_data ) { return p_data; } /* Otherwise, the parent widget has it */ widget = gtk_menu_get_attach_widget( GTK_MENU( widget ) ); } /* We look for the top widget */ widget = gtk_widget_get_toplevel( GTK_WIDGET( widget ) ); p_data = gtk_object_get_data( GTK_OBJECT( widget ), "p_intf" ); return p_data;}static void PlaylistAddItem(GtkWidget *widget, gchar *name, char **ppsz_options, int i_size){ intf_thread_t *p_intf = GtkGetIntf( widget ); playlist_t *p_playlist; int i_id , i_pos=0; GtkTreeView *p_tvplaylist = NULL; p_playlist = pl_Yield( p_intf ); if( p_playlist == NULL) { /* Bail out when VLC's playlist object is not found. */ return; } /* Add to playlist object. */ p_tvplaylist = (GtkTreeView *) lookup_widget( GTK_WIDGET(widget), "tvPlaylist"); if (p_tvplaylist) { GtkTreeModel *p_play_model; GtkTreeIter p_play_iter; p_play_model = gtk_tree_view_get_model(p_tvplaylist); if (p_play_model) { int i; /* Add a new row to the playlist treeview model */ gtk_list_store_append (GTK_LIST_STORE(p_play_model), &p_play_iter); gtk_list_store_set (GTK_LIST_STORE(p_play_model), &p_play_iter, 0, name, /* Add path to it !!! */ 1, "no info", 2, playlist_CurrentSize(p_playlist), /* Hidden index. */ -1 ); /* Add to VLC's playlist */#if 0 if (p_intf->p_sys->b_autoplayfile) { playlist_Add( p_playlist, (const char*)name, (const char**)ppsz_options, i_size, PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END); } else#endif { i_id = playlist_AddExt( p_playlist, (const char*)name, (const char*)name, PLAYLIST_APPEND, PLAYLIST_END, (mtime_t) 0, (const char **) ppsz_options, i_pos, true, pl_Unlocked ); } /* Cleanup memory */ for (i=0; i<i_size; i++) free(ppsz_options[i]); free(ppsz_options); } } pl_Release( p_intf );}void PlaylistRebuildListStore( intf_thread_t *p_intf, GtkListStore * p_list, playlist_t * p_playlist ){ GtkTreeIter iter; int i_dummy; gchar * ppsz_text[2];#if 0 GdkColor red; red.red = 65535; red.blue = 0; red.green = 0;#endif vlc_object_lock( p_playlist ); for( i_dummy = 0; i_dummy < playlist_CurrentSize(p_playlist) ; i_dummy++ ) { playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_dummy, pl_Locked ); if( p_item ) { ppsz_text[0] = p_item->p_input->psz_name; ppsz_text[1] = "no info"; gtk_list_store_append (p_list, &iter); gtk_list_store_set (p_list, &iter, 0, ppsz_text[0], 1, ppsz_text[1], 2, i_dummy, /* Hidden index */ -1); } } vlc_object_unlock( p_playlist );}/***************************************************************** * Read directory helper function. ****************************************************************/void ReadDirectory(intf_thread_t *p_intf, GtkListStore *p_list, char *psz_dir ){ GtkTreeIter iter; struct dirent **pp_namelist; struct passwd *p_pw; struct group *p_grp; struct stat st; int n=-1, status=-1; msg_Dbg(p_intf, "Changing to dir %s", psz_dir); if (psz_dir) { status = chdir(psz_dir); if (status<0) msg_Dbg(p_intf, "permision denied" ); } n = scandir(".", &pp_namelist, 0, alphasort); if (n<0) perror("scandir"); else { int i; gchar *ppsz_text[4]; if (lstat("..", &st)==0) { /* user, group */ p_pw = getpwuid(st.st_uid); p_grp = getgrgid(st.st_gid); /* XXX : kludge temporaire pour yopy */ ppsz_text[0] = ".."; ppsz_text[1] = get_file_perms(st); ppsz_text[2] = p_pw->pw_name; ppsz_text[3] = p_grp->gr_name; /* Add a new row to the model */ gtk_list_store_append (p_list, &iter); gtk_list_store_set (p_list, &iter, 0, ppsz_text[0], 1, ppsz_text[1], 2, st.st_size, 3, ppsz_text[2], 4, ppsz_text[3], -1); free(ppsz_text[1]); } /* kludge */ for (i=0; i<n; i++) { if ((pp_namelist[i]->d_name[0] != '.') && (lstat(pp_namelist[i]->d_name, &st)==0)) { /* user, group */ p_pw = getpwuid(st.st_uid); p_grp = getgrgid(st.st_gid); /* This is a list of strings. */ ppsz_text[0] = pp_namelist[i]->d_name; ppsz_text[1] = get_file_perms(st); ppsz_text[2] = p_pw->pw_name; ppsz_text[3] = p_grp->gr_name;#if 0 msg_Dbg(p_intf, "(%d) file: %s permission: %s user: %s group: %s", i, ppsz_text[0], ppsz_text[1], ppsz_text[2], ppsz_text[3] );#endif gtk_list_store_append (p_list, &iter); gtk_list_store_set (p_list, &iter, 0, ppsz_text[0], 1, ppsz_text[1], 2, st.st_size, 3, ppsz_text[2], 4, ppsz_text[3], -1); free(ppsz_text[1]); } } free(pp_namelist); }}static char *get_file_perms(const struct stat st){ char *psz_perm; psz_perm = (char *) malloc(sizeof(char)*10); strncpy( psz_perm, "----------", sizeof("----------")); /* determine permission modes */ if (S_ISLNK(st.st_mode)) psz_perm[0]= 'l'; else if (S_ISDIR(st.st_mode)) psz_perm[0]= 'd'; else if (S_ISCHR(st.st_mode)) psz_perm[0]= 'c'; else if (S_ISBLK(st.st_mode)) psz_perm[0]= 'b'; else if (S_ISFIFO(st.st_mode)) psz_perm[0]= 'f'; else if (S_ISSOCK(st.st_mode)) psz_perm[0]= 's'; else if (S_ISREG(st.st_mode)) psz_perm[0]= '-'; else /* Unknown type is an error */ psz_perm[0]= '?'; /* Get file permissions */ /* User */ if (st.st_mode & S_IRUSR) psz_perm[1]= 'r'; if (st.st_mode & S_IWUSR) psz_perm[2]= 'w'; if (st.st_mode & S_IXUSR) { if (st.st_mode & S_ISUID) psz_perm[3] = 's'; else psz_perm[3]= 'x'; } else if (st.st_mode & S_ISUID) psz_perm[3] = 'S'; /* Group */ if (st.st_mode & S_IRGRP) psz_perm[4]= 'r'; if (st.st_mode & S_IWGRP) psz_perm[5]= 'w'; if (st.st_mode & S_IXGRP) { if (st.st_mode & S_ISGID) psz_perm[6] = 's'; else psz_perm[6]= 'x'; } else if (st.st_mode & S_ISGID) psz_perm[6] = 'S'; /* Other */ if (st.st_mode & S_IROTH) psz_perm[7]= 'r'; if (st.st_mode & S_IWOTH) psz_perm[8]= 'w'; if (st.st_mode & S_IXOTH) { /* 'sticky' bit */ if (st.st_mode &S_ISVTX) psz_perm[9] = 't'; else psz_perm[9]= 'x'; } else if (st.st_mode &S_ISVTX) psz_perm[9]= 'T'; return psz_perm;}/* * Main interface callbacks */gboolean onPDADeleteEvent(GtkWidget *widget, GdkEvent *event, gpointer user_data){ intf_thread_t *p_intf = GtkGetIntf( widget ); vlc_mutex_lock( &p_intf->change_lock ); vlc_object_kill( p_intf->p_libvlc ); vlc_mutex_unlock( &p_intf->change_lock ); msg_Dbg( p_intf, "about to exit vlc ... signaled" ); return TRUE;}void onRewind(GtkButton *button, gpointer user_data){ intf_thread_t *p_intf = GtkGetIntf( button ); if (p_intf->p_sys->p_input != NULL) { var_SetVoid( p_intf->p_sys->p_input, "rate-slower" ); }}void onPause(GtkButton *button, gpointer user_data){ intf_thread_t *p_intf = GtkGetIntf( button ); if (p_intf->p_sys->p_input != NULL) { var_SetInteger( p_intf->p_sys->p_input, "state", PAUSE_S ); }}void onPlay(GtkButton *button, gpointer user_data){ intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) ); playlist_t *p_playlist = pl_Yield( p_intf ); if (p_playlist) { vlc_object_lock( p_playlist ); if (playlist_CurrentSize(p_playlist)) { vlc_object_unlock( p_playlist ); playlist_Play( p_playlist ); gdk_window_lower( p_intf->p_sys->p_window->window ); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -