File indexing completed on 2024-04-21 15:38:18
0001 /** 0002 * Copyright (C) 2002-2003 by Koos Vriezen <koos.vriezen@gmail.com> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License version 2 as published by the Free Software Foundation. 0007 * 0008 * This library is distributed in the hope that it will be useful, 0009 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0011 * Library General Public License for more details. 0012 * 0013 * You should have received a copy of the GNU Library General Public License 0014 * along with this library; see the file COPYING.LIB. If not, write to 0015 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, 0016 * Boston, MA 02110-1301, USA. 0017 **/ 0018 0019 #ifndef KMPLAYERPARTBASE_H 0020 #define KMPLAYERPARTBASE_H 0021 0022 #include "config-kmplayer.h" 0023 0024 #include "kmplayer_def.h" 0025 0026 #include <qobject.h> 0027 #include <QList> 0028 #include <QPointer> 0029 #include <QUrl> 0030 #include <qstringlist.h> 0031 #include <qmap.h> 0032 #include <QModelIndex> 0033 0034 #include <kmediaplayer/player.h> 0035 #include <kurl.h> 0036 #include <ksharedconfig.h> 0037 #include <kconfiggroup.h> 0038 0039 #include "kmplayerview.h" 0040 #include "kmplayerplaylist.h" 0041 0042 class QMenu; 0043 0044 class KAboutData; 0045 class KActionCollection; 0046 class KBookmarkMenu; 0047 class KBookmarkManager; 0048 0049 0050 namespace KMPlayer { 0051 0052 class PartBase; 0053 class Process; 0054 class MPlayer; 0055 class BookmarkOwner; 0056 class PlayModel; 0057 class Settings; 0058 class MediaManager; 0059 0060 0061 /** 0062 * Class for a certain media, like URL, DVD, TV etc 0063 */ 0064 class KMPLAYER_EXPORT Source : public QObject, public PlayListNotify { 0065 Q_OBJECT 0066 public: 0067 struct LangInfo { 0068 LangInfo (int i, const QString & n) : id (i), name (n) {} 0069 int id; QString name; SharedPtr <LangInfo> next; 0070 }; 0071 typedef SharedPtr <LangInfo> LangInfoPtr; 0072 0073 Source (const QString & name, PartBase * player, const char * src); 0074 virtual ~Source (); 0075 virtual void init (); 0076 virtual bool processOutput (const QString & line); 0077 0078 bool identified () const { return m_identified; } 0079 virtual bool hasLength (); 0080 virtual bool isSeekable (); 0081 0082 KDE_NO_EXPORT int width () const { return m_width; } 0083 KDE_NO_EXPORT int height () const { return m_height; } 0084 virtual void dimensions (int & w, int & h) { w = m_width; h = m_height; } 0085 /* length () returns length in deci-seconds */ 0086 KDE_NO_EXPORT int length () const { return m_length; } 0087 /* position () returns position in deci-seconds */ 0088 KDE_NO_EXPORT int position () const { return m_position; } 0089 KDE_NO_EXPORT float aspect () const { return m_aspect; } 0090 KDE_NO_EXPORT const KUrl & url () const { return m_url; } 0091 KDE_NO_EXPORT const KUrl & subUrl () const { return m_sub_url; } 0092 PartBase * player () { return m_player; } 0093 virtual void reset (); 0094 KDE_NO_EXPORT const QString & audioDevice () const { return m_audiodevice; } 0095 KDE_NO_EXPORT const QString & videoDevice () const { return m_videodevice; } 0096 KDE_NO_EXPORT const QString & videoNorm () const { return m_videonorm; } 0097 /* frequency() if set, returns frequency in kHz */ 0098 KDE_NO_EXPORT int frequency () const { return m_frequency; } 0099 KDE_NO_EXPORT int xvPort () const { return m_xvport; } 0100 KDE_NO_EXPORT int xvEncoding () const { return m_xvencoding; } 0101 KDE_NO_EXPORT int audioLangId () const { return m_audio_id; } 0102 KDE_NO_EXPORT int subTitleId () const { return m_subtitle_id; } 0103 KDE_NO_EXPORT const QString & pipeCmd () const { return m_pipecmd; } 0104 KDE_NO_EXPORT const QString & options () const { return m_options; } 0105 KDE_NO_EXPORT const QString & recordCmd () const { return m_recordcmd; } 0106 KDE_NO_EXPORT const QString & tuner () const { return m_tuner; } 0107 KDE_NO_EXPORT const char* name() const { return m_name; } 0108 KDE_NO_EXPORT Mrl *current() { return m_current ? m_current->mrl() : NULL;} 0109 virtual void setCurrent (Mrl *mrl); 0110 QString plugin (const QString &mime) const; 0111 virtual NodePtr document (); 0112 void setDocument (KMPlayer::NodePtr doc, KMPlayer::NodePtr cur); 0113 virtual NodePtr root (); 0114 virtual QString filterOptions (); 0115 virtual bool authoriseUrl (const QString &url); 0116 0117 virtual void setUrl (const QString &url); 0118 void insertURL (NodePtr mrl, const QString & url, const QString & title=QString()); 0119 KDE_NO_EXPORT void setSubURL (const KUrl & url) { m_sub_url = url; } 0120 void setLanguages (LangInfoPtr alang, LangInfoPtr slang) KDE_NO_EXPORT; 0121 KDE_NO_EXPORT void setWidth (int w) { m_width = w; } 0122 KDE_NO_EXPORT void setHeight (int h) { m_height = h; } 0123 virtual void setDimensions (NodePtr, int w, int h); 0124 virtual void setAspect (NodePtr, float a); 0125 /* setLength (len) set length in deci-seconds */ 0126 void setLength (NodePtr, int len); 0127 /* setPosition (pos) set position in deci-seconds */ 0128 void setPosition (int pos) KDE_NO_EXPORT; 0129 virtual void setIdentified (bool b = true); 0130 KDE_NO_EXPORT void setAutoPlay (bool b) { m_auto_play = b; } 0131 KDE_NO_EXPORT bool autoPlay () const { return m_auto_play; } 0132 KDE_NO_EXPORT void setAvoidRedirects (bool b) { m_avoid_redirects = b; } 0133 KDE_NO_EXPORT bool avoidRedirects () const { return m_avoid_redirects; } 0134 void setTitle (const QString & title); 0135 void setLoading (int percentage) KDE_NO_EXPORT; 0136 0137 virtual QString prettyName (); 0138 virtual void activate () = 0; 0139 virtual void deactivate () = 0; 0140 virtual void forward (); 0141 virtual void backward (); 0142 /** 0143 * Play at node position 0144 */ 0145 virtual void play (Mrl *); 0146 signals: 0147 void startPlaying (); 0148 void stopPlaying (); 0149 /** 0150 * Signal for notifying this source is at the end of play items 0151 */ 0152 void endOfPlayItems (); 0153 void dimensionsChanged (); 0154 void titleChanged (const QString & title); 0155 public slots: 0156 void slotActivate (); 0157 void setAudioLang (int) KDE_NO_EXPORT; 0158 void setSubtitle (int) KDE_NO_EXPORT; 0159 protected: 0160 void timerEvent (QTimerEvent *); 0161 /** 0162 * PlayListNotify implementation 0163 */ 0164 void stateElementChanged (Node * element, Node::State os, Node::State ns); 0165 void bitRates (int & preferred, int & maximal); 0166 void setTimeout (int ms); 0167 void openUrl (const KUrl &url, const QString &target, const QString &srv); 0168 void enableRepaintUpdaters (bool enable, unsigned int off_time); 0169 0170 NodePtr m_document; 0171 NodePtrW m_current; 0172 const char* m_name; 0173 PartBase * m_player; 0174 QString m_recordcmd; 0175 bool m_identified; 0176 bool m_auto_play; 0177 bool m_avoid_redirects; 0178 KUrl m_url; 0179 KUrl m_sub_url; 0180 QString m_audiodevice; 0181 QString m_videodevice; 0182 QString m_videonorm; 0183 QString m_tuner; 0184 int m_frequency; 0185 int m_xvport; 0186 int m_xvencoding; 0187 int m_audio_id; 0188 int m_subtitle_id; 0189 QString m_pipecmd; 0190 QString m_options; 0191 QString m_plugin; 0192 LangInfoPtr m_audio_infos; 0193 LangInfoPtr m_subtitle_infos; 0194 private: 0195 int m_width; 0196 int m_height; 0197 float m_aspect; 0198 int m_length; 0199 int m_position; 0200 int m_doc_timer; 0201 private slots: 0202 void changedUrl(); 0203 }; 0204 0205 class KMPLAYER_EXPORT SourceDocument : public Document { 0206 public: 0207 SourceDocument (Source *s, const QString &url); 0208 0209 void message (MessageType msg, void *data=NULL); 0210 void *role (RoleType msg, void *data=NULL); 0211 protected: 0212 Source *m_source; 0213 ConnectionList m_KeyListeners; 0214 }; 0215 /* 0216 * Source from URLs 0217 */ 0218 class KMPLAYER_EXPORT URLSource : public Source { 0219 Q_OBJECT 0220 public: 0221 URLSource (PartBase * player, const KUrl & url = KUrl ()); 0222 virtual ~URLSource (); 0223 0224 virtual void dimensions (int & w, int & h); 0225 virtual bool hasLength (); 0226 virtual QString prettyName (); 0227 virtual void reset (); 0228 virtual void setUrl (const QString &url); 0229 virtual bool authoriseUrl (const QString &url); 0230 virtual void init (); 0231 virtual void activate () KDE_NO_EXPORT; 0232 virtual void deactivate (); 0233 virtual void forward (); 0234 virtual void backward (); 0235 virtual void play (Mrl *); 0236 protected: 0237 bool activated; // 'solve' an singleShot race w/ cmdline url's 0238 }; 0239 0240 /* 0241 * KDE's KMediaPlayer::Player implementation and base for KMPlayerPart 0242 */ 0243 class KMPLAYER_EXPORT PartBase : public KMediaPlayer::Player { 0244 Q_OBJECT 0245 public: 0246 PartBase (QWidget *parent, QObject *objParent, KSharedConfigPtr); 0247 ~PartBase (); 0248 void init (KActionCollection *ac, const QString &objname, bool transparent); 0249 virtual KMediaPlayer::View* view (); 0250 View* viewWidget () const { return m_view; } 0251 static KAboutData* createAboutData (); 0252 0253 Settings * settings () const { return m_settings; } 0254 void keepMovieAspect (bool); 0255 KUrl url () const { return m_sources ["urlsource"]->url (); } 0256 void setUrl (const QString &url) { m_sources ["urlsource"]->setUrl (url); } 0257 KUrl docBase () const { return m_docbase; } 0258 0259 /* Changes the backend process */ 0260 QString processName (Mrl *mrl); 0261 0262 /* Changes the source, 0263 * calls init() and reschedules an activate() on the source 0264 * */ 0265 void setSource (Source * source); 0266 void createBookmarkMenu(QMenu *owner, KActionCollection *ac); 0267 void connectPanel (ControlPanel * panel); 0268 void connectPlaylist (PlayListView * playlist); 0269 void connectInfoPanel (InfoWindow * infopanel); 0270 void connectSource (Source * old_source, Source * source); 0271 MediaManager *mediaManager () const { return m_media_manager; } 0272 PlayModel *playModel () const { return m_play_model; } 0273 Source * source () const { return m_source; } 0274 QMap <QString, Source *> & sources () { return m_sources; } 0275 KSharedConfigPtr config () const { return m_config; } 0276 bool mayResize () const { return !m_noresize; } 0277 void updatePlayerMenu (ControlPanel *, const QString &backend=QString ()); 0278 void updateInfo (const QString & msg); 0279 void updateStatus (const QString & msg); 0280 0281 // these are called from Process 0282 void changeURL (const QString & url) KDE_NO_EXPORT; 0283 void updateTree (bool full=true, bool force=false); 0284 void setLanguages (const QStringList & alang, const QStringList & slang); 0285 void recorderPlaying (); 0286 void recorderStopped (); 0287 void stopRecording (); 0288 bool isRecording (); 0289 public slots: 0290 virtual bool openUrl (const QUrl & url); 0291 virtual bool openUrl (const KUrl & url); 0292 virtual void openUrl (const KUrl &, const QString &t, const QString &srv); 0293 virtual bool openUrl(const QList<QUrl>& urls); 0294 virtual bool closeUrl (); 0295 virtual void pause (void); 0296 virtual void play (void); 0297 virtual void stop (void); 0298 void record (); 0299 void record (const QString &src, const QString &file, 0300 const QString &recorder, int auto_start); 0301 void adjustVolume (int incdec); 0302 bool playing () const; 0303 void showConfigDialog (); 0304 void showPlayListWindow () KDE_NO_EXPORT; 0305 void slotPlayerMenu (QAction*) KDE_NO_EXPORT; 0306 void back (); 0307 void forward (); 0308 void addBookMark (const QString & title, const QString & url) KDE_NO_EXPORT; 0309 void volumeChanged (int) KDE_NO_EXPORT; 0310 void increaseVolume (); 0311 void decreaseVolume (); 0312 void setPosition (int position, int length) KDE_NO_EXPORT; 0313 virtual void setLoaded (int percentage); 0314 virtual void processCreated (Process *); 0315 public: 0316 virtual bool isSeekable (void) const; 0317 virtual qlonglong position (void) const; 0318 virtual bool hasLength (void) const; 0319 virtual qlonglong length (void) const; 0320 virtual void seek (qlonglong); 0321 void toggleFullScreen () KDE_NO_EXPORT; 0322 bool isPlaying () KDE_NO_EXPORT; 0323 0324 virtual QString doEvaluate (const QString &script); 0325 void showControls (bool show) KDE_NO_EXPORT; 0326 QString getStatus (); 0327 signals: 0328 void sourceChanged (KMPlayer::Source * old, KMPlayer::Source * nw); 0329 void sourceDimensionChanged (); 0330 void loading (int percentage); 0331 void urlAdded (const QString & url); 0332 void urlChanged (const QString & url); 0333 void processChanged (const char *); 0334 void treeChanged (int id, NodePtr root, NodePtr, bool select, bool open); 0335 void infoUpdated (const QString & msg); 0336 void statusUpdated (const QString & msg); 0337 void languagesUpdated(const QStringList & alang, const QStringList & slang); 0338 void audioIsSelected (int id); 0339 void subtitleIsSelected (int id); 0340 void positioned (int pos, int length); 0341 void panelActionToggled(QAction*); 0342 void recording (bool); 0343 protected: 0344 bool openFile(); 0345 virtual void timerEvent (QTimerEvent *); 0346 virtual void playingStarted (); 0347 virtual void playingStopped (); 0348 protected slots: 0349 void posSliderPressed () KDE_NO_EXPORT; 0350 void posSliderReleased () KDE_NO_EXPORT; 0351 void positionValueChanged (int val) KDE_NO_EXPORT; 0352 void contrastValueChanged (int val) KDE_NO_EXPORT; 0353 void brightnessValueChanged (int val) KDE_NO_EXPORT; 0354 void hueValueChanged (int val) KDE_NO_EXPORT; 0355 void saturationValueChanged (int val) KDE_NO_EXPORT; 0356 void sourceHasChangedAspects () KDE_NO_EXPORT; 0357 void fullScreen () KDE_NO_EXPORT; 0358 void playListItemClicked (const QModelIndex &) KDE_NO_EXPORT; 0359 void playListItemActivated (const QModelIndex &) KDE_NO_EXPORT; 0360 void slotPlayingStarted (); 0361 void slotPlayingStopped (); 0362 void settingsChanged (); 0363 void audioSelected (QAction*) KDE_NO_EXPORT; 0364 void subtitleSelected (QAction*) KDE_NO_EXPORT; 0365 protected: 0366 KUrl m_docbase; 0367 NodePtr m_record_doc; 0368 KSharedConfigPtr m_config; 0369 QPointer <View> m_view; 0370 QMap <QString, QString> temp_backends; 0371 Settings *m_settings; 0372 MediaManager *m_media_manager; 0373 PlayModel *m_play_model; 0374 Source * m_source; 0375 QMap <QString, Source *> m_sources; 0376 KBookmarkManager * m_bookmark_manager; 0377 BookmarkOwner * m_bookmark_owner; 0378 KBookmarkMenu * m_bookmark_menu; 0379 int m_update_tree_timer; 0380 int m_rec_timer; 0381 bool m_noresize : 1; 0382 bool m_auto_controls : 1; 0383 bool m_use_slave : 1; 0384 bool m_bPosSliderPressed : 1; 0385 bool m_in_update_tree : 1; 0386 bool m_update_tree_full : 1; 0387 }; 0388 0389 } // namespace 0390 0391 #endif