l10n: Punjabi Translation Added
[lxde/pcmanfm.git] / src / pcmanfm.c
CommitLineData
b6e3c554
HJYP
1/*
2 * pcmanfm.c
d3451adb 3 *
7b7d923f 4 * Copyright 2009 - 2010 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
d3451adb 5 *
b6e3c554
HJYP
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
d3451adb 10 *
b6e3c554
HJYP
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
d3451adb 15 *
b6e3c554
HJYP
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
08e70fea 22#ifdef HAVE_CONFIG_H
b6e3c554 23#include <config.h>
08e70fea
HJYP
24#endif
25
b6e3c554
HJYP
26#include <gtk/gtk.h>
27#include <stdio.h>
f8f2bfad
HJYP
28#include <glib/gi18n.h>
29
30#include <stdlib.h>
31#include <string.h>
32/* socket is used to keep single instance */
33#include <sys/types.h>
f8f2bfad
HJYP
34#include <signal.h>
35#include <unistd.h> /* for getcwd */
b6e3c554 36
20c0bc9a 37#include <libfm/fm-gtk.h>
4d55886c 38#include "app-config.h"
b6e3c554 39#include "main-win.h"
8505a8ef 40#include "desktop.h"
71f82759 41#include "volume-manager.h"
c5fccf1d 42#include "pref.h"
df6826e0 43#include "pcmanfm.h"
cc448d7f 44#include "single-inst.h"
f8f2bfad 45
94435bc3
HJYP
46static int signal_pipe[2] = {-1, -1};
47
f8f2bfad
HJYP
48gboolean daemon_mode = FALSE;
49
f8f2bfad 50static char** files_to_open = NULL;
cc448d7f 51static int n_files_to_open = 0;
f970e846 52static char* profile = NULL;
f8f2bfad
HJYP
53static gboolean no_desktop = FALSE;
54static gboolean show_desktop = FALSE;
55static gboolean desktop_off = FALSE;
56static gboolean desktop_running = FALSE;
107cdb22 57/* static gboolean new_tab = FALSE; */
f8f2bfad
HJYP
58static int show_pref = 0;
59static gboolean desktop_pref = FALSE;
60static char* set_wallpaper = NULL;
107cdb22 61static char* wallpaper_mode = NULL;
f8f2bfad 62static gboolean find_files = FALSE;
5b890032 63static char* ipc_cwd = NULL;
f8f2bfad
HJYP
64
65static int n_pcmanfm_ref = 0;
66
67static GOptionEntry opt_entries[] =
8505a8ef 68{
107cdb22 69 /* { "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 }, */
a48f9fc8 70 { "profile", 'p', 0, G_OPTION_ARG_STRING, &profile, N_("Name of configuration profile"), "<profile name>" },
f8f2bfad
HJYP
71 { "desktop", '\0', 0, G_OPTION_ARG_NONE, &show_desktop, N_("Launch desktop manager"), NULL },
72 { "desktop-off", '\0', 0, G_OPTION_ARG_NONE, &desktop_off, N_("Turn off desktop manager if it's running"), NULL },
f8f2bfad 73 { "daemon-mode", 'd', 0, G_OPTION_ARG_NONE, &daemon_mode, N_("Run PCManFM as a daemon"), NULL },
f8f2bfad 74 { "desktop-pref", '\0', 0, G_OPTION_ARG_NONE, &desktop_pref, N_("Open desktop preference dialog"), NULL },
f970e846 75 { "set-wallpaper", 'w', 0, G_OPTION_ARG_FILENAME, &set_wallpaper, N_("Set desktop wallpaper"), N_("<image file>") },
107cdb22 76 { "wallpaper-mode", '\0', 0, G_OPTION_ARG_STRING, &wallpaper_mode, N_("Set mode of desktop wallpaper. <mode>=(color|stretch|fit|center|tile)"), N_("<mode>") },
a48f9fc8 77 { "show-pref", '\0', 0, G_OPTION_ARG_INT, &show_pref, N_("Open preference dialog. 'n' is number of the page you want to show (1, 2, 3...)."), "n" },
1d071341 78 /* { "find-files", 'f', 0, G_OPTION_ARG_NONE, &find_files, N_("Open Find Files utility"), NULL }, */
f970e846 79 { "no-desktop", '\0', 0, G_OPTION_ARG_NONE, &no_desktop, N_("No function. Just to be compatible with nautilus"), NULL },
f8f2bfad
HJYP
80 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &files_to_open, NULL, N_("[FILE1, FILE2,...]")},
81 { NULL }
82};
83
cc448d7f
HJYP
84/* single instance command id */
85enum {
86 CMD_INVALID,
87 CMD_CWD,
88 CMD_PROFILE,
89 CMD_DESKTOP,
90 CMD_DESKTOP_OFF,
91 CMD_DAEMON_MODE,
92 CMD_DESKTOP_PREF,
93 CMD_SET_WALLPAPER,
94 CMD_WALLPAPER_MODE,
95 CMD_SHOW_PREF,
96 CMD_FILES_TO_OPEN,
97 CMD_EOF
98};
99
107cdb22
HJYP
100static const char* valid_wallpaper_modes[] = {"color", "stretch", "fit", "center", "tile"};
101
f8f2bfad 102static gboolean pcmanfm_run();
b6e3c554 103
94435bc3
HJYP
104/* it's not safe to call gtk+ functions in unix signal handler
105 * since the process is interrupted here and the state of gtk+ is unpredictable. */
106static void unix_signal_handler(int sig_num)
107{
108 /* postpond the signal handling by using a pipe */
109 write(signal_pipe[1], &sig_num, sizeof(sig_num));
110}
111
112static gboolean on_unix_signal(GIOChannel* ch, GIOCondition cond, gpointer user_data)
113{
114 int sig_num;
115 g_io_channel_read_chars(ch, &sig_num, 1, NULL, NULL);
116 switch(sig_num)
117 {
118 case SIGTERM:
119 default:
120 gtk_main_quit();
121 }
122 return TRUE;
123}
124
cc448d7f
HJYP
125static gboolean on_single_inst_command(int cmd, SingleInstCmdData* data)
126{
127 switch(cmd)
128 {
129 case CMD_CWD:
130 g_free(ipc_cwd);
131 ipc_cwd = single_inst_get_str(data, NULL);
132 break;
133 case CMD_PROFILE:
134 /* Not supported */
135 break;
136 case CMD_DESKTOP:
137 single_inst_get_bool(data, &show_desktop);
138 break;
139 case CMD_DESKTOP_OFF:
140 single_inst_get_bool(data, &desktop_off);
141 break;
142 case CMD_DAEMON_MODE:
143 /* Not supported */
144 break;
145 case CMD_DESKTOP_PREF:
146 single_inst_get_bool(data, &desktop_pref);
147 break;
148 case CMD_SET_WALLPAPER:
149 g_free(set_wallpaper);
150 set_wallpaper = single_inst_get_str(data, NULL);
151 break;
152 case CMD_WALLPAPER_MODE:
153 g_free(wallpaper_mode);
154 wallpaper_mode = single_inst_get_str(data, NULL);
155 break;
156 case CMD_SHOW_PREF:
157 single_inst_get_int(data, &show_pref);
158 break;
159 case CMD_FILES_TO_OPEN:
160 {
161 g_strfreev(files_to_open);
162 n_files_to_open = 0;
163 files_to_open = single_inst_get_strv(data, &n_files_to_open);
164 }
165 break;
166 case CMD_EOF:
167 {
168 int i;
169 /* canonicalize filename if needed. */
170 for(i = 0; i < n_files_to_open; ++i)
171 {
172 char* file = files_to_open[i];
173 char* scheme = g_uri_parse_scheme(file);
174 if(scheme) /* a valid URI */
175 {
176 /* FIXME: should we canonicalize URIs? and how about file:///? */
177 g_free(scheme);
178 }
179 else /* a file path */
180 {
181 files_to_open[i] = fm_canonicalize_filename(file, ipc_cwd);
182 g_free(file);
183 }
184 }
185
186 /* handle the parsed result and run the main program */
187 pcmanfm_run();
188 }
189 break;
190 }
191 return TRUE;
192}
193
194/* we're not the first instance. pass the argv to the existing one. */
195static void pass_args_to_existing_instance()
196{
197 /* send our current working dir to existing instance via IPC. */
198 ipc_cwd = g_get_current_dir();
199 single_inst_send_str(CMD_CWD, ipc_cwd);
200 g_free(ipc_cwd);
201
202 single_inst_send_bool(CMD_DESKTOP, show_desktop);
203 single_inst_send_bool(CMD_DESKTOP_OFF, desktop_off);
204 single_inst_send_bool(CMD_DESKTOP_PREF, desktop_pref);
205 single_inst_send_str(CMD_SET_WALLPAPER, set_wallpaper);
206 single_inst_send_str(CMD_WALLPAPER_MODE, wallpaper_mode);
207 single_inst_send_int(CMD_SHOW_PREF, show_pref);
208 /* single_inst_send_bool(CMD_FIND_FILES, find_files); */
209
210 single_inst_send_strv(CMD_FILES_TO_OPEN, files_to_open);
211 single_inst_send_bool(CMD_EOF, TRUE); /* all args have been sent. */
212
213 single_inst_finalize();
214}
215
b6e3c554
HJYP
216int main(int argc, char** argv)
217{
4d55886c 218 FmConfig* config;
f8f2bfad
HJYP
219 GError* err = NULL;
220
221#ifdef ENABLE_NLS
222 bindtextdomain ( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR );
223 bind_textdomain_codeset ( GETTEXT_PACKAGE, "UTF-8" );
224 textdomain ( GETTEXT_PACKAGE );
225#endif
226
227 /* initialize GTK+ and parse the command line arguments */
228 if(G_UNLIKELY(!gtk_init_with_args(&argc, &argv, "", opt_entries, GETTEXT_PACKAGE, &err)))
229 {
230 g_printf("%s\n", err->message);
c5fccf1d 231 g_error_free(err);
f8f2bfad
HJYP
232 return 1;
233 }
234
cc448d7f
HJYP
235 /* ensure that there is only one instance of pcmanfm. */
236 switch(single_inst_init("pcmanfm", on_single_inst_command))
237 {
238 case SINGLE_INST_CLIENT: /* we're not the first instance. */
239 pass_args_to_existing_instance();
240 gdk_notify_startup_complete();
241 return 0;
242 case SINGLE_INST_ERROR: /* error happened. */
243 single_inst_finalize();
244 return 1;
245 }
f8f2bfad 246
94435bc3
HJYP
247 if(pipe(signal_pipe) == 0)
248 {
249 GIOChannel* ch = g_io_channel_unix_new(signal_pipe[0]);
250 g_io_add_watch(ch, G_IO_IN|G_IO_PRI, (GIOFunc)on_unix_signal, NULL);
251 g_io_channel_unref(ch);
252
253 /* intercept signals */
254 signal( SIGPIPE, SIG_IGN );
255 /* signal( SIGHUP, gtk_main_quit ); */
256 signal( SIGTERM, unix_signal_handler );
257 }
b6e3c554 258
f970e846 259 config = fm_app_config_new(); /* this automatically load libfm config file. */
17d12cc9 260
f970e846 261 /* load pcmanfm-specific config file */
17d12cc9 262 fm_app_config_load_from_profile(FM_APP_CONFIG(config), profile);
f970e846 263
94435bc3 264 fm_gtk_init(config);
b6e3c554 265
f8f2bfad
HJYP
266 /* the main part */
267 if(pcmanfm_run())
268 {
71f82759 269 fm_volume_manager_init();
94435bc3 270 gtk_main();
f8f2bfad
HJYP
271 if(desktop_running)
272 fm_desktop_manager_finalize();
f8f2bfad 273 fm_config_save(config, NULL); /* save libfm config */
17d12cc9 274 fm_app_config_save_profile((FmAppConfig*)config, profile); /* save pcmanfm config */
71f82759 275 fm_volume_manager_finalize();
f8f2bfad 276 }
cc448d7f
HJYP
277
278 single_inst_finalize();
8505a8ef 279
f8f2bfad
HJYP
280 fm_gtk_finalize();
281 g_object_unref(config);
94435bc3 282 return 0;
f8f2bfad
HJYP
283}
284
ee12f37e
HJYP
285static FmJobErrorAction on_file_info_job_error(FmFileInfoJob* job, GError* err, FmJobErrorSeverity severity, gpointer user_data)
286{
16a17d6b 287 if(err->domain == G_IO_ERROR)
ee12f37e 288 {
16a17d6b
HJYP
289 if(err->code == G_IO_ERROR_NOT_MOUNTED)
290 {
291 if(fm_mount_path(NULL, fm_file_info_job_get_current(job), TRUE))
292 return FM_JOB_RETRY;
293 }
294 else if(err->code == G_IO_ERROR_FAILED_HANDLED)
295 return FM_JOB_CONTINUE;
ee12f37e 296 }
16a17d6b 297 fm_show_error(NULL, err->message);
ee12f37e
HJYP
298 return FM_JOB_CONTINUE;
299}
f8f2bfad
HJYP
300
301gboolean pcmanfm_run()
302{
303 gboolean ret = TRUE;
f8f2bfad 304
f8f2bfad
HJYP
305 if(!files_to_open)
306 {
307 /* Launch desktop manager */
308 if(show_desktop)
309 {
310 if(!desktop_running)
311 {
312 fm_desktop_manager_init();
313 desktop_running = TRUE;
314 }
19abb8bf 315 show_desktop = FALSE;
f8f2bfad
HJYP
316 return TRUE;
317 }
318 else if(desktop_off)
319 {
320 if(desktop_running)
321 {
322 desktop_running = FALSE;
323 fm_desktop_manager_finalize();
324 }
19abb8bf 325 desktop_off = FALSE;
f8f2bfad
HJYP
326 return FALSE;
327 }
328 else if(show_pref > 0)
329 {
c5fccf1d
HJYP
330 fm_edit_preference(NULL, show_pref - 1);
331 show_pref = 0;
f8f2bfad
HJYP
332 return TRUE;
333 }
334 else if(desktop_pref)
335 {
c5fccf1d 336 fm_desktop_preference();
19abb8bf 337 desktop_pref = FALSE;
f8f2bfad
HJYP
338 return TRUE;
339 }
107cdb22 340 else
f8f2bfad 341 {
107cdb22
HJYP
342 gboolean need_to_exit = (wallpaper_mode || set_wallpaper);
343 gboolean wallpaper_changed = FALSE;
344 if(set_wallpaper) /* a new wallpaper is assigned */
345 {
346 /* g_debug("\'%s\'", set_wallpaper); */
347 /* Make sure this is a support image file. */
348 if(gdk_pixbuf_get_file_info(set_wallpaper, NULL, NULL))
349 {
350 if(app_config->wallpaper)
351 g_free(app_config->wallpaper);
352 app_config->wallpaper = set_wallpaper;
353 set_wallpaper = NULL;
354 if(! wallpaper_mode) /* if wallpaper mode is not specified */
355 {
356 /* do not use solid color mode; otherwise wallpaper won't be shown. */
357 if(app_config->wallpaper_mode == FM_WP_COLOR)
358 app_config->wallpaper_mode = FM_WP_FIT;
359 }
360 wallpaper_changed = TRUE;
361 }
362 }
363
364 if(wallpaper_mode)
365 {
366 int i = 0;
367 for(i = 0; i < G_N_ELEMENTS(valid_wallpaper_modes); ++i)
368 {
369 if(strcmp(valid_wallpaper_modes[i], wallpaper_mode) == 0)
370 {
371 if(i != app_config->wallpaper_mode)
372 {
373 app_config->wallpaper_mode = i;
374 wallpaper_changed = TRUE;
375 }
376 break;
377 }
378 }
379 g_free(wallpaper_mode);
380 wallpaper_mode = NULL;
381 }
382
383 if(wallpaper_changed)
f8f2bfad 384 {
4b3e1fe9 385 fm_config_emit_changed(FM_CONFIG(app_config), "wallpaper");
17d12cc9 386 fm_app_config_save_profile(app_config, profile);
f8f2bfad 387 }
107cdb22
HJYP
388
389 if(need_to_exit)
390 return FALSE;
f8f2bfad
HJYP
391 }
392 }
393
394 if(G_UNLIKELY(find_files))
395 {
396 /* FIXME: find files */
397 }
398 else
399 {
df6826e0
HJYP
400 if(files_to_open)
401 {
402 char** filename;
0a053694 403 FmJob* job = fm_file_info_job_new(NULL, 0);
cacf261a 404 FmPath* cwd = NULL;
d951adb8 405 GList* infos;
df6826e0
HJYP
406 for(filename=files_to_open; *filename; ++filename)
407 {
cacf261a
HJYP
408 FmPath* path;
409 if( **filename == '/' || strstr(*filename, ":/") ) /* absolute path or URI */
410 path = fm_path_new(*filename);
0d8dce1a
HJYP
411 else if( strcmp(*filename, "~") == 0 ) /* special case for home dir */
412 {
413 path = fm_path_get_home();
414 fm_main_win_add_win(NULL, path);
415 continue;
416 }
cacf261a
HJYP
417 else /* basename */
418 {
419 if(G_UNLIKELY(!cwd))
420 {
421 /* FIXME: This won't work if those filenames are passed via IPC since the receiving process has different cwd. */
422 char* cwd_str = g_get_current_dir();
423 cwd = fm_path_new(cwd_str);
424 g_free(cwd_str);
425 }
426 path = fm_path_new_relative(cwd, *filename);
427 }
4b3e1fe9 428 fm_file_info_job_add(FM_FILE_INFO_JOB(job), path);
df6826e0
HJYP
429 fm_path_unref(path);
430 }
cacf261a
HJYP
431 if(cwd)
432 fm_path_unref(cwd);
ee12f37e 433 g_signal_connect(job, "error", G_CALLBACK(on_file_info_job_error), NULL);
a48f9fc8 434 fm_job_run_sync_with_mainloop(job);
d951adb8
HJYP
435 infos = fm_list_peek_head_link(FM_FILE_INFO_JOB(job)->file_infos);
436 fm_launch_files_simple(NULL, NULL, infos, pcmanfm_open_folder, NULL);
df6826e0 437 g_object_unref(job);
cacf261a 438 ret = (n_pcmanfm_ref >= 1); /* if there is opened window, return true to run the main loop. */
2b46b521
HJYP
439
440 g_strfreev(files_to_open);
441 files_to_open = NULL;
df6826e0
HJYP
442 }
443 else
f8f2bfad
HJYP
444 {
445 FmPath* path;
5b890032 446 char* cwd = ipc_cwd ? ipc_cwd : g_get_current_dir();
0d8dce1a
HJYP
447 path = fm_path_new(cwd);
448 fm_main_win_add_win(NULL, path);
449 fm_path_unref(path);
450 g_free(cwd);
5b890032 451 ipc_cwd = NULL;
f8f2bfad
HJYP
452 }
453 }
454 return ret;
455}
456
457/* After opening any window/dialog/tool, this should be called. */
458void pcmanfm_ref()
459{
460 ++n_pcmanfm_ref;
461 /* g_debug("ref: %d", n_pcmanfm_ref); */
462}
463
464/* After closing any window/dialog/tool, this should be called.
465 * If the last window is closed and we are not a deamon, pcmanfm will quit.
466 */
467void pcmanfm_unref()
468{
469 --n_pcmanfm_ref;
470 /* g_debug("unref: %d, daemon_mode=%d, desktop_running=%d", n_pcmanfm_ref, daemon_mode, desktop_running); */
471 if( 0 == n_pcmanfm_ref && !daemon_mode && !desktop_running )
472 gtk_main_quit();
b6e3c554 473}
df6826e0
HJYP
474
475gboolean pcmanfm_open_folder(GAppLaunchContext* ctx, GList* folder_infos, gpointer user_data, GError** err)
476{
df6826e0
HJYP
477 GList* l = folder_infos;
478 for(; l; l=l->next)
479 {
480 FmFileInfo* fi = (FmFileInfo*)l->data;
481 fm_main_win_open_in_last_active(fi->path);
482 }
483 return TRUE;
484}
dcecce78
HJYP
485
486void pcmanfm_save_config()
487{
488 fm_config_save(fm_config, NULL);
17d12cc9 489 fm_app_config_save_profile(app_config, profile);
dcecce78 490}
c56a211a
HJYP
491
492void pcmanfm_open_folder_in_terminal(GtkWindow* parent, FmPath* dir)
493{
494 GAppInfo* app;
c56a211a
HJYP
495 char** argv;
496 int argc;
497 if(!fm_config->terminal)
498 {
499 fm_show_error(parent, _("Terminal emulator is not set."));
500 fm_edit_preference(parent, PREF_ADVANCED);
501 return;
502 }
503 if(!g_shell_parse_argv(fm_config->terminal, &argc, &argv, NULL))
504 return;
505 app = g_app_info_create_from_commandline(argv[0], NULL, 0, NULL);
506 g_strfreev(argv);
507 if(app)
508 {
509 GError* err = NULL;
510 GAppLaunchContext* ctx = gdk_app_launch_context_new();
511 char* cwd_str;
512
513 if(fm_path_is_native(dir))
514 cwd_str = fm_path_to_str(dir);
515 else
516 {
517 GFile* gf = fm_path_to_gfile(dir);
518 cwd_str = g_file_get_path(gf);
519 g_object_unref(gf);
520 }
99476ede 521 gdk_app_launch_context_set_screen(GDK_APP_LAUNCH_CONTEXT(ctx), parent ? gtk_widget_get_screen(GTK_WIDGET(parent)) : gdk_screen_get_default());
c56a211a
HJYP
522 gdk_app_launch_context_set_timestamp(GDK_APP_LAUNCH_CONTEXT(ctx), gtk_get_current_event_time());
523 g_chdir(cwd_str); /* FIXME: currently we don't have better way for this. maybe a wrapper script? */
524 g_free(cwd_str);
525 if(!g_app_info_launch(app, NULL, ctx, &err))
526 {
527 fm_show_error(parent, err->message);
528 g_error_free(err);
529 }
530 g_object_unref(ctx);
531 g_object_unref(app);
532 }
533}
7cb06c27
HJYP
534
535/* FIXME: Need to load content of ~/Templates and list available templates in popup menus. */
536void pcmanfm_create_new(GtkWindow* parent, FmPath* cwd, const char* templ)
537{
538 GError* err = NULL;
539 FmPath* dest;
540 char* basename;
541_retry:
542 basename = fm_get_user_input(parent, _("Create New..."), _("Enter a name for the newly created file:"), _("New"));
543 if(!basename)
544 return;
545
546 dest = fm_path_new_child(cwd, basename);
547 g_free(basename);
548
549 if( templ == TEMPL_NAME_FOLDER )
550 {
551 GFile* gf = fm_path_to_gfile(dest);
552 if(!g_file_make_directory(gf, NULL, &err))
553 {
98daf506 554 if(err->domain == G_IO_ERROR && err->code == G_IO_ERROR_EXISTS)
7cb06c27
HJYP
555 {
556 fm_path_unref(dest);
557 g_error_free(err);
558 g_object_unref(gf);
559 err = NULL;
560 goto _retry;
561 }
562 fm_show_error(parent, err->message);
563 g_error_free(err);
564 }
565
566 if(!err) /* select the newly created file */
567 {
568 /*FIXME: this doesn't work since the newly created file will
569 * only be shown after file-created event was fired on its
570 * folder's monitor and after FmFolder handles it in idle
571 * handler. So, we cannot select it since it's not yet in
572 * the folder model now. */
573 /* fm_folder_view_select_file_path(fv, dest); */
574 }
575 g_object_unref(gf);
576 }
577 else if( templ == TEMPL_NAME_BLANK )
578 {
579 GFile* gf = fm_path_to_gfile(dest);
580 GFileOutputStream* f = g_file_create(gf, G_FILE_CREATE_NONE, NULL, &err);
581 if(f)
582 {
583 g_output_stream_close(G_OUTPUT_STREAM(f), NULL, NULL);
584 g_object_unref(f);
585 }
586 else
587 {
98daf506 588 if(err->domain == G_IO_ERROR && err->code == G_IO_ERROR_EXISTS)
7cb06c27
HJYP
589 {
590 fm_path_unref(dest);
591 g_error_free(err);
592 g_object_unref(gf);
593 err = NULL;
594 goto _retry;
595 }
596 fm_show_error(parent, err->message);
597 g_error_free(err);
598 }
599
600 if(!err) /* select the newly created file */
601 {
602 /*FIXME: this doesn't work since the newly created file will
603 * only be shown after file-created event was fired on its
604 * folder's monitor and after FmFolder handles it in idle
605 * handler. So, we cannot select it since it's not yet in
606 * the folder model now. */
607 /* fm_folder_view_select_file_path(fv, dest); */
608 }
609 g_object_unref(gf);
610 }
611 else /* templates in ~/Templates */
612 {
613 FmPath* dir = fm_path_new(g_get_user_special_dir(G_USER_DIRECTORY_TEMPLATES));
614 FmPath* template = fm_path_new_child(dir, templ);
615 fm_copy_file(template, cwd);
616 fm_path_unref(template);
617 }
618 fm_path_unref(dest);
619}
92f8ca49
HJYP
620
621char* pcmanfm_get_profile_dir(gboolean create)
622{
623 char* dir = g_build_filename(g_get_user_config_dir(), "pcmanfm", profile ? profile : "default", NULL);
624 if(create)
625 g_mkdir_with_parents(dir, 0700);
626 return dir;
627}