Replace gdbus and GTK with dbus-1-tqt and TDE native notifications

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
feat/with_dbus-1-tqt
Emanoil Kotsev 4 years ago
parent 7cda7848a1
commit ccc9cce4c1

@ -18,7 +18,6 @@ tde_set_project_version( )
project( kdbusnotification )
#### include essential cmake modules
include( FindPkgConfig )

@ -25,23 +25,12 @@ if( WITH_GCC_VISIBILITY )
endif( WITH_GCC_VISIBILITY )
##### check for dbus-binding-tool
find_program( DBUS_BINDING_TOOL NAMES dbus-binding-tool )
if( "${DBUS_BINDING_TOOL}" STREQUAL "DBUS_BINDING_TOOL-NOTFOUND" )
tde_message_fatal( "The dbus-binding-tool executable is required, but was not found on your system" )
# check for dbus-1-tqt
pkg_search_module( DBUS_TQT dbus-1-tqt )
if( NOT DBUS_TQT_FOUND )
tde_message_fatal( "dbus-1-tqt is required, but was not found on your system" )
endif( )
##### check for dbus-1
pkg_search_module( DBUS dbus-1 )
if( NOT DBUS_FOUND )
tde_message_fatal( "The dbus library is required, but was not found on your system" )
endif( NOT DBUS_FOUND )
##### check for dbus-glib-1
pkg_search_module( DBUS-GLIB dbus-glib-1 )
@ -49,18 +38,3 @@ if( NOT DBUS-GLIB_FOUND )
tde_message_fatal( "The dbus-glib library is required, but was not found on your system" )
endif( NOT DBUS-GLIB_FOUND )
##### check for glib-2.0
pkg_search_module( GLIB2 glib-2.0 )
if( NOT GLIB2_FOUND )
tde_message_fatal( "The glib2.0 library is required, but was not found on your system" )
endif( NOT GLIB2_FOUND )
##### check for gtk2.0
find_package( GTK2 )
if( NOT GTK2_FOUND )
tde_message_fatal( "The gtk2.0 library is required, but was not found on your system" )
endif( NOT GTK2_FOUND )

@ -18,8 +18,4 @@ Here are suggested default options:
Requirement:
============
- dbus-binding-tool (executable)
- dbus-1
- dbus-glib-1
- gtk2.0
- glib2.0
- dbus-1-tqt

@ -0,0 +1,70 @@
kdbusnotification - a DBUS notification service for TDE.
Kdbusnotification is a small program for the Trinity Desktop that
displays DBUS notifications via passive popups.
CONTRIBUTING
==============
If you wish to contribute to Kdbusnotification (TDE), you might do so:
- TDE Gitea Workspace (TGW) collaboration tool.
https://mirror.git.trinitydesktop.org/gitea
- TDE Weblate Translation Workspace (TWTW) collaboration tool.
https://mirror.git.trinitydesktop.org/weblate
DOCUMENTATION
===============
https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html
https://sylvaindurand.org/update-notifications-with-libnotify/
gdbus call \
--session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.Notify \
"identifier" \
"1" \
"" \
"Notification title" \
"Notification description" \
"[]" \
"{}" \
"2000"
The second identifier (here 1) concerns the id of the notification we wish to replace,
we will come back to this shortly.
The next identifier allows you to define an icon.
"[]" allows you to define actions, "{}" to define hints,
and finally the last argument 2000 presents the time during which the notification
must remain visible (in milliseconds).
Once this command is executed, the system returns a response that looks like :
(uint32 13,)
This number, here 13, is the id of the notification that we will be able to replace.
This means that the following command will not create a new notification, but will
replace the one we just created:
gdbus call \
--session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.Notify \
"identifier" \
"13" \
"" \
"My updated title" \
"My updated description" \
"[]" \
"{}" \
"2000"

@ -4,51 +4,43 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${TDE_INCLUDE_DIR}
${TQT_INCLUDE_DIRS}
${DBUS_INCLUDE_DIRS}
${DBUS-GLIB_INCLUDE_DIRS}
${GLIB2_INCLUDE_DIRS}
${GTK2_INCLUDE_DIRS}
${DBUS_TQT_INCLUDE_DIRS}
)
link_directories(
${TQT_LIBRARY_DIRS}
${TDE_LIB_DIR}
${DBUS_LIBRARY_DIRS}
${DBUS-GLIB_LIBRARY_DIRS}
${GLIB2_LIBRARY_DIRS}
${GTK2_LIBRARY_DIRS}
)
set( INTROSPECTIONFILE ${CMAKE_CURRENT_SOURCE_DIR}/notificationdaemon.xml )
set( DBUSXML2QT3_EXECUTABLE dbusxml2qt3 )
##### notification-daemon-tde (executable)
set( NotificationDaemon_HDRS dbusbaseNode.h introspectableInterface.h notificationsInterface.h notificationsNode.h notificationsProxy.h )
set( NotificationDaemon_SRCS dbusbaseNode.cpp introspectableInterface.cpp notificationsInterface.cpp notificationsNode.cpp notificationsProxy.cpp )
set( _header notificationdaemon-dbus-glue.h )
set( _xml notificationdaemon.xml )
function( make_moc fileinput )
add_custom_command( OUTPUT ${fileinput}.moc
COMMAND ${TMOC_EXECUTABLE} ${fileinput}.h -o ${fileinput}.moc
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${fileinput}.h
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_property( SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${fileinput}.cpp APPEND
PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${fileinput}.moc )
endfunction( )
##### HardwareControl #########################
add_custom_command(
OUTPUT ${_header}
COMMAND ${DBUS_BINDING_TOOL}
ARGS --mode=glib-server --prefix=notification_daemon_tde ${CMAKE_CURRENT_SOURCE_DIR}/${_xml} > ${_header}
DEPENDS ${_xml}
OUTPUT ${NotificationDaemon_HDRS} ${NotificationDaemon_SRCS}
COMMAND ${DBUSXML2QT3_EXECUTABLE} ${INTROSPECTIONFILE} 2>/dev/null
DEPENDS ${INTROSPECTIONFILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_source_files_properties(
daemon.cpp
PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${_header}
)
make_moc ( notificationsProxy )
tde_add_executable( notification-daemon-tde AUTOMOC
SOURCES
daemon.cpp
LINK
tdecore-shared
tdeio-shared
tdeui-shared
${DBUS_LIBRARIES}
${DBUS-GLIB_LIBRARIES}
${GLIB2_LIBRARIES}
${GTK2_LIBRARIES}
SOURCES ${NotificationDaemon_SRCS} notificationNodeService.cpp
NotificationsService.cpp NotificationDaemon.cpp NotifyWidget.cpp main.cpp
LINK ${DBUS_TQT_LIBRARIES} tdecore-shared tdeio-shared tdeui-shared
DESTINATION ${BIN_INSTALL_DIR}
)

@ -0,0 +1,127 @@
/*
* NotificationDaemon.cpp
*
* Created on: May 11, 2021
* Author: emanoil
*
* kdbusnotification Copyright (C) 2009 kdbusnotification development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <tqtimer.h>
#include <tqdbusmessage.h>
#include <tqdbuserror.h>
#include "NotificationDaemon.h"
#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications"
#define NOTIFICATIONS_DBUS_SRVC "org.freedesktop.Notifications"
#define DBUS_PATH "/org/freedesktop/DBus"
#define DBUS_SRVC "org.freedesktop.DBus"
#define DBUS_CONNECTION_TIMEOUT 4000
#define DBUS_CONNECTION_RETRY 3
NotificationDaemon::NotificationDaemon() : KUniqueApplication()
{
// TODO Auto-generated constructor stub
retryCount=0;
// init session connection to dbus
if (!initDBUS()) {
tqDebug("Failed to initialize the connection to DBus");
TQTimer::singleShot(DBUS_CONNECTION_TIMEOUT, this, TQT_SLOT(slotReconnect()));
retryCount++;
}
}
NotificationDaemon::~NotificationDaemon()
{
// close D-Bus connection
close();
delete notificationService;
delete freedesktopService;
delete orgService;
delete rootService;
// delete receiver;
}
bool NotificationDaemon::isConnectedToDBUS(){
return mConnection.isConnected();
}
bool NotificationDaemon::initDBUS(){
mConnection = TQT_DBusConnection::addConnection(TQT_DBusConnection::SessionBus, NOTIFICATIONS_DBUS_SRVC);
if ( !mConnection.isConnected() ) {
tqDebug("Failed to open connection to system message bus: "
+ mConnection.lastError().message());
return false;
}
// try to get a specific service name
if (!mConnection.requestName(NOTIFICATIONS_DBUS_SRVC, TQT_DBusConnection::NoReplace))
return false;
mConnection.scheduleDispatch();
mConnection.connect(this, TQT_SLOT(slotDbusSignal(const TQT_DBusMessage&)));
TQTimer::singleShot(10, this, TQT_SLOT(slotConnectionCheck()));
return true;
}
void NotificationDaemon::close() {
if(mConnection.isConnected()) {
mConnection.disconnect(this, TQT_SLOT(slotDbusSignal(const TQT_DBusMessage&)));
mConnection.closeConnection(NOTIFICATIONS_DBUS_SRVC);
}
}
void NotificationDaemon::slotReconnect() {
close();
if (!initDBUS()) {
if (DBUS_CONNECTION_RETRY > retryCount) {
tqFatal("Failed to initialize the connection to DBus");
}
TQTimer::singleShot(DBUS_CONNECTION_TIMEOUT, this, TQT_SLOT(slotReconnect()));
retryCount++;
}
}
void NotificationDaemon::slotDbusSignal(const TQT_DBusMessage& message) {
if (message.interface() != TQString("org.freedesktop.DBus"))
return;
if (message.member() != TQString("NameAcquired"))
return;
tqDebug("Name acquired: " + message[0].toString());
serviceName = message[0].toString();
}
void NotificationDaemon::slotConnectionCheck() {
if (serviceName != NOTIFICATIONS_DBUS_SRVC) {
tqFatal("TDE Notification service already running or no unique name possible.");
}
rootService = new RootNodeService(mConnection);
orgService = new OrgNodeService(mConnection);
freedesktopService = new FreeDesktopNodeService(mConnection);
notificationService = new NotificationsNodeService(mConnection);
tqDebug("TDE Notification service setup done.");
}
#include "NotificationDaemon.moc"

@ -0,0 +1,89 @@
/*
* NotificationDaemon.h
*
* Created on: May 11, 2021
* Author: emanoil
*
* kdbusnotification Copyright (C) 2009 kdbusnotification development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SRC_DAEMON_NOTIFICATIONDAEMON_H_
#define SRC_DAEMON_NOTIFICATIONDAEMON_H_
#include <kuniqueapplication.h>
#include <tqdbusconnection.h>
#include <tqdbusmessage.h>
#include "notificationNodeService.h"
class NotificationDaemon : public KUniqueApplication
{
Q_OBJECT
public:
NotificationDaemon();
virtual ~NotificationDaemon();
bool isConnectedToDBUS();
private slots:
/*!
* This function does a reconnect to D-Bus.
* \return void
*/
void slotReconnect();
/*!
* This function is to process D-Bus signals.
* \return void
*/
void slotDbusSignal(const TQT_DBusMessage&);
/*!
* This function is to check D-Bus connection.
* and if the name is the unique name prepare the receivers
* If the name is not the unique name it mans the service
* is already running or unique name can not be obtained from
* DBus. In this latter case the application will terminate.
*
* \return void
*/
void slotConnectionCheck();
// void slotCloseNotification(const TQ_UINT32);
private:
/*!
* This function initialise the connection to the D-Bus daemon.
* \return boolean with the result of the operation
* \retval true if successful initialised D-Bus connection
* \retval false if unsuccessful
*/
bool initDBUS();
//! to close the connection to D-Bus
void close();
private:
RootNodeService *rootService;
OrgNodeService *orgService;
FreeDesktopNodeService *freedesktopService;
NotificationsNodeService *notificationService;
// DBusReceiver *receiver;
TQT_DBusConnection mConnection;
int retryCount;
TQString serviceName;
};
#endif /* SRC_DAEMON_NOTIFICATIONDAEMON_H_ */

@ -0,0 +1,107 @@
/*
* PropertiesService.cpp
*
* Created on: Feb 7, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2009 hardwarecontrol development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "NotificationsService.h"
#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications"
#define IMAGE_SIZE 48
#define TDE_VERSION "R14.1.0"
#define VERSION "0.1"
NotificationsService::NotificationsService(TQT_DBusConnection &conn)
: org::freedesktop::NotificationsInterface(), mConnection(&conn)
{
// TODO Auto-generated constructor stub
}
NotificationsService::~NotificationsService()
{
// TODO Auto-generated destructor stub
}
bool NotificationsService::handleSignalSend(const TQT_DBusMessage& reply) {
return true;
}
TQString NotificationsService::objectPath() const {
return TQString(NOTIFICATIONS_DBUS_PATH);
}
bool NotificationsService::GetCapabilities(TQStringList& return_caps, TQT_DBusError& error) {
return_caps.clear();
return_caps << "actions" << "body" << "body-hyperlinks" << "body-markup" << "icon-static";
return true;
}
void NotificationsService::CloseNotificationAsync(int asyncCallId, TQ_UINT32 id) {
// Do nothing
}
bool NotificationsService::ReloadSettings(TQT_DBusError& error) {
// Do nothing
return true;
}
bool NotificationsService::GetServerInformation(TQString& return_name, TQString& return_vendor, TQString& return_version, TQString& return_spec_version, TQT_DBusError& error) {
return_name = TQString("Notification Daemon");
return_vendor = TQString("Trinity Desktop Project");
return_version = TQString(TDE_VERSION);
return_spec_version = TQString(VERSION);
return true;
}
void NotificationsService::NotifyAsync(
int asyncCallId,
const TQString& app_name, TQ_UINT32 id, const TQString& icon,
const TQString& summary, const TQString& body,
const TQStringList& actions,
const TQMap<TQString, TQT_DBusVariant>& hints, TQ_INT32 timeout)
{
notificationMap[id] = new NotifyWidget(0, app_name.ascii() );
notificationMap[id]->setFrameStyle( TQFrame::NoFrame );
notificationMap[id]->setIcon(icon);
notificationMap[id]->setPaletteBackgroundColor(TQt::black);
notificationMap[id]->setPaletteForegroundColor(TQt::white);
// FXIME: handle hypertext in the body
notificationMap[id]->setText(app_name + ": " + summary + "\n" + body);
notificationMap[id]->setActions(actions);
// notificationMap[id]->setHints(hints);
notificationMap[id]->setTimeout(timeout);
notificationMap[id]->show();
notificationMap[id]->raise();
notificationMap[id]->setActiveWindow();
NotifyAsyncReply(asyncCallId, id);
}
void NotificationsService::handleMethodReply(const TQT_DBusMessage& reply){
mConnection->send(reply);
}

@ -0,0 +1,64 @@
/*
* PropertiesService.h
*
* Created on: Feb 7, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2009 hardwarecontrol development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef NOTIFICATIONSSERVICE_H_
#define NOTIFICATIONSSERVICE_H_
#include <tqdbusconnection.h>
#include <tqdbusvariant.h>
#include <tqstringlist.h>
#include <tqmap.h>
#include "notificationsInterface.h"
#include "NotifyWidget.h"
class NotificationsService: public org::freedesktop::NotificationsInterface
{
public:
NotificationsService(TQT_DBusConnection&);
virtual ~NotificationsService();
protected: // implement sending signals
virtual bool handleSignalSend(const TQT_DBusMessage& reply);
virtual TQString objectPath() const;
protected:
virtual bool GetCapabilities(TQStringList& return_caps, TQT_DBusError& error);
virtual void CloseNotificationAsync(int asyncCallId, TQ_UINT32 id);
virtual bool ReloadSettings(TQT_DBusError& error);
virtual bool GetServerInformation(TQString& return_name, TQString& return_vendor, TQString& return_version, TQString& return_spec_version, TQT_DBusError& error);
virtual void NotifyAsync(int asyncCallId, const TQString& app_name, TQ_UINT32 id, const TQString& icon, const TQString& summary, const TQString& body, const TQStringList& actions, const TQMap< TQString, TQT_DBusVariant >& hints, TQ_INT32 timeout);
protected: // implement sending replies
virtual void handleMethodReply(const TQT_DBusMessage& reply);
private:
TQT_DBusConnection *mConnection;
TQMap<TQ_UINT32, NotifyWidget*> notificationMap;
};
#endif /* NOTIFICATIONSSERVICE_H_ */

@ -0,0 +1,76 @@
/*
* NotifyWidget.cpp
*
* Created on: May 14, 2021
* Author: emanoil
*
* kdbusnotification Copyright (C) 2009 kdbusnotification development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <tqtimer.h>
#include "NotifyWidget.h"
NotifyWidget::NotifyWidget( TQWidget *parent, const char *name )
: TQLabel( parent, name , WStyle_Customize | WStyle_Splash), id(TQString(name))
{
// TODO Auto-generated constructor stub
}
NotifyWidget::~NotifyWidget()
{
// TODO Auto-generated destructor stub
}
void NotifyWidget::mousePressEvent( TQMouseEvent *e )
{
this->close();
}
void NotifyWidget::timeout()
{
this->close();
//TODO emit NotificationClosed
}
void NotifyWidget::setAutoMask(bool b)
{
if (b)
setBackgroundMode( PaletteForeground );
else
setBackgroundMode( PaletteBackground );
TQWidget::setAutoMask(b);
}
void NotifyWidget::setIcon(const TQString& icon) {
mIcon = icon;
// TODO handle icon
}
void NotifyWidget::setActions(const TQStringList& actions) {
mActions = actions;
// TODO handle actions
}
//void NotifyWidget::setHints(const TQMap< TQString, TQT_DBusVariant >& hints) {
// mHints = hints;
//}
void NotifyWidget::setTimeout(TQ_INT32 t) {
TQTimer::singleShot(t, this, TQT_SLOT(timeout()));
}
#include "NotifyWidget.moc"

@ -0,0 +1,57 @@
/*
* NotifyWidget.h
*
* Created on: May 14, 2021
* Author: emanoil
*
* kdbusnotification Copyright (C) 2009 kdbusnotification development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef SRC_DAEMON_NOTIFYWIDGET_H_
#define SRC_DAEMON_NOTIFYWIDGET_H_
#include <tqlabel.h>
class NotifyWidget: public TQLabel
{
TQ_OBJECT
public:
NotifyWidget( TQWidget *parent=0, const char *name=0 );
virtual ~NotifyWidget();
void setAutoMask(bool b);
void setIcon(const TQString& icon);
void setActions(const TQStringList& actions);
// void setHints(const TQMap< TQString, TQT_DBusVariant >& hints);
void setTimeout(TQ_INT32 t);
protected:
void mousePressEvent( TQMouseEvent *);
private slots:
void timeout();
private:
TQString mIcon;
TQStringList mActions;
// TQMap< TQString, TQT_DBusVariant > mHints;
TQ_INT32 mTimeout;
TQString id;
};
#endif /* SRC_DAEMON_NOTIFYWIDGET_H_ */

@ -1,319 +0,0 @@
/* $Id: daemon.c 2337 2007-01-11 19:17:30Z nick $
*
* Copyright (C) 2006 Christian Hammond <chipx86@chipx86.com>
* Copyright (C) 2005 John (J5) Palmieri <johnp@redhat.com>
* Copyright (C) 2006 Nick Schermer <nick@xfce.org>
*
* 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 2, 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <tqsignalmapper.h>
#include <tqevent.h>
#include <tqsize.h>
#include <tqcursor.h>
#include <tqpixmap.h>
#include <tqtimer.h>
#include <knotifyclient.h>
#include <tdeaboutdata.h>
#include <tdecmdlineargs.h>
#include <tdelocale.h>
#include <tdeapplication.h>
#include <kiconloader.h>
#include <tdeglobalsettings.h>
#include <tdepassivepopupstack.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include "daemon.h"
NotificationContainer* GTKNotifierContainer = NULL;
void real_handleGTKMain();
NotificationContainer::NotificationContainer() : TDEPassivePopupStackContainer() {
//
}
NotificationContainer::~NotificationContainer() {
//
}
void NotificationContainer::handleGTKMain() {
real_handleGTKMain();
}
#undef signals
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include "notificationdaemon-dbus-glue.h"
#define IMAGE_SIZE 48
#define NW_GET_NOTIFY_ID(nw) \
(GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(nw), "_notify_id")))
#define NW_GET_NOTIFY_SENDER(nw) \
(g_object_get_data(G_OBJECT(nw), "_notify_sender"))
#define NW_GET_DAEMON(nw) \
(g_object_get_data(G_OBJECT(nw), "_notify_daemon"))
static const char *description =
I18N_NOOP("A DBUS notification to TDE interface.");
static const char *message =
I18N_NOOP("First release October 2011.");
static const char *version = "0.01";
typedef struct
{
GTimeVal expiration;
GTimeVal paused_diff;
gboolean has_timeout;
gboolean paused;
guint id;
GtkWindow *nw;
} NotifyTimeout;
static DBusConnection *dbus_conn = NULL;
#define CHECK_DBUS_VERSION(major, minor) \
(DBUS_MAJOR_VER > (major) || \
(DBUS_MAJOR_VER == (major) && DBUS_MINOR_VER >= (minor)))
#if !CHECK_DBUS_VERSION(0, 60)
/* This is a hack that will go away in time. For now, it's fairly safe. */
struct _DBusGMethodInvocation
{
DBusGConnection *connection;
DBusGMessage *message;
const DBusGObjectInfo *object;
const DBusGMethodInfo *method;
};
#endif /* D-BUS < 0.60 */
G_DEFINE_TYPE(NotifyDaemon, notify_daemon, G_TYPE_OBJECT);
static void
notify_daemon_finalize(GObject *object)
{
NotifyDaemon *daemon = NOTIFY_DAEMON(object);
GObjectClass *parent_class = G_OBJECT_CLASS(notify_daemon_parent_class);
if (parent_class->finalize != NULL)
parent_class->finalize(object);
}
static void
notify_daemon_class_init(NotifyDaemonClass *daemon_class)
{
GObjectClass *object_class = G_OBJECT_CLASS(daemon_class);
object_class->finalize = notify_daemon_finalize;
}
static void
notify_daemon_init(NotifyDaemon *daemon)
{
}
gboolean
notify_daemon_notify_handler(NotifyDaemon *daemon,
const gchar *app_name,
guint id,
const gchar *icon,
const gchar *summary,
const gchar *body,
gchar **actions,
GHashTable *hints,
int timeout, DBusGMethodInvocation *context)
{
NotifyDaemonPrivate *priv = daemon->priv;
NotifyTimeout *nt = NULL;
GtkWindow *nw = NULL;
GValue *data;
gboolean use_pos_data = FALSE;
gboolean new_notification = FALSE;
gint x = 0;
gint y = 0;
guint return_id;
gchar *sender;
gint i;
/* deal with x, and y hints */
if ((data = (GValue *)g_hash_table_lookup(hints, "x")) != NULL)
{
x = g_value_get_int(data);
if ((data = (GValue *)g_hash_table_lookup(hints, "y")) != NULL)
{
y = g_value_get_int(data);
use_pos_data = TRUE;
}
}
// Send a notification request to KDE here...
TQString messageCaption = TQString::fromLocal8Bit(summary);
TQString messageText = TQString::fromLocal8Bit(body);
GTKNotifierContainer->displayMessage(messageCaption, messageText, TQString(icon), x, y);
GTKNotifierContainer->processEvents();
return_id = 0;
dbus_g_method_return(context, return_id);
return TRUE;
}
gboolean
notify_daemon_close_notification_handler(NotifyDaemon *daemon,
guint id, GError **error)
{
// Do nothing
return TRUE;
}
gboolean
notify_daemon_get_capabilities(NotifyDaemon *daemon, char ***caps)
{
*caps = g_new0(char *, 6);
(*caps)[0] = g_strdup("actions");
(*caps)[1] = g_strdup("body");
(*caps)[2] = g_strdup("body-hyperlinks");
(*caps)[3] = g_strdup("body-markup");
(*caps)[4] = g_strdup("icon-static");
(*caps)[5] = NULL;
return TRUE;
}
gboolean
notify_daemon_reload_settings (NotifyDaemon *daemon)
{
// Do nothing
return TRUE;
}
gboolean
notify_daemon_get_server_information(NotifyDaemon *daemon,
char **out_name,
char **out_vendor,
char **out_version,
char **out_spec_ver)
{
*out_name = g_strdup("Notification Daemon");
*out_vendor = g_strdup("Trinity Desktop Project");
*out_version = g_strdup(VERSION);
*out_spec_ver = g_strdup("0.1");
return TRUE;
}
int
main(int argc, char **argv)
{
NotifyDaemon *daemon;
DBusGConnection *connection;
DBusGProxy *bus_proxy;
GError *error;
guint request_name_result;
g_set_application_name ("notification-daemon-tde");
#ifdef G_ENABLE_DEBUG
g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
#endif
gtk_init(&argc, &argv);
error = NULL;
connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if (connection == NULL)
{
g_printerr("Failed to open connection to bus: %s\n",
error->message);
g_error_free(error);
exit(1);
}
dbus_conn = dbus_g_connection_get_connection(connection);
dbus_g_object_type_install_info(NOTIFY_TYPE_DAEMON,
&dbus_glib_notification_daemon_tde_object_info);
bus_proxy = dbus_g_proxy_new_for_name(connection,
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus");
if (!dbus_g_proxy_call(bus_proxy, "RequestName", &error,
G_TYPE_STRING, "org.freedesktop.Notifications",
G_TYPE_UINT, 0,
G_TYPE_INVALID,
G_TYPE_UINT, &request_name_result,
G_TYPE_INVALID))
{
g_error("Could not acquire name: %s", error->message);
}
daemon = static_cast<NotifyDaemon*>(g_object_new(NOTIFY_TYPE_DAEMON, NULL));
dbus_g_connection_register_g_object(connection,
"/org/freedesktop/Notifications",
G_OBJECT(daemon));
TDEAboutData aboutData("notification-daemon-tde", I18N_NOOP("TDE DBUS Notification Daemon"), version,
description, TDEAboutData::License_GPL,
"(c) 2011, Timothy Pearson",
message, 0 /* TODO: Website */, "kb9vqf@pearsoncomputing.net");
TDECmdLineArgs::init(argc, argv, &aboutData);
TDEApplication app;
NotificationContainer nc;
app.setMainWidget(&nc);
GTKNotifierContainer = &nc;
TQTimer *gtkEventProcessor = new TQTimer( &app );
TQObject::connect( gtkEventProcessor, TQ_SIGNAL(timeout()), &nc, TQ_SLOT(handleGTKMain()) );
gtkEventProcessor->start( 100, FALSE ); // Every 0.1 seconds poll gtk for DBUS events
app.disableSessionManagement();
app.exec();
return 0;
}
void real_handleGTKMain() {
while (gtk_events_pending())
gtk_main_iteration();
}
#include "daemon.moc"

@ -1,113 +0,0 @@
/* $Id: daemon.h 2114 2006-10-22 14:44:42Z nick $
*
* Copyright (C) 2006 Christian Hammond <chipx86@chipx86.com>
* Copyright (C) 2005 John (J5) Palmieri <johnp@redhat.com>
*
* 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 2, 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef NOTIFY_DAEMON_H
#define NOTIFY_DAEMON_H
class TDEUI_EXPORT NotificationContainer : public TDEPassivePopupStackContainer
{
TQ_OBJECT
public:
NotificationContainer();
~NotificationContainer();
public slots:
void handleGTKMain();
};
#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#define NOTIFY_TYPE_DAEMON (notify_daemon_get_type())
#define NOTIFY_DAEMON(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), NOTIFY_TYPE_DAEMON, NotifyDaemon))
#define NOTIFY_DAEMON_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), NOTIFY_TYPE_DAEMON, NotifyDaemonClass))
#define NOTIFY_IS_DAEMON(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), NOTIFY_TYPE_DAEMON))
#define NOTIFY_IS_DAEMON_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), NOTIFY_TYPE_DAEMON))
#define NOTIFY_DAEMON_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), NOTIFY_TYPE_DAEMON, NotifyDaemonClass))
#define NOTIFY_DAEMON_DEFAULT_TIMEOUT 7000
typedef struct _NotifyDaemon NotifyDaemon;
typedef struct _NotifyDaemonClass NotifyDaemonClass;
typedef struct _NotifyDaemonPrivate NotifyDaemonPrivate;
struct _NotifyDaemon
{
GObject parent;
/*< private > */
NotifyDaemonPrivate *priv;
};
struct _NotifyDaemonClass
{
GObjectClass parent_class;
};
enum _NotifyDaemonError
{
NOTIFY_DAEMON_ERROR_GENERIC = 0,
};
G_BEGIN_DECLS
GType notify_daemon_get_type(void);
NotifyDaemon *notify_daemon_new(void)
G_GNUC_MALLOC;
gboolean notify_daemon_notify_handler(NotifyDaemon *daemon,
const gchar *app_name,
guint id,
const gchar *icon,
const gchar *summary,
const gchar *body,
gchar **actions,
GHashTable *hints,
int timeout,
DBusGMethodInvocation *context);
gboolean notify_daemon_close_notification_handler(NotifyDaemon *daemon,
guint id, GError **error);
gboolean notify_daemon_get_capabilities(NotifyDaemon *daemon,
char ***out_caps);
gboolean notify_daemon_reload_settings (NotifyDaemon *daemon);
gboolean notify_daemon_get_server_information(NotifyDaemon *daemon,
char **out_name,
char **out_vendor,
char **out_version,
char **out_spec_ver);
G_END_DECLS
#endif /* NOTIFY_DAEMON_H */

@ -0,0 +1,71 @@
/*
* main.cpp
*
* Created on: May 11, 2021
* Author: emanoil
*
* kdbusnotification Copyright (C) 2009 kdbusnotification development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <iostream>
#include <tdecmdlineargs.h>
#include <tdeaboutdata.h>
#include <tdemessagebox.h>
#include "NotificationDaemon.h"
int
main(int argc, char **argv)
{
TDEAboutData aboutData(
"notification-daemon-tde",
I18N_NOOP("TDE DBUS Notification Daemon"),
"0.1",
I18N_NOOP("A DBUS notification to TDE interface."), // description
TDEAboutData::License_GPL,
"(c) 2021, Emanoil Kotsev",
I18N_NOOP("TDE DBUS Notification Daemon"), // message
0 /* TODO: Website */,
"deloptes@gmail.com");
TDECmdLineArgs::init( argc, argv, &aboutData );
// TODO handle options if needed
// TDECmdLineArgs::addCmdLineOptions( options );
// KUniqueApplication::addCmdLineOptions();
if (!KUniqueApplication::start())
{
std::cerr << i18n("notification-daemon-tde is already running.\n").local8Bit();
return 0;
}
NotificationDaemon app;
app.disableSessionManagement();
if (!app.isConnectedToDBUS())
{
KMessageBox::error(NULL,i18n("Can't connect to DBus!"));
// debug message for testing
std::cerr << i18n("Can't connect to DBus!\n").local8Bit();
KUniqueApplication::kApplication()->quit();
return 0;
}
else
{
return app.exec();
}
}

