Skip to content

Commit 70429fe

Browse files
committed
Add notifications
1 parent e7e7e86 commit 70429fe

17 files changed

+429
-16
lines changed

Diff for: click/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifest.json DESTINATION ${CMAKE_INST
3434
install(FILES ${PROJECT_NAME}.apparmor DESTINATION ${DATA_DIR})
3535
install(FILES ${DESKTOP_FILE_NAME} DESTINATION ${DATA_DIR})
3636
install(FILES ./run.sh PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ DESTINATION ${CMAKE_INSTALL_BINDIR})
37+
38+
39+
install(FILES exphone-helper PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ DESTINATION ${DATA_DIR})
40+
install(FILES exphone-push-helper.json DESTINATION ${DATA_DIR})
41+
install(FILES exphone-push.apparmor DESTINATION ${DATA_DIR})

Diff for: click/exphone-helper

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/python3
2+
import sys
3+
f1, f2 = sys.argv[1:3]
4+
open(f2, "w").write(open(f1).read())

Diff for: click/exphone-push-helper.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"exec": "exphone-helper"
3+
}

Diff for: click/exphone-push.apparmor

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"template": "ubuntu-push-helper",
3+
"policy_groups": [
4+
"push-notification-client"
5+
],
6+
"policy_version": 20.04
7+
}

Diff for: click/manifest.json.in

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"exphone": {
88
"apparmor": "exphone.apparmor",
99
"desktop": "exphone.desktop"
10+
},
11+
"push": {
12+
"apparmor": "exphone-push.apparmor",
13+
"push-helper": "exphone-push-helper.json"
1014
}
1115
},
1216
"version": "1.0.1",

Diff for: daemon/CMakeLists.txt

