• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

作図ソフト dia の改良版


コミットメタ情報

リビジョン74f401706c77e444171557b13bd75a6c298916b3 (tree)
日時2007-03-18 03:48:31
作者Hans Breuer <hans@breu...>
コミッターHans Breuer

ログメッセージ

plugged some leaks and made the filter sensitive extension update work, by

2007-03-17 Hans Breuer <hans@breuer.org>

* app/filedlg.c : plugged some leaks and made the filter sensitive
extension update work, by relying less on what we get back from gtk+
Fixes bug #403195.

svn path=/trunk/; revision=3639

変更サマリ

差分

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
11 2007-03-17 Hans Breuer <hans@breuer.org>
22
3+ * app/filedlg.c : plugged some leaks and made the filter sensitive
4+ extension update work, by relying less on what we get back from gtk+
5+ Fixes bug #403195.
6+
37 [some playing with valgrind : memory leaks]
48 * lib/text.c(text_set_line_text) : removed superfluous g_strdup()
59 * app/interface.c : gtk_accelerator_get_label() and g_strconcat()
--- a/app/filedlg.c
+++ b/app/filedlg.c
@@ -149,7 +149,7 @@ file_open_response_callback(GtkWidget *fs,
149149 gint response,
150150 gpointer user_data)
151151 {
152- const char *filename;
152+ char *filename;
153153 Diagram *diagram = NULL;
154154
155155 if (response == GTK_RESPONSE_ACCEPT) {
@@ -160,6 +160,8 @@ file_open_response_callback(GtkWidget *fs,
160160 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fs));
161161
162162 diagram = diagram_load(filename, ifilter_by_index (index - 1, filename));
163+
164+ g_free (filename);
163165
164166 if (diagram != NULL) {
165167 diagram_update_extents(diagram);
@@ -289,7 +291,7 @@ file_save_as_response_callback(GtkWidget *fs,
289291 gint response,
290292 gpointer user_data)
291293 {
292- const char *filename;
294+ char *filename;
293295 Diagram *dia;
294296 struct stat stat_struct;
295297
@@ -325,6 +327,7 @@ file_save_as_response_callback(GtkWidget *fs,
325327 /* don't hide/destroy the dialog, but simply go back to it */
326328 gtk_window_present (GTK_WINDOW (fs));
327329 gtk_widget_destroy(dialog);
330+ g_free (filename);
328331 return;
329332 }
330333 gtk_widget_destroy(dialog);
@@ -336,6 +339,8 @@ file_save_as_response_callback(GtkWidget *fs,
336339
337340 diagram_set_filename(dia, filename);
338341 diagram_save(dia, filename);
342+
343+ g_free (filename);
339344 }
340345 /* if we have our own reference, drop it before destroy */
341346 if ((dia = gtk_object_get_user_data(GTK_OBJECT(fs))) != NULL) {
@@ -455,49 +460,63 @@ file_save_callback(gpointer data, guint action, GtkWidget *widget)
455460 }
456461
457462 /**
458- * Given an export filter index and optionally a filename for fallback
459- * return the export filter to use
463+ * Given an export filter index return the export filter to use
460464 */
461465 static DiaExportFilter *
462-efilter_by_index (int index, const char* filename)
466+efilter_by_index (int index, const gchar** ext)
463467 {
464468 DiaExportFilter *efilter = NULL;
465469
466- if (index >= 0)
470+ /* the index in the selection list *is* the index of the filter,
471+ * filters supporing multiple formats are multiple times in the list */
472+ if (index >= 0) {
467473 efilter = g_list_nth_data (filter_get_export_filters(), index);
468- else if (filename) /* fallback, should not happen */
469- efilter = filter_guess_export_filter(filename);
474+ if (efilter) {
475+ if (ext)
476+ *ext = efilter->extensions[0];
477+ return efilter;
478+ }
479+ else /* getting here means invalid index */
480+ g_warning ("efilter_by_index() index=%d out of range", index);
481+ }
470482
471483 return efilter;
472484 }
473485
474486 /**
475- * Adapt the filename to the export filter selection
487+ * Adapt the filename to the export filter index
476488 */
477489 static void
478-export_set_extension(GtkWidget *widget)
490+export_adapt_extension (const gchar* name, int index)
479491 {
480- int index = gtk_combo_box_get_active (GTK_COMBO_BOX(widget)) - 1; /* Ignore "By Extension" */
481- DiaExportFilter *efilter = efilter_by_index (index, NULL);
482- GString *s;
483- const gchar *text = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(exportdlg));
484- const gchar *last_dot = text ? strrchr(text, '.') : NULL;
485- gchar *basename = NULL;
486-
487- if (!efilter || last_dot == text || text[0] == '\0' ||
488- efilter->extensions[0] == NULL)
489- return;
490- basename = g_path_get_basename (text);
491- last_dot = strrchr(basename, '.');
492- s = g_string_new(basename);
493- if (last_dot)
494- g_string_truncate(s, last_dot-basename);
495- g_string_append(s, ".");
496- g_string_append(s, efilter->extensions[0]);
497- gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(exportdlg), s->str);
498- g_string_free (s, TRUE);
492+ const gchar* ext = NULL;
493+ DiaExportFilter *efilter = efilter_by_index (index, &ext);
494+ gchar *basename = g_path_get_basename (name);
495+
496+ if (!efilter || !ext)
497+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(exportdlg), basename);
498+ else {
499+ const gchar *last_dot = strrchr(basename, '.');
500+ GString *s = g_string_new(basename);
501+ if (last_dot)
502+ g_string_truncate(s, last_dot-basename);
503+ g_string_append(s, ".");
504+ g_string_append(s, ext);
505+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(exportdlg), s->str);
506+ g_string_free (s, TRUE);
507+ }
499508 g_free (basename);
500509 }
510+static void
511+export_adapt_extension_callback(GtkWidget *widget)
512+{
513+ int index = gtk_combo_box_get_active (GTK_COMBO_BOX(widget));
514+ gchar *name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(exportdlg));
515+
516+ if (name && index > 0) /* Ignore "By Extension" */
517+ export_adapt_extension (name, index - 1);
518+ g_free (name);
519+}
501520
502521 /**
503522 * Create a new "option menu" for the export options
@@ -522,7 +541,7 @@ create_export_menu(void)
522541 g_free(filter_label);
523542 }
524543 g_signal_connect(GTK_OBJECT(menu), "changed",
525- G_CALLBACK(export_set_extension), NULL);
544+ G_CALLBACK(export_adapt_extension_callback), NULL);
526545 return menu;
527546 }
528547
@@ -534,7 +553,7 @@ file_export_response_callback(GtkWidget *fs,
534553 gint response,
535554 gpointer user_data)
536555 {
537- const char *filename;
556+ char *filename;
538557 Diagram *dia;
539558 DiaExportFilter *ef;
540559 struct stat statbuf;
@@ -565,6 +584,7 @@ file_export_response_callback(GtkWidget *fs,
565584 if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_YES) {
566585 /* if not overwrite allow to select another filename */
567586 gtk_widget_destroy(dialog);
587+ g_free (filename);
568588 return;
569589 }
570590 gtk_widget_destroy(dialog);
@@ -573,7 +593,7 @@ file_export_response_callback(GtkWidget *fs,
573593 index = gtk_combo_box_get_active (GTK_COMBO_BOX(user_data));
574594 if (index >= 0)
575595 persistence_set_integer ("export-filter", index);
576- ef = efilter_by_index (index - 1, filename);
596+ ef = efilter_by_index (index - 1, NULL);
577597 if (!ef)
578598 ef = filter_guess_export_filter(filename);
579599 if (ef) {
@@ -583,6 +603,7 @@ file_export_response_callback(GtkWidget *fs,
583603 } else
584604 message_error(_("Could not determine which export filter\n"
585605 "to use to save '%s'"), dia_message_filename(filename));
606+ g_free (filename);
586607 }
587608 g_object_unref (dia); /* drop our diagram reference */
588609 gtk_widget_destroy(exportdlg);
@@ -672,15 +693,13 @@ file_export_callback(gpointer data, guint action, GtkWidget *widget)
672693 char *basename = g_path_get_basename (fnabs);
673694 /* can't use gtk_file_chooser_set_filename for various reasons, see e.g. bug #305850 */
674695 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(exportdlg), folder);
675- gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(exportdlg), basename);
696+ export_adapt_extension (basename, persistence_get_integer ("export-filter") - 1);
676697 g_free (folder);
677698 g_free (basename);
678699 }
679700 g_free(fnabs);
680701 g_free(filename);
681702 }
682- export_set_extension(GTK_WIDGET(g_object_get_data(G_OBJECT(exportdlg),
683- "export-menu")));
684703
685704 gtk_widget_show(exportdlg);
686705 }