Exemplo n.º 1
0
static void general_load (PluginHandle * plugin)
{
    GList * node = g_list_find_custom (loaded_general_plugins, plugin,
     (GCompareFunc) general_find_cb);
    if (node != NULL)
        return;

    AUDDBG ("Loading %s.\n", plugin_get_name (plugin));
    GeneralPlugin * gp = plugin_get_header (plugin);
    g_return_if_fail (gp != NULL);

    LoadedGeneral * general = g_slice_new (LoadedGeneral);
    general->plugin = plugin;
    general->gp = gp;
    general->widget = NULL;

    if (gp->get_widget != NULL)
        general->widget = gp->get_widget ();

    if (general->widget != NULL)
    {
        AUDDBG ("Adding %s to interface.\n", plugin_get_name (plugin));
        g_signal_connect (general->widget, "destroy", (GCallback)
         gtk_widget_destroyed, & general->widget);
        interface_add_plugin_widget (plugin, general->widget);
    }

    loaded_general_plugins = g_list_prepend (loaded_general_plugins, general);
}
Exemplo n.º 2
0
static void start_single (int type)
{
    PluginHandle * p;

    if ((p = find_enabled (type)) != NULL)
    {
        AUDDBG ("Starting selected %s plugin %s.\n", table[type].name,
         plugin_get_name (p));

        if (table[type].u.s.set_current (p))
            return;

        AUDDBG ("%s failed to start.\n", plugin_get_name (p));
        plugin_set_enabled (p, FALSE);
    }

    AUDDBG ("Probing for %s plugin.\n", table[type].name);

    if ((p = table[type].u.s.probe ()) == NULL)
    {
        fprintf (stderr, "FATAL: No %s plugin found.\n", table[type].name);
        exit (EXIT_FAILURE);
    }

    AUDDBG ("Starting %s.\n", plugin_get_name (p));
    plugin_set_enabled (p, TRUE);

    if (! table[type].u.s.set_current (p))
    {
        fprintf (stderr, "FATAL: %s failed to start.\n", plugin_get_name (p));
        plugin_set_enabled (p, FALSE);
        exit (EXIT_FAILURE);
    }
}
Exemplo n.º 3
0
static void set_plugin_list(PluginWindow *pluginwindow)
{
	GSList *plugins, *cur, *unloaded;
	const gchar *text;
	GtkListStore *store;
	GtkTreeIter iter;
	GtkTextBuffer *textbuf;
	GtkTextIter start_iter, end_iter;
	GtkTreeSelection *selection;

	plugins = plugin_get_list();
	unloaded = plugin_get_unloaded_list();

	store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW
				(pluginwindow->plugin_list_view)));
 	gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),
                                             0, GTK_SORT_ASCENDING);
	gtk_list_store_clear(store);
	
	textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(pluginwindow->plugin_desc));
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(pluginwindow->plugin_desc), FALSE);
	gtk_text_view_set_editable(GTK_TEXT_VIEW(pluginwindow->plugin_desc), FALSE);
	gtk_text_buffer_get_start_iter(textbuf, &start_iter);
	gtk_text_buffer_get_end_iter(textbuf, &end_iter);
	gtk_text_buffer_delete(textbuf, &start_iter, &end_iter);
	gtk_widget_set_sensitive(pluginwindow->unload_btn, FALSE);

	for(cur = plugins; cur != NULL; cur = g_slist_next(cur)) {
		Plugin *plugin = (Plugin *) cur->data;

		gtk_list_store_append(store, &iter);
		text = plugin_get_name(plugin); 
		gtk_list_store_set(store, &iter,
				   PLUGINWINDOW_NAME, text,
				   PLUGINWINDOW_DATA, plugin,
				   PLUGINWINDOW_STYLE, PANGO_STYLE_NORMAL,
				   -1);
	}

	for(cur = unloaded; cur != NULL; cur = g_slist_next(cur)) {
		Plugin *plugin = (Plugin *) cur->data;

		gtk_list_store_append(store, &iter);
		text = plugin_get_name(plugin);
		gtk_list_store_set(store, &iter,
				   PLUGINWINDOW_NAME, text,
				   PLUGINWINDOW_DATA, plugin,
				   PLUGINWINDOW_STYLE, PANGO_STYLE_ITALIC,
				   -1);
	}

	selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pluginwindow->plugin_list_view));
	if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
		gtk_tree_selection_select_iter(selection, &iter);
		
	g_slist_free(plugins);
}
Exemplo n.º 4
0
static bool_t start_multi_cb (PluginHandle * p, void * type)
{
    AUDDBG ("Starting %s.\n", plugin_get_name (p));

    if (! table[GPOINTER_TO_INT (type)].u.m.start (p))
    {
        AUDDBG ("%s failed to start; disabling.\n", plugin_get_name (p));
        plugin_set_enabled (p, FALSE);
    }

    return TRUE;
}
Exemplo n.º 5
0
void interface_add_plugin_widget (PluginHandle * plugin, GtkWidget * widget)
{
    g_return_if_fail (current_interface);

    if (PLUGIN_HAS_FUNC (current_interface, run_gtk_plugin))
        current_interface->run_gtk_plugin (widget, plugin_get_name (plugin));
    else
    {
        GtkWidget * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title ((GtkWindow *) window, plugin_get_name (plugin));
        gtk_window_set_default_size ((GtkWindow *) window, 300, 200);
        gtk_container_add ((GtkContainer *) window, widget);
        g_signal_connect (window, "delete-event", (GCallback) delete_cb, plugin);
        gtk_widget_show_all (window);
    }
}
Exemplo n.º 6
0
static void effect_remove (PluginHandle * plugin)
{
    GList * node = g_list_find_custom (running_effects, plugin, (GCompareFunc)
     effect_find_cb);
    if (node == NULL)
        return;

    AUDDBG ("Removing %s without reset.\n", plugin_get_name (plugin));
    ((RunningEffect *) node->data)->remove_flag = TRUE;
}
Exemplo n.º 7
0
static void general_unload (PluginHandle * plugin)
{
    GList * node = g_list_find_custom (loaded_general_plugins, plugin,
     (GCompareFunc) general_find_cb);
    if (node == NULL)
        return;

    AUDDBG ("Unloading %s.\n", plugin_get_name (plugin));
    LoadedGeneral * general = node->data;
    loaded_general_plugins = g_list_delete_link (loaded_general_plugins, node);

    if (general->widget != NULL)
    {
        AUDDBG ("Removing %s from interface.\n", plugin_get_name (plugin));
        interface_remove_plugin_widget (plugin, general->widget);
        g_return_if_fail (general->widget == NULL); /* not destroyed? */
    }

    g_slice_free (LoadedGeneral, general);
}
Exemplo n.º 8
0
static bool_t enable_multi (int type, PluginHandle * p, bool_t enable)
{
    AUDDBG ("%sabling %s.\n", enable ? "En" : "Dis", plugin_get_name (p));
    plugin_set_enabled (p, enable);

    if (enable)
    {
        if (table[type].u.m.start && ! table[type].u.m.start (p))
        {
            fprintf (stderr, "%s failed to start.\n", plugin_get_name (p));
            plugin_set_enabled (p, FALSE);
            return FALSE;
        }
    }
    else
    {
        if (table[type].u.m.stop)
            table[type].u.m.stop (p);
    }

    return TRUE;
}
Exemplo n.º 9
0
static void effect_insert (PluginHandle * plugin, EffectPlugin * header)
{
    if (g_list_find_custom (running_effects, plugin, (GCompareFunc)
     effect_find_cb) != NULL)
        return;

    AUDDBG ("Adding %s without reset.\n", plugin_get_name (plugin));
    RunningEffect * effect = g_malloc (sizeof (RunningEffect));
    effect->plugin = plugin;
    effect->header = header;
    effect->remove_flag = FALSE;

    running_effects = g_list_insert_sorted (running_effects, effect,
     (GCompareFunc) effect_compare);
    GList * node = g_list_find (running_effects, effect);

    int channels, rate;
    if (node->prev != NULL)
    {
        RunningEffect * prev = node->prev->data;
        AUDDBG ("Added %s after %s.\n", plugin_get_name (plugin),
         plugin_get_name (prev->plugin));
        channels = prev->channels_returned;
        rate = prev->rate_returned;
    }
    else
    {
        AUDDBG ("Added %s as first effect.\n", plugin_get_name (plugin));
        channels = input_channels;
        rate = input_rate;
    }

    AUDDBG ("Starting %s at %d channels, %d Hz.\n", plugin_get_name (plugin),
     channels, rate);
    header->start (& channels, & rate);
    effect->channels_returned = channels;
    effect->rate_returned = rate;
}
Exemplo n.º 10
0
static bool_t enable_single (int type, PluginHandle * p)
{
    PluginHandle * old = table[type].u.s.get_current ();

    AUDDBG ("Switching from %s to %s.\n", plugin_get_name (old),
     plugin_get_name (p));
    plugin_set_enabled (old, FALSE);
    plugin_set_enabled (p, TRUE);

    if (table[type].u.s.set_current (p))
        return TRUE;

    fprintf (stderr, "%s failed to start; falling back to %s.\n",
     plugin_get_name (p), plugin_get_name (old));
    plugin_set_enabled (p, FALSE);
    plugin_set_enabled (old, TRUE);

    if (table[type].u.s.set_current (old))
        return FALSE;

    fprintf (stderr, "FATAL: %s failed to start.\n", plugin_get_name (old));
    plugin_set_enabled (old, FALSE);
    exit (EXIT_FAILURE);
}
Exemplo n.º 11
0
bool_t iface_plugin_set_current (PluginHandle * plugin)
{
    hook_call ("config save", NULL); /* tell interface to save layout */

    if (current_plugin != NULL)
    {
        AUDDBG ("Unloading plugin widgets.\n");
        general_cleanup ();

        AUDDBG ("Unloading visualizers.\n");
        vis_cleanup ();

        AUDDBG ("Unloading %s.\n", plugin_get_name (current_plugin));
        interface_unload ();

        current_plugin = NULL;
    }

    if (plugin != NULL)
    {
        AUDDBG ("Loading %s.\n", plugin_get_name (plugin));

        if (! interface_load (plugin))
            return FALSE;

        current_plugin = plugin;

        AUDDBG ("Loading visualizers.\n");
        vis_init ();

        AUDDBG ("Loading plugin widgets.\n");
        general_init ();
    }

    return TRUE;
}
Exemplo n.º 12
0
void* plugin_discover(char* dirname, Plugin_Manager* pm) {
	DIR* dir = opendir(dirname);
	
	if (!dir) {
		//char* err = dstring_format("Unable to open path '%s'", dirname);
		perror("Couldn't open plugin directory");
		//free(err);
		return NULL;
	}

	Plugin_DiscoveryState* plugins_state = malloc(sizeof(*plugins_state));
	plugins_state->handle_list = NULL;

	// Look at all DSOs in the plugin directory and attempt to load them.
	struct dirent* direntry;
	while ((direntry = readdir(dir))) {
		char* name = plugin_get_name(direntry->d_name);
		if (!name)
			continue;
		char *fullpath = malloc(strlen(dirname) + strlen(direntry->d_name) + 8);
		memset(fullpath, 0x00, (strlen(dirname) + strlen(direntry->d_name) + 8));
		snprintf(fullpath, (strlen(dirname) + strlen(direntry->d_name) + 8), "%s/%s", dirname, direntry->d_name);

		// Load the plugin, get the DSO handle and add it to the list
		void* handle = plugin_load(name, fullpath, pm);
		if (handle) {
			Plugin_HandleList* handle_node = malloc(sizeof(*handle_node));
			handle_node->handle = handle;
			handle_node->next = plugins_state->handle_list;
			plugins_state->handle_list = handle_node;
		}

		free(name);
		free(fullpath);
	}

	closedir(dir);
	// Return a state if plugins were found.
	if (plugins_state->handle_list)
		return (void *) plugins_state;
	else {
		free(plugins_state);
		return NULL;
	}
}
Exemplo n.º 13
0
static bool_t effect_start_cb (PluginHandle * plugin, EffectStartState * state)
{
    AUDDBG ("Starting %s at %d channels, %d Hz.\n", plugin_get_name (plugin),
     * state->channels, * state->rate);
    EffectPlugin * header = plugin_get_header (plugin);
    g_return_val_if_fail (header != NULL, TRUE);
    header->start (state->channels, state->rate);

    RunningEffect * effect = g_malloc (sizeof (RunningEffect));
    effect->plugin = plugin;
    effect->header = header;
    effect->channels_returned = * state->channels;
    effect->rate_returned = * state->rate;
    effect->remove_flag = FALSE;

    running_effects = g_list_prepend (running_effects, effect);
    return TRUE;
}
Exemplo n.º 14
0
static void stop_plugins (int type)
{
    if (headless && type == PLUGIN_TYPE_IFACE)
        return;

    plugin_for_enabled (type, misc_cleanup_cb, GINT_TO_POINTER (type));

    if (table[type].is_single)
    {
        AUDDBG ("Shutting down %s.\n", plugin_get_name
         (table[type].u.s.get_current ()));
        table[type].u.s.set_current (NULL);
    }
    else
    {
        if (table[type].u.m.stop)
            plugin_for_enabled (type, stop_multi_cb, GINT_TO_POINTER (type));
    }
}
Exemplo n.º 15
0
static void effect_enable (PluginHandle * plugin, EffectPlugin * ep, bool_t
 enable)
{
    if (ep->preserves_format)
    {
        pthread_mutex_lock (& mutex);

        if (enable)
            effect_insert (plugin, ep);
        else
            effect_remove (plugin);

        pthread_mutex_unlock (& mutex);
    }
    else
    {
        AUDDBG ("Reset to add/remove %s.\n", plugin_get_name (plugin));
        output_reset (OUTPUT_RESET_EFFECTS_ONLY);
    }
}
Exemplo n.º 16
0
static void effect_enable (PluginHandle * plugin, EffectPlugin * ep, bool_t
 enable)
{
    if (ep->preserves_format)
    {
        pthread_mutex_lock (& mutex);

        if (enable)
            effect_insert (plugin, ep);
        else
            effect_remove (plugin);

        pthread_mutex_unlock (& mutex);
    }
    else
    {
        AUDDBG ("Reset to add/remove %s.\n", plugin_get_name (plugin));
        int time = playback_get_time ();
        bool_t paused = playback_get_paused ();
        playback_stop ();
        playback_play (time, paused);
    }
}
Exemplo n.º 17
0
void
gui_chat_printf_date_tags (struct t_gui_buffer *buffer, time_t date,
                           const char *tags, const char *message, ...)
{
    va_list argptr;
    time_t date_printed;
    int display_time, length, at_least_one_message_printed;
    char *pos, *pos_prefix, *pos_tab, *pos_end;
    char *modifier_data, *new_msg, *ptr_msg;
    struct t_gui_line *ptr_line;
    
    if (!gui_buffer_valid (buffer))
        return;
    
    if (!message)
        return;
    
    if (gui_init_ok)
    {
        if (!buffer)
            buffer = gui_buffer_search_main ();

        if (!buffer)
            return;
        
        if (buffer->type != GUI_BUFFER_TYPE_FORMATTED)
            buffer = gui_buffers;
        
        if (buffer->type != GUI_BUFFER_TYPE_FORMATTED)
            return;
    }
    
    if (!gui_chat_buffer)
        gui_chat_buffer = malloc (GUI_CHAT_BUFFER_PRINTF_SIZE);
    if (!gui_chat_buffer)
        return;
    
    va_start (argptr, message);
    vsnprintf (gui_chat_buffer, GUI_CHAT_BUFFER_PRINTF_SIZE, message, argptr);
    va_end (argptr);
    
    utf8_normalize (gui_chat_buffer, '?');
    
    date_printed = time (NULL);
    if (date <= 0)
        date = date_printed;
    
    at_least_one_message_printed = 0;
    
    pos = gui_chat_buffer;
    while (pos)
    {
        /* display until next end of line */
        pos_end = strchr (pos, '\n');
        if (pos_end)
            pos_end[0] = '\0';
        
        /* call modifier for message printed ("weechat_print") */
        new_msg = NULL;
        if (buffer)
        {
            length = strlen (plugin_get_name (buffer->plugin)) + 1 +
                strlen (buffer->name) + 1 + ((tags) ? strlen (tags) : 0) + 1;
            modifier_data = malloc (length);
            if (modifier_data)
            {
                snprintf (modifier_data, length, "%s;%s;%s",
                          plugin_get_name (buffer->plugin),
                          buffer->name,
                          (tags) ? tags : "");
                new_msg = hook_modifier_exec (NULL,
                                              "weechat_print",
                                              modifier_data,
                                              pos);
                /* no changes in new message */
                if (new_msg && (strcmp (message, new_msg) == 0))
                {
                    free (new_msg);
                    new_msg = NULL;
                }
                free (modifier_data);
            }
        }
        
        pos_prefix = NULL;
        display_time = 1;
        ptr_msg = (new_msg) ? new_msg : pos;
        
        /* space followed by tab => prefix ignored */
        if ((ptr_msg[0] == ' ') && (ptr_msg[1] == '\t'))
        {
            ptr_msg += 2;
        }
        else
        {
            /* if two first chars are tab, then do not display time */
            if ((ptr_msg[0] == '\t') && (ptr_msg[1] == '\t'))
            {
                display_time = 0;
                ptr_msg += 2;
            }
            else
            {
                /* if tab found, use prefix (before tab) */
                pos_tab = strchr (ptr_msg, '\t');
                if (pos_tab)
                {
                    pos_tab[0] = '\0';
                    pos_prefix = ptr_msg;
                    ptr_msg = pos_tab + 1;
                }
            }
        }
        
        if (gui_init_ok)
        {
            ptr_line = gui_line_add (buffer, (display_time) ? date : 0,
                                     (display_time) ? date_printed : 0,
                                     tags, pos_prefix, ptr_msg);
            if (ptr_line)
            {
                if (buffer->print_hooks_enabled)
                    hook_print_exec (buffer, ptr_line);
                if (ptr_line->data->displayed)
                    at_least_one_message_printed = 1;
            }
        }
        else
        {
            if (pos_prefix)
                string_iconv_fprintf (stdout, "%s ", pos_prefix);
            string_iconv_fprintf (stdout, "%s\n", ptr_msg);
        }
        
        if (new_msg)
            free (new_msg);
        
        pos = (pos_end && pos_end[1]) ? pos_end + 1 : NULL;
    }
    
    if (gui_init_ok && at_least_one_message_printed)
        gui_buffer_ask_chat_refresh (buffer, 1);
}
Exemplo n.º 18
0
static bool_t stop_multi_cb (PluginHandle * p, void * type)
{
    AUDDBG ("Shutting down %s.\n", plugin_get_name (p));
    table[GPOINTER_TO_INT (type)].u.m.stop (p);
    return TRUE;
}
Exemplo n.º 19
0
int
input_exec_command (struct t_gui_buffer *buffer,
                    int any_plugin,
                    struct t_weechat_plugin *plugin,
                    const char *string)
{
    char *command, *command_name, *pos;
    int rc;

    if ((!string) || (!string[0]))
        return WEECHAT_RC_ERROR;

    command = strdup (string);
    if (!command)
        return WEECHAT_RC_ERROR;

    /* ignore spaces at the end of command */
    pos = &command[strlen (command) - 1];
    if (pos[0] == ' ')
    {
        while ((pos > command) && (pos[0] == ' '))
            pos--;
        pos[1] = '\0';
    }

    /* extract command name */
    pos = strchr (command, ' ');
    command_name = (pos) ?
        string_strndup (command, pos - command) : strdup (command);
    if (!command_name)
    {
        free (command);
        return WEECHAT_RC_ERROR;
    }

    /* execute command */
    rc = WEECHAT_RC_OK;
    switch (hook_command_exec (buffer, any_plugin, plugin, command))
    {
        case HOOK_COMMAND_EXEC_OK:
            /* command hooked, OK (executed) */
            break;
        case HOOK_COMMAND_EXEC_ERROR:
            /* command hooked, error */
            rc = WEECHAT_RC_ERROR;
            break;
        case HOOK_COMMAND_EXEC_NOT_FOUND:
            /*
             * command not found: if unknown commands are accepted by this
             * buffer, just send input text as data to buffer,
             * otherwise display error
             */
            if (buffer->input_get_unknown_commands)
            {
                input_exec_data (buffer, string);
            }
            else
            {
                gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
                                           _("%sError: unknown command \"%s\" "
                                             "(type /help for help)"),
                                           gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
                                           command_name);
                rc = WEECHAT_RC_ERROR;
            }
            break;
        case HOOK_COMMAND_EXEC_AMBIGUOUS_PLUGINS:
            /* command is ambiguous (exists for other plugins) */
            gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
                                       _("%sError: ambiguous command \"%s\": "
                                         "it exists in many plugins and not in "
                                         "\"%s\" plugin"),
                                       gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
                                       command_name,
                                       plugin_get_name (plugin));
            rc = WEECHAT_RC_ERROR;
            break;
        case HOOK_COMMAND_EXEC_AMBIGUOUS_INCOMPLETE:
            /*
             * command is ambiguous (incomplete command and multiple commands
             * start with this name)
             */
            gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
                                       _("%sError: incomplete command \"%s\" "
                                         "and multiple commands start with "
                                         "this name"),
                                       gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
                                       command_name);
            rc = WEECHAT_RC_ERROR;
            break;
        case HOOK_COMMAND_EXEC_RUNNING:
            /* command is running */
            gui_chat_printf_date_tags (NULL, 0, GUI_FILTER_TAG_NO_FILTER,
                                       _("%sError: too many calls to command "
                                         "\"%s\" (looping)"),
                                       gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
                                       command_name);
            rc = WEECHAT_RC_ERROR;
            break;
        default:
            break;
    }

    free (command);
    free (command_name);

    return rc;
}
Exemplo n.º 20
0
struct t_hashtable *
gui_focus_to_hashtable (struct t_gui_focus_info *focus_info, const char *key)
{
    struct t_hashtable *hashtable;
    char str_value[128], *str_time, *str_prefix, *str_tags, *str_message;
    const char *nick;

    hashtable = hashtable_new (32,
                               WEECHAT_HASHTABLE_STRING,
                               WEECHAT_HASHTABLE_STRING,
                               NULL, NULL);
    if (!hashtable)
        return NULL;

    /* key (key from keyboard or mouse event) */
    FOCUS_STR("_key", key);

    /* x,y */
    FOCUS_INT("_x", focus_info->x);
    FOCUS_INT("_y", focus_info->y);

    /* window */
    FOCUS_PTR("_window", focus_info->window);
    if (focus_info->window)
    {
        FOCUS_INT("_window_number", (focus_info->window)->number);
    }
    else
    {
        FOCUS_STR("_window_number", "*");
    }

    /* buffer */
    FOCUS_PTR("_buffer", focus_info->buffer);
    if (focus_info->buffer)
    {
        FOCUS_INT("_buffer_number", (focus_info->buffer)->number);
        FOCUS_STR("_buffer_plugin", plugin_get_name ((focus_info->buffer)->plugin));
        FOCUS_STR("_buffer_name", (focus_info->buffer)->name);
        FOCUS_STR("_buffer_full_name", (focus_info->buffer)->full_name);
        hashtable_map ((focus_info->buffer)->local_variables,
                       &gui_focus_buffer_localvar_map_cb, hashtable);
    }
    else
    {
        FOCUS_PTR("_buffer", NULL);
        FOCUS_STR("_buffer_number", "-1");
        FOCUS_STR("_buffer_plugin", "");
        FOCUS_STR("_buffer_name", "");
        FOCUS_STR("_buffer_full_name", "");
    }

    /* chat area */
    FOCUS_INT("_chat", focus_info->chat);
    str_time = NULL;
    str_prefix = NULL;
    if (focus_info->chat_line)
    {
        str_time = gui_color_decode (((focus_info->chat_line)->data)->str_time, NULL);
        str_prefix = gui_color_decode (((focus_info->chat_line)->data)->prefix, NULL);
        str_tags = string_build_with_split_string ((const char **)((focus_info->chat_line)->data)->tags_array, ",");
        str_message = gui_color_decode (((focus_info->chat_line)->data)->message, NULL);
        nick = gui_line_get_nick_tag (focus_info->chat_line);
        FOCUS_PTR("_chat_line", focus_info->chat_line);
        FOCUS_INT("_chat_line_x", focus_info->chat_line_x);
        FOCUS_INT("_chat_line_y", ((focus_info->chat_line)->data)->y);
        FOCUS_TIME("_chat_line_date", ((focus_info->chat_line)->data)->date);
        FOCUS_TIME("_chat_line_date_printed", ((focus_info->chat_line)->data)->date_printed);
        FOCUS_STR_VAR("_chat_line_time", str_time);
        FOCUS_STR_VAR("_chat_line_tags", str_tags);
        FOCUS_STR_VAR("_chat_line_nick", nick);
        FOCUS_STR_VAR("_chat_line_prefix", str_prefix);
        FOCUS_STR_VAR("_chat_line_message", str_message);
        if (str_time)
            free (str_time);
        if (str_prefix)
            free (str_prefix);
        if (str_tags)
            free (str_tags);
        if (str_message)
            free (str_message);
    }
    else
    {
        FOCUS_PTR("_chat_line", NULL);
        FOCUS_STR("_chat_line_x", "-1");
        FOCUS_STR("_chat_line_y", "-1");
        FOCUS_STR("_chat_line_date", "-1");
        FOCUS_STR("_chat_line_date_printed", "-1");
        FOCUS_STR("_chat_line_time", "");
        FOCUS_STR("_chat_line_tags", "");
        FOCUS_STR("_chat_line_nick", "");
        FOCUS_STR("_chat_line_prefix", "");
        FOCUS_STR("_chat_line_message", "");
    }
    FOCUS_STR_VAR("_chat_word", focus_info->chat_word);
    FOCUS_STR_VAR("_chat_bol", focus_info->chat_bol);
    FOCUS_STR_VAR("_chat_eol", focus_info->chat_eol);

    /* bar/item */
    if (focus_info->bar_window)
    {
        FOCUS_STR("_bar_name", ((focus_info->bar_window)->bar)->name);
        FOCUS_STR("_bar_filling", gui_bar_filling_string[gui_bar_get_filling ((focus_info->bar_window)->bar)]);
    }
    else
    {
        FOCUS_STR("_bar_name", "");
        FOCUS_STR("_bar_filling", "");
    }
    FOCUS_STR_VAR("_bar_item_name", focus_info->bar_item);
    FOCUS_INT("_bar_item_line", focus_info->bar_item_line);
    FOCUS_INT("_bar_item_col", focus_info->bar_item_col);

    return hashtable;
}
Exemplo n.º 21
0
void
input_exec_command (struct t_gui_buffer *buffer,
                    int any_plugin,
                    struct t_weechat_plugin *plugin,
                    const char *string)
{
    int rc;
    char *command, *pos, *ptr_args;

    if ((!string) || (!string[0]))
        return;

    command = strdup (string);
    if (!command)
        return ;

    /* look for end of command */
    ptr_args = NULL;

    pos = &command[strlen (command) - 1];
    if (pos[0] == ' ')
    {
        while ((pos > command) && (pos[0] == ' '))
            pos--;
        pos[1] = '\0';
    }

    rc = hook_command_exec (buffer, any_plugin, plugin, command);

    pos = strchr (command, ' ');
    if (pos)
    {
        pos[0] = '\0';
        pos++;
        while (pos[0] == ' ')
            pos++;
        ptr_args = pos;
        if (!ptr_args[0])
            ptr_args = NULL;
    }

    switch (rc)
    {
        case 0: /* command hooked, KO */
            gui_chat_printf (NULL,
                             _("%sError with command \"%s\" (try /help %s)"),
                             gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
                             command + 1, command + 1);
            break;
        case 1: /* command hooked, OK (executed) */
            break;
        case -2: /* command is ambiguous (exists for other plugins) */
            gui_chat_printf (NULL,
                             _("%sError: ambiguous command \"%s\": it exists "
                               "in many plugins and not in \"%s\" plugin"),
                             gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
                             command + 1,
                             plugin_get_name (plugin));
            break;
        case -3: /* command is running */
            gui_chat_printf (NULL,
                             _("%sError: too much calls to command \"%s\" "
                               "(looping)"),
                             gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
                             command + 1);
            break;
        default: /* no command hooked */
            /*
             * if unknown commands are accepted by this buffer, just send
             * input text as data to buffer, otherwise display error
             */
            if (buffer->input_get_unknown_commands)
            {
                input_exec_data (buffer, string);
            }
            else
            {
                gui_chat_printf (NULL,
                                 _("%sError: unknown command \"%s\" (type "
                                   "/help for help)"),
                                 gui_chat_prefix[GUI_CHAT_PREFIX_ERROR],
                                 command + 1);
            }
            break;
    }
    free (command);
}