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

📄 pda_callbacks.c

📁 VLC媒体播放程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * pda_callbacks.c : Callbacks for the pda Linux Gtk+ plugin. ***************************************************************************** * Copyright (C) 2000, 2001 VideoLAN * $Id: pda_callbacks.c,v 1.29 2004/02/29 22:59:59 jpsaman Exp $ * * Authors: Jean-Paul Saman <jpsaman@wxs.nl> * * 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 <sys/types.h>                                              /* off_t */#include <stdlib.h>#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc/vout.h>#include <stdio.h>#include <string.h>#include <dirent.h>#include <sys/stat.h>#include <unistd.h>#include <pwd.h>#include <grp.h>#ifdef HAVE_CONFIG_H#  include <config.h>#endif#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 * E_(__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;}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 = (playlist_t *)             vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );    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, p_playlist->i_size, /* 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 );            }            /* Cleanup memory */            for (i=0; i<i_size; i++)                free(ppsz_options[i]);            free(ppsz_options);        }    }    vlc_object_release( p_playlist );}void PlaylistRebuildListStore( 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_mutex_lock( &p_playlist->object_lock );    for( i_dummy = 0; i_dummy < p_playlist->i_size ; i_dummy++ )    {        ppsz_text[0] = p_playlist->pp_items[i_dummy]->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_mutex_unlock( &p_playlist->object_lock );}/***************************************************************** * 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);            if (ppsz_text[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);                if (ppsz_text[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 );    p_intf->p_vlc->b_die = VLC_TRUE;    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)    {        input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_SLOWER );    }}void onPause(GtkButton *button, gpointer user_data){    intf_thread_t *p_intf = GtkGetIntf( button );    if (p_intf->p_sys->p_input != NULL)    {        input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PAUSE );    }}void onPlay(GtkButton *button, gpointer user_data){    intf_thread_t *p_intf = GtkGetIntf( GTK_WIDGET( button ) );    playlist_t *p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );    if (p_playlist)    {        vlc_mutex_lock( &p_playlist->object_lock );        if (p_playlist->i_size)        {            vlc_mutex_unlock( &p_playlist->object_lock );            playlist_Play( p_playlist );            gdk_window_lower( p_intf->p_sys->p_window->window );        }        else        {            vlc_mutex_unlock( &p_playlist->object_lock );        }

⌨️ 快捷键说明

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