diff options
Diffstat (limited to 'src/plugins')
33 files changed, 3331 insertions, 390 deletions
diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.h b/src/plugins/bearer/corewlan/qcorewlanengine.h index 044b433..cfd89e4 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.h +++ b/src/plugins/bearer/corewlan/qcorewlanengine.h @@ -46,6 +46,7 @@ #include <QMap> #include <QTimer> +#include <SystemConfiguration/SystemConfiguration.h> QT_BEGIN_NAMESPACE @@ -91,6 +92,11 @@ private: bool isKnownSsid(const QString &interfaceName, const QString &ssid); QList<QNetworkConfigurationPrivate *> foundConfigurations; + SCDynamicStoreRef storeSession; + CFRunLoopSourceRef runloopSource; + + void startNetworkChangeLoop(); + }; QT_END_NAMESPACE diff --git a/src/plugins/bearer/corewlan/qcorewlanengine.mm b/src/plugins/bearer/corewlan/qcorewlanengine.mm index 9a28a33..2d33d36 100644 --- a/src/plugins/bearer/corewlan/qcorewlanengine.mm +++ b/src/plugins/bearer/corewlan/qcorewlanengine.mm @@ -105,12 +105,23 @@ static QString qGetInterfaceType(const QString &interfaceString) return networkInterfaces.value(interfaceString, QLatin1String("Unknown")); } +void networkChangeCallback(SCDynamicStoreRef/* store*/, CFArrayRef changedKeys, void *info) +{ + for ( long i = 0; i < CFArrayGetCount(changedKeys); i++) { + + CFStringRef changed = (CFStringRef)CFArrayGetValueAtIndex(changedKeys, i); + if( cfstringRefToQstring(changed).contains("/Network/Global/IPv4")) { + QCoreWlanEngine* wlanEngine = static_cast<QCoreWlanEngine*>(info); + wlanEngine->requestUpdate(); + } + } + return; +} + QCoreWlanEngine::QCoreWlanEngine(QObject *parent) : QBearerEngineImpl(parent) { - connect(&pollTimer, SIGNAL(timeout()), this, SLOT(doRequestUpdate())); - pollTimer.setInterval(10000); - doRequestUpdate(); + startNetworkChangeLoop(); } QCoreWlanEngine::~QCoreWlanEngine() @@ -150,7 +161,6 @@ void QCoreWlanEngine::connectToId(const QString &id) NSEnumerator *enumerator = [remNets objectEnumerator]; CWWirelessProfile *wProfile; NSUInteger index=0; - CWNetwork *apNetwork; NSDictionary *parametersDict; NSArray* apArray; @@ -160,7 +170,7 @@ void QCoreWlanEngine::connectToId(const QString &id) while ((wProfile = [enumerator nextObject])) { //CWWirelessProfile - if(id == nsstringToQString([wProfile ssid])) { + if(id == QString::number(qHash(QLatin1String("corewlan:") + nsstringToQString([wProfile ssid])))) { user8021XProfile = nil; user8021XProfile = [ wProfile user8021XProfile]; @@ -179,7 +189,7 @@ void QCoreWlanEngine::connectToId(const QString &id) if(!err) { for(uint row=0; row < [apArray count]; row++ ) { - apNetwork = [apArray objectAtIndex:row]; + CWNetwork *apNetwork = [apArray objectAtIndex:row]; if([[apNetwork ssid] compare:[wProfile ssid]] == NSOrderedSame) { bool result = [wifiInterface associateToNetwork: apNetwork parameters:[NSDictionary dictionaryWithDictionary:params] error:&err]; @@ -196,7 +206,6 @@ void QCoreWlanEngine::connectToId(const QString &id) } index++; } - [apNetwork release]; emit connectionError(id, InterfaceLookupError); #endif @@ -282,7 +291,7 @@ void QCoreWlanEngine::doRequestUpdate() if (!interface.addressEntries().isEmpty()) state = QNetworkConfiguration::Active; - if (accessPointConfigurations.contains(id)) { + if (accessPointConfigurations.contains(id)) { //handle only scanned AP's QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.value(id); bool changed = false; @@ -309,20 +318,6 @@ void QCoreWlanEngine::doRequestUpdate() if (changed) emit configurationChanged(ptr); - } else { - QNetworkConfigurationPrivatePointer ptr(new QNetworkConfigurationPrivate); - - ptr->name = name; - ptr->isValid = true; - ptr->id = id; - ptr->state = state; - ptr->type = QNetworkConfiguration::InternetAccessPoint; - ptr->bearer = qGetInterfaceType(interface.name()); - - accessPointConfigurations.insert(id, ptr); - configurationInterface.insert(id, interface.name()); - - emit configurationAdded(ptr); } } @@ -486,12 +481,6 @@ bool QCoreWlanEngine::getAllScInterfaces() CFStringRef type = SCNetworkInterfaceGetInterfaceType((SCNetworkInterfaceRef)thisInterface); if ( CFEqual(type, kSCNetworkInterfaceTypeIEEE80211)) { typeStr = "WLAN"; -// } else if (CFEqual(type, kSCNetworkInterfaceTypeBluetooth)) { -// typeStr = "Bluetooth"; - } else if(CFEqual(type, kSCNetworkInterfaceTypeEthernet)) { - typeStr = "Ethernet"; - } else if(CFEqual(type, kSCNetworkInterfaceTypeFireWire)) { - typeStr = "Ethernet"; //ok a bit fudged } if(!networkInterfaces.contains(interfaceName) && !typeStr.isEmpty()) { networkInterfaces.insert(interfaceName,typeStr); @@ -536,6 +525,60 @@ QNetworkConfigurationManager::Capabilities QCoreWlanEngine::capabilities() const return QNetworkConfigurationManager::ForcedRoaming; } +void QCoreWlanEngine::startNetworkChangeLoop() +{ + storeSession = NULL; + + SCDynamicStoreContext dynStoreContext = { 0, this/*(void *)storeSession*/, NULL, NULL, NULL }; + storeSession = SCDynamicStoreCreate(NULL, + CFSTR("networkChangeCallback"), + networkChangeCallback, + &dynStoreContext); + if (!storeSession ) { + qWarning() << "could not open dynamic store: error:" << SCErrorString(SCError()); + return; + } + + CFMutableArrayRef notificationKeys; + notificationKeys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + CFMutableArrayRef patternsArray; + patternsArray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); + + CFStringRef storeKey; + storeKey = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, + kSCDynamicStoreDomainState, + kSCEntNetIPv4); + CFArrayAppendValue(notificationKeys, storeKey); + CFRelease(storeKey); + + storeKey = SCDynamicStoreKeyCreateNetworkServiceEntity(NULL, + kSCDynamicStoreDomainState, + kSCCompAnyRegex, + kSCEntNetIPv4); + CFArrayAppendValue(patternsArray, storeKey); + CFRelease(storeKey); + + if (!SCDynamicStoreSetNotificationKeys(storeSession , notificationKeys, patternsArray)) { + qWarning() << "register notification error:"<< SCErrorString(SCError()); + CFRelease(storeSession ); + CFRelease(notificationKeys); + CFRelease(patternsArray); + return; + } + CFRelease(notificationKeys); + CFRelease(patternsArray); + + runloopSource = SCDynamicStoreCreateRunLoopSource(NULL, storeSession , 0); + if (!runloopSource) { + qWarning() << "runloop source error:"<< SCErrorString(SCError()); + CFRelease(storeSession ); + return; + } + + CFRunLoopAddSource(CFRunLoopGetCurrent(), runloopSource, kCFRunLoopDefaultMode); + return; +} + QNetworkSessionPrivate *QCoreWlanEngine::createSessionBackend() { return new QNetworkSessionPrivateImpl; diff --git a/src/plugins/bearer/icd/monitor.cpp b/src/plugins/bearer/icd/monitor.cpp index 0ff45d2..5b0af7e 100644 --- a/src/plugins/bearer/icd/monitor.cpp +++ b/src/plugins/bearer/icd/monitor.cpp @@ -47,32 +47,12 @@ #include <maemo_icd.h> #include <iapconf.h> -#define IAP "/system/osso/connectivity/IAP" - -static int iap_prefix_len; - -/* Notify func that is called when IAP is added or deleted */ -void notify_iap(GConfClient *, guint, GConfEntry *entry, gpointer user_data) -{ - const char *key = gconf_entry_get_key(entry); - if (key && g_str_has_prefix(key, IAP)) { - IapMonitor *ptr = (IapMonitor *)user_data; - if (gconf_entry_get_value(entry)) { - ptr->iapAdded(key, entry); - } else { - ptr->iapDeleted(key, entry); - } - } -} - void IapMonitor::setup(QIcdEngine *d_ptr) { if (first_call) { - d = d_ptr; - iap_prefix_len = strlen(IAP); - iap = new Maemo::IAPMonitor(notify_iap, (gpointer)this); - first_call = false; + d = d_ptr; + first_call = false; } } @@ -80,37 +60,25 @@ void IapMonitor::setup(QIcdEngine *d_ptr) void IapMonitor::cleanup() { if (!first_call) { - delete iap; - timers.removeAll(); - first_call = true; + timers.removeAll(); + first_call = true; } } -void IapMonitor::iapAdded(const char *key, GConfEntry * /*entry*/) +void IapMonitor::iapAdded(const QString &iap_id) { - //qDebug("Notify called for added element: %s=%s", - // gconf_entry_get_key(entry), gconf_value_to_string(gconf_entry_get_value(entry))); - - /* We cannot know when the IAP is fully added to gconf, so a timer is + /* We cannot know when the IAP is fully added to db, so a timer is * installed instead. When the timer expires we hope that IAP is added ok. */ - QString iap_id = QString(key + iap_prefix_len + 1).section('/',0,0); - timers.add(iap_id, d); + QString id = iap_id; + timers.add(id, d); } -void IapMonitor::iapDeleted(const char *key, GConfEntry * /*entry*/) +void IapMonitor::iapRemoved(const QString &iap_id) { - //qDebug("Notify called for deleted element: %s", gconf_entry_get_key(entry)); - - /* We are only interested in IAP deletions so we skip the config entries - */ - if (strstr(key + iap_prefix_len + 1, "/")) { - //qDebug("Deleting IAP config %s", key+iap_prefix_len); - return; - } - - QString iap_id = key + iap_prefix_len + 1; - d->deleteConfiguration(iap_id); + QString id = iap_id; + d->deleteConfiguration(id); } + diff --git a/src/plugins/bearer/icd/monitor.h b/src/plugins/bearer/icd/monitor.h index 82b0f36..10ffb30 100644 --- a/src/plugins/bearer/icd/monitor.h +++ b/src/plugins/bearer/icd/monitor.h @@ -53,7 +53,7 @@ class QIcdEngine; /* The IapAddTimer is a helper class that makes sure we update - * the configuration only after all gconf additions to certain + * the configuration only after all db additions to certain * iap are finished (after a certain timeout) */ class _IapAddTimer : public QObject @@ -64,10 +64,10 @@ public: _IapAddTimer() {} ~_IapAddTimer() { - if (timer.isActive()) { - QObject::disconnect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); - timer.stop(); - } + if (timer.isActive()) { + QObject::disconnect(&timer, SIGNAL(timeout()), this, SLOT(timeout())); + timer.stop(); + } } void add(QString& iap_id, QIcdEngine *d); @@ -92,23 +92,21 @@ public: void removeAll(); }; -class IapMonitor +class IapMonitor : public Maemo::IAPMonitor { public: IapMonitor() : first_call(true) { } - friend void notify_iap(GConfClient *, guint, - GConfEntry *entry, gpointer user_data); void setup(QIcdEngine *d); void cleanup(); +protected: + void iapAdded(const QString &iapId); + void iapRemoved(const QString &iapId); + private: bool first_call; - void iapAdded(const char *key, GConfEntry *entry); - void iapDeleted(const char *key, GConfEntry *entry); - - Maemo::IAPMonitor *iap; QIcdEngine *d; IapAddTimer timers; }; diff --git a/src/plugins/bearer/icd/qicdengine.cpp b/src/plugins/bearer/icd/qicdengine.cpp index f10042a..206a6fd 100644 --- a/src/plugins/bearer/icd/qicdengine.cpp +++ b/src/plugins/bearer/icd/qicdengine.cpp @@ -189,14 +189,9 @@ void QIcdEngine::doRequestUpdate() QList<QString> all_iaps; Maemo::IAPConf::getAll(all_iaps); - foreach (QString escaped_iap_id, all_iaps) { + foreach (QString iap_id, all_iaps) { QByteArray ssid; - /* The key that is returned by getAll() needs to be unescaped */ - gchar *unescaped_id = gconf_unescape_key(escaped_iap_id.toUtf8().data(), -1); - QString iap_id = QString((char *)unescaped_id); - g_free(unescaped_id); - previous.removeAll(iap_id); Maemo::IAPConf saved_ap(iap_id); @@ -231,11 +226,12 @@ void QIcdEngine::doRequestUpdate() IcdNetworkConfigurationPrivate *cpPriv = new IcdNetworkConfigurationPrivate; cpPriv->name = saved_ap.value("name").toString(); - if (cpPriv->name.isEmpty()) - if (!ssid.isEmpty() && ssid.size() > 0) - cpPriv->name = ssid.data(); - else - cpPriv->name = iap_id; + if (cpPriv->name.isEmpty()) { + if (!ssid.isEmpty() && ssid.size() > 0) + cpPriv->name = ssid.data(); + else + cpPriv->name = iap_id; + } cpPriv->isValid = true; cpPriv->id = iap_id; cpPriv->network_id = ssid; @@ -379,9 +375,9 @@ void QIcdEngine::deleteConfiguration(const QString &iap_id) { QMutexLocker locker(&mutex); - /* Called when IAPs are deleted in gconf, in this case we do not scan - * or read all the IAPs from gconf because it might take too much power - * (multiple applications would need to scan and read all IAPs from gconf) + /* Called when IAPs are deleted in db, in this case we do not scan + * or read all the IAPs from db because it might take too much power + * (multiple applications would need to scan and read all IAPs from db) */ if (accessPointConfigurations.contains(iap_id)) { QNetworkConfigurationPrivatePointer ptr = accessPointConfigurations.take(iap_id); diff --git a/src/plugins/bearer/icd/qnetworksession_impl.cpp b/src/plugins/bearer/icd/qnetworksession_impl.cpp index e7c56a2..03624fa 100644 --- a/src/plugins/bearer/icd/qnetworksession_impl.cpp +++ b/src/plugins/bearer/icd/qnetworksession_impl.cpp @@ -49,6 +49,7 @@ #include <maemo_icd.h> #include <iapconf.h> +#include <proxyconf.h> #include <sys/types.h> #include <ifaddrs.h> @@ -299,6 +300,8 @@ void IcdListener::cleanupSession(QNetworkSessionPrivateImpl *ptr) void QNetworkSessionPrivateImpl::cleanupSession(void) { icdListener()->cleanupSession(this); + + QObject::disconnect(q, SIGNAL(stateChanged(QNetworkSession::State)), this, SLOT(updateProxies(QNetworkSession::State))); } @@ -451,6 +454,8 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() connect(&manager, SIGNAL(configurationChanged(QNetworkConfiguration)), this, SLOT(configurationChanged(QNetworkConfiguration))); + QObject::connect(q, SIGNAL(stateChanged(QNetworkSession::State)), this, SLOT(updateProxies(QNetworkSession::State))); + state = QNetworkSession::Invalid; lastError = QNetworkSession::UnknownSessionError; @@ -867,7 +872,6 @@ void QNetworkSessionPrivateImpl::do_open() qDebug() << "connect to"<< iap << "failed, result is empty"; #endif updateState(QNetworkSession::Disconnected); - emit quitPendingWaitsForOpened(); emit QNetworkSessionPrivate::error(QNetworkSession::InvalidConfigurationError); if (publicConfig.type() == QNetworkConfiguration::UserChoice) cleanupAnyConfiguration(); @@ -882,7 +886,6 @@ void QNetworkSessionPrivateImpl::do_open() if ((publicConfig.type() != QNetworkConfiguration::UserChoice) && (connected_iap != config.identifier())) { updateState(QNetworkSession::Disconnected); - emit quitPendingWaitsForOpened(); emit QNetworkSessionPrivate::error(QNetworkSession::InvalidConfigurationError); return; } @@ -946,7 +949,6 @@ void QNetworkSessionPrivateImpl::do_open() updateState(QNetworkSession::Disconnected); if (publicConfig.type() == QNetworkConfiguration::UserChoice) cleanupAnyConfiguration(); - emit quitPendingWaitsForOpened(); emit QNetworkSessionPrivate::error(QNetworkSession::UnknownSessionError); } } @@ -1099,6 +1101,30 @@ QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const return QNetworkSession::UnknownSessionError; } +void QNetworkSessionPrivateImpl::updateProxies(QNetworkSession::State newState) +{ + if ((newState == QNetworkSession::Connected) && + (newState != currentState)) + updateProxyInformation(); + else if ((newState == QNetworkSession::Disconnected) && + (currentState == QNetworkSession::Closing)) + clearProxyInformation(); + + currentState = newState; +} + + +void QNetworkSessionPrivateImpl::updateProxyInformation() +{ + Maemo::ProxyConf::update(); +} + + +void QNetworkSessionPrivateImpl::clearProxyInformation() +{ + Maemo::ProxyConf::clear(); +} + #include "qnetworksession_impl.moc" QT_END_NAMESPACE diff --git a/src/plugins/bearer/icd/qnetworksession_impl.h b/src/plugins/bearer/icd/qnetworksession_impl.h index b7461dc..587e6dc 100644 --- a/src/plugins/bearer/icd/qnetworksession_impl.h +++ b/src/plugins/bearer/icd/qnetworksession_impl.h @@ -75,7 +75,7 @@ class QNetworkSessionPrivateImpl : public QNetworkSessionPrivate public: QNetworkSessionPrivateImpl(QIcdEngine *engine) - : engine(engine), connectFlags(ICD_CONNECTION_FLAG_USER_EVENT) + : engine(engine), connectFlags(ICD_CONNECTION_FLAG_USER_EVENT), currentState(QNetworkSession::Invalid) { } @@ -118,6 +118,7 @@ private Q_SLOTS: void do_open(); void networkConfigurationsChanged(); void configurationChanged(const QNetworkConfiguration &config); + void updateProxies(QNetworkSession::State newState); private: QNetworkConfigurationManager manager; @@ -139,6 +140,10 @@ private: void updateIdentifier(QString &newId); quint64 getStatistics(bool sent) const; void cleanupSession(void); + + void updateProxyInformation(); + void clearProxyInformation(); + QNetworkSession::State currentState; }; QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp index 5c6efe3..0fa8f3c 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerengine.cpp @@ -49,7 +49,6 @@ #include <QtCore/qdebug.h> -#include <NetworkManager/NetworkManager.h> #include <QtDBus> #include <QDBusConnection> #include <QDBusError> @@ -147,7 +146,7 @@ QString QNetworkManagerEngine::getInterfaceFromId(const QString &id) continue; QNetworkManagerInterfaceDevice device(devices.at(0).path()); - return device.interface().name(); + return device.networkInterface().name(); } } diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp index 5dc0ea4..c780fbc 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.cpp @@ -41,26 +41,22 @@ #include <QObject> #include <QList> -#include <QtDBus> -#include <QDBusConnection> -#include <QDBusError> -#include <QDBusInterface> -#include <QDBusMessage> -#include <QDBusReply> -#include <QDBusPendingCallWatcher> -#include <QDBusObjectPath> -#include <QDBusPendingCall> - -#include <NetworkManager/NetworkManager.h> +#include <QtDBus/QtDBus> +#include <QtDBus/QDBusConnection> +#include <QtDBus/QDBusError> +#include <QtDBus/QDBusInterface> +#include <QtDBus/QDBusMessage> +#include <QtDBus/QDBusReply> +#include <QtDBus/QDBusPendingCallWatcher> +#include <QtDBus/QDBusObjectPath> +#include <QtDBus/QDBusPendingCall> -#include "qnmdbushelper.h" #include "qnetworkmanagerservice.h" +#include "qnmdbushelper.h" -//Q_DECLARE_METATYPE(QList<uint>) QT_BEGIN_NAMESPACE static QDBusConnection dbusConnection = QDBusConnection::systemBus(); -//static QDBusInterface iface(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, dbusConnection); class QNetworkManagerInterfacePrivate { @@ -70,19 +66,19 @@ public: }; QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) - : QObject(parent), nmDBusHelper(0) + : QObject(parent) { d = new QNetworkManagerInterfacePrivate(); - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String(NM_DBUS_INTERFACE), dbusConnection); if (!d->connectionInterface->isValid()) { d->valid = false; return; } d->valid = true; - nmDBusHelper = new QNmDBusHelper; + nmDBusHelper = new QNmDBusHelper(this); connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), @@ -92,8 +88,6 @@ QNetworkManagerInterface::QNetworkManagerInterface(QObject *parent) QNetworkManagerInterface::~QNetworkManagerInterface() { - if (nmDBusHelper) - delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -108,24 +102,24 @@ bool QNetworkManagerInterface::setConnections() if(!isValid() ) return false; bool allOk = false; - if (!dbusConnection.connect(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - "PropertiesChanged", + if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String(NM_DBUS_INTERFACE), + QLatin1String("PropertiesChanged"), nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>)))) { allOk = true; } - if (!dbusConnection.connect(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - "DeviceAdded", + if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String(NM_DBUS_INTERFACE), + QLatin1String("DeviceAdded"), this,SIGNAL(deviceAdded(QDBusObjectPath)))) { allOk = true; } - if (!dbusConnection.connect(NM_DBUS_SERVICE, - NM_DBUS_PATH, - NM_DBUS_INTERFACE, - "DeviceRemoved", + if (!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), + QLatin1String(NM_DBUS_PATH), + QLatin1String(NM_DBUS_INTERFACE), + QLatin1String("DeviceRemoved"), this,SIGNAL(deviceRemoved(QDBusObjectPath)))) { allOk = true; } @@ -140,7 +134,7 @@ QDBusInterface *QNetworkManagerInterface::connectionInterface() const QList <QDBusObjectPath> QNetworkManagerInterface::getDevices() const { - QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call("GetDevices"); + QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetDevices")); return reply.value(); } @@ -149,7 +143,7 @@ void QNetworkManagerInterface::activateConnection( const QString &serviceName, QDBusObjectPath devicePath, QDBusObjectPath specificObject) { - QDBusPendingCall pendingCall = d->connectionInterface->asyncCall("ActivateConnection", + QDBusPendingCall pendingCall = d->connectionInterface->asyncCall(QLatin1String("ActivateConnection"), QVariant(serviceName), QVariant::fromValue(connectionPath), QVariant::fromValue(devicePath), @@ -162,7 +156,7 @@ void QNetworkManagerInterface::activateConnection( const QString &serviceName, void QNetworkManagerInterface::deactivateConnection(QDBusObjectPath connectionPath) const { - d->connectionInterface->call("DeactivateConnection", QVariant::fromValue(connectionPath)); + d->connectionInterface->call(QLatin1String("DeactivateConnection"), QVariant::fromValue(connectionPath)); } bool QNetworkManagerInterface::wirelessEnabled() const @@ -186,7 +180,6 @@ quint32 QNetworkManagerInterface::state() return d->connectionInterface->property("State").toUInt(); } -///////////// class QNetworkManagerInterfaceAccessPointPrivate { public: @@ -200,9 +193,9 @@ QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const Q { d = new QNetworkManagerInterfaceAccessPointPrivate(); d->path = dbusPathName; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_ACCESS_POINT, + QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), dbusConnection); if (!d->connectionInterface->isValid()) { d->valid = false; @@ -215,8 +208,6 @@ QNetworkManagerInterfaceAccessPoint::QNetworkManagerInterfaceAccessPoint(const Q QNetworkManagerInterfaceAccessPoint::~QNetworkManagerInterfaceAccessPoint() { - if (nmDBusHelper) - delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -232,17 +223,15 @@ bool QNetworkManagerInterfaceAccessPoint::setConnections() return false; bool allOk = false; - if (nmDBusHelper) - delete nmDBusHelper; - nmDBusHelper = 0; - nmDBusHelper = new QNmDBusHelper; + delete nmDBusHelper; + nmDBusHelper = new QNmDBusHelper(this); connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); - if(dbusConnection.connect(NM_DBUS_SERVICE, + if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_ACCESS_POINT, - "PropertiesChanged", + QLatin1String(NM_DBUS_INTERFACE_ACCESS_POINT), + QLatin1String("PropertiesChanged"), nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) { allOk = true; @@ -300,7 +289,6 @@ quint32 QNetworkManagerInterfaceAccessPoint::strength() const return d->connectionInterface->property("Strength").toUInt(); } -///////////// class QNetworkManagerInterfaceDevicePrivate { public: @@ -314,9 +302,9 @@ QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &de { d = new QNetworkManagerInterfaceDevicePrivate(); d->path = deviceObjectPath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_DEVICE, + QLatin1String(NM_DBUS_INTERFACE_DEVICE), dbusConnection); if (!d->connectionInterface->isValid()) { d->valid = false; @@ -328,8 +316,6 @@ QNetworkManagerInterfaceDevice::QNetworkManagerInterfaceDevice(const QString &de QNetworkManagerInterfaceDevice::~QNetworkManagerInterfaceDevice() { - if (nmDBusHelper) - delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -345,16 +331,14 @@ bool QNetworkManagerInterfaceDevice::setConnections() return false; bool allOk = false; - if (nmDBusHelper) - delete nmDBusHelper; - nmDBusHelper = 0; - nmDBusHelper = new QNmDBusHelper; + delete nmDBusHelper; + nmDBusHelper = new QNmDBusHelper(this); connect(nmDBusHelper,SIGNAL(pathForStateChanged(const QString &, quint32)), this, SIGNAL(stateChanged(const QString&, quint32))); - if(dbusConnection.connect(NM_DBUS_SERVICE, + if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_DEVICE, - "StateChanged", + QLatin1String(NM_DBUS_INTERFACE_DEVICE), + QLatin1String("StateChanged"), nmDBusHelper,SLOT(deviceStateChanged(quint32)))) { allOk = true; } @@ -371,7 +355,7 @@ QString QNetworkManagerInterfaceDevice::udi() const return d->connectionInterface->property("Udi").toString(); } -QNetworkInterface QNetworkManagerInterfaceDevice::interface() const +QNetworkInterface QNetworkManagerInterfaceDevice::networkInterface() const { return QNetworkInterface::interfaceFromName(d->connectionInterface->property("Interface").toString()); } @@ -397,7 +381,6 @@ QDBusObjectPath QNetworkManagerInterfaceDevice::ip4config() const return prop.value<QDBusObjectPath>(); } -///////////// class QNetworkManagerInterfaceDeviceWiredPrivate { public: @@ -411,9 +394,9 @@ QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const Q { d = new QNetworkManagerInterfaceDeviceWiredPrivate(); d->path = ifaceDevicePath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_DEVICE_WIRED, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; @@ -425,8 +408,6 @@ QNetworkManagerInterfaceDeviceWired::QNetworkManagerInterfaceDeviceWired(const Q QNetworkManagerInterfaceDeviceWired::~QNetworkManagerInterfaceDeviceWired() { - if (nmDBusHelper) - delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -444,16 +425,14 @@ bool QNetworkManagerInterfaceDeviceWired::setConnections() bool allOk = false; - if (nmDBusHelper) - delete nmDBusHelper; - nmDBusHelper = 0; - nmDBusHelper = new QNmDBusHelper; + delete nmDBusHelper; + nmDBusHelper = new QNmDBusHelper(this); connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); - if(dbusConnection.connect(NM_DBUS_SERVICE, + if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_DEVICE_WIRED, - "PropertiesChanged", + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRED), + QLatin1String("PropertiesChanged"), nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) { allOk = true; } @@ -480,7 +459,6 @@ bool QNetworkManagerInterfaceDeviceWired::carrier() const return d->connectionInterface->property("Carrier").toBool(); } -///////////// class QNetworkManagerInterfaceDeviceWirelessPrivate { public: @@ -494,9 +472,9 @@ QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(c { d = new QNetworkManagerInterfaceDeviceWirelessPrivate(); d->path = ifaceDevicePath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; @@ -508,8 +486,6 @@ QNetworkManagerInterfaceDeviceWireless::QNetworkManagerInterfaceDeviceWireless(c QNetworkManagerInterfaceDeviceWireless::~QNetworkManagerInterfaceDeviceWireless() { - if (nmDBusHelper) - delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -525,10 +501,8 @@ bool QNetworkManagerInterfaceDeviceWireless::setConnections() return false; bool allOk = false; - if (nmDBusHelper) - delete nmDBusHelper; - nmDBusHelper = 0; - nmDBusHelper = new QNmDBusHelper; + delete nmDBusHelper; + nmDBusHelper = new QNmDBusHelper(this); connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); @@ -538,28 +512,28 @@ bool QNetworkManagerInterfaceDeviceWireless::setConnections() connect(nmDBusHelper, SIGNAL(pathForAccessPointRemoved(const QString &,QDBusObjectPath)), this,SIGNAL(accessPointRemoved(const QString &,QDBusObjectPath))); - if(!dbusConnection.connect(NM_DBUS_SERVICE, + if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "AccessPointAdded", + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), + QLatin1String("AccessPointAdded"), nmDBusHelper, SLOT(slotAccessPointAdded( QDBusObjectPath )))) { allOk = true; } - if(!dbusConnection.connect(NM_DBUS_SERVICE, + if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "AccessPointRemoved", + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), + QLatin1String("AccessPointRemoved"), nmDBusHelper, SLOT(slotAccessPointRemoved( QDBusObjectPath )))) { allOk = true; } - if(!dbusConnection.connect(NM_DBUS_SERVICE, + if(!dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_DEVICE_WIRELESS, - "PropertiesChanged", + QLatin1String(NM_DBUS_INTERFACE_DEVICE_WIRELESS), + QLatin1String("PropertiesChanged"), nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>)))) { allOk = true; } @@ -574,7 +548,7 @@ QDBusInterface *QNetworkManagerInterfaceDeviceWireless::connectionInterface() co QList <QDBusObjectPath> QNetworkManagerInterfaceDeviceWireless::getAccessPoints() { - QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call("GetAccessPoints"); + QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("GetAccessPoints")); return reply.value(); } @@ -603,7 +577,6 @@ quint32 QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities() const return d->connectionInterface->property("WirelelessCapabilities").toUInt(); } -///////////// class QNetworkManagerSettingsPrivate { public: @@ -618,8 +591,8 @@ QNetworkManagerSettings::QNetworkManagerSettings(const QString &settingsService, d = new QNetworkManagerSettingsPrivate(); d->path = settingsService; d->connectionInterface = new QDBusInterface(settingsService, - NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS, + QLatin1String(NM_DBUS_PATH_SETTINGS), + QLatin1String(NM_DBUS_IFACE_SETTINGS), dbusConnection); if (!d->connectionInterface->isValid()) { d->valid = false; @@ -644,8 +617,8 @@ bool QNetworkManagerSettings::setConnections() { bool allOk = false; - if (!dbusConnection.connect(d->path, NM_DBUS_PATH_SETTINGS, - NM_DBUS_IFACE_SETTINGS, "NewConnection", + if (!dbusConnection.connect(d->path, QLatin1String(NM_DBUS_PATH_SETTINGS), + QLatin1String(NM_DBUS_IFACE_SETTINGS), QLatin1String("NewConnection"), this, SIGNAL(newConnection(QDBusObjectPath)))) { allOk = true; } @@ -655,7 +628,7 @@ bool QNetworkManagerSettings::setConnections() QList <QDBusObjectPath> QNetworkManagerSettings::listConnections() { - QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call("ListConnections"); + QDBusReply<QList<QDBusObjectPath> > reply = d->connectionInterface->call(QLatin1String("ListConnections")); return reply.value(); } @@ -665,7 +638,6 @@ QDBusInterface *QNetworkManagerSettings::connectionInterface() const } -///////////// class QNetworkManagerSettingsConnectionPrivate { public: @@ -685,7 +657,7 @@ QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QStri d->service = settingsService; d->connectionInterface = new QDBusInterface(settingsService, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, + QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), dbusConnection, parent); if (!d->connectionInterface->isValid()) { //qWarning() << "Could not find NetworkManagerSettingsConnection"; @@ -693,14 +665,12 @@ QNetworkManagerSettingsConnection::QNetworkManagerSettingsConnection(const QStri return; } d->valid = true; - QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings")); d->settingsMap = rep.value(); } QNetworkManagerSettingsConnection::~QNetworkManagerSettingsConnection() { - if (nmDBusHelper) - delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -717,32 +687,26 @@ bool QNetworkManagerSettingsConnection::setConnections() bool allOk = false; if(!dbusConnection.connect(d->service, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, "Updated", + QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Updated"), this, SIGNAL(updated(QNmSettingsMap)))) { allOk = true; } else { QDBusError error = dbusConnection.lastError(); } - if (nmDBusHelper) - delete nmDBusHelper; - nmDBusHelper = 0; - nmDBusHelper = new QNmDBusHelper; + delete nmDBusHelper; + nmDBusHelper = new QNmDBusHelper(this); connect(nmDBusHelper, SIGNAL(pathForSettingsRemoved(const QString &)), this,SIGNAL(removed( const QString &))); if (!dbusConnection.connect(d->service, d->path, - NM_DBUS_IFACE_SETTINGS_CONNECTION, "Removed", + QLatin1String(NM_DBUS_IFACE_SETTINGS_CONNECTION), QLatin1String("Removed"), nmDBusHelper, SIGNAL(slotSettingsRemoved()))) { allOk = true; } return allOk; } -//QNetworkManagerSettingsConnection::update(QNmSettingsMap map) -//{ -// d->connectionInterface->call("Update", QVariant::fromValue(map)); -//} QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const { @@ -751,23 +715,23 @@ QDBusInterface *QNetworkManagerSettingsConnection::connectionInterface() const QNmSettingsMap QNetworkManagerSettingsConnection::getSettings() { - QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call("GetSettings"); + QDBusReply< QNmSettingsMap > rep = d->connectionInterface->call(QLatin1String("GetSettings")); d->settingsMap = rep.value(); return d->settingsMap; } NMDeviceType QNetworkManagerSettingsConnection::getType() { - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { QMap<QString,QVariant> innerMap = i.value(); - QMap<QString,QVariant>::const_iterator ii = innerMap.find("type"); - while (ii != innerMap.end() && ii.key() == "type") { + QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("type")); + while (ii != innerMap.end() && ii.key() == QLatin1String("type")) { QString devType = ii.value().toString(); - if (devType == "802-3-ethernet") { + if (devType == QLatin1String("802-3-ethernet")) { return DEVICE_TYPE_802_3_ETHERNET; } - if (devType == "802-11-wireless") { + if (devType == QLatin1String("802-11-wireless")) { return DEVICE_TYPE_802_11_WIRELESS; } ii++; @@ -779,11 +743,11 @@ NMDeviceType QNetworkManagerSettingsConnection::getType() bool QNetworkManagerSettingsConnection::isAutoConnect() { - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { QMap<QString,QVariant> innerMap = i.value(); - QMap<QString,QVariant>::const_iterator ii = innerMap.find("autoconnect"); - while (ii != innerMap.end() && ii.key() == "autoconnect") { + QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("autoconnect")); + while (ii != innerMap.end() && ii.key() == QLatin1String("autoconnect")) { return ii.value().toBool(); ii++; } @@ -794,11 +758,11 @@ bool QNetworkManagerSettingsConnection::isAutoConnect() quint64 QNetworkManagerSettingsConnection::getTimestamp() { - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { QMap<QString,QVariant> innerMap = i.value(); - QMap<QString,QVariant>::const_iterator ii = innerMap.find("timestamp"); - while (ii != innerMap.end() && ii.key() == "timestamp") { + QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("timestamp")); + while (ii != innerMap.end() && ii.key() == QLatin1String("timestamp")) { return ii.value().toUInt(); ii++; } @@ -809,11 +773,11 @@ quint64 QNetworkManagerSettingsConnection::getTimestamp() QString QNetworkManagerSettingsConnection::getId() { - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { QMap<QString,QVariant> innerMap = i.value(); - QMap<QString,QVariant>::const_iterator ii = innerMap.find("id"); - while (ii != innerMap.end() && ii.key() == "id") { + QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("id")); + while (ii != innerMap.end() && ii.key() == QLatin1String("id")) { return ii.value().toString(); ii++; } @@ -824,11 +788,11 @@ QString QNetworkManagerSettingsConnection::getId() QString QNetworkManagerSettingsConnection::getUuid() { - QNmSettingsMap::const_iterator i = d->settingsMap.find("connection"); - while (i != d->settingsMap.end() && i.key() == "connection") { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("connection")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("connection")) { QMap<QString,QVariant> innerMap = i.value(); - QMap<QString,QVariant>::const_iterator ii = innerMap.find("uuid"); - while (ii != innerMap.end() && ii.key() == "uuid") { + QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("uuid")); + while (ii != innerMap.end() && ii.key() == QLatin1String("uuid")) { return ii.value().toString(); ii++; } @@ -840,11 +804,11 @@ QString QNetworkManagerSettingsConnection::getUuid() QString QNetworkManagerSettingsConnection::getSsid() { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); - while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-11-wireless")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("802-11-wireless")) { QMap<QString,QVariant> innerMap = i.value(); - QMap<QString,QVariant>::const_iterator ii = innerMap.find("ssid"); - while (ii != innerMap.end() && ii.key() == "ssid") { + QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("ssid")); + while (ii != innerMap.end() && ii.key() == QLatin1String("ssid")) { return ii.value().toString(); ii++; } @@ -856,11 +820,11 @@ QString QNetworkManagerSettingsConnection::getSsid() QString QNetworkManagerSettingsConnection::getMacAddress() { if(getType() == DEVICE_TYPE_802_3_ETHERNET) { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-3-ethernet"); - while (i != d->settingsMap.end() && i.key() == "802-3-ethernet") { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-3-ethernet")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("802-3-ethernet")) { QMap<QString,QVariant> innerMap = i.value(); - QMap<QString,QVariant>::const_iterator ii = innerMap.find("mac-address"); - while (ii != innerMap.end() && ii.key() == "mac-address") { + QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("mac-address")); + while (ii != innerMap.end() && ii.key() == QLatin1String("mac-address")) { return ii.value().toString(); ii++; } @@ -869,11 +833,11 @@ QString QNetworkManagerSettingsConnection::getMacAddress() } else if(getType() == DEVICE_TYPE_802_11_WIRELESS) { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); - while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-11-wireless")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("802-11-wireless")) { QMap<QString,QVariant> innerMap = i.value(); - QMap<QString,QVariant>::const_iterator ii = innerMap.find("mac-address"); - while (ii != innerMap.end() && ii.key() == "mac-address") { + QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("mac-address")); + while (ii != innerMap.end() && ii.key() == QLatin1String("mac-address")) { return ii.value().toString(); ii++; } @@ -886,11 +850,11 @@ QString QNetworkManagerSettingsConnection::getMacAddress() QStringList QNetworkManagerSettingsConnection::getSeenBssids() { if(getType() == DEVICE_TYPE_802_11_WIRELESS) { - QNmSettingsMap::const_iterator i = d->settingsMap.find("802-11-wireless"); - while (i != d->settingsMap.end() && i.key() == "802-11-wireless") { + QNmSettingsMap::const_iterator i = d->settingsMap.find(QLatin1String("802-11-wireless")); + while (i != d->settingsMap.end() && i.key() == QLatin1String("802-11-wireless")) { QMap<QString,QVariant> innerMap = i.value(); - QMap<QString,QVariant>::const_iterator ii = innerMap.find("seen-bssids"); - while (ii != innerMap.end() && ii.key() == "seen-bssids") { + QMap<QString,QVariant>::const_iterator ii = innerMap.find(QLatin1String("seen-bssids")); + while (ii != innerMap.end() && ii.key() == QLatin1String("seen-bssids")) { return ii.value().toStringList(); ii++; } @@ -900,7 +864,6 @@ QStringList QNetworkManagerSettingsConnection::getSeenBssids() return QStringList(); } -///////////// class QNetworkManagerConnectionActivePrivate { public: @@ -914,9 +877,9 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString { d = new QNetworkManagerConnectionActivePrivate(); d->path = activeConnectionObjectPath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_ACTIVE_CONNECTION, + QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; @@ -928,8 +891,6 @@ QNetworkManagerConnectionActive::QNetworkManagerConnectionActive( const QString QNetworkManagerConnectionActive::~QNetworkManagerConnectionActive() { - if (nmDBusHelper) - delete nmDBusHelper; delete d->connectionInterface; delete d; } @@ -945,16 +906,14 @@ bool QNetworkManagerConnectionActive::setConnections() return false; bool allOk = false; - if (nmDBusHelper) - delete nmDBusHelper; - nmDBusHelper = 0; - nmDBusHelper = new QNmDBusHelper; + delete nmDBusHelper; + nmDBusHelper = new QNmDBusHelper(this); connect(nmDBusHelper, SIGNAL(pathForPropertiesChanged(const QString &,QMap<QString,QVariant>)), this,SIGNAL(propertiesChanged( const QString &, QMap<QString,QVariant>))); - if(dbusConnection.connect(NM_DBUS_SERVICE, + if(dbusConnection.connect(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_ACTIVE_CONNECTION, - "PropertiesChanged", + QLatin1String(NM_DBUS_INTERFACE_ACTIVE_CONNECTION), + QLatin1String("PropertiesChanged"), nmDBusHelper,SLOT(slotPropertiesChanged( QMap<QString,QVariant>))) ) { allOk = true; } @@ -1000,8 +959,6 @@ bool QNetworkManagerConnectionActive::defaultRoute() const return d->connectionInterface->property("Default").toBool(); } - -//// class QNetworkManagerIp4ConfigPrivate { public: @@ -1015,9 +972,9 @@ QNetworkManagerIp4Config::QNetworkManagerIp4Config( const QString &deviceObjectP { d = new QNetworkManagerIp4ConfigPrivate(); d->path = deviceObjectPath; - d->connectionInterface = new QDBusInterface(NM_DBUS_SERVICE, + d->connectionInterface = new QDBusInterface(QLatin1String(NM_DBUS_SERVICE), d->path, - NM_DBUS_INTERFACE_IP4_CONFIG, + QLatin1String(NM_DBUS_INTERFACE_IP4_CONFIG), dbusConnection, parent); if (!d->connectionInterface->isValid()) { d->valid = false; diff --git a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h index 81903ec..048f628 100644 --- a/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h +++ b/src/plugins/bearer/networkmanager/qnetworkmanagerservice.h @@ -53,26 +53,87 @@ // We mean it. // -#include <NetworkManager/NetworkManager.h> -#include <QtDBus> -#include <QDBusConnection> -#include <QDBusError> -#include <QDBusInterface> -#include <QDBusMessage> -#include <QDBusReply> +#include <QtDBus/QtDBus> +#include <QtDBus/QDBusConnection> +#include <QtDBus/QDBusError> +#include <QtDBus/QDBusInterface> +#include <QtDBus/QDBusMessage> +#include <QtDBus/QDBusReply> #include <QNetworkInterface> -#include <QDBusPendingCallWatcher> +#include <QtDBus/QDBusPendingCallWatcher> +#include <QtDBus/QDBusObjectPath> +#include <QtDBus/QDBusContext> +#include <QMap> #include "qnmdbushelper.h" +#ifndef NETWORK_MANAGER_H +typedef enum NMDeviceType +{ + DEVICE_TYPE_UNKNOWN = 0, + DEVICE_TYPE_802_3_ETHERNET, + DEVICE_TYPE_802_11_WIRELESS, + DEVICE_TYPE_GSM, + DEVICE_TYPE_CDMA +} NMDeviceType; + +typedef enum +{ + NM_DEVICE_STATE_UNKNOWN = 0, + NM_DEVICE_STATE_UNMANAGED, + NM_DEVICE_STATE_UNAVAILABLE, + NM_DEVICE_STATE_DISCONNECTED, + NM_DEVICE_STATE_PREPARE, + NM_DEVICE_STATE_CONFIG, + NM_DEVICE_STATE_NEED_AUTH, + NM_DEVICE_STATE_IP_CONFIG, + NM_DEVICE_STATE_ACTIVATED, + NM_DEVICE_STATE_FAILED +} NMDeviceState; + +typedef enum +{ + NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0, + NM_ACTIVE_CONNECTION_STATE_ACTIVATING, + NM_ACTIVE_CONNECTION_STATE_ACTIVATED +} NMActiveConnectionState; + +#define NM_DBUS_SERVICE "org.freedesktop.NetworkManager" + +#define NM_DBUS_PATH "/org/freedesktop/NetworkManager" +#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager" +#define NM_DBUS_INTERFACE_DEVICE NM_DBUS_INTERFACE ".Device" +#define NM_DBUS_INTERFACE_DEVICE_WIRED NM_DBUS_INTERFACE_DEVICE ".Wired" +#define NM_DBUS_INTERFACE_DEVICE_WIRELESS NM_DBUS_INTERFACE_DEVICE ".Wireless" +#define NM_DBUS_PATH_ACCESS_POINT NM_DBUS_PATH "/AccessPoint" +#define NM_DBUS_INTERFACE_ACCESS_POINT NM_DBUS_INTERFACE ".AccessPoint" + +#define NM_DBUS_PATH_SETTINGS "/org/freedesktop/NetworkManagerSettings" + +#define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManagerSettings.Connection" +#define NM_DBUS_IFACE_SETTINGS "org.freedesktop.NetworkManagerSettings" +#define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active" +#define NM_DBUS_INTERFACE_IP4_CONFIG NM_DBUS_INTERFACE ".IP4Config" + +#define NM_DBUS_SERVICE_USER_SETTINGS "org.freedesktop.NetworkManagerUserSettings" +#define NM_DBUS_SERVICE_SYSTEM_SETTINGS "org.freedesktop.NetworkManagerSystemSettings" + +#define NM_802_11_AP_FLAGS_NONE 0x00000000 +#define NM_802_11_AP_FLAGS_PRIVACY 0x00000001 +#endif + QT_BEGIN_NAMESPACE typedef QMap< QString, QMap<QString,QVariant> > QNmSettingsMap; typedef QList<quint32> ServerThing; -Q_DECLARE_METATYPE(QNmSettingsMap) -Q_DECLARE_METATYPE(ServerThing) +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QNmSettingsMap)) +Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(ServerThing)) + +QT_BEGIN_NAMESPACE class QNetworkManagerInterfacePrivate; class QNetworkManagerInterface : public QObject @@ -107,12 +168,10 @@ Q_SIGNALS: private Q_SLOTS: private: -// Q_DISABLE_COPY(QNetworkManagerInterface); ?? QNetworkManagerInterfacePrivate *d; QNmDBusHelper *nmDBusHelper; -}; //end QNetworkManagerInterface +}; -//////// class QNetworkManagerInterfaceAccessPointPrivate; class QNetworkManagerInterfaceAccessPoint : public QObject { @@ -120,7 +179,6 @@ class QNetworkManagerInterfaceAccessPoint : public QObject public: - // NM_DEVICE_STATE enum DeviceState { Unknown = 0, Unmanaged, @@ -181,9 +239,8 @@ private: QNetworkManagerInterfaceAccessPointPrivate *d; QNmDBusHelper *nmDBusHelper; -}; //end QNetworkManagerInterfaceAccessPoint +}; -//////// class QNetworkManagerInterfaceDevicePrivate; class QNetworkManagerInterfaceDevice : public QObject { @@ -195,7 +252,7 @@ public: ~QNetworkManagerInterfaceDevice(); QString udi() const; - QNetworkInterface interface() const; + QNetworkInterface networkInterface() const; QDBusInterface *connectionInterface() const; quint32 ip4Address() const; quint32 state() const; @@ -211,9 +268,8 @@ Q_SIGNALS: private: QNetworkManagerInterfaceDevicePrivate *d; QNmDBusHelper *nmDBusHelper; -}; //end QNetworkManagerInterfaceDevice +}; -//////// class QNetworkManagerInterfaceDeviceWiredPrivate; class QNetworkManagerInterfaceDeviceWired : public QObject { @@ -236,9 +292,8 @@ Q_SIGNALS: private: QNetworkManagerInterfaceDeviceWiredPrivate *d; QNmDBusHelper *nmDBusHelper; -}; // end QNetworkManagerInterfaceDeviceWired +}; -//// class QNetworkManagerInterfaceDeviceWirelessPrivate; class QNetworkManagerInterfaceDeviceWireless : public QObject { @@ -278,9 +333,8 @@ Q_SIGNALS: private: QNetworkManagerInterfaceDeviceWirelessPrivate *d; QNmDBusHelper *nmDBusHelper; -}; // end QNetworkManagerInterfaceDeviceWireless +}; -//// class QNetworkManagerSettingsPrivate; class QNetworkManagerSettings : public QObject { @@ -300,9 +354,8 @@ Q_SIGNALS: void newConnection(QDBusObjectPath); private: QNetworkManagerSettingsPrivate *d; -}; //end QNetworkManagerSettings +}; -//// class QNetworkManagerSettingsConnectionPrivate; class QNetworkManagerSettingsConnection : public QObject { @@ -315,7 +368,6 @@ public: QDBusInterface *connectionInterface() const; QNmSettingsMap getSettings(); - // void update(QNmSettingsMap map); bool setConnections(); NMDeviceType getType(); bool isAutoConnect(); @@ -335,9 +387,8 @@ Q_SIGNALS: private: QNmDBusHelper *nmDBusHelper; QNetworkManagerSettingsConnectionPrivate *d; -}; //end QNetworkManagerSettingsConnection +}; -//// class QNetworkManagerConnectionActivePrivate; class QNetworkManagerConnectionActive : public QObject { @@ -371,9 +422,8 @@ Q_SIGNALS: private: QNetworkManagerConnectionActivePrivate *d; QNmDBusHelper *nmDBusHelper; -}; //QNetworkManagerConnectionActive +}; -//// class QNetworkManagerIp4ConfigPrivate; class QNetworkManagerIp4Config : public QObject { @@ -383,14 +433,12 @@ public: QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0); ~QNetworkManagerIp4Config(); - // QList<quint32> nameservers(); QStringList domains() const; bool isValid(); private: QNetworkManagerIp4ConfigPrivate *d; }; -//// QT_END_NAMESPACE diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp index d5e20f3..e195eeb 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.cpp +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.cpp @@ -43,7 +43,7 @@ #include "qnmdbushelper.h" -#include <NetworkManager/NetworkManager.h> +#include "qnetworkmanagerservice.h" #include <QDBusError> #include <QDBusInterface> @@ -54,6 +54,15 @@ QT_BEGIN_NAMESPACE +QNmDBusHelper::QNmDBusHelper(QObject * parent) + : QObject(parent) +{ +} + +QNmDBusHelper::~QNmDBusHelper() +{ +} + void QNmDBusHelper::deviceStateChanged(quint32 state) { QDBusMessage msg = this->message(); diff --git a/src/plugins/bearer/networkmanager/qnmdbushelper.h b/src/plugins/bearer/networkmanager/qnmdbushelper.h index 862290c..933d55a 100644 --- a/src/plugins/bearer/networkmanager/qnmdbushelper.h +++ b/src/plugins/bearer/networkmanager/qnmdbushelper.h @@ -52,6 +52,8 @@ class QNmDBusHelper: public QObject, protected QDBusContext { Q_OBJECT public: + QNmDBusHelper(QObject *parent = 0); + ~QNmDBusHelper(); public slots: void deviceStateChanged(quint32); diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index 05ce62f..11585ef 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -147,6 +147,8 @@ void QNetworkSessionPrivateImpl::open() if ((activeConfig.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { lastError =QNetworkSession::InvalidConfigurationError; + state = QNetworkSession::Invalid; + emit stateChanged(state); emit QNetworkSessionPrivate::error(lastError); return; } @@ -400,7 +402,6 @@ void QNetworkSessionPrivateImpl::connectionError(const QString &id, lastError = QNetworkSession::UnknownSessionError; } - emit quitPendingWaitsForOpened(); emit QNetworkSessionPrivate::error(lastError); } } diff --git a/src/plugins/bearer/symbian/qnetworksession_impl.cpp b/src/plugins/bearer/symbian/qnetworksession_impl.cpp index 9af1fe9..bec562d 100644 --- a/src/plugins/bearer/symbian/qnetworksession_impl.cpp +++ b/src/plugins/bearer/symbian/qnetworksession_impl.cpp @@ -141,7 +141,10 @@ void QNetworkSessionPrivateImpl::syncStateWithInterface() if (state != QNetworkSession::Connected) { // There were no open connections to used IAP or SNAP - if ((privateConfiguration(publicConfig)->state & QNetworkConfiguration::Discovered) == + if (iError == QNetworkSession::InvalidConfigurationError) { + newState(QNetworkSession::Invalid); + } + else if ((privateConfiguration(publicConfig)->state & QNetworkConfiguration::Discovered) == QNetworkConfiguration::Discovered) { newState(QNetworkSession::Disconnected); } else { @@ -231,13 +234,23 @@ QNetworkSession::SessionError QNetworkSessionPrivateImpl::error() const void QNetworkSessionPrivateImpl::open() { - if (isOpen || !privateConfiguration(publicConfig) || (state == QNetworkSession::Connecting)) { + if (isOpen || (state == QNetworkSession::Connecting)) { return; } // Cancel notifications from RConnectionMonitor // => RConnection::ProgressNotification will be used for IAP/SNAP monitoring iConnectionMonitor.CancelNotifications(); + + // Configuration must be at least in Discovered - state for connecting purposes. + if ((publicConfig.state() & QNetworkConfiguration::Discovered) != + QNetworkConfiguration::Discovered) { + newState(QNetworkSession::Invalid); + iError = QNetworkSession::InvalidConfigurationError; + emit QNetworkSessionPrivate::error(iError); + syncStateWithInterface(); + return; + } TInt error = iSocketServ.Connect(); if (error != KErrNone) { diff --git a/src/plugins/bearer/symbian/symbianengine.cpp b/src/plugins/bearer/symbian/symbianengine.cpp index b3c9cb3..88a563c 100644 --- a/src/plugins/bearer/symbian/symbianengine.cpp +++ b/src/plugins/bearer/symbian/symbianengine.cpp @@ -98,7 +98,7 @@ QString SymbianNetworkConfigurationPrivate::bearerName() const } SymbianEngine::SymbianEngine(QObject *parent) -: QBearerEngine(parent), CActive(CActive::EPriorityIdle), iInitOk(true) +: QBearerEngine(parent), CActive(CActive::EPriorityIdle), iFirstUpdate(true), iInitOk(true) { CActiveScheduler::Add(this); @@ -136,9 +136,12 @@ SymbianEngine::SymbianEngine(QObject *parent) updateConfigurations(); updateStatesToSnaps(); + + updateAvailableAccessPoints(); // On first time updates synchronously (without WLAN scans) // Start monitoring IAP and/or SNAP changes in Symbian CommsDB startCommsDatabaseNotifications(); + iFirstUpdate = false; } SymbianEngine::~SymbianEngine() @@ -153,7 +156,14 @@ SymbianEngine::~SymbianEngine() #endif delete ipAccessPointsAvailabilityScanner; + + // CCommsDatabase destructor uses cleanup stack. Since QNetworkConfigurationManager + // is a global static, but the time we are here, E32Main() has been exited already and + // the thread's default cleanup stack has been deleted. Without this line, a + // 'E32USER-CBase 69' -panic will occur. + CTrapCleanup* cleanup = CTrapCleanup::New(); delete ipCommsDB; + delete cleanup; } bool SymbianEngine::hasIdentifier(const QString &id) @@ -692,9 +702,10 @@ void SymbianEngine::accessPointScanningReady(TBool scanSuccessful, TConnMonIapIn updateStatesToSnaps(); - startCommsDatabaseNotifications(); - - emit updateCompleted(); + if (!iFirstUpdate) { + startCommsDatabaseNotifications(); + emit updateCompleted(); + } } void SymbianEngine::updateStatesToSnaps() @@ -987,11 +998,22 @@ void AccessPointsAvailabilityScanner::DoCancel() void AccessPointsAvailabilityScanner::StartScanning() { - iConnectionMonitor.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iIapBuf, iStatus); - if (!IsActive()) { - SetActive(); + if (iOwner.iFirstUpdate) { + // On first update (the mgr is being instantiated) update only those bearers who + // don't need time-consuming scans (WLAN). + // Note: EBearerIdWCDMA covers also GPRS bearer + iConnectionMonitor.GetPckgAttribute(EBearerIdWCDMA, 0, KIapAvailability, iIapBuf, iStatus); + User::WaitForRequest(iStatus); + if (iStatus.Int() == KErrNone) { + iOwner.accessPointScanningReady(true,iIapBuf()); + } + } else { + iConnectionMonitor.GetPckgAttribute(EBearerIdAll, 0, KIapAvailability, iIapBuf, iStatus); + if (!IsActive()) { + SetActive(); + } } -} +} void AccessPointsAvailabilityScanner::RunL() { diff --git a/src/plugins/bearer/symbian/symbianengine.h b/src/plugins/bearer/symbian/symbianengine.h index 5448813..ee6d070 100644 --- a/src/plugins/bearer/symbian/symbianengine.h +++ b/src/plugins/bearer/symbian/symbianengine.h @@ -162,6 +162,7 @@ private: // MConnectionMonitorObserver void EventL(const CConnMonEventBase& aEvent); private: // Data + bool iFirstUpdate; CCommsDatabase* ipCommsDB; RConnectionMonitor iConnectionMonitor; diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp index 2d7aaa8..e646693 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp @@ -59,6 +59,9 @@ QT_BEGIN_NAMESPACE QGstreamerPlayerControl::QGstreamerPlayerControl(QGstreamerPlayerSession *session, QObject *parent) : QMediaPlayerControl(parent) , m_session(session) + , m_state(QMediaPlayer::StoppedState) + , m_mediaStatus(QMediaPlayer::NoMedia) + , m_bufferProgress(-1) , m_stream(0) , m_fifoNotifier(0) , m_fifoCanWrite(false) @@ -77,11 +80,11 @@ QGstreamerPlayerControl::QGstreamerPlayerControl(QGstreamerPlayerSession *sessio connect(m_session, SIGNAL(volumeChanged(int)), this, SIGNAL(volumeChanged(int))); connect(m_session, SIGNAL(stateChanged(QMediaPlayer::State)), - this, SIGNAL(stateChanged(QMediaPlayer::State))); - connect(m_session, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), - this, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); + this, SLOT(updateState(QMediaPlayer::State))); connect(m_session,SIGNAL(bufferingProgressChanged(int)), - this, SIGNAL(bufferStatusChanged(int))); + this, SLOT(setBufferProgress(int))); + connect(m_session, SIGNAL(playbackFinished()), + this, SLOT(processEOS())); connect(m_session, SIGNAL(audioAvailableChanged(bool)), this, SIGNAL(audioAvailableChanged(bool))); connect(m_session, SIGNAL(videoAvailableChanged(bool)), @@ -114,17 +117,20 @@ qint64 QGstreamerPlayerControl::duration() const QMediaPlayer::State QGstreamerPlayerControl::state() const { - return m_session->state(); + return m_state; } QMediaPlayer::MediaStatus QGstreamerPlayerControl::mediaStatus() const { - return m_session->mediaStatus(); + return m_mediaStatus; } int QGstreamerPlayerControl::bufferStatus() const { - return 100; + if (m_bufferProgress == -1) { + return m_session->state() == QMediaPlayer::StoppedState ? 0 : 100; + } else + return m_bufferProgress; } int QGstreamerPlayerControl::volume() const @@ -169,23 +175,33 @@ void QGstreamerPlayerControl::setPosition(qint64 pos) void QGstreamerPlayerControl::play() { - m_session->play(); - - if (m_fifoFd[1] >= 0) { - m_fifoCanWrite = true; - - writeFifo(); + if (m_session->play()) { + if (m_state != QMediaPlayer::PlayingState) + emit stateChanged(m_state = QMediaPlayer::PlayingState); } } void QGstreamerPlayerControl::pause() { - m_session->pause(); + if (m_session->pause()) { + if (m_state != QMediaPlayer::PausedState) + emit stateChanged(m_state = QMediaPlayer::PausedState); + } } void QGstreamerPlayerControl::stop() { - m_session->stop(); + if (m_state != QMediaPlayer::StoppedState) { + m_session->pause(); + if (!m_session->seek(0)) { + m_bufferProgress = -1; + m_session->stop(); + m_session->pause(); + } + emit positionChanged(0); + if (m_state != QMediaPlayer::StoppedState) + emit stateChanged(m_state = QMediaPlayer::StoppedState); + } } void QGstreamerPlayerControl::setVolume(int volume) @@ -210,8 +226,15 @@ const QIODevice *QGstreamerPlayerControl::mediaStream() const void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream) { + QMediaPlayer::State oldState = m_state; + m_state = QMediaPlayer::StoppedState; m_session->stop(); + if (m_bufferProgress != -1) { + m_bufferProgress = -1; + emit bufferStatusChanged(0); + } + if (m_stream) { closeFifo(); @@ -234,7 +257,25 @@ void QGstreamerPlayerControl::setMedia(const QMediaContent &content, QIODevice * m_session->load(url); + if (m_fifoFd[1] >= 0) { + m_fifoCanWrite = true; + + writeFifo(); + } + + if (!url.isEmpty()) { + if (m_mediaStatus != QMediaPlayer::LoadingMedia) + emit mediaStatusChanged(m_mediaStatus = QMediaPlayer::LoadingMedia); + m_session->pause(); + } else { + if (m_mediaStatus != QMediaPlayer::NoMedia) + emit mediaStatusChanged(m_mediaStatus = QMediaPlayer::NoMedia); + setBufferProgress(0); + } + emit mediaChanged(m_currentResource); + if (m_state != oldState) + emit stateChanged(m_state); } void QGstreamerPlayerControl::setVideoOutput(QObject *output) @@ -252,6 +293,68 @@ bool QGstreamerPlayerControl::isVideoAvailable() const return m_session->isVideoAvailable(); } +void QGstreamerPlayerControl::updateState(QMediaPlayer::State state) +{ + QMediaPlayer::MediaStatus oldStatus = m_mediaStatus; + + switch (state) { + case QMediaPlayer::StoppedState: + if (m_state != QMediaPlayer::StoppedState) + emit stateChanged(m_state = QMediaPlayer::StoppedState); + break; + + case QMediaPlayer::PlayingState: + case QMediaPlayer::PausedState: + if (m_state == QMediaPlayer::StoppedState) + m_mediaStatus = QMediaPlayer::LoadedMedia; + else { + if (m_bufferProgress == -1) + m_mediaStatus = QMediaPlayer::BufferedMedia; + } + break; + } + + if (m_mediaStatus != oldStatus) + emit mediaStatusChanged(m_mediaStatus); +} + +void QGstreamerPlayerControl::processEOS() +{ + m_mediaStatus = QMediaPlayer::EndOfMedia; + m_state = QMediaPlayer::StoppedState; + + emit stateChanged(m_state); + emit mediaStatusChanged(m_mediaStatus); +} + +void QGstreamerPlayerControl::setBufferProgress(int progress) +{ + if (m_bufferProgress == progress || m_mediaStatus == QMediaPlayer::NoMedia) + return; + + QMediaPlayer::MediaStatus oldStatus = m_mediaStatus; + + m_bufferProgress = progress; + + if (m_state == QMediaPlayer::StoppedState) { + m_mediaStatus = QMediaPlayer::LoadedMedia; + } else { + if (m_bufferProgress < 100) { + m_mediaStatus = QMediaPlayer::StalledMedia; + m_session->pause(); + } else { + m_mediaStatus = QMediaPlayer::BufferedMedia; + if (m_state == QMediaPlayer::PlayingState) + m_session->play(); + } + } + + if (m_mediaStatus != oldStatus) + emit mediaStatusChanged(m_mediaStatus); + + emit bufferStatusChanged(m_bufferProgress); +} + void QGstreamerPlayerControl::writeFifo() { if (m_fifoCanWrite) { diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h index ae0f8b6..0c53945 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayercontrol.h @@ -107,11 +107,18 @@ private Q_SLOTS: void writeFifo(); void fifoReadyWrite(int socket); + void updateState(QMediaPlayer::State); + void processEOS(); + void setBufferProgress(int progress); + private: bool openFifo(); void closeFifo(); QGstreamerPlayerSession *m_session; + QMediaPlayer::State m_state; + QMediaPlayer::MediaStatus m_mediaStatus; + int m_bufferProgress; QMediaContent m_currentResource; QIODevice *m_stream; QSocketNotifier *m_fifoNotifier; diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp index 600621e..392a7a8 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.cpp @@ -57,7 +57,6 @@ QT_BEGIN_NAMESPACE QGstreamerPlayerSession::QGstreamerPlayerSession(QObject *parent) :QObject(parent), m_state(QMediaPlayer::StoppedState), - m_mediaStatus(QMediaPlayer::UnknownMediaStatus), m_busHelper(0), m_playbin(0), m_nullVideoOutput(0), @@ -92,6 +91,7 @@ QGstreamerPlayerSession::QGstreamerPlayerSession(QObject *parent) m_busHelper->installSyncEventFilter(this); m_nullVideoOutput = gst_element_factory_make("fakesink", NULL); + gst_object_ref(GST_OBJECT(m_nullVideoOutput)); g_object_set(G_OBJECT(m_playbin), "video-sink", m_nullVideoOutput, NULL); // Initial volume @@ -109,12 +109,14 @@ QGstreamerPlayerSession::~QGstreamerPlayerSession() delete m_busHelper; gst_object_unref(GST_OBJECT(m_bus)); gst_object_unref(GST_OBJECT(m_playbin)); + gst_object_unref(GST_OBJECT(m_nullVideoOutput)); } } void QGstreamerPlayerSession::load(const QUrl &url) { m_url = url; + if (m_playbin) { m_tags.clear(); emit tagsChanged(); @@ -259,26 +261,36 @@ bool QGstreamerPlayerSession::isSeekable() const return m_seekable; } -void QGstreamerPlayerSession::play() +bool QGstreamerPlayerSession::play() { if (m_playbin) { if (gst_element_set_state(m_playbin, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) { qWarning() << "GStreamer; Unable to play -" << m_url.toString(); - m_state = QMediaPlayer::StoppedState; - m_mediaStatus = QMediaPlayer::InvalidMedia; + m_state = QMediaPlayer::StoppedState; emit stateChanged(m_state); - emit mediaStatusChanged(m_mediaStatus); - emit error(int(QMediaPlayer::ResourceError), tr("Unable to play %1").arg(m_url.path())); - } + } else + return true; } + + return false; } -void QGstreamerPlayerSession::pause() +bool QGstreamerPlayerSession::pause() { - if (m_playbin) - gst_element_set_state(m_playbin, GST_STATE_PAUSED); + if (m_playbin) { + if (gst_element_set_state(m_playbin, GST_STATE_PAUSED) == GST_STATE_CHANGE_FAILURE) { + qWarning() << "GStreamer; Unable to play -" << m_url.toString(); + m_state = QMediaPlayer::StoppedState; + + emit stateChanged(m_state); + emit error(int(QMediaPlayer::ResourceError), tr("Unable to play %1").arg(m_url.path())); + } else + return true; + } + + return false; } void QGstreamerPlayerSession::stop() @@ -292,31 +304,45 @@ void QGstreamerPlayerSession::stop() } } -void QGstreamerPlayerSession::seek(qint64 ms) +bool QGstreamerPlayerSession::seek(qint64 ms) { if (m_playbin && m_state != QMediaPlayer::StoppedState) { gint64 position = (gint64)ms * 1000000; - gst_element_seek_simple(m_playbin, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, position); + return gst_element_seek_simple(m_playbin, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, position); } + + return false; } void QGstreamerPlayerSession::setVolume(int volume) { - m_volume = volume; - emit volumeChanged(m_volume); + if (m_volume != volume) { + m_volume = volume; - if (!m_muted && m_playbin) - g_object_set(G_OBJECT(m_playbin), "volume", m_volume/100.0, NULL); + if (m_playbin) { +#ifndef USE_PLAYBIN2 + if(!m_muted) +#endif + g_object_set(G_OBJECT(m_playbin), "volume", m_volume/100.0, NULL); + } + + emit volumeChanged(m_volume); + } } void QGstreamerPlayerSession::setMuted(bool muted) { - m_muted = muted; - - g_object_set(G_OBJECT(m_playbin), "volume", (m_muted ? 0 : m_volume/100.0), NULL); + if (m_muted != muted) { + m_muted = muted; - emit mutedStateChanged(m_muted); +#ifdef USE_PLAYBIN2 + g_object_set(G_OBJECT(m_playbin), "mute", m_muted, NULL); +#else + g_object_set(G_OBJECT(m_playbin), "volume", (m_muted ? 0 : m_volume/100.0), NULL); +#endif + emit mutedStateChanged(m_muted); + } } static void addTagToMap(const GstTagList *list, @@ -388,14 +414,6 @@ void QGstreamerPlayerSession::setSeekable(bool seekable) } } -void QGstreamerPlayerSession::setMediaStatus(QMediaPlayer::MediaStatus status) -{ - if (m_mediaStatus != status) { - m_mediaStatus = status; - emit mediaStatusChanged(status); - } -} - bool QGstreamerPlayerSession::processSyncMessage(const QGstreamerMessage &message) { GstMessage* gm = message.rawMessage(); @@ -440,9 +458,6 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) if (GST_MESSAGE_SRC(gm) == GST_OBJECT_CAST(m_playbin)) { switch (GST_MESSAGE_TYPE(gm)) { - case GST_MESSAGE_DURATION: - break; - case GST_MESSAGE_STATE_CHANGED: { GstState oldState; @@ -462,24 +477,19 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) switch (newState) { case GST_STATE_VOID_PENDING: case GST_STATE_NULL: - setMediaStatus(QMediaPlayer::UnknownMediaStatus); setSeekable(false); if (m_state != QMediaPlayer::StoppedState) emit stateChanged(m_state = QMediaPlayer::StoppedState); break; case GST_STATE_READY: - setMediaStatus(QMediaPlayer::LoadedMedia); setSeekable(false); if (m_state != QMediaPlayer::StoppedState) emit stateChanged(m_state = QMediaPlayer::StoppedState); break; case GST_STATE_PAUSED: - //don't emit state changes for intermediate states - if (m_state != QMediaPlayer::PausedState && pending == GST_STATE_VOID_PENDING) + if (m_state != QMediaPlayer::PausedState) emit stateChanged(m_state = QMediaPlayer::PausedState); - setMediaStatus(QMediaPlayer::LoadedMedia); - //check for seekable if (oldState == GST_STATE_READY) { /* @@ -513,17 +523,13 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) if (m_state != QMediaPlayer::PlayingState) emit stateChanged(m_state = QMediaPlayer::PlayingState); + break; } } break; case GST_MESSAGE_EOS: - if (m_state != QMediaPlayer::StoppedState) - emit stateChanged(m_state = QMediaPlayer::StoppedState); - - setMediaStatus(QMediaPlayer::EndOfMedia); - emit playbackFinished(); break; @@ -546,7 +552,11 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) case GST_MESSAGE_INFO: break; case GST_MESSAGE_BUFFERING: - setMediaStatus(QMediaPlayer::BufferingMedia); + { + int progress = 0; + gst_message_parse_buffering(gm, &progress); + emit bufferingProgressChanged(progress); + } break; case GST_MESSAGE_STATE_DIRTY: case GST_MESSAGE_STEP_DONE: @@ -556,8 +566,32 @@ void QGstreamerPlayerSession::busMessage(const QGstreamerMessage &message) case GST_MESSAGE_STRUCTURE_CHANGE: case GST_MESSAGE_APPLICATION: case GST_MESSAGE_ELEMENT: + break; case GST_MESSAGE_SEGMENT_START: + { + const GstStructure *structure = gst_message_get_structure(gm); + qint64 position = g_value_get_int64(gst_structure_get_value(structure, "position")); + position /= 1000000; + m_lastPosition = position; + emit positionChanged(position); + } + break; case GST_MESSAGE_SEGMENT_DONE: + break; + case GST_MESSAGE_DURATION: + { + GstFormat format = GST_FORMAT_TIME; + gint64 duration = 0; + + if (gst_element_query_duration(m_playbin, &format, &duration)) { + int newDuration = duration / 1000000; + if (m_duration != newDuration) { + m_duration = newDuration; + emit durationChanged(m_duration); + } + } + } + break; case GST_MESSAGE_LATENCY: #if (GST_VERSION_MAJOR >= 0) && (GST_VERSION_MINOR >= 10) && (GST_VERSION_MICRO >= 13) case GST_MESSAGE_ASYNC_START: @@ -604,7 +638,7 @@ void QGstreamerPlayerSession::getStreamsInfo() haveAudio = audioStreamsCount > 0; haveVideo = videoStreamsCount > 0; - m_playbin2StreamOffset[QMediaStreamsControl::AudioStream] = 0; + /*m_playbin2StreamOffset[QMediaStreamsControl::AudioStream] = 0; m_playbin2StreamOffset[QMediaStreamsControl::VideoStream] = audioStreamsCount; m_playbin2StreamOffset[QMediaStreamsControl::SubPictureStream] = audioStreamsCount+videoStreamsCount; @@ -648,7 +682,9 @@ void QGstreamerPlayerSession::getStreamsInfo() } m_streamProperties.append(streamProperties); + } + */ #else enum { diff --git a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h index d650ec7..edfec5b 100644 --- a/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h +++ b/src/plugins/mediaservices/gstreamer/mediaplayer/qgstreamerplayersession.h @@ -71,7 +71,6 @@ public: QUrl url() const; QMediaPlayer::State state() const { return m_state; } - QMediaPlayer::MediaStatus mediaStatus() const { return m_mediaStatus; } qint64 duration() const; qint64 position() const; @@ -105,11 +104,11 @@ public: public slots: void load(const QUrl &url); - void play(); - void pause(); + bool play(); + bool pause(); void stop(); - void seek(qint64 pos); + bool seek(qint64 pos); void setVolume(int volume); void setMuted(bool muted); @@ -118,7 +117,6 @@ signals: void durationChanged(qint64 duration); void positionChanged(qint64 position); void stateChanged(QMediaPlayer::State state); - void mediaStatusChanged(QMediaPlayer::MediaStatus mediaStatus); void volumeChanged(int volume); void mutedStateChanged(bool muted); void audioAvailableChanged(bool audioAvailable); @@ -137,11 +135,8 @@ private slots: void setSeekable(bool); private: - void setMediaStatus(QMediaPlayer::MediaStatus); - QUrl m_url; QMediaPlayer::State m_state; - QMediaPlayer::MediaStatus m_mediaStatus; QGstreamerBusHelper* m_busHelper; GstElement* m_playbin; GstElement* m_nullVideoOutput; diff --git a/src/plugins/mediaservices/gstreamer/qgstreamermessage.cpp b/src/plugins/mediaservices/gstreamer/qgstreamermessage.cpp index 863b6d4..d52aa75 100644 --- a/src/plugins/mediaservices/gstreamer/qgstreamermessage.cpp +++ b/src/plugins/mediaservices/gstreamer/qgstreamermessage.cpp @@ -50,7 +50,7 @@ static int wuchi = qRegisterMetaType<QGstreamerMessage>(); /*! - \class gstreamer::QGstreamerMessage + \class QGstreamerMessage \internal */ diff --git a/src/plugins/mediaservices/mediaservices.pro b/src/plugins/mediaservices/mediaservices.pro index d84b276..19d678b 100644 --- a/src/plugins/mediaservices/mediaservices.pro +++ b/src/plugins/mediaservices/mediaservices.pro @@ -1,7 +1,7 @@ TEMPLATE = subdirs contains(QT_CONFIG, mediaservice) { - win32:!wince: SUBDIRS += directshow + win32:!wince*: SUBDIRS += directshow mac: SUBDIRS += qt7 diff --git a/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.mm b/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.mm index b046672..59d01a2 100644 --- a/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.mm +++ b/src/plugins/mediaservices/qt7/mediaplayer/qt7playermetadata.mm @@ -251,6 +251,7 @@ void QT7PlayerMetaDataControl::updateTags() readFormattedData(metaDataRef, kQTMetaDataStorageFormatiTunes, metaMap); } #else + AutoReleasePool pool; NSString *name = [movie attributeForKey:@"QTMovieDisplayNameAttribute"]; metaMap.insert(QLatin1String("nam"), QString::fromUtf8([name UTF8String])); #endif // QUICKTIME_C_API_AVAILABLE diff --git a/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp b/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp index 8becbf3..a2e74f4 100644 --- a/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp +++ b/src/plugins/qdeclarativemodules/multimedia/multimedia.cpp @@ -41,17 +41,27 @@ #include <QtDeclarative/qdeclarativeextensionplugin.h> #include <QtDeclarative/qdeclarative.h> -#include <QtMultimedia/multimediadeclarative.h> +#include <QtMultimedia/private/qsoundeffect_p.h> + +#include "qdeclarativevideo_p.h" +#include "qdeclarativeaudio_p.h" + + +QML_DECLARE_TYPE(QSoundEffect) QT_BEGIN_NAMESPACE -class QMultimediaQmlModule : public QDeclarativeExtensionPlugin +class QMultimediaDeclarativeModule : public QDeclarativeExtensionPlugin { Q_OBJECT public: virtual void registerTypes(const char *uri) { - QtMultimedia::qRegisterDeclarativeElements(uri); + Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.multimedia")); + + qmlRegisterType<QSoundEffect>(uri, 4, 7, "SoundEffect"); + qmlRegisterType<QDeclarativeAudio>(uri, 4, 7, "Audio"); + qmlRegisterType<QDeclarativeVideo>(uri, 4, 7, "Video"); } }; @@ -59,5 +69,5 @@ QT_END_NAMESPACE #include "multimedia.moc" -Q_EXPORT_PLUGIN2(qmultimediaqmlmodule, QT_PREPEND_NAMESPACE(QMultimediaQmlModule)); +Q_EXPORT_PLUGIN2(qmultimediadeclarativemodule, QT_PREPEND_NAMESPACE(QMultimediaDeclarativeModule)); diff --git a/src/plugins/qdeclarativemodules/multimedia/multimedia.pro b/src/plugins/qdeclarativemodules/multimedia/multimedia.pro index d8ad18e..7b63e7c 100644 --- a/src/plugins/qdeclarativemodules/multimedia/multimedia.pro +++ b/src/plugins/qdeclarativemodules/multimedia/multimedia.pro @@ -3,7 +3,18 @@ include(../../qpluginbase.pri) QT += multimedia declarative -SOURCES += multimedia.cpp +HEADERS += \ + qdeclarativeaudio_p.h \ + qdeclarativemediabase_p.h \ + qdeclarativevideo_p.h \ + qmetadatacontrolmetaobject_p.h \ + +SOURCES += \ + multimedia.cpp \ + qdeclarativeaudio.cpp \ + qdeclarativemediabase.cpp \ + qdeclarativevideo.cpp \ + qmetadatacontrolmetaobject.cpp QTDIR_build:DESTDIR = $$QT_BUILD_TREE/imports/Qt/multimedia target.path = $$[QT_INSTALL_IMPORTS]/Qt/multimedia diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio.cpp b/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio.cpp new file mode 100644 index 0000000..df2888c --- /dev/null +++ b/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio.cpp @@ -0,0 +1,327 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativeaudio_p.h" + +#include <QtMultimedia/qmediaplayercontrol.h> + +QT_BEGIN_NAMESPACE + + +/*! + \qmlclass Audio QDeclarativeAudio + \since 4.7 + \brief The Audio element allows you to add audio playback to a scene. + + \qml + Audio { source: "audio/song.mp3" } + \endqml + + \sa Video +*/ + +/*! + \internal + \class QDeclarativeAudio + \brief The QDeclarativeAudio class provides an audio item that you can add to a QDeclarativeView. +*/ + +void QDeclarativeAudio::_q_error(int errorCode, const QString &errorString) +{ + m_error = QMediaPlayer::Error(errorCode); + m_errorString = errorString; + + emit error(Error(errorCode), errorString); + emit errorChanged(); +} + + +QDeclarativeAudio::QDeclarativeAudio(QObject *parent) + : QObject(parent) +{ + setObject(this); +} + +QDeclarativeAudio::~QDeclarativeAudio() +{ + shutdown(); +} + +/*! + \qmlmethod Audio::play() + + Starts playback of the media. + + Sets the \l playing property to true, and the \l paused property to false. +*/ + +void QDeclarativeAudio::play() +{ + m_playerControl->play(); + + if (m_paused) { + m_paused = false; + emit pausedChanged(); + } +} + +/*! + \qmlmethod Audio::pause() + + Pauses playback of the media. + + Sets the \l playing and \l paused properties to true. +*/ + +void QDeclarativeAudio::pause() +{ + m_playerControl->pause(); + + if (!m_paused && m_state == QMediaPlayer::PausedState) { + m_paused = true; + emit pausedChanged(); + } +} + +/*! + \qmlmethod Audio::stop() + + Stops playback of the media. + + Sets the \l playing and \l paused properties to false. +*/ + +void QDeclarativeAudio::stop() +{ + m_playerControl->stop(); + + if (m_paused) { + m_paused = false; + emit pausedChanged(); + } +} + +/*! + \qmlproperty url Audio::source + + This property holds the source URL of the media. +*/ + +/*! + \qmlproperty bool Audio::playing + + This property holds whether the media is playing. + + Defaults to false, and can be set to true to start playback. +*/ + +/*! + \qmlproperty bool Audio::paused + + This property holds whether the media is paused. + + Defaults to false, and can be set to true to pause playback. +*/ + +/*! + \qmlsignal Audio::onStarted() + + This handler is called when playback is started. +*/ + +/*! + \qmlsignal Audio::onResumed() + + This handler is called when playback is resumed from the paused state. +*/ + +/*! + \qmlsignal Audio::onPaused() + + This handler is called when playback is paused. +*/ + +/*! + \qmlsignal Audio::onStopped() + + This handler is called when playback is stopped. +*/ + +/*! + \qmlproperty enum Audio::status + + This property holds the status of media loading. It can be one of: + + \list + \o NoMedia - no media has been set. + \o Loading - the media is currently being loaded. + \o Loaded - the media has been loaded. + \o Buffering - the media is buffering data. + \o Stalled - playback has been interrupted while the media is buffering data. + \o Buffered - the media has buffered data. + \o EndOfMedia - the media has played to the end. + \o InvalidMedia - the media cannot be played. + \o UnknownStatus - the status of the media is unknown. + \endlist +*/ + +QDeclarativeAudio::Status QDeclarativeAudio::status() const +{ + return Status(m_status); +} + +/*! + \qmlsignal Audio::onLoaded() + + This handler is called when the media source has been loaded. +*/ + +/*! + \qmlsignal Audio::onBuffering() + + This handler is called when the media starts buffering. +*/ + +/*! + \qmlsignal Audio::onStalled() + + This handler is called when playback has stalled while the media buffers. +*/ + +/*! + \qmlsignal Audio::onBuffered() + + This handler is called when the media has finished buffering. +*/ + +/*! + \qmlsignal Audio::onEndOfMedia() + + This handler is called when playback stops because end of the media has been reached. +*/ +/*! + \qmlproperty int Audio::duration + + This property holds the duration of the media in milliseconds. + + If the media doesn't have a fixed duration (a live stream for example) this will be 0. +*/ + +/*! + \qmlproperty int Audio::position + + This property holds the current playback position in milliseconds. + + If the \l seekable property is true, this property can be set to seek to a new position. +*/ + +/*! + \qmlproperty qreal Audio::volume + + This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume). +*/ + +/*! + \qmlproperty bool Audio::muted + + This property holds whether the audio output is muted. +*/ + +/*! + \qmlproperty qreal Audio::bufferProgress + + This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0 + (full). +*/ + +/*! + \qmlproperty bool Audio::seekable + + This property holds whether position of the audio can be changed. + + If true; setting a \l position value will cause playback to seek to the new position. +*/ + +/*! + \qmlproperty qreal Audio::playbackRate + + This property holds the rate at which audio is played at as a multiple of the normal rate. +*/ + +/*! + \qmlproperty enum Audio::error + + This property holds the error state of the audio. It can be one of: + + \list + \o NoError - there is no current error. + \o ResourceError - the audio cannot be played due to a problem allocating resources. + \o FormatError - the audio format is not supported. + \o NetworkError - the audio cannot be played due to network issues. + \o AccessDenied - the audio cannot be played due to insufficient permissions. + \o ServiceMissing - the audio cannot be played because the media service could not be + instantiated. + \endlist +*/ + +QDeclarativeAudio::Error QDeclarativeAudio::error() const +{ + return Error(m_error); +} + +/*! + \qmlproperty string Audio::errorString + + This property holds a string describing the current error condition in more detail. +*/ + +/*! + \qmlsignal Audio::onError(error, errorString) + + This handler is called when an \l {Error}{error} has occurred. The errorString parameter + may contain more detailed information about the error. +*/ + +QT_END_NAMESPACE + +#include "moc_qdeclarativeaudio_p.cpp" + + diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio_p.h b/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio_p.h new file mode 100644 index 0000000..9881dbc --- /dev/null +++ b/src/plugins/qdeclarativemodules/multimedia/qdeclarativeaudio_p.h @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEAUDIO_P_H +#define QDECLARATIVEAUDIO_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qdeclarativemediabase_p.h" + +#include <QtCore/qbasictimer.h> +#include <QtDeclarative/qdeclarativeitem.h> + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QTimerEvent; + +class QDeclarativeAudio : public QObject, public QDeclarativeMediaBase, public QDeclarativeParserStatus +{ + Q_OBJECT + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) + Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(int duration READ duration NOTIFY durationChanged) + Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged) + Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) + Q_PROPERTY(int bufferProgress READ bufferProgress NOTIFY bufferProgressChanged) + Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged) + Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) + Q_PROPERTY(Error error READ error NOTIFY errorChanged) + Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) + Q_ENUMS(Status) + Q_ENUMS(Error) + Q_INTERFACES(QDeclarativeParserStatus) +public: + enum Status + { + UnknownStatus = QMediaPlayer::UnknownMediaStatus, + NoMedia = QMediaPlayer::NoMedia, + Loading = QMediaPlayer::LoadingMedia, + Loaded = QMediaPlayer::LoadedMedia, + Stalled = QMediaPlayer::StalledMedia, + Buffering = QMediaPlayer::BufferingMedia, + Buffered = QMediaPlayer::BufferedMedia, + EndOfMedia = QMediaPlayer::EndOfMedia, + InvalidMedia = QMediaPlayer::InvalidMedia + }; + + enum Error + { + NoError = QMediaPlayer::NoError, + ResourceError = QMediaPlayer::ResourceError, + FormatError = QMediaPlayer::FormatError, + NetworkError = QMediaPlayer::NetworkError, + AccessDenied = QMediaPlayer::AccessDeniedError, + ServiceMissing = QMediaPlayer::ServiceMissingError + }; + + QDeclarativeAudio(QObject *parent = 0); + ~QDeclarativeAudio(); + + Status status() const; + Error error() const; + +public Q_SLOTS: + void play(); + void pause(); + void stop(); + +Q_SIGNALS: + void sourceChanged(); + + void playingChanged(); + void pausedChanged(); + + void started(); + void resumed(); + void paused(); + void stopped(); + + void statusChanged(); + + void loaded(); + void buffering(); + void stalled(); + void buffered(); + void endOfMedia(); + + void durationChanged(); + void positionChanged(); + + void volumeChanged(); + void mutedChanged(); + + void bufferProgressChanged(); + + void seekableChanged(); + void playbackRateChanged(); + + void errorChanged(); + void error(QDeclarativeAudio::Error error, const QString &errorString); + +private Q_SLOTS: + void _q_error(int, const QString &); + +private: + Q_DISABLE_COPY(QDeclarativeAudio) + Q_PRIVATE_SLOT(mediaBase(), void _q_stateChanged(QMediaPlayer::State)) + Q_PRIVATE_SLOT(mediaBase(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus)) + Q_PRIVATE_SLOT(mediaBase(), void _q_metaDataChanged()) + + inline QDeclarativeMediaBase *mediaBase() { return this; } +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeAudio)) + +QT_END_HEADER + +#endif diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase.cpp b/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase.cpp new file mode 100644 index 0000000..8e87e44 --- /dev/null +++ b/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase.cpp @@ -0,0 +1,413 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativemediabase_p.h" + +#include <QtCore/qcoreevent.h> +#include <QtCore/qurl.h> + +#include <QtMultimedia/qmediaplayercontrol.h> +#include <QtMultimedia/qmediaservice.h> +#include <QtMultimedia/qmediaserviceprovider.h> +#include <QtMultimedia/qmetadatacontrol.h> +#include "qmetadatacontrolmetaobject_p.h" + + + +QT_BEGIN_NAMESPACE + + +class QDeclarativeMediaBaseObject : public QMediaObject +{ +public: + QDeclarativeMediaBaseObject(QMediaService *service) + : QMediaObject(0, service) + { + } +}; + +class QDeclarativeMediaBasePlayerControl : public QMediaPlayerControl +{ +public: + QDeclarativeMediaBasePlayerControl(QObject *parent) + : QMediaPlayerControl(parent) + { + } + + QMediaPlayer::State state() const { return QMediaPlayer::StoppedState; } + QMediaPlayer::MediaStatus mediaStatus() const { return QMediaPlayer::NoMedia; } + + qint64 duration() const { return 0; } + qint64 position() const { return 0; } + void setPosition(qint64) {} + int volume() const { return 0; } + void setVolume(int) {} + bool isMuted() const { return false; } + void setMuted(bool) {} + int bufferStatus() const { return 0; } + bool isAudioAvailable() const { return false; } + bool isVideoAvailable() const { return false; } + bool isSeekable() const { return false; } + QMediaTimeRange availablePlaybackRanges() const { return QMediaTimeRange(); } + qreal playbackRate() const { return 1; } + void setPlaybackRate(qreal) {} + QMediaContent media() const { return QMediaContent(); } + const QIODevice *mediaStream() const { return 0; } + void setMedia(const QMediaContent &, QIODevice *) {} + + void play() {} + void pause() {} + void stop() {} +}; + +class QDeclarativeMediaBaseAnimation : public QObject +{ +public: + QDeclarativeMediaBaseAnimation(QDeclarativeMediaBase *media) + : m_media(media) + { + } + + void start() { if (!m_timer.isActive()) m_timer.start(500, this); } + void stop() { m_timer.stop(); } + +protected: + void timerEvent(QTimerEvent *event) + { + if (event->timerId() == m_timer.timerId()) { + event->accept(); + + if (m_media->m_state == QMediaPlayer::PlayingState) + emit m_media->positionChanged(); + if (m_media->m_status == QMediaPlayer::BufferingMedia || QMediaPlayer::StalledMedia) + emit m_media->bufferProgressChanged(); + } else { + QObject::timerEvent(event); + } + } + +private: + QDeclarativeMediaBase *m_media; + QBasicTimer m_timer; +}; + +void QDeclarativeMediaBase::_q_stateChanged(QMediaPlayer::State state) +{ + if (state != m_state) { + QMediaPlayer::State oldState = m_state; + + m_state = state; + + if (state == QMediaPlayer::StoppedState) { + emit stopped(); + emit playingChanged(); + } else if (oldState == QMediaPlayer::StoppedState) { + emit started(); + emit playingChanged(); + } else if (oldState == QMediaPlayer::PausedState) { + m_paused = false; + + emit resumed(); + emit pausedChanged(); + } + + if (state == m_state && state == QMediaPlayer::PausedState) { + bool wasPaused = m_paused; + + m_paused = true; + + emit paused(); + + if (!wasPaused) + emit pausedChanged(); + } + + if (m_state == QMediaPlayer::PlayingState + || m_status == QMediaPlayer::BufferingMedia + || m_status == QMediaPlayer::StalledMedia) { + m_animation->start(); + } else { + m_animation->stop(); + } + } +} + +void QDeclarativeMediaBase::_q_mediaStatusChanged(QMediaPlayer::MediaStatus status) +{ + if (status != m_status) { + m_status = status; + + switch (status) { + case QMediaPlayer::LoadedMedia: + emit loaded(); + break; + case QMediaPlayer::BufferingMedia: + emit buffering(); + break; + case QMediaPlayer::BufferedMedia: + emit buffered(); + break; + case QMediaPlayer::StalledMedia: + emit stalled(); + break; + case QMediaPlayer::EndOfMedia: + emit endOfMedia(); + break; + default: + break; + } + + emit statusChanged(); + + if (m_state == QMediaPlayer::PlayingState + || m_status == QMediaPlayer::BufferingMedia + || m_status == QMediaPlayer::StalledMedia) { + m_animation->start(); + } else { + m_animation->stop(); + } + } +} + +void QDeclarativeMediaBase::_q_metaDataChanged() +{ + m_metaObject->metaDataChanged(); +} + +QDeclarativeMediaBase::QDeclarativeMediaBase() + : m_mediaService(0) + , m_playerControl(0) + , m_mediaObject(0) + , m_mediaProvider(0) + , m_metaDataControl(0) + , m_metaObject(0) + , m_animation(0) + , m_state(QMediaPlayer::StoppedState) + , m_status(QMediaPlayer::NoMedia) + , m_error(QMediaPlayer::NoError) + , m_paused(false) +{ +} + +QDeclarativeMediaBase::~QDeclarativeMediaBase() +{ +} + +void QDeclarativeMediaBase::shutdown() +{ + delete m_metaObject; + delete m_mediaObject; + + if (m_mediaProvider) + m_mediaProvider->releaseService(m_mediaService); + + delete m_animation; + +} + +void QDeclarativeMediaBase::setObject(QObject *object) +{ + if ((m_mediaProvider = QMediaServiceProvider::defaultServiceProvider())) { + if ((m_mediaService = m_mediaProvider->requestService(Q_MEDIASERVICE_MEDIAPLAYER))) { + m_playerControl = qobject_cast<QMediaPlayerControl *>( + m_mediaService->control(QMediaPlayerControl_iid)); + m_metaDataControl = qobject_cast<QMetaDataControl *>( + m_mediaService->control(QMetaDataControl_iid)); + m_mediaObject = new QDeclarativeMediaBaseObject(m_mediaService); + } + } + + if (m_playerControl) { + QObject::connect(m_playerControl, SIGNAL(stateChanged(QMediaPlayer::State)), + object, SLOT(_q_stateChanged(QMediaPlayer::State))); + QObject::connect(m_playerControl, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), + object, SLOT(_q_mediaStatusChanged(QMediaPlayer::MediaStatus))); + QObject::connect(m_playerControl, SIGNAL(mediaChanged(QMediaContent)), + object, SIGNAL(sourceChanged())); + QObject::connect(m_playerControl, SIGNAL(durationChanged(qint64)), + object, SIGNAL(durationChanged())); + QObject::connect(m_playerControl, SIGNAL(positionChanged(qint64)), + object, SIGNAL(positionChanged())); + QObject::connect(m_playerControl, SIGNAL(volumeChanged(int)), + object, SIGNAL(volumeChanged())); + QObject::connect(m_playerControl, SIGNAL(mutedChanged(bool)), + object, SIGNAL(mutedChanged())); + QObject::connect(m_playerControl, SIGNAL(bufferStatusChanged(int)), + object, SIGNAL(bufferProgressChanged())); + QObject::connect(m_playerControl, SIGNAL(seekableChanged(bool)), + object, SIGNAL(seekableChanged())); + QObject::connect(m_playerControl, SIGNAL(playbackRateChanged(qreal)), + object, SIGNAL(playbackRateChanged())); + QObject::connect(m_playerControl, SIGNAL(error(int,QString)), + object, SLOT(_q_error(int,QString))); + + m_animation = new QDeclarativeMediaBaseAnimation(this); + } else { + m_error = QMediaPlayer::ServiceMissingError; + + m_playerControl = new QDeclarativeMediaBasePlayerControl(object); + } + + if (m_metaDataControl) { + m_metaObject = new QMetaDataControlMetaObject(m_metaDataControl, object); + + QObject::connect(m_metaDataControl, SIGNAL(metaDataChanged()), + object, SLOT(_q_metaDataChanged())); + } +} + +QUrl QDeclarativeMediaBase::source() const +{ + return m_playerControl->media().canonicalUrl(); +} + +void QDeclarativeMediaBase::setSource(const QUrl &url) +{ + if (m_error != QMediaPlayer::ServiceMissingError && m_error != QMediaPlayer::NoError) { + m_error = QMediaPlayer::NoError; + m_errorString = QString(); + + emit errorChanged(); + } + + m_playerControl->setMedia(QMediaContent(url), 0); +} + +bool QDeclarativeMediaBase::isPlaying() const +{ + return m_state != QMediaPlayer::StoppedState; +} + +void QDeclarativeMediaBase::setPlaying(bool playing) +{ + if (playing && m_state == QMediaPlayer::StoppedState) { + if (m_paused) + m_playerControl->pause(); + else + m_playerControl->play(); + } else if (!playing) { + m_playerControl->stop(); + } +} + +bool QDeclarativeMediaBase::isPaused() const +{ + return m_paused; +} + +void QDeclarativeMediaBase::setPaused(bool paused) +{ + if (m_paused != paused) { + if (paused && m_state == QMediaPlayer::PlayingState) { + m_playerControl->pause(); + } else if (!paused && m_state == QMediaPlayer::PausedState) { + m_playerControl->play(); + } else { + m_paused = paused; + + emit pausedChanged(); + } + } +} + +int QDeclarativeMediaBase::duration() const +{ + return m_playerControl->duration(); +} + +int QDeclarativeMediaBase::position() const +{ + return m_playerControl->position(); + +} + +void QDeclarativeMediaBase::setPosition(int position) +{ + m_playerControl->setPosition(position); +} + +qreal QDeclarativeMediaBase::volume() const +{ + return qreal(m_playerControl->volume()) / 100; +} + +void QDeclarativeMediaBase::setVolume(qreal volume) +{ + m_playerControl->setVolume(qRound(volume * 100)); +} + +bool QDeclarativeMediaBase::isMuted() const +{ + return m_playerControl->isMuted(); +} + +void QDeclarativeMediaBase::setMuted(bool muted) +{ + m_playerControl->setMuted(muted); +} + +qreal QDeclarativeMediaBase::bufferProgress() const +{ + return qreal(m_playerControl->bufferStatus()) / 100; +} + +bool QDeclarativeMediaBase::isSeekable() const +{ + return m_playerControl->isSeekable(); +} + +qreal QDeclarativeMediaBase::playbackRate() const +{ + return m_playerControl->playbackRate(); +} + +void QDeclarativeMediaBase::setPlaybackRate(qreal rate) +{ + m_playerControl->setPlaybackRate(rate); +} + +QString QDeclarativeMediaBase::errorString() const +{ + return m_errorString; +} + +QT_END_NAMESPACE + diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase_p.h b/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase_p.h new file mode 100644 index 0000000..b40e84e --- /dev/null +++ b/src/plugins/qdeclarativemodules/multimedia/qdeclarativemediabase_p.h @@ -0,0 +1,168 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEMEDIABASE_P_H +#define QDECLARATIVEMEDIABASE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qbasictimer.h> +#include <QtMultimedia/qmediaplayer.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QMediaPlayerControl; +class QMediaService; +class QMediaServiceProvider; +class QMetaDataControl; +class QMetaDataControlMetaObject; +class QDeclarativeMediaBaseAnimation; + +class QDeclarativeMediaBase +{ +public: + QDeclarativeMediaBase(); + virtual ~QDeclarativeMediaBase(); + + QUrl source() const; + void setSource(const QUrl &url); + + bool isPlaying() const; + void setPlaying(bool playing); + + bool isPaused() const; + void setPaused(bool paused); + + int duration() const; + + int position() const; + void setPosition(int position); + + qreal volume() const; + void setVolume(qreal volume); + + bool isMuted() const; + void setMuted(bool muted); + + qreal bufferProgress() const; + + bool isSeekable() const; + + qreal playbackRate() const; + void setPlaybackRate(qreal rate); + + QString errorString() const; + + void _q_stateChanged(QMediaPlayer::State state); + void _q_mediaStatusChanged(QMediaPlayer::MediaStatus status); + + void _q_metaDataChanged(); + +protected: + void shutdown(); + + void setObject(QObject *object); + + virtual void sourceChanged() = 0; + + virtual void playingChanged() = 0; + virtual void pausedChanged() = 0; + + virtual void started() = 0; + virtual void resumed() = 0; + virtual void paused() = 0; + virtual void stopped() = 0; + + virtual void statusChanged() = 0; + + virtual void loaded() = 0; + virtual void buffering() = 0; + virtual void stalled() = 0; + virtual void buffered() = 0; + virtual void endOfMedia() = 0; + + virtual void durationChanged() = 0; + virtual void positionChanged() = 0; + + virtual void volumeChanged() = 0; + virtual void mutedChanged() = 0; + + virtual void bufferProgressChanged() = 0; + + virtual void seekableChanged() = 0; + virtual void playbackRateChanged() = 0; + + virtual void errorChanged() = 0; + + QMediaService *m_mediaService; + QMediaPlayerControl *m_playerControl; + + QMediaObject *m_mediaObject; + QMediaServiceProvider *m_mediaProvider; + QMetaDataControl *m_metaDataControl; + QMetaDataControlMetaObject *m_metaObject; + QDeclarativeMediaBaseAnimation *m_animation; + + QMediaPlayer::State m_state; + QMediaPlayer::MediaStatus m_status; + QMediaPlayer::Error m_error; + bool m_paused; + QString m_errorString; + + friend class QDeclarativeMediaBaseAnimation; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo.cpp b/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo.cpp new file mode 100644 index 0000000..064f242 --- /dev/null +++ b/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo.cpp @@ -0,0 +1,945 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdeclarativevideo_p.h" + +#include <QtMultimedia/qmediaplayercontrol.h> +#include <QtMultimedia/qmediaservice.h> +#include <QtMultimedia/private/qpaintervideosurface_p.h> +#include <QtMultimedia/qvideooutputcontrol.h> +#include <QtMultimedia/qvideorenderercontrol.h> + + +QT_BEGIN_NAMESPACE + + +void QDeclarativeVideo::_q_nativeSizeChanged(const QSizeF &size) +{ + setImplicitWidth(size.width()); + setImplicitHeight(size.height()); +} + +void QDeclarativeVideo::_q_error(int errorCode, const QString &errorString) +{ + m_error = QMediaPlayer::Error(errorCode); + m_errorString = errorString; + + emit error(Error(errorCode), errorString); + emit errorChanged(); +} + + +/*! + \qmlclass Video QDeclarativeVideo + \since 4.7 + \brief The Video element allows you to add videos to a scene. + \inherits Item + + \qml + Video { source: "video/movie.mpg" } + \endqml + + The video item supports untransformed, stretched, and uniformly scaled video presentation. + For a description of stretched uniformly scaled presentation, see the \l fillMode property + description. + + The video item is only visible when the \l hasVideo property is true and the video is playing. + + \sa Audio +*/ + +/*! + \internal + \class QDeclarativeVideo + \brief The QDeclarativeVideo class provides a video item that you can add to a QDeclarativeView. +*/ + +QDeclarativeVideo::QDeclarativeVideo(QDeclarativeItem *parent) + : QDeclarativeItem(parent) + , m_graphicsItem(0) + +{ + m_graphicsItem = new QGraphicsVideoItem(this); + connect(m_graphicsItem, SIGNAL(nativeSizeChanged(QSizeF)), + this, SLOT(_q_nativeSizeChanged(QSizeF))); + + setObject(this); + + if (m_mediaService) { + connect(m_playerControl, SIGNAL(audioAvailableChanged(bool)), + this, SIGNAL(hasAudioChanged())); + connect(m_playerControl, SIGNAL(videoAvailableChanged(bool)), + this, SIGNAL(hasVideoChanged())); + + m_graphicsItem->setMediaObject(m_mediaObject); + } +} + +QDeclarativeVideo::~QDeclarativeVideo() +{ + shutdown(); + + delete m_graphicsItem; +} + +/*! + \qmlproperty url Video::source + + This property holds the source URL of the media. +*/ + +/*! + \qmlproperty bool Video::playing + + This property holds whether the media is playing. + + Defaults to false, and can be set to true to start playback. +*/ + +/*! + \qmlproperty bool Video::paused + + This property holds whether the media is paused. + + Defaults to false, and can be set to true to pause playback. +*/ + +/*! + \qmlsignal Video::onStarted() + + This handler is called when playback is started. +*/ + +/*! + \qmlsignal Video::onResumed() + + This handler is called when playback is resumed from the paused state. +*/ + +/*! + \qmlsignal Video::onPaused() + + This handler is called when playback is paused. +*/ + +/*! + \qmlsignal Video::onStopped() + + This handler is called when playback is stopped. +*/ + +/*! + \qmlproperty enum Video::status + + This property holds the status of media loading. It can be one of: + + \list + \o NoMedia - no media has been set. + \o Loading - the media is currently being loaded. + \o Loaded - the media has been loaded. + \o Buffering - the media is buffering data. + \o Stalled - playback has been interrupted while the media is buffering data. + \o Buffered - the media has buffered data. + \o EndOfMedia - the media has played to the end. + \o InvalidMedia - the media cannot be played. + \o UnknownStatus - the status of the media is cannot be determined. + \endlist +*/ + +QDeclarativeVideo::Status QDeclarativeVideo::status() const +{ + return Status(m_status); +} + +/*! + \qmlsignal Video::onLoaded() + + This handler is called when the media source has been loaded. +*/ + +/*! + \qmlsignal Video::onBuffering() + + This handler is called when the media starts buffering. +*/ + +/*! + \qmlsignal Video::onStalled() + + This handler is called when playback has stalled while the media buffers. +*/ + +/*! + \qmlsignal Video::onBuffered() + + This handler is called when the media has finished buffering. +*/ + +/*! + \qmlsignal Video::onEndOfMedia() + + This handler is called when playback stops because end of the media has been reached. +*/ + +/*! + \qmlproperty int Video::duration + + This property holds the duration of the media in milliseconds. + + If the media doesn't have a fixed duration (a live stream for example) this will be 0. +*/ + +/*! + \qmlproperty int Video::position + + This property holds the current playback position in milliseconds. +*/ + +/*! + \qmlproperty qreal Video::volume + + This property holds the volume of the audio output, from 0.0 (silent) to 1.0 (maximum volume). +*/ + +/*! + \qmlproperty bool Video::muted + + This property holds whether the audio output is muted. +*/ + +/*! + \qmlproperty bool Video::hasAudio + + This property holds whether the media contains audio. +*/ + +bool QDeclarativeVideo::hasAudio() const +{ + return m_playerControl->isAudioAvailable(); +} + +/*! + \qmlproperty bool Video::hasVideo + + This property holds whether the media contains video. +*/ + +bool QDeclarativeVideo::hasVideo() const +{ + return m_playerControl->isVideoAvailable(); +} + +/*! + \qmlproperty qreal Video::bufferProgress + + This property holds how much of the data buffer is currently filled, from 0.0 (empty) to 1.0 + (full). +*/ + +/*! + \qmlproperty bool Video::seekable + + This property holds whether position of the video can be changed. +*/ + +/*! + \qmlproperty qreal Video::playbackRate + + This property holds the rate at which video is played at as a multiple of the normal rate. +*/ + +/*! + \qmlproperty enum Video::error + + This property holds the error state of the video. It can be one of: + + \list + \o NoError - there is no current error. + \o ResourceError - the video cannot be played due to a problem allocating resources. + \o FormatError - the video format is not supported. + \o NetworkError - the video cannot be played due to network issues. + \o AccessDenied - the video cannot be played due to insufficient permissions. + \o ServiceMissing - the video cannot be played because the media service could not be + instantiated. + \endlist +*/ + + +QDeclarativeVideo::Error QDeclarativeVideo::error() const +{ + return Error(m_error); +} + +/*! + \qmlproperty string Video::errorString + + This property holds a string describing the current error condition in more detail. +*/ + +/*! + \qmlsignal Video::onError(error, errorString) + + This handler is called when an \l {Error}{error} has occurred. The errorString parameter + may contain more detailed information about the error. +*/ + +/*! + \qmlproperty enum Video::fillMode + + Set this property to define how the video is scaled to fit the target area. + + \list + \o Stretch - the video is scaled to fit. + \o PreserveAspectFit - the video is scaled uniformly to fit without cropping + \o PreserveAspectCrop - the video is scaled uniformly to fill, cropping if necessary + \endlist + + The default fill mode is PreserveAspectFit. +*/ + +QDeclarativeVideo::FillMode QDeclarativeVideo::fillMode() const +{ + return FillMode(m_graphicsItem->aspectRatioMode()); +} + +void QDeclarativeVideo::setFillMode(FillMode mode) +{ + m_graphicsItem->setAspectRatioMode(Qt::AspectRatioMode(mode)); +} + +/*! + \qmlmethod Video::play() + + Starts playback of the media. + + Sets the \l playing property to true, and the \l paused property to false. +*/ + +void QDeclarativeVideo::play() +{ + m_playerControl->play(); + + if (m_paused) { + m_paused = false; + emit pausedChanged(); + } +} + +/*! + \qmlmethod Video::pause() + + Pauses playback of the media. + + Sets the \l playing and \l paused properties to true. +*/ + +void QDeclarativeVideo::pause() +{ + m_playerControl->pause(); + + if (!m_paused && m_state == QMediaPlayer::PausedState) { + m_paused = true; + emit pausedChanged(); + } +} + +/*! + \qmlmethod Video::stop() + + Stops playback of the media. + + Sets the \l playing and \l paused properties to false. +*/ + +void QDeclarativeVideo::stop() +{ + m_playerControl->stop(); + + if (m_paused) { + m_paused = false; + emit pausedChanged(); + } +} + +void QDeclarativeVideo::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) +{ +} + +void QDeclarativeVideo::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) +{ + m_graphicsItem->setSize(newGeometry.size()); + + QDeclarativeItem::geometryChanged(newGeometry, oldGeometry); +} + +QT_END_NAMESPACE + +// *************************************** +// Documentation for meta-data properties. +// *************************************** + +/*! + \qmlproperty variant Video::title + + This property holds the tile of the media. + + \sa {QtMultimedia::Title} +*/ + +/*! + \qmlproperty variant Video::subTitle + + This property holds the sub-title of the media. + + \sa {QtMultimedia::SubTitle} +*/ + +/*! + \qmlproperty variant Video::author + + This property holds the author of the media. + + \sa {QtMultimedia::Author} +*/ + +/*! + \qmlproperty variant Video::comment + + This property holds a user comment about the media. + + \sa {QtMultimedia::Comment} +*/ + +/*! + \qmlproperty variant Video::description + + This property holds a description of the media. + + \sa {QtMultimedia::Description} +*/ + +/*! + \qmlproperty variant Video::category + + This property holds the category of the media + + \sa {QtMultimedia::Category} +*/ + +/*! + \qmlproperty variant Video::genre + + This property holds the genre of the media. + + \sa {QtMultimedia::Genre} +*/ + +/*! + \qmlproperty variant Video::year + + This property holds the year of release of the media. + + \sa {QtMultimedia::Year} +*/ + +/*! + \qmlproperty variant Video::date + + This property holds the date of the media. + + \sa {QtMultimedia::Date} +*/ + +/*! + \qmlproperty variant Video::userRating + + This property holds a user rating of the media in the range of 0 to 100. + + \sa {QtMultimedia::UserRating} +*/ + +/*! + \qmlproperty variant Video::keywords + + This property holds a list of keywords describing the media. + + \sa {QtMultimedia::Keywords} +*/ + +/*! + \qmlproperty variant Video::language + + This property holds the language of the media, as an ISO 639-2 code. + + \sa {QtMultimedia::Language} +*/ + +/*! + \qmlproperty variant Video::publisher + + This property holds the publisher of the media. + + \sa {QtMultimedia::Publisher} +*/ + +/*! + \qmlproperty variant Video::copyright + + This property holds the media's copyright notice. + + \sa {QtMultimedia::Copyright} +*/ + +/*! + \qmlproperty variant Video::parentalRating + + This property holds the parental rating of the media. + + \sa {QtMultimedia::ParentalRating} +*/ + +/*! + \qmlproperty variant Video::ratingOrganisation + + This property holds the name of the rating organisation responsible for the + parental rating of the media. + + \sa {QtMultimedia::RatingOrganisation} +*/ + +/*! + \qmlproperty variant Video::size + + This property property holds the size of the media in bytes. + + \sa {QtMultimedia::Size} +*/ + +/*! + \qmlproperty variant Video::mediaType + + This property holds the type of the media. + + \sa {QtMultimedia::MediaType} +*/ + +/*! + \qmlproperty variant Video::audioBitRate + + This property holds the bit rate of the media's audio stream ni bits per + second. + + \sa {QtMultimedia::AudioBitRate} +*/ + +/*! + \qmlproperty variant Video::audioCodec + + This property holds the encoding of the media audio stream. + + \sa {QtMultimedia::AudioCodec} +*/ + +/*! + \qmlproperty variant Video::averageLevel + + This property holds the average volume level of the media. + + \sa {QtMultimedia::AverageLevel} +*/ + +/*! + \qmlproperty variant Video::channelCount + + This property holds the number of channels in the media's audio stream. + + \sa {QtMultimedia::ChannelCount} +*/ + +/*! + \qmlproperty variant Video::peakValue + + This property holds the peak volume of media's audio stream. + + \sa {QtMultimedia::PeakValue} +*/ + +/*! + \qmlproperty variant Video::sampleRate + + This property holds the sample rate of the media's audio stream in hertz. + + \sa {QtMultimedia::SampleRate} +*/ + +/*! + \qmlproperty variant Video::albumTitle + + This property holds the title of the album the media belongs to. + + \sa {QtMultimedia::AlbumTitle} +*/ + +/*! + \qmlproperty variant Video::albumArtist + + This property holds the name of the principal artist of the album the media + belongs to. + + \sa {QtMultimedia::AlbumArtist} +*/ + +/*! + \qmlproperty variant Video::contributingArtist + + This property holds the names of artists contributing to the media. + + \sa {QtMultimedia::ContributingArtist} +*/ + +/*! + \qmlproperty variant Video::composer + + This property holds the composer of the media. + + \sa {QtMultimedia::Composer} +*/ + +/*! + \qmlproperty variant Video::conductor + + This property holds the conductor of the media. + + \sa {QtMultimedia::Conductor} +*/ + +/*! + \qmlproperty variant Video::lyrics + + This property holds the lyrics to the media. + + \sa {QtMultimedia::Lyrics} +*/ + +/*! + \qmlproperty variant Video::mood + + This property holds the mood of the media. + + \sa {QtMultimedia::Mood} +*/ + +/*! + \qmlproperty variant Video::trackNumber + + This property holds the track number of the media. + + \sa {QtMultimedia::TrackNumber} +*/ + +/*! + \qmlproperty variant Video::trackCount + + This property holds the number of track on the album containing the media. + + \sa {QtMultimedia::TrackNumber} +*/ + +/*! + \qmlproperty variant Video::coverArtUrlSmall + + This property holds the URL of a small cover art image. + + \sa {QtMultimedia::CoverArtUrlSmall} +*/ + +/*! + \qmlproperty variant Video::coverArtUrlLarge + + This property holds the URL of a large cover art image. + + \sa {QtMultimedia::CoverArtUrlLarge} +*/ + +/*! + \qmlproperty variant Video::resolution + + This property holds the dimension of an image or video. + + \sa {QtMultimedia::Resolution} +*/ + +/*! + \qmlproperty variant Video::pixelAspectRatio + + This property holds the pixel aspect ratio of an image or video. + + \sa {QtMultimedia::PixelAspectRatio} +*/ + +/*! + \qmlproperty variant Video::videoFrameRate + + This property holds the frame rate of the media's video stream. + + \sa {QtMultimedia::VideoFrameRate} +*/ + +/*! + \qmlproperty variant Video::videoBitRate + + This property holds the bit rate of the media's video stream in bits per + second. + + \sa {QtMultimedia::VideoBitRate} +*/ + +/*! + \qmlproperty variant Video::videoCodec + + This property holds the encoding of the media's video stream. + + \sa {QtMultimedia::VideoCodec} +*/ + +/*! + \qmlproperty variant Video::posterUrl + + This property holds the URL of a poster image. + + \sa {QtMultimedia::PosterUrl} +*/ + +/*! + \qmlproperty variant Video::chapterNumber + + This property holds the chapter number of the media. + + \sa {QtMultimedia::ChapterNumber} +*/ + +/*! + \qmlproperty variant Video::director + + This property holds the director of the media. + + \sa {QtMultimedia::Director} +*/ + +/*! + \qmlproperty variant Video::leadPerformer + + This property holds the lead performer in the media. + + \sa {QtMultimedia::LeadPerformer} +*/ + +/*! + \qmlproperty variant Video::writer + + This property holds the writer of the media. + + \sa {QtMultimedia::Writer} +*/ + +// The remaining properties are related to photos, and are technically +// available but will certainly never have values. +#ifndef Q_QDOC + +/*! + \qmlproperty variant Video::cameraManufacturer + + \sa {QtMultimedia::CameraManufacturer} +*/ + +/*! + \qmlproperty variant Video::cameraModel + + \sa {QtMultimedia::CameraModel} +*/ + +/*! + \qmlproperty variant Video::event + + \sa {QtMultimedia::Event} +*/ + +/*! + \qmlproperty variant Video::subject + + \sa {QtMultimedia::Subject} +*/ + +/*! + \qmlproperty variant Video::orientation + + \sa {QtMultimedia::Orientation} +*/ + +/*! + \qmlproperty variant Video::exposureTime + + \sa {QtMultimedia::ExposureTime} +*/ + +/*! + \qmlproperty variant Video::fNumber + + \sa {QtMultimedia::FNumber} +*/ + +/*! + \qmlproperty variant Video::exposureProgram + + \sa {QtMultimedia::ExposureProgram} +*/ + +/*! + \qmlproperty variant Video::isoSpeedRatings + + \sa {QtMultimedia::ISOSpeedRatings} +*/ + +/*! + \qmlproperty variant Video::exposureBiasValue + + \sa {QtMultimedia::ExposureBiasValue} +*/ + +/*! + \qmlproperty variant Video::dateTimeDigitized + + \sa {QtMultimedia::DateTimeDigitized} +*/ + +/*! + \qmlproperty variant Video::subjectDistance + + \sa {QtMultimedia::SubjectDistance} +*/ + +/*! + \qmlproperty variant Video::meteringMode + + \sa {QtMultimedia::MeteringMode} +*/ + +/*! + \qmlproperty variant Video::lightSource + + \sa {QtMultimedia::LightSource} +*/ + +/*! + \qmlproperty variant Video::flash + + \sa {QtMultimedia::Flash} +*/ + +/*! + \qmlproperty variant Video::focalLength + + \sa {QtMultimedia::FocalLength} +*/ + +/*! + \qmlproperty variant Video::exposureMode + + \sa {QtMultimedia::ExposureMode} +*/ + +/*! + \qmlproperty variant Video::whiteBalance + + \sa {QtMultimedia::WhiteBalance} +*/ + +/*! + \qmlproperty variant Video::DigitalZoomRatio + + \sa {QtMultimedia::DigitalZoomRatio} +*/ + +/*! + \qmlproperty variant Video::focalLengthIn35mmFilm + + \sa {QtMultimedia::FocalLengthIn35mmFile} +*/ + +/*! + \qmlproperty variant Video::sceneCaptureType + + \sa {QtMultimedia::SceneCaptureType} +*/ + +/*! + \qmlproperty variant Video::gainControl + + \sa {QtMultimedia::GainControl} +*/ + +/*! + \qmlproperty variant Video::contrast + + \sa {QtMultimedia::contrast} +*/ + +/*! + \qmlproperty variant Video::saturation + + \sa {QtMultimedia::Saturation} +*/ + +/*! + \qmlproperty variant Video::sharpness + + \sa {QtMultimedia::Sharpness} +*/ + +/*! + \qmlproperty variant Video::deviceSettingDescription + + \sa {QtMultimedia::DeviceSettingDescription} +*/ + +#endif + +#include "moc_qdeclarativevideo_p.cpp" diff --git a/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo_p.h b/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo_p.h new file mode 100644 index 0000000..fb13519 --- /dev/null +++ b/src/plugins/qdeclarativemodules/multimedia/qdeclarativevideo_p.h @@ -0,0 +1,204 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QDECLARATIVEVIDEO_H +#define QDECLARATIVEVIDEO_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qdeclarativemediabase_p.h" + +#include <QtMultimedia/qgraphicsvideoitem.h> + +#include <QtCore/qbasictimer.h> +#include <QtDeclarative/qdeclarativeitem.h> + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QTimerEvent; +class QVideoSurfaceFormat; + + +class QDeclarativeVideo : public QDeclarativeItem, public QDeclarativeMediaBase +{ + Q_OBJECT + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) + Q_PROPERTY(bool playing READ isPlaying WRITE setPlaying NOTIFY playingChanged) + Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) + Q_PROPERTY(Status status READ status NOTIFY statusChanged) + Q_PROPERTY(int duration READ duration NOTIFY durationChanged) + Q_PROPERTY(int position READ position WRITE setPosition NOTIFY positionChanged) + Q_PROPERTY(qreal volume READ volume WRITE setVolume NOTIFY volumeChanged) + Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) + Q_PROPERTY(bool hasAudio READ hasAudio NOTIFY hasAudioChanged) + Q_PROPERTY(bool hasVideo READ hasVideo NOTIFY hasVideoChanged) + Q_PROPERTY(int bufferProgress READ bufferProgress NOTIFY bufferProgressChanged) + Q_PROPERTY(bool seekable READ isSeekable NOTIFY seekableChanged) + Q_PROPERTY(qreal playbackRate READ playbackRate WRITE setPlaybackRate NOTIFY playbackRateChanged) + Q_PROPERTY(Error error READ error NOTIFY errorChanged) + Q_PROPERTY(QString errorString READ errorString NOTIFY errorChanged) + Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode) + Q_ENUMS(FillMode) + Q_ENUMS(Status) + Q_ENUMS(Error) +public: + enum FillMode + { + Stretch = Qt::IgnoreAspectRatio, + PreserveAspectFit = Qt::KeepAspectRatio, + PreserveAspectCrop = Qt::KeepAspectRatioByExpanding + }; + + enum Status + { + UnknownStatus = QMediaPlayer::UnknownMediaStatus, + NoMedia = QMediaPlayer::NoMedia, + Loading = QMediaPlayer::LoadingMedia, + Loaded = QMediaPlayer::LoadedMedia, + Stalled = QMediaPlayer::StalledMedia, + Buffering = QMediaPlayer::BufferingMedia, + Buffered = QMediaPlayer::BufferedMedia, + EndOfMedia = QMediaPlayer::EndOfMedia, + InvalidMedia = QMediaPlayer::InvalidMedia + }; + + enum Error + { + NoError = QMediaPlayer::NoError, + ResourceError = QMediaPlayer::ResourceError, + FormatError = QMediaPlayer::FormatError, + NetworkError = QMediaPlayer::NetworkError, + AccessDenied = QMediaPlayer::AccessDeniedError, + ServiceMissing = QMediaPlayer::ServiceMissingError + }; + + QDeclarativeVideo(QDeclarativeItem *parent = 0); + ~QDeclarativeVideo(); + + bool hasAudio() const; + bool hasVideo() const; + + FillMode fillMode() const; + void setFillMode(FillMode mode); + + Status status() const; + Error error() const; + + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); + +public Q_SLOTS: + void play(); + void pause(); + void stop(); + +Q_SIGNALS: + void sourceChanged(); + + void playingChanged(); + void pausedChanged(); + + void started(); + void resumed(); + void paused(); + void stopped(); + + void statusChanged(); + + void loaded(); + void buffering(); + void stalled(); + void buffered(); + void endOfMedia(); + + void durationChanged(); + void positionChanged(); + + void volumeChanged(); + void mutedChanged(); + void hasAudioChanged(); + void hasVideoChanged(); + + void bufferProgressChanged(); + + void seekableChanged(); + void playbackRateChanged(); + + void errorChanged(); + void error(QDeclarativeVideo::Error error, const QString &errorString); + +protected: + void geometryChanged(const QRectF &geometry, const QRectF &); + +private Q_SLOTS: + void _q_nativeSizeChanged(const QSizeF &size); + void _q_error(int, const QString &); + +private: + Q_DISABLE_COPY(QDeclarativeVideo) + + QGraphicsVideoItem *m_graphicsItem; + + Q_PRIVATE_SLOT(mediaBase(), void _q_stateChanged(QMediaPlayer::State)) + Q_PRIVATE_SLOT(mediaBase(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus)) + Q_PRIVATE_SLOT(mediaBase(), void _q_metaDataChanged()) + + inline QDeclarativeMediaBase *mediaBase() { return this; } +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPE(QT_PREPEND_NAMESPACE(QDeclarativeVideo)) + +QT_END_HEADER + +#endif diff --git a/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject.cpp b/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject.cpp new file mode 100644 index 0000000..e90cbd6 --- /dev/null +++ b/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject.cpp @@ -0,0 +1,362 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qmetadatacontrolmetaobject_p.h" +#include <QtMultimedia/qmetadatacontrol.h> + + +QT_BEGIN_NAMESPACE + +// copied from qmetaobject.cpp +// do not touch without touching the moc as well +enum PropertyFlags { + Invalid = 0x00000000, + Readable = 0x00000001, + Writable = 0x00000002, + Resettable = 0x00000004, + EnumOrFlag = 0x00000008, + StdCppSet = 0x00000100, +// Override = 0x00000200, + Designable = 0x00001000, + ResolveDesignable = 0x00002000, + Scriptable = 0x00004000, + ResolveScriptable = 0x00008000, + Stored = 0x00010000, + ResolveStored = 0x00020000, + Editable = 0x00040000, + ResolveEditable = 0x00080000, + User = 0x00100000, + ResolveUser = 0x00200000, + Notify = 0x00400000, + Dynamic = 0x00800000 +}; + +enum MethodFlags { + AccessPrivate = 0x00, + AccessProtected = 0x01, + AccessPublic = 0x02, + AccessMask = 0x03, //mask + + MethodMethod = 0x00, + MethodSignal = 0x04, + MethodSlot = 0x08, + MethodConstructor = 0x0c, + MethodTypeMask = 0x0c, + + MethodCompatibility = 0x10, + MethodCloned = 0x20, + MethodScriptable = 0x40 +}; + +struct QMetaObjectPrivate +{ + int revision; + int className; + int classInfoCount, classInfoData; + int methodCount, methodData; + int propertyCount, propertyData; + int enumeratorCount, enumeratorData; + int constructorCount, constructorData; + int flags; +}; + +static inline const QMetaObjectPrivate *priv(const uint* m_data) +{ return reinterpret_cast<const QMetaObjectPrivate*>(m_data); } +// end of copied lines from qmetaobject.cpp + +namespace +{ + struct MetaDataKey + { + QtMultimedia::MetaData key; + const char *name; + }; + + const MetaDataKey qt_metaDataKeys[] = + { + { QtMultimedia::Title, "title" }, + { QtMultimedia::SubTitle, "subTitle" }, + { QtMultimedia::Author, "author" }, + { QtMultimedia::Comment, "comment" }, + { QtMultimedia::Description, "description" }, + { QtMultimedia::Category, "category" }, + { QtMultimedia::Genre, "genre" }, + { QtMultimedia::Year, "year" }, + { QtMultimedia::Date, "date" }, + { QtMultimedia::UserRating, "userRating" }, + { QtMultimedia::Keywords, "keywords" }, + { QtMultimedia::Language, "language" }, + { QtMultimedia::Publisher, "publisher" }, + { QtMultimedia::Copyright, "copyright" }, + { QtMultimedia::ParentalRating, "parentalRating" }, + { QtMultimedia::RatingOrganisation, "ratingOrganisation" }, + + // Media + { QtMultimedia::Size, "size" }, + { QtMultimedia::MediaType, "mediaType" }, +// { QtMultimedia::Duration, "duration" }, + + // Audio + { QtMultimedia::AudioBitRate, "audioBitRate" }, + { QtMultimedia::AudioCodec, "audioCodec" }, + { QtMultimedia::AverageLevel, "averageLevel" }, + { QtMultimedia::ChannelCount, "channelCount" }, + { QtMultimedia::PeakValue, "peakValue" }, + { QtMultimedia::SampleRate, "sampleRate" }, + + // Music + { QtMultimedia::AlbumTitle, "albumTitle" }, + { QtMultimedia::AlbumArtist, "albumArtist" }, + { QtMultimedia::ContributingArtist, "contributingArtist" }, + { QtMultimedia::Composer, "composer" }, + { QtMultimedia::Conductor, "conductor" }, + { QtMultimedia::Lyrics, "lyrics" }, + { QtMultimedia::Mood, "mood" }, + { QtMultimedia::TrackNumber, "trackNumber" }, + { QtMultimedia::TrackCount, "trackCount" }, + + { QtMultimedia::CoverArtUrlSmall, "coverArtUrlSmall" }, + { QtMultimedia::CoverArtUrlLarge, "coverArtUrlLarge" }, + + // Image/Video + { QtMultimedia::Resolution, "resolution" }, + { QtMultimedia::PixelAspectRatio, "pixelAspectRatio" }, + + // Video + { QtMultimedia::VideoFrameRate, "videoFrameRate" }, + { QtMultimedia::VideoBitRate, "videoBitRate" }, + { QtMultimedia::VideoCodec, "videoCodec" }, + + { QtMultimedia::PosterUrl, "posterUrl" }, + + // Movie + { QtMultimedia::ChapterNumber, "chapterNumber" }, + { QtMultimedia::Director, "director" }, + { QtMultimedia::LeadPerformer, "leadPerformer" }, + { QtMultimedia::Writer, "writer" }, + + // Photos + { QtMultimedia::CameraManufacturer, "cameraManufacturer" }, + { QtMultimedia::CameraModel, "cameraModel" }, + { QtMultimedia::Event, "event" }, + { QtMultimedia::Subject, "subject" }, + { QtMultimedia::Orientation, "orientation" }, + { QtMultimedia::ExposureTime, "exposureTime" }, + { QtMultimedia::FNumber, "fNumber" }, + { QtMultimedia::ExposureProgram, "exposureProgram" }, + { QtMultimedia::ISOSpeedRatings, "isoSpeedRatings" }, + { QtMultimedia::ExposureBiasValue, "exposureBiasValue" }, + { QtMultimedia::DateTimeOriginal, "dateTimeOriginal" }, + { QtMultimedia::DateTimeDigitized, "dateTimeDigitized" }, + { QtMultimedia::SubjectDistance, "subjectDistance" }, + { QtMultimedia::MeteringMode, "meteringMode" }, + { QtMultimedia::LightSource, "lightSource" }, + { QtMultimedia::Flash, "flash" }, + { QtMultimedia::FocalLength, "focalLength" }, + { QtMultimedia::ExposureMode, "exposureMode" }, + { QtMultimedia::WhiteBalance, "whiteBalance" }, + { QtMultimedia::DigitalZoomRatio, "digitalZoomRatio" }, + { QtMultimedia::FocalLengthIn35mmFilm, "focalLengthIn35mmFilm" }, + { QtMultimedia::SceneCaptureType, "sceneCaptureType" }, + { QtMultimedia::GainControl, "gainControl" }, + { QtMultimedia::Contrast, "contrast" }, + { QtMultimedia::Saturation, "saturation" }, + { QtMultimedia::Sharpness, "sharpness" }, + { QtMultimedia::DeviceSettingDescription, "deviceSettingDescription" } + }; + + class QMetaDataControlObject : public QObject + { + public: + inline QObjectData *data() { return d_ptr.data(); } + }; +} + +QMetaDataControlMetaObject::QMetaDataControlMetaObject(QMetaDataControl *control, QObject *object) + : m_control(control) + , m_object(object) + , m_string(0) + , m_data(0) + , m_propertyOffset(0) + , m_signalOffset(0) +{ + const QMetaObject *superClass = m_object->metaObject(); + + const int propertyCount = sizeof(qt_metaDataKeys) / sizeof(MetaDataKey); + const int dataSize = sizeof(uint) + * (13 // QMetaObjectPrivate members. + + 5 // 5 members per signal. + + 4 * propertyCount // 3 members per property + 1 notify signal per property. + + 1); // Terminating value. + + m_data = reinterpret_cast<uint *>(qMalloc(dataSize)); + + QMetaObjectPrivate *pMeta = reinterpret_cast<QMetaObjectPrivate *>(m_data); + + pMeta->revision = 3; + pMeta->className = 0; + pMeta->classInfoCount = 0; + pMeta->classInfoData = 0; + pMeta->methodCount = 1; + pMeta->methodData = 13; + pMeta->propertyCount = propertyCount; + pMeta->propertyData = 18; + pMeta->enumeratorCount = 0; + pMeta->enumeratorData = 0; + pMeta->constructorCount = 0; + pMeta->constructorData = 0; + pMeta->flags = 0x01; // Dynamic meta object flag. + + const int classNameSize = qstrlen(superClass->className()) + 1; + + int stringIndex = classNameSize + 1; + + // __metaDataChanged() signal. + static const char *changeSignal = "__metaDataChanged()"; + const int changeSignalSize = qstrlen(changeSignal) + 1; + + m_data[13] = stringIndex; // Signature. + m_data[14] = classNameSize; // Parameters. + m_data[15] = classNameSize; // Type. + m_data[16] = classNameSize; // Tag. + m_data[17] = MethodSignal | AccessProtected; // Flags. + + stringIndex += changeSignalSize; + + const char *qvariantName = "QVariant"; + const int qvariantSize = qstrlen(qvariantName) + 1; + const int qvariantIndex = stringIndex; + + stringIndex += qvariantSize; + + // Properties. + for (int i = 0; i < propertyCount; ++i) { + m_data[18 + 3 * i] = stringIndex; // Name. + m_data[19 + 3 * i] = qvariantIndex; // Type. + m_data[20 + 3 * i] + = Readable | Writable | Notify | Dynamic | (0xffffffff << 24); // Flags. + m_data[18 + propertyCount * 3 + i] = 0; // Notify signal. + + stringIndex += qstrlen(qt_metaDataKeys[i].name) + 1; + } + + // Terminating value. + m_data[18 + propertyCount * 4] = 0; + + // Build string. + m_string = reinterpret_cast<char *>(qMalloc(stringIndex + 1)); + + // Class name. + qMemCopy(m_string, superClass->className(), classNameSize); + + stringIndex = classNameSize; + + // Null m_string. + m_string[stringIndex] = '\0'; + stringIndex += 1; + + // __metaDataChanged() signal. + qMemCopy(m_string + stringIndex, changeSignal, changeSignalSize); + stringIndex += changeSignalSize; + + qMemCopy(m_string + stringIndex, qvariantName, qvariantSize); + stringIndex += qvariantSize; + + // Properties. + for (int i = 0; i < propertyCount; ++i) { + const int propertyNameSize = qstrlen(qt_metaDataKeys[i].name) + 1; + + qMemCopy(m_string + stringIndex, qt_metaDataKeys[i].name, propertyNameSize); + stringIndex += propertyNameSize; + } + + // Terminating character. + m_string[stringIndex] = '\0'; + + d.superdata = superClass; + d.stringdata = m_string; + d.data = m_data; + d.extradata = 0; + + static_cast<QMetaDataControlObject *>(m_object)->data()->metaObject = this; + + m_propertyOffset = propertyOffset(); + m_signalOffset = methodOffset(); +} + +QMetaDataControlMetaObject::~QMetaDataControlMetaObject() +{ + static_cast<QMetaDataControlObject *>(m_object)->data()->metaObject = 0; + + qFree(m_data); + qFree(m_string); +} + +int QMetaDataControlMetaObject::metaCall(QMetaObject::Call c, int id, void **a) +{ + if (c == QMetaObject::ReadProperty && id >= m_propertyOffset) { + int propId = id - m_propertyOffset; + + *reinterpret_cast<QVariant *>(a[0]) = m_control->metaData(qt_metaDataKeys[propId].key); + + return -1; + } else if (c == QMetaObject::WriteProperty && id >= m_propertyOffset) { + int propId = id - m_propertyOffset; + + m_control->setMetaData(qt_metaDataKeys[propId].key, *reinterpret_cast<QVariant *>(a[0])); + + return -1; + } else { + return m_object->qt_metacall(c, id, a); + } +} + +int QMetaDataControlMetaObject::createProperty(const char *, const char *) +{ + return -1; +} + +void QMetaDataControlMetaObject::metaDataChanged() +{ + activate(m_object, m_signalOffset, 0); +} + +QT_END_NAMESPACE diff --git a/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject_p.h b/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject_p.h new file mode 100644 index 0000000..c381f2d --- /dev/null +++ b/src/plugins/qdeclarativemodules/multimedia/qmetadatacontrolmetaobject_p.h @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QMETADATACONTROLMETAOBJECT_P_H +#define QMETADATACONTROLMETAOJBECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qmetaobject.h> +#include <QtMultimedia/qtmedianamespace.h> + +#include <QtCore/private/qobject_p.h> + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QMetaDataControl; + +class QMetaDataControlMetaObject : public QAbstractDynamicMetaObject +{ +public: + QMetaDataControlMetaObject(QMetaDataControl *control, QObject *object); + ~QMetaDataControlMetaObject(); + + int metaCall(QMetaObject::Call call, int _id, void **arguments); + int createProperty(const char *, const char *); + + void metaDataChanged(); + +private: + QMetaDataControl *m_control; + QObject *m_object; + char *m_string; + uint *m_data; + + int m_propertyOffset; + int m_signalOffset; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif |