Changeset 6559


Ignore:
Timestamp:
Aug 17, 2008, 12:39:26 PM (13 years ago)
Author:
muks
Message:

Don't show an error when transmission is run twice

Instead, present the main window. This commit also auto-generates
the dbus bindings.

Location:
trunk
Files:
1 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r6539 r6559  
    165165    AC_SUBST(DBUS_GLIB_CFLAGS)
    166166    if test "x$use_dbus_glib" = "xyes"; then
     167        AC_PATH_PROG(DBUS_BINDING_TOOL, dbus-binding-tool, no)
     168        if test "x$DBUS_BINDING_TOOL" = xno; then
     169          AC_MSG_WARN([Cannot find dbus-binding-tool])
     170          use_dbus_glib="no (dbus-binding-tool not found)"
     171        fi
     172    fi
     173    if test "x$use_dbus_glib" = "xyes"; then
    167174        AC_DEFINE([HAVE_DBUS_GLIB], 1)
    168175    fi
  • trunk/gtk/Makefile.am

    r6532 r6559  
    5050bin_PROGRAMS = transmission
    5151
     52dbus_generated_sources = tr-core-dbus.h
     53
    5254transmission_SOURCES = \
    5355    actions.c \
     
    7274    tr-torrent.c \
    7375    tr-window.c \
    74     util.c
     76    util.c \
     77    $(dbus_generated_sources)
    7578
    7679dist_man_MANS = transmission.1
     
    107110    transmission.desktop
    108111
     112CLEANFILES = $(dbus_generated_sources)
     113
     114$(srcdir)/tr-core-dbus.c: tr-core-dbus.h
     115
     116tr-core-dbus.h: $(srcdir)/tr-core-dbus.xml
     117        $(DBUS_BINDING_TOOL) --mode=glib-server --prefix=tr_core $< > $(@F)
  • trunk/gtk/actions.c

    r6490 r6559  
    130130  { "help", GTK_STOCK_HELP, N_("_Contents"), "F1", NULL, G_CALLBACK(action_cb) },
    131131  { "update-tracker", GTK_STOCK_NETWORK,
    132     N_("Ask Tracker for _More Peers"), NULL, NULL, G_CALLBACK(action_cb) }
     132    N_("Ask Tracker for _More Peers"), NULL, NULL, G_CALLBACK(action_cb) },
     133  { "present-main-window", NULL, NULL, NULL, NULL, G_CALLBACK(action_cb) },
    133134};
    134135
  • trunk/gtk/conf.c

    r6166 r6559  
    7272/* errstr may be NULL, this might be called before GTK is initialized */
    7373static gboolean
    74 lockfile(const char * filename, char **errstr)
    75 {
    76     const int state = tr_lockfile( filename );
     74lockfile(const char * filename, tr_lockfile_state_t *tr_state, char **errstr)
     75{
     76    const tr_lockfile_state_t state = tr_lockfile( filename );
    7777    const gboolean success = state == TR_LOCKFILE_SUCCESS;
    7878
     
    9191    }
    9292
     93    if( tr_state != NULL)
     94        *tr_state = state;
     95
    9396    return success;
    9497}
     
    112115/* errstr may be NULL, this might be called before GTK is initialized */
    113116gboolean
    114 cf_lock( char ** errstr )
     117cf_lock( tr_lockfile_state_t *tr_state, char ** errstr )
    115118{
    116119    char * path = getLockFilename( );
    117     const gboolean didLock = lockfile( path, errstr );
     120    const gboolean didLock = lockfile( path, tr_state, errstr );
    118121    if( didLock )
    119122        gl_lockpath = g_strdup( path );
  • trunk/gtk/conf.h

    r6162 r6559  
    6767cf_init(const char *confdir, char **errstr);
    6868gboolean
    69 cf_lock(char **errstr);
     69cf_lock(tr_lockfile_state_t *tr_state, char **errstr);
    7070void
    7171cf_check_older_configs(void);
  • trunk/gtk/main.c

    r6556 r6559  
    348348    char * domain = "transmission";
    349349    char * configDir = NULL;
     350    tr_lockfile_state_t tr_state;
    350351
    351352    GOptionEntry entries[] = {
     
    398399     * transmission that's running, OR if there are files to
    399400     * be added, delegate that to the running instance via dbus */
    400     didlock = cf_lock( &err );
     401    didlock = cf_lock( &tr_state, &err );
    401402    argfiles = checkfilenames( argc-1, argv+1 );
    402403    if( !didlock && argfiles )
     
    408409        if( delegated )
    409410            err = NULL;
     411    }
     412    else if( (!didlock) && (tr_state == TR_LOCKFILE_ELOCK) )
     413    {
     414        gtr_dbus_present_window();
     415        err = NULL;
    410416    }
    411417
     
    577583
    578584static void
    579 toggleMainWindow( struct cbdata * cbdata )
     585toggleMainWindow( struct cbdata * cbdata, gboolean present )
    580586{
    581587    GtkWindow * window = GTK_WINDOW( cbdata->wind );
     
    583589    static int x=0, y=0;
    584590
    585     if( hide )
     591    if( (!present) && hide )
    586592    {
    587593        gtk_window_get_position( window, &x, &y );
     
    593599    {
    594600        gtk_window_set_skip_taskbar_hint( window, FALSE );
    595         gtk_window_move( window, x, y );
     601        if ( x != 0 && y != 0 )
     602            gtk_window_move( window, x, y );
    596603        gtk_widget_show( GTK_WIDGET( window ) );
    597604        gtk_window_deiconify( window );
     
    13581365    else if (!strcmp (action_name, "toggle-main-window"))
    13591366    {
    1360         toggleMainWindow( data );
     1367        toggleMainWindow( data, FALSE );
     1368    }
     1369    else if (!strcmp (action_name, "present-main-window"))
     1370    {
     1371        toggleMainWindow( data, TRUE );
    13611372    }
    13621373    else g_error ("Unhandled action: %s", action_name );
  • trunk/gtk/tr-core-dbus.xml

    r5843 r6559  
    66      <arg type="s" name="filename" direction="in"/>
    77    </method>
     8    <method name="PresentWindow">
     9      <arg type="b" name="handled" direction="out"/>
     10    </method>
    811  </interface>
    912</node>
  • trunk/gtk/tr-core.c

    r6490 r6559  
    4545#include "tr-torrent.h"
    4646#include "util.h"
     47#include "actions.h"
    4748
    4849static void maybeInhibitHibernation( TrCore * core );
     
    786787}
    787788
     789gboolean
     790tr_core_present_window( TrCore      * core UNUSED,
     791                        gboolean    * success,
     792                        GError     ** err UNUSED )
     793{
     794    action_activate( "present-main-window" );
     795    *success = TRUE;
     796    return TRUE;
     797}
     798
    788799void
    789800tr_core_add_list( TrCore      * core,
  • trunk/gtk/tr-core.h

    r6344 r6559  
    131131gboolean tr_core_add_file( TrCore*, const char * filename, gboolean * setme_success, GError ** err );
    132132
     133/** Present the main window */
     134gboolean tr_core_present_window( TrCore*, gboolean * setme_success, GError ** err );
     135
    133136/** Add a torrent. */
    134137void tr_core_add_torrent( TrCore*, TrTorrent* );
  • trunk/gtk/util.c

    r6516 r6559  
    501501}
    502502
     503gboolean
     504gtr_dbus_present_window()
     505{
     506    static gboolean success = FALSE;
     507#ifdef HAVE_DBUS_GLIB
     508    DBusGProxy * proxy = NULL;
     509    GError * err = NULL;
     510    DBusGConnection * conn;
     511    if(( conn = dbus_g_bus_get( DBUS_BUS_SESSION, &err )))
     512        proxy = dbus_g_proxy_new_for_name (conn, VALUE_SERVICE_NAME,
     513                                                 VALUE_SERVICE_OBJECT_PATH,
     514                                                 VALUE_SERVICE_INTERFACE );
     515    else if( err )
     516       g_message( "err: %s", err->message );
     517    if( proxy )
     518        dbus_g_proxy_call( proxy, "PresentWindow", &err,
     519                           G_TYPE_INVALID,
     520                           G_TYPE_BOOLEAN, &success,
     521                           G_TYPE_INVALID );
     522    if( err )
     523       g_message( "err: %s", err->message );
     524
     525    g_object_unref( proxy );
     526    dbus_g_connection_unref( conn );
     527#endif
     528    return success;
     529}
     530
    503531GtkWidget *
    504532tr_button_new_from_stock( const char * stock,
  • trunk/gtk/util.h

    r6402 r6559  
    8181
    8282gboolean gtr_dbus_add_torrent( const char * filename );
     83gboolean gtr_dbus_present_window( void );
    8384
    8485char* gtr_get_help_url( void );
  • trunk/libtransmission/platform.c

    r6514 r6559  
    604604***/
    605605
    606 int
     606tr_lockfile_state_t
    607607tr_lockfile( const char * filename )
    608608{
    609     int ret;
     609    tr_lockfile_state_t ret;
    610610
    611611#ifdef WIN32
  • trunk/libtransmission/platform.h

    r6498 r6559  
    5757int          tr_lockHave       ( const tr_lock * );
    5858
    59 
    60 enum
    61 {
    62   TR_LOCKFILE_SUCCESS,
    63   TR_LOCKFILE_EOPEN,
    64   TR_LOCKFILE_ELOCK
    65 };
    66 
    67 int          tr_lockfile       ( const char * filename );
     59tr_lockfile_state_t tr_lockfile       ( const char * filename );
    6860
    6961#endif
  • trunk/libtransmission/transmission.h

    r6556 r6559  
    11801180tr_errno;
    11811181
     1182typedef enum
     1183{
     1184  TR_LOCKFILE_SUCCESS = 0,
     1185  TR_LOCKFILE_EOPEN,
     1186  TR_LOCKFILE_ELOCK
     1187} tr_lockfile_state_t;
     1188
    11821189tr_torrent_status tr_torrentGetStatus( tr_torrent * );
    11831190
Note: See TracChangeset for help on using the changeset viewer.