2008-02-24 15:42:31 +00:00
|
|
|
/*
|
2010-01-04 21:00:47 +00:00
|
|
|
* This file Copyright (C) 2008-2010 Mnemosyne LLC
|
2008-02-24 15:42:31 +00:00
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
2008-09-23 19:11:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
2008-02-24 15:42:31 +00:00
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
2008-09-23 19:11:04 +00:00
|
|
|
*
|
2008-03-02 16:14:46 +00:00
|
|
|
* $Id$
|
2008-02-24 15:42:31 +00:00
|
|
|
*/
|
|
|
|
|
2008-08-22 01:05:38 +00:00
|
|
|
#include <string.h>
|
2009-11-22 18:55:24 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBCANBERRA
|
|
|
|
#include <canberra-gtk.h>
|
|
|
|
#endif
|
|
|
|
|
2008-03-09 19:02:16 +00:00
|
|
|
#ifdef HAVE_GIO
|
2008-09-23 19:11:04 +00:00
|
|
|
#include <gio/gio.h>
|
2008-03-09 19:02:16 +00:00
|
|
|
#endif
|
2009-11-22 18:55:24 +00:00
|
|
|
|
2008-03-03 04:44:27 +00:00
|
|
|
#include <glib/gi18n.h>
|
2009-01-13 16:39:19 +00:00
|
|
|
#include "conf.h"
|
2008-02-24 15:42:31 +00:00
|
|
|
#include "notify.h"
|
2009-01-12 21:15:14 +00:00
|
|
|
#include "tr-prefs.h"
|
2008-04-11 02:21:33 +00:00
|
|
|
#include "util.h"
|
2008-02-24 15:42:31 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_LIBNOTIFY
|
|
|
|
|
2009-06-11 16:17:48 +00:00
|
|
|
void tr_notify_init( void ) { }
|
|
|
|
void tr_notify_send( TrTorrent * tor UNUSED ) { }
|
|
|
|
void tr_notify_added( const char * name UNUSED ) { }
|
2008-02-24 15:42:31 +00:00
|
|
|
|
|
|
|
#else
|
2008-09-23 19:11:04 +00:00
|
|
|
#include <libnotify/notify.h>
|
2008-02-24 15:42:31 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
tr_notify_init( void )
|
|
|
|
{
|
|
|
|
notify_init( "Transmission" );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notifyCallback( NotifyNotification * n UNUSED,
|
2008-09-23 19:11:04 +00:00
|
|
|
const char * action,
|
|
|
|
gpointer gdata )
|
2008-02-24 15:42:31 +00:00
|
|
|
{
|
|
|
|
TrTorrent * gtor = TR_TORRENT( gdata );
|
|
|
|
|
|
|
|
if( !strcmp( action, "folder" ) )
|
|
|
|
{
|
2008-04-11 02:21:33 +00:00
|
|
|
tr_torrent_open_folder( gtor );
|
2008-02-24 15:42:31 +00:00
|
|
|
}
|
|
|
|
else if( !strcmp( action, "file" ) )
|
2008-03-07 19:10:08 +00:00
|
|
|
{
|
2009-06-11 14:59:50 +00:00
|
|
|
tr_torrent * tor = tr_torrent_handle( gtor );
|
2008-04-11 02:21:33 +00:00
|
|
|
const tr_info * info = tr_torrent_info( gtor );
|
2009-06-11 14:59:50 +00:00
|
|
|
if( tor && info )
|
|
|
|
{
|
|
|
|
const char * dir = tr_torrentGetDownloadDir( tor );
|
|
|
|
char * path = g_build_filename( dir, info->files[0].name, NULL );
|
|
|
|
gtr_open_file( path );
|
|
|
|
g_free( path );
|
|
|
|
}
|
2008-03-07 19:10:08 +00:00
|
|
|
}
|
2008-02-24 15:42:31 +00:00
|
|
|
}
|
|
|
|
|
2009-02-25 17:48:45 +00:00
|
|
|
static gboolean
|
|
|
|
can_support_actions( void )
|
|
|
|
{
|
|
|
|
static gboolean supported;
|
|
|
|
static gboolean have_checked = FALSE;
|
|
|
|
|
|
|
|
if( !have_checked )
|
|
|
|
{
|
|
|
|
GList * c;
|
|
|
|
GList * caps = notify_get_server_caps( );
|
|
|
|
|
|
|
|
have_checked = TRUE;
|
|
|
|
|
|
|
|
for( c=caps; c && !supported; c=c->next )
|
|
|
|
supported = !strcmp( "actions", (char*)c->data );
|
|
|
|
|
|
|
|
g_list_foreach( caps, (GFunc)g_free, NULL );
|
|
|
|
g_list_free( caps );
|
|
|
|
}
|
|
|
|
|
|
|
|
return supported;
|
|
|
|
}
|
|
|
|
|
2008-02-24 15:42:31 +00:00
|
|
|
void
|
2008-09-23 19:11:04 +00:00
|
|
|
tr_notify_send( TrTorrent *tor )
|
|
|
|
{
|
2009-11-22 18:55:24 +00:00
|
|
|
#ifdef HAVE_LIBCANBERRA
|
|
|
|
if( pref_flag_get( PREF_KEY_PLAY_DOWNLOAD_COMPLETE_SOUND ) )
|
|
|
|
{
|
|
|
|
/* play the sound, using sounds from the naming spec */
|
|
|
|
ca_context_play( ca_gtk_context_get (), 0,
|
|
|
|
CA_PROP_EVENT_ID, "complete-download",
|
|
|
|
CA_PROP_APPLICATION_NAME, g_get_application_name,
|
|
|
|
CA_PROP_EVENT_DESCRIPTION, _("Download complete"),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-01-12 18:48:20 +00:00
|
|
|
if( pref_flag_get( PREF_KEY_SHOW_DESKTOP_NOTIFICATION ) )
|
|
|
|
{
|
|
|
|
const tr_info * info = tr_torrent_info( tor );
|
|
|
|
NotifyNotification * n;
|
|
|
|
|
|
|
|
n = notify_notification_new( _( "Torrent Complete" ),
|
|
|
|
info->name,
|
|
|
|
"transmission", NULL );
|
|
|
|
|
2009-02-25 17:48:45 +00:00
|
|
|
if( can_support_actions( ) )
|
|
|
|
{
|
|
|
|
if( info->fileCount == 1 )
|
|
|
|
notify_notification_add_action(
|
|
|
|
n, "file", _( "Open File" ),
|
|
|
|
NOTIFY_ACTION_CALLBACK( notifyCallback ), tor,
|
|
|
|
NULL );
|
2008-09-23 19:11:04 +00:00
|
|
|
|
2009-02-25 17:48:45 +00:00
|
|
|
notify_notification_add_action(
|
|
|
|
n, "folder", _( "Open Folder" ),
|
|
|
|
NOTIFY_ACTION_CALLBACK( notifyCallback ), tor, NULL );
|
|
|
|
}
|
2009-01-12 18:48:20 +00:00
|
|
|
|
|
|
|
notify_notification_show( n, NULL );
|
|
|
|
}
|
2008-02-24 15:42:31 +00:00
|
|
|
}
|
|
|
|
|
2009-06-11 16:17:48 +00:00
|
|
|
void
|
|
|
|
tr_notify_added( const char * name )
|
|
|
|
{
|
|
|
|
if( pref_flag_get( PREF_KEY_SHOW_DESKTOP_NOTIFICATION ) )
|
|
|
|
{
|
|
|
|
NotifyNotification * n = notify_notification_new(
|
|
|
|
_( "Torrent Added" ), name, "transmission", NULL );
|
|
|
|
notify_notification_set_timeout( n, NOTIFY_EXPIRES_DEFAULT );
|
|
|
|
notify_notification_show( n, NULL );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-24 15:42:31 +00:00
|
|
|
#endif
|