~ubuntu-branches/ubuntu/hardy/pcmanfm/hardy-backports

« back to all changes in this revision

Viewing changes to src/main.c

  • Committer: Bazaar Package Importer
  • Author(s): J?r?me Guelfucci
  • Date: 2008-07-01 00:40:37 UTC
  • mfrom: (5.1.3 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080701004037-q6pfacskp0xnk10k
Tags: 0.4.3-1~hardy1
Automated backport upload; no source changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
* Initial main.c file generated by Glade. Edit as required.
3
 
* Glade will not overwrite this file.
 
2
* Author: Hong Jen Yee (PCMan) <pcman.tw (AT) gmail.com>, (C) 2006
 
3
*
 
4
* Copyright: See COPYING file that comes with this distribution
 
5
*
4
6
*/
5
7
 
6
8
#ifdef HAVE_CONFIG_H
7
9
#  include <config.h>
8
10
#endif
9
11
 
 
12
/* turn on to debug GDK_THREADS_ENTER/GDK_THREADS_LEAVE related deadlocks */
 
13
#undef _DEBUG_THREAD
 
14
 
 
15
#include "private.h"
 
16
 
10
17
#include <gtk/gtk.h>
11
18
#include <glib.h>
12
19
 
13
20
#include <stdlib.h>
 
21
#include <string.h>
14
22
 
15
23
/* socket is used to keep single instance */
16
24
#include <sys/types.h>
17
25
#include <sys/socket.h>
18
26
#include <sys/un.h>
19
27
 
 
28
#include <signal.h>
 
29
 
20
30
#include "main-window.h"
21
31
 
22
32
#include "vfs-file-info.h"
25
35
 
26
36
#include "vfs-file-monitor.h"
27
37
#include "vfs-volume.h"
 
38
#include "vfs-thumbnail-loader.h"
28
39
 
29
40
#include "ptk-utils.h"
30
 
#include "app-chooser-dialog.h"
 
41
#include "ptk-app-chooser.h"
 
42
#include "ptk-file-properties.h"
 
43
#include "ptk-file-menu.h"
31
44
 
32
 
#include "glade-support.h"
33
45
#include "settings.h"
34
46
 
35
 
static char* init_path = NULL;
 
47
#include "desktop.h"
 
48
 
 
49
typedef enum{
 
50
    CMD_OPEN = 1,
 
51
    CMD_OPEN_TAB,
 
52
    CMD_FILE_PROP,
 
53
    CMD_FILE_MENU,
 
54
    CMD_DAEMON_MODE
 
55
}SocketEvent;
 
56
 
 
57
static gboolean initialized = FALSE;
36
58
 
37
59
static int sock;
38
60
GIOChannel* io_channel = NULL;
39
61
 
 
62
gboolean daemon_mode = FALSE;
 
63
 
 
64
static char* default_files[2] = {NULL, NULL};
 
65
static char** files = NULL;
 
66
static gboolean no_desktop = FALSE;
 
67
static gboolean old_show_desktop = FALSE;
 
68
 
 
69
static gboolean new_tab = FALSE;
 
70
static gboolean file_prop = FALSE;
 
71
static gboolean file_menu = FALSE;
 
72
 
 
73
#ifdef HAVE_HAL
 
74
static char* mount = NULL;
 
75
static char* umount = NULL;
 
76
static char* eject = NULL;
 
77
#endif
 
78
 
 
79
static GOptionEntry opt_entries[] =
 
80
{
 
81
    { "no-desktop", '\0', 0, G_OPTION_ARG_NONE, &no_desktop, N_("Don't show desktop icons."), NULL },
 
82
    { "daemon-mode", 'd', 0, G_OPTION_ARG_NONE, &daemon_mode, N_("Run PCManFM as a daemon"), NULL },
 
83
    { "new-tab", 't', 0, G_OPTION_ARG_NONE, &new_tab, N_("Open folders in new tabs of the last used window instead of creating new windows"), NULL },
 
84
/*    { "file-prop", 'p', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &file_prop, NULL, NULL },
 
85
    { "file-menu", 'n', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &file_menu, NULL, NULL }, */
 
86
#ifdef HAVE_HAL
 
87
    /* hidden arguments used to mount volumes */
 
88
    { "mount", 'm', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &mount, NULL, NULL },
 
89
    { "umount", 'u', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &umount, NULL, NULL },
 
90
    { "eject", 'e', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING, &eject, NULL, NULL },
 
91
#endif
 
92
    {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &files, NULL, N_("[FILE1, FILE2,...]")},
 
93
    { NULL }
 
94
};
 
95
 
 
96
static gboolean single_instance_check();
 
97
static void single_instance_finalize();
 
98
static void get_socket_name( char* buf, int len );
 
99
static gboolean on_socket_event( GIOChannel* ioc, GIOCondition cond, gpointer data );
 
100
 
 
101
static void init_folder();
 
102
static void check_icon_theme();
 
103
 
 
104
static gboolean handle_parsed_commandline_args();
 
105
 
40
106
static FMMainWindow* create_main_window();
41
 
 
42
107
static void open_file( const char* path );
43
108
 
44
 
static gboolean on_socket_event( GIOChannel* ioc,
45
 
                                 GIOCondition cond,
46
 
                                 gpointer data )
 
109
static GList* get_file_info_list( char** files );
 
110
 
 
111
gboolean on_socket_event( GIOChannel* ioc, GIOCondition cond, gpointer data )
47
112
{
48
113
    int client, r;
49
114
    socklen_t addr_len = 0;
50
 
    struct sockaddr_un client_addr =
51
 
        {
52
 
            0
53
 
        };
54
 
    FMMainWindow* main_window;
55
 
    static char path[ PATH_MAX ];
 
115
    struct sockaddr_un client_addr ={ 0 };
 
116
    static char buf[ 1024 ];
 
117
    GString* args;
 
118
    char** file;
 
119
    SocketEvent cmd;
56
120
 
57
121
    if ( cond & G_IO_IN )
58
122
    {
59
123
        client = accept( g_io_channel_unix_get_fd( ioc ), (struct sockaddr *)&client_addr, &addr_len );
60
124
        if ( client != -1 )
61
125
        {
62
 
            r = read( client, path, PATH_MAX );
63
 
            if ( r != -1 )
64
 
            {
65
 
                path[ r ] = '\0';
66
 
                GDK_THREADS_ENTER();
67
 
                if ( g_file_test( path, G_FILE_TEST_IS_DIR ) )
68
 
                {
69
 
                    main_window = create_main_window();
70
 
                    fm_main_window_add_new_tab( main_window, path,
71
 
                                                appSettings.showSidePane,
72
 
                                                appSettings.sidePaneMode );
73
 
                    gtk_window_present( GTK_WINDOW(main_window) );
74
 
                }
75
 
                else
76
 
                {
77
 
                    open_file( path );
78
 
                }
79
 
                GDK_THREADS_LEAVE();
80
 
            }
 
126
            args = g_string_new_len( NULL, 2048 );
 
127
            while( (r = read( client, buf, sizeof(buf) )) > 0 )
 
128
                g_string_append_len( args, buf, r);
81
129
            shutdown( client, 2 );
82
130
            close( client );
 
131
 
 
132
            new_tab = FALSE;
 
133
            file_prop = FALSE;
 
134
            file_menu = FALSE;
 
135
 
 
136
            switch( args->str[0] )
 
137
            {
 
138
            case CMD_OPEN_TAB:
 
139
                new_tab = TRUE;
 
140
                break;
 
141
            case CMD_FILE_PROP:
 
142
                file_prop = TRUE;
 
143
                break;
 
144
            case CMD_FILE_MENU:
 
145
                file_menu = TRUE;
 
146
                break;
 
147
            case CMD_DAEMON_MODE:
 
148
                daemon_mode = TRUE;
 
149
                g_string_free( args, TRUE );
 
150
                return TRUE;
 
151
            }
 
152
 
 
153
            if( args->str[ 1 ] )
 
154
                files = g_strsplit( args->str + 1, "\n", 0 );
 
155
            else
 
156
                files = NULL;
 
157
            g_string_free( args, TRUE );
 
158
 
 
159
            GDK_THREADS_ENTER();
 
160
 
 
161
            if( files )
 
162
            {
 
163
                for( file = files; *file; ++file )
 
164
                {
 
165
                    if( ! **file )  /* remove empty string at tail */
 
166
                        *file = NULL;
 
167
                }
 
168
            }
 
169
            handle_parsed_commandline_args();
 
170
 
 
171
            GDK_THREADS_LEAVE();
83
172
        }
84
173
    }
 
174
 
85
175
    return TRUE;
86
176
}
87
177
 
88
 
static void get_socket_name( char* buf, int len )
 
178
void get_socket_name( char* buf, int len )
89
179
{
90
 
    g_snprintf( buf, len, "/tmp/.pcmanfm-socket%s-%s", gdk_get_display(), g_get_user_name() );
 
180
    char* dpy = gdk_get_display();
 
181
    g_snprintf( buf, len, "/tmp/.pcmanfm-socket%s-%s", dpy, g_get_user_name() );
 
182
    g_free( dpy );
91
183
}
92
184
 
93
 
static void single_instance_init()
 
185
gboolean single_instance_check()
94
186
{
95
187
    struct sockaddr_un addr;
96
188
    int addr_len;
106
198
    addr.sun_family = AF_UNIX;
107
199
    get_socket_name( addr.sun_path, sizeof( addr.sun_path ) );
108
200
#ifdef SUN_LEN
109
 
 
110
201
    addr_len = SUN_LEN( &addr );
111
202
#else
112
203
 
113
204
    addr_len = strlen( addr.sun_path ) + sizeof( addr.sun_family );
114
205
#endif
115
206
 
 
207
    /* try to connect to existing instance */
116
208
    if ( connect( sock, ( struct sockaddr* ) & addr, addr_len ) == 0 )
117
209
    {
118
210
        /* connected successfully */
119
 
        write( sock, init_path, strlen( init_path ) );
 
211
        char** file;
 
212
        char cmd = CMD_OPEN;
 
213
 
 
214
        if( daemon_mode )
 
215
            cmd = CMD_DAEMON_MODE;
 
216
        else if( new_tab )
 
217
            cmd = CMD_OPEN_TAB;
 
218
        else if( file_prop )
 
219
            cmd = CMD_FILE_PROP;
 
220
        else if( file_menu )
 
221
            cmd = CMD_FILE_MENU;
 
222
 
 
223
        write( sock, &cmd, sizeof(char) );
 
224
 
 
225
        if( files )
 
226
        {
 
227
            for( file = files; *file; ++file )
 
228
            {
 
229
                write( sock, *file, strlen( *file ) );
 
230
                write( sock, "\n", 1 );
 
231
            }
 
232
        }
 
233
 
120
234
        shutdown( sock, 2 );
121
235
        close( sock );
122
 
        gdk_notify_startup_complete();
123
 
 
124
236
        ret = 0;
125
237
        goto _exit;
126
238
    }
127
239
 
128
 
    /* There is no existing server. So, we are in the first instance. */
 
240
    /* There is no existing server, and we are in the first instance. */
129
241
    unlink( addr.sun_path ); /* delete old socket file if it exists. */
130
242
    reuse = 1;
131
243
    ret = setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof( reuse ) );
150
262
    return ;
151
263
 
152
264
_exit:
153
 
    g_free( init_path );
154
 
    init_path = NULL;
 
265
 
 
266
    gdk_notify_startup_complete();
155
267
    exit( ret );
156
268
}
157
269
 
