mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Merge branch 'master' into plugins
Conflicts: src/ui/core.c
This commit is contained in:
commit
bd79b97101
1
.gitignore
vendored
1
.gitignore
vendored
@ -51,3 +51,4 @@ libprofanity.la
|
||||
libtool
|
||||
runvalgrind.sh
|
||||
src/prof_config.h
|
||||
clean.sh
|
||||
|
@ -30,7 +30,6 @@ core_sources = \
|
||||
src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
|
||||
src/ui/console.c src/ui/notifier.c \
|
||||
src/ui/windows.c src/ui/windows.h \
|
||||
src/ui/muc_window.c src/ui/muc_window.h \
|
||||
src/command/command.h src/command/command.c src/command/history.c \
|
||||
src/command/commands.h src/command/commands.c \
|
||||
src/command/history.h src/tools/parser.c \
|
||||
|
@ -255,7 +255,7 @@ _ui_incoming_msg(const char * const from, const char * const message,
|
||||
|
||||
// currently viewing chat window with sender
|
||||
if (wins_is_current(window)) {
|
||||
window->print_incoming_message(window, tv_stamp, display_from, new_message);
|
||||
win_print_incoming_message(window, tv_stamp, display_from, new_message);
|
||||
title_bar_set_typing(FALSE);
|
||||
title_bar_draw();
|
||||
status_bar_active(num);
|
||||
@ -281,7 +281,7 @@ _ui_incoming_msg(const char * const from, const char * const message,
|
||||
}
|
||||
}
|
||||
|
||||
window->print_incoming_message(window, tv_stamp, display_from, new_message);
|
||||
win_print_incoming_message(window, tv_stamp, display_from, new_message);
|
||||
}
|
||||
|
||||
int ui_index = num;
|
||||
@ -344,7 +344,7 @@ _ui_handle_error_message(const char * const from, const char * const err_msg)
|
||||
cons_show_error("Unknown error received from service.");
|
||||
} else {
|
||||
ProfWin *current = wins_get_current();
|
||||
gboolean handled = current->handle_error_message(current, from, err_msg);
|
||||
gboolean handled = win_handle_error_message(current, from, err_msg);
|
||||
if (handled != TRUE) {
|
||||
cons_show_error("Error received from server: %s", err_msg);
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* muc_window.c
|
||||
*
|
||||
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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
|
||||
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "ui/window.h"
|
||||
|
||||
gboolean
|
||||
muc_handle_error_message(ProfWin *self, const char * const from,
|
||||
const char * const err_msg)
|
||||
{
|
||||
gboolean handled = FALSE;
|
||||
if (g_strcmp0(err_msg, "conflict") == 0) {
|
||||
win_print_line(self, '-', 0, "Nickname already in use.");
|
||||
win_refresh(self);
|
||||
handled = TRUE;
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
/*
|
||||
* muc_window.h
|
||||
*
|
||||
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
* 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
|
||||
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UI_MUC_WINDOW_H
|
||||
#define UI_MUC_WINDOW_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "ui/window.h"
|
||||
|
||||
gboolean muc_handle_error_message(ProfWin *self, const char * const from,
|
||||
const char * const err_msg);
|
||||
|
||||
#endif
|
119
src/ui/window.c
119
src/ui/window.c
@ -24,6 +24,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <glib.h>
|
||||
#ifdef PROF_HAVE_NCURSESW_NCURSES_H
|
||||
@ -34,12 +35,12 @@
|
||||
|
||||
#include "config/theme.h"
|
||||
#include "ui/window.h"
|
||||
#include "ui/muc_window.h"
|
||||
|
||||
static gboolean _default_handle_error_message(ProfWin *self, const char * const from,
|
||||
const char * const err_msg);
|
||||
static void _print_incoming_message(ProfWin *self, GTimeVal *tv_stamp,
|
||||
static void _win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
|
||||
const char * const from, const char * const message);
|
||||
static gboolean
|
||||
_muc_handle_error_message(ProfWin *window, const char * const from,
|
||||
const char * const err_msg);
|
||||
|
||||
ProfWin*
|
||||
win_create(const char * const title, int cols, win_type_t type)
|
||||
@ -53,35 +54,6 @@ win_create(const char * const title, int cols, win_type_t type)
|
||||
new_win->unread = 0;
|
||||
new_win->history_shown = 0;
|
||||
new_win->type = type;
|
||||
|
||||
switch (new_win->type)
|
||||
{
|
||||
case WIN_CONSOLE:
|
||||
new_win->handle_error_message = _default_handle_error_message;
|
||||
new_win->print_incoming_message = NULL;
|
||||
break;
|
||||
case WIN_CHAT:
|
||||
new_win->handle_error_message = _default_handle_error_message;
|
||||
new_win->print_incoming_message = _print_incoming_message;
|
||||
break;
|
||||
case WIN_MUC:
|
||||
new_win->handle_error_message = muc_handle_error_message;
|
||||
new_win->print_incoming_message = NULL;
|
||||
break;
|
||||
case WIN_PRIVATE:
|
||||
new_win->handle_error_message = _default_handle_error_message;
|
||||
new_win->print_incoming_message = _print_incoming_message;
|
||||
break;
|
||||
case WIN_DUCK:
|
||||
new_win->handle_error_message = _default_handle_error_message;
|
||||
new_win->print_incoming_message = NULL;
|
||||
break;
|
||||
default:
|
||||
new_win->handle_error_message = _default_handle_error_message;
|
||||
new_win->print_incoming_message = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
scrollok(new_win->win, TRUE);
|
||||
|
||||
return new_win;
|
||||
@ -314,40 +286,85 @@ win_show_status_string(ProfWin *window, const char * const from,
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_default_handle_error_message(ProfWin *self, const char * const from,
|
||||
void
|
||||
win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
|
||||
const char * const from, const char * const message)
|
||||
{
|
||||
switch (window->type)
|
||||
{
|
||||
case WIN_CHAT:
|
||||
case WIN_PRIVATE:
|
||||
_win_chat_print_incoming_message(window, tv_stamp, from, message);
|
||||
break;
|
||||
default:
|
||||
assert(FALSE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
win_handle_error_message(ProfWin *window, const char * const from,
|
||||
const char * const err_msg)
|
||||
{
|
||||
return FALSE;
|
||||
gboolean handled = FALSE;
|
||||
switch (window->type)
|
||||
{
|
||||
case WIN_CHAT:
|
||||
case WIN_PRIVATE:
|
||||
case WIN_DUCK:
|
||||
case WIN_CONSOLE:
|
||||
handled = FALSE;
|
||||
case WIN_MUC:
|
||||
handled = _muc_handle_error_message(window, from, err_msg);
|
||||
default:
|
||||
assert(FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_muc_handle_error_message(ProfWin *window, const char * const from,
|
||||
const char * const err_msg)
|
||||
{
|
||||
gboolean handled = FALSE;
|
||||
if (g_strcmp0(err_msg, "conflict") == 0) {
|
||||
win_print_line(window, '-', 0, "Nickname already in use.");
|
||||
win_refresh(window);
|
||||
handled = TRUE;
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
static void
|
||||
_print_incoming_message(ProfWin *self, GTimeVal *tv_stamp,
|
||||
_win_chat_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
|
||||
const char * const from, const char * const message)
|
||||
{
|
||||
if (tv_stamp == NULL) {
|
||||
win_print_time(self, '-');
|
||||
win_print_time(window, '-');
|
||||
} else {
|
||||
GDateTime *time = g_date_time_new_from_timeval_utc(tv_stamp);
|
||||
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
|
||||
wattron(self->win, COLOUR_TIME);
|
||||
wprintw(self->win, "%s - ", date_fmt);
|
||||
wattroff(self->win, COLOUR_TIME);
|
||||
wattron(window->win, COLOUR_TIME);
|
||||
wprintw(window->win, "%s - ", date_fmt);
|
||||
wattroff(window->win, COLOUR_TIME);
|
||||
g_date_time_unref(time);
|
||||
g_free(date_fmt);
|
||||
}
|
||||
|
||||
if (strncmp(message, "/me ", 4) == 0) {
|
||||
wattron(self->win, COLOUR_THEM);
|
||||
wprintw(self->win, "*%s ", from);
|
||||
waddstr(self->win, message + 4);
|
||||
wprintw(self->win, "\n");
|
||||
wattroff(self->win, COLOUR_THEM);
|
||||
wattron(window->win, COLOUR_THEM);
|
||||
wprintw(window->win, "*%s ", from);
|
||||
waddstr(window->win, message + 4);
|
||||
wprintw(window->win, "\n");
|
||||
wattroff(window->win, COLOUR_THEM);
|
||||
} else {
|
||||
wattron(self->win, COLOUR_THEM);
|
||||
wprintw(self->win, "%s: ", from);
|
||||
wattroff(self->win, COLOUR_THEM);
|
||||
waddstr(self->win, message);
|
||||
wprintw(self->win, "\n");
|
||||
wattron(window->win, COLOUR_THEM);
|
||||
wprintw(window->win, "%s: ", from);
|
||||
wattroff(window->win, COLOUR_THEM);
|
||||
waddstr(window->win, message);
|
||||
wprintw(window->win, "\n");
|
||||
}
|
||||
}
|
||||
|
@ -53,10 +53,6 @@ typedef struct prof_win_t {
|
||||
int paged;
|
||||
int unread;
|
||||
int history_shown;
|
||||
gboolean (*handle_error_message)(struct prof_win_t *self,
|
||||
const char * const from, const char * const err_msg);
|
||||
void (*print_incoming_message)(struct prof_win_t *self, GTimeVal *tv_stamp,
|
||||
const char * const from, const char * const message);
|
||||
} ProfWin;
|
||||
|
||||
ProfWin* win_create(const char * const title, int cols, win_type_t type);
|
||||
@ -73,5 +69,10 @@ void win_show_status_string(ProfWin *window, const char * const from,
|
||||
const char * const show, const char * const status,
|
||||
GDateTime *last_activity, const char * const pre,
|
||||
const char * const default_show);
|
||||
void win_print_incoming_message(ProfWin *window, GTimeVal *tv_stamp,
|
||||
const char * const from, const char * const message);
|
||||
gboolean
|
||||
win_handle_error_message(ProfWin *window, const char * const from,
|
||||
const char * const err_msg);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user