]> git.sesse.net Git - vlc/blob - modules/gui/qt4/dialogs/podcast_configuration.cpp
Qt4: podcast configuration, don't use a modal window, don't use a Qdailog but a QVLCF...
[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 PodcastConfigDialog *PodcastConfigDialog::instance = NULL;
27
28 PodcastConfigDialog::PodcastConfigDialog( intf_thread_t *_p_intf)
29                 : QVLCFrame( _p_intf )
30
31 {
32     ui.setupUi( this );
33
34     QPushButton *okButton = new QPushButton( qtr( "OK" ), this );
35     QPushButton *cancelButton = new QPushButton( qtr( "Cancel" ), this );
36     ui.okCancel->addButton( okButton, QDialogButtonBox::AcceptRole );
37     ui.okCancel->addButton( cancelButton, QDialogButtonBox::RejectRole );
38     CONNECT( ui.podcastAdd, clicked(), this, add() );
39     CONNECT( ui.podcastDelete, clicked(), this, remove() );
40
41     char *psz_urls = config_GetPsz( p_intf, "podcast-urls" );
42     if( psz_urls )
43     {
44         char *psz_url = psz_urls;
45         while( 1 )
46         {
47             char *psz_tok = strchr( psz_url, '|' );
48             if( psz_tok ) *psz_tok = '\0';
49             ui.podcastList->addItem( psz_url );
50             if( psz_tok ) psz_url = psz_tok+1;
51             else break;
52         }
53         free( psz_urls );
54     }
55 }
56
57 PodcastConfigDialog::~PodcastConfigDialog()
58 {
59 }
60
61 void PodcastConfigDialog::accept()
62 {
63     QString urls = "";
64     for( int i = 0; i < ui.podcastList->count(); i++ )
65     {
66         urls +=  ui.podcastList->item(i)->text();
67         if( i != ui.podcastList->count()-1 ) urls += "|";
68     }
69     const char *psz_urls = qtu( urls );
70     config_PutPsz( p_intf, "podcast-urls", psz_urls );
71     vlc_object_t *p_obj = (vlc_object_t*)
72                           vlc_object_find_name( p_intf->p_libvlc,
73                                                 "podcast", FIND_CHILD );
74     if( p_obj )
75     {
76         var_SetString( p_obj, "podcast-urls", psz_urls );
77         vlc_object_release( p_obj );
78     }
79
80     if( playlist_IsServicesDiscoveryLoaded( THEPL, "podcast" ) )
81     {
82         msg_Dbg( p_intf, "You will need to reload the podcast module to take into account deleted podcast urls" );
83     }
84 }
85
86 void PodcastConfigDialog::add()
87 {
88     if( ui.podcastURL->text() != QString( "" ) )
89     {
90         ui.podcastList->addItem( ui.podcastURL->text() );
91         ui.podcastURL->clear();
92     }
93 }
94
95 void PodcastConfigDialog::remove()
96 {
97     delete ui.podcastList->currentItem();
98 }