mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-31 07:26:21 +00:00
Build URL ac upon printing of message in window
This commit is contained in:
@@ -3921,12 +3921,12 @@ _urlopen_autocomplete(ProfWin *window, const char *const input, gboolean previou
|
|||||||
{
|
{
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
|
|
||||||
if (window->type == WIN_CONSOLE){
|
if (window->type == WIN_CHAT ||
|
||||||
return result;
|
window->type == WIN_MUC ||
|
||||||
|
window->type == WIN_PRIVATE) {
|
||||||
|
result = autocomplete_param_with_func(input, "/urlopen", wins_get_url, previous, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = autocomplete_param_no_with_func(input, "/urlopen", 2, buffer_get_url, previous, window->layout->buffer);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8862,19 +8862,27 @@ cmd_slashguard(ProfWin *window, const char *const command, gchar **args)
|
|||||||
gboolean
|
gboolean
|
||||||
cmd_urlopen(ProfWin *window, const char *const command, gchar **args)
|
cmd_urlopen(ProfWin *window, const char *const command, gchar **args)
|
||||||
{
|
{
|
||||||
if (args[0] == NULL) {
|
if (window->type == WIN_CHAT ||
|
||||||
cons_bad_cmd_usage(command);
|
window->type == WIN_MUC ||
|
||||||
return TRUE;
|
window->type == WIN_PRIVATE) {
|
||||||
|
|
||||||
|
if (args[0] == NULL) {
|
||||||
|
cons_bad_cmd_usage(command);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: make function. see src/xmpp/avatar.c
|
||||||
|
GString *cmd = g_string_new("");
|
||||||
|
|
||||||
|
g_string_append_printf(cmd, "%s %s > /dev/null 2>&1", "xdg-open", args[0]);
|
||||||
|
cons_show("Calling: %s", cmd->str);
|
||||||
|
FILE *stream = popen(cmd->str, "r");
|
||||||
|
|
||||||
|
pclose(stream);
|
||||||
|
g_string_free(cmd, TRUE);
|
||||||
|
} else {
|
||||||
|
cons_show("urlopen not supported in this window");
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: make function. see src/xmpp/avatar.c
|
|
||||||
GString *cmd = g_string_new("");
|
|
||||||
|
|
||||||
g_string_append_printf(cmd, "%s %s > /dev/null 2>&1", "xdg-open", args[0]);
|
|
||||||
cons_show("Calling: %s", cmd->str);
|
|
||||||
FILE *stream = popen(cmd->str, "r");
|
|
||||||
|
|
||||||
pclose(stream);
|
|
||||||
g_string_free(cmd, TRUE);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -162,39 +162,6 @@ buffer_get_entry_by_id(ProfBuff buffer, const char *const id)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
|
||||||
buffer_get_url(const char *const search_str, gboolean previous, void *context)
|
|
||||||
{
|
|
||||||
Autocomplete urls_ac = autocomplete_new();
|
|
||||||
ProfBuff buffer = (ProfBuff)context;
|
|
||||||
GSList *entries = buffer->entries;
|
|
||||||
|
|
||||||
while (entries) {
|
|
||||||
ProfBuffEntry *entry = entries->data;
|
|
||||||
|
|
||||||
GRegex *regex;
|
|
||||||
GMatchInfo *match_info;
|
|
||||||
|
|
||||||
regex = g_regex_new("https?://\\S+", 0, 0, NULL);
|
|
||||||
g_regex_match (regex, entry->message, 0, &match_info);
|
|
||||||
while (g_match_info_matches (match_info))
|
|
||||||
{
|
|
||||||
gchar *word = g_match_info_fetch (match_info, 0);
|
|
||||||
|
|
||||||
autocomplete_add(urls_ac, word);
|
|
||||||
|
|
||||||
g_free (word);
|
|
||||||
g_match_info_next (match_info, NULL);
|
|
||||||
}
|
|
||||||
g_match_info_free (match_info);
|
|
||||||
g_regex_unref (regex);
|
|
||||||
|
|
||||||
entries = g_slist_next(entries);
|
|
||||||
}
|
|
||||||
|
|
||||||
return autocomplete_complete(urls_ac, "", FALSE, previous);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_free_entry(ProfBuffEntry *entry)
|
_free_entry(ProfBuffEntry *entry)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,6 +73,5 @@ int buffer_size(ProfBuff buffer);
|
|||||||
ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
|
ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
|
||||||
ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char *const id);
|
ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char *const id);
|
||||||
gboolean buffer_mark_received(ProfBuff buffer, const char *const id);
|
gboolean buffer_mark_received(ProfBuff buffer, const char *const id);
|
||||||
char* buffer_get_url(const char *const search_str, gboolean previous, void *context);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -292,7 +292,7 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
|
|||||||
//1) only send IQ once
|
//1) only send IQ once
|
||||||
//2) sort incoming messages on timestamp
|
//2) sort incoming messages on timestamp
|
||||||
//for now if experimental MAM is enabled we dont show no history from sql either
|
//for now if experimental MAM is enabled we dont show no history from sql either
|
||||||
|
|
||||||
// MUCPMs also get printed here. In their case we don't save any logs (because nick owners can change) and thus we shouldn't read logs
|
// MUCPMs also get printed here. In their case we don't save any logs (because nick owners can change) and thus we shouldn't read logs
|
||||||
// (and if we do we need to check the resourcepart)
|
// (and if we do we need to check the resourcepart)
|
||||||
if (!prefs_get_boolean(PREF_MAM) && prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY) && message->type == PROF_MSG_TYPE_CHAT) {
|
if (!prefs_get_boolean(PREF_MAM) && prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY) && message->type == PROF_MSG_TYPE_CHAT) {
|
||||||
@@ -311,6 +311,8 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
|
|||||||
win_print_incoming(window, display_name, message);
|
win_print_incoming(window, display_name, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wins_add_urls_ac(window, message);
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_BEEP)) {
|
if (prefs_get_boolean(PREF_BEEP)) {
|
||||||
beep();
|
beep();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -557,6 +557,7 @@ mucwin_incoming_msg(ProfMucWin *mucwin, const ProfMessage *const message, GSList
|
|||||||
}
|
}
|
||||||
|
|
||||||
win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid);
|
win_insert_last_read_position_marker((ProfWin*)mucwin, mucwin->roomjid);
|
||||||
|
wins_add_urls_ac(window, message);
|
||||||
|
|
||||||
if (g_slist_length(mentions) > 0) {
|
if (g_slist_length(mentions) > 0) {
|
||||||
_mucwin_print_mention(window, message->plain, message->from_jid->resourcepart, mynick, mentions, ch, flags);
|
_mucwin_print_mention(window, message->plain, message->from_jid->resourcepart, mynick, mentions, ch, flags);
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, ProfMessage *message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wins_add_urls_ac(window, message);
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_BEEP)) {
|
if (prefs_get_boolean(PREF_BEEP)) {
|
||||||
beep();
|
beep();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ typedef enum {
|
|||||||
typedef struct prof_win_t {
|
typedef struct prof_win_t {
|
||||||
win_type_t type;
|
win_type_t type;
|
||||||
ProfLayout *layout;
|
ProfLayout *layout;
|
||||||
|
Autocomplete urls_ac;
|
||||||
} ProfWin;
|
} ProfWin;
|
||||||
|
|
||||||
typedef struct prof_console_win_t {
|
typedef struct prof_console_win_t {
|
||||||
|
|||||||
@@ -534,7 +534,7 @@ wins_close_by_num(int i)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
autocomplete_free(window->urls_ac);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
@@ -546,6 +546,7 @@ wins_close_by_num(int i)
|
|||||||
if (mucwin->last_msg_timestamp) {
|
if (mucwin->last_msg_timestamp) {
|
||||||
g_date_time_unref(mucwin->last_msg_timestamp);
|
g_date_time_unref(mucwin->last_msg_timestamp);
|
||||||
}
|
}
|
||||||
|
autocomplete_free(window->urls_ac);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WIN_PRIVATE:
|
case WIN_PRIVATE:
|
||||||
@@ -553,6 +554,7 @@ wins_close_by_num(int i)
|
|||||||
ProfPrivateWin *privwin = (ProfPrivateWin*)window;
|
ProfPrivateWin *privwin = (ProfPrivateWin*)window;
|
||||||
autocomplete_remove(wins_ac, privwin->fulljid);
|
autocomplete_remove(wins_ac, privwin->fulljid);
|
||||||
autocomplete_remove(wins_close_ac, privwin->fulljid);
|
autocomplete_remove(wins_close_ac, privwin->fulljid);
|
||||||
|
autocomplete_free(window->urls_ac);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WIN_XML:
|
case WIN_XML:
|
||||||
@@ -624,6 +626,7 @@ wins_new_chat(const char *const barejid)
|
|||||||
autocomplete_add(wins_close_ac, nick);
|
autocomplete_add(wins_close_ac, nick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
newwin->urls_ac = autocomplete_new();
|
||||||
|
|
||||||
return newwin;
|
return newwin;
|
||||||
}
|
}
|
||||||
@@ -638,6 +641,8 @@ wins_new_muc(const char *const roomjid)
|
|||||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||||
autocomplete_add(wins_ac, roomjid);
|
autocomplete_add(wins_ac, roomjid);
|
||||||
autocomplete_add(wins_close_ac, roomjid);
|
autocomplete_add(wins_close_ac, roomjid);
|
||||||
|
newwin->urls_ac = autocomplete_new();
|
||||||
|
|
||||||
return newwin;
|
return newwin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -649,6 +654,7 @@ wins_new_config(const char *const roomjid, DataForm *form, ProfConfWinCallback s
|
|||||||
g_list_free(keys);
|
g_list_free(keys);
|
||||||
ProfWin *newwin = win_create_config(roomjid, form, submit, cancel, userdata);
|
ProfWin *newwin = win_create_config(roomjid, form, submit, cancel, userdata);
|
||||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||||
|
|
||||||
return newwin;
|
return newwin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,6 +668,8 @@ wins_new_private(const char *const fulljid)
|
|||||||
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
||||||
autocomplete_add(wins_ac, fulljid);
|
autocomplete_add(wins_ac, fulljid);
|
||||||
autocomplete_add(wins_close_ac, fulljid);
|
autocomplete_add(wins_close_ac, fulljid);
|
||||||
|
newwin->urls_ac = autocomplete_new();
|
||||||
|
|
||||||
return newwin;
|
return newwin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1141,3 +1149,34 @@ wins_get_next_unread(void)
|
|||||||
g_list_free(values);
|
g_list_free(values);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wins_add_urls_ac(const ProfWin *const win, const ProfMessage *const message)
|
||||||
|
{
|
||||||
|
GRegex *regex;
|
||||||
|
GMatchInfo *match_info;
|
||||||
|
|
||||||
|
regex = g_regex_new("https?://\\S+", 0, 0, NULL);
|
||||||
|
g_regex_match (regex, message->plain, 0, &match_info);
|
||||||
|
|
||||||
|
while (g_match_info_matches (match_info))
|
||||||
|
{
|
||||||
|
gchar *word = g_match_info_fetch (match_info, 0);
|
||||||
|
|
||||||
|
autocomplete_add(win->urls_ac, word);
|
||||||
|
|
||||||
|
g_free (word);
|
||||||
|
g_match_info_next (match_info, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_match_info_free (match_info);
|
||||||
|
g_regex_unref (regex);
|
||||||
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
wins_get_url(const char *const search_str, gboolean previous, void *context)
|
||||||
|
{
|
||||||
|
ProfWin *win = (ProfWin*)context;
|
||||||
|
|
||||||
|
return autocomplete_complete(win->urls_ac, search_str, FALSE, previous);
|
||||||
|
}
|
||||||
|
|||||||
@@ -98,4 +98,7 @@ void win_reset_search_attempts(void);
|
|||||||
char* win_close_autocomplete(const char *const search_str, gboolean previous, void *context);
|
char* win_close_autocomplete(const char *const search_str, gboolean previous, void *context);
|
||||||
void win_close_reset_search_attempts(void);
|
void win_close_reset_search_attempts(void);
|
||||||
|
|
||||||
|
void wins_add_urls_ac(const ProfWin *const win, const ProfMessage *const message);
|
||||||
|
char* wins_get_url(const char *const search_str, gboolean previous, void *context);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user