xed/plugins/filebrowser/pluma-file-browser-messages.c

1034 lines
25 KiB
C
Raw Normal View History

2011-11-07 16:52:18 -06:00
#include "pluma-file-browser-messages.h"
#include "pluma-file-browser-store.h"
#include <pluma/pluma-message.h>
2011-11-07 13:46:58 -06:00
#define MESSAGE_OBJECT_PATH "/plugins/filebrowser"
2011-11-07 16:52:18 -06:00
#define WINDOW_DATA_KEY "PlumaFileBrowserMessagesWindowData"
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
#define BUS_CONNECT(bus, name, data) pluma_message_bus_connect(bus, MESSAGE_OBJECT_PATH, #name, (PlumaMessageCallback) message_##name##_cb, data, NULL)
2011-11-07 13:46:58 -06:00
typedef struct
{
2011-11-07 16:52:18 -06:00
PlumaWindow *window;
PlumaMessage *message;
2011-11-07 13:46:58 -06:00
} MessageCacheData;
typedef struct
{
guint row_inserted_id;
guint row_deleted_id;
guint root_changed_id;
guint begin_loading_id;
guint end_loading_id;
GList *merge_ids;
GtkActionGroup *merged_actions;
2011-11-07 16:52:18 -06:00
PlumaMessageBus *bus;
PlumaFileBrowserWidget *widget;
2011-11-07 13:46:58 -06:00
GHashTable *row_tracking;
GHashTable *filters;
} WindowData;
typedef struct
{
gulong id;
2011-11-07 16:52:18 -06:00
PlumaWindow *window;
PlumaMessage *message;
2011-11-07 13:46:58 -06:00
} FilterData;
static WindowData *
2011-11-07 16:52:18 -06:00
window_data_new (PlumaWindow *window,
PlumaFileBrowserWidget *widget)
2011-11-07 13:46:58 -06:00
{
WindowData *data = g_slice_new (WindowData);
GtkUIManager *manager;
GList *groups;
2011-11-07 16:52:18 -06:00
data->bus = pluma_window_get_message_bus (window);
2011-11-07 13:46:58 -06:00
data->widget = widget;
data->row_tracking = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify)g_free,
(GDestroyNotify)gtk_tree_row_reference_free);
data->filters = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify)g_free,
NULL);
2011-11-07 16:52:18 -06:00
manager = pluma_file_browser_widget_get_ui_manager (widget);
2011-11-07 13:46:58 -06:00
data->merge_ids = NULL;
data->merged_actions = gtk_action_group_new ("MessageMergedActions");
groups = gtk_ui_manager_get_action_groups (manager);
gtk_ui_manager_insert_action_group (manager, data->merged_actions, g_list_length (groups));
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, data);
return data;
}
static WindowData *
2011-11-07 16:52:18 -06:00
get_window_data (PlumaWindow * window)
2011-11-07 13:46:58 -06:00
{
return (WindowData *) (g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY));
}
static void
2011-11-07 16:52:18 -06:00
window_data_free (PlumaWindow *window)
2011-11-07 13:46:58 -06:00
{
WindowData *data = get_window_data (window);
GtkUIManager *manager;
GList *item;
g_hash_table_destroy (data->row_tracking);
g_hash_table_destroy (data->filters);
2011-11-07 16:52:18 -06:00
manager = pluma_file_browser_widget_get_ui_manager (data->widget);
2011-11-07 13:46:58 -06:00
gtk_ui_manager_remove_action_group (manager, data->merged_actions);
for (item = data->merge_ids; item; item = item->next)
gtk_ui_manager_remove_ui (manager, GPOINTER_TO_INT (item->data));
g_list_free (data->merge_ids);
g_object_unref (data->merged_actions);
g_slice_free (WindowData, data);
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
}
static FilterData *
2011-11-07 16:52:18 -06:00
filter_data_new (PlumaWindow *window,
PlumaMessage *message)
2011-11-07 13:46:58 -06:00
{
FilterData *data = g_slice_new (FilterData);
WindowData *wdata;
data->window = window;
data->id = 0;
data->message = message;
wdata = get_window_data (window);
g_hash_table_insert (wdata->filters,
2011-11-07 16:52:18 -06:00
pluma_message_type_identifier (pluma_message_get_object_path (message),
pluma_message_get_method (message)),
2011-11-07 13:46:58 -06:00
data);
return data;
}
static void
filter_data_free (FilterData *data)
{
WindowData *wdata = get_window_data (data->window);
gchar *identifier;
2011-11-07 16:52:18 -06:00
identifier = pluma_message_type_identifier (pluma_message_get_object_path (data->message),
pluma_message_get_method (data->message));
2011-11-07 13:46:58 -06:00
g_hash_table_remove (wdata->filters, identifier);
g_free (identifier);
g_object_unref (data->message);
g_slice_free (FilterData, data);
}
static GtkTreePath *
track_row_lookup (WindowData *data,
const gchar *id)
{
GtkTreeRowReference *ref;
ref = (GtkTreeRowReference *)g_hash_table_lookup (data->row_tracking, id);
if (!ref)
return NULL;
return gtk_tree_row_reference_get_path (ref);
}
static void
message_cache_data_free (MessageCacheData *data)
{
g_object_unref (data->message);
g_slice_free (MessageCacheData, data);
}
static MessageCacheData *
2011-11-07 16:52:18 -06:00
message_cache_data_new (PlumaWindow *window,
PlumaMessage *message)
2011-11-07 13:46:58 -06:00
{
MessageCacheData *data = g_slice_new (MessageCacheData);
data->window = window;
data->message = message;
return data;
}
static void
2011-11-07 16:52:18 -06:00
message_get_root_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
2011-11-07 16:52:18 -06:00
PlumaFileBrowserStore *store;
2011-11-07 13:46:58 -06:00
gchar *uri;
2011-11-07 16:52:18 -06:00
store = pluma_file_browser_widget_get_browser_store (data->widget);
uri = pluma_file_browser_store_get_virtual_root (store);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_set (message, "uri", uri, NULL);
2011-11-07 13:46:58 -06:00
g_free (uri);
}
static void
2011-11-07 16:52:18 -06:00
message_set_root_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
gchar *root = NULL;
gchar *virtual = NULL;
2011-11-07 16:52:18 -06:00
pluma_message_get (message, "uri", &root, NULL);
2011-11-07 13:46:58 -06:00
if (!root)
return;
2011-11-07 16:52:18 -06:00
if (pluma_message_has_key (message, "virtual"))
pluma_message_get (message, "virtual", &virtual, NULL);
2011-11-07 13:46:58 -06:00
if (virtual)
2011-11-07 16:52:18 -06:00
pluma_file_browser_widget_set_root_and_virtual_root (data->widget, root, virtual);
2011-11-07 13:46:58 -06:00
else
2011-11-07 16:52:18 -06:00
pluma_file_browser_widget_set_root (data->widget, root, TRUE);
2011-11-07 13:46:58 -06:00
g_free (root);
g_free (virtual);
}
static void
2011-11-07 16:52:18 -06:00
message_set_emblem_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
gchar *id = NULL;
gchar *emblem = NULL;
GtkTreePath *path;
2011-11-07 16:52:18 -06:00
PlumaFileBrowserStore *store;
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_get (message, "id", &id, "emblem", &emblem, NULL);
2011-11-07 13:46:58 -06:00
if (!id || !emblem)
{
g_free (id);
g_free (emblem);
return;
}
path = track_row_lookup (data, id);
if (path != NULL)
{
GError *error = NULL;
GdkPixbuf *pixbuf;
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
emblem,
10,
0,
&error);
if (pixbuf)
{
GValue value = { 0, };
GtkTreeIter iter;
2011-11-07 16:52:18 -06:00
store = pluma_file_browser_widget_get_browser_store (data->widget);
2011-11-07 13:46:58 -06:00
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
{
g_value_init (&value, GDK_TYPE_PIXBUF);
g_value_set_object (&value, pixbuf);
2011-11-07 16:52:18 -06:00
pluma_file_browser_store_set_value (store,
2011-11-07 13:46:58 -06:00
&iter,
2011-11-07 16:52:18 -06:00
PLUMA_FILE_BROWSER_STORE_COLUMN_EMBLEM,
2011-11-07 13:46:58 -06:00
&value);
g_value_unset (&value);
}
g_object_unref (pixbuf);
}
if (error)
g_error_free (error);
}
g_free (id);
g_free (emblem);
}
static gchar *
item_id (const gchar *path,
const gchar *uri)
{
return g_strconcat (path, "::", uri, NULL);
}
static gchar *
track_row (WindowData *data,
2011-11-07 16:52:18 -06:00
PlumaFileBrowserStore *store,
2011-11-07 13:46:58 -06:00
GtkTreePath *path,
const gchar *uri)
{
GtkTreeRowReference *ref;
gchar *id;
gchar *pathstr;
pathstr = gtk_tree_path_to_string (path);
id = item_id (pathstr, uri);
ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store), path);
g_hash_table_insert (data->row_tracking, g_strdup (id), ref);
g_free (pathstr);
return id;
}
static void
set_item_message (WindowData *data,
GtkTreeIter *iter,
GtkTreePath *path,
2011-11-07 16:52:18 -06:00
PlumaMessage *message)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
PlumaFileBrowserStore *store;
2011-11-07 13:46:58 -06:00
gchar *uri = NULL;
guint flags = 0;
gchar *track_id;
2011-11-07 16:52:18 -06:00
store = pluma_file_browser_widget_get_browser_store (data->widget);
2011-11-07 13:46:58 -06:00
gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
2011-11-07 16:52:18 -06:00
PLUMA_FILE_BROWSER_STORE_COLUMN_URI, &uri,
PLUMA_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
2011-11-07 13:46:58 -06:00
-1);
if (!uri)
return;
if (path && gtk_tree_path_get_depth (path) != 0)
track_id = track_row (data, store, path, uri);
else
track_id = NULL;
2011-11-07 16:52:18 -06:00
pluma_message_set (message,
2011-11-07 13:46:58 -06:00
"id", track_id,
"uri", uri,
NULL);
2011-11-07 16:52:18 -06:00
if (pluma_message_has_key (message, "is_directory"))
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
pluma_message_set (message,
2011-11-07 13:46:58 -06:00
"is_directory", FILE_IS_DIR (flags),
NULL);
}
g_free (uri);
g_free (track_id);
}
static gboolean
2011-11-07 16:52:18 -06:00
custom_message_filter_func (PlumaFileBrowserWidget *widget,
PlumaFileBrowserStore *store,
2011-11-07 13:46:58 -06:00
GtkTreeIter *iter,
FilterData *data)
{
WindowData *wdata = get_window_data (data->window);
gchar *uri = NULL;
guint flags = 0;
gboolean filter = FALSE;
GtkTreePath *path;
gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
2011-11-07 16:52:18 -06:00
PLUMA_FILE_BROWSER_STORE_COLUMN_URI, &uri,
PLUMA_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
2011-11-07 13:46:58 -06:00
-1);
if (!uri || FILE_IS_DUMMY (flags))
{
g_free (uri);
return FALSE;
}
path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
set_item_message (wdata, iter, path, data->message);
gtk_tree_path_free (path);
2011-11-07 16:52:18 -06:00
pluma_message_set (data->message, "filter", filter, NULL);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_bus_send_message_sync (wdata->bus, data->message);
pluma_message_get (data->message, "filter", &filter, NULL);
2011-11-07 13:46:58 -06:00
return !filter;
}
static void
2011-11-07 16:52:18 -06:00
message_add_filter_cb (PlumaMessageBus *bus,
PlumaMessage *message,
PlumaWindow *window)
2011-11-07 13:46:58 -06:00
{
gchar *object_path = NULL;
gchar *method = NULL;
gulong id;
2011-11-07 16:52:18 -06:00
PlumaMessageType *message_type;
PlumaMessage *cbmessage;
2011-11-07 13:46:58 -06:00
FilterData *filter_data;
WindowData *data = get_window_data (window);
2011-11-07 16:52:18 -06:00
pluma_message_get (message,
2011-11-07 13:46:58 -06:00
"object_path", &object_path,
"method", &method,
NULL);
// Check if there exists such a 'callback' message
if (!object_path || !method)
{
g_free (object_path);
g_free (method);
return;
}
2011-11-07 16:52:18 -06:00
message_type = pluma_message_bus_lookup (bus, object_path, method);
2011-11-07 13:46:58 -06:00
if (!message_type)
{
g_free (object_path);
g_free (method);
return;
}
// Check if the message type has the correct arguments
2011-11-07 16:52:18 -06:00
if (pluma_message_type_lookup (message_type, "id") != G_TYPE_STRING ||
pluma_message_type_lookup (message_type, "uri") != G_TYPE_STRING ||
pluma_message_type_lookup (message_type, "is_directory") != G_TYPE_BOOLEAN ||
pluma_message_type_lookup (message_type, "filter") != G_TYPE_BOOLEAN)
2011-11-07 13:46:58 -06:00
{
return;
}
2011-11-07 16:52:18 -06:00
cbmessage = pluma_message_type_instantiate (message_type,
2011-11-07 13:46:58 -06:00
"id", NULL,
"uri", NULL,
"is_directory", FALSE,
"filter", FALSE,
NULL);
// Register the custom filter on the widget
filter_data = filter_data_new (window, cbmessage);
2011-11-07 16:52:18 -06:00
id = pluma_file_browser_widget_add_filter (data->widget,
(PlumaFileBrowserWidgetFilterFunc)custom_message_filter_func,
2011-11-07 13:46:58 -06:00
filter_data,
(GDestroyNotify)filter_data_free);
filter_data->id = id;
}
static void
2011-11-07 16:52:18 -06:00
message_remove_filter_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
gulong id = 0;
2011-11-07 16:52:18 -06:00
pluma_message_get (message, "id", &id, NULL);
2011-11-07 13:46:58 -06:00
if (!id)
return;
2011-11-07 16:52:18 -06:00
pluma_file_browser_widget_remove_filter (data->widget, id);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
message_up_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
2011-11-07 16:52:18 -06:00
PlumaFileBrowserStore *store = pluma_file_browser_widget_get_browser_store (data->widget);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_file_browser_store_set_virtual_root_up (store);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
message_history_back_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
2011-11-07 16:52:18 -06:00
pluma_file_browser_widget_history_back (data->widget);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
message_history_forward_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
2011-11-07 16:52:18 -06:00
pluma_file_browser_widget_history_forward (data->widget);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
message_refresh_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
2011-11-07 16:52:18 -06:00
pluma_file_browser_widget_refresh (data->widget);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
message_set_show_hidden_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
gboolean active = FALSE;
2011-11-07 16:52:18 -06:00
PlumaFileBrowserStore *store;
PlumaFileBrowserStoreFilterMode mode;
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_get (message, "active", &active, NULL);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
store = pluma_file_browser_widget_get_browser_store (data->widget);
mode = pluma_file_browser_store_get_filter_mode (store);
2011-11-07 13:46:58 -06:00
if (active)
2011-11-07 16:52:18 -06:00
mode &= ~PLUMA_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN;
2011-11-07 13:46:58 -06:00
else
2011-11-07 16:52:18 -06:00
mode |= PLUMA_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN;
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_file_browser_store_set_filter_mode (store, mode);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
message_set_show_binary_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
gboolean active = FALSE;
2011-11-07 16:52:18 -06:00
PlumaFileBrowserStore *store;
PlumaFileBrowserStoreFilterMode mode;
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_get (message, "active", &active, NULL);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
store = pluma_file_browser_widget_get_browser_store (data->widget);
mode = pluma_file_browser_store_get_filter_mode (store);
2011-11-07 13:46:58 -06:00
if (active)
2011-11-07 16:52:18 -06:00
mode &= ~PLUMA_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY;
2011-11-07 13:46:58 -06:00
else
2011-11-07 16:52:18 -06:00
mode |= PLUMA_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY;
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_file_browser_store_set_filter_mode (store, mode);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
message_show_bookmarks_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
2011-11-07 16:52:18 -06:00
pluma_file_browser_widget_show_bookmarks (data->widget);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
message_show_files_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
2011-11-07 16:52:18 -06:00
pluma_file_browser_widget_show_files (data->widget);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
message_add_context_item_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
GtkAction *action = NULL;
gchar *path = NULL;
gchar *name;
GtkUIManager *manager;
guint merge_id;
2011-11-07 16:52:18 -06:00
pluma_message_get (message,
2011-11-07 13:46:58 -06:00
"action", &action,
"path", &path,
NULL);
if (!action || !path)
{
if (action)
g_object_unref (action);
g_free (path);
return;
}
gtk_action_group_add_action (data->merged_actions, action);
2011-11-07 16:52:18 -06:00
manager = pluma_file_browser_widget_get_ui_manager (data->widget);
2011-11-07 13:46:58 -06:00
name = g_strconcat (gtk_action_get_name (action), "MenuItem", NULL);
merge_id = gtk_ui_manager_new_merge_id (manager);
gtk_ui_manager_add_ui (manager,
merge_id,
path,
name,
gtk_action_get_name (action),
GTK_UI_MANAGER_AUTO,
FALSE);
if (gtk_ui_manager_get_widget (manager, path))
{
data->merge_ids = g_list_prepend (data->merge_ids, GINT_TO_POINTER (merge_id));
2011-11-07 16:52:18 -06:00
pluma_message_set (message, "id", merge_id, NULL);
2011-11-07 13:46:58 -06:00
}
else
{
2011-11-07 16:52:18 -06:00
pluma_message_set (message, "id", 0, NULL);
2011-11-07 13:46:58 -06:00
}
g_object_unref (action);
g_free (path);
g_free (name);
}
static void
2011-11-07 16:52:18 -06:00
message_remove_context_item_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
guint merge_id = 0;
GtkUIManager *manager;
2011-11-07 16:52:18 -06:00
pluma_message_get (message, "id", &merge_id, NULL);
2011-11-07 13:46:58 -06:00
if (merge_id == 0)
return;
2011-11-07 16:52:18 -06:00
manager = pluma_file_browser_widget_get_ui_manager (data->widget);
2011-11-07 13:46:58 -06:00
data->merge_ids = g_list_remove (data->merge_ids, GINT_TO_POINTER (merge_id));
gtk_ui_manager_remove_ui (manager, merge_id);
}
static void
2011-11-07 16:52:18 -06:00
message_get_view_cb (PlumaMessageBus *bus,
PlumaMessage *message,
2011-11-07 13:46:58 -06:00
WindowData *data)
{
2011-11-07 16:52:18 -06:00
PlumaFileBrowserView *view;
view = pluma_file_browser_widget_get_browser_view (data->widget);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_set (message, "view", view, NULL);
2011-11-07 13:46:58 -06:00
}
static void
2011-11-07 16:52:18 -06:00
register_methods (PlumaWindow *window,
PlumaFileBrowserWidget *widget)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
PlumaMessageBus *bus = pluma_window_get_message_bus (window);
2011-11-07 13:46:58 -06:00
WindowData *data = get_window_data (window);
/* Register method calls */
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "get_root",
1,
"uri", G_TYPE_STRING,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "set_root",
1,
"uri", G_TYPE_STRING,
"virtual", G_TYPE_STRING,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "set_emblem",
0,
"id", G_TYPE_STRING,
"emblem", G_TYPE_STRING,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "add_filter",
1,
"object_path", G_TYPE_STRING,
"method", G_TYPE_STRING,
"id", G_TYPE_ULONG,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "remove_filter",
0,
"id", G_TYPE_ULONG,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "add_context_item",
1,
"action", GTK_TYPE_ACTION,
"path", G_TYPE_STRING,
"id", G_TYPE_UINT,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "remove_context_item",
0,
"id", G_TYPE_UINT,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus, MESSAGE_OBJECT_PATH, "up", 0, NULL);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus, MESSAGE_OBJECT_PATH, "history_back", 0, NULL);
pluma_message_bus_register (bus, MESSAGE_OBJECT_PATH, "history_forward", 0, NULL);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus, MESSAGE_OBJECT_PATH, "refresh", 0, NULL);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "set_show_hidden",
0,
"active", G_TYPE_BOOLEAN,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "set_show_binary",
0,
"active", G_TYPE_BOOLEAN,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_bookmarks", 0, NULL);
pluma_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_files", 0, NULL);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "get_view",
1,
2011-11-07 16:52:18 -06:00
"view", PLUMA_TYPE_FILE_BROWSER_VIEW,
2011-11-07 13:46:58 -06:00
NULL);
BUS_CONNECT (bus, get_root, data);
BUS_CONNECT (bus, set_root, data);
BUS_CONNECT (bus, set_emblem, data);
BUS_CONNECT (bus, add_filter, window);
BUS_CONNECT (bus, remove_filter, data);
BUS_CONNECT (bus, add_context_item, data);
BUS_CONNECT (bus, remove_context_item, data);
BUS_CONNECT (bus, up, data);
BUS_CONNECT (bus, history_back, data);
BUS_CONNECT (bus, history_forward, data);
BUS_CONNECT (bus, refresh, data);
BUS_CONNECT (bus, set_show_hidden, data);
BUS_CONNECT (bus, set_show_binary, data);
BUS_CONNECT (bus, show_bookmarks, data);
BUS_CONNECT (bus, show_files, data);
BUS_CONNECT (bus, get_view, data);
}
static void
2011-11-07 16:52:18 -06:00
store_row_inserted (PlumaFileBrowserStore *store,
2011-11-07 13:46:58 -06:00
GtkTreePath *path,
GtkTreeIter *iter,
MessageCacheData *data)
{
gchar *uri = NULL;
guint flags = 0;
gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
2011-11-07 16:52:18 -06:00
PLUMA_FILE_BROWSER_STORE_COLUMN_URI, &uri,
PLUMA_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
2011-11-07 13:46:58 -06:00
-1);
if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags))
{
WindowData *wdata = get_window_data (data->window);
set_item_message (wdata, iter, path, data->message);
2011-11-07 16:52:18 -06:00
pluma_message_bus_send_message_sync (wdata->bus, data->message);
2011-11-07 13:46:58 -06:00
}
g_free (uri);
}
static void
2011-11-07 16:52:18 -06:00
store_row_deleted (PlumaFileBrowserStore *store,
2011-11-07 13:46:58 -06:00
GtkTreePath *path,
MessageCacheData *data)
{
GtkTreeIter iter;
gchar *uri = NULL;
guint flags = 0;
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
return;
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
2011-11-07 16:52:18 -06:00
PLUMA_FILE_BROWSER_STORE_COLUMN_URI, &uri,
PLUMA_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
2011-11-07 13:46:58 -06:00
-1);
if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags))
{
WindowData *wdata = get_window_data (data->window);
set_item_message (wdata, &iter, path, data->message);
2011-11-07 16:52:18 -06:00
pluma_message_bus_send_message_sync (wdata->bus, data->message);
2011-11-07 13:46:58 -06:00
}
g_free (uri);
}
static void
2011-11-07 16:52:18 -06:00
store_virtual_root_changed (PlumaFileBrowserStore *store,
2011-11-07 13:46:58 -06:00
GParamSpec *spec,
MessageCacheData *data)
{
WindowData *wdata = get_window_data (data->window);
gchar *uri;
2011-11-07 16:52:18 -06:00
uri = pluma_file_browser_store_get_virtual_root (store);
2011-11-07 13:46:58 -06:00
if (!uri)
return;
2011-11-07 16:52:18 -06:00
pluma_message_set (data->message,
2011-11-07 13:46:58 -06:00
"uri", uri,
NULL);
2011-11-07 16:52:18 -06:00
pluma_message_bus_send_message_sync (wdata->bus, data->message);
2011-11-07 13:46:58 -06:00
g_free (uri);
}
static void
2011-11-07 16:52:18 -06:00
store_begin_loading (PlumaFileBrowserStore *store,
2011-11-07 13:46:58 -06:00
GtkTreeIter *iter,
MessageCacheData *data)
{
GtkTreePath *path;
WindowData *wdata = get_window_data (data->window);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
set_item_message (wdata, iter, path, data->message);
2011-11-07 16:52:18 -06:00
pluma_message_bus_send_message_sync (wdata->bus, data->message);
2011-11-07 13:46:58 -06:00
gtk_tree_path_free (path);
}
static void
2011-11-07 16:52:18 -06:00
store_end_loading (PlumaFileBrowserStore *store,
2011-11-07 13:46:58 -06:00
GtkTreeIter *iter,
MessageCacheData *data)
{
GtkTreePath *path;
WindowData *wdata = get_window_data (data->window);
path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), iter);
set_item_message (wdata, iter, path, data->message);
2011-11-07 16:52:18 -06:00
pluma_message_bus_send_message_sync (wdata->bus, data->message);
2011-11-07 13:46:58 -06:00
gtk_tree_path_free (path);
}
static void
2011-11-07 16:52:18 -06:00
register_signals (PlumaWindow *window,
PlumaFileBrowserWidget *widget)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
PlumaMessageBus *bus = pluma_window_get_message_bus (window);
PlumaFileBrowserStore *store;
PlumaMessageType *inserted_type;
PlumaMessageType *deleted_type;
PlumaMessageType *begin_loading_type;
PlumaMessageType *end_loading_type;
PlumaMessageType *root_changed_type;
PlumaMessage *message;
2011-11-07 13:46:58 -06:00
WindowData *data;
/* Register signals */
2011-11-07 16:52:18 -06:00
root_changed_type = pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "root_changed",
0,
"id", G_TYPE_STRING,
"uri", G_TYPE_STRING,
NULL);
2011-11-07 16:52:18 -06:00
begin_loading_type = pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "begin_loading",
0,
"id", G_TYPE_STRING,
"uri", G_TYPE_STRING,
NULL);
2011-11-07 16:52:18 -06:00
end_loading_type = pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "end_loading",
0,
"id", G_TYPE_STRING,
"uri", G_TYPE_STRING,
NULL);
2011-11-07 16:52:18 -06:00
inserted_type = pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "inserted",
0,
"id", G_TYPE_STRING,
"uri", G_TYPE_STRING,
"is_directory", G_TYPE_BOOLEAN,
NULL);
2011-11-07 16:52:18 -06:00
deleted_type = pluma_message_bus_register (bus,
2011-11-07 13:46:58 -06:00
MESSAGE_OBJECT_PATH, "deleted",
0,
"id", G_TYPE_STRING,
"uri", G_TYPE_STRING,
"is_directory", G_TYPE_BOOLEAN,
NULL);
2011-11-07 16:52:18 -06:00
store = pluma_file_browser_widget_get_browser_store (widget);
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
message = pluma_message_type_instantiate (inserted_type,
2011-11-07 13:46:58 -06:00
"id", NULL,
"uri", NULL,
"is_directory", FALSE,
NULL);
data = get_window_data (window);
data->row_inserted_id =
g_signal_connect_data (store,
"row-inserted",
G_CALLBACK (store_row_inserted),
message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free,
0);
2011-11-07 16:52:18 -06:00
message = pluma_message_type_instantiate (deleted_type,
2011-11-07 13:46:58 -06:00
"id", NULL,
"uri", NULL,
"is_directory", FALSE,
NULL);
data->row_deleted_id =
g_signal_connect_data (store,
"row-deleted",
G_CALLBACK (store_row_deleted),
message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free,
0);
2011-11-07 16:52:18 -06:00
message = pluma_message_type_instantiate (root_changed_type,
2011-11-07 13:46:58 -06:00
"id", NULL,
"uri", NULL,
NULL);
data->root_changed_id =
g_signal_connect_data (store,
"notify::virtual-root",
G_CALLBACK (store_virtual_root_changed),
message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free,
0);
2011-11-07 16:52:18 -06:00
message = pluma_message_type_instantiate (begin_loading_type,
2011-11-07 13:46:58 -06:00
"id", NULL,
"uri", NULL,
NULL);
data->begin_loading_id =
g_signal_connect_data (store,
"begin_loading",
G_CALLBACK (store_begin_loading),
message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free,
0);
2011-11-07 16:52:18 -06:00
message = pluma_message_type_instantiate (end_loading_type,
2011-11-07 13:46:58 -06:00
"id", NULL,
"uri", NULL,
NULL);
data->end_loading_id =
g_signal_connect_data (store,
"end_loading",
G_CALLBACK (store_end_loading),
message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free,
0);
}
static void
2011-11-07 16:52:18 -06:00
message_unregistered (PlumaMessageBus *bus,
PlumaMessageType *message_type,
PlumaWindow *window)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
gchar *identifier = pluma_message_type_identifier (pluma_message_type_get_object_path (message_type),
pluma_message_type_get_method (message_type));
2011-11-07 13:46:58 -06:00
FilterData *data;
WindowData *wdata = get_window_data (window);
data = g_hash_table_lookup (wdata->filters, identifier);
if (data)
2011-11-07 16:52:18 -06:00
pluma_file_browser_widget_remove_filter (wdata->widget, data->id);
2011-11-07 13:46:58 -06:00
g_free (identifier);
}
void
2011-11-07 16:52:18 -06:00
pluma_file_browser_messages_register (PlumaWindow *window,
PlumaFileBrowserWidget *widget)
2011-11-07 13:46:58 -06:00
{
window_data_new (window, widget);
register_methods (window, widget);
register_signals (window, widget);
2011-11-07 16:52:18 -06:00
g_signal_connect (pluma_window_get_message_bus (window),
2011-11-07 13:46:58 -06:00
"unregistered",
G_CALLBACK (message_unregistered),
window);
}
static void
2011-11-07 16:52:18 -06:00
cleanup_signals (PlumaWindow *window)
2011-11-07 13:46:58 -06:00
{
WindowData *data = get_window_data (window);
2011-11-07 16:52:18 -06:00
PlumaFileBrowserStore *store;
2011-11-07 13:46:58 -06:00
2011-11-07 16:52:18 -06:00
store = pluma_file_browser_widget_get_browser_store (data->widget);
2011-11-07 13:46:58 -06:00
g_signal_handler_disconnect (store, data->row_inserted_id);
g_signal_handler_disconnect (store, data->row_deleted_id);
g_signal_handler_disconnect (store, data->root_changed_id);
g_signal_handler_disconnect (store, data->begin_loading_id);
g_signal_handler_disconnect (store, data->end_loading_id);
g_signal_handlers_disconnect_by_func (data->bus, message_unregistered, window);
}
void
2011-11-07 16:52:18 -06:00
pluma_file_browser_messages_unregister (PlumaWindow *window)
2011-11-07 13:46:58 -06:00
{
2011-11-07 16:52:18 -06:00
PlumaMessageBus *bus = pluma_window_get_message_bus (window);
2011-11-07 13:46:58 -06:00
cleanup_signals (window);
2011-11-07 16:52:18 -06:00
pluma_message_bus_unregister_all (bus, MESSAGE_OBJECT_PATH);
2011-11-07 13:46:58 -06:00
window_data_free (window);
}