Commit 0b49bb86 authored by John Sullivan's avatar John Sullivan

Fixed bug 1219 (saved viewer not used if not in preferred list)

	* libnautilus-extensions/nautilus-metadata.h:
	Removed NAUTILUS_METADATA_KEY_INITIAL_VIEW 'cuz it's not needed
	anymore.

	* libnautilus-extensions/nautilus-mime-actions.h:
	* libnautilus-extensions/nautilus-mime-actions.c:
	(nautilus_mime_get_default_component_for_uri_internal):
	New private function, returns both the default component
	and whether it was user-chosen (as opposed to just inherited
	from the value for this MIME type).
	(nautilus_mime_get_default_component_for_uri): Now calls
	this new function. Also fixed a bug where it was using a
	different metadata string than _set_default_, and thus
	never retrieving the stored value.
	(nautilus_mime_is_default_component_for_uri_user_chosen):
	New public function, reports whether the default component
	was chosen by the user or just inherited.

	* src/nautilus-window.c: (nautilus_window_switch_views):
	Call nautilus_mime_set_default_component_for_uri when the
	user explicitly chooses a view, rather than setting the
	now-obsolete "INITIAL_VIEW" metadata.

	* src/nautilus-applicable-views.c:
	(got_file_info_callback): Rename "fallback_id" to "default_id"
	and eliminate code that adds default component to menu here.
	The current view is always added to the menu in a special way
	if required later.
	(set_initial_content_id): Don't get remembered value, instead
	use nautilus_mime_is_default_component_for_uri_user_chosen to
	choose priority between default component and referring component.
	And don't require that the initial component is in the preferred
	list.
