mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-09-24 00:27:09 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02a6902cec |
+1
-15
@@ -126,21 +126,7 @@ ctcp_handle (session *sess, char *to, char *nick, char *ip,
|
||||
if (ctcp_check (sess, nick, word, word_eol, word[4] + ctcp_offset))
|
||||
goto generic;
|
||||
|
||||
{
|
||||
gboolean private_fromme = !serv->p_cmp (nick, serv->nick) && !is_channel (serv, to);
|
||||
|
||||
if (private_fromme)
|
||||
{
|
||||
session *target = find_dialog (serv, to);
|
||||
|
||||
if (target)
|
||||
sess = target;
|
||||
else if (serv->front_session)
|
||||
sess = serv->front_session;
|
||||
}
|
||||
|
||||
inbound_action (sess, to, nick, ip, msg + 7, private_fromme, tags_data->identified, tags_data);
|
||||
}
|
||||
inbound_action (sess, to, nick, ip, msg + 7, FALSE, tags_data->identified, tags_data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1368,7 +1368,7 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[],
|
||||
{
|
||||
if (ignore_check (word[1], IG_PRIV))
|
||||
return;
|
||||
if (!serv->p_cmp (nick, serv->nick))
|
||||
if (serv->have_echo_message && !serv->p_cmp (nick, serv->nick))
|
||||
{
|
||||
session *target_sess = find_dialog (serv, to);
|
||||
|
||||
|
||||
+1
-1
@@ -114,7 +114,7 @@ typedef struct restore_gui
|
||||
|
||||
/* information stored when this tab isn't front-most */
|
||||
GtkListStore *user_model; /* for filling the GtkTreeView */
|
||||
GHashTable *user_row_iters; /* User * -> persistent GtkTreeIter * */
|
||||
GHashTable *user_row_refs;
|
||||
void *buffer; /* xtext_Buffer */
|
||||
char *input_text; /* input text buffer (while not-front tab) */
|
||||
char *topic_text; /* topic GtkEntry buffer */
|
||||
|
||||
+224
-3
@@ -925,10 +925,217 @@ mg_send_reply_or_text (session *sess, char *cmd)
|
||||
mg_reply_update (sess);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gboolean bold;
|
||||
gboolean italic;
|
||||
gboolean underline;
|
||||
gboolean strikethrough;
|
||||
gboolean reverse;
|
||||
gint foreground;
|
||||
gint background;
|
||||
gboolean pending_foreground;
|
||||
gboolean pending_background;
|
||||
} MgInputFormatState;
|
||||
|
||||
static void
|
||||
mg_input_format_state_at_cursor (GtkEntry *entry, MgInputFormatState *state)
|
||||
{
|
||||
const char *text;
|
||||
const char *cursor;
|
||||
gsize limit;
|
||||
gsize i;
|
||||
gint cursor_pos;
|
||||
|
||||
memset (state, 0, sizeof (*state));
|
||||
state->foreground = -1;
|
||||
state->background = -1;
|
||||
|
||||
text = gtk_entry_get_text (entry);
|
||||
cursor_pos = gtk_editable_get_position (GTK_EDITABLE (entry));
|
||||
if (!text || cursor_pos < 0)
|
||||
return;
|
||||
|
||||
cursor = g_utf8_offset_to_pointer (text, cursor_pos);
|
||||
limit = (gsize) (cursor - text);
|
||||
|
||||
for (i = 0; i < limit;)
|
||||
{
|
||||
guchar ch = (guchar) text[i++];
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case ATTR_BOLD:
|
||||
state->bold = !state->bold;
|
||||
break;
|
||||
case ATTR_ITALICS:
|
||||
state->italic = !state->italic;
|
||||
break;
|
||||
case ATTR_UNDERLINE:
|
||||
state->underline = !state->underline;
|
||||
break;
|
||||
case ATTR_STRIKETHROUGH:
|
||||
state->strikethrough = !state->strikethrough;
|
||||
break;
|
||||
case ATTR_REVERSE:
|
||||
state->reverse = !state->reverse;
|
||||
break;
|
||||
case ATTR_RESET:
|
||||
case '\n':
|
||||
state->bold = FALSE;
|
||||
state->italic = FALSE;
|
||||
state->underline = FALSE;
|
||||
state->strikethrough = FALSE;
|
||||
state->reverse = FALSE;
|
||||
state->foreground = -1;
|
||||
state->background = -1;
|
||||
state->pending_foreground = FALSE;
|
||||
state->pending_background = FALSE;
|
||||
break;
|
||||
case ATTR_COLOR:
|
||||
{
|
||||
gint value = 0;
|
||||
gint digits = 0;
|
||||
|
||||
state->pending_foreground = FALSE;
|
||||
state->pending_background = FALSE;
|
||||
|
||||
if (i >= limit)
|
||||
{
|
||||
state->pending_foreground = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!g_ascii_isdigit (text[i]))
|
||||
{
|
||||
state->foreground = -1;
|
||||
state->background = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
while (i < limit && digits < 2 && g_ascii_isdigit (text[i]))
|
||||
{
|
||||
value = (value * 10) + (text[i] - '0');
|
||||
i++;
|
||||
digits++;
|
||||
}
|
||||
state->foreground = value;
|
||||
state->background = -1;
|
||||
|
||||
if (i < limit && text[i] == ',')
|
||||
{
|
||||
i++;
|
||||
if (i >= limit)
|
||||
{
|
||||
state->pending_background = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
value = 0;
|
||||
digits = 0;
|
||||
while (i < limit && digits < 2 && g_ascii_isdigit (text[i]))
|
||||
{
|
||||
value = (value * 10) + (text[i] - '0');
|
||||
i++;
|
||||
digits++;
|
||||
}
|
||||
if (digits > 0)
|
||||
state->background = value;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mg_input_format_append (GString *summary, const char *text)
|
||||
{
|
||||
if (summary->len > 0)
|
||||
g_string_append (summary, " · ");
|
||||
g_string_append (summary, text);
|
||||
}
|
||||
|
||||
static void
|
||||
mg_input_format_update (GtkEntry *entry)
|
||||
{
|
||||
GtkWidget *format_box;
|
||||
GtkWidget *format_label;
|
||||
MgInputFormatState state;
|
||||
GString *summary;
|
||||
char color[48];
|
||||
char *markup;
|
||||
|
||||
format_box = g_object_get_data (G_OBJECT (entry), "zoitechat-format-box");
|
||||
format_label = g_object_get_data (G_OBJECT (entry), "zoitechat-format-label");
|
||||
if (!format_box || !format_label)
|
||||
return;
|
||||
|
||||
if (!prefs.hex_gui_input_attr)
|
||||
{
|
||||
gtk_widget_hide (format_box);
|
||||
return;
|
||||
}
|
||||
|
||||
mg_input_format_state_at_cursor (entry, &state);
|
||||
summary = g_string_new (NULL);
|
||||
|
||||
if (state.bold)
|
||||
mg_input_format_append (summary, "<b>Bold</b>");
|
||||
if (state.italic)
|
||||
mg_input_format_append (summary, "<i>Italic</i>");
|
||||
if (state.underline)
|
||||
mg_input_format_append (summary, "<u>Underline</u>");
|
||||
if (state.strikethrough)
|
||||
mg_input_format_append (summary, "<s>Strikethrough</s>");
|
||||
if (state.reverse)
|
||||
mg_input_format_append (summary, "Reverse");
|
||||
|
||||
if (state.foreground >= 0)
|
||||
{
|
||||
g_snprintf (color, sizeof (color), "Text color <b>%02d</b>", state.foreground);
|
||||
mg_input_format_append (summary, color);
|
||||
}
|
||||
if (state.background >= 0)
|
||||
{
|
||||
g_snprintf (color, sizeof (color), "Background <b>%02d</b>", state.background);
|
||||
mg_input_format_append (summary, color);
|
||||
}
|
||||
if (state.pending_foreground)
|
||||
mg_input_format_append (summary, "Color: type foreground[,background]");
|
||||
else if (state.pending_background)
|
||||
mg_input_format_append (summary, "Background: type color");
|
||||
|
||||
if (summary->len == 0)
|
||||
{
|
||||
gtk_widget_hide (format_box);
|
||||
g_string_free (summary, TRUE);
|
||||
return;
|
||||
}
|
||||
|
||||
markup = g_strdup_printf ("<span foreground='#7d8790'>Formatting · %s</span>", summary->str);
|
||||
gtk_label_set_markup (GTK_LABEL (format_label), markup);
|
||||
gtk_widget_show (format_label);
|
||||
gtk_widget_show (format_box);
|
||||
g_free (markup);
|
||||
g_string_free (summary, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
mg_inputbox_cursor_changed (GObject *object, GParamSpec *pspec, gpointer userdata)
|
||||
{
|
||||
(void) pspec;
|
||||
(void) userdata;
|
||||
mg_input_format_update (GTK_ENTRY (object));
|
||||
}
|
||||
|
||||
static void
|
||||
mg_inputbox_changed (GtkEditable *editable, session_gui *gui)
|
||||
{
|
||||
key_check_replace_on_change (editable, NULL);
|
||||
mg_input_format_update (GTK_ENTRY (editable));
|
||||
if (current_sess && current_sess->gui == gui)
|
||||
mg_typing_update (current_sess, gtk_entry_get_text (GTK_ENTRY (editable)));
|
||||
}
|
||||
@@ -4799,7 +5006,7 @@ mg_create_search(session *sess, GtkWidget *box)
|
||||
static void
|
||||
mg_create_entry (session *sess, GtkWidget *box)
|
||||
{
|
||||
GtkWidget *hbox, *but, *entry;
|
||||
GtkWidget *hbox, *but, *entry, *format_box, *format_label;
|
||||
session_gui *gui = sess->gui;
|
||||
const char *emoji_fallback_icon_names[] = {
|
||||
"face-smile-symbolic",
|
||||
@@ -4811,6 +5018,16 @@ mg_create_entry (session *sess, GtkWidget *box)
|
||||
};
|
||||
const char *emoji_fallback_icon_name;
|
||||
|
||||
format_box = mg_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 6);
|
||||
gtk_widget_set_name (format_box, "zoitechat-formatbar");
|
||||
gtk_widget_set_no_show_all (format_box, TRUE);
|
||||
gtk_box_pack_start (GTK_BOX (box), format_box, 0, 0, 0);
|
||||
format_label = gtk_label_new ("");
|
||||
gtk_label_set_ellipsize (GTK_LABEL (format_label), PANGO_ELLIPSIZE_END);
|
||||
gtk_box_pack_start (GTK_BOX (format_box), format_label, TRUE, TRUE, 8);
|
||||
gtk_widget_show (format_label);
|
||||
gtk_widget_hide (format_box);
|
||||
|
||||
gui->reply_box = mg_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 6);
|
||||
gtk_widget_set_name (gui->reply_box, "zoitechat-replybar");
|
||||
gtk_widget_set_no_show_all (gui->reply_box, TRUE);
|
||||
@@ -4841,12 +5058,16 @@ mg_create_entry (session *sess, GtkWidget *box)
|
||||
gui->input_box = entry = sexy_spell_entry_new ();
|
||||
sexy_spell_entry_set_checked ((SexySpellEntry *)entry, prefs.hex_gui_input_spell);
|
||||
sexy_spell_entry_set_parse_attributes ((SexySpellEntry *)entry, prefs.hex_gui_input_attr);
|
||||
g_object_set_data (G_OBJECT (entry), "zoitechat-format-box", format_box);
|
||||
g_object_set_data (G_OBJECT (entry), "zoitechat-format-label", format_label);
|
||||
|
||||
gtk_entry_set_max_length (GTK_ENTRY (gui->input_box), 0);
|
||||
g_signal_connect (G_OBJECT (entry), "activate",
|
||||
G_CALLBACK (mg_inputbox_cb), gui);
|
||||
g_signal_connect (G_OBJECT (entry), "changed",
|
||||
G_CALLBACK (mg_inputbox_changed), gui);
|
||||
g_signal_connect (G_OBJECT (entry), "notify::cursor-position",
|
||||
G_CALLBACK (mg_inputbox_cursor_changed), gui);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
|
||||
|
||||
gtk_widget_set_name (entry, "zoitechat-inputbox");
|
||||
@@ -5786,9 +6007,9 @@ void
|
||||
fe_session_callback (session *sess)
|
||||
{
|
||||
gtk_xtext_buffer_free (sess->res->buffer);
|
||||
if (sess->res->user_row_iters)
|
||||
g_hash_table_destroy (sess->res->user_row_iters);
|
||||
g_object_unref (G_OBJECT (sess->res->user_model));
|
||||
if (sess->res->user_row_refs)
|
||||
g_hash_table_destroy (sess->res->user_row_refs);
|
||||
|
||||
if (sess->res->banlist && sess->res->banlist->window)
|
||||
mg_close_gen (NULL, sess->res->banlist->window);
|
||||
|
||||
+47
-20
@@ -218,49 +218,75 @@ scroll_to_iter (GtkTreeIter *iter, GtkTreeView *treeview, GtkTreeModel *model)
|
||||
static GHashTable *
|
||||
userlist_row_map_ensure (session *sess)
|
||||
{
|
||||
if (!sess->res->user_row_iters)
|
||||
sess->res->user_row_iters = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) gtk_tree_iter_free);
|
||||
if (!sess->res->user_row_refs)
|
||||
sess->res->user_row_refs = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) gtk_tree_row_reference_free);
|
||||
|
||||
return sess->res->user_row_iters;
|
||||
return sess->res->user_row_refs;
|
||||
}
|
||||
|
||||
static void
|
||||
userlist_row_map_remove (session *sess, struct User *user)
|
||||
{
|
||||
if (!sess->res->user_row_iters)
|
||||
if (!sess->res->user_row_refs)
|
||||
return;
|
||||
|
||||
g_hash_table_remove (sess->res->user_row_iters, user);
|
||||
g_hash_table_remove (sess->res->user_row_refs, user);
|
||||
}
|
||||
|
||||
static void
|
||||
userlist_row_map_set (session *sess, GtkTreeModel *model, struct User *user, GtkTreeIter *iter)
|
||||
{
|
||||
/* The shared tree view can still show another session's model while a
|
||||
* tab switch is pending. Never cache an iterator from that model. */
|
||||
if (model != GTK_TREE_MODEL (sess->res->user_model))
|
||||
GtkTreePath *path;
|
||||
GtkTreeRowReference *ref;
|
||||
|
||||
path = gtk_tree_model_get_path (model, iter);
|
||||
if (!path)
|
||||
return;
|
||||
|
||||
/* GtkListStore guarantees persistent iterators until their row is
|
||||
* removed, including across sorting. Unlike row references, these do
|
||||
* not require every cached position to be updated on each insertion. */
|
||||
g_hash_table_replace (userlist_row_map_ensure (sess), user, gtk_tree_iter_copy (iter));
|
||||
ref = gtk_tree_row_reference_new (model, path);
|
||||
gtk_tree_path_free (path);
|
||||
if (!ref)
|
||||
return;
|
||||
|
||||
g_hash_table_replace (userlist_row_map_ensure (sess), user, ref);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
userlist_row_map_get_iter (session *sess, GtkTreeModel *model, struct User *user, GtkTreeIter *iter)
|
||||
{
|
||||
GtkTreeIter *cached;
|
||||
GtkTreeRowReference *ref;
|
||||
GtkTreePath *path;
|
||||
struct User *row_user;
|
||||
|
||||
if (model != GTK_TREE_MODEL (sess->res->user_model) || !sess->res->user_row_iters)
|
||||
if (!sess->res->user_row_refs)
|
||||
return FALSE;
|
||||
|
||||
cached = g_hash_table_lookup (sess->res->user_row_iters, user);
|
||||
if (!cached)
|
||||
ref = g_hash_table_lookup (sess->res->user_row_refs, user);
|
||||
if (!ref)
|
||||
return FALSE;
|
||||
|
||||
/* Removal and clear invalidate the cache before deleting model rows. */
|
||||
*iter = *cached;
|
||||
path = gtk_tree_row_reference_get_path (ref);
|
||||
if (!path)
|
||||
{
|
||||
g_hash_table_remove (sess->res->user_row_refs, user);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gtk_tree_model_get_iter (model, iter, path))
|
||||
{
|
||||
gtk_tree_path_free (path);
|
||||
g_hash_table_remove (sess->res->user_row_refs, user);
|
||||
return FALSE;
|
||||
}
|
||||
gtk_tree_path_free (path);
|
||||
|
||||
gtk_tree_model_get (model, iter, COL_USER, &row_user, -1);
|
||||
if (row_user != user)
|
||||
{
|
||||
g_hash_table_remove (sess->res->user_row_refs, user);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -561,6 +587,7 @@ fe_userlist_rehash (session *sess, struct User *user)
|
||||
GTK_TREE_MODEL(sess->res->user_model), user, &sel);
|
||||
if (!iter)
|
||||
return;
|
||||
userlist_row_map_set (sess, GTK_TREE_MODEL (sess->res->user_model), user, iter);
|
||||
|
||||
if (prefs.hex_away_track && user->away)
|
||||
{
|
||||
@@ -671,8 +698,8 @@ fe_userlist_insert (session *sess, struct User *newuser, gboolean sel)
|
||||
void
|
||||
fe_userlist_clear (session *sess)
|
||||
{
|
||||
if (sess->res->user_row_iters)
|
||||
g_hash_table_remove_all (sess->res->user_row_iters);
|
||||
if (sess->res->user_row_refs)
|
||||
g_hash_table_remove_all (sess->res->user_row_refs);
|
||||
gtk_list_store_clear (sess->res->user_model);
|
||||
}
|
||||
|
||||
|
||||
+7
-16
@@ -3130,7 +3130,6 @@ gtk_xtext_class_init (GtkXTextClass * class)
|
||||
|
||||
typedef struct chunk_s {
|
||||
GSList *slp;
|
||||
gboolean collect_metadata;
|
||||
int off1, len1, emph;
|
||||
offlen_t meta;
|
||||
} chunk_t;
|
||||
@@ -3143,19 +3142,12 @@ xtext_do_chunk(chunk_t *c)
|
||||
if (c->len1 == 0)
|
||||
return;
|
||||
|
||||
/* Copying, searching and saving only need the stripped text. */
|
||||
if (!c->collect_metadata)
|
||||
{
|
||||
c->len1 = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
meta = g_new (offlen_t, 1);
|
||||
meta->off = c->off1;
|
||||
meta->len = c->len1;
|
||||
meta->emph = c->emph;
|
||||
meta->width = 0;
|
||||
c->slp = g_slist_prepend (c->slp, meta);
|
||||
c->slp = g_slist_append (c->slp, meta);
|
||||
|
||||
c->len1 = 0;
|
||||
}
|
||||
@@ -3178,7 +3170,6 @@ gtk_xtext_strip_color (unsigned char *text, int len, unsigned char *outbuf,
|
||||
new_str = outbuf;
|
||||
|
||||
c.slp = NULL;
|
||||
c.collect_metadata = slpp != NULL;
|
||||
c.off1 = 0;
|
||||
c.len1 = 0;
|
||||
c.emph = 0;
|
||||
@@ -3249,7 +3240,9 @@ bad_utf8: /* Normal ending sequence, and give up if bad utf8 */
|
||||
*newlen = i;
|
||||
|
||||
if (slpp)
|
||||
*slpp = g_slist_reverse (c.slp);
|
||||
*slpp = c.slp;
|
||||
else
|
||||
g_slist_free_full (c.slp, g_free);
|
||||
|
||||
return new_str;
|
||||
}
|
||||
@@ -4348,7 +4341,7 @@ gtk_xtext_lines_taken (xtext_buffer *buf, textentry * ent)
|
||||
|
||||
if (win_width >= ent->indent + ent->str_width)
|
||||
{
|
||||
ent->sublines = g_slist_prepend (ent->sublines, GINT_TO_POINTER (ent->str_len));
|
||||
ent->sublines = g_slist_append (ent->sublines, GINT_TO_POINTER (ent->str_len));
|
||||
ent->subline_count = 1;
|
||||
return ent->subline_count;
|
||||
}
|
||||
@@ -4359,15 +4352,13 @@ gtk_xtext_lines_taken (xtext_buffer *buf, textentry * ent)
|
||||
do
|
||||
{
|
||||
len = find_next_wrap (buf->xtext, ent, str, win_width, indent);
|
||||
ent->sublines = g_slist_prepend (ent->sublines, GINT_TO_POINTER (str + len - ent->str));
|
||||
ent->subline_count++;
|
||||
ent->sublines = g_slist_append (ent->sublines, GINT_TO_POINTER (str + len - ent->str));
|
||||
indent = buf->indent;
|
||||
str += len;
|
||||
}
|
||||
while (str < ent->str + ent->str_len);
|
||||
|
||||
/* Preserve display order without walking the growing list per wrap. */
|
||||
ent->sublines = g_slist_reverse (ent->sublines);
|
||||
ent->subline_count = g_slist_length (ent->sublines);
|
||||
return ent->subline_count;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user