comparison pidgin/plugins/adiumthemes/webkit.c @ 32088:7d8f8c6ebae2

some code for style_changed and also default any empty file to "" rather than NULL.
author tdrhq@soc.pidgin.im
date Mon, 10 Aug 2009 10:03:47 +0000
parents 1c84e102c8ee
children 1cd4613c620d
comparison
equal deleted inserted replaced
32087:1c84e102c8ee 32088:7d8f8c6ebae2
168 return NULL; 168 return NULL;
169 } 169 }
170 g_free (file); 170 g_free (file);
171 171
172 file = g_build_filename(styledir, "Contents", "Resources", "main.css", NULL); 172 file = g_build_filename(styledir, "Contents", "Resources", "main.css", NULL);
173 g_file_get_contents(file, &style->basestyle_css, NULL, NULL); 173 if (!g_file_get_contents(file, &style->basestyle_css, NULL, NULL))
174 style->basestyle_css = g_strdup ("");
174 g_free (file); 175 g_free (file);
175 176
176 file = g_build_filename(styledir, "Contents", "Resources", "Header.html", NULL); 177 file = g_build_filename(styledir, "Contents", "Resources", "Header.html", NULL);
177 g_file_get_contents(file, &style->header_html, NULL, NULL); 178 if (!g_file_get_contents(file, &style->header_html, NULL, NULL))
179 style->header_html = g_strdup ("");
178 g_free (file); 180 g_free (file);
179 181
180 file = g_build_filename(styledir, "Contents", "Resources", "Footer.html", NULL); 182 file = g_build_filename(styledir, "Contents", "Resources", "Footer.html", NULL);
181 g_file_get_contents(file, &style->footer_html, NULL, NULL); 183 if (!g_file_get_contents(file, &style->footer_html, NULL, NULL))
184 style->footer_html = g_strdup ("");
182 g_free (file); 185 g_free (file);
183 186
184 file = g_build_filename(styledir, "Contents", "Resources", "Incoming", "Content.html", NULL); 187 file = g_build_filename(styledir, "Contents", "Resources", "Incoming", "Content.html", NULL);
185 if (!g_file_get_contents(file, &style->incoming_content_html, NULL, NULL)) { 188 if (!g_file_get_contents(file, &style->incoming_content_html, NULL, NULL)) {
186 pidgin_message_style_unref (style); 189 pidgin_message_style_unref (style);
449 PidginMessageStyle *style, *oldStyle; 452 PidginMessageStyle *style, *oldStyle;
450 oldStyle = g_object_get_data (G_OBJECT(webkit), MESSAGE_STYLE_KEY); 453 oldStyle = g_object_get_data (G_OBJECT(webkit), MESSAGE_STYLE_KEY);
451 454
452 if (oldStyle) return; 455 if (oldStyle) return;
453 456
457 purple_debug_info ("webkit", "loading %s", style_dir);
454 style = pidgin_message_style_load (style_dir); 458 style = pidgin_message_style_load (style_dir);
455 g_assert (style); 459 g_assert (style);
456 460
457 basedir = g_build_filename (style->style_dir, "Contents", "Resources", "Template.html", NULL); 461 basedir = g_build_filename (style->style_dir, "Contents", "Resources", "Template.html", NULL);
458 baseuri = g_strdup_printf ("file://%s", basedir); 462 baseuri = g_strdup_printf ("file://%s", basedir);
459 header = replace_header_tokens(style->header_html, strlen(style->header_html), conv); 463 header = replace_header_tokens(style->header_html, strlen(style->header_html), conv);
464 g_assert (style);
460 footer = replace_header_tokens(style->footer_html, strlen(style->footer_html), conv); 465 footer = replace_header_tokens(style->footer_html, strlen(style->footer_html), conv);
461 template = replace_template_tokens(style, style->template_html, strlen(style->template_html) + strlen(style->header_html), header, footer); 466 template = replace_template_tokens(style, style->template_html, strlen(style->template_html) + strlen(style->header_html), header, footer);
462 467
463 webkit_web_view_load_string(WEBKIT_WEB_VIEW(webkit), template, "text/html", "UTF-8", baseuri); 468 webkit_web_view_load_string(WEBKIT_WEB_VIEW(webkit), template, "text/html", "UTF-8", baseuri);
464 469
704 { 709 {
705 GList *all, *iter; 710 GList *all, *iter;
706 const char *css_path = purple_prefs_get_string ("/plugins/gtk/adiumthemes/csspath"); 711 const char *css_path = purple_prefs_get_string ("/plugins/gtk/adiumthemes/csspath");
707 712
708 g_free (style->css_path); 713 g_free (style->css_path);
709 if (g_str_has_prefix (css_path, style->style_dir) && 714 if (css_path && g_str_has_prefix (css_path, style->style_dir) &&
710 g_file_test (css_path, G_FILE_TEST_EXISTS)) { 715 g_file_test (css_path, G_FILE_TEST_EXISTS)) {
711 style->css_path = g_strdup (css_path); 716 style->css_path = g_strdup (css_path);
712 return; 717 return;
713 } 718 }
714 else { 719 else {
789 } 794 }
790 795
791 return TRUE; 796 return TRUE;
792 } 797 }
793 798
799 static void
800 style_changed (GtkWidget* combobox, gpointer null)
801 {
802 char *name = gtk_combo_box_get_active_text (GTK_COMBO_BOX(combobox));
803
804 g_free (cur_style_dir);
805 cur_style_dir = name;
806 }
794 807
795 static GtkWidget* 808 static GtkWidget*
796 get_style_config_frame () 809 get_style_config_frame ()
797 { 810 {
798 GtkWidget *combobox = gtk_combo_box_new_text (); 811 GtkWidget *combobox = gtk_combo_box_new_text ();
808 selected = index; 821 selected = index;
809 pidgin_message_style_unref (style); 822 pidgin_message_style_unref (style);
810 } 823 }
811 } 824 }
812 gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), selected); 825 gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), selected);
826 g_signal_connect (G_OBJECT(combobox), "changed", G_CALLBACK(style_changed), NULL);
813 return combobox; 827 return combobox;
814 } 828 }
815 829
816 static void 830 static void
817 variant_update_conversation (PurpleConversation *conv) 831 variant_update_conversation (PurpleConversation *conv)