/* preferred_format: 0=from config, 1=text, 2=html */ void message_view::display_body(const display_prefs& prefs, int preferred_format) { if (!m_pmsg) return; if (preferred_format==0) { preferred_format = get_config().get_string("display/body/preferred_format").toLower()=="text" ? 1: 2; } reset_state(); reset_commands(); /* First we try to fetch html contents from body.bodyhtml If it's empty, we look for an HTML part (even if we won't load it later) */ attachment* html_attachment=NULL; QString body_html = m_pmsg->get_body_html(); // from the body table if (body_html.isEmpty()) html_attachment = m_pmsg->body_html_attached_part(); // from the attachments QString body_text = m_pmsg->get_body_text(true); attachments_list& attchs = m_pmsg->attachments(); if (m_pmsg->has_attachments() > 0) { // Note: don't try to optimize here by removing the fetch: we need // it later for a lot of reasons, and the result is cached. attchs.fetch(); } if (preferred_format==1) { if (body_text.isEmpty()) { if (attchs.size() > 0) { attachments_list::iterator iter; for (iter=attchs.begin(); iter!=attchs.end(); iter++) { if (iter->filename().isEmpty() && iter->mime_type()=="text/plain") { iter->append_decoded_contents(body_text); } } } } } else { // preferred display format=html if (html_attachment && body_html.isEmpty()) { html_attachment->append_decoded_contents(body_html); } } // Format headers mail_displayer disp(this); QString h = QString("<div id=\"manitou-header\">%1%2%3</div><p>") .arg(disp.sprint_headers(prefs.m_show_headers_level, m_pmsg)) .arg(disp.sprint_additional_headers(prefs, m_pmsg)) .arg(QString("<div id=\"manitou-commands\"></div>")); m_has_text_part = !body_text.isEmpty(); m_has_html_part = (html_attachment!=NULL || !body_html.isEmpty()); if (preferred_format==1 || body_html.isEmpty()) { QString b2 = "<html><body>"; b2.append(h); b2.append("<div id=\"manitou-body\">"); b2.append(disp.text_body_to_html(body_text, prefs)); b2.append("</div>"); b2.append("</body></html>"); set_html_contents(b2, 1); // partial load? if (m_pmsg->body_length()>0 && m_pmsg->body_fetched_length() < m_pmsg->body_length()) { if (m_parent) { enable_command("complete_load", true); QString msg = QString(tr("Partial load (%1%)")).arg(m_pmsg->body_fetched_length()*100/ m_pmsg->body_length()); m_parent->blip_status_message(msg); } } if (m_parent) { enable_command("to_html", m_has_html_part); } } else { body_html.prepend("<div id=\"manitou-body\">"); body_html.append("</div>"); set_html_contents(body_html, 2); prepend_body_fragment(h); if (m_parent) enable_command("to_text", m_has_text_part); } display_commands(); }
static void execute_user_command(client_t *c, int narg, char **args) { const char *cmd; cmd = args[0]; narg--; args++; switch (narg) { case 0: if (!strcmp(cmd, "register")) register_client(c); else if (!strcmp(cmd, "unregister")) unregister_client(c); else if (!strcmp(cmd, "exit")) quit_mainloop(c, 0); else if (!strcmp(cmd, "quit")) quit_mainloop(c, 0); else if (!strcmp(cmd, "help")) { print(c, "Available commands:"); print(c, " register - register to server"); print(c, " unregister - unregister from server"); print(c, " focus none|shared|exclusive - request voice focus"); print(c, " add command <command> - add new command"); print(c, " del command <command> - delete a command"); print(c, " render tts '<msg>' \\ - request TTS of <msg>"); print(c, " [-voice:<voice>] \\"); print(c, " [-timeout:<timeout>]\\"); print(c, " [-events]"); print(c, " cancel tts '<id>' - cancel given TTS " "request"); print(c, " list commands - list commands set"); print(c, " list voices - list available voices"); print(c, " help - show this help"); print(c, " exit - exit from client"); } else print(c, "Unknown command '%s'.", cmd); break; case 1: if (!strcmp(cmd, "focus")) { if (strcmp(args[0], "none") && strcmp(args[0], "shared") && strcmp(args[0], "exclusive")) { print(c, "Invalid focus '%s', valid foci are: " "none, shared, and exclusive.", args[0]); } else request_focus(c, args[0]); } else if (!strcmp(cmd, "reset") && !strcmp(args[0], "commands")) reset_commands(c); else if (!strcmp(cmd, "list" ) && !strcmp(args[0], "commands")) list_commands(c); else if (!strcmp(cmd, "list" ) && !strcmp(args[0], "voices")) query_voices(c, NULL); else if (!strcmp(cmd, "cancel" ) && !strcmp(args[0], "tts")) cancel_tts(c, 0, NULL); else print(c, "Invalid command."); break; case 2: if (!strcmp(cmd, "list" ) && !strcmp(args[0], "voices")) query_voices(c, args[1]); else if (!strcmp(cmd, "cancel")) cancel_tts(c, narg-1, args+1); else print(c, "Invalid command."); break; default: if (!strcmp(args[0], "command")) { if (!strcmp(cmd, "add" )) add_command(c, narg-1, args+1); else if (!strcmp(cmd, "del" ) || !strcmp(cmd, "delete")) del_command(c, narg-1, args+1); else print(c, "Invalid command."); } else if (!strcmp(args[0], "tts")) { if (!strcmp(cmd, "render")) request_tts(c, narg-1, args+1); else print(c, "Invalid TTS command."); } else print(c, "Invalid command."); break; } }