@ -0,0 +1,106 @@
/*
*
* HardwareControl DBus Service implementation
*
* Copyright (C) 2020 Emanoil Kotsev <deloptes@gmail.com>
*
*
* This file is part of tdecore/tdehw.
*
* hardwarecontrol 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 2 of the License, or
* (at your option) any later version.
*
* hardwarecontrol 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 tdelibs; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
// TQt includes
#include <tqdbusobjectpath.h>
#include "notificationNodeService.h"
#include "NotificationsService.h"
#define NOTIFICATIONS_DBUS_PATH "/org/freedesktop/Notifications"
/*
* Root Node
*/
RootNodeService::RootNodeService(TQT_DBusConnection &connection )
: DBusBaseNode(), mConnection(connection)
{
addChildNode(TQString("org"));
registerObject(mConnection,TQString("/"));
}
RootNodeService::~RootNodeService(){
}
TQT_DBusObjectBase* RootNodeService::createInterface(const TQString& interfaceName)
{
return (TQT_DBusObjectBase*) mInterfaces[interfaceName];
}
/*
* Org Node
*/
OrgNodeService::OrgNodeService(TQT_DBusConnection &connection )
: DBusBaseNode(), mConnection(connection)
{
addChildNode(TQString("freedesktop"));
registerObject(mConnection,TQString("/org"));
}
OrgNodeService::~OrgNodeService(){
}
TQT_DBusObjectBase* OrgNodeService::createInterface(const TQString& interfaceName)
{
return (TQT_DBusObjectBase*) mInterfaces[interfaceName];
}
/*
* FreeDesktop Node
*/
FreeDesktopNodeService::FreeDesktopNodeService(TQT_DBusConnection &connection )
: DBusBaseNode(), mConnection(connection)
{
addChildNode(TQString("Notifications"));
registerObject(mConnection,TQString("/org/freedesktop"));
}
FreeDesktopNodeService::~FreeDesktopNodeService(){
}
TQT_DBusObjectBase* FreeDesktopNodeService::createInterface(const TQString& interfaceName)
{
return (TQT_DBusObjectBase*) mInterfaces[interfaceName];
}
/*
* Notifications Node
*/
NotificationsNodeService::NotificationsNodeService(TQT_DBusConnection &conn)
: org::freedesktop::NotificationsNode(),
mConnection(conn)
{
mInterfaces.insert("org.freedesktop.DBus.Introspectable", this);
mInterfaces.insert("org.freedesktop.Notifications", new NotificationsService(mConnection));
registerObject(mConnection,TQString(NOTIFICATIONS_DBUS_PATH));
}
NotificationsNodeService::~NotificationsNodeService(){
}
TQT_DBusObjectBase* NotificationsNodeService::createInterface(const TQString& interfaceName)
{
return (TQT_DBusObjectBase*) mInterfaces[interfaceName];
}