parent 78132c91
2000-06-06 John Sullivan <sullivan@eazel.com>
Fixed bug 1219 (saved viewer not used if not in preferred list)
* libnautilus-extensions/nautilus-metadata.h:
Removed NAUTILUS_METADATA_KEY_INITIAL_VIEW 'cuz it's not needed
anymore.
* libnautilus-extensions/nautilus-mime-actions.h:
* libnautilus-extensions/nautilus-mime-actions.c:
(nautilus_mime_get_default_component_for_uri_internal):
New private function, returns both the default component
and whether it was user-chosen (as opposed to just inherited
from the value for this MIME type).
(nautilus_mime_get_default_component_for_uri): Now calls
this new function. Also fixed a bug where it was using a
different metadata string than _set_default_, and thus
never retrieving the stored value.
(nautilus_mime_is_default_component_for_uri_user_chosen):
New public function, reports whether the default component
was chosen by the user or just inherited.
* src/nautilus-window.c: (nautilus_window_switch_views):
Call nautilus_mime_set_default_component_for_uri when the
user explicitly chooses a view, rather than setting the
now-obsolete "INITIAL_VIEW" metadata.
* src/nautilus-applicable-views.c:
(got_file_info_callback): Rename "fallback_id" to "default_id"
and eliminate code that adds default component to menu here.
The current view is always added to the menu in a special way
if required later.
(set_initial_content_id): Don't get remembered value, instead
use nautilus_mime_is_default_component_for_uri_user_chosen to
choose priority between default component and referring component.
And don't require that the initial component is in the preferred
list.
2000-06-06 Andy Hertzfeld <andy@eazel.com>
made tiled image backgrounds work properly in anti-aliased mode
......
......@@ -31,7 +31,6 @@
/* Per-directory */
#define NAUTILUS_METADATA_KEY_INITIAL_VIEW "INITIAL_VIEW"
#define NAUTILUS_METADATA_KEY_CONTENT_VIEWS "CONTENT_VIEWS"
#define NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR "BACKGROUND_COLOR"
......
......@@ -182,10 +182,8 @@ nautilus_mime_get_default_application_for_uri (const char *uri)
return result;
}
OAF_ServerInfo *
nautilus_mime_get_default_component_for_uri (const char *uri)
static OAF_ServerInfo *
nautilus_mime_get_default_component_for_uri_internal (const char *uri, gboolean *user_chosen)
{
GList *info_list;
OAF_ServerInfo *mime_default;
......@@ -197,7 +195,10 @@ nautilus_mime_get_default_component_for_uri (const char *uri)
GList *attributes;
GList *explicit_iids;
CORBA_Environment ev;
OAF_ServerInfo *server;
OAF_ServerInfo *server;
gboolean used_user_chosen_info;
used_user_chosen_info = TRUE;
CORBA_exception_init (&ev);
......@@ -211,14 +212,19 @@ nautilus_mime_get_default_component_for_uri (const char *uri)
attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_FAST_MIME_TYPE);
files = nautilus_directory_wait_until_ready (directory, attributes, TRUE);
default_component_string = nautilus_directory_get_metadata (directory, "DEFAULT_COMPONENT_IID", NULL);
default_component_string = nautilus_directory_get_metadata (directory, "DEFAULT_COMPONENT", NULL);
explicit_iids = get_explicit_content_view_iids_from_metafile (directory);
g_list_free (attributes);
nautilus_directory_unref (directory);
if (default_component_string == NULL && mime_type != NULL) {
mime_default = gnome_vfs_mime_get_default_component (mime_type);
if (mime_default != NULL) {
default_component_string = g_strdup (mime_default->iid);
if (default_component_string != NULL) {
/* Default component chosen based only on type. */
used_user_chosen_info = FALSE;
}
CORBA_free (mime_default);
}
}
......@@ -230,6 +236,7 @@ nautilus_mime_get_default_component_for_uri (const char *uri)
if (default_component_string == NULL) {
info_list = nautilus_do_component_query (mime_type, uri_scheme, files, explicit_iids, NULL, &ev);
used_user_chosen_info = TRUE; /* Default component chosen based on user-stored explicit_iids. */
} else {
char *iid_condition;
char *sort_conditions[2];
......@@ -260,11 +267,36 @@ nautilus_mime_get_default_component_for_uri (const char *uri)
}
CORBA_exception_free (&ev);
nautilus_directory_unref (directory);
if (user_chosen != NULL) {
*user_chosen = used_user_chosen_info;
}
return server;
}
OAF_ServerInfo *
nautilus_mime_get_default_component_for_uri (const char *uri)
{
return nautilus_mime_get_default_component_for_uri_internal (uri, NULL);
}
gboolean
nautilus_mime_is_default_component_for_uri_user_chosen (const char *uri)
{
OAF_ServerInfo *component;
gboolean user_chosen;
component = nautilus_mime_get_default_component_for_uri_internal (uri, &user_chosen);
/* Doesn't count as user chosen if the user-specified data is bogus and doesn't
* result in an actual component.
*/
return user_chosen && component != NULL;
}
GList *
nautilus_mime_get_short_list_applications_for_uri (const char *uri)
{
......
......@@ -32,6 +32,7 @@ GnomeVFSMimeActionType nautilus_mime_get_default_action_type_for_uri (co
GnomeVFSMimeAction *nautilus_mime_get_default_action_for_uri (const char *uri);
GnomeVFSMimeApplication *nautilus_mime_get_default_application_for_uri (const char *uri);
OAF_ServerInfo *nautilus_mime_get_default_component_for_uri (const char *uri);
gboolean nautilus_mime_is_default_component_for_uri_user_chosen (const char *uri);
GList *nautilus_mime_get_short_list_applications_for_uri (const char *uri);
GList *nautilus_mime_get_short_list_components_for_uri (const char *uri);
GList *nautilus_mime_get_all_applications_for_uri (const char *uri);
......
......@@ -31,7 +31,6 @@
/* Per-directory */
#define NAUTILUS_METADATA_KEY_INITIAL_VIEW "INITIAL_VIEW"
#define NAUTILUS_METADATA_KEY_CONTENT_VIEWS "CONTENT_VIEWS"
#define NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR "BACKGROUND_COLOR"
......
......@@ -182,10 +182,8 @@ nautilus_mime_get_default_application_for_uri (const char *uri)
return result;
}
OAF_ServerInfo *
nautilus_mime_get_default_component_for_uri (const char *uri)
static OAF_ServerInfo *
nautilus_mime_get_default_component_for_uri_internal (const char *uri, gboolean *user_chosen)
{
GList *info_list;
OAF_ServerInfo *mime_default;
......@@ -197,7 +195,10 @@ nautilus_mime_get_default_component_for_uri (const char *uri)
GList *attributes;
GList *explicit_iids;
CORBA_Environment ev;
OAF_ServerInfo *server;
OAF_ServerInfo *server;
gboolean used_user_chosen_info;
used_user_chosen_info = TRUE;
CORBA_exception_init (&ev);
......@@ -211,14 +212,19 @@ nautilus_mime_get_default_component_for_uri (const char *uri)
attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_FAST_MIME_TYPE);
files = nautilus_directory_wait_until_ready (directory, attributes, TRUE);
default_component_string = nautilus_directory_get_metadata (directory, "DEFAULT_COMPONENT_IID", NULL);
default_component_string = nautilus_directory_get_metadata (directory, "DEFAULT_COMPONENT", NULL);
explicit_iids = get_explicit_content_view_iids_from_metafile (directory);
g_list_free (attributes);
nautilus_directory_unref (directory);
if (default_component_string == NULL && mime_type != NULL) {
mime_default = gnome_vfs_mime_get_default_component (mime_type);
if (mime_default != NULL) {
default_component_string = g_strdup (mime_default->iid);
if (default_component_string != NULL) {
/* Default component chosen based only on type. */
used_user_chosen_info = FALSE;
}
CORBA_free (mime_default);
}
}
......@@ -230,6 +236,7 @@ nautilus_mime_get_default_component_for_uri (const char *uri)
if (default_component_string == NULL) {
info_list = nautilus_do_component_query (mime_type, uri_scheme, files, explicit_iids, NULL, &ev);
used_user_chosen_info = TRUE; /* Default component chosen based on user-stored explicit_iids. */
} else {
char *iid_condition;
char *sort_conditions[2];
......@@ -260,11 +267,36 @@ nautilus_mime_get_default_component_for_uri (const char *uri)
}
CORBA_exception_free (&ev);
nautilus_directory_unref (directory);
if (user_chosen != NULL) {
*user_chosen = used_user_chosen_info;
}
return server;
}
OAF_ServerInfo *
nautilus_mime_get_default_component_for_uri (const char *uri)
{
return nautilus_mime_get_default_component_for_uri_internal (uri, NULL);
}
gboolean
nautilus_mime_is_default_component_for_uri_user_chosen (const char *uri)
{
OAF_ServerInfo *component;
gboolean user_chosen;
component = nautilus_mime_get_default_component_for_uri_internal (uri, &user_chosen);
/* Doesn't count as user chosen if the user-specified data is bogus and doesn't
* result in an actual component.
*/
return user_chosen && component != NULL;
}
GList *
nautilus_mime_get_short_list_applications_for_uri (const char *uri)
{
......
......@@ -32,6 +32,7 @@ GnomeVFSMimeActionType nautilus_mime_get_default_action_type_for_uri (co
GnomeVFSMimeAction *nautilus_mime_get_default_action_for_uri (const char *uri);
GnomeVFSMimeApplication *nautilus_mime_get_default_application_for_uri (const char *uri);
OAF_ServerInfo *nautilus_mime_get_default_component_for_uri (const char *uri);
gboolean nautilus_mime_is_default_component_for_uri_user_chosen (const char *uri);
GList *nautilus_mime_get_short_list_applications_for_uri (const char *uri);
GList *nautilus_mime_get_short_list_components_for_uri (const char *uri);
GList *nautilus_mime_get_all_applications_for_uri (const char *uri);
......
......@@ -120,13 +120,12 @@ check_iid (gconstpointer a, gconstpointer b)
*/
static void
set_initial_content_id (NautilusNavigationInfo *navinfo,
NautilusViewIdentifier *fallback_view_id)
NautilusViewIdentifier *default_id)
{
char *remembered_value;
NautilusViewIdentifier *new_id;
GList *node;
g_assert (fallback_view_id != NULL);
g_assert (default_id != NULL);
g_assert (g_list_length (navinfo->content_identifiers) > 0);
new_id = NULL;
......@@ -136,25 +135,15 @@ set_initial_content_id (NautilusNavigationInfo *navinfo,
* setting that doesn't affect any other locations. Maybe we should change
* this to work that way.
*/
remembered_value = nautilus_directory_get_metadata
(navinfo->directory, NAUTILUS_METADATA_KEY_INITIAL_VIEW, NULL);
/* Use the remembered value if it's non-NULL and in the list of choices. */
if (remembered_value != NULL) {
node = g_list_find_custom (navinfo->content_identifiers,
remembered_value, check_iid);
if (node != NULL) {
new_id = node->data;
} else {
g_message ("Unknown iid \"%s\" stored for %s",
remembered_value,
navinfo->navinfo.requested_uri);
}
}
if (new_id == NULL) {
/* Can't use remembered value, use referring value if
* it's non-NULL and in the list of choices.
/* Use the user-chosen default for this uri if there is one */
if (nautilus_mime_is_default_component_for_uri_user_chosen
(navinfo->navinfo.requested_uri)) {
new_id = default_id;
} else {
/* Prefer the viewer used in the referring location to
* the default for this type, but only if it's in the
* preferred list for this file.
*/
if (navinfo->referring_iid != NULL) {
node = g_list_find_custom (navinfo->content_identifiers,
......@@ -164,28 +153,17 @@ set_initial_content_id (NautilusNavigationInfo *navinfo,
}
}
/* Can't use remembered or referring value, use fallback value. */
/* The referring viewer was nonexistent or not in this
* file's preferred list, so use the default for this type.
*/
if (new_id == NULL) {
new_id = fallback_view_id;
}
new_id = default_id;
}
}
g_assert (new_id != NULL);
navinfo->initial_content_id = nautilus_view_identifier_copy (new_id);
g_free (remembered_value);
}
static gint
view_identifier_has_iid (NautilusViewIdentifier *identifier, const char *iid)
{
return strcmp (identifier->iid, iid);
}
static gint
view_identifier_iids_compare (NautilusViewIdentifier *a, NautilusViewIdentifier *b)
{
return strcmp (a->iid, b->iid);
}
static void
......@@ -199,7 +177,7 @@ got_file_info_callback (GnomeVFSAsyncHandle *ah,
NautilusNavigationCallback notify_ready;
gpointer notify_ready_data;
NautilusNavigationResult result_code;
NautilusViewIdentifier *fallback_id;
NautilusViewIdentifier *default_id;
GList *components;
GList *p;
OAF_ServerInfo *default_component;
......@@ -242,30 +220,16 @@ got_file_info_callback (GnomeVFSAsyncHandle *ah,
default_component = nautilus_mime_get_default_component_for_uri (navinfo->navinfo.requested_uri);
if (default_component != NULL) {
fallback_id = nautilus_view_identifier_new_from_content_view (default_component);
/* FIXME: This merges the default component into the list if it
* wasn't already there. This might not be the right thing to do
* since the View As menu already handles the case where the current
* view is not in the standard list. I don't know when this case happens
* in practice though.
*/
if (g_list_find_custom (navinfo->content_identifiers, default_component->iid,
(GCompareFunc) view_identifier_has_iid) == NULL) {
navinfo->content_identifiers = g_list_insert_sorted
(navinfo->content_identifiers,
nautilus_view_identifier_new_from_content_view (default_component),
(GCompareFunc) view_identifier_iids_compare);
}
default_id = nautilus_view_identifier_new_from_content_view (default_component);
CORBA_free (default_component);
} else if (navinfo->content_identifiers != NULL) {
/* No default component, just take first one from list. */
fallback_id = nautilus_view_identifier_copy (navinfo->content_identifiers->data);
default_id = nautilus_view_identifier_copy (navinfo->content_identifiers->data);
}
#ifdef DEBUG_MJS
printf ("XXXXXX - fallback_id: %s (%s)\n", fallback_id->iid, fallback_id->name);
printf ("XXXXXX - default_id: %s (%s)\n", default_id->iid, default_id->name);
#endif
if (navinfo->content_identifiers != NULL) {
......@@ -283,9 +247,9 @@ got_file_info_callback (GnomeVFSAsyncHandle *ah,
/* Now that all the content_identifiers are in place, we're ready to choose
* the initial one.
*/
g_assert (fallback_id != NULL);
set_initial_content_id (navinfo, fallback_id);
nautilus_view_identifier_free (fallback_id);
g_assert (default_id != NULL);
set_initial_content_id (navinfo, default_id);
nautilus_view_identifier_free (default_id);
out:
if (result_code == NAUTILUS_NAVIGATION_RESULT_UNDEFINED) {
......
......@@ -48,6 +48,7 @@
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus-extensions/nautilus-mime-actions.h>
#include <libnautilus-extensions/nautilus-program-choosing.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-mini-icon.h>
......@@ -676,10 +677,8 @@ nautilus_window_switch_views (NautilusWindow *window, NautilusViewIdentifier *id
directory = nautilus_directory_get (window->ni->requested_uri);
g_assert (directory != NULL);
nautilus_directory_set_metadata (directory,
NAUTILUS_METADATA_KEY_INITIAL_VIEW,
NULL,
id->iid);
nautilus_mime_set_default_component_for_uri (window->ni->requested_uri,
id->iid);
nautilus_directory_unref (directory);
nautilus_window_allow_stop (window, TRUE);
......
......@@ -48,6 +48,7 @@
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus-extensions/nautilus-mime-actions.h>
#include <libnautilus-extensions/nautilus-program-choosing.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-mini-icon.h>
......@@ -676,10 +677,8 @@ nautilus_window_switch_views (NautilusWindow *window, NautilusViewIdentifier *id
directory = nautilus_directory_get (window->ni->requested_uri);
g_assert (directory != NULL);
nautilus_directory_set_metadata (directory,
NAUTILUS_METADATA_KEY_INITIAL_VIEW,
NULL,
id->iid);
nautilus_mime_set_default_component_for_uri (window->ni->requested_uri,
id->iid);
nautilus_directory_unref (directory);
nautilus_window_allow_stop (window, TRUE);
......
......@@ -48,6 +48,7 @@
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus-extensions/nautilus-mime-actions.h>
#include <libnautilus-extensions/nautilus-program-choosing.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-mini-icon.h>
......@@ -676,10 +677,8 @@ nautilus_window_switch_views (NautilusWindow *window, NautilusViewIdentifier *id
directory = nautilus_directory_get (window->ni->requested_uri);
g_assert (directory != NULL);
nautilus_directory_set_metadata (directory,
NAUTILUS_METADATA_KEY_INITIAL_VIEW,
NULL,
id->iid);
nautilus_mime_set_default_component_for_uri (window->ni->requested_uri,
id->iid);
nautilus_directory_unref (directory);
nautilus_window_allow_stop (window, TRUE);
......
......@@ -48,6 +48,7 @@
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus-extensions/nautilus-mime-actions.h>
#include <libnautilus-extensions/nautilus-program-choosing.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-mini-icon.h>
......@@ -676,10 +677,8 @@ nautilus_window_switch_views (NautilusWindow *window, NautilusViewIdentifier *id
directory = nautilus_directory_get (window->ni->requested_uri);
g_assert (directory != NULL);
nautilus_directory_set_metadata (directory,
NAUTILUS_METADATA_KEY_INITIAL_VIEW,
NULL,
id->iid);
nautilus_mime_set_default_component_for_uri (window->ni->requested_uri,
id->iid);
nautilus_directory_unref (directory);
nautilus_window_allow_stop (window, TRUE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment