Re: $HOME and gtk_file_chooser_set_current_folder



On Wed, 1 Mar 2017, Ian Chapman wrote:

Hi, this is most likely my failure to fully understand gtk. I have enclosed the following code snippets that work and fail to work. I have a work round so it is not too bad an issue for me.

gchar WorkingPath[500] = {"$HOME/Project/" }; //FAILS (this grows as sub-projects are selected in project)

gchar WorkingPath[500] = {"~/Project/" };    //Also fails

So far as gtk (and C generally) are concerned, "$HOME" and "~" have no special meaning, they're just arbitrary strings.

MyWorkRound()

strcpy (WorkingPath, getenv("HOME"));
strcat (WorkingPath, "/Project/");

Or

sprintf(WorkingPath, "%s/Project/", getenv("HOME"));

This isn't a work-around, it's what you have to do. More idiomatic for gtk might be

gchar *WorkingPath;

WorkingPath = g_strdup_printf("%s/Project", g_get_home_dir());

/* use the path, then */

g_free(WorkingPath);

Or see g_build_path().

--
Allin Cottrell
Department of Economics
Wake Forest University


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]