@ -0,0 +1,109 @@
/*
*
* Notification DBus Service implementation
*
* Copyright (C) 2020 Emanoil Kotsev <deloptes@gmail.com>
*
*
* This file is part of kdbusnotification.
*
* kdbusnotification 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 2 of the License, or
* (at your option) any later version.
*
* kdbusnotification 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 kdbusnotification; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef NOTIFICATIONSNODEERVICE_H
#define NOTIFICATIONSNODEERVICE_H
#include <tqmap.h>
#include <tqdbusconnection.h>
#include "notificationsNode.h"
#include "dbusbaseNode.h"
/**
* RootNodeService
* Service: -
* Path : /
* Children: org
*/
class RootNodeService : public DBusBaseNode
{
public:
RootNodeService(TQT_DBusConnection&);
~RootNodeService();
protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&);
private:
TQMap<TQString, TQT_DBusObjectBase*> mInterfaces;
TQT_DBusConnection mConnection;
};
/**
* OrgNodeService
* Service: -
* Path : /org
* Children: freedesktop
*/
class OrgNodeService : public DBusBaseNode
{
public:
OrgNodeService(TQT_DBusConnection&);
~OrgNodeService();
protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&);
private:
TQMap<TQString, TQT_DBusObjectBase*> mInterfaces;
TQT_DBusConnection mConnection;
};
/**
* FreeDesktopNodeService
* Service: -
* Path : /org/freedesktop
* Children: notifications
*/
class FreeDesktopNodeService : public DBusBaseNode
{
public:
FreeDesktopNodeService(TQT_DBusConnection&);
~FreeDesktopNodeService();
protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&);
private:
TQMap<TQString, TQT_DBusObjectBase*> mInterfaces;
TQT_DBusConnection mConnection;
};
/*
* NotificationsNodeService
* Service: org.freedesktop.DBus.Introspectable
* Path : /org/freedesktop/Notifications
* Children: -
*/
class NotificationsNodeService : public org::freedesktop::NotificationsNode
{
public:
NotificationsNodeService(TQT_DBusConnection&);
~NotificationsNodeService();
protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&);
private:
TQMap<TQString, TQT_DBusObjectBase*> mInterfaces;
TQT_DBusConnection mConnection;
};
#endif // NOTIFICATIONSNODEERVICE_H

@ -1,12 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<!--
https://specifications.freedesktop.org/notification-spec/latest/ar01s09.html
-->
<node name="/org/freedesktop/Notifications">
<interface name="org.freedesktop.Notifications">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="NotifyDaemon"/>
<method name="GetCapabilities">
<arg type="as" name="return_caps" direction="out"/>
</method>
<method name="Notify">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="notify_daemon_notify_handler"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="s" name="app_name" direction="in" />
<arg type="u" name="id" direction="in" />
<arg type="s" name="icon" direction="in" />
@ -19,26 +26,28 @@
</method>
<method name="CloseNotification">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="notify_daemon_close_notification_handler"/>
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="u" name="id" direction="in" />
</method>
<method name="GetCapabilities">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="notify_daemon_get_capabilities"/>
<arg type="as" name="return_caps" direction="out"/>
</method>
<method name="ReloadSettings">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="notify_daemon_reload_settings"/>
</method>
<method name="GetServerInformation">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="notify_daemon_get_server_information"/>
<arg type="s" name="return_name" direction="out"/>
<arg type="s" name="return_vendor" direction="out"/>
<arg type="s" name="return_version" direction="out"/>
<arg type="s" name="return_spec_version" direction="out"/>
</method>
<signal name="NotificationClosed">
<arg name="id" type="u" direction="out"/>
<arg name="reason" type="u" direction="out"/>
</signal>
<signal name="ActionInvoked">
<arg name="id" type="u" direction="out"/>
<arg name="action_key" type="s" direction="out"/>
</signal>
</interface>
</node>

Loading…
Cancel
Save