~ubuntu-branches/ubuntu/natty/transmission/natty

« back to all changes in this revision

Viewing changes to gtk/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Klimonda
  • Date: 2009-12-08 10:49:11 UTC
  • mfrom: (1.1.29 upstream) (2.1.10 sid)
  • Revision ID: james.westby@ubuntu.com-20091208104911-06gio45n2nla3vpg
Tags: 1.80~b1-0ubuntu1
* New upstream release (LP: #460620), rebased on debian unstable
  remaining changes:
  - debian/control:
    + Added replaces & provides clutch (now included as part of transmission).
      Can be removed in lucid+1
    + Added quilt, liblaunchpad-integration-dev and lsb-release to Build-Depends
  - debian/rules:
    + create a po template during package build.
  - debian/patches/01_lpi.patch:
    + integrate transmission with launchpad
  - debian/patches/20_add_x-ubuntu-gettext-domain.diff:
    + add x-ubuntu-gettext-domain to .desktop file.
  - debian/transmission-daemon.default:
    - remove --auth from OPTIONS
* Fixes bugs:
  - tray menu shows wrong status for "main window" when started minimized
    (LP: #451415)
* Refreshed patches:
  - dont_build_libevent.patch
  - 99_autoreconf.patch
* Removed patches:
  - 21_onPortTested.diff, 23_tr_torrentNext.diff and
    24_tr_torrentDeleteLocalData_do_move.diff
* debian/patches/21_fix_inhibition.patch:
  - The right value for suspend inhibition is 4
* debian/control:
  - Build-Depend on libgconf2-dev to enable magnet link registration and on
    libcanberra-gtk-dev for notification sound.
* debian/watch:
  - make it detect beta versions, to be removed after 1.80 is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * This file Copyright (C) 2008-2009 Charles Kerr <charles@transmissionbt.com>
 
2
 * This file Copyright (C) 2008-2009 Mnemosyne LLC
3
3
 *
4
4
 * This file is licensed by the GPL version 2.  Works owned by the
5
5
 * Transmission project are granted a special exemption to clause 2(b)
7
7
 * This exemption does not extend to derived works not owned by
8
8
 * the Transmission project.
9
9
 *
10
 
 * $Id: util.c 9093 2009-09-10 17:39:44Z charles $
 
10
 * $Id: util.c 9671 2009-12-05 02:19:24Z charles $
11
11
 */
12
12
 
13
13
#include <ctype.h> /* isxdigit() */
322
322
    return ret;
323
323
}
324
324
 
 
325
 
 
326
gboolean
 
327
gtr_is_supported_url( const char * str )
 
328
{
 
329
    return !strncmp( str, "ftp://", 6 )
 
330
        || !strncmp( str, "http://", 7 )
 
331
        || !strncmp( str, "https://", 8 );
 
332
}
 
333
 
 
334
gboolean
 
335
gtr_is_magnet_link( const char * str )
 
336
{
 
337
    return !strncmp( str, "magnet:?", 8 );
 
338
}
 
339
 
 
340
gboolean
 
341
gtr_is_hex_hashcode( const char * str )
 
342
{
 
343
    int i;
 
344
 
 
345
    if( !str || ( strlen( str ) != 40 ) )
 
346
        return FALSE;
 
347
 
 
348
    for( i=0; i<40; ++i )
 
349
        if( !isxdigit( str[i] ) )
 
350
            return FALSE;
 
351
 
 
352
    return TRUE;
 
353
}
 
354
 
325
355
GSList *
326
 
checkfilenames( int    argc,
327
 
                char **argv )
 
356
checkfilenames( int argc, char **argv )
328
357
{
329
 
    int      i;
 
358
    int i;
330
359
    GSList * ret = NULL;
331
 
    char *   pwd = g_get_current_dir( );
 
360
    char * pwd = g_get_current_dir( );
332
361
 
333
 
    for( i = 0; i < argc; ++i )
 
362
    for( i=0; i<argc; ++i )
334
363
    {
335
 
        char * filename = g_path_is_absolute( argv[i] )
336
 
                          ? g_strdup ( argv[i] )
337
 
                          : g_build_filename( pwd, argv[i], NULL );
 
364
        if( gtr_is_supported_url( argv[i] ) || gtr_is_magnet_link( argv[i] ) )
 
365
        {
 
366
            ret = g_slist_prepend( ret, g_strdup( argv[i] ) );
 
367
        }
 
368
        else /* local file */
 
369
        {
 
370
            char * filename = g_path_is_absolute( argv[i] )
 
371
                            ? g_strdup ( argv[i] )
 
372
                            : g_build_filename( pwd, argv[i], NULL );
338
373
 
339
 
        if( g_file_test( filename, G_FILE_TEST_EXISTS ) )
340
 
            ret = g_slist_prepend( ret, filename );
341
 
        else
342
 
            g_free( filename );
 
374
            if( g_file_test( filename, G_FILE_TEST_EXISTS ) )
 
375
                ret = g_slist_prepend( ret, filename );
 
376
            else {
 
377
                if( gtr_is_hex_hashcode( argv[i] ) )
 
378
                    ret = g_slist_prepend( ret, g_strdup_printf( "magnet:?xt=urn:btih:%s", argv[i] ) );
 
379
                g_free( filename );
 
380
            }
 
381
        }
343
382
    }
344
383
 
345
384
    g_free( pwd );
408
447
            gtk_tree_path_free( path );
409
448
        }
410
449
 
411
 
        ( (PopupFunc*)func )( view, event );
 
450
        if( func != NULL )
 
451
            ( (PopupFunc*)func )( view, event );
412
452
 
413
453
        return TRUE;
414
454
    }
