pidgin/gtkconv.c

branch
cpw.qulogic.gtk3-required
changeset 33149
e1b50abc07bb
parent 33146
1f729ff8cab4
parent 33051
2e75223c078e
child 33160
4ddceddab409
equal deleted inserted replaced
33148:34d89dcecc9b 33149:e1b50abc07bb
1056 } 1056 }
1057 1057
1058 static void 1058 static void
1059 savelog_writefile_cb(void *user_data, const char *filename) 1059 savelog_writefile_cb(void *user_data, const char *filename)
1060 { 1060 {
1061 /* TODO WEBKIT: I don't know how to support this using webkit yet. */
1062 #if 0
1063 PurpleConversation *conv = (PurpleConversation *)user_data; 1061 PurpleConversation *conv = (PurpleConversation *)user_data;
1062 GtkWebView *webview;
1064 FILE *fp; 1063 FILE *fp;
1065 const char *name; 1064 const char *name;
1066 char **lines;
1067 gchar *text; 1065 gchar *text;
1068 1066
1069 if ((fp = g_fopen(filename, "w+")) == NULL) { 1067 if ((fp = g_fopen(filename, "w+")) == NULL) {
1070 purple_notify_error(PIDGIN_CONVERSATION(conv), NULL, _("Unable to open file."), NULL); 1068 purple_notify_error(PIDGIN_CONVERSATION(conv), NULL, _("Unable to open file."), NULL);
1071 return; 1069 return;
1072 } 1070 }
1073 1071
1072 webview = GTK_WEBVIEW(PIDGIN_CONVERSATION(conv)->webview);
1074 name = purple_conversation_get_name(conv); 1073 name = purple_conversation_get_name(conv);
1075 fprintf(fp, "<html>\n<head>\n"); 1074 fprintf(fp, "<html>\n");
1075
1076 fprintf(fp, "<head>\n");
1076 fprintf(fp, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n"); 1077 fprintf(fp, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n");
1077 fprintf(fp, "<title>%s</title>\n</head>\n<body>\n", name); 1078 fprintf(fp, "<title>%s</title>\n", name);
1078 fprintf(fp, _("<h1>Conversation with %s</h1>\n"), name); 1079 text = gtk_webview_get_head_html(webview);
1079
1080 lines = gtk_imhtml_get_markup_lines(
1081 GTK_IMHTML(PIDGIN_CONVERSATION(conv)->imhtml));
1082 text = g_strjoinv("<br>\n", lines);
1083 fprintf(fp, "%s", text); 1080 fprintf(fp, "%s", text);
1084 g_free(text); 1081 g_free(text);
1085 g_strfreev(lines); 1082 fprintf(fp, "</head>\n");
1086 1083
1087 fprintf(fp, "\n</body>\n</html>\n"); 1084 fprintf(fp, "<body>\n");
1085 fprintf(fp, _("<h1>Conversation with %s</h1>\n"), name);
1086 text = gtk_webview_get_body_html(webview);
1087 fprintf(fp, "%s", text);
1088 g_free(text);
1089 fprintf(fp, "\n</body>\n");
1090
1091 fprintf(fp, "</html>\n");
1088 fclose(fp); 1092 fclose(fp);
1089 #endif /* if 0 */
1090 } 1093 }
1091 1094
1092 /* 1095 /*
1093 * It would be kinda cool if this gave the option of saving a 1096 * It would be kinda cool if this gave the option of saving a
1094 * plaintext v. HTML file. 1097 * plaintext v. HTML file.
5087 if (text == NULL || *text == '\0') 5090 if (text == NULL || *text == '\0')
5088 return NULL; 5091 return NULL;
5089 5092
5090 str = g_string_new(NULL); 5093 str = g_string_new(NULL);
5091 while ((cur = strchr(cur, '%'))) { 5094 while ((cur = strchr(cur, '%'))) {
5095 char *freeval = NULL;
5092 const char *replace = NULL; 5096 const char *replace = NULL;
5093 const char *fin = NULL; 5097 const char *fin = NULL;
5094 5098
5095 if (g_str_has_prefix(cur, "%chatName%")) { 5099 if (g_str_has_prefix(cur, "%chatName%")) {
5096 replace = purple_conversation_get_name(conv); 5100 replace = purple_conversation_get_name(conv);
5116 } else if (g_str_has_prefix(cur, "%outgoingIconPath%")) { 5120 } else if (g_str_has_prefix(cur, "%outgoingIconPath%")) {
5117 replace = purple_account_get_buddy_icon_path(account); 5121 replace = purple_account_get_buddy_icon_path(account);
5118 5122
5119 } else if (g_str_has_prefix(cur, "%timeOpened")) { 5123 } else if (g_str_has_prefix(cur, "%timeOpened")) {
5120 const char *tmp = cur + strlen("%timeOpened"); 5124 const char *tmp = cur + strlen("%timeOpened");
5121 char *format = NULL;
5122 5125
5123 if (*tmp == '{') { 5126 if (*tmp == '{') {
5124 const char *end; 5127 const char *end;
5125 tmp++; 5128 tmp++;
5126 end = strstr(tmp, "}%"); 5129 end = strstr(tmp, "}%");
5127 if (!end) /* Invalid string */ 5130 if (!end) /* Invalid string */
5128 continue; 5131 continue;
5129 format = g_strndup(tmp, end - tmp); 5132 if (!tm) {
5133 mtime = time(NULL);
5134 tm = localtime(&mtime);
5135 }
5136 replace = freeval = purple_uts35_to_str(tmp, end - tmp, tm);
5130 fin = end + 1; 5137 fin = end + 1;
5138 } else {
5139 if (!tm) {
5140 mtime = time(NULL);
5141 tm = localtime(&mtime);
5142 }
5143
5144 replace = purple_utf8_strftime("%X", tm);
5131 } 5145 }
5132
5133 if (!tm) {
5134 mtime = time(NULL);
5135 tm = localtime(&mtime);
5136 }
5137
5138 replace = purple_utf8_strftime(format ? format : "%X", tm);
5139 g_free(format);
5140 5146
5141 } else if (g_str_has_prefix(cur, "%dateOpened%")) { 5147 } else if (g_str_has_prefix(cur, "%dateOpened%")) {
5142 if (!tm) { 5148 if (!tm) {
5143 mtime = time(NULL); 5149 mtime = time(NULL);
5144 tm = localtime(&mtime); 5150 tm = localtime(&mtime);
5160 if (fin) { 5166 if (fin) {
5161 prev = cur = fin + 1; 5167 prev = cur = fin + 1;
5162 } else { 5168 } else {
5163 prev = cur = strchr(cur + 1, '%') + 1; 5169 prev = cur = strchr(cur + 1, '%') + 1;
5164 } 5170 }
5171 g_free(freeval);
5172 freeval = NULL;
5165 } 5173 }
5166 5174
5167 /* And wrap it up */ 5175 /* And wrap it up */
5168 g_string_append(str, prev); 5176 g_string_append(str, prev);
5169 return g_string_free(str, FALSE); 5177 return g_string_free(str, FALSE);
6202 6210
6203 replace = freeval = g_string_free(classes, FALSE); 6211 replace = freeval = g_string_free(classes, FALSE);
6204 6212
6205 } else if (g_str_has_prefix(cur, "%time")) { 6213 } else if (g_str_has_prefix(cur, "%time")) {
6206 const char *tmp = cur + strlen("%time"); 6214 const char *tmp = cur + strlen("%time");
6207 char *format = NULL;
6208 6215
6209 if (*tmp == '{') { 6216 if (*tmp == '{') {
6210 char *end; 6217 char *end;
6211 tmp++; 6218 tmp++;
6212 end = strstr(tmp, "}%"); 6219 end = strstr(tmp, "}%");
6213 if (!end) /* Invalid string */ 6220 if (!end) /* Invalid string */
6214 continue; 6221 continue;
6215 format = g_strndup(tmp, end - tmp); 6222 if (!tm)
6223 tm = localtime(&mtime);
6224 replace = freeval = purple_uts35_to_str(tmp, end - tmp, tm);
6216 fin = end + 1; 6225 fin = end + 1;
6226 } else {
6227 if (!tm)
6228 tm = localtime(&mtime);
6229
6230 replace = purple_utf8_strftime("%X", tm);
6217 } 6231 }
6218
6219 if (!tm)
6220 tm = localtime(&mtime);
6221
6222 replace = purple_utf8_strftime(format ? format : "%X", tm);
6223 g_free(format);
6224 6232
6225 } else if (g_str_has_prefix(cur, "%shortTime%")) { 6233 } else if (g_str_has_prefix(cur, "%shortTime%")) {
6226 if (!tm) 6234 if (!tm)
6227 tm = localtime(&mtime); 6235 tm = localtime(&mtime);
6228 6236

mercurial