Changeset 12638


Ignore:
Timestamp:
Aug 7, 2011, 4:42:38 PM (12 years ago)
Author:
jordan
Message:

(trunk gtk) bump the glib2 requirement from 2.8 to 2.26 s.t. transmission-gtk can use glib's GDBus module and drop the glib-dbus library dependency

Location:
trunk
Files:
1 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r12578 r12638  
    5151##
    5252##
    53 GLIB_MINIMUM=2.8.0
    54 AC_SUBST(GLIB_MINIMUM)
    5553GTK_MINIMUM=2.8.0
    5654AC_SUBST(GTK_MINIMUM)
     55GLIB_MINIMUM=2.26.0
     56AC_SUBST(GLIB_MINIMUM)
     57GIO_MINIMUM=2.26.0
     58AC_SUBST(GIO_MINIMUM)
    5759
    5860##
     
    6163##
    6264##
    63 # inhibit hibernation when a torrent is active...
    64 DBUS_GLIB_MINIMUM=0.70
    65 AC_SUBST(DBUS_GLIB_MINIMUM)
    66 # implement "watch" directories to use new .torrent files...
    67 GIO_MINIMUM=2.15.5
    68 AC_SUBST(GIO_MINIMUM)
     65
    6966# create the tray icon with AppIndicator
    7067LIBAPPINDICATOR_MINIMUM=0.0.11
     
    244241                  [gtk+-2.0 >= $GTK_MINIMUM
    245242                   glib-2.0 >= $GLIB_MINIMUM
     243                   gio-2.0 >= $GIO_MINIMUM],
    246244                   gmodule-2.0 >= $GLIB_MINIMUM
    247245                   gthread-2.0 >= $GLIB_MINIMUM],
     
    253251              [want_gtk=${have_gtk}])
    254252build_gtk=no
    255 use_gio=no
    256253use_libappindicator=no
    257 use_dbus_glib=no
    258254if test "x$want_gtk" = "xyes" ; then
    259255    if test "x$have_gtk" = "xyes"; then
     
    266262
    267263if test "x$build_gtk" = "xyes"; then
    268 
    269     PKG_CHECK_MODULES([GIO],
    270                       [gio-2.0 >= $GIO_MINIMUM],
    271                       [use_gio=yes],
    272                       [use_gio=no])
    273     if test "x$use_gio" = "xyes"; then
    274         AC_DEFINE([HAVE_GIO], 1)
    275     fi
    276264
    277265    PKG_CHECK_MODULES([LIBAPPINDICATOR],
     
    291279            LIBAPPINDICATOR_CFLAGS=
    292280            LIBAPPINDICATOR_LIBS=
    293         fi
    294     fi
    295 
    296     PKG_CHECK_MODULES([DBUS_GLIB],
    297                       [dbus-glib-1 >= $DBUS_GLIB_MINIMUM],
    298                       [use_dbus_glib=yes],
    299                       [use_dbus_glib=no])
    300     if test "x$use_dbus_glib" = "xyes"; then
    301         AC_DEFINE([HAVE_DBUS_GLIB], 1)
    302     fi
    303     if test "x$use_dbus_glib" = "xyes"; then
    304         AC_PATH_PROG(DBUS_BINDING_TOOL, dbus-binding-tool, no)
    305         if test "x$DBUS_BINDING_TOOL" = xno; then
    306           AC_MSG_WARN([Cannot find dbus-binding-tool])
    307           use_dbus_glib="no (dbus-binding-tool not found)"
    308281        fi
    309282    fi
     
    462435
    463436   Build libtransmission:                             yes
    464 
    465437      * optimized for low-resource systems:           ${enable_lightweight}
    466438      * µTP enabled:                                  ${build_utp}
     
    469441
    470442   Build GTK+ client:                                 ${build_gtk}
    471 
    472      Optional dependencies for GTK+ client:
    473 
    474       * dbus support:                                 ${use_dbus_glib}
    475       * gio for watchdir and mime-type support:       ${use_gio}
    476443      * libappindicator for an Ubuntu-style tray:     ${use_libappindicator}
    477444
  • trunk/gtk/Makefile.am

    r12578 r12638  
    1818    @GTK_CFLAGS@ \
    1919    @LIBCURL_CFLAGS@ \
    20     @GIO_CFLAGS@ \
    21     @DBUS_GLIB_CFLAGS@ \
    2220    @OPENSSL_CFLAGS@ \
    2321    @ZLIB_CFLAGS@ \
     
    5149    torrent-cell-renderer.h \
    5250    tr-core.h \
    53     tr-core-dbus.h \
    5451    tr-icon.h \
    5552    tr-prefs.h \
     
    5956
    6057bin_PROGRAMS = transmission-gtk
    61 
    62 dbus_generated_sources = tr-core-dbus.h
    6358
    6459transmission_gtk_SOURCES = \
     
    8479    tr-prefs.c \
    8580    tr-window.c \
    86     util.c \
    87     $(dbus_generated_sources)
     81    util.c
    8882
    8983dist_man_MANS = transmission-gtk.1
     
    9690    @LIBUTP_LIBS@ \
    9791    @GTK_LIBS@ \
    98     @GIO_LIBS@ \
    9992    @LIBAPPINDICATOR_LIBS@ \
    10093    @LIBEVENT_LIBS@ \
    101     @DBUS_GLIB_LIBS@ \
    10294    @LIBCURL_LIBS@ \
    10395    @OPENSSL_LIBS@ \
     
    118110    $(DESKTOP_IN_FILES) \
    119111    marshal.list \
    120     tr-core-dbus.xml \
    121112    transmission.png
    122113
    123114DISTCLEANFILES = \
    124115    transmission-gtk.desktop
    125 
    126 CLEANFILES = $(dbus_generated_sources)
    127 
    128 $(srcdir)/tr-core.c: tr-core-dbus.h
    129 
    130 tr-core-dbus.h: $(srcdir)/tr-core-dbus.xml
    131         $(DBUS_BINDING_TOOL) --mode=glib-server --prefix=gtr_core $< > $(@F)
    132116
    133117if WIN32
     
    139123        setransmission.res
    140124
    141 CLEANFILES += \
     125CLEANFILES = \
    142126        transmission.res
    143127
  • trunk/gtk/actions.c

    r12611 r12638  
    133133    { "queue-move-up", GTK_STOCK_GO_UP, N_( "Move _Up" ), NULL, NULL, G_CALLBACK( action_cb ) },
    134134    { "queue-move-down", GTK_STOCK_GO_DOWN, N_( "Move _Down" ), NULL, NULL, G_CALLBACK( action_cb ) },
    135     { "queue-move-bottom", GTK_STOCK_GOTO_BOTTOM, N_( "Move to _Bottom" ), NULL, NULL, G_CALLBACK( action_cb ) }
     135    { "queue-move-bottom", GTK_STOCK_GOTO_BOTTOM, N_( "Move to _Bottom" ), NULL, NULL, G_CALLBACK( action_cb ) },
     136    { "present-main-window", NULL, N_( "Present Main Window" ), NULL, NULL, G_CALLBACK( action_cb ) }
    136137};
    137138
  • trunk/gtk/conf.c

    r12578 r12638  
    5656    gl_confdir = g_strdup( configDir );
    5757
    58     if( gtr_mkdir_with_parents( gl_confdir, 0755 ) )
     58    if( g_mkdir_with_parents( gl_confdir, 0755 ) )
    5959        return TRUE;
    6060
     
    153153    cf_check_older_configs( );
    154154
    155 #ifdef HAVE_GIO
    156155    str = NULL;
    157156    if( !str ) str = g_get_user_special_dir( G_USER_DIRECTORY_DOWNLOAD );
     
    160159    tr_bencDictAddStr ( d, PREF_KEY_DIR_WATCH, str );
    161160    tr_bencDictAddBool( d, PREF_KEY_DIR_WATCH_ENABLED, FALSE );
    162 #endif
    163161
    164162    tr_bencDictAddBool( d, PREF_KEY_USER_HAS_GIVEN_INFORMED_CONSENT, FALSE );
     
    192190    tr_bencDictAddInt( d, PREF_KEY_MAIN_WINDOW_Y, 50 );
    193191
    194     str = NULL;
    195 #if GLIB_CHECK_VERSION( 2, 14, 0 )
    196     if( !str ) str = g_get_user_special_dir( G_USER_DIRECTORY_DOWNLOAD );
    197 #endif
    198     if( !str ) str = tr_getDefaultDownloadDir( );
     192    str = g_get_user_special_dir( G_USER_DIRECTORY_DOWNLOAD );
    199193    tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR, str );
    200194
  • trunk/gtk/favicon.c

    r12306 r12638  
    1818
    1919#include "favicon.h"
    20 #include "util.h" /* gtr_mkdir_with_parents(), gtr_idle_add() */
     20#include "util.h" /* gtr_idle_add() */
    2121
    2222#define IMAGE_TYPES 4
     
    5151                                "favicons",
    5252                                NULL );
    53         gtr_mkdir_with_parents( dir, 0777 );
     53        g_mkdir_with_parents( dir, 0777 );
    5454    }
    5555
  • trunk/gtk/icons.c

    r11709 r12638  
    1212#include "icons.h"
    1313
    14 #ifdef HAVE_GIO
    15  #if GTK_CHECK_VERSION( 2, 12, 0 )
    16    #define USE_GIO_ICONS
    17  #endif
     14#if GTK_CHECK_VERSION( 2, 12, 0 )
     15 #define USE_GIO_ICONS
    1816#endif
    1917
  • trunk/gtk/main.c

    r12611 r12638  
    3636#include <glib/gi18n.h>
    3737#include <glib/gstdio.h>
    38 #ifdef HAVE_GIO
    39  #include <gio/gio.h>
    40 #endif
     38#include <gio/gio.h>
    4139#include <gtk/gtk.h>
    4240
     
    377375register_magnet_link_handler( void )
    378376{
    379 #ifdef HAVE_GIO
    380377    GAppInfo * app_info = g_app_info_get_default_for_uri_scheme( "magnet" );
    381378    if( app_info == NULL )
     
    391388        }
    392389    }
    393 #endif
    394390}
    395391
     
    748744        /* ensure the directories are created */
    749745        if(( str = gtr_pref_string_get( TR_PREFS_KEY_DOWNLOAD_DIR )))
    750             gtr_mkdir_with_parents( str, 0777 );
     746            g_mkdir_with_parents( str, 0777 );
    751747        if(( str = gtr_pref_string_get( TR_PREFS_KEY_INCOMPLETE_DIR )))
    752             gtr_mkdir_with_parents( str, 0777 );
     748            g_mkdir_with_parents( str, 0777 );
    753749
    754750        /* initialize the libtransmission session */
     
    884880
    885881static void
     882presentMainWindow( struct cbdata * cbdata )
     883{
     884    GtkWindow * window = cbdata->wind;
     885
     886    if( cbdata->is_iconified )
     887    {
     888        cbdata->is_iconified = false;
     889
     890        gtk_window_set_skip_taskbar_hint( window, FALSE );
     891    }
     892
     893    if( !gtk_widget_get_visible( GTK_WIDGET( window ) ) )
     894    {
     895        gtk_window_resize( window, gtr_pref_int_get( PREF_KEY_MAIN_WINDOW_WIDTH ),
     896                                   gtr_pref_int_get( PREF_KEY_MAIN_WINDOW_HEIGHT ) );
     897        gtk_window_move( window, gtr_pref_int_get( PREF_KEY_MAIN_WINDOW_X ),
     898                                 gtr_pref_int_get( PREF_KEY_MAIN_WINDOW_Y ) );
     899        gtr_widget_set_visible( GTK_WIDGET( window ), TRUE );
     900    }
     901    gtr_window_present( window );
     902}
     903
     904static void
     905hideMainWindow( struct cbdata * cbdata )
     906{
     907    GtkWindow * window = cbdata->wind;
     908    gtk_window_set_skip_taskbar_hint( window, TRUE );
     909    gtr_widget_set_visible( GTK_WIDGET( window ), FALSE );
     910    cbdata->is_iconified = true;
     911}
     912
     913static void
    886914toggleMainWindow( struct cbdata * cbdata )
    887915{
    888     GtkWindow * window = cbdata->wind;
    889     const int   doShow = cbdata->is_iconified;
    890     static int  x = 0;
    891     static int  y = 0;
    892 
    893     if( doShow )
    894     {
    895         cbdata->is_iconified = 0;
    896         gtk_window_set_skip_taskbar_hint( window, FALSE );
    897         gtk_window_move( window, x, y );
    898         gtr_widget_set_visible( GTK_WIDGET( window ), TRUE );
    899         gtr_window_present( window );
    900     }
     916    if( cbdata->is_iconified )
     917        presentMainWindow( cbdata );
    901918    else
    902     {
    903         gtk_window_get_position( window, &x, &y );
    904         gtk_window_set_skip_taskbar_hint( window, TRUE );
    905         gtr_widget_set_visible( GTK_WIDGET( window ), FALSE );
    906         cbdata->is_iconified = 1;
    907     }
     919        hideMainWindow( cbdata );
    908920}
    909921
     
    17611773        toggleMainWindow( data );
    17621774    }
     1775    else if( !strcmp( action_name, "present-main-window" ) )
     1776    {
     1777        presentMainWindow( data );
     1778    }
    17631779    else g_error ( "Unhandled action: %s", action_name );
    17641780
  • trunk/gtk/makemeta-ui.c

    r12412 r12638  
    368368getDefaultSavePath( void )
    369369{
    370     const char * path;
    371 #if GLIB_CHECK_VERSION( 2,14,0 )
    372     path = g_get_user_special_dir( G_USER_DIRECTORY_DESKTOP );
    373 #else
    374     path = g_get_home_dir( );
    375 #endif
    376     return path;
     370    return g_get_user_special_dir( G_USER_DIRECTORY_DESKTOP );
    377371}
    378372
  • trunk/gtk/torrent-cell-renderer.c

    r12611 r12638  
    982982    p->progress_renderer = gtk_cell_renderer_progress_new(  );
    983983    p->icon_renderer = gtk_cell_renderer_pixbuf_new(  );
    984     gtr_object_ref_sink( p->text_renderer );
    985     gtr_object_ref_sink( p->progress_renderer );
    986     gtr_object_ref_sink( p->icon_renderer );
     984    g_object_ref_sink( p->text_renderer );
     985    g_object_ref_sink( p->progress_renderer );
     986    g_object_ref_sink( p->icon_renderer );
    987987
    988988    p->bar_height = DEFAULT_BAR_HEIGHT;
  • trunk/gtk/tr-core.c

    r12611 r12638  
    2828#include <gtk/gtk.h>
    2929#include <glib/gi18n.h>
    30 #ifdef HAVE_GIO
    31  #include <gio/gio.h>
    32 #endif
    33 #ifdef HAVE_DBUS_GLIB
    34  #include <dbus/dbus-glib.h>
    35 #endif
     30#include <gio/gio.h>
    3631
    3732#include <event2/buffer.h>
     
    4742#include "notify.h"
    4843#include "tr-core.h"
    49 #ifdef HAVE_DBUS_GLIB
    50  #include "tr-core-dbus.h"
    51 #endif
    5244#include "tr-prefs.h"
    5345#include "util.h"
     
    7466static void core_maybe_inhibit_hibernation( TrCore * core );
    7567
    76 static gboolean our_instance_adds_remote_torrents = FALSE;
    77 
    7868struct TrCorePrivate
    7969{
    80 #ifdef HAVE_GIO
    8170    GFileMonitor * monitor;
    8271    gulong         monitor_tag;
     
    8473    GSList       * monitor_files;
    8574    guint          monitor_idle_tag;
    86 #endif
     75
    8776    gboolean       adding_from_watch_dir;
    8877    gboolean       inhibit_allowed;
     
    9079    gboolean       dbus_error;
    9180    guint          inhibit_cookie;
     81    guint          dbus_session_owner_id;
     82    guint          dbus_display_owner_id;
    9283    gint           busy_count;
    9384    GtkTreeModel * raw_model;
     
    200191        G_TYPE_NONE,
    201192        1, G_TYPE_STRING );
    202 
    203 #ifdef HAVE_DBUS_GLIB
    204     {
    205         DBusGConnection * bus = dbus_g_bus_get( DBUS_BUS_SESSION, NULL );
    206         DBusGProxy *      bus_proxy = NULL;
    207         if( bus )
    208             bus_proxy =
    209                 dbus_g_proxy_new_for_name( bus, "org.freedesktop.DBus",
    210                                            "/org/freedesktop/DBus",
    211                                            "org.freedesktop.DBus" );
    212         if( bus_proxy )
     193}
     194
     195static void
     196handle_dbus_method( GDBusConnection       * connection UNUSED,
     197                    const gchar           * sender UNUSED,
     198                    const gchar           * object_path,
     199                    const gchar           * interface_name,
     200                    const gchar           * method_name,
     201                    GVariant              * parameters,
     202                    GDBusMethodInvocation * invocation,
     203                    gpointer                core )
     204{
     205    gboolean handled = false;
     206
     207    if( !g_strcmp0( interface_name, TR_DBUS_SESSION_INTERFACE ) )
     208    {
     209        if( !g_strcmp0( method_name, "TorrentAdd" ) )
    213210        {
    214             int result = 0;
    215             dbus_g_proxy_call( bus_proxy, "RequestName", NULL,
    216                                G_TYPE_STRING,
    217                                "com.transmissionbt.Transmission",
    218                                G_TYPE_UINT, 0,
    219                                G_TYPE_INVALID,
    220                                G_TYPE_UINT, &result,
    221                                G_TYPE_INVALID );
    222             if( ( our_instance_adds_remote_torrents = result == 1 ) )
    223                 dbus_g_object_type_install_info(
    224                     TR_CORE_TYPE,
    225                     &dbus_glib_gtr_core_object_info );
     211            GVariant * args = g_variant_get_child_value( parameters, 0 );
     212            GVariant * filename_variant = g_variant_lookup_value ( args, "filename", G_VARIANT_TYPE_STRING );
     213            char * filename = g_variant_dup_string( filename_variant, NULL );
     214            GSList * files = g_slist_append( NULL, filename );
     215            gtr_core_add_list_defaults( TR_CORE( core ), files, TRUE );
     216            g_dbus_method_invocation_return_value( invocation, g_variant_new( "(b)", true ) );
     217            handled = true;
    226218        }
    227219    }
    228 #endif
     220    else if( !g_strcmp0( interface_name, TR_DBUS_DISPLAY_INTERFACE ) )
     221    {
     222        if( !g_strcmp0( method_name, "PresentWindow" ) )
     223        {
     224            gtr_action_activate( "present-main-window" );
     225            g_dbus_method_invocation_return_value( invocation, NULL );
     226            handled = true;
     227        }
     228    }
     229
     230    if( !handled )
     231        g_warning( "Unhandled method call:\n\tObject Path: %s\n\tInterface Name: %s\n\tMethod Name: %s",
     232                   object_path, interface_name, method_name );
     233};
     234
     235static void
     236on_session_registered_in_dbus( GDBusConnection *connection, const gchar *name UNUSED, gpointer core )
     237{
     238    GError * err = NULL;
     239    GDBusNodeInfo * node_info;
     240    GDBusInterfaceVTable vtable;
     241    const char * interface_xml = "<node>"
     242                                 "  <interface name='" TR_DBUS_SESSION_INTERFACE "'>"
     243                                 "    <method name='TorrentAdd'>"
     244                                 "      <arg type='a{sv}' name='args' direction='in'/>"
     245                                 "      <arg type='b' name='response' direction='out'/>"
     246                                 "    </method>"
     247                                 "  </interface>"
     248                                 "</node>";
     249
     250    node_info = g_dbus_node_info_new_for_xml( interface_xml, &err );
     251
     252    vtable.method_call = handle_dbus_method;
     253    vtable.get_property = NULL;
     254    vtable.set_property = NULL;
     255
     256    g_dbus_connection_register_object ( connection,
     257                                        TR_DBUS_SESSION_OBJECT_PATH,
     258                                        node_info->interfaces[0],
     259                                        &vtable,
     260                                        core,
     261                                        NULL,
     262                                        &err );
     263
     264    if( err != NULL ) {
     265        g_warning( "%s:%d Error registering object: %s", __FILE__, __LINE__, err->message );
     266        g_error_free( err );
     267    }
     268}
     269
     270static void
     271on_display_registered_in_dbus( GDBusConnection *connection, const gchar *name UNUSED, gpointer core )
     272{
     273    GError * err = NULL;
     274    const char * interface_xml = "<node>"
     275                                 "  <interface name='" TR_DBUS_DISPLAY_INTERFACE "'>"
     276                                 "    <method name='PresentWindow'>"
     277                                 "    </method>"
     278                                 "  </interface>"
     279                                 "</node>";
     280    GDBusInterfaceVTable vtable = { .method_call=handle_dbus_method };
     281    GDBusNodeInfo * node_info = g_dbus_node_info_new_for_xml( interface_xml, &err );
     282
     283    g_dbus_connection_register_object ( connection,
     284                                        TR_DBUS_DISPLAY_OBJECT_PATH,
     285                                        node_info->interfaces[0],
     286                                        &vtable,
     287                                        core,
     288                                        NULL,
     289                                        &err );
     290
     291    if( err != NULL ) {
     292        g_warning( "%s:%d Error registering object: %s", __FILE__, __LINE__, err->message );
     293        g_error_free( err );
     294    }
    229295}
    230296
     
    266332    g_object_unref( p->raw_model );
    267333
    268 #ifdef HAVE_DBUS_GLIB
    269     if( our_instance_adds_remote_torrents )
    270     {
    271         DBusGConnection * bus = dbus_g_bus_get( DBUS_BUS_SESSION, NULL );
    272         if( bus )
    273             dbus_g_connection_register_g_object(
    274                  bus,
    275                 "/com/transmissionbt/Transmission",
    276                 G_OBJECT( self ) );
    277     }
    278 #endif
     334    p->dbus_session_owner_id = g_bus_own_name( G_BUS_TYPE_SESSION,
     335                                               TR_DBUS_SESSION_SERVICE_NAME,
     336                                               G_BUS_NAME_OWNER_FLAGS_NONE,
     337                                               NULL,
     338                                               on_session_registered_in_dbus,
     339                                               NULL,
     340                                               self,
     341                                               NULL );
     342
     343    p->dbus_display_owner_id = g_bus_own_name( G_BUS_TYPE_SESSION,
     344                                               TR_DBUS_DISPLAY_SERVICE_NAME,
     345                                               G_BUS_NAME_OWNER_FLAGS_NONE,
     346                                               NULL,
     347                                               on_display_registered_in_dbus,
     348                                               NULL,
     349                                               self,
     350                                               NULL );
    279351}
    280352
     
    634706***/
    635707
    636 #ifdef HAVE_GIO
    637 
    638708struct watchdir_file
    639709{
     
    804874}
    805875
    806 #endif
    807 
    808876/***
    809877****
     
    834902        core_maybe_inhibit_hibernation( core );
    835903    }
    836 #ifdef HAVE_GIO
    837904    else if( !strcmp( key, PREF_KEY_DIR_WATCH )
    838905           || !strcmp( key, PREF_KEY_DIR_WATCH_ENABLED ) )
     
    840907        core_watchdir_update( core );
    841908    }
    842 #endif
    843909}
    844910
     
    876942        tr_sessionClose( session );
    877943    }
     944
     945    g_bus_unown_name( core->priv->dbus_display_owner_id );
     946    g_bus_unown_name( core->priv->dbus_session_owner_id );
    878947}
    879948
     
    11471216    core_apply_defaults( ctor );
    11481217    core_add_ctor( core, ctor, do_prompt, do_notify );
    1149 }
    1150 
    1151 /* invoked remotely via dbus. */
    1152 gboolean
    1153 gtr_core_add_metainfo( TrCore      * core,
    1154                        const char  * payload,
    1155                        gboolean    * setme_handled,
    1156                        GError     ** gerr UNUSED )
    1157 {
    1158     tr_session * session = gtr_core_session( core );
    1159 
    1160     if( !session )
    1161     {
    1162         *setme_handled = FALSE;
    1163     }
    1164     else if( gtr_is_supported_url( payload ) || gtr_is_magnet_link( payload ) )
    1165     {
    1166         gtr_core_add_from_url( core, payload );
    1167         *setme_handled = TRUE;
    1168     }
    1169     else /* base64-encoded metainfo */
    1170     {
    1171         int file_length;
    1172         tr_ctor * ctor;
    1173         char * file_contents;
    1174         gboolean do_prompt = gtr_pref_flag_get( PREF_KEY_OPTIONS_PROMPT );
    1175 
    1176         ctor = tr_ctorNew( session );
    1177         core_apply_defaults( ctor );
    1178 
    1179         file_contents = tr_base64_decode( payload, -1, &file_length );
    1180         tr_ctorSetMetainfo( ctor, (const uint8_t*)file_contents, file_length );
    1181         core_add_ctor( core, ctor, do_prompt, TRUE );
    1182 
    1183         tr_free( file_contents );
    1184         gtr_core_torrents_added( core );
    1185         *setme_handled = TRUE;
    1186     }
    1187 
    1188     return TRUE;
    11891218}
    11901219
     
    15221551**/
    15231552
    1524 #ifdef HAVE_DBUS_GLIB
    1525 
    1526 static DBusGProxy*
    1527 get_hibernation_inhibit_proxy( void )
    1528 {
    1529     GError * error = NULL;
    1530     const char * name = "org.gnome.SessionManager";
    1531     const char * path = "/org/gnome/SessionManager";
    1532     const char * interface = "org.gnome.SessionManager";
    1533     DBusGConnection * conn = dbus_g_bus_get( DBUS_BUS_SESSION, &error );
    1534 
    1535     if( error )
    1536     {
    1537         g_warning ( "DBUS cannot connect : %s", error->message );
    1538         g_error_free ( error );
    1539         return NULL;
    1540     }
    1541 
    1542     return dbus_g_proxy_new_for_name ( conn, name, path, interface );
    1543 }
     1553#define SESSION_MANAGER_SERVICE_NAME  "org.gnome.SessionManager"
     1554#define SESSION_MANAGER_INTERFACE     "org.gnome.SessionManager"
     1555#define SESSION_MANAGER_OBJECT_PATH   "/org/gnome/SessionManager"
    15441556
    15451557static gboolean
    15461558gtr_inhibit_hibernation( guint * cookie )
    15471559{
    1548     gboolean success = FALSE;
    1549     DBusGProxy * proxy = get_hibernation_inhibit_proxy( );
    1550 
    1551     if( proxy )
    1552     {
    1553         GError * error = NULL;
    1554         const int toplevel_xid = 0;
    1555         const char * application = _( "Transmission Bittorrent Client" );
    1556         const char * reason = _( "BitTorrent Activity" );
    1557         const int flags = 4; /* Inhibit suspending the session or computer */
    1558 
    1559         success = dbus_g_proxy_call( proxy, "Inhibit", &error,
    1560                                      G_TYPE_STRING, application,
    1561                                      G_TYPE_UINT, toplevel_xid,
    1562                                      G_TYPE_STRING, reason,
    1563                                      G_TYPE_UINT, flags,
    1564                                      G_TYPE_INVALID, /* sentinel - end of input args */
    1565                                      G_TYPE_UINT, cookie,
    1566                                      G_TYPE_INVALID /* senitnel - end of output args */ );
    1567 
    1568         if( success )
    1569             tr_inf( "%s", _( "Disallowing desktop hibernation" ) );
    1570         else
    1571         {
    1572             tr_err( _( "Couldn't disable desktop hibernation: %s" ),
    1573                     error->message );
    1574             g_error_free( error );
    1575         }
    1576 
    1577         g_object_unref( G_OBJECT( proxy ) );
    1578     }
    1579 
    1580     return success != 0;
     1560    gboolean success;
     1561    GVariant * response;
     1562    GDBusConnection * connection;
     1563    GError * err = NULL;
     1564    const char * application = "Transmission BitTorrent Client";
     1565    const char * reason = "BitTorrent Activity";
     1566    const int toplevel_xid = 0;
     1567    const int flags = 4; /* Inhibit suspending the session or computer */
     1568
     1569    connection = g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, &err );
     1570
     1571    response = g_dbus_connection_call_sync( connection,
     1572                                            SESSION_MANAGER_SERVICE_NAME,
     1573                                            SESSION_MANAGER_OBJECT_PATH,
     1574                                            SESSION_MANAGER_INTERFACE,
     1575                                            "Inhibit",
     1576                                            g_variant_new( "(susu)", application, toplevel_xid, reason, flags ),
     1577                                            NULL, G_DBUS_CALL_FLAGS_NONE,
     1578                                            1000, NULL, &err );
     1579
     1580    *cookie = g_variant_get_uint32( g_variant_get_child_value( response, 0 ) );
     1581
     1582    success = err == NULL;
     1583
     1584    /* logging */
     1585    if( success )
     1586        tr_inf( "%s", _( "Inhibiting desktop hibernation" ) );
     1587    else {
     1588        tr_err( _( "Couldn't inhibit desktop hibernation: %s" ), err->message );
     1589        g_error_free( err );
     1590    }
     1591
     1592    /* cleanup */
     1593    g_variant_unref( response );
     1594    g_object_unref( connection );
     1595    return success;
    15811596}
    15821597
     
    15841599gtr_uninhibit_hibernation( guint inhibit_cookie )
    15851600{
    1586     DBusGProxy * proxy = get_hibernation_inhibit_proxy( );
    1587 
    1588     if( proxy )
    1589     {
    1590         GError * error = NULL;
    1591         gboolean success = dbus_g_proxy_call( proxy, "Uninhibit", &error,
    1592                                               G_TYPE_UINT, inhibit_cookie,
    1593                                               G_TYPE_INVALID,
    1594                                               G_TYPE_INVALID );
    1595         if( success )
    1596             tr_inf( "%s", _( "Allowing desktop hibernation" ) );
    1597         else
    1598         {
    1599             g_warning( "Couldn't uninhibit the system from suspending: %s.",
    1600                        error->message );
    1601             g_error_free( error );
    1602         }
    1603 
    1604         g_object_unref( G_OBJECT( proxy ) );
    1605     }
    1606 }
    1607 
    1608 #endif
     1601    GVariant * response;
     1602    GDBusConnection * connection;
     1603    GError * err = NULL;
     1604
     1605    connection = g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, &err );
     1606
     1607    response = g_dbus_connection_call_sync( connection,
     1608                                            SESSION_MANAGER_SERVICE_NAME,
     1609                                            SESSION_MANAGER_OBJECT_PATH,
     1610                                            SESSION_MANAGER_INTERFACE,
     1611                                            "Uninhibit",
     1612                                            g_variant_new( "(u)", inhibit_cookie ),
     1613                                            NULL, G_DBUS_CALL_FLAGS_NONE,
     1614                                            1000, NULL, &err );
     1615
     1616    /* logging */
     1617    if( err == NULL )
     1618        tr_inf( "%s", _( "Allowing desktop hibernation" ) );
     1619    else {
     1620        g_warning( "Couldn't uninhibit desktop hibernation: %s.", err->message );
     1621        g_error_free( err );
     1622    }
     1623
     1624    /* cleanup */
     1625    g_variant_unref( response );
     1626    g_object_unref( connection );
     1627}
    16091628
    16101629static void
    16111630gtr_core_set_hibernation_allowed( TrCore * core, gboolean allowed )
    16121631{
    1613 #ifdef HAVE_DBUS_GLIB
    16141632    g_return_if_fail( core );
    16151633    g_return_if_fail( core->priv );
     
    16321650            core->priv->dbus_error = TRUE;
    16331651    }
    1634 #endif
    16351652}
    16361653
     
    19191936    }
    19201937}
    1921 
    1922 gboolean
    1923 gtr_core_present_window( TrCore      * core UNUSED,
    1924                          gboolean    * success,
    1925                          GError     ** err  UNUSED )
    1926 {
    1927     /* Setting the toggle-main-window GtkCheckMenuItem to
    1928        make sure its state is correctly set */
    1929     gtr_action_set_toggled( "toggle-main-window", TRUE);
    1930 
    1931     *success = TRUE;
    1932     return TRUE;
    1933 }
  • trunk/gtk/tr-core.h

    r12607 r12638  
    117117                                 gboolean    do_notify );
    118118
    119 /** @brief Add a torrent. */
    120 gboolean gtr_core_add_metainfo( TrCore      * core,
    121                                 const char  * base64_metainfo,
    122                                 gboolean    * setme_success,
    123                                 GError     ** err );
    124119
    125120/** @brief Add a torrent from a URL */
     
    132127/** Add a torrent. */
    133128void gtr_core_add_torrent( TrCore*, tr_torrent*, gboolean do_notify );
    134 
    135 /** Present the main window */
    136 gboolean gtr_core_present_window( TrCore*, gboolean * setme_success, GError ** err );
    137129
    138130/**
     
    208200};
    209201
     202
     203#define TR_DBUS_SESSION_SERVICE_NAME  "com.transmissionbt.transmission.Session"
     204#define TR_DBUS_SESSION_INTERFACE     "com.transmissionbt.transmission.Session"
     205#define TR_DBUS_SESSION_OBJECT_PATH   "/com/transmissionbt/transmission/Session"
     206
     207#define TR_DBUS_DISPLAY_SERVICE_NAME  "com.transmissionbt.transmission.Display"
     208#define TR_DBUS_DISPLAY_INTERFACE     "com.transmissionbt.transmission.Display"
     209#define TR_DBUS_DISPLAY_OBJECT_PATH   "/com/transmissionbt/transmission/Display"
     210
     211
    210212#endif /* GTR_CORE_H */
  • trunk/gtk/tr-prefs.c

    r12636 r12638  
    338338    hig_workarea_add_wide_control( t, &row, w );
    339339
    340 #ifdef HAVE_GIO
    341340    s = _( "Automatically _add torrents from:" );
    342341    l = new_check_button( s, PREF_KEY_DIR_WATCH_ENABLED, core );
    343342    w = new_path_chooser_button( PREF_KEY_DIR_WATCH, core );
    344     gtk_widget_set_sensitive( GTK_WIDGET( w ),
    345                              gtr_pref_flag_get( PREF_KEY_DIR_WATCH_ENABLED ) );
     343    gtk_widget_set_sensitive( GTK_WIDGET( w ), gtr_pref_flag_get( PREF_KEY_DIR_WATCH_ENABLED ) );
    346344    g_signal_connect( l, "toggled", G_CALLBACK( target_cb ), w );
    347345    hig_workarea_add_row_w( t, &row, l, w, NULL );
    348 #endif
    349346
    350347    hig_workarea_add_section_divider( t, &row );
  • trunk/gtk/util.c

    r12592 r12638  
    2323#include <glib/gi18n.h>
    2424#include <glib/gstdio.h> /* g_unlink() */
    25 #ifdef HAVE_GIO
    26  #include <gio/gio.h> /* g_file_trash() */
    27 #endif
    28 #ifdef HAVE_DBUS_GLIB
    29  #include <dbus/dbus-glib.h>
    30 #endif
     25#include <gio/gio.h> /* g_file_trash() */
    3126
    3227#include <libtransmission/transmission.h> /* TR_RATIO_NA, TR_RATIO_INF */
     
    3631
    3732#include "hig.h"
     33#include "tr-core.h" /* dbus names */
    3834#include "util.h"
    3935
     
    195191}
    196192
    197 int
    198 gtr_mkdir_with_parents( const char * path, int mode )
    199 {
    200 #if GLIB_CHECK_VERSION( 2, 8, 0 )
    201     return !g_mkdir_with_parents( path, mode );
    202 #else
    203     return !tr_mkdirp( path, mode );
    204 #endif
    205 }
    206 
    207193/* pattern-matching text; ie, legaltorrents.com */
    208194void
     
    362348}
    363349
    364 gpointer
    365 gtr_object_ref_sink( gpointer object )
    366 {
    367 #if GLIB_CHECK_VERSION( 2, 10, 0 )
    368     g_object_ref_sink( object );
    369 #else
    370     g_object_ref( object );
    371     gtk_object_sink( GTK_OBJECT( object ) );
    372 #endif
    373     return object;
    374 }
    375 
    376350int
    377351gtr_file_trash_or_remove( const char * filename )
     
    380354    {
    381355        gboolean trashed = FALSE;
    382 #ifdef HAVE_GIO
    383356        GError * err = NULL;
    384357        GFile *  file = g_file_new_for_path( filename );
     
    388361        g_clear_error( &err );
    389362        g_object_unref( G_OBJECT( file ) );
    390 #endif
    391363
    392364        if( !trashed && g_remove( filename ) )
     
    421393    char * uri = NULL;
    422394
    423 #ifdef HAVE_GIO
    424395    GFile * file = g_file_new_for_path( path );
    425396    uri = g_file_get_uri( file );
    426397    g_object_unref( G_OBJECT( file ) );
    427 #else
     398
    428399    if( g_path_is_absolute( path ) )
    429400        uri = g_strdup_printf( "file://%s", path );
     
    433404        g_free( cwd );
    434405    }
    435 #endif
    436406
    437407    gtr_open_uri( uri );
     
    451421#endif
    452422
    453 #ifdef HAVE_GIO
    454423        if( !opened )
    455424            opened = g_app_info_launch_default_for_uri( uri, NULL, NULL );
    456 #endif
    457425
    458426        if( !opened ) {
     
    467435}
    468436
    469 #define VALUE_SERVICE_NAME        "com.transmissionbt.Transmission"
    470 #define VALUE_SERVICE_OBJECT_PATH "/com/transmissionbt/Transmission"
    471 #define VALUE_SERVICE_INTERFACE   "com.transmissionbt.Transmission"
    472 
    473437gboolean
    474438gtr_dbus_add_torrent( const char * filename )
    475439{
    476     /* FIXME: why is this static? */
    477     static gboolean handled = FALSE;
    478 
    479 #ifdef HAVE_DBUS_GLIB
    480     char * payload;
    481     gsize file_length;
    482     char * file_contents = NULL;
    483 
    484     /* If it's a file, load its contents and send them over the wire...
    485      * it might be a temporary file that's going to disappear. */
    486     if( g_file_get_contents( filename, &file_contents, &file_length, NULL ) )
    487         payload = tr_base64_encode( file_contents, file_length, NULL );
    488     else if( gtr_is_supported_url( filename ) || gtr_is_magnet_link( filename ) )
    489         payload = tr_strdup( filename );
    490     else
    491         payload = NULL;
    492 
    493     if( payload != NULL )
    494     {
    495         GError * err = NULL;
    496         DBusGConnection * conn;
    497         DBusGProxy * proxy = NULL;
    498 
    499         if(( conn = dbus_g_bus_get( DBUS_BUS_SESSION, &err )))
    500             proxy = dbus_g_proxy_new_for_name (conn, VALUE_SERVICE_NAME,
    501                                                      VALUE_SERVICE_OBJECT_PATH,
    502                                                      VALUE_SERVICE_INTERFACE );
    503         else if( err )
    504            g_message( "err: %s", err->message );
    505 
    506         if( proxy )
    507             dbus_g_proxy_call( proxy, "AddMetainfo", &err,
    508                                G_TYPE_STRING, payload,
    509                                G_TYPE_INVALID,
    510                                G_TYPE_BOOLEAN, &handled,
    511                                G_TYPE_INVALID );
    512         if( err )
    513            g_message( "err: %s", err->message );
    514 
    515         if( proxy )
    516             g_object_unref( proxy );
    517         if( conn )
    518             dbus_g_connection_unref( conn );
    519 
    520         tr_free( payload );
    521     }
    522 
    523     g_free( file_contents );
    524 
    525 #endif
     440    GVariant * response;
     441    GVariant * args;
     442    GVariant * parameters;
     443    GVariantBuilder * builder;
     444    GDBusConnection * connection;
     445    GError * err = NULL;
     446    gboolean handled = FALSE;
     447
     448    /* "args" is a dict as described in the RPC spec's "torrent-add" section */
     449    builder = g_variant_builder_new( G_VARIANT_TYPE( "a{sv}" ) );
     450    g_variant_builder_add( builder, "{sv}", "filename", g_variant_new_string( filename ) );
     451    args = g_variant_builder_end( builder );
     452    parameters = g_variant_new_tuple( &args, 1 );
     453    g_variant_builder_unref( builder );
     454
     455    connection = g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, &err );
     456
     457    response = g_dbus_connection_call_sync( connection,
     458                                            TR_DBUS_SESSION_SERVICE_NAME,
     459                                            TR_DBUS_SESSION_OBJECT_PATH,
     460                                            TR_DBUS_SESSION_INTERFACE,
     461                                            "TorrentAdd",
     462                                            parameters,
     463                                            G_VARIANT_TYPE_TUPLE,
     464                                            G_DBUS_CALL_FLAGS_NONE,
     465                                            10000, /* wait 10 sec */
     466                                            NULL,
     467                                            &err );
     468
     469
     470    handled = g_variant_get_boolean( g_variant_get_child_value( response, 0 ) );
     471
     472    g_object_unref( connection );
     473    g_variant_unref( response );
    526474    return handled;
    527475}
     
    530478gtr_dbus_present_window( void )
    531479{
    532     static gboolean   success = FALSE;
    533 
    534 #ifdef HAVE_DBUS_GLIB
    535     DBusGProxy *      proxy = NULL;
    536     GError *          err = NULL;
    537     DBusGConnection * conn;
    538     if( ( conn = dbus_g_bus_get( DBUS_BUS_SESSION, &err ) ) )
    539         proxy = dbus_g_proxy_new_for_name ( conn, VALUE_SERVICE_NAME,
    540                                             VALUE_SERVICE_OBJECT_PATH,
    541                                             VALUE_SERVICE_INTERFACE );
    542     else if( err )
    543         g_message( "err: %s", err->message );
    544     if( proxy )
    545         dbus_g_proxy_call( proxy, "PresentWindow", &err,
    546                            G_TYPE_INVALID,
    547                            G_TYPE_BOOLEAN, &success,
    548                            G_TYPE_INVALID );
    549     if( err )
    550         g_message( "err: %s", err->message );
    551 
    552     g_object_unref( proxy );
    553     dbus_g_connection_unref( conn );
    554 #endif
     480    gboolean success;
     481    GDBusConnection * connection;
     482    GError * err = NULL;
     483
     484    connection = g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, &err );
     485
     486    g_dbus_connection_call_sync( connection,
     487                                 TR_DBUS_DISPLAY_SERVICE_NAME,
     488                                 TR_DBUS_DISPLAY_OBJECT_PATH,
     489                                 TR_DBUS_DISPLAY_INTERFACE,
     490                                 "PresentWindow",
     491                                 NULL,
     492                                 NULL, G_DBUS_CALL_FLAGS_NONE,
     493                                 1000, NULL, &err );
     494
     495    success = err == NULL;
     496
     497    /* cleanup */
     498    if( err != NULL )
     499        g_error_free( err );
     500    g_object_unref( connection );
    555501    return success;
    556502}
  • trunk/gtk/util.h

    r12412 r12638  
    109109***/
    110110
    111 /* backwards-compatible wrapper around g_mkdir_with_parents() */
    112 int gtr_mkdir_with_parents( const char *name, int mode );
    113 
    114111/* backwards-compatible wrapper around gdk_threads_add_timeout_seconds() */
    115112guint gtr_timeout_add_seconds( guint seconds, GSourceFunc func, gpointer data );
     
    129126/* backwards-compatible wrapper around gtk_widget_set_visible() */
    130127void gtr_widget_set_visible( GtkWidget *, gboolean );
    131 
    132 /* backwards-compatible wrapper around g_object_ref_sink() */
    133 gpointer gtr_object_ref_sink( gpointer object );
    134128
    135129void gtr_dialog_set_content( GtkDialog * dialog, GtkWidget * content );
  • trunk/transmission-gtk.spec.in

    r12578 r12638  
    2727Requires: glib2 >= @GLIB_MINIMUM@
    2828Requires: gtk2 >= @GTK_MINIMUM@
    29 # OPTIONAL for the gtk+ client... see configure.ac for details
    30 BuildRequires: dbus-glib-devel >= @DBUS_GLIB_MINIMUM@
    31 Requires: dbus-glib >= @DBUS_GLIB_MINIMUM@
    3229
    3330Provides: %{name}
Note: See TracChangeset for help on using the changeset viewer.