/* Setup the fileitem, depending uri's scheme * Return a string to search in. */ static gchar * fileitem_setup (FileItem *item) { gchar *scheme; gchar *filename; gchar *candidate = NULL; gchar *path; gchar *name; scheme = g_uri_parse_scheme (item->uri); if (g_strcmp0 (scheme, "file") == 0) { filename = g_filename_from_uri ((const gchar *)item->uri, NULL, NULL); if (filename) { path = g_path_get_dirname (filename); item->path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL); g_free (path); name = g_path_get_basename (filename); item->name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL); g_free (name); candidate = g_utf8_strdown (filename, -1); g_free (filename); } } g_free (scheme); return candidate; }
/* * This function recursively creates the xmlnode tree from the prefs * tree structure. Yay recursion! */ static void pref_to_xmlnode(xmlnode *parent, struct purple_pref *pref) { xmlnode *node, *childnode; struct purple_pref *child; char buf[21]; GList *cur; /* Create a new node */ node = xmlnode_new_child(parent, "pref"); xmlnode_set_attrib(node, "name", pref->name); /* Set the type of this node (if type == PURPLE_PREF_NONE then do nothing) */ if (pref->type == PURPLE_PREF_INT) { xmlnode_set_attrib(node, "type", "int"); g_snprintf(buf, sizeof(buf), "%d", pref->value.integer); xmlnode_set_attrib(node, "value", buf); } else if (pref->type == PURPLE_PREF_STRING) { xmlnode_set_attrib(node, "type", "string"); xmlnode_set_attrib(node, "value", pref->value.string ? pref->value.string : ""); } else if (pref->type == PURPLE_PREF_STRING_LIST) { xmlnode_set_attrib(node, "type", "stringlist"); for (cur = pref->value.stringlist; cur != NULL; cur = cur->next) { childnode = xmlnode_new_child(node, "item"); xmlnode_set_attrib(childnode, "value", cur->data ? cur->data : ""); } } else if (pref->type == PURPLE_PREF_PATH) { char *encoded = g_filename_to_utf8(pref->value.string ? pref->value.string : "", -1, NULL, NULL, NULL); xmlnode_set_attrib(node, "type", "path"); xmlnode_set_attrib(node, "value", encoded); g_free(encoded); } else if (pref->type == PURPLE_PREF_PATH_LIST) { xmlnode_set_attrib(node, "type", "pathlist"); for (cur = pref->value.stringlist; cur != NULL; cur = cur->next) { char *encoded = g_filename_to_utf8(cur->data ? cur->data : "", -1, NULL, NULL, NULL); childnode = xmlnode_new_child(node, "item"); xmlnode_set_attrib(childnode, "value", encoded); g_free(encoded); } } else if (pref->type == PURPLE_PREF_BOOLEAN) { xmlnode_set_attrib(node, "type", "bool"); g_snprintf(buf, sizeof(buf), "%d", pref->value.boolean); xmlnode_set_attrib(node, "value", buf); } /* All My Children */ for (child = pref->first_child; child != NULL; child = child->sibling) pref_to_xmlnode(node, child); }
// GTK >= 2.4 static const gchar* create_fsel_2(const gchar *dirname, const gchar *filename, const gchar *ext, gboolean save) { GtkWidget *dialog; GtkFileFilter *filter; gchar *path, *tmp; gchar **sarray; gint i; gchar *sfilename, *sext; // gtk_file_chooser_set_current_name and gtk_file_filter_add_pattern ALWAYS want UTF-8. sfilename = filename ? g_filename_to_utf8(filename,-1,NULL,NULL,NULL) : NULL; sext = ext ? g_filename_to_utf8(ext,-1,NULL,NULL,NULL) : NULL; // create box dialog = gtk_file_chooser_dialog_new ( save ? "Save File" : "Open File", NULL, save ? GTK_FILE_CHOOSER_ACTION_SAVE : GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); // set default folder tmp = g_strconcat(dirname, G_DIR_SEPARATOR_S, NULL); // add leading '/' otherwise get_dirname is confused path = g_path_get_dirname(tmp); g_free(tmp); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); g_free(path); // set default name if(filename) gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), sfilename); // set wildcards filter = gtk_file_filter_new(); sarray = g_strsplit(sext, ";", -1); for(i = 0; sarray[i] != NULL; i++) gtk_file_filter_add_pattern (filter, sarray[i]); g_strfreev(sarray); gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); // get result g_free(fname); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); else fname = NULL; gtk_widget_destroy (dialog); g_free(sfilename); g_free(sext); return fname; }
/* Setup the fileitem, depending uri's scheme * Return a string to search in. */ static gchar * fileitem_setup (FileItem *item) { gchar *scheme; gchar *filename; gchar *normalized_filename = NULL; gchar *candidate = NULL; gchar *path; gchar *name; scheme = g_uri_parse_scheme (item->uri); if (g_strcmp0 (scheme, "file") == 0) { filename = g_filename_from_uri ((const gchar *)item->uri, NULL, NULL); if (filename) { path = g_path_get_dirname (filename); item->path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL); g_free (path); name = g_path_get_basename (filename); item->name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL); g_free (name); normalized_filename = g_utf8_normalize (filename, -1, G_NORMALIZE_ALL); g_free (filename); } } else { GFile *file; gchar *parse_name; file = g_file_new_for_uri (item->uri); item->path = gedit_utils_location_get_dirname_for_display (file); item->name = gedit_utils_basename_for_display (file); parse_name = g_file_get_parse_name (file); g_object_unref (file); normalized_filename = g_utf8_normalize (parse_name, -1, G_NORMALIZE_ALL); g_free (parse_name); } if (normalized_filename) { candidate = g_utf8_casefold (normalized_filename, -1); g_free (normalized_filename); } g_free (scheme); return candidate; }
void save_copy_as_callb(GtkWidget *wdg,gpointer data) { // Saves top document under a new name, // after copying it in a new window // Choose new file name // Returns if cancelled // Create new doc_wrapper // Simple implementation (probably with overhead...): // Save under a new name, reopen the original document, // swap on the top the old renamed document app_struct *app; gchar *dname, *fname; doc_wrapper *doc; app = (app_struct *)data; if (!app->docs) return; if (!app->docs->current_doc) return; doc = app->docs->current_doc; if (doc->fname_tochoose) { my_msg(_("You'll be asked to save the document before cloning it."),INFO); } // Any modification should be saved, whatever happens commit_or_reset (app->stack); doc_save(app->docs->current_doc); if (app->file_on_cmdline) x_free(app->file_on_cmdline); app->file_on_cmdline = concat_dname_fname(doc->dir, doc->filename); app->docs->current_doc->fname_tochoose = TRUE; if (!doc_save(app->docs->current_doc)) { app->docs->current_doc->fname_tochoose = FALSE; return; } fname = doc->filename; // new name dname = doc->dir; open_callb(NULL,data); // Open the filename given by app->file_on_cmdline (old name) // Swap the file and dir names (some window focusing problems, otherwise) doc->filename = app->docs->current_doc->filename; // old name doc->dir = app->docs->current_doc->dir; app->docs->current_doc->filename = fname; app->docs->current_doc->dir = dname; // Old name for original doc gtk_window_set_title(GTK_WINDOW(doc->window), g_filename_to_utf8(app->file_on_cmdline,-1, NULL, NULL, NULL)); // New name for newly opened doc gtk_window_set_title(GTK_WINDOW(app->docs->current_doc->window), g_filename_to_utf8(concat_dname_fname(dname, fname), -1, NULL, NULL, NULL)); }
static void add_entry(GMenuTreeEntry *entry, const char *path, GSList**p) { GSList* data = *p; char *utf8_path; char *utf8_file_id; Menu_list_item * item; gchar * file_name; utf8_path = g_filename_to_utf8(gmenu_tree_entry_get_desktop_file_path(entry), -1, NULL, NULL, NULL); utf8_file_id = g_filename_to_utf8(gmenu_tree_entry_get_desktop_file_id(entry), -1, NULL, NULL, NULL); file_name = utf8_path ? utf8_path : _("[Invalid Filename]"); item = g_malloc(sizeof(Menu_list_item)); item->item_type = MENU_ITEM_ENTRY; item->name = gmenu_tree_entry_get_name(entry); item->icon = gmenu_tree_entry_get_icon(entry); item->exec = gmenu_tree_entry_get_exec(entry); char *str = item->exec; while (*str) { if (*str == '%') { *str = ' '; if (*(str + 1)) { str++; *str = ' '; } } str++; } item->comment = gmenu_tree_entry_get_comment(entry); item->launch_in_terminal = gmenu_tree_entry_get_launch_in_terminal(entry); item->desktop = g_strdup(file_name); data = g_slist_append(data, item); *p = data; g_free(utf8_file_id); g_free(utf8_path); }
static gchar * sanity_check_filename_encoding (void) { gchar *result; GError *error = NULL; result = g_filename_to_utf8 ("", -1, NULL, NULL, &error); if (! result) { gchar *msg = g_strdup_printf (_("The configured filename encoding cannot be converted to UTF-8: " "%s\n\n" "Please check the value of the environment variable " "G_FILENAME_ENCODING."), error->message); g_error_free (error); return msg; } g_free (result); result = g_filename_to_utf8 (gimp_directory (), -1, NULL, NULL, &error); if (! result) { gchar *msg = g_strdup_printf (_("The name of the directory holding the GIMP user configuration " "cannot be converted to UTF-8: " "%s\n\n" "Your filesystem probably stores files in an encoding " "other than UTF-8 and you didn't tell GLib about this. " "Please set the environment variable G_FILENAME_ENCODING."), error->message); g_error_free (error); return msg; } g_free (result); return NULL; }
static void find_fonts_callback(GtkFileChooser *dialog) { GSList *files = gtk_file_chooser_get_filenames(dialog); GSList *test; int len, cnt, i; char ***fonts, *pt, *text; if ( files==NULL || (cnt = g_slist_length(files))==0 ) gtk_widget_set_tooltip_text(GTK_WIDGET(dialog),""); else { fonts = gcalloc(cnt,sizeof(char **)); cnt = len = 0; for ( test=files; test!=NULL; test=test->next, ++cnt) { fonts[cnt] = GetFontNames((char *) (test->data)); if ( fonts[cnt]!=NULL ) { len += 4*strlen((char *) (test->data))+1; /* allow space for utf8 conversion */ for ( i=0; fonts[cnt][i]!=NULL; ++i ) len += strlen( fonts[cnt][i])+2; } } pt = text = galloc(len+10); cnt = 0; for ( test=files; test!=NULL; test=test->next, ++cnt) { if ( fonts[cnt]!=NULL ) { /* If there is only one file selected, don't bother to name it */ if ( cnt!=0 || test->next!=NULL ) { gsize junk; char *temp = g_filename_to_utf8(GFileNameTail( (char *) (test->data) ), -1, &junk, &junk, NULL); strcpy(pt,temp); g_free(temp); pt += strlen(pt); *pt++ = '\n'; } for ( i=0; fonts[cnt][i]!=NULL; ++i ) { *pt++ = ' '; strcpy(pt,fonts[cnt][i]); free(fonts[cnt][i]); pt += strlen(pt); *pt ++ = '\n'; } free(fonts[cnt]); } } if ( pt>text && pt[-1]=='\n' ) pt[-1]='\0'; else *pt = '\0'; free(fonts); if ( *text=='\0' ) gtk_widget_set_tooltip_text(GTK_WIDGET(dialog), "???"); else { gtk_widget_set_tooltip_text(GTK_WIDGET(dialog), text); } free(text); } for ( test=files; test!=NULL; test=test->next) g_free(test->data); g_slist_free(files); }
char* M_UnLocalizePath(const char *local_path) { gsize sz; gchar *ulp; char *out; if (!local_path) return NULL; clear_file_error(); #ifdef _WIN32 ulp = g_convert(local_path, -1, "UTF-8", "wchar_t", NULL, &sz, &file_error); #else ulp = g_filename_to_utf8(local_path, -1, NULL, &sz, &file_error); #endif out = calloc(sz + 1, sizeof(char)); if (!out) I_Error("M_UnLocalizePath: calloc failed"); memcpy(out, ulp, sz); g_free(ulp); return out; }
void prepend_current_dir_if_relative (char **result, const gchar *uri) { if (!uri) { *(result) = NULL; return; } char *full_path = (char *) g_malloc (1001); char *cwd = g_get_current_dir(); gsize bytesRead = 0; gsize bytesWritten = 0; GError* error = NULL; gchar* cwd_utf8 = g_filename_to_utf8 ( cwd, -1, &bytesRead, &bytesWritten, &error); inkscape_rel2abs (uri, cwd_utf8, full_path, 1000); *(result) = g_strdup (full_path); g_free (full_path); g_free (cwd); }
static void foldersel_cb(GtkWidget *widget, gpointer data) { struct ArchiverPrefsPage *page = (struct ArchiverPrefsPage *) data; gchar *startdir = NULL; gchar *dirname; gchar *tmp; if (archiver_prefs.save_folder && *archiver_prefs.save_folder) startdir = g_strconcat(archiver_prefs.save_folder, G_DIR_SEPARATOR_S, NULL); else startdir = g_strdup(get_home_dir()); dirname = filesel_select_file_save_folder(_("Select destination folder"), startdir); if (!dirname) { g_free(startdir); return; } if (!is_dir_exist(dirname)) { alertpanel_error(_("'%s' is not a directory."),dirname); g_free(dirname); g_free(startdir); return; } if (dirname[strlen(dirname)-1] == G_DIR_SEPARATOR) dirname[strlen(dirname)-1] = '\0'; g_free(startdir); tmp = g_filename_to_utf8(dirname,-1, NULL, NULL, NULL); gtk_entry_set_text(GTK_ENTRY(page->save_folder), tmp); g_free(dirname); g_free(tmp); }
// static void LLFilePicker::add_to_selectedfiles(gpointer data, gpointer user_data) { // We need to run g_filename_to_utf8 in the user's locale std::string saved_locale(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, ""); LLFilePicker* picker = (LLFilePicker*) user_data; GError *error = NULL; gchar* filename_utf8 = g_filename_to_utf8((gchar*)data, -1, NULL, NULL, &error); if (error) { // *FIXME. // This condition should really be notified to the user, e.g. // through a message box. Just logging it is inappropriate. // g_filename_display_name is ideal, but >= glib 2.6, so: // a hand-rolled hacky makeASCII which disallows control chars std::string display_name; for (const gchar *str = (const gchar *)data; *str; str++) { display_name += (char)((*str >= 0x20 && *str <= 0x7E) ? *str : '?'); } llwarns << "g_filename_to_utf8 failed on \"" << display_name << "\": " << error->message << llendl; } if (filename_utf8) { picker->mFiles.push_back(std::string(filename_utf8)); lldebugs << "ADDED FILE " << filename_utf8 << llendl; g_free(filename_utf8); } setlocale(LC_ALL, saved_locale.c_str()); }
gchar* get_8_filename (const gchar *filename) { gsize bytes_read; gsize bytes_written; return g_filename_to_utf8 (filename, -1, &bytes_read, &bytes_written, NULL); }
static void scan_dir( char * path ) { DIR * dir = NULL; char * curr; struct dirent * dirent; struct stat statbuf; gchar * name; char * text[1][2]; text[0][1]=""; gtk_clist_clear( GTK_CLIST( CLFiles ) ); if ( (dir=opendir( path )) ) { NrOfEntrys=0; while( (dirent=readdir( dir )) ) { curr=calloc( 1,strlen( path ) + strlen( dirent->d_name ) + 3 ); sprintf( curr,"%s/%s",path,dirent->d_name ); if ( stat( curr,&statbuf ) != -1 && ( S_ISREG( statbuf.st_mode ) || S_ISLNK( statbuf.st_mode ) ) ) { name=g_filename_to_utf8( dirent->d_name, -1, NULL, NULL, NULL ); text[0][0]=name ? name : dirent->d_name; gtk_clist_append( GTK_CLIST( CLFiles ), text[0] ); g_free( name ); NrOfEntrys++; } free( curr ); } closedir( dir ); gtk_clist_sort( GTK_CLIST( CLFiles ) ); } }
void side_set_application_mode(int type) { GSettings *theme = g_settings_new("org.jetspace.desktop.session"); GdkDisplay *display; GdkScreen *screen; display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); mode = type; if(g_variant_get_boolean(g_settings_get_value(theme, "use-custom-theme"))) { GtkCssProvider *provider; provider = gtk_css_provider_new (); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); gsize bytes, read; const gchar* t = g_strdup_printf( "%s%s",g_variant_get_string(g_settings_get_value(theme, "custom-theme-path"), NULL), "/side-session/gtk.css"); if(access(t, F_OK) != 0) { system("side-notifier --theme-not-found &"); return; } gtk_css_provider_load_from_path (provider,g_filename_to_utf8(t, strlen(t), &read, &bytes, NULL),NULL); g_object_unref (provider); } }
PyObject * _pygi_marshal_to_py_filename (PyGIInvokeState *state, PyGICallableCache *callable_cache, PyGIArgCache *arg_cache, GIArgument *arg) { gchar *string; PyObject *py_obj = NULL; GError *error = NULL; if (arg->v_string == NULL) { py_obj = Py_None; Py_INCREF (py_obj); return py_obj; } string = g_filename_to_utf8 (arg->v_string, -1, NULL, NULL, &error); if (string == NULL) { PyErr_SetString (PyExc_Exception, error->message); /* TODO: Convert the error to an exception. */ return NULL; } py_obj = PYGLIB_PyUnicode_FromString (string); g_free (string); return py_obj; }
gchar * gsearchtool_get_next_duplicate_name (const gchar * basename) { gchar * utf8_name; gchar * utf8_result; gchar * result; utf8_name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL); if (utf8_name == NULL) { /* Couldn't convert to utf8 - probably * G_BROKEN_FILENAMES not set when it should be. * Try converting from the locale */ utf8_name = g_locale_to_utf8 (basename, -1, NULL, NULL, NULL); if (utf8_name == NULL) { utf8_name = make_valid_utf8 (basename); } } utf8_result = get_duplicate_name (utf8_name); g_free (utf8_name); result = g_filename_from_utf8 (utf8_result, -1, NULL, NULL, NULL); g_free (utf8_result); return result; }
/** * g_dir_open: * @path: the path to the directory you are interested in. On Unix * in the on-disk encoding. On Windows in UTF-8 * @flags: Currently must be set to 0. Reserved for future use. * @error: return location for a #GError, or %NULL. * If non-%NULL, an error will be set if and only if * g_dir_open() fails. * * Opens a directory for reading. The names of the files in the * directory can then be retrieved using g_dir_read_name(). Note * that the ordering is not defined. * * Returns: a newly allocated #GDir on success, %NULL on failure. * If non-%NULL, you must free the result with g_dir_close() * when you are finished with it. **/ GDir * g_dir_open (const gchar *path, guint flags, GError **error) { gint saved_errno; GDir *dir; dir = g_dir_open_with_errno (path, flags); if (dir == NULL) { gchar *utf8_path; saved_errno = errno; utf8_path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL); g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (saved_errno), _("Error opening directory '%s': %s"), utf8_path, g_strerror (saved_errno)); g_free (utf8_path); } return dir; }
gchar *my_filename_to_utf8 (const char *fname) { GError *err = NULL; gchar *ret = NULL; if (g_utf8_validate(fname, -1, NULL)) { ret = g_strdup(fname); } else { /* On Windows, with GTK >= 2.6, the GLib filename encoding is UTF-8; however, filenames coming from a native Windows source will be in the locale charset */ gsize bytes; #ifdef G_OS_WIN32 ret = g_locale_to_utf8(fname, -1, NULL, &bytes, &err); #else ret = g_filename_to_utf8(fname, -1, NULL, &bytes, &err); #endif } if (err) { errbox(err->message); g_error_free(err); } return ret; }
MateWPItem * mate_wp_item_new (const gchar * filename, GHashTable * wallpapers, MateDesktopThumbnailFactory * thumbnails) { MateWPItem *item = g_new0 (MateWPItem, 1); item->filename = g_strdup (filename); item->fileinfo = mate_wp_info_new (filename, thumbnails); if (item->fileinfo != NULL && item->fileinfo->mime_type != NULL && (g_str_has_prefix (item->fileinfo->mime_type, "image/") || strcmp (item->fileinfo->mime_type, "application/xml") == 0)) { if (g_utf8_validate (item->fileinfo->name, -1, NULL)) item->name = g_strdup (item->fileinfo->name); else item->name = g_filename_to_utf8 (item->fileinfo->name, -1, NULL, NULL, NULL); mate_wp_item_update (item); mate_wp_item_ensure_mate_bg (item); mate_wp_item_update_description (item); g_hash_table_insert (wallpapers, item->filename, item); } else { mate_wp_item_free (item); item = NULL; } return item; }
/* XXX: eats arguments! */ static GwyRecentFile* gwy_app_recent_file_new(gchar *filename_utf8, gchar *filename_sys) { GError *err = NULL; GwyRecentFile *rf; g_return_val_if_fail(filename_utf8 || filename_sys, NULL); if (!filename_utf8) filename_utf8 = g_filename_to_utf8(filename_sys, -1, NULL, NULL, NULL); if (!filename_sys) filename_sys = g_filename_from_utf8(filename_utf8, -1, NULL, NULL, NULL); rf = g_new0(GwyRecentFile, 1); rf->file_utf8 = filename_utf8; rf->file_sys = filename_sys; if (!(rf->file_uri = g_filename_to_uri(filename_sys, NULL, &err))) { /* TODO: recovery ??? */ rf->thumb_state = FILE_STATE_FAILED; g_clear_error(&err); return rf; } rf->thumb_sys = gwy_recent_file_thumbnail_name(rf->file_uri); return rf; }
gchar * file_utils_uri_to_utf8_filename (const gchar *uri) { g_return_val_if_fail (uri != NULL, NULL); if (g_str_has_prefix (uri, "file:")) { gchar *filename = file_utils_filename_from_uri (uri); if (filename) { GError *error = NULL; gchar *utf8; utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, &error); g_free (filename); if (utf8) return utf8; g_warning ("%s: cannot convert filename to UTF-8: %s", G_STRLOC, error->message); g_error_free (error); } } return g_strdup (uri); }
static void meta_open_startup_file (GtkWidget * wid, gpointer value) { GtkWidget *file_chooser; gint response; file_chooser = gtk_file_chooser_dialog_new (_("Select file..."), GTK_WINDOW(value), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); response = gtk_dialog_run (GTK_DIALOG (file_chooser)); if (response == GTK_RESPONSE_ACCEPT) { gchar * filename; filename = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (file_chooser) ); gchar *utf = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL); g_free (filename); gtk_entry_set_text (GTK_ENTRY (file_entry), utf); g_free (utf); } gtk_widget_destroy (file_chooser); }
static void matedialog_fileselection_dialog_response (GtkWidget *widget, int response, gpointer data) { MateDialogFileData *file_data = data; GSList *selections, *iter; switch (response) { case GTK_RESPONSE_OK: zen_data->exit_code = matedialog_util_return_exit_code (MATEDIALOG_OK); selections = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (widget)); for (iter = selections;iter != NULL; iter = iter->next) { g_print ("%s", g_filename_to_utf8 ((gchar*)iter->data, -1, NULL, NULL, NULL)); g_free (iter->data); if (iter->next != NULL) g_print ("%s",file_data->separator); } g_print("\n"); g_slist_free(selections); break; case GTK_RESPONSE_CANCEL: zen_data->exit_code = matedialog_util_return_exit_code (MATEDIALOG_CANCEL); break; default: /* Esc dialog */ zen_data->exit_code = matedialog_util_return_exit_code (MATEDIALOG_ESC); break; } gtk_main_quit (); }
static gboolean win32_read_thread (GIOChannel *source, GIOCondition cond, struct file_req *freq) { char buf[512]; char *file; waitline2 (source, buf, sizeof buf); switch (buf[0]) { case '0': /* filedialog has closed */ freq->callback (freq->userdata, NULL); break; case '1': /* got a filename! */ waitline2 (source, buf, sizeof buf); file = g_filename_to_utf8 (buf, -1, 0, 0, 0); freq->callback (freq->userdata, file); g_free (file); return TRUE; } /* it doesn't work to close them here, because of the weird way giowin32 works. We must _return_ before closing them */ g_timeout_add(3000, (GSourceFunc)win32_close_pipe, freq->th->pipe_fd[0]); g_timeout_add(2000, (GSourceFunc)win32_close_pipe, freq->th->pipe_fd[1]); g_free (freq->title); free (freq->th); free (freq); return FALSE; }
void GTK_browse_server_executable(GtkWidget *entry, gpointer user_data) { GtkWidget *w; const gchar *path = gtk_entry_get_text(GTK_ENTRY(entry)); const gchar *os_path; gchar *s; w = gtk_file_selection_new("Select Local Executable"); gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(w)); if (*path) { os_path = g_filename_from_utf8(path, -1, NULL, NULL, NULL); if (os_path) { s = g_find_program_in_path(os_path); gtk_file_selection_set_filename(GTK_FILE_SELECTION(w), s ? s : os_path); g_free(s); g_free((void *)os_path); } } if (gtk_dialog_run(GTK_DIALOG(w)) == GTK_RESPONSE_OK) { os_path = gtk_file_selection_get_filename(GTK_FILE_SELECTION(w)); path = g_filename_to_utf8(os_path, -1, NULL, NULL, NULL); if (path) { gtk_entry_set_text(GTK_ENTRY(entry), path); g_free((void *)path); } } gtk_widget_destroy(w); }
static void purple_xfer_show_file_error(PurpleXfer *xfer, const char *filename) { int err = errno; gchar *msg = NULL, *utf8; PurpleXferType xfer_type = purple_xfer_get_type(xfer); PurpleAccount *account = purple_xfer_get_account(xfer); utf8 = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); switch(xfer_type) { case PURPLE_XFER_SEND: msg = g_strdup_printf(_("Error reading %s: \n%s.\n"), utf8, g_strerror(err)); break; case PURPLE_XFER_RECEIVE: msg = g_strdup_printf(_("Error writing %s: \n%s.\n"), utf8, g_strerror(err)); break; default: msg = g_strdup_printf(_("Error accessing %s: \n%s.\n"), utf8, g_strerror(err)); break; } g_free(utf8); purple_xfer_conversation_write(xfer, msg, TRUE); purple_xfer_error(xfer_type, account, xfer->who, msg); g_free(msg); }
HexDocument * hex_document_new_from_file (const gchar *name) { HexDocument *doc; gchar *path_end; doc = HEX_DOCUMENT (g_object_new (hex_document_get_type(), NULL)); g_return_val_if_fail (doc != NULL, NULL); doc->file_name = (gchar *)g_strdup(name); if (get_document_attributes(doc)) { doc->gap_size = 100; doc->buffer_size = doc->file_size + doc->gap_size; doc->buffer = (guchar *)g_malloc(doc->buffer_size); /* find the start of the filename without path */ path_end = g_path_get_basename (doc->file_name); doc->path_end = g_filename_to_utf8 (path_end, -1, NULL, NULL, NULL); g_free (path_end); if (hex_document_read(doc)) { doc_list = g_list_append(doc_list, doc); return doc; } } g_object_unref(G_OBJECT(doc)); return NULL; }
char *gwwv_open_filename_mult(const char *title, const char *def_name, const struct gwwv_filter *filters, int mult ) { GtkWidget *dialog; char *filename = NULL; gsize read, written; if ( mult ) dialog = gtk_file_chooser_dialog_new (title, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, GTK_STOCK_NEW, -100, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); else dialog = gtk_file_chooser_dialog_new (title, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER( dialog ), mult ); gwwv_file_def_filters(dialog,def_name,filters); filename = NULL; if ( gtk_dialog_run(GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT ) { char *temp = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); filename = g_filename_to_utf8(temp,-1,&read,&written,NULL); } gtk_widget_destroy (dialog); return( filename ); }
char *gwwv_save_filename_with_gadget(const char *title, const char *def_name, const struct gwwv_filter *filters, GtkWidget *extra ) { GtkWidget *dialog; char *filename = NULL; gsize read, written; dialog = gtk_file_chooser_dialog_new (title, NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); gwwv_file_def_filters(dialog,def_name,filters); if ( extra != NULL ) gtk_file_chooser_set_extra_widget( GTK_FILE_CHOOSER( dialog ), extra ); filename = NULL; if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { char *temp = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); filename = g_filename_to_utf8(temp,-1,&read,&written,NULL); free(temp); } gtk_widget_destroy (dialog); return( filename ); }