iteminfo.cpp
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:12k
源码类别:

多媒体

开发平台:

MultiPlatform

  1. /*****************************************************************************
  2.  * iteminfo.cpp : wxWindows plugin for vlc
  3.  *****************************************************************************
  4.  * Copyright (C) 2000-2004 VideoLAN
  5.  * $Id: iteminfo.cpp 8664 2004-09-08 10:07:05Z gbazin $
  6.  *
  7.  * Authors: Cl閙ent Stenac <zorglub@videolan.org>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  22.  *****************************************************************************/
  23. /*****************************************************************************
  24.  * Preamble
  25.  *****************************************************************************/
  26. #include <stdlib.h>                                      /* malloc(), free() */
  27. #include <errno.h>                                                 /* ENOMEM */
  28. #include <string.h>                                            /* strerror() */
  29. #include <stdio.h>
  30. #include <vlc/vlc.h>
  31. #include <wx/combobox.h>
  32. #include <wx/statline.h>
  33. #include <vlc/intf.h>
  34. #include "wxwindows.h"
  35. #ifndef wxRB_SINGLE
  36. #   define wxRB_SINGLE 0
  37. #endif
  38. /*****************************************************************************
  39.  * Event Table.
  40.  *****************************************************************************/
  41. /* IDs for the controls and the menu commands */
  42. enum
  43. {
  44.     Uri_Event,
  45.     Name_Event,
  46.     Author_Event,
  47.     Enabled_Event,
  48.     New_Event,
  49. };
  50. BEGIN_EVENT_TABLE(ItemInfoDialog, wxDialog)
  51.     /* Button events */
  52.     EVT_BUTTON(wxID_OK, ItemInfoDialog::OnOk)
  53.     EVT_BUTTON(wxID_CANCEL, ItemInfoDialog::OnCancel)
  54.     /* Events generated by the panels */
  55.     EVT_BUTTON( New_Event, ItemInfoDialog::OnNewGroup)
  56. END_EVENT_TABLE()
  57. /*****************************************************************************
  58.  * Constructor.
  59.  *****************************************************************************/
  60. ItemInfoDialog::ItemInfoDialog( intf_thread_t *_p_intf,
  61.                                 playlist_item_t *_p_item,
  62.                                 wxWindow* _p_parent ):
  63.     wxDialog( _p_parent, -1, wxU(_("Playlist item info")),
  64.              wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE )
  65. {
  66.     /* Initializations */
  67.     p_intf = _p_intf;
  68.     p_parent = _p_parent;
  69.     p_item = _p_item;
  70.     SetIcon( *p_intf->p_sys->p_icon );
  71.     /* Create a panel to put everything in */
  72.     wxPanel *panel = new wxPanel( this, -1 );
  73.     panel->SetAutoLayout( TRUE );
  74.     /* Create the standard info panel */
  75.     wxPanel *info_panel = InfoPanel( panel );
  76.     /* Create the group panel */
  77.     wxPanel *group_panel = GroupPanel( panel );
  78.     /* Separation */
  79.     wxStaticLine *static_line = new wxStaticLine( panel, wxID_OK );
  80.     /* Create the buttons */
  81.     wxButton *ok_button = new wxButton( panel, wxID_OK, wxU(_("OK")) );
  82.     ok_button->SetDefault();
  83.     wxButton *cancel_button = new wxButton( panel, wxID_CANCEL,
  84.                                             wxU(_("Cancel")) );
  85.     /* Place everything in sizers */
  86.     wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
  87.     button_sizer->Add( ok_button, 0, wxALL, 5 );
  88.     button_sizer->Add( cancel_button, 0, wxALL, 5 );
  89.     button_sizer->Layout();
  90.     wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
  91.     wxBoxSizer *panel_sizer = new wxBoxSizer( wxVERTICAL );
  92.     panel_sizer->Add( info_panel, 0, wxEXPAND | wxALL, 5 );
  93.     panel_sizer->Add( group_panel, 0, wxEXPAND | wxALL, 5 );
  94.     panel_sizer->Add( static_line, 0, wxEXPAND | wxALL, 5 );
  95.     panel_sizer->Add( button_sizer, 0, wxALIGN_LEFT | wxALIGN_BOTTOM |
  96.                       wxALL, 5 );
  97.     panel_sizer->Layout();
  98.     panel->SetSizerAndFit( panel_sizer );
  99.     main_sizer->Add( panel, 1, wxGROW, 0 );
  100.     main_sizer->Layout();
  101.     SetSizerAndFit( main_sizer );
  102. }
  103. ItemInfoDialog::~ItemInfoDialog()
  104. {
  105. }
  106. /*****************************************************************************
  107.  * Private methods.
  108.  *****************************************************************************/
  109. wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
  110. {
  111.     wxPanel *info_panel = new wxPanel( parent, -1, wxDefaultPosition,
  112.                                   wxDefaultSize );
  113.     info_panel->SetAutoLayout( TRUE );
  114.     wxBoxSizer *info_sizer = new wxBoxSizer( wxHORIZONTAL );
  115.     /* Create a box to surround the controls */
  116.     wxStaticBox *panel_box = new wxStaticBox( info_panel, -1,
  117.                                    wxU(_("Item Info")) );
  118.     wxStaticBoxSizer *box_sizer = new wxStaticBoxSizer( panel_box,
  119.                                                           wxVERTICAL );
  120.     wxFlexGridSizer *sizer = new wxFlexGridSizer(2,3,20);
  121.     /* URI Textbox */
  122.     wxStaticText *uri_label =
  123.            new wxStaticText( info_panel, -1, wxU(_("URI")) );
  124.     uri_text = new wxTextCtrl( info_panel, Uri_Event,
  125.         wxU(p_item->input.psz_uri), wxDefaultPosition, wxSize( 300, -1 ),
  126.         wxTE_PROCESS_ENTER );
  127.     sizer->Add( uri_label, 0 , wxALIGN_LEFT |wxALL , 5 );
  128.     sizer->Add( uri_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
  129.     /* Name Textbox */
  130.     wxStaticText *name_label =
  131.            new wxStaticText(  info_panel, -1, wxU(_("Name")) );
  132.     name_text = new wxTextCtrl( info_panel, Uri_Event,
  133.         wxU(p_item->input.psz_name), wxDefaultPosition, wxSize( 300, -1 ),
  134.         wxTE_PROCESS_ENTER );
  135.     sizer->Add( name_label, 0 , wxALIGN_LEFT |wxALL , 5  );
  136.     sizer->Add( name_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
  137.     /* Author Textbox */
  138.     wxStaticText *author_label =
  139.            new wxStaticText( info_panel, -1, wxU(_("Author")) );
  140.     author_text = new wxTextCtrl( info_panel, Uri_Event,
  141.                                    wxU( playlist_ItemGetInfo( p_item,
  142.                                           _("General"), _("Author") ) ),
  143.                                    wxDefaultPosition, wxSize( 300, -1 ),
  144.                                    wxTE_PROCESS_ENTER);
  145.     sizer->Add( author_label, 0 , wxALIGN_LEFT | wxALL , 5 );
  146.     sizer->Add( author_text, 1 , wxALIGN_RIGHT | wxALL , 5);
  147.     /* Treeview */
  148.     info_tree = new wxTreeCtrl( info_panel, -1, wxDefaultPosition,
  149.                                 wxSize(220,200),
  150.                                 wxSUNKEN_BORDER |wxTR_HAS_BUTTONS |
  151.                                 wxTR_HIDE_ROOT );
  152.     sizer->Layout();
  153.     box_sizer->Add( sizer, 0, wxEXPAND, 5 );
  154.     box_sizer->Add( info_tree, 0, wxEXPAND, 5 );
  155.     info_sizer->Add( box_sizer, 1, wxBOTTOM, 5 );
  156.     info_panel->SetSizer( info_sizer );
  157.     info_sizer->Layout();
  158.     info_sizer->SetSizeHints( info_panel );
  159.     UpdateInfo();
  160.     return info_panel;
  161. }
  162. wxPanel *ItemInfoDialog::GroupPanel( wxWindow* parent )
  163. {
  164.     wxPanel *panel = new wxPanel( parent, -1, wxDefaultPosition,
  165.                                   wxDefaultSize );
  166.     wxStaticBox *panel_box = new wxStaticBox( panel, -1,
  167.                                    wxU(_("Group Info")) );
  168.     wxStaticBoxSizer *panel_sizer = new wxStaticBoxSizer( panel_box,
  169.                                                          wxVERTICAL);
  170.     wxBoxSizer *subpanel_sizer;
  171.     group_subpanel = new wxPanel( panel, -1 );
  172.     subpanel_sizer = new wxBoxSizer( wxVERTICAL) ;
  173.     enabled_checkbox = new wxCheckBox( group_subpanel,
  174.                                      -1, wxU(_("Item Enabled")) );
  175.     enabled_checkbox->SetValue( p_item->b_enabled);
  176.     wxStaticText *group_label = new wxStaticText( group_subpanel,
  177.                                         -1, wxU(_("Group")) );
  178.     playlist_t *p_playlist =
  179.                 (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
  180.                                        FIND_ANYWHERE );
  181.     if( p_playlist == NULL )
  182.     {
  183.         return NULL;
  184.     }
  185.     group_combo = new wxComboBox( group_subpanel, -1,
  186.                                  wxT(""),wxDefaultPosition, wxDefaultSize,
  187.                                  0, NULL, wxCB_READONLY );
  188.     wxButton *newgroup_button = new wxButton( group_subpanel, New_Event,
  189.                                     wxU(_("New Group")));
  190.     for( int i=0; i< p_playlist->i_groups ; i++)
  191.     {
  192.         group_combo->Append( wxU( p_playlist->pp_groups[i]->psz_name ) );
  193.         if( p_playlist->pp_groups[i]->i_id == p_item->i_group )
  194.         {
  195.             group_combo->SetSelection( i );
  196.             group_combo->SetValue( wxU( p_playlist->pp_groups[i]->psz_name ) );
  197.         }
  198.     }
  199.     vlc_object_release ( p_playlist );
  200.     subpanel_sizer->Add( enabled_checkbox, 0, wxALIGN_RIGHT|
  201.                          wxALIGN_CENTER_VERTICAL );
  202.     subpanel_sizer->Add( group_label, 0, wxALIGN_LEFT |
  203.                          wxALIGN_CENTER_VERTICAL );
  204.     wxBoxSizer *group_sizer = new wxBoxSizer( wxHORIZONTAL);
  205.     group_sizer->Add(group_combo, 0, wxALIGN_LEFT|wxRIGHT, 5);
  206.     group_sizer->Add( newgroup_button, 0, wxALIGN_RIGHT|wxLEFT, 5);
  207.     group_sizer->Layout();
  208.     subpanel_sizer->Add( group_sizer, 0, wxALIGN_RIGHT );
  209.     group_subpanel->SetSizerAndFit( subpanel_sizer );
  210.     /* Stuff everything into the main panel */
  211.     panel_sizer->Add( group_subpanel, 0,
  212.                       wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxALL, 5 );
  213.     panel->SetSizerAndFit( panel_sizer );
  214.     /* Update panel */
  215.     return panel;
  216. }
  217. void ItemInfoDialog::UpdateInfo()
  218. {
  219.     if( !info_root )
  220.     {
  221.        info_root = info_tree->AddRoot( wxU( p_item->input.psz_name) );
  222.     }
  223.     /* Rebuild the tree */
  224.     for( int i = 0; i< p_item->input.i_categories ; i++)
  225.     {
  226.         wxTreeItemId cat = info_tree->AppendItem( info_root,
  227.                             wxU( p_item->input.pp_categories[i]->psz_name) );
  228.         for( int j = 0 ; j < p_item->input.pp_categories[i]->i_infos ; j++ )
  229.         {
  230.            info_tree->AppendItem( cat , (wxString)
  231.                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_name) +
  232.                wxT(": ") +
  233.                wxU(p_item->input.pp_categories[i]->pp_infos[j]->psz_value) );
  234.         }
  235.         info_tree->Expand( cat );
  236.     }
  237. }
  238. /*****************************************************************************
  239.  * Events methods.
  240.  *****************************************************************************/
  241. void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
  242. {
  243.     vlc_mutex_lock( &p_item->input.lock );
  244.     p_item->input.psz_name = strdup( name_text->GetLineText(0).mb_str() );
  245.     p_item->input.psz_uri = strdup( uri_text->GetLineText(0).mb_str() );
  246.     playlist_ItemAddInfo( p_item,"General","Author",
  247.                             author_text->GetLineText(0).mb_str() );
  248.     vlc_bool_t b_old_enabled = p_item->b_enabled;
  249.     playlist_t * p_playlist =
  250.           (playlist_t *)vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,
  251.                                        FIND_ANYWHERE );
  252.     if( p_playlist != NULL )
  253.     {
  254.         if( b_old_enabled == VLC_FALSE && enabled_checkbox->IsChecked() )
  255.             p_playlist->i_enabled ++;
  256.         else if( b_old_enabled == VLC_TRUE && !enabled_checkbox->IsChecked() )
  257.             p_playlist->i_enabled --;
  258.         for (int i=0 ; i< p_playlist->i_groups ; i++)
  259.         {
  260.            if( !strcasecmp( p_playlist->pp_groups[i]->psz_name,
  261.                             group_combo->GetValue().mb_str() ))
  262.            {
  263.                p_item->i_group = p_playlist->pp_groups[i]->i_id;
  264.                break;
  265.            }
  266.         }
  267.         vlc_object_release( p_playlist );
  268.     }
  269.     p_item->b_enabled = enabled_checkbox->IsChecked() ? VLC_TRUE : VLC_FALSE ;
  270.     vlc_mutex_unlock( &p_item->input.lock );
  271.     EndModal( wxID_OK );
  272. }
  273. void ItemInfoDialog::OnCancel( wxCommandEvent& WXUNUSED(event) )
  274. {
  275.     EndModal( wxID_CANCEL );
  276. }
  277. void ItemInfoDialog::OnNewGroup( wxCommandEvent& WXUNUSED(event) )
  278. {
  279.     NewGroup *p_newgroup = NULL;
  280.     p_newgroup = new NewGroup( p_intf, this );
  281.     if( p_newgroup)
  282.     {
  283.         if( p_newgroup->ShowModal() == wxID_OK && p_newgroup->psz_name)
  284.         {
  285.             group_combo->Append( wxU( p_newgroup->psz_name ) );
  286.         }
  287.         delete( p_newgroup );
  288.     }
  289. }