+20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1+
file(GLOB TS_FILES translations/*.ts)
2+
13
add_executable(exphoned
24
daemon.cpp
35
blockcontroler.cpp
46
blockcontroler.h
7+
${TS_FILES}
58
)
69

10+
11+
if(FLAVOR STREQUAL "uuitk")
12+
add_definitions(-DTRANSLATION_FOLDER="../share/exphone/translations")
13+
else()
14+
add_definitions(-DTRANSLATION_FOLDER=".")
15+
endif()
16+
17+
QT5_ADD_TRANSLATION(QM_FILES ${TS_FILES})
18+
add_custom_target(exphoned_translations DEPENDS ${QM_FILES})
19+
add_dependencies(exphoned exphoned_translations)
20+
21+
QT5_CREATE_TRANSLATION(QT_FILES "${CMAKE_SOURCE_DIR}"
22+
OPTIONS "-no-obsolete")
23+
24+
install(FILES ${QM_FILES}
25+
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/exphone/translations")
26+
727
install(TARGETS exphoned RUNTIME
828
DESTINATION ${CMAKE_INSTALL_BINDIR})
929

Diff for: daemon/blockcontroler.cpp

+52-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
#include <QObject>
2+
#include <QString>
3+
#include <QJsonObject>
4+
#include <QJsonArray>
5+
16
#include "blockcontroler.h"
27
#include "exphoneconfig.h"
3-
#include <QObject>
8+
#include "pushclient.h"
9+
410

511
BlockControler::BlockControler(QObject *parent) :
612
QObject(parent) {
713

814
m_blockModel.initDb();
915

16+
showNotification("+420123456789", "Phishing");
17+
1018
#if defined(MER_EDITION_SAILFISH) || defined(UUITK_EDITION)
1119
connect(&m_voiceCallController, &watchfish::VoiceCallController::ringingChanged, this, &BlockControler::onRingingChanged);
1220
#endif
@@ -50,6 +58,48 @@ void BlockControler::incomingCall(const QString &_callerId, const QString &calle
5058
#if defined(MER_EDITION_SAILFISH) || defined(UUITK_EDITION)
5159
m_voiceCallController.hangup();
5260
#endif
53-
qDebug() << "TODO send notification";
61+
showNotification(callerId, callerName);
5462
}
5563
}
64+
65+
66+
void BlockControler::showNotification(const QString &callerId, const QString &callerName) {
67+
#if defined(UUITK_EDITION)
68+
QString summary = QObject::tr("Phone call was blocked");
69+
QString body;
70+
if ((callerName == "") || (callerId == callerName)) {
71+
//: phone number in notification body formatted as "%s"
72+
body = tr("%1").arg(callerId);
73+
} else {
74+
//: phone number and contact name formatted as "%s (%s)"
75+
body = tr("%1 (%2)").arg(callerId, callerName);
76+
}
77+
78+
QString icon = QString("file://%1/../share/icons/hicolor/512x512/apps/exphone.png").arg(QCoreApplication::applicationDirPath());
79+
80+
QJsonObject c;
81+
c["summary"] = summary;
82+
c["body"] = body;
83+
c["popup"] = true;
84+
c["persist"] = true;
85+
c["icon"] = icon;
86+
// QJsonArray actions = QJsonArray();
87+
// QString actionUri = QStringLiteral("appid://com.github.jmlich.exphone/exphone/current-user-version");
88+
// actions.append(actionUri);
89+
// c["actions"] = actions;
90+
91+
QJsonObject notification;
92+
notification["card"] = c;
93+
notification["sound"] = true;
94+
notification["vibrate"] = false;
95+
QJsonObject message;
96+
message["notification"] = notification;
97+
98+
PushClient *pushClient = PushClient::instance();
99+
if (pushClient->send(message)) {
100+
qDebug() << Q_FUNC_INFO << "Message sent successfully." << summary;
101+
} else {
102+
qWarning() << Q_FUNC_INFO << "Failed to send the message." << summary;
103+
}
104+
#endif
105+
}

Diff for: daemon/blockcontroler.h

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class BlockControler: public QObject {
2222

2323
void incomingCall(const QString &callerId, const QString &callerName);
2424

25+
void showNotification(const QString &callerId, const QString &callerName);
26+
27+
2528
public slots:
2629
void onRingingChanged();
2730

Diff for: daemon/daemon.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ int main(int argc, char **argv)
4242
QCoreApplication::setApplicationName("exphone");
4343
QCoreApplication::setOrganizationName("exphone");
4444
QCoreApplication::setOrganizationDomain("com.github.jmlich");
45+
46+
{
47+
QString tr_path(TRANSLATION_FOLDER);
48+
if (QDir::isRelativePath(tr_path)) {
49+
tr_path = QDir(QFileInfo(QCoreApplication::applicationFilePath()).absolutePath() + "/" + tr_path ).absolutePath();
50+
}
51+
52+
QString locale = QLocale::system().name();
53+
QTranslator *translator = new QTranslator();
54+
if ( translator->load(QLocale(), "exphoned", "_", tr_path) ) {
55+
if (app.installTranslator(translator)) {
56+
qDebug() << "Install translation success for " << locale << " " << tr_path;
57+
} else {
58+
qWarning() << "Install translation failed for " << locale << " " << tr_path;
59+
}
60+
} else {
61+
qWarning() << "Failed to load translation for " << locale << " " << tr_path;
62+
}
63+
64+
}
65+
66+
4567
daemonize();
4668

4769
setlinebuf(stdout);

Diff for: daemon/translations/exphoned.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE TS>
3+
<TS version="2.1">
4+
<context>
5+
<name>BlockControler</name>
6+
<message>
7+
<location filename="../blockcontroler.cpp" line="72"/>
8+
<source>%1</source>
9+
<extracomment>phone number in notification body formatted as &quot;%s&quot;</extracomment>
10+
<translation type="unfinished"></translation>
11+
</message>
12+
<message>
13+
<location filename="../blockcontroler.cpp" line="75"/>
14+
<source>%1 (%2)</source>
15+
<extracomment>phone number and contact name formatted as &quot;%s (%s)&quot;</extracomment>
16+
<translation type="unfinished"></translation>
17+
</message>
18+
</context>
19+
<context>
20+
<name>QObject</name>
21+
<message>
22+
<location filename="../blockcontroler.cpp" line="68"/>
23+
<source>Phone call was blocked</source>
24+
<translation type="unfinished"></translation>
25+
</message>
26+
</context>
27+
</TS>

Diff for: daemon/translations/exphoned_cs.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!DOCTYPE TS>
3+
<TS version="2.1" language="cs">
4+
<context>
5+
<name>BlockControler</name>
6+
<message>
7+
<location filename="../blockcontroler.cpp" line="72"/>
8+
<source>%1</source>
9+
<extracomment>phone number in notification body formatted as &quot;%s&quot;</extracomment>
10+
<translation>%1</translation>
11+
</message>
12+
<message>
13+
<location filename="../blockcontroler.cpp" line="75"/>
14+
<source>%1 (%2)</source>
15+
<extracomment>phone number and contact name formatted as &quot;%s (%s)&quot;</extracomment>
16+
<translation>číslo %1 (kontakt %2)</translation>
17+
</message>
18+
</context>
19+
<context>
20+
<name>QObject</name>
21+
<message>
22+
<location filename="../blockcontroler.cpp" line="68"/>
23+
<source>Phone call was blocked</source>
24+
<translation>Hovor byl zablokován</translation>
25+
</message>
26+
</context>
27+
</TS>

Diff for: lib/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ add_library(exphone-lib
55
blockmodel.h
66
exphoneconfig.cpp
77
exphoneconfig.h
8+
pushclient.cpp
9+
pushclient.h
810
)
911

1012
target_include_directories(exphone-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
11-
target_link_libraries(exphone-lib PUBLIC Qt5::Core Qt5::Gui Qt5::Sql)
13+
target_link_libraries(exphone-lib PUBLIC Qt5::Core Qt5::Gui Qt5::Sql Qt5::DBus)
1214

0 commit comments

Comments
 (0)