/* * Save changes of the ETFile (write tag and rename file) * - multiple_files = TRUE : when saving files, a msgbox appears with ability * to do the same action for all files. * - multiple_files = FALSE : appears only a msgbox to ask confirmation. */ static gint Save_File (ET_File *ETFile, gboolean multiple_files, gboolean force_saving_files) { const File_Tag *FileTag; const File_Name *FileNameNew; gint stop_loop = 0; const gchar *filename_cur_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8; const gchar *filename_new_utf8 = ((File_Name *)ETFile->FileNameNew->data)->value_utf8; gchar *basename_cur_utf8, *basename_new_utf8; gchar *dirname_cur_utf8, *dirname_new_utf8; g_return_val_if_fail (ETFile != NULL, 0); basename_cur_utf8 = g_path_get_basename(filename_cur_utf8); basename_new_utf8 = g_path_get_basename(filename_new_utf8); /* Save the current displayed data */ //ET_Save_File_Data_From_UI((ET_File *)ETFileList->data); // Not needed, because it was done before FileTag = ETFile->FileTag->data; FileNameNew = ETFile->FileNameNew->data; /* * Check if file was changed by an external program */ /*stat(filename_cur,&statbuf); if (ETFile->FileModificationTime != statbuf.st_mtime) { // File was changed GtkWidget *msgbox = NULL; gint response; msg = g_strdup_printf(_("The file '%s' was changed by an external program.\nDo you want to continue?"),basename_cur_utf8); msgbox = msg_box_new(_("Write File"), GTK_WINDOW(MainWindow), NULL, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, msg, GTK_STOCK_DIALOG_WARNING, GTK_STOCK_NO, GTK_RESPONSE_NO, GTK_STOCK_YES, GTK_RESPONSE_YES, NULL); g_free(msg); response = gtk_dialog_run(GTK_DIALOG(msgbox)); gtk_widget_destroy(msgbox); switch (response) { case GTK_RESPONSE_YES: break; case GTK_RESPONSE_NO: case GTK_RESPONSE_NONE: stop_loop = -1; return stop_loop; break; } }*/ /* * First part: write tag information (artist, title,...) */ // Note : the option 'force_saving_files' is only used to save tags if ( force_saving_files || FileTag->saved == FALSE ) // This tag had been already saved ? { GtkWidget *msgdialog = NULL; GtkWidget *msgdialog_check_button = NULL; gint response; if (g_settings_get_boolean (MainSettings, "confirm-write-tags") && !SF_HideMsgbox_Write_Tag) { // ET_Display_File_Data_To_UI(ETFile); msgdialog = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Do you want to write the tag of file ‘%s’?"), basename_cur_utf8); gtk_window_set_title(GTK_WINDOW(msgdialog),_("Confirm Tag Writing")); if (multiple_files) { GtkWidget *message_area; message_area = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(msgdialog)); msgdialog_check_button = gtk_check_button_new_with_label(_("Repeat action for the remaining files")); gtk_container_add(GTK_CONTAINER(message_area),msgdialog_check_button); gtk_widget_show (msgdialog_check_button); gtk_dialog_add_buttons (GTK_DIALOG (msgdialog), _("_Discard"), GTK_RESPONSE_NO, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_Save"), GTK_RESPONSE_YES, NULL); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(msgdialog_check_button), TRUE); // Checked by default } else { gtk_dialog_add_buttons (GTK_DIALOG (msgdialog), _("_Cancel"), GTK_RESPONSE_NO, _("_Save"), GTK_RESPONSE_YES, NULL); } gtk_dialog_set_default_response (GTK_DIALOG (msgdialog), GTK_RESPONSE_YES); SF_ButtonPressed_Write_Tag = response = gtk_dialog_run(GTK_DIALOG(msgdialog)); // When check button in msgbox was activated : do not display the message again if (msgdialog_check_button && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(msgdialog_check_button))) SF_HideMsgbox_Write_Tag = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(msgdialog_check_button)); gtk_widget_destroy(msgdialog); }else { if (SF_HideMsgbox_Write_Tag) response = SF_ButtonPressed_Write_Tag; else response = GTK_RESPONSE_YES; } switch (response) { case GTK_RESPONSE_YES: { gboolean rc; // if 'SF_HideMsgbox_Write_Tag is TRUE', then errors are displayed only in log rc = Write_File_Tag(ETFile,SF_HideMsgbox_Write_Tag); // if an error occurs when 'SF_HideMsgbox_Write_Tag is TRUE', we don't stop saving... if (rc != TRUE && !SF_HideMsgbox_Write_Tag) { stop_loop = -1; g_free (basename_cur_utf8); g_free (basename_new_utf8); return stop_loop; } break; } case GTK_RESPONSE_NO: break; case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_DELETE_EVENT: stop_loop = -1; g_free (basename_cur_utf8); g_free (basename_new_utf8); return stop_loop; break; default: g_assert_not_reached (); break; } } /* * Second part: rename the file */ // Do only if changed! (don't take force_saving_files into account) if ( FileNameNew->saved == FALSE ) // This filename had been already saved ? { GtkWidget *msgdialog = NULL; GtkWidget *msgdialog_check_button = NULL; gint response; if (g_settings_get_boolean (MainSettings, "confirm-rename-file") && !SF_HideMsgbox_Rename_File) { gchar *msgdialog_title = NULL; gchar *msg = NULL; gchar *msg1 = NULL; // ET_Display_File_Data_To_UI(ETFile); dirname_cur_utf8 = g_path_get_dirname(filename_cur_utf8); dirname_new_utf8 = g_path_get_dirname(filename_new_utf8); // Directories were renamed? or only filename? if (g_utf8_collate(dirname_cur_utf8,dirname_new_utf8) != 0) { if (g_utf8_collate(basename_cur_utf8,basename_new_utf8) != 0) { // Directories and filename changed msgdialog_title = g_strdup (_("Rename File and Directory")); msg = g_strdup(_("File and directory rename confirmation required")); msg1 = g_strdup_printf (_("Do you want to rename the file and directory ‘%s’ to ‘%s’?"), filename_cur_utf8, filename_new_utf8); }else { // Only directories changed msgdialog_title = g_strdup (_("Rename Directory")); msg = g_strdup(_("Directory rename confirmation required")); msg1 = g_strdup_printf (_("Do you want to rename the directory ‘%s’ to ‘%s’?"), dirname_cur_utf8, dirname_new_utf8); } }else { // Only filename changed msgdialog_title = g_strdup (_("Rename File")); msg = g_strdup(_("File rename confirmation required")); msg1 = g_strdup_printf (_("Do you want to rename the file ‘%s’ to ‘%s’?"), basename_cur_utf8, basename_new_utf8); } g_free(dirname_cur_utf8); g_free(dirname_new_utf8); msgdialog = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", msg); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msgdialog),"%s",msg1); gtk_window_set_title(GTK_WINDOW(msgdialog),msgdialog_title); if (multiple_files) { GtkWidget *message_area; message_area = gtk_message_dialog_get_message_area(GTK_MESSAGE_DIALOG(msgdialog)); msgdialog_check_button = gtk_check_button_new_with_label(_("Repeat action for the remaining files")); gtk_container_add(GTK_CONTAINER(message_area),msgdialog_check_button); gtk_widget_show (msgdialog_check_button); gtk_dialog_add_buttons (GTK_DIALOG (msgdialog), _("_Discard"), GTK_RESPONSE_NO, _("_Cancel"), GTK_RESPONSE_CANCEL, _("_Save"), GTK_RESPONSE_YES, NULL); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(msgdialog_check_button), TRUE); // Checked by default } else { gtk_dialog_add_buttons (GTK_DIALOG (msgdialog), _("_Discard"), GTK_RESPONSE_NO, _("_Save"), GTK_RESPONSE_YES, NULL); } g_free(msg); g_free(msg1); g_free(msgdialog_title); gtk_dialog_set_default_response (GTK_DIALOG (msgdialog), GTK_RESPONSE_YES); SF_ButtonPressed_Rename_File = response = gtk_dialog_run(GTK_DIALOG(msgdialog)); if (msgdialog_check_button && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(msgdialog_check_button))) SF_HideMsgbox_Rename_File = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(msgdialog_check_button)); gtk_widget_destroy(msgdialog); }else { if (SF_HideMsgbox_Rename_File) response = SF_ButtonPressed_Rename_File; else response = GTK_RESPONSE_YES; } switch(response) { case GTK_RESPONSE_YES: { gboolean rc; GError *error = NULL; const gchar *cur_filename = ((File_Name *)ETFile->FileNameCur->data)->value; const gchar *new_filename = ((File_Name *)ETFile->FileNameNew->data)->value; rc = et_rename_file (cur_filename, new_filename, &error); // if 'SF_HideMsgbox_Rename_File is TRUE', then errors are displayed only in log if (!rc) { if (!SF_HideMsgbox_Rename_File) { msgdialog = gtk_message_dialog_new (GTK_WINDOW (MainWindow), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Cannot rename file ‘%s’ to ‘%s’"), filename_cur_utf8, filename_new_utf8); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog), "%s", error->message); gtk_window_set_title (GTK_WINDOW (msgdialog), _("Rename File Error")); gtk_dialog_run (GTK_DIALOG (msgdialog)); gtk_widget_destroy (msgdialog); } Log_Print (LOG_ERROR, _("Cannot rename file ‘%s’ to ‘%s’: %s"), filename_cur_utf8, filename_new_utf8, error->message); et_application_window_status_bar_message (ET_APPLICATION_WINDOW (MainWindow), _("File(s) not renamed"), TRUE); g_error_free (error); } // if an error occurs when 'SF_HideMsgbox_Rename_File is TRUE', we don't stop saving... if (!rc && !SF_HideMsgbox_Rename_File) { stop_loop = -1; g_free (basename_cur_utf8); g_free (basename_new_utf8); return stop_loop; } /* Mark after renaming files. */ ETFile->FileNameCur = ETFile->FileNameNew; ET_Mark_File_Name_As_Saved (ETFile); break; } case GTK_RESPONSE_NO: break; case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_DELETE_EVENT: stop_loop = -1; g_free (basename_cur_utf8); g_free (basename_new_utf8); return stop_loop; break; default: g_assert_not_reached (); break; } } g_free(basename_cur_utf8); g_free(basename_new_utf8); /* Refresh file into browser list */ // Browser_List_Refresh_File_In_List(ETFile); return 1; }
static void export_vpn_to_file_cb (GtkWidget *dialog, gint response, gpointer user_data) { NMConnection *connection = NM_CONNECTION (user_data); char *filename = NULL; GError *error = NULL; NMVpnPluginUiInterface *plugin; NMSettingConnection *s_con = NULL; NMSettingVPN *s_vpn = NULL; const char *service_type; const char *id = NULL; gboolean success = FALSE; if (response != GTK_RESPONSE_ACCEPT) goto out; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); if (!filename) { g_set_error (&error, NMA_ERROR, NMA_ERROR_GENERIC, "no filename"); goto done; } if (g_file_test (filename, G_FILE_TEST_EXISTS)) { int replace_response; GtkWidget *replace_dialog; char *bname; bname = g_path_get_basename (filename); replace_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL, _("A file named \"%s\" already exists."), bname); gtk_dialog_add_buttons (GTK_DIALOG (replace_dialog), _("_Replace"), GTK_RESPONSE_OK, NULL); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (replace_dialog), _("Do you want to replace %s with the VPN connection you are saving?"), bname); g_free (bname); replace_response = gtk_dialog_run (GTK_DIALOG (replace_dialog)); gtk_widget_destroy (replace_dialog); if (replace_response != GTK_RESPONSE_OK) goto out; } s_con = nm_connection_get_setting_connection (connection); id = s_con ? nm_setting_connection_get_id (s_con) : NULL; if (!id) { g_set_error (&error, NMA_ERROR, NMA_ERROR_GENERIC, "connection setting invalid"); goto done; } s_vpn = nm_connection_get_setting_vpn (connection); service_type = s_vpn ? nm_setting_vpn_get_service_type (s_vpn) : NULL; if (!service_type) { g_set_error (&error, NMA_ERROR, NMA_ERROR_GENERIC, "VPN setting invalid"); goto done; } plugin = vpn_get_plugin_by_service (service_type); if (plugin) success = nm_vpn_plugin_ui_interface_export (plugin, filename, connection, &error); done: if (!success) { GtkWidget *err_dialog; char *bname = filename ? g_path_get_basename (filename) : g_strdup ("(none)"); err_dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot export VPN connection")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (err_dialog), _("The VPN connection '%s' could not be exported to %s.\n\nError: %s."), id ? id : "(unknown)", bname, error ? error->message : "unknown error"); g_free (bname); g_signal_connect (err_dialog, "delete-event", G_CALLBACK (gtk_widget_destroy), NULL); g_signal_connect (err_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL); gtk_widget_show_all (err_dialog); gtk_window_present (GTK_WINDOW (err_dialog)); } out: if (error) g_error_free (error); g_object_unref (connection); gtk_widget_hide (dialog); gtk_widget_destroy (dialog); }
/** * asb_utils_get_cache_id_for_filename: * @filename: utf8 filename * * Gets the cache-id for a given filename. * * Returns: utf8 string * * Since: 0.1.0 **/ gchar * asb_utils_get_cache_id_for_filename (const gchar *filename) { return g_path_get_basename (filename); }
void sample_save_as_cb(GtkWidget * widget, gpointer data) { GtkWidget *dialog; gint win_width, win_height; sw_view * view = (sw_view *)data; sw_sample * sample; GtkWidget * save_options; GtkWidget * frame; GtkWidget * hbox; GtkWidget * label; GtkWidget * option_menu; GtkWidget * save_menu; struct stat statbuf; gchar *filename; gint retval; save_as_data * sd; char buf[512]; win_width = gdk_screen_width () / 2; win_height = gdk_screen_height () / 2; sample = view->sample; dialog = gtk_file_chooser_dialog_new (_("Sweep: Save file"), GTK_WINDOW(view->window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); //gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); attach_window_close_accel(GTK_WINDOW(dialog)); sweep_set_window_icon (GTK_WINDOW(dialog)); save_options = gtk_hbox_new (TRUE, 1); frame = gtk_frame_new (_("Save Options")); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN); gtk_box_pack_start (GTK_BOX (save_options), frame, TRUE, TRUE, 4); hbox = gtk_hbox_new (FALSE, 4); gtk_container_set_border_width (GTK_CONTAINER (hbox), 4); gtk_container_add (GTK_CONTAINER (frame), hbox); gtk_widget_show (hbox); label = gtk_label_new (_("Determine File Type:")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_widget_show (label); option_menu = gtk_option_menu_new (); gtk_box_pack_start (GTK_BOX (hbox), option_menu, TRUE, TRUE, 0); gtk_widget_show (option_menu); save_menu = create_save_menu (sample); gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), save_menu); gtk_widget_show (frame); /* pack the containing save_options hbox into the save-dialog */ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), save_options, FALSE, FALSE, 0); gtk_widget_show (save_options); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); gtk_widget_set_size_request (dialog, win_width, win_height); if (strcmp (g_path_get_dirname(sample->pathname), ".") == 0) { char last_save [512]; prefs_get_string (LAST_SAVE_KEY, last_save, sizeof (last_save), ""); if (last_save [0]) { gchar * last_save_dir = g_dirname (last_save); gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog), last_save_dir); gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(dialog), sample->pathname); g_free (last_save_dir); } } else { retval = gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(dialog), sample->pathname); /* FIXME: bug (local only?) causes gtk_file_chooser_set_filename to fail silently in some cases*/ filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); //printf("filename pre: %s\n", filename); //printf("sample->pathname: %s\n", sample->pathname); } retval = gtk_dialog_run (GTK_DIALOG (dialog)); filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); //printf("filename post: %s\n", filename); sample = view->sample; sd = g_malloc (sizeof (save_as_data)); sd->sample = sample; sd->pathname = filename; if (retval == GTK_RESPONSE_ACCEPT) { if (!sweep_dir_exists (filename)) { g_free (sd); g_free (filename); return; } if (stat (filename, &statbuf) == -1) { switch (errno) { case ENOENT: /* If it doesn't exist, it's ok to save as */ overwrite_ok_cb (NULL, sd); break; default: sweep_perror (errno, filename); break; } } else { /* file exists */ if (access(filename, W_OK) == -1) { sweep_perror (errno, _("You are not allowed to write to\n%s"), filename); } else { snprintf (buf, sizeof (buf), _("%s exists. Overwrite?"), filename); question_dialog_new (sample, _("File exists"), buf, _("Overwrite"), _("Don't overwrite"), G_CALLBACK (overwrite_ok_cb), sd, G_CALLBACK (overwrite_cancel_cb), sd, SWEEP_EDIT_MODE_META); } } /* FIXME: wrapped this due to the above gtk_file_chooser_set_filename problem */ } else if (sd->pathname != NULL) { gchar msg [1024]; snprintf (msg, sizeof (msg), _("Save as %s cancelled"), g_path_get_basename (sd->pathname)); sample_set_tmp_message (sd->sample, msg); } else { g_free (sd); g_free (filename); } gtk_widget_destroy (dialog); }
/*! \brief Do autosave on all pages that are marked. * \par Function Description * Looks for pages with the do_autosave_backup flag activated and * autosaves them. * * \param [in] w_current The GschemToplevel object to search for autosave's. */ void o_autosave_backups(GschemToplevel *w_current) { TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current); GList *iter; PAGE *p_save, *p_current; gchar *backup_filename; gchar *real_filename; gchar *only_filename; gchar *dirname; mode_t saved_umask; mode_t mask; struct stat st; /* save current page */ p_save = toplevel->page_current; for ( iter = geda_list_get_glist( toplevel->pages ); iter != NULL; iter = g_list_next( iter ) ) { p_current = (PAGE *)iter->data; if (p_current->do_autosave_backup == 0) { continue; } if (p_current->ops_since_last_backup != 0) { /* make p_current the current page of toplevel */ s_page_goto (toplevel, p_current); gschem_toplevel_page_changed (w_current); /* Get the real filename and file permissions */ real_filename = follow_symlinks (p_current->page_filename, NULL); if (real_filename == NULL) { s_log_message (_("o_autosave_backups: Can't get the real filename of %s."), p_current->page_filename); } else { /* Get the directory in which the real filename lives */ dirname = g_path_get_dirname (real_filename); only_filename = g_path_get_basename(real_filename); backup_filename = g_strdup_printf("%s%c"AUTOSAVE_BACKUP_FILENAME_STRING, dirname, G_DIR_SEPARATOR, only_filename); /* If there is not an existing file with that name, compute the * permissions and uid/gid that we will use for the newly-created file. */ if (stat (real_filename, &st) != 0) { #if defined(HAVE_GETUID) && defined(HAVE_GETGID) struct stat dir_st; int result; #endif /* Use default permissions */ saved_umask = umask(0); st.st_mode = 0666 & ~saved_umask; umask(saved_umask); #if defined(HAVE_GETUID) && defined(HAVE_GETGID) st.st_uid = getuid (); result = stat (dirname, &dir_st); if (result == 0 && (dir_st.st_mode & S_ISGID)) st.st_gid = dir_st.st_gid; else st.st_gid = getgid (); #endif } g_free (dirname); g_free (only_filename); g_free (real_filename); /* Make the backup file writable before saving a new one */ if ( g_file_test (backup_filename, G_FILE_TEST_EXISTS) && (! g_file_test (backup_filename, G_FILE_TEST_IS_DIR))) { saved_umask = umask(0); if (chmod(backup_filename, (S_IWRITE|S_IWGRP|S_IWOTH) & ((~saved_umask) & 0777)) != 0) { s_log_message (_("Could NOT set previous backup file [%s] read-write\n"), backup_filename); } umask(saved_umask); } if (o_save (toplevel, s_page_objects (toplevel->page_current), backup_filename, NULL)) { p_current->ops_since_last_backup = 0; p_current->do_autosave_backup = 0; /* Make the backup file readonly so a 'rm *' command will ask the user before deleting it */ saved_umask = umask(0); mask = (S_IWRITE|S_IWGRP|S_IEXEC|S_IXGRP|S_IXOTH); mask = (~mask)&0777; mask &= ((~saved_umask) & 0777); if (chmod(backup_filename,mask) != 0) { s_log_message (_("Could NOT set backup file [%s] readonly\n"), backup_filename); } umask(saved_umask); } else { s_log_message (_("Could NOT save backup file [%s]\n"), backup_filename); } g_free (backup_filename); } } } /* restore current page */ s_page_goto (toplevel, p_save); gschem_toplevel_page_changed (w_current); }
static void yahoo_sendfile_connected(gpointer data, gint source, const gchar *error_message) { PurpleXfer *xfer; struct yahoo_xfer_data *xd; struct yahoo_packet *pkt; gchar *size, *filename, *encoded_filename, *header; guchar *pkt_buf; const char *host; int port; size_t content_length, header_len, pkt_buf_len; PurpleConnection *gc; PurpleAccount *account; struct yahoo_data *yd; purple_debug(PURPLE_DEBUG_INFO, "yahoo", "AAA - in yahoo_sendfile_connected\n"); if (!(xfer = data)) return; if (!(xd = xfer->data)) return; if (source < 0) { purple_xfer_error(PURPLE_XFER_RECEIVE, purple_xfer_get_account(xfer), xfer->who, _("Unable to connect.")); purple_xfer_cancel_remote(xfer); return; } xfer->fd = source; /* Assemble the tx buffer */ gc = xd->gc; account = purple_connection_get_account(gc); yd = gc->proto_data; pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, YAHOO_STATUS_AVAILABLE, yd->session_id); size = g_strdup_printf("%" G_GSIZE_FORMAT, purple_xfer_get_size(xfer)); filename = g_path_get_basename(purple_xfer_get_local_filename(xfer)); encoded_filename = yahoo_string_encode(gc, filename, NULL); yahoo_packet_hash(pkt, "sssss", 0, purple_connection_get_display_name(gc), 5, xfer->who, 14, "", 27, encoded_filename, 28, size); g_free(size); g_free(encoded_filename); g_free(filename); content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, yd->jp, &pkt_buf); yahoo_packet_free(pkt); host = purple_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); port = purple_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); header = g_strdup_printf( "POST http://%s:%d/notifyft HTTP/1.0\r\n" "Content-length: %" G_GSIZE_FORMAT "\r\n" "Host: %s:%d\r\n" "Cookie: Y=%s; T=%s\r\n" "\r\n", host, port, content_length + 4 + purple_xfer_get_size(xfer), host, port, yd->cookie_y, yd->cookie_t); header_len = strlen(header); xd->txbuflen = header_len + pkt_buf_len + 4; xd->txbuf = g_malloc(xd->txbuflen); memcpy(xd->txbuf, header, header_len); g_free(header); memcpy(xd->txbuf + header_len, pkt_buf, pkt_buf_len); g_free(pkt_buf); memcpy(xd->txbuf + header_len + pkt_buf_len, "29\xc0\x80", 4); xd->txbuf_written = 0; if (xd->tx_handler == 0) { xd->tx_handler = purple_input_add(source, PURPLE_INPUT_WRITE, yahoo_sendfile_send_cb, xfer); yahoo_sendfile_send_cb(xfer, source, PURPLE_INPUT_WRITE); } }
/* Convert an upgrade into an image. The image has neither boot block nor certificate. */ int ti68k_convert_tib_to_image(const char *srcname, const char *dirname, char **dstname, int hw_type) { FILE *f; int err; IMG_INFO img; char *ext; gchar *basename; int i, j; int num_blocks, last_block; int real_size; HW_PARM_BLOCK hwpb; *dstname = NULL; // No filename, exits if(!strcmp(g_basename(srcname), "")) return ERR_CANT_OPEN; // Preload upgrade memset(&img, 0, sizeof(IMG_INFO)); err = ti68k_get_tib_infos(srcname, &img, !0); if(err) { free(img.data); tiemu_info(_("Unable to get information on FLASH upgrade: <%s>"), srcname); return err; } ti68k_display_tib_infos(&img); // Create destination file basename = g_path_get_basename(srcname); ext = strrchr(basename, '.'); *ext='\0'; strcat(basename, ".img"); *dstname = g_strconcat(dirname, basename, NULL); g_free(basename); // Open dest file f = fopen(*dstname, "wb"); if(f == NULL) { tiemu_warning("Unable to open this file: <%s>\n", *dstname); return ERR_CANT_OPEN; } // Fill header strcpy(img.signature, IMG_SIGN); img.header_size = sizeof(IMG_INFO); img.revision = IMG_REV; real_size = img.size - SPP; img.size = ti68k_get_rom_size(img.calc_type); img.hw_type = hw_type; if(hw_type == -1) { if(img.calc_type == TI89t) img.hw_type = HW3; //default else if(img.calc_type == TI89 || img.calc_type == TI92p || img.calc_type == V200) img.hw_type = HW2; // default } // Write header if (fwrite(&img, 1, sizeof(IMG_INFO), f) < sizeof(IMG_INFO)) { tiemu_warning("Failed to write to file: <%s>\n", *dstname); fclose(f); return ERR_CANT_OPEN; } // Write boot block memcpy(img.data, &img.data[SPP + BO], 256); if (fwrite(img.data, 1, 256, f) < 256) { tiemu_warning("Failed to write to file: <%s>\n", *dstname); fclose(f); return ERR_CANT_OPEN; } // Write hardware param block // fill structure hwpb.len = 24; switch(img.calc_type) { case TI89: hwpb.hardwareID = HWID_TI89; hwpb.hardwareRevision = img.hw_type - 1; break; case TI92p: hwpb.hardwareID = HWID_TI92P; hwpb.hardwareRevision = img.hw_type - 1; break; case V200: hwpb.hardwareID = HWID_V200; hwpb.hardwareRevision = 2; break; case TI89t: hwpb.hardwareID = HWID_TI89T; hwpb.hardwareRevision = 2; break; } hwpb.bootMajor = hwpb.bootRevision = hwpb.bootBuild = 1; hwpb.gateArray = img.hw_type; ti68k_put_hw_param_block((uint8_t *)img.data, img.rom_base, &hwpb); // write filler if (fputc(0xfe, f) < 0 || fputc(0xed, f) < 0 || fputc(0xba, f) < 0 || fputc(0xbe, f) < 0 //fwrite(&hwpb, 1hwpb.len+2, f); // write address (pointer) || fputc(0x00, f) < 0 || fputc(img.rom_base, f) < 0 || fputc(0x01, f) < 0 || fputc(0x08, f) < 0 // write structure || fputc(MSB(hwpb.len), f) < 0 || fputc(LSB(hwpb.len), f) < 0 || fputc(MSB(MSW(hwpb.hardwareID)), f) < 0 || fputc(LSB(MSW(hwpb.hardwareID)), f) < 0 || fputc(MSB(LSW(hwpb.hardwareID)), f) < 0 || fputc(LSB(LSW(hwpb.hardwareID)), f) < 0 || fputc(MSB(MSW(hwpb.hardwareRevision)), f) < 0 || fputc(LSB(MSW(hwpb.hardwareRevision)), f) < 0 || fputc(MSB(LSW(hwpb.hardwareRevision)), f) < 0 || fputc(LSB(LSW(hwpb.hardwareRevision)), f) < 0 || fputc(MSB(MSW(hwpb.bootMajor)), f) < 0 || fputc(LSB(MSW(hwpb.bootMajor)), f) < 0 || fputc(MSB(LSW(hwpb.bootMajor)), f) < 0 || fputc(LSB(LSW(hwpb.bootMajor)), f) < 0 || fputc(MSB(MSW(hwpb.hardwareRevision)), f) < 0 || fputc(LSB(MSW(hwpb.hardwareRevision)), f) < 0 || fputc(MSB(LSW(hwpb.hardwareRevision)), f) < 0 || fputc(LSB(LSW(hwpb.hardwareRevision)), f) < 0 || fputc(MSB(MSW(hwpb.bootBuild)), f) < 0 || fputc(LSB(MSW(hwpb.bootBuild)), f) < 0 || fputc(MSB(LSW(hwpb.bootBuild)), f) < 0 || fputc(LSB(LSW(hwpb.bootBuild)), f) < 0 || fputc(MSB(MSW(hwpb.gateArray)), f) < 0 || fputc(LSB(MSW(hwpb.gateArray)), f) < 0 || fputc(MSB(LSW(hwpb.gateArray)), f) < 0 || fputc(LSB(LSW(hwpb.gateArray)), f) < 0) { tiemu_warning("Failed to write to file: <%s>\n", *dstname); fclose(f); return ERR_CANT_OPEN; } // Fill with 0xff up-to System Part for(i = 0x108 + hwpb.len+2; i < SPP; i++) if (fputc(0xff, f) < 0) { tiemu_warning("Failed to write to file: <%s>\n", *dstname); fclose(f); return ERR_CANT_OPEN; } // Copy FLASH upgrade at 0x12000 (SPP) num_blocks = real_size / 65536; for(i = 0; i < num_blocks; i++ ) { tiemu_info("."); fflush(stdout); if (fwrite(&img.data[65536 * i + SPP], sizeof(char), 65536, f) < 65536) { tiemu_warning("Failed to write to file: <%s>\n", *dstname); fclose(f); return ERR_CANT_OPEN; } } last_block = real_size % 65536; if (fwrite(&img.data[65536 * i + SPP], sizeof(char), last_block, f) < (size_t)last_block) { tiemu_warning("Failed to write to file: <%s>\n", *dstname); fclose(f); return ERR_CANT_OPEN; } tiemu_info(""); tiemu_info("Completing to %iMB size\n", img.size >> 20); for(j = SPP + real_size; j < img.size; j++) if (fputc(0xff, f) < 0) { tiemu_warning("Failed to write to file: <%s>\n", *dstname); fclose(f); return ERR_CANT_OPEN; } // Close file if (fclose(f)) { tiemu_warning("Failed to close file: <%s>\n", *dstname); return ERR_CANT_OPEN; } return 0; }
int main (int argc, char **argv) { GHashTable *candidates; gchar *dir; gchar *base; gchar *highest = NULL; gchar *binary; /* actual binary we're going to run */ gchar *path = NULL; /* and its path */ gchar *desc; GOptionContext *ctx; GError *err = NULL; /* detect stuff */ dir = get_dir_of_binary (argv[0]); base = g_path_get_basename (argv[0]); /* parse command line options */ desc = g_strdup_printf ("wrapper to call versioned %s", base); ctx = g_option_context_new (desc); g_free (desc); g_option_context_set_ignore_unknown_options (ctx, TRUE); g_option_context_add_main_entries (ctx, wrapper_options, GETTEXT_PACKAGE); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", err->message); exit (1); } g_option_context_free (ctx); /* unmangle libtool if necessary */ unmangle_libtool (&dir, &base); /* get all candidate binaries */ candidates = get_candidates (dir, base); g_free (dir); if (_arg_mm) { /* if a version was forced, look it up in the hash table */ dir = g_hash_table_lookup (candidates, _arg_mm); if (!dir) { g_print ("ERROR: Major/minor %s of tool %s not found.\n", _arg_mm, base); return 1; } binary = g_strdup_printf ("%s-%s", base, _arg_mm); } else { highest = NULL; /* otherwise, just look up the highest version */ if (candidates) { g_hash_table_foreach (candidates, (GHFunc) find_highest_version, &highest); } if (highest == NULL) { g_print ("ERROR: No version of tool %s found.\n", base); return 1; } dir = g_hash_table_lookup (candidates, highest); binary = g_strdup_printf ("%s-%s", base, highest); } g_free (base); path = g_build_filename (dir, binary, NULL); g_free (binary); /* print out list of major/minors we found if asked for */ /* FIXME: do them in order by creating a GList of keys and sort them */ if (_arg_list_mm) { g_hash_table_foreach (candidates, (GHFunc) hash_print_key, NULL); g_hash_table_destroy (candidates); return 0; } /* print out command line if asked for */ argv[0] = path; if (_print) { int i; for (i = 0; i < argc; ++i) { g_print ("%s", argv[i]); if (i < argc - 1) g_print (" "); } g_print ("\n"); } /* execute */ if (execv (path, argv) == -1) { g_warning ("Error executing %s: %s (%d)", path, g_strerror (errno), errno); } g_free (path); return 0; }
void format_pretty_list (xmmsc_connection_t *conn, GList *list) { guint count = 0; GList *n; gint columns; gchar *format_header, *format_rows; columns = find_terminal_width (); format_header = make_justified_columns_format (columns, 's'); format_rows = make_justified_columns_format (columns, 'd'); print_padded_string (columns, '-', TRUE, "-[Result]-"); print_info (format_header, "Id", "Artist", "Album", "Title"); for (n = list; n; n = g_list_next (n)) { const gchar *title; xmmsc_result_t *res; xmmsv_t *propdict, *val; gint mid = XPOINTER_TO_INT (n->data); if (!mid) { print_error ("Empty result!"); } res = xmmsc_medialib_get_info (conn, mid); xmmsc_result_wait (res); propdict = xmmsc_result_get_value (res); val = xmmsv_propdict_to_dict (propdict, NULL); if (xmmsv_dict_entry_get_string (val, "title", &title)) { const gchar *artist, *album; if (!xmmsv_dict_entry_get_string (val, "artist", &artist)) { artist = "Unknown"; } if (!xmmsv_dict_entry_get_string (val, "album", &album)) { album = "Unknown"; } print_info (format_rows, mid, artist, album, title); } else { const gchar *url; xmmsv_dict_entry_get_string (val, "url", &url); if (url) { gchar *filename = g_path_get_basename (url); if (filename) { print_info ("%-5.5d| %s", mid, filename); g_free (filename); } } } count++; xmmsv_unref (val); xmmsc_result_unref (res); } print_padded_string (columns, '-', FALSE, "-[Count:%6.d]-----", count); g_free (format_header); g_free (format_rows); }
static gboolean gimp_thumbnail_save (GimpThumbnail *thumbnail, GimpThumbSize size, const gchar *filename, GdkPixbuf *pixbuf, const gchar *software, GError **error) { const gchar *keys[12]; gchar *values[12]; gchar *basename; gchar *dirname; gchar *tmpname; gboolean success; gint i = 0; keys[i] = TAG_DESCRIPTION; values[i] = g_strdup_printf ("Thumbnail of %s", thumbnail->image_uri); i++; keys[i] = TAG_SOFTWARE; values[i] = g_strdup (software); i++; keys[i] = TAG_THUMB_URI; values[i] = g_strdup (thumbnail->image_uri); i++; keys[i] = TAG_THUMB_MTIME; values[i] = g_strdup_printf ("%" G_GINT64_FORMAT, thumbnail->image_mtime); i++; keys[i] = TAG_THUMB_FILESIZE; values[i] = g_strdup_printf ("%" G_GINT64_FORMAT, thumbnail->image_filesize); i++; if (thumbnail->image_mimetype) { keys[i] = TAG_THUMB_MIMETYPE; values[i] = g_strdup (thumbnail->image_mimetype); i++; } if (thumbnail->image_width > 0) { keys[i] = TAG_THUMB_IMAGE_WIDTH; values[i] = g_strdup_printf ("%d", thumbnail->image_width); i++; } if (thumbnail->image_height > 0) { keys[i] = TAG_THUMB_IMAGE_HEIGHT; values[i] = g_strdup_printf ("%d", thumbnail->image_height); i++; } if (thumbnail->image_type) { keys[i] = TAG_THUMB_GIMP_TYPE; values[i] = g_strdup (thumbnail->image_type); i++; } if (thumbnail->image_num_layers > 0) { keys[i] = TAG_THUMB_GIMP_LAYERS; values[i] = g_strdup_printf ("%d", thumbnail->image_num_layers); i++; } keys[i] = NULL; values[i] = NULL; basename = g_path_get_basename (filename); dirname = g_path_get_dirname (filename); tmpname = g_strdup_printf ("%s%cgimp-thumb-%d-%.8s", dirname, G_DIR_SEPARATOR, getpid (), basename); g_free (dirname); g_free (basename); success = gdk_pixbuf_savev (pixbuf, tmpname, "png", (gchar **) keys, values, error); for (i = 0; keys[i]; i++) g_free (values[i]); if (success) { #ifdef GIMP_THUMB_DEBUG g_printerr ("thumbnail saved to temporary file %s\n", tmpname); #endif success = (g_rename (tmpname, filename) == 0); if (! success) g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), _("Could not create thumbnail for %s: %s"), thumbnail->image_uri, g_strerror (errno)); } if (success) { #ifdef GIMP_THUMB_DEBUG g_printerr ("temporary thumbnail file renamed to %s\n", filename); #endif success = (g_chmod (filename, 0600) == 0); if (! success) g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), "Could not set permissions of thumbnail for %s: %s", thumbnail->image_uri, g_strerror (errno)); g_object_freeze_notify (G_OBJECT (thumbnail)); gimp_thumbnail_update_thumb (thumbnail, size); if (success && thumbnail->thumb_state == GIMP_THUMB_STATE_EXISTS && strcmp (filename, thumbnail->thumb_filename) == 0) { thumbnail->thumb_state = GIMP_THUMB_STATE_OK; } g_object_thaw_notify (G_OBJECT (thumbnail)); } g_unlink (tmpname); g_free (tmpname); return success; }
static void create_file_save_as_dialog(const gchar *extension, ExportFunc func, gboolean show_zoom_level_checkbox) { GtkWidget *dialog, *vbox; GeanyDocument *doc; ExportInfo *exi; g_return_if_fail(extension != NULL); doc = document_get_current(); g_return_if_fail(doc != NULL); exi = g_new(ExportInfo, 1); exi->doc = doc; exi->export_func = func; exi->have_zoom_level_checkbox = FALSE; dialog = gtk_file_chooser_dialog_new(_("Export File"), GTK_WINDOW(geany->main_widgets->window), GTK_FILE_CHOOSER_ACTION_SAVE, NULL, NULL); gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE); gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG); gtk_widget_set_name(dialog, "GeanyExportDialog"); gtk_dialog_add_buttons(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); /* file chooser extra widget */ vbox = gtk_vbox_new(FALSE, 0); gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(dialog), vbox); { GtkWidget *check_line_numbers; check_line_numbers = gtk_check_button_new_with_mnemonic(_("_Insert line numbers")); gtk_widget_set_tooltip_text(check_line_numbers, _("Insert line numbers before each line in the exported document")); gtk_box_pack_start(GTK_BOX(vbox), check_line_numbers, FALSE, FALSE, 0); gtk_widget_show_all(vbox); ui_hookup_widget(dialog, check_line_numbers, "check_line_numbers"); } if (show_zoom_level_checkbox) { GtkWidget *check_zoom_level; check_zoom_level = gtk_check_button_new_with_mnemonic(_("_Use current zoom level")); gtk_widget_set_tooltip_text(check_zoom_level, _("Renders the font size of the document together with the current zoom level")); gtk_box_pack_start(GTK_BOX(vbox), check_zoom_level, FALSE, FALSE, 0); gtk_widget_show_all(vbox); ui_hookup_widget(dialog, check_zoom_level, "check_zoom_level"); exi->have_zoom_level_checkbox = TRUE; } g_signal_connect(dialog, "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL); g_signal_connect(dialog, "response", G_CALLBACK(on_file_save_dialog_response), exi); gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(geany->main_widgets->window)); /* if the current document has a filename we use it as the default. */ gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(dialog)); if (doc->file_name != NULL) { gchar *base_name = g_path_get_basename(doc->file_name); gchar *file_name; gchar *locale_filename; gchar *locale_dirname; const gchar *suffix = ""; if (g_str_has_suffix(doc->file_name, extension)) suffix = "_export"; file_name = g_strconcat(base_name, suffix, extension, NULL); locale_filename = utils_get_locale_from_utf8(doc->file_name); locale_dirname = g_path_get_dirname(locale_filename); /* set the current name to base_name.html which probably doesn't exist yet so * gtk_file_chooser_set_filename() can't be used and we need * gtk_file_chooser_set_current_folder() additionally */ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_dirname); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), file_name); g_free(locale_dirname); g_free(locale_filename); g_free(file_name); g_free(base_name); } else { const gchar *default_open_path = geany->prefs->default_open_path; gchar *fname = g_strconcat(GEANY_STRING_UNTITLED, extension, NULL); gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(dialog)); gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), fname); /* use default startup directory(if set) if no files are open */ if (!EMPTY(default_open_path) && g_path_is_absolute(default_open_path)) { gchar *locale_path = utils_get_locale_from_utf8(default_open_path); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), locale_path); g_free(locale_path); } g_free(fname); } gtk_dialog_run(GTK_DIALOG(dialog)); }
static void panel_run_dialog_update_completion (PanelRunDialog *dialog, const char *text) { GList *list; GList *executables; char prefix; char *buf; char *dirname; char *dirprefix; char *key; g_assert (text != NULL && *text != '\0' && !g_ascii_isspace (*text)); list = NULL; executables = NULL; if (!dialog->completion) { dialog->completion = g_completion_new (NULL); dialog->possible_executables = fill_possible_executables (); dialog->dir_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); } buf = g_path_get_basename (text); prefix = buf[0]; g_free (buf); if (prefix == '/' || prefix == '.') return; if (text [0] == '/') { /* complete against absolute path */ dirname = g_path_get_dirname (text); dirprefix = g_strdup (dirname); } else { /* complete against relative path and executable name */ if (!strchr (text, '/')) { executables = fill_executables (dialog->possible_executables, dialog->completion_items, text [0]); dirprefix = g_strdup (""); } else { dirprefix = g_path_get_dirname (text); } dirname = g_build_filename (g_get_home_dir (), dirprefix, NULL); } key = g_strdup_printf ("%s%c%c", dirprefix, G_DIR_SEPARATOR, prefix); if (!g_hash_table_lookup (dialog->dir_hash, key)) { g_hash_table_insert (dialog->dir_hash, key, dialog); list = fill_files_from (dirname, dirprefix, prefix, dialog->completion_items); } else { g_free (key); } list = g_list_concat (list, executables); g_free (dirname); g_free (dirprefix); if (list == NULL) return; g_completion_add_items (dialog->completion, list); dialog->completion_items = g_list_concat (dialog->completion_items, list); }
static void i2c_sys_plugin_add_sensor(GList **sensors, const gchar *path) { gchar *filename; gchar *id; gchar *label; gboolean enable; guint sensor_type; IconType icon_type = GENERIC_ICON; filename = g_path_get_basename(path); /* setup temp2 as CPU sensor and enable it */ if (g_ascii_strcasecmp(filename, "temp2_input") == 0) { id = g_strndup(filename, 5); label = g_strdup(_("CPU")); sensor_type = TEMP_SENSOR; enable = TRUE; icon_type = CPU_ICON; } else { switch(filename[0]) { case 'c': /* either current or cpu?_vid sensor */ if (filename[1] == 'u') { /* currents are curr?_input */ id = g_strndup(filename, 5); label = g_strndup(filename, 5); sensor_type = CURRENT_SENSOR; } else { /* cpu_vid is cpu?_vid */ id = g_strdup(filename); label = g_strdup(filename); sensor_type = VOLTAGE_SENSOR; } break; case 'f': /* fans are "fan?_input" */ id = g_strndup(filename, 4); label = g_strndup(filename, 4); sensor_type = FAN_SENSOR; icon_type = FAN_ICON; break; case 't': /* temps are "temp?_input" */ id = g_strndup(filename, 5); label = g_strndup(filename, 5); sensor_type = TEMP_SENSOR; break; case 'i': /* voltages are "in?_input" */ id = g_strndup(filename, 3); label = g_strndup(filename, 3); sensor_type = VOLTAGE_SENSOR; break; default: /* SHOULDN'T BE ABLE * TO GET HERE!! */ g_warning("filename:\"%s\" begins with a charater that is not covered by this switch statement... not adding sensor", filename); g_free(filename); g_free(id); g_free(label); return; } /* disable all other sensors */ enable = FALSE; } sensors_applet_plugin_add_sensor(sensors, path, id, label, sensor_type, enable, icon_type, DEFAULT_GRAPH_COLOR); g_free(filename); g_free(id); g_free(label); }
/* * Write tag of the ETFile * Return TRUE => OK * FALSE => error */ static gboolean Write_File_Tag (ET_File *ETFile, gboolean hide_msgbox) { GError *error = NULL; const gchar *cur_filename_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8; gchar *msg = NULL; gchar *basename_utf8; GtkWidget *msgdialog; basename_utf8 = g_path_get_basename(cur_filename_utf8); msg = g_strdup_printf (_("Writing tag of ‘%s’"),basename_utf8); et_application_window_status_bar_message (ET_APPLICATION_WINDOW (MainWindow), msg, TRUE); g_free(msg); msg = NULL; if (ET_Save_File_Tag_To_HD (ETFile, &error)) { msg = g_strdup_printf (_("Wrote tag of ‘%s’"), basename_utf8); et_application_window_status_bar_message (ET_APPLICATION_WINDOW (MainWindow), msg, TRUE); g_free (msg); g_free (basename_utf8); return TRUE; } Log_Print (LOG_ERROR, "%s", error->message); if (!hide_msgbox) { #ifdef ENABLE_ID3LIB if (g_error_matches (error, ET_ID3_ERROR, ET_ID3_ERROR_BUGGY_ID3LIB)) { msgdialog = gtk_message_dialog_new (GTK_WINDOW (MainWindow), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", _("You have tried to save " "this tag to Unicode but it " "was detected that your " "version of id3lib is buggy")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog), _("If you reload this " "file, some characters " "in the tag may not be " "displayed correctly. " "Please, apply the " "patch " "src/id3lib/patch_id3lib_3.8.3_UTF16_writing_bug.diff " "to id3lib, which is " "available in the " "EasyTAG package " "sources.\nNote that " "this message will " "appear only " "once.\n\nFile: %s"), basename_utf8); } else #endif { msgdialog = gtk_message_dialog_new (GTK_WINDOW (MainWindow), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Cannot write tag in file ‘%s’"), basename_utf8); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (msgdialog), "%s", error->message); gtk_window_set_title (GTK_WINDOW (msgdialog), _("Tag Write Error")); } gtk_dialog_run(GTK_DIALOG(msgdialog)); gtk_widget_destroy(msgdialog); } g_clear_error (&error); g_free(basename_utf8); return FALSE; }
gint pk_backend_fetchcb (const gchar *url, const gchar *path, gint force) { GRegex *xo, *xi; gchar *oldpwd, *basename, *file, *part; gchar *tempcmd = NULL, *finalcmd = NULL; gint result = 0; g_return_val_if_fail (url != NULL, -1); g_return_val_if_fail (path != NULL, -1); g_return_val_if_fail (xfercmd != NULL, -1); g_return_val_if_fail (backend != NULL, -1); oldpwd = g_get_current_dir (); if (g_chdir (path) < 0) { g_warning ("could not find or read directory %s", path); g_free (oldpwd); return -1; } xo = g_regex_new ("%o", 0, 0, NULL); xi = g_regex_new ("%u", 0, 0, NULL); basename = g_path_get_basename (url); file = g_strconcat (path, basename, NULL); part = g_strconcat (file, ".part", NULL); if (force != 0 && g_file_test (part, G_FILE_TEST_EXISTS)) { g_unlink (part); } if (force != 0 && g_file_test (file, G_FILE_TEST_EXISTS)) { g_unlink (file); } tempcmd = g_regex_replace_literal (xo, xfercmd, -1, 0, part, 0, NULL); if (tempcmd == NULL) { result = -1; goto out; } finalcmd = g_regex_replace_literal (xi, tempcmd, -1, 0, url, 0, NULL); if (finalcmd == NULL) { result = -1; goto out; } if (!pk_backend_spawn (backend, finalcmd)) { result = -1; goto out; } else if (g_strrstr (xfercmd, "%o") != NULL) { /* using .part filename */ if (g_rename (part, file) < 0) { g_warning ("could not rename %s", part); result = -1; goto out; } } out: g_free (finalcmd); g_free (tempcmd); g_free (part); g_free (file); g_free (basename); g_regex_unref (xi); g_regex_unref (xo); g_chdir (oldpwd); g_free (oldpwd); return result; }
static DiaSvgRenderer * new_shape_renderer(DiagramData *data, const char *filename) { ShapeRenderer *shape_renderer; DiaSvgRenderer *renderer; FILE *file; char *point; xmlNsPtr name_space; xmlNodePtr xml_node_ptr; gint i; gchar *png_filename; char *shapename, *dirname, *fullname; char *sheetname; file = g_fopen(filename, "w"); if (file==NULL) { message_error(_("Can't open output file %s: %s\n"), dia_message_filename(filename), strerror(errno)); return NULL; } fclose(file); shape_renderer = g_object_new(SHAPE_TYPE_RENDERER, NULL); renderer = DIA_SVG_RENDERER (shape_renderer); renderer->filename = g_strdup(filename); renderer->dash_length = 1.0; renderer->dot_length = 0.2; renderer->saved_line_style = LINESTYLE_SOLID; /* keep everything unscaled, i.e. in Dia's scale default */ renderer->scale = 1.0; /* set up the root node */ renderer->doc = xmlNewDoc((const xmlChar *)"1.0"); renderer->doc->encoding = xmlStrdup((const xmlChar *)"UTF-8"); renderer->root = xmlNewDocNode(renderer->doc, NULL, (const xmlChar *)"shape", NULL); name_space = xmlNewNs(renderer->root, (const xmlChar *)"http://www.daa.com.au/~james/dia-shape-ns", NULL); renderer->svg_name_space = xmlNewNs(renderer->root, (const xmlChar *)"http://www.w3.org/2000/svg", (const xmlChar *)"svg"); renderer->doc->xmlRootNode = renderer->root; dirname = g_path_get_dirname(filename); sheetname = g_path_get_basename(dirname); shapename = g_strndup(g_basename(filename), strlen(g_basename(filename))-6); fullname = g_strdup_printf ("%s - %s", sheetname, shapename); g_free(dirname); g_free(sheetname); g_free(shapename); xmlNewChild(renderer->root, NULL, (const xmlChar *)"name", (xmlChar *) fullname); g_free(fullname); point = strrchr(filename, '.'); i = (int)(point-filename); point = g_strndup(filename, i); png_filename = g_strdup_printf("%s.png",point); g_free(point); xmlNewChild(renderer->root, NULL, (const xmlChar *)"icon", (xmlChar *) g_basename(png_filename)); g_free(png_filename); shape_renderer->connection_root = xmlNewChild(renderer->root, NULL, (const xmlChar *)"connections", NULL); xml_node_ptr = xmlNewChild(renderer->root, NULL, (const xmlChar *)"aspectratio",NULL); xmlSetProp(xml_node_ptr, (const xmlChar *)"type", (const xmlChar *)"fixed"); renderer->root = xmlNewChild(renderer->root, renderer->svg_name_space, (const xmlChar *)"svg", NULL); return renderer; }
static void update_cb(evhtp_request_t *req, void *arg) { RecvFSM *fsm = arg; SearpcClient *rpc_client = NULL; char *target_file, *parent_dir = NULL, *filename = NULL; const char *head_id = NULL; GError *error = NULL; int error_code = ERROR_INTERNAL; if (!fsm || fsm->state == RECV_ERROR) return; if (!fsm->tmp_files) { seaf_warning ("[update] No file uploaded.\n"); evhtp_send_reply (req, EVHTP_RES_BADREQ); return; } target_file = g_hash_table_lookup (fsm->form_kvs, "target_file"); if (!target_file) { seaf_warning ("[Update] No target file given.\n"); evbuffer_add_printf(req->buffer_out, "Invalid URL.\n"); evhtp_send_reply (req, EVHTP_RES_BADREQ); return; } parent_dir = g_path_get_dirname (target_file); filename = g_path_get_basename (target_file); if (!check_tmp_file_list (fsm->tmp_files, &error_code)) goto error; head_id = evhtp_kv_find (req->uri->query, "head"); rpc_client = ccnet_create_pooled_rpc_client (seaf->client_pool, NULL, "seafserv-threaded-rpcserver"); if (seafile_check_quota (rpc_client, fsm->repo_id, NULL) < 0) { seaf_warning ("[update] Out of quota.\n"); error_code = ERROR_QUOTA; goto error; } seafile_put_file (rpc_client, fsm->repo_id, (char *)(fsm->tmp_files->data), parent_dir, filename, fsm->user, head_id, &error); if (error) { if (g_strcmp0 (error->message, "file does not exist") == 0) { error_code = ERROR_NOT_EXIST; } if (error->message) printf ("%s\n", error->message); g_clear_error (&error); goto error; } ccnet_rpc_client_free (rpc_client); /* Redirect to repo dir page after upload finishes. */ redirect_to_success_page (req, fsm->repo_id, parent_dir); g_free (parent_dir); g_free (filename); return; error: if (rpc_client) ccnet_rpc_client_free (rpc_client); redirect_to_update_error (req, fsm->repo_id, target_file, error_code); g_free (parent_dir); g_free (filename); }
/** * @brief Open a new resource and create a new instance * * @param srv The server object for the vhost requesting the resource * @param inner_path The path, relative to the avroot, for the * resource * * @return A new Resource object * @retval NULL Error while opening resource */ Resource *r_open(struct feng *srv, const char *inner_path) { Resource *r; const Demuxer *dmx; gchar *mrl = g_strjoin ("/", srv->config_storage[0].document_root->ptr, inner_path, NULL); struct stat filestat; if (stat(mrl, &filestat) == -1 ) { switch(errno) { case ENOENT: fnc_log(FNC_LOG_ERR,"%s: file not found\n", mrl); break; default: fnc_log(FNC_LOG_ERR,"Cannot stat file %s\n", mrl); break; } goto error; } if ( S_ISFIFO(filestat.st_mode) ) { fnc_log(FNC_LOG_ERR, "%s: not a file\n"); goto error; } if ( (dmx = r_find_demuxer(mrl)) == NULL ) { fnc_log(FNC_LOG_DEBUG, "[MT] Could not find a valid demuxer for resource %s\n", mrl); goto error; } fnc_log(FNC_LOG_DEBUG, "[MT] registrered demuxer \"%s\" for resource" "\"%s\"\n", dmx->info->name, mrl); r = g_slice_new0(Resource); r->info = g_slice_new0(ResourceInfo); r->info->mrl = mrl; r->info->mtime = filestat.st_mtime; r->info->name = g_path_get_basename(inner_path); r->info->seekable = (dmx->seek != NULL); r->demuxer = dmx; r->srv = srv; if (r->demuxer->init(r)) { r_free_cb(r, NULL); return NULL; } /* Now that we have opened the actual resource we can proceed with * the extras */ r->lock = g_mutex_new(); #ifdef HAVE_METADATA cpd_find_request(srv, r, filename); #endif return r; error: g_free(mrl); return NULL; }
/* Convert a romdump into an image. This kind of image is complete (boot & certificate). */ int ti68k_convert_rom_to_image(const char *srcname, const char *dirname, char **dstname) { FILE *f; int err; IMG_INFO img; char *ext; gchar *basename; *dstname = NULL; // No filename, exits if(!strcmp(g_basename(srcname), "")) return ERR_CANT_OPEN; // Preload romdump memset(&img, 0, sizeof(IMG_INFO)); err = ti68k_get_rom_infos(srcname, &img, !0); if(err) { free(img.data); tiemu_info(_("Unable to get information on ROM dump: %s"), srcname); return err; } ti68k_display_rom_infos(&img); // Create destination file basename = g_path_get_basename(srcname); ext = strrchr(basename, '.'); *ext='\0'; strcat(basename, ".img"); *dstname = g_strconcat(dirname, basename, NULL); g_free(basename); // Open dest file f = fopen(*dstname, "wb"); if(f == NULL) { tiemu_warning("Unable to open this file: <%s>\n", *dstname); return ERR_CANT_OPEN; } // Some V200 and TI89 Titanium ROMs are half the size if((img.size < 4*MB) && (img.calc_type == V200 || img.calc_type == TI89t)) { img.size = 4*MB; img.data = realloc(img.data, 4*MB + 4); tiemu_info(_("Completing image to 4 MB!")); memset(img.data + 2*MB, 0xff, 2*MB); } // Fill header strcpy(img.signature, IMG_SIGN); img.header_size = sizeof(IMG_INFO); img.revision = IMG_REV; // Write file if (fwrite(&img, 1, sizeof(IMG_INFO), f) < (size_t)sizeof(IMG_INFO) || fwrite(img.data, sizeof(char), img.size, f) < (size_t)img.size) { tiemu_warning("Failed to write to file: <%s>\n", *dstname); fclose(f); return ERR_CANT_OPEN; } // Close file if (fclose(f)) { tiemu_warning("Failed to close file: <%s>\n", *dstname); return ERR_CANT_OPEN; } return 0; }
/** * Read QTH data from file. * * \param filename The file to read from. * \param qth Pointer to a qth_t data structure where the data will be stored. * \return FALSE if an error occurred, TRUE otherwise. * * \note The function uses the new key=value file parser from glib. */ gint qth_data_read(const gchar * filename, qth_t * qth) { GError *error = NULL; gchar *buff; gchar **buffv; qth->data = g_key_file_new(); g_key_file_set_list_separator(qth->data, ';'); /* bail out with error message if data can not be read */ g_key_file_load_from_file(qth->data, filename, G_KEY_FILE_KEEP_COMMENTS, &error); if (error != NULL) { g_key_file_free(qth->data); qth->data = NULL; sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Could not load data from %s (%s)"), __func__, filename, error->message); return FALSE; } /* send a debug message, then read data */ sat_log_log(SAT_LOG_LEVEL_DEBUG, _("%s: QTH data: %s"), __func__, filename); /*** FIXME: should check that strings are UTF-8? */ /* QTH Name */ buff = g_path_get_basename(filename); buffv = g_strsplit(buff, ".qth", 0); qth->name = g_strdup(buffv[0]); g_free(buff); g_strfreev(buffv); /* QTH location */ qth->loc = g_key_file_get_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_LOC_KEY, &error); if (error != NULL) { sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: QTH has no location (%s)."), __func__, error->message); qth->loc = g_strdup(""); g_clear_error(&error); } /* QTH description */ qth->desc = g_key_file_get_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_DESC_KEY, &error); if ((qth->desc == NULL) || (error != NULL)) { sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: QTH has no description."), __func__); qth->desc = g_strdup(""); g_clear_error(&error); } /* Weather station */ qth->wx = g_key_file_get_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_WX_KEY, &error); if ((qth->wx == NULL) || (error != NULL)) { sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: QTH has no weather station."), __func__); qth->wx = g_strdup(""); g_clear_error(&error); } /* QTH Latitude */ buff = g_key_file_get_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_LAT_KEY, &error); if (error != NULL) { sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Error reading QTH latitude (%s)."), __func__, error->message); g_clear_error(&error); if (buff != NULL) g_free(buff); qth->lat = 0.0; } else { qth->lat = g_ascii_strtod(buff, NULL); g_free(buff); } /* QTH Longitude */ buff = g_key_file_get_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_LON_KEY, &error); if (error != NULL) { sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Error reading QTH longitude (%s)."), __func__, error->message); g_clear_error(&error); if (buff != NULL) g_free(buff); qth->lon = 0.0; } else { qth->lon = g_ascii_strtod(buff, NULL); g_free(buff); } /* QTH Altitude */ qth->alt = g_key_file_get_integer(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_ALT_KEY, &error); if (error != NULL) { sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Error reading QTH altitude (%s)."), __func__, error->message); g_clear_error(&error); if (buff != NULL) g_free(buff); qth->alt = 0; } /* QTH Type */ qth->type = g_key_file_get_integer(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_TYPE_KEY, &error); if (error != NULL) { sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: Error reading QTH type (%s)."), __func__, error->message); g_clear_error(&error); qth->type = QTH_STATIC_TYPE; } #if HAS_LIBGPS /* GPSD Port */ qth->gpsd_port = g_key_file_get_integer(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_GPSD_PORT_KEY, &error); if (error != NULL) { sat_log_log(SAT_LOG_LEVEL_ERROR, _("%s: Error reading GPSD port (%s)."), __func__, error->message); g_clear_error(&error); qth->gpsd_port = 2947; } /* GPSD Server */ qth->gpsd_server = g_key_file_get_string(qth->data, QTH_CFG_MAIN_SECTION, QTH_CFG_GPSD_SERVER_KEY, &error); if ((qth->gpsd_server == NULL) || (error != NULL)) { sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: QTH has no GPSD Server."), __func__); qth->gpsd_server = g_strdup(""); g_clear_error(&error); } #endif /* set QRA based on data */ if (longlat2locator(qth->lon, qth->lat, qth->qra, 2) != RIG_OK) { sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: Could not set QRA for %s at %f, %f."), __func__, qth->name, qth->lon, qth->lat); } qth_validate(qth); /* Now, send debug message and return */ sat_log_log(SAT_LOG_LEVEL_INFO, _("%s: QTH data: %s, %.4f, %.4f, %d"), __func__, qth->name, qth->lat, qth->lon, qth->alt); return TRUE; }
/* Convert an romdump into image and replace SPP by upgrade. The resulting image has boot block. */ int ti68k_merge_rom_and_tib_to_image(const char *srcname1, const char *srcname2, const char *dirname, char **dstname) { FILE *f; int err; IMG_INFO img; char *ext; gchar *basename; int real_size; *dstname = NULL; // No filename, exits if(!strcmp(g_basename(srcname1), "")) return ERR_CANT_OPEN; if(!strcmp(g_basename(srcname2), "")) return ERR_CANT_OPEN; // Preload romdump memset(&img, 0, sizeof(IMG_INFO)); err = ti68k_get_rom_infos(srcname1, &img, !0); if(err) { free(img.data); tiemu_info(_("Unable to get information on ROM dump: %s"), srcname1); return err; } ti68k_display_rom_infos(&img); // Save size real_size = img.size; // Load upgrade err = ti68k_get_tib_infos(srcname2, &img, !0); if(err) { free(img.data); tiemu_info(_("Unable to get information on ROM dump: %s"), srcname2); return err; } ti68k_display_tib_infos(&img); // Create destination file basename = g_path_get_basename(srcname1); ext = strrchr(basename, '.'); *ext='\0'; strcat(basename, ".img"); *dstname = g_strconcat(dirname, basename, NULL); g_free(basename); // Restore size img.size = real_size; // Open dest file f = fopen(*dstname, "wb"); if(f == NULL) { tiemu_warning("Unable to open this file: <%s>\n", *dstname); return ERR_CANT_OPEN; } // Fill header strcpy(img.signature, IMG_SIGN); img.header_size = sizeof(IMG_INFO); img.revision = IMG_REV; img.has_boot = 1; // Write file if (fwrite(&img, 1, sizeof(IMG_INFO), f) < sizeof(IMG_INFO) || fwrite(img.data, sizeof(char), img.size, f) < (size_t)img.size) { tiemu_warning("Failed to write to file: <%s>\n", *dstname); fclose(f); return ERR_CANT_OPEN; } // Close file if (fclose(f)) { tiemu_warning("Failed to close file: <%s>\n", *dstname); return ERR_CANT_OPEN; } return 0; }
static gboolean gtk_app_chooser_search_equal_func (GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer user_data) { gchar *normalized_key; gchar *name, *normalized_name; gchar *path, *normalized_path; gchar *basename, *normalized_basename; gboolean ret; if (key != NULL) { normalized_key = g_utf8_casefold (key, -1); g_assert (normalized_key != NULL); ret = TRUE; gtk_tree_model_get (model, iter, COLUMN_NAME, &name, COLUMN_EXEC, &path, -1); if (name != NULL) { normalized_name = g_utf8_casefold (name, -1); g_assert (normalized_name != NULL); if (strncmp (normalized_name, normalized_key, strlen (normalized_key)) == 0) ret = FALSE; g_free (normalized_name); } if (ret && path != NULL) { normalized_path = g_utf8_casefold (path, -1); g_assert (normalized_path != NULL); basename = g_path_get_basename (path); g_assert (basename != NULL); normalized_basename = g_utf8_casefold (basename, -1); g_assert (normalized_basename != NULL); if (strncmp (normalized_path, normalized_key, strlen (normalized_key)) == 0 || strncmp (normalized_basename, normalized_key, strlen (normalized_key)) == 0) ret = FALSE; g_free (basename); g_free (normalized_basename); g_free (normalized_path); } g_free (name); g_free (path); g_free (normalized_key); return ret; } else { return TRUE; } }
static GPid ip4_start (NMDHCPClient *client, NMSettingIP4Config *s_ip4, guint8 *dhcp_anycast_addr, const char *hostname) { NMDHCPDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (client); GPtrArray *argv = NULL; GPid pid = -1; GError *error = NULL; char *pid_contents = NULL, *binary_name, *cmd_str; const char *iface, *uuid; g_return_val_if_fail (priv->pid_file == NULL, -1); iface = nm_dhcp_client_get_iface (client); uuid = nm_dhcp_client_get_uuid (client); priv->pid_file = g_strdup_printf (NMSTATEDIR "/dhcpcd-%s.pid", iface); if (!g_file_test (priv->path, G_FILE_TEST_EXISTS)) { nm_log_warn (LOGD_DHCP4, "%s does not exist.", priv->path); return -1; } /* Kill any existing dhcpcd from the pidfile */ binary_name = g_path_get_basename (priv->path); nm_dhcp_client_stop_existing (priv->pid_file, binary_name); g_free (binary_name); argv = g_ptr_array_new (); g_ptr_array_add (argv, (gpointer) priv->path); g_ptr_array_add (argv, (gpointer) "-B"); /* Don't background on lease (disable fork()) */ g_ptr_array_add (argv, (gpointer) "-K"); /* Disable built-in carrier detection */ g_ptr_array_add (argv, (gpointer) "-L"); /* Disable built-in IPv4LL since we use avahi-autoipd */ g_ptr_array_add (argv, (gpointer) "-G"); /* Let NM handle routing */ g_ptr_array_add (argv, (gpointer) "-c"); /* Set script file */ g_ptr_array_add (argv, (gpointer) nm_dhcp_helper_path); if (hostname && strlen (hostname)) { g_ptr_array_add (argv, (gpointer) "-h"); /* Send hostname to DHCP server */ g_ptr_array_add (argv, (gpointer) hostname ); } g_ptr_array_add (argv, (gpointer) iface); g_ptr_array_add (argv, NULL); cmd_str = g_strjoinv (" ", (gchar **) argv->pdata); nm_log_dbg (LOGD_DHCP4, "running: %s", cmd_str); g_free (cmd_str); if (!g_spawn_async (NULL, (char **) argv->pdata, NULL, G_SPAWN_DO_NOT_REAP_CHILD, &dhcpcd_child_setup, NULL, &pid, &error)) { nm_log_warn (LOGD_DHCP4, "dhcpcd failed to start. error: '%s'", error->message); g_error_free (error); pid = -1; } else nm_log_info (LOGD_DHCP4, "dhcpcd started with pid %d", pid); g_free (pid_contents); g_ptr_array_free (argv, TRUE); return pid; }
/* * If the addlist window exists, updates it with the addlist from mpd */ gboolean mpc_addlist_update(void) { GPtrArray * list; GHashTable * hash; enum mpc_addlist_type type; gchar * filename; gint i; GtkTreeIter iter; GPtrArray * iterpath; GtkTreeIter * tempiter; GtkTreeIter * parentiter = NULL; gint level = 0; gchar * p; gchar * nicename = NULL; if (!mpc_addlist) { /* Nothing to do */ } else { /* Get list of all files form mpd */ list = mpc_mpd_get_clumps("listall\n", TRUE); if (!list) { return (FALSE); } gtk_tree_store_clear(mpc_addlist_store); iterpath = g_ptr_array_new(); for (i=0; i < list->len; i++) { hash = g_ptr_array_index(list, i); if ((filename = g_hash_table_lookup(hash, "directory"))) { type = MPC_ADDLIST_TYPE_DIRECTORY; } else if ((filename = g_hash_table_lookup(hash, "file"))) { type = MPC_ADDLIST_TYPE_FILE; } else if ((filename = g_hash_table_lookup(hash, "playlist"))) { type = MPC_ADDLIST_TYPE_PLAYLIST; } else { continue; } /* Update parentiter */ if (type == MPC_ADDLIST_TYPE_DIRECTORY) { level = 1; p = filename; while (*(p++)) { if (*p == '/') { level++; } } while (iterpath->len >= level) { tempiter = g_ptr_array_index(iterpath, iterpath->len - 1); g_free(tempiter); g_ptr_array_remove_index(iterpath, iterpath->len - 1); } if (iterpath->len) parentiter = g_ptr_array_index(iterpath, iterpath->len - 1); else parentiter = NULL; } /* Set nicename */ nicename = g_path_get_basename(filename); /* Add new row to store */ gtk_tree_store_append(mpc_addlist_store, &iter, parentiter); /* Set vars in new row */ gtk_tree_store_set(mpc_addlist_store, &iter , MPC_ADDLIST_COLUMN_ICON, (type == MPC_ADDLIST_TYPE_DIRECTORY ? GTK_STOCK_OPEN : GTK_STOCK_NEW) , MPC_ADDLIST_COLUMN_RAWNAME, filename , MPC_ADDLIST_COLUMN_DISPLAYNAME, nicename , MPC_ADDLIST_COLUMN_TYPE, type , -1); /* Update parentiter */ if (type == MPC_ADDLIST_TYPE_DIRECTORY) { tempiter = g_malloc(sizeof(iter)); memcpy(tempiter, &iter, sizeof(iter)); g_ptr_array_add(iterpath, tempiter); parentiter = tempiter; } g_hash_table_destroy(hash); } g_ptr_array_free(iterpath, TRUE); g_ptr_array_free(list, FALSE); } return (TRUE); }
/** Listener interface for import job */ void _camera_image_downloaded(const dt_camera_t *camera,const char *filename,void *data) { // Import downloaded image to import filmroll dt_camera_import_t *t = (dt_camera_import_t *)data; dt_image_import(t->film->id, filename, FALSE); dt_control_queue_redraw_center(); dt_control_log(_("%d/%d imported to %s"), t->import_count+1,g_list_length(t->images), g_path_get_basename(filename)); t->fraction+=1.0/g_list_length(t->images); dt_control_backgroundjobs_progress(darktable.control, t->bgj, t->fraction ); t->import_count++; }
static MenuCacheApp* match_app_by_exec(const char* exec) { GSList* l; MenuCacheApp* ret = NULL; char* exec_path = g_find_program_in_path(exec); const char* pexec; int path_len, exec_len, len; if( ! exec_path ) return NULL; path_len = strlen(exec_path); exec_len = strlen(exec); for( l = app_list; l; l = l->next ) { MenuCacheApp* app = MENU_CACHE_APP(l->data); const char* app_exec = menu_cache_app_get_exec(app); if ( ! app_exec) continue; #if 0 /* This is useless and incorrect. */ /* Dirty hacks to skip sudo programs. This can be a little bit buggy */ if( g_str_has_prefix(app_exec, "gksu") ) { app_exec += 4; if( app_exec[0] == '\0' ) /* "gksu" itself */ app_exec -= 4; else if( app_exec[0] == ' ' ) /* "gksu something..." */ ++app_exec; else if( g_str_has_prefix(app_exec, "do ") ) /* "gksudo something" */ app_exec += 3; } else if( g_str_has_prefix(app_exec, "kdesu ") ) /* kdesu */ app_exec += 6; #endif if( g_path_is_absolute(app_exec) ) { pexec = exec_path; len = path_len; } else { pexec = exec; len = exec_len; } if( strncmp(app_exec, pexec, len) == 0 ) { /* exact match has the highest priority */ if( app_exec[len] == '\0' ) { ret = app; break; } /* those matches the pattern: exe_name %F|%f|%U|%u have higher priority */ if( app_exec[len] == ' ' ) { if( app_exec[len + 1] == '%' ) { if( strchr( "FfUu", app_exec[len + 2] ) ) { ret = app; break; } } ret = app; } } } /* if this is a symlink */ if( ! ret && g_file_test(exec_path, G_FILE_TEST_IS_SYMLINK) ) { char target[512]; /* FIXME: is this enough? */ len = readlink( exec_path, target, sizeof(target) - 1); if( len > 0 ) { target[len] = '\0'; ret = match_app_by_exec(target); if( ! ret ) { /* FIXME: Actually, target could be relative paths. * So, actually path resolution is needed here. */ char* basename = g_path_get_basename(target); char* locate = g_find_program_in_path(basename); if( locate && strcmp(locate, target) == 0 ) { ret = match_app_by_exec(basename); g_free(locate); } g_free(basename); } } } g_free(exec_path); return ret; }
GHashTable * vpn_get_plugins (GError **error) { GDir *dir; const char *f; if (error) g_return_val_if_fail (*error == NULL, NULL); if (plugins) return plugins; dir = g_dir_open (VPN_NAME_FILES_DIR, 0, NULL); if (!dir) { g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Couldn't read VPN .name files directory " VPN_NAME_FILES_DIR "."); return NULL; } plugins = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); while ((f = g_dir_read_name (dir))) { char *path = NULL, *service = NULL; char *so_path = NULL, *so_name = NULL; GKeyFile *keyfile = NULL; GModule *module; NMVpnPluginUiFactory factory = NULL; if (!g_str_has_suffix (f, ".name")) continue; path = g_strdup_printf ("%s/%s", VPN_NAME_FILES_DIR, f); keyfile = g_key_file_new (); if (!g_key_file_load_from_file (keyfile, path, 0, NULL)) goto next; service = g_key_file_get_string (keyfile, "VPN Connection", "service", NULL); if (!service) goto next; so_path = g_key_file_get_string (keyfile, "GNOME", "properties", NULL); if (!so_path) goto next; /* Remove any path and extension components, then reconstruct path * to the SO in LIBDIR */ so_name = g_path_get_basename (so_path); g_free (so_path); so_path = g_strdup_printf ("%s/NetworkManager/%s", LIBDIR, so_name); g_free (so_name); module = g_module_open (so_path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (!module) { g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "Cannot load the VPN plugin which provides the " "service '%s'.", service); goto next; } if (g_module_symbol (module, "nm_vpn_plugin_ui_factory", (gpointer) &factory)) { NMVpnPluginUiInterface *plugin; GError *factory_error = NULL; gboolean success = FALSE; plugin = factory (&factory_error); if (plugin) { char *plug_name = NULL, *plug_service = NULL; /* Validate plugin properties */ g_object_get (G_OBJECT (plugin), NM_VPN_PLUGIN_UI_INTERFACE_NAME, &plug_name, NM_VPN_PLUGIN_UI_INTERFACE_SERVICE, &plug_service, NULL); if (!plug_name || !strlen (plug_name)) { g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot load VPN plugin in '%s': missing plugin name", g_module_name (module)); } else if (!plug_service || strcmp (plug_service, service)) { g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot load VPN plugin in '%s': invalid service name", g_module_name (module)); } else { /* Success! */ g_object_set_data_full (G_OBJECT (plugin), "gmodule", module, (GDestroyNotify) g_module_close); g_hash_table_insert (plugins, g_strdup (service), plugin); success = TRUE; } g_free (plug_name); g_free (plug_service); } else { g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot load VPN plugin in '%s': %s", g_module_name (module), g_module_error ()); } if (!success) g_module_close (module); } else { g_set_error (error, NMA_ERROR, NMA_ERROR_GENERIC, "cannot locate nm_vpn_plugin_ui_factory() in '%s': %s", g_module_name (module), g_module_error ()); g_module_close (module); } next: g_free (so_path); g_free (service); g_key_file_free (keyfile); g_free (path); } g_dir_close (dir); return plugins; }
static void on_swap_header_source(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) { GSList *header_patterns, *source_patterns; GeanyDocument *doc; gboolean known_type = TRUE; gboolean is_header; gchar *doc_basename; doc = document_get_current(); if (!g_prj || !geany_data->app->project || !doc || !doc->file_name) return; header_patterns = get_precompiled_patterns(g_prj->header_patterns); source_patterns = get_precompiled_patterns(g_prj->source_patterns); doc_basename = g_path_get_basename(doc->file_name); if (patterns_match(header_patterns, doc_basename)) is_header = TRUE; else if (patterns_match(source_patterns, doc_basename)) is_header = FALSE; else known_type = FALSE; if (known_type) { gboolean swapped; GSList *elem, *list = NULL; gint i; foreach_document(i) { gchar *filename; filename = document_index(i)->file_name; if (gprj_project_is_in_project(filename)) list = g_slist_prepend(list, filename); } swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); g_slist_free(list); list = NULL; if (!swapped) { gchar *doc_dir; doc_dir = g_path_get_dirname(doc->file_name); setptr(doc_dir, utils_get_locale_from_utf8(doc_dir)); list = utils_get_file_list(doc_dir, NULL, NULL); for (elem = list; elem != NULL; elem = g_slist_next(elem)) { gchar *full_name; full_name = g_build_filename(doc_dir, elem->data, NULL); setptr(full_name, utils_get_utf8_from_locale(full_name)); setptr(elem->data, full_name); } swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); g_slist_foreach(list, (GFunc) g_free, NULL); g_slist_free(list); g_free(doc_dir); list = NULL; } if (!swapped) { g_hash_table_foreach(g_prj->file_tag_table, (GHFunc) get_project_file_list, &list); try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); g_slist_free(list); } } g_free(doc_basename); g_slist_foreach(header_patterns, (GFunc) g_pattern_spec_free, NULL); g_slist_free(header_patterns); g_slist_foreach(source_patterns, (GFunc) g_pattern_spec_free, NULL); g_slist_free(source_patterns); }
/** * asb_task_process: * @task: A #AsbTask * @error_not_used: A #GError or %NULL * * Processes the task. * * Returns: %TRUE for success, %FALSE otherwise * * Since: 0.1.0 **/ gboolean asb_task_process (AsbTask *task, GError **error_not_used) { AsRelease *release; AsbApp *app; AsbPlugin *plugin = NULL; AsbTaskPrivate *priv = GET_PRIVATE (task); GList *apps = NULL; GList *l; GPtrArray *array; gboolean ret; gchar *cache_id; guint i; guint nr_added = 0; g_autoptr(GError) error = NULL; g_autofree gchar *basename = NULL; /* reset the profile timer */ asb_package_log_start (priv->pkg); /* ensure nevra read */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_NEVRA, error_not_used)) return FALSE; g_debug ("starting: %s", asb_package_get_name (priv->pkg)); /* treat archive as a special case */ if (g_str_has_suffix (priv->filename, ".cab")) { AsApp *app_tmp; GPtrArray *apps_tmp; g_autoptr(AsStore) store = as_store_new (); g_autoptr(GFile) file = g_file_new_for_path (priv->filename); if (!as_store_from_file (store, file, NULL, NULL, &error)) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to parse %s: %s", asb_package_get_filename (priv->pkg), error->message); return TRUE; } apps_tmp = as_store_get_apps (store); for (i = 0; i < apps_tmp->len; i++) { g_autoptr(AsbApp) app2 = NULL; app_tmp = AS_APP (g_ptr_array_index (apps_tmp, i)); app2 = asb_app_new (priv->pkg, as_app_get_id (app_tmp)); as_app_subsume (AS_APP (app2), app_tmp); asb_context_add_app (priv->ctx, app2); /* set cache-id in case we want to use the metadata directly */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID)) { cache_id = asb_utils_get_cache_id_for_filename (priv->filename); as_app_add_metadata (AS_APP (app2), "X-CacheID", cache_id); g_free (cache_id); } nr_added++; } g_debug ("added %u apps from archive", apps_tmp->len); goto skip; } /* ensure file list read */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_FILES, error_not_used)) return FALSE; /* did we get a file match on any plugin */ basename = g_path_get_basename (priv->filename); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Getting filename match for %s", basename); asb_task_add_suitable_plugins (task); if (priv->plugins_to_run->len == 0) { asb_context_add_app_ignore (priv->ctx, priv->pkg); goto out; } /* delete old tree if it exists */ ret = asb_utils_ensure_exists_and_empty (priv->tmpdir, &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to clear: %s", error->message); goto out; } /* explode tree */ g_debug ("decompressing files: %s", asb_package_get_name (priv->pkg)); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Exploding tree for %s", asb_package_get_name (priv->pkg)); ret = asb_package_explode (priv->pkg, priv->tmpdir, asb_context_get_file_globs (priv->ctx), &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to explode: %s", error->message); g_clear_error (&error); goto skip; } /* add extra packages */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_DEPS | ASB_PACKAGE_ENSURE_SOURCE, error_not_used)) return FALSE; ret = asb_task_explode_extra_packages (task, &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to explode extra file: %s", error->message); goto skip; } /* run plugins */ g_debug ("examining: %s", asb_package_get_name (priv->pkg)); for (i = 0; i < priv->plugins_to_run->len; i++) { GList *apps_tmp = NULL; plugin = g_ptr_array_index (priv->plugins_to_run, i); asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_DEBUG, "Processing %s with %s", basename, plugin->name); apps_tmp = asb_plugin_process (plugin, priv->pkg, priv->tmpdir, &error); if (apps_tmp == NULL) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to run process '%s': %s", plugin->name, error->message); g_clear_error (&error); } for (l = apps_tmp; l != NULL; l = l->next) { app = ASB_APP (l->data); asb_plugin_add_app (&apps, AS_APP (app)); } g_list_free_full (apps_tmp, g_object_unref); } if (apps == NULL) goto skip; /* print */ g_debug ("processing: %s", asb_package_get_name (priv->pkg)); for (l = apps; l != NULL; l = l->next) { app = l->data; /* never set */ if (as_app_get_id (AS_APP (app)) == NULL) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_INFO, "app id not set for %s", asb_package_get_name (priv->pkg)); continue; } /* copy data from pkg into app */ if (!asb_package_ensure (priv->pkg, ASB_PACKAGE_ENSURE_LICENSE | ASB_PACKAGE_ENSURE_RELEASES | ASB_PACKAGE_ENSURE_VCS | ASB_PACKAGE_ENSURE_URL, error_not_used)) return FALSE; if (asb_package_get_url (priv->pkg) != NULL && as_app_get_url_item (AS_APP (app), AS_URL_KIND_HOMEPAGE) == NULL) { as_app_add_url (AS_APP (app), AS_URL_KIND_HOMEPAGE, asb_package_get_url (priv->pkg)); } if (asb_package_get_license (priv->pkg) != NULL && as_app_get_project_license (AS_APP (app)) == NULL) { as_app_set_project_license (AS_APP (app), asb_package_get_license (priv->pkg)); } /* add the source name so we can suggest these together */ if (g_strcmp0 (asb_package_get_source_pkgname (priv->pkg), asb_package_get_name (priv->pkg)) != 0) { as_app_set_source_pkgname (AS_APP (app), asb_package_get_source_pkgname (priv->pkg)); } /* set all the releases on the app */ array = asb_package_get_releases (priv->pkg); for (i = 0; i < array->len; i++) { release = g_ptr_array_index (array, i); as_app_add_release (AS_APP (app), release); } /* run each refine plugin on each app */ ret = asb_plugin_loader_process_app (asb_context_get_plugin_loader (priv->ctx), priv->pkg, app, priv->tmpdir, &error); if (!ret) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to run process on %s: %s", as_app_get_id (AS_APP (app)), error->message); g_clear_error (&error); goto skip; } /* set cache-id in case we want to use the metadata directly */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID)) { cache_id = asb_utils_get_cache_id_for_filename (priv->filename); as_app_add_metadata (AS_APP (app), "X-CacheID", cache_id); g_free (cache_id); } /* set the VCS information into the metadata */ if (asb_package_get_vcs (priv->pkg) != NULL) { as_app_add_metadata (AS_APP (app), "VersionControlSystem", asb_package_get_vcs (priv->pkg)); } /* save any screenshots early */ if (array->len == 0) { if (!asb_app_save_resources (ASB_APP (app), ASB_APP_SAVE_FLAG_SCREENSHOTS, error_not_used)) return FALSE; } /* all okay */ asb_context_add_app (priv->ctx, app); nr_added++; } skip: /* add a dummy element to the AppStream metadata so that we don't keep * parsing this every time */ if (asb_context_get_flag (priv->ctx, ASB_CONTEXT_FLAG_ADD_CACHE_ID) && nr_added == 0) asb_context_add_app_ignore (priv->ctx, priv->pkg); /* delete tree */ g_debug ("deleting temp files: %s", asb_package_get_name (priv->pkg)); if (!asb_utils_rmtree (priv->tmpdir, &error)) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to delete tree: %s", error->message); goto out; } /* write log */ g_debug ("writing log: %s", asb_package_get_name (priv->pkg)); if (!asb_package_log_flush (priv->pkg, &error)) { asb_package_log (priv->pkg, ASB_PACKAGE_LOG_LEVEL_WARNING, "Failed to write package log: %s", error->message); goto out; } out: /* clear loaded resources */ asb_package_close (priv->pkg, NULL); asb_package_clear (priv->pkg, ASB_PACKAGE_ENSURE_DEPS | ASB_PACKAGE_ENSURE_FILES); g_list_free_full (apps, (GDestroyNotify) g_object_unref); return TRUE; }
/* * Save_List_Of_Files: Function to save a list of files. * - force_saving_files = TRUE => force saving the file even if it wasn't changed * - force_saving_files = FALSE => force saving only the changed files */ static gint Save_List_Of_Files (GList *etfilelist, gboolean force_saving_files) { EtApplicationWindow *window; gint progress_bar_index; gint saving_answer; gint nb_files_to_save; gint nb_files_changed_by_ext_program; gchar *msg; gchar progress_bar_text[30]; GList *l; ET_File *etfile_save_position = NULL; File_Tag *FileTag; File_Name *FileNameNew; double fraction; GAction *action; GVariant *variant; GtkWidget *widget_focused; GtkTreePath *currentPath = NULL; g_return_val_if_fail (ETCore != NULL, FALSE); window = ET_APPLICATION_WINDOW (MainWindow); /* Save the current position in the list */ etfile_save_position = ETCore->ETFileDisplayed; et_application_window_update_et_file_from_ui (window); /* Save widget that has current focus, to give it again the focus after saving */ widget_focused = gtk_window_get_focus(GTK_WINDOW(MainWindow)); /* Count the number of files to save */ /* Count the number of files changed by an external program */ nb_files_to_save = 0; nb_files_changed_by_ext_program = 0; for (l = etfilelist; l != NULL; l = g_list_next (l)) { GFile *file; GFileInfo *fileinfo; const ET_File *ETFile = (ET_File *)l->data; const File_Tag *file_tag = (File_Tag *)ETFile->FileTag->data; const File_Name *FileName = (File_Name *)ETFile->FileNameNew->data; const gchar *filename_cur = ((File_Name *)ETFile->FileNameCur->data)->value; const gchar *filename_cur_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8; gchar *basename_cur_utf8 = g_path_get_basename(filename_cur_utf8); // Count only the changed files or all files if force_saving_files==TRUE if (force_saving_files || (FileName && FileName->saved == FALSE) || (file_tag && file_tag->saved == FALSE)) nb_files_to_save++; file = g_file_new_for_path (filename_cur); fileinfo = g_file_query_info (file, G_FILE_ATTRIBUTE_TIME_MODIFIED, G_FILE_QUERY_INFO_NONE, NULL, NULL); g_object_unref (file); if (fileinfo) { if (ETFile->FileModificationTime != g_file_info_get_attribute_uint64 (fileinfo, G_FILE_ATTRIBUTE_TIME_MODIFIED)) { nb_files_changed_by_ext_program++; } g_object_unref (fileinfo); } g_free(basename_cur_utf8); } /* Initialize status bar */ et_application_window_progress_set_fraction (window, 0.0); progress_bar_index = 0; g_snprintf(progress_bar_text, 30, "%d/%d", progress_bar_index, nb_files_to_save); et_application_window_progress_set_text (window, progress_bar_text); /* Set to unsensitive all command buttons (except Quit button) */ et_application_window_disable_command_actions (window); et_application_window_browser_set_sensitive (window, FALSE); et_application_window_tag_area_set_sensitive (window, FALSE); et_application_window_file_area_set_sensitive (window, FALSE); /* Show msgbox (if needed) to ask confirmation ('SF' for Save File) */ SF_HideMsgbox_Write_Tag = FALSE; SF_HideMsgbox_Rename_File = FALSE; Main_Stop_Button_Pressed = FALSE; /* Activate the stop button. */ action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "stop"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE); /* * Check if file was changed by an external program */ if (nb_files_changed_by_ext_program > 0) { // Some files were changed by other program than EasyTAG GtkWidget *msgdialog = NULL; gint response; msgdialog = gtk_message_dialog_new(GTK_WINDOW(MainWindow), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_NONE, ngettext ("A file was changed by an external program", "%d files were changed by an external program", nb_files_changed_by_ext_program), nb_files_changed_by_ext_program); gtk_dialog_add_buttons (GTK_DIALOG (msgdialog), _("_Discard"), GTK_RESPONSE_NO, _("_Save"), GTK_RESPONSE_YES, NULL); gtk_dialog_set_default_response (GTK_DIALOG (msgdialog), GTK_RESPONSE_YES); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(msgdialog),"%s",_("Do you want to continue saving the file?")); gtk_window_set_title(GTK_WINDOW(msgdialog),_("Quit")); response = gtk_dialog_run(GTK_DIALOG(msgdialog)); gtk_widget_destroy(msgdialog); switch (response) { case GTK_RESPONSE_YES: break; case GTK_RESPONSE_NO: case GTK_RESPONSE_DELETE_EVENT: /* Skip the following loop. */ Main_Stop_Button_Pressed = TRUE; break; default: g_assert_not_reached (); break; } } for (l = etfilelist; l != NULL && !Main_Stop_Button_Pressed; l = g_list_next (l)) { FileTag = ((ET_File *)l->data)->FileTag->data; FileNameNew = ((ET_File *)l->data)->FileNameNew->data; /* We process only the files changed and not saved, or we force to save all * files if force_saving_files==TRUE */ if ( force_saving_files || FileTag->saved == FALSE || FileNameNew->saved == FALSE ) { /* ET_Display_File_Data_To_UI ((ET_File *)l->data); * Use of 'currentPath' to try to increase speed. Indeed, in many * cases, the next file to select, is the next in the list. */ currentPath = et_application_window_browser_select_file_by_et_file2 (window, (ET_File *)l->data, FALSE, currentPath); fraction = (++progress_bar_index) / (double) nb_files_to_save; et_application_window_progress_set_fraction (window, fraction); g_snprintf(progress_bar_text, 30, "%d/%d", progress_bar_index, nb_files_to_save); et_application_window_progress_set_text (window, progress_bar_text); /* Needed to refresh status bar */ while (gtk_events_pending()) gtk_main_iteration(); // Save tag and rename file saving_answer = Save_File ((ET_File *)l->data, nb_files_to_save > 1 ? TRUE : FALSE, force_saving_files); if (saving_answer == -1) { /* Stop saving files + reinit progress bar */ et_application_window_progress_set_text (window, ""); et_application_window_progress_set_fraction (window, 0.0); et_application_window_status_bar_message (window, _("Saving files was stopped"), TRUE); /* To update state of command buttons */ et_application_window_update_actions (window); et_application_window_browser_set_sensitive (window, TRUE); et_application_window_tag_area_set_sensitive (window, TRUE); et_application_window_file_area_set_sensitive (window, TRUE); if (currentPath) { gtk_tree_path_free (currentPath); } return -1; /* We stop all actions */ } } } if (currentPath) gtk_tree_path_free(currentPath); if (Main_Stop_Button_Pressed) msg = g_strdup (_("Saving files was stopped")); else msg = g_strdup (_("All files have been saved")); Main_Stop_Button_Pressed = FALSE; action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "stop"); g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE); /* Return to the saved position in the list */ et_application_window_display_et_file (ET_APPLICATION_WINDOW (MainWindow), etfile_save_position); et_application_window_browser_select_file_by_et_file (ET_APPLICATION_WINDOW (MainWindow), etfile_save_position, TRUE); /* FIXME: Find out why this is a special case for the artist/album mode. */ action = g_action_map_lookup_action (G_ACTION_MAP (MainWindow), "file-artist-view"); variant = g_action_get_state (action); if (strcmp (g_variant_get_string (variant, NULL), "artist") == 0) { et_application_window_browser_toggle_display_mode (window); } g_variant_unref (variant); /* To update state of command buttons */ et_application_window_update_actions (ET_APPLICATION_WINDOW (MainWindow)); et_application_window_browser_set_sensitive (window, TRUE); et_application_window_tag_area_set_sensitive (window, TRUE); et_application_window_file_area_set_sensitive (window, TRUE); /* Give again focus to the first entry, else the focus is passed to another */ gtk_widget_grab_focus(GTK_WIDGET(widget_focused)); et_application_window_progress_set_text (window, ""); et_application_window_progress_set_fraction (window, 0.0); et_application_window_status_bar_message (window, msg, TRUE); g_free(msg); et_application_window_browser_refresh_list (window); return TRUE; }