• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • interfaces
 

interfaces

  • interfaces
  • kmediaplayer
  • kfileaudiopreview
kfileaudiopreview.cpp
1 #include "kfileaudiopreview.h"
2 
3 #include <tqcheckbox.h>
4 #include <tqhbox.h>
5 #include <tqlayout.h>
6 #include <tqvgroupbox.h>
7 
8 #include <kglobal.h>
9 #include <kconfig.h>
10 #include <klibloader.h>
11 #include <klocale.h>
12 #include <kmediaplayer/player.h>
13 #include <kmimetype.h>
14 #include <kparts/componentfactory.h>
15 
16 #include <kplayobjectfactory.h>
17 
18 #include <config-kfile.h>
19 
20 class KFileAudioPreviewFactory : public KLibFactory
21 {
22 protected:
23  virtual TQObject *createObject( TQObject *parent, const char *name,
24  const char *className, const TQStringList & args)
25  {
26  Q_UNUSED(className);
27  Q_UNUSED(args);
28  return TQT_TQOBJECT(new KFileAudioPreview( dynamic_cast<TQWidget*>( parent ), name ));
29  }
30 };
31 
32 K_EXPORT_COMPONENT_FACTORY( kfileaudiopreview, KFileAudioPreviewFactory )
33 
34 
35 
38 
39 class KFileAudioPreview::KFileAudioPreviewPrivate
40 {
41 public:
42  KFileAudioPreviewPrivate( TQWidget *parent )
43  {
44  player = KParts::ComponentFactory::createInstanceFromQuery<KMediaPlayer::Player>( "KMediaPlayer/Player", TQString(), TQT_TQOBJECT(parent) );
45  }
46 
47  ~KFileAudioPreviewPrivate()
48  {
49  delete player;
50  }
51 
52  KMediaPlayer::Player *player;
53 };
54 
55 
56 KFileAudioPreview::KFileAudioPreview( TQWidget *parent, const char *name )
57  : KPreviewWidgetBase( parent, name )
58 {
59  KGlobal::locale()->insertCatalogue("kfileaudiopreview");
60 
61  TQStringList formats = KDE::PlayObjectFactory::mimeTypes();
62  // ###
63  TQStringList::ConstIterator it = formats.begin();
64  for ( ; it != formats.end(); ++it )
65  m_supportedFormats.insert( *it, (void*) 1 );
66 
67  TQVGroupBox *box = new TQVGroupBox( i18n("Media Player"), this );
68  TQVBoxLayout *layout = new TQVBoxLayout( this );
69  layout->addWidget( box );
70 
71  (void) new TQWidget( box ); // spacer
72 
73  d = new KFileAudioPreviewPrivate( 0L ); // not box -- being reparented anyway
74  if ( d->player ) // only if there actually is a component...
75  {
76  setSupportedMimeTypes( formats );
77  KMediaPlayer::View *view = d->player->view();
78  view->setEnabled( false );
79 
80  // if we have access to the video widget, show it above the player
81  // So, reparent first the video widget, then the view.
82  if ( view->videoWidget() )
83  {
84  TQHBox *frame = new TQHBox( box );
85  frame->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
86  frame->setSizePolicy( TQSizePolicy( TQSizePolicy::Expanding, TQSizePolicy::Expanding ) );
87  view->videoWidget()->reparent( frame, TQPoint(0,0) );
88  }
89 
90  view->reparent( box, TQPoint(0,0) );
91  }
92 
93  m_autoPlay = new TQCheckBox( i18n("Play &automatically"), box );
94  KConfigGroup config( KGlobal::config(), ConfigGroup );
95  m_autoPlay->setChecked( config.readBoolEntry( "Autoplay sounds", true ) );
96  connect( m_autoPlay, TQT_SIGNAL(toggled(bool)), TQT_SLOT(toggleAuto(bool)) );
97 }
98 
99 KFileAudioPreview::~KFileAudioPreview()
100 {
101  KConfigGroup config( KGlobal::config(), ConfigGroup );
102  config.writeEntry( "Autoplay sounds", m_autoPlay->isChecked() );
103 
104  delete d;
105 }
106 
107 void KFileAudioPreview::showPreview( const KURL &url )
108 {
109  if ( !d->player || !url.isValid() )
110  return;
111 
112  KMimeType::Ptr mt = KMimeType::findByURL( url );
113  bool supported = m_supportedFormats.find( mt->name() );
114  d->player->view()->setEnabled( supported );
115  if ( !supported )
116  return;
117 
118  static_cast<KParts::ReadOnlyPart*>(d->player)->openURL( url );
119  if ( m_autoPlay->isChecked() )
120  d->player->play();
121 }
122 
123 void KFileAudioPreview::clearPreview()
124 {
125  if ( d->player )
126  {
127  d->player->stop();
128  d->player->closeURL();
129  }
130 }
131 
132 void KFileAudioPreview::toggleAuto( bool on )
133 {
134  if ( !d->player )
135  return;
136 
137  if ( on && m_currentURL.isValid() && d->player->view()->isEnabled() )
138  d->player->play();
139  else
140  d->player->stop();
141 }
142 
143 void KFileAudioPreview::virtual_hook( int, void* )
144 {}
145 
146 #include "kfileaudiopreview.moc"
KConfigGroup
KFileAudioPreview
Audio "preview" widget for the file dialog.
Definition: kfileaudiopreview.h:38
KGlobal::config
static KConfig * config()
KGlobal::locale
static KLocale * locale()
KLibFactory
KLibFactory::createObject
virtual TQObject * createObject(TQObject *parent=0, const char *name=0, const char *className=TQOBJECT_OBJECT_NAME_STRING, const TQStringList &args=TQStringList())=0
KLocale::insertCatalogue
void insertCatalogue(const TQString &catalog)
KMediaPlayer::Player
Player is the center of the KMediaPlayer interface.
Definition: player.h:47
KMediaPlayer::View
View is part of the user interface of a Player.
Definition: kmediaplayer/view.h:35
KMediaPlayer::View::videoWidget
TQWidget * videoWidget()
Return the TQWidget in which video is displayed.
Definition: view.cpp:84
KParts::ReadOnlyPart
KURL
KURL::isValid
bool isValid() const
klocale.h
KStdAccel::name
TQString name(StdAccel id)

interfaces

Skip menu "interfaces"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

interfaces

Skip menu "interfaces"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for interfaces by doxygen 1.9.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |