Skip to content

Commit

Permalink
Implemented history and number of bugfixes
Browse files Browse the repository at this point in the history
git-svn-id: http://sanoi.webfactional.com/trunk@111 79def182-f41f-0410-b320-e94a04284523
  • Loading branch information
mario committed Oct 12, 2007
1 parent 0f99d69 commit 853c417
Show file tree
Hide file tree
Showing 10 changed files with 460 additions and 87 deletions.
9 changes: 9 additions & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ wchar_t *commandline_get_buffer();
void commandline_draw();
void commandline_move_cursor(gint);
void commandline_delete();
void commandline_set_cmd(gchar *line);

/* Keyfile.c */
gboolean keyfile_read();
Expand All @@ -210,6 +211,7 @@ GKeyFile *keyfile_get();
#define FAMA_LOGFILE_DIR "logs"
#define FAMA_CONFIG_FILE "config"
#define FAMA_ACCOUNTS "accounts"
#define FAMA_HISTORY_FILE "history"

/* Window.c */
FamaWindow *window_new(FamaWindowType);
Expand All @@ -236,6 +238,13 @@ void log_get_time(gchar *, gsize);
void command_init();
void command_add(gchar *, CommandFunc);
gboolean command_execute(gint, gchar **);
gboolean command_hist_init();
gboolean commandline_hist_loadpre();
gboolean commandline_hist_loadnext();

/* history*/
/** default list number of history*/
#define DEFAULTLISTNUMBER 10

/* Color.c */
void color_init();
Expand Down
8 changes: 8 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "ui-history.h"

GMainLoop *loop;

Expand Down Expand Up @@ -179,6 +180,12 @@ init_all()

command_init();

/*
* Initialize history interface
*/

famahistory_command_init();

/*
* Call stdin_handle_input when there's input from stdin
*/
Expand All @@ -199,3 +206,4 @@ init_all()

return TRUE;
}

1 change: 1 addition & 0 deletions src/ui-command-account.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ command_func_account(gint argc, gchar ** argv)
window_add_message(window_get_current(), title, A_BOLD, outbuf);

g_ptr_array_free(items, TRUE);
g_free(outbuf);
}
return TRUE;
}
19 changes: 19 additions & 0 deletions src/ui-command-line.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "common.h"
#include <string.h>

#define COMMAND_LINE_MAX_LENGHT 512

Expand Down Expand Up @@ -114,3 +115,21 @@ commandline_add_wch(wchar_t c)

commandline_draw();
}

void
commandline_set_cmd(gchar *line)
{
gint strlength;
if (!line) {
cmdbuf[0] = L'\0';
len = ptr = 0;
return;
}
cmdbuf[0] = L'/';
strlength = strlen(line);
utf8_to_wchar(line, cmdbuf + 1, strlength);
cmdbuf[strlength + 1] = L'\0';
len = strlength;
ptr = len;
}

119 changes: 117 additions & 2 deletions src/ui-command.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "common.h"
#include <string.h>
#include <stdlib.h>
#include <glib/gprintf.h>
#include "ui-history.h"

GHashTable *table = NULL;


gboolean command_func_window(gint argc, gchar ** argv);
gboolean command_func_help(gint argc, gchar ** argv);
gboolean command_func_connect(gint argc, gchar ** argv);
Expand All @@ -13,7 +14,13 @@ gboolean command_func_account(gint argc, gchar ** argv);
gboolean command_func_contact(gint argc, gchar ** argv);
gboolean command_func_status(gint argc, gchar ** argv);
gboolean command_func_log(gint argc, gchar ** argv);
gboolean command_func_history(gint argc, gchar ** argv);

/** argc is number of arguments in a command line,
* argv is array of the arguments*/
void command_hist_add(gint argc, gchar ** argv);
/** load history setting in profile(keyfile)*/
gboolean command_hist_loadprofile();
/*
* This function is for command_func_help()'s private use
*/
Expand Down Expand Up @@ -67,6 +74,7 @@ gboolean
command_func_quit(gint argc, gchar ** argv)
{
stop_main_loop();
famahistory_command_savesession();
return TRUE;
}

Expand Down Expand Up @@ -132,6 +140,112 @@ command_func_window(gint argc, gchar ** argv)
return TRUE;
}

gboolean
command_func_history(gint argc, gchar ** argv)
{
gchar **infostring;
gchar *string, strtitle[256];
wchar_t *outbuf, wtitle[256];
gint mask = 0;
if (argc == 0)
return FALSE;
g_sprintf(strtitle, "History infomation : ");
if (argc == 1) {
infostring = famahistory_info_get(HISINFO_USAGE | HISINFO_MAXNUMBER |
HISINFO_ENABLE | HISINFO_LISTNUM);

g_assert(infostring);
string = g_strjoinv("\n", infostring);
outbuf = g_new(wchar_t, strlen(string) + 1);

utf8_to_wchar(string, outbuf, strlen(string));
utf8_to_wchar(strtitle, wtitle, strlen(strtitle));
window_add_message(window_get_main(),
wtitle,
A_BOLD, outbuf);

g_strfreev(infostring);
g_free(string);
g_free(outbuf);
return TRUE;
}

if (g_ascii_strcasecmp("maxnumber", argv[1]) == 0) {
if (argc == 3) {
gint max = atoi(argv[2]);
famahistory_setmax(max);
g_sprintf(strtitle, "History infomation : %s",
"Succeed in setting max number of history.");
} else
mask |= HISINFO_USAGE;
mask |= HISINFO_MAXNUMBER;
infostring = famahistory_info_get(mask);
string = g_strjoinv("\n", infostring);
outbuf = g_new(wchar_t, strlen(string) + 1);
utf8_to_wchar(string, outbuf, strlen(string));
utf8_to_wchar(strtitle, wtitle, strlen(strtitle));
window_add_message(window_get_main(),
wtitle, A_BOLD, outbuf);
g_strfreev(infostring);
g_free(string);
g_free(outbuf);
return TRUE;
}
if (g_ascii_strcasecmp("enable", argv[1]) == 0) {
if (argc == 3) {
gint enab = -1;
if (g_ascii_strcasecmp("on", argv[2]) == 0) {
enab = 1;
} else if (g_ascii_strcasecmp("off", argv[2]) == 0) {
enab = 0;
} else
mask |= HISINFO_USAGE;
if (enab >= 0) {
famahistory_enable(enab);
g_sprintf(strtitle, "History infomation : %s",
"Succeed in setting of history enable flag.");
}
} else
mask |= HISINFO_USAGE;
mask |= HISINFO_ENABLE;
infostring = famahistory_info_get(mask);
string = g_strjoinv("\n", infostring);
outbuf = g_new(wchar_t, strlen(string) + 1);
utf8_to_wchar(string, outbuf, strlen(string));
utf8_to_wchar(strtitle, wtitle, strlen(strtitle));
window_add_message(window_get_main(),
wtitle, A_BOLD, outbuf);
g_strfreev(infostring);
g_free(string);
g_free(outbuf);
return TRUE;
}
if (g_ascii_strcasecmp("list", argv[1]) == 0) {
gint listnum;
g_sprintf(strtitle, "History infomation : has %d records",
famahistory_number());
if (argc == 3) {
if (g_ascii_strcasecmp("all", argv[2]) == 0)
listnum = famahistory_number();
else
listnum = atoi(argv[2]);
} else {
listnum = DEFAULTLISTNUMBER;
}
infostring = famahistory_info_getlist(listnum);
string = g_strjoinv("\n", infostring);
outbuf = g_new(wchar_t, strlen(string) + 1);
utf8_to_wchar(string, outbuf, strlen(string));
utf8_to_wchar(strtitle, wtitle, strlen(strtitle));
window_add_message(window_get_main(),
wtitle, A_BOLD, outbuf);
g_strfreev(infostring);
g_free(string);
g_free(outbuf);
return TRUE;
}return TRUE;
}

/*
* Add a new command
*/
Expand All @@ -156,6 +270,7 @@ command_init()
command_add("status", command_func_status);
command_add("contact", command_func_contact);
command_add("log", command_func_log);
command_add("history", command_func_history);
}

/*
Expand All @@ -175,6 +290,6 @@ command_execute(gint argc, gchar ** argv)
return FALSE;

func(argc, argv);

return TRUE;
}

Loading

0 comments on commit 853c417

Please sign in to comment.