1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Moved cons_about() to console module

This commit is contained in:
James Booth 2013-04-20 23:39:17 +01:00
parent 3e66b0a9d2
commit c7100203e4
8 changed files with 404 additions and 382 deletions

View File

@ -1550,6 +1550,9 @@ _cmd_about(gchar **args, struct cmd_help_t help)
{
cons_show("");
cons_about();
if (!win_current_is_console()) {
status_bar_new(0);
}
return TRUE;
}
@ -1808,6 +1811,10 @@ _cmd_who(gchar **args, struct cmd_help_t help)
}
}
if (!win_current_is_console()) {
status_bar_new(0);
}
return TRUE;
}

View File

@ -19,6 +19,7 @@
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <assert.h>
#include <errno.h>
@ -260,6 +261,32 @@ release_get_latest()
}
}
gboolean
release_is_new(char *found_version)
{
int curr_maj, curr_min, curr_patch, found_maj, found_min, found_patch;
int parse_curr = sscanf(PACKAGE_VERSION, "%d.%d.%d", &curr_maj, &curr_min,
&curr_patch);
int parse_found = sscanf(found_version, "%d.%d.%d", &found_maj, &found_min,
&found_patch);
if (parse_found == 3 && parse_curr == 3) {
if (found_maj > curr_maj) {
return TRUE;
} else if (found_maj == curr_maj && found_min > curr_min) {
return TRUE;
} else if (found_maj == curr_maj && found_min == curr_min
&& found_patch > curr_patch) {
return TRUE;
} else {
return FALSE;
}
} else {
return FALSE;
}
}
gboolean
valid_resource_presence_string(const char * const str)
{

View File

@ -83,6 +83,7 @@ char* encode_xml(const char * const xml);
char * prof_getline(FILE *stream);
int octet_compare(unsigned char *str1, unsigned char *str2);
char* release_get_latest(void);
gboolean release_is_new(char *found_version);
gchar * xdg_get_config_home(void);
gchar * xdg_get_data_home(void);

View File

@ -20,24 +20,184 @@
*
*/
#include <string.h>
#include <stdlib.h>
#ifdef HAVE_NCURSESW_NCURSES_H
#include <ncursesw/ncurses.h>
#elif HAVE_NCURSES_H
#include <ncurses.h>
#endif
#include "common.h"
#include "config/preferences.h"
#include "config/theme.h"
#include "ui/window.h"
#define CONS_WIN_TITLE "_cons"
static ProfWin* console;
static int dirty;
static void _cons_splash_logo(void);
ProfWin *
console_create(void)
cons_create(void)
{
int cols = getmaxx(stdscr);
console = window_create(CONS_WIN_TITLE, cols, WIN_CONSOLE);
dirty = FALSE;
return console;
}
void
cons_refresh(void)
{
int rows, cols;
if (dirty == TRUE) {
getmaxyx(stdscr, rows, cols);
prefresh(console->win, console->y_pos, 0, 1, 0, rows-3, cols-1);
dirty = FALSE;
}
}
void
cons_show(const char * const msg, ...)
{
va_list arg;
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
window_show_time(console, '-');
wprintw(console->win, "%s\n", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
dirty = TRUE;
}
void
cons_about(void)
{
int rows, cols;
getmaxyx(stdscr, rows, cols);
if (prefs_get_boolean(PREF_SPLASH)) {
_cons_splash_logo();
} else {
window_show_time(console, '-');
if (strcmp(PACKAGE_STATUS, "development") == 0) {
wprintw(console->win, "Welcome to Profanity, version %sdev\n", PACKAGE_VERSION);
} else {
wprintw(console->win, "Welcome to Profanity, version %s\n", PACKAGE_VERSION);
}
}
window_show_time(console, '-');
wprintw(console->win, "Copyright (C) 2012, 2013 James Booth <%s>.\n", PACKAGE_BUGREPORT);
window_show_time(console, '-');
wprintw(console->win, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
window_show_time(console, '-');
wprintw(console->win, "\n");
window_show_time(console, '-');
wprintw(console->win, "This is free software; you are free to change and redistribute it.\n");
window_show_time(console, '-');
wprintw(console->win, "There is NO WARRANTY, to the extent permitted by law.\n");
window_show_time(console, '-');
wprintw(console->win, "\n");
window_show_time(console, '-');
wprintw(console->win, "Type '/help' to show complete help.\n");
window_show_time(console, '-');
wprintw(console->win, "\n");
if (prefs_get_boolean(PREF_VERCHECK)) {
cons_check_version(FALSE);
}
prefresh(console->win, 0, 0, 1, 0, rows-3, cols-1);
dirty = TRUE;
}
void
cons_check_version(gboolean not_available_msg)
{
char *latest_release = release_get_latest();
if (latest_release != NULL) {
gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0);
if (relase_valid) {
if (release_is_new(latest_release)) {
window_show_time(console, '-');
wprintw(console->win, "A new version of Profanity is available: %s", latest_release);
window_show_time(console, '-');
wprintw(console->win, "Check <http://www.profanity.im> for details.\n");
free(latest_release);
window_show_time(console, '-');
wprintw(console->win, "\n");
} else {
if (not_available_msg) {
cons_show("No new version available.");
cons_show("");
}
}
dirty = TRUE;
}
}
}
static void
_cons_splash_logo(void)
{
window_show_time(console, '-');
wprintw(console->win, "Welcome to\n");
window_show_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " ___ _ \n");
wattroff(console->win, COLOUR_SPLASH);
window_show_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " / __) (_)_ \n");
wattroff(console->win, COLOUR_SPLASH);
window_show_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, " ____ ____ ___ | |__ ____ ____ _| |_ _ _ \n");
wattroff(console->win, COLOUR_SPLASH);
window_show_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "| _ \\ / ___) _ \\| __) _ | _ \\| | _) | | |\n");
wattroff(console->win, COLOUR_SPLASH);
window_show_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "| | | | | | |_| | | ( ( | | | | | | |_| |_| |\n");
wattroff(console->win, COLOUR_SPLASH);
window_show_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "| ||_/|_| \\___/|_| \\_||_|_| |_|_|\\___)__ |\n");
wattroff(console->win, COLOUR_SPLASH);
window_show_time(console, '-');
wattron(console->win, COLOUR_SPLASH);
wprintw(console->win, "|_| (____/ \n");
wattroff(console->win, COLOUR_SPLASH);
window_show_time(console, '-');
wprintw(console->win, "\n");
window_show_time(console, '-');
if (strcmp(PACKAGE_STATUS, "development") == 0) {
wprintw(console->win, "Version %sdev\n", PACKAGE_VERSION);
} else {
wprintw(console->win, "Version %s\n", PACKAGE_VERSION);
}
}

View File

@ -25,7 +25,11 @@
#include "ui/window.h"
ProfWin* console_create(void);
ProfWin* cons_create(void);
void cons_refresh(void);
void cons_show(const char * const msg, ...);
void cons_about(void);
void cons_check_version(gboolean not_available_msg);
#endif

View File

@ -64,3 +64,15 @@ window_free(ProfWin* window)
free(window);
window = NULL;
}
void
window_show_time(ProfWin* window, char show_char)
{
GDateTime *time = g_date_time_new_now_local();
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wattron(window->win, COLOUR_TIME);
wprintw(window->win, "%s %c ", date_fmt, show_char);
wattroff(window->win, COLOUR_TIME);
g_date_time_unref(time);
g_free(date_fmt);
}

View File

@ -39,4 +39,6 @@ typedef struct prof_win_t {
ProfWin* window_create(const char * const title, int cols, win_type_t type);
void window_free(ProfWin *window);
void window_show_time(ProfWin* window, char show_char);
#endif

File diff suppressed because it is too large Load Diff