Merge userstyles into the userscript panel

This commit is contained in:
Christian Dywan 2009-09-22 23:46:51 +02:00
parent b3817bfc52
commit ba1084d236
4 changed files with 30 additions and 76 deletions

View file

@ -960,11 +960,6 @@ midori_app_add_browser_cb (MidoriApp* app,
gtk_widget_show (addon); gtk_widget_show (addon);
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon)); midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
/* Userstyles */
addon = midori_addons_new (MIDORI_ADDON_USER_STYLES, GTK_WIDGET (browser));
gtk_widget_show (addon);
midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
/* Plugins */ /* Plugins */
addon = g_object_new (MIDORI_TYPE_PLUGINS, "app", app, NULL); addon = g_object_new (MIDORI_TYPE_PLUGINS, "app", app, NULL);
gtk_widget_show (addon); gtk_widget_show (addon);

View file

@ -28,7 +28,6 @@
#define STOCK_WEB_BROWSER "web-browser" #define STOCK_WEB_BROWSER "web-browser"
#define STOCK_NEWS_FEED "news-feed" #define STOCK_NEWS_FEED "news-feed"
#define STOCK_STYLE "gnome-settings-theme" #define STOCK_STYLE "gnome-settings-theme"
#define STOCK_STYLES "gnome-settings-theme"
#define STOCK_TRANSFER "package" #define STOCK_TRANSFER "package"
#define STOCK_TRANSFERS "package" #define STOCK_TRANSFERS "package"
#define STOCK_PLUGINS GTK_STOCK_CONVERT #define STOCK_PLUGINS GTK_STOCK_CONVERT
@ -38,7 +37,7 @@
#define STOCK_IMAGE "gnome-mime-image" #define STOCK_IMAGE "gnome-mime-image"
#define STOCK_NETWORK_OFFLINE "network-offline" #define STOCK_NETWORK_OFFLINE "network-offline"
#define STOCK_SCRIPT "stock_script" #define STOCK_SCRIPT "stock_script"
#define STOCK_SCRIPTS "stock_script" #define STOCK_SCRIPTS "gnome-settings-theme"
#define STOCK_SEND "stock_mail-send" #define STOCK_SEND "stock_mail-send"
#define STOCK_TAB_NEW "stock_new-tab" #define STOCK_TAB_NEW "stock_new-tab"
#define STOCK_USER_TRASH "gnome-stock-trash" #define STOCK_USER_TRASH "gnome-stock-trash"

View file

@ -866,7 +866,6 @@ sokoke_register_stock_items (void)
{ STOCK_HISTORY, N_("_History"), 0, 0, GTK_STOCK_SORT_ASCENDING }, { STOCK_HISTORY, N_("_History"), 0, 0, GTK_STOCK_SORT_ASCENDING },
{ STOCK_HOMEPAGE, N_("_Homepage"), 0, 0, GTK_STOCK_HOME }, { STOCK_HOMEPAGE, N_("_Homepage"), 0, 0, GTK_STOCK_HOME },
{ STOCK_SCRIPTS, N_("_Userscripts"), 0, 0, GTK_STOCK_EXECUTE }, { 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_TAB_NEW, N_("New _Tab"), 0, 0, GTK_STOCK_ADD },
{ STOCK_TRANSFERS, N_("_Transfers"), 0, 0, GTK_STOCK_SAVE }, { STOCK_TRANSFERS, N_("_Transfers"), 0, 0, GTK_STOCK_SAVE },
{ STOCK_PLUGINS, N_("Netscape p_lugins"), 0, 0, GTK_STOCK_CONVERT }, { STOCK_PLUGINS, N_("Netscape p_lugins"), 0, 0, GTK_STOCK_CONVERT },

View file

