i18n.c opens catopen("dtchat", NL_CAT_LOCALE) and dc_text(id, fallback) reads set 1; the program calls dc_i18n_init after setlocale. The visible labels of the main window, the account editor, the request/peer/file/pair dialogs and the local status texts use ui_text.h ids; dtchat.msg (English) has 75 entries and programs/localized/de_DE.UTF-8/msg/dtchat.msg the German copy (ASCII transliteration, core font). test_i18n builds both catalogs with gencat and checks File/Datei, Send/Senden and the fallback; the German run under Xvfb shows Datei/Bearbeiten/Ansicht/Konversation/Hilfe, In der Naehe and Senden (screenshot build/mcde-shots/dtchat-t104-de.png) and the smoke stays green. Dynamic formatted statuses are partly still English. The in-tree build is pending: a foreign release chain holds the lock (pid 141722).
212 lines
6.0 KiB
C
212 lines
6.0 KiB
C
/*
|
|
* ui_peer.c -- the peer details dialog
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* Shows what the local peer model knows: name, identity, certificate
|
|
* fingerprint, address, state and whether the peer came from mDNS or was
|
|
* added by hand. The Blocked toggle is applied at once (dc_peer_set_blocked)
|
|
* and reported to the caller; the dialog stays open.
|
|
*/
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include "ui_peer.h"
|
|
#include "ui_text.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <Xm/DialogS.h>
|
|
#include <Xm/Form.h>
|
|
#include <Xm/Label.h>
|
|
#include <Xm/PushB.h>
|
|
#include <Xm/RowColumn.h>
|
|
#include <Xm/Separator.h>
|
|
#include <Xm/ToggleB.h>
|
|
#include <Xm/Xm.h>
|
|
|
|
struct DtPeerDialog {
|
|
Widget shell;
|
|
Widget blocked;
|
|
DcPeer *peer;
|
|
DtPeerBlockFn fn;
|
|
void *arg;
|
|
int applied;
|
|
};
|
|
|
|
static XmString
|
|
xs(const char *s)
|
|
{
|
|
return XmStringCreateLocalized((char *)s);
|
|
}
|
|
|
|
static void
|
|
set_label(Widget w, const char *text)
|
|
{
|
|
XmString x = xs(text);
|
|
|
|
XtVaSetValues(w, XmNlabelString, x, NULL);
|
|
XmStringFree(x);
|
|
}
|
|
|
|
static Widget
|
|
row(Widget parent, Widget previous, const char *name, const char *value)
|
|
{
|
|
Widget form = XtVaCreateManagedWidget(name, xmFormWidgetClass, parent,
|
|
XmNleftAttachment, XmATTACH_FORM,
|
|
XmNrightAttachment, XmATTACH_FORM,
|
|
XmNtopAttachment, previous != NULL ? XmATTACH_WIDGET :
|
|
XmATTACH_FORM,
|
|
XmNtopWidget, previous,
|
|
XmNheight, 26, NULL);
|
|
Widget label = XmCreateLabel(form, "label", NULL, 0);
|
|
Widget text = XmCreateLabel(form, "value", NULL, 0);
|
|
XmString x = xs(name);
|
|
|
|
XtVaSetValues(label, XmNlabelString, x,
|
|
XmNleftAttachment, XmATTACH_FORM,
|
|
XmNtopAttachment, XmATTACH_FORM,
|
|
XmNwidth, 130, XmNrecomputeSize, False,
|
|
XmNalignment, XmALIGNMENT_END, XmNmarginRight, 8, NULL);
|
|
XmStringFree(x);
|
|
XtManageChild(label);
|
|
set_label(text, value != NULL ? value : "");
|
|
XtVaSetValues(text,
|
|
XmNleftAttachment, XmATTACH_WIDGET, XmNleftWidget, label,
|
|
XmNrightAttachment, XmATTACH_FORM,
|
|
XmNtopAttachment, XmATTACH_FORM,
|
|
XmNalignment, XmALIGNMENT_BEGINNING, NULL);
|
|
XtManageChild(text);
|
|
return form;
|
|
}
|
|
|
|
static void
|
|
apply_cb(Widget w, XtPointer client, XtPointer call)
|
|
{
|
|
DtPeerDialog *dialog = client;
|
|
int blocked;
|
|
|
|
(void)w;
|
|
(void)call;
|
|
blocked = XmToggleButtonGetState(dialog->blocked) ? 1 : 0;
|
|
dc_peer_set_blocked(dialog->peer, blocked);
|
|
dialog->applied = 1;
|
|
if (dialog->fn != NULL)
|
|
dialog->fn(dc_peer_id(dialog->peer), blocked, dialog->arg);
|
|
}
|
|
|
|
static void
|
|
close_cb(Widget w, XtPointer client, XtPointer call)
|
|
{
|
|
DtPeerDialog *dialog = client;
|
|
|
|
(void)w;
|
|
(void)call;
|
|
dtchat_peer_dialog_destroy(dialog);
|
|
}
|
|
|
|
DtPeerDialog *
|
|
dtchat_peer_dialog_create(Widget parent, DcPeer *peer, DtPeerBlockFn blocked,
|
|
void *arg)
|
|
{
|
|
DtPeerDialog *dialog;
|
|
Widget form, rows, buttons, apply, close;
|
|
char line[512];
|
|
const char *name;
|
|
const char *id;
|
|
const char *pin;
|
|
Widget previous = NULL;
|
|
XmString x;
|
|
|
|
if (parent == NULL || peer == NULL)
|
|
return NULL;
|
|
dialog = calloc(1, sizeof(*dialog));
|
|
if (dialog == NULL)
|
|
return NULL;
|
|
dialog->peer = peer;
|
|
dialog->fn = blocked;
|
|
dialog->arg = arg;
|
|
form = XmCreateFormDialog(parent, "peerDialog", NULL, 0);
|
|
if (form == NULL) {
|
|
free(dialog);
|
|
return NULL;
|
|
}
|
|
dialog->shell = XtParent(form);
|
|
XtVaSetValues(dialog->shell, XmNtitle,
|
|
(char *)dc_text(TX_PEER, "Peer"), XmNwidth, 480,
|
|
XmNheight, 330, XmNdeleteResponse, XmDESTROY, NULL);
|
|
|
|
rows = XtVaCreateManagedWidget("rows", xmFormWidgetClass, form,
|
|
XmNtopAttachment, XmATTACH_FORM,
|
|
XmNleftAttachment, XmATTACH_FORM,
|
|
XmNrightAttachment, XmATTACH_FORM, XmNmarginHeight, 6, NULL);
|
|
|
|
name = dc_peer_name(peer);
|
|
id = dc_peer_id(peer);
|
|
pin = dc_peer_pin(peer);
|
|
previous = row(rows, NULL, dc_text(TX_NAME, "Name"), name);
|
|
previous = row(rows, previous, dc_text(TX_IDENTITY, "Identity"), id);
|
|
previous = row(rows, previous, dc_text(TX_FINGERPRINT, "Fingerprint"),
|
|
pin != NULL && *pin != '\0' ? pin :
|
|
dc_text(TX_NOT_KNOWN, "(not known yet)"));
|
|
snprintf(line, sizeof(line), "%s:%d",
|
|
dc_peer_host(peer) != NULL && dc_peer_host(peer)[0] != '\0' ?
|
|
dc_peer_host(peer) : "(no address)", dc_peer_port(peer));
|
|
previous = row(rows, previous, dc_text(TX_ADDRESS, "Address"), line);
|
|
previous = row(rows, previous, dc_text(TX_STATE, "State"),
|
|
dc_peer_online(peer) ? "online" : "offline");
|
|
previous = row(rows, previous, dc_text(TX_SOURCE, "Source"),
|
|
dc_peer_manual(peer) ? dc_text(TX_ADDED_BY_HAND, "added by hand") :
|
|
dc_text(TX_FOUND_NETWORK, "found on the network"));
|
|
|
|
dialog->blocked = XmCreateToggleButton(rows, "blocked", NULL, 0);
|
|
x = xs(dc_text(TX_BLOCK_PEER, "Block this peer"));
|
|
XtVaSetValues(dialog->blocked, XmNlabelString, x,
|
|
XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, previous,
|
|
XmNleftAttachment, XmATTACH_FORM, XmNtopOffset, 8, NULL);
|
|
XmStringFree(x);
|
|
XmToggleButtonSetState(dialog->blocked, dc_peer_blocked(peer), False);
|
|
XtManageChild(dialog->blocked);
|
|
XtVaSetValues(rows, XmNbottomAttachment, XmATTACH_WIDGET,
|
|
XmNbottomWidget, dialog->blocked, NULL);
|
|
|
|
buttons = XtVaCreateManagedWidget("buttons", xmRowColumnWidgetClass,
|
|
form, XmNorientation, XmHORIZONTAL, XmNspacing, 6,
|
|
XmNbottomAttachment, XmATTACH_FORM,
|
|
XmNleftAttachment, XmATTACH_FORM,
|
|
XmNrightAttachment, XmATTACH_FORM, XmNmarginHeight, 6, NULL);
|
|
apply = XmCreatePushButton(buttons, "apply", NULL, 0);
|
|
set_label(apply, dc_text(TX_APPLY, "Apply"));
|
|
XtAddCallback(apply, XmNactivateCallback, apply_cb, dialog);
|
|
XtManageChild(apply);
|
|
close = XmCreatePushButton(buttons, "close", NULL, 0);
|
|
set_label(close, dc_text(TX_CLOSE, "Close"));
|
|
XtAddCallback(close, XmNactivateCallback, close_cb, dialog);
|
|
XtManageChild(close);
|
|
|
|
XtManageChild(form);
|
|
XtPopup(dialog->shell, XtGrabNone);
|
|
return dialog;
|
|
}
|
|
|
|
void
|
|
dtchat_peer_dialog_destroy(DtPeerDialog *dialog)
|
|
{
|
|
if (dialog == NULL)
|
|
return;
|
|
if (dialog->shell != NULL) {
|
|
Widget shell = dialog->shell;
|
|
|
|
dialog->shell = NULL;
|
|
XtDestroyWidget(shell);
|
|
}
|
|
free(dialog);
|
|
}
|
|
|
|
Widget
|
|
dtchat_peer_dialog_shell(const DtPeerDialog *dialog)
|
|
{
|
|
return dialog != NULL ? dialog->shell : NULL;
|
|
}
|