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