]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/podcast_configuration.cpp
Qt4 - Podcast dialog: Don't use the default OK/Cancel buttons, because they wouldn...
[vlc] / modules / gui / qt4 / dialogs / podcast_configuration.cpp
1 /*****************************************************************************
2  * podcast_configuration.cpp: Podcast configuration dialog
3  ****************************************************************************
4  * Copyright (C) 2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea at videolan dot 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include "podcast_configuration.hpp"
25
26 PodcastConfigurationDialog::PodcastConfigurationDialog( intf_thread_t *_p_intf )
27     :p_intf( _p_intf )
28 {
29     ui.setupUi( this );
30     QPushButton *okButton = new QPushButton( qtr( "OK" ), this );
31     QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ), this );
32     ui.okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
33     ui.okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
34     CONNECT( ui.podcastAdd, clicked(), this, add() );
35     CONNECT( ui.podcastDelete, clicked(), this, remove() );
36
37     char *psz_urls = config_GetPsz( p_intf, "podcast-urls" );
38     if( psz_urls )
39     {
40         char *psz_url = psz_urls;
41         while( 1 )
42         {
43             char *psz_tok = strchr( psz_url, '|' );
44             if( psz_tok ) *psz_tok = '\0';
45             ui.podcastList->addItem( psz_url );
46             if( psz_tok ) psz_url = psz_tok+1;
47             else break;
48         }
49         free( psz_urls );
50     }
51 }
52
53 void PodcastConfigurationDialog::accept()
54 {
55     QString urls = "";
56     for( int i = 0; i < ui.podcastList->count(); i++ )
57     {
58         urls +=  ui.podcastList->item(i)->text();
59         if( i != ui.podcastList->count()-1 ) urls += "|";
60     }
61     const char *psz_urls = qtu( urls );
62     config_PutPsz( p_intf, "podcast-urls", psz_urls );
63     vlc_object_t *p_obj = (vlc_object_t*)
64                           vlc_object_find_name( p_intf->p_libvlc,
65                                                 "podcast", FIND_CHILD );
66     if( p_obj )
67     {
68         var_SetString( p_obj, "podcast-urls", psz_urls );
69         vlc_object_release( p_obj );
70     }
71
72     if( playlist_IsServicesDiscoveryLoaded( THEPL, "podcast" ) )
73     {
74         msg_Dbg( p_intf, "You will need to reload the podcast module to take into account deleted podcast urls" );
75     }
76
77     QDialog::accept();
78 }
79
80 void PodcastConfigurationDialog::add()
81 {
82     if( ui.podcastURL->text() != QString( "" ) )
83     {
84         ui.podcastList->addItem( ui.podcastURL->text() );
85         ui.podcastURL->clear();
86     }
87 }
88
89 void PodcastConfigurationDialog::remove()
90 {
91     delete ui.podcastList->currentItem();
92 }