예제 #1
0
void
prof_run(const int disable_tls, char *log_level, char *account_name)
{
    _init(disable_tls, log_level);
    log_info("Starting main event loop");
    inp_non_block();
    GTimer *timer = g_timer_new();
    gboolean cmd_result = TRUE;
    jabber_conn_status_t conn_status = jabber_get_connection_status();

    char inp[INP_WIN_MAX];
    int size = 0;

    ui_update_screen();

    if (account_name != NULL) {
      char *cmd = "/connect";
      snprintf(inp, sizeof(inp), "%s %s", cmd, account_name);
      process_input(inp);
    } else if (prefs_get_string(PREF_CONNECT_ACCOUNT) != NULL) {
      char *cmd = "/connect";
      snprintf(inp, sizeof(inp), "%s %s", cmd, prefs_get_string(PREF_CONNECT_ACCOUNT));
      process_input(inp);
    }

    while(cmd_result == TRUE) {
        wint_t ch = ERR;
        size = 0;

        while(ch != '\n') {
            conn_status = jabber_get_connection_status();
            if (conn_status == JABBER_CONNECTED) {
                _handle_idle_time();
            }

            gdouble elapsed = g_timer_elapsed(timer, NULL);

            gint remind_period = prefs_get_notify_remind();
            if (remind_period > 0 && elapsed >= remind_period) {
                notify_remind();
                g_timer_start(timer);
            }

            ui_handle_special_keys(&ch, inp, size);
            ui_update_screen();
            jabber_process_events();

            ch = inp_get_char(inp, &size);
            if (ch != ERR) {
                ui_reset_idle_time();
            }
        }

        inp[size++] = '\0';
        cmd_result = process_input(inp);
    }

    g_timer_destroy(timer);
}
예제 #2
0
static void
_check_autoaway()
{
    jabber_conn_status_t conn_status = jabber_get_connection_status();
    if (conn_status != JABBER_CONNECTED) {
        return;
    }

    gint prefs_time = prefs_get_autoaway_time() * 60000;
    unsigned long idle_ms = ui_get_idle_time();
    char *pref_autoaway_mode = prefs_get_string(PREF_AUTOAWAY_MODE);

    if (!idle) {
        resource_presence_t current_presence = accounts_get_last_presence(jabber_get_account_name());
        if ((current_presence == RESOURCE_ONLINE) || (current_presence == RESOURCE_CHAT)) {
            if (idle_ms >= prefs_time) {
                idle = TRUE;
                char *pref_autoaway_message = prefs_get_string(PREF_AUTOAWAY_MESSAGE);

                // handle away mode
                if (strcmp(pref_autoaway_mode, "away") == 0) {
                    presence_update(RESOURCE_AWAY, pref_autoaway_message, 0);
                    ui_auto_away();

                // handle idle mode
                } else if (strcmp(pref_autoaway_mode, "idle") == 0) {
                    presence_update(RESOURCE_ONLINE, pref_autoaway_message, idle_ms / 1000);
                }

                prefs_free_string(pref_autoaway_message);
            }
        }

    } else {
        if (idle_ms < prefs_time) {
            idle = FALSE;

            // handle check
            if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) {
                if (strcmp(pref_autoaway_mode, "away") == 0) {
                    presence_update(RESOURCE_ONLINE, NULL, 0);
                    ui_end_auto_away();
                } else if (strcmp(pref_autoaway_mode, "idle") == 0) {
                    presence_update(RESOURCE_ONLINE, NULL, 0);
                    ui_titlebar_presence(CONTACT_ONLINE);
                }
            }
        }
    }

    prefs_free_string(pref_autoaway_mode);
}
예제 #3
0
void
handle_incoming_message(char *from, char *message, gboolean priv)
{
#ifdef HAVE_LIBOTR
    gboolean was_decrypted = FALSE;
    char *newmessage;
    if (!priv) {
        newmessage = otr_decrypt_message(from, message, &was_decrypted);

        // internal OTR message
        if (newmessage == NULL) {
            return;
        }
    } else {
        newmessage = message;
    }

    ui_incoming_msg(from, newmessage, NULL, priv);
    ui_current_page_off();

    if (prefs_get_boolean(PREF_CHLOG) && !priv) {
        Jid *from_jid = jid_create(from);
        const char *jid = jabber_get_fulljid();
        Jid *jidp = jid_create(jid);

        if (!was_decrypted || (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0)) {
            chat_log_chat(jidp->barejid, from_jid->barejid, newmessage, PROF_IN_LOG, NULL);
        } else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) {
            chat_log_chat(jidp->barejid, from_jid->barejid, "[redacted]", PROF_IN_LOG, NULL);
        }

        jid_destroy(jidp);
        jid_destroy(from_jid);
    }

    if (!priv)
        otr_free_message(newmessage);
