Re: [Nautilus-list] Open with Other -- how does this work, anyway?

on 11/1/01 11:21 AM, David Moles at david moles vykor com wrote:

> Unfortunately, (1) Nautilus recognizes .lyx files as plain
> text documents -- I presume because so does file(1)

Nautilus determines file types using an API that's in gnome-vfs. There are
three parts to this process in gnome-vfs:

    a) "magic number" checking of file contents
    b) hard-coded rules in gnome-vfs code
    a) mapping file types based on extension

Part (a) is similar to what file(1) does, but it uses a separate database
that's part of gnome-vfs, not the one from file(1). Note that this entire
file typing scheme is not new to gnome-vfs. It was a set of calls from
gnome-libs that was moved into gnome-vfs and enhanced for use with Nautilus.

> -- and (2)
> since I upgraded to control-center-1.5.9-ximian.1 it's no longer
> possible (as far as I can tell) to "configure which programs are
> offered for which file types in the GNOME Control Center". (You'd
> think this is what "Default Applications" would be, but it isn't.)

The "File Types and Programs" panel, under the "Document Handlers" category
in the GNOME Control Center is what allows you to configure which programs
are offered for which MIME types. It also allows you to associate extensions
with particular MIME types.

> but (1) seems to be a symptom of a messier problem -- the
> whole file types, MIME types business seems to be both screwed
> up and poorly documented.

The fact that gnome-vfs doesn't recognize .lyx files is a symptom of the
fact that LyX files are not in the database. And the "File Types and
Programs" panel is the way to add ".lyx" support as an end user.

I'll leave it up to you to decide if there's a "messier problem" here. It
seems to me that the main problem is that you couldn't fine the "File Types
and Programs" panel.

> For instance, LyX files are easily
> identified by either their extension or by the fact that they
> start with the string "#LyX", but I have no idea how to inform
> Nautilus (or any other part of the system) about that.

The way to do this as an end user is to use the "File Types and Programs"

As a programmer contributing to gnome-vfs, it can be added to the MIME magic
database. The magic database is not extensible the way the MIME types and
extensions database is, so we have to update the gnome-vfs distribution
itself if we want to add "#LyX" as a magic number -- that's something we
inherited from file(1) and should improve.

I bet the gnome-vfs maintainers would be happy to add this magic number.

> Earlier,
> I ran into the problem that StarOffice 6.0b .sxw files just look
> like a ZIP archive to Nautilus -- and the same problem, I assume,
> will arise with any other file format that uses ZIP or gzip or
> tar+gzip as the last action in its save chain...

That's a separate problem, a mistake in the design of part (b) of the
gnome-vfs MIME type system. It has been fixed on HEAD for the next release
of gnome-vfs. In general, we could use some fancier ways for the extension
rules to interact with the magic number and hard-coded rules. The question
is, if a file's contents look like one thing, but it's extension says
another, which wins?

> Anyway, for LyX and file(1), I suppose I can hack /usr/share/magic,
> but Joe Home User is going to want a better way.

As far as file(1) is concerned, there's no interface for changing the magic
numbers database other than editing the magic file, which will probably be
overwritten the next time you install a newer file(1).

The gnome-vfs database for part (a) above also is not end-user editable. We
used the same design as file(1) and inherited that problem. But for a future
version we could come up with some way to add more MIME magic -- it's not
terribly difficult, but not something anyone has tackled yet.

> And what about mime types?

The MIME type information used by gnome-vfs has a part that's installed by
gnome-vfs and not intended to edited directly, and a part that's used by the
end-user to override what gnome-vfs installed. This end-user override part
is what "File Types and Programs" edits.

> I know there's /etc/mailcap,

Nautilus and gnome-vfs don't look at /etc/mailcap.

> but I also see I have files
> in .gnome/mime-info that say "this file was autogenerated by
> gnome-vfs-mime-info, DO NOT EDIT". I'm tempted, though, since
> neither gnome-vfs nor gnome-vfs-extras seems to have any executable
> files associated with it. Any ideas?

If you want to add MIME info by hand editing, you can put other files in
that directory with ".keys" and ".mime" extensions. All files in that
directory with those extensions will are looked at by gnome-vfs for end-user

You can also edit the files if you like despite the warning. Those are the
end-user files that are edited by "File Types and Programs". The
gnome-vfs-mime-info that's referred to in the comments is a part of the
gnome-vfs library, not the name of a program. The program is the "File Types
and Programs" panel, which I think is called file-types-capplet.

There's some documentation of how this works in the gnome-vfs doc directory.
Specifically, mime-data-specification.txt.

    -- Darin

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]