diff --git a/components/fullscreenpanel.cpp b/components/fullscreenpanel.cpp --- a/components/fullscreenpanel.cpp +++ b/components/fullscreenpanel.cpp @@ -96,6 +96,3 @@ using namespace KWayland::Client; QQuickWindow::showEvent(event); } - -#include "fullscreenpanel.moc" - diff --git a/containments/homescreen/applicationlistmodel.cpp b/containments/homescreen/applicationlistmodel.cpp --- a/containments/homescreen/applicationlistmodel.cpp +++ b/containments/homescreen/applicationlistmodel.cpp @@ -201,7 +201,7 @@ return m_applicationList.count(); } -void ApplicationListModel::moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild) +void ApplicationListModel::moveRow(const QModelIndex& /* sourceParent */, int sourceRow, const QModelIndex& /* destinationParent */, int destinationChild) { moveItem(sourceRow, destinationChild); } @@ -249,7 +249,7 @@ KService::Ptr service = KService::serviceByStorageId(storageId); - KRun::run(*service, QList(), 0); + KRun::runService(*service, QList(), 0); } QStringList ApplicationListModel::appOrder() const @@ -272,5 +272,3 @@ } emit appOrderChanged(); } - -#include "applicationlistmodel.moc" diff --git a/dialer/package/contents/ui/Dialer/Dialer.qml b/dialer/package/contents/ui/Dialer/Dialer.qml --- a/dialer/package/contents/ui/Dialer/Dialer.qml +++ b/dialer/package/contents/ui/Dialer/Dialer.qml @@ -29,10 +29,6 @@ property alias numberEntryText: status.text - function addNumber(number) { - status.text = status.text + number - } - Rectangle { width: parent.width / 2 x: parent.width / 4 @@ -59,24 +55,21 @@ margins: units.largeSpacing } - PlasmaComponents.Label { + PhoneNumberInput { id: status + Layout.fillWidth: true - Layout.minimumHeight: parent.height / 6 + Layout.minimumHeight: units.gridUnit * 3.5 Layout.maximumHeight: Layout.minimumHeight - - horizontalAlignment: Qt.AlignRight - verticalAlignment: Qt.AlignVCenter - font.pointSize: 1024 - fontSizeMode: Text.Fit + font.pointSize: 30 } Dialpad { Layout.fillWidth: true Layout.fillHeight: true callback: function (string) { - addNumber(string); + status.append(string) } pressedCallback: function (string) { //TODO diff --git a/dialer/package/contents/ui/Dialpad/DialerButton.qml b/dialer/package/contents/ui/Dialpad/DialerButton.qml --- a/dialer/package/contents/ui/Dialpad/DialerButton.qml +++ b/dialer/package/contents/ui/Dialpad/DialerButton.qml @@ -9,6 +9,7 @@ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details * @@ -23,22 +24,16 @@ import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents -PlasmaComponents.Label { +Item { + id: root Layout.fillWidth: true Layout.fillHeight: true - //This is 0 to override the Label default height that would cause a binding loop - height: 0 - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignTop - font.pointSize: 21 //anything higher for some reason makes number 4 not rendered - minimumPointSize: 8 - fontSizeMode: Text.VerticalFit - - property alias sub: longHold.text - property var callback - property var pressedCallback - property var releasedCallback + property string text + property string sub + property string display + property string subdisplay + property bool special: false Rectangle { anchors.fill: parent @@ -57,68 +52,61 @@ MouseArea { id: mouse anchors.fill: parent + onPressed: { - if (pressedCallback) { - pressedCallback(parent.text); - } else if (pad.pressedCallback) { + if (pad.pressedCallback) { pad.pressedCallback(parent.text); } } onReleased: { - if (releasedCallback) { - releasedCallback(parent.text); - } else if (pad.releasedCallback) { + if (pad.releasedCallback) { pad.releasedCallback(parent.text); } } onCanceled: { - if (releasedCallback) { - releasedCallback(parent.text); - } else if (pad.releasedCallback) { + if (pad.releasedCallback) { pad.releasedCallback(parent.text); } } - onClicked: { - if (callback) { - callback(parent.text); - } else if (pad.callback) { + if (pad.callback) { pad.callback(parent.text); } } - onPressAndHold: { - var text; - if (longHold.visible) { - text = longHold.text; - } else { - text = parent.text; - } - - if (text.length > 1) { - return; - } - - if (callback) { - callback(text); - } else if (pad.callback) { + var text = parent.sub.length > 0 ? parent.sub : parent.text + if (pad.callback && text.length === 1) { pad.callback(text); } } } - PlasmaComponents.Label { - id: longHold - anchors { - bottom: parent.bottom + ColumnLayout { + spacing: -5 + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + + PlasmaComponents.Label { + id: main + + text: root.display || root.text + opacity: special? 0.4 : 1.0 + // anything higher for some reason makes number 4 not rendered + font.pointSize: 30 + fontSizeMode: Text.VerticalFit + Layout.minimumWidth: parent.width + horizontalAlignment: Text.AlignHCenter } - height: parent.height * 0.4 - width: parent.width - verticalAlignment: Text.AlignBottom - horizontalAlignment: Text.AlignHCenter - visible: text.length > 0 - opacity: 0.4 - fontSizeMode: Text.VerticalFit + PlasmaComponents.Label { + id: longHold + + text: root.subdisplay || root.sub + opacity: 0.4 + font.pointSize: 16 + fontSizeMode: Text.VerticalFit + Layout.minimumWidth: parent.width + horizontalAlignment: Text.AlignHCenter + } } } diff --git a/dialer/package/contents/ui/Dialpad/DialerIconButton.qml b/dialer/package/contents/ui/Dialpad/DialerIconButton.qml --- a/dialer/package/contents/ui/Dialpad/DialerIconButton.qml +++ b/dialer/package/contents/ui/Dialpad/DialerIconButton.qml @@ -56,7 +56,7 @@ id: icon anchors.verticalCenter: parent.verticalCenter width: height - height: buttonRoot.height * 0.6 + height: units.gridUnit * 3.5 } PlasmaComponents.Label { id: label diff --git a/dialer/package/contents/ui/Dialpad/Dialpad.qml b/dialer/package/contents/ui/Dialpad/Dialpad.qml --- a/dialer/package/contents/ui/Dialpad/Dialpad.qml +++ b/dialer/package/contents/ui/Dialpad/Dialpad.qml @@ -26,34 +26,37 @@ GridLayout { id: pad columns: 3 + rowSpacing: 10 + columnSpacing: 10 property var callback property var pressedCallback property var releasedCallback - property int buttonHeight: parent.height / 6 - - DialerButton { id: one; text: "1" } + DialerButton { id: one; text: "1" } DialerButton { text: "2"; sub: "ABC" } DialerButton { text: "3"; sub: "DEF" } - DialerButton { text: "4"; sub: "GHI" } + DialerButton { text: "4"; sub: "GHI" } DialerButton { text: "5"; sub: "JKL" } DialerButton { text: "6"; sub: "MNO" } - DialerButton { text: "7"; sub: "PQRS" } + DialerButton { text: "7"; sub: "PQRS" } DialerButton { text: "8"; sub: "TUV" } DialerButton { text: "9"; sub: "WXYZ" } - DialerButton { text: "*"; } - DialerButton { text: "0"; sub: "+"; } - DialerButton { text: "#" } + DialerButton { display: "*"; text: "*"; special: true; } + DialerButton { text: "0"; subdisplay: "+"; sub: "+"; } + DialerButton { display: "#"; text: "#"; special: true; } + Item { + Layout.fillWidth: true + Layout.fillHeight: true + } DialerIconButton { id: callButton Layout.fillWidth: true - Layout.maximumHeight: buttonHeight - Layout.minimumHeight: Layout.maximumHeight + Layout.fillHeight: true enabled: status.text.length > 0 opacity: enabled ? 1 : 0.5 @@ -64,19 +67,6 @@ } Item { Layout.fillWidth: true - } - DialerIconButton { - Layout.fillWidth: true - Layout.maximumHeight: buttonHeight - Layout.minimumHeight: Layout.maximumHeight - - enabled: status.text.length > 0 - opacity: enabled ? 1 : 0.5 - source: "edit-clear" - callback: function(text) { - if (status.text.length > 0) { - status.text = status.text.substr(0, status.text.length - 1); - } - } + Layout.fillHeight: true } } diff --git a/dialer/package/contents/ui/Dialpad/PhoneNumberInput.qml b/dialer/package/contents/ui/Dialpad/PhoneNumberInput.qml new file mode 100644 --- /dev/null +++ b/dialer/package/contents/ui/Dialpad/PhoneNumberInput.qml @@ -0,0 +1,62 @@ +import QtQuick 2.0 +import QtQuick.Controls.Styles 1.4 +import QtQuick.Layouts 1.1 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents + +PlasmaComponents.TextField { + id: root + + horizontalAlignment: Qt.AlignHCenter + verticalAlignment: Qt.AlignBottom + + style: TextFieldStyle { + background: Rectangle { + opacity: 0 + } + } + + signal append(string digit) + onAppend: { + text += digit + } + onTextChanged: { + text = dialerUtils.formatNumber(text); + } + + // TODO: search through contacts while typing + + Row { + anchors { + right: parent.right + rightMargin: 6 + verticalCenter: parent.verticalCenter + } + + PlasmaCore.IconItem { + id: delBtn + // ltr confusingly refers to the direction of the arrow in the icon, + // not the text direction which it should be used in. + source: LayoutMirroring.enabled ? + "edit-clear-locationbar-ltr" : "edit-clear-locationbar-rtl" + height: Math.max(root.height * 0.8, units.iconSizes.small) + width: height + opacity: (root.length > 0 && root.enabled) ? 1 : 0 + visible: opacity > 0 + Behavior on opacity { + NumberAnimation { + duration: units.longDuration + easing.type: Easing.InOutQuad + } + } + MouseArea { + anchors.fill: parent + onClicked: { + if (text.length > 0) { + text = text.slice(0, -1); + } + } + } + } + } +} diff --git a/dialer/plugin/kpeoplehelperplugin.cpp b/dialer/plugin/kpeoplehelperplugin.cpp --- a/dialer/plugin/kpeoplehelperplugin.cpp +++ b/dialer/plugin/kpeoplehelperplugin.cpp @@ -27,5 +27,3 @@ qmlRegisterType(uri, 1, 0, "KPeopleHelper"); } - -#include "kpeoplehelperplugin.moc" diff --git a/dialer/src/CMakeLists.txt b/dialer/src/CMakeLists.txt --- a/dialer/src/CMakeLists.txt +++ b/dialer/src/CMakeLists.txt @@ -11,8 +11,10 @@ target_compile_definitions(plasmaphonedialer PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") #find_package(ActiveApp REQUIRED) +find_library(phonenumber REQUIRED) target_link_libraries(plasmaphonedialer + phonenumber Qt5::Gui Qt5::Quick Qt5::Widgets diff --git a/dialer/src/dialerutils.h b/dialer/src/dialerutils.h --- a/dialer/src/dialerutils.h +++ b/dialer/src/dialerutils.h @@ -58,6 +58,7 @@ Q_INVOKABLE void resetMissedCalls(); Q_INVOKABLE void dial(const QString &number); + Q_INVOKABLE const QString formatNumber(const QString& number); Q_SIGNALS: void missedCallsActionTriggered(); @@ -77,9 +78,9 @@ int m_missedCalls; QString m_callState; Tp::AccountPtr m_simAccount; - QString m_callContactAlias; QString m_callContactNumber; uint m_callDuration; + QString m_callContactAlias; bool m_isIncomingCall; }; diff --git a/dialer/src/dialerutils.cpp b/dialer/src/dialerutils.cpp --- a/dialer/src/dialerutils.cpp +++ b/dialer/src/dialerutils.cpp @@ -20,15 +20,17 @@ #include -#include #include #include #include #include #include #include #include +#include "phonenumbers/phonenumberutil.h" +#include "phonenumbers/asyoutypeformatter.h" + DialerUtils::DialerUtils(const Tp::AccountPtr &simAccount, QObject *parent) : QObject(parent), m_missedCalls(0), @@ -77,6 +79,33 @@ return m_callState; } +const QString DialerUtils::formatNumber(const QString& number) +{ + using namespace ::i18n::phonenumbers; + + // Get formatter instance + QLocale locale; + QStringList qcountry = locale.name().split('_'); + QString countrycode(qcountry.constLast()); + const char* country = countrycode.toUtf8().constData(); + PhoneNumberUtil* util = PhoneNumberUtil::GetInstance(); + AsYouTypeFormatter* formatter = util->PhoneNumberUtil::GetAsYouTypeFormatter(country); + + // Normalize input + string stdnumber = number.toUtf8().constData(); + util->NormalizeDiallableCharsOnly(&stdnumber); + + // Format + string formatted; + formatter->Clear(); + for (char& c : stdnumber) { + formatter->InputDigit(c, &formatted); + } + delete formatter; + + return QString::fromStdString(formatted); +} + void DialerUtils::setCallState(const QString &state) { if (m_callState != state) { diff --git a/dialer/src/main.cpp b/dialer/src/main.cpp --- a/dialer/src/main.cpp +++ b/dialer/src/main.cpp @@ -52,25 +52,35 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) { - // TODO: print it on stdout too? QFile file(QDir::homePath() + "/dialer.log"); bool opened = file.open(QIODevice::WriteOnly | QIODevice::Append); Q_ASSERT(opened); - QTextStream out(&file); + QString strout; + QTextStream out(&strout); out << QTime::currentTime().toString("hh:mm:ss.zzz "); out << context.function << ":" << context.line << " "; switch (type) { - case QtDebugMsg: out << "DBG"; break; + case QtDebugMsg: out << "DBG"; break; + case QtInfoMsg: out << "NFO"; break; case QtWarningMsg: out << "WRN"; break; case QtCriticalMsg: out << "CRT"; break; case QtFatalMsg: out << "FTL"; break; } out << " " << msg << '\n'; + + // Write to log file + QTextStream fileout(&file); + fileout << strout; out.flush(); + + // Write to stdout + QTextStream console(stdout); + console << strout; + console.flush(); } int main(int argc, char **argv)