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