Changeset 5242


Ignore:
Timestamp:
Mar 13, 2008, 1:06:54 AM (15 years ago)
Author:
charles
Message:

(gtk) clean up the "watch directory" code a little.

File:
1 edited

Legend:

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

    r5238 r5242  
    327327
    328328static void
     329maybeAddTorrent( TrCore * core, const char * filename )
     330{
     331    const gboolean isTorrent = g_str_has_suffix( filename, ".torrent" );
     332
     333    if( isTorrent )
     334    {
     335        struct TrCorePrivate * p = core->priv;
     336
     337        if( !g_list_find_custom( p->monitor_files, filename, (GCompareFunc)strcmp ) )
     338            p->monitor_files = g_list_append( p->monitor_files, g_strdup( filename ) );
     339        if( !p->monitor_idle_tag )
     340            p->monitor_idle_tag = g_timeout_add( 1000, watchFolderIdle, core );
     341    }
     342}
     343
     344static void
    329345watchFolderChanged( GFileMonitor       * monitor UNUSED,
    330346                    GFile              * file,
     
    336352    {
    337353        char * filename = g_file_get_path( file );
    338         const gboolean isTorrent = g_str_has_suffix( filename, ".torrent" );
    339 
    340         if( isTorrent )
    341         {
    342             struct TrCorePrivate * p = TR_CORE( core )->priv;
    343 
    344             if( !g_list_find_custom( p->monitor_files, filename, (GCompareFunc)strcmp ) )
    345                 p->monitor_files = g_list_append( p->monitor_files, g_strdup( filename ) );
    346             if( !p->monitor_idle_tag )
    347                 p->monitor_idle_tag = g_timeout_add( 1000, watchFolderIdle, core );
    348         }
    349 
     354        maybeAddTorrent( core, filename );
    350355        g_free( filename );
    351356    }
     
    358363    if( isEnabled )
    359364    {
    360         GList * torrents = NULL;
    361365        char * dirname = pref_string_get( PREF_KEY_DIR_WATCH );
    362366        GDir * dir = g_dir_open( dirname, 0, NULL );
    363367        const char * basename;
    364         while(( basename = g_dir_read_name( dir )))
    365             if( g_str_has_suffix( basename, ".torrent" ) )
    366                 torrents = g_list_append( torrents, g_build_filename( dirname, basename, NULL ) );
    367         if( torrents )
    368             tr_core_add_list( core, torrents, tr_ctorNew( core->priv->handle ) );
     368        while(( basename = g_dir_read_name( dir ))) {
     369            char * filename = g_build_filename( dirname, basename, NULL );
     370            maybeAddTorrent( core, filename );
     371            g_free( filename );
     372        }
    369373        g_free( dirname );
    370374    }
Note: See TracChangeset for help on using the changeset viewer.