aboutsummaryrefslogtreecommitdiff
path: root/shell.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell.c')
-rw-r--r--shell.c91
1 files changed, 51 insertions, 40 deletions
diff --git a/shell.c b/shell.c
index 820a505b..50f36f6c 100644
--- a/shell.c
+++ b/shell.c
@@ -24,6 +24,7 @@
#include <hardinfo.h>
#include <shell.h>
+#include <syncmanager.h>
#include <iconcache.h>
#include <menu.h>
#include <stock.h>
@@ -104,7 +105,7 @@ void shell_action_set_property(const gchar * action_name,
void shell_action_set_enabled(const gchar * action_name, gboolean setting)
{
- if (params.gui_running) {
+ if (params.gui_running && shell->action_group) {
GtkAction *action;
action =
@@ -419,8 +420,6 @@ static void add_module_to_menu(gchar * name, GdkPixbuf * pixbuf)
{
gchar *about_module = g_strdup_printf("AboutModule%s", name);
- stock_icon_register_pixbuf(pixbuf, name);
-
GtkActionEntry entries[] = {
{
name, /* name */
@@ -440,6 +439,8 @@ static void add_module_to_menu(gchar * name, GdkPixbuf * pixbuf)
},
};
+ stock_icon_register_pixbuf(pixbuf, name);
+
gtk_action_group_add_actions(shell->action_group, entries, 2, NULL);
gtk_ui_manager_add_ui(shell->ui_manager,
@@ -458,8 +459,6 @@ static void
add_module_entry_to_view_menu(gchar * module, gchar * name,
GdkPixbuf * pixbuf, GtkTreeIter * iter)
{
- stock_icon_register_pixbuf(pixbuf, name);
-
GtkActionEntry entries[] = {
{
name, /* name */
@@ -471,6 +470,7 @@ add_module_entry_to_view_menu(gchar * module, gchar * name,
},
};
+ stock_icon_register_pixbuf(pixbuf, name);
gtk_action_group_add_actions(shell->action_group, entries, 1, iter);
gtk_ui_manager_add_ui(shell->ui_manager,
@@ -525,6 +525,11 @@ static void add_modules_to_gui(gpointer data, gpointer user_data)
}
}
+static void __tree_iter_destroy(gpointer data)
+{
+ gtk_tree_iter_free((GtkTreeIter *) data);
+}
+
void shell_init(GSList * modules)
{
if (shell) {
@@ -544,6 +549,8 @@ void shell_init(GSList * modules)
shell->info = info_tree_new(FALSE);
shell->moreinfo = info_tree_new(TRUE);
shell->loadgraph = load_graph_new(75);
+ update_tbl = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, __tree_iter_destroy);
gtk_paned_pack1(GTK_PANED(shell->hpaned), shell->tree->scroll,
SHELL_PACK_RESIZE, SHELL_PACK_SHRINK);
@@ -581,12 +588,24 @@ void shell_init(GSList * modules)
shell_action_set_enabled("SaveGraphAction", FALSE);
shell_action_set_active("SidePaneAction", TRUE);
shell_action_set_active("ToolbarAction", TRUE);
+
+#ifndef HAS_LIBSOUP
+ shell_action_set_enabled("SyncManagerAction", FALSE);
+#else
+ shell_action_set_enabled("SyncManagerAction", sync_manager_count_entries() > 0);
+#endif
}
static gboolean update_field(gpointer data)
{
- ShellFieldUpdate *fu = (ShellFieldUpdate *) data;
- GtkTreeIter *iter = g_hash_table_lookup(update_tbl, fu->field_name);
+ ShellFieldUpdate *fu;
+ GtkTreeIter *iter;
+
+ fu = (ShellFieldUpdate *) data;
+ g_return_val_if_fail(fu != NULL, FALSE);
+
+ iter = g_hash_table_lookup(update_tbl, fu->field_name);
+ g_return_val_if_fail(iter != NULL, FALSE);
/* if the entry is still selected, update it */
if (iter && fu->entry->selected && fu->entry->fieldfunc) {
@@ -917,9 +936,6 @@ moreinfo_handle_normal(GKeyFile * key_file, gchar * group, gchar ** keys)
}
}
-/* FIXME: This code must be rewritten. Although it works, it is *very* slow and
- too complex for this simple task. I am lazy, so I'm not fixing it.
- Be my guest to fix it. */
static void update_progress()
{
GtkTreeModel *model = shell->info->model;
@@ -1002,9 +1018,8 @@ static void
module_selected_show_info(ShellModuleEntry * entry, gboolean reload)
{
GKeyFile *key_file = g_key_file_new();
- gchar *key_data;
- gchar **groups;
GtkTreeStore *store;
+ gchar *key_data, **groups;
gint i;
gsize ngroups;
@@ -1016,16 +1031,9 @@ module_selected_show_info(ShellModuleEntry * entry, gboolean reload)
/* recreate the iter hash table */
if (!reload) {
- if (update_tbl) {
- g_hash_table_foreach_remove(update_tbl, (GHRFunc) gtk_true,
- NULL);
- } else {
- update_tbl =
- g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
- g_free);
- }
+ h_hash_table_remove_all(update_tbl);
}
-
+
if (update_sfusrc) {
GSList *sfusrc;
@@ -1124,22 +1132,26 @@ static void module_selected(gpointer data)
ShellModuleEntry *entry;
static ShellModuleEntry *current = NULL;
static gboolean updating = FALSE;
-
- if (updating)
- return;
-
- updating = TRUE;
+
/* Gets the currently selected item on the left-side TreeView; if there is no
selection, silently return */
if (!gtk_tree_selection_get_selected
- (shelltree->selection, &model, &parent))
+ (shelltree->selection, &model, &parent)) {
return;
+ }
/* Mark the currently selected module as "unselected"; this is used to kill the
update timeout. */
- if (current)
+ if (current) {
current->selected = FALSE;
+ }
+
+ if (updating) {
+ return;
+ } else {
+ updating = TRUE;
+ }
/* Get the current selection and shows its related info */
gtk_tree_model_get(model, &parent, TREE_COL_DATA, &entry, -1);
@@ -1157,18 +1169,17 @@ static void module_selected(gpointer data)
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(shell->info->view));
/* urgh. why don't GTK do this when the model is cleared? */
- gtk_range_set_value(GTK_RANGE
- (GTK_SCROLLED_WINDOW(shell->info->scroll)->
- vscrollbar), 0.0);
- gtk_range_set_value(GTK_RANGE
- (GTK_SCROLLED_WINDOW(shell->info->scroll)->
- hscrollbar), 0.0);
- gtk_range_set_value(GTK_RANGE
- (GTK_SCROLLED_WINDOW(shell->moreinfo->scroll)->
- vscrollbar), 0.0);
- gtk_range_set_value(GTK_RANGE
- (GTK_SCROLLED_WINDOW(shell->moreinfo->scroll)->
- hscrollbar), 0.0);
+#define RANGE_SET_VALUE(tree,scrollbar,value) \
+ gtk_range_set_value(GTK_RANGE \
+ (GTK_SCROLLED_WINDOW(shell->tree->scroll)-> \
+ scrollbar), value);
+
+ RANGE_SET_VALUE(info, vscrollbar, 0.0);
+ RANGE_SET_VALUE(info, hscrollbar, 0.0);
+ RANGE_SET_VALUE(moreinfo, vscrollbar, 0.0);
+ RANGE_SET_VALUE(moreinfo, hscrollbar, 0.0);
+
+#undef RANGE_SET_VALUE
shell_status_update("Done.");
shell_status_set_enabled(FALSE);