file-browser-messages: Clean up formatting

This commit is contained in:
JosephMcc 2017-02-13 15:02:25 -08:00
parent 372399891d
commit fe9e6ac91c
1 changed files with 263 additions and 249 deletions

View File

@ -2,8 +2,8 @@
#include "xed-file-browser-store.h" #include "xed-file-browser-store.h"
#include <xed/xed-message.h> #include <xed/xed-message.h>
#define MESSAGE_OBJECT_PATH "/plugins/filebrowser" #define MESSAGE_OBJECT_PATH "/plugins/filebrowser"
#define WINDOW_DATA_KEY "XedFileBrowserMessagesWindowData" #define WINDOW_DATA_KEY "XedFileBrowserMessagesWindowData"
#define BUS_CONNECT(bus, name, data) xed_message_bus_connect(bus, MESSAGE_OBJECT_PATH, #name, (XedMessageCallback) message_##name##_cb, data, NULL) #define BUS_CONNECT(bus, name, data) xed_message_bus_connect(bus, MESSAGE_OBJECT_PATH, #name, (XedMessageCallback) message_##name##_cb, data, NULL)
@ -41,7 +41,7 @@ typedef struct
static WindowData * static WindowData *
window_data_new (XedWindow *window, window_data_new (XedWindow *window,
XedFileBrowserWidget *widget) XedFileBrowserWidget *widget)
{ {
WindowData *data = g_slice_new (WindowData); WindowData *data = g_slice_new (WindowData);
GtkUIManager *manager; GtkUIManager *manager;
@ -50,14 +50,14 @@ window_data_new (XedWindow *window,
data->bus = xed_window_get_message_bus (window); data->bus = xed_window_get_message_bus (window);
data->widget = widget; data->widget = widget;
data->row_tracking = g_hash_table_new_full (g_str_hash, data->row_tracking = g_hash_table_new_full (g_str_hash,
g_str_equal, g_str_equal,
(GDestroyNotify)g_free, (GDestroyNotify)g_free,
(GDestroyNotify)gtk_tree_row_reference_free); (GDestroyNotify)gtk_tree_row_reference_free);
data->filters = g_hash_table_new_full (g_str_hash, data->filters = g_hash_table_new_full (g_str_hash,
g_str_equal, g_str_equal,
(GDestroyNotify)g_free, (GDestroyNotify)g_free,
NULL); NULL);
manager = xed_file_browser_widget_get_ui_manager (widget); manager = xed_file_browser_widget_get_ui_manager (widget);
@ -92,7 +92,9 @@ window_data_free (XedWindow *window)
gtk_ui_manager_remove_action_group (manager, data->merged_actions); gtk_ui_manager_remove_action_group (manager, data->merged_actions);
for (item = data->merge_ids; item; item = item->next) for (item = data->merge_ids; item; item = item->next)
{
gtk_ui_manager_remove_ui (manager, GPOINTER_TO_INT (item->data)); gtk_ui_manager_remove_ui (manager, GPOINTER_TO_INT (item->data));
}
g_list_free (data->merge_ids); g_list_free (data->merge_ids);
g_object_unref (data->merged_actions); g_object_unref (data->merged_actions);
@ -104,7 +106,7 @@ window_data_free (XedWindow *window)
static FilterData * static FilterData *
filter_data_new (XedWindow *window, filter_data_new (XedWindow *window,
XedMessage *message) XedMessage *message)
{ {
FilterData *data = g_slice_new (FilterData); FilterData *data = g_slice_new (FilterData);
WindowData *wdata; WindowData *wdata;
@ -115,10 +117,8 @@ filter_data_new (XedWindow *window,
wdata = get_window_data (window); wdata = get_window_data (window);
g_hash_table_insert (wdata->filters, g_hash_table_insert (wdata->filters, xed_message_type_identifier (xed_message_get_object_path (message),
xed_message_type_identifier (xed_message_get_object_path (message), xed_message_get_method (message)), data);
xed_message_get_method (message)),
data);
return data; return data;
} }
@ -130,7 +130,7 @@ filter_data_free (FilterData *data)
gchar *identifier; gchar *identifier;
identifier = xed_message_type_identifier (xed_message_get_object_path (data->message), identifier = xed_message_type_identifier (xed_message_get_object_path (data->message),
xed_message_get_method (data->message)); xed_message_get_method (data->message));
g_hash_table_remove (wdata->filters, identifier); g_hash_table_remove (wdata->filters, identifier);
g_free (identifier); g_free (identifier);
@ -141,14 +141,16 @@ filter_data_free (FilterData *data)
static GtkTreePath * static GtkTreePath *
track_row_lookup (WindowData *data, track_row_lookup (WindowData *data,
const gchar *id) const gchar *id)
{ {
GtkTreeRowReference *ref; GtkTreeRowReference *ref;
ref = (GtkTreeRowReference *)g_hash_table_lookup (data->row_tracking, id); ref = (GtkTreeRowReference *)g_hash_table_lookup (data->row_tracking, id);
if (!ref) if (!ref)
{
return NULL; return NULL;
}
return gtk_tree_row_reference_get_path (ref); return gtk_tree_row_reference_get_path (ref);
} }
@ -161,8 +163,8 @@ message_cache_data_free (MessageCacheData *data)
} }
static MessageCacheData * static MessageCacheData *
message_cache_data_new (XedWindow *window, message_cache_data_new (XedWindow *window,
XedMessage *message) XedMessage *message)
{ {
MessageCacheData *data = g_slice_new (MessageCacheData); MessageCacheData *data = g_slice_new (MessageCacheData);
@ -174,8 +176,8 @@ message_cache_data_new (XedWindow *window,
static void static void
message_get_root_cb (XedMessageBus *bus, message_get_root_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
XedFileBrowserStore *store; XedFileBrowserStore *store;
GFile *location; GFile *location;
@ -192,8 +194,8 @@ message_get_root_cb (XedMessageBus *bus,
static void static void
message_set_root_cb (XedMessageBus *bus, message_set_root_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
GFile *root; GFile *root;
GFile *virtual = NULL; GFile *virtual = NULL;
@ -201,21 +203,29 @@ message_set_root_cb (XedMessageBus *bus,
xed_message_get (message, "location", &root, NULL); xed_message_get (message, "location", &root, NULL);
if (!root) if (!root)
{
return; return;
}
if (xed_message_has_key (message, "virtual")) if (xed_message_has_key (message, "virtual"))
{
xed_message_get (message, "virtual", &virtual, NULL); xed_message_get (message, "virtual", &virtual, NULL);
}
if (virtual) if (virtual)
{
xed_file_browser_widget_set_root_and_virtual_root (data->widget, root, virtual); xed_file_browser_widget_set_root_and_virtual_root (data->widget, root, virtual);
}
else else
{
xed_file_browser_widget_set_root (data->widget, root, TRUE); xed_file_browser_widget_set_root (data->widget, root, TRUE);
}
} }
static void static void
message_set_emblem_cb (XedMessageBus *bus, message_set_emblem_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
gchar *id = NULL; gchar *id = NULL;
gchar *emblem = NULL; gchar *emblem = NULL;
@ -239,11 +249,7 @@ message_set_emblem_cb (XedMessageBus *bus,
GError *error = NULL; GError *error = NULL;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), emblem, 10, 0, &error);
emblem,
10,
0,
&error);
if (pixbuf) if (pixbuf)
{ {
@ -257,10 +263,7 @@ message_set_emblem_cb (XedMessageBus *bus,
g_value_init (&value, GDK_TYPE_PIXBUF); g_value_init (&value, GDK_TYPE_PIXBUF);
g_value_set_object (&value, pixbuf); g_value_set_object (&value, pixbuf);
xed_file_browser_store_set_value (store, xed_file_browser_store_set_value (store, &iter, XED_FILE_BROWSER_STORE_COLUMN_EMBLEM, &value);
&iter,
XED_FILE_BROWSER_STORE_COLUMN_EMBLEM,
&value);
g_value_unset (&value); g_value_unset (&value);
} }
@ -278,7 +281,7 @@ message_set_emblem_cb (XedMessageBus *bus,
static gchar * static gchar *
item_id (const gchar *path, item_id (const gchar *path,
GFile *location) GFile *location)
{ {
gchar *uri; gchar *uri;
gchar *id; gchar *id;
@ -291,10 +294,10 @@ item_id (const gchar *path,
} }
static gchar * static gchar *
track_row (WindowData *data, track_row (WindowData *data,
XedFileBrowserStore *store, XedFileBrowserStore *store,
GtkTreePath *path, GtkTreePath *path,
GFile *location) GFile *location)
{ {
GtkTreeRowReference *ref; GtkTreeRowReference *ref;
gchar *id; gchar *id;
@ -312,10 +315,10 @@ track_row (WindowData *data,
} }
static void static void
set_item_message (WindowData *data, set_item_message (WindowData *data,
GtkTreeIter *iter, GtkTreeIter *iter,
GtkTreePath *path, GtkTreePath *path,
XedMessage *message) XedMessage *message)
{ {
XedFileBrowserStore *store; XedFileBrowserStore *store;
GFile *location; GFile *location;
@ -325,28 +328,29 @@ set_item_message (WindowData *data,
store = xed_file_browser_widget_get_browser_store (data->widget); store = xed_file_browser_widget_get_browser_store (data->widget);
gtk_tree_model_get (GTK_TREE_MODEL (store), iter, gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1); -1);
if (!location) if (!location)
{
return; return;
}
if (path && gtk_tree_path_get_depth (path) != 0) if (path && gtk_tree_path_get_depth (path) != 0)
{
track_id = track_row (data, store, path, location); track_id = track_row (data, store, path, location);
}
else else
{
track_id = NULL; track_id = NULL;
}
xed_message_set (message, xed_message_set (message, "id", track_id, "location", location, NULL);
"id", track_id,
"location", location,
NULL);
if (xed_message_has_key (message, "is_directory")) if (xed_message_has_key (message, "is_directory"))
{ {
xed_message_set (message, xed_message_set (message, "is_directory", FILE_IS_DIR (flags), NULL);
"is_directory", FILE_IS_DIR (flags),
NULL);
} }
g_free (track_id); g_free (track_id);
@ -354,9 +358,9 @@ set_item_message (WindowData *data,
static gboolean static gboolean
custom_message_filter_func (XedFileBrowserWidget *widget, custom_message_filter_func (XedFileBrowserWidget *widget,
XedFileBrowserStore *store, XedFileBrowserStore *store,
GtkTreeIter *iter, GtkTreeIter *iter,
FilterData *data) FilterData *data)
{ {
WindowData *wdata = get_window_data (data->window); WindowData *wdata = get_window_data (data->window);
GFile *location; GFile *location;
@ -365,9 +369,9 @@ custom_message_filter_func (XedFileBrowserWidget *widget,
GtkTreePath *path; GtkTreePath *path;
gtk_tree_model_get (GTK_TREE_MODEL (store), iter, gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1); -1);
if (!location || FILE_IS_DUMMY (flags)) if (!location || FILE_IS_DUMMY (flags))
{ {
@ -388,8 +392,8 @@ custom_message_filter_func (XedFileBrowserWidget *widget,
static void static void
message_add_filter_cb (XedMessageBus *bus, message_add_filter_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
XedWindow *window) XedWindow *window)
{ {
gchar *object_path = NULL; gchar *object_path = NULL;
gchar *method = NULL; gchar *method = NULL;
@ -399,10 +403,7 @@ message_add_filter_cb (XedMessageBus *bus,
FilterData *filter_data; FilterData *filter_data;
WindowData *data = get_window_data (window); WindowData *data = get_window_data (window);
xed_message_get (message, xed_message_get (message, "object_path", &object_path, "method", &method, NULL);
"object_path", &object_path,
"method", &method,
NULL);
// Check if there exists such a 'callback' message // Check if there exists such a 'callback' message
if (!object_path || !method) if (!object_path || !method)
@ -433,41 +434,43 @@ message_add_filter_cb (XedMessageBus *bus,
} }
cbmessage = xed_message_type_instantiate (message_type, cbmessage = xed_message_type_instantiate (message_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
"is_directory", FALSE, "is_directory", FALSE,
"filter", FALSE, "filter", FALSE,
NULL); NULL);
// Register the custom filter on the widget // Register the custom filter on the widget
filter_data = filter_data_new (window, cbmessage); filter_data = filter_data_new (window, cbmessage);
id = xed_file_browser_widget_add_filter (data->widget, id = xed_file_browser_widget_add_filter (data->widget,
(XedFileBrowserWidgetFilterFunc)custom_message_filter_func, (XedFileBrowserWidgetFilterFunc)custom_message_filter_func,
filter_data, filter_data,
(GDestroyNotify)filter_data_free); (GDestroyNotify)filter_data_free);
filter_data->id = id; filter_data->id = id;
} }
static void static void
message_remove_filter_cb (XedMessageBus *bus, message_remove_filter_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
gulong id = 0; gulong id = 0;
xed_message_get (message, "id", &id, NULL); xed_message_get (message, "id", &id, NULL);
if (!id) if (!id)
{
return; return;
}
xed_file_browser_widget_remove_filter (data->widget, id); xed_file_browser_widget_remove_filter (data->widget, id);
} }
static void static void
message_up_cb (XedMessageBus *bus, message_up_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
XedFileBrowserStore *store = xed_file_browser_widget_get_browser_store (data->widget); XedFileBrowserStore *store = xed_file_browser_widget_get_browser_store (data->widget);
@ -476,32 +479,32 @@ message_up_cb (XedMessageBus *bus,
static void static void
message_history_back_cb (XedMessageBus *bus, message_history_back_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_history_back (data->widget); xed_file_browser_widget_history_back (data->widget);
} }
static void static void
message_history_forward_cb (XedMessageBus *bus, message_history_forward_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_history_forward (data->widget); xed_file_browser_widget_history_forward (data->widget);
} }
static void static void
message_refresh_cb (XedMessageBus *bus, message_refresh_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_refresh (data->widget); xed_file_browser_widget_refresh (data->widget);
} }
static void static void
message_set_show_hidden_cb (XedMessageBus *bus, message_set_show_hidden_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
gboolean active = FALSE; gboolean active = FALSE;
XedFileBrowserStore *store; XedFileBrowserStore *store;
@ -513,17 +516,21 @@ message_set_show_hidden_cb (XedMessageBus *bus,
mode = xed_file_browser_store_get_filter_mode (store); mode = xed_file_browser_store_get_filter_mode (store);
if (active) if (active)
{
mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN;
}
else else
{
mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN;
}
xed_file_browser_store_set_filter_mode (store, mode); xed_file_browser_store_set_filter_mode (store, mode);
} }
static void static void
message_set_show_binary_cb (XedMessageBus *bus, message_set_show_binary_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
gboolean active = FALSE; gboolean active = FALSE;
XedFileBrowserStore *store; XedFileBrowserStore *store;
@ -535,33 +542,37 @@ message_set_show_binary_cb (XedMessageBus *bus,
mode = xed_file_browser_store_get_filter_mode (store); mode = xed_file_browser_store_get_filter_mode (store);
if (active) if (active)
{
mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY;
}
else else
{
mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY;
}
xed_file_browser_store_set_filter_mode (store, mode); xed_file_browser_store_set_filter_mode (store, mode);
} }
static void static void
message_show_bookmarks_cb (XedMessageBus *bus, message_show_bookmarks_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_show_bookmarks (data->widget); xed_file_browser_widget_show_bookmarks (data->widget);
} }
static void static void
message_show_files_cb (XedMessageBus *bus, message_show_files_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
xed_file_browser_widget_show_files (data->widget); xed_file_browser_widget_show_files (data->widget);
} }
static void static void
message_add_context_item_cb (XedMessageBus *bus, message_add_context_item_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
GtkAction *action = NULL; GtkAction *action = NULL;
gchar *path = NULL; gchar *path = NULL;
@ -569,15 +580,14 @@ message_add_context_item_cb (XedMessageBus *bus,
GtkUIManager *manager; GtkUIManager *manager;
guint merge_id; guint merge_id;
xed_message_get (message, xed_message_get (message, "action", &action, "path", &path, NULL);
"action", &action,
"path", &path,
NULL);
if (!action || !path) if (!action || !path)
{ {
if (action) if (action)
{
g_object_unref (action); g_object_unref (action);
}
g_free (path); g_free (path);
return; return;
@ -589,12 +599,12 @@ message_add_context_item_cb (XedMessageBus *bus,
merge_id = gtk_ui_manager_new_merge_id (manager); merge_id = gtk_ui_manager_new_merge_id (manager);
gtk_ui_manager_add_ui (manager, gtk_ui_manager_add_ui (manager,
merge_id, merge_id,
path, path,
name, name,
gtk_action_get_name (action), gtk_action_get_name (action),
GTK_UI_MANAGER_AUTO, GTK_UI_MANAGER_AUTO,
FALSE); FALSE);
if (gtk_ui_manager_get_widget (manager, path)) if (gtk_ui_manager_get_widget (manager, path))
{ {
@ -613,8 +623,8 @@ message_add_context_item_cb (XedMessageBus *bus,
static void static void
message_remove_context_item_cb (XedMessageBus *bus, message_remove_context_item_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
guint merge_id = 0; guint merge_id = 0;
GtkUIManager *manager; GtkUIManager *manager;
@ -622,7 +632,9 @@ message_remove_context_item_cb (XedMessageBus *bus,
xed_message_get (message, "id", &merge_id, NULL); xed_message_get (message, "id", &merge_id, NULL);
if (merge_id == 0) if (merge_id == 0)
{
return; return;
}
manager = xed_file_browser_widget_get_ui_manager (data->widget); manager = xed_file_browser_widget_get_ui_manager (data->widget);
@ -632,8 +644,8 @@ message_remove_context_item_cb (XedMessageBus *bus,
static void static void
message_get_view_cb (XedMessageBus *bus, message_get_view_cb (XedMessageBus *bus,
XedMessage *message, XedMessage *message,
WindowData *data) WindowData *data)
{ {
XedFileBrowserView *view; XedFileBrowserView *view;
view = xed_file_browser_widget_get_browser_view (data->widget); view = xed_file_browser_widget_get_browser_view (data->widget);
@ -643,59 +655,59 @@ message_get_view_cb (XedMessageBus *bus,
static void static void
register_methods (XedWindow *window, register_methods (XedWindow *window,
XedFileBrowserWidget *widget) XedFileBrowserWidget *widget)
{ {
XedMessageBus *bus = xed_window_get_message_bus (window); XedMessageBus *bus = xed_window_get_message_bus (window);
WindowData *data = get_window_data (window); WindowData *data = get_window_data (window);
/* Register method calls */ /* Register method calls */
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "get_root", MESSAGE_OBJECT_PATH, "get_root",
1, 1,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "set_root", MESSAGE_OBJECT_PATH, "set_root",
1, 1,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
"virtual", G_TYPE_STRING, "virtual", G_TYPE_STRING,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "set_emblem", MESSAGE_OBJECT_PATH, "set_emblem",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"emblem", G_TYPE_STRING, "emblem", G_TYPE_STRING,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "add_filter", MESSAGE_OBJECT_PATH, "add_filter",
1, 1,
"object_path", G_TYPE_STRING, "object_path", G_TYPE_STRING,
"method", G_TYPE_STRING, "method", G_TYPE_STRING,
"id", G_TYPE_ULONG, "id", G_TYPE_ULONG,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "remove_filter", MESSAGE_OBJECT_PATH, "remove_filter",
0, 0,
"id", G_TYPE_ULONG, "id", G_TYPE_ULONG,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "add_context_item", MESSAGE_OBJECT_PATH, "add_context_item",
1, 1,
"action", GTK_TYPE_ACTION, "action", GTK_TYPE_ACTION,
"path", G_TYPE_STRING, "path", G_TYPE_STRING,
"id", G_TYPE_UINT, "id", G_TYPE_UINT,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "remove_context_item", MESSAGE_OBJECT_PATH, "remove_context_item",
0, 0,
"id", G_TYPE_UINT, "id", G_TYPE_UINT,
NULL); NULL);
xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "up", 0, NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "up", 0, NULL);
@ -705,24 +717,24 @@ register_methods (XedWindow *window,
xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "refresh", 0, NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "refresh", 0, NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "set_show_hidden", MESSAGE_OBJECT_PATH, "set_show_hidden",
0, 0,
"active", G_TYPE_BOOLEAN, "active", G_TYPE_BOOLEAN,
NULL); NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "set_show_binary", MESSAGE_OBJECT_PATH, "set_show_binary",
0, 0,
"active", G_TYPE_BOOLEAN, "active", G_TYPE_BOOLEAN,
NULL); NULL);
xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_bookmarks", 0, NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_bookmarks", 0, NULL);
xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_files", 0, NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_files", 0, NULL);
xed_message_bus_register (bus, xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "get_view", MESSAGE_OBJECT_PATH, "get_view",
1, 1,
"view", XED_TYPE_FILE_BROWSER_VIEW, "view", XED_TYPE_FILE_BROWSER_VIEW,
NULL); NULL);
BUS_CONNECT (bus, get_root, data); BUS_CONNECT (bus, get_root, data);
BUS_CONNECT (bus, set_root, data); BUS_CONNECT (bus, set_root, data);
@ -750,15 +762,15 @@ register_methods (XedWindow *window,
static void static void
store_row_inserted (XedFileBrowserStore *store, store_row_inserted (XedFileBrowserStore *store,
GtkTreePath *path, GtkTreePath *path,
GtkTreeIter *iter, GtkTreeIter *iter,
MessageCacheData *data) MessageCacheData *data)
{ {
guint flags = 0; guint flags = 0;
gtk_tree_model_get (GTK_TREE_MODEL (store), iter, gtk_tree_model_get (GTK_TREE_MODEL (store), iter,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1); -1);
if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags))
{ {
@ -771,18 +783,20 @@ store_row_inserted (XedFileBrowserStore *store,
static void static void
store_row_deleted (XedFileBrowserStore *store, store_row_deleted (XedFileBrowserStore *store,
GtkTreePath *path, GtkTreePath *path,
MessageCacheData *data) MessageCacheData *data)
{ {
GtkTreeIter iter; GtkTreeIter iter;
guint flags = 0; guint flags = 0;
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path))
{
return; return;
}
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags,
-1); -1);
if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags))
{ {
@ -795,8 +809,8 @@ store_row_deleted (XedFileBrowserStore *store,
static void static void
store_virtual_root_changed (XedFileBrowserStore *store, store_virtual_root_changed (XedFileBrowserStore *store,
GParamSpec *spec, GParamSpec *spec,
MessageCacheData *data) MessageCacheData *data)
{ {
WindowData *wdata = get_window_data (data->window); WindowData *wdata = get_window_data (data->window);
GFile *vroot; GFile *vroot;
@ -804,11 +818,11 @@ store_virtual_root_changed (XedFileBrowserStore *store,
vroot = xed_file_browser_store_get_virtual_root (store); vroot = xed_file_browser_store_get_virtual_root (store);
if (!vroot) if (!vroot)
{
return; return;
}
xed_message_set (data->message, xed_message_set (data->message, "location", vroot, NULL);
"location", vroot,
NULL);
xed_message_bus_send_message_sync (wdata->bus, data->message); xed_message_bus_send_message_sync (wdata->bus, data->message);
@ -817,8 +831,8 @@ store_virtual_root_changed (XedFileBrowserStore *store,
static void static void
store_begin_loading (XedFileBrowserStore *store, store_begin_loading (XedFileBrowserStore *store,
GtkTreeIter *iter, GtkTreeIter *iter,
MessageCacheData *data) MessageCacheData *data)
{ {
GtkTreePath *path; GtkTreePath *path;
WindowData *wdata = get_window_data (data->window); WindowData *wdata = get_window_data (data->window);
@ -833,8 +847,8 @@ store_begin_loading (XedFileBrowserStore *store,
static void static void
store_end_loading (XedFileBrowserStore *store, store_end_loading (XedFileBrowserStore *store,
GtkTreeIter *iter, GtkTreeIter *iter,
MessageCacheData *data) MessageCacheData *data)
{ {
GtkTreePath *path; GtkTreePath *path;
WindowData *wdata = get_window_data (data->window); WindowData *wdata = get_window_data (data->window);
@ -849,7 +863,7 @@ store_end_loading (XedFileBrowserStore *store,
static void static void
register_signals (XedWindow *window, register_signals (XedWindow *window,
XedFileBrowserWidget *widget) XedFileBrowserWidget *widget)
{ {
XedMessageBus *bus = xed_window_get_message_bus (window); XedMessageBus *bus = xed_window_get_message_bus (window);
XedFileBrowserStore *store; XedFileBrowserStore *store;
@ -864,141 +878,141 @@ register_signals (XedWindow *window,
/* Register signals */ /* Register signals */
root_changed_type = xed_message_bus_register (bus, root_changed_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "root_changed", MESSAGE_OBJECT_PATH, "root_changed",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
NULL); NULL);
begin_loading_type = xed_message_bus_register (bus, begin_loading_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "begin_loading", MESSAGE_OBJECT_PATH, "begin_loading",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
NULL); NULL);
end_loading_type = xed_message_bus_register (bus, end_loading_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "end_loading", MESSAGE_OBJECT_PATH, "end_loading",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
NULL); NULL);
inserted_type = xed_message_bus_register (bus, inserted_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "inserted", MESSAGE_OBJECT_PATH, "inserted",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
"is_directory", G_TYPE_BOOLEAN, "is_directory", G_TYPE_BOOLEAN,
NULL); NULL);
deleted_type = xed_message_bus_register (bus, deleted_type = xed_message_bus_register (bus,
MESSAGE_OBJECT_PATH, "deleted", MESSAGE_OBJECT_PATH, "deleted",
0, 0,
"id", G_TYPE_STRING, "id", G_TYPE_STRING,
"location", G_TYPE_FILE, "location", G_TYPE_FILE,
"is_directory", G_TYPE_BOOLEAN, "is_directory", G_TYPE_BOOLEAN,
NULL); NULL);
store = xed_file_browser_widget_get_browser_store (widget); store = xed_file_browser_widget_get_browser_store (widget);
message = xed_message_type_instantiate (inserted_type, message = xed_message_type_instantiate (inserted_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
"is_directory", FALSE, "is_directory", FALSE,
NULL); NULL);
data = get_window_data (window); data = get_window_data (window);
data->row_inserted_id = data->row_inserted_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"row-inserted", "row-inserted",
G_CALLBACK (store_row_inserted), G_CALLBACK (store_row_inserted),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
message = xed_message_type_instantiate (deleted_type, message = xed_message_type_instantiate (deleted_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
"is_directory", FALSE, "is_directory", FALSE,
NULL); NULL);
data->row_deleted_id = data->row_deleted_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"row-deleted", "row-deleted",
G_CALLBACK (store_row_deleted), G_CALLBACK (store_row_deleted),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
message = xed_message_type_instantiate (root_changed_type, message = xed_message_type_instantiate (root_changed_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
NULL); NULL);
data->root_changed_id = data->root_changed_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"notify::virtual-root", "notify::virtual-root",
G_CALLBACK (store_virtual_root_changed), G_CALLBACK (store_virtual_root_changed),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
message = xed_message_type_instantiate (begin_loading_type, message = xed_message_type_instantiate (begin_loading_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
NULL); NULL);
data->begin_loading_id = data->begin_loading_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"begin_loading", "begin_loading",
G_CALLBACK (store_begin_loading), G_CALLBACK (store_begin_loading),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
message = xed_message_type_instantiate (end_loading_type, message = xed_message_type_instantiate (end_loading_type,
"id", NULL, "id", NULL,
"location", NULL, "location", NULL,
NULL); NULL);
data->end_loading_id = data->end_loading_id =
g_signal_connect_data (store, g_signal_connect_data (store,
"end_loading", "end_loading",
G_CALLBACK (store_end_loading), G_CALLBACK (store_end_loading),
message_cache_data_new (window, message), message_cache_data_new (window, message),
(GClosureNotify)message_cache_data_free, (GClosureNotify)message_cache_data_free,
0); 0);
} }
static void static void
message_unregistered (XedMessageBus *bus, message_unregistered (XedMessageBus *bus,
XedMessageType *message_type, XedMessageType *message_type,
XedWindow *window) XedWindow *window)
{ {
gchar *identifier = xed_message_type_identifier (xed_message_type_get_object_path (message_type), gchar *identifier = xed_message_type_identifier (xed_message_type_get_object_path (message_type),
xed_message_type_get_method (message_type)); xed_message_type_get_method (message_type));
FilterData *data; FilterData *data;
WindowData *wdata = get_window_data (window); WindowData *wdata = get_window_data (window);
data = g_hash_table_lookup (wdata->filters, identifier); data = g_hash_table_lookup (wdata->filters, identifier);
if (data) if (data)
{
xed_file_browser_widget_remove_filter (wdata->widget, data->id); xed_file_browser_widget_remove_filter (wdata->widget, data->id);
}
g_free (identifier); g_free (identifier);
} }
void void
xed_file_browser_messages_register (XedWindow *window, xed_file_browser_messages_register (XedWindow *window,
XedFileBrowserWidget *widget) XedFileBrowserWidget *widget)
{ {
window_data_new (window, widget); window_data_new (window, widget);
register_methods (window, widget); register_methods (window, widget);
register_signals (window, widget); register_signals (window, widget);
g_signal_connect (xed_window_get_message_bus (window), g_signal_connect (xed_window_get_message_bus (window), "unregistered",
"unregistered", G_CALLBACK (message_unregistered), window);
G_CALLBACK (message_unregistered),
window);
} }
static void static void