diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ac8c87a745dca00665786d12810aa7a95b1f743..ae0eb17f17f4001237e6fea70b61a68d833d172e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,9 +56,9 @@ set( qtsflphone_LIB_SRCS phonenumber.cpp numbercategory.cpp abstractitembackendmodelextension.cpp - video/videodevice.cpp - video/videorenderer.cpp - video/videocodec.cpp + video/device.cpp + video/renderer.cpp + video/codec.cpp #Models accountmodel.cpp @@ -84,13 +84,13 @@ set( qtsflphone_LIB_SRCS certificate.cpp contactmodel.cpp itembackendmodel.cpp - video/videodevicemodel.cpp + video/devicemodel.cpp video/sourcesmodel.cpp - video/videocodecmodel.cpp - video/videochannel.cpp - video/videoresolution.cpp - video/videorate.cpp - video/videomanager.cpp + video/codecmodel2.cpp + video/channel.cpp + video/resolution.cpp + video/rate.cpp + video/manager.cpp audio/alsapluginmodel.cpp audio/codecmodel.cpp audio/inputdevicemodel.cpp @@ -164,16 +164,16 @@ set( qtsflphone_LIB_HDRS hookmanager.h uri.h abstractitembackendmodelextension.h - video/videodevice.h - video/videodevicemodel.h + video/device.h + video/devicemodel.h video/sourcesmodel.h - video/videocodec.h - video/videocodecmodel.h - video/videomanager.h - video/videorenderer.h - video/videoresolution.h - video/videochannel.h - video/videorate.h + video/codec.h + video/codecmodel2.h + video/manager.h + video/renderer.h + video/resolution.h + video/channel.h + video/rate.h audio/alsapluginmodel.h audio/codecmodel.h audio/inputdevicemodel.h diff --git a/src/account.cpp b/src/account.cpp index 1350a03177d23e9621c190c8ad304c772e53e30c..dceec031166f06de26ac4ad55aa9204e660659a4 100644 --- a/src/account.cpp +++ b/src/account.cpp @@ -37,7 +37,7 @@ #include "accountmodel.h" #include "credentialmodel.h" #include "audio/codecmodel.h" -#include "video/videocodecmodel.h" +#include "video/codecmodel2.h" #include "ringtonemodel.h" #include "phonenumber.h" #include "phonedirectorymodel.h" @@ -89,7 +89,7 @@ public: CredentialModel* m_pCredentials ; Audio::CodecModel* m_pAudioCodecs ; - VideoCodecModel* m_pVideoCodecs ; + Video::CodecModel2* m_pVideoCodecs ; RingToneModel* m_pRingToneModel ; KeyExchangeModel* m_pKeyExchangeModel; SecurityValidationModel* m_pSecurityValidationModel; @@ -388,24 +388,24 @@ Audio::CodecModel* Account::audioCodecModel() const } ///Create and return the video codec model -VideoCodecModel* Account::videoCodecModel() const +Video::CodecModel2* Account::videoCodecModel() const { if (!d_ptr->m_pVideoCodecs) - const_cast<Account*>(this)->d_ptr->m_pVideoCodecs = new VideoCodecModel(const_cast<Account*>(this)); + d_ptr->m_pVideoCodecs = new Video::CodecModel2(const_cast<Account*>(this)); return d_ptr->m_pVideoCodecs; } RingToneModel* Account::ringToneModel() const { if (!d_ptr->m_pRingToneModel) - const_cast<Account*>(this)->d_ptr->m_pRingToneModel = new RingToneModel(const_cast<Account*>(this)); + d_ptr->m_pRingToneModel = new RingToneModel(const_cast<Account*>(this)); return d_ptr->m_pRingToneModel; } KeyExchangeModel* Account::keyExchangeModel() const { if (!d_ptr->m_pKeyExchangeModel) { - const_cast<Account*>(this)->d_ptr->m_pKeyExchangeModel = new KeyExchangeModel(const_cast<Account*>(this)); + d_ptr->m_pKeyExchangeModel = new KeyExchangeModel(const_cast<Account*>(this)); } return d_ptr->m_pKeyExchangeModel; } @@ -413,7 +413,7 @@ KeyExchangeModel* Account::keyExchangeModel() const SecurityValidationModel* Account::securityValidationModel() const { if (!d_ptr->m_pSecurityValidationModel) { - const_cast<Account*>(this)->d_ptr->m_pSecurityValidationModel = new SecurityValidationModel(const_cast<Account*>(this)); + d_ptr->m_pSecurityValidationModel = new SecurityValidationModel(const_cast<Account*>(this)); } return d_ptr->m_pSecurityValidationModel; } @@ -563,7 +563,7 @@ int Account::tlsListenerPort() const Certificate* Account::tlsCaListCertificate() const { if (!d_ptr->m_pCaCert) { - const_cast<Account*>(this)->d_ptr->m_pCaCert = new Certificate(Certificate::Type::AUTHORITY,this); + d_ptr->m_pCaCert = new Certificate(Certificate::Type::AUTHORITY,this); connect(d_ptr->m_pCaCert,SIGNAL(changed()),d_ptr.data(),SLOT(slotUpdateCertificate())); } const_cast<Account*>(this)->d_ptr->m_pCaCert->setPath(d_ptr->accountDetail(Account::MapField::TLS::CA_LIST_FILE)); @@ -574,7 +574,7 @@ Certificate* Account::tlsCaListCertificate() const Certificate* Account::tlsCertificate() const { if (!d_ptr->m_pTlsCert) { - const_cast<Account*>(this)->d_ptr->m_pTlsCert = new Certificate(Certificate::Type::USER,this); + d_ptr->m_pTlsCert = new Certificate(Certificate::Type::USER,this); connect(d_ptr->m_pTlsCert,SIGNAL(changed()),d_ptr.data(),SLOT(slotUpdateCertificate())); } const_cast<Account*>(this)->d_ptr->m_pTlsCert->setPath(d_ptr->accountDetail(Account::MapField::TLS::CERTIFICATE_FILE)); @@ -585,7 +585,7 @@ Certificate* Account::tlsCertificate() const Certificate* Account::tlsPrivateKeyCertificate() const { if (!d_ptr->m_pPrivateKey) { - const_cast<Account*>(this)->d_ptr->m_pPrivateKey = new Certificate(Certificate::Type::PRIVATE_KEY,this); + d_ptr->m_pPrivateKey = new Certificate(Certificate::Type::PRIVATE_KEY,this); connect(d_ptr->m_pPrivateKey,SIGNAL(changed()),d_ptr.data(),SLOT(slotUpdateCertificate())); } const_cast<Account*>(this)->d_ptr->m_pPrivateKey->setPath(d_ptr->accountDetail(Account::MapField::TLS::PRIVATE_KEY_FILE)); diff --git a/src/account.h b/src/account.h index 1cda3f70fdf763a6733c8440f9cbc9a2751de892..4da4ba292212a3ac6bdc93ca2180d6c14f31693a 100644 --- a/src/account.h +++ b/src/account.h @@ -26,13 +26,12 @@ class QString; //SFLPhone -#include "video/videocodecmodel.h" +#include "video/codecmodel2.h" #include "keyexchangemodel.h" #include "tlsmethodmodel.h" #include "sflphone_const.h" #include "typedefs.h" class CredentialModel; -class VideoCodecModel; class RingToneModel ; class PhoneNumber ; class SecurityValidationModel; @@ -41,6 +40,9 @@ class Certificate ; namespace Audio { class CodecModel; } +namespace Video { + class CodecModel2; +} //Private class AccountPrivate; @@ -334,7 +336,7 @@ class LIB_EXPORT Account : public QObject { Q_INVOKABLE CredentialModel* credentialsModel() const; Q_INVOKABLE Audio::CodecModel* audioCodecModel () const; - Q_INVOKABLE VideoCodecModel* videoCodecModel () const; + Q_INVOKABLE Video::CodecModel2* videoCodecModel () const; Q_INVOKABLE RingToneModel* ringToneModel () const; Q_INVOKABLE KeyExchangeModel* keyExchangeModel() const; Q_INVOKABLE SecurityValidationModel* securityValidationModel() const; @@ -470,7 +472,7 @@ class LIB_EXPORT Account : public QObject { private: //Constructors - Account(); + explicit Account(); QScopedPointer<AccountPrivate> d_ptr; Q_DECLARE_PRIVATE(Account) diff --git a/src/audio/codecmodel.cpp b/src/audio/codecmodel.cpp index e1a3db25f5e4155580e5d1bbff7d22ed1a003026..f4b4a8c084354ed2b5e7b56ffbc517c48ae5fbe6 100644 --- a/src/audio/codecmodel.cpp +++ b/src/audio/codecmodel.cpp @@ -229,7 +229,7 @@ void Audio::CodecModel::reload() foreach (const int aCodec, codecIdList) { if (!d_ptr->findCodec(aCodec)) { const QStringList codec = configurationManager.getAudioCodecDetails(aCodec); - QModelIndex idx = add(); + const QModelIndex& idx = add(); setData(idx,codec[0],Audio::CodecModel::Role::NAME ); setData(idx,codec[1],Audio::CodecModel::Role::SAMPLERATE ); setData(idx,codec[2],Audio::CodecModel::Role::BITRATE ); @@ -244,7 +244,7 @@ void Audio::CodecModel::save() { QStringList _codecList; for (int i=0; i < rowCount();i++) { - QModelIndex idx = index(i,0); + const QModelIndex& idx = index(i,0); if (data(idx,Qt::CheckStateRole) == Qt::Checked) { _codecList << data(idx,Audio::CodecModel::Role::ID).toString(); } diff --git a/src/call.cpp b/src/call.cpp index 69d3f0f4c3073404bf3a3feba141dcac91fcf7cd..d319461b9ad673dc5af90632a1626d6bde10465f 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -36,7 +36,7 @@ #include "uri.h" #include "account.h" #include "accountmodel.h" -#include "video/videomanager.h" +#include "video/manager.h" #include "historymodel.h" #include "instantmessagingmodel.h" #include "useractionmodel.h" @@ -44,7 +44,7 @@ #include "numbercategory.h" #include "phonedirectorymodel.h" #include "phonenumber.h" -#include "video/videorenderer.h" +#include "video/renderer.h" #include "tlsmethodmodel.h" #include "audio/settings.h" #include "contactmodel.h" @@ -727,7 +727,7 @@ AbstractHistoryBackend* Call::backend() const bool Call::hasVideo() const { #ifdef ENABLE_VIDEO - return VideoManager::instance()->getRenderer(this) != nullptr; + return Video::Manager::instance()->getRenderer(this) != nullptr; #else return false; #endif @@ -783,10 +783,10 @@ bool Call::isSecure() const } //isSecure ///Return the renderer associated with this call or nullptr -VideoRenderer* Call::videoRenderer() const +Video::Renderer* Call::videoRenderer() const { #ifdef ENABLE_VIDEO - return VideoManager::instance()->getRenderer(this); + return Video::Manager::instance()->getRenderer(this); #else return nullptr; #endif diff --git a/src/call.h b/src/call.h index 89b3b72d4a20094284bbd60a61d5ef256c52155b..8ee0af5a4e431ced6aef2127c2300f28a05de9e8 100644 --- a/src/call.h +++ b/src/call.h @@ -32,12 +32,14 @@ class QTimer; #include "typedefs.h" #include "historytimecategorymodel.h" class Account; -class VideoRenderer; class InstantMessagingModel; class UserActionModel; class PhoneNumber; class TemporaryPhoneNumber; class AbstractHistoryBackend; +namespace Video { + class Renderer; +} class Call; @@ -248,7 +250,7 @@ public: Q_PROPERTY( uint stopTimeStamp READ stopTimeStamp ) Q_PROPERTY( uint startTimeStamp READ startTimeStamp ) Q_PROPERTY( bool isSecure READ isSecure ) - Q_PROPERTY( VideoRenderer* videoRenderer READ videoRenderer ) + Q_PROPERTY( Video::Renderer* videoRenderer READ videoRenderer ) Q_PROPERTY( QString formattedName READ formattedName ) Q_PROPERTY( QString length READ length ) Q_PROPERTY( bool hasRecording READ hasRecording ) @@ -289,7 +291,7 @@ public: const QString transferNumber () const; const QString dialNumber () const; const QString recordingPath () const; - VideoRenderer* videoRenderer () const; + Video::Renderer* videoRenderer () const; const QString formattedName () const; bool hasRecording () const; QString length () const; diff --git a/src/phonenumber.cpp b/src/phonenumber.cpp index 453b505f1797238947f6d0c72af3dba7ee6050ca..ec69db2275b53c90b8e856ee7d2667deb0549d93 100644 --- a/src/phonenumber.cpp +++ b/src/phonenumber.cpp @@ -118,7 +118,7 @@ const PhoneNumber* PhoneNumber::BLANK() { if (!m_spBlank) { m_spBlank = new PhoneNumber(QString(),NumberCategoryModel::other()); - const_cast<PhoneNumber*>(m_spBlank)->d->m_Type = PhoneNumber::Type::BLANK; + const_cast<PhoneNumber*>(m_spBlank)->d_ptr->m_Type = PhoneNumber::Type::BLANK; } return m_spBlank; } @@ -132,156 +132,156 @@ PrivatePhoneNumber::PrivatePhoneNumber(const URI& uri, NumberCategory* cat, Phon ///Constructor PhoneNumber::PhoneNumber(const URI& number, NumberCategory* cat, Type st) : QObject(PhoneDirectoryModel::instance()), -d(new PrivatePhoneNumber(number,cat,st)) +d_ptr(new PrivatePhoneNumber(number,cat,st)) { - setObjectName(d->m_Uri); - d->m_hasType = cat != NumberCategoryModel::other(); - if (d->m_hasType) { + setObjectName(d_ptr->m_Uri); + d_ptr->m_hasType = cat != NumberCategoryModel::other(); + if (d_ptr->m_hasType) { NumberCategoryModel::instance()->registerNumber(this); } - d->m_lParents << this; + d_ptr->m_lParents << this; } PhoneNumber::~PhoneNumber() { - d->m_lParents.removeAll(this); - if (!d->m_lParents.size()) - delete d; + d_ptr->m_lParents.removeAll(this); + if (!d_ptr->m_lParents.size()) + delete d_ptr; } ///Return if this number presence is being tracked bool PhoneNumber::isTracked() const { //If the number doesn't support it, ignore the flag - return supportPresence() && d->m_Tracked; + return supportPresence() && d_ptr->m_Tracked; } ///Is this number present bool PhoneNumber::isPresent() const { - return d->m_Tracked && d->m_Present; + return d_ptr->m_Tracked && d_ptr->m_Present; } ///This number presence status string QString PhoneNumber::presenceMessage() const { - return d->m_PresentMessage; + return d_ptr->m_PresentMessage; } ///Return the number URI PhoneNumber::uri() const { - return d->m_Uri ; + return d_ptr->m_Uri ; } ///This phone number has a type bool PhoneNumber::hasType() const { - return d->m_hasType; + return d_ptr->m_hasType; } ///Protected getter to get the number index int PhoneNumber::index() const { - return d->m_Index; + return d_ptr->m_Index; } ///Return the phone number type NumberCategory* PhoneNumber::category() const { - return d->m_pCategory ; + return d_ptr->m_pCategory ; } ///Return this number associated account, if any Account* PhoneNumber::account() const { - return d->m_pAccount; + return d_ptr->m_pAccount; } ///Return this number associated contact, if any Contact* PhoneNumber::contact() const { - return d->m_pContact; + return d_ptr->m_pContact; } ///Return when this number was last used time_t PhoneNumber::lastUsed() const { - return d->m_LastUsed; + return d_ptr->m_LastUsed; } ///Set this number default account void PhoneNumber::setAccount(Account* account) { - d->m_pAccount = account; - if (d->m_pAccount) - connect (d->m_pAccount,SIGNAL(destroyed(QObject*)),this,SLOT(accountDestroyed(QObject*))); - d->changed(); + d_ptr->m_pAccount = account; + if (d_ptr->m_pAccount) + connect (d_ptr->m_pAccount,SIGNAL(destroyed(QObject*)),this,SLOT(accountDestroyed(QObject*))); + d_ptr->changed(); } ///Set this number contact void PhoneNumber::setContact(Contact* contact) { - d->m_pContact = contact; - if (contact && d->m_Type != PhoneNumber::Type::TEMPORARY) { - PhoneDirectoryModel::instance()->d_ptr->indexNumber(this,d->m_hNames.keys()+QStringList(contact->formattedName())); - d->m_PrimaryName_cache = contact->formattedName(); - d->primaryNameChanged(d->m_PrimaryName_cache); + d_ptr->m_pContact = contact; + if (contact && d_ptr->m_Type != PhoneNumber::Type::TEMPORARY) { + PhoneDirectoryModel::instance()->d_ptr->indexNumber(this,d_ptr->m_hNames.keys()+QStringList(contact->formattedName())); + d_ptr->m_PrimaryName_cache = contact->formattedName(); + d_ptr->primaryNameChanged(d_ptr->m_PrimaryName_cache); connect(contact,SIGNAL(rebased(Contact*)),this,SLOT(contactRebased(Contact*))); } - d->changed(); + d_ptr->changed(); } ///Protected setter to set if there is a type void PhoneNumber::setHasType(bool value) { - d->m_hasType = value; + d_ptr->m_hasType = value; } ///Protected setter to set the PhoneDirectoryModel index void PhoneNumber::setIndex(int value) { - d->m_Index = value; + d_ptr->m_Index = value; } ///Protected setter to change the popularity index void PhoneNumber::setPopularityIndex(int value) { - d->m_PopularityIndex = value; + d_ptr->m_PopularityIndex = value; } void PhoneNumber::setCategory(NumberCategory* cat) { - if (cat == d->m_pCategory) return; - if (d->m_hasType) + if (cat == d_ptr->m_pCategory) return; + if (d_ptr->m_hasType) NumberCategoryModel::instance()->unregisterNumber(this); - d->m_hasType = cat != NumberCategoryModel::other(); - d->m_pCategory = cat; - if (d->m_hasType) + d_ptr->m_hasType = cat != NumberCategoryModel::other(); + d_ptr->m_pCategory = cat; + if (d_ptr->m_hasType) NumberCategoryModel::instance()->registerNumber(this); - d->changed(); + d_ptr->changed(); } void PhoneNumber::setBookmarked(bool bookmarked ) { - d->m_IsBookmark = bookmarked; + d_ptr->m_IsBookmark = bookmarked; } ///Force an Uid on this number (instead of hash) void PhoneNumber::setUid(const QString& uri) { - d->m_Uid = uri; + d_ptr->m_Uid = uri; } ///Attempt to change the number type bool PhoneNumber::setType(PhoneNumber::Type t) { - if (d->m_Type == PhoneNumber::Type::BLANK) + if (d_ptr->m_Type == PhoneNumber::Type::BLANK) return false; if (account() && t == PhoneNumber::Type::ACCOUNT) { if (account()->supportPresenceSubscribe()) { - d->m_Tracked = true; //The daemon will init the tracker itself - d->trackedChanged(true); + d_ptr->m_Tracked = true; //The daemon will init the tracker itself + d_ptr->trackedChanged(true); } - d->m_Type = t; + d_ptr->m_Type = t; return true; } return false; @@ -290,72 +290,72 @@ bool PhoneNumber::setType(PhoneNumber::Type t) ///Set if this number is tracking presence information void PhoneNumber::setTracked(bool track) { - if (track != d->m_Tracked) { //Subscribe only once + if (track != d_ptr->m_Tracked) { //Subscribe only once //You can't subscribe without account - if (track && !d->m_pAccount) return; - d->m_Tracked = track; - DBus::PresenceManager::instance().subscribeBuddy(d->m_pAccount->id(),uri().fullUri(),track); - d->changed(); - d->trackedChanged(track); + if (track && !d_ptr->m_pAccount) return; + d_ptr->m_Tracked = track; + DBus::PresenceManager::instance().subscribeBuddy(d_ptr->m_pAccount->id(),uri().fullUri(),track); + d_ptr->changed(); + d_ptr->trackedChanged(track); } } ///Allow phonedirectorymodel to change presence status void PhoneNumber::setPresent(bool present) { - if (d->m_Present != present) { - d->m_Present = present; - d->presentChanged(present); + if (d_ptr->m_Present != present) { + d_ptr->m_Present = present; + d_ptr->presentChanged(present); } } void PhoneNumber::setPresenceMessage(const QString& message) { - if (d->m_PresentMessage != message) { - d->m_PresentMessage = message; - d->presenceMessageChanged(message); + if (d_ptr->m_PresentMessage != message) { + d_ptr->m_PresentMessage = message; + d_ptr->presenceMessageChanged(message); } } ///Return the current type of the number PhoneNumber::Type PhoneNumber::type() const { - return d->m_Type; + return d_ptr->m_Type; } ///Return the number of calls from this number int PhoneNumber::callCount() const { - return d->m_lCalls.size(); + return d_ptr->m_lCalls.size(); } uint PhoneNumber::weekCount() const { - return d->m_LastWeekCount; + return d_ptr->m_LastWeekCount; } uint PhoneNumber::trimCount() const { - return d->m_LastTrimCount; + return d_ptr->m_LastTrimCount; } bool PhoneNumber::haveCalled() const { - return d->m_HaveCalled; + return d_ptr->m_HaveCalled; } ///Best bet for this person real name QString PhoneNumber::primaryName() const { //Compute the primary name - if (d->m_PrimaryName_cache.isEmpty()) { + if (d_ptr->m_PrimaryName_cache.isEmpty()) { QString ret; - if (d->m_hNames.size() == 1) - ret = d->m_hNames.constBegin().key(); + if (d_ptr->m_hNames.size() == 1) + ret = d_ptr->m_hNames.constBegin().key(); else { QString toReturn = tr("Unknown"); int max = 0; - for (QHash<QString,int>::const_iterator i = d->m_hNames.begin(); i != d->m_hNames.end(); ++i) { + for (QHash<QString,int>::const_iterator i = d_ptr->m_hNames.begin(); i != d_ptr->m_hNames.end(); ++i) { if (i.value() > max) { max = i.value(); toReturn = i.key (); @@ -363,32 +363,32 @@ QString PhoneNumber::primaryName() const } ret = toReturn; } - const_cast<PhoneNumber*>(this)->d->m_PrimaryName_cache = ret; - const_cast<PhoneNumber*>(this)->d->primaryNameChanged(d->m_PrimaryName_cache); + const_cast<PhoneNumber*>(this)->d_ptr->m_PrimaryName_cache = ret; + const_cast<PhoneNumber*>(this)->d_ptr->primaryNameChanged(d_ptr->m_PrimaryName_cache); } //Fallback: Use the URI - if (d->m_PrimaryName_cache.isEmpty()) { + if (d_ptr->m_PrimaryName_cache.isEmpty()) { return uri(); } //Return the cached primaryname - return d->m_PrimaryName_cache; + return d_ptr->m_PrimaryName_cache; } ///Is this number bookmarked bool PhoneNumber::isBookmarked() const { - return d->m_IsBookmark; + return d_ptr->m_IsBookmark; } ///If this number could (theoretically) support presence status bool PhoneNumber::supportPresence() const { //Without an account, presence is impossible - if (!d->m_pAccount) + if (!d_ptr->m_pAccount) return false; //The account also have to support it - if (!d->m_pAccount->supportPresenceSubscribe()) + if (!d_ptr->m_pAccount->supportPresenceSubscribe()) return false; //In the end, it all come down to this, is the number tracked @@ -404,53 +404,53 @@ QVariant PhoneNumber::icon() const ///The number of seconds spent with the URI (from history) int PhoneNumber::totalSpentTime() const { - return d->m_TotalSeconds; + return d_ptr->m_TotalSeconds; } ///Return this number unique identifier (hash) QString PhoneNumber::uid() const { - return d->m_Uid.isEmpty()?toHash():d->m_Uid; + return d_ptr->m_Uid.isEmpty()?toHash():d_ptr->m_Uid; } ///Return all calls from this number QList<Call*> PhoneNumber::calls() const { - return d->m_lCalls; + return d_ptr->m_lCalls; } ///Return the phonenumber position in the popularity index int PhoneNumber::popularityIndex() const { - return d->m_PopularityIndex; + return d_ptr->m_PopularityIndex; } QHash<QString,int> PhoneNumber::alternativeNames() const { - return d->m_hNames; + return d_ptr->m_hNames; } ///Add a call to the call list, notify listener void PhoneNumber::addCall(Call* call) { if (!call) return; - d->m_Type = PhoneNumber::Type::USED; - d->m_lCalls << call; - d->m_TotalSeconds += call->stopTimeStamp() - call->startTimeStamp(); + d_ptr->m_Type = PhoneNumber::Type::USED; + d_ptr->m_lCalls << call; + d_ptr->m_TotalSeconds += call->stopTimeStamp() - call->startTimeStamp(); time_t now; ::time ( &now ); if (now - 3600*24*7 < call->stopTimeStamp()) - d->m_LastWeekCount++; + d_ptr->m_LastWeekCount++; if (now - 3600*24*7*15 < call->stopTimeStamp()) - d->m_LastTrimCount++; + d_ptr->m_LastTrimCount++; if (call->historyState() == Call::LegacyHistoryState::OUTGOING || call->direction() == Call::Direction::OUTGOING) - d->m_HaveCalled = true; + d_ptr->m_HaveCalled = true; - d->callAdded(call); - if (call->startTimeStamp() > d->m_LastUsed) - d->m_LastUsed = call->startTimeStamp(); - d->changed(); + d_ptr->callAdded(call); + if (call->startTimeStamp() > d_ptr->m_LastUsed) + d_ptr->m_LastUsed = call->startTimeStamp(); + d_ptr->changed(); } ///Generate an unique representation of this number @@ -464,20 +464,20 @@ QString PhoneNumber::toHash() const ///Increment name counter and update indexes void PhoneNumber::incrementAlternativeName(const QString& name) { - const bool needReIndexing = !d->m_hNames[name]; - d->m_hNames[name]++; - if (needReIndexing && d->m_Type != PhoneNumber::Type::TEMPORARY) { - PhoneDirectoryModel::instance()->d_ptr->indexNumber(this,d->m_hNames.keys()+(d->m_pContact?(QStringList(d->m_pContact->formattedName())):QStringList())); + const bool needReIndexing = !d_ptr->m_hNames[name]; + d_ptr->m_hNames[name]++; + if (needReIndexing && d_ptr->m_Type != PhoneNumber::Type::TEMPORARY) { + PhoneDirectoryModel::instance()->d_ptr->indexNumber(this,d_ptr->m_hNames.keys()+(d_ptr->m_pContact?(QStringList(d_ptr->m_pContact->formattedName())):QStringList())); //Invalid m_PrimaryName_cache - if (!d->m_pContact) - d->m_PrimaryName_cache.clear(); + if (!d_ptr->m_pContact) + d_ptr->m_PrimaryName_cache.clear(); } } void PhoneNumber::accountDestroyed(QObject* o) { - if (o == d->m_pAccount) - d->m_pAccount = nullptr; + if (o == d_ptr->m_pAccount) + d_ptr->m_pAccount = nullptr; } /** @@ -486,12 +486,12 @@ void PhoneNumber::accountDestroyed(QObject* o) */ void PhoneNumber::contactRebased(Contact* other) { - d->m_PrimaryName_cache = other->formattedName(); - d->primaryNameChanged(d->m_PrimaryName_cache); - d->changed(); + d_ptr->m_PrimaryName_cache = other->formattedName(); + d_ptr->primaryNameChanged(d_ptr->m_PrimaryName_cache); + d_ptr->changed(); //It is a "partial" rebase, so the PhoneNumber data stay the same - d->rebased(this); + d_ptr->rebased(this); } /** @@ -503,7 +503,7 @@ void PhoneNumber::contactRebased(Contact* other) bool PhoneNumber::merge(PhoneNumber* other) { - if ((!other) || other == this || other->d == d) + if ((!other) || other == this || other->d_ptr == d_ptr) return false; //This is invalid, those are different numbers @@ -516,20 +516,20 @@ bool PhoneNumber::merge(PhoneNumber* other) //TODO Handle presence - PrivatePhoneNumber* currentD = d; + PrivatePhoneNumber* currentD = d_ptr; //Replace the D-Pointer - this->d = other->d; - d->m_lParents << this; + this->d_ptr= other->d_ptr; + d_ptr->m_lParents << this; //In case the URI is different, take the longest and most precise //TODO keep a log of all URI used - if (currentD->m_Uri.size() > other->d->m_Uri.size()) { - other->d->m_lOtherURIs << other->d->m_Uri; - other->d->m_Uri = currentD->m_Uri; + if (currentD->m_Uri.size() > other->d_ptr->m_Uri.size()) { + other->d_ptr->m_lOtherURIs << other->d_ptr->m_Uri; + other->d_ptr->m_Uri = currentD->m_Uri; } else - other->d->m_lOtherURIs << currentD->m_Uri; + other->d_ptr->m_lOtherURIs << currentD->m_Uri; emit changed(); emit rebased(other); @@ -542,22 +542,22 @@ bool PhoneNumber::merge(PhoneNumber* other) bool PhoneNumber::operator==(PhoneNumber* other) { - return other && this->d == other->d; + return other && this->d_ptr== other->d_ptr; } bool PhoneNumber::operator==(const PhoneNumber* other) const { - return other && this->d == other->d; + return other && this->d_ptr== other->d_ptr; } bool PhoneNumber::operator==(PhoneNumber& other) { - return &other && this->d == other.d; + return &other && this->d_ptr== other.d_ptr; } bool PhoneNumber::operator==(const PhoneNumber& other) const { - return &other && this->d == other.d; + return &other && this->d_ptr== other.d_ptr; } /************************************************************************************ @@ -568,8 +568,8 @@ bool PhoneNumber::operator==(const PhoneNumber& other) const void TemporaryPhoneNumber::setUri(const QString& uri) { - d->m_Uri = uri; - d->changed(); + d_ptr->m_Uri = uri; + d_ptr->changed(); } ///Constructor diff --git a/src/phonenumber.h b/src/phonenumber.h index 35788661d1730a8199b7d05012f93edb3047b351..ba5c1efa3fae6fd5b91becf02d0b595db871fc8a 100644 --- a/src/phonenumber.h +++ b/src/phonenumber.h @@ -150,7 +150,7 @@ protected: void setPopularityIndex(int value); //Many phone numbers can have the same "d" if they were merged - PrivatePhoneNumber* d; + PrivatePhoneNumber* d_ptr; private: friend class PhoneNumberPrivate; diff --git a/src/private/videochannel_p.h b/src/private/videochannel_p.h index 9993a6802100e7172dfb3640cab35fe4c2925f12..3659b797734c6cbbcfa97c841029fcc2ccc1fccc 100644 --- a/src/private/videochannel_p.h +++ b/src/private/videochannel_p.h @@ -22,10 +22,10 @@ class VideoChannelPrivate { public: VideoChannelPrivate(); - QString m_Name; - QList<VideoResolution*> m_lValidResolutions; - VideoResolution* m_pCurrentResolution; - VideoDevice* m_pDevice; + QString m_Name; + QList<Video::Resolution*> m_lValidResolutions; + Video::Resolution* m_pCurrentResolution; + Video::Device* m_pDevice; }; #endif \ No newline at end of file diff --git a/src/private/videocodec_p.h b/src/private/videocodec_p.h index e4db32414492096f98862188a291aca56aaf84c8..ea7bafa027d383b7129511eca91fb22d0b97fd21 100644 --- a/src/private/videocodec_p.h +++ b/src/private/videocodec_p.h @@ -18,7 +18,7 @@ #ifndef VIDEOCODECPRIVATE_H #define VIDEOCODECPRIVATE_H -typedef QHash<QString,VideoCodec*> CodecHash; +typedef QHash<QString,Video::Codec*> CodecHash; class VideoCodecPrivate { diff --git a/src/private/videodevice_p.h b/src/private/videodevice_p.h index 4cbc417d4fab1ee64ac00722e9254603003be2ba..716d6a0cb6302e6094ebd9a35a62410f976d6c7c 100644 --- a/src/private/videodevice_p.h +++ b/src/private/videodevice_p.h @@ -29,12 +29,12 @@ public: constexpr static const char* SIZE = "size" ; }; - VideoDevicePrivate(); + explicit VideoDevicePrivate(); //Attributes - QString m_DeviceId ; - VideoChannel* m_pCurrentChannel; - QList<VideoChannel*> m_lChannels ; + QString m_DeviceId ; + Video::Channel* m_pCurrentChannel; + QList<Video::Channel*> m_lChannels ; }; #endif \ No newline at end of file diff --git a/src/uri.cpp b/src/uri.cpp index 4fb7b978dadcdb26505c709f329a02c6caf3cde8..fd1b4fe20a09a5cdaf97ffedffa3ef60b177c457 100644 --- a/src/uri.cpp +++ b/src/uri.cpp @@ -19,10 +19,10 @@ constexpr const char* URI::schemeNames[]; -class UriPrivate +class URIPrivate { public: - UriPrivate(QString* uri); + URIPrivate(QString* uri); //Attributes QString m_Hostname ; QString m_Userinfo ; @@ -39,17 +39,17 @@ private: QString* q_ptr; }; -UriPrivate::UriPrivate(QString* uri) : m_Parsed(false),m_HeaderType(URI::SchemeType::NONE),q_ptr(uri) +URIPrivate::URIPrivate(QString* uri) : m_Parsed(false),m_HeaderType(URI::SchemeType::NONE),q_ptr(uri) { } -URI::URI(const QString& other):QString(), d_ptr(new UriPrivate(this)) +URI::URI(const QString& other):QString(), d_ptr(new URIPrivate(this)) { - d_ptr->m_Stripped = UriPrivate::strip(other,d_ptr->m_HeaderType); + d_ptr->m_Stripped = URIPrivate::strip(other,d_ptr->m_HeaderType); (*static_cast<QString*>(this)) = d_ptr->m_Stripped ; } -URI::URI(const URI& o):QString(), d_ptr(new UriPrivate(this)) +URI::URI(const URI& o):QString(), d_ptr(new URIPrivate(this)) { d_ptr->m_Parsed = o.d_ptr->m_Parsed ; d_ptr->m_Hostname = o.d_ptr->m_Hostname ; @@ -62,11 +62,25 @@ URI::URI(const URI& o):QString(), d_ptr(new UriPrivate(this)) URI::~URI() { + (*static_cast<QString*>(this)) = QString(); + d_ptr->m_Stripped = QString(); delete d_ptr; } +URI& URI::operator=(const URI& o) +{ + d_ptr->m_Parsed = o.d_ptr->m_Parsed ; + d_ptr->m_Hostname = o.d_ptr->m_Hostname ; + d_ptr->m_HeaderType = o.d_ptr->m_HeaderType; + d_ptr->m_Userinfo = o.d_ptr->m_Userinfo ; + d_ptr->m_Stripped = o.d_ptr->m_Stripped ; + + (*static_cast<QString*>(this)) = o.d_ptr->m_Stripped; + return (*this); +} + ///Strip out <sip:****> from the URI -QString UriPrivate::strip(const QString& uri, URI::SchemeType& sheme) +QString URIPrivate::strip(const QString& uri, URI::SchemeType& sheme) { if (uri.isEmpty()) return QString(); @@ -105,7 +119,7 @@ bool URI::hasHostname() const } ///Keep a cache of the values to avoid re-parsing them -void UriPrivate::parse() +void URIPrivate::parse() { if (q_ptr->indexOf('@') != -1) { const QStringList splitted = q_ptr->split('@'); diff --git a/src/uri.h b/src/uri.h index 896274d26fb0c8b2d874036cf086440a61135166..e4ec4b7bb4facaf06b4d82ce4b970f53379170e6 100644 --- a/src/uri.h +++ b/src/uri.h @@ -22,7 +22,7 @@ #include <QStringList> -class UriPrivate; +class URIPrivate; /** * @class URI A specialised string with multiple attributes @@ -116,8 +116,9 @@ public: QString userinfo () const; bool hasHostname() const; + URI& operator=(const URI&); private: - UriPrivate* d_ptr; + URIPrivate* d_ptr; }; // Q_DECLARE_METATYPE(URI*) diff --git a/src/video/videochannel.cpp b/src/video/channel.cpp similarity index 79% rename from src/video/videochannel.cpp rename to src/video/channel.cpp index 105de01b163cec95fba1db51723bfe98f4a06999..233626b8e9f3778b25cacfa8eff6815d15dc3a25 100644 --- a/src/video/videochannel.cpp +++ b/src/video/channel.cpp @@ -15,11 +15,11 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************/ -#include "videochannel.h" +#include "channel.h" //SFLphone -#include "videoresolution.h" -#include "videodevice.h" +#include "resolution.h" +#include "device.h" #include "../dbus/videomanager.h" #include "../private/videochannel_p.h" #include "../private/videodevice_p.h" @@ -28,19 +28,19 @@ VideoChannelPrivate::VideoChannelPrivate() : m_pCurrentResolution(nullptr) { } -VideoChannel::VideoChannel(VideoDevice* dev,const QString& name) : QAbstractListModel(dev), +Video::Channel::Channel(Video::Device* dev,const QString& name) : QAbstractListModel(dev), d_ptr(new VideoChannelPrivate()) { d_ptr->m_Name = name; d_ptr->m_pDevice = dev; } -VideoChannel::~VideoChannel() +Video::Channel::~Channel() { delete d_ptr; } -QVariant VideoChannel::data( const QModelIndex& index, int role) const +QVariant Video::Channel::data( const QModelIndex& index, int role) const { if (index.isValid() && role == Qt::DisplayRole) { return d_ptr->m_lValidResolutions[index.row()]->name(); @@ -48,19 +48,19 @@ QVariant VideoChannel::data( const QModelIndex& index, int role) const return QVariant(); } -int VideoChannel::rowCount( const QModelIndex& parent) const +int Video::Channel::rowCount( const QModelIndex& parent) const { return (parent.isValid())?0:d_ptr->m_lValidResolutions.size(); } -Qt::ItemFlags VideoChannel::flags( const QModelIndex& idx) const +Qt::ItemFlags Video::Channel::flags( const QModelIndex& idx) const { if (idx.column() == 0) return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; return QAbstractItemModel::flags(idx); } -bool VideoChannel::setData( const QModelIndex& index, const QVariant &value, int role) +bool Video::Channel::setData( const QModelIndex& index, const QVariant &value, int role) { Q_UNUSED(index) Q_UNUSED(value) @@ -68,17 +68,17 @@ bool VideoChannel::setData( const QModelIndex& index, const QVariant &value, int return false; } -int VideoChannel::relativeIndex() { +int Video::Channel::relativeIndex() { return d_ptr->m_pDevice->channelList().indexOf(this); } -bool VideoChannel::setActiveResolution(int idx) +bool Video::Channel::setActiveResolution(int idx) { if (idx < 0 || idx >= d_ptr->m_lValidResolutions.size()) return false; return setActiveResolution(d_ptr->m_lValidResolutions[idx]); } -bool VideoChannel::setActiveResolution(VideoResolution* res) { +bool Video::Channel::setActiveResolution(Video::Resolution* res) { if ((!res) || d_ptr->m_lValidResolutions.indexOf(res) == -1 || res->name().isEmpty()) { qWarning() << "Invalid active resolution" << (res?res->name():"NULL"); return false; @@ -88,13 +88,13 @@ bool VideoChannel::setActiveResolution(VideoResolution* res) { return true; } -VideoResolution* VideoChannel::activeResolution() +Video::Resolution* Video::Channel::activeResolution() { //If it is the current device, then there is "current" resolution if ((!d_ptr->m_pCurrentResolution) && d_ptr->m_pDevice->isActive()) { VideoManagerInterface& interface = DBus::VideoManager::instance(); const QString res = QMap<QString,QString>(interface.getSettings(d_ptr->m_pDevice->id()))[VideoDevicePrivate::PreferenceNames::SIZE]; - foreach(VideoResolution* r, validResolutions()) { + foreach(Video::Resolution* r, validResolutions()) { if (r->name() == res) { d_ptr->m_pCurrentResolution = r; break; @@ -109,16 +109,16 @@ VideoResolution* VideoChannel::activeResolution() return d_ptr->m_pCurrentResolution; } -QString VideoChannel::name() const +QString Video::Channel::name() const { return d_ptr->m_Name; } -QList<VideoResolution*> VideoChannel::validResolutions() const +QList<Video::Resolution*> Video::Channel::validResolutions() const { return d_ptr->m_lValidResolutions; } -VideoDevice* VideoChannel::device() const +Video::Device* Video::Channel::device() const { return d_ptr->m_pDevice; } diff --git a/src/video/videochannel.h b/src/video/channel.h similarity index 79% rename from src/video/videochannel.h rename to src/video/channel.h index 6ebb72d52b2b95727439115492dab759189b8658..d7efe7989e64cd27a70196c6e391fd7bde7e2e99 100644 --- a/src/video/videochannel.h +++ b/src/video/channel.h @@ -21,24 +21,28 @@ #include "../typedefs.h" #include <QtCore/QAbstractListModel> -class VideoResolution; -class VideoDevice; +namespace Video { + class Resolution; + class Device; +} class VideoChannelPrivate; -///@typedef VideoChannel A channel available in a Device -class LIB_EXPORT VideoChannel : public QAbstractListModel +namespace Video { + +///@typedef Channel A channel available in a Device +class LIB_EXPORT Channel : public QAbstractListModel { - //Only VideoDevice can add resolutions - friend class VideoDevice; + //Only Video::Device can add resolutions + friend class Video::Device; public: QString name() const; - VideoResolution* activeResolution(); - QList<VideoResolution*> validResolutions() const; - VideoDevice* device() const; + Video::Resolution* activeResolution(); + QList<Video::Resolution*> validResolutions() const; + Video::Device* device() const; int relativeIndex(); - bool setActiveResolution(VideoResolution* res); + bool setActiveResolution(Video::Resolution* res); bool setActiveResolution(int idx); //Model @@ -48,10 +52,12 @@ public: virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override; private: - VideoChannel(VideoDevice* dev,const QString& name); - virtual ~VideoChannel(); + Channel(Video::Device* dev,const QString& name); + virtual ~Channel(); VideoChannelPrivate* d_ptr; }; +} + #endif diff --git a/src/video/videocodec.cpp b/src/video/codec.cpp similarity index 82% rename from src/video/videocodec.cpp rename to src/video/codec.cpp index 99ec95b64e8a1010135c08386c4e3a4a5a021240..9b9bf8232e860e46468eae890293b7fa92efe6b1 100644 --- a/src/video/videocodec.cpp +++ b/src/video/codec.cpp @@ -15,13 +15,13 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************/ -#include "videocodec.h" +#include "codec.h" #include "../private/videocodec_p.h" #include <account.h> -QHash<QString,VideoCodec*> VideoCodecPrivate::m_slCodecs; +QHash<QString,Video::Codec*> VideoCodecPrivate::m_slCodecs; bool VideoCodecPrivate::m_sInit = false; VideoCodecPrivate::VideoCodecPrivate() : m_Enabled(false),m_Bitrate(0) @@ -29,7 +29,7 @@ VideoCodecPrivate::VideoCodecPrivate() : m_Enabled(false),m_Bitrate(0) } ///Private constructor -VideoCodec::VideoCodec(const QString &codecName, uint bitRate, bool enabled) : QObject(nullptr), +Video::Codec::Codec(const QString &codecName, uint bitRate, bool enabled) : QObject(nullptr), d_ptr(new VideoCodecPrivate()) { d_ptr->m_Name = codecName; @@ -39,55 +39,55 @@ d_ptr(new VideoCodecPrivate()) setObjectName("VideoCodec"+codecName); } -VideoCodec::~VideoCodec() +Video::Codec::~Codec() { delete d_ptr; } ///Get the current codec name -QString VideoCodec::name() const +QString Video::Codec::name() const { return d_ptr->m_Name; } ///Get the current codec id -uint VideoCodec::bitrate() const +uint Video::Codec::bitrate() const { return d_ptr->m_Bitrate; } ///Get the current codec id -bool VideoCodec::isEnabled() const +bool Video::Codec::isEnabled() const { return d_ptr->m_Enabled; } ///Set the codec bitrate -void VideoCodec::setBitrate(const uint bitrate) +void Video::Codec::setBitrate(const uint bitrate) { d_ptr->m_Bitrate = bitrate; } ///Set if the codec is enabled -void VideoCodec::setEnabled(const bool enabled) +void Video::Codec::setEnabled(const bool enabled) { d_ptr->m_Enabled = enabled; } ///Set codec parameters -void VideoCodec::setParamaters(const QString& params ) +void Video::Codec::setParamaters(const QString& params ) { d_ptr->m_Parameters = params; } ///Get codec parameters -QString VideoCodec::parameters() const +QString Video::Codec::parameters() const { return d_ptr->m_Parameters; } ///Generate a daemon compatible codec representation -QMap<QString,QString> VideoCodec::toMap() const +QMap<QString,QString> Video::Codec::toMap() const { QMap<QString,QString> ret; ret[VideoCodecPrivate::CodecFields::ENABLED ] = isEnabled ()?"true":"false"; diff --git a/src/video/videocodec.h b/src/video/codec.h similarity index 87% rename from src/video/videocodec.h rename to src/video/codec.h index 4600d963a5e7cbb71b8b402782d18fa65125ebd2..c55788b5caabf4ed3f33086586d37cc5344ec465 100644 --- a/src/video/videocodec.h +++ b/src/video/codec.h @@ -22,14 +22,16 @@ #include <QtCore/QObject> class Account; -class VideoCodec; class VideoCodecPrivate; -///VideoCodec: Codecs used for video calls -class LIB_EXPORT VideoCodec : public QObject { +namespace Video { + + +///Codec: Codecs used for video calls +class LIB_EXPORT Codec : public QObject { Q_OBJECT - friend class VideoCodecModel; + friend class CodecModel2; public: //Properties Q_PROPERTY(QString name READ name ) @@ -38,7 +40,7 @@ class LIB_EXPORT VideoCodec : public QObject { Q_PROPERTY(QString parameters READ parameters WRITE setParamaters) //Static setters - static void setActiveCodecList(Account* account, QStringList codecs); +// static void setActiveCodecList(Account* account, const QStringList& codecs); //Getters QString name () const; @@ -54,10 +56,12 @@ class LIB_EXPORT VideoCodec : public QObject { private: //Constructor - VideoCodec(const QString &codecName, uint bitRate, bool enabled); - virtual ~VideoCodec(); + Codec(const QString &codecName, uint bitRate, bool enabled); + virtual ~Codec(); VideoCodecPrivate* d_ptr; }; +} + #endif diff --git a/src/video/videocodecmodel.cpp b/src/video/codecmodel2.cpp similarity index 76% rename from src/video/videocodecmodel.cpp rename to src/video/codecmodel2.cpp index ed68adc121217fd76f929cecf5486d9bee262dea..715c7b1c567ffdd7fdfcc44e724d39779c234d6b 100644 --- a/src/video/videocodecmodel.cpp +++ b/src/video/codecmodel2.cpp @@ -15,57 +15,70 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************/ -#include "videocodecmodel.h" +#include "codecmodel2.h" #include <call.h> #include <account.h> -#include <video/videocodec.h> +#include <video/codec.h> #include "../private/videocodec_p.h" #include "../dbus/videomanager.h" #include <QtCore/QCoreApplication> -class VideoCodecModelPrivate +namespace Video { +class CodecModelPrivate { public: - VideoCodecModelPrivate(); + CodecModelPrivate(); //Attrbutes - QList<VideoCodec*> m_lCodecs; - Account* m_pAccount; + QList<Video::Codec*> m_lCodecs; + Account* m_pAccount; }; +} -VideoCodecModelPrivate::VideoCodecModelPrivate() : m_pAccount(nullptr) +Video::CodecModelPrivate::CodecModelPrivate() : m_pAccount(nullptr) {} ///Constructor -VideoCodecModel::VideoCodecModel(Account* account) : QAbstractListModel(QCoreApplication::instance()),d_ptr(new VideoCodecModelPrivate()) +Video::CodecModel2::CodecModel2(Account* account) : QAbstractListModel(QCoreApplication::instance()),d_ptr(new Video::CodecModelPrivate()) { d_ptr->m_pAccount = account; reload(); } +///Destructor +Video::CodecModel2::~CodecModel2() +{ + while (d_ptr->m_lCodecs.size()) { + Video::Codec* c = d_ptr->m_lCodecs[0]; + d_ptr->m_lCodecs.removeAt(0); + delete c; + } + delete d_ptr; +} + ///Get data from the model -QVariant VideoCodecModel::data( const QModelIndex& idx, int role) const +QVariant Video::CodecModel2::data( const QModelIndex& idx, int role) const { if(idx.column() == 0 && role == Qt::DisplayRole) return QVariant(d_ptr->m_lCodecs[idx.row()]->name()); else if(idx.column() == 0 && role == Qt::CheckStateRole) { return QVariant(d_ptr->m_lCodecs[idx.row()]->isEnabled()?Qt::Checked:Qt::Unchecked); } - else if (idx.column() == 0 && role == VideoCodecModel::BITRATE_ROLE) + else if (idx.column() == 0 && role == Video::CodecModel2::BITRATE_ROLE) return QVariant(d_ptr->m_lCodecs[idx.row()]->bitrate()); return QVariant(); } ///The number of codec -int VideoCodecModel::rowCount( const QModelIndex& par ) const +int Video::CodecModel2::rowCount( const QModelIndex& par ) const { Q_UNUSED(par) return d_ptr->m_lCodecs.size(); } ///Items flag -Qt::ItemFlags VideoCodecModel::flags( const QModelIndex& idx ) const +Qt::ItemFlags Video::CodecModel2::flags( const QModelIndex& idx ) const { if (idx.column() == 0) return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; @@ -73,7 +86,7 @@ Qt::ItemFlags VideoCodecModel::flags( const QModelIndex& idx ) const } ///Set the codec data (codecs can't be added or removed that way) -bool VideoCodecModel::setData(const QModelIndex& idx, const QVariant &value, int role) +bool Video::CodecModel2::setData(const QModelIndex& idx, const QVariant &value, int role) { if (idx.column() == 0 && role == Qt::CheckStateRole) { @@ -83,7 +96,7 @@ bool VideoCodecModel::setData(const QModelIndex& idx, const QVariant &value, int emit dataChanged(idx, idx); return true; } - else if (idx.column() == 0 && role == VideoCodecModel::BITRATE_ROLE) { + else if (idx.column() == 0 && role == Video::CodecModel2::BITRATE_ROLE) { bool changed = d_ptr->m_lCodecs[idx.row()]->bitrate() != value.toUInt(); d_ptr->m_lCodecs[idx.row()]->setBitrate(value.toInt()); if (changed) @@ -93,29 +106,18 @@ bool VideoCodecModel::setData(const QModelIndex& idx, const QVariant &value, int return false; } -///Destructor -VideoCodecModel::~VideoCodecModel() -{ - while (d_ptr->m_lCodecs.size()) { - VideoCodec* c = d_ptr->m_lCodecs[0]; - d_ptr->m_lCodecs.removeAt(0); - delete c; - } - delete d_ptr; -} - ///Force a model reload from dbus -void VideoCodecModel::reload() +void Video::CodecModel2::reload() { while (d_ptr->m_lCodecs.size()) { - VideoCodec* c = d_ptr->m_lCodecs[0]; + Video::Codec* c = d_ptr->m_lCodecs[0]; d_ptr->m_lCodecs.removeAt(0); delete c; } VideoManagerInterface& interface = DBus::VideoManager::instance(); const VectorMapStringString codecs = interface.getCodecs(d_ptr->m_pAccount->id()); foreach(const MapStringString& h,codecs) { - VideoCodec* c = new VideoCodec(h[VideoCodecPrivate::CodecFields::NAME], + Video::Codec* c = new Video::Codec(h[VideoCodecPrivate::CodecFields::NAME], h[VideoCodecPrivate::CodecFields::BITRATE].toInt(), h[VideoCodecPrivate::CodecFields::ENABLED]=="true"); c->setParamaters(h[VideoCodecPrivate::CodecFields::PARAMETERS]); @@ -125,21 +127,21 @@ void VideoCodecModel::reload() } ///Save the current model over dbus -void VideoCodecModel::save() +void Video::CodecModel2::save() { VideoManagerInterface& interface = DBus::VideoManager::instance(); VectorMapStringString toSave; - foreach(VideoCodec* vc, d_ptr->m_lCodecs) { + foreach(Video::Codec* vc, d_ptr->m_lCodecs) { toSave << vc->toMap(); } interface.setCodecs(d_ptr->m_pAccount->id(),toSave); } ///Increase codec priority -bool VideoCodecModel::moveUp(QModelIndex idx) +bool Video::CodecModel2::moveUp(const QModelIndex& idx) { if(idx.row() > 0 && idx.row() <= rowCount()) { - VideoCodec* data2 = d_ptr->m_lCodecs[idx.row()]; + Video::Codec* data2 = d_ptr->m_lCodecs[idx.row()]; d_ptr->m_lCodecs.removeAt(idx.row()); d_ptr->m_lCodecs.insert(idx.row() - 1, data2); emit dataChanged(index(idx.row() - 1, 0, QModelIndex()), index(idx.row(), 0, QModelIndex())); @@ -149,10 +151,10 @@ bool VideoCodecModel::moveUp(QModelIndex idx) } ///Decrease codec priority -bool VideoCodecModel::moveDown(QModelIndex idx) +bool Video::CodecModel2::moveDown(const QModelIndex& idx) { if(idx.row() >= 0 && idx.row() < rowCount()) { - VideoCodec* data2 = d_ptr->m_lCodecs[idx.row()]; + Video::Codec* data2 = d_ptr->m_lCodecs[idx.row()]; d_ptr->m_lCodecs.removeAt(idx.row()); d_ptr->m_lCodecs.insert(idx.row() + 1, data2); emit dataChanged(index(idx.row(), 0, QModelIndex()), index(idx.row() + 1, 0, QModelIndex())); diff --git a/src/video/videocodecmodel.h b/src/video/codecmodel2.h similarity index 84% rename from src/video/videocodecmodel.h rename to src/video/codecmodel2.h index 8fee8bf41244b697a3d6ec02735574ba3c522853..14a730a7932c2bc43e9223c4fc217936fef37af2 100644 --- a/src/video/videocodecmodel.h +++ b/src/video/codecmodel2.h @@ -27,13 +27,19 @@ class Account; //Typedef -class VideoCodec; -typedef QHash<QString,VideoCodec*> CodecHash; +namespace Video { + class Codec; +} -class VideoCodecModelPrivate; +typedef QHash<QString,Video::Codec*> CodecHash; + + +namespace Video { + +class CodecModelPrivate; ///Abstract model for managing account video codec list -class LIB_EXPORT VideoCodecModel : public QAbstractListModel { +class LIB_EXPORT CodecModel2 : public QAbstractListModel { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" Q_OBJECT @@ -41,8 +47,8 @@ class LIB_EXPORT VideoCodecModel : public QAbstractListModel { public: //Private constructor, can only be called by 'Account' - explicit VideoCodecModel(Account* account = nullptr); - virtual ~VideoCodecModel(); + explicit CodecModel2(Account* account = nullptr); + virtual ~CodecModel2(); //Roles static const int BITRATE_ROLE = 101; @@ -55,12 +61,14 @@ public: void reload(); void save(); - bool moveUp (QModelIndex idx); - bool moveDown(QModelIndex idx); + bool moveUp (const QModelIndex& idx); + bool moveDown(const QModelIndex& idx); private: - VideoCodecModelPrivate* d_ptr; + CodecModelPrivate* d_ptr; }; -Q_DECLARE_METATYPE(VideoCodecModel*) + +} +Q_DECLARE_METATYPE(Video::CodecModel2*) #endif diff --git a/src/video/videodevice.cpp b/src/video/device.cpp similarity index 79% rename from src/video/videodevice.cpp rename to src/video/device.cpp index c9899618d48f9e2745bb1b4c724f893a63201f1a..87757d2a88c9f3e276c87ce7ed775a6efb0d1f08 100644 --- a/src/video/videodevice.cpp +++ b/src/video/device.cpp @@ -15,14 +15,14 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************/ -#include "videodevice.h" +#include "device.h" #include "../dbus/videomanager.h" #include "../private/videochannel_p.h" #include "../private/videodevice_p.h" -#include "videodevicemodel.h" -#include "videoresolution.h" -#include "videorate.h" -#include "videochannel.h" +#include "devicemodel.h" +#include "resolution.h" +#include "rate.h" +#include "channel.h" @@ -31,7 +31,7 @@ VideoDevicePrivate::VideoDevicePrivate() : m_pCurrentChannel(nullptr) } ///Constructor -VideoDevice::VideoDevice(const QString &id) : QAbstractListModel(nullptr), +Video::Device::Device(const QString &id) : QAbstractListModel(nullptr), d_ptr(new VideoDevicePrivate()) { d_ptr->m_DeviceId = id; @@ -41,18 +41,18 @@ d_ptr(new VideoDevicePrivate()) while (channels.hasNext()) { channels.next(); - VideoChannel* chan = new VideoChannel(this,channels.key()); + Video::Channel* chan = new Video::Channel(this,channels.key()); d_ptr->m_lChannels << chan; QMapIterator<QString, VectorString> resolutions(channels.value()); while (resolutions.hasNext()) { resolutions.next(); - VideoResolution* res = new VideoResolution(resolutions.key(),chan); + Video::Resolution* res = new Video::Resolution(resolutions.key(),chan); chan->d_ptr->m_lValidResolutions << res; foreach(const QString& rate, resolutions.value()) { - VideoRate* r = new VideoRate(res,rate); + Video::Rate* r = new Video::Rate(res,rate); res->m_lValidRates << r; } } @@ -61,12 +61,12 @@ d_ptr(new VideoDevicePrivate()) } ///Destructor -VideoDevice::~VideoDevice() +Video::Device::~Device() { delete d_ptr; } -QVariant VideoDevice::data( const QModelIndex& index, int role) const +QVariant Video::Device::data( const QModelIndex& index, int role) const { if (index.isValid() && role == Qt::DisplayRole) { return d_ptr->m_lChannels[index.row()]->name(); @@ -74,19 +74,19 @@ QVariant VideoDevice::data( const QModelIndex& index, int role) const return QVariant(); } -int VideoDevice::rowCount( const QModelIndex& parent) const +int Video::Device::rowCount( const QModelIndex& parent) const { return (parent.isValid())?0:d_ptr->m_lChannels.size(); } -Qt::ItemFlags VideoDevice::flags( const QModelIndex& idx) const +Qt::ItemFlags Video::Device::flags( const QModelIndex& idx) const { if (idx.column() == 0) return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; return QAbstractItemModel::flags(idx); } -bool VideoDevice::setData( const QModelIndex& index, const QVariant &value, int role) +bool Video::Device::setData( const QModelIndex& index, const QVariant &value, int role) { Q_UNUSED(index) Q_UNUSED(value) @@ -94,18 +94,18 @@ bool VideoDevice::setData( const QModelIndex& index, const QVariant &value, int return false; } -// int VideoDevice::relativeIndex() { +// int Video::Device::relativeIndex() { // return m_pDevice->channelList().indexOf(this); // } ///Get the valid channel list -QList<VideoChannel*> VideoDevice::channelList() const +QList<Video::Channel*> Video::Device::channelList() const { return d_ptr->m_lChannels; } ///Save the current settings -void VideoDevice::save() +void Video::Device::save() { //In case new (unsupported) fields are added, merge with existing VideoManagerInterface& interface = DBus::VideoManager::instance(); @@ -117,25 +117,25 @@ void VideoDevice::save() } ///Get the device id -const QString VideoDevice::id() const +const QString Video::Device::id() const { return d_ptr->m_DeviceId; } ///Get the device name -const QString VideoDevice::name() const +const QString Video::Device::name() const { VideoManagerInterface& interface = DBus::VideoManager::instance(); return QMap<QString,QString>(interface.getSettings(d_ptr->m_DeviceId))[VideoDevicePrivate::PreferenceNames::NAME];; } ///Is this device the default one -bool VideoDevice::isActive() const +bool Video::Device::isActive() const { - return VideoDeviceModel::instance()->activeDevice() == this; + return Video::DeviceModel::instance()->activeDevice() == this; } -bool VideoDevice::setActiveChannel(VideoChannel* chan) +bool Video::Device::setActiveChannel(Video::Channel* chan) { if (!chan || !d_ptr->m_lChannels.indexOf(chan)) { qWarning() << "Trying to set an invalid channel" << (chan?chan->name():"NULL") << "for" << id(); @@ -146,18 +146,18 @@ bool VideoDevice::setActiveChannel(VideoChannel* chan) return true; } -bool VideoDevice::setActiveChannel(int idx) +bool Video::Device::setActiveChannel(int idx) { if (idx < 0 || idx >= d_ptr->m_lChannels.size()) return false; return setActiveChannel(d_ptr->m_lChannels[idx]); } -VideoChannel* VideoDevice::activeChannel() const +Video::Channel* Video::Device::activeChannel() const { if (!d_ptr->m_pCurrentChannel) { VideoManagerInterface& interface = DBus::VideoManager::instance(); const QString chan = QMap<QString,QString>(interface.getSettings(d_ptr->m_DeviceId))[VideoDevicePrivate::PreferenceNames::CHANNEL]; - foreach(VideoChannel* c, d_ptr->m_lChannels) { + foreach(Video::Channel* c, d_ptr->m_lChannels) { if (c->name() == chan) { d_ptr->m_pCurrentChannel = c; break; diff --git a/src/video/videodevice.h b/src/video/device.h similarity index 57% rename from src/video/videodevice.h rename to src/video/device.h index a85c9b7e81c5e1776b53d8d5bd4905e83e9cce0d..981af1c813a3e4b40fd80d7fcba38dc6c132e40b 100644 --- a/src/video/videodevice.h +++ b/src/video/device.h @@ -26,47 +26,56 @@ #include <QtCore/QSize> //SFLPhone -class VideoRenderer; -class VideoResolution; -class VideoRate; -class VideoChannel; -class VideoDevice; -class VideoModel; +namespace Video { + class Renderer; + class Resolution; + class Rate; + class Channel; + class Device; + class Model; + class Manager; + class DeviceModel; + class ManagerPrivate; +} class VideoDevicePrivate; -///VideoDevice: V4L devices used to record video for video call -class LIB_EXPORT VideoDevice : public QAbstractListModel { +namespace Video { + + +///Device: V4L devices used to record video for video call +class LIB_EXPORT Device : public QAbstractListModel { Q_OBJECT - friend class VideoManager; - friend class VideoManagerPrivate; - friend class VideoDeviceModel; + friend class Video::Manager; + friend class Video::ManagerPrivate; + friend class Video::DeviceModel; + friend class VideoDevicePrivate; //Need to access the PreferenceNames table - friend class VideoChannel; - friend class Resolution; + friend class Video::Channel; + friend class Video::Resolution; public: //Constants constexpr static const char* NONE = ""; //Model - QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const; - int rowCount ( const QModelIndex& parent = QModelIndex() ) const; - Qt::ItemFlags flags ( const QModelIndex& index ) const; - virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) ; + virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; + virtual int rowCount ( const QModelIndex& parent = QModelIndex() ) const override; + virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; + virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override; //Getter - QList<VideoChannel*> channelList () const; - VideoChannel* activeChannel () const; - const QString id () const; - const QString name () const; - bool isActive () const; + QList<Channel*> channelList () const; + Video::Channel* activeChannel () const; + const QString id () const; + const QString name () const; + bool isActive () const; //Static getter //Setter - bool setActiveChannel(VideoChannel* chan); + bool setActiveChannel(Video::Channel* chan); bool setActiveChannel(int idx); //Mutator @@ -74,16 +83,17 @@ class LIB_EXPORT VideoDevice : public QAbstractListModel { private: //Constructor - explicit VideoDevice(const QString &id); - virtual ~VideoDevice(); + explicit Device(const QString& id); + virtual ~Device(); VideoDevicePrivate* d_ptr; - Q_DECLARE_PRIVATE(VideoDevice) Q_SIGNALS: - void renderingStarted(VideoRenderer*); - void renderingStopped(VideoRenderer*); + void renderingStarted(Video::Renderer*); + void renderingStopped(Video::Renderer*); void renderStateChanged(bool state); }; + +} #endif diff --git a/src/video/videodevicemodel.cpp b/src/video/devicemodel.cpp similarity index 67% rename from src/video/videodevicemodel.cpp rename to src/video/devicemodel.cpp index f612b707a08f0c6d74dda6f8b1224e54b9e953b3..8a6eb6a76e7aea930037edae45033cdf36f542fa 100644 --- a/src/video/videodevicemodel.cpp +++ b/src/video/devicemodel.cpp @@ -15,53 +15,53 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************/ -#include "videodevicemodel.h" -#include "videodevice.h" +#include "devicemodel.h" +#include "device.h" #include <call.h> #include <account.h> -#include "videocodec.h" +#include "codec.h" #include "../dbus/videomanager.h" #include <QtCore/QCoreApplication> -VideoDeviceModel* VideoDeviceModel::m_spInstance = nullptr; +Video::DeviceModel* Video::DeviceModel::m_spInstance = nullptr; - -class VideoDeviceModelPrivate +namespace Video { +class DeviceModelPrivate { public: - VideoDeviceModelPrivate(); + DeviceModelPrivate(); //Attrbutes - QHash<QString,VideoDevice*> m_hDevices ; - QList<VideoDevice*> m_lDevices ; - VideoDevice* m_pDummyDevice ; - VideoDevice* m_pActiveDevice; + QHash<QString,Video::Device*> m_hDevices ; + QList<Video::Device*> m_lDevices ; + Video::Device* m_pDummyDevice ; + Video::Device* m_pActiveDevice; }; +} - -VideoDeviceModelPrivate::VideoDeviceModelPrivate() : m_pDummyDevice(nullptr),m_pActiveDevice(nullptr) +Video::DeviceModelPrivate::DeviceModelPrivate() : m_pDummyDevice(nullptr),m_pActiveDevice(nullptr) { } ///Constructor -VideoDeviceModel::VideoDeviceModel() : QAbstractListModel(QCoreApplication::instance()), -d_ptr(new VideoDeviceModelPrivate()) +Video::DeviceModel::DeviceModel() : QAbstractListModel(QCoreApplication::instance()), +d_ptr(new Video::DeviceModelPrivate()) { m_spInstance = this; reload(); } -VideoDeviceModel* VideoDeviceModel::instance() +Video::DeviceModel* Video::DeviceModel::instance() { if (!m_spInstance) - m_spInstance = new VideoDeviceModel(); + m_spInstance = new Video::DeviceModel(); return m_spInstance; } ///Get data from the model -QVariant VideoDeviceModel::data( const QModelIndex& idx, int role) const +QVariant Video::DeviceModel::data( const QModelIndex& idx, int role) const { if(idx.column() == 0 && role == Qt::DisplayRole) return QVariant(d_ptr->m_lDevices[idx.row()]->id()); @@ -69,14 +69,14 @@ QVariant VideoDeviceModel::data( const QModelIndex& idx, int role) const } ///The number of codec -int VideoDeviceModel::rowCount( const QModelIndex& par ) const +int Video::DeviceModel::rowCount( const QModelIndex& par ) const { Q_UNUSED(par) return d_ptr->m_lDevices.size(); } ///Items flag -Qt::ItemFlags VideoDeviceModel::flags( const QModelIndex& idx ) const +Qt::ItemFlags Video::DeviceModel::flags( const QModelIndex& idx ) const { if (idx.column() == 0) return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; @@ -84,7 +84,7 @@ Qt::ItemFlags VideoDeviceModel::flags( const QModelIndex& idx ) const } ///Set the codec data (codecs can't be added or removed that way) -bool VideoDeviceModel::setData(const QModelIndex& idx, const QVariant &value, int role) +bool Video::DeviceModel::setData(const QModelIndex& idx, const QVariant &value, int role) { Q_UNUSED(idx) Q_UNUSED(value) @@ -93,10 +93,10 @@ bool VideoDeviceModel::setData(const QModelIndex& idx, const QVariant &value, in } ///Destructor -VideoDeviceModel::~VideoDeviceModel() +Video::DeviceModel::~DeviceModel() { while (d_ptr->m_lDevices.size()) { - VideoDevice* c = d_ptr->m_lDevices[0]; + Video::Device* c = d_ptr->m_lDevices[0]; d_ptr->m_lDevices.removeAt(0); delete c; } @@ -104,7 +104,7 @@ VideoDeviceModel::~VideoDeviceModel() } ///Save the current model over dbus -void VideoDeviceModel::setActive(const QModelIndex& idx) +void Video::DeviceModel::setActive(const QModelIndex& idx) { if (idx.isValid()) { VideoManagerInterface& interface = DBus::VideoManager::instance(); @@ -116,26 +116,26 @@ void VideoDeviceModel::setActive(const QModelIndex& idx) } ///Convenience -void VideoDeviceModel::setActive(const int idx) +void Video::DeviceModel::setActive(const int idx) { setActive(index(idx,0,QModelIndex())); } -void VideoDeviceModel::setActive(const VideoDevice* device) +void Video::DeviceModel::setActive(const Video::Device* device) { VideoManagerInterface& interface = DBus::VideoManager::instance(); - interface.setDefaultDevice(device?device->id():VideoDevice::NONE); - d_ptr->m_pActiveDevice = const_cast<VideoDevice*>(device); + interface.setDefaultDevice(device?device->id():Video::Device::NONE); + d_ptr->m_pActiveDevice = const_cast<Video::Device*>(device); emit changed(); - const int idx = d_ptr->m_lDevices.indexOf((VideoDevice*)device); + const int idx = d_ptr->m_lDevices.indexOf((Video::Device*)device); emit currentIndexChanged(idx); } -void VideoDeviceModel::reload() +void Video::DeviceModel::reload() { - QHash<QString,VideoDevice*> devicesHash; + QHash<QString,Video::Device*> devicesHash; VideoManagerInterface& interface = DBus::VideoManager::instance(); const QStringList deviceList = interface.getDeviceList(); if (deviceList.size() == d_ptr->m_hDevices.size()) { @@ -144,13 +144,13 @@ void VideoDeviceModel::reload() foreach(const QString& deviceName,deviceList) { if (!d_ptr->m_hDevices[deviceName]) { - devicesHash[deviceName] = new VideoDevice(deviceName); + devicesHash[deviceName] = new Video::Device(deviceName); } else { devicesHash[deviceName] = d_ptr->m_hDevices[deviceName]; } } - foreach(VideoDevice* dev, d_ptr->m_hDevices) { + foreach(Video::Device* dev, d_ptr->m_hDevices) { if (dev && devicesHash.key(dev).isEmpty()) { delete dev; } @@ -165,14 +165,14 @@ void VideoDeviceModel::reload() } -VideoDevice* VideoDeviceModel::activeDevice() const +Video::Device* Video::DeviceModel::activeDevice() const { if (!d_ptr->m_pActiveDevice) { VideoManagerInterface& interface = DBus::VideoManager::instance(); const QString deId = interface.getDefaultDevice(); if (!d_ptr->m_lDevices.size()) - const_cast<VideoDeviceModel*>(this)->reload(); - VideoDevice* dev = d_ptr->m_hDevices[deId]; + const_cast<Video::DeviceModel*>(this)->reload(); + Video::Device* dev = d_ptr->m_hDevices[deId]; //Handling null everywhere is too long, better create a dummy device and //log the event @@ -180,7 +180,7 @@ VideoDevice* VideoDeviceModel::activeDevice() const if (!deId.isEmpty()) qWarning() << "Requested unknown device" << deId; if (!d_ptr->m_pDummyDevice) - d_ptr->m_pDummyDevice = new VideoDevice("None"); + d_ptr->m_pDummyDevice = new Video::Device("None"); return d_ptr->m_pDummyDevice; } d_ptr->m_pActiveDevice = dev; @@ -189,18 +189,18 @@ VideoDevice* VideoDeviceModel::activeDevice() const } -int VideoDeviceModel::activeIndex() const +int Video::DeviceModel::activeIndex() const { return d_ptr->m_lDevices.indexOf(activeDevice()); } -VideoDevice* VideoDeviceModel::getDevice(const QString& devId) const +Video::Device* Video::DeviceModel::getDevice(const QString& devId) const { return d_ptr->m_hDevices[devId]; } -QList<VideoDevice*> VideoDeviceModel::devices() const +QList<Video::Device*> Video::DeviceModel::devices() const { return d_ptr->m_lDevices; } diff --git a/src/video/videodevicemodel.h b/src/video/devicemodel.h similarity index 82% rename from src/video/videodevicemodel.h rename to src/video/devicemodel.h index 0529ec7013e040d0034f151a0a364fcca410bab4..73f7e30487c7748d7991546178afb9f6a6166241 100644 --- a/src/video/videodevicemodel.h +++ b/src/video/devicemodel.h @@ -22,15 +22,18 @@ #include <QtCore/QAbstractListModel> #include <QtCore/QUrl> #include <QtCore/QRect> -#include "videodevice.h" +#include "device.h" //Qt -class VideoDeviceModelPrivate; + +namespace Video { + +class DeviceModelPrivate; ///Abstract model for managing account video codec list -class LIB_EXPORT VideoDeviceModel : public QAbstractListModel { +class LIB_EXPORT DeviceModel : public QAbstractListModel { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" Q_OBJECT @@ -38,8 +41,8 @@ class LIB_EXPORT VideoDeviceModel : public QAbstractListModel { public: //Private constructor, can only be called by 'Account' - explicit VideoDeviceModel(); - virtual ~VideoDeviceModel(); + explicit DeviceModel(); + virtual ~DeviceModel(); //Model functions virtual QVariant data ( const QModelIndex& index, int role = Qt::DisplayRole ) const override; @@ -47,22 +50,22 @@ public: virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override; - static VideoDeviceModel* instance(); + static DeviceModel* instance(); - VideoDevice* activeDevice() const; + Video::Device* activeDevice() const; int activeIndex() const; - VideoDevice* getDevice(const QString& devId) const; - QList<VideoDevice*> devices() const; + Video::Device* getDevice(const QString& devId) const; + QList<Video::Device*> devices() const; private: - VideoDeviceModelPrivate* d_ptr; - static VideoDeviceModel* m_spInstance; + DeviceModelPrivate* d_ptr; + static DeviceModel* m_spInstance; public Q_SLOTS: void setActive(const QModelIndex& idx); void setActive(const int idx); - void setActive(const VideoDevice* device); + void setActive(const Video::Device* device); void reload(); Q_SIGNALS: @@ -70,5 +73,7 @@ Q_SIGNALS: void currentIndexChanged(int); }; -Q_DECLARE_METATYPE(VideoDeviceModel*) + +} +Q_DECLARE_METATYPE(Video::DeviceModel*) #endif diff --git a/src/video/videomanager.cpp b/src/video/manager.cpp similarity index 70% rename from src/video/videomanager.cpp rename to src/video/manager.cpp index a57aea596a50182b3d2b89b3b61408f1962c2115..86847bcb8aa94e255dc92234b76e2220c892e14d 100644 --- a/src/video/videomanager.cpp +++ b/src/video/manager.cpp @@ -15,31 +15,32 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************/ -#include "videomanager.h" +#include "manager.h" //Qt #include <QtCore/QMutex> //SFLPhone #include "../dbus/videomanager.h" -#include "videodevice.h" +#include "device.h" #include <call.h> #include <callmodel.h> -#include "videorenderer.h" -#include "videodevicemodel.h" -#include "videochannel.h" -#include "videorate.h" -#include "videoresolution.h" +#include "renderer.h" +#include "devicemodel.h" +#include "channel.h" +#include "rate.h" +#include "resolution.h" //Static member -VideoManager* VideoManager::m_spInstance = nullptr; +Video::Manager* Video::Manager::m_spInstance = nullptr; -class VideoManagerPrivate : public QObject +namespace Video { +class ManagerPrivate : public QObject { Q_OBJECT public: - VideoManagerPrivate(VideoManager* parent); + ManagerPrivate(Video::Manager* parent); //Attributes bool m_PreviewState; @@ -47,10 +48,10 @@ public: uint m_ShmKey ; uint m_SemKey ; QMutex* m_SSMutex ; - QHash<QString,VideoRenderer*> m_lRenderers; + QHash<QString,Video::Renderer*> m_lRenderers; private: - VideoManager* q_ptr; + Video::Manager* q_ptr; private Q_SLOTS: void startedDecoding(const QString& id, const QString& shmPath, int width, int height); @@ -58,15 +59,16 @@ private Q_SLOTS: void deviceEvent(); }; +} -VideoManagerPrivate::VideoManagerPrivate(VideoManager* parent) : QObject(parent), q_ptr(parent), +Video::ManagerPrivate::ManagerPrivate(Video::Manager* parent) : QObject(parent), q_ptr(parent), m_BufferSize(0),m_ShmKey(0),m_SemKey(0),m_PreviewState(false),m_SSMutex(new QMutex()) { } ///Constructor -VideoManager::VideoManager():QThread(), d_ptr(new VideoManagerPrivate(this)) +Video::Manager::Manager():QThread(), d_ptr(new Video::ManagerPrivate(this)) { VideoManagerInterface& interface = DBus::VideoManager::instance(); connect( &interface , SIGNAL(deviceEvent()) , d_ptr, SLOT(deviceEvent()) ); @@ -75,43 +77,43 @@ VideoManager::VideoManager():QThread(), d_ptr(new VideoManagerPrivate(this)) } -VideoManager::~VideoManager() +Video::Manager::~Manager() { delete d_ptr; } ///Singleton -VideoManager* VideoManager::instance() +Video::Manager* Video::Manager::instance() { if (!m_spInstance) { - m_spInstance = new VideoManager(); + m_spInstance = new Video::Manager(); } return m_spInstance; } ///Return the call renderer or nullptr -VideoRenderer* VideoManager::getRenderer(const Call* call) const +Video::Renderer* Video::Manager::getRenderer(const Call* call) const { if (!call) return nullptr; return d_ptr->m_lRenderers[call->id()]; } ///Get the video preview renderer -VideoRenderer* VideoManager::previewRenderer() +Video::Renderer* Video::Manager::previewRenderer() { if (!d_ptr->m_lRenderers["local"]) { - VideoResolution* res = VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution(); + Video::Resolution* res = Video::DeviceModel::instance()->activeDevice()->activeChannel()->activeResolution(); if (!res) { qWarning() << "Misconfigured video device"; return nullptr; } - d_ptr->m_lRenderers["local"] = new VideoRenderer("local","",res->size()); + d_ptr->m_lRenderers["local"] = new Video::Renderer("local","",res->size()); } return d_ptr->m_lRenderers["local"]; } ///Stop video preview -void VideoManager::stopPreview() +void Video::Manager::stopPreview() { VideoManagerInterface& interface = DBus::VideoManager::instance(); interface.stopCamera(); @@ -119,7 +121,7 @@ void VideoManager::stopPreview() } ///Start video preview -void VideoManager::startPreview() +void Video::Manager::startPreview() { if (d_ptr->m_PreviewState) return; VideoManagerInterface& interface = DBus::VideoManager::instance(); @@ -128,52 +130,52 @@ void VideoManager::startPreview() } ///Is the video model fetching preview from a camera -bool VideoManager::isPreviewing() +bool Video::Manager::isPreviewing() { return d_ptr->m_PreviewState; } ///@todo Set the video buffer size -void VideoManager::setBufferSize(uint size) +void Video::Manager::setBufferSize(uint size) { d_ptr->m_BufferSize = size; } ///Event callback -void VideoManagerPrivate::deviceEvent() +void Video::ManagerPrivate::deviceEvent() { //TODO is there anything useful to do? } ///A video is not being rendered -void VideoManagerPrivate::startedDecoding(const QString& id, const QString& shmPath, int width, int height) +void Video::ManagerPrivate::startedDecoding(const QString& id, const QString& shmPath, int width, int height) { Q_UNUSED(id) QSize res = QSize(width,height); -// if (VideoDeviceModel::instance()->activeDevice() -// && VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->width() == width) { +// if (Video::DeviceModel::instance()->activeDevice() +// && Video::DeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->width() == width) { // //FIXME flawed logic -// res = VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->size(); +// res = Video::DeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->size(); // } // else { // res = QSize(width,height); // } if (m_lRenderers[id] == nullptr ) { - m_lRenderers[id] = new VideoRenderer(id,shmPath,res); + m_lRenderers[id] = new Video::Renderer(id,shmPath,res); m_lRenderers[id]->moveToThread(q_ptr); if (!q_ptr->isRunning()) q_ptr->start(); } else { - VideoRenderer* renderer = m_lRenderers[id]; + Video::Renderer* renderer = m_lRenderers[id]; renderer->setShmPath(shmPath); renderer->setSize(res); } m_lRenderers[id]->startRendering(); - VideoDevice* dev = VideoDeviceModel::instance()->getDevice(id); + Video::Device* dev = Video::DeviceModel::instance()->getDevice(id); if (dev) { emit dev->renderingStarted(m_lRenderers[id]); } @@ -189,17 +191,17 @@ void VideoManagerPrivate::startedDecoding(const QString& id, const QString& shmP } ///A video stopped being rendered -void VideoManagerPrivate::stoppedDecoding(const QString& id, const QString& shmPath) +void Video::ManagerPrivate::stoppedDecoding(const QString& id, const QString& shmPath) { Q_UNUSED(shmPath) - VideoRenderer* r = m_lRenderers[id]; + Video::Renderer* r = m_lRenderers[id]; if ( r ) { r->stopRendering(); } qDebug() << "Video stopped for call" << id << "Renderer found:" << (m_lRenderers[id] != nullptr); // emit videoStopped(); - VideoDevice* dev = VideoDeviceModel::instance()->getDevice(id); + Video::Device* dev = Video::DeviceModel::instance()->getDevice(id); if (dev) { emit dev->renderingStopped(r); } @@ -213,15 +215,15 @@ void VideoManagerPrivate::stoppedDecoding(const QString& id, const QString& shmP delete r; } -void VideoManager::switchDevice(const VideoDevice* device) const +void Video::Manager::switchDevice(const Video::Device* device) const { VideoManagerInterface& interface = DBus::VideoManager::instance(); interface.switchInput(device->id()); } -QMutex* VideoManager::startStopMutex() const +QMutex* Video::Manager::startStopMutex() const { return d_ptr->m_SSMutex; } -#include <videomanager.moc> +#include <manager.moc> diff --git a/src/video/videomanager.h b/src/video/manager.h similarity index 79% rename from src/video/videomanager.h rename to src/video/manager.h index 25e3e996732a4f2c3c87c34a665da5cd04dbf4c3..8446e822d152ae8e8c8bd394b0885f614b1f7e55 100644 --- a/src/video/videomanager.h +++ b/src/video/manager.h @@ -25,47 +25,51 @@ #include <QtCore/QHash> //SFLPhone -#include "videodevice.h" -class VideoRenderer; +#include "device.h" +namespace Video { + class Renderer; +} class Call; class QMutex; struct SHMHeader; -class VideoManagerPrivate; +namespace Video { + +class ManagerPrivate; ///VideoModel: Video event dispatcher -class LIB_EXPORT VideoManager : public QThread { +class LIB_EXPORT Manager : public QThread { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" Q_OBJECT #pragma GCC diagnostic pop public: //Singleton - static VideoManager* instance(); + static Manager* instance(); //Getters bool isPreviewing (); - VideoRenderer* getRenderer(const Call* call) const; - VideoRenderer* previewRenderer(); + Video::Renderer* getRenderer(const Call* call) const; + Video::Renderer* previewRenderer(); QMutex* startStopMutex() const; //Setters void setBufferSize(uint size); - void switchDevice(const VideoDevice* device) const; + void switchDevice(const Video::Device* device) const; protected: // void run(); private: //Constructor - explicit VideoManager(); - virtual ~VideoManager(); + explicit Manager(); + virtual ~Manager(); - VideoManagerPrivate* d_ptr; - Q_DECLARE_PRIVATE(VideoManager) + ManagerPrivate* d_ptr; + Q_DECLARE_PRIVATE(Manager) //Static attributes - static VideoManager* m_spInstance; + static Manager* m_spInstance; public Q_SLOTS: void stopPreview (); @@ -77,12 +81,14 @@ Q_SIGNALS: ///Emmitted when the video is stopped, before the framebuffer become invalid // void videoStopped(); ///Emmitted when a call make video available - void videoCallInitiated(VideoRenderer*); + void videoCallInitiated(Video::Renderer*); ///The preview started/stopped void previewStateChanged(bool startStop); - void previewStarted(VideoRenderer* renderer); - void previewStopped(VideoRenderer* renderer); - + void previewStarted(Video::Renderer* renderer); + void previewStopped(Video::Renderer* renderer); + }; +} + #endif diff --git a/src/video/videorate.cpp b/src/video/rate.cpp similarity index 82% rename from src/video/videorate.cpp rename to src/video/rate.cpp index 5b66ad2594b6ea44ae772d5c36ceb71d671fd44e..f706d4d8c20b98098c28074e403a10499b26519f 100644 --- a/src/video/videorate.cpp +++ b/src/video/rate.cpp @@ -15,17 +15,17 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************/ -#include "videorate.h" -#include "videodevicemodel.h" -#include "videochannel.h" -#include "videoresolution.h" +#include "rate.h" +#include "devicemodel.h" +#include "channel.h" +#include "resolution.h" -int VideoRate::relativeIndex() +int Video::Rate::relativeIndex() { - return VideoDeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->validRates().indexOf(this); + return Video::DeviceModel::instance()->activeDevice()->activeChannel()->activeResolution()->validRates().indexOf(this); } -QString VideoRate::name() const +QString Video::Rate::name() const { return m_Name; } diff --git a/src/video/videorate.h b/src/video/rate.h similarity index 82% rename from src/video/videorate.h rename to src/video/rate.h index e77307dc256f9707da61ae163674d7b3f2651f33..57bffeee4dc7851456c7d51dd486c82f400dd637 100644 --- a/src/video/videorate.h +++ b/src/video/rate.h @@ -20,30 +20,36 @@ #include "../typedefs.h" -class VideoResolution; - +namespace Video { + class Resolution; + class Device; +} // class VideoRatePrivate // { // public: // // }; -///@typedef VideoRate The rate for a device -class LIB_EXPORT VideoRate +namespace Video { + +///@typedef Rate The rate for a device +class LIB_EXPORT Rate { - //Can only be created by VideoDevice - friend class VideoDevice; + //Can only be created by Video::Device + friend class Video::Device; public: - virtual ~VideoRate() {} + virtual ~Rate() {} QString name() const; int relativeIndex(); private: - VideoRate(const VideoResolution* res,const QString& name) : + Rate(const Video::Resolution* res,const QString& name) : m_Name(name),m_pResolution(res) {} QString m_Name; - const VideoResolution* m_pResolution; + const Video::Resolution* m_pResolution; }; +} + #endif diff --git a/src/video/videorenderer.cpp b/src/video/renderer.cpp similarity index 86% rename from src/video/videorenderer.cpp rename to src/video/renderer.cpp index cf1d18a1ac387739bff15bb39c759aec1b47b4bd..b8cc8d3b2f376f2321387eb4f2115f367d26833f 100644 --- a/src/video/videorenderer.cpp +++ b/src/video/renderer.cpp @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************/ -#include "videorenderer.h" +#include "renderer.h" #include <QtCore/QDebug> #include <QtCore/QMutex> @@ -36,8 +36,8 @@ #endif #include <QtCore/QTimer> -#include "videomanager.h" -#include "videoresolution.h" +#include "manager.h" +#include "resolution.h" ///Shared memory object struct SHMHeader{ @@ -55,11 +55,13 @@ struct SHMHeader{ #pragma GCC diagnostic pop }; -class VideoRendererPrivate : public QObject +namespace Video { + +class RendererPrivate : public QObject { Q_OBJECT public: - VideoRendererPrivate(VideoRenderer* parent); + RendererPrivate(Video::Renderer* parent); //Attributes QString m_ShmPath ; @@ -89,13 +91,15 @@ public: bool renderToBitmap(); private: - VideoRenderer* q_ptr; + Video::Renderer* q_ptr; private Q_SLOTS: void timedEvents(); }; -VideoRendererPrivate::VideoRendererPrivate(VideoRenderer* parent) : QObject(parent), q_ptr(parent), +} + +Video::RendererPrivate::RendererPrivate(Video::Renderer* parent) : QObject(parent), q_ptr(parent), fd(-1),m_fpsC(0),m_Fps(0), m_pShmArea((SHMHeader*)MAP_FAILED), m_ShmAreaLen(0), m_BufferGen(0), m_isRendering(false),m_pTimer(nullptr),m_pMutex(new QMutex()), @@ -104,23 +108,23 @@ VideoRendererPrivate::VideoRendererPrivate(VideoRenderer* parent) : QObject(pare } ///Constructor -VideoRenderer::VideoRenderer(const QString& id, const QString& shmPath, const QSize& res): QObject(nullptr), d_ptr(new VideoRendererPrivate(this)) +Video::Renderer::Renderer(const QString& id, const QString& shmPath, const QSize& res): QObject(nullptr), d_ptr(new RendererPrivate(this)) { d_ptr->m_ShmPath = shmPath; d_ptr->m_Id = id; d_ptr->m_pSize = res; - setObjectName("VideoRenderer:"+id); + setObjectName("Video::Renderer:"+id); } ///Destructor -VideoRenderer::~VideoRenderer() +Video::Renderer::~Renderer() { stopShm(); //delete m_pShmArea; } ///Get the data from shared memory and transform it into a QByteArray -bool VideoRendererPrivate::renderToBitmap() +bool Video::RendererPrivate::renderToBitmap() { #ifdef Q_OS_LINUX if (!m_isRendering) { @@ -131,7 +135,7 @@ bool VideoRendererPrivate::renderToBitmap() return false; } - if(!VideoManager::instance()->startStopMutex()->tryLock()) + if(!Video::Manager::instance()->startStopMutex()->tryLock()) return false; // wait for a new buffer @@ -163,7 +167,7 @@ bool VideoRendererPrivate::renderToBitmap() // break; // } if ((err < 0) || (!shmLock())) { - VideoManager::instance()->startStopMutex()->unlock(); + Video::Manager::instance()->startStopMutex()->unlock(); return false; } usleep((1/60.0)*100); @@ -171,7 +175,7 @@ bool VideoRendererPrivate::renderToBitmap() if (!q_ptr->resizeShm()) { qDebug() << "Could not resize shared memory"; - VideoManager::instance()->startStopMutex()->unlock(); + Video::Manager::instance()->startStopMutex()->unlock(); return false; } @@ -183,7 +187,7 @@ bool VideoRendererPrivate::renderToBitmap() shmUnlock(); m_FrameIdx = !m_FrameIdx; - VideoManager::instance()->startStopMutex()->unlock(); + Video::Manager::instance()->startStopMutex()->unlock(); return true; #else return false; @@ -191,7 +195,7 @@ bool VideoRendererPrivate::renderToBitmap() } ///Connect to the shared memory -bool VideoRenderer::startShm() +bool Video::Renderer::startShm() { if (d_ptr->fd != -1) { qDebug() << "fd must be -1"; @@ -217,7 +221,7 @@ bool VideoRenderer::startShm() } ///Disconnect from the shared memory -void VideoRenderer::stopShm() +void Video::Renderer::stopShm() { if (d_ptr->fd >= 0) close(d_ptr->fd); @@ -230,7 +234,7 @@ void VideoRenderer::stopShm() } ///Resize the shared memory -bool VideoRenderer::resizeShm() +bool Video::Renderer::resizeShm() { while (( (unsigned int) sizeof(SHMHeader) + (unsigned int) d_ptr->m_pShmArea->m_BufferSize) > (unsigned int) d_ptr->m_ShmAreaLen) { const size_t new_size = sizeof(SHMHeader) + d_ptr->m_pShmArea->m_BufferSize; @@ -261,7 +265,7 @@ bool VideoRenderer::resizeShm() } ///Lock the memory while the copy is being made -bool VideoRendererPrivate::shmLock() +bool Video::RendererPrivate::shmLock() { #ifdef Q_OS_LINUX return sem_trywait(&m_pShmArea->mutex) >= 0; @@ -271,7 +275,7 @@ bool VideoRendererPrivate::shmLock() } ///Remove the lock, allow a new frame to be drawn -void VideoRendererPrivate::shmUnlock() +void Video::RendererPrivate::shmUnlock() { sem_post(&m_pShmArea->mutex); } @@ -284,7 +288,7 @@ void VideoRendererPrivate::shmUnlock() ****************************************************************************/ ///Update the buffer -void VideoRendererPrivate::timedEvents() +void Video::RendererPrivate::timedEvents() { bool ok = renderToBitmap(); @@ -308,9 +312,9 @@ void VideoRendererPrivate::timedEvents() } ///Start the rendering loop -void VideoRenderer::startRendering() +void Video::Renderer::startRendering() { - VideoManager::instance()->startStopMutex()->lock(); + Video::Manager::instance()->startStopMutex()->lock(); QMutexLocker locker(d_ptr->m_pMutex); startShm(); if (!d_ptr->m_pTimer) { @@ -329,13 +333,13 @@ void VideoRenderer::startRendering() qDebug() << "Timer already started!"; d_ptr->m_isRendering = true; - VideoManager::instance()->startStopMutex()->unlock(); + Video::Manager::instance()->startStopMutex()->unlock(); } ///Stop the rendering loop -void VideoRenderer::stopRendering() +void Video::Renderer::stopRendering() { - VideoManager::instance()->startStopMutex()->lock(); + Video::Manager::instance()->startStopMutex()->lock(); QMutexLocker locker(d_ptr->m_pMutex); d_ptr->m_isRendering = false; qDebug() << "Stopping rendering on" << d_ptr->m_Id; @@ -343,7 +347,7 @@ void VideoRenderer::stopRendering() d_ptr->m_pTimer->stop(); emit stopped(); stopShm(); - VideoManager::instance()->startStopMutex()->unlock(); + Video::Manager::instance()->startStopMutex()->unlock(); } @@ -354,38 +358,38 @@ void VideoRenderer::stopRendering() ****************************************************************************/ ///Get the raw bytes directly from the SHM, not recommended, but optimal -const char* VideoRenderer::rawData() +const char* Video::Renderer::rawData() { return d_ptr->m_isRendering?d_ptr->m_Frame[d_ptr->m_FrameIdx].data():nullptr; } ///Is this redenrer active -bool VideoRenderer::isRendering() +bool Video::Renderer::isRendering() { return d_ptr->m_isRendering; } ///Return the current framerate -const QByteArray& VideoRenderer::currentFrame() +const QByteArray& Video::Renderer::currentFrame() { static QByteArray empty; return d_ptr->m_isRendering?d_ptr->m_Frame[d_ptr->m_FrameIdx]:empty; } ///Return the current resolution -QSize VideoRenderer::size() +QSize Video::Renderer::size() { return d_ptr->m_pSize; } ///Get mutex, in case renderer and views are not in the same thread -QMutex* VideoRenderer::mutex() +QMutex* Video::Renderer::mutex() { return d_ptr->m_pMutex; } ///Get the current frame rate of this renderer -int VideoRenderer::fps() const +int Video::Renderer::fps() const { return d_ptr->m_Fps; } @@ -397,15 +401,15 @@ int VideoRenderer::fps() const * * ****************************************************************************/ -void VideoRenderer::setSize(const QSize& size) +void Video::Renderer::setSize(const QSize& size) { d_ptr->m_pSize = size; } -void VideoRenderer::setShmPath(const QString& path) +void Video::Renderer::setShmPath(const QString& path) { d_ptr->m_ShmPath = path; } -#include <videorenderer.moc> +#include <renderer.moc> diff --git a/src/video/videorenderer.h b/src/video/renderer.h similarity index 89% rename from src/video/videorenderer.h rename to src/video/renderer.h index c2da07432b3be0c57e31c03c40b8858f908222a6..ef5aa6870f4b348182f9876a3e429120f4a41aa5 100644 --- a/src/video/videorenderer.h +++ b/src/video/renderer.h @@ -29,14 +29,17 @@ class QTimer; class QMutex; //SFLPhone -#include "videodevice.h" +#include "device.h" //Private -class VideoRendererPrivate; struct SHMHeader; + +namespace Video { +class RendererPrivate; + ///Manage shared memory and convert it to QByteArray -class LIB_EXPORT VideoRenderer : public QObject { +class LIB_EXPORT Renderer : public QObject { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" Q_OBJECT @@ -44,8 +47,8 @@ class LIB_EXPORT VideoRenderer : public QObject { public: //Constructor - VideoRenderer (const QString& id, const QString& shmPath, const QSize& res); - virtual ~VideoRenderer(); + Renderer (const QString& id, const QString& shmPath, const QSize& res); + virtual ~Renderer(); //Mutators bool resizeShm(); @@ -65,8 +68,8 @@ class LIB_EXPORT VideoRenderer : public QObject { void setShmPath (const QString& path); private: - QScopedPointer<VideoRendererPrivate> d_ptr; - Q_DECLARE_PRIVATE(VideoRenderer) + QScopedPointer<RendererPrivate> d_ptr; + Q_DECLARE_PRIVATE(Renderer) public Q_SLOTS: void startRendering(); @@ -80,4 +83,6 @@ Q_SIGNALS: }; +} + #endif diff --git a/src/video/videoresolution.cpp b/src/video/resolution.cpp similarity index 76% rename from src/video/videoresolution.cpp rename to src/video/resolution.cpp index 9e90330ebe3b44e1ef6a9cfa6e1d6abaf9b4418b..179baca32991b0916f05c93317e3fb769052b42e 100644 --- a/src/video/videoresolution.cpp +++ b/src/video/resolution.cpp @@ -15,17 +15,17 @@ * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * ***************************************************************************/ -#include "videoresolution.h" +#include "resolution.h" #include "../dbus/videomanager.h" #include "../private/videodevice_p.h" -#include "videochannel.h" -#include "videorate.h" -#include "videodevice.h" +#include "channel.h" +#include "rate.h" +#include "device.h" #include <QtCore/QStringList> -VideoResolution::VideoResolution(const QString& size, VideoChannel* chan) +Video::Resolution::Resolution(const QString& size, Video::Channel* chan) : QAbstractListModel(chan), m_pCurrentRate(nullptr),m_pChannel(chan) { Q_ASSERT(chan != nullptr); @@ -35,13 +35,13 @@ VideoResolution::VideoResolution(const QString& size, VideoChannel* chan) } } -const QString VideoResolution::name() const +const QString Video::Resolution::name() const { return QString::number(width())+'x'+QString::number(height()); } -QVariant VideoResolution::data( const QModelIndex& index, int role) const +QVariant Video::Resolution::data( const QModelIndex& index, int role) const { if (index.isValid() && role == Qt::DisplayRole && index.row() < m_lValidRates.size()) { return m_lValidRates[index.row()]->name(); @@ -49,19 +49,19 @@ QVariant VideoResolution::data( const QModelIndex& index, int role) const return QVariant(); } -int VideoResolution::rowCount( const QModelIndex& parent) const +int Video::Resolution::rowCount( const QModelIndex& parent) const { return (parent.isValid())?0:m_lValidRates.size(); } -Qt::ItemFlags VideoResolution::flags( const QModelIndex& idx) const +Qt::ItemFlags Video::Resolution::flags( const QModelIndex& idx) const { if (idx.column() == 0) return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; return QAbstractItemModel::flags(idx); } -bool VideoResolution::setData( const QModelIndex& index, const QVariant &value, int role) +bool Video::Resolution::setData( const QModelIndex& index, const QVariant &value, int role) { Q_UNUSED(index) Q_UNUSED(value) @@ -70,12 +70,12 @@ bool VideoResolution::setData( const QModelIndex& index, const QVariant &value, } -const QList<VideoRate*> VideoResolution::validRates() const { +const QList<Video::Rate*> Video::Resolution::validRates() const { return m_lValidRates; } -bool VideoResolution::setActiveRate(VideoRate* rate) { +bool Video::Resolution::setActiveRate(Video::Rate* rate) { if (!rate || (m_lValidRates.indexOf(rate) == -1)) { qWarning() << "Trying to set an invalid rate" << rate; return false; @@ -86,13 +86,13 @@ bool VideoResolution::setActiveRate(VideoRate* rate) { } -bool VideoResolution::setActiveRate(int idx) +bool Video::Resolution::setActiveRate(int idx) { if (idx >= m_lValidRates.size() || idx < 0) return false; return setActiveRate(m_lValidRates[idx]); } -VideoRate* VideoResolution::activeRate() +Video::Rate* Video::Resolution::activeRate() { if (!m_pChannel) { qWarning() << "Trying to get the active rate of an unattached resolution"; @@ -102,7 +102,7 @@ VideoRate* VideoResolution::activeRate() VideoManagerInterface& interface = DBus::VideoManager::instance(); const QString rate = QMap<QString,QString>( interface.getSettings(m_pChannel->device()->id()))[VideoDevicePrivate::PreferenceNames::RATE]; - foreach(VideoRate* r, m_lValidRates) { + foreach(Video::Rate* r, m_lValidRates) { if (r->name() == rate) { m_pCurrentRate = r; break; @@ -115,32 +115,32 @@ VideoRate* VideoResolution::activeRate() return m_pCurrentRate; } -int VideoResolution::relativeIndex() const +int Video::Resolution::relativeIndex() const { - return m_pChannel?m_pChannel->validResolutions().indexOf(const_cast<VideoResolution*>(this)):-1; + return m_pChannel?m_pChannel->validResolutions().indexOf(const_cast<Video::Resolution*>(this)):-1; } -int VideoResolution::width() const +int Video::Resolution::width() const { return m_Size.width(); } -int VideoResolution::height() const +int Video::Resolution::height() const { return m_Size.height(); } -QSize VideoResolution::size() const +QSize Video::Resolution::size() const { return m_Size; } -void VideoResolution::setWidth(int width) +void Video::Resolution::setWidth(int width) { m_Size.setWidth(width); } -void VideoResolution::setHeight(int height) +void Video::Resolution::setHeight(int height) { m_Size.setHeight(height); } diff --git a/src/video/videoresolution.h b/src/video/resolution.h similarity index 78% rename from src/video/videoresolution.h rename to src/video/resolution.h index e4e4a09a8794828d7267d7889bba46733e933948..23a58240d60a550975f48c7f81052d2c00614940 100644 --- a/src/video/videoresolution.h +++ b/src/video/resolution.h @@ -22,9 +22,11 @@ #include <QtCore/QSize> #include "../typedefs.h" -class VideoRate; -class VideoChannel; -class VideoDevice; +namespace Video { + class Rate; + class Channel; + class Device; +} // class VideoResolutionPrivate // { @@ -32,22 +34,26 @@ class VideoDevice; // // }; -///@struct VideoResolution Equivalent of "640x480" -class LIB_EXPORT VideoResolution : public QAbstractListModel { + + +namespace Video { + +///@struct Resolution Equivalent of "640x480" +class LIB_EXPORT Resolution : public QAbstractListModel { Q_OBJECT - //Only VideoDevice can add validated rates - friend class VideoDevice; + //Only Video::Device can add validated rates + friend class Video::Device; public: //Constructor - VideoResolution(const QString& size, VideoChannel* chan); - explicit VideoResolution(); + Resolution(const QString& size, Video::Channel* chan); + explicit Resolution(); //Getter const QString name() const; - const QList<VideoRate*> validRates() const; + const QList<Video::Rate*> validRates() const; int relativeIndex() const; - VideoRate* activeRate(); - bool setActiveRate(VideoRate* rate); + Video::Rate* activeRate(); + bool setActiveRate(Video::Rate* rate); bool setActiveRate(int index); int width() const; int height() const; @@ -67,10 +73,12 @@ public: private: //Attributes - QList<VideoRate*> m_lValidRates; - VideoRate* m_pCurrentRate; - VideoChannel* m_pChannel; - QSize m_Size; + QList<Video::Rate*> m_lValidRates; + Video::Rate* m_pCurrentRate; + Video::Channel* m_pChannel; + QSize m_Size; }; +} + #endif diff --git a/src/video/sourcesmodel.cpp b/src/video/sourcesmodel.cpp index c0840a3d124b0c663422e90916816e4f5633c6c5..88e37583d07596a31d3cb9500af2a7bcb861350e 100644 --- a/src/video/sourcesmodel.cpp +++ b/src/video/sourcesmodel.cpp @@ -19,12 +19,13 @@ #include <QtCore/QUrl> #include <QtCore/QCoreApplication> #include "../dbus/videomanager.h" -#include "videodevicemodel.h" +#include "devicemodel.h" -class VideoSourcesModelPrivate +namespace Video { +class SourcesModelPrivate { public: - VideoSourcesModelPrivate(); + SourcesModelPrivate(); //Constants class ProtocolPrefix { @@ -45,28 +46,29 @@ public: Display m_Display; int m_CurrentSelection; }; +} -VideoSourcesModelPrivate::VideoSourcesModelPrivate() : m_CurrentSelection(-1) +Video::SourcesModelPrivate::SourcesModelPrivate() : m_CurrentSelection(-1) { } -VideoSourcesModel* VideoSourcesModel::m_spInstance = nullptr; +Video::SourcesModel* Video::SourcesModel::m_spInstance = nullptr; -VideoSourcesModel::VideoSourcesModel() : QAbstractListModel(QCoreApplication::instance()), -d_ptr(new VideoSourcesModelPrivate()) +Video::SourcesModel::SourcesModel() : QAbstractListModel(QCoreApplication::instance()), +d_ptr(new Video::SourcesModelPrivate()) { d_ptr->m_Display.rect = QRect(0,0,0,0); } -VideoSourcesModel* VideoSourcesModel::instance() +Video::SourcesModel* Video::SourcesModel::instance() { if (!m_spInstance) - m_spInstance = new VideoSourcesModel(); + m_spInstance = new Video::SourcesModel(); return m_spInstance; } -QVariant VideoSourcesModel::data( const QModelIndex& index, int role ) const +QVariant Video::SourcesModel::data( const QModelIndex& index, int role ) const { switch (index.row()) { case ExtendedDeviceList::NONE: @@ -88,18 +90,18 @@ QVariant VideoSourcesModel::data( const QModelIndex& index, int role ) const }; break; default: - return VideoDeviceModel::instance()->data(VideoDeviceModel::instance()->index(index.row()-ExtendedDeviceList::__COUNT,0),role); + return Video::DeviceModel::instance()->data(Video::DeviceModel::instance()->index(index.row()-ExtendedDeviceList::__COUNT,0),role); }; return QVariant(); } -int VideoSourcesModel::rowCount( const QModelIndex& parent ) const +int Video::SourcesModel::rowCount( const QModelIndex& parent ) const { Q_UNUSED(parent) - return VideoDeviceModel::instance()->rowCount() + ExtendedDeviceList::__COUNT; + return Video::DeviceModel::instance()->rowCount() + ExtendedDeviceList::__COUNT; } -Qt::ItemFlags VideoSourcesModel::flags( const QModelIndex& idx ) const +Qt::ItemFlags Video::SourcesModel::flags( const QModelIndex& idx ) const { switch (idx.row()) { case ExtendedDeviceList::NONE : @@ -108,11 +110,11 @@ Qt::ItemFlags VideoSourcesModel::flags( const QModelIndex& idx ) const return QAbstractItemModel::flags(idx) | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; break; default: - return VideoDeviceModel::instance()->flags(VideoDeviceModel::instance()->index(idx.row()-ExtendedDeviceList::__COUNT,0)); + return Video::DeviceModel::instance()->flags(Video::DeviceModel::instance()->index(idx.row()-ExtendedDeviceList::__COUNT,0)); }; } -bool VideoSourcesModel::setData( const QModelIndex& index, const QVariant &value, int role) +bool Video::SourcesModel::setData( const QModelIndex& index, const QVariant &value, int role) { Q_UNUSED(index) Q_UNUSED(value) @@ -120,43 +122,43 @@ bool VideoSourcesModel::setData( const QModelIndex& index, const QVariant &value return false; } -void VideoSourcesModel::switchTo(const QModelIndex& idx) +void Video::SourcesModel::switchTo(const QModelIndex& idx) { switchTo(idx.row()); } ///This model is designed for "live" switching rather than configuration -void VideoSourcesModel::switchTo(const int idx) +void Video::SourcesModel::switchTo(const int idx) { switch (idx) { case ExtendedDeviceList::NONE: - DBus::VideoManager::instance().switchInput(VideoSourcesModelPrivate::ProtocolPrefix::NONE); + DBus::VideoManager::instance().switchInput(Video::SourcesModelPrivate::ProtocolPrefix::NONE); break; case ExtendedDeviceList::SCREEN: - DBus::VideoManager::instance().switchInput( QString(VideoSourcesModelPrivate::ProtocolPrefix::DISPLAY)+QString(":%1 %2x%3") + DBus::VideoManager::instance().switchInput( QString(Video::SourcesModelPrivate::ProtocolPrefix::DISPLAY)+QString(":%1 %2x%3") .arg(d_ptr->m_Display.index) .arg(d_ptr->m_Display.rect.width()) .arg(d_ptr->m_Display.rect.height())); break; case ExtendedDeviceList::FILE: DBus::VideoManager::instance().switchInput( - !d_ptr->m_CurrentFile.isEmpty()?+VideoSourcesModelPrivate::ProtocolPrefix::FILE+d_ptr->m_CurrentFile.path():VideoSourcesModelPrivate::ProtocolPrefix::NONE + !d_ptr->m_CurrentFile.isEmpty()?+Video::SourcesModelPrivate::ProtocolPrefix::FILE+d_ptr->m_CurrentFile.path():Video::SourcesModelPrivate::ProtocolPrefix::NONE ); break; default: - DBus::VideoManager::instance().switchInput(VideoSourcesModelPrivate::ProtocolPrefix::V4L2 + - VideoDeviceModel::instance()->index(idx-ExtendedDeviceList::__COUNT,0).data(Qt::DisplayRole).toString()); + DBus::VideoManager::instance().switchInput(Video::SourcesModelPrivate::ProtocolPrefix::V4L2 + + Video::DeviceModel::instance()->index(idx-ExtendedDeviceList::__COUNT,0).data(Qt::DisplayRole).toString()); break; }; d_ptr->m_CurrentSelection = (ExtendedDeviceList) idx; } -void VideoSourcesModel::switchTo(VideoDevice* device) +void Video::SourcesModel::switchTo(Video::Device* device) { - DBus::VideoManager::instance().switchInput(VideoSourcesModelPrivate::ProtocolPrefix::V4L2 + device->id()); + DBus::VideoManager::instance().switchInput(Video::SourcesModelPrivate::ProtocolPrefix::V4L2 + device->id()); } -VideoDevice* VideoSourcesModel::deviceAt(const QModelIndex& idx) const +Video::Device* Video::SourcesModel::deviceAt(const QModelIndex& idx) const { if (!idx.isValid()) return nullptr; switch (idx.row()) { @@ -165,25 +167,25 @@ VideoDevice* VideoSourcesModel::deviceAt(const QModelIndex& idx) const case ExtendedDeviceList::FILE: return nullptr; default: - return VideoDeviceModel::instance()->devices()[idx.row()-ExtendedDeviceList::__COUNT]; + return Video::DeviceModel::instance()->devices()[idx.row()-ExtendedDeviceList::__COUNT]; }; } -int VideoSourcesModel::activeIndex() const +int Video::SourcesModel::activeIndex() const { if (d_ptr->m_CurrentSelection == -1) { - return ExtendedDeviceList::__COUNT + VideoDeviceModel::instance()->activeIndex(); + return ExtendedDeviceList::__COUNT + Video::DeviceModel::instance()->activeIndex(); } return d_ptr->m_CurrentSelection; } -void VideoSourcesModel::setFile(const QUrl& url) +void Video::SourcesModel::setFile(const QUrl& url) { d_ptr->m_CurrentFile = url; switchTo(ExtendedDeviceList::FILE); } -void VideoSourcesModel::setDisplay(int index, QRect rect) +void Video::SourcesModel::setDisplay(int index, QRect rect) { d_ptr->m_Display.index = index ; d_ptr->m_Display.rect = rect ; diff --git a/src/video/sourcesmodel.h b/src/video/sourcesmodel.h index 6d152acf63584ca59c8169d16d7804cc7f6a9aa1..a9bbc621f44a7ed5b4e3a2950a16336bfd9a1f08 100644 --- a/src/video/sourcesmodel.h +++ b/src/video/sourcesmodel.h @@ -22,12 +22,14 @@ #include "../typedefs.h" //SFLPhone -class VideoDevice; -class VideoSourcesModelPrivate; +namespace Video { + +class Device; +class SourcesModelPrivate; //TODO qt5, use QIdentityProxyModel -class LIB_EXPORT VideoSourcesModel : public QAbstractListModel { +class LIB_EXPORT SourcesModel : public QAbstractListModel { Q_OBJECT public: enum ExtendedDeviceList { @@ -41,24 +43,26 @@ public: virtual Qt::ItemFlags flags ( const QModelIndex& index ) const override; virtual bool setData ( const QModelIndex& index, const QVariant &value, int role) override; - VideoDevice* deviceAt(const QModelIndex& idx) const; + Device* deviceAt(const QModelIndex& idx) const; int activeIndex() const; //Singleton - static VideoSourcesModel* instance(); + static Video::SourcesModel* instance(); private: - explicit VideoSourcesModel(); + explicit SourcesModel(); - VideoSourcesModelPrivate* d_ptr; - static VideoSourcesModel* m_spInstance; + Video::SourcesModelPrivate* d_ptr; + static Video::SourcesModel* m_spInstance; public Q_SLOTS: void switchTo(const QModelIndex& idx); void switchTo(const int idx); - void switchTo(VideoDevice* device); + void switchTo(Video::Device* device); void setFile(const QUrl& url); void setDisplay(int index, QRect rect = QRect(0,0,0,0)); }; +} + #endif \ No newline at end of file