2012-02-20 20:07:38 +00:00
|
|
|
/*
|
|
|
|
* profanity.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2012-02-09 22:24:03 +00:00
|
|
|
#include <string.h>
|
2012-03-10 20:37:42 +00:00
|
|
|
#include <stdlib.h>
|
2012-07-19 21:38:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2012-04-24 00:02:22 +00:00
|
|
|
#include <glib.h>
|
2012-02-09 22:24:03 +00:00
|
|
|
|
2012-08-21 23:30:24 +00:00
|
|
|
#include "config.h"
|
2012-02-09 22:24:03 +00:00
|
|
|
#include "profanity.h"
|
2012-02-05 15:10:10 +00:00
|
|
|
#include "log.h"
|
2012-07-22 19:53:55 +00:00
|
|
|
#include "chat_log.h"
|
2012-05-24 00:11:43 +00:00
|
|
|
#include "ui.h"
|
2012-02-09 22:24:03 +00:00
|
|
|
#include "jabber.h"
|
2012-02-09 23:15:53 +00:00
|
|
|
#include "command.h"
|
2012-05-10 02:29:48 +00:00
|
|
|
#include "preferences.h"
|
2012-05-13 22:06:01 +00:00
|
|
|
#include "contact_list.h"
|
2012-07-28 00:36:08 +00:00
|
|
|
#include "tinyurl.h"
|
2012-02-09 22:24:03 +00:00
|
|
|
|
2012-08-21 23:30:24 +00:00
|
|
|
static log_level_t _get_log_level(char *log_level);
|
2012-03-10 20:37:42 +00:00
|
|
|
static void _profanity_shutdown(void);
|
|
|
|
|
2012-07-24 22:19:48 +00:00
|
|
|
void
|
|
|
|
profanity_run(void)
|
2012-02-09 22:50:19 +00:00
|
|
|
{
|
2012-04-24 00:02:22 +00:00
|
|
|
gboolean cmd_result = TRUE;
|
2012-02-09 22:50:19 +00:00
|
|
|
|
2012-08-21 23:30:24 +00:00
|
|
|
log_msg(PROF_LEVEL_INFO, "prof", "Starting main event loop");
|
|
|
|
|
2012-02-09 22:50:19 +00:00
|
|
|
inp_non_block();
|
2012-02-09 23:15:53 +00:00
|
|
|
while(cmd_result == TRUE) {
|
2012-02-09 22:50:19 +00:00
|
|
|
int ch = ERR;
|
2012-07-09 22:48:53 +00:00
|
|
|
char inp[INP_WIN_MAX];
|
2012-02-09 22:50:19 +00:00
|
|
|
int size = 0;
|
|
|
|
|
2012-03-01 01:52:35 +00:00
|
|
|
while(ch != '\n') {
|
2012-04-17 21:43:35 +00:00
|
|
|
win_handle_special_keys(&ch);
|
2012-04-22 19:59:36 +00:00
|
|
|
|
2012-04-17 22:28:21 +00:00
|
|
|
if (ch == KEY_RESIZE) {
|
|
|
|
gui_resize(ch, inp, size);
|
|
|
|
}
|
2012-04-22 19:59:36 +00:00
|
|
|
|
|
|
|
gui_refresh();
|
|
|
|
jabber_process_events();
|
|
|
|
|
|
|
|
inp_get_char(&ch, inp, &size);
|
2012-03-01 01:52:35 +00:00
|
|
|
}
|
2012-02-17 00:42:41 +00:00
|
|
|
|
2012-02-20 01:42:29 +00:00
|
|
|
inp[size++] = '\0';
|
|
|
|
cmd_result = process_input(inp);
|
2012-02-09 22:50:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-24 22:19:48 +00:00
|
|
|
void
|
2012-08-19 02:43:18 +00:00
|
|
|
profanity_init(const int disable_tls, char *log_level)
|
2012-02-27 01:48:51 +00:00
|
|
|
{
|
2012-07-19 20:30:07 +00:00
|
|
|
create_config_directory();
|
2012-08-21 23:30:24 +00:00
|
|
|
log_level_t prof_log_level = _get_log_level(log_level);
|
2012-08-19 02:43:18 +00:00
|
|
|
log_init(prof_log_level);
|
2012-08-21 23:30:24 +00:00
|
|
|
log_msg(PROF_LEVEL_INFO, PROF, "Starting Profanity (%s)...", PACKAGE_VERSION);
|
2012-07-22 19:53:55 +00:00
|
|
|
chat_log_init();
|
2012-06-18 22:06:17 +00:00
|
|
|
prefs_load();
|
2012-03-01 01:44:47 +00:00
|
|
|
gui_init();
|
2012-02-27 01:48:51 +00:00
|
|
|
jabber_init(disable_tls);
|
2012-08-22 23:30:11 +00:00
|
|
|
cmd_init();
|
2012-05-13 22:06:01 +00:00
|
|
|
contact_list_init();
|
2012-03-10 20:37:42 +00:00
|
|
|
atexit(_profanity_shutdown);
|
2012-02-27 01:48:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-24 22:19:48 +00:00
|
|
|
void
|
|
|
|
_profanity_shutdown(void)
|
2012-03-01 01:44:47 +00:00
|
|
|
{
|
2012-08-19 02:43:18 +00:00
|
|
|
log_msg(PROF_LEVEL_INFO, PROF, "Profanity is shutting down.");
|
2012-03-01 01:44:47 +00:00
|
|
|
jabber_disconnect();
|
|
|
|
gui_close();
|
2012-07-22 19:53:55 +00:00
|
|
|
chat_log_close();
|
2012-07-31 22:01:15 +00:00
|
|
|
prefs_close();
|
2012-08-21 23:30:24 +00:00
|
|
|
log_msg(PROF_LEVEL_INFO, "prof", "Shutdown complete");
|
|
|
|
log_close();
|
2012-03-01 01:44:47 +00:00
|
|
|
}
|
2012-08-19 02:43:18 +00:00
|
|
|
|
2012-08-21 23:30:24 +00:00
|
|
|
static log_level_t
|
|
|
|
_get_log_level(char *log_level)
|
2012-08-19 02:43:18 +00:00
|
|
|
{
|
|
|
|
if (strcmp(log_level, "DEBUG") == 0) {
|
|
|
|
return PROF_LEVEL_DEBUG;
|
|
|
|
} else if (strcmp(log_level, "INFO") == 0) {
|
|
|
|
return PROF_LEVEL_INFO;
|
|
|
|
} else if (strcmp(log_level, "WARN") == 0) {
|
|
|
|
return PROF_LEVEL_WARN;
|
|
|
|
} else {
|
|
|
|
return PROF_LEVEL_ERROR;
|
|
|
|
}
|
|
|
|
}
|