2008-02-24 15:42:31 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
|
|
|
|
*
|
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
|
|
|
*
|
2008-03-02 16:14:46 +00:00
|
|
|
* $Id$
|
2008-02-24 15:42:31 +00:00
|
|
|
*/
|
|
|
|
|
2008-03-09 19:02:16 +00:00
|
|
|
#ifdef HAVE_GIO
|
|
|
|
#include <gio/gio.h>
|
|
|
|
#endif
|
2008-03-03 04:44:27 +00:00
|
|
|
#include <glib/gi18n.h>
|
2008-02-24 15:42:31 +00:00
|
|
|
#include "notify.h"
|
|
|
|
|
|
|
|
#ifndef HAVE_LIBNOTIFY
|
|
|
|
|
|
|
|
void tr_notify_init( void ) { }
|
2008-02-25 21:47:21 +00:00
|
|
|
void tr_notify_send( TrTorrent * tor UNUSED ) { }
|
2008-02-24 15:42:31 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
#include <libnotify/notify.h>
|
|
|
|
|
|
|
|
void
|
|
|
|
tr_notify_init( void )
|
|
|
|
{
|
|
|
|
notify_init( "Transmission" );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
notifyCallback( NotifyNotification * n UNUSED,
|
|
|
|
const char * action,
|
|
|
|
gpointer gdata )
|
|
|
|
{
|
|
|
|
TrTorrent * gtor = TR_TORRENT( gdata );
|
|
|
|
tr_torrent * tor = tr_torrent_handle( gtor );
|
|
|
|
const tr_info * info = tr_torrent_info( gtor );
|
2008-03-07 19:10:08 +00:00
|
|
|
char * path = NULL;
|
2008-02-24 15:42:31 +00:00
|
|
|
|
|
|
|
if( !strcmp( action, "folder" ) )
|
|
|
|
{
|
2008-03-07 19:10:08 +00:00
|
|
|
if( info->fileCount == 1 )
|
|
|
|
{
|
|
|
|
path = g_build_filename( tr_torrentGetFolder(tor), NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
path = g_build_filename( tr_torrentGetFolder(tor), info->name, NULL );
|
|
|
|
}
|
2008-02-24 15:42:31 +00:00
|
|
|
}
|
|
|
|
else if( !strcmp( action, "file" ) )
|
2008-03-07 19:10:08 +00:00
|
|
|
{
|
|
|
|
path = g_build_filename( tr_torrentGetFolder(tor), info->files[0].name, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( path )
|
|
|
|
{
|
2008-03-09 19:02:16 +00:00
|
|
|
gboolean opened = FALSE;
|
|
|
|
#ifdef HAVE_GIO
|
|
|
|
GFile * file = g_file_new_for_path( path );
|
|
|
|
char * uri = g_file_get_uri( file );
|
|
|
|
opened = g_app_info_launch_default_for_uri( uri, NULL, NULL );
|
|
|
|
g_free( uri );
|
|
|
|
g_object_unref( G_OBJECT( file ) );
|
|
|
|
#endif
|
|
|
|
if( !opened ) {
|
|
|
|
char * argv[] = { "xdg-open", path, NULL };
|
|
|
|
g_spawn_async( NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL );
|
|
|
|
}
|
2008-02-25 04:13:54 +00:00
|
|
|
g_free( path );
|
2008-03-07 19:10:08 +00:00
|
|
|
}
|
2008-02-24 15:42:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
tr_notify_send(TrTorrent *tor)
|
|
|
|
{
|
|
|
|
const tr_info * info = tr_torrent_info( tor );
|
2008-03-03 04:44:27 +00:00
|
|
|
NotifyNotification * n = notify_notification_new( _( "Torrent Complete" ), info->name, "transmission", NULL );
|
2008-02-24 15:42:31 +00:00
|
|
|
|
|
|
|
if (info->fileCount == 1)
|
2008-03-03 04:44:27 +00:00
|
|
|
notify_notification_add_action( n, "file", _( "Open File" ),
|
2008-02-24 15:42:31 +00:00
|
|
|
NOTIFY_ACTION_CALLBACK(notifyCallback), tor, NULL);
|
2008-03-03 04:44:27 +00:00
|
|
|
notify_notification_add_action( n, "folder", _( "Open Folder" ),
|
2008-02-24 15:42:31 +00:00
|
|
|
NOTIFY_ACTION_CALLBACK(notifyCallback), tor, NULL );
|
|
|
|
notify_notification_show( n, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|