(gtk) added optional libnotify support to gtk client. (wereHamster, charles)
This commit is contained in:
parent
27d5e73d7c
commit
a311e12f9b
13
configure.ac
13
configure.ac
|
@ -13,9 +13,11 @@ AC_PROG_LIBTOOL
|
|||
GLIB_MINIMUM=2.6.0
|
||||
GTK_MINIMUM=2.6.0
|
||||
WX_MINIMUM=2.6.0
|
||||
LIBNOTIFY_MINIMUM=0.4.4
|
||||
AC_SUBST(GLIB_MINIMUM)
|
||||
AC_SUBST(GTK_MINIMUM)
|
||||
AC_SUBST(WX_MINIMUM)
|
||||
AC_SUBST(LIBNOTIFY_MINIMUM)
|
||||
|
||||
AC_PROG_CC
|
||||
AC_PROG_CXX
|
||||
|
@ -92,6 +94,16 @@ AM_CONDITIONAL([BUILD_GTK],[test "x$build_gtk" = "xyes"])
|
|||
AC_SUBST(GTK_LIBS)
|
||||
AC_SUBST(GTK_CFLAGS)
|
||||
|
||||
PKG_CHECK_MODULES([LIBNOTIFY],
|
||||
[libnotify >= $LIBNOTIFY_MINIMUM],
|
||||
[use_libnotify=yes],
|
||||
[use_libnotify=no])
|
||||
AC_SUBST(LIBNOTIFY_LIBS)
|
||||
AC_SUBST(LIBNOTIFY_CFLAGS)
|
||||
if test "x$use_libnotify" = "xyes"; then
|
||||
AC_DEFINE([HAVE_LIBNOTIFY], 1)
|
||||
fi
|
||||
|
||||
IT_PROG_INTLTOOL([0.23],[no-xml])
|
||||
GETTEXT_PACKAGE=transmission
|
||||
AC_SUBST(GETTEXT_PACKAGE)
|
||||
|
@ -264,6 +276,7 @@ Configuration:
|
|||
Build Daemon: ${build_daemon}
|
||||
Build BeOS client: ${build_beos}
|
||||
Build GTK+ client: ${build_gtk}
|
||||
... libnotify support: ${use_libnotify}
|
||||
Build OS X client: ${build_darwin}
|
||||
Build wxWidgets client: ${build_wx}
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ AM_CPPFLAGS = \
|
|||
AM_CFLAGS = \
|
||||
$(GTK_CFLAGS) \
|
||||
$(OPENSSL_CFLAGS) \
|
||||
$(PTHREAD_CFLAGS)
|
||||
$(PTHREAD_CFLAGS) \
|
||||
$(LIBNOTIFY_CFLAGS)
|
||||
|
||||
noinst_HEADERS = \
|
||||
actions.h \
|
||||
|
@ -50,6 +51,7 @@ transmission_SOURCES = \
|
|||
main.c \
|
||||
makemeta-ui.c \
|
||||
msgwin.c \
|
||||
notify.c \
|
||||
open-dialog.c \
|
||||
sexy-icon-entry.c \
|
||||
stats.c \
|
||||
|
@ -69,6 +71,7 @@ transmission_LDADD = \
|
|||
$(top_builddir)/third-party/miniupnp/libminiupnp.a \
|
||||
$(top_builddir)/third-party/libnatpmp/libnatpmp.a \
|
||||
$(GTK_LIBS) \
|
||||
$(LIBNOTIFY_LIBS) \
|
||||
$(OPENSSL_LIBS) \
|
||||
$(PTHREAD_LIBS) -lm
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "ipc.h"
|
||||
#include "makemeta-ui.h"
|
||||
#include "msgwin.h"
|
||||
#include "notify.h"
|
||||
#include "open-dialog.h"
|
||||
#include "stats.h"
|
||||
#include "tr_core.h"
|
||||
|
@ -267,6 +268,8 @@ main( int argc, char ** argv )
|
|||
return 0;
|
||||
}
|
||||
|
||||
tr_notify_init( );
|
||||
|
||||
didinit = cf_init( tr_getPrefsDirectory(), NULL ); /* must come before actions_init */
|
||||
tr_prefs_init_global( );
|
||||
myUIManager = gtk_ui_manager_new ();
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
#include "notify.h"
|
||||
|
||||
#ifndef HAVE_LIBNOTIFY
|
||||
|
||||
void tr_notify_init( void ) { }
|
||||
void tr_notify_send( TrTorrent * tor ) { }
|
||||
|
||||
#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 );
|
||||
|
||||
if( !strcmp( action, "folder" ) )
|
||||
{
|
||||
char *argv[] = { "xdg-open", (char*)tr_torrentGetFolder(tor), NULL };
|
||||
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
|
||||
}
|
||||
else if( !strcmp( action, "file" ) )
|
||||
{
|
||||
char * path = g_build_filename(tr_torrentGetFolder(tor), info->files[0].name, NULL);
|
||||
char *argv[] = { "xdg-open", path, NULL };
|
||||
g_message( "path: %s", path );
|
||||
g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
|
||||
g_free(path);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tr_notify_send(TrTorrent *tor)
|
||||
{
|
||||
const tr_info * info = tr_torrent_info( tor );
|
||||
char * buf = g_strdup_printf( "%s was downloaded", info->name );
|
||||
NotifyNotification * n = notify_notification_new( "Torrent Complete", buf, "transmission", NULL );
|
||||
|
||||
if (info->fileCount == 1)
|
||||
notify_notification_add_action( n, "file", "Open File",
|
||||
NOTIFY_ACTION_CALLBACK(notifyCallback), tor, NULL);
|
||||
notify_notification_add_action( n, "folder", "Open Containing Folder",
|
||||
NOTIFY_ACTION_CALLBACK(notifyCallback), tor, NULL );
|
||||
notify_notification_show( n, NULL );
|
||||
|
||||
g_free( buf );
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* $Id:$
|
||||
*/
|
||||
|
||||
#ifndef __TR_NOTIFY_H__
|
||||
#define __TR_NOTIFY_H__
|
||||
|
||||
#include "tr_torrent.h"
|
||||
|
||||
void tr_notify_init( void );
|
||||
void tr_notify_send( TrTorrent * tor );
|
||||
|
||||
#endif
|
|
@ -34,6 +34,7 @@
|
|||
#include "tr_prefs.h"
|
||||
#include "tr_torrent.h"
|
||||
#include "conf.h"
|
||||
#include "notify.h"
|
||||
#include "util.h"
|
||||
|
||||
struct TrTorrentPrivate
|
||||
|
@ -161,11 +162,29 @@ tr_torrent_stop( TrTorrent * self )
|
|||
tr_torrentStop( handle );
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
notifyInMainThread( gpointer user_data )
|
||||
{
|
||||
g_message( "calling tr_notify_send on %p", user_data );
|
||||
tr_notify_send( TR_TORRENT( user_data ) );
|
||||
return FALSE;
|
||||
}
|
||||
static void
|
||||
statusChangedCallback( tr_torrent * tor UNUSED,
|
||||
cp_status_t status,
|
||||
void * user_data )
|
||||
{
|
||||
g_message( "status changed! new status is %d, user_data is %p", status, user_data );
|
||||
if( status == TR_CP_COMPLETE )
|
||||
g_idle_add( notifyInMainThread, user_data );
|
||||
}
|
||||
static TrTorrent *
|
||||
maketorrent( tr_torrent * handle )
|
||||
{
|
||||
TrTorrent * tor = g_object_new( TR_TORRENT_TYPE, NULL );
|
||||
tor->priv->handle = handle;
|
||||
tr_torrentSetStatusCallback( handle, statusChangedCallback, tor );
|
||||
return tor;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,11 @@ Epoch: 1
|
|||
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
|
||||
BuildRequires: glib2-devel >= @GLIB_REQUIRED@
|
||||
BuildRequires: gtk2-devel >= @GTK_REQUIRED@
|
||||
BuildRequires: libnotify-devel >= @LIBNOTIFY_REQUIRED@
|
||||
|
||||
Requires: glib2 >= @GLIB_REQUIRED@
|
||||
Requires: gtk2 >= @GTK_REQUIRED@
|
||||
Requires: libnotify >= @LIBNOTIFY_REQUIRED@
|
||||
|
||||
Provides: %{name}
|
||||
|
||||
|
|
Loading…
Reference in New Issue