[dialer] Add call timer to the call page

This commit is contained in:
Martin Klapetek 2015-06-29 18:16:10 +02:00
parent a8db07cf55
commit 3e68d4589f
4 changed files with 35 additions and 2 deletions

View file

@ -122,7 +122,7 @@ Item {
//STATUS_DIALING //STATUS_DIALING
} else if (ofonoWrapper.status == "dialing") { } else if (ofonoWrapper.status == "dialing") {
return i18n("Calling..."); return i18n("Calling...");
} else if (ofonoWrapper.duration > 0) { } else if (dialerUtils.duration > 0) {
return secondsToTimeString(ofonoWrapper.duration); return secondsToTimeString(ofonoWrapper.duration);
} else { } else {
return ''; return '';

View file

@ -16,6 +16,7 @@
*/ */
#include "call-manager.h" #include "call-manager.h"
#include "dialerutils.h" #include "dialerutils.h"
#include <QTimer>
#include <KNotification> #include <KNotification>
#include <KLocalizedString> #include <KLocalizedString>
@ -36,6 +37,7 @@ struct CallManager::Private
KNotification *ringingNotification; KNotification *ringingNotification;
KNotification *callsNotification; KNotification *callsNotification;
uint missedCalls; uint missedCalls;
QTimer *callTimer;
}; };
CallManager::CallManager(const Tp::CallChannelPtr &callChannel, DialerUtils *dialerUtils, QObject *parent) CallManager::CallManager(const Tp::CallChannelPtr &callChannel, DialerUtils *dialerUtils, QObject *parent)
@ -58,6 +60,7 @@ CallManager::CallManager(const Tp::CallChannelPtr &callChannel, DialerUtils *dia
d->ringingNotification = nullptr; d->ringingNotification = nullptr;
d->callsNotification = nullptr; d->callsNotification = nullptr;
d->callTimer = nullptr;
//create the channel handler //create the channel handler
// d->channelHandler = new CallChannelHandler(callChannel, this); // d->channelHandler = new CallChannelHandler(callChannel, this);
@ -147,6 +150,12 @@ void CallManager::onCallStateChanged(Tp::CallState state)
// delete d->approver.data(); // delete d->approver.data();
} }
d->dialerUtils->setCallState("active"); d->dialerUtils->setCallState("active");
d->callTimer = new QTimer(this);
connect(d->callTimer, &QTimer::timeout, [=]() {
d->dialerUtils->setCallDuration(d->dialerUtils->callDuration() + 1);
});
d->callTimer->start(1000);
// ensureCallWindow(); // ensureCallWindow();
// d->callWindow.data()->setStatus(CallWindow::StatusActive); // d->callWindow.data()->setStatus(CallWindow::StatusActive);
break; break;
@ -178,6 +187,13 @@ void CallManager::onCallStateChanged(Tp::CallState state)
d->callsNotification->update(); d->callsNotification->update();
} }
} }
if (d->callTimer) {
d->callTimer->stop();
d->callTimer->deleteLater();
d->callTimer = nullptr;
d->dialerUtils->setCallDuration(0);
}
//if we requested the call, make sure we have a window to show the error (if any) //if we requested the call, make sure we have a window to show the error (if any)
// if (d->callChannel->isRequested()) { // if (d->callChannel->isRequested()) {
// ensureCallWindow(); // ensureCallWindow();

View file

@ -32,7 +32,8 @@
DialerUtils::DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent) DialerUtils::DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent)
: QObject(parent), : QObject(parent),
m_missedCalls(0), m_missedCalls(0),
m_simAccount(simAccount) m_simAccount(simAccount),
m_callDuration(0),
{ {
Tp::PendingReady *op = m_simAccount->becomeReady(Tp::Features() << Tp::Account::FeatureCore); Tp::PendingReady *op = m_simAccount->becomeReady(Tp::Features() << Tp::Account::FeatureCore);
@ -82,6 +83,17 @@ void DialerUtils::setCallState(const QString &state)
} }
} }
uint DialerUtils::callDuration() const
{
return m_callDuration;
}
void DialerUtils::setCallDuration(uint duration)
{
m_callDuration = duration;
Q_EMIT callDurationChanged();
}
void DialerUtils::resetMissedCalls() void DialerUtils::resetMissedCalls()
{ {
m_missedCalls = 0; m_missedCalls = 0;

View file

@ -29,6 +29,7 @@ class DialerUtils : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString callState READ callState NOTIFY callStateChanged); Q_PROPERTY(QString callState READ callState NOTIFY callStateChanged);
Q_PROPERTY(uint callDuration READ callDuration NOTIFY callDurationChanged);
public: public:
DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent = 0); DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent = 0);
@ -37,12 +38,15 @@ public:
QString callState() const; QString callState() const;
void setCallState(const QString &state); void setCallState(const QString &state);
uint callDuration() const;
void setCallDuration(uint duration);
Q_INVOKABLE void resetMissedCalls(); Q_INVOKABLE void resetMissedCalls();
Q_INVOKABLE void dial(const QString &number); Q_INVOKABLE void dial(const QString &number);
Q_SIGNALS: Q_SIGNALS:
void missedCallsActionTriggered(); void missedCallsActionTriggered();
void callStateChanged(); void callStateChanged();
void callDurationChanged();
void acceptCall(); void acceptCall();
void rejectCall(); void rejectCall();
void hangUp(); void hangUp();
@ -53,6 +57,7 @@ private:
int m_missedCalls; int m_missedCalls;
QString m_callState; QString m_callState;
Tp::AccountPtr m_simAccount; Tp::AccountPtr m_simAccount;
uint m_callDuration;
}; };