#else
    ui_incoming_msg(from, message, NULL, priv);
    ui_current_page_off();

    if (prefs_get_boolean(PREF_CHLOG) && !priv) {
        Jid *from_jid = jid_create(from);
        const char *jid = jabber_get_fulljid();
        Jid *jidp = jid_create(jid);
        chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL);
        jid_destroy(jidp);
        jid_destroy(from_jid);
    }
#endif
}
예제 #4
0
void
status_bar_print_message(const char * const msg)
{
    werase(status_bar);

    if (message) {
        free(message);
    }
    message = strdup(msg);

    char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
    gchar *date_fmt = g_date_time_format(last_time, time_pref);
    assert(date_fmt != NULL);
    size_t len = strlen(date_fmt);
    g_free(date_fmt);
    if (g_strcmp0(time_pref, "") != 0) {
        mvwprintw(status_bar, 0, 5 + len, message);
    } else {
        mvwprintw(status_bar, 0, 1, message);
    }
    prefs_free_string(time_pref);

    int cols = getmaxx(stdscr);
    int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);

    wattron(status_bar, bracket_attrs);
    mvwprintw(status_bar, 0, cols - 34, _active);
    mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
    wattroff(status_bar, bracket_attrs);

    _status_bar_draw();
}
예제 #5
0
static void
_status_bar_draw(void)
{
    if (last_time) {
        g_date_time_unref(last_time);
    }
    last_time = g_date_time_new_now_local();

    int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);

    char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
    if (g_strcmp0(time_pref, "off") != 0) {
        gchar *date_fmt = g_date_time_format(last_time, time_pref);
        assert(date_fmt != NULL);
        size_t len = strlen(date_fmt);
        wattron(status_bar, bracket_attrs);
        mvwaddch(status_bar, 0, 1, '[');
        wattroff(status_bar, bracket_attrs);
        mvwprintw(status_bar, 0, 2, date_fmt);
        wattron(status_bar, bracket_attrs);
        mvwaddch(status_bar, 0, 2 + len, ']');
        wattroff(status_bar, bracket_attrs);
        g_free(date_fmt);
    }
    prefs_free_string(time_pref);

    _update_win_statuses();
    wnoutrefresh(status_bar);
    inp_put_back();
}
예제 #6
0
void
status_bar_resize(void)
{
    int rows, cols;
    getmaxyx(stdscr, rows, cols);

    werase(status_bar);

    int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);

    mvwin(status_bar, rows-2, 0);
    wresize(status_bar, 1, cols);
    wbkgd(status_bar, theme_attrs(THEME_STATUS_TEXT));
    wattron(status_bar, bracket_attrs);
    mvwprintw(status_bar, 0, cols - 34, _active);
    mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
    wattroff(status_bar, bracket_attrs);

    if (message) {
        char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
        if (g_strcmp0(time_pref, "minutes") == 0) {
            mvwprintw(status_bar, 0, 10, message);
        } else if (g_strcmp0(time_pref, "seconds") == 0) {
            mvwprintw(status_bar, 0, 13, message);
        } else {
            mvwprintw(status_bar, 0, 1, message);
        }
    }
    if (last_time) {
        g_date_time_unref(last_time);
    }
    last_time = g_date_time_new_now_local();

    _status_bar_draw();
}
예제 #7
0
void
status_bar_print_message(const char * const msg)
{
    werase(status_bar);

    if (message) {
        free(message);
    }
    message = strdup(msg);

    char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR);
    if (g_strcmp0(time_pref, "minutes") == 0) {
        mvwprintw(status_bar, 0, 10, message);
    } else if (g_strcmp0(time_pref, "seconds") == 0) {
        mvwprintw(status_bar, 0, 13, message);
    } else {
        mvwprintw(status_bar, 0, 1, message);
    }

    int cols = getmaxx(stdscr);
    int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET);

    wattron(status_bar, bracket_attrs);
    mvwprintw(status_bar, 0, cols - 34, _active);
    mvwprintw(status_bar, 0, cols - 34 + ((current - 1) * 3), bracket);
    wattroff(status_bar, bracket_attrs);

    _status_bar_draw();
}
예제 #8
0
/* Must free the returned string yourself */
gchar *charset_to_utf8 (const gchar *str)
{
    gchar *charset;  /* From prefs */
    const gchar *locale_charset; /* Used if prefs doesn't have a charset */
    gchar *result;

    if (str == NULL) return NULL;  /* sanity */
    charset = charset_check_auto (str);
    if (charset)
    {
	g_free(auto_charset);
	auto_charset = g_strdup(charset);
    }
    else
    {
	charset = prefs_get_string("charset");
	if (!charset || !strlen (charset))
	{    /* use standard locale charset */
	    g_free(charset);
	    g_get_charset (&locale_charset);
	    charset = g_strdup(locale_charset);
	}
    }

    result = charset_to_charset (charset, "UTF-8", str);
    g_free(charset);
    return result;
}
예제 #9
0
/* Must free the returned string yourself */
gchar *charset_track_charset_from_utf8 (Track *s, const gchar *str)
{
    gchar *charset;
    const gchar *locale_charset;
    gchar *result;
    ExtraTrackData *etd;

    g_return_val_if_fail (s, NULL);
    g_return_val_if_fail (s->userdata, NULL);

    if (str == NULL) return NULL;  /* sanity */

    etd = s->userdata;

    if (etd->charset && strlen (etd->charset))
	   charset = g_strdup(etd->charset);
    else
	charset = prefs_get_string("charset");

    if (!charset || !strlen (charset))
    {    /* use standard locale charset */
	g_free(charset);
	g_get_charset (&locale_charset);
	charset = g_strdup(locale_charset);
    }

    result = charset_to_charset ("UTF-8", charset, str);
    g_free(charset);
    return result;
}
예제 #10
0
static void
_win_print_wrapped(WINDOW *win, const char * const message)
{
    int linei = 0;
    int wordi = 0;
    char *word = malloc(strlen(message) + 1);

    char *time_pref = prefs_get_string(PREF_TIME);
    int indent = 0;
    if (g_strcmp0(time_pref, "minutes") == 0) {
        indent = 8;
    } else if (g_strcmp0(time_pref, "seconds") == 0) {
        indent = 11;
    }
    free(time_pref);

    while (message[linei] != '\0') {
        if (message[linei] == ' ') {
            waddch(win, ' ');
            linei++;
        } else if (message[linei] == '\n') {
            waddch(win, '\n');
            _win_indent(win, indent);
            linei++;
        } else {
            wordi = 0;
            while (message[linei] != ' ' && message[linei] != '\n' && message[linei] != '\0') {
                word[wordi++] = message[linei++];
            }
            word[wordi] = '\0';

            int curx = getcurx(win);
            int maxx = getmaxx(win);

            // word larger than line
            if (strlen(word) > (maxx - indent)) {
                int i;
                for (i = 0; i < wordi; i++) {
                    curx = getcurx(win);
                    if (curx < indent) {
                        _win_indent(win, indent);
                    }
                    waddch(win, word[i]);
                }
            } else {
                if (curx + strlen(word) > maxx) {
                    waddch(win, '\n');
                    _win_indent(win, indent);
                }
                if (curx < indent) {
                    _win_indent(win, indent);
                }
                wprintw(win, "%s", word);
            }
        }
    }

    free(word);
}
예제 #11
0
static void
_init(char *log_level)
{
    setlocale(LC_ALL, "");
    // ignore SIGPIPE
    signal(SIGPIPE, SIG_IGN);
    signal(SIGINT, SIG_IGN);
    signal(SIGTSTP, SIG_IGN);
    signal(SIGWINCH, ui_sigwinch_handler);
    if (pthread_mutex_init(&lock, NULL) != 0) {
        log_error("Mutex init failed");
        exit(1);
    }
    pthread_mutex_lock(&lock);
    files_create_directories();
    log_level_t prof_log_level = log_level_from_string(log_level);
    prefs_load();
    log_init(prof_log_level);
    log_stderr_init(PROF_LEVEL_ERROR);
    if (strcmp(PACKAGE_STATUS, "development") == 0) {
#ifdef HAVE_GIT_VERSION
            log_info("Starting Profanity (%sdev.%s.%s)...", PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
            log_info("Starting Profanity (%sdev)...", PACKAGE_VERSION);
#endif
    } else {
        log_info("Starting Profanity (%s)...", PACKAGE_VERSION);
    }
    chat_log_init();
    groupchat_log_init();
    accounts_load();
    char *theme = prefs_get_string(PREF_THEME);
    theme_init(theme);
    prefs_free_string(theme);
    ui_init();
    session_init();
    cmd_init();
    log_info("Initialising contact list");
    muc_init();
    tlscerts_init();
    scripts_init();
#ifdef HAVE_LIBOTR
    otr_init();
#endif
#ifdef HAVE_LIBGPGME
    p_gpg_init();
#endif
#ifdef HAVE_OMEMO
    omemo_init();
#endif
    atexit(_shutdown);
    plugins_init();
#ifdef HAVE_GTK
    tray_init();
#endif
    inp_nonblocking(TRUE);
    ui_resize();
}
예제 #12
0
void
ui_contact_offline(char *barejid, char *resource, char *status)
{
    char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
    char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
    Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
    PContact contact = roster_get_contact(barejid);
    if (p_contact_subscription(contact)) {
        if (strcmp(p_contact_subscription(contact), "none") != 0) {

            // show in console if "all"
            if (g_strcmp0(show_console, "all") == 0) {
                cons_show_contact_offline(contact, resource, status);

            // show in console of "online"
            } else if (g_strcmp0(show_console, "online") == 0) {
                cons_show_contact_offline(contact, resource, status);
            }

            // show in chat win if "all"
            if (g_strcmp0(show_chat_win, "all") == 0) {
                ProfChatWin *chatwin = wins_get_chat(barejid);
                if (chatwin) {
                    chatwin_contact_offline(chatwin, resource, status);
                }

            // show in chat win if "online" and presence online
            } else if (g_strcmp0(show_chat_win, "online") == 0) {
                ProfChatWin *chatwin = wins_get_chat(barejid);
                if (chatwin) {
                    chatwin_contact_offline(chatwin, resource, status);
                }
            }
        }
    }

    ProfChatWin *chatwin = wins_get_chat(barejid);
    if (chatwin && chatwin->resource_override && (g_strcmp0(resource, chatwin->resource_override) == 0)) {
        FREE_SET_NULL(chatwin->resource_override);
    }

    prefs_free_string(show_console);
    prefs_free_string(show_chat_win);
    jid_destroy(jid);
}
예제 #13
0
void
sample_load_cb(GtkWidget * widget, gpointer data)
{

  GtkWidget *dialog;
  gchar load_current_file [512];
  gint win_width, win_height;
  GSList *filenames, *list;

  filenames = list = NULL;

  win_width = gdk_screen_width () / 2;
  win_height = gdk_screen_height () / 2;

  dialog = gtk_file_chooser_dialog_new (_("Sweep: Open Files"),
				      data,
				      GTK_FILE_CHOOSER_ACTION_OPEN,
				      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				      NULL);

  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
  gtk_widget_set_size_request (dialog, win_width, win_height);
  gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);

  sweep_set_window_icon (GTK_WINDOW(dialog));
  attach_window_close_accel(GTK_WINDOW(dialog));

  prefs_get_string (LAST_LOAD_KEY, load_current_file, sizeof (load_current_file), "");

  if (load_current_file [0]) {
      gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(dialog), load_current_file);
  }

  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {

   filenames = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER(dialog));

   for (list = filenames; list; list = list->next) {

     if (list->data) {
       sample_load ((gchar *)list->data);
       g_free (list->data);
     }
  }

  if (filenames)
    g_slist_free(filenames);

  } else {
    /* do nothing so exit */
     sample_bank_remove(NULL);
  }

  gtk_widget_destroy (dialog);
}
예제 #14
0
void
cons_theme_setting(void)
{
    gchar *theme = prefs_get_string(PREF_THEME);
    if (theme == NULL) {
        cons_show("Theme (/theme)               : default");
    } else {
        cons_show("Theme (/theme)               : %s", theme);
    }
}
예제 #15
0
void
handle_contact_online(char *barejid, Resource *resource,
    GDateTime *last_activity)
{
    gboolean updated = roster_update_presence(barejid, resource, last_activity);

    if (updated) {
        char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
        char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
        PContact contact = roster_get_contact(barejid);
        if (p_contact_subscription(contact) != NULL) {
            if (strcmp(p_contact_subscription(contact), "none") != 0) {

                // show in console if "all"
                if (g_strcmp0(show_console, "all") == 0) {
                    cons_show_contact_online(contact, resource, last_activity);

                // show in console of "online" and presence online
                } else if (g_strcmp0(show_console, "online") == 0 &&
                        resource->presence == RESOURCE_ONLINE) {
                    cons_show_contact_online(contact, resource, last_activity);

                }

                // show in chat win if "all"
                if (g_strcmp0(show_chat_win, "all") == 0) {
                    ui_chat_win_contact_online(contact, resource, last_activity);

                // show in char win if "online" and presence online
                } else if (g_strcmp0(show_chat_win, "online") == 0 &&
                        resource->presence == RESOURCE_ONLINE) {
                    ui_chat_win_contact_online(contact, resource, last_activity);
                }
            }
        }
        prefs_free_string(show_console);
        prefs_free_string(show_chat_win);
    }

    ui_roster();
}
예제 #16
0
void
ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity)
{
    char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
    char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
    PContact contact = roster_get_contact(barejid);

    // show nothing
    if (g_strcmp0(p_contact_subscription(contact), "none") == 0) {
        free(show_console);
        free(show_chat_win);
        return;
    }

    // show in console if "all"
    if (g_strcmp0(show_console, "all") == 0) {
        cons_show_contact_online(contact, resource, last_activity);

    // show in console of "online" and presence online
    } else if (g_strcmp0(show_console, "online") == 0 && resource->presence == RESOURCE_ONLINE) {
        cons_show_contact_online(contact, resource, last_activity);
    }

    // show in chat win if "all"
    if (g_strcmp0(show_chat_win, "all") == 0) {
        ProfChatWin *chatwin = wins_get_chat(barejid);
        if (chatwin) {
            chatwin_contact_online(chatwin, resource, last_activity);
        }

    // show in char win if "online" and presence online
    } else if (g_strcmp0(show_chat_win, "online") == 0 && resource->presence == RESOURCE_ONLINE) {
        ProfChatWin *chatwin = wins_get_chat(barejid);
        if (chatwin) {
            chatwin_contact_online(chatwin, resource, last_activity);
        }
    }

    free(show_console);
    free(show_chat_win);
}
예제 #17
0
void
handle_room_member_offline(const char * const room, const char * const nick,
    const char * const show, const char * const status)
{
    muc_remove_from_roster(room, nick);

    char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
    if (g_strcmp0(muc_status_pref, "none") != 0) {
        ui_room_member_offline(room, nick);
    }
    prefs_free_string(muc_status_pref);
}
예제 #18
0
파일: otr.c 프로젝트: BlueMonday/profanity
prof_otrpolicy_t
otr_get_policy(const char *const recipient)
{
    char *account_name = jabber_get_account_name();
    ProfAccount *account = accounts_get_account(account_name);
    // check contact specific setting
    if (g_list_find_custom(account->otr_manual, recipient, (GCompareFunc)g_strcmp0)) {
        account_free(account);
        return PROF_OTRPOLICY_MANUAL;
    }
    if (g_list_find_custom(account->otr_opportunistic, recipient, (GCompareFunc)g_strcmp0)) {
        account_free(account);
        return PROF_OTRPOLICY_OPPORTUNISTIC;
    }
    if (g_list_find_custom(account->otr_always, recipient, (GCompareFunc)g_strcmp0)) {
        account_free(account);
        return PROF_OTRPOLICY_ALWAYS;
    }

    // check default account setting
    if (account->otr_policy) {
        prof_otrpolicy_t result;
        if (g_strcmp0(account->otr_policy, "manual") == 0) {
            result = PROF_OTRPOLICY_MANUAL;
        }
        if (g_strcmp0(account->otr_policy, "opportunistic") == 0) {
            result = PROF_OTRPOLICY_OPPORTUNISTIC;
        }
        if (g_strcmp0(account->otr_policy, "always") == 0) {
            result = PROF_OTRPOLICY_ALWAYS;
        }
        account_free(account);
        return result;
    }
    account_free(account);

    // check global setting
    char *pref_otr_policy = prefs_get_string(PREF_OTR_POLICY);

    // pref defaults to manual
    prof_otrpolicy_t result = PROF_OTRPOLICY_MANUAL;

    if (strcmp(pref_otr_policy, "opportunistic") == 0) {
        result = PROF_OTRPOLICY_OPPORTUNISTIC;
    } else if (strcmp(pref_otr_policy, "always") == 0) {
        result = PROF_OTRPOLICY_ALWAYS;
    }

    prefs_free_string(pref_otr_policy);

    return result;
}
예제 #19
0
static void
_init(char *log_level)
{
    setlocale(LC_ALL, "");
    // ignore SIGPIPE
    signal(SIGPIPE, SIG_IGN);
    signal(SIGINT, SIG_IGN);
    signal(SIGTSTP, SIG_IGN);
    signal(SIGWINCH, ui_sigwinch_handler);
    _create_directories();
    log_level_t prof_log_level = log_level_from_string(log_level);
    prefs_load();
    log_init(prof_log_level);
    log_stderr_init(PROF_LEVEL_ERROR);
    if (strcmp(PROF_PACKAGE_STATUS, "development") == 0) {
#ifdef PROF_HAVE_GIT_VERSION
            log_info("Starting Profanity (%sdev.%s.%s)...", PROF_PACKAGE_VERSION, PROF_GIT_BRANCH, PROF_GIT_REVISION);
#else
            log_info("Starting Profanity (%sdev)...", PROF_PACKAGE_VERSION);
#endif
    } else {
        log_info("Starting Profanity (%s)...", PROF_PACKAGE_VERSION);
    }
    chat_log_init();
    groupchat_log_init();
    accounts_load();
    char *theme = prefs_get_string(PREF_THEME);
    theme_init(theme);
    prefs_free_string(theme);
    ui_init();
    jabber_init();
    cmd_init();
    log_info("Initialising contact list");
    muc_init();
    tlscerts_init();
    scripts_init();
#ifdef PROF_HAVE_LIBOTR
    otr_init();
#endif
#ifdef PROF_HAVE_LIBGPGME
    p_gpg_init();
#endif
    atexit(_shutdown);
    plugins_init();
#ifdef PROF_HAVE_GTK
    if (gtk_ready) {
        log_debug("Building GTK icon");
        create_tray();
    }
#endif
    inp_nonblocking(TRUE);
}
예제 #20
0
void
sv_ev_room_occupant_offline(const char * const room, const char * const nick,
    const char * const show, const char * const status)
{
    muc_roster_remove(room, nick);

    char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
    if (g_strcmp0(muc_status_pref, "none") != 0) {
        ui_room_member_offline(room, nick);
    }
    prefs_free_string(muc_status_pref);
    occupantswin_occupants(room);
}
예제 #21
0
void
handle_contact_offline(char *barejid, char *resource, char *status)
{
    gboolean updated = roster_contact_offline(barejid, resource, status);

    if (resource != NULL && updated) {
        char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
        char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
        Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
        PContact contact = roster_get_contact(barejid);
        if (p_contact_subscription(contact) != NULL) {
            if (strcmp(p_contact_subscription(contact), "none") != 0) {

                // show in console if "all"
                if (g_strcmp0(show_console, "all") == 0) {
                    cons_show_contact_offline(contact, resource, status);

                // show in console of "online"
                } else if (g_strcmp0(show_console, "online") == 0) {
                    cons_show_contact_offline(contact, resource, status);
                }

                // show in chat win if "all"
                if (g_strcmp0(show_chat_win, "all") == 0) {
                    ui_chat_win_contact_offline(contact, resource, status);

                // show in char win if "online" and presence online
                } else if (g_strcmp0(show_chat_win, "online") == 0) {
                    ui_chat_win_contact_offline(contact, resource, status);
                }
            }
        }
        prefs_free_string(show_console);
        prefs_free_string(show_chat_win);
        jid_destroy(jid);
    }

    ui_roster();
}
예제 #22
0
static void
_connect_default(const char * const account)
{
    if (account) {
        cmd_execute_connect(account);
    } else {
        char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT);
        if (pref_connect_account) {
            cmd_execute_connect(pref_connect_account);
            prefs_free_string(pref_connect_account);
        }
    }
}
예제 #23
0
static void
_connect_default(const char *const account)
{
    ProfWin *window = wins_get_current();
    if (account) {
        cmd_execute_connect(window, account);
    } else {
        char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT);
        if (pref_connect_account) {
            cmd_execute_connect(window, pref_connect_account);
            prefs_free_string(pref_connect_account);
        }
    }
}
예제 #24
0
void cmd_otr_log_off_disables_logging(void **state)
{
    gchar *args[] = { "log", "off", NULL };
    prefs_set_string(PREF_OTR_LOG, "on");
    prefs_set_boolean(PREF_CHLOG, TRUE);

    expect_cons_show("OTR message logging disabled.");

    gboolean result = cmd_otr(NULL, CMD_OTR, args);
    char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);

    assert_true(result);
    assert_string_equal("off", pref_otr_log);
}
예제 #25
0
void cmd_otr_redact_redacts_logging(void **state)
{
    gchar *args[] = { "log", "redact", NULL };
    prefs_set_string(PREF_OTR_LOG, "on");
    prefs_set_boolean(PREF_CHLOG, TRUE);

    expect_cons_show("OTR messages will be logged as '[redacted]'.");

    gboolean result = cmd_otr(NULL, CMD_OTR, args);
    char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);

    assert_true(result);
    assert_string_equal("redact", pref_otr_log);
}
예제 #26
0
void
rosterwin_roster(void)
{
    ProfWin *console = wins_get_console();
    if (console) {
        ProfLayoutSplit *layout = (ProfLayoutSplit*)console->layout;
        assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);

       char *by = prefs_get_string(PREF_ROSTER_BY);
        if (g_strcmp0(by, "presence") == 0) {
            werase(layout->subwin);
            _rosterwin_contacts_by_presence(layout, "chat", " -Available for chat");
            _rosterwin_contacts_by_presence(layout, "online", " -Online");
            _rosterwin_contacts_by_presence(layout, "away", " -Away");
            _rosterwin_contacts_by_presence(layout, "xa", " -Extended Away");
            _rosterwin_contacts_by_presence(layout, "dnd", " -Do not disturb");
            if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) {
                _rosterwin_contacts_by_presence(layout, "offline", " -Offline");
            }
        } else if (g_strcmp0(by, "group") == 0) {
            werase(layout->subwin);
            GSList *groups = roster_get_groups();
            GSList *curr_group = groups;
            while (curr_group) {
                _rosterwin_contacts_by_group(layout, curr_group->data);
                curr_group = g_slist_next(curr_group);
            }
            g_slist_free_full(groups, free);
            _rosterwin_contacts_by_no_group(layout);
        } else {
            GSList *contacts = roster_get_contacts();
            if (contacts) {
                werase(layout->subwin);

                wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
                win_printline_nowrap(layout->subwin, " -Roster");
                wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));

                GSList *curr_contact = contacts;
                while (curr_contact) {
                    PContact contact = curr_contact->data;
                    _rosterwin_contact(layout, contact);
                    curr_contact = g_slist_next(curr_contact);
                }
            }
            g_slist_free(contacts);
        }
        free(by);
    }
}
예제 #27
0
void
cons_autoaway_setting(void)
{
    if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "off") == 0) {
        cons_show("Autoaway (/autoaway mode)            : OFF");
    } else {
        cons_show("Autoaway (/autoaway mode)            : %s", prefs_get_string(PREF_AUTOAWAY_MODE));
    }

    cons_show("Autoaway minutes (/autoaway time)    : %d minutes", prefs_get_autoaway_time());

    if ((prefs_get_string(PREF_AUTOAWAY_MESSAGE) == NULL) ||
            (strcmp(prefs_get_string(PREF_AUTOAWAY_MESSAGE), "") == 0)) {
        cons_show("Autoaway message (/autoaway message) : OFF");
    } else {
        cons_show("Autoaway message (/autoaway message) : \"%s\"", prefs_get_string(PREF_AUTOAWAY_MESSAGE));
    }

    if (prefs_get_boolean(PREF_AUTOAWAY_CHECK)) {
        cons_show("Autoaway check (/autoaway check)     : ON");
    } else {
        cons_show("Autoaway check (/autoaway check)     : OFF");
    }
}
예제 #28
0
void
handle_room_member_presence(const char * const room,
    const char * const nick, const char * const show,
    const char * const status)
{
    gboolean updated = muc_add_to_roster(room, nick, show, status);

    if (updated) {
        char *muc_status_pref = prefs_get_string(PREF_STATUSES_MUC);
        if (g_strcmp0(muc_status_pref, "all") == 0) {
            ui_room_member_presence(room, nick, show, status);
        }
        prefs_free_string(muc_status_pref);
    }
}
예제 #29
0
파일: main.c 프로젝트: eaglexmw/pnmixer
/**
 * Creates the volume popup window.
 */
