2013-08-20 18:08:21 -04:00
|
|
|
/*
|
2015-06-15 14:26:28 -04:00
|
|
|
* window_list.c
|
2019-11-13 06:11:05 -05:00
|
|
|
* vim: expandtab:ts=4:sts=4:sw=4
|
2013-08-20 18:08:21 -04:00
|
|
|
*
|
2019-01-22 05:31:45 -05:00
|
|
|
* Copyright (C) 2012 - 2019 James Booth <boothj5@gmail.com>
|
2022-05-09 09:43:33 -04:00
|
|
|
* Copyright (C) 2019 - 2022 Michael Vetter <jubalh@iodoru.org>
|
2013-08-20 18:08:21 -04:00
|
|
|
*
|
|
|
|
* This file is part of Profanity.
|
|
|
|
*
|
|
|
|
* Profanity is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Profanity is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-07-23 20:14:49 -04:00
|
|
|
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
|
2013-08-20 18:08:21 -04:00
|
|
|
*
|
2014-08-24 15:57:39 -04:00
|
|
|
* In addition, as a special exception, the copyright holders give permission to
|
|
|
|
* link the code of portions of this program with the OpenSSL library under
|
|
|
|
* certain conditions as described in each individual source file, and
|
|
|
|
* distribute linked combinations including the two.
|
|
|
|
*
|
|
|
|
* You must obey the GNU General Public License in all respects for all of the
|
|
|
|
* code used other than OpenSSL. If you modify file(s) with this exception, you
|
|
|
|
* may extend this exception to your version of the file(s), but you are not
|
|
|
|
* obligated to do so. If you do not wish to do so, delete this exception
|
|
|
|
* statement from your version. If you delete this exception statement from all
|
|
|
|
* source files in the program, then also delete it here.
|
|
|
|
*
|
2013-08-20 18:08:21 -04:00
|
|
|
*/
|
|
|
|
|
2016-03-31 16:05:02 -04:00
|
|
|
#include "config.h"
|
2013-08-20 18:08:21 -04:00
|
|
|
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <string.h>
|
2014-12-18 18:57:19 -05:00
|
|
|
#include <assert.h>
|
2014-12-21 17:01:56 -05:00
|
|
|
#include <stdlib.h>
|
2013-08-20 18:08:21 -04:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2013-08-27 17:02:23 -04:00
|
|
|
#include "common.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "config/preferences.h"
|
2013-08-20 18:08:21 -04:00
|
|
|
#include "config/theme.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "plugins/plugins.h"
|
2013-08-20 18:08:21 -04:00
|
|
|
#include "ui/ui.h"
|
2016-07-24 10:43:51 -04:00
|
|
|
#include "ui/window_list.h"
|
2020-04-17 04:05:09 -04:00
|
|
|
#include "xmpp/xmpp.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "xmpp/roster_list.h"
|
|
|
|
#include "tools/http_upload.h"
|
2013-08-20 18:08:21 -04:00
|
|
|
|
2021-06-01 13:13:20 -04:00
|
|
|
#ifdef HAVE_OMEMO
|
|
|
|
#include "omemo/omemo.h"
|
|
|
|
#endif
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
static GHashTable* windows;
|
2013-08-20 18:08:21 -04:00
|
|
|
static int current;
|
2016-01-06 19:38:17 -05:00
|
|
|
static Autocomplete wins_ac;
|
2016-01-13 18:19:11 -05:00
|
|
|
static Autocomplete wins_close_ac;
|
2013-08-20 18:08:21 -04:00
|
|
|
|
2016-07-24 12:02:09 -04:00
|
|
|
static int _wins_cmp_num(gconstpointer a, gconstpointer b);
|
2020-07-07 08:18:57 -04:00
|
|
|
static int _wins_get_next_available_num(GList* used);
|
2016-07-24 12:02:09 -04:00
|
|
|
|
2013-08-20 18:08:21 -04:00
|
|
|
void
|
|
|
|
wins_init(void)
|
|
|
|
{
|
2016-07-24 19:57:42 -04:00
|
|
|
windows = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)win_free);
|
2013-08-20 18:08:21 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* console = win_create_console();
|
2013-08-27 18:38:25 -04:00
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(1), console);
|
2013-08-20 18:08:21 -04:00
|
|
|
|
2013-08-27 18:38:25 -04:00
|
|
|
current = 1;
|
2016-01-06 19:38:17 -05:00
|
|
|
|
|
|
|
wins_ac = autocomplete_new();
|
|
|
|
autocomplete_add(wins_ac, "console");
|
2016-01-13 18:19:11 -05:00
|
|
|
|
|
|
|
wins_close_ac = autocomplete_new();
|
|
|
|
autocomplete_add(wins_close_ac, "all");
|
|
|
|
autocomplete_add(wins_close_ac, "read");
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2013-08-20 18:08:21 -04:00
|
|
|
wins_get_console(void)
|
|
|
|
{
|
2013-08-27 18:38:25 -04:00
|
|
|
return g_hash_table_lookup(windows, GINT_TO_POINTER(1));
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2015-10-26 18:43:32 -04:00
|
|
|
gboolean
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_chat_exists(const char* const barejid)
|
2015-10-26 18:43:32 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2015-10-26 18:43:32 -04:00
|
|
|
return (chatwin != NULL);
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfChatWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_get_chat(const char* const barejid)
|
2014-12-18 18:57:19 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2014-12-18 18:57:19 -05:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2014-12-18 18:57:19 -05:00
|
|
|
if (window->type == WIN_CHAT) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
2014-12-18 18:57:19 -05:00
|
|
|
if (g_strcmp0(chatwin->barejid, barejid) == 0) {
|
|
|
|
g_list_free(values);
|
|
|
|
return chatwin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(values);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-06 19:49:48 -05:00
|
|
|
static gint
|
2020-07-07 08:18:57 -04:00
|
|
|
_cmp_unsubscribed_wins(ProfChatWin* a, ProfChatWin* b)
|
2016-02-06 19:49:48 -05:00
|
|
|
{
|
|
|
|
return g_strcmp0(a->barejid, b->barejid);
|
|
|
|
}
|
|
|
|
|
|
|
|
GList*
|
|
|
|
wins_get_chat_unsubscribed(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* result = NULL;
|
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2016-02-06 19:49:48 -05:00
|
|
|
|
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2016-02-06 19:49:48 -05:00
|
|
|
if (window->type == WIN_CHAT) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
2016-02-06 19:49:48 -05:00
|
|
|
PContact contact = roster_get_contact(chatwin->barejid);
|
|
|
|
if (contact == NULL) {
|
|
|
|
result = g_list_insert_sorted(result, chatwin, (GCompareFunc)_cmp_unsubscribed_wins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(values);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-04-11 12:57:50 -04:00
|
|
|
ProfConfWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_get_conf(const char* const roomjid)
|
2014-12-18 18:57:19 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2014-12-18 18:57:19 -05:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2018-04-11 12:57:50 -04:00
|
|
|
if (window->type == WIN_CONFIG) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfConfWin* confwin = (ProfConfWin*)window;
|
2014-12-21 17:01:56 -05:00
|
|
|
if (g_strcmp0(confwin->roomjid, roomjid) == 0) {
|
2014-12-18 18:57:19 -05:00
|
|
|
g_list_free(values);
|
|
|
|
return confwin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(values);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfMucWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_get_muc(const char* const roomjid)
|
2014-12-18 18:57:19 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2014-12-18 18:57:19 -05:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2014-12-19 19:52:35 -05:00
|
|
|
if (window->type == WIN_MUC) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = (ProfMucWin*)window;
|
2014-12-19 19:52:35 -05:00
|
|
|
if (g_strcmp0(mucwin->roomjid, roomjid) == 0) {
|
2015-02-09 17:08:47 -05:00
|
|
|
g_list_free(values);
|
2014-12-19 19:52:35 -05:00
|
|
|
return mucwin;
|
|
|
|
}
|
2014-12-18 18:57:19 -05:00
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(values);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfPrivateWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_get_private(const char* const fulljid)
|
2014-12-18 18:57:19 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2014-12-18 18:57:19 -05:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2014-12-18 18:57:19 -05:00
|
|
|
if (window->type == WIN_PRIVATE) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
|
2014-12-18 18:57:19 -05:00
|
|
|
if (g_strcmp0(privatewin->fulljid, fulljid) == 0) {
|
2015-02-09 17:08:47 -05:00
|
|
|
g_list_free(values);
|
2014-12-18 18:57:19 -05:00
|
|
|
return privatewin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(values);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-14 17:28:55 -05:00
|
|
|
ProfPluginWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_get_plugin(const char* const tag)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2016-02-14 17:28:55 -05:00
|
|
|
|
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2016-02-14 17:28:55 -05:00
|
|
|
if (window->type == WIN_PLUGIN) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPluginWin* pluginwin = (ProfPluginWin*)window;
|
2016-02-14 17:28:55 -05:00
|
|
|
if (g_strcmp0(pluginwin->tag, tag) == 0) {
|
2016-03-07 13:30:13 -05:00
|
|
|
g_list_free(values);
|
2016-02-14 17:28:55 -05:00
|
|
|
return pluginwin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(values);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-05 17:46:00 -04:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_close_plugin(char* tag)
|
2016-07-05 17:46:00 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* toclose = wins_get_by_string(tag);
|
2016-07-11 20:51:27 -04:00
|
|
|
if (toclose == NULL) {
|
|
|
|
return;
|
2016-07-05 17:46:00 -04:00
|
|
|
}
|
|
|
|
|
2016-07-11 20:51:27 -04:00
|
|
|
int index = wins_get_num(toclose);
|
|
|
|
ui_close_win(index);
|
|
|
|
|
2018-03-09 17:42:20 -05:00
|
|
|
wins_tidy();
|
2016-07-05 17:46:00 -04:00
|
|
|
}
|
|
|
|
|
2016-01-23 19:33:24 -05:00
|
|
|
GList*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_get_private_chats(const char* const roomjid)
|
2016-01-23 19:33:24 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* result = NULL;
|
|
|
|
GString* prefix = g_string_new(roomjid);
|
2016-01-23 19:33:24 -05:00
|
|
|
g_string_append(prefix, "/");
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2016-01-23 19:33:24 -05:00
|
|
|
|
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2016-01-23 19:33:24 -05:00
|
|
|
if (window->type == WIN_PRIVATE) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
|
2016-01-23 20:30:02 -05:00
|
|
|
if (roomjid == NULL || g_str_has_prefix(privatewin->fulljid, prefix->str)) {
|
2016-01-23 19:33:24 -05:00
|
|
|
result = g_list_append(result, privatewin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(values);
|
|
|
|
g_string_free(prefix, TRUE);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-02 18:25:26 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_private_nick_change(const char* const roomjid, const char* const oldnick, const char* const newnick)
|
2016-02-02 18:25:26 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
Jid* oldjid = jid_create_from_bare_and_resource(roomjid, oldnick);
|
2016-02-02 18:25:26 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPrivateWin* privwin = wins_get_private(oldjid->fulljid);
|
2016-02-02 18:25:26 -05:00
|
|
|
if (privwin) {
|
|
|
|
free(privwin->fulljid);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
Jid* newjid = jid_create_from_bare_and_resource(roomjid, newnick);
|
2016-02-02 18:25:26 -05:00
|
|
|
privwin->fulljid = strdup(newjid->fulljid);
|
2020-02-20 12:11:08 -05:00
|
|
|
win_println((ProfWin*)privwin, THEME_THEM, "!", "** %s is now known as %s.", oldjid->resourcepart, newjid->resourcepart);
|
2016-02-02 18:25:26 -05:00
|
|
|
|
|
|
|
autocomplete_remove(wins_ac, oldjid->fulljid);
|
|
|
|
autocomplete_remove(wins_close_ac, oldjid->fulljid);
|
|
|
|
autocomplete_add(wins_ac, newjid->fulljid);
|
|
|
|
autocomplete_add(wins_close_ac, newjid->fulljid);
|
|
|
|
|
|
|
|
jid_destroy(newjid);
|
|
|
|
}
|
|
|
|
|
|
|
|
jid_destroy(oldjid);
|
|
|
|
}
|
|
|
|
|
2016-02-03 17:19:29 -05:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_change_nick(const char* const barejid, const char* const oldnick, const char* const newnick)
|
2016-02-03 17:19:29 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2016-02-03 17:19:29 -05:00
|
|
|
if (chatwin) {
|
|
|
|
if (oldnick) {
|
|
|
|
autocomplete_remove(wins_ac, oldnick);
|
|
|
|
autocomplete_remove(wins_close_ac, oldnick);
|
|
|
|
}
|
|
|
|
autocomplete_add(wins_ac, newnick);
|
|
|
|
autocomplete_add(wins_close_ac, newnick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_remove_nick(const char* const barejid, const char* const oldnick)
|
2016-02-03 17:19:29 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2016-02-03 17:19:29 -05:00
|
|
|
if (chatwin) {
|
|
|
|
if (oldnick) {
|
|
|
|
autocomplete_remove(wins_ac, oldnick);
|
|
|
|
autocomplete_remove(wins_close_ac, oldnick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2013-08-20 18:08:21 -04:00
|
|
|
wins_get_current(void)
|
|
|
|
{
|
2015-05-04 18:12:55 -04:00
|
|
|
if (windows) {
|
2014-09-16 17:23:59 -04:00
|
|
|
return g_hash_table_lookup(windows, GINT_TO_POINTER(current));
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
GList*
|
2013-08-29 19:33:46 -04:00
|
|
|
wins_get_nums(void)
|
|
|
|
{
|
|
|
|
return g_hash_table_get_keys(windows);
|
|
|
|
}
|
|
|
|
|
2013-08-20 18:08:21 -04:00
|
|
|
void
|
|
|
|
wins_set_current_by_num(int i)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = g_hash_table_lookup(windows, GINT_TO_POINTER(i));
|
2014-12-21 18:14:01 -05:00
|
|
|
if (window) {
|
2013-08-20 18:08:21 -04:00
|
|
|
current = i;
|
2014-12-21 18:14:01 -05:00
|
|
|
if (window->type == WIN_CHAT) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
2014-12-21 18:14:01 -05:00
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
|
|
|
chatwin->unread = 0;
|
2016-04-07 17:06:14 -04:00
|
|
|
plugins_on_chat_win_focus(chatwin->barejid);
|
2014-12-21 18:14:01 -05:00
|
|
|
} else if (window->type == WIN_MUC) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = (ProfMucWin*)window;
|
2014-12-21 18:14:01 -05:00
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
|
|
|
mucwin->unread = 0;
|
2016-01-24 19:19:26 -05:00
|
|
|
mucwin->unread_mentions = FALSE;
|
|
|
|
mucwin->unread_triggers = FALSE;
|
2016-04-07 17:15:03 -04:00
|
|
|
plugins_on_room_win_focus(mucwin->roomjid);
|
2014-12-21 18:14:01 -05:00
|
|
|
} else if (window->type == WIN_PRIVATE) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
|
2014-12-21 18:14:01 -05:00
|
|
|
privatewin->unread = 0;
|
|
|
|
}
|
2020-07-09 09:44:35 -04:00
|
|
|
|
|
|
|
// if we switched to console
|
|
|
|
if (current == 0) {
|
|
|
|
// remove all alerts
|
|
|
|
cons_clear_alerts();
|
|
|
|
} else {
|
|
|
|
// remove alert from window where we switch to
|
|
|
|
cons_remove_alert(window);
|
|
|
|
// if there a no more alerts left
|
|
|
|
if (!cons_has_alerts()) {
|
|
|
|
// dont highlight console (no news there)
|
|
|
|
ProfWin* conswin = wins_get_console();
|
|
|
|
status_bar_active(1, conswin->type, "console");
|
|
|
|
}
|
|
|
|
}
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2013-08-20 18:08:21 -04:00
|
|
|
wins_get_by_num(int i)
|
|
|
|
{
|
2013-08-27 18:38:25 -04:00
|
|
|
return g_hash_table_lookup(windows, GINT_TO_POINTER(i));
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2016-01-06 19:38:17 -05:00
|
|
|
ProfWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_get_by_string(const char* str)
|
2016-01-06 19:38:17 -05:00
|
|
|
{
|
|
|
|
if (g_strcmp0(str, "console") == 0) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* conswin = wins_get_console();
|
2019-11-01 12:35:17 -04:00
|
|
|
return conswin;
|
2016-01-06 19:38:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_strcmp0(str, "xmlconsole") == 0) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfXMLWin* xmlwin = wins_get_xmlconsole();
|
|
|
|
return (ProfWin*)xmlwin;
|
2016-01-06 19:38:17 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(str);
|
2016-01-06 19:38:17 -05:00
|
|
|
if (chatwin) {
|
|
|
|
return (ProfWin*)chatwin;
|
|
|
|
}
|
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
jabber_conn_status_t conn_status = connection_get_status();
|
2016-01-06 19:38:17 -05:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
2020-07-07 08:18:57 -04:00
|
|
|
char* barejid = roster_barejid_from_name(str);
|
2016-01-06 19:38:17 -05:00
|
|
|
if (barejid) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = wins_get_chat(barejid);
|
2016-01-06 19:38:17 -05:00
|
|
|
if (chatwin) {
|
|
|
|
return (ProfWin*)chatwin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = wins_get_muc(str);
|
2016-01-06 19:38:17 -05:00
|
|
|
if (mucwin) {
|
|
|
|
return (ProfWin*)mucwin;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPrivateWin* privwin = wins_get_private(str);
|
2016-01-06 19:38:17 -05:00
|
|
|
if (privwin) {
|
|
|
|
return (ProfWin*)privwin;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPluginWin* pluginwin = wins_get_plugin(str);
|
2016-02-29 19:03:11 -05:00
|
|
|
if (pluginwin) {
|
|
|
|
return (ProfWin*)pluginwin;
|
|
|
|
}
|
|
|
|
|
2016-01-06 19:38:17 -05:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2013-09-25 19:25:04 -04:00
|
|
|
wins_get_next(void)
|
|
|
|
{
|
|
|
|
// get and sort win nums
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
keys = g_list_sort(keys, _wins_cmp_num);
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* curr = keys;
|
2013-09-25 19:25:04 -04:00
|
|
|
|
|
|
|
// find our place in the list
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2013-09-25 19:25:04 -04:00
|
|
|
if (current == GPOINTER_TO_INT(curr->data)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is a next window return it
|
|
|
|
curr = g_list_next(curr);
|
2015-05-04 18:12:55 -04:00
|
|
|
if (curr) {
|
2014-07-07 16:29:51 -04:00
|
|
|
int next = GPOINTER_TO_INT(curr->data);
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(keys);
|
2014-07-07 16:29:51 -04:00
|
|
|
return wins_get_by_num(next);
|
2020-07-07 08:18:57 -04:00
|
|
|
// otherwise return the first window (console)
|
2013-09-25 19:25:04 -04:00
|
|
|
} else {
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(keys);
|
2013-09-25 19:25:04 -04:00
|
|
|
return wins_get_console();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2013-09-25 19:25:04 -04:00
|
|
|
wins_get_previous(void)
|
|
|
|
{
|
|
|
|
// get and sort win nums
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
keys = g_list_sort(keys, _wins_cmp_num);
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* curr = keys;
|
2013-09-25 19:25:04 -04:00
|
|
|
|
|
|
|
// find our place in the list
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2013-09-25 19:25:04 -04:00
|
|
|
if (current == GPOINTER_TO_INT(curr->data)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is a previous window return it
|
|
|
|
curr = g_list_previous(curr);
|
2015-05-04 18:12:55 -04:00
|
|
|
if (curr) {
|
2014-07-07 16:29:51 -04:00
|
|
|
int previous = GPOINTER_TO_INT(curr->data);
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(keys);
|
2014-07-07 16:29:51 -04:00
|
|
|
return wins_get_by_num(previous);
|
2020-07-07 08:18:57 -04:00
|
|
|
// otherwise return the last window
|
2013-09-25 19:25:04 -04:00
|
|
|
} else {
|
|
|
|
int new_num = GPOINTER_TO_INT(g_list_last(keys)->data);
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(keys);
|
2013-09-25 19:25:04 -04:00
|
|
|
return wins_get_by_num(new_num);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-20 18:08:21 -04:00
|
|
|
int
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_get_num(ProfWin* window)
|
2013-08-20 18:08:21 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
|
|
|
GList* curr = keys;
|
2013-08-27 18:38:25 -04:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2013-08-27 18:38:25 -04:00
|
|
|
gconstpointer num_p = curr->data;
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* curr_win = g_hash_table_lookup(windows, num_p);
|
2014-12-19 19:52:35 -05:00
|
|
|
if (curr_win == window) {
|
2014-06-15 16:36:47 -04:00
|
|
|
g_list_free(keys);
|
2013-08-27 18:38:25 -04:00
|
|
|
return GPOINTER_TO_INT(num_p);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
2013-08-27 18:38:25 -04:00
|
|
|
curr = g_list_next(curr);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2014-06-15 16:36:47 -04:00
|
|
|
g_list_free(keys);
|
2013-08-27 18:38:25 -04:00
|
|
|
return -1;
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
wins_get_current_num(void)
|
|
|
|
{
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wins_close_by_num(int i)
|
|
|
|
{
|
2014-04-06 16:06:50 -04:00
|
|
|
// console cannot be closed
|
2013-08-27 18:38:25 -04:00
|
|
|
if (i != 1) {
|
2014-04-06 16:06:50 -04:00
|
|
|
|
|
|
|
// go to console if closing current window
|
2013-08-20 18:08:21 -04:00
|
|
|
if (i == current) {
|
2013-08-27 18:38:25 -04:00
|
|
|
current = 1;
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = wins_get_current();
|
2014-04-06 16:06:50 -04:00
|
|
|
win_update_virtual(window);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
2014-04-06 16:06:50 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = wins_get_by_num(i);
|
2016-01-06 19:38:17 -05:00
|
|
|
if (window) {
|
2020-12-10 03:24:32 -05:00
|
|
|
// cancel upload processes of this window
|
2020-04-17 04:05:09 -04:00
|
|
|
http_upload_cancel_processes(window);
|
2016-04-11 14:13:18 -04:00
|
|
|
|
2016-01-06 19:38:17 -05:00
|
|
|
switch (window->type) {
|
|
|
|
case WIN_CHAT:
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
2016-01-06 19:38:17 -05:00
|
|
|
autocomplete_remove(wins_ac, chatwin->barejid);
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_remove(wins_close_ac, chatwin->barejid);
|
2016-01-06 19:38:17 -05:00
|
|
|
|
2016-05-05 18:51:49 -04:00
|
|
|
jabber_conn_status_t conn_status = connection_get_status();
|
2016-01-06 19:38:17 -05:00
|
|
|
if (conn_status == JABBER_CONNECTED) {
|
|
|
|
PContact contact = roster_get_contact(chatwin->barejid);
|
|
|
|
if (contact) {
|
|
|
|
const char* nick = p_contact_name(contact);
|
|
|
|
if (nick) {
|
|
|
|
autocomplete_remove(wins_ac, nick);
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_remove(wins_close_ac, nick);
|
2016-01-06 19:38:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-20 03:48:42 -04:00
|
|
|
autocomplete_free(window->urls_ac);
|
2022-03-20 18:10:07 -04:00
|
|
|
autocomplete_free(window->quotes_ac);
|
2016-01-06 19:38:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WIN_MUC:
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfMucWin* mucwin = (ProfMucWin*)window;
|
2016-01-06 19:38:17 -05:00
|
|
|
autocomplete_remove(wins_ac, mucwin->roomjid);
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_remove(wins_close_ac, mucwin->roomjid);
|
2019-06-19 06:30:57 -04:00
|
|
|
|
|
|
|
if (mucwin->last_msg_timestamp) {
|
|
|
|
g_date_time_unref(mucwin->last_msg_timestamp);
|
|
|
|
}
|
2020-05-20 03:48:42 -04:00
|
|
|
autocomplete_free(window->urls_ac);
|
2022-03-20 18:10:07 -04:00
|
|
|
autocomplete_free(window->quotes_ac);
|
2016-01-06 19:38:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WIN_PRIVATE:
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPrivateWin* privwin = (ProfPrivateWin*)window;
|
2016-01-06 19:38:17 -05:00
|
|
|
autocomplete_remove(wins_ac, privwin->fulljid);
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_remove(wins_close_ac, privwin->fulljid);
|
2020-05-20 03:48:42 -04:00
|
|
|
autocomplete_free(window->urls_ac);
|
2022-03-20 18:10:07 -04:00
|
|
|
autocomplete_free(window->quotes_ac);
|
2016-01-06 19:38:17 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case WIN_XML:
|
|
|
|
{
|
|
|
|
autocomplete_remove(wins_ac, "xmlconsole");
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_remove(wins_close_ac, "xmlconsole");
|
2016-01-06 19:38:17 -05:00
|
|
|
break;
|
|
|
|
}
|
2016-02-29 19:03:11 -05:00
|
|
|
case WIN_PLUGIN:
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfPluginWin* pluginwin = (ProfPluginWin*)window;
|
2016-07-11 21:16:12 -04:00
|
|
|
plugins_close_win(pluginwin->plugin_name, pluginwin->tag);
|
2016-02-29 19:03:11 -05:00
|
|
|
autocomplete_remove(wins_ac, pluginwin->tag);
|
|
|
|
autocomplete_remove(wins_close_ac, pluginwin->tag);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-11 12:57:50 -04:00
|
|
|
case WIN_CONFIG:
|
2016-01-06 19:38:17 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-27 18:38:25 -04:00
|
|
|
g_hash_table_remove(windows, GINT_TO_POINTER(i));
|
2013-08-29 19:21:41 -04:00
|
|
|
status_bar_inactive(i);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_is_current(ProfWin* window)
|
2013-08-20 18:08:21 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current_window = wins_get_current();
|
2013-08-27 18:38:25 -04:00
|
|
|
|
2014-12-19 19:52:35 -05:00
|
|
|
if (current_window == window) {
|
2013-08-20 18:08:21 -04:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2014-12-14 19:28:28 -05:00
|
|
|
wins_new_xmlconsole(void)
|
2013-08-20 18:08:21 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
int result = _wins_get_next_available_num(keys);
|
2015-02-09 16:53:55 -05:00
|
|
|
g_list_free(keys);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* newwin = win_create_xmlconsole();
|
2014-12-19 19:52:35 -05:00
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
2016-01-06 19:38:17 -05:00
|
|
|
autocomplete_add(wins_ac, "xmlconsole");
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_add(wins_close_ac, "xmlconsole");
|
2014-12-19 19:52:35 -05:00
|
|
|
return newwin;
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_new_chat(const char* const barejid)
|
2014-12-10 17:34:33 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
int result = _wins_get_next_available_num(keys);
|
2015-02-09 16:53:55 -05:00
|
|
|
g_list_free(keys);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* newwin = win_create_chat(barejid);
|
2014-12-19 19:52:35 -05:00
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
2016-01-06 19:38:17 -05:00
|
|
|
|
|
|
|
autocomplete_add(wins_ac, barejid);
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_add(wins_close_ac, barejid);
|
2016-01-06 19:38:17 -05:00
|
|
|
PContact contact = roster_get_contact(barejid);
|
|
|
|
if (contact) {
|
|
|
|
const char* nick = p_contact_name(contact);
|
|
|
|
if (nick) {
|
|
|
|
autocomplete_add(wins_ac, nick);
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_add(wins_close_ac, nick);
|
2016-01-06 19:38:17 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-20 03:48:42 -04:00
|
|
|
newwin->urls_ac = autocomplete_new();
|
2022-03-20 18:10:07 -04:00
|
|
|
newwin->quotes_ac = autocomplete_new();
|
2016-01-06 19:38:17 -05:00
|
|
|
|
2014-12-19 19:52:35 -05:00
|
|
|
return newwin;
|
2014-12-10 17:34:33 -05:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_new_muc(const char* const roomjid)
|
2014-12-14 19:28:28 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
int result = _wins_get_next_available_num(keys);
|
2015-02-09 16:53:55 -05:00
|
|
|
g_list_free(keys);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* newwin = win_create_muc(roomjid);
|
2014-12-19 19:52:35 -05:00
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
2016-01-06 19:38:17 -05:00
|
|
|
autocomplete_add(wins_ac, roomjid);
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_add(wins_close_ac, roomjid);
|
2020-05-20 03:48:42 -04:00
|
|
|
newwin->urls_ac = autocomplete_new();
|
2022-03-20 18:10:07 -04:00
|
|
|
newwin->quotes_ac = autocomplete_new();
|
2020-05-20 03:48:42 -04:00
|
|
|
|
2014-12-19 19:52:35 -05:00
|
|
|
return newwin;
|
2014-12-14 19:28:28 -05:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_new_config(const char* const roomjid, DataForm* form, ProfConfWinCallback submit, ProfConfWinCallback cancel, const void* userdata)
|
2014-12-14 19:28:28 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
int result = _wins_get_next_available_num(keys);
|
2015-02-09 16:53:55 -05:00
|
|
|
g_list_free(keys);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* newwin = win_create_config(roomjid, form, submit, cancel, userdata);
|
2014-12-19 19:52:35 -05:00
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
2020-05-20 03:48:42 -04:00
|
|
|
|
2014-12-19 19:52:35 -05:00
|
|
|
return newwin;
|
2014-12-14 19:28:28 -05:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfWin*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_new_private(const char* const fulljid)
|
2014-12-10 17:34:33 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
int result = _wins_get_next_available_num(keys);
|
2015-02-09 16:53:55 -05:00
|
|
|
g_list_free(keys);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* newwin = win_create_private(fulljid);
|
2014-12-19 19:52:35 -05:00
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
2016-01-06 19:38:17 -05:00
|
|
|
autocomplete_add(wins_ac, fulljid);
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_add(wins_close_ac, fulljid);
|
2020-05-20 03:48:42 -04:00
|
|
|
newwin->urls_ac = autocomplete_new();
|
2022-03-20 18:10:07 -04:00
|
|
|
newwin->quotes_ac = autocomplete_new();
|
2020-05-20 03:48:42 -04:00
|
|
|
|
2014-12-19 19:52:35 -05:00
|
|
|
return newwin;
|
2014-12-10 17:34:33 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin*
|
|
|
|
wins_new_plugin(const char* const plugin_name, const char* const tag)
|
2016-02-14 17:28:55 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
int result = _wins_get_next_available_num(keys);
|
2016-02-14 17:28:55 -05:00
|
|
|
g_list_free(keys);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* newwin = win_create_plugin(plugin_name, tag);
|
2016-02-29 19:03:11 -05:00
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
|
|
|
|
autocomplete_add(wins_ac, tag);
|
|
|
|
autocomplete_add(wins_close_ac, tag);
|
|
|
|
return newwin;
|
2016-02-14 17:28:55 -05:00
|
|
|
}
|
|
|
|
|
2015-11-25 17:08:33 -05:00
|
|
|
gboolean
|
2016-02-03 19:21:38 -05:00
|
|
|
wins_do_notify_remind(void)
|
2015-11-25 17:08:33 -05:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2015-11-25 17:08:33 -05:00
|
|
|
|
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2016-02-06 20:15:40 -05:00
|
|
|
if (win_notify_remind(window)) {
|
2015-11-25 17:08:33 -05:00
|
|
|
g_list_free(values);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
2016-02-13 20:49:57 -05:00
|
|
|
g_list_free(values);
|
2015-11-25 17:08:33 -05:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-08-20 18:08:21 -04:00
|
|
|
int
|
|
|
|
wins_get_total_unread(void)
|
|
|
|
{
|
|
|
|
int result = 0;
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2013-08-27 18:38:25 -04:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2014-12-21 18:14:01 -05:00
|
|
|
result += win_unread(window);
|
2013-08-27 18:38:25 -04:00
|
|
|
curr = g_list_next(curr);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
2014-06-17 17:01:01 -04:00
|
|
|
g_list_free(values);
|
2013-08-20 18:08:21 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wins_resize_all(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2015-06-15 13:08:47 -04:00
|
|
|
win_resize(window);
|
2014-10-07 12:06:02 -04:00
|
|
|
curr = g_list_next(curr);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
2014-06-29 09:04:23 -04:00
|
|
|
g_list_free(values);
|
2013-08-20 18:08:21 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current_win = wins_get_current();
|
2014-11-15 17:59:13 -05:00
|
|
|
win_update_virtual(current_win);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2014-10-09 16:27:16 -04:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_hide_subwin(ProfWin* window)
|
2014-10-09 16:27:16 -04:00
|
|
|
{
|
|
|
|
win_hide_subwin(window);
|
2014-10-09 16:42:09 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current_win = wins_get_current();
|
2015-06-15 13:59:20 -04:00
|
|
|
win_refresh_without_subwin(current_win);
|
2014-10-09 16:27:16 -04:00
|
|
|
}
|
|
|
|
|
2014-10-09 16:42:09 -04:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_show_subwin(ProfWin* window)
|
2014-10-09 16:42:09 -04:00
|
|
|
{
|
|
|
|
win_show_subwin(window);
|
|
|
|
|
2020-04-22 08:03:29 -04:00
|
|
|
// only mucwin and console have occupants/roster subwin
|
2020-04-23 07:30:49 -04:00
|
|
|
if (window->type != WIN_MUC && window->type != WIN_CONSOLE) {
|
2020-04-22 08:03:29 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* current_win = wins_get_current();
|
2015-06-15 13:59:20 -04:00
|
|
|
win_refresh_with_subwin(current_win);
|
2014-10-09 16:42:09 -04:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
ProfXMLWin*
|
2014-04-15 08:16:32 -04:00
|
|
|
wins_get_xmlconsole(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2014-04-15 08:16:32 -04:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2014-06-17 18:14:54 -04:00
|
|
|
if (window->type == WIN_XML) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfXMLWin* xmlwin = (ProfXMLWin*)window;
|
2014-12-21 19:28:03 -05:00
|
|
|
assert(xmlwin->memcheck == PROFXMLWIN_MEMCHECK);
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(values);
|
2014-12-21 19:28:03 -05:00
|
|
|
return xmlwin;
|
2014-06-17 18:14:54 -04:00
|
|
|
}
|
2014-04-15 08:16:32 -04:00
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(values);
|
2014-04-15 08:16:32 -04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
GSList*
|
2013-08-20 18:08:21 -04:00
|
|
|
wins_get_chat_recipients(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GSList* result = NULL;
|
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2013-08-27 18:38:25 -04:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2013-08-27 18:38:25 -04:00
|
|
|
if (window->type == WIN_CHAT) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
2014-12-19 19:52:35 -05:00
|
|
|
result = g_slist_append(result, chatwin->barejid);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
2013-08-27 18:38:25 -04:00
|
|
|
curr = g_list_next(curr);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
2014-06-17 17:27:14 -04:00
|
|
|
g_list_free(values);
|
2013-08-20 18:08:21 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
GSList*
|
2014-12-19 19:52:35 -05:00
|
|
|
wins_get_prune_wins(void)
|
2013-08-20 18:08:21 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GSList* result = NULL;
|
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2013-08-27 18:38:25 -04:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
|
|
|
if (win_unread(window) == 0 && window->type != WIN_MUC && window->type != WIN_CONFIG && window->type != WIN_XML && window->type != WIN_CONSOLE) {
|
2014-12-19 19:52:35 -05:00
|
|
|
result = g_slist_append(result, window);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
2013-08-27 18:38:25 -04:00
|
|
|
curr = g_list_next(curr);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(values);
|
2013-08-20 18:08:21 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wins_lost_connection(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2013-08-27 18:38:25 -04:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2013-08-27 18:38:25 -04:00
|
|
|
if (window->type != WIN_CONSOLE) {
|
2020-02-20 12:11:08 -05:00
|
|
|
win_println(window, THEME_ERROR, "-", "Lost connection.");
|
2013-08-20 18:08:21 -04:00
|
|
|
|
|
|
|
// if current win, set current_win_dirty
|
|
|
|
if (wins_is_current(window)) {
|
2014-04-06 16:06:50 -04:00
|
|
|
win_update_virtual(window);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
}
|
2013-08-27 18:38:25 -04:00
|
|
|
curr = g_list_next(curr);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(values);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2019-06-05 03:33:10 -04:00
|
|
|
void
|
|
|
|
wins_reestablished_connection(void)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
GList* curr = values;
|
2019-06-05 03:33:10 -04:00
|
|
|
|
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = curr->data;
|
2019-06-05 03:33:10 -04:00
|
|
|
if (window->type != WIN_CONSOLE) {
|
2020-02-20 12:11:08 -05:00
|
|
|
win_println(window, THEME_TEXT, "-", "Connection re-established.");
|
2019-06-05 03:33:10 -04:00
|
|
|
|
2021-06-01 13:13:20 -04:00
|
|
|
#ifdef HAVE_OMEMO
|
|
|
|
if (window->type == WIN_CHAT) {
|
|
|
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
|
|
|
if (chatwin->is_omemo) {
|
2021-06-02 07:10:42 -04:00
|
|
|
win_println(window, THEME_TEXT, "-", "Restarted OMEMO session.");
|
2021-06-01 13:13:20 -04:00
|
|
|
omemo_start_session(chatwin->barejid);
|
|
|
|
}
|
|
|
|
} else if (window->type == WIN_MUC) {
|
|
|
|
ProfMucWin* mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
|
|
|
if (mucwin->is_omemo) {
|
2021-06-02 07:10:42 -04:00
|
|
|
win_println(window, THEME_TEXT, "-", "Restarted OMEMO session.");
|
2021-06-01 13:13:20 -04:00
|
|
|
omemo_start_muc_sessions(mucwin->roomjid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-06-05 03:33:10 -04:00
|
|
|
// if current win, set current_win_dirty
|
|
|
|
if (wins_is_current(window)) {
|
|
|
|
win_update_virtual(window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
g_list_free(values);
|
|
|
|
}
|
|
|
|
|
2018-03-09 17:59:38 -05:00
|
|
|
void
|
2014-04-24 16:50:59 -04:00
|
|
|
wins_swap(int source_win, int target_win)
|
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win));
|
|
|
|
ProfWin* console = wins_get_console();
|
2014-04-24 16:50:59 -04:00
|
|
|
|
2015-03-03 17:10:01 -05:00
|
|
|
if (source) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win));
|
2014-04-24 16:50:59 -04:00
|
|
|
|
2014-04-24 18:06:42 -04:00
|
|
|
// target window empty
|
2018-03-09 16:11:59 -05:00
|
|
|
if (target == NULL) {
|
2014-04-24 16:50:59 -04:00
|
|
|
g_hash_table_steal(windows, GINT_TO_POINTER(source_win));
|
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source);
|
2015-03-03 17:10:01 -05:00
|
|
|
status_bar_inactive(source_win);
|
2020-07-07 08:18:57 -04:00
|
|
|
char* identifier = win_get_tab_identifier(source);
|
2014-12-21 18:14:01 -05:00
|
|
|
if (win_unread(source) > 0) {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_new(target_win, source->type, identifier);
|
2014-04-24 16:50:59 -04:00
|
|
|
} else {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_active(target_win, source->type, identifier);
|
2014-04-24 16:50:59 -04:00
|
|
|
}
|
2018-03-09 16:11:59 -05:00
|
|
|
free(identifier);
|
2015-03-03 17:10:01 -05:00
|
|
|
if (wins_get_current_num() == source_win) {
|
|
|
|
wins_set_current_by_num(target_win);
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win(console);
|
2014-04-24 16:50:59 -04:00
|
|
|
}
|
2014-04-24 18:06:42 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
// target window occupied
|
2014-04-24 16:50:59 -04:00
|
|
|
} else {
|
2014-04-24 18:06:42 -04:00
|
|
|
g_hash_table_steal(windows, GINT_TO_POINTER(source_win));
|
|
|
|
g_hash_table_steal(windows, GINT_TO_POINTER(target_win));
|
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(source_win), target);
|
|
|
|
g_hash_table_insert(windows, GINT_TO_POINTER(target_win), source);
|
2020-07-07 08:18:57 -04:00
|
|
|
char* source_identifier = win_get_tab_identifier(source);
|
|
|
|
char* target_identifier = win_get_tab_identifier(target);
|
2014-12-21 18:14:01 -05:00
|
|
|
if (win_unread(source) > 0) {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_new(target_win, source->type, source_identifier);
|
2014-04-24 18:06:42 -04:00
|
|
|
} else {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_active(target_win, source->type, source_identifier);
|
2014-04-24 18:06:42 -04:00
|
|
|
}
|
2014-12-21 18:14:01 -05:00
|
|
|
if (win_unread(target) > 0) {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_new(source_win, target->type, target_identifier);
|
2014-04-24 18:06:42 -04:00
|
|
|
} else {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_active(source_win, target->type, target_identifier);
|
2014-04-24 18:06:42 -04:00
|
|
|
}
|
2018-03-09 16:11:59 -05:00
|
|
|
free(source_identifier);
|
|
|
|
free(target_identifier);
|
2014-04-24 18:06:42 -04:00
|
|
|
if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) {
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win(console);
|
2014-04-24 18:06:42 -04:00
|
|
|
}
|
2014-04-24 16:50:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-24 12:02:09 -04:00
|
|
|
static int
|
|
|
|
_wins_cmp_num(gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
int real_a = GPOINTER_TO_INT(a);
|
|
|
|
int real_b = GPOINTER_TO_INT(b);
|
|
|
|
|
|
|
|
if (real_a == 0) {
|
|
|
|
real_a = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (real_b == 0) {
|
|
|
|
real_b = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (real_a < real_b) {
|
|
|
|
return -1;
|
|
|
|
} else if (real_a == real_b) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2020-07-07 08:18:57 -04:00
|
|
|
_wins_get_next_available_num(GList* used)
|
2016-07-24 12:02:09 -04:00
|
|
|
{
|
|
|
|
// only console used
|
|
|
|
if (g_list_length(used) == 1) {
|
|
|
|
return 2;
|
|
|
|
} else {
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* sorted = NULL;
|
|
|
|
GList* curr = used;
|
2016-07-24 12:02:09 -04:00
|
|
|
while (curr) {
|
|
|
|
sorted = g_list_insert_sorted(sorted, curr->data, _wins_cmp_num);
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
int last_num = 1;
|
|
|
|
curr = sorted;
|
|
|
|
// skip console
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
while (curr) {
|
|
|
|
int curr_num = GPOINTER_TO_INT(curr->data);
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
if (((last_num != 9) && ((last_num + 1) != curr_num)) || ((last_num == 9) && (curr_num != 0))) {
|
2016-07-24 12:02:09 -04:00
|
|
|
result = last_num + 1;
|
|
|
|
if (result == 10) {
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
g_list_free(sorted);
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
last_num = curr_num;
|
|
|
|
if (last_num == 0) {
|
|
|
|
last_num = 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
result = last_num + 1;
|
|
|
|
if (result == 10) {
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(sorted);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-20 18:08:21 -04:00
|
|
|
gboolean
|
|
|
|
wins_tidy(void)
|
|
|
|
{
|
2013-08-27 18:38:25 -04:00
|
|
|
gboolean tidy_required = FALSE;
|
|
|
|
// check for gaps
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
keys = g_list_sort(keys, _wins_cmp_num);
|
2013-08-27 18:38:25 -04:00
|
|
|
|
|
|
|
// get last used
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* last = g_list_last(keys);
|
2013-08-27 18:38:25 -04:00
|
|
|
int last_num = GPOINTER_TO_INT(last->data);
|
|
|
|
|
|
|
|
// find first free num TODO - Will sort again
|
2016-07-24 12:02:09 -04:00
|
|
|
int next_available = _wins_get_next_available_num(keys);
|
2013-08-27 18:38:25 -04:00
|
|
|
|
2013-08-28 16:45:46 -04:00
|
|
|
// found gap (next available before last window)
|
2016-07-24 12:02:09 -04:00
|
|
|
if (_wins_cmp_num(GINT_TO_POINTER(next_available), GINT_TO_POINTER(last_num)) < 0) {
|
2013-08-27 18:38:25 -04:00
|
|
|
tidy_required = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tidy_required) {
|
2013-08-29 19:49:38 -04:00
|
|
|
status_bar_set_all_inactive();
|
2020-07-07 08:18:57 -04:00
|
|
|
GHashTable* new_windows = g_hash_table_new_full(g_direct_hash,
|
|
|
|
g_direct_equal, NULL, (GDestroyNotify)win_free);
|
2013-08-27 18:38:25 -04:00
|
|
|
|
|
|
|
int num = 1;
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* curr = keys;
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = g_hash_table_lookup(windows, curr->data);
|
|
|
|
char* identifier = win_get_tab_identifier(window);
|
2016-07-24 19:57:42 -04:00
|
|
|
g_hash_table_steal(windows, curr->data);
|
2013-08-27 18:38:25 -04:00
|
|
|
if (num == 10) {
|
2013-08-28 18:09:54 -04:00
|
|
|
g_hash_table_insert(new_windows, GINT_TO_POINTER(0), window);
|
2014-12-21 18:14:01 -05:00
|
|
|
if (win_unread(window) > 0) {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_new(0, window->type, identifier);
|
2013-08-27 18:38:25 -04:00
|
|
|
} else {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_active(0, window->type, identifier);
|
2013-08-27 18:38:25 -04:00
|
|
|
}
|
|
|
|
} else {
|
2013-08-28 18:09:54 -04:00
|
|
|
g_hash_table_insert(new_windows, GINT_TO_POINTER(num), window);
|
2014-12-21 18:14:01 -05:00
|
|
|
if (win_unread(window) > 0) {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_new(num, window->type, identifier);
|
2013-08-27 18:38:25 -04:00
|
|
|
} else {
|
2018-03-09 16:11:59 -05:00
|
|
|
status_bar_active(num, window->type, identifier);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
}
|
2018-03-09 16:11:59 -05:00
|
|
|
free(identifier);
|
2013-08-27 18:38:25 -04:00
|
|
|
num++;
|
|
|
|
curr = g_list_next(curr);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2016-07-24 19:57:42 -04:00
|
|
|
g_hash_table_destroy(windows);
|
2013-08-27 18:38:25 -04:00
|
|
|
windows = new_windows;
|
2013-10-02 19:02:30 -04:00
|
|
|
current = 1;
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* console = wins_get_console();
|
2015-11-02 15:59:36 -05:00
|
|
|
ui_focus_win(console);
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(keys);
|
2013-08-27 18:38:25 -04:00
|
|
|
return TRUE;
|
|
|
|
} else {
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(keys);
|
2013-08-27 18:38:25 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2015-10-25 20:52:33 -04:00
|
|
|
GSList*
|
2015-11-29 19:17:44 -05:00
|
|
|
wins_create_summary(gboolean unread)
|
2013-08-20 18:08:21 -04:00
|
|
|
{
|
2015-11-29 19:17:44 -05:00
|
|
|
if (unread && wins_get_total_unread() == 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
GSList* result = NULL;
|
2013-08-20 18:08:21 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
2016-07-24 12:02:09 -04:00
|
|
|
keys = g_list_sort(keys, _wins_cmp_num);
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* curr = keys;
|
2013-08-27 18:38:25 -04:00
|
|
|
|
2015-05-04 18:12:55 -04:00
|
|
|
while (curr) {
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* window = g_hash_table_lookup(windows, curr->data);
|
2015-11-29 19:17:44 -05:00
|
|
|
if (!unread || (unread && win_unread(window) > 0)) {
|
2020-07-07 08:18:57 -04:00
|
|
|
GString* line = g_string_new("");
|
2015-11-29 19:17:44 -05:00
|
|
|
|
|
|
|
int ui_index = GPOINTER_TO_INT(curr->data);
|
2020-07-07 08:18:57 -04:00
|
|
|
char* winstring = win_to_string(window);
|
2015-11-29 19:17:44 -05:00
|
|
|
if (!winstring) {
|
|
|
|
g_string_free(line, TRUE);
|
|
|
|
continue;
|
|
|
|
}
|
2013-08-27 18:38:25 -04:00
|
|
|
|
2015-11-29 19:17:44 -05:00
|
|
|
g_string_append_printf(line, "%d: %s", ui_index, winstring);
|
|
|
|
free(winstring);
|
|
|
|
|
|
|
|
result = g_slist_append(result, strdup(line->str));
|
2015-11-29 18:58:52 -05:00
|
|
|
g_string_free(line, TRUE);
|
|
|
|
}
|
2014-09-06 19:49:42 -04:00
|
|
|
|
2013-08-27 18:38:25 -04:00
|
|
|
curr = g_list_next(curr);
|
2013-08-20 18:08:21 -04:00
|
|
|
}
|
|
|
|
|
2014-06-17 18:14:54 -04:00
|
|
|
g_list_free(keys);
|
2015-11-29 18:58:52 -05:00
|
|
|
|
2013-08-20 18:08:21 -04:00
|
|
|
return result;
|
|
|
|
}
|
2013-08-26 12:47:29 -04:00
|
|
|
|
2021-05-29 03:30:13 -04:00
|
|
|
GSList*
|
|
|
|
wins_create_summary_attention()
|
|
|
|
{
|
|
|
|
GSList* result = NULL;
|
|
|
|
|
|
|
|
GList* keys = g_hash_table_get_keys(windows);
|
|
|
|
keys = g_list_sort(keys, _wins_cmp_num);
|
|
|
|
GList* curr = keys;
|
|
|
|
|
|
|
|
while (curr) {
|
|
|
|
ProfWin* window = g_hash_table_lookup(windows, curr->data);
|
|
|
|
gboolean has_attention = FALSE;
|
|
|
|
if (window->type == WIN_CHAT) {
|
|
|
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
|
|
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
|
|
|
has_attention = chatwin->has_attention;
|
|
|
|
} else if (window->type == WIN_MUC) {
|
|
|
|
ProfMucWin* mucwin = (ProfMucWin*)window;
|
|
|
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
|
|
|
has_attention = mucwin->has_attention;
|
|
|
|
}
|
2021-06-01 13:13:20 -04:00
|
|
|
if (has_attention) {
|
2021-05-29 03:30:13 -04:00
|
|
|
GString* line = g_string_new("");
|
|
|
|
|
|
|
|
int ui_index = GPOINTER_TO_INT(curr->data);
|
|
|
|
char* winstring = win_to_string(window);
|
|
|
|
if (!winstring) {
|
|
|
|
g_string_free(line, TRUE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_append_printf(line, "%d: %s", ui_index, winstring);
|
|
|
|
free(winstring);
|
|
|
|
|
|
|
|
result = g_slist_append(result, strdup(line->str));
|
|
|
|
g_string_free(line, TRUE);
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(keys);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-01-06 19:38:17 -05:00
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
win_autocomplete(const char* const search_str, gboolean previous, void* context)
|
2016-01-06 19:38:17 -05:00
|
|
|
{
|
2017-03-31 19:27:11 -04:00
|
|
|
return autocomplete_complete(wins_ac, search_str, TRUE, previous);
|
2016-01-06 19:38:17 -05:00
|
|
|
}
|
|
|
|
|
2016-01-13 18:19:11 -05:00
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
win_close_autocomplete(const char* const search_str, gboolean previous, void* context)
|
2016-01-13 18:19:11 -05:00
|
|
|
{
|
2017-03-31 19:27:11 -04:00
|
|
|
return autocomplete_complete(wins_close_ac, search_str, TRUE, previous);
|
2016-01-13 18:19:11 -05:00
|
|
|
}
|
|
|
|
|
2016-01-06 19:38:17 -05:00
|
|
|
void
|
|
|
|
win_reset_search_attempts(void)
|
|
|
|
{
|
|
|
|
autocomplete_reset(wins_ac);
|
|
|
|
}
|
|
|
|
|
2016-01-13 18:19:11 -05:00
|
|
|
void
|
|
|
|
win_close_reset_search_attempts(void)
|
|
|
|
{
|
|
|
|
autocomplete_reset(wins_close_ac);
|
|
|
|
}
|
|
|
|
|
2013-08-26 12:47:29 -04:00
|
|
|
void
|
|
|
|
wins_destroy(void)
|
|
|
|
{
|
2013-08-27 18:38:25 -04:00
|
|
|
g_hash_table_destroy(windows);
|
2016-01-06 19:38:17 -05:00
|
|
|
autocomplete_free(wins_ac);
|
2016-01-13 18:19:11 -05:00
|
|
|
autocomplete_free(wins_close_ac);
|
2013-08-26 12:47:29 -04:00
|
|
|
}
|
2019-09-30 12:28:05 -04:00
|
|
|
|
|
|
|
ProfWin*
|
|
|
|
wins_get_next_unread(void)
|
|
|
|
{
|
|
|
|
// get and sort win nums
|
2021-06-09 12:41:56 -04:00
|
|
|
GList* values = g_hash_table_get_keys(windows);
|
2019-09-30 12:28:05 -04:00
|
|
|
values = g_list_sort(values, _wins_cmp_num);
|
2020-07-07 08:18:57 -04:00
|
|
|
GList* curr = values;
|
2019-09-30 12:28:05 -04:00
|
|
|
|
|
|
|
while (curr) {
|
2021-06-09 12:41:56 -04:00
|
|
|
int curr_win_num = GPOINTER_TO_INT(curr->data);
|
|
|
|
ProfWin* window = wins_get_by_num(curr_win_num);
|
2019-09-30 12:28:05 -04:00
|
|
|
|
2021-06-09 12:41:56 -04:00
|
|
|
// test if window has unread messages
|
2019-09-30 12:28:05 -04:00
|
|
|
if (win_unread(window) > 0) {
|
|
|
|
g_list_free(values);
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(values);
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-05-20 03:48:42 -04:00
|
|
|
|
2021-05-29 14:16:21 -04:00
|
|
|
ProfWin*
|
|
|
|
wins_get_next_attention(void)
|
|
|
|
{
|
|
|
|
// get and sort win nums
|
|
|
|
GList* values = g_hash_table_get_values(windows);
|
|
|
|
values = g_list_sort(values, _wins_cmp_num);
|
|
|
|
GList* curr = values;
|
|
|
|
|
2021-06-01 13:13:20 -04:00
|
|
|
ProfWin* current_window = wins_get_by_num(current);
|
2021-05-29 16:01:44 -04:00
|
|
|
|
|
|
|
// search the current window
|
2021-06-01 13:13:20 -04:00
|
|
|
while (curr) {
|
2021-05-29 16:01:44 -04:00
|
|
|
ProfWin* window = curr->data;
|
2021-06-01 13:13:20 -04:00
|
|
|
if (current_window == window) {
|
2021-05-29 16:01:44 -04:00
|
|
|
current_window = window;
|
2021-05-29 14:16:21 -04:00
|
|
|
curr = g_list_next(curr);
|
2021-05-29 16:01:44 -04:00
|
|
|
break;
|
2021-05-29 14:16:21 -04:00
|
|
|
}
|
2021-05-29 16:01:44 -04:00
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
2021-05-29 14:16:21 -04:00
|
|
|
|
2021-05-29 16:01:44 -04:00
|
|
|
// Start from current window
|
2021-06-01 13:13:20 -04:00
|
|
|
while (current_window && curr) {
|
2021-05-29 14:16:21 -04:00
|
|
|
ProfWin* window = curr->data;
|
2021-05-29 16:01:44 -04:00
|
|
|
if (win_has_attention(window)) {
|
|
|
|
g_list_free(values);
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
// Start from begin
|
|
|
|
curr = values;
|
2021-06-01 13:13:20 -04:00
|
|
|
while (current_window && curr) {
|
2021-05-29 16:01:44 -04:00
|
|
|
ProfWin* window = curr->data;
|
2021-06-01 13:13:20 -04:00
|
|
|
if (current_window == window) {
|
2021-05-29 16:01:44 -04:00
|
|
|
// we are at current again
|
|
|
|
break;
|
2021-05-29 14:16:21 -04:00
|
|
|
}
|
|
|
|
if (win_has_attention(window)) {
|
|
|
|
g_list_free(values);
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
curr = g_list_next(curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free(values);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-05-20 03:48:42 -04:00
|
|
|
void
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_add_urls_ac(const ProfWin* const win, const ProfMessage* const message)
|
2020-05-20 03:48:42 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
GRegex* regex;
|
|
|
|
GMatchInfo* match_info;
|
2020-05-20 03:48:42 -04:00
|
|
|
|
2020-06-07 16:17:55 -04:00
|
|
|
regex = g_regex_new("(https?|aesgcm)://\\S+", 0, 0, NULL);
|
2020-07-07 08:18:57 -04:00
|
|
|
g_regex_match(regex, message->plain, 0, &match_info);
|
2020-05-20 03:48:42 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
while (g_match_info_matches(match_info)) {
|
|
|
|
gchar* word = g_match_info_fetch(match_info, 0);
|
2020-05-20 03:48:42 -04:00
|
|
|
|
2020-05-29 05:26:18 -04:00
|
|
|
autocomplete_add_reverse(win->urls_ac, word);
|
2020-05-20 04:26:48 -04:00
|
|
|
// for people who run profanity a long time, we don't want to waste a lot of memory
|
2020-05-29 05:26:18 -04:00
|
|
|
autocomplete_remove_older_than_max_reverse(win->urls_ac, 20);
|
2020-05-20 03:48:42 -04:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
g_free(word);
|
|
|
|
g_match_info_next(match_info, NULL);
|
2020-05-20 03:48:42 -04:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
g_match_info_free(match_info);
|
|
|
|
g_regex_unref(regex);
|
2020-05-20 03:48:42 -04:00
|
|
|
}
|
|
|
|
|
2022-03-20 18:10:07 -04:00
|
|
|
void
|
|
|
|
wins_add_quotes_ac(const ProfWin* const win, const char* const message)
|
|
|
|
{
|
|
|
|
autocomplete_add_reverse(win->quotes_ac, message);
|
|
|
|
// for people who run profanity a long time, we don't want to waste a lot of memory
|
|
|
|
autocomplete_remove_older_than_max_reverse(win->quotes_ac, 20);
|
|
|
|
}
|
|
|
|
|
2020-05-20 03:48:42 -04:00
|
|
|
char*
|
2020-07-07 08:18:57 -04:00
|
|
|
wins_get_url(const char* const search_str, gboolean previous, void* context)
|
2020-05-20 03:48:42 -04:00
|
|
|
{
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfWin* win = (ProfWin*)context;
|
2020-05-20 03:48:42 -04:00
|
|
|
|
|
|
|
return autocomplete_complete(win->urls_ac, search_str, FALSE, previous);
|
|
|
|
}
|
2022-03-20 18:10:07 -04:00
|
|
|
|
|
|
|
char*
|
|
|
|
wins_get_quote(const char* const search_str, gboolean previous, void* context)
|
|
|
|
{
|
|
|
|
ProfWin* win = (ProfWin*)context;
|
|
|
|
|
|
|
|
return autocomplete_complete(win->quotes_ac, search_str, FALSE, previous);
|
|
|
|
}
|