158
 
static void single_instance_finalize()
 
270
void single_instance_finalize()
159
271
{
160
272
    char lock_file[ 256 ];
161
273
 
171
283
{
172
284
    FMMainWindow * main_window = FM_MAIN_WINDOW(fm_main_window_new ());
173
285
    gtk_window_set_default_size( GTK_WINDOW( main_window ),
174
 
                                 appSettings.width, appSettings.height );
 
286
                                 app_settings.width, app_settings.height );
 
287
    if ( app_settings.maximized )
 
288
    {
 
289
        gtk_window_maximize( GTK_WINDOW( main_window ) );
 
290
    }
175
291
    gtk_widget_show ( GTK_WIDGET( main_window ) );
176
292
    return main_window;
177
293
}
178
294
 
179
 
static void check_icon_theme()
 
295
void check_icon_theme()
180
296
{
181
297
    GtkSettings * settings;
182
298
    char* theme;
215
331
    g_free( theme );
216
332
}
217
333
 
218
 
int
219
 
main ( int argc, char *argv[] )
220
 
{
221
 
    FMMainWindow * main_window;
222
 
    GtkSettings *settings;
223
 
    gboolean is_init_path_dir;
224
 
 
225
 
    load_settings();
226
 
 
227
 
    /* Use multithreading */
228
 
    g_thread_init( NULL );
229
 
    gdk_threads_init ();
230
 
 
231
 
    gtk_init ( &argc, &argv );
232
 
 
233
 
    /* FIXME: Support opening mutiple dirs|files from command line */
234
 
 
235
 
    /* FIXME: support command line options */
236
 
    --argc;
237
 
    /* Add check for -- to skip unknown options */
238
 
    if ( argc > 0 && *argv[ argc ] && strncmp( argv[ argc ], "--", 2 ) )
239
 
    {
240
 
        /* If this is a URI */
241
 
        if ( 0 == g_ascii_strncasecmp( argv[ argc ], "file:", 5 ) )
242
 
            init_path = g_filename_from_uri( argv[ argc ], NULL, NULL );
243
 
        else
244
 
            init_path = vfs_file_resolve_path( NULL, argv[ argc ] );
245
 
        is_init_path_dir = g_file_test( init_path, G_FILE_TEST_IS_DIR );
246
 
    }
247
 
    else
248
 
    {
249
 
        init_path = g_strdup( g_get_home_dir() );
250
 
        is_init_path_dir = TRUE;
251
 
    }
252
 
 
253
 
    /* if ( appSettings.singleInstance ) */
254
 
    single_instance_init();
 
334
#ifdef _DEBUG_THREAD
 
335
 
 
336
G_LOCK_DEFINE(gdk_lock);
 
337
void debug_gdk_threads_enter (const char* message)
 
338
{
 
339
    g_debug( "Thread %p tries to get GDK lock: %s", g_thread_self (), message );
 
340
    G_LOCK(gdk_lock);
 
341
    g_debug( "Thread %p got GDK lock: %s", g_thread_self (), message );
 
342
}
 
343
 
 
344
static void _debug_gdk_threads_enter ()
 
345
{
 
346
    debug_gdk_threads_enter( "called from GTK+ internal" );
 
347
}
 
348
 
 
349
void debug_gdk_threads_leave( const char* message )
 
350
{
 
351
    g_debug( "Thread %p tries to release GDK lock: %s", g_thread_self (), message );
 
352
    G_LOCK(gdk_lock);
 
353
    g_debug( "Thread %p released GDK lock: %s", g_thread_self (), message );
 
354
}
 
355
 
 
356
static void _debug_gdk_threads_leave()
 
357
{
 
358
    debug_gdk_threads_leave( "called from GTK+ internal" );
 
359
}
 
360
#endif
 
361
 
 
362
void init_folder()
 
363
{
 
364
    if( G_LIKELY(initialized) )
 
365
        return;
 
366
 
 
367
    app_settings.bookmarks = ptk_bookmarks_get();
 
368
 
 
369
    vfs_volume_init();
 
370
    vfs_thumbnail_init();
 
371
 
 
372
    vfs_mime_type_set_icon_size( app_settings.big_icon_size,
 
373
                                 app_settings.small_icon_size );
 
374
    vfs_file_info_set_thumbnail_size( app_settings.big_icon_size,
 
375
                                      app_settings.small_icon_size );
 
376
 
 
377
    check_icon_theme();
 
378
    initialized = TRUE;
 
379
}
 
380
 
 
381
#ifdef HAVE_HAL
 
382
 
 
383
/* FIXME: Currently, this cannot be supported without HAL */
 
384
 
 
385
static int handle_mount( char** argv )
 
386
{
 
387
    gboolean success;
 
388
    vfs_volume_init();
 
389
    if( mount )
 
390
        success = vfs_volume_mount_by_udi( mount, NULL );
 
391
    else if( umount )
 
392
        success = vfs_volume_umount_by_udi( umount, NULL );
 
393
    else /* if( eject ) */
 
394
        success = vfs_volume_eject_by_udi( eject, NULL );
 
395
    vfs_volume_finalize();
 
396
    return success ? 0 : 1;
 
397
}
 
398
#endif
 
399
 
 
400
GList* get_file_info_list( char** file_paths )
 
401
{
 
402
    GList* file_list = NULL;
 
403
    char** file;
 
404
    VFSFileInfo* fi;
 
405
 
 
406
    for( file = file_paths; *file; ++file )
 
407
    {
 
408
        fi = vfs_file_info_new();
 
409
        if( vfs_file_info_get( fi, *file, NULL ) )
 
410
            file_list = g_list_append( file_list, fi );
 
411
        else
 
412
            vfs_file_info_unref( fi );
 
413
    }
 
414
 
 
415
    return file_list;
 
416
}
 
417
 
 
418
gboolean delayed_popup( GtkWidget* popup )
 
419
{
 
420
    GDK_THREADS_ENTER();
 
421
 
 
422
    gtk_menu_popup( GTK_MENU( popup ), NULL, NULL,
 
423
                    NULL, NULL, 0, gtk_get_current_event_time() );
 
424
 
 
425
    GDK_THREADS_LEAVE();
 
426
 
 
427
    return FALSE;
 
428
}
 
429
 
 
430
gboolean handle_parsed_commandline_args()
 
431
{
 
432
    FMMainWindow * main_window = NULL;
 
433
    char** file;
 
434
 
 
435
    /* If no files are specified, open home dir by defualt. */
 
436
    if( G_LIKELY( ! files ) )
 
437
    {
 
438
        files = default_files;
 
439
        files[0] = (char *) g_get_home_dir();
 
440
    }
 
441
 
 
442
    /* get the last active window, if available */
 
443
    if( new_tab )
 
444
    {
 
445
        main_window = fm_main_window_get_last_active();
 
446
    }
 
447
    else if( file_menu )    /* show popup menu for files */
 
448
    {
 
449
        /* FIXME: This doesn't work properly */
 
450
        GtkMenu* popup;
 
451
        GList* file_list;
 
452
 
 
453
        if( ! daemon_mode )
 
454
        {
 
455
            g_warning( "--file-menu is only availble when pcmanfm daemon is running." );
 
456
            return FALSE;
 
457
        }
 
458
 
 
459
        file_list = get_file_info_list( files );
 
460
 
 
461
        if( file_list )
 
462
        {
 
463
            char* dir_name = g_path_get_dirname( files[0] );
 
464
            popup = ptk_file_menu_new(
 
465
                        files[0], (VFSFileInfo*)file_list->data,
 
466
                        dir_name,
 
467
                        file_list, NULL );
 
468
            /* FIXME: I have no idea why this crap is needed.
 
469
             *  Without this delay, the menu will fail to popup. */
 
470
            g_timeout_add( 150, (GSourceFunc)delayed_popup, popup );
 
471
        }
 
472
 
 
473
        if( files != default_files )
 
474
            g_free( files );
 
475
        files = NULL;
 
476
        return TRUE;
 
477
    }
 
478
    else if( file_prop )    /* show file properties dialog */
 
479
    {
 
480
        GList* file_list;
 
481
 
 
482
        file_list = get_file_info_list( files );
 
483
        if( file_list )
 
484
        {
 
485
            GtkWidget* dlg;
 
486
            char* dir_name = g_path_get_dirname( files[0] );
 
487
            dlg = file_properties_dlg_new( NULL, dir_name, file_list );
 
488
            gtk_dialog_run( dlg );
 
489
            gtk_widget_destroy( dlg );
 
490
            g_free( dir_name );
 
491
 
 
492
            if( files != default_files )
 
493
                g_free( files );
 
494
            return FALSE;
 
495
        }
 
496
    }
 
497
 
 
498
    /* open files passed in command line arguments */
 
499
    for( file = files; *file; ++file )
 
500
    {
 
501
        char* file_path, *real_path;
 
502
 
 
503
        if( ! **file )  /* skip empty string */
 
504
            continue;
 
505
 
 
506
        if( g_str_has_prefix( *file, "file:" ) ) /* It's a URI */
 
507
        {
 
508
            file_path = g_filename_from_uri( *file, NULL, NULL );
 
509
            g_free( *file );
 
510
            *file = file_path;
 
511
        }
 
512
        else
 
513
            file_path = *file;
 
514
 
 
515
        real_path = vfs_file_resolve_path( NULL, file_path );
 
516
        if( g_file_test( real_path, G_FILE_TEST_IS_DIR ) )
 
517
        {
 
518
            if( G_UNLIKELY( ! main_window ) )   /* create main window if needed */
 
519
            {
 
520
                /* initialize things required by folder view... */
 
521
                if( G_UNLIKELY( ! daemon_mode ) )
 
522
                    init_folder();
 
523
                main_window = create_main_window();
 
524
            }
 
525
            fm_main_window_add_new_tab( main_window, real_path,
 
526
                                        app_settings.show_side_pane,
 
527
                                        app_settings.side_pane_mode );
 
528
        }
 
529
        else
 
530
        {
 
531
            open_file( real_path );
 
532
        }
 
533
        g_free( real_path );
 
534
    }
 
535
 
 
536
    if( files != default_files )
 
537
        g_strfreev( files );
 
538
 
 
539
    files = NULL;
 
540
 
 
541
    return TRUE;
 
542
}
 
543
 
 
544
int main ( int argc, char *argv[] )
 
545
{
 
546
    gboolean run = FALSE;
 
547
    GError* err = NULL;
255
548
 
256
549
#ifdef ENABLE_NLS
257
550
    bindtextdomain ( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR );
259
552
    textdomain ( GETTEXT_PACKAGE );
260
553
#endif
261
554
 
 
555
    /* Initialize multithreading
 
556
         No matter we use threads or not, it's safer to initialize this earlier. */
 
557
#ifdef _DEBUG_THREAD
 
558
    gdk_threads_set_lock_functions(_debug_gdk_threads_enter, _debug_gdk_threads_leave);
 
559
#endif
 
560
    g_thread_init( NULL );
 
561
    gdk_threads_init ();
 
562
 
 
563
    /* initialize GTK+ and parse the command line arguments */
 
564
    if( G_UNLIKELY( ! gtk_init_with_args( &argc, &argv, "", opt_entries, GETTEXT_PACKAGE, &err ) ) )
 
565
        return 1;
 
566
 
 
567
#if HAVE_HAL
 
568
    /* If the user wants to mount/umount/eject a device */
 
569
    if( G_UNLIKELY( mount || umount || eject ) )
 
570
        return handle_mount( argv );
 
571
#endif
 
572
 
 
573
    /* ensure that there is only one instance of pcmanfm.
 
574
         if there is an existing instance, command line arguments
 
575
         will be passed to the existing instance, and exit() will be called here.  */
 
576
    single_instance_check( argc - 1, argv + 1 );
 
577
 
 
578
    load_settings();    /* load config file */
 
579
 
 
580
    /* initialize the file alteration monitor */
 
581
    if( G_UNLIKELY( ! vfs_file_monitor_init() ) )
 
582
    {
 
583
        ptk_show_error( NULL, _("Error"), _("Error: Unable to establish connection with FAM.\n\nDo you have \"FAM\" or \"Gamin\" installed and running?") );
 
584
        vfs_file_monitor_clean();
 
585
        free_settings();
 
586
        return 1;
 
587
    }
 
588
 
 
589
    /* check if the filename encoding is UTF-8 */
262
590
    vfs_file_info_set_utf8_filename( g_get_filename_charsets( NULL ) );
 
591
 
 
592
    /* Initialize our mime-type system */
263
593
    vfs_mime_type_init();
264
594
 
265
 
    if ( ! is_init_path_dir )
266
 
    {
267
 
        open_file( init_path );
268
 
        g_free( init_path );
269
 
        return 0;
270
 
    }
271
 
 
272
 
    vfs_volume_init();
273
 
 
274
 
    vfs_mime_type_set_icon_size( appSettings.bigIconSize,
275
 
                                 appSettings.smallIconSize );
276
 
    vfs_file_info_set_thumbnail_size( appSettings.bigIconSize,
277
 
                                      appSettings.smallIconSize );
278
 
 
279
 
    check_icon_theme();
280
 
 
281
 
    if( appSettings.showDesktop )
282
 
        fm_desktop_init();
 
595
    /* temporarily turn off desktop if needed */
 
596
    if( G_LIKELY( no_desktop ) )
 
597
    {
 
598
        /* No matter what the value of show_desktop is, we don't showdesktop icons
 
599
         * if --no-desktop argument is passed by the users. */
 
600
        old_show_desktop = app_settings.show_desktop;
 
601
        /* This config value will be restored before saving config files, if needed. */
 
602
        app_settings.show_desktop = FALSE;
 
603
    }
 
604
 
 
605
    /* handle the parsed result of command line args */
 
606
    if( daemon_mode || app_settings.show_desktop )
 
607
    {
 
608
        init_folder();
 
609
        run = TRUE; /* we always need to run the main loop for daemon mode */
 
610
 
 
611
        /* FIXME: are these necessary?? */
 
612
        signal( SIGPIPE, SIG_IGN );
 
613
        signal( SIGHUP, gtk_main_quit );
 
614
        signal( SIGINT, gtk_main_quit );
 
615
        signal( SIGTERM, gtk_main_quit );
 
616
    }
283
617
    else
 
618
        run = handle_parsed_commandline_args();
 
619
 
 
620
    if( app_settings.show_desktop )
284
621
    {
285
 
        main_window = create_main_window();
286
 
        fm_main_window_add_new_tab( main_window, init_path,
287
 
                                    appSettings.showSidePane,
288
 
                                    appSettings.sidePaneMode );
 
622
        fm_turn_on_desktop_icons();
289
623
    }
290
 
    g_free( init_path );
291
 
    init_path = NULL;
292
 
 
293
 
    gtk_main ();
294
 
 
295
 
    /* if ( appSettings.singleInstance ) */
 
624
 
 
625
    if( run )   /* run the main loop */
 
626
        gtk_main();
 
627
 
296
628
    single_instance_finalize();
297
629
 
298
 
    save_settings();
 
630
    if( app_settings.show_desktop )
 
631
        fm_turn_off_desktop_icons();
 
632
 
 
633
    if( no_desktop )    /* desktop icons is temporarily supressed */
 
634
    {
 
635
        if( old_show_desktop )  /* restore original settings */
 
636
        {
 
637
            old_show_desktop = app_settings.show_desktop;
 
638
            app_settings.show_desktop = TRUE;
 
639
        }
 
640
    }
 
641
 
 
642
    if( run )
 
643
        save_settings();    /* write config file */
 
644
 
299
645
    free_settings();
300
646
 
301
 
    vfs_volume_clean();
 
647
    vfs_volume_finalize();
302
648
    vfs_mime_type_clean();
303
649
    vfs_file_monitor_clean();
304
650
 
305
 
    if( appSettings.showDesktop )
306
 
        fm_desktop_cleanup();
307
 
 
308
651
    return 0;
309
652
}
310
653
 
319
662
 
320
663
    if ( ! g_file_test( path, G_FILE_TEST_EXISTS ) )
321
664
    {
322
 
        ptk_show_error( NULL, _( "File doesn't exist" ) );
 
665
        ptk_show_error( NULL, _("Error"), _( "File doesn't exist" ) );
323
666
        return ;
324
667
    }
325
668
 
340
683
        VFSAppDesktop* app;
341
684
        GList* files;
342
685
 
343
 
        app_name = ptk_choose_app_for_mime_type( NULL, mime_type );
 
686
        app_name = (char *) ptk_choose_app_for_mime_type( NULL, mime_type );
344
687
        if ( app_name )
345
688
        {
346
689
            app = vfs_app_desktop_new( app_name );
347
690
            if ( ! vfs_app_desktop_get_exec( app ) )
348
691
                app->exec = g_strdup( app_name ); /* This is a command line */
349
 
            files = g_list_prepend( NULL, path );
 
692
            files = g_list_prepend( NULL, (gpointer) path );
350
693
            opened = vfs_app_desktop_open_files( gdk_screen_get_default(),
351
694
                                                 NULL, app, files, &err );
352
695
            g_free( files->data );
370
713
        disp_path = g_filename_display_name( path );
371
714
        msg = g_strdup_printf( _( "Unable to open file:\n\"%s\"\n%s" ), disp_path, error_msg );
372
715
        g_free( disp_path );
373
 
        ptk_show_error( NULL, msg );
 
716
        ptk_show_error( NULL, _("Error"), msg );
374
717
        g_free( msg );
375
718
        if ( err )
376
719
            g_error_free( err );