diff --git a/src/bookmarkmodel.cpp b/src/bookmarkmodel.cpp index e0f45f4c9263d34c8026a6f51d936fb0a139cd27..ff0ff3de5da8dd77e6f0e9ecd8d92f777333af5a 100644 --- a/src/bookmarkmodel.cpp +++ b/src/bookmarkmodel.cpp @@ -166,7 +166,7 @@ QHash<int,QByteArray> BookmarkModel::roleNames() const static bool initRoles = false; if (!initRoles) { initRoles = true; - roles[Call::Role::Name] = CallModel::instance()->roleNames()[Call::Role::Name]; + roles[static_cast<int>(Call::Role::Name)] = CallModel::instance()->roleNames()[static_cast<int>(Call::Role::Name)]; } return roles; } @@ -260,7 +260,7 @@ QVariant BookmarkModel::data( const QModelIndex& index, int role) const switch (role) { case Qt::DisplayRole: return static_cast<BookmarkTopLevelItem*>(modelItem)->m_Name; - case Call::Role::Name: + case static_cast<int>(Call::Role::Name): if (static_cast<BookmarkTopLevelItem*>(modelItem)->m_MostPopular) { return "000000"; } @@ -356,7 +356,7 @@ QMimeData* BookmarkModel::mimeData(const QModelIndexList &indexes) const QMimeData *mimeData = new QMimeData(); foreach (const QModelIndex &index, indexes) { if (index.isValid()) { - QString text = data(index, Call::Role::Number).toString(); + QString text = data(index, static_cast<int>(Call::Role::Number)).toString(); mimeData->setData(RingMimes::PLAIN_TEXT , text.toUtf8()); mimeData->setData(RingMimes::PHONENUMBER, text.toUtf8()); return mimeData; @@ -379,45 +379,42 @@ QVariant BookmarkModelPrivate::commonCallInfo(NumberTreeBackend* number, int rol QVariant cat; switch (role) { case Qt::DisplayRole: - case Call::Role::Name: + case static_cast<int>(Call::Role::Name): cat = number->m_pNumber->contact()?number->m_pNumber->contact()->formattedName():number->m_pNumber->primaryName(); break; case Qt::ToolTipRole: cat = number->m_pNumber->presenceMessage(); break; - case Call::Role::Number: + case static_cast<int>(Call::Role::Number): cat = number->m_pNumber->uri();//call->getPeerContactMethod(); break; - case Call::Role::Direction2: + case static_cast<int>(Call::Role::Direction): cat = 4;//call->getHistoryState(); break; - case Call::Role::Date: + case static_cast<int>(Call::Role::Date): cat = tr("N/A");//call->getStartTimeStamp(); break; - case Call::Role::Length: + case static_cast<int>(Call::Role::Length): cat = tr("N/A");//call->getLength(); break; - case Call::Role::FormattedDate: + case static_cast<int>(Call::Role::FormattedDate): cat = tr("N/A");//QDateTime::fromTime_t(call->getStartTimeStamp().toUInt()).toString(); break; - case Call::Role::HasRecording: + case static_cast<int>(Call::Role::HasRecording): cat = false;//call->hasRecording(); break; - case Call::Role::Historystate: - cat = (int)Call::LegacyHistoryState::NONE;//call->getHistoryState(); - break; - case Call::Role::FuzzyDate: + case static_cast<int>(Call::Role::FuzzyDate): cat = "N/A";//timeToHistoryCategory(QDateTime::fromTime_t(call->getStartTimeStamp().toUInt()).date()); break; - case Call::Role::PhoneNu: + case static_cast<int>(Call::Role::ContactMethod): return QVariant::fromValue(number->m_pNumber); - case Call::Role::IsBookmark: + case static_cast<int>(Call::Role::IsBookmark): return true; - case Call::Role::Filter: + case static_cast<int>(Call::Role::Filter): return number->m_pNumber->uri()+number->m_pNumber->primaryName(); - case Call::Role::IsPresent: + case static_cast<int>(Call::Role::IsPresent): return number->m_pNumber->isPresent(); - case Call::Role::PhotoPtr: + case static_cast<int>(Call::Role::Photo): if (number->m_pNumber->contact()) return number->m_pNumber->contact()->photo(); cat = true; diff --git a/src/call.cpp b/src/call.cpp index 25a14585861b1aefd7274c7642b8f9794f22a0a5..879d9abb5919a01bfee959d3ed6080733d046256 100644 --- a/src/call.cpp +++ b/src/call.cpp @@ -30,6 +30,7 @@ //DRing #include <account_const.h> +#include <call_const.h> //Ring library #include "dbus/callmanager.h" @@ -45,7 +46,9 @@ #include "instantmessagingmodel.h" #include "useractionmodel.h" #include "callmodel.h" +#include "certificate.h" #include "numbercategory.h" +#include "certificatemodel.h" #include "phonedirectorymodel.h" #include "contactmethod.h" #include "video/renderer.h" @@ -106,7 +109,7 @@ const TypedStateMachine< TypedStateMachine< function , Call::Action > , Call::St }};// */ -const TypedStateMachine< TypedStateMachine< Call::State , Call::DaemonState> , Call::State> CallPrivate::stateChangedStateMap = +const TypedStateMachine< TypedStateMachine< Call::State , CallPrivate::DaemonState> , Call::State> CallPrivate::stateChangedStateMap = {{ // RINGING CURRENT BUSY HOLD HUNGUP FAILURE /**/ /*INCOMING */ {{Call::State::INCOMING , Call::State::CURRENT , Call::State::BUSY , Call::State::HOLD , Call::State::OVER , Call::State::FAILURE }},/**/ @@ -125,7 +128,7 @@ const TypedStateMachine< TypedStateMachine< Call::State , Call::DaemonState> , C /*INIT */ {{Call::State::RINGING , Call::State::CURRENT , Call::State::BUSY , Call::State::HOLD , Call::State::OVER , Call::State::FAILURE }},/**/ }};// */ -const TypedStateMachine< TypedStateMachine< function , Call::DaemonState > , Call::State > CallPrivate::stateChangedFunctionMap = +const TypedStateMachine< TypedStateMachine< function , CallPrivate::DaemonState > , Call::State > CallPrivate::stateChangedFunctionMap = {{ // RINGING CURRENT BUSY HOLD HUNGUP FAILURE /**/ /*INCOMING */ {{CP::nothing , CP::start , CP::startWeird , CP::startWeird , CP::startStop , CP::failure }},/**/ @@ -185,6 +188,7 @@ const TypedStateMachine< TypedStateMachine< bool , Call::LifeCycleState > , Call /*^^ A call _can_ be created on hold (conference) and as over (peer hang up before pickup) the progress->failure one is an implementation bug*/ +QDebug LIB_EXPORT operator<<(QDebug dbg, const CallPrivate::DaemonState& c ); QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::State& c) { @@ -192,7 +196,7 @@ QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::State& c) return dbg.space(); } -QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::DaemonState& c) +QDebug LIB_EXPORT operator<<(QDebug dbg, const CallPrivate::DaemonState& c) { dbg.nospace() << static_cast<int>(c); return dbg.space(); @@ -231,7 +235,7 @@ m_pImModel(nullptr),m_pTimer(nullptr),m_Recording(false),m_Account(nullptr), m_PeerName(),m_pPeerContactMethod(nullptr),m_HistoryConst(HistoryTimeCategoryModel::HistoryConst::Never), m_pStartTimeStamp(0),m_pDialNumber(nullptr),m_pTransferNumber(nullptr), m_History(false),m_Missed(false),m_Direction(Call::Direction::OUTGOING),m_Type(Call::Type::CALL), -m_pUserActionModel(nullptr),m_HistoryState(Call::LegacyHistoryState::NONE), m_CurrentState(Call::State::ERROR) +m_pUserActionModel(nullptr), m_CurrentState(Call::State::ERROR),m_pCertificate(nullptr) { } @@ -311,7 +315,6 @@ Call* CallPrivate::buildExistingCall(const QString& callId) Call* call = new Call(startState, peerName, nb, acc); call->d_ptr->m_DringId = callId; call->d_ptr->m_Recording = callManager.getIsRecording(callId); - call->d_ptr->m_HistoryState = historyStateFromType(details[Call::HistoryMapFields::STATE]); if (!details[ CallPrivate::DetailsMapFields::TIMESTAMP_START ].isEmpty()) call->d_ptr->setStartTimeStamp(details[ CallPrivate::DetailsMapFields::TIMESTAMP_START ].toInt()); @@ -327,6 +330,11 @@ Call* CallPrivate::buildExistingCall(const QString& callId) call->peerContactMethod()->addCall(call); } + //Load the certificate if it's now available + if (!call->certificate() && !details[DRing::Call::Details::TLS_PEER_CERT].isEmpty()) { + call->d_ptr->m_pCertificate = CertificateModel::instance()->getCertificateFromContent(details[DRing::Call::Details::TLS_PEER_CERT].toLatin1()); + } + return call; } //buildExistingCall @@ -334,7 +342,6 @@ Call* CallPrivate::buildExistingCall(const QString& callId) Call* CallPrivate::buildDialingCall(const QString & peerName, Account* account) { Call* call = new Call(Call::State::DIALING, peerName, nullptr, account); - call->d_ptr->m_HistoryState = Call::LegacyHistoryState::NONE; call->d_ptr->m_Direction = Call::Direction::OUTGOING; if (Audio::Settings::instance()->isRoomToneEnabled()) { Audio::Settings::instance()->playRoomTone(); @@ -356,11 +363,16 @@ Call* CallPrivate::buildIncomingCall(const QString& callId) ContactMethod* nb = PhoneDirectoryModel::instance()->getNumber(from,acc); Call* call = new Call(Call::State::INCOMING, peerName, nb, acc); call->d_ptr->m_DringId = callId; - call->d_ptr->m_HistoryState = Call::LegacyHistoryState::MISSED; call->d_ptr->m_Direction = Call::Direction::INCOMING; if (call->peerContactMethod()) { call->peerContactMethod()->addCall(call); } + + //Load the certificate if it's now available + if (!call->certificate() && !details[DRing::Call::Details::TLS_PEER_CERT].isEmpty()) { + call->d_ptr->m_pCertificate = CertificateModel::instance()->getCertificateFromContent(details[DRing::Call::Details::TLS_PEER_CERT].toLatin1()); + } + return call; } //buildIncomingCall @@ -377,12 +389,17 @@ Call* CallPrivate::buildRingingCall(const QString & callId) ContactMethod* nb = PhoneDirectoryModel::instance()->getNumber(from,acc); Call* call = new Call(Call::State::RINGING, peerName, nb, acc); call->d_ptr->m_DringId = callId; - call->d_ptr->m_HistoryState = Call::LegacyHistoryState::OUTGOING; call->d_ptr->m_Direction = Call::Direction::OUTGOING; if (call->peerContactMethod()) { call->peerContactMethod()->addCall(call); } + + //Load the certificate if it's now available + if (!call->certificate() && !details[DRing::Call::Details::TLS_PEER_CERT].isEmpty()) { + call->d_ptr->m_pCertificate = CertificateModel::instance()->getCertificateFromContent(details[DRing::Call::Details::TLS_PEER_CERT].toLatin1()); + } + return call; } //buildRingingCall @@ -429,33 +446,21 @@ Call* Call::buildHistoryCall(const QMap<QString,QString>& hc) call->d_ptr->m_pStopTimeStamp = stopTimeStamp ; call->d_ptr->setStartTimeStamp(startTimeStamp); call->d_ptr->m_History = true; - call->d_ptr->m_HistoryState = CallPrivate::historyStateFromType(type); call->d_ptr->m_Account = AccountModel::instance()->getById(accId); - //BEGIN In ~2015, remove the old logic and clean this - if (missed || call->d_ptr->m_HistoryState == Call::LegacyHistoryState::MISSED) { + if (missed) { call->d_ptr->m_Missed = true; - call->d_ptr->m_HistoryState = Call::LegacyHistoryState::MISSED; } if (!direction.isEmpty()) { if (direction == Call::HistoryStateName::INCOMING) { call->d_ptr->m_Direction = Call::Direction::INCOMING ; - call->d_ptr->m_HistoryState = Call::LegacyHistoryState::INCOMING; } else if (direction == Call::HistoryStateName::OUTGOING) { call->d_ptr->m_Direction = Call::Direction::OUTGOING ; - call->d_ptr->m_HistoryState = Call::LegacyHistoryState::OUTGOING; } } - else if (call->d_ptr->m_HistoryState == Call::LegacyHistoryState::INCOMING) - call->d_ptr->m_Direction = Call::Direction::INCOMING ; - else if (call->d_ptr->m_HistoryState == Call::LegacyHistoryState::OUTGOING) - call->d_ptr->m_Direction = Call::Direction::OUTGOING ; else //Getting there is a bug. Pick one, even if it is the wrong one call->d_ptr->m_Direction = Call::Direction::OUTGOING ; - if (missed) - call->d_ptr->m_HistoryState = Call::LegacyHistoryState::MISSED; - //END call->setObjectName("History:"+call->d_ptr->m_DringId); @@ -484,18 +489,6 @@ Call* operator<<(Call* c, Call::Action action) return (!c) ? nullptr : (*c) << action; } -///Get the history state from the type (see Call.cpp header) -Call::LegacyHistoryState CallPrivate::historyStateFromType(const QString& type) -{ - if(type == Call::HistoryStateName::MISSED ) - return Call::LegacyHistoryState::MISSED ; - else if(type == Call::HistoryStateName::OUTGOING ) - return Call::LegacyHistoryState::OUTGOING ; - else if(type == Call::HistoryStateName::INCOMING ) - return Call::LegacyHistoryState::INCOMING ; - return Call::LegacyHistoryState::NONE ; -} - ///Get the start sate from the daemon state Call::State CallPrivate::startStateFromDaemonCallState(const QString& daemonCallState, const QString& daemonCallType) { @@ -525,25 +518,25 @@ Call::State CallPrivate::startStateFromDaemonCallState(const QString& daemonCall ****************************************************************************/ ///Transfer state from internal to daemon internal syntaz -Call::DaemonState CallPrivate::toDaemonCallState(const QString& stateName) +CallPrivate::DaemonState CallPrivate::toDaemonCallState(const QString& stateName) { if(stateName == CallPrivate::StateChange::HUNG_UP ) - return Call::DaemonState::HUNG_UP ; + return CallPrivate::DaemonState::HUNG_UP ; if(stateName == CallPrivate::StateChange::RINGING ) - return Call::DaemonState::RINGING ; + return CallPrivate::DaemonState::RINGING ; if(stateName == CallPrivate::StateChange::CURRENT ) - return Call::DaemonState::CURRENT ; + return CallPrivate::DaemonState::CURRENT ; if(stateName == CallPrivate::StateChange::UNHOLD_CURRENT ) - return Call::DaemonState::CURRENT ; + return CallPrivate::DaemonState::CURRENT ; if(stateName == CallPrivate::StateChange::HOLD ) - return Call::DaemonState::HOLD ; + return CallPrivate::DaemonState::HOLD ; if(stateName == CallPrivate::StateChange::BUSY ) - return Call::DaemonState::BUSY ; + return CallPrivate::DaemonState::BUSY ; if(stateName == CallPrivate::StateChange::FAILURE ) - return Call::DaemonState::FAILURE ; + return CallPrivate::DaemonState::FAILURE ; qDebug() << "stateChanged signal received with unknown state."; - return Call::DaemonState::FAILURE ; + return CallPrivate::DaemonState::FAILURE ; } //toDaemonCallState ///Transform a conference call state to a proper call state @@ -696,6 +689,12 @@ bool Call::hasRecording() const return !recordingPath().isEmpty() && QFile::exists(recordingPath()); } +///If this call is encrypted, return the certificate associated with it +Certificate* Call::certificate() const +{ + return d_ptr->m_pCertificate; +} + ///Generate an human readable string from the difference between StartTimeStamp and StopTimeStamp (or 'now') QString Call::length() const { @@ -715,7 +714,7 @@ QString Call::length() const } ///Is this call part of history -bool Call::isHistory() +bool Call::isHistory() const { if (lifeCycleState() == Call::LifeCycleState::FINISHED && !d_ptr->m_History) d_ptr->m_History = true; @@ -725,7 +724,7 @@ bool Call::isHistory() ///Is this call missed bool Call::isMissed() const { - return d_ptr->m_Missed || d_ptr->m_HistoryState == Call::LegacyHistoryState::MISSED; + return d_ptr->m_Missed; } ///Is the call incoming or outgoing @@ -787,12 +786,6 @@ const QString Call::recordingPath() const return d_ptr->m_RecordingPath; } -///Get the history state -Call::LegacyHistoryState Call::historyState() const -{ - return d_ptr->m_HistoryState; -} - ///This function could also be called mayBeSecure or haveChancesToBeEncryptedButWeCantTell. bool Call::isSecure() const { @@ -900,8 +893,8 @@ Call::State CallPrivate::stateChanged(const QString& newStateName) { const Call::State previousState = m_CurrentState; if (q_ptr->type() != Call::Type::CONFERENCE) { - Call::DaemonState dcs = toDaemonCallState(newStateName); - if (dcs == Call::DaemonState::COUNT__ || m_CurrentState == Call::State::COUNT__) { + CallPrivate::DaemonState dcs = toDaemonCallState(newStateName); + if (dcs == CallPrivate::DaemonState::COUNT__ || m_CurrentState == Call::State::COUNT__) { qDebug() << "Error: Invalid state change"; return Call::State::FAILURE; } @@ -925,7 +918,7 @@ Call::State CallPrivate::stateChanged(const QString& newStateName) FORCE_ERROR_STATE_P() return m_CurrentState; } - catch(Call::DaemonState& state) { + catch(CallPrivate::DaemonState& state) { qDebug() << "State change failed (stateChangedStateMap)" << state; FORCE_ERROR_STATE_P() return m_CurrentState; @@ -941,6 +934,11 @@ Call::State CallPrivate::stateChanged(const QString& newStateName) if (details[CallPrivate::DetailsMapFields::PEER_NAME] != m_PeerName) m_PeerName = details[CallPrivate::DetailsMapFields::PEER_NAME]; + //Load the certificate if it's now available + if (!q_ptr->certificate() && !details[DRing::Call::Details::TLS_PEER_CERT].isEmpty()) { + m_pCertificate = CertificateModel::instance()->getCertificateFromContent(details[DRing::Call::Details::TLS_PEER_CERT].toLatin1()); + } + try { (this->*(stateChangedFunctionMap[previousState][dcs]))(); } @@ -949,7 +947,7 @@ Call::State CallPrivate::stateChanged(const QString& newStateName) FORCE_ERROR_STATE_P() return m_CurrentState; } - catch(Call::DaemonState& state) { + catch(CallPrivate::DaemonState& state) { qDebug() << "State change failed (stateChangedFunctionMap)" << state; FORCE_ERROR_STATE_P() return m_CurrentState; @@ -1124,7 +1122,6 @@ void CallPrivate::accept() time_t curTime; ::time(&curTime); setStartTimeStamp(curTime); - this->m_HistoryState = Call::LegacyHistoryState::INCOMING; m_Direction = Call::Direction::INCOMING; } @@ -1137,7 +1134,6 @@ void CallPrivate::refuse() time_t curTime; ::time(&curTime); setStartTimeStamp(curTime); - this->m_HistoryState = Call::LegacyHistoryState::MISSED; m_Missed = true; //If the daemon crashed then re-spawned when a call is ringing, this happen. @@ -1169,7 +1165,6 @@ void CallPrivate::acceptHold() qDebug() << "Accepting call and holding it. callId : " << q_ptr << "ConfId:" << q_ptr; callManager.accept(m_DringId); Q_NOREPLY callManager.hold(m_DringId); - this->m_HistoryState = Call::LegacyHistoryState::INCOMING; m_Direction = Call::Direction::INCOMING; } @@ -1301,7 +1296,6 @@ void CallPrivate::call() time_t curTime; ::time(&curTime); setStartTimeStamp(curTime); - this->m_HistoryState = Call::LegacyHistoryState::OUTGOING; m_Direction = Call::Direction::OUTGOING; if (q_ptr->peerContactMethod()) { q_ptr->peerContactMethod()->addCall(q_ptr); @@ -1314,7 +1308,6 @@ void CallPrivate::call() else { qDebug() << "Trying to call " << (m_pTransferNumber?QString(m_pTransferNumber->uri()):"ERROR") << " with no account registered . callId : " << q_ptr << "ConfId:" << q_ptr; - this->m_HistoryState = Call::LegacyHistoryState::NONE; throw tr("No account registered!"); } } @@ -1642,12 +1635,17 @@ void CallPrivate::initTimer() } } +QVariant Call::roleData(Call::Role role) const +{ + return roleData(static_cast<int>(role)); +} + ///Common source for model data roles QVariant Call::roleData(int role) const { const Person* ct = peerContactMethod()?peerContactMethod()->contact():nullptr; switch (role) { - case Call::Role::Name: + case static_cast<int>(Call::Role::Name): case Qt::DisplayRole: if (type() == Call::Type::CONFERENCE) return tr("Conference"); @@ -1663,30 +1661,27 @@ QVariant Call::roleData(int role) const break; case Qt::EditRole: return dialNumber(); - case Call::Role::Number: + case static_cast<int>(Call::Role::Number): return peerContactMethod()->uri(); break; - case Call::Role::Direction2: + case static_cast<int>(Call::Role::Direction): return QVariant::fromValue(d_ptr->m_Direction); break; - case Call::Role::Date: + case static_cast<int>(Call::Role::Date): return (int)startTimeStamp(); break; - case Call::Role::Length: + case static_cast<int>(Call::Role::Length): return length(); break; - case Call::Role::FormattedDate: + case static_cast<int>(Call::Role::FormattedDate): return QDateTime::fromTime_t(startTimeStamp()).toString(); break; - case Call::Role::HasRecording: + case static_cast<int>(Call::Role::HasRecording): return hasRecording(); break; - case Call::Role::Historystate: - return QVariant::fromValue(historyState()); - break; - case Call::Role::Filter: { + case static_cast<int>(Call::Role::Filter): { QString normStripppedC; - foreach(QChar char2,(static_cast<int>(historyState())+'\n'+roleData(Call::Role::Name).toString()+'\n'+ + foreach(QChar char2,(static_cast<int>(direction())+'\n'+roleData(Call::Role::Name).toString()+'\n'+ roleData(Call::Role::Number).toString()).toLower().normalized(QString::NormalizationForm_KD) ) { if (!char2.combiningClass()) normStripppedC += char2; @@ -1694,68 +1689,71 @@ QVariant Call::roleData(int role) const return normStripppedC; } break; - case Call::Role::FuzzyDate: + case static_cast<int>(Call::Role::FuzzyDate): return QVariant::fromValue(d_ptr->m_HistoryConst); break; - case Call::Role::IsBookmark: + case static_cast<int>(Call::Role::IsBookmark): return false; break; - case Call::Role::Security: + case static_cast<int>(Call::Role::Security): return isSecure(); break; - case Call::Role::Department: + case static_cast<int>(Call::Role::Department): return ct?ct->department():QVariant(); break; - case Call::Role::Email: + case static_cast<int>(Call::Role::Email): return ct?ct->preferredEmail():QVariant(); break; - case Call::Role::Organisation: + case static_cast<int>(Call::Role::Organisation): return ct?ct->organization():QVariant(); break; - case Call::Role::Object: + case static_cast<int>(Call::Role::Object): return QVariant::fromValue(const_cast<Call*>(this)); break; - case Call::Role::PhoneNu: + case static_cast<int>(Call::Role::ContactMethod): return QVariant::fromValue(peerContactMethod()); break; - case Call::Role::PhotoPtr: + case static_cast<int>(Call::Role::Photo): return ct?ct->photo():QVariant(); break; - case Call::Role::CallState: + case static_cast<int>(Call::Role::State): return QVariant::fromValue(state()); break; - case Call::Role::StartTime: + case static_cast<int>(Call::Role::StartTime): return (int) d_ptr->m_pStartTimeStamp; - case Call::Role::StopTime: + case static_cast<int>(Call::Role::StopTime): return (int) d_ptr->m_pStopTimeStamp; - case Call::Role::IsRecording: + case static_cast<int>(Call::Role::IsRecording): return isRecording(); - case Call::Role::IsPresent: + case static_cast<int>(Call::Role::IsPresent): return peerContactMethod()->isPresent(); - case Call::Role::IsTracked: + case static_cast<int>(Call::Role::IsTracked): return peerContactMethod()->isTracked(); - case Call::Role::SupportPresence: + case static_cast<int>(Call::Role::SupportPresence): return peerContactMethod()->supportPresence(); - case Call::Role::CategoryIcon: + case static_cast<int>(Call::Role::CategoryIcon): return peerContactMethod()->category()->icon(peerContactMethod()->isTracked(),peerContactMethod()->isPresent()); - case Call::Role::CallCount: + case static_cast<int>(Call::Role::CallCount): return peerContactMethod()->callCount(); - case Call::Role::TotalSpentTime: + case static_cast<int>(Call::Role::TotalSpentTime): return peerContactMethod()->totalSpentTime(); - case Call::Role::DropState: + case static_cast<int>(Call::Role::Certificate): + return QVariant::fromValue(certificate()); + break; + case static_cast<int>(Call::Role::DropState): return property("dropState"); break; - case Call::Role::Missed: + case static_cast<int>(Call::Role::Missed): return isMissed(); - case Call::Role::CallLifeCycleState: + case static_cast<int>(Call::Role::LifeCycleState): return static_cast<int>(lifeCycleState()); //TODO Qt5, use the Q_ENUM - case Call::Role::DTMFAnimState: + case static_cast<int>(Call::Role::DTMFAnimState): return property("DTMFAnimState"); break; - case Call::Role::LastDTMFidx: + case static_cast<int>(Call::Role::LastDTMFidx): return property("latestDtmfIdx"); break; - case Call::Role::DropPosition: + case static_cast<int>(Call::Role::DropPosition): return property("dropPosition"); break; default: diff --git a/src/call.h b/src/call.h index 87ea78d7ca99faddb7ffcd812db1d4cd17fc35bf..6fe51cbcb51e226cce6bcc6c765e10a5f77a4c8c 100644 --- a/src/call.h +++ b/src/call.h @@ -31,12 +31,14 @@ class QTimer; //Ring #include "typedefs.h" #include "historytimecategorymodel.h" -class Account; -class InstantMessagingModel; -class UserActionModel; -class ContactMethod; +class Account ; +class InstantMessagingModel ; +class UserActionModel ; +class ContactMethod ; class TemporaryContactMethod; -class CollectionInterface; +class CollectionInterface ; +class Certificate ; + namespace Video { class Manager; class Renderer; @@ -66,50 +68,51 @@ class LIB_EXPORT Call : public ItemBase<QObject> Q_OBJECT #pragma GCC diagnostic pop public: - friend class CallModel; - friend class HistoryModel; - friend class CallModelPrivate; + friend class CallModel ; + friend class HistoryModel ; + friend class CallModelPrivate ; friend class IMConversationManager; - friend class Video::Manager; + friend class Video::Manager ; //Enum ///Model roles - enum Role { - Name = 100, /*!< The peer name from SIP or Persons */ - Number = 101, /*!< The peer URI / phone number (as text) */ - Direction2 = 102, /*!< */ - Date = 103, /*!< The date when the call started */ - Length = 104, /*!< The current length of the call */ - FormattedDate = 105, /*!< An human readable starting date */ - HasRecording = 106, /*!< If the call has a recording attached */ - Historystate = 107, /*!< */ - Filter = 108, /*!< */ - FuzzyDate = 109, /*!< */ - IsBookmark = 110, /*!< */ - Security = 111, /*!< */ - Department = 112, /*!< */ - Email = 113, /*!< */ - Organisation = 114, /*!< */ - Object = 117, /*!< */ - PhotoPtr = 118, /*!< */ - CallState = 119, /*!< */ - StartTime = 121, /*!< */ - StopTime = 122, /*!< */ - IsRecording = 123, /*!< */ - PhoneNu = 124, /*!< */ - IsPresent = 125, /*!< */ - SupportPresence = 126, /*!< */ - IsTracked = 127, /*!< */ - CategoryIcon = 128, /*!< */ - CallCount = 129, /*!< The number of calls made with the same phone number */ - TotalSpentTime = 130, /*!< The total time spent speaking to with this phone number*/ - Missed = 131, /*!< This call has been missed */ - CallLifeCycleState = 132, /*!< */ - DropState = 300, /*!< GUI related state to keep track of metadata during drag and drop */ - DTMFAnimState = 400, /*!< GUI related state to hold animation key(s) */ - LastDTMFidx = 401, /*!< The last DTMF (button) sent on this call */ - DropPosition = 402, /*!< GUI related state to keep track of metadata during drag and drop */ + enum class Role { + Name = 100, /*!< The peer name from SIP or Persons */ + Number = 101, /*!< The peer URI / phone number (as text) */ + Direction = 102, /*!< */ + Date = 103, /*!< The date when the call started */ + Length = 104, /*!< The current length of the call */ + FormattedDate = 105, /*!< An human readable starting date */ + HasRecording = 106, /*!< If the call has a recording attached */ + Historystate = 107, /*!< */ + Filter = 108, /*!< */ + FuzzyDate = 109, /*!< */ + IsBookmark = 110, /*!< */ + Security = 111, /*!< */ + Department = 112, /*!< */ + Email = 113, /*!< */ + Organisation = 114, /*!< */ + Object = 117, /*!< */ + Photo = 118, /*!< */ + State = 119, /*!< */ + StartTime = 121, /*!< */ + StopTime = 122, /*!< */ + IsRecording = 123, /*!< */ + ContactMethod = 124, /*!< */ + IsPresent = 125, /*!< */ + SupportPresence = 126, /*!< */ + IsTracked = 127, /*!< */ + CategoryIcon = 128, /*!< */ + CallCount = 129, /*!< The number of calls made with the same phone number */ + TotalSpentTime = 130, /*!< The total time spent speaking to with this phone number */ + Missed = 131, /*!< This call has been missed */ + LifeCycleState = 132, /*!< */ + Certificate = 133, /*!< The certificate (for encrypted calls) */ + DropState = 300, /*!< GUI related state to keep track of metadata during drag and drop */ + DTMFAnimState = 400, /*!< GUI related state to hold animation key(s) */ + LastDTMFidx = 401, /*!< The last DTMF (button) sent on this call */ + DropPosition = 402, /*!< GUI related state to keep track of metadata during drag and drop */ }; enum DropAction { @@ -119,40 +122,24 @@ public: ///Possible call states enum class State : unsigned int{ - INCOMING = 0, /*!< Ringing incoming call */ - RINGING = 1, /*!< Ringing outgoing call */ - CURRENT = 2, /*!< Call to which the user can speak and hear */ - DIALING = 3, /*!< Call which numbers are being added by the user */ - HOLD = 4, /*!< Call is on hold */ - FAILURE = 5, /*!< Call has failed */ - BUSY = 6, /*!< Call is busy */ + INCOMING = 0, /*!< Ringing incoming call */ + RINGING = 1, /*!< Ringing outgoing call */ + CURRENT = 2, /*!< Call to which the user can speak and hear */ + DIALING = 3, /*!< Call which numbers are being added by the user */ + HOLD = 4, /*!< Call is on hold */ + FAILURE = 5, /*!< Call has failed */ + BUSY = 6, /*!< Call is busy */ TRANSFERRED = 7, /*!< Call is being transferred. During this state, the user can enter the new number. */ - TRANSF_HOLD = 8, /*!< Call is on hold for transfer */ - OVER = 9, /*!< Call is over and should not be used */ - ERROR = 10,/*!< This state should never be reached */ - CONFERENCE = 11,/*!< This call is the current conference*/ - CONFERENCE_HOLD = 12,/*!< This call is a conference on hold*/ - INITIALIZATION = 13,/*!< The call have been placed, but the peer hasn't confirmed yet */ + TRANSF_HOLD = 8, /*!< Call is on hold for transfer */ + OVER = 9, /*!< Call is over and should not be used */ + ERROR = 10,/*!< This state should never be reached */ + CONFERENCE = 11,/*!< This call is the current conference */ + CONFERENCE_HOLD = 12,/*!< This call is a conference on hold */ + INITIALIZATION = 13,/*!< The call have been placed, but the peer hasn't confirmed yet */ COUNT__, }; Q_ENUMS(State) - /** - * @enum Call::LegacyHistoryState - * History items create before December 2013 will have a "state" field - * mixing direction and missed. Newer items will have separated fields for that. - * - * Ring-KDE will keep support for at least a year - */ - enum class LegacyHistoryState : int //DEPRECATED remove - { - INCOMING, /*!< The call is coming from the peer */ - OUTGOING, /*!< The call is going to the peer */ - MISSED , /*!< The call has been missed */ - NONE /*!< The legacy state is not set */ - }; - Q_ENUMS(LegacyHistoryState) - ///@enum Direction If the user have been called or have called enum class Direction : int { INCOMING, /*!< Someone has called */ @@ -167,30 +154,16 @@ public: HISTORY , /*!< A call from a previous session */ }; - /** @enum Call::DaemonState - * This enum have all the states a call can take for the daemon. - */ - enum class DaemonState : unsigned int - { - RINGING = 0, /*!< Ringing outgoing or incoming call */ - CURRENT = 1, /*!< Call to which the user can speak and hear */ - BUSY = 2, /*!< Call is busy */ - HOLD = 3, /*!< Call is on hold */ - HUNG_UP = 4, /*!< Call is over */ - FAILURE = 5, /*!< Call has failed */ - COUNT__, - }; - /** @enum Call::Action * This enum have all the actions you can make on a call. */ enum class Action : unsigned int { ACCEPT = 0, /*!< Accept, create or place call or place transfer */ - REFUSE = 1, /*!< Red button, refuse or hang up */ - TRANSFER = 2, /*!< Put into or out of transfer mode*/ - HOLD = 3, /*!< Hold or unhold the call */ - RECORD = 4, /*!< Enable or disable recording */ + REFUSE = 1, /*!< Red button, refuse or hang up */ + TRANSFER = 2, /*!< Put into or out of transfer mode */ + HOLD = 3, /*!< Hold or unhold the call */ + RECORD = 4, /*!< Enable or disable recording */ COUNT__, }; @@ -207,7 +180,7 @@ public: COUNT__ }; - ///"getHistory()" fields + ///TODO should be deprecated when a better factory system is implemented class HistoryMapFields { public: constexpr static const char* ACCOUNT_ID = "accountid" ; @@ -225,6 +198,7 @@ public: constexpr static const char* NUMBER_TYPE = "number_type" ; }; + //TODO should be deprecated when a better factory system is implemented ///@class HistoryStateName history map fields state names class HistoryStateName { public: @@ -234,31 +208,31 @@ public: }; //Read only properties - Q_PROPERTY( Call::State state READ state NOTIFY stateChanged ) - Q_PROPERTY( QString historyId READ historyId ) - Q_PROPERTY( Account* account READ account ) - Q_PROPERTY( bool isHistory READ isHistory ) - Q_PROPERTY( uint stopTimeStamp READ stopTimeStamp ) - Q_PROPERTY( uint startTimeStamp READ startTimeStamp ) - Q_PROPERTY( bool isSecure READ isSecure ) - 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 ) - Q_PROPERTY( bool recording READ isRecording ) - Q_PROPERTY( UserActionModel* userActionModel READ userActionModel CONSTANT ) - Q_PROPERTY( QString toHumanStateName READ toHumanStateName ) - Q_PROPERTY( bool missed READ isMissed ) - Q_PROPERTY( Direction direction READ direction ) - Q_PROPERTY( bool hasVideo READ hasVideo ) - Q_PROPERTY( Call::LegacyHistoryState historyState READ historyState ) + Q_PROPERTY( Call::State state READ state NOTIFY stateChanged ) + Q_PROPERTY( QString historyId READ historyId ) + Q_PROPERTY( Account* account READ account ) + Q_PROPERTY( bool isHistory READ isHistory ) + Q_PROPERTY( uint stopTimeStamp READ stopTimeStamp ) + Q_PROPERTY( uint startTimeStamp READ startTimeStamp ) + Q_PROPERTY( bool isSecure READ isSecure ) + 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 ) + Q_PROPERTY( bool recording READ isRecording ) + Q_PROPERTY( UserActionModel* userActionModel READ userActionModel CONSTANT ) + Q_PROPERTY( QString toHumanStateName READ toHumanStateName ) + Q_PROPERTY( bool missed READ isMissed ) + Q_PROPERTY( Direction direction READ direction ) + Q_PROPERTY( bool hasVideo READ hasVideo ) + Q_PROPERTY( Certificate* certificate READ certificate ) //Read/write properties - Q_PROPERTY( ContactMethod* peerContactMethod READ peerContactMethod ) - Q_PROPERTY( QString peerName READ peerName WRITE setPeerName ) - Q_PROPERTY( QString transferNumber READ transferNumber WRITE setTransferNumber ) - Q_PROPERTY( QString recordingPath READ recordingPath WRITE setRecordingPath ) - Q_PROPERTY( QString dialNumber READ dialNumber WRITE setDialNumber NOTIFY dialNumberChanged(QString)) + Q_PROPERTY( ContactMethod* peerContactMethod READ peerContactMethod ) + Q_PROPERTY( QString peerName READ peerName WRITE setPeerName ) + Q_PROPERTY( QString transferNumber READ transferNumber WRITE setTransferNumber ) + Q_PROPERTY( QString recordingPath READ recordingPath WRITE setRecordingPath ) + Q_PROPERTY( QString dialNumber READ dialNumber WRITE setDialNumber NOTIFY dialNumberChanged(QString)) //Constructors & Destructors static Call* buildHistoryCall (const QMap<QString,QString>& hc); @@ -271,7 +245,6 @@ public: const QString historyId () const; ContactMethod* peerContactMethod() const; const QString peerName () const; - Call::LegacyHistoryState historyState () const; bool isRecording () const; Account* account () const; bool isHistory () const; @@ -285,16 +258,17 @@ public: const QString formattedName () const; bool hasRecording () const; QString length () const; - QVariant roleData (int role) const; UserActionModel* userActionModel () const; QString toHumanStateName () const; - bool isHistory () ; bool isMissed () const; Call::Direction direction () const; bool hasVideo () const; Call::LifeCycleState lifeCycleState () const; Call::Type type () const; bool hasRemote () const; + Certificate* certificate () const; + QVariant roleData (int role) const; + QVariant roleData (Role role) const; //Automated function Call::State performAction(Call::Action action); @@ -358,12 +332,13 @@ Q_SIGNALS: Q_DECLARE_METATYPE(Call*) Q_DECLARE_METATYPE(Call::State) +Q_DECLARE_METATYPE(Call::Type) +Q_DECLARE_METATYPE(Call::Action) Q_DECLARE_METATYPE(Call::Direction) -Q_DECLARE_METATYPE(Call::LegacyHistoryState) +Q_DECLARE_METATYPE(Call::LifeCycleState) Call* operator<<(Call* c, Call::Action a); QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::State& c ); -QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::DaemonState& c ); QDebug LIB_EXPORT operator<<(QDebug dbg, const Call::Action& c ); #endif diff --git a/src/callmodel.cpp b/src/callmodel.cpp index 73f8f578c490f6d48499346a54ca99f294321c75..fbee91a2bf8cb7723b93fa09bb913897a4ba1740 100644 --- a/src/callmodel.cpp +++ b/src/callmodel.cpp @@ -218,30 +218,31 @@ QHash<int,QByteArray> CallModel::roleNames() const static bool initRoles = false; if (!initRoles) { initRoles = true; - roles.insert(Call::Role::Name ,QByteArray("name")); - roles.insert(Call::Role::Number ,QByteArray("number")); - roles.insert(Call::Role::Direction2 ,QByteArray("direction")); - roles.insert(Call::Role::Date ,QByteArray("date")); - roles.insert(Call::Role::Length ,QByteArray("length")); - roles.insert(Call::Role::FormattedDate ,QByteArray("formattedDate")); - roles.insert(Call::Role::HasRecording ,QByteArray("hasRecording")); - roles.insert(Call::Role::Historystate ,QByteArray("historyState")); - roles.insert(Call::Role::Filter ,QByteArray("filter")); - roles.insert(Call::Role::FuzzyDate ,QByteArray("fuzzyDate")); - roles.insert(Call::Role::IsBookmark ,QByteArray("isBookmark")); - roles.insert(Call::Role::Security ,QByteArray("security")); - roles.insert(Call::Role::Department ,QByteArray("department")); - roles.insert(Call::Role::Email ,QByteArray("email")); - roles.insert(Call::Role::Organisation ,QByteArray("organisation")); - roles.insert(Call::Role::Object ,QByteArray("object")); - roles.insert(Call::Role::PhotoPtr ,QByteArray("photoPtr")); - roles.insert(Call::Role::CallState ,QByteArray("callState")); - roles.insert(Call::Role::StartTime ,QByteArray("startTime")); - roles.insert(Call::Role::StopTime ,QByteArray("stopTime")); - roles.insert(Call::Role::DropState ,QByteArray("dropState")); - roles.insert(Call::Role::DTMFAnimState ,QByteArray("dTMFAnimState")); - roles.insert(Call::Role::LastDTMFidx ,QByteArray("lastDTMFidx")); - roles.insert(Call::Role::IsRecording ,QByteArray("isRecording")); + roles.insert(static_cast<int>(Call::Role::Name ) ,QByteArray("name")); + roles.insert(static_cast<int>(Call::Role::Number ) ,QByteArray("number")); + roles.insert(static_cast<int>(Call::Role::Direction ) ,QByteArray("direction")); + roles.insert(static_cast<int>(Call::Role::Date ) ,QByteArray("date")); + roles.insert(static_cast<int>(Call::Role::Length ) ,QByteArray("length")); + roles.insert(static_cast<int>(Call::Role::FormattedDate ) ,QByteArray("formattedDate")); + roles.insert(static_cast<int>(Call::Role::HasRecording ) ,QByteArray("hasRecording")); + roles.insert(static_cast<int>(Call::Role::Historystate ) ,QByteArray("historyState")); + roles.insert(static_cast<int>(Call::Role::Filter ) ,QByteArray("filter")); + roles.insert(static_cast<int>(Call::Role::FuzzyDate ) ,QByteArray("fuzzyDate")); + roles.insert(static_cast<int>(Call::Role::IsBookmark ) ,QByteArray("isBookmark")); + roles.insert(static_cast<int>(Call::Role::Security ) ,QByteArray("security")); + roles.insert(static_cast<int>(Call::Role::Department ) ,QByteArray("department")); + roles.insert(static_cast<int>(Call::Role::Email ) ,QByteArray("email")); + roles.insert(static_cast<int>(Call::Role::Organisation ) ,QByteArray("organisation")); + roles.insert(static_cast<int>(Call::Role::Object ) ,QByteArray("object")); + roles.insert(static_cast<int>(Call::Role::Photo ) ,QByteArray("photo")); + roles.insert(static_cast<int>(Call::Role::State ) ,QByteArray("state")); + roles.insert(static_cast<int>(Call::Role::StartTime ) ,QByteArray("startTime")); + roles.insert(static_cast<int>(Call::Role::StopTime ) ,QByteArray("stopTime")); + roles.insert(static_cast<int>(Call::Role::DropState ) ,QByteArray("dropState")); + roles.insert(static_cast<int>(Call::Role::DTMFAnimState ) ,QByteArray("dTMFAnimState")); + roles.insert(static_cast<int>(Call::Role::LastDTMFidx ) ,QByteArray("lastDTMFidx")); + roles.insert(static_cast<int>(Call::Role::IsRecording ) ,QByteArray("isRecording")); + roles.insert(static_cast<int>(Call::Role::LifeCycleState) ,QByteArray("lifeCycleState")); } return roles; } @@ -344,8 +345,8 @@ UserActionModel* CallModel::userActionModel() const ///Get the call associated with this index Call* CallModel::getCall( const QModelIndex& idx ) const { - if (idx.isValid() && rowCount(idx.parent()) > idx.row() && idx.data(Call::Role::Object).canConvert<Call*>()) - return qvariant_cast<Call*>(idx.data(Call::Role::Object)); + if (idx.isValid() && rowCount(idx.parent()) > idx.row() && idx.data(static_cast<int>(Call::Role::Object)).canConvert<Call*>()) + return qvariant_cast<Call*>(idx.data(static_cast<int>(Call::Role::Object))); return nullptr; } @@ -699,7 +700,7 @@ void CallModelPrivate::removeConference(Call* call) bool CallModel::setData( const QModelIndex& idx, const QVariant &value, int role) { if (idx.isValid()) { - if (role == Call::Role::DropState) { + if (role == static_cast<int>(Call::Role::DropState)) { Call* call = getCall(idx); if (call) call->setProperty("dropState",value.toInt()); @@ -714,7 +715,7 @@ bool CallModel::setData( const QModelIndex& idx, const QVariant &value, int role return true; } } - else if (role == Call::Role::DTMFAnimState) { + else if (role == static_cast<int>(Call::Role::DTMFAnimState)) { Call* call = getCall(idx); if (call) { call->setProperty("DTMFAnimState",value.toInt()); @@ -722,7 +723,7 @@ bool CallModel::setData( const QModelIndex& idx, const QVariant &value, int role return true; } } - else if (role == Call::Role::DropPosition) { + else if (role == static_cast<int>(Call::Role::DropPosition)) { Call* call = getCall(idx); if (call) { call->setProperty("dropPosition",value.toInt()); @@ -855,7 +856,7 @@ QMimeData* CallModel::mimeData(const QModelIndexList& indexes) const QMimeData* mData = new QMimeData(); foreach (const QModelIndex &idx, indexes) { if (idx.isValid()) { - const QString text = data(idx, Call::Role::Number).toString(); + const QString text = data(idx, static_cast<int>(Call::Role::Number)).toString(); mData->setData(RingMimes::PLAIN_TEXT , text.toUtf8()); Call* call = getCall(idx); if (call) { @@ -934,7 +935,7 @@ bool CallModel::dropMimeData(const QMimeData* mimedata, Qt::DropAction action, i } //Drop a call on a conference -> add it to the conference else if (target && (targetIdx.parent().isValid() || target->type() == Call::Type::CONFERENCE)) { - Call* conf = target->type() == Call::Type::CONFERENCE?target:qvariant_cast<Call*>(targetIdx.parent().data(Call::Role::Object)); + Call* conf = target->type() == Call::Type::CONFERENCE?target:qvariant_cast<Call*>(targetIdx.parent().data(static_cast<int>(Call::Role::Object))); if (conf) { qDebug() << "Adding call " << call << "to conference" << conf; addParticipant(call,conf); @@ -1262,7 +1263,7 @@ void CallModelPrivate::slotDTMFPlayed( const QString& str ) call->setProperty("latestDtmfIdx",idx); } const QModelIndex& idx = q_ptr->getIndex(call); - q_ptr->setData(idx,50, Call::Role::DTMFAnimState); + q_ptr->setData(idx,50, static_cast<int>(Call::Role::DTMFAnimState)); } ///Called when a recording state change diff --git a/src/certificate.cpp b/src/certificate.cpp index 3b11201ffcd30a0f41a55e45ea03626abb93f001..c239783fefa42514bbdfa6abf8d9831a85423b2f 100644 --- a/src/certificate.cpp +++ b/src/certificate.cpp @@ -80,17 +80,30 @@ public: Certificate::CheckValues m_NotActivated ; }; +/** + * Certificates can be loaded either from disk or directly from the + * network sockets. In that case, they don't (always) need to be saved + */ +enum class LoadingType { + FROM_PATH, + FROM_CONTENT +}; + class CertificatePrivate { public: //Types typedef Certificate::CheckValues (Certificate::*accessor)(); - //Attributes - CertificatePrivate(); + //Constructor + CertificatePrivate(LoadingType _ltype); ~CertificatePrivate(); - QUrl m_Path; - Certificate::Type m_Type; + + //Attributes + QUrl m_Path ; + Certificate::Type m_Type ; + QByteArray m_Content ; + LoadingType m_LoadingType; mutable DetailsCache* m_pDetailsCache; mutable ChecksCache* m_pCheckCache ; @@ -200,8 +213,8 @@ Matrix1D<Certificate::Details,QString> CertificatePrivate::m_slDetailssDescripti }}; -CertificatePrivate::CertificatePrivate() : -m_pCheckCache(nullptr), m_pDetailsCache(nullptr) +CertificatePrivate::CertificatePrivate(LoadingType _type) : +m_pCheckCache(nullptr), m_pDetailsCache(nullptr), m_LoadingType(_type) { } @@ -271,7 +284,15 @@ ChecksCache::ChecksCache(const MapStringString& checks) void CertificatePrivate::loadDetails() { if (!m_pDetailsCache) { - const MapStringString d = DBus::ConfigurationManager::instance().getCertificateDetails(m_Path.toString()); + MapStringString d; + switch(m_LoadingType) { + case LoadingType::FROM_PATH: + d = DBus::ConfigurationManager::instance().getCertificateDetails(m_Path.toString()); + break; + case LoadingType::FROM_CONTENT: + d = DBus::ConfigurationManager::instance().getCertificateDetailsRaw(m_Content); + break; + } m_pDetailsCache = new DetailsCache(d); } } @@ -284,13 +305,19 @@ void CertificatePrivate::loadChecks() } } -Certificate::Certificate(const QUrl& path, Type type, const QUrl& privateKey) : QObject(CertificateModel::instance()),d_ptr(new CertificatePrivate()) +Certificate::Certificate(const QUrl& path, Type type, const QUrl& privateKey) : QObject(CertificateModel::instance()),d_ptr(new CertificatePrivate(LoadingType::FROM_PATH)) { Q_UNUSED(privateKey) d_ptr->m_Path = path.path(); d_ptr->m_Type = type; } +Certificate::Certificate(const QByteArray& content, Type type): QObject(CertificateModel::instance()),d_ptr(new CertificatePrivate(LoadingType::FROM_CONTENT)) +{ + d_ptr->m_Content = content; + d_ptr->m_Type = type; +} + Certificate::~Certificate() { diff --git a/src/certificate.h b/src/certificate.h index d2d8243b77737bc224c4374063bc4ee9efd71ef4..e35bd98063110da0453251c0b6e2dee8045a5af7 100644 --- a/src/certificate.h +++ b/src/certificate.h @@ -83,6 +83,7 @@ public: AUTHORITY , USER , PRIVATE_KEY, + CALL , NONE , }; @@ -229,6 +230,7 @@ public: private: explicit Certificate(const QUrl& path, Type type = Type::NONE, const QUrl& privateKey = QUrl()); + Certificate(const QByteArray& content, Type type = Type::CALL); virtual ~Certificate(); CertificatePrivate* d_ptr; diff --git a/src/certificatemodel.cpp b/src/certificatemodel.cpp index cb3a2738eb8d662bb0d741eefb671c34f7fd1a2b..1b27c7a0925815cff7804c875f2a53fd8d5ea960 100644 --- a/src/certificatemodel.cpp +++ b/src/certificatemodel.cpp @@ -20,6 +20,7 @@ //Qt #include <QtCore/QCoreApplication> #include <QtCore/QObject> +#include <QtCore/QCryptographicHash> //LibSTDC++ #include <functional> @@ -304,4 +305,11 @@ Certificate* CertificateModel::getCertificate(const QUrl& path, Certificate::Typ } return cert; -} \ No newline at end of file +} + +Certificate* CertificateModel::getCertificateFromContent(const QByteArray& rawContent, bool save) +{ + QCryptographicHash hash(QCryptographicHash::Sha1); + hash.addData(rawContent); + return nullptr; +} diff --git a/src/certificatemodel.h b/src/certificatemodel.h index 216380aa3726d4ce7fbb519cc5cf59f5fcc6e875..da5baee1818cf95fc07a58342da6b0d00be2a7af 100644 --- a/src/certificatemodel.h +++ b/src/certificatemodel.h @@ -51,6 +51,7 @@ public: //Mutator Certificate* getCertificate(const QUrl& path, Certificate::Type type = Certificate::Type::NONE); + Certificate* getCertificateFromContent(const QByteArray& rawContent, bool save = true); //Singleton static CertificateModel* instance(); diff --git a/src/contactmethod.cpp b/src/contactmethod.cpp index 2741bc520dbc20db45bc14e9a6d0ed9710facb0d..17787f5ad6326dc2f5be77751044f117f7b2efe6 100644 --- a/src/contactmethod.cpp +++ b/src/contactmethod.cpp @@ -444,7 +444,7 @@ void ContactMethod::addCall(Call* call) if (now - 3600*24*7*15 < call->stopTimeStamp()) d_ptr->m_LastTrimCount++; - if (call->historyState() == Call::LegacyHistoryState::OUTGOING || call->direction() == Call::Direction::OUTGOING) + if (call->direction() == Call::Direction::OUTGOING) d_ptr->m_HaveCalled = true; d_ptr->callAdded(call); diff --git a/src/contactmethod.h b/src/contactmethod.h index 94707d9b5454afe0b3d2c9cef4605c627f668f8d..682444eee77abf33e41fa6c5f761195ce6511c09 100644 --- a/src/contactmethod.h +++ b/src/contactmethod.h @@ -48,7 +48,7 @@ public: //Properties Q_PROPERTY(Account* account READ account WRITE setAccount ) - Q_PROPERTY(Person* contact READ contact WRITE setPerson ) + Q_PROPERTY(Person* person READ contact WRITE setPerson ) Q_PROPERTY(int lastUsed READ lastUsed ) Q_PROPERTY(QString uri READ uri ) Q_PROPERTY(int callCount READ callCount ) @@ -81,37 +81,37 @@ public: Q_ENUMS(Type) //Getters - URI uri () const; - NumberCategory* category () const; - bool isTracked () const; - bool isPresent () const; - QString presenceMessage () const; - Account* account () const; - Person* contact () const; - time_t lastUsed () const; - ContactMethod::Type type () const; - int callCount () const; - uint weekCount () const; - uint trimCount () const; - bool haveCalled () const; - QList<Call*> calls () const; - int popularityIndex () const; - QHash<QString,int> alternativeNames() const; - QString primaryName () const; - bool isBookmarked () const; - bool supportPresence () const; - QVariant icon () const; - int totalSpentTime () const; - QString uid () const; + URI uri () const; + NumberCategory* category () const; + bool isTracked () const; + bool isPresent () const; + QString presenceMessage () const; + Account* account () const; + Person* contact () const; + time_t lastUsed () const; + ContactMethod::Type type () const; + int callCount () const; + uint weekCount () const; + uint trimCount () const; + bool haveCalled () const; + QList<Call*> calls () const; + int popularityIndex () const; + QHash<QString,int> alternativeNames() const; + QString primaryName () const; + bool isBookmarked () const; + bool supportPresence () const; + QVariant icon () const; + int totalSpentTime () const; + QString uid () const; //Setters - Q_INVOKABLE void setAccount(Account* account); - Q_INVOKABLE void setPerson(Person* contact); - Q_INVOKABLE void setTracked(bool track ); - void setCategory(NumberCategory* cat ); - void setBookmarked(bool bookmarked ); - void setUid(const QString& uri ); - bool setType(ContactMethod::Type t ); + Q_INVOKABLE void setAccount (Account* account ); + Q_INVOKABLE void setPerson (Person* contact ); + Q_INVOKABLE void setTracked (bool track ); + void setCategory (NumberCategory* cat ); + void setBookmarked(bool bookmarked); + void setUid (const QString& uri ); + bool setType (ContactMethod::Type t ); //Mutator Q_INVOKABLE void addCall(Call* call); diff --git a/src/contactproxymodel.cpp b/src/contactproxymodel.cpp index 6c66aba890c204f16638734ccbff0a72de98a432..a987d4d9b3c2fcc56fce6e3200be0600119494c5 100644 --- a/src/contactproxymodel.cpp +++ b/src/contactproxymodel.cpp @@ -366,7 +366,7 @@ QVariant ContactProxyModel::headerData(int section, Qt::Orientation orientation, bool ContactProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { Q_UNUSED( action ) - setData(parent,-1,Call::Role::DropState); + setData(parent,-1,static_cast<int>(Call::Role::DropState)); if (data->hasFormat(RingMimes::CALLID)) { const QByteArray encodedCallId = data->data( RingMimes::CALLID ); const QModelIndex targetIdx = index ( row,column,parent ); diff --git a/src/historymodel.cpp b/src/historymodel.cpp index fb76009911146e3de3fbfda6aa0c0144a309dad5..4d81506ba9a2db054a1d175100c9323d015d584d 100644 --- a/src/historymodel.cpp +++ b/src/historymodel.cpp @@ -182,7 +182,7 @@ Call* HistoryModelPrivate::HistoryItem::call() const ****************************************************************************/ HistoryModelPrivate::HistoryModelPrivate(HistoryModel* parent) : QObject(parent), q_ptr(parent), -m_Role(Call::Role::FuzzyDate) +m_Role(static_cast<int>(Call::Role::FuzzyDate)) { } @@ -215,30 +215,30 @@ QHash<int,QByteArray> HistoryModel::roleNames() const static bool initRoles = false; if (!initRoles) { initRoles = true; - roles.insert(Call::Role::Name ,QByteArray("name" )); - roles.insert(Call::Role::Number ,QByteArray("number" )); - roles.insert(Call::Role::Direction2 ,QByteArray("direction" )); - roles.insert(Call::Role::Date ,QByteArray("date" )); - roles.insert(Call::Role::Length ,QByteArray("length" )); - roles.insert(Call::Role::FormattedDate ,QByteArray("formattedDate" )); - roles.insert(Call::Role::HasRecording ,QByteArray("hasRecording" )); - roles.insert(Call::Role::Historystate ,QByteArray("historyState" )); - roles.insert(Call::Role::Filter ,QByteArray("filter" )); - roles.insert(Call::Role::FuzzyDate ,QByteArray("fuzzyDate" )); - roles.insert(Call::Role::IsBookmark ,QByteArray("isBookmark" )); - roles.insert(Call::Role::Security ,QByteArray("security" )); - roles.insert(Call::Role::Department ,QByteArray("department" )); - roles.insert(Call::Role::Email ,QByteArray("email" )); - roles.insert(Call::Role::Organisation ,QByteArray("organisation" )); - roles.insert(Call::Role::Object ,QByteArray("object" )); - roles.insert(Call::Role::PhotoPtr ,QByteArray("photoPtr" )); - roles.insert(Call::Role::CallState ,QByteArray("callState" )); - roles.insert(Call::Role::StartTime ,QByteArray("startTime" )); - roles.insert(Call::Role::StopTime ,QByteArray("stopTime" )); - roles.insert(Call::Role::DropState ,QByteArray("dropState" )); - roles.insert(Call::Role::DTMFAnimState ,QByteArray("dTMFAnimState" )); - roles.insert(Call::Role::LastDTMFidx ,QByteArray("lastDTMFidx" )); - roles.insert(Call::Role::IsRecording ,QByteArray("isRecording" )); + roles.insert(static_cast<int>(Call::Role::Name ) ,QByteArray("name" )); + roles.insert(static_cast<int>(Call::Role::Number ) ,QByteArray("number" )); + roles.insert(static_cast<int>(Call::Role::Direction ) ,QByteArray("direction" )); + roles.insert(static_cast<int>(Call::Role::Date ) ,QByteArray("date" )); + roles.insert(static_cast<int>(Call::Role::Length ) ,QByteArray("length" )); + roles.insert(static_cast<int>(Call::Role::FormattedDate ) ,QByteArray("formattedDate" )); + roles.insert(static_cast<int>(Call::Role::HasRecording ) ,QByteArray("hasRecording" )); + roles.insert(static_cast<int>(Call::Role::Historystate ) ,QByteArray("historyState" )); + roles.insert(static_cast<int>(Call::Role::Filter ) ,QByteArray("filter" )); + roles.insert(static_cast<int>(Call::Role::FuzzyDate ) ,QByteArray("fuzzyDate" )); + roles.insert(static_cast<int>(Call::Role::IsBookmark ) ,QByteArray("isBookmark" )); + roles.insert(static_cast<int>(Call::Role::Security ) ,QByteArray("security" )); + roles.insert(static_cast<int>(Call::Role::Department ) ,QByteArray("department" )); + roles.insert(static_cast<int>(Call::Role::Email ) ,QByteArray("email" )); + roles.insert(static_cast<int>(Call::Role::Organisation ) ,QByteArray("organisation" )); + roles.insert(static_cast<int>(Call::Role::Object ) ,QByteArray("object" )); + roles.insert(static_cast<int>(Call::Role::Photo ) ,QByteArray("photo" )); + roles.insert(static_cast<int>(Call::Role::State ) ,QByteArray("state" )); + roles.insert(static_cast<int>(Call::Role::StartTime ) ,QByteArray("startTime" )); + roles.insert(static_cast<int>(Call::Role::StopTime ) ,QByteArray("stopTime" )); + roles.insert(static_cast<int>(Call::Role::DropState ) ,QByteArray("dropState" )); + roles.insert(static_cast<int>(Call::Role::DTMFAnimState ) ,QByteArray("dTMFAnimState" )); + roles.insert(static_cast<int>(Call::Role::LastDTMFidx ) ,QByteArray("lastDTMFidx" )); + roles.insert(static_cast<int>(Call::Role::IsRecording ) ,QByteArray("isRecording" )); } return roles; } @@ -263,7 +263,7 @@ HistoryTopLevelItem* HistoryModelPrivate::getCategory(const Call* call) HistoryTopLevelItem* category = nullptr; static QString name; int index = -1; - if (m_Role == Call::Role::FuzzyDate) { + if (m_Role == static_cast<int>(Call::Role::FuzzyDate)) { index = call->roleData(Call::Role::FuzzyDate).toInt(); name = HistoryTimeCategoryModel::indexToName(index); category = m_hCategories[index]; @@ -407,7 +407,7 @@ bool HistoryModel::setData( const QModelIndex& idx, const QVariant &value, int r { if (idx.isValid() && idx.parent().isValid()) { CategorizedCompositeNode* modelItem = (CategorizedCompositeNode*)idx.internalPointer(); - if (role == Call::Role::DropState) { + if (role == static_cast<int>(Call::Role::DropState)) { modelItem->setDropState(value.toInt()); emit dataChanged(idx, idx); } @@ -426,15 +426,15 @@ QVariant HistoryModel::data( const QModelIndex& idx, int role) const switch (role) { case Qt::DisplayRole: return static_cast<HistoryTopLevelItem*>(modelItem)->m_NameStr; - case Call::Role::FuzzyDate: - case Call::Role::Date: + case static_cast<int>(Call::Role::FuzzyDate): + case static_cast<int>(Call::Role::Date): return d_ptr->m_lCategoryCounter.size() - static_cast<HistoryTopLevelItem*>(modelItem)->m_Index; default: break; } break; case CategorizedCompositeNode::Type::CALL: - if (role == Call::Role::DropState) + if (role == static_cast<int>(Call::Role::DropState)) return QVariant(modelItem->dropState()); else { const int parRow = idx.parent().row(); @@ -556,7 +556,7 @@ QMimeData* HistoryModel::mimeData(const QModelIndexList &indexes) const QMimeData *mimeData2 = new QMimeData(); foreach (const QModelIndex &idx, indexes) { if (idx.isValid()) { - const QString text = data(idx, Call::Role::Number).toString(); + const QString text = data(idx, static_cast<int>(Call::Role::Number)).toString(); mimeData2->setData(RingMimes::PLAIN_TEXT , text.toUtf8()); const Call* call = (Call*)((CategorizedCompositeNode*)(idx.internalPointer()))->getSelf(); mimeData2->setData(RingMimes::PHONENUMBER, call->peerContactMethod()->toHash().toUtf8()); @@ -575,7 +575,7 @@ bool HistoryModel::dropMimeData(const QMimeData *mime, Qt::DropAction action, in Q_UNUSED(row) Q_UNUSED(column) Q_UNUSED(action) - setData(parentIdx,-1,Call::Role::DropState); + setData(parentIdx,-1,static_cast<int>(Call::Role::DropState)); QByteArray encodedContactMethod = mime->data( RingMimes::PHONENUMBER ); QByteArray encodedPerson = mime->data( RingMimes::CONTACT ); @@ -630,7 +630,7 @@ int HistoryModel::acceptedPayloadTypes() const return CallModel::DropPayloadType::CALL; } -void HistoryModel::setCategoryRole(Call::Role role) +void HistoryModel::setCategoryRole(int role) { if (d_ptr->m_Role != role) { d_ptr->m_Role = role; diff --git a/src/historymodel.h b/src/historymodel.h index b7475493346aa5b3d994c251a7d691aaf0de1c78..3ab9c2e09a50a3a587007a51cc798194eba1f8db 100644 --- a/src/historymodel.h +++ b/src/historymodel.h @@ -63,7 +63,7 @@ public: virtual bool clearAllCollections() const override; //Setters - void setCategoryRole(Call::Role role); + void setCategoryRole(int role); void setHistoryLimited(bool isLimited); void setHistoryLimit(int numberOfDays); diff --git a/src/private/call_p.h b/src/private/call_p.h index 14624dcecd1b14a8cea9541c79a6ef91434be244..096b364a85cf34deeb41e9a3a9f2ea0567bd25d9 100644 --- a/src/private/call_p.h +++ b/src/private/call_p.h @@ -31,6 +31,7 @@ class Account; class ContactMethod; class UserActionModel; class InstantMessagingModel; +class Certificate; class CallPrivate; typedef void (CallPrivate::*function)(); @@ -96,6 +97,20 @@ public: constexpr static const char* OUTGOING = "1"; }; + /** @enum DaemonState + * This enum have all the states a call can take for the daemon. + */ + enum class DaemonState : unsigned int + { + RINGING = 0, /*!< Ringing outgoing or incoming call */ + CURRENT = 1, /*!< Call to which the user can speak and hear */ + BUSY = 2, /*!< Call is busy */ + HOLD = 3, /*!< Call is on hold */ + HUNG_UP = 4, /*!< Call is over */ + FAILURE = 5, /*!< Call has failed */ + COUNT__, + }; + explicit CallPrivate(Call* parent); //Attributes @@ -104,7 +119,6 @@ public: ContactMethod* m_pPeerContactMethod; QString m_PeerName ; QString m_RecordingPath ; - Call::LegacyHistoryState m_HistoryState ; time_t m_pStartTimeStamp ; time_t m_pStopTimeStamp ; Call::State m_CurrentState ; @@ -116,6 +130,7 @@ public: bool m_Missed ; Call::Direction m_Direction ; Call::Type m_Type ; + Certificate* m_pCertificate ; mutable TemporaryContactMethod* m_pTransferNumber ; mutable TemporaryContactMethod* m_pDialNumber ; @@ -144,7 +159,7 @@ public: * callStateChanged with arg daemon_new_state * on a call in state orig_state. **/ - static const TypedStateMachine< TypedStateMachine< Call::State , Call::DaemonState > , Call::State > stateChangedStateMap; + static const TypedStateMachine< TypedStateMachine< Call::State , DaemonState > , Call::State > stateChangedStateMap; /** * stateChangedFunctionMap[orig_state][daemon_new_state] @@ -152,7 +167,7 @@ public: * callStateChanged with arg daemon_new_state * on a call in state orig_state. **/ - static const TypedStateMachine< TypedStateMachine< function , Call::DaemonState > , Call::State > stateChangedFunctionMap; + static const TypedStateMachine< TypedStateMachine< function , DaemonState > , Call::State > stateChangedFunctionMap; /** * metaStateTransitionValidationMap help validate if a state transition violate the lifecycle logic. @@ -169,7 +184,7 @@ public: static Call* buildHistoryCall (const QMap<QString,QString>& hc); - static Call::DaemonState toDaemonCallState (const QString& stateName); + static DaemonState toDaemonCallState (const QString& stateName); static Call::State confStatetoCallState(const QString& stateName); Call::State stateChanged(const QString & newState); void performAction(Call::State previousState, Call::Action action); @@ -206,7 +221,6 @@ public: void initTimer(); //Static getters - static Call::LegacyHistoryState historyStateFromType ( const QString& type ); static Call::State startStateFromDaemonCallState ( const QString& daemonCallState, const QString& daemonCallType ); //Constructor diff --git a/src/useractionmodel.cpp b/src/useractionmodel.cpp index c19438e9192fae705c33c109567b395ea6c5e86c..055cc6e68627c71a4bd2e629e7f30d12b1278ffd 100644 --- a/src/useractionmodel.cpp +++ b/src/useractionmodel.cpp @@ -386,7 +386,7 @@ bool UserActionModelPrivate::updateAction(UserActionModel::Action action) //Aggregate and reduce the action state for each selected calls for (const QModelIndex& idx : CallModel::instance()->selectionModel()->selectedRows()) { - const Call* c = qvariant_cast<Call*>(idx.data(Call::Role::Object)); + const Call* c = qvariant_cast<Call*>(idx.data(static_cast<int>(Call::Role::Object))); updateCheckMask ( state ,action, c ); ret &= updateByCall( action , c ); } @@ -433,7 +433,7 @@ bool UserActionModel::execute(const UserActionModel::Action action) const break; case UserActionModelPrivate::UserActionModelMode::CALLMODEL: { for (const QModelIndex& idx : CallModel::instance()->selectionModel()->selectedRows()) { - Call* c = qvariant_cast<Call*>(idx.data(Call::Role::Object)); + Call* c = qvariant_cast<Call*>(idx.data(static_cast<int>(Call::Role::Object))); if (c) selected << c; } diff --git a/xml/configurationmanager-introspec.xml b/xml/configurationmanager-introspec.xml index 3c219b4809747d6db78122aadce6a29fddadd29e..6b0f38963ce998a9a0eefb3b7a0e4ddd0a36a646 100644 --- a/xml/configurationmanager-introspec.xml +++ b/xml/configurationmanager-introspec.xml @@ -664,6 +664,21 @@ </arg> </method> + <method name="getCertificateDetailsRaw" tp:name-for-bindings="getCertificateDetailsRaw"> + <arg type="ay" name="certificateRaw" direction="in"> + <tp:docstring> + <p>A raw certificate</p> + </tp:docstring> + </arg> + <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/> + <arg type="a{ss}" name="details" direction="out"> + <tp:docstring> + <p>A key-value list of all certificate details</p> + The constants used as keys are defined in the "security.h" constants header file + </tp:docstring> + </arg> + </method> + <method name="getAddrFromInterfaceName" tp:name-for-bindings="getAddrFromInterfaceName"> <arg type="s" name="interface" direction="in"> </arg>