Ejemplo n.º 1
0
gboolean edit_bookmarks( GtkWindow* parent )
{
    GList* l;
    GtkWidget* dlg;
    GtkWidget* btn_box;
    GtkWidget* add_btn;
    GtkWidget* delete_btn;
    GtkWidget* scroll;
    GtkWidget* list_view;
    GtkListStore* list;
    GtkTreeViewColumn* col;
    GtkTreeIter it;
    GtkTreeSelection* sel;
    gchar *name, *path, *item;
    gboolean ret = FALSE;
    PtkBookmarks* bookmarks;
    GtkCellRenderer *renderer, *icon_renderer;
    GdkPixbuf* icon;

    dlg = gtk_dialog_new_with_buttons ( _("Edit Bookmarks"),
                                        parent,
                                        GTK_DIALOG_MODAL,
                                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                        GTK_STOCK_OK, GTK_RESPONSE_OK,
                                        NULL );
    gtk_dialog_set_alternative_button_order( GTK_DIALOG(dlg), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1 );

    list = gtk_list_store_new( NUM_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING );

    icon = gtk_icon_theme_load_icon( gtk_icon_theme_get_default(),
                                     "gnome-fs-directory",
                                     20, 0, NULL );
    bookmarks = ptk_bookmarks_get();
    for( l = bookmarks->list; l; l = l->next )
    {
        gtk_list_store_append( list, &it );
        gtk_list_store_set( list, &it,
                            COL_ICON, icon,
                            COL_NAME, l->data,
                            COL_DIRPATH, ptk_bookmarks_item_get_path((char*)l->data),
                            -1);
    }
    if( icon )
        g_object_unref( icon );

    scroll = gtk_scrolled_window_new(NULL, NULL);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(scroll),
                                         GTK_SHADOW_IN);

    list_view = gtk_tree_view_new_with_model( GTK_TREE_MODEL(list) );
    g_object_set_data( G_OBJECT(dlg), "list_view", list_view );

    sel = gtk_tree_view_get_selection( GTK_TREE_VIEW(list_view) );
    gtk_tree_selection_set_mode( sel, GTK_SELECTION_BROWSE );

    if( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL(list), &it ) )
    {
        gtk_tree_selection_select_iter( sel, &it );
    }

    icon_renderer = gtk_cell_renderer_pixbuf_new();
    renderer = gtk_cell_renderer_text_new();
    g_object_set( G_OBJECT(renderer), "editable", TRUE, NULL );
    g_signal_connect( renderer, "edited", G_CALLBACK(on_name_edited), list );
    col = gtk_tree_view_column_new_with_attributes(NULL, icon_renderer, "pixbuf", COL_ICON, NULL );
    gtk_tree_view_append_column( GTK_TREE_VIEW(list_view), col );

    col = gtk_tree_view_column_new_with_attributes(_("Name"), renderer, "text", COL_NAME, NULL);
    gtk_tree_view_column_set_resizable(col, TRUE);
    gtk_tree_view_column_set_fixed_width(col, 160);
    gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
    gtk_tree_view_append_column( GTK_TREE_VIEW(list_view), col );

    renderer = gtk_cell_renderer_text_new();
    g_object_set( G_OBJECT(renderer), "editable", TRUE, NULL );
    g_signal_connect( renderer, "edited", G_CALLBACK(on_path_edited), list );
    col = gtk_tree_view_column_new_with_attributes(_("Path"),
                                                   renderer, "text", COL_DIRPATH, NULL);
    gtk_tree_view_column_set_resizable(col, TRUE);
    gtk_tree_view_append_column( GTK_TREE_VIEW(list_view), col );

    gtk_tree_view_set_reorderable ( GTK_TREE_VIEW(list_view), TRUE );

    gtk_container_add( GTK_CONTAINER(scroll), list_view);

    btn_box = gtk_hbutton_box_new();
    gtk_button_box_set_layout ( GTK_BUTTON_BOX(btn_box), GTK_BUTTONBOX_START );
    add_btn = gtk_button_new_from_stock ( GTK_STOCK_ADD );
    g_signal_connect( add_btn, "clicked", G_CALLBACK(on_add), dlg );
    gtk_box_pack_start_defaults ( GTK_BOX(btn_box), add_btn );

    delete_btn = gtk_button_new_from_stock ( GTK_STOCK_DELETE );
    g_signal_connect( delete_btn, "clicked", G_CALLBACK(on_delete), dlg );
    gtk_box_pack_start_defaults ( GTK_BOX(btn_box), delete_btn );

    gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dlg)->vbox), btn_box,
                        FALSE, FALSE, 4 );
    gtk_box_pack_start_defaults( GTK_BOX(GTK_DIALOG(dlg)->vbox), scroll );
    gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dlg)->vbox),
                        gtk_label_new(_("Use drag & drop to sort the items")),
                        FALSE, FALSE, 4 );

    gtk_window_set_default_size ( GTK_WINDOW(dlg), 480, 400 );

    gtk_widget_show_all( dlg );
    gtk_widget_grab_focus( list_view );

    pcmanfm_ref();

    if( gtk_dialog_run( GTK_DIALOG(dlg) ) == GTK_RESPONSE_OK )
    {
        l = NULL;
        if( gtk_tree_model_get_iter_first( GTK_TREE_MODEL(list), &it ) )
        {
            do
            {
                gtk_tree_model_get( GTK_TREE_MODEL(list), &it,
                                    COL_NAME, &name,
                                    COL_DIRPATH, &path,
                                    -1 );
                if( ! name )
                    name = g_path_get_basename( path );
                item = ptk_bookmarks_item_new( name, strlen(name),
                                               path ? path : "", path ? strlen(path) : 0 );
                l = g_list_append( l, item );
                g_free(name);
                g_free(path);
            }
            while( gtk_tree_model_iter_next( GTK_TREE_MODEL(list), &it) );
        }

        ptk_bookmarks_set( l );

        ret = TRUE;
    }

    ptk_bookmarks_unref();

    gtk_widget_destroy( dlg );
    pcmanfm_unref();

    return ret;
}
Ejemplo n.º 2
0
void fm_find_files( const char** search_dirs )
{
    FindFile* data = g_slice_new0(FindFile);
    GtkTreeIter it;
    GtkTreeViewColumn* col;
    GtkWidget *add_folder_btn, *remove_folder_btn, *img;

    GtkBuilder* builder = _gtk_builder_new_from_file( PACKAGE_UI_DIR "/find-files.ui", NULL );
    data->win = (GtkWidget*)gtk_builder_get_object( builder, "win" );
    g_object_set_data_full( G_OBJECT( data->win ), "find-files", data, (GDestroyNotify)free_data );

    GdkPixbuf* icon = NULL;
    GtkIconTheme* theme = gtk_icon_theme_get_default();
    if ( theme )
        icon = gtk_icon_theme_load_icon( theme, "spacefm-find", 48, 0, NULL );
    if ( icon )
    {
        gtk_window_set_icon( GTK_WINDOW( data->win ), icon );
        g_object_unref( icon );
    }
    else
        gtk_window_set_icon_name( GTK_WINDOW( data->win ), GTK_STOCK_FIND );

    /* search criteria pane */
    data->search_criteria = (GtkWidget*)gtk_builder_get_object( builder, "search_criteria" );

    data->fn_pattern = (GtkWidget*)gtk_builder_get_object( builder, "fn_pattern" );
    data->fn_pattern_entry = gtk_bin_get_child( GTK_BIN( data->fn_pattern ) );
    data->fn_case_sensitive = (GtkWidget*)gtk_builder_get_object( builder, "fn_case_sensitive" );
    gtk_entry_set_activates_default( (GtkEntry*)data->fn_pattern_entry, TRUE );

    /* file content */
    data->fc_pattern = (GtkWidget*)gtk_builder_get_object( builder, "fc_pattern" );
    data->fc_case_sensitive = (GtkWidget*)gtk_builder_get_object( builder, "fc_case_sensitive" );
    data->fc_use_regexp = (GtkWidget*)gtk_builder_get_object( builder, "fc_use_regexp" );

    /* advanced options */
    data->search_hidden = (GtkWidget*)gtk_builder_get_object( builder, "search_hidden" );

    /* size & date */
    data->use_size_lower = (GtkWidget*)gtk_builder_get_object( builder, "use_size_lower" );
    data->use_size_upper = (GtkWidget*)gtk_builder_get_object( builder, "use_size_upper" );
    data->size_lower = (GtkWidget*)gtk_builder_get_object( builder, "size_lower" );
    data->size_upper = (GtkWidget*)gtk_builder_get_object( builder, "size_upper" );
    data->size_lower_unit = (GtkWidget*)gtk_builder_get_object( builder, "size_lower_unit" );
    data->size_upper_unit = (GtkWidget*)gtk_builder_get_object( builder, "size_upper_unit" );
    g_signal_connect( data->use_size_lower, "toggled",
                            G_CALLBACK( on_use_size_lower_toggled ), data );
    g_signal_connect( data->use_size_upper, "toggled",
                            G_CALLBACK( on_use_size_upper_toggled ), data );
    on_use_size_lower_toggled( data->use_size_lower, data );
    on_use_size_upper_toggled( data->use_size_upper, data );

    data->date_limit = (GtkWidget*)gtk_builder_get_object( builder, "date_limit" );
    data->date1 = (GtkWidget*)gtk_builder_get_object( builder, "date1" );
    data->date2 = (GtkWidget*)gtk_builder_get_object( builder, "date2" );
    g_signal_connect( data->date_limit, "changed", G_CALLBACK( on_date_limit_changed ), data );

    /* file types */
    data->all_files = (GtkWidget*)gtk_builder_get_object( builder, "all_files" );
    data->text_files = (GtkWidget*)gtk_builder_get_object( builder, "text_files" );
    data->img_files = (GtkWidget*)gtk_builder_get_object( builder, "img_files" );
    data->audio_files = (GtkWidget*)gtk_builder_get_object( builder, "audio_files" );
    data->video_files = (GtkWidget*)gtk_builder_get_object( builder, "video_files" );

    /* places */
    data->places_list = gtk_list_store_new( 1, G_TYPE_STRING );
    data->places_view = (GtkWidget*)gtk_builder_get_object( builder, "places_view" );
    add_folder_btn = (GtkWidget*)gtk_builder_get_object( builder, "add_folder_btn" );
    remove_folder_btn = (GtkWidget*)gtk_builder_get_object( builder, "remove_folder_btn" );
    data->include_sub = (GtkWidget*)gtk_builder_get_object( builder, "include_sub" );

    if( search_dirs )
    {
        const char** dir;
        for( dir = search_dirs; *dir; ++dir )
        {
            if( g_file_test( *dir, G_FILE_TEST_IS_DIR ) )
                gtk_list_store_insert_with_values( data->places_list, &it, 0, 0, *dir, -1 );
        }
    }

    gtk_tree_view_set_model( (GtkTreeView*)data->places_view, (GtkTreeModel*)data->places_list );
    g_object_unref( data->places_list );
    col = gtk_tree_view_column_new_with_attributes(NULL, gtk_cell_renderer_text_new(), "text", 0, NULL );
    gtk_tree_view_append_column( (GtkTreeView*)data->places_view, col );

    g_signal_connect(add_folder_btn, "clicked", G_CALLBACK( on_add_search_folder ), data );
    g_signal_connect(remove_folder_btn, "clicked", G_CALLBACK( on_remove_search_folder ), data );

    /* search result pane */
    data->search_result = (GtkWidget*)gtk_builder_get_object( builder, "search_result" );
    /* replace the problematic GtkTreeView with ExoTreeView */
    data->result_view = exo_tree_view_new();
    if( app_settings.single_click )
    {
        exo_tree_view_set_single_click( EXO_TREE_VIEW( data->result_view ), TRUE );
        exo_tree_view_set_single_click_timeout( EXO_TREE_VIEW( data->result_view ),
                                                        SINGLE_CLICK_TIMEOUT );
    }
    gtk_widget_show( data->result_view );
    gtk_container_add( (GtkContainer*)gtk_builder_get_object(builder, "result_scroll"), data->result_view );
    init_search_result( data );
    g_signal_connect(data->result_view, "button-press-event", G_CALLBACK( on_view_button_press ), data );

    /* buttons */
    data->start_btn = (GtkWidget*)gtk_builder_get_object( builder, "start_btn" );
    data->stop_btn = (GtkWidget*)gtk_builder_get_object( builder, "stop_btn" );
    data->again_btn = (GtkWidget*)gtk_builder_get_object( builder, "again_btn" );
    img = gtk_image_new_from_icon_name( GTK_STOCK_REFRESH, GTK_ICON_SIZE_BUTTON );
    gtk_button_set_image( (GtkButton*)data->again_btn, img );

    g_signal_connect(data->start_btn, "clicked", G_CALLBACK( on_start_search ), data );
    g_signal_connect(data->stop_btn, "clicked", G_CALLBACK( on_stop_search ), data );
    g_signal_connect(data->again_btn, "clicked", G_CALLBACK( on_search_again ), data );


    gtk_entry_set_text( (GtkEntry*)data->fn_pattern_entry, "*" );
    gtk_editable_select_region( (GtkEditable*)data->fn_pattern_entry, 0, -1 );

    gtk_combo_box_set_active( (GtkComboBox*)data->size_lower_unit, 1 );
    gtk_spin_button_set_range( (GtkSpinButton*)data->size_lower, 0, G_MAXINT );
    gtk_combo_box_set_active( (GtkComboBox*)data->size_upper_unit, 2 );
    gtk_spin_button_set_range( (GtkSpinButton*)data->size_upper, 0, G_MAXINT );

    gtk_combo_box_set_active( (GtkComboBox*)data->date_limit, 0 );

    g_signal_connect( data->win, "delete-event", G_CALLBACK(gtk_widget_destroy), NULL );

    pcmanfm_ref();
    g_signal_connect( data->win, "destroy", G_CALLBACK(pcmanfm_unref), NULL );

    int width = xset_get_int( "main_search", "x" );
    int height = xset_get_int( "main_search", "y" );
    if ( width && height )
        gtk_window_set_default_size( GTK_WINDOW( data->win ), width, height );
    
    gtk_widget_show( data->win );

}
Ejemplo n.º 3
0
inline static void show_autorun_dlg(GVolume* vol, GMount* mount)
{
    GtkBuilder* builder;
    GtkTreeIter it;
    GtkTreeViewColumn* col;
    GtkTreeSelection* tree_sel;
    GtkCellRenderer*render;
    GtkImage* icon;
    GIcon* gicon;
    AutoRun* data;

    data = g_slice_new(AutoRun);
    data->cancel = g_cancellable_new();

    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder, PACKAGE_UI_DIR "/autorun.glade", NULL);
    data->dlg = GTK_DIALOG(gtk_builder_get_object(builder, "dlg"));
    data->view = GTK_TREE_VIEW(gtk_builder_get_object(builder, "listview"));
    data->type = GTK_LABEL(gtk_builder_get_object(builder, "type"));
    icon = GTK_IMAGE(gtk_builder_get_object(builder, "icon"));
    g_object_unref(builder);

    gicon = g_volume_get_icon(vol);
    gtk_image_set_from_gicon(icon, gicon, GTK_ICON_SIZE_DIALOG);
    g_object_unref(gicon);

    gtk_dialog_set_default_response(data->dlg, GTK_RESPONSE_OK);
    gtk_dialog_set_alternative_button_order(data->dlg, GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, -1);

    tree_sel = gtk_tree_view_get_selection(data->view);
    gtk_tree_selection_set_mode(tree_sel, GTK_SELECTION_BROWSE);

    col = gtk_tree_view_column_new();
    render = gtk_cell_renderer_pixbuf_new();
    gtk_tree_view_column_pack_start(col, render, FALSE);
    gtk_tree_view_column_set_attributes(col, render, "gicon", 0, NULL);

    render = gtk_cell_renderer_text_new();
    gtk_tree_view_column_pack_start(col, render, FALSE);
    gtk_tree_view_column_set_attributes(col, render, "text", 1, NULL);

    gtk_tree_view_append_column(data->view, col);

    data->store = gtk_list_store_new(3, G_TYPE_ICON, G_TYPE_STRING, G_TYPE_OBJECT);
    data->mount = (GMount*)g_object_ref(mount);

    gtk_list_store_append(data->store, &it);
    gicon = g_themed_icon_new("system-file-manager");
    gtk_list_store_set(data->store, &it, 0, gicon, 1, _("Open in File Manager"), -1);
    g_object_unref(gicon);

    gtk_tree_view_set_model(data->view, GTK_TREE_MODEL(data->store));

    gtk_tree_model_get_iter_first(GTK_TREE_MODEL(data->store), &it);
    gtk_tree_selection_select_iter(tree_sel, &it);

    g_signal_connect(data->view, "row-activated", G_CALLBACK(on_row_activated), data);
    g_signal_connect(data->dlg, "response", G_CALLBACK(on_dlg_response), data);

    g_signal_connect(data->mount, "unmounted", G_CALLBACK(on_unmount), data);

    gtk_window_set_keep_above(GTK_WINDOW(data->dlg), TRUE);
    gtk_window_present(GTK_WINDOW(data->dlg));

    g_mount_guess_content_type(mount, TRUE, data->cancel, on_content_type_finished, data);

    pcmanfm_ref();
}