summaryrefslogtreecommitdiffstats
path: root/src/app/playDialog.cpp
blob: 50a9ca26725d24fd6b102717f118d3d7331e17f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// (C) 2005 Max Howell (max.howell@methylblue.com)
// See COPYING file for licensing information

#include "config.h"
#include "listView.cpp"
#include <kapplication.h>
#include <kconfig.h>
#include <kguiitem.h>
#include <klistview.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>
#include "playDialog.h"
#include "mxcl.library.h"
#include <qfile.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qsignalmapper.h>

QString i18n( const char *text );


namespace Codeine {


PlayDialog::PlayDialog( QWidget *parent, bool be_welcome_dialog )
      : QDialog( parent )
{
   setCaption( kapp->makeStdCaption( i18n("Play Media") ) );

   QSignalMapper *mapper = new QSignalMapper( this );
   QWidget *o, *closeButton = new KPushButton( KStdGuiItem::close(), this );
   QBoxLayout *hbox, *vbox = new QVBoxLayout( this, 15, 20 );

   vbox->addWidget( new QLabel( i18n( "What media would you like to play?" ), this ) );

   QGridLayout *grid = new QGridLayout( vbox, 1, 3, 20 );

   //TODO use the kguiItems from the actions
   mapper->setMapping( o = new KPushButton( KGuiItem( i18n("Play File..."), "fileopen" ), this ), FILE );
   connect( o, SIGNAL(clicked()), mapper, SLOT(map()) );
   grid->QLayout::add( o );

   mapper->setMapping( o = new KPushButton( KGuiItem( i18n("Play VCD"), "cdaudio_unmount" ), this ), VCD );
   connect( o, SIGNAL(clicked()), mapper, SLOT(map()) );
   grid->QLayout::add( o );

   mapper->setMapping( o = new KPushButton( KGuiItem( i18n("Play DVD"), "dvd_unmount" ), this ), DVD );
   connect( o, SIGNAL(clicked()), mapper, SLOT(map()) );
   grid->QLayout::add( o );

   mapper->setMapping( closeButton, QDialog::Rejected );
   connect( closeButton, SIGNAL(clicked()), mapper, SLOT(map()) );

   createRecentFileWidget( vbox );

   hbox = new QHBoxLayout( vbox );
   hbox->addItem( new QSpacerItem( 10, 10, QSizePolicy::Expanding ) );

   if( be_welcome_dialog ) {
      QWidget *w = new KPushButton( KStdGuiItem::quit(), this );
      hbox->addWidget( w );
      connect( w, SIGNAL(clicked()), kapp, SLOT(quit()) );
   }

   hbox->addWidget( closeButton );

   connect( mapper, SIGNAL(mapped( int )), SLOT(done( int )) );
}

void
PlayDialog::createRecentFileWidget( QBoxLayout *layout )
{
   KListView *lv;
   lv = new Codeine::ListView( this );
   lv->setColumnText( 1, i18n("Recently Played Media") );

   const QStringList list1 = Codeine::config( "General" )->readPathListEntry( "Recent Urls" );
   KURL::List urls;

   foreach( list1 )
      urls += *it;

   for( KURL::List::Iterator it = urls.begin(), end = urls.end(); it != end; ) {
      if( urls.contains( *it ) > 1 )
         //remove duplicates
         it = urls.remove( it );
      else if( (*it).protocol() == "file" && !QFile::exists( (*it).path() ) )
         //remove stale entries
         it = urls.remove( it );
      else
         ++it;
   }

   for( KURL::List::ConstIterator it = urls.begin(), end = urls.end(); it != end; ++it ) {
      const QString fileName = (*it).fileName();
      new KListViewItem( lv, 0, (*it).url(), fileName.isEmpty() ? (*it).prettyURL() : fileName );
   }

   if( lv->childCount() ) {
      layout->addWidget( lv, 1 );
      connect( lv, SIGNAL(executed( QListViewItem* )), SLOT(done( QListViewItem* )) );
   }
   else
      delete lv;
}

void
PlayDialog::done( QListViewItem *item )
{
   m_url = item->text( 0 );
   QDialog::done( RECENT_FILE );
}

}