{ STOCK_HISTORY, N_("_History"), 0, 0, GTK_STOCK_SORT_ASCENDING },
{ STOCK_HOMEPAGE, N_("_Homepage"), 0, 0, GTK_STOCK_HOME },
{ STOCK_SCRIPTS, N_("_Userscripts"), 0, 0, GTK_STOCK_EXECUTE },
- { STOCK_STYLES, N_("User_styles"), 0, 0, GTK_STOCK_SELECT_COLOR },
{ STOCK_TAB_NEW, N_("New _Tab"), 0, 0, GTK_STOCK_ADD },
{ STOCK_TRANSFERS, N_("_Transfers"), 0, 0, GTK_STOCK_SAVE },
{ STOCK_PLUGINS, N_("Netscape p_lugins"), 0, 0, GTK_STOCK_CONVERT },
{
GtkVBox parent_instance;
- MidoriAddonKind kind;
GtkWidget* web_widget;
GtkWidget* toolbar;
GtkWidget* treeview;
static const gchar*
midori_addons_get_label (MidoriViewable* viewable)
{
- if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_SCRIPTS)
- return _("Userscripts");
- else if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_STYLES)
- return _("Userstyles");
- else
- return NULL;
+ return _("Userscripts");
}
static const gchar*
midori_addons_get_stock_id (MidoriViewable* viewable)
{
- if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_SCRIPTS)
- return STOCK_SCRIPTS;
- else if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_STYLES)
- return STOCK_STYLES;
- else
- return NULL;
+ return STOCK_SCRIPTS;
}
static void
switch (prop_id)
{
case PROP_KIND:
- addons->kind = g_value_get_enum (value);
+ /* Ignored */
break;
case PROP_WEB_WIDGET:
katze_object_assign (addons->web_widget, g_value_dup_object (value));
switch (prop_id)
{
case PROP_KIND:
- g_value_set_enum (value, addons->kind);
+ g_value_set_enum (value, MIDORI_ADDON_USER_SCRIPTS);
break;
case PROP_WEB_WIDGET:
g_value_set_object (value, addons->web_widget);
}
}
-static const gchar*
-_addons_get_folder (MidoriAddons* addons)
-{
- switch (addons->kind)
- {
- case MIDORI_ADDON_USER_SCRIPTS:
- return "scripts";
- case MIDORI_ADDON_USER_STYLES:
- return "styles";
- default:
- return NULL;
- }
-}
-
-static const gchar*
-_addons_get_extension (MidoriAddons* addons)
-{
- switch (addons->kind)
- {
- case MIDORI_ADDON_USER_SCRIPTS:
- return ".js";
- case MIDORI_ADDON_USER_STYLES:
- return ".css";
- default:
- return NULL;
- }
-}
-
static GSList*
_addons_get_directories (MidoriAddons* addons)
{
+ const gchar* folders[] = { "scripts", "styles" };
GSList *directories;
+ guint i;
const char* const* datadirs;
- const gchar* folder;
gchar* path;
- folder = _addons_get_folder (addons);
-
- /* user data dir */
- path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
- PACKAGE_NAME, folder, NULL);
- directories = g_slist_prepend (NULL, path);
+ directories = NULL;
- /* system data dirs */
- datadirs = g_get_system_data_dirs ();
- while (*datadirs)
+ for (i = 0; i < G_N_ELEMENTS (folders); i++)
{
- path = g_build_path (G_DIR_SEPARATOR_S, *datadirs,
- PACKAGE_NAME, folder, NULL);
+ path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
+ PACKAGE_NAME, folders[i], NULL);
directories = g_slist_prepend (directories, path);
- datadirs++;
+
+ datadirs = g_get_system_data_dirs ();
+ while (*datadirs)
+ {
+ path = g_build_path (G_DIR_SEPARATOR_S, *datadirs,
+ PACKAGE_NAME, folders[i], NULL);
+ directories = g_slist_prepend (directories, path);
+ datadirs++;
+ }
}
return directories;
{
GSList* files;
GDir* addon_dir;
- const gchar* folder;
- const gchar* extension;
GSList* list;
GSList* directories;
const gchar* filename;
gchar* fullname;
files = NULL;
- folder = _addons_get_folder (addons);
- extension = _addons_get_extension (addons);
directories = _addons_get_directories (addons);
list = directories;
{
while ((filename = g_dir_read_name (addon_dir)))
{
- if (g_str_has_suffix (filename, extension))
+ if (g_str_has_suffix (filename, ".js")
+ || g_str_has_suffix (filename, ".css"))
{
fullname = g_build_filename (dirname, filename, NULL);
files = g_slist_prepend (files, fullname);
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (addons))),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
- "Put scripts in the folder ~/.local/share/midori/%s",
- _addons_get_folder (addons));
+ _("Copy userscripts to the folder %s and "
+ "copy userstyles to the folder %s."),
+ "~/.local/share/midori/scripts",
+ "~/.local/share/midori/styles");
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
}
exception = NULL;
- if (addons->kind == MIDORI_ADDON_USER_SCRIPTS &&
+ if (g_str_has_suffix (fullname, ".js") &&
!_js_script_from_file (js_context, fullname, &exception))
{
message = g_strdup_printf ("console.error ('%s');", exception);
g_free (message);
g_free (exception);
}
- else if (addons->kind == MIDORI_ADDON_USER_STYLES &&
+ else if (g_str_has_suffix (fullname, ".css") &&
!_js_style_from_file (js_context, fullname, &exception))
{
message = g_strdup_printf ("console.error ('%s');", exception);
struct AddonElement* element;
g_return_if_fail (MIDORI_IS_ADDONS (addons));
- g_return_if_fail (addons->kind != MIDORI_ADDON_NONE);
/* FIXME: would GHashTable be better? */
disabled = g_tree_new ((GCompareFunc)strcmp);
excludes = NULL;
broken = FALSE;
- if (addons->kind == MIDORI_ADDON_USER_SCRIPTS)
+ if (g_str_has_suffix (fullname, ".js"))
{
name = NULL;
if (!js_metadata_from_file (fullname, &includes, &excludes,
displayname = name;
}
}
- else if (addons->kind == MIDORI_ADDON_USER_STYLES)
+ else if (g_str_has_suffix (fullname, ".css"))
{
if (!css_metadata_from_file (fullname, &includes, &excludes))
broken = TRUE;