예제 #1
0
static char *timestamp_cb_common(PurpleConversation *conv,
                                 time_t t,
                                 gboolean show_date,
                                 gboolean force,
                                 const char *dates,
								 gboolean parens)
{
	g_return_val_if_fail(dates != NULL, NULL);

	if (show_date ||
	    !strcmp(dates, "always") ||
	    (conv != NULL && purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_CHAT && !strcmp(dates, "chats")))
	{
		struct tm *tm = localtime(&t);
		if (force)
			return g_strdup_printf("%s%s%s", parens ? "(" : "", purple_utf8_strftime("%Y-%m-%d %H:%M:%S", tm), parens ? ")" : "");
		else
			return g_strdup_printf("%s%s%s", parens ? "(" : "", purple_date_format_long(tm), parens ? ")" : "");
	}

	if (force)
	{
		struct tm *tm = localtime(&t);
		return g_strdup_printf("%s%s%s", parens ? "(" : "", purple_utf8_strftime("%H:%M:%S", tm), parens ? ")" : "");
	}

	return NULL;
}
예제 #2
0
void Notify::UserInfoDialog::update(PurpleConnection *gc, const char *who,
    PurpleNotifyUserInfo *user_info)
{
  treeview->clear();
  CppConsUI::TreeView::NodeReference parent;
  CppConsUI::Button *button;

  // local information
  PurpleAccount *account = purple_connection_get_account(gc);
  PurpleBuddy *buddy = purple_find_buddy(account, who);
  if (buddy) {
    /* Note that we should always be able to find the specified buddy, unless
     * something goes very wrong. */
    button = new CppConsUI::TreeView::ToggleCollapseButton(
        _("Local information"));
    parent = treeview->appendNode(treeview->getRootNode(), *button);

    button = new CppConsUI::Button(CppConsUI::Button::FLAG_VALUE,
        _("Alias"), purple_buddy_get_alias(buddy));
    treeview->appendNode(parent, *button);

    time_t saved_time;
    struct tm local_time;
    const char *formatted_time;

    // last_seen
    if (PURPLE_BUDDY_IS_ONLINE(buddy))
      formatted_time = _("Now");
    else {
      saved_time = static_cast<time_t>(purple_blist_node_get_int(
            PURPLE_BLIST_NODE(buddy), "last_seen"));
      if (saved_time && localtime_r(&saved_time, &local_time))
        formatted_time = purple_date_format_long(&local_time);
      else
        formatted_time = _("Unknown");
    }
    button = new CppConsUI::Button(CppConsUI::Button::FLAG_VALUE,
        _("Last seen"), formatted_time);
    treeview->appendNode(parent, *button);

    // last_activity
    saved_time = static_cast<time_t>(purple_blist_node_get_int(
          PURPLE_BLIST_NODE(buddy), "last_activity"));
    if (saved_time && localtime_r(&saved_time, &local_time))
      formatted_time = purple_date_format_long(&local_time);
    else
      formatted_time = _("Unknown");
    button = new CppConsUI::Button(CppConsUI::Button::FLAG_VALUE,
        _("Last activity"), formatted_time);
    treeview->appendNode(parent, *button);
  }

  // remote information
  button = new CppConsUI::TreeView::ToggleCollapseButton(
      _("Remote information"));
  parent = treeview->appendNode(treeview->getRootNode(), *button);
  CppConsUI::TreeView::NodeReference subparent = parent;
  for (GList *i = purple_notify_user_info_get_entries(user_info); i;
      i = i->next) {
    PurpleNotifyUserInfoEntry *entry
      = reinterpret_cast<PurpleNotifyUserInfoEntry*>(i->data);
    PurpleNotifyUserInfoEntryType type
      = purple_notify_user_info_entry_get_type(entry);

    const char *label = purple_notify_user_info_entry_get_label(entry);
    if (!label)
      continue;
    const char *value = purple_notify_user_info_entry_get_value(entry);
    char *nohtml = purple_markup_strip_html(value);
    switch (type) {
      case PURPLE_NOTIFY_USER_INFO_ENTRY_PAIR:
        button = new CppConsUI::Button(
            nohtml ? CppConsUI::Button::FLAG_VALUE : 0, label, nohtml);
        treeview->appendNode(subparent, *button);
        break;
      case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_BREAK:
        // ignore section breaks
        break;
      case PURPLE_NOTIFY_USER_INFO_ENTRY_SECTION_HEADER:
        button = new CppConsUI::TreeView::ToggleCollapseButton(label);
        subparent = treeview->appendNode(parent, *button);
        break;
      default:
        LOG->error(_("Unhandled userinfo entry type '%d'."), type);
        break;
    }
    g_free(nohtml);
  }

  treeview->grabFocus();
}