mirror of
https://github.com/vicr123/theshell.git
synced 2025-01-23 04:11:49 -05:00
New notifications
This commit is contained in:
parent
f66cf651cc
commit
3668ce2765
28 changed files with 1057 additions and 1545 deletions
|
@ -1,5 +1,5 @@
|
|||
/****************************************
|
||||
*
|
||||
*
|
||||
* theShell - Desktop Environment
|
||||
* Copyright (C) 2017 Victor Tran
|
||||
*
|
||||
|
@ -15,12 +15,12 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
#include "dbusevents.h"
|
||||
|
||||
extern NotificationDBus* ndbus;
|
||||
extern NotificationsDBusAdaptor* ndbus;
|
||||
|
||||
DbusEvents::DbusEvents(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************
|
||||
*
|
||||
*
|
||||
* theShell - Desktop Environment
|
||||
* Copyright (C) 2017 Victor Tran
|
||||
*
|
||||
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
#ifndef DBUSEVENTS_H
|
||||
|
@ -33,7 +33,7 @@
|
|||
#include <QSettings>
|
||||
#include <QTimer>
|
||||
#include <QSoundEffect>
|
||||
#include "notificationdbus.h"
|
||||
#include "notificationsWidget/notificationsdbusadaptor.h"
|
||||
#include "newmedia.h"
|
||||
|
||||
class DbusEvents : public QObject
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "ui_endsessionwait.h"
|
||||
|
||||
extern float getDPIScaling();
|
||||
|
||||
extern void sendMessageToRootWindow(const char* message, Window window, long data0 = 0, long data1 = 0, long data2 = 0, long data3 = 0, long data4 = 0);
|
||||
|
||||
EndSessionWait::EndSessionWait(shutdownType type, QWidget *parent) :
|
||||
|
|
|
@ -33,7 +33,7 @@ extern float getDPIScaling();
|
|||
extern QDBusServiceWatcher* dbusServiceWatcher;
|
||||
extern QDBusServiceWatcher* dbusServiceWatcherSystem;
|
||||
extern UPowerDBus* updbus;
|
||||
extern NotificationDBus* ndbus;
|
||||
extern NotificationsDBusAdaptor* ndbus;
|
||||
extern DBusSignals* dbusSignals;
|
||||
|
||||
InfoPaneDropdown::InfoPaneDropdown(WId MainWindowId, QWidget *parent) :
|
||||
|
@ -53,12 +53,14 @@ InfoPaneDropdown::InfoPaneDropdown(WId MainWindowId, QWidget *parent) :
|
|||
|
||||
this->MainWindowId = MainWindowId;
|
||||
|
||||
ndbus->setDropdownPane(this);
|
||||
//ndbus->setDropdownPane(this);
|
||||
|
||||
connect(ndbus, SIGNAL(newNotification(int,QString,QString,QIcon)), this, SLOT(newNotificationReceived(int,QString,QString,QIcon)));
|
||||
/*connect(ndbus, SIGNAL(newNotification(int,QString,QString,QIcon)), this, SLOT(newNotificationReceived(int,QString,QString,QIcon)));
|
||||
connect(ndbus, SIGNAL(removeNotification(int)), this, SLOT(removeNotification(int)));
|
||||
connect(ndbus, SIGNAL(NotificationClosed(uint,uint)), this, SLOT(notificationClosed(uint,uint)));*/
|
||||
//connect(this, SIGNAL(closeNotification(int)), ndbus, SLOT(CloseNotificationUserInitiated(int)));
|
||||
connect(ndbus, SIGNAL(NotificationClosed(uint,uint)), this, SLOT(notificationClosed(uint,uint)));
|
||||
connect(this, SIGNAL(closeNotification(int)), ndbus, SLOT(CloseNotificationUserInitiated(int)));
|
||||
connect(ndbus, SIGNAL(ActionInvoked(uint,QString)), this, SLOT(notificationAction(uint,QString)));
|
||||
|
||||
connect(dbusServiceWatcher, SIGNAL(serviceRegistered(QString)), this, SLOT(DBusServiceRegistered(QString)));
|
||||
connect(dbusServiceWatcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(DBusServiceUnregistered(QString)));
|
||||
|
@ -802,491 +804,9 @@ void InfoPaneDropdown::on_pushButton_clicked()
|
|||
}
|
||||
|
||||
void InfoPaneDropdown::getNetworks() {
|
||||
/*if (!networkListUpdating) {
|
||||
//Set the updating flag
|
||||
networkListUpdating = true;
|
||||
|
||||
QFuture<void> future = QtConcurrent::run([=] {
|
||||
//Get the NetworkManager interface
|
||||
QDBusInterface i("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", QDBusConnection::systemBus());
|
||||
|
||||
//Get the devices
|
||||
QDBusReply<QList<QDBusObjectPath>> reply = i.call("GetDevices");
|
||||
|
||||
//Create a variable to store text on main window
|
||||
QStringList NetworkLabel;
|
||||
int signalStrength = -1;
|
||||
|
||||
//Check if we are in flight mode
|
||||
if (ui->FlightSwitch->isChecked()) {
|
||||
//Update text accordingly
|
||||
NetworkLabel.append(tr("Flight Mode"));
|
||||
}
|
||||
|
||||
//Create an enum to store the type of network we're currently using.
|
||||
//Higher numbers take precedence over others.
|
||||
enum NetworkType {
|
||||
None = 0,
|
||||
Bluetooth = 1,
|
||||
Wireless = 2,
|
||||
Wired = 3
|
||||
};
|
||||
|
||||
NetworkType NetworkLabelType = NetworkType::None;
|
||||
|
||||
//Make sure that the devices are valid
|
||||
if (reply.isValid()) {
|
||||
//Keep the current selection
|
||||
int currentSelection = ui->networkList->currentRow();
|
||||
|
||||
//Clear the list of network connections
|
||||
ui->networkList->clear();
|
||||
|
||||
bool allowAppendNoNetworkMessage = false;
|
||||
|
||||
//Iterate over all devices
|
||||
for (QDBusObjectPath device : reply.value()) {
|
||||
//Get the device interface
|
||||
QDBusInterface deviceInterface("org.freedesktop.NetworkManager", device.path(), "org.freedesktop.NetworkManager.Device", QDBusConnection::systemBus());
|
||||
|
||||
//Get the driver interface
|
||||
QString interface = deviceInterface.property("Interface").toString();
|
||||
|
||||
//Switch based on the device type
|
||||
switch (deviceInterface.property("DeviceType").toInt()) {
|
||||
case 1: //Ethernet
|
||||
{
|
||||
QDBusInterface *wire = new QDBusInterface("org.freedesktop.NetworkManager", device.path(), "org.freedesktop.NetworkManager.Device.Wired", QDBusConnection::systemBus());
|
||||
if (wire->property("Carrier").toBool()) { //Connected to a network
|
||||
if (!connectedNetworks.keys().contains(interface)) {
|
||||
connectedNetworks.insert(interface, "true");
|
||||
} else {
|
||||
if (connectedNetworks.value(interface) != "false") {
|
||||
connectedNetworks.insert(interface, "false");
|
||||
QVariantMap hints;
|
||||
hints.insert("category", "network.disconnected");
|
||||
hints.insert("transient", true);
|
||||
ndbus->Notify("theShell", 0, "", tr("Wired Connection"),
|
||||
tr("You've been disconnected from the internet over a wired connection"),
|
||||
QStringList(), hints, -1);
|
||||
}
|
||||
}
|
||||
NetworkLabel.append(tr("Connected over a wired connection"));
|
||||
NetworkLabelType = NetworkType::Wired;
|
||||
signalStrength = 5;
|
||||
allowAppendNoNetworkMessage = true;
|
||||
} else { //Not connected over Ethernet
|
||||
if (!connectedNetworks.keys().contains(interface)) {
|
||||
connectedNetworks.insert(interface, "false");
|
||||
} else {
|
||||
if (connectedNetworks.value(interface) == "true") {
|
||||
connectedNetworks.insert(interface, "true");
|
||||
QVariantMap hints;
|
||||
hints.insert("category", "network.connected");
|
||||
hints.insert("transient", true);
|
||||
ndbus->Notify("theShell", 0, "", tr("Wired Connection"),
|
||||
tr("You're now connected to the internet over a wired connection"),
|
||||
QStringList(), hints, -1);
|
||||
doNetworkCheck();
|
||||
}
|
||||
}
|
||||
|
||||
if (signalStrength < 0) {
|
||||
if (ui->FlightSwitch->isChecked()) {
|
||||
signalStrength = -1;
|
||||
} else {
|
||||
signalStrength = -4;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete wire;
|
||||
}
|
||||
break;
|
||||
case 2: //WiFi
|
||||
{
|
||||
QDBusInterface wifi("org.freedesktop.NetworkManager", device.path(), "org.freedesktop.NetworkManager.Device.Wireless", QDBusConnection::systemBus());
|
||||
QString connectedSsid;
|
||||
{ //Detect Connected Network
|
||||
if (NetworkLabelType < NetworkType::Wireless) {
|
||||
QDBusInterface ap("org.freedesktop.NetworkManager", wifi.property("ActiveAccessPoint").value<QDBusObjectPath>().path(), "org.freedesktop.NetworkManager.AccessPoint", QDBusConnection::systemBus());
|
||||
switch (deviceInterface.property("State").toInt()) {
|
||||
case 30:
|
||||
if (!connectedNetworks.keys().contains(interface)) {
|
||||
connectedNetworks.insert(interface, "");
|
||||
} else {
|
||||
if (connectedNetworks.value(interface) != "") {
|
||||
connectedNetworks.insert(interface, "");
|
||||
QVariantMap hints;
|
||||
hints.insert("category", "network.disconnected");
|
||||
hints.insert("transient", true);
|
||||
ndbus->Notify("theShell", 0, "", tr("Wireless Connection"),
|
||||
tr("You've been disconnected from the internet over a wireless connection"),
|
||||
QStringList(), hints, -1);
|
||||
}
|
||||
}
|
||||
signalStrength = -3;
|
||||
break;
|
||||
case 40:
|
||||
case 50:
|
||||
case 60:
|
||||
connectedSsid = ap.property("Ssid").toString();
|
||||
NetworkLabel.append(tr("Connecting to %1...").arg(connectedSsid));
|
||||
NetworkLabelType = NetworkType::Wireless;
|
||||
break;
|
||||
case 70:
|
||||
connectedSsid = ap.property("Ssid").toString();
|
||||
NetworkLabel.append(tr("Getting IP address from %1...").arg(connectedSsid));
|
||||
NetworkLabelType = NetworkType::Wireless;
|
||||
break;
|
||||
case 80:
|
||||
connectedSsid = ap.property("Ssid").toString();
|
||||
NetworkLabel.append(tr("Doing some checks..."));
|
||||
NetworkLabelType = NetworkType::Wireless;
|
||||
break;
|
||||
case 90:
|
||||
connectedSsid = ap.property("Ssid").toString();
|
||||
NetworkLabel.append(tr("Connecting to a secondary connection..."));
|
||||
NetworkLabelType = NetworkType::Wireless;
|
||||
break;
|
||||
case 100: {
|
||||
connectedSsid = ap.property("Ssid").toString();
|
||||
int strength = ap.property("Strength").toInt();
|
||||
|
||||
if (strength < 15) {
|
||||
signalStrength = 0;
|
||||
} else if (strength < 35) {
|
||||
signalStrength = 1;
|
||||
} else if (strength < 65) {
|
||||
signalStrength = 2;
|
||||
} else if (strength < 85) {
|
||||
signalStrength = 3;
|
||||
} else {
|
||||
signalStrength = 4;
|
||||
}
|
||||
|
||||
NetworkLabel.append(connectedSsid);
|
||||
NetworkLabelType = NetworkType::Wireless;
|
||||
ui->networkMac->setText("MAC Address: " + wifi.property("PermHwAddress").toString());
|
||||
if (!connectedNetworks.keys().contains(interface)) {
|
||||
connectedNetworks.insert(interface, connectedSsid);
|
||||
} else {
|
||||
if (connectedNetworks.value(interface) != connectedSsid) {
|
||||
connectedNetworks.insert(interface, connectedSsid);
|
||||
QVariantMap hints;
|
||||
hints.insert("category", "network.connected");
|
||||
hints.insert("transient", true);
|
||||
ndbus->Notify("theShell", 0, "", tr("Wireless Connection"),
|
||||
tr("You're now connected to the network \"%1\"").arg(connectedSsid),
|
||||
QStringList(), hints, -1);
|
||||
doNetworkCheck();
|
||||
}
|
||||
}
|
||||
allowAppendNoNetworkMessage = true;
|
||||
break;
|
||||
}
|
||||
case 110:
|
||||
case 120:
|
||||
connectedSsid = ap.property("Ssid").toString();
|
||||
NetworkLabel.append(tr("Disconnecting from %1...").arg(connectedSsid));
|
||||
NetworkLabelType = NetworkType::Wireless;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{ //Detect Available Networks
|
||||
QList<QDBusObjectPath> accessPoints = wifi.property("AccessPoints").value<QList<QDBusObjectPath>>();
|
||||
QStringList foundSsids;
|
||||
for (QDBusObjectPath accessPoint : accessPoints) {
|
||||
QDBusInterface ap("org.freedesktop.NetworkManager", accessPoint.path(), "org.freedesktop.NetworkManager.AccessPoint", QDBusConnection::systemBus());
|
||||
QString ssid = ap.property("Ssid").toString();
|
||||
//Have we seen this SSID already? Is the SSID not broadcast?
|
||||
if (foundSsids.contains(ssid) || ssid == "") {
|
||||
//Ignore it and continue on
|
||||
continue;
|
||||
}
|
||||
|
||||
int strength = ap.property("Strength").toInt();
|
||||
|
||||
QListWidgetItem* apItem = new QListWidgetItem();
|
||||
apItem->setText(ssid);
|
||||
if (strength < 15) {
|
||||
apItem->setIcon(QIcon::fromTheme("network-wireless-connected-00"));
|
||||
} else if (strength < 35) {
|
||||
apItem->setIcon(QIcon::fromTheme("network-wireless-connected-25"));
|
||||
} else if (strength < 65) {
|
||||
apItem->setIcon(QIcon::fromTheme("network-wireless-connected-50"));
|
||||
} else if (strength < 85) {
|
||||
apItem->setIcon(QIcon::fromTheme("network-wireless-connected-75"));
|
||||
} else {
|
||||
apItem->setIcon(QIcon::fromTheme("network-wireless-connected-100"));
|
||||
}
|
||||
if (ssid == connectedSsid) {
|
||||
apItem->setBackground(QBrush(QColor(0, 255, 0, 100)));
|
||||
}
|
||||
apItem->setData(Qt::UserRole, QVariant::fromValue(accessPoint));
|
||||
apItem->setData(Qt::UserRole + 1, QVariant::fromValue(device));
|
||||
apItem->setData(Qt::UserRole + 2, ssid == connectedSsid);
|
||||
ui->networkList->addItem(apItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 5: //Bluetooth
|
||||
{
|
||||
if (NetworkLabelType < NetworkType::Bluetooth) {
|
||||
QDBusInterface bt("org.freedesktop.NetworkManager", device.path(), "org.freedesktop.NetworkManager.Device.Bluetooth", QDBusConnection::systemBus());
|
||||
switch (deviceInterface.property("State").toInt()) {
|
||||
case 100:
|
||||
if (!connectedNetworks.keys().contains(interface)) {
|
||||
connectedNetworks.insert(interface, "true");
|
||||
} else {
|
||||
if (connectedNetworks.value(interface) == "false") {
|
||||
connectedNetworks.insert(interface, "true");
|
||||
QVariantMap hints;
|
||||
hints.insert("category", "network.connected");
|
||||
hints.insert("transient", true);
|
||||
ndbus->Notify("theShell", 0, "", tr("Bluetooth Connection"),
|
||||
tr("You're now connected to the internet over a bluetooth connection"),
|
||||
QStringList(), hints, -1);
|
||||
}
|
||||
}
|
||||
|
||||
NetworkLabel.append(tr("Connected to %1 over Bluetooth").arg(bt.property("Name").toString()));
|
||||
NetworkLabelType = NetworkType::Bluetooth;
|
||||
signalStrength = 6;
|
||||
allowAppendNoNetworkMessage = true;
|
||||
break;
|
||||
default:
|
||||
if (!connectedNetworks.keys().contains(interface)) {
|
||||
connectedNetworks.insert(interface, "false");
|
||||
} else {
|
||||
if (connectedNetworks.value(interface) == "true") {
|
||||
connectedNetworks.insert(interface, "false");
|
||||
QVariantMap hints;
|
||||
hints.insert("category", "network.disconnected");
|
||||
hints.insert("transient", true);
|
||||
ndbus->Notify("theShell", 0, "", tr("Bluetooth Connection"),
|
||||
tr("You've been disconnected from the internet over a bluetooth connection"),
|
||||
QStringList(), hints, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allowAppendNoNetworkMessage && networkOk != Ok) {
|
||||
if (NetworkLabelType == Wired) {
|
||||
signalStrength = -5;
|
||||
} else {
|
||||
signalStrength = -2;
|
||||
}
|
||||
|
||||
if (networkOk == Unspecified) {
|
||||
NetworkLabel.prepend(tr("Can't get to the internet"));
|
||||
} else if (networkOk == BehindPortal) {
|
||||
NetworkLabel.prepend(tr("Login required"));
|
||||
}
|
||||
}
|
||||
|
||||
//If possible, restore the current selection
|
||||
if (currentSelection != -1 && ui->networkList->count() > currentSelection) {
|
||||
ui->networkList->setCurrentRow(currentSelection);
|
||||
}
|
||||
|
||||
} else {
|
||||
NetworkLabel.append(tr("NetworkManager Error"));
|
||||
}
|
||||
|
||||
|
||||
//Populate current connection area
|
||||
{
|
||||
QDBusObjectPath active = i.property("PrimaryConnection").value<QDBusObjectPath>();
|
||||
if (active.path() == "/") {
|
||||
ui->networkInfoFrame->setVisible(false);
|
||||
} else {
|
||||
QDBusInterface conn("org.freedesktop.NetworkManager", active.path(), "org.freedesktop.NetworkManager.Connection.Active", QDBusConnection::systemBus());
|
||||
/*{
|
||||
QDBusObjectPath ipv4 = conn->property("Ip4Config").value<QDBusObjectPath>();
|
||||
//QDBusInterface *ip4 = new QDBusInterface("org.freedesktop.NetworkManager", ipv4.path(), "org.freedesktop.NetworkManager.IP4Config", QDBusConnection::systemBus(), this);
|
||||
QDBusInterface ip4("org.freedesktop.NetworkManager", ipv4.path(), "org.freedesktop.NetworkManager.IP4Config", QDBusConnection::systemBus(), this);
|
||||
|
||||
QList<QVariantMap> addressData = ip4.property("AddressData").value<QList<QVariantMap>>();
|
||||
ui->networkIpv4->setText("IPv4 Address: " + addressData.first().value("address").toString());
|
||||
//delete ip4;
|
||||
}
|
||||
{
|
||||
QDBusObjectPath ipv6 = conn->property("Ip6Config").value<QDBusObjectPath>();
|
||||
QDBusInterface *ip6 = new QDBusInterface("org.freedesktop.NetworkManager", ipv6.path(), "org.freedesktop.NetworkManager.IP6Config", QDBusConnection::systemBus(), this);
|
||||
QList<QVariantMap> addressData = ip6->property("AddressData").value<QList<QVariantMap>>();
|
||||
ui->networkIpv6->setText("IPv6 Address: " + addressData.first().value("address").toString());
|
||||
delete ip6;
|
||||
}*//*
|
||||
|
||||
//Get devices
|
||||
QList<QDBusObjectPath> devices = conn.property("Devices").value<QList<QDBusObjectPath>>();
|
||||
|
||||
//Iterate over all devices
|
||||
qulonglong txBytes = 0, rxBytes = 0;
|
||||
for (QDBusObjectPath object : devices) {
|
||||
QDBusInterface statsInterface("org.freedesktop.NetworkManager", object.path(), "org.freedesktop.NetworkManager.Device.Statistics", QDBusConnection::systemBus());
|
||||
txBytes += statsInterface.property("TxBytes").toULongLong();
|
||||
rxBytes += statsInterface.property("RxBytes").toULongLong();
|
||||
}
|
||||
ui->networkSent->setText(tr("Data Sent: %1").arg(calculateSize(txBytes)));
|
||||
ui->networkReceived->setText(tr("Data Received: %1").arg(calculateSize(rxBytes)));
|
||||
|
||||
//Hide individual frames
|
||||
ui->networkInfoWirelessFrame->setVisible(false);
|
||||
|
||||
if (devices.count() > 0) {
|
||||
//Do the rest on the first device
|
||||
switch (NetworkLabelType) {
|
||||
case Wireless:
|
||||
{
|
||||
QDBusInterface firstDeviceInterface("org.freedesktop.NetworkManager", devices.first().path(), "org.freedesktop.NetworkManager.Device.Wireless", QDBusConnection::systemBus());
|
||||
QDBusObjectPath activeAccessPoint = firstDeviceInterface.property("ActiveAccessPoint").value<QDBusObjectPath>();
|
||||
QDBusInterface activeAccessPointInterface("org.freedesktop.NetworkManager", activeAccessPoint.path(), "org.freedesktop.NetworkManager.AccessPoint", QDBusConnection::systemBus());
|
||||
ui->networkWirelessStrength->setText(tr("Signal Strength: %1").arg(QString::number(activeAccessPointInterface.property("Strength").toInt()) + "%"));
|
||||
ui->networkWirelessFrequency->setText(tr("Frequency: %1").arg(QString::number(activeAccessPointInterface.property("Frequency").toFloat() / 1e3f, 'f', 1) + " GHz"));
|
||||
ui->networkInfoWirelessFrame->setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ui->networkInfoFrame->setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (NetworkLabel.count() == 0) {
|
||||
NetworkLabel.append(tr("Disconnected from the Internet"));
|
||||
}
|
||||
|
||||
//Emit change signal
|
||||
emit networkLabelChanged(NetworkLabel.join(""), signalStrength);
|
||||
});
|
||||
|
||||
QFutureWatcher<void>* watcher = new QFutureWatcher<void>();
|
||||
connect(watcher, &QFutureWatcher<void>::finished, [=] {
|
||||
watcher->deleteLater();
|
||||
|
||||
//Set the updating flag
|
||||
networkListUpdating = false;
|
||||
});
|
||||
watcher->setFuture(future);
|
||||
}*/
|
||||
|
||||
ui->NetworkManager->updateGlobals();
|
||||
}
|
||||
|
||||
void InfoPaneDropdown::on_networkList_currentItemChanged(QListWidgetItem *current, QListWidgetItem*)
|
||||
{
|
||||
//Check if network list is updating
|
||||
/*if (!networkListUpdating) {
|
||||
ui->networkKey->setText("");
|
||||
if (current == NULL || !current) {
|
||||
ui->networkKey->setVisible(false);
|
||||
ui->networkConnect->setVisible(false);
|
||||
} else {
|
||||
if (current->data(Qt::UserRole + 2).toBool()) { //Connected to this network
|
||||
ui->networkKey->setVisible(false);
|
||||
ui->networkConnect->setText(tr("Disconnect"));
|
||||
ui->networkConnect->setIcon(QIcon::fromTheme("network-disconnect"));
|
||||
ui->networkConnect->setVisible(true);
|
||||
} else { //Not connected to this network
|
||||
QDBusInterface *ap = new QDBusInterface("org.freedesktop.NetworkManager", current->data(Qt::UserRole).value<QDBusObjectPath>().path(), "org.freedesktop.NetworkManager.AccessPoint", QDBusConnection::systemBus(), this);
|
||||
|
||||
bool isSaved = false;
|
||||
QDBusInterface *settings = new QDBusInterface("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/Settings", "org.freedesktop.NetworkManager.Settings", QDBusConnection::systemBus(), this);
|
||||
QDBusReply<QList<QDBusObjectPath>> allConnections = settings->call("ListConnections");
|
||||
for (QDBusObjectPath connection : allConnections.value()) {
|
||||
QDBusInterface *settings = new QDBusInterface("org.freedesktop.NetworkManager", connection.path(), "org.freedesktop.NetworkManager.Settings.Connection", QDBusConnection::systemBus(), this);
|
||||
|
||||
QDBusReply<QMap<QString, QVariantMap>> reply = settings->call("GetSettings");
|
||||
QMap<QString, QVariantMap> connectionSettings = reply.value();
|
||||
if (connectionSettings.value("802-11-wireless").value("ssid").toString() == ap->property("Ssid")) {
|
||||
isSaved = true;
|
||||
}
|
||||
}
|
||||
|
||||
current->setData(Qt::UserRole + 3, isSaved);
|
||||
|
||||
if (ap->property("WpaFlags").toUInt() != 0 && !isSaved) {
|
||||
ui->networkKey->setVisible(true);
|
||||
} else {
|
||||
ui->networkKey->setVisible(false);
|
||||
}
|
||||
ui->networkConnect->setText(tr("Connect"));
|
||||
ui->networkConnect->setIcon(QIcon::fromTheme("network-connect"));
|
||||
ui->networkConnect->setVisible(true);
|
||||
delete ap;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
void InfoPaneDropdown::on_networkConnect_clicked()
|
||||
{
|
||||
/*QDBusObjectPath device = ui->networkList->selectedItems().first()->data(Qt::UserRole + 1).value<QDBusObjectPath>();
|
||||
QDBusObjectPath accessPoint = ui->networkList->selectedItems().first()->data(Qt::UserRole).value<QDBusObjectPath>();
|
||||
|
||||
if (ui->networkList->selectedItems().first()->data(Qt::UserRole + 2).toBool()) { //Already connected, disconnect from this network
|
||||
QDBusInterface *d = new QDBusInterface("org.freedesktop.NetworkManager", device.path(), "org.freedesktop.NetworkManager.Device", QDBusConnection::systemBus(), this);
|
||||
d->call("Disconnect");
|
||||
delete d;
|
||||
} else { //Not connected, connect to this network
|
||||
QDBusMessage message;
|
||||
if (ui->networkList->selectedItems().first()->data(Qt::UserRole + 3).toBool()) { //This network is already known
|
||||
message = QDBusMessage::createMethodCall("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", "ActivateConnection");
|
||||
|
||||
QVariantList arguments;
|
||||
arguments.append(QVariant::fromValue(QDBusObjectPath("/")));
|
||||
arguments.append(QVariant::fromValue(device));
|
||||
arguments.append(QVariant::fromValue(accessPoint));
|
||||
message.setArguments(arguments);
|
||||
} else {
|
||||
QDBusInterface *ap = new QDBusInterface("org.freedesktop.NetworkManager", accessPoint.path(), "org.freedesktop.NetworkManager.AccessPoint", QDBusConnection::systemBus(), this);
|
||||
uint wpaFlags = ap->property("WpaFlags").toUInt();
|
||||
|
||||
QMap<QString, QVariantMap> connection;
|
||||
|
||||
if (wpaFlags != 0) {
|
||||
QVariantMap wireless;
|
||||
wireless.insert("security", "802-11-wireless-security");
|
||||
connection.insert("802-11-wireless", wireless);
|
||||
|
||||
QVariantMap wirelessSecurity;
|
||||
if (wpaFlags == 0x1 || wpaFlags == 0x2) { //WEP Authentication
|
||||
wirelessSecurity.insert("key-mgmt", "none");
|
||||
wirelessSecurity.insert("auth-alg", "shared");
|
||||
wirelessSecurity.insert("wep-key0", ui->networkKey->text());
|
||||
} else { //WPA Authentication
|
||||
wirelessSecurity.insert("key-mgmt", "wpa-psk");
|
||||
wirelessSecurity.insert("psk", ui->networkKey->text());
|
||||
}
|
||||
connection.insert("802-11-wireless-security", wirelessSecurity);
|
||||
}
|
||||
message = QDBusMessage::createMethodCall("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager", "org.freedesktop.NetworkManager", "AddAndActivateConnection");
|
||||
QVariantList arguments;
|
||||
|
||||
arguments.append(QVariant::fromValue(connection));
|
||||
arguments.append(QVariant::fromValue(device));
|
||||
arguments.append(QVariant::fromValue(accessPoint));
|
||||
|
||||
message.setArguments(arguments);
|
||||
delete ap;
|
||||
}
|
||||
QDBusMessage reply = QDBusConnection::systemBus().call(message);
|
||||
qDebug() << reply.errorMessage();
|
||||
|
||||
ui->networkKey->setText("");
|
||||
}*/
|
||||
}
|
||||
|
||||
void InfoPaneDropdown::on_pushButton_5_clicked()
|
||||
{
|
||||
changeDropDown(dropdownType(currentDropDown - 1));
|
||||
|
@ -1330,8 +850,10 @@ void InfoPaneDropdown::startTimer(QTime time) {
|
|||
emit timerVisibleChanged(false);
|
||||
emit timerEnabledChanged(true);
|
||||
}
|
||||
|
||||
ui->pushButton_2->setText(tr("Pause"));
|
||||
timeUntilTimeout = time;
|
||||
lastTimer = time;
|
||||
ui->label_7->setText(ui->timeEdit->text());
|
||||
ui->timeEdit->setVisible(false);
|
||||
ui->label_7->setVisible(true);
|
||||
|
@ -1349,12 +871,20 @@ void InfoPaneDropdown::startTimer(QTime time) {
|
|||
timer = NULL;
|
||||
|
||||
if (AudioMan->QuietMode() != AudioManager::notifications && AudioMan->QuietMode() != AudioManager::mute) { //Check if we should show the notification so the user isn't stuck listening to the tone
|
||||
QStringList actions;
|
||||
actions << "restart" << "Restart Timer";
|
||||
actions << "+0.5" << "+30 sec";
|
||||
actions << "+1" << "+1 min";
|
||||
actions << "+2" << "+2 min";
|
||||
actions << "+5" << "+5 min";
|
||||
actions << "+10" << "+10 min";
|
||||
|
||||
QVariantMap hints;
|
||||
hints.insert("x-thesuite-timercomplete", true);
|
||||
hints.insert("suppress-sound", true);
|
||||
timerNotificationId = ndbus->Notify("theShell", 0, "", tr("Timer Elapsed"),
|
||||
tr("Your timer has completed."),
|
||||
QStringList(), hints, 0);
|
||||
actions, hints, 0);
|
||||
ui->timeEdit->setVisible(true);
|
||||
ui->label_7->setVisible(false);
|
||||
ui->pushButton_2->setText("Start");
|
||||
|
@ -1376,7 +906,6 @@ void InfoPaneDropdown::startTimer(QTime time) {
|
|||
ringtone->setPlaylist(playlist);
|
||||
ringtone->play();
|
||||
|
||||
|
||||
AudioMan->attenuateStreams();
|
||||
}
|
||||
updateTimers();
|
||||
|
@ -1545,9 +1074,9 @@ void InfoPaneDropdown::newNotificationReceived(int id, QString summary, QString
|
|||
});
|
||||
layout->addWidget(button);
|
||||
|
||||
ui->notificationsList->layout()->addWidget(frame);
|
||||
ui->noNotifications->setVisible(false);
|
||||
ui->clearAllNotifications->setVisible(true);
|
||||
//ui->notificationsList->layout()->addWidget(frame);
|
||||
//ui->noNotifications->setVisible(false);
|
||||
//ui->clearAllNotifications->setVisible(true);
|
||||
frame->setProperty("summaryLabel", QVariant::fromValue(sumLabel));
|
||||
frame->setProperty("bodyLabel", QVariant::fromValue(bodyLabel));
|
||||
|
||||
|
@ -1566,8 +1095,8 @@ void InfoPaneDropdown::removeNotification(int id) {
|
|||
emit numNotificationsChanged(notificationFrames.count());
|
||||
|
||||
if (notificationFrames.count() == 0) {
|
||||
ui->noNotifications->setVisible(true);
|
||||
ui->clearAllNotifications->setVisible(false);
|
||||
//ui->noNotifications->setVisible(true);
|
||||
//ui->clearAllNotifications->setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2269,7 +1798,7 @@ void InfoPaneDropdown::doNetworkCheck() {
|
|||
uint notificationId = ndbus->Notify("theShell", 0, "", tr("Network Login"),
|
||||
tr("Your connection to the internet is blocked by a login page."),
|
||||
actions, hints, 30000);
|
||||
connect(ndbus, &NotificationDBus::ActionInvoked, [=](uint id, QString key) {
|
||||
connect(ndbus, &NotificationsDBusAdaptor::ActionInvoked, [=](uint id, QString key) {
|
||||
if (notificationId == id && key == "login") {
|
||||
QProcess::startDetached("xdg-open http://nmcheck.gnome.org/");
|
||||
}
|
||||
|
@ -3225,3 +2754,29 @@ void InfoPaneDropdown::on_userSettingsStandardAccount_toggled(bool checked)
|
|||
ui->userSettingsAdminAccount->setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
void InfoPaneDropdown::notificationAction(uint id, QString action) {
|
||||
if (id == timerNotificationId) {
|
||||
//Preserve old timer in case user wants to restart it
|
||||
QTime lastTimer = this->lastTimer;
|
||||
|
||||
ringtone->stop();
|
||||
AudioMan->restoreStreams();
|
||||
timerNotificationId = 0;
|
||||
|
||||
if (action == "+0.5") {
|
||||
startTimer(QTime(0, 0, 30));
|
||||
} else if (action == "+1") {
|
||||
startTimer(QTime(0, 1));
|
||||
} else if (action == "+2") {
|
||||
startTimer(QTime(0, 2));
|
||||
} else if (action == "+5") {
|
||||
startTimer(QTime(0, 5));
|
||||
} else if (action == "+10") {
|
||||
startTimer(QTime(0, 10));
|
||||
} else if (action == "restart") {
|
||||
startTimer(lastTimer);
|
||||
}
|
||||
this->lastTimer = lastTimer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
|
||||
#include <QDialog>
|
||||
#include <QResizeEvent>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QMap>
|
||||
|
@ -50,7 +47,7 @@
|
|||
#include <QtCharts/QValueAxis>
|
||||
#include <QtCharts/QDateTimeAxis>
|
||||
#include "animatedstackedwidget.h"
|
||||
#include "notificationdbus.h"
|
||||
#include "notificationsWidget/notificationsdbusadaptor.h"
|
||||
#include "upowerdbus.h"
|
||||
#include "endsessionwait.h"
|
||||
#include "audiomanager.h"
|
||||
|
@ -66,6 +63,7 @@
|
|||
#include <QFuture>
|
||||
#include <QFutureWatcher>
|
||||
#include <ttoast.h>
|
||||
#include <QDBusServiceWatcher>
|
||||
|
||||
class UPowerDBus;
|
||||
|
||||
|
@ -200,10 +198,6 @@ private slots:
|
|||
|
||||
void newNetworkDevice(QDBusObjectPath device);
|
||||
|
||||
void on_networkConnect_clicked();
|
||||
|
||||
void on_networkList_currentItemChanged(QListWidgetItem *current, QListWidgetItem*);
|
||||
|
||||
void on_TextSwitch_toggled(bool checked);
|
||||
|
||||
void on_windowManager_textEdited(const QString &arg1);
|
||||
|
@ -384,6 +378,8 @@ private slots:
|
|||
|
||||
void on_userSettingsAdminAccount_toggled(bool checked);
|
||||
|
||||
void notificationAction(uint id, QString action);
|
||||
|
||||
public slots:
|
||||
void getNetworks();
|
||||
|
||||
|
@ -416,6 +412,7 @@ private:
|
|||
int timerNotificationId = 0;
|
||||
QTimer* eventTimer;
|
||||
QTime timeUntilTimeout;
|
||||
QTime lastTimer = QTime(0, 0);
|
||||
QTime startTime;
|
||||
void reject();
|
||||
|
||||
|
|
|
@ -335,7 +335,7 @@
|
|||
<item>
|
||||
<widget class="AnimatedStackedWidget" name="pageStack">
|
||||
<property name="currentIndex">
|
||||
<number>5</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="clockFrame">
|
||||
<property name="autoFillBackground">
|
||||
|
@ -590,14 +590,14 @@
|
|||
<second>0</second>
|
||||
<year>1969</year>
|
||||
<month>9</month>
|
||||
<day>27</day>
|
||||
<day>26</day>
|
||||
</datetime>
|
||||
</property>
|
||||
<property name="date">
|
||||
<date>
|
||||
<year>1969</year>
|
||||
<month>9</month>
|
||||
<day>27</day>
|
||||
<day>26</day>
|
||||
</date>
|
||||
</property>
|
||||
<property name="displayFormat">
|
||||
|
@ -1445,114 +1445,15 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="noNotifications">
|
||||
<property name="text">
|
||||
<string>No New Notifications</string>
|
||||
<widget class="NotificationsWidget" name="widget_2" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="notificationsScroll">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="notificationsListLayout">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1165</width>
|
||||
<height>565</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_17">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QFrame" name="notificationsList">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>20</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_11">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_8">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="clearAllNotifications">
|
||||
<property name="text">
|
||||
<string>Clear All Notifications</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="edit-clear">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="kdeConnectFrame">
|
||||
|
@ -2358,8 +2259,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>883</width>
|
||||
<height>589</height>
|
||||
<width>372</width>
|
||||
<height>465</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_21">
|
||||
|
@ -4740,6 +4641,12 @@ Items that will be kept if you choose to keep files:
|
|||
<header>networkmanager/networkwidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>NotificationsWidget</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>notificationsWidget/notificationswidget.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
|
|
12
main.cpp
12
main.cpp
|
@ -56,7 +56,7 @@ LocationServices* locationServices = NULL;
|
|||
QDBusServiceWatcher* dbusServiceWatcher = NULL;
|
||||
QDBusServiceWatcher* dbusServiceWatcherSystem = NULL;
|
||||
UPowerDBus* updbus = NULL;
|
||||
NotificationDBus* ndbus = NULL;
|
||||
NotificationsDBusAdaptor* ndbus = NULL;
|
||||
DBusSignals* dbusSignals = NULL;
|
||||
|
||||
#define ONBOARDING_VERSION 4
|
||||
|
@ -215,6 +215,12 @@ int main(int argc, char *argv[])
|
|||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||
dbus.registerService("org.thesuite.theshell");
|
||||
|
||||
QObject* notificationParent = new QObject();
|
||||
ndbus = new NotificationsDBusAdaptor(notificationParent);
|
||||
|
||||
dbus.registerObject("/org/freedesktop/Notifications", "org.freedesktop.Notifications", notificationParent);
|
||||
dbus.registerService("org.freedesktop.Notifications");
|
||||
|
||||
dbusSignals = new DBusSignals();
|
||||
|
||||
if (startKscreen) {
|
||||
|
@ -276,9 +282,6 @@ int main(int argc, char *argv[])
|
|||
NativeFilter = new NativeEventFilter();
|
||||
a.installNativeEventFilter(NativeFilter);
|
||||
|
||||
ndbus = new NotificationDBus();
|
||||
updbus = new UPowerDBus();
|
||||
|
||||
if (settings.value("startup/lastOnboarding", 0) < ONBOARDING_VERSION || startOnboarding) {
|
||||
Onboarding* onboardingWindow = new Onboarding();
|
||||
onboardingWindow->showFullScreen();
|
||||
|
@ -290,6 +293,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
updbus = new UPowerDBus();
|
||||
MainWin = new MainWindow();
|
||||
|
||||
new GlobalFilter(&a);
|
||||
|
|
|
@ -31,7 +31,7 @@ extern NativeEventFilter* NativeFilter;
|
|||
extern float getDPIScaling();
|
||||
extern LocationServices* locationServices;
|
||||
extern UPowerDBus* updbus;
|
||||
extern NotificationDBus* ndbus;
|
||||
extern NotificationsDBusAdaptor* ndbus;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
|
@ -91,6 +91,27 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(timer, SIGNAL(timeout()), taskbarManager, SLOT(ReloadWindows()));
|
||||
timer->start();
|
||||
|
||||
infoPane = new InfoPaneDropdown(this->winId());
|
||||
infoPane->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
connect(infoPane, SIGNAL(networkLabelChanged(QString,QIcon)), this, SLOT(internetLabelChanged(QString,QIcon)));
|
||||
connect(infoPane, SIGNAL(numNotificationsChanged(int)), this, SLOT(numNotificationsChanged(int)));
|
||||
connect(infoPane, SIGNAL(timerChanged(QString)), this, SLOT(setTimer(QString)));
|
||||
connect(infoPane, SIGNAL(timerVisibleChanged(bool)), this, SLOT(setTimerVisible(bool)));
|
||||
connect(infoPane, SIGNAL(timerEnabledChanged(bool)), this, SLOT(setTimerEnabled(bool)));
|
||||
connect(infoPane, &InfoPaneDropdown::batteryStretchChanged, [=](bool isOn) {
|
||||
if (isOn) {
|
||||
timer->setInterval(1000);
|
||||
} else {
|
||||
timer->setInterval(100);
|
||||
}
|
||||
});
|
||||
connect(infoPane, SIGNAL(updateStrutsSignal()), this, SLOT(updateStruts()));
|
||||
connect(infoPane, &InfoPaneDropdown::flightModeChanged, [=](bool flight) {
|
||||
ui->flightIcon->setVisible(flight);
|
||||
ui->StatusBarFlight->setVisible(flight);
|
||||
});
|
||||
infoPane->getNetworks();
|
||||
|
||||
connect(updbus, &UPowerDBus::updateDisplay, [=](QString display) {
|
||||
if (updbus->hasBattery()) {
|
||||
if (updbus->hasPCBattery()) {
|
||||
|
@ -159,27 +180,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
DBusEvents = new DbusEvents();
|
||||
|
||||
infoPane = new InfoPaneDropdown(this->winId());
|
||||
infoPane->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
connect(infoPane, SIGNAL(networkLabelChanged(QString,QIcon)), this, SLOT(internetLabelChanged(QString,QIcon)));
|
||||
connect(infoPane, SIGNAL(numNotificationsChanged(int)), this, SLOT(numNotificationsChanged(int)));
|
||||
connect(infoPane, SIGNAL(timerChanged(QString)), this, SLOT(setTimer(QString)));
|
||||
connect(infoPane, SIGNAL(timerVisibleChanged(bool)), this, SLOT(setTimerVisible(bool)));
|
||||
connect(infoPane, SIGNAL(timerEnabledChanged(bool)), this, SLOT(setTimerEnabled(bool)));
|
||||
connect(infoPane, &InfoPaneDropdown::batteryStretchChanged, [=](bool isOn) {
|
||||
if (isOn) {
|
||||
timer->setInterval(1000);
|
||||
} else {
|
||||
timer->setInterval(100);
|
||||
}
|
||||
});
|
||||
connect(infoPane, SIGNAL(updateStrutsSignal()), this, SLOT(updateStruts()));
|
||||
connect(infoPane, &InfoPaneDropdown::flightModeChanged, [=](bool flight) {
|
||||
ui->flightIcon->setVisible(flight);
|
||||
ui->StatusBarFlight->setVisible(flight);
|
||||
});
|
||||
infoPane->getNetworks();
|
||||
|
||||
QString loginSoundPath = settings.value("sounds/login", "").toString();
|
||||
if (loginSoundPath == "") {
|
||||
loginSoundPath = "/usr/share/sounds/contemporary/login.ogg";
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include <math.h>
|
||||
#include "window.h"
|
||||
#include "menu.h"
|
||||
#include "notificationdbus.h"
|
||||
#include "notificationsWidget/notificationsdbusadaptor.h"
|
||||
#include "upowerdbus.h"
|
||||
#include "infopanedropdown.h"
|
||||
#include "touchkeyboard.h"
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include <functional>
|
||||
#include <QDebug>
|
||||
#include "availablenetworkslist.h"
|
||||
#include "nativeeventfilter.h"
|
||||
#include <ttoast.h>
|
||||
|
||||
namespace Ui {
|
||||
class NetworkWidget;
|
||||
|
|
|
@ -1,294 +0,0 @@
|
|||
/****************************************
|
||||
*
|
||||
* theShell - Desktop Environment
|
||||
* Copyright (C) 2017 Victor Tran
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
#include "notificationdbus.h"
|
||||
|
||||
extern QIcon getIconFromTheme(QString name, QColor textColor);
|
||||
extern TutorialWindow* TutorialWin;
|
||||
extern AudioManager* AudioMan;
|
||||
|
||||
NotificationDBus::NotificationDBus(QObject *parent) : QObject(parent)
|
||||
{
|
||||
new NotificationsAdaptor(this);
|
||||
QDBusConnection dbus = QDBusConnection::sessionBus();
|
||||
dbus.registerObject("/org/freedesktop/Notifications", this);
|
||||
dbus.registerService("org.freedesktop.Notifications");
|
||||
}
|
||||
|
||||
QStringList NotificationDBus::GetCapabilities() {
|
||||
return QStringList() << "body" << "body-markup" << "icon-static" << "persistence" << "actions" << "sound";
|
||||
}
|
||||
|
||||
uint NotificationDBus::Notify(QString app_name, uint replaces_id,
|
||||
QString app_icon, QString summary,
|
||||
QString body, QStringList actions,
|
||||
QVariantMap hints, int expire_timeout) {\
|
||||
NotificationDialog::notificationType type = NotificationDialog::normalType;
|
||||
bool showDialog = true;
|
||||
|
||||
if (app_name == "tsbt") { //Do special notifications for ts-bt
|
||||
if (hints.value("call-incoming", false).toBool()) {
|
||||
summary = "Incoming Call (" + hints.value("device").toString() + ")";
|
||||
body = hints.value("caller").toString();
|
||||
hints.insert("category", "call.incoming");
|
||||
type = NotificationDialog::callType;
|
||||
expire_timeout = 0;
|
||||
}
|
||||
} else if (app_name == "KDE Connect") { //Do special notifications for KDE Connect
|
||||
QString kdeEventId = hints.value("x-kde-eventId").toString();
|
||||
app_icon = "kdeconnect";
|
||||
if (kdeEventId == "pingReceived") {
|
||||
body = "Ping received from " + summary;
|
||||
summary = "KDE Connect";
|
||||
} else if (kdeEventId == "callReceived") {
|
||||
QString tempBody, tempSummary;
|
||||
tempSummary = "Incoming Call (" + summary + ")";
|
||||
tempBody = body.remove("Incoming call from ");
|
||||
summary = tempSummary;
|
||||
body = tempBody;
|
||||
hints.insert("category", "call.incoming");
|
||||
type = NotificationDialog::callType;
|
||||
expire_timeout = 30000;
|
||||
} else if (kdeEventId == "missedCall") {
|
||||
showDialog = false;
|
||||
} else if (kdeEventId == "smsReceived") {
|
||||
summary = "KDE Connect";
|
||||
} else if (kdeEventId == "notification") {
|
||||
QString appName = body.left(body.indexOf(":"));
|
||||
QString appSummary = body.mid(body.indexOf(":") + 2, body.indexOf("‐") - body.indexOf(":") - 3);
|
||||
QString appBody = body.right(body.indexOf("‐") + 12);
|
||||
summary = appSummary + " (" + appName + " from " + summary + ")";
|
||||
body = appBody;
|
||||
hints.insert("transient", true);
|
||||
} else if (kdeEventId == "batteryLow") {
|
||||
summary = summary.remove(": Low Battery");
|
||||
body = "The battery is low. Connect the device to power.";
|
||||
expire_timeout = 10000;
|
||||
hints.insert("category", "battery.low");
|
||||
}
|
||||
}
|
||||
|
||||
if (replaces_id == 0 || dialogs.count() <= replaces_id) {
|
||||
replaces_id = nextId;
|
||||
nextId++;
|
||||
|
||||
if (AudioMan != NULL) {
|
||||
if (AudioMan->QuietMode() == AudioManager::notifications) {
|
||||
QStringList allowedCategories;
|
||||
allowedCategories.append("battery.low");
|
||||
allowedCategories.append("battery.critical");
|
||||
allowedCategories.append("reminder.activate");
|
||||
if (!allowedCategories.contains(hints.value("category").toString()) && !hints.value("x-thesuite-timercomplete", false).toBool()) {
|
||||
showDialog = false;
|
||||
}
|
||||
} else if (AudioMan->QuietMode() == AudioManager::mute) {
|
||||
showDialog = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NotificationDialog *d = new NotificationDialog(app_name, app_icon, summary, body, actions, replaces_id, hints, expire_timeout, type);
|
||||
d->dbusParent = this;
|
||||
|
||||
connect(d, SIGNAL(closing(int, int)), this, SLOT(sendCloseNotification(int, int)));
|
||||
|
||||
d->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
if (showDialog) {
|
||||
if (currentDialog != NULL) {
|
||||
currentDialog->close(1);
|
||||
QTimer::singleShot(600, [=]() {
|
||||
d->show();
|
||||
currentDialog = d;
|
||||
});
|
||||
} else {
|
||||
d->show();
|
||||
currentDialog = d;
|
||||
}
|
||||
connect(currentDialog, &NotificationDialog::closing, [=]() {
|
||||
if (currentDialog == d) {
|
||||
currentDialog = NULL;
|
||||
}
|
||||
});
|
||||
}
|
||||
dialogs.append(d);
|
||||
|
||||
//Send the notification to the lock screen if the user desires
|
||||
if (settings.value("notifications/lockScreen").toString() != "none") {
|
||||
//If the notification is transient, don't send it to the lock screen
|
||||
if (!hints.value("transient", false).toBool()) {
|
||||
//Create a DBus message relaying the message to the lock screen
|
||||
QDBusMessage NotificationEmit = QDBusMessage::createMethodCall("org.thesuite.tsscreenlock", "/org/thesuite/tsscreenlock", "org.thesuite.tsscreenlock.Notifications", "newNotification");
|
||||
QVariantList NotificationArgs;
|
||||
|
||||
if (settings.value("notifications/lockScreen", "noContents").toString() == "contents") {
|
||||
NotificationArgs.append(summary);
|
||||
NotificationArgs.append(body);
|
||||
NotificationArgs.append(replaces_id);
|
||||
NotificationArgs.append(actions);
|
||||
} else {
|
||||
NotificationArgs.append(app_name);
|
||||
NotificationArgs.append("New Notification");
|
||||
NotificationArgs.append(replaces_id);
|
||||
NotificationArgs.append(QStringList());
|
||||
}
|
||||
NotificationArgs.append(hints);
|
||||
|
||||
NotificationEmit.setArguments(NotificationArgs);
|
||||
QDBusConnection::sessionBus().call(NotificationEmit, QDBus::NoBlock);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dialogs.at(replaces_id - 1)->setParams(app_name, summary, body);
|
||||
dialogs.at(replaces_id - 1)->show();
|
||||
}
|
||||
|
||||
if (!hints.value("transient", false).toBool()) {
|
||||
QColor color = QApplication::palette("QLabel").color(QPalette::Window);
|
||||
QIcon icon = QIcon::fromTheme("dialog-warning");
|
||||
if (hints.keys().contains("category")) {
|
||||
QString category = hints.value("category").toString();
|
||||
if (category == "network.connected") {
|
||||
icon = QIcon::fromTheme("network-connect").pixmap(24, 24);
|
||||
} else if (category == "network.disconnected") {
|
||||
icon = QIcon::fromTheme("network-disconnect").pixmap(24, 24);
|
||||
} else if (category == "email.arrived") {
|
||||
icon = QIcon::fromTheme("mail-receive").pixmap(24, 24);
|
||||
} else if (category == "battery.charging") {
|
||||
icon = getIconFromTheme("battery-charging.svg", color).pixmap(24, 24);
|
||||
} else if (category == "battery.charged") {
|
||||
icon = getIconFromTheme("battery-charged.svg", color).pixmap(24, 24);
|
||||
} else if (category == "battery.discharging") {
|
||||
icon = getIconFromTheme("battery-not-charging.svg", color).pixmap(24, 24);
|
||||
} else if (category == "battery.low") {
|
||||
icon = getIconFromTheme("battery-low.svg", color).pixmap(24, 24);
|
||||
} else if (category == "battery.critical") {
|
||||
icon = getIconFromTheme("battery-critical.svg", color).pixmap(24, 24);
|
||||
} else if (category == "device.added") {
|
||||
icon = getIconFromTheme("connect.svg", color).pixmap(24, 24);
|
||||
} else if (category == "device.removed") {
|
||||
icon = getIconFromTheme("disconnect.svg", color).pixmap(24, 24);
|
||||
} else if (category == "device.removed") {
|
||||
icon = getIconFromTheme("disconnect.svg", color).pixmap(24, 24);
|
||||
} else if (category == "reminder.activate") {
|
||||
icon = getIconFromTheme("reminder", color).pixmap(24, 24);
|
||||
}
|
||||
} else if (hints.keys().contains("urgency")) {
|
||||
QChar urgency = hints.value("urgency").toChar();
|
||||
if (urgency.unicode() == 0) {
|
||||
icon = QIcon::fromTheme("dialog-information");
|
||||
} else if (urgency.unicode() == 2) {
|
||||
icon = QIcon::fromTheme("dialog-error");
|
||||
}
|
||||
}
|
||||
emit newNotification(replaces_id, summary, body, icon);
|
||||
}
|
||||
|
||||
if (!hints.value("suppress-sound", false).toBool() && !(AudioMan->QuietMode() == AudioManager::notifications || AudioMan->QuietMode() == AudioManager::mute)) {
|
||||
if (hints.contains("sound-file")) {
|
||||
if (settings.value("notifications/attenuate", true).toBool()) {
|
||||
AudioMan->attenuateStreams();
|
||||
}
|
||||
|
||||
QMediaPlayer* player = new QMediaPlayer();
|
||||
if (hints.value("sound-file").toString().startsWith("qrc:")) {
|
||||
player->setMedia(QMediaContent(QUrl(hints.value("sound-file").toString())));
|
||||
} else {
|
||||
player->setMedia(QMediaContent(QUrl::fromLocalFile(hints.value("sound-file").toString())));
|
||||
}
|
||||
player->play();
|
||||
connect(player, &QMediaPlayer::stateChanged, [=](QMediaPlayer::State state) {
|
||||
if (state == QMediaPlayer::StoppedState) {
|
||||
player->deleteLater();
|
||||
if (settings.value("notifications/attenuate", true).toBool()) {
|
||||
AudioMan->restoreStreams();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (settings.value("notifications/attenuate", true).toBool()) {
|
||||
AudioMan->attenuateStreams();
|
||||
}
|
||||
|
||||
QSoundEffect* sound = new QSoundEffect();
|
||||
|
||||
QString notificationSound = settings.value("notifications/sound", "tripleping").toString();
|
||||
if (notificationSound == "tripleping") {
|
||||
sound->setSource(QUrl("qrc:/sounds/notifications/tripleping.wav"));
|
||||
} else if (notificationSound == "upsidedown") {
|
||||
sound->setSource(QUrl("qrc:/sounds/notifications/upsidedown.wav"));
|
||||
} else if (notificationSound == "echo") {
|
||||
sound->setSource(QUrl("qrc:/sounds/notifications/echo.wav"));
|
||||
}
|
||||
sound->play();
|
||||
connect(sound, SIGNAL(playingChanged()), sound, SLOT(deleteLater()));
|
||||
|
||||
if (settings.value("notifications/attenuate", true).toBool()) {
|
||||
connect(sound, &QSoundEffect::playingChanged, [=]() {
|
||||
AudioMan->restoreStreams();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return replaces_id;
|
||||
}
|
||||
|
||||
QString NotificationDBus::GetServerInformation(QString &vendor, QString &version, QString &spec_version) {
|
||||
|
||||
vendor = "theSuite";
|
||||
version = "1.0";
|
||||
spec_version = "1.2";
|
||||
return "theShell";
|
||||
}
|
||||
|
||||
void NotificationDBus::CloseNotification(uint id) {
|
||||
if (id != 0) {
|
||||
if (dialogs.count() >= id) {
|
||||
NotificationDialog *d = dialogs.at(id - 1);
|
||||
d->close(3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationDBus::CloseNotificationUserInitiated(int id) {
|
||||
NotificationDialog *d = dialogs.at(id - 1);
|
||||
d->close(2);
|
||||
}
|
||||
|
||||
void NotificationDBus::sendCloseNotification(int id, int reason) {
|
||||
emit NotificationClosed((uint) id, (uint) reason);
|
||||
|
||||
if (reason == 2 || reason == 3) {
|
||||
emit removeNotification(id);
|
||||
}
|
||||
|
||||
if (reason == 1) {
|
||||
TutorialWin->showScreen(TutorialWindow::MissedNotification);
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationDBus::invokeAction(uint id, QString key) {
|
||||
emit ActionInvoked(id, key);
|
||||
NotificationDialog *d = dialogs.at(id - 1);
|
||||
d->close(2);
|
||||
}
|
||||
|
||||
void NotificationDBus::setDropdownPane(InfoPaneDropdown *pane) {
|
||||
this->dropdownPane = pane;
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/****************************************
|
||||
*
|
||||
* theShell - Desktop Environment
|
||||
* Copyright (C) 2017 Victor Tran
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
#ifndef NOTIFICATIONDBUS_H
|
||||
#define NOTIFICATIONDBUS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QApplication>
|
||||
#include <QIcon>
|
||||
#include "notificationdialog.h"
|
||||
#include "notifications_adaptor.h"
|
||||
#include "infopanedropdown.h"
|
||||
#include "tutorialwindow.h"
|
||||
|
||||
class NotificationDialog;
|
||||
|
||||
class InfoPaneDropdown;
|
||||
|
||||
class NotificationDBus : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications")
|
||||
public:
|
||||
explicit NotificationDBus(QObject *parent = 0);
|
||||
void setDropdownPane(InfoPaneDropdown* pane);
|
||||
|
||||
Q_SIGNALS:
|
||||
Q_SCRIPTABLE void NotificationClosed(uint id, uint reason);
|
||||
Q_SCRIPTABLE void ActionInvoked(uint id, QString action_key);
|
||||
void newNotification(int id, QString summary, QString body, QIcon icon);
|
||||
void removeNotification(int id);
|
||||
|
||||
public Q_SLOTS:
|
||||
QStringList GetCapabilities();
|
||||
uint Notify(QString app_name, uint replaces_id,
|
||||
QString app_icon, QString summary,
|
||||
QString body, QStringList actions,
|
||||
QVariantMap hints, int expire_timeout);
|
||||
void CloseNotification(uint id);
|
||||
QString GetServerInformation(QString &vendor,
|
||||
QString &version, QString &spec_version);
|
||||
void invokeAction(uint id, QString key);
|
||||
|
||||
protected Q_SLOTS:
|
||||
void sendCloseNotification(int id, int reason);
|
||||
void CloseNotificationUserInitiated(int id);
|
||||
|
||||
private:
|
||||
QList<NotificationDialog*> dialogs;
|
||||
NotificationDialog* currentDialog = NULL;
|
||||
int nextId = 1;
|
||||
|
||||
InfoPaneDropdown* dropdownPane = NULL;
|
||||
QSettings settings;
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONDBUS_H
|
|
@ -1,297 +0,0 @@
|
|||
/****************************************
|
||||
*
|
||||
* theShell - Desktop Environment
|
||||
* Copyright (C) 2017 Victor Tran
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
#include "notificationdialog.h"
|
||||
#include "ui_notificationdialog.h"
|
||||
|
||||
extern QIcon getIconFromTheme(QString name, QColor textColor);
|
||||
extern float getDPIScaling();
|
||||
|
||||
NotificationDialog::NotificationDialog(QString appName, QString appIconStr, QString title, QString body, QStringList actions, int id, QVariantMap hints, int timeout, notificationType type, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NotificationDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
this->hints = hints;
|
||||
this->setAttribute(Qt::WA_X11NetWmWindowTypeNotification, true);
|
||||
|
||||
/*QBrush background = this->palette().background();
|
||||
QPalette pal = this->palette();
|
||||
pal.setBrush(QPalette::Background, pal.foreground());
|
||||
pal.setColor(QPalette::Button, pal.foreground().color());
|
||||
pal.setColor(QPalette::ButtonText, background.color());
|
||||
pal.setBrush(QPalette::Foreground, background);
|
||||
//pal().background().setColor(this->palette().foreground().color());
|
||||
//pal().foreground().setColor(background);
|
||||
this->setPalette(pal);*/
|
||||
|
||||
ui->appName->setText(appName);
|
||||
switch (type) {
|
||||
case normalType:
|
||||
ui->notificationType->setCurrentIndex(0);
|
||||
ui->title->setText(title);
|
||||
ui->body->setText(body);
|
||||
ui->page2->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
|
||||
break;
|
||||
case callType:
|
||||
ui->notificationType->setCurrentIndex(1);
|
||||
ui->title1->setText(title);
|
||||
ui->body1->setText(body);
|
||||
break;
|
||||
}
|
||||
|
||||
this->setFixedHeight(this->sizeHint().height());
|
||||
|
||||
for (int i = 0; i < actions.length(); i = i + 2) {
|
||||
QString action = actions.at(i);
|
||||
QString readable = actions.at(i + 1);
|
||||
|
||||
QPushButton *button = new QPushButton();
|
||||
button->setText(readable);
|
||||
//button->setPalette(pal);
|
||||
connect(button, &QPushButton::clicked, [=]() {
|
||||
uint id2 = id;
|
||||
QString key = action;
|
||||
dbusParent->invokeAction(id2, key);
|
||||
});
|
||||
ui->actionsLayout->addWidget(button);
|
||||
}
|
||||
|
||||
this->setAttribute(Qt::WA_ShowWithoutActivating, true);
|
||||
|
||||
this->id = id;
|
||||
QRect screenGeometry = QApplication::desktop()->screenGeometry();
|
||||
//w.setGeometry(screenGeometry.x() - 1, screenGeometry.y(), screenGeometry.width(), w.height());
|
||||
this->setGeometry(QRect(screenGeometry.x(), screenGeometry.y() - this->height(), screenGeometry.width(), this->height()));
|
||||
|
||||
QColor color = this->palette().color(QPalette::Window);
|
||||
|
||||
QIcon appIcon;
|
||||
bool foundAppIcon = false;
|
||||
if (appIconStr != "" && QIcon::hasThemeIcon(appIconStr)) {
|
||||
appIcon = QIcon::fromTheme(appIconStr);
|
||||
foundAppIcon = true;
|
||||
} else if (QIcon::hasThemeIcon(appName.toLower().replace(" ", "-"))) {
|
||||
appIcon = QIcon::fromTheme(appName.toLower().replace(" ", "-"));
|
||||
foundAppIcon = true;
|
||||
} else if (QIcon::hasThemeIcon(appName.toLower().replace(" ", ""))) {
|
||||
appIcon = QIcon::fromTheme(appName.toLower().replace(" ", ""));
|
||||
foundAppIcon = true;
|
||||
} else {
|
||||
QString filename = hints.value("desktop-entry", "").toString() + ".desktop";
|
||||
|
||||
QDir appFolder("/usr/share/applications/");
|
||||
QDirIterator* iterator = new QDirIterator(appFolder, QDirIterator::Subdirectories);
|
||||
|
||||
while (iterator->hasNext()) {
|
||||
iterator->next();
|
||||
QFileInfo info = iterator->fileInfo();
|
||||
if (info.fileName() == filename || info.baseName().toLower() == appName.toLower()) {
|
||||
QFile file(info.filePath());
|
||||
file.open(QFile::ReadOnly);
|
||||
QString appinfo(file.readAll());
|
||||
|
||||
QStringList desktopLines;
|
||||
QString currentDesktopLine;
|
||||
for (QString desktopLine : appinfo.split("\n")) {
|
||||
if (desktopLine.startsWith("[") && currentDesktopLine != "") {
|
||||
desktopLines.append(currentDesktopLine);
|
||||
currentDesktopLine = "";
|
||||
}
|
||||
currentDesktopLine.append(desktopLine + "\n");
|
||||
}
|
||||
desktopLines.append(currentDesktopLine);
|
||||
|
||||
for (QString desktopPart : desktopLines) {
|
||||
for (QString line : desktopPart.split("\n")) {
|
||||
if (line.startsWith("icon=", Qt::CaseInsensitive)) {
|
||||
QString iconname = line.split("=")[1];
|
||||
if (QFile(iconname).exists()) {
|
||||
appIcon = QIcon(iconname);
|
||||
} else {
|
||||
appIcon = QIcon::fromTheme(iconname, QIcon::fromTheme("application-x-executable"));
|
||||
}
|
||||
foundAppIcon = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
delete iterator;
|
||||
}
|
||||
|
||||
if (foundAppIcon) {
|
||||
ui->appIcon->setPixmap(appIcon.pixmap(16 * getDPIScaling(), 16 * getDPIScaling()));
|
||||
} else {
|
||||
ui->appIcon->setVisible(false);
|
||||
}
|
||||
|
||||
// Don't forget to add extra categories to the notificationdbus class too!
|
||||
|
||||
QSize iconSize(24 * getDPIScaling(), 24 * getDPIScaling());
|
||||
if (hints.value("x-thesuite-timercomplete", false).toBool()) {
|
||||
ui->label->setPixmap(QIcon::fromTheme("chronometer").pixmap(iconSize));
|
||||
} else {
|
||||
if (hints.keys().contains("category")) {
|
||||
QString category = hints.value("category").toString();
|
||||
if (category == "network.connected") {
|
||||
ui->label->setPixmap(QIcon::fromTheme("network-connect").pixmap(iconSize));
|
||||
} else if (category == "network.disconnected") {
|
||||
ui->label->setPixmap(QIcon::fromTheme("network-disconnect").pixmap(iconSize));
|
||||
} else if (category == "email.arrived") {
|
||||
ui->label->setPixmap(QIcon::fromTheme("mail-receive").pixmap(iconSize));
|
||||
} else if (category == "battery.charging") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-charging.svg", color).pixmap(iconSize));
|
||||
} else if (category == "battery.charged") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-charged.svg", color).pixmap(iconSize));
|
||||
} else if (category == "battery.discharging") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-not-charging.svg", color).pixmap(iconSize));
|
||||
} else if (category == "battery.low") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-low.svg", color).pixmap(iconSize));
|
||||
} else if (category == "battery.critical") {
|
||||
ui->label->setPixmap(getIconFromTheme("battery-critical.svg", color).pixmap(iconSize));
|
||||
} else if (category == "device.added") {
|
||||
ui->label->setPixmap(getIconFromTheme("connect.svg", color).pixmap(iconSize));
|
||||
} else if (category == "device.removed") {
|
||||
ui->label->setPixmap(getIconFromTheme("disconnect.svg", color).pixmap(iconSize));
|
||||
} else if (category == "call.incoming") {
|
||||
ui->label->setPixmap(QIcon::fromTheme("call-start").pixmap(iconSize));
|
||||
} else if (category == "reminder.activate") {
|
||||
ui->label->setPixmap(QIcon::fromTheme("reminder").pixmap(iconSize));
|
||||
} else {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(iconSize));
|
||||
}
|
||||
} else {
|
||||
if (hints.keys().contains("urgency")) {
|
||||
QChar urgency = hints.value("urgency").toChar();
|
||||
if (urgency.unicode() == 0) {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-information").pixmap(iconSize));
|
||||
} else if (urgency.unicode() == 1) {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(iconSize));
|
||||
} else if (urgency.unicode() == 2) {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-error").pixmap(iconSize));
|
||||
}
|
||||
} else {
|
||||
ui->label->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(iconSize));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (timeout == -1) { //Timeout default
|
||||
this->timeout = 5000;
|
||||
} else if (timeout > 0) { //Timeout given by notification
|
||||
this->timeout = timeout;
|
||||
} else { //No timeout
|
||||
this->timeout = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationDialog::setParams(QString appName, QString title, QString body) {
|
||||
ui->appName->setText(appName);
|
||||
ui->title->setText(title);
|
||||
ui->body->setText(body);
|
||||
}
|
||||
|
||||
NotificationDialog::~NotificationDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void NotificationDialog::show() {
|
||||
Atom DesktopWindowTypeAtom;
|
||||
DesktopWindowTypeAtom = XInternAtom(QX11Info::display(), "_NET_WM_WINDOW_TYPE_NOTIFICATION", False);
|
||||
int retval = XChangeProperty(QX11Info::display(), this->winId(), XInternAtom(QX11Info::display(), "_NET_WM_WINDOW_TYPE", False),
|
||||
XA_ATOM, 32, PropModeReplace, (unsigned char*) &DesktopWindowTypeAtom, 1); //Change Window Type
|
||||
|
||||
unsigned long desktop = 0xFFFFFFFF;
|
||||
retval = XChangeProperty(QX11Info::display(), this->winId(), XInternAtom(QX11Info::display(), "_NET_WM_DESKTOP", False),
|
||||
XA_CARDINAL, 32, PropModeReplace, (unsigned char*) &desktop, 1); //Set visible on all desktops
|
||||
|
||||
QDialog::show();
|
||||
closed = false;
|
||||
|
||||
QRect screenGeometry = QApplication::desktop()->screenGeometry();
|
||||
this->setGeometry(screenGeometry.x(), screenGeometry.y() - this->height(), screenGeometry.width(), this->height());
|
||||
|
||||
//QThread::sleep(1); //Buffer for Window Manager Animations
|
||||
|
||||
tPropertyAnimation *anim = new tPropertyAnimation(this, "geometry");
|
||||
anim->setStartValue(this->geometry());
|
||||
anim->setEndValue(QRect(screenGeometry.x(), screenGeometry.y(), screenGeometry.width(), this->height()));
|
||||
anim->setDuration(500);
|
||||
anim->setEasingCurve(QEasingCurve::OutBounce);
|
||||
connect(anim, &tPropertyAnimation::finished, [=](){
|
||||
this->repaint();
|
||||
});
|
||||
anim->start();
|
||||
|
||||
if (timeout != -1) {
|
||||
QTimer *t = new QTimer(this);
|
||||
t->setInterval(timeout);
|
||||
t->setSingleShot(true);
|
||||
connect(t, &QTimer::timeout, [=]() {
|
||||
this->close(1);
|
||||
});
|
||||
t->start();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationDialog::on_pushButton_clicked()
|
||||
{
|
||||
this->close(2);
|
||||
}
|
||||
|
||||
void NotificationDialog::close(int reason) {
|
||||
if (!closed) {
|
||||
QRect screenGeometry = QApplication::desktop()->screenGeometry();
|
||||
|
||||
tPropertyAnimation *anim = new tPropertyAnimation(this, "geometry");
|
||||
anim->setStartValue(this->geometry());
|
||||
anim->setEndValue(QRect(screenGeometry.x(), screenGeometry.y() - this->height(), screenGeometry.width(), this->height()));
|
||||
anim->setDuration(500);
|
||||
anim->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(anim, &tPropertyAnimation::finished, [=]() {
|
||||
QDialog::close();
|
||||
//this->deleteLater();
|
||||
//delete this;
|
||||
});
|
||||
anim->start();
|
||||
|
||||
emit closing(id, reason);
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationDialog::setGeometry(int x, int y, int w, int h) { //Use wmctrl command because KWin has a problem with moving windows offscreen.
|
||||
QDialog::setGeometry(x, y, w, h);
|
||||
QProcess::execute("wmctrl -r " + this->windowTitle() + " -e 0," +
|
||||
QString::number(x) + "," + QString::number(y) + "," +
|
||||
QString::number(w) + "," + QString::number(h));
|
||||
}
|
||||
|
||||
void NotificationDialog::setGeometry(QRect geometry) {
|
||||
this->setGeometry(geometry.x(), geometry.y(), geometry.width(), geometry.height());
|
||||
}
|
||||
|
||||
void NotificationDialog::paintEvent(QPaintEvent *event) {
|
||||
QPainter painter(this);
|
||||
painter.setPen(this->palette().color(QPalette::WindowText));
|
||||
painter.drawLine(0, this->height() - 1, this->width(), this->height() - 1);
|
||||
event->accept();
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
/****************************************
|
||||
*
|
||||
* theShell - Desktop Environment
|
||||
* Copyright (C) 2017 Victor Tran
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
#ifndef NOTIFICATIONDIALOG_H
|
||||
#define NOTIFICATIONDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QDesktopWidget>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QTimer>
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include "notificationdbus.h"
|
||||
|
||||
class NotificationDBus;
|
||||
|
||||
namespace Ui {
|
||||
class NotificationDialog;
|
||||
}
|
||||
|
||||
class NotificationDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QRect geometry READ geometry WRITE setGeometry)
|
||||
|
||||
public:
|
||||
enum notificationType {
|
||||
normalType,
|
||||
callType,
|
||||
};
|
||||
|
||||
explicit NotificationDialog(QString appName, QString appIconStr, QString title, QString body, QStringList actions, int id, QVariantMap hints, int timeout, notificationType type = normalType, QWidget *parent = 0);
|
||||
~NotificationDialog();
|
||||
|
||||
void show();
|
||||
void close(int reason);
|
||||
|
||||
void setParams(QString appName, QString title, QString body);
|
||||
void setGeometry(int x, int y, int w, int h);
|
||||
void setGeometry(QRect geometry);
|
||||
|
||||
NotificationDBus* dbusParent;
|
||||
|
||||
signals:
|
||||
void closing(int id, int reason);
|
||||
|
||||
private slots:
|
||||
void on_pushButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::NotificationDialog *ui;
|
||||
|
||||
int id;
|
||||
int timeout;
|
||||
QVariantMap hints;
|
||||
bool closed = true;
|
||||
|
||||
void paintEvent(QPaintEvent* event);
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONDIALOG_H
|
139
notificationsWidget/notificationobject.cpp
Normal file
139
notificationsWidget/notificationobject.cpp
Normal file
|
@ -0,0 +1,139 @@
|
|||
#include "notificationobject.h"
|
||||
|
||||
int NotificationObject::currentId = 0;
|
||||
|
||||
NotificationObject::NotificationObject(QString app_name, QString app_icon, QString summary, QString body, QStringList actions, QVariantMap hints, int expire_timeout, QObject *parent) : QObject(parent) {
|
||||
currentId++;
|
||||
this->id = currentId;
|
||||
|
||||
dialog = new NotificationPopup(currentId);
|
||||
connect(dialog, SIGNAL(actionClicked(QString)), this, SIGNAL(actionClicked(QString)));
|
||||
connect(dialog, &NotificationPopup::notificationClosed, [=](uint reason) {
|
||||
emit closed((NotificationCloseReason) reason);
|
||||
});
|
||||
|
||||
setParameters(app_name, app_icon, summary, body, actions, hints, expire_timeout);
|
||||
}
|
||||
|
||||
void NotificationObject::setParameters(QString &app_name, QString &app_icon, QString &summary, QString &body, QStringList &actions, QVariantMap &hints, int expire_timeout) {
|
||||
this->appName = app_name;
|
||||
this->appIcon = app_icon;
|
||||
this->summary = summary;
|
||||
this->body = body;
|
||||
this->actions = actions;
|
||||
this->hints = hints;
|
||||
this->timeout = expire_timeout;
|
||||
|
||||
appIc = QIcon::fromTheme("generic-app");
|
||||
if (appIcon != "" && QIcon::hasThemeIcon(appIcon)) {
|
||||
appIc = QIcon::fromTheme(appIcon);
|
||||
} else if (QIcon::hasThemeIcon(appName.toLower().replace(" ", "-"))) {
|
||||
appIc = QIcon::fromTheme(appName.toLower().replace(" ", "-"));
|
||||
} else if (QIcon::hasThemeIcon(appName.toLower().replace(" ", ""))) {
|
||||
appIc = QIcon::fromTheme(appName.toLower().replace(" ", ""));
|
||||
} else {
|
||||
QString filename = hints.value("desktop-entry", "").toString() + ".desktop";
|
||||
|
||||
QDir appFolder("/usr/share/applications/");
|
||||
QDirIterator iterator(appFolder, QDirIterator::Subdirectories);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
QFileInfo info = iterator.fileInfo();
|
||||
if (info.fileName() == filename || info.baseName().toLower() == appName.toLower()) {
|
||||
QFile file(info.filePath());
|
||||
file.open(QFile::ReadOnly);
|
||||
QString appinfo(file.readAll());
|
||||
|
||||
QStringList desktopLines;
|
||||
QString currentDesktopLine;
|
||||
for (QString desktopLine : appinfo.split("\n")) {
|
||||
if (desktopLine.startsWith("[") && currentDesktopLine != "") {
|
||||
desktopLines.append(currentDesktopLine);
|
||||
currentDesktopLine = "";
|
||||
}
|
||||
currentDesktopLine.append(desktopLine + "\n");
|
||||
}
|
||||
desktopLines.append(currentDesktopLine);
|
||||
|
||||
for (QString desktopPart : desktopLines) {
|
||||
for (QString line : desktopPart.split("\n")) {
|
||||
if (line.startsWith("icon=", Qt::CaseInsensitive)) {
|
||||
QString iconname = line.split("=")[1];
|
||||
if (QFile(iconname).exists()) {
|
||||
appIc = QIcon(iconname);
|
||||
} else {
|
||||
appIc = QIcon::fromTheme(iconname, QIcon::fromTheme("application-x-executable"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bigIc = QIcon();
|
||||
if (hints.value("x-thesuite-timercomplete", false).toBool()) {
|
||||
bigIc = QIcon::fromTheme("chronometer");
|
||||
} else {
|
||||
if (hints.keys().contains("category")) {
|
||||
QString category = hints.value("category").toString();
|
||||
if (category == "network.connected") {
|
||||
bigIc = QIcon::fromTheme("network-connect");
|
||||
} else if (category == "network.disconnected") {
|
||||
bigIc = QIcon::fromTheme("network-disconnect");
|
||||
} else if (category == "email.arrived") {
|
||||
bigIc = QIcon::fromTheme("mail-receive");
|
||||
} else if (category == "battery.charging") {
|
||||
bigIc = QIcon::fromTheme("battery-charging-040");
|
||||
} else if (category == "battery.charged") {
|
||||
bigIc = QIcon::fromTheme("battery-charging-100");
|
||||
} else if (category == "battery.discharging") {
|
||||
bigIc = QIcon::fromTheme("battery-040");
|
||||
} else if (category == "battery.low") {
|
||||
bigIc = QIcon::fromTheme("battery-020");
|
||||
} else if (category == "battery.critical") {
|
||||
bigIc = QIcon::fromTheme("battery-000");
|
||||
} else if (category == "device.added") {
|
||||
bigIc = QIcon::fromTheme("drive-removable-media");
|
||||
} else if (category == "device.removed") {
|
||||
bigIc = QIcon::fromTheme("drive-removable-media");
|
||||
} else if (category == "call.incoming") {
|
||||
bigIc = QIcon::fromTheme("call-start");
|
||||
} else if (category == "reminder.activate") {
|
||||
bigIc = QIcon::fromTheme("reminder");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationObject::post() {
|
||||
dialog->setHints(hints);
|
||||
dialog->setApp(appName, appIc);
|
||||
dialog->setSummary(summary);
|
||||
dialog->setBody(body);
|
||||
dialog->setActions(actions);
|
||||
dialog->setBigIcon(bigIc);
|
||||
|
||||
if (timeout < 0) {
|
||||
timeout = 5000;
|
||||
}
|
||||
dialog->setTimeout(timeout);
|
||||
|
||||
dialog->show();
|
||||
}
|
||||
|
||||
int NotificationObject::getId() {
|
||||
return this->id;
|
||||
}
|
||||
|
||||
void NotificationObject::closeDialog() {
|
||||
if (dialog->isVisible()) {
|
||||
dialog->close();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationObject::dismiss() {
|
||||
closeDialog();
|
||||
|
||||
}
|
48
notificationsWidget/notificationobject.h
Normal file
48
notificationsWidget/notificationobject.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef NOTIFICATIONOBJECT_H
|
||||
#define NOTIFICATIONOBJECT_H
|
||||
|
||||
#include <QObject>
|
||||
#include "notificationpopup.h"
|
||||
|
||||
class NotificationPopup;
|
||||
|
||||
class NotificationObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum NotificationCloseReason : uint {
|
||||
Expired = 1,
|
||||
Dismissed = 2,
|
||||
ProgrammaticallyClosed = 3,
|
||||
Undefined = 4
|
||||
};
|
||||
|
||||
explicit NotificationObject(QString app_name, QString app_icon, QString summary, QString body, QStringList actions, QVariantMap hints, int expire_timeout, QObject *parent = nullptr);
|
||||
static int currentId;
|
||||
|
||||
int getId();
|
||||
|
||||
signals:
|
||||
void parametersUpdated();
|
||||
void actionClicked(QString key);
|
||||
void closed(NotificationCloseReason reason);
|
||||
|
||||
public slots:
|
||||
void post();
|
||||
void setParameters(QString &app_name, QString &app_icon, QString &summary, QString &body, QStringList &actions, QVariantMap &hints, int expire_timeout);
|
||||
void closeDialog();
|
||||
void dismiss();
|
||||
|
||||
private:
|
||||
QString appName, appIcon, summary, body;
|
||||
QStringList actions;
|
||||
QVariantMap hints;
|
||||
int timeout;
|
||||
uint id;
|
||||
|
||||
NotificationPopup* dialog;
|
||||
|
||||
QIcon appIc, bigIc;
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONOBJECT_H
|
237
notificationsWidget/notificationpopup.cpp
Normal file
237
notificationsWidget/notificationpopup.cpp
Normal file
|
@ -0,0 +1,237 @@
|
|||
#include "notificationpopup.h"
|
||||
#include "ui_notificationpopup.h"
|
||||
|
||||
#include "notificationobject.h"
|
||||
|
||||
extern float getDPIScaling();
|
||||
extern NotificationsDBusAdaptor* ndbus;
|
||||
|
||||
NotificationPopup::NotificationPopup(int id, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::NotificationPopup)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
this->setAttribute(Qt::WA_X11NetWmWindowTypeNotification, true);
|
||||
this->setWindowFlag(Qt::WindowStaysOnTopHint);
|
||||
ui->buttonsWidget->setFixedHeight(0);
|
||||
ui->downArrow->setPixmap(QIcon::fromTheme("go-down").pixmap(16 * getDPIScaling(), 16 * getDPIScaling()));
|
||||
ui->ContentsWidget->setFixedHeight(ui->bodyLabel->fontMetrics().height() + ui->ContentsWidget->layout()->contentsMargins().top());
|
||||
this->id = id;
|
||||
|
||||
dismisser = new QTimer();
|
||||
dismisser->setInterval(500);
|
||||
connect(dismisser, &QTimer::timeout, [=] {
|
||||
if (timeoutLeft != -2000) {
|
||||
timeoutLeft -= 500;
|
||||
if (timeoutLeft < 0) {
|
||||
this->close();
|
||||
emit notificationClosed(NotificationObject::Expired);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
NotificationPopup::~NotificationPopup()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void NotificationPopup::show() {
|
||||
QRect screenGeometry = QApplication::desktop()->screenGeometry();
|
||||
this->move(screenGeometry.topLeft().x(), screenGeometry.top() - this->height());
|
||||
this->setFixedWidth(screenGeometry.width());
|
||||
|
||||
textHeight = ui->bodyLabel->fontMetrics().boundingRect(QRect(0, 0, screenGeometry.width() - this->layout()->contentsMargins().left() - this->layout()->contentsMargins().right(), 10000), Qt::TextWordWrap | Qt::AlignLeft | Qt::AlignTop, ui->bodyLabel->text()).height();
|
||||
|
||||
bool showDownArrow = false;
|
||||
if (textHeight > ui->bodyLabel->fontMetrics().height()) {
|
||||
showDownArrow = true;
|
||||
}
|
||||
if (actions.count() > 0) {
|
||||
showDownArrow = true;
|
||||
}
|
||||
ui->downContainer->setVisible(showDownArrow);
|
||||
|
||||
this->setFixedHeight(this->sizeHint().height());
|
||||
QDialog::show();
|
||||
|
||||
tPropertyAnimation* anim = new tPropertyAnimation(this, "geometry");
|
||||
anim->setStartValue(this->geometry());
|
||||
anim->setEndValue(QRect(this->x(), screenGeometry.y(), this->width(), this->height()));
|
||||
anim->setDuration(500);
|
||||
anim->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||
anim->start();
|
||||
|
||||
dismisser->start();
|
||||
|
||||
mouseEvents = true;
|
||||
}
|
||||
|
||||
void NotificationPopup::close() {
|
||||
dismisser->stop();
|
||||
|
||||
QRect screenGeometry = QApplication::desktop()->screenGeometry();
|
||||
|
||||
tPropertyAnimation* anim = new tPropertyAnimation(this, "geometry");
|
||||
anim->setStartValue(this->geometry());
|
||||
anim->setEndValue(QRect(this->x(), screenGeometry.y() - this->height(), this->width(), this->height()));
|
||||
anim->setDuration(500);
|
||||
anim->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||
connect(anim, &tPropertyAnimation::finished, [=] {
|
||||
QDialog::close();
|
||||
});
|
||||
anim->start();
|
||||
|
||||
mouseEvents = false;
|
||||
}
|
||||
|
||||
void NotificationPopup::enterEvent(QEvent *event) {
|
||||
Q_UNUSED(event)
|
||||
|
||||
if (mouseEvents) {
|
||||
tVariantAnimation* anim = new tVariantAnimation();
|
||||
anim->setStartValue(ui->buttonsWidget->height());
|
||||
anim->setEndValue(ui->buttonsWidget->sizeHint().height());
|
||||
anim->setDuration(250);
|
||||
anim->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||
connect(anim, &tVariantAnimation::valueChanged, [=](QVariant value) {
|
||||
ui->buttonsWidget->setFixedHeight(value.toInt());
|
||||
this->setFixedHeight(this->sizeHint().height());
|
||||
});
|
||||
anim->start();
|
||||
|
||||
tVariantAnimation* anim2 = new tVariantAnimation();
|
||||
anim2->setStartValue(ui->downContainer->height());
|
||||
anim2->setEndValue(0);
|
||||
anim2->setDuration(250);
|
||||
anim2->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(anim2, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||
connect(anim2, &tVariantAnimation::valueChanged, [=](QVariant value) {
|
||||
ui->downContainer->setFixedHeight(value.toInt());
|
||||
});
|
||||
anim2->start();
|
||||
|
||||
tVariantAnimation* anim3 = new tVariantAnimation();
|
||||
anim3->setStartValue(ui->ContentsWidget->height());
|
||||
anim3->setEndValue(textHeight);
|
||||
anim3->setDuration(250);
|
||||
anim3->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(anim3, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||
connect(anim3, &tVariantAnimation::valueChanged, [=](QVariant value) {
|
||||
ui->ContentsWidget->setFixedHeight(value.toInt() + ui->ContentsWidget->layout()->contentsMargins().top());
|
||||
});
|
||||
anim3->start();
|
||||
|
||||
dismisser->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationPopup::leaveEvent(QEvent *event) {
|
||||
Q_UNUSED(event)
|
||||
|
||||
if (mouseEvents) {
|
||||
if (!this->rect().contains(mapFromGlobal(QCursor::pos()))) {
|
||||
tVariantAnimation* anim = new tVariantAnimation();
|
||||
anim->setStartValue(ui->buttonsWidget->height());
|
||||
anim->setEndValue(0);
|
||||
anim->setDuration(250);
|
||||
anim->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(anim, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||
connect(anim, &tVariantAnimation::valueChanged, [=](QVariant value) {
|
||||
ui->buttonsWidget->setFixedHeight(value.toInt());
|
||||
this->setFixedHeight(this->sizeHint().height());
|
||||
});
|
||||
anim->start();
|
||||
|
||||
tVariantAnimation* anim2 = new tVariantAnimation();
|
||||
anim2->setStartValue(ui->downContainer->height());
|
||||
anim2->setEndValue(ui->downContainer->sizeHint().height());
|
||||
anim2->setDuration(250);
|
||||
anim2->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(anim2, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||
connect(anim2, &tVariantAnimation::valueChanged, [=](QVariant value) {
|
||||
ui->downContainer->setFixedHeight(value.toInt());
|
||||
});
|
||||
anim2->start();
|
||||
|
||||
tVariantAnimation* anim3 = new tVariantAnimation();
|
||||
anim3->setStartValue(ui->ContentsWidget->height());
|
||||
anim3->setEndValue(ui->bodyLabel->fontMetrics().height());
|
||||
anim3->setDuration(250);
|
||||
anim3->setEasingCurve(QEasingCurve::OutCubic);
|
||||
connect(anim3, SIGNAL(finished()), anim, SLOT(deleteLater()));
|
||||
connect(anim3, &tVariantAnimation::valueChanged, [=](QVariant value) {
|
||||
ui->ContentsWidget->setFixedHeight(value.toInt() + ui->ContentsWidget->layout()->contentsMargins().top());
|
||||
});
|
||||
anim3->start();
|
||||
|
||||
dismisser->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationPopup::paintEvent(QPaintEvent *event) {
|
||||
Q_UNUSED(event)
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setPen(this->palette().color(QPalette::WindowText));
|
||||
painter.drawLine(0, this->height() - 1, this->width(), this->height() - 1);
|
||||
}
|
||||
|
||||
void NotificationPopup::setApp(QString appName, QIcon appIcon) {
|
||||
ui->appnameLabel->setText(appName);
|
||||
ui->appIcon->setPixmap(appIcon.pixmap(16 * getDPIScaling(), 16 * getDPIScaling()));
|
||||
}
|
||||
|
||||
void NotificationPopup::setSummary(QString summary) {
|
||||
ui->summaryLabel->setText(summary);
|
||||
}
|
||||
|
||||
void NotificationPopup::setBody(QString body) {
|
||||
ui->bodyLabel->setText(body);
|
||||
}
|
||||
|
||||
void NotificationPopup::setHints(QVariantMap hints) {
|
||||
this->hints = hints;
|
||||
}
|
||||
|
||||
void NotificationPopup::setActions(QStringList actions) {
|
||||
if (actions.count() % 2 == 0) {
|
||||
for (int i = 0; i < actions.length(); i += 2) {
|
||||
QString key = actions.at(i);
|
||||
QString value = actions.at(i + 1);
|
||||
|
||||
QPushButton* button = new QPushButton();
|
||||
button->setText(value);
|
||||
connect(button, &QPushButton::clicked, [=] {
|
||||
emit actionClicked(key);
|
||||
this->close();
|
||||
});
|
||||
((QBoxLayout*) ui->actionsWidget->layout())->addWidget(button);
|
||||
|
||||
this->actions.insert(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationPopup::setTimeout(int timeout) {
|
||||
if (timeout == 0) {
|
||||
timeoutLeft = -2000;
|
||||
} else {
|
||||
timeoutLeft = timeout;
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationPopup::on_dismissButton_clicked()
|
||||
{
|
||||
this->close();
|
||||
emit notificationClosed(NotificationObject::Dismissed);
|
||||
}
|
||||
|
||||
void NotificationPopup::setBigIcon(QIcon bigIcon) {
|
||||
ui->bigIconLabel->setPixmap(bigIcon.pixmap(32 * getDPIScaling(), 32 * getDPIScaling()));
|
||||
}
|
64
notificationsWidget/notificationpopup.h
Normal file
64
notificationsWidget/notificationpopup.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
#ifndef NOTIFICATIONPOPUP_H
|
||||
#define NOTIFICATIONPOPUP_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "tpropertyanimation.h"
|
||||
#include "notificationsdbusadaptor.h"
|
||||
#include <QDesktopWidget>
|
||||
#include <QApplication>
|
||||
#include <QTimer>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QBoxLayout>
|
||||
#include <QDirIterator>
|
||||
|
||||
namespace Ui {
|
||||
class NotificationPopup;
|
||||
}
|
||||
|
||||
class NotificationPopup : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NotificationPopup(int id, QWidget *parent = 0);
|
||||
~NotificationPopup();
|
||||
|
||||
void show();
|
||||
void close();
|
||||
|
||||
void setApp(QString appName, QIcon appIcon);
|
||||
void setSummary(QString summary);
|
||||
void setBody(QString body);
|
||||
void setActions(QStringList actions);
|
||||
void setTimeout(int timeout);
|
||||
void setHints(QVariantMap hints);
|
||||
void setBigIcon(QIcon bigIcon);
|
||||
|
||||
private slots:
|
||||
void on_dismissButton_clicked();
|
||||
|
||||
signals:
|
||||
void actionClicked(QString key);
|
||||
void notificationClosed(uint reason);
|
||||
|
||||
private:
|
||||
Ui::NotificationPopup *ui;
|
||||
|
||||
int id;
|
||||
int textHeight;
|
||||
bool mouseEvents = false;
|
||||
|
||||
void enterEvent(QEvent* event);
|
||||
void leaveEvent(QEvent* event);
|
||||
void paintEvent(QPaintEvent* event);
|
||||
|
||||
QTimer* dismisser = NULL;
|
||||
int timeoutLeft;
|
||||
QMap<QString, QString> actions;
|
||||
QVariantMap hints;
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONPOPUP_H
|
256
notificationsWidget/notificationpopup.ui
Normal file
256
notificationsWidget/notificationpopup.ui
Normal file
|
@ -0,0 +1,256 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NotificationPopup</class>
|
||||
<widget class="QDialog" name="NotificationPopup">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>558</width>
|
||||
<height>121</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="appIcon">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="appnameLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>8</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">App Na&me</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="ContentsWidget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="summaryLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">Summary</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="bodyLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string notr="true">&Body</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="bigIconLabel">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="buttonsWidget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="actionsWidget" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="dismissButton">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset theme="dialog-close">
|
||||
<normaloff>.</normaloff>.</iconset>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="downContainer" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="downArrow">
|
||||
<property name="text">
|
||||
<string notr="true">Down</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
61
notificationsWidget/notificationsdbusadaptor.cpp
Normal file
61
notificationsWidget/notificationsdbusadaptor.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include "notificationsdbusadaptor.h"
|
||||
#include "notificationswidget.h"
|
||||
#include "notificationobject.h"
|
||||
|
||||
NotificationsDBusAdaptor::NotificationsDBusAdaptor(QObject *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
this->setAutoRelaySignals(true);
|
||||
}
|
||||
|
||||
NotificationsDBusAdaptor::~NotificationsDBusAdaptor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void NotificationsDBusAdaptor::CloseNotification(uint id)
|
||||
{
|
||||
if (this->parentWidget()->hasNotificationId(id)) {
|
||||
NotificationObject* notification = this->parentWidget()->getNotification(id);
|
||||
notification->dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
QStringList NotificationsDBusAdaptor::GetCapabilities()
|
||||
{
|
||||
return QStringList() << "body" << "body-hyperlinks" << "body-markup";
|
||||
}
|
||||
|
||||
QString NotificationsDBusAdaptor::GetServerInformation(QString &vendor, QString &version, QString &spec_version)
|
||||
{
|
||||
vendor = "theSuite";
|
||||
version = "2.0";
|
||||
spec_version = "1.2";
|
||||
return "theShell";
|
||||
}
|
||||
|
||||
uint NotificationsDBusAdaptor::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int expire_timeout)
|
||||
{
|
||||
if (this->parentWidget() != NULL) {
|
||||
NotificationObject* notification;
|
||||
if (this->parentWidget()->hasNotificationId(replaces_id)) {
|
||||
notification = this->parentWidget()->getNotification(replaces_id);
|
||||
} else {
|
||||
notification = new NotificationObject(app_name, app_icon, summary, body, actions, hints, expire_timeout);
|
||||
}
|
||||
this->parentWidget()->addNotification(notification);
|
||||
|
||||
notification->post();
|
||||
|
||||
return notification->getId();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NotificationsWidget* NotificationsDBusAdaptor::parentWidget() {
|
||||
return pt;
|
||||
}
|
||||
|
||||
void NotificationsDBusAdaptor::setParentWidget(NotificationsWidget *parent) {
|
||||
pt = parent;
|
||||
}
|
|
@ -1,55 +1,20 @@
|
|||
/****************************************
|
||||
*
|
||||
* theShell - Desktop Environment
|
||||
* Copyright (C) 2017 Victor Tran
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* *************************************/
|
||||
#ifndef NOTIFICATIONSDBUSADAPTOR_H
|
||||
#define NOTIFICATIONSDBUSADAPTOR_H
|
||||
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -l NotificationDBus -i notificationdbus.h -a notifications_adaptor.h: ../theShell/org.freedesktop.Notifications.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd.
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* This file may have been hand-edited. Look for HAND-EDIT comments
|
||||
* before re-generating it.
|
||||
*/
|
||||
#include <QObject>
|
||||
#include <QDBusAbstractAdaptor>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusArgument>
|
||||
#include <QDBusUnixFileDescriptor>
|
||||
#include <QDBusMetaType>
|
||||
#include <QSettings>
|
||||
#include <QApplication>
|
||||
#include <QDBusReply>
|
||||
|
||||
#ifndef NOTIFICATIONS_ADAPTOR_H
|
||||
#define NOTIFICATIONS_ADAPTOR_H
|
||||
class NotificationsWidget;
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtDBus/QtDBus>
|
||||
#include "notificationdbus.h"
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QByteArray;
|
||||
template<class T> class QList;
|
||||
template<class Key, class Value> class QMap;
|
||||
class QString;
|
||||
class QStringList;
|
||||
class QVariant;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
class NotificationDBus;
|
||||
|
||||
/*
|
||||
* Adaptor class for interface org.freedesktop.Notifications
|
||||
*/
|
||||
class NotificationsAdaptor: public QDBusAbstractAdaptor
|
||||
class NotificationsDBusAdaptor : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications")
|
||||
|
@ -89,22 +54,27 @@ class NotificationsAdaptor: public QDBusAbstractAdaptor
|
|||
" </method>\n"
|
||||
" </interface>\n"
|
||||
"")
|
||||
public:
|
||||
NotificationsAdaptor(NotificationDBus *parent);
|
||||
virtual ~NotificationsAdaptor();
|
||||
|
||||
inline NotificationDBus *parent() const
|
||||
{ return ((NotificationDBus*) QObject::parent()); }
|
||||
public:
|
||||
NotificationsDBusAdaptor(QObject* parent = nullptr);
|
||||
virtual ~NotificationsDBusAdaptor();
|
||||
|
||||
NotificationsWidget* parentWidget();
|
||||
void setParentWidget(NotificationsWidget* parent);
|
||||
|
||||
public: // PROPERTIES
|
||||
public Q_SLOTS: // METHODS
|
||||
public slots: // METHODS
|
||||
void CloseNotification(uint id);
|
||||
QStringList GetCapabilities();
|
||||
QString GetServerInformation(QString &vendor, QString &version, QString &spec_version);
|
||||
uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int expire_timeout);
|
||||
Q_SIGNALS: // SIGNALS
|
||||
|
||||
signals: // SIGNALS
|
||||
void ActionInvoked(uint id, const QString &action_key);
|
||||
void NotificationClosed(uint id, uint reason);
|
||||
|
||||
private:
|
||||
NotificationsWidget* pt = NULL;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // NOTIFICATIONSDBUSADAPTOR_H
|
37
notificationsWidget/notificationswidget.cpp
Normal file
37
notificationsWidget/notificationswidget.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "notificationswidget.h"
|
||||
#include "ui_notificationswidget.h"
|
||||
|
||||
extern NotificationsDBusAdaptor* ndbus;
|
||||
|
||||
NotificationsWidget::NotificationsWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::NotificationsWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ndbus->setParentWidget(this);
|
||||
}
|
||||
|
||||
NotificationsWidget::~NotificationsWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void NotificationsWidget::addNotification(NotificationObject *object) {
|
||||
notifications.insert(object->getId(), object);
|
||||
|
||||
connect(object, &NotificationObject::actionClicked, [=](QString key) {
|
||||
emit ndbus->ActionInvoked(object->getId(), key);
|
||||
});
|
||||
connect(object, &NotificationObject::closed, [=](NotificationObject::NotificationCloseReason reason) {
|
||||
emit ndbus->NotificationClosed(object->getId(), reason);
|
||||
});
|
||||
}
|
||||
|
||||
bool NotificationsWidget::hasNotificationId(uint id) {
|
||||
return notifications.contains(id);
|
||||
}
|
||||
|
||||
NotificationObject* NotificationsWidget::getNotification(uint id) {
|
||||
return notifications.value(id);
|
||||
}
|
31
notificationsWidget/notificationswidget.h
Normal file
31
notificationsWidget/notificationswidget.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef NOTIFICATIONSWIDGET_H
|
||||
#define NOTIFICATIONSWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "notificationsdbusadaptor.h"
|
||||
#include "notificationpopup.h"
|
||||
#include "notificationobject.h"
|
||||
|
||||
namespace Ui {
|
||||
class NotificationsWidget;
|
||||
}
|
||||
|
||||
class NotificationsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NotificationsWidget(QWidget *parent = 0);
|
||||
~NotificationsWidget();
|
||||
|
||||
void addNotification(NotificationObject* object);
|
||||
bool hasNotificationId(uint id);
|
||||
NotificationObject* getNotification(uint id);
|
||||
|
||||
private:
|
||||
Ui::NotificationsWidget *ui;
|
||||
|
||||
QMap<int, NotificationObject*> notifications;
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONSWIDGET_H
|
31
notificationsWidget/notificationswidget.ui
Normal file
31
notificationsWidget/notificationswidget.ui
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NotificationsWidget</class>
|
||||
<widget class="QWidget" name="NotificationsWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Recent notifications coming soon.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -1,80 +0,0 @@
|
|||
/****************************************
|
||||
*
|
||||
* theShell - Desktop Environment
|
||||
* Copyright (C) 2017 Victor Tran
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* *************************************/
|
||||
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -i notifications_adaptor.h -l NotificationDBus -i notificationdbus.h -a :notifications_adaptor.cpp ../theShell/org.freedesktop.Notifications.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2016 The Qt Company Ltd.
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* Do not edit! All changes made to it will be lost.
|
||||
*/
|
||||
|
||||
#include "notifications_adaptor.h"
|
||||
#include "notificationdbus.h"
|
||||
#include <QtCore/QMetaObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
/*
|
||||
* Implementation of adaptor class NotificationsAdaptor
|
||||
*/
|
||||
|
||||
NotificationsAdaptor::NotificationsAdaptor(NotificationDBus *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
// constructor
|
||||
setAutoRelaySignals(true);
|
||||
}
|
||||
|
||||
NotificationsAdaptor::~NotificationsAdaptor()
|
||||
{
|
||||
// destructor
|
||||
}
|
||||
|
||||
void NotificationsAdaptor::CloseNotification(uint id)
|
||||
{
|
||||
// handle method call org.freedesktop.Notifications.CloseNotification
|
||||
parent()->CloseNotification(id);
|
||||
}
|
||||
|
||||
QStringList NotificationsAdaptor::GetCapabilities()
|
||||
{
|
||||
// handle method call org.freedesktop.Notifications.GetCapabilities
|
||||
return parent()->GetCapabilities();
|
||||
}
|
||||
|
||||
QString NotificationsAdaptor::GetServerInformation(QString &vendor, QString &version, QString &spec_version)
|
||||
{
|
||||
// handle method call org.freedesktop.Notifications.GetServerInformation
|
||||
return parent()->GetServerInformation(vendor, version, spec_version);
|
||||
}
|
||||
|
||||
uint NotificationsAdaptor::Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int expire_timeout)
|
||||
{
|
||||
// handle method call org.freedesktop.Notifications.Notify
|
||||
return parent()->Notify(app_name, replaces_id, app_icon, summary, body, actions, hints, expire_timeout);
|
||||
}
|
||||
|
23
theShell.pro
23
theShell.pro
|
@ -41,14 +41,11 @@ SOURCES += main.cpp\
|
|||
endsessionwait.cpp \
|
||||
app.cpp \
|
||||
background.cpp \
|
||||
notificationdbus.cpp \
|
||||
notificationdialog.cpp \
|
||||
upowerdbus.cpp \
|
||||
infopanedropdown.cpp \
|
||||
clickablelabel.cpp \
|
||||
thewaveworker.cpp \
|
||||
loginsplash.cpp \
|
||||
notifications_adaptor.cpp \
|
||||
hoverframe.cpp \
|
||||
choosebackground.cpp \
|
||||
switch.cpp \
|
||||
|
@ -75,7 +72,11 @@ SOURCES += main.cpp\
|
|||
taskbarmanager.cpp \
|
||||
dbussignals.cpp \
|
||||
networkmanager/networkwidget.cpp \
|
||||
networkmanager/availablenetworkslist.cpp
|
||||
networkmanager/availablenetworkslist.cpp \
|
||||
notificationsWidget/notificationswidget.cpp \
|
||||
notificationsWidget/notificationsdbusadaptor.cpp \
|
||||
notificationsWidget/notificationpopup.cpp \
|
||||
notificationsWidget/notificationobject.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
window.h \
|
||||
|
@ -83,15 +84,11 @@ HEADERS += mainwindow.h \
|
|||
endsessionwait.h \
|
||||
app.h \
|
||||
background.h \
|
||||
notificationdbus.h \
|
||||
notifications_adaptor.h \
|
||||
notificationdialog.h \
|
||||
upowerdbus.h \
|
||||
infopanedropdown.h \
|
||||
clickablelabel.h \
|
||||
thewaveworker.h \
|
||||
loginsplash.h \
|
||||
notifications_adaptor.h \
|
||||
hoverframe.h \
|
||||
choosebackground.h \
|
||||
switch.h \
|
||||
|
@ -119,7 +116,11 @@ HEADERS += mainwindow.h \
|
|||
taskbarmanager.h \
|
||||
dbussignals.h \
|
||||
networkmanager/networkwidget.h \
|
||||
networkmanager/availablenetworkslist.h
|
||||
networkmanager/availablenetworkslist.h \
|
||||
notificationsWidget/notificationswidget.h \
|
||||
notificationsWidget/notificationsdbusadaptor.h \
|
||||
notificationsWidget/notificationpopup.h \
|
||||
notificationsWidget/notificationobject.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
menu.ui \
|
||||
|
@ -137,7 +138,9 @@ FORMS += mainwindow.ui \
|
|||
newmedia.ui \
|
||||
tutorialwindow.ui \
|
||||
screenshotwindow.ui \
|
||||
networkmanager/networkwidget.ui
|
||||
networkmanager/networkwidget.ui \
|
||||
notificationsWidget/notificationswidget.ui \
|
||||
notificationsWidget/notificationpopup.ui
|
||||
|
||||
DISTFILES += \
|
||||
org.freedesktop.Notifications.xml \
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "power_adaptor.h"
|
||||
|
||||
extern void EndSession(EndSessionWait::shutdownType type);
|
||||
extern NotificationDBus* ndbus;
|
||||
extern NotificationsDBusAdaptor* ndbus;
|
||||
|
||||
UPowerDBus::UPowerDBus(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
|
|
@ -22,9 +22,6 @@
|
|||
#define UPOWERDBUS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusObjectPath>
|
||||
#include <QDBusReply>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
|
@ -32,7 +29,8 @@
|
|||
#include <QIcon>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QSoundEffect>
|
||||
#include "notificationdbus.h"
|
||||
#include "endsessionwait.h"
|
||||
#include "notificationsWidget/notificationsdbusadaptor.h"
|
||||
|
||||
class UPowerDBus : public QObject
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue