View Single Post
b666m's Avatar
Posts: 1,090 | Thanked: 476 times | Joined on Jan 2010 @ Ingolstadt, Germany
#47
SUMMARY:
tried to port the nowplayingd project to a pidginnotifyd project ^^
this means that after all there should be a libnotify notification when someone writes you.
unfortunately i hadn't too much time - so this is just quick and dirty.
one important thing to do would be programming a function which looks up if there is an fullscreen app (like browser) opened - and ONLY then make a notification - a notification on every message like it would be now would be a total overkill.
(maybe you could make a preferences-file which states when the notification should show up and can be easily edited by the user)
(but in my opinion: if no fullscreen-app is opened the statusbar plugin which shows a little icon when someone wrote you is already good enough for this job)

-------------------------------

i tried to do some coding on the notify thingy:
HAVEN'T TESTED IT YET - JUST WRITTEN TOGETHER SOME STUFF!

Code:
#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <hildon/hildon-notification.h>

#include "marshal.h"  /* The file generated from marshal.list via tool glib-genmarshal */

/* pidgin dbus station name */
#define DBUS_SERVICE_PURPLE      "im.pidgin.purple.PurpleService"
#define DBUS_PATH_PURPLE         "/im/pidgin/purple/PurpleObject"
#define DBUS_INTERFACE_PURPLE    "im.pidgin.purple.PurpleInterface"

/* global dbus instance */
DBusGConnection *bus;
DBusGProxy *purple_proxy;

/* Main event loop */
GMainLoop *loop = NULL;

/* Signal callback handling routing */
void received_im_msg_cb (DBusGProxy *purple_proxy, int account_id, 
                         const char *sender, const char *message, 
                         int conv_id, unsigned int flags,
                         gpointer user_data)
{
    HildonNotification *n = NULL;

    n = hildon_notification_new( sender, message, "pidgin", "network" );
    
    /* maybe someone can find an dbus call for bringing the current conversation
       window to foreground when being clicked - using the "com.nokia.SOMETHING" interface */
    /* an example for using the pidgin interface - not tried yet ^^ */
    /* hildon_notification_add_dbus_action( n, "default", "pidgin",
        DBUS_SERVICE_PURPLE,
        DBUS_PATH_PURPLE,
        DBUS_INTERFACE_PURPLE,
        "$METHOD", // see http://developer.pidgin.im/wiki/DbusHowto#CallingPidginmethods for methods?!
        G_TYPE_NONE, NULL,
        -1 ); */
		
    notify_notification_show( NOTIFY_NOTIFICATION( n ), NULL );
    g_timeout_add_seconds( 2, close_notification, n );  
}

/*
 * The main process, loop waiting for any signals
 */
int main (int argc, char **argv)
{
    GError *error = NULL;
    
    g_type_init ();

    /* Get the bus */
    bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
    if (bus == NULL) {
        g_printerr("Failed to open connection to bus: %s", error->message);
        g_error_free(error);
        return -1;
    }

    /* Create a proxy object for the bus driver */
    purple_proxy = dbus_g_proxy_new_for_name (bus,
                                              DBUS_SERVICE_PURPLE,
                                              DBUS_PATH_PURPLE,
                                              DBUS_INTERFACE_PURPLE);
    
    if (!purple_proxy) {
        g_printerr("Couldn't connect to the Purple Service: %s", error->message);
        g_error_free(error);
        return -1;
    }

    /* Create the main loop instance */
    loop = g_main_loop_new (NULL, FALSE);

    /* Register dbus signal marshaller */
    dbus_g_object_register_marshaller(marshal_VOID__INT_STRING_STRING_INT_UINT, 
                                      G_TYPE_NONE, G_TYPE_INT, G_TYPE_STRING, 
                                      G_TYPE_STRING, G_TYPE_INT, G_TYPE_UINT, 
                                      G_TYPE_INVALID);
        
    /* Add the signal to the proxy */
    dbus_g_proxy_add_signal(purple_proxy, "ReceivedImMsg", 
                            G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, 
                            G_TYPE_INT, G_TYPE_UINT, G_TYPE_INVALID);

    /* Connect the signal handler to the proxy */
    dbus_g_proxy_connect_signal(purple_proxy, "ReceivedImMsg",
                                G_CALLBACK(received_im_msg_cb), bus, NULL);

    /* Main loop */
    g_main_loop_run (loop);

    return 0;
}
thanks to timu and his nowplayingd project for the notification example in his source-code.
and a special thanks to the guys over at http://developer.pidgin.im/wiki/DbusHowto - don't know who has written this howto but it's nearly what i was looking for (:

maybe someone can look into this code and improve it - maybe compile it too - THIS WOULD BE VERY APPRECIATED ;D

this code is meant to be run as a daemon like nowplayingd:

Code:
#!/bin/sh                                                                                                
DAEMON=/usr/bin/pidginnotifyd
DSMETOOL=/usr/sbin/dsmetool
DSMETOOL_PARAMETERS="-t"

$DSMETOOL $DSMETOOL_PARAMETERS $DAEMON
NO WARRANTY FOR THIS ONE!
(maybe someone will be inspired by this quick&dirty code ^^)

Last edited by b666m; 2010-06-23 at 16:58.