~ubuntu-branches/ubuntu/maverick/nautilus-actions/maverick

« back to all changes in this revision

Viewing changes to src/nact/nact-ibackground-tab.c

  • Committer: Bazaar Package Importer
  • Author(s): Christine Spang
  • Date: 2009-10-25 14:04:13 UTC
  • mfrom: (1.1.7 upstream) (3.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091025140413-okqdth1kvcx8ko3o
Tags: 2.29.1-1
* New upstream version.
  - implements full API as defined for use by Nautilus menu
    extensions : this let the user define items which will be
    available when there is no selection, and will apply to
    current folder, either in the 'File' menu or in the
    toolbar ;
  - the ability for the user to define a full hierarchy of
    actions with menus, submenus, and so on ;
  - drag and drop ;
  - full cut/copy/paste clipboard support.
  - Gnome bugs fixed:
    - #325528 reported by Frederic Ruaudel
              (bloated  contextual menu)
    - #325587 reported by Frederic Ruaudel
              (drag & drop support)
    - #326699 reported by Frederic Ruaudel
              (action items do not remain in user defined order)
    - #353353 reported by Frederic Ruaudel
              (check if command exist and if not warn user)
    - #588482 reported by Sean
            (ordering in actions list)
    - #326699 reported by Frederic Ruaudel
            (action items do not remain in user defined order)
    - #353353 reported by Frederic Ruaudel
              (check if command exist and if not warn user)
    - #588482 reported by Sean
              (ordering in actions list)
    - #590400 reported by Pierre Wieser
              (have some sort of warnings in the ui)
    - #599520 reported by António Lima
              (do not mark authors names and emails for translating)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Nautilus Actions
 
3
 * A Nautilus extension which offers configurable context menu actions.
 
4
 *
 
5
 * Copyright (C) 2005 The GNOME Foundation
 
6
 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
 
7
 * Copyright (C) 2009 Pierre Wieser and others (see AUTHORS)
 
8
 *
 
9
 * This Program is free software; you can redistribute it and/or
 
10
 * modify it under the terms of the GNU General Public License as
 
11
 * published by the Free Software Foundation; either version 2 of
 
12
 * the License, or (at your option) any later version.
 
13
 *
 
14
 * This Program is distributed in the hope that it will be useful,
 
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 * GNU General Public License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU General Public
 
20
 * License along with this Library; see the file COPYING.  If not,
 
21
 * write to the Free Software Foundation, Inc., 59 Temple Place,
 
22
 * Suite 330, Boston, MA 02111-1307, USA.
 
23
 *
 
24
 * Authors:
 
25
 *   Frederic Ruaudel <grumz@grumz.net>
 
26
 *   Rodrigo Moya <rodrigo@gnome-db.org>
 
27
 *   Pierre Wieser <pwieser@trychlos.org>
 
28
 *   ... and many others (see AUTHORS)
 
29
 */
 
30
 
 
31
#ifdef HAVE_CONFIG_H
 
32
#include <config.h>
 
33
#endif
 
34
 
 
35
#include <glib/gi18n.h>
 
36
#include <string.h>
 
37
 
 
38
#include <common/na-iprefs.h>
 
39
#include <common/na-object-api.h>
 
40
#include <common/na-utils.h>
 
41
 
 
42
#include <runtime/na-pivot.h>
 
43
 
 
44
#include "base-iprefs.h"
 
45
#include "base-window.h"
 
46
#include "nact-application.h"
 
47
#include "nact-main-tab.h"
 
48
#include "nact-ibackground-tab.h"
 
49
 
 
50
/* private interface data
 
51
 */
 
52
struct NactIBackgroundTabInterfacePrivate {
 
53
        void *empty;                                            /* so that gcc -pedantic is happy */
 
54
};
 
55
 
 
56
/* column ordering
 
57
 */
 
58
enum {
 
59
        BACKGROUND_URI_COLUMN = 0,
 
60
        BACKGROUND_N_COLUMN
 
61
};
 
62
 
 
63
#define IPREFS_BACKGROUND_DIALOG                "ibackground-chooser"
 
64
#define IPREFS_BACKGROUND_URI                   "ibackground-uri"
 
65
 
 
66
static gboolean st_initialized = FALSE;
 
67
static gboolean st_finalized = FALSE;
 
68
 
 
69
static GType        register_type( void );
 
70
static void         interface_base_init( NactIBackgroundTabInterface *klass );
 
71
static void         interface_base_finalize( NactIBackgroundTabInterface *klass );
 
72
 
 
73
static void         on_tab_updatable_selection_changed( NactIBackgroundTab *instance, gint count_selected );
 
74
static void         on_tab_updatable_enable_tab( NactIBackgroundTab *instance, NAObjectItem *item );
 
75
static gboolean     tab_set_sensitive( NactIBackgroundTab *instance );
 
76
 
 
77
static void         add_row( NactIBackgroundTab *instance, GtkTreeView *listview, const gchar *uri );
 
78
static void         add_uri_to_folders( NactIBackgroundTab *instance, const gchar *uri );
 
79
static GtkTreeView *get_folders_treeview( NactIBackgroundTab *instance );
 
80
static void         on_folder_uri_edited( GtkCellRendererText *renderer, const gchar *path, const gchar *text, NactIBackgroundTab *instance );
 
81
static void         on_folders_selection_changed( GtkTreeSelection *selection, NactIBackgroundTab *instance );
 
82
static void         on_add_folder_clicked( GtkButton *button, NactIBackgroundTab *instance );
 
83
static void         on_remove_folder_clicked( GtkButton *button, NactIBackgroundTab *instance );
 
84
static void         reset_folders( NactIBackgroundTab *instance );
 
85
static void         setup_folders( NactIBackgroundTab *instance );
 
86
static void         treeview_cell_edited( NactIBackgroundTab *instance, const gchar *path_string, const gchar *text, gint column, gboolean *state, gchar **old_text );
 
87
 
 
88
GType
 
89
nact_ibackground_tab_get_type( void )
 
90
{
 
91
        static GType iface_type = 0;
 
92
 
 
93
        if( !iface_type ){
 
94
                iface_type = register_type();
 
95
        }
 
96
 
 
97
        return( iface_type );
 
98
}
 
99
 
 
100
static GType
 
101
register_type( void )
 
102
{
 
103
        static const gchar *thisfn = "nact_ibackground_tab_register_type";
 
104
        GType type;
 
105
 
 
106
        static const GTypeInfo info = {
 
107
                sizeof( NactIBackgroundTabInterface ),
 
108
                ( GBaseInitFunc ) interface_base_init,
 
109
                ( GBaseFinalizeFunc ) interface_base_finalize,
 
110
                NULL,
 
111
                NULL,
 
112
                NULL,
 
113
                0,
 
114
                0,
 
115
                NULL
 
116
        };
 
117
 
 
118
        g_debug( "%s", thisfn );
 
119
 
 
120
        type = g_type_register_static( G_TYPE_INTERFACE, "NactIBackgroundTab", &info, 0 );
 
121
 
 
122
        g_type_interface_add_prerequisite( type, BASE_WINDOW_TYPE );
 
123
 
 
124
        return( type );
 
125
}
 
126
 
 
127
static void
 
128
interface_base_init( NactIBackgroundTabInterface *klass )
 
129
{
 
130
        static const gchar *thisfn = "nact_ibackground_tab_interface_base_init";
 
131
 
 
132
        if( !st_initialized ){
 
133
                g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
 
134
 
 
135
                klass->private = g_new0( NactIBackgroundTabInterfacePrivate, 1 );
 
136
 
 
137
                st_initialized = TRUE;
 
138
        }
 
139
}
 
140
 
 
141
static void
 
142
interface_base_finalize( NactIBackgroundTabInterface *klass )
 
143
{
 
144
        static const gchar *thisfn = "nact_ibackground_tab_interface_base_finalize";
 
145
 
 
146
        if( !st_finalized ){
 
147
                g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
 
148
 
 
149
                g_free( klass->private );
 
150
 
 
151
                st_finalized = TRUE;
 
152
        }
 
153
}
 
154
 
 
155
void
 
156
nact_ibackground_tab_initial_load_toplevel( NactIBackgroundTab *instance )
 
157
{
 
158
        static const gchar *thisfn = "nact_ibackground_tab_initial_load_toplevel";
 
159
        GtkTreeView *listview;
 
160
        GtkListStore *model;
 
161
        GtkTreeViewColumn *column;
 
162
        GtkCellRenderer *text_cell;
 
163
 
 
164
        g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 
165
        g_return_if_fail( NACT_IS_IBACKGROUND_TAB( instance ));
 
166
 
 
167
        if( st_initialized && !st_finalized ){
 
168
 
 
169
                model = gtk_list_store_new( BACKGROUND_N_COLUMN, G_TYPE_STRING );
 
170
                gtk_tree_sortable_set_sort_column_id( GTK_TREE_SORTABLE( model ), BACKGROUND_URI_COLUMN, GTK_SORT_ASCENDING );
 
171
                listview = get_folders_treeview( instance );
 
172
                gtk_tree_view_set_model( listview, GTK_TREE_MODEL( model ));
 
173
                g_object_unref( model );
 
174
 
 
175
                text_cell = gtk_cell_renderer_text_new();
 
176
                g_object_set( G_OBJECT( text_cell ), "editable", TRUE, NULL );
 
177
                column = gtk_tree_view_column_new_with_attributes(
 
178
                                "folder-uri",
 
179
                                text_cell,
 
180
                                "text", BACKGROUND_URI_COLUMN,
 
181
                                NULL );
 
182
                gtk_tree_view_append_column( listview, column );
 
183
 
 
184
                gtk_tree_view_set_headers_visible( listview, FALSE );
 
185
        }
 
186
}
 
187
 
 
188
void
 
189
nact_ibackground_tab_runtime_init_toplevel( NactIBackgroundTab *instance )
 
190
{
 
191
        static const gchar *thisfn = "nact_ibackground_tab_runtime_init_toplevel";
 
192
        GtkTreeView *listview;
 
193
        GtkTreeViewColumn *column;
 
194
        GList *renderers;
 
195
        GtkWidget *add_button, *remove_button;
 
196
 
 
197
        g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 
198
        g_return_if_fail( NACT_IS_IBACKGROUND_TAB( instance ));
 
199
 
 
200
        if( st_initialized && !st_finalized ){
 
201
 
 
202
                g_signal_connect(
 
203
                                G_OBJECT( instance ),
 
204
                                TAB_UPDATABLE_SIGNAL_SELECTION_CHANGED,
 
205
                                G_CALLBACK( on_tab_updatable_selection_changed ),
 
206
                                instance );
 
207
 
 
208
                g_signal_connect(
 
209
                                G_OBJECT( instance ),
 
210
                                TAB_UPDATABLE_SIGNAL_ENABLE_TAB,
 
211
                                G_CALLBACK( on_tab_updatable_enable_tab ),
 
212
                                instance );
 
213
 
 
214
                listview = get_folders_treeview( instance );
 
215
                column = gtk_tree_view_get_column( listview, BACKGROUND_URI_COLUMN );
 
216
                renderers = gtk_tree_view_column_get_cell_renderers( column );
 
217
                g_signal_connect(
 
218
                                G_OBJECT( renderers->data ),
 
219
                                "edited",
 
220
                                G_CALLBACK( on_folder_uri_edited ),
 
221
                                instance );
 
222
 
 
223
                add_button = base_window_get_widget( BASE_WINDOW( instance ), "AddFolderButton");
 
224
                g_signal_connect(
 
225
                                G_OBJECT( add_button ),
 
226
                                "clicked",
 
227
                                G_CALLBACK( on_add_folder_clicked ),
 
228
                                instance );
 
229
 
 
230
                remove_button = base_window_get_widget( BASE_WINDOW( instance ), "RemoveFolderButton");
 
231
                g_signal_connect(
 
232
                                G_OBJECT( remove_button ),
 
233
                                "clicked",
 
234
                                G_CALLBACK( on_remove_folder_clicked ),
 
235
                                instance );
 
236
 
 
237
                g_signal_connect(
 
238
                                G_OBJECT( gtk_tree_view_get_selection( listview )),
 
239
                                "changed",
 
240
                                G_CALLBACK( on_folders_selection_changed ),
 
241
                                instance );
 
242
        }
 
243
}
 
244
 
 
245
void
 
246
nact_ibackground_tab_all_widgets_showed( NactIBackgroundTab *instance )
 
247
{
 
248
        static const gchar *thisfn = "nact_ibackground_tab_all_widgets_showed";
 
249
 
 
250
        g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 
251
        g_return_if_fail( NACT_IS_IBACKGROUND_TAB( instance ));
 
252
 
 
253
        if( st_initialized && !st_finalized ){
 
254
        }
 
255
}
 
256
 
 
257
void
 
258
nact_ibackground_tab_dispose( NactIBackgroundTab *instance )
 
259
{
 
260
        static const gchar *thisfn = "nact_ibackground_tab_dispose";
 
261
 
 
262
        g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
 
263
        g_return_if_fail( NACT_IS_IBACKGROUND_TAB( instance ));
 
264
 
 
265
        if( st_initialized && !st_finalized ){
 
266
 
 
267
                reset_folders( instance );
 
268
        }
 
269
}
 
270
 
 
271
static void
 
272
on_tab_updatable_selection_changed( NactIBackgroundTab *instance, gint count_selected )
 
273
{
 
274
        static const gchar *thisfn = "nact_ibackground_tab_on_tab_updatable_selection_changed";
 
275
        NAObjectItem *item;
 
276
        gboolean enable_tab;
 
277
 
 
278
        g_debug( "%s: instance=%p, count_selected=%d", thisfn, ( void * ) instance, count_selected );
 
279
        g_return_if_fail( NACT_IS_IBACKGROUND_TAB( instance ));
 
280
 
 
281
        if( st_initialized && !st_finalized ){
 
282
 
 
283
                reset_folders( instance );
 
284
 
 
285
                g_object_get(
 
286
                                G_OBJECT( instance ),
 
287
                                TAB_UPDATABLE_PROP_EDITED_ACTION, &item,
 
288
                                NULL );
 
289
 
 
290
                g_return_if_fail( !item || NA_IS_OBJECT_ITEM( item ));
 
291
 
 
292
                enable_tab = tab_set_sensitive( instance );
 
293
 
 
294
                if( item && NA_IS_OBJECT_ACTION( item )){
 
295
                        setup_folders( instance );
 
296
                }
 
297
        }
 
298
}
 
299
 
 
300
static void
 
301
on_tab_updatable_enable_tab( NactIBackgroundTab *instance, NAObjectItem *item )
 
302
{
 
303
        static const gchar *thisfn = "nact_ibackground_tab_on_tab_updatable_enable_tab";
 
304
 
 
305
        if( st_initialized && !st_finalized ){
 
306
 
 
307
                g_debug( "%s: instance=%p, item=%p", thisfn, ( void * ) instance, ( void * ) item );
 
308
                g_return_if_fail( NACT_IS_IBACKGROUND_TAB( instance ));
 
309
 
 
310
                tab_set_sensitive( instance );
 
311
        }
 
312
}
 
313
 
 
314
static gboolean
 
315
tab_set_sensitive( NactIBackgroundTab *instance )
 
316
{
 
317
        NAObjectAction *action;
 
318
        NAObjectProfile *profile;
 
319
        gboolean enable_tab;
 
320
 
 
321
        g_object_get(
 
322
                        G_OBJECT( instance ),
 
323
                        TAB_UPDATABLE_PROP_EDITED_ACTION, &action,
 
324
                        TAB_UPDATABLE_PROP_EDITED_PROFILE, &profile,
 
325
                        NULL );
 
326
 
 
327
        enable_tab = ( profile != NULL &&
 
328
                        ( na_object_action_is_target_background( action ) || na_object_action_is_target_toolbar( action )));
 
329
 
 
330
        nact_main_tab_enable_page( NACT_MAIN_WINDOW( instance ), TAB_BACKGROUND, enable_tab );
 
331
 
 
332
        return( enable_tab );
 
333
}
 
334
 
 
335
static void
 
336
add_row( NactIBackgroundTab *instance, GtkTreeView *listview, const gchar *uri )
 
337
{
 
338
        GtkTreeModel *model;
 
339
        GtkTreeIter row;
 
340
 
 
341
        model = gtk_tree_view_get_model( listview );
 
342
 
 
343
        gtk_list_store_append(
 
344
                        GTK_LIST_STORE( model ),
 
345
                        &row );
 
346
 
 
347
        gtk_list_store_set(
 
348
                        GTK_LIST_STORE( model ),
 
349
                        &row,
 
350
                        BACKGROUND_URI_COLUMN, uri,
 
351
                        -1 );
 
352
}
 
353
 
 
354
static void
 
355
add_uri_to_folders( NactIBackgroundTab *instance, const gchar *uri )
 
356
{
 
357
        NAObjectAction *action;
 
358
        NAObjectProfile *edited;
 
359
        GSList *folders;
 
360
 
 
361
        g_object_get(
 
362
                        G_OBJECT( instance ),
 
363
                        TAB_UPDATABLE_PROP_EDITED_ACTION, &action,
 
364
                        TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
 
365
                        NULL );
 
366
 
 
367
        folders = na_object_profile_get_folders( edited );
 
368
        folders = g_slist_prepend( folders, ( gpointer ) g_strdup( uri ));
 
369
        na_object_profile_set_folders( edited, folders );
 
370
        na_utils_free_string_list( folders );
 
371
 
 
372
        g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 
373
}
 
374
 
 
375
static GtkTreeView *
 
376
get_folders_treeview( NactIBackgroundTab *instance )
 
377
{
 
378
        GtkWidget *treeview;
 
379
 
 
380
        treeview = base_window_get_widget( BASE_WINDOW( instance ), "FoldersTreeview" );
 
381
        g_assert( GTK_IS_TREE_VIEW( treeview ));
 
382
 
 
383
        return( GTK_TREE_VIEW( treeview ));
 
384
}
 
385
 
 
386
static void
 
387
on_add_folder_clicked( GtkButton *button, NactIBackgroundTab *instance )
 
388
{
 
389
        GtkWidget *dialog;
 
390
        GtkWindow *toplevel;
 
391
        NactApplication *application;
 
392
        NAPivot *pivot;
 
393
        gchar *uri;
 
394
        GtkTreeView *listview;
 
395
 
 
396
        uri = NULL;
 
397
        listview = get_folders_treeview( instance );
 
398
        toplevel = base_window_get_toplevel( BASE_WINDOW( instance ));
 
399
 
 
400
        /* i18n: title of the FileChoose dialog when selecting an URI which
 
401
         * will be comparent to Nautilus 'current_folder'
 
402
         */
 
403
        dialog = gtk_file_chooser_dialog_new( _( "Select a folder" ),
 
404
                        toplevel,
 
405
                        GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
 
406
                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
407
                        GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 
408
                        NULL );
 
409
 
 
410
        application = NACT_APPLICATION( base_window_get_application( BASE_WINDOW( instance )));
 
411
        pivot = nact_application_get_pivot( application );
 
412
 
 
413
        base_iprefs_position_named_window( BASE_WINDOW( instance ), GTK_WINDOW( dialog ), IPREFS_BACKGROUND_DIALOG );
 
414
 
 
415
        uri = na_iprefs_read_string( NA_IPREFS( pivot ), IPREFS_BACKGROUND_URI, "x-nautilus-desktop:///" );
 
416
        if( uri && strlen( uri )){
 
417
                gtk_file_chooser_set_uri( GTK_FILE_CHOOSER( dialog ), uri );
 
418
        }
 
419
        g_free( uri );
 
420
 
 
421
        if( gtk_dialog_run( GTK_DIALOG( dialog )) == GTK_RESPONSE_ACCEPT ){
 
422
                uri = gtk_file_chooser_get_uri( GTK_FILE_CHOOSER( dialog ));
 
423
                na_iprefs_write_string( NA_IPREFS( pivot ), IPREFS_BACKGROUND_URI, uri );
 
424
                add_row( instance, listview, uri );
 
425
                add_uri_to_folders( instance, uri );
 
426
                g_free( uri );
 
427
        }
 
428
 
 
429
        base_iprefs_save_named_window_position( BASE_WINDOW( instance ), GTK_WINDOW( dialog ), IPREFS_BACKGROUND_DIALOG );
 
430
 
 
431
        gtk_widget_destroy( dialog );
 
432
}
 
433
 
 
434
static void
 
435
on_folder_uri_edited( GtkCellRendererText *renderer, const gchar *path, const gchar *text, NactIBackgroundTab *instance )
 
436
{
 
437
        treeview_cell_edited( instance, path, text, BACKGROUND_URI_COLUMN, NULL, NULL );
 
438
}
 
439
 
 
440
static void
 
441
on_folders_selection_changed( GtkTreeSelection *selection, NactIBackgroundTab *instance )
 
442
{
 
443
        GtkWidget *button;
 
444
 
 
445
        button = base_window_get_widget( BASE_WINDOW( instance ), "RemoveFolderButton");
 
446
 
 
447
        gtk_widget_set_sensitive( button, gtk_tree_selection_count_selected_rows( selection ) > 0 );
 
448
}
 
449
 
 
450
static void
 
451
on_remove_folder_clicked( GtkButton *button, NactIBackgroundTab *instance )
 
452
{
 
453
        GtkTreeView *listview;
 
454
        GtkTreeModel *model;
 
455
        GtkTreeSelection *selection;
 
456
        GList *selected_path, *isp;
 
457
        GtkTreePath *path;
 
458
        GtkTreeIter iter;
 
459
        gchar *uri;
 
460
        NAObjectAction *action;
 
461
        NAObjectProfile *edited;
 
462
        GSList *folders;
 
463
 
 
464
        listview = get_folders_treeview( instance );
 
465
        model = gtk_tree_view_get_model( listview );
 
466
        selection = gtk_tree_view_get_selection( listview );
 
467
        selected_path = gtk_tree_selection_get_selected_rows( selection, NULL );
 
468
 
 
469
        for( isp = selected_path ; isp ; isp = isp->next ){
 
470
                path = ( GtkTreePath * ) isp->data;
 
471
                gtk_tree_model_get_iter( model, &iter, path );
 
472
                gtk_tree_model_get( model, &iter, BACKGROUND_URI_COLUMN, &uri, -1 );
 
473
                gtk_list_store_remove( GTK_LIST_STORE( model ), &iter );
 
474
 
 
475
                g_object_get(
 
476
                                G_OBJECT( instance ),
 
477
                                TAB_UPDATABLE_PROP_EDITED_ACTION, &action,
 
478
                                TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
 
479
                                NULL );
 
480
 
 
481
                folders = na_object_profile_get_folders( edited );
 
482
                folders = na_utils_remove_from_string_list( folders, uri );
 
483
                na_object_profile_set_folders( edited, folders );
 
484
 
 
485
                na_utils_free_string_list( folders );
 
486
                g_free( uri );
 
487
 
 
488
                g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 
489
        }
 
490
 
 
491
        g_list_foreach( selected_path, ( GFunc ) gtk_tree_path_free, NULL );
 
492
        g_list_free( selected_path );
 
493
}
 
494
 
 
495
static void
 
496
reset_folders( NactIBackgroundTab *instance )
 
497
{
 
498
        GtkTreeView *listview;
 
499
        GtkTreeModel *model;
 
500
 
 
501
        listview = get_folders_treeview( instance );
 
502
        model = gtk_tree_view_get_model( listview );
 
503
        gtk_list_store_clear( GTK_LIST_STORE( model ));
 
504
}
 
505
 
 
506
static void
 
507
setup_folders( NactIBackgroundTab *instance )
 
508
{
 
509
        NAObjectProfile *edited;
 
510
        GSList *folders, *is;
 
511
        GtkTreeView *listview;
 
512
 
 
513
        listview = get_folders_treeview( instance );
 
514
 
 
515
        g_object_get(
 
516
                        G_OBJECT( instance ),
 
517
                        TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
 
518
                        NULL );
 
519
 
 
520
        folders = na_object_profile_get_folders( edited );
 
521
        for( is = folders ; is ; is = is->next ){
 
522
                add_row( instance, listview, ( const gchar * ) is->data );
 
523
        }
 
524
        na_utils_free_string_list( folders );
 
525
}
 
526
 
 
527
static void
 
528
treeview_cell_edited( NactIBackgroundTab *instance, const gchar *path_string, const gchar *text, gint column, gboolean *state, gchar **old_text )
 
529
{
 
530
        GtkTreeView *listview;
 
531
        GtkTreeModel *model;
 
532
        GtkTreeIter iter;
 
533
        GtkTreePath *path;
 
534
        NAObjectAction *action;
 
535
        NAObjectProfile *edited;
 
536
 
 
537
        listview = get_folders_treeview( instance );
 
538
        model = gtk_tree_view_get_model( listview );
 
539
        path = gtk_tree_path_new_from_string( path_string );
 
540
        gtk_tree_model_get_iter( model, &iter, path );
 
541
        gtk_tree_path_free( path );
 
542
 
 
543
        if( state && old_text ){
 
544
                gtk_tree_model_get( model, &iter, BACKGROUND_URI_COLUMN, old_text, -1 );
 
545
        }
 
546
 
 
547
        gtk_list_store_set( GTK_LIST_STORE( model ), &iter, column, text, -1 );
 
548
 
 
549
        g_object_get(
 
550
                        G_OBJECT( instance ),
 
551
                        TAB_UPDATABLE_PROP_EDITED_ACTION, &action,
 
552
                        TAB_UPDATABLE_PROP_EDITED_PROFILE, &edited,
 
553
                        NULL );
 
554
 
 
555
        na_object_profile_replace_folder_uri( edited, *old_text, text );
 
556
 
 
557
        g_signal_emit_by_name( G_OBJECT( instance ), TAB_UPDATABLE_SIGNAL_ITEM_UPDATED, edited, FALSE );
 
558
}