Skip to content

Commit

Permalink
Fix #27
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Dec 28, 2020
1 parent 1b5dfe9 commit 359c98c
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 1 deletion.
94 changes: 94 additions & 0 deletions applications/launcher/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
#include "sysobject.h"
#include "inputmanager.h"
#include "wifinetworklist.h"
#include "notificationlist.h"
#include "dbusservice_interface.h"
#include "powerapi_interface.h"
#include "wifiapi_interface.h"
#include "network_interface.h"
#include "bss_interface.h"
#include "appsapi_interface.h"
#include "systemapi_interface.h"
#include "notification_interface.h"
#include "notificationapi_interface.h"

#define OXIDE_SERVICE "codes.eeems.oxide1"
#define OXIDE_SERVICE_PATH "/codes/eeems/oxide1"
Expand All @@ -39,11 +42,14 @@ class Controller : public QObject
Q_PROPERTY(bool showBatteryTemperature MEMBER m_showBatteryTemperature WRITE setShowBatteryTemperature NOTIFY showBatteryTemperatureChanged);
Q_PROPERTY(int sleepAfter MEMBER m_sleepAfter WRITE setSleepAfter NOTIFY sleepAfterChanged);
Q_PROPERTY(WifiNetworkList* networks MEMBER networks READ getNetworks NOTIFY networksChanged)
Q_PROPERTY(NotificationList* notifications MEMBER notifications READ getNotifications NOTIFY notificationsChanged)
Q_PROPERTY(bool wifiOn MEMBER m_wifion READ wifiOn NOTIFY wifiOnChanged)
Q_PROPERTY(QString autoStartApplication READ autoStartApplication WRITE setAutoStartApplication NOTIFY autoStartApplicationChanged)
Q_PROPERTY(bool powerOffInhibited READ powerOffInhibited NOTIFY powerOffInhibitedChanged)
Q_PROPERTY(bool sleepInhibited READ sleepInhibited NOTIFY sleepInhibitedChanged)
Q_PROPERTY(bool showDate MEMBER m_showDate WRITE setShowDate NOTIFY showDateChanged);
Q_PROPERTY(bool hasNotification MEMBER m_hasNotification NOTIFY hasNotificationChanged);
Q_PROPERTY(QString notificationText MEMBER m_notificationText NOTIFY notificationTextChanged);
public:
static std::string exec(const char* cmd);
EventFilter* filter;
Expand All @@ -56,6 +62,7 @@ class Controller : public QObject
inputManager(),
applications() {
networks = new WifiNetworkList();
notifications = new NotificationList();
uiTimer = new QTimer(this);
uiTimer->setSingleShot(false);
uiTimer->setInterval(3 * 1000); // 3 seconds
Expand Down Expand Up @@ -152,10 +159,28 @@ class Controller : public QObject
clock->setProperty("text", text + QTime::currentTime().toString("h:mm a"));
}
bool showDate(){ return m_showDate; }
void setNotification(QString notificationText){
if(m_notificationText == notificationText){
return;
}
m_notificationText = notificationText;
emit notificationTextChanged(notificationText);
if(!m_hasNotification){
m_hasNotification = true;
emit hasNotificationChanged(true);
}
}
void clearNotification(){
m_notificationText = "";
emit notificationTextChanged(m_notificationText);
m_hasNotification = false;
emit hasNotificationChanged(m_hasNotification);
}
QString autoStartApplication() { return m_autoStartApplication; }
void setAutoStartApplication(QString autoStartApplication);
bool getPowerConnected(){ return m_powerConnected; }
WifiNetworkList* getNetworks(){ return networks; }
NotificationList* getNotifications() { return notifications; }
bool powerOffInhibited(){
if(systemApi == nullptr){
return true;
Expand Down Expand Up @@ -221,6 +246,9 @@ class Controller : public QObject
void powerOffInhibitedChanged(bool);
void sleepInhibitedChanged(bool);
void showDateChanged(bool);
void hasNotificationChanged(bool);
void notificationTextChanged(QString);
void notificationsChanged(NotificationList*);

public slots:
void updateUIElements();
Expand Down Expand Up @@ -340,8 +368,70 @@ public slots:
appsApi = new Apps(OXIDE_SERVICE, path, bus);
connect(appsApi, &Apps::applicationUnregistered, this, &Controller::unregisterApplication);
connect(appsApi, &Apps::applicationRegistered, this, &Controller::registerApplication);
reply = api.requestAPI("notification");
reply.waitForFinished();
if(reply.isError()){
qDebug() << reply.error();
qFatal("Could not request notification API");
}
path = ((QDBusObjectPath)reply).path();
if(path == "/"){
qDebug() << "API not available";
qFatal("Notification API was not available");
}
if(notificationApi != nullptr){
delete notificationApi;
}
notificationApi = new Notifications(OXIDE_SERVICE, path, bus);
connect(notificationApi, &Notifications::notificationAdded, this, &Controller::notificationAdded);
connect(notificationApi, &Notifications::notificationRemoved, this, &Controller::notificationRemoved);
connect(notificationApi, &Notifications::notificationChanged, this, &Controller::notificationChanged);
connect(notifications, &NotificationList::updated, this, &Controller::notificationsUpdated);
}
private slots:
void notificationsUpdated(){
if(notifications->length() > 1){
setNotification(QStringLiteral("%1 notifications").arg(notifications->length()));
return;
}else if(!notifications->empty()){
setNotification("1 notification");
}else{
clearNotification();
}
emit notificationsChanged(notifications);
}
void notificationAdded(const QDBusObjectPath& path){
auto notification = new Notification(OXIDE_SERVICE, path.path(), QDBusConnection::systemBus(), this);
notifications->append(notification);
emit notificationsChanged(notifications);
if(notifications->length() > 1){
setNotification(QStringLiteral("%1 notifications").arg(notifications->length()));
return;
}
setNotification("1 notification");
}
void notificationRemoved(const QDBusObjectPath& path){
auto notification = notifications->get(path);
if(notification == nullptr){
return;
}
notifications->removeAll(notification);
delete notification;
emit notificationsChanged(notifications);
if(notifications->empty()){
clearNotification();
return;
}
if(notifications->length() > 1){
setNotification(QStringLiteral("%1 notifications").arg(notifications->length()));
return;
}
setNotification("1 notification");
}
void notificationChanged(const QDBusObjectPath& path){
Q_UNUSED(path);
emit notificationsChanged(notifications);
}
void unregisterApplication(QDBusObjectPath path){
if(appsApi == nullptr){
qDebug() << "Unable to access apps API";
Expand Down Expand Up @@ -569,6 +659,8 @@ private slots:
bool m_showBatteryTemperature = false;
bool m_showDate = false;
QString m_autoStartApplication = "";
bool m_hasNotification = false;
QString m_notificationText = "";

bool m_powerConnected = false;
int wifiState = WifiUnknown;
Expand All @@ -584,7 +676,9 @@ private slots:
Wifi* wifiApi = nullptr;
System* systemApi = nullptr;
Apps* appsApi = nullptr;
Notifications* notificationApi = nullptr;
QList<QObject*> applications;
AppItem* getApplication(QString name);
WifiNetworkList* networks;
NotificationList* notifications;
};
Binary file added applications/launcher/img/notifications/black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added applications/launcher/img/notifications/white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions applications/launcher/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ ApplicationWindow {
Action { text: qsTr(" Options"); onTriggered: stateController.state = "settings" }
}
}
StatusIcon {
source: "qrc:/img/notifications/white.png"
text: controller.notificationText
visible: controller.hasNotification
clip: true
Layout.maximumWidth: 300
MouseArea {
anchors.fill: parent
enabled: parent.visible
onClicked: stateController.state = "notifications"
}
}
}
Label { Layout.fillWidth: true }
RowLayout {
Expand Down Expand Up @@ -376,6 +388,12 @@ ApplicationWindow {
id: calendar
onClosed: stateController.state = "loaded"
visible: false
},
NotificationsPopup {
id: notifications
onClosed: stateController.state = "loaded"
visible: false
model: controller.notifications
}

]
Expand All @@ -399,6 +417,7 @@ ApplicationWindow {
PropertyAction { target: settings; property: "visible"; value: true }
PropertyAction { target: wifi; property: "visible"; value: false }
PropertyAction { target: calendar; property: "visible"; value: false }
PropertyAction { target: notifications; property: "visible"; value: false }
PropertyAction { target: menu; property: "focus"; value: false }
}
},
Expand All @@ -410,6 +429,7 @@ ApplicationWindow {
PropertyAction { target: wifi; property: "visible"; value: true }
PropertyAction { target: calendar; property: "visible"; value: false }
PropertyAction { target: settings; property: "visible"; value: false }
PropertyAction { target: notifications; property: "visible"; value: false }
PropertyAction { target: menu; property: "focus"; value: false }
}
},
Expand All @@ -421,6 +441,19 @@ ApplicationWindow {
PropertyAction { target: calendar; property: "visible"; value: true }
PropertyAction { target: settings; property: "visible"; value: false }
PropertyAction { target: wifi; property: "visible"; value: false }
PropertyAction { target: notifications; property: "visible"; value: false }
PropertyAction { target: menu; property: "focus"; value: false }
}
},
Transition {
from: "*"; to: "notifications"
SequentialAnimation {
ScriptAction { script: stateController.previousState = "notifications" }
ScriptAction { script: console.log("Opening notifications") }
PropertyAction { target: notifications; property: "visible"; value: true }
PropertyAction { target: calendar; property: "visible"; value: false }
PropertyAction { target: settings; property: "visible"; value: false }
PropertyAction { target: wifi; property: "visible"; value: false }
PropertyAction { target: menu; property: "focus"; value: false }
}
},
Expand All @@ -438,6 +471,7 @@ ApplicationWindow {
PropertyAction { target: calendar; property: "visible"; value: false }
PropertyAction { target: settings; property: "visible"; value: false }
PropertyAction { target: wifi; property: "visible"; value: false }
PropertyAction { target: notifications; property: "visible"; value: false }
PropertyAction { target: menu; property: "focus"; value: false }
PropertyAction { target: appsView; property: "focus"; value: true }
}
Expand Down
Loading

0 comments on commit 359c98c

Please sign in to comment.