Skip to content

Commit

Permalink
Add a new struct ConfOptions to handle options.
Browse files Browse the repository at this point in the history
Changes were made among the code to use only one global var
named "options" of type ConfOptions *.
Initialization takes place in new init_options().
  • Loading branch information
Laurent Monin committed Apr 11, 2008
1 parent 1155979 commit d2979ca
Show file tree
Hide file tree
Showing 33 changed files with 812 additions and 849 deletions.
2 changes: 1 addition & 1 deletion src/bar_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ gint comment_write(FileData *fd, GList *keywords, const gchar *comment)
{
if (!fd) return FALSE;

if (enable_metadata_dirs && /* FIXME - use dedicated option */
if (options->enable_metadata_dirs && /* FIXME - use dedicated option */
comment_xmp_write(fd, keywords, comment))
{
comment_delete_legacy(fd);
Expand Down
2 changes: 1 addition & 1 deletion src/cache-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static gboolean cache_loader_process(CacheLoader *cl)
else
{
/* done, save then call done function */
if (enable_thumb_caching &&
if (options->enable_thumb_caching &&
cl->done_mask != CACHE_LOADER_NONE)
{
gchar *base;
Expand Down
8 changes: 4 additions & 4 deletions src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ gchar *cache_get_location(CacheType type, const gchar *source, gint include_name
cache_ext = NULL;
}

if (((type != CACHE_TYPE_METADATA && enable_thumb_dirs) ||
(type == CACHE_TYPE_METADATA && enable_metadata_dirs)) &&
if (((type != CACHE_TYPE_METADATA && options->enable_thumb_dirs) ||
(type == CACHE_TYPE_METADATA && options->enable_metadata_dirs)) &&
access_file(base, W_OK))
{
path = g_strconcat(base, "/", cache_local, name, cache_ext, NULL);
Expand Down Expand Up @@ -699,11 +699,11 @@ gchar *cache_find_location(CacheType type, const gchar *source)

if (type == CACHE_TYPE_METADATA)
{
prefer_local = enable_metadata_dirs;
prefer_local = options->enable_metadata_dirs;
}
else
{
prefer_local = enable_thumb_dirs;
prefer_local = options->enable_thumb_dirs;
}

if (prefer_local)
Expand Down
10 changes: 6 additions & 4 deletions src/cache_maint.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,8 @@ void cache_maint_moved(FileData *fd)
}
g_free(base);

if (enable_thumb_caching && thumbnail_spec_standard) thumb_std_maint_moved(src, dest);
if (options->enable_thumb_caching && options->thumbnail_spec_standard)
thumb_std_maint_moved(src, dest);
}

static void cache_file_remove(const gchar *path)
Expand All @@ -574,7 +575,8 @@ void cache_maint_removed(FileData *fd)
cache_file_remove(buf);
g_free(buf);

if (enable_thumb_caching && thumbnail_spec_standard) thumb_std_maint_removed(fd->path);
if (options->enable_thumb_caching && options->thumbnail_spec_standard)
thumb_std_maint_removed(fd->path);
}

void cache_maint_copied(FileData *fd)
Expand Down Expand Up @@ -738,7 +740,7 @@ static gint cache_manager_render_file(CleanData *cd)
path = cd->list->data;
cd->list = g_list_remove(cd->list, path);

cd->tl = (ThumbLoaderStd *)thumb_loader_new(thumb_max_width, thumb_max_height);
cd->tl = (ThumbLoaderStd *)thumb_loader_new(options->thumb_max_width, options->thumb_max_height);
thumb_loader_set_callbacks((ThumbLoader *)cd->tl,
cache_manager_render_thumb_done_cb,
cache_manager_render_thumb_done_cb,
Expand Down Expand Up @@ -849,7 +851,7 @@ static void cache_manager_render_dialog(GtkWidget *widget, const gchar *path)

pref_checkbox_new_int(cd->group, _("Include subfolders"), FALSE, &cd->recurse);
button = pref_checkbox_new_int(cd->group, _("Store thumbnails local to source images"), FALSE, &cd->local);
gtk_widget_set_sensitive(button, thumbnail_spec_standard);
gtk_widget_set_sensitive(button, options->thumbnail_spec_standard);

pref_line(cd->gd->vbox, PREF_PAD_SPACE);
hbox = pref_box_new(cd->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
Expand Down
2 changes: 1 addition & 1 deletion src/collect-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static void collection_load_thumb_step(CollectionData *cd)
/* setup loader and call it */
cd->thumb_info = ci;
thumb_loader_free(cd->thumb_loader);
cd->thumb_loader = thumb_loader_new(thumb_max_width, thumb_max_height);
cd->thumb_loader = thumb_loader_new(options->thumb_max_width, options->thumb_max_height);
thumb_loader_set_callbacks(cd->thumb_loader,
collection_load_thumb_done_cb,
collection_load_thumb_error_cb,
Expand Down
18 changes: 9 additions & 9 deletions src/collect-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ static gint collection_table_get_icon_width(CollectTable *ct)
{
gint width;

if (!ct->show_text) return thumb_max_width;
if (!ct->show_text) return options->thumb_max_width;

width = thumb_max_width + thumb_max_width / 2;
width = options->thumb_max_width + options->thumb_max_width / 2;
if (width < THUMB_MIN_ICON_WIDTH) width = THUMB_MIN_ICON_WIDTH;
if (width > THUMB_MAX_ICON_WIDTH) width = thumb_max_width;
if (width > THUMB_MAX_ICON_WIDTH) width = options->thumb_max_width;

return width;
}
Expand Down Expand Up @@ -366,7 +366,7 @@ static void collection_table_select_region_util(CollectTable *ct, CollectInfo *s

ct->prev_selection = end;

if (!collection_rectangular_selection)
if (!options->collection_rectangular_selection)
{
GList *work;
CollectInfo *info;
Expand Down Expand Up @@ -988,8 +988,8 @@ static gint page_height(CollectTable *ct)
adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
page_size = (gint)adj->page_increment;

row_height = thumb_max_height + THUMB_BORDER_PADDING * 2;
if (ct->show_text) row_height += thumb_max_height / 3;
row_height = options->thumb_max_height + THUMB_BORDER_PADDING * 2;
if (ct->show_text) row_height += options->thumb_max_height / 3;

ret = page_size / row_height;
if (ret < 1) ret = 1;
Expand Down Expand Up @@ -1100,7 +1100,7 @@ static gint collection_table_press_key_cb(GtkWidget *widget, GdkEventKey *event,
{
if (event->state & GDK_SHIFT_MASK)
{
if (!collection_rectangular_selection)
if (!options->collection_rectangular_selection)
{
collection_table_select_region_util(ct, old_info, new_info, FALSE);
}
Expand Down Expand Up @@ -1392,7 +1392,7 @@ static void collection_table_scroll(CollectTable *ct, gint scroll)
else
{
GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(ct->listview));
widget_auto_scroll_start(ct->listview, adj, -1, thumb_max_height / 2,
widget_auto_scroll_start(ct->listview, adj, -1, options->thumb_max_height / 2,
collection_table_auto_scroll_notify_cb, ct);
}
}
Expand Down Expand Up @@ -1594,7 +1594,7 @@ static void collection_table_populate(CollectTable *ct, gint resize)
if (cell && GQV_IS_CELL_RENDERER_ICON(cell))
{
g_object_set(G_OBJECT(cell), "fixed_width", thumb_width,
"fixed_height", thumb_max_height,
"fixed_height", options->thumb_max_height,
"show_text", ct->show_text, NULL);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/collect.c
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ CollectWindow *collection_window_new(const gchar *path)
GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);


if (save_window_positions && path && collection_load_only_geometry(cw->cd, path))
if (options->save_window_positions && path && collection_load_only_geometry(cw->cd, path))
{
/* FIXME: x, y is not implemented */
gtk_window_set_default_size(GTK_WINDOW(cw->window), cw->cd->window_w, cw->cd->window_h);
Expand Down
20 changes: 10 additions & 10 deletions src/dupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ static gint dupe_match(DupeItem *a, DupeItem *b, DupeMatchType mask, gdouble *ra

if (mask & DUPE_MATCH_SIM_HIGH) m = 0.95;
else if (mask & DUPE_MATCH_SIM_MED) m = 0.90;
else if (mask & DUPE_MATCH_SIM_CUSTOM) m = (gdouble)dupe_custom_threshold / 100.0;
else if (mask & DUPE_MATCH_SIM_CUSTOM) m = (gdouble)options->dupe_custom_threshold / 100.0;
else m = 0.85;

if (fast)
Expand Down Expand Up @@ -1327,7 +1327,7 @@ static void dupe_thumb_step(DupeWindow *dw)

dw->thumb_item = di;
thumb_loader_free(dw->thumb_loader);
dw->thumb_loader = thumb_loader_new(thumb_max_width, thumb_max_height);
dw->thumb_loader = thumb_loader_new(options->thumb_max_width, options->thumb_max_height);

thumb_loader_set_callbacks(dw->thumb_loader,
dupe_thumb_done_cb,
Expand Down Expand Up @@ -1393,7 +1393,7 @@ static void dupe_loader_done_cb(ImageLoader *il, gpointer data)
di->width = gdk_pixbuf_get_width(pixbuf);
di->height = gdk_pixbuf_get_height(pixbuf);
}
if (enable_thumb_caching)
if (options->enable_thumb_caching)
{
dupe_item_write_cache(di);
}
Expand Down Expand Up @@ -1451,14 +1451,14 @@ static gint dupe_check_cb(gpointer data)
dupe_window_update_progress(dw, _("Reading checksums..."),
dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE);

if (enable_thumb_caching)
if (options->enable_thumb_caching)
{
dupe_item_read_cache(di);
if (di->md5sum) return TRUE;
}

di->md5sum = md5_text_from_file_utf8(di->fd->path, "");
if (enable_thumb_caching)
if (options->enable_thumb_caching)
{
dupe_item_write_cache(di);
}
Expand All @@ -1484,14 +1484,14 @@ static gint dupe_check_cb(gpointer data)
dupe_window_update_progress(dw, _("Reading dimensions..."),
dw->setup_count == 0 ? 0.0 : (gdouble)(dw->setup_n - 1) / dw->setup_count, FALSE);

if (enable_thumb_caching)
if (options->enable_thumb_caching)
{
dupe_item_read_cache(di);
if (di->width != 0 || di->height != 0) return TRUE;
}

image_load_dimensions(di->fd, &di->width, &di->height);
if (enable_thumb_caching)
if (options->enable_thumb_caching)
{
dupe_item_write_cache(di);
}
Expand All @@ -1518,7 +1518,7 @@ static gint dupe_check_cb(gpointer data)
dupe_window_update_progress(dw, _("Reading similarity data..."),
dw->setup_count == 0 ? 0.0 : (gdouble)dw->setup_n / dw->setup_count, FALSE);

if (enable_thumb_caching)
if (options->enable_thumb_caching)
{
dupe_item_read_cache(di);
if (cache_sim_data_filled(di->simd))
Expand Down Expand Up @@ -2751,14 +2751,14 @@ static void dupe_listview_set_height(GtkWidget *listview, gint thumb)
column = gtk_tree_view_get_column(GTK_TREE_VIEW(listview), DUPE_COLUMN_THUMB - 1);
if (!column) return;

gtk_tree_view_column_set_fixed_width(column, (thumb) ? thumb_max_width : 4);
gtk_tree_view_column_set_fixed_width(column, (thumb) ? options->thumb_max_width : 4);

list = gtk_tree_view_column_get_cell_renderers(column);
if (!list) return;
cell = list->data;
g_list_free(list);

g_object_set(G_OBJECT(cell), "height", (thumb) ? thumb_max_height : -1, NULL);
g_object_set(G_OBJECT(cell), "height", (thumb) ? options->thumb_max_height : -1, NULL);
gtk_tree_view_columns_autosize(GTK_TREE_VIEW(listview));
}

Expand Down
22 changes: 11 additions & 11 deletions src/editors.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ void editor_reset_defaults(void)

for (i = 0; i < GQ_EDITOR_SLOTS; i++)
{
g_free(editor_name[i]);
editor_name[i] = g_strdup(_(editor_slot_defaults[i * 2]));
g_free(editor_command[i]);
editor_command[i] = g_strdup(editor_slot_defaults[i * 2 + 1]);
g_free(options->editor_name[i]);
options->editor_name[i] = g_strdup(_(editor_slot_defaults[i * 2]));
g_free(options->editor_command[i]);
options->editor_command[i] = g_strdup(editor_slot_defaults[i * 2 + 1]);
}
}

Expand Down Expand Up @@ -785,11 +785,11 @@ gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpo
gint error;

if (n < 0 || n >= GQ_EDITOR_SLOTS || !list ||
!editor_command[n] ||
strlen(editor_command[n]) == 0) return FALSE;
!options->editor_command[n] ||
strlen(options->editor_command[n]) == 0) return FALSE;

command = g_locale_from_utf8(editor_command[n], -1, NULL, NULL, NULL);
error = editor_command_start(command, editor_name[n], list, cb, data);
command = g_locale_from_utf8(options->editor_command[n], -1, NULL, NULL, NULL);
error = editor_command_start(command, options->editor_name[n], list, cb, data);
g_free(command);
return error;
}
Expand Down Expand Up @@ -821,10 +821,10 @@ gint start_editor_from_file(gint n, FileData *fd)
gint editor_window_flag_set(gint n)
{
if (n < 0 || n >= GQ_EDITOR_SLOTS ||
!editor_command[n] ||
strlen(editor_command[n]) == 0) return TRUE;
!options->editor_command[n] ||
strlen(options->editor_command[n]) == 0) return TRUE;

return (editor_command_parse(editor_command[n], NULL, NULL) & EDITOR_KEEP_FS);
return (editor_command_parse(options->editor_command[n], NULL, NULL) & EDITOR_KEEP_FS);
}


Expand Down
12 changes: 6 additions & 6 deletions src/filelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ gint filter_name_exists(const gchar *name)
GList *work;
gint ln;

if (!extension_list || file_filter_disable) return TRUE;
if (!extension_list || options->file_filter_disable) return TRUE;

ln = strlen(name);
work = extension_list;
Expand Down Expand Up @@ -423,7 +423,7 @@ GList *path_list_filter(GList *list, gint is_dir_list)
{
GList *work;

if (!is_dir_list && file_filter_disable && show_dot_files) return list;
if (!is_dir_list && options->file_filter_disable && options->show_dot_files) return list;

work = list;
while (work)
Expand All @@ -433,7 +433,7 @@ GList *path_list_filter(GList *list, gint is_dir_list)

base = filename_from_path(name);

if ((!show_dot_files && ishidden(base)) ||
if ((!options->show_dot_files && ishidden(base)) ||
(!is_dir_list && !filter_name_exists(base)) ||
(is_dir_list && base[0] == '.' && (strcmp(base, GQ_CACHE_LOCAL_THUMB) == 0 ||
strcmp(base, GQ_CACHE_LOCAL_METADATA) == 0)) )
Expand Down Expand Up @@ -1220,7 +1220,7 @@ static gint filelist_read_real(const gchar *path, GList **files, GList **dirs, g
while ((dir = readdir(dp)) != NULL)
{
gchar *name = dir->d_name;
if (show_dot_files || !ishidden(name))
if (options->show_dot_files || !ishidden(name))
{
gchar *filepath = g_strconcat(pathl, "/", name, NULL);
if ((follow_symlinks ?
Expand Down Expand Up @@ -1349,15 +1349,15 @@ GList *filelist_filter(GList *list, gint is_dir_list)
{
GList *work;

if (!is_dir_list && file_filter_disable && show_dot_files) return list;
if (!is_dir_list && options->file_filter_disable && options->show_dot_files) return list;

work = list;
while (work)
{
FileData *fd = (FileData *)(work->data);
const gchar *name = fd->name;

if ((!show_dot_files && ishidden(name)) ||
if ((!options->show_dot_files && ishidden(name)) ||
(!is_dir_list && !filter_name_exists(name)) ||
(is_dir_list && name[0] == '.' && (strcmp(name, GQ_CACHE_LOCAL_THUMB) == 0 ||
strcmp(name, GQ_CACHE_LOCAL_METADATA) == 0)) )
Expand Down
Loading

0 comments on commit d2979ca

Please sign in to comment.