void
create_popup_window(void)
{
	GtkBuilder *builder;
	GError *error = NULL;
	gchar *uifile;
	gchar *slider_orientation;

	slider_orientation = prefs_get_string("SliderOrientation", "vertical");

	if (!g_strcmp0(slider_orientation, "horizontal"))
		uifile = get_ui_file(UI_FILE_POPUP_VOLUME_HORIZONTAL);
	else
		uifile = get_ui_file(UI_FILE_POPUP_VOLUME_VERTICAL);

	g_free(slider_orientation);

	if (!uifile) {
		report_error(_
			     ("Can't find the volume popup window interface file. "
			      "Please ensure PNMixer is installed correctly. Exiting."));
		exit(1);
	}

	DEBUG_PRINT("Loading volume popup ui from '%s'", uifile);
	builder = gtk_builder_new();
	if (!gtk_builder_add_from_file(builder, uifile, &error)) {
		g_warning("%s", error->message);
		report_error(error->message);
		exit(1);
	}

	g_free(uifile);

	vol_adjustment = GTK_ADJUSTMENT(gtk_builder_get_object(builder,
					"vol_scale_adjustment"));
	/* get original adjustments */
	get_current_levels();

	vol_scale = GTK_WIDGET(gtk_builder_get_object(builder, "vol_scale"));
	mute_check_popup_window = GTK_WIDGET(gtk_builder_get_object(builder, "mute_check_popup_window"));
	popup_window = GTK_WIDGET(gtk_builder_get_object(builder, "popup_window"));

	gtk_builder_connect_signals(builder, NULL);
	g_object_unref(G_OBJECT(builder));

	gtk_widget_grab_focus(vol_scale);
}
예제 #30
0
int prefs_get_int(prefs_handle_t *prefs, const char *section, const char *key, int default_val)
{
	char str[1024];
	const char *res;
	int val;

	assert(prefs);
	assert(key);
	assert(section);

	snprintf(str, sizeof (str), "%d", default_val);
	res = prefs_get_string(prefs, section, key, str);
	if (sscanf(res, "%d", &val) != 1)
		return default_val;
	return val;
}