@ -29,7 +29,6 @@ struct _MidoriAddons
{ {
GtkVBox parent_instance; GtkVBox parent_instance;
MidoriAddonKind kind;
GtkWidget* web_widget; GtkWidget* web_widget;
GtkWidget* toolbar; GtkWidget* toolbar;
GtkWidget* treeview; GtkWidget* treeview;
@ -137,23 +136,13 @@ midori_addons_class_init (MidoriAddonsClass* class)
static const gchar* static const gchar*
midori_addons_get_label (MidoriViewable* viewable) midori_addons_get_label (MidoriViewable* viewable)
{ {
if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_SCRIPTS) return _("Userscripts");
return _("Userscripts");
else if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_STYLES)
return _("Userstyles");
else
return NULL;
} }
static const gchar* static const gchar*
midori_addons_get_stock_id (MidoriViewable* viewable) midori_addons_get_stock_id (MidoriViewable* viewable)
{ {
if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_SCRIPTS) return STOCK_SCRIPTS;
return STOCK_SCRIPTS;
else if (MIDORI_ADDONS (viewable)->kind == MIDORI_ADDON_USER_STYLES)
return STOCK_STYLES;
else
return NULL;
} }
static void static void
@ -175,7 +164,7 @@ midori_addons_set_property (GObject* object,
switch (prop_id) switch (prop_id)
{ {
case PROP_KIND: case PROP_KIND:
addons->kind = g_value_get_enum (value); /* Ignored */
break; break;
case PROP_WEB_WIDGET: case PROP_WEB_WIDGET:
katze_object_assign (addons->web_widget, g_value_dup_object (value)); katze_object_assign (addons->web_widget, g_value_dup_object (value));
@ -197,7 +186,7 @@ midori_addons_get_property (GObject* object,
switch (prop_id) switch (prop_id)
{ {
case PROP_KIND: case PROP_KIND:
g_value_set_enum (value, addons->kind); g_value_set_enum (value, MIDORI_ADDON_USER_SCRIPTS);
break; break;
case PROP_WEB_WIDGET: case PROP_WEB_WIDGET:
g_value_set_object (value, addons->web_widget); g_value_set_object (value, addons->web_widget);
@ -208,57 +197,31 @@ midori_addons_get_property (GObject* object,
} }
} }
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* static GSList*
_addons_get_directories (MidoriAddons* addons) _addons_get_directories (MidoriAddons* addons)
{ {
const gchar* folders[] = { "scripts", "styles" };
GSList *directories; GSList *directories;
guint i;
const char* const* datadirs; const char* const* datadirs;
const gchar* folder;
gchar* path; gchar* path;
folder = _addons_get_folder (addons); directories = NULL;
/* user data dir */ for (i = 0; i < G_N_ELEMENTS (folders); i++)
path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
PACKAGE_NAME, folder, NULL);
directories = g_slist_prepend (NULL, path);
/* system data dirs */
datadirs = g_get_system_data_dirs ();
while (*datadirs)
{ {
path = g_build_path (G_DIR_SEPARATOR_S, *datadirs, path = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (),
PACKAGE_NAME, folder, NULL); PACKAGE_NAME, folders[i], NULL);
directories = g_slist_prepend (directories, path); 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; return directories;
@ -269,8 +232,6 @@ _addons_get_files (MidoriAddons* addons)
{ {
GSList* files; GSList* files;
GDir* addon_dir; GDir* addon_dir;
const gchar* folder;
const gchar* extension;
GSList* list; GSList* list;
GSList* directories; GSList* directories;
const gchar* filename; const gchar* filename;
@ -278,8 +239,6 @@ _addons_get_files (MidoriAddons* addons)
gchar* fullname; gchar* fullname;
files = NULL; files = NULL;
folder = _addons_get_folder (addons);
extension = _addons_get_extension (addons);
directories = _addons_get_directories (addons); directories = _addons_get_directories (addons);
list = directories; list = directories;
@ -290,7 +249,8 @@ _addons_get_files (MidoriAddons* addons)
{ {
while ((filename = g_dir_read_name (addon_dir))) 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); fullname = g_build_filename (dirname, filename, NULL);
files = g_slist_prepend (files, fullname); files = g_slist_prepend (files, fullname);
@ -324,8 +284,10 @@ midori_addons_button_add_clicked_cb (GtkToolItem* toolitem,
GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (addons))), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (addons))),
GTK_DIALOG_DESTROY_WITH_PARENT, GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE,
"Put scripts in the folder ~/.local/share/midori/%s", _("Copy userscripts to the folder %s and "
_addons_get_folder (addons)); "copy userstyles to the folder %s."),
"~/.local/share/midori/scripts",
"~/.local/share/midori/styles");
gtk_dialog_run (GTK_DIALOG (dialog)); gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
} }
@ -850,7 +812,7 @@ midori_web_widget_context_ready_cb (GtkWidget* web_widget,
} }
exception = NULL; exception = NULL;
if (addons->kind == MIDORI_ADDON_USER_SCRIPTS && if (g_str_has_suffix (fullname, ".js") &&
!_js_script_from_file (js_context, fullname, &exception)) !_js_script_from_file (js_context, fullname, &exception))
{ {
message = g_strdup_printf ("console.error ('%s');", exception); message = g_strdup_printf ("console.error ('%s');", exception);
@ -858,7 +820,7 @@ midori_web_widget_context_ready_cb (GtkWidget* web_widget,
g_free (message); g_free (message);
g_free (exception); 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)) !_js_style_from_file (js_context, fullname, &exception))
{ {
message = g_strdup_printf ("console.error ('%s');", exception); message = g_strdup_printf ("console.error ('%s');", exception);
@ -1012,7 +974,6 @@ midori_addons_update_elements (MidoriAddons* addons)
struct AddonElement* element; struct AddonElement* element;
g_return_if_fail (MIDORI_IS_ADDONS (addons)); g_return_if_fail (MIDORI_IS_ADDONS (addons));
g_return_if_fail (addons->kind != MIDORI_ADDON_NONE);
/* FIXME: would GHashTable be better? */ /* FIXME: would GHashTable be better? */
disabled = g_tree_new ((GCompareFunc)strcmp); disabled = g_tree_new ((GCompareFunc)strcmp);
@ -1043,7 +1004,7 @@ midori_addons_update_elements (MidoriAddons* addons)
excludes = NULL; excludes = NULL;
broken = FALSE; broken = FALSE;
if (addons->kind == MIDORI_ADDON_USER_SCRIPTS) if (g_str_has_suffix (fullname, ".js"))
{ {
name = NULL; name = NULL;
if (!js_metadata_from_file (fullname, &includes, &excludes, if (!js_metadata_from_file (fullname, &includes, &excludes,
@ -1056,7 +1017,7 @@ midori_addons_update_elements (MidoriAddons* addons)
displayname = name; 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)) if (!css_metadata_from_file (fullname, &includes, &excludes))
broken = TRUE; broken = TRUE;