Changeset 5232


Ignore:
Timestamp:
Mar 9, 2008, 10:11:36 PM (14 years ago)
Author:
charles
Message:

(gtk) in the "watch directory" feature, better handling of when the user changes the watch directory via the preferences dialog

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/tr-core.c

    r5230 r5232  
    4444#ifdef HAVE_GIO
    4545    GFileMonitor     * monitor;
     46    gulong             monitor_tag;
     47    char             * monitor_path;
    4648#endif
    4749    GtkTreeModel     * model;
     
    284286}
    285287
     288static void
     289tr_core_apply_defaults( tr_ctor * ctor )
     290{
     291    if( tr_ctorGetPaused( ctor, TR_FORCE, NULL ) )
     292        tr_ctorSetPaused( ctor, TR_FORCE, !pref_flag_get( PREF_KEY_START ) );
     293
     294    if( tr_ctorGetDeleteSource( ctor, NULL ) )
     295        tr_ctorSetDeleteSource( ctor, pref_flag_get( PREF_KEY_TRASH_ORIGINAL ) );
     296
     297    if( tr_ctorGetMaxConnectedPeers( ctor, TR_FORCE, NULL ) )
     298        tr_ctorSetMaxConnectedPeers( ctor, TR_FORCE,
     299                              pref_int_get( PREF_KEY_MAX_PEERS_PER_TORRENT ) );
     300
     301    if( tr_ctorGetDestination( ctor, TR_FORCE, NULL ) ) {
     302        char * path = pref_string_get( PREF_KEY_DIR_DEFAULT );
     303        tr_ctorSetDestination( ctor, TR_FORCE, path );
     304        g_free( path );
     305    }
     306}
     307
    286308#ifdef HAVE_GIO
     309static gboolean
     310canAddTorrent( TrCore * core, const char * filename )
     311{
     312    gboolean canAdd;
     313    tr_ctor * ctor = tr_ctorNew( core->priv->handle );
     314    tr_core_apply_defaults( ctor );
     315    tr_ctorSetMetainfoFromFile( ctor, filename );
     316    canAdd = !tr_torrentParse( core->priv->handle, ctor, NULL );
     317    tr_ctorFree( ctor );
     318    return canAdd;
     319}
     320
    287321static void
    288322watchFolderChanged( GFileMonitor       * monitor UNUSED,
     
    297331        char * filename = g_file_get_path( file );
    298332        const gboolean isTorrent = g_str_has_suffix( filename, ".torrent" );
    299         if( isTorrent )
     333
     334        if( isTorrent && canAddTorrent( core, filename ) )
    300335        {
    301336            tr_ctor * ctor = tr_ctorNew( core->priv->handle );
    302337            tr_core_add_list( core, g_list_append( NULL, g_strdup( filename ) ), ctor );
    303338        }
     339
    304340        g_free( filename );
    305341    }
     
    331367    const gboolean isEnabled = pref_flag_get( PREF_KEY_DIR_WATCH_ENABLED );
    332368
    333     if( core->priv->monitor && !isEnabled )
    334     {
    335         GFileMonitor * m = core->priv->monitor;
     369    if( core->priv->monitor && ( !isEnabled || tr_strcmp( filename, core->priv->monitor_path ) ) )
     370    {
     371        g_signal_handler_disconnect( core->priv->monitor, core->priv->monitor_tag );
     372        g_free( core->priv->monitor_path );
     373        g_file_monitor_cancel( core->priv->monitor );
     374        g_object_unref( G_OBJECT( core->priv->monitor ) );
     375        core->priv->monitor_path = NULL;
    336376        core->priv->monitor = NULL;
    337         g_signal_handlers_disconnect_by_func( m, watchFolderChanged, core );
    338         g_file_monitor_cancel( m );
    339         g_object_unref( G_OBJECT( m ) );
    340     }
    341     else if( isEnabled && !core->priv->monitor )
     377        core->priv->monitor_tag = 0;
     378    }
     379
     380    if( isEnabled && !core->priv->monitor )
    342381    {
    343382        GFile * file = g_file_new_for_path( filename );
    344383        GFileMonitor * m = g_file_monitor_directory( file, 0, NULL, NULL );
    345384        scanWatchDir( core );
    346         g_signal_connect( m, "changed", G_CALLBACK (watchFolderChanged), core );
    347385        core->priv->monitor = m;
     386        core->priv->monitor_path = g_strdup( filename );
     387        core->priv->monitor_tag = g_signal_connect( m, "changed", G_CALLBACK (watchFolderChanged), core );
    348388    }
    349389
     
    576616}
    577617
    578 static void
    579 tr_core_apply_defaults( tr_ctor * ctor )
    580 {
    581     if( tr_ctorGetPaused( ctor, TR_FORCE, NULL ) )
    582         tr_ctorSetPaused( ctor, TR_FORCE, !pref_flag_get( PREF_KEY_START ) );
    583 
    584     if( tr_ctorGetDeleteSource( ctor, NULL ) )
    585         tr_ctorSetDeleteSource( ctor, pref_flag_get( PREF_KEY_TRASH_ORIGINAL ) );
    586 
    587     if( tr_ctorGetMaxConnectedPeers( ctor, TR_FORCE, NULL ) )
    588         tr_ctorSetMaxConnectedPeers( ctor, TR_FORCE,
    589                               pref_int_get( PREF_KEY_MAX_PEERS_PER_TORRENT ) );
    590 
    591     if( tr_ctorGetDestination( ctor, TR_FORCE, NULL ) ) {
    592         char * path = pref_string_get( PREF_KEY_DIR_DEFAULT );
    593         tr_ctorSetDestination( ctor, TR_FORCE, path );
    594         g_free( path );
    595     }
    596 }
    597 
    598618void
    599619tr_core_add_ctor( TrCore * self, tr_ctor * ctor )
Note: See TracChangeset for help on using the changeset viewer.