File indexing completed on 2024-03-24 16:22:08
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 KMPLAYER_PART_H 0020 #define KMPLAYER_PART_H 0021 0022 #include <kpluginfactory.h> 0023 #include <kparts/browserextension.h> 0024 #include <kparts/liveconnectextension.h> 0025 #include <kaboutdata.h> 0026 #include "kmplayerpartbase.h" 0027 #include "config-kmplayer.h" 0028 0029 0030 class QLabel; 0031 class KMPlayerPart; 0032 class JSCommandEntry; 0033 namespace KMPlayer { 0034 class PlayListNotify; 0035 } 0036 0037 class KMPlayerFactory : public KPluginFactory { 0038 Q_OBJECT 0039 Q_PLUGIN_METADATA(IID "org.kde.KPluginFactory") 0040 Q_INTERFACES(KPluginFactory) 0041 public: 0042 KMPlayerFactory(); 0043 virtual ~KMPlayerFactory(); 0044 0045 virtual QObject* create(const char *iface, QWidget* parentWidget, QObject* parent, 0046 const QVariantList& args, const QString& keyword) Q_DECL_OVERRIDE; 0047 static KAboutData& aboutData(); 0048 private: 0049 static KAboutData* s_about; 0050 }; 0051 0052 /* 0053 * Document to get first frame for streams starting with a picture 0054 */ 0055 class KMPLAYER_NO_EXPORT GrabDocument : public KMPlayer::SourceDocument { 0056 public: 0057 GrabDocument (KMPlayerPart *part, const QString &url, const QString &file, 0058 KMPlayer::PlayListNotify *); 0059 0060 virtual void activate (); 0061 virtual void undefer (); 0062 virtual void begin (); 0063 virtual void message (KMPlayer::MessageType msg, void *content); 0064 0065 QString m_grab_file; 0066 KMPlayerPart *m_part; 0067 }; 0068 0069 /* 0070 * Part notifications to hosting application 0071 */ 0072 class KMPLAYER_NO_EXPORT KMPlayerBrowserExtension : public KParts::BrowserExtension { 0073 Q_OBJECT 0074 public: 0075 KMPlayerBrowserExtension(KMPlayerPart *parent); 0076 KDE_NO_CDTOR_EXPORT ~KMPlayerBrowserExtension () {} 0077 void urlChanged (const QString & url); 0078 void setLoadingProgress (int percentage); 0079 0080 void saveState (QDataStream & stream); 0081 void restoreState (QDataStream & stream); 0082 void requestOpenURL (const KUrl & url, const QString & target, const QString & service); 0083 }; 0084 0085 /* 0086 * Part javascript support 0087 */ 0088 class KMPLAYER_NO_EXPORT KMPlayerLiveConnectExtension : public KParts::LiveConnectExtension { 0089 Q_OBJECT 0090 public: 0091 KMPlayerLiveConnectExtension (KMPlayerPart * parent); 0092 ~KMPlayerLiveConnectExtension (); 0093 0094 // LiveConnect interface 0095 bool get (const unsigned long, const QString &, 0096 KParts::LiveConnectExtension::Type &, unsigned long &, QString &); 0097 bool put (const unsigned long, const QString &, const QString &); 0098 bool call (const unsigned long, const QString &, 0099 const QStringList &, KParts::LiveConnectExtension::Type &, 0100 unsigned long &, QString &); 0101 void unregister (const unsigned long); 0102 void sendEvent(const unsigned long objid, const QString & event, const KParts::LiveConnectExtension::ArgList & args ) { 0103 emit partEvent(objid, event, args); 0104 } 0105 0106 void enableFinishEvent (bool b = true) { m_enablefinish = b; } 0107 QString evaluate (const QString & script); 0108 signals: 0109 void partEvent (const unsigned long, const QString &, 0110 const KParts::LiveConnectExtension::ArgList &); 0111 void requestGet (const uint32_t, const QString &, QString *); 0112 void requestCall (const uint32_t, const QString &, const QStringList &, QString *); 0113 public slots: 0114 void setSize (int w, int h); 0115 void started (); 0116 void finished (); 0117 void evaluate (const QString & script, bool store, QString & result); 0118 private: 0119 KMPlayerPart * player; 0120 QString script_result; 0121 QString m_allow; 0122 QStringList redir_funcs; 0123 const JSCommandEntry * lastJSCommandEntry; 0124 unsigned int object_counter; 0125 bool m_started; 0126 bool m_enablefinish; 0127 bool m_evaluating; 0128 bool m_skip_put; 0129 }; 0130 0131 0132 /* 0133 * Part that gets created when used a KPart 0134 */ 0135 class KMPLAYER_NO_EXPORT KMPlayerPart : public KMPlayer::PartBase { 0136 Q_OBJECT 0137 friend struct GroupPredicate; 0138 public: 0139 enum Features { 0140 Feat_Unknown = 0, 0141 Feat_Viewer = 0x01, Feat_Controls = 0x02, 0142 Feat_Label = 0x04, Feat_StatusBar = 0x08, 0143 Feat_InfoPanel = 0x10, Feat_VolumeSlider = 0x20, Feat_PlayList = 0x40, 0144 Feat_ImageWindow = 0x80, Feat_All = 0xff 0145 }; 0146 KMPlayerPart (QWidget *wparent, QObject *parent, const QVariantList &args); 0147 ~KMPlayerPart (); 0148 0149 KDE_NO_EXPORT KMPlayerBrowserExtension * browserextension() const 0150 { return m_browserextension; } 0151 KMPlayerLiveConnectExtension * liveconnectextension () const 0152 { return m_liveconnectextension; } 0153 KDE_NO_EXPORT bool hasFeature (int f) { return m_features & f; } 0154 bool allowRedir (const KUrl & url) const; 0155 void connectToPart (KMPlayerPart *); 0156 KMPlayerPart * master () const { return m_master; } 0157 void setMaster (KMPlayerPart * m) { m_master = m; } 0158 virtual void setLoaded (int percentage); 0159 bool openNewURL (const KUrl & url); // for JS interface 0160 bool startUrl (const KUrl &url, const QString &pic=QString ());//clickToPlay 0161 0162 virtual QString doEvaluate (const QString &script); 0163 0164 using KMPlayer::PartBase::openUrl; 0165 public slots: 0166 virtual bool openUrl(const QUrl& url); 0167 virtual void openUrl(const QUrl&, const QString& t, const QString& srv); 0168 virtual bool closeUrl (); 0169 void setMenuZoom (int id); 0170 protected: 0171 virtual void processCreated (KMPlayer::Process *); 0172 virtual void playingStarted (); 0173 virtual void playingStopped (); 0174 protected slots: 0175 void viewerPartDestroyed (QObject *); 0176 void viewerPartProcessChanged (const char *); 0177 void viewerPartSourceChanged (KMPlayer::Source *, KMPlayer::Source *); 0178 void waitForImageWindowTimeOut (); 0179 void statusPosition (int pos, int length); 0180 void nppLoaded (); 0181 #ifndef KMPLAYER_WITH_CAIRO 0182 void pictureClicked (); 0183 #endif 0184 private: 0185 void setAutoControls (bool); 0186 KMPlayerPart * m_master; 0187 KMPlayerBrowserExtension * m_browserextension; 0188 KMPlayerLiveConnectExtension * m_liveconnectextension; 0189 QLabel* m_playtime_info; 0190 QString m_group; 0191 QString m_src_url; 0192 QString m_href_url; 0193 QString m_file_name; 0194 QString m_grab_file; 0195 QString m_target; 0196 int m_expected_view_width; 0197 int m_expected_view_height; 0198 int m_features; 0199 int last_time_left; 0200 bool m_started_emited : 1; 0201 bool m_wait_npp_loaded : 1; 0202 //bool m_noresize : 1; 0203 }; 0204 0205 0206 #endif