509
549
        }
510
550
 
511
551
        if( !opened )
 
552
        {
512
553
            g_message( "Unable to open \"%s\"", path );
 
554
        }
513
555
    }
514
556
}
515
557
 
522
564
{
523
565
    /* FIXME: why is this static? */
524
566
    static gboolean success = FALSE;
 
567
 
525
568
#ifdef HAVE_DBUS_GLIB
526
 
    DBusGProxy * proxy = NULL;
527
 
    GError * err = NULL;
528
 
    DBusGConnection * conn;
529
 
    char * file_contents;
 
569
    char * payload;
530
570
    gsize file_length;
 
571
    char * file_contents = NULL;
531
572
 
 
573
    /* If it's a file, load its contents and send them over the wire...
 
574
     * it might be a temporary file that's going to disappear. */
532
575
    if( g_file_get_contents( filename, &file_contents, &file_length, NULL ) )
 
576
        payload = tr_base64_encode( file_contents, file_length, NULL );
 
577
    else if( gtr_is_supported_url( filename ) || gtr_is_magnet_link( filename ) )
 
578
        payload = tr_strdup( filename );
 
579
    else
 
580
        payload = NULL;
 
581
 
 
582
    if( payload != NULL )
533
583
    {
534
 
        char * b64 = tr_base64_encode( file_contents, file_length, NULL );
 
584
        GError * err = NULL;
 
585
        DBusGConnection * conn;
 
586
        DBusGProxy * proxy = NULL;
 
587
 
535
588
        if(( conn = dbus_g_bus_get( DBUS_BUS_SESSION, &err )))
536
589
            proxy = dbus_g_proxy_new_for_name (conn, VALUE_SERVICE_NAME,
537
590
                                                     VALUE_SERVICE_OBJECT_PATH,
538
591
                                                     VALUE_SERVICE_INTERFACE );
539
592
        else if( err )
540
593
           g_message( "err: %s", err->message );
 
594
 
541
595
        if( proxy )
542
596
            dbus_g_proxy_call( proxy, "AddMetainfo", &err,
543
 
                               G_TYPE_STRING, b64,
 
597
                               G_TYPE_STRING, payload,
544
598
                               G_TYPE_INVALID,
545
599
                               G_TYPE_BOOLEAN, &success,
546
600
                               G_TYPE_INVALID );
552
606
        if( conn )
553
607
            dbus_g_connection_unref( conn );
554
608
 
555
 
        tr_free( b64 );
556
 
        g_free( file_contents );
 
609
        tr_free( payload );
557
610
    }
558
 
    else g_message( "couldn't read %s", filename );
 
611
 
 
612
    g_free( file_contents );
559
613
 
560
614
#endif
561
615
    return success;