search: export mime types utilities

Use the same mimetypes utilities and extract the functions to
mime-actions to clean it up and being able to be used outside of
the search popover class.
parent 1e447d8d
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
/* nautilus-mime-actions.c - uri-specific versions of mime action functions /* nautilus-mime-actions.c - uri-specific versions of mime action functions
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <eel/eel-glib-extensions.h> #include <eel/eel-glib-extensions.h>
#include <eel/eel-stock-dialogs.h> #include <eel/eel-stock-dialogs.h>
#include <eel/eel-string.h> #include <eel/eel-string.h>
#include <glib.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <glib/gstdio.h> #include <glib/gstdio.h>
#include <string.h> #include <string.h>
...@@ -86,6 +87,150 @@ typedef struct { ...@@ -86,6 +87,150 @@ typedef struct {
gboolean user_confirmation; gboolean user_confirmation;
} ActivateParameters; } ActivateParameters;
struct {
char *name;
char *mimetypes[20];
} mimetype_groups[] = {
{
N_("Anything"),
{ NULL }
},
{
N_("Files"),
{ "application/octet-stream",
"text/plain",
NULL
}
},
{
N_("Folders"),
{ "inode/directory",
NULL
}
},
{ N_("Documents"),
{ "application/rtf",
"application/msword",
"application/vnd.sun.xml.writer",
"application/vnd.sun.xml.writer.global",
"application/vnd.sun.xml.writer.template",
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.text-template",
"application/x-abiword",
"application/x-applix-word",
"application/x-mswrite",
"application/docbook+xml",
"application/x-kword",
"application/x-kword-crypt",
"application/x-lyx",
NULL
}
},
{ N_("Illustration"),
{ "application/illustrator",
"application/vnd.corel-draw",
"application/vnd.stardivision.draw",
"application/vnd.oasis.opendocument.graphics",
"application/x-dia-diagram",
"application/x-karbon",
"application/x-killustrator",
"application/x-kivio",
"application/x-kontour",
"application/x-wpg",
NULL
}
},
{ N_("Music"),
{ "application/ogg",
"audio/x-vorbis+ogg",
"audio/ac3",
"audio/basic",
"audio/midi",
"audio/x-flac",
"audio/mp4",
"audio/mpeg",
"audio/x-mpeg",
"audio/x-ms-asx",
"audio/x-pn-realaudio",
NULL
}
},
{ N_("PDF / Postscript"),
{ "application/pdf",
"application/postscript",
"application/x-dvi",
"image/x-eps",
NULL
}
},
{ N_("Picture"),
{ "application/vnd.oasis.opendocument.image",
"application/x-krita",
"image/bmp",
"image/cgm",
"image/gif",
"image/jpeg",
"image/jpeg2000",
"image/png",
"image/svg+xml",
"image/tiff",
"image/x-compressed-xcf",
"image/x-pcx",
"image/x-photo-cd",
"image/x-psd",
"image/x-tga",
"image/x-xcf",
NULL
}
},
{ N_("Presentation"),
{ "application/vnd.ms-powerpoint",
"application/vnd.sun.xml.impress",
"application/vnd.oasis.opendocument.presentation",
"application/x-magicpoint",
"application/x-kpresenter",
NULL
}
},
{ N_("Spreadsheet"),
{ "application/vnd.lotus-1-2-3",
"application/vnd.ms-excel",
"application/vnd.stardivision.calc",
"application/vnd.sun.xml.calc",
"application/vnd.oasis.opendocument.spreadsheet",
"application/x-applix-spreadsheet",
"application/x-gnumeric",
"application/x-kspread",
"application/x-kspread-crypt",
"application/x-quattropro",
"application/x-sc",
"application/x-siag",
NULL
}
},
{ N_("Text File"),
{ "text/plain",
NULL
}
},
{ N_("Video"),
{ "video/mp4",
"video/3gpp",
"video/mpeg",
"video/quicktime",
"video/vivo",
"video/x-avi",
"video/x-mng",
"video/x-ms-asf",
"video/x-ms-wmv",
"video/x-msvideo",
"video/x-nsv",
"video/x-real-video",
NULL
}
}
};
/* Number of seconds until cancel dialog shows up */ /* Number of seconds until cancel dialog shows up */
#define DELAY_UNTIL_CANCEL_MSECS 5000 #define DELAY_UNTIL_CANCEL_MSECS 5000
...@@ -2131,3 +2276,36 @@ nautilus_mime_activate_file (GtkWindow *parent_window, ...@@ -2131,3 +2276,36 @@ nautilus_mime_activate_file (GtkWindow *parent_window,
nautilus_mime_activate_files (parent_window, slot, files, launch_directory, flags, FALSE); nautilus_mime_activate_files (parent_window, slot, files, launch_directory, flags, FALSE);
g_list_free (files); g_list_free (files);
} }
gint
nautilus_mime_types_get_number_of_groups (void)
{
return G_N_ELEMENTS (mimetype_groups);
}
const gchar*
nautilus_mime_types_group_get_name (gint group_index)
{
g_return_val_if_fail (group_index < G_N_ELEMENTS (mimetype_groups), NULL);
return gettext (mimetype_groups[group_index].name);
}
GList*
nautilus_mime_types_group_get_mimetypes (gint group_index)
{
GList *mimetypes;
gint i;
g_return_val_if_fail (group_index < G_N_ELEMENTS (mimetype_groups), NULL);
mimetypes = NULL;
/* Setup the new mimetypes set */
for (i = 0; mimetype_groups[group_index].mimetypes[i]; i++)
{
mimetypes = g_list_append (mimetypes, mimetype_groups[group_index].mimetypes[i]);
}
return mimetypes;
}
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define NAUTILUS_MIME_ACTIONS_H #define NAUTILUS_MIME_ACTIONS_H
#include <gio/gio.h> #include <gio/gio.h>
#include <glib/gi18n.h>
#include <libnautilus-private/nautilus-file.h> #include <libnautilus-private/nautilus-file.h>
...@@ -51,6 +52,9 @@ void nautilus_mime_activate_file (GtkWi ...@@ -51,6 +52,9 @@ void nautilus_mime_activate_file (GtkWi
NautilusFile *file, NautilusFile *file,
const char *launch_directory, const char *launch_directory,
NautilusWindowOpenFlags flags); NautilusWindowOpenFlags flags);
gint nautilus_mime_types_get_number_of_groups (void);
const gchar* nautilus_mime_types_group_get_name (gint group_index);
GList* nautilus_mime_types_group_get_mimetypes (gint group_index);
#endif /* NAUTILUS_MIME_ACTIONS_H */ #endif /* NAUTILUS_MIME_ACTIONS_H */
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <config.h> #include <config.h>
#include "nautilus-query-editor.h" #include "nautilus-query-editor.h"
#include "nautilus-search-popover.h" #include "nautilus-search-popover.h"
#include "nautilus-mime-actions.h"
#include <string.h> #include <string.h>
#include <glib/gi18n.h> #include <glib/gi18n.h>
...@@ -443,18 +444,27 @@ search_popover_date_range_changed_cb (NautilusSearchPopover *popover, ...@@ -443,18 +444,27 @@ search_popover_date_range_changed_cb (NautilusSearchPopover *popover,
static void static void
search_popover_mime_type_changed_cb (NautilusSearchPopover *popover, search_popover_mime_type_changed_cb (NautilusSearchPopover *popover,
GList *data, gint mimetype_group,
const gchar *mimetype,
NautilusQueryEditor *editor) NautilusQueryEditor *editor)
{ {
NautilusQueryEditorPrivate *priv; NautilusQueryEditorPrivate *priv;
GList *mimetypes;
priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor)); priv = nautilus_query_editor_get_instance_private (NAUTILUS_QUERY_EDITOR (editor));
if (!priv->query) if (!priv->query)
create_query (editor); create_query (editor);
nautilus_query_set_mime_types (priv->query, data); if (mimetype_group >= 0) {
mimetypes = nautilus_mime_types_group_get_mimetypes (mimetype_group);
} else {
mimetypes = g_list_append (NULL, (gpointer) mimetype);
}
nautilus_query_set_mime_types (priv->query, mimetypes);
nautilus_query_editor_changed (editor); nautilus_query_editor_changed (editor);
g_list_free (mimetypes);
} }
static void static void
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "nautilus-enum-types.h" #include "nautilus-enum-types.h"
#include "nautilus-search-popover.h" #include "nautilus-search-popover.h"
#include "nautilus-mime-actions.h"
#include <glib/gi18n.h> #include <glib/gi18n.h>
#include <libnautilus-private/nautilus-file.h> #include <libnautilus-private/nautilus-file.h>
...@@ -74,150 +75,6 @@ enum { ...@@ -74,150 +75,6 @@ enum {
static guint signals[LAST_SIGNAL]; static guint signals[LAST_SIGNAL];
struct {
char *name;
char *mimetypes[20];
} mimetype_groups[] = {
{
N_("Anything"),
{ NULL }
},
{
N_("Files"),
{ "application/octet-stream",
"text/plain",
NULL
}
},
{
N_("Folders"),
{ "inode/directory",
NULL
}
},
{ N_("Documents"),
{ "application/rtf",
"application/msword",
"application/vnd.sun.xml.writer",
"application/vnd.sun.xml.writer.global",
"application/vnd.sun.xml.writer.template",
"application/vnd.oasis.opendocument.text",
"application/vnd.oasis.opendocument.text-template",
"application/x-abiword",
"application/x-applix-word",
"application/x-mswrite",
"application/docbook+xml",
"application/x-kword",
"application/x-kword-crypt",
"application/x-lyx",
NULL
}
},
{ N_("Illustration"),
{ "application/illustrator",
"application/vnd.corel-draw",
"application/vnd.stardivision.draw",
"application/vnd.oasis.opendocument.graphics",
"application/x-dia-diagram",
"application/x-karbon",
"application/x-killustrator",
"application/x-kivio",
"application/x-kontour",
"application/x-wpg",
NULL
}
},
{ N_("Music"),
{ "application/ogg",
"audio/x-vorbis+ogg",
"audio/ac3",
"audio/basic",
"audio/midi",
"audio/x-flac",
"audio/mp4",
"audio/mpeg",
"audio/x-mpeg",
"audio/x-ms-asx",
"audio/x-pn-realaudio",
NULL
}
},
{ N_("PDF / Postscript"),
{ "application/pdf",
"application/postscript",
"application/x-dvi",
"image/x-eps",
NULL
}
},
{ N_("Picture"),
{ "application/vnd.oasis.opendocument.image",
"application/x-krita",
"image/bmp",
"image/cgm",
"image/gif",
"image/jpeg",
"image/jpeg2000",
"image/png",
"image/svg+xml",
"image/tiff",
"image/x-compressed-xcf",
"image/x-pcx",
"image/x-photo-cd",
"image/x-psd",
"image/x-tga",
"image/x-xcf",
NULL
}
},
{ N_("Presentation"),
{ "application/vnd.ms-powerpoint",
"application/vnd.sun.xml.impress",
"application/vnd.oasis.opendocument.presentation",
"application/x-magicpoint",
"application/x-kpresenter",
NULL
}
},
{ N_("Spreadsheet"),
{ "application/vnd.lotus-1-2-3",
"application/vnd.ms-excel",
"application/vnd.stardivision.calc",
"application/vnd.sun.xml.calc",
"application/vnd.oasis.opendocument.spreadsheet",
"application/x-applix-spreadsheet",
"application/x-gnumeric",
"application/x-kspread",
"application/x-kspread-crypt",
"application/x-quattropro",
"application/x-sc",
"application/x-siag",
NULL
}
},
{ N_("Text File"),
{ "text/plain",
NULL
}
},
{ N_("Video"),
{ "video/mp4",
"video/3gpp",
"video/mpeg",
"video/quicktime",
"video/vivo",
"video/x-avi",
"video/x-mng",
"video/x-ms-asf",
"video/x-ms-wmv",
"video/x-msvideo",
"video/x-nsv",
"video/x-real-video",
NULL
}
}
};
/* Callbacks */ /* Callbacks */
...@@ -459,22 +316,10 @@ types_listbox_row_activated (GtkListBox *listbox, ...@@ -459,22 +316,10 @@ types_listbox_row_activated (GtkListBox *listbox,
} }
else else
{ {
GList *mimetypes; gtk_label_set_label (GTK_LABEL (popover->type_label),
gint i; nautilus_mime_types_group_get_name (group));
mimetypes = NULL;
/* Setup the new mimetypes set */
for (i = 0; mimetype_groups[group].mimetypes[i]; i++)
{
mimetypes = g_list_append (mimetypes, mimetype_groups[group].mimetypes[i]);
}
gtk_label_set_label (GTK_LABEL (popover->type_label), gettext (mimetype_groups[group].name));
g_signal_emit_by_name (popover, "mime-type", mimetypes, NULL);
g_list_free (mimetypes); g_signal_emit_by_name (popover, "mime-type", group, NULL);
} }
gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button"); gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
...@@ -619,15 +464,17 @@ fill_types_listbox (NautilusSearchPopover *popover) ...@@ -619,15 +464,17 @@ fill_types_listbox (NautilusSearchPopover *popover)
{ {
GtkWidget *row; GtkWidget *row;
int i; int i;
gint n_groups;
n_groups = nautilus_mime_types_get_number_of_groups ();
/* Mimetypes */ /* Mimetypes */
for (i = 0; i < G_N_ELEMENTS (mimetype_groups); i++) for (i = 0; i < n_groups; i++)
{ {
/* On the third row, which is right below "Folders", there should be an /* On the third row, which is right below "Folders", there should be an
* separator to logically group the types. * separator to logically group the types.
*/ */
row = create_row_for_label (gettext (mimetype_groups[i].name), i == 3); row = create_row_for_label (nautilus_mime_types_group_get_name (i), i == 3);
g_object_set_data (G_OBJECT (row), "mimetype-group", GINT_TO_POINTER (i)); g_object_set_data (G_OBJECT (row), "mimetype-group", GINT_TO_POINTER (i));
gtk_container_add (GTK_CONTAINER (popover->type_listbox), row); gtk_container_add (GTK_CONTAINER (popover->type_listbox), row);
...@@ -734,8 +581,8 @@ show_other_types_dialog (NautilusSearchPopover *popover) ...@@ -734,8 +581,8 @@ show_other_types_dialog (NautilusSearchPopover *popover)
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GList *mimetypes; char *mimetype;
char *mimetype, *description; char *description;
gtk_tree_selection_get_selected (selection, NULL, &iter); gtk_tree_selection_get_selected (selection, NULL, &iter);
gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
...@@ -743,11 +590,9 @@ show_other_types_dialog (NautilusSearchPopover *popover) ...@@ -743,11 +590,9 @@ show_other_types_dialog (NautilusSearchPopover *popover)
1, &mimetype, 1, &mimetype,
-1); -1);
mimetypes = g_list_append (NULL, mimetype);
gtk_label_set_label (GTK_LABEL (popover->type_label), description); gtk_label_set_label (GTK_LABEL (popover->type_label), description);
g_signal_emit_by_name (popover, "mime-type", mimetypes, NULL); g_signal_emit_by_name (popover, "mime-type", -1, mimetype);
gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button"); gtk_stack_set_visible_child_name (GTK_STACK (popover->type_stack), "type-button");
} }
...@@ -889,26 +734,27 @@ nautilus_search_popover_class_init (NautilusSearchPopoverClass *klass) ...@@ -889,26 +734,27 @@ nautilus_search_popover_class_init (NautilusSearchPopoverClass *klass)
G_TYPE_POINTER); G_TYPE_POINTER);
signals[MIME_TYPE] = g_signal_new ("mime-type", signals[MIME_TYPE] = g_signal_new ("mime-type",
NAUTILUS_TYPE_SEARCH_POPOVER, NAUTILUS_TYPE_SEARCH_POPOVER,
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
0, 0,
NULL, NULL,
NULL, NULL,
g_cclosure_marshal_generic, g_cclosure_marshal_generic,
G_TYPE_NONE, G_TYPE_NONE,
1, 2,
G_TYPE_POINTER); G_TYPE_INT,
G_TYPE_POINTER);
signals[TIME_TYPE] = g_signal_new ("time-type", signals[TIME_TYPE] = g_signal_new ("time-type",
NAUTILUS_TYPE_SEARCH_POPOVER, NAUTILUS_TYPE_SEARCH_POPOVER,
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
0, 0,
NULL, NULL,
NULL, NULL,
g_cclosure_marshal_generic, g_cclosure_marshal_generic,
G_TYPE_NONE, G_TYPE_NONE,
1, 1,
G_TYPE_INT); G_TYPE_INT);
/** /**
* NautilusSearchPopover::query: * NautilusSearchPopover::query:
......
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