1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Moved beep/flash settings to preferences

This commit is contained in:
James Booth 2012-05-10 09:55:55 +01:00
parent 90c985c4d2
commit aa26278a46
8 changed files with 43 additions and 37 deletions

View File

@ -15,7 +15,7 @@ profanity: $(OBJS)
$(CC) -o profanity $(OBJS) $(LIBS) $(CC) -o profanity $(OBJS) $(LIBS)
log.o: log.h log.o: log.h
windows.o: windows.h util.h contact_list.h windows.o: windows.h util.h contact_list.h preferences.h
title_bar.o: windows.h title_bar.o: windows.h
status_bar.o: windows.h util.h status_bar.o: windows.h util.h
input_win.o: windows.h input_win.o: windows.h
@ -27,7 +27,7 @@ history.o: history.h prof_history.h
contact_list.o: contact_list.h contact.h contact_list.o: contact_list.h contact.h
prof_history.o: prof_history.h prof_history.o: prof_history.h
contact.o: contact.h contact.o: contact.h
preferences.o: preferences.h windows.h preferences.o: preferences.h
main.o: profanity.h main.o: profanity.h
test_contact_list.o: contact_list.h contact.h test_contact_list.o: contact_list.h contact.h

View File

@ -31,6 +31,7 @@
#include "jabber.h" #include "jabber.h"
#include "windows.h" #include "windows.h"
#include "util.h" #include "util.h"
#include "preferences.h"
static gboolean _handle_command(const char * const command, static gboolean _handle_command(const char * const command,
const char * const inp); const char * const inp);
@ -223,10 +224,10 @@ static gboolean _cmd_set_beep(const char * const inp)
{ {
if (strcmp(inp, "/beep on") == 0) { if (strcmp(inp, "/beep on") == 0) {
cons_show("Sound enabled."); cons_show("Sound enabled.");
win_set_beep(TRUE); prefs_set_beep(TRUE);
} else if (strcmp(inp, "/beep off") == 0) { } else if (strcmp(inp, "/beep off") == 0) {
cons_show("Sound disabled."); cons_show("Sound disabled.");
win_set_beep(FALSE); prefs_set_beep(FALSE);
} else { } else {
cons_show("Usage: /beep <on/off>"); cons_show("Usage: /beep <on/off>");
} }
@ -238,10 +239,10 @@ static gboolean _cmd_set_flash(const char * const inp)
{ {
if (strcmp(inp, "/flash on") == 0) { if (strcmp(inp, "/flash on") == 0) {
cons_show("Screen flash enabled."); cons_show("Screen flash enabled.");
status_bar_set_flash(TRUE); prefs_set_flash(TRUE);
} else if (strcmp(inp, "/flash off") == 0) { } else if (strcmp(inp, "/flash off") == 0) {
cons_show("Screen flash disabled."); cons_show("Screen flash disabled.");
status_bar_set_flash(FALSE); prefs_set_flash(FALSE);
} else { } else {
cons_show("Usage: /flash <on/off>"); cons_show("Usage: /flash <on/off>");
} }

View File

@ -23,25 +23,38 @@
#include <stdlib.h> #include <stdlib.h>
#include <glib.h> #include <glib.h>
#include "windows.h" static GKeyFile *prefs;
void prefs_load(void) void prefs_load(void)
{ {
GString *prefs_loc = g_string_new(getenv("HOME")); GString *prefs_loc = g_string_new(getenv("HOME"));
g_string_append(prefs_loc, "/.profanity"); g_string_append(prefs_loc, "/.profanity");
GKeyFile *g_prefs = g_key_file_new(); prefs = g_key_file_new();
g_key_file_load_from_file(g_prefs, prefs_loc->str, g_key_file_load_from_file(prefs, prefs_loc->str, G_KEY_FILE_NONE, NULL);
G_KEY_FILE_NONE, NULL);
gboolean beep = g_key_file_get_boolean(g_prefs, "ui", "beep", NULL);
gboolean flash = g_key_file_get_boolean(g_prefs, "ui", "flash", NULL);
win_set_beep(beep);
status_bar_set_flash(flash);
// g_key_file_set_string(g_prefs, "settings", "somekey2", "someothervalue"); // g_key_file_set_string(g_prefs, "settings", "somekey2", "someothervalue");
// gsize g_data_len; // gsize g_data_len;
// char *g_prefs_data = g_key_file_to_data(g_prefs, &g_data_len, NULL); // char *g_prefs_data = g_key_file_to_data(g_prefs, &g_data_len, NULL);
// g_file_set_contents("/home/james/.profanity", g_prefs_data, g_data_len, NULL); // g_file_set_contents("/home/james/.profanity", g_prefs_data, g_data_len, NULL);
} }
gboolean prefs_get_beep(void)
{
return g_key_file_get_boolean(prefs, "ui", "beep", NULL);
}
void prefs_set_beep(gboolean value)
{
g_key_file_set_boolean(prefs, "ui", "beep", value);
}
gboolean prefs_get_flash(void)
{
return g_key_file_get_boolean(prefs, "ui", "flash", NULL);
}
void prefs_set_flash(gboolean value)
{
g_key_file_set_boolean(prefs, "ui", "flash", value);
}

View File

@ -23,6 +23,13 @@
#ifndef PREFERENCES_H #ifndef PREFERENCES_H
#define PREFERENCES_H #define PREFERENCES_H
#include <glib.h>
void prefs_load(void); void prefs_load(void);
gboolean prefs_get_beep(void);
void prefs_set_beep(gboolean value);
gboolean prefs_get_flash(void);
void prefs_set_flash(gboolean value);
#endif #endif

View File

@ -64,11 +64,11 @@ void profanity_run(void)
void profanity_init(const int disable_tls) void profanity_init(const int disable_tls)
{ {
prefs_load();
log_init(); log_init();
gui_init(); gui_init();
jabber_init(disable_tls); jabber_init(disable_tls);
command_init(); command_init();
prefs_load();
atexit(_profanity_shutdown); atexit(_profanity_shutdown);
} }

View File

@ -24,8 +24,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <ncurses.h> #include <ncurses.h>
#include "windows.h" #include "windows.h"
#include "util.h" #include "util.h"
#include "preferences.h"
static WINDOW *status_bar; static WINDOW *status_bar;
static char *message = NULL; static char *message = NULL;
@ -35,9 +37,6 @@ static int is_new[9];
static int dirty; static int dirty;
static char curr_time[80]; static char curr_time[80];
// allow flash?
static int do_flash = FALSE;
static void _status_bar_update_time(void); static void _status_bar_update_time(void);
void create_status_bar(void) void create_status_bar(void)
@ -161,17 +160,12 @@ void status_bar_new(const int win)
wattroff(status_bar, COLOR_PAIR(3)); wattroff(status_bar, COLOR_PAIR(3));
wattroff(status_bar, A_BLINK); wattroff(status_bar, A_BLINK);
if (do_flash == TRUE) if (prefs_get_flash())
flash(); flash();
dirty = TRUE; dirty = TRUE;
} }
void status_bar_set_flash(int val)
{
do_flash = val;
}
void status_bar_get_password(void) void status_bar_get_password(void)
{ {
status_bar_print_message("Enter password:"); status_bar_print_message("Enter password:");

View File

@ -29,6 +29,7 @@
#include "windows.h" #include "windows.h"
#include "util.h" #include "util.h"
#include "contact.h" #include "contact.h"
#include "preferences.h"
#define CONS_WIN_TITLE "_cons" #define CONS_WIN_TITLE "_cons"
#define PAD_SIZE 200 #define PAD_SIZE 200
@ -49,9 +50,6 @@ static int dirty;
// max columns for main windows, never resize below // max columns for main windows, never resize below
static int max_cols = 0; static int max_cols = 0;
// allow beep?
static int do_beep = FALSE;
static void _create_windows(void); static void _create_windows(void);
static int _find_prof_win_index(const char * const contact); static int _find_prof_win_index(const char * const contact);
static int _new_prof_win(const char * const contact); static int _new_prof_win(const char * const contact);
@ -156,11 +154,6 @@ int win_in_chat(void)
(strcmp(_wins[_curr_prof_win].from, "") != 0)); (strcmp(_wins[_curr_prof_win].from, "") != 0));
} }
void win_set_beep(int val)
{
do_beep = val;
}
char *win_get_recipient(void) char *win_get_recipient(void)
{ {
struct prof_win current = _wins[_curr_prof_win]; struct prof_win current = _wins[_curr_prof_win];
@ -192,7 +185,7 @@ void win_show_incomming_msg(const char * const from, const char * const message)
_cons_show_incoming_message(short_from, win_index); _cons_show_incoming_message(short_from, win_index);
} }
if (do_beep == TRUE) if (prefs_get_beep())
beep(); beep();
} }

View File

@ -67,7 +67,6 @@ void win_contact_online(const char * const from, const char * const show,
void win_contact_offline(const char * const from, const char * const show, void win_contact_offline(const char * const from, const char * const show,
const char * const status); const char * const status);
void win_disconnected(void); void win_disconnected(void);
void win_set_beep(int val);
// console window actions // console window actions
void cons_help(void); void cons_help(void);
@ -87,7 +86,6 @@ void status_bar_inactive(const int win);
void status_bar_active(const int win); void status_bar_active(const int win);
void status_bar_new(const int win); void status_bar_new(const int win);
void status_bar_update_time(void); void status_bar_update_time(void);
void status_bar_set_flash(int val);
// input window actions // input window actions
void inp_get_char(int *ch, char *input, int *size); void inp_get_char(int *ch, char *input, int *size);