Changeset 10995


Ignore:
Timestamp:
Jul 11, 2010, 5:56:58 PM (12 years ago)
Author:
charles
Message:

(trunk gtk) #3395 "open files by double-clicking on them in the file list" -- added.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/configure.ac

    r10963 r10995  
    5151##
    5252##
    53 GLIB_MINIMUM=2.6.0
     53GLIB_MINIMUM=2.8.0
    5454AC_SUBST(GLIB_MINIMUM)
    55 GTK_MINIMUM=2.6.0
     55GTK_MINIMUM=2.8.0
    5656AC_SUBST(GTK_MINIMUM)
    5757
  • trunk/gtk/file-list.c

    r10642 r10995  
    588588}
    589589
     590/* build a filename from tr_torrentGetCurrentDir() + the model's FC_LABELs */
     591static char*
     592buildFilename( tr_torrent * tor, GtkTreeModel * model,
     593               GtkTreePath * path, GtkTreeIter * iter )
     594{
     595    char * ret;
     596    GtkTreeIter child;
     597    GtkTreeIter parent = *iter;
     598    int n = gtk_tree_path_get_depth( path );
     599    char ** tokens = g_new0( char*, n + 2 );
     600    tokens[0] = g_strdup( tr_torrentGetCurrentDir( tor ) );
     601    do {
     602        child = parent;
     603        gtk_tree_model_get( model, &child, FC_LABEL, &tokens[n--], -1 );
     604    } while( gtk_tree_model_iter_parent( model, &parent, &child ) );
     605    ret = g_build_filenamev( tokens );
     606    g_strfreev( tokens );
     607    return ret;
     608}
     609
     610static gboolean
     611onRowActivated( GtkTreeView * view, GtkTreePath * path,
     612                GtkTreeViewColumn * col UNUSED, gpointer gdata )
     613{
     614    gboolean handled = FALSE;
     615    FileData * data = gdata;
     616    tr_torrent * tor = tr_torrentFindFromId( tr_core_session( data->core ), data->torrentId );
     617
     618    if( tor != NULL )
     619    {
     620        GtkTreeIter iter;
     621        GtkTreeModel * model = gtk_tree_view_get_model( view );
     622
     623        if( gtk_tree_model_get_iter( model, &iter, path ) )
     624        {
     625            int prog;
     626            char * filename = buildFilename( tor, model, path, &iter );
     627            gtk_tree_model_get( model, &iter, FC_PROG, &prog, -1 );
     628
     629            /* if the file's not done, walk up the directory tree until we find
     630             * an ancestor that exists, and open that instead */
     631            if( filename && ( prog<100 || !g_file_test( filename, G_FILE_TEST_EXISTS ) ) ) do
     632            {
     633                char * tmp = g_path_get_dirname( filename );
     634                g_free( filename );
     635                filename = tmp;
     636            }
     637            while( filename && *filename && !g_file_test( filename, G_FILE_TEST_EXISTS ) );
     638
     639            if(( handled = filename && *filename ))
     640                gtr_open_file( filename );
     641        }
     642    }
     643
     644    return handled;
     645}
     646
     647
    590648static gboolean
    591649onViewButtonPressed( GtkWidget * w, GdkEventButton * event, gpointer gdata )
     
    701759    g_signal_connect( view, "button-press-event",
    702760                      G_CALLBACK( onViewButtonPressed ), data );
     761    g_signal_connect( view, "row_activated",
     762                      G_CALLBACK( onRowActivated ), data );
    703763    g_signal_connect( view, "button-release-event",
    704764                      G_CALLBACK( on_tree_view_button_released ), NULL );
Note: See TracChangeset for help on using the changeset viewer.