Ejemplo n.º 1
0
void
eom_plugin_engine_update_plugins_ui (EomWindow *window,
				     gboolean   new_window)
{
	GList *pl;

	eom_debug (DEBUG_PLUGINS);

	g_return_if_fail (EOM_IS_WINDOW (window));

	if (new_window)
		reactivate_all (window);

	/* Updated ui of all the plugins that implement update_ui */
	for (pl = eom_plugins_list; pl; pl = pl->next) {
		EomPluginInfo *info = (EomPluginInfo*)pl->data;

		if (!info->available || !info->active)
			continue;

	       	eom_debug_message (DEBUG_PLUGINS, "Updating UI of %s", info->name);

		eom_plugin_update_ui (info->plugin, window);
	}
}
Ejemplo n.º 2
0
static void
reactivate_all (EomWindow *window)
{
	GList *pl;

	eom_debug (DEBUG_PLUGINS);

	for (pl = eom_plugins_list; pl; pl = pl->next) {
		gboolean res = TRUE;

		EomPluginInfo *info = (EomPluginInfo*)pl->data;

		/* If plugin is not available, don't try to activate/load it */
		if (info->available && info->active) {
			if (info->plugin == NULL)
				res = load_plugin_module (info);

			if (res)
				eom_plugin_activate (info->plugin,
						     window);
		}
	}

	eom_debug_message (DEBUG_PLUGINS, "End");
}
Ejemplo n.º 3
0
static void
eom_python_module_unload (GTypeModule *module)
{
	EomPythonModulePrivate *priv = EOM_PYTHON_MODULE_GET_PRIVATE (module);

	eom_debug_message (DEBUG_PLUGINS, "Unloading Python module");

	priv->type = 0;
}
Ejemplo n.º 4
0
static gboolean
plugin_manager_set_active (GtkTreeIter  *iter,
			   GtkTreeModel *model,
			   gboolean      active)
{
	EomPluginInfo *info;
	gboolean res = TRUE;

	eom_debug (DEBUG_PLUGINS);

	gtk_tree_model_get (model, iter, INFO_COLUMN, &info, -1);

	g_return_val_if_fail (info != NULL, FALSE);

	if (active) {
		/* Activate the plugin */
		if (!eom_plugin_engine_activate_plugin (info)) {
			eom_debug_message (DEBUG_PLUGINS, "Could not activate %s.\n",
					   eom_plugin_engine_get_plugin_name (info));

			res = FALSE;
		}
	} else {
		/* Deactivate the plugin */
		if (!eom_plugin_engine_deactivate_plugin (info)) {
			eom_debug_message (DEBUG_PLUGINS, "Could not deactivate %s.\n",
					     eom_plugin_engine_get_plugin_name (info));

			res = FALSE;
		}
	}

	/* Set new value */
	gtk_list_store_set (GTK_LIST_STORE (model),
			    iter,
			    ACTIVE_COLUMN, eom_plugin_engine_plugin_is_active (info),
			    AVAILABLE_COLUMN, eom_plugin_engine_plugin_is_available (info),
			    -1);

	return res;
}
Ejemplo n.º 5
0
static void
eom_python_module_finalize (GObject *object)
{
	EomPythonModulePrivate *priv = EOM_PYTHON_MODULE_GET_PRIVATE (object);

	eom_debug_message (DEBUG_PLUGINS, "Finalizing Python module %s", g_type_name (priv->type));

	g_free (priv->module);
	g_free (priv->path);

	G_OBJECT_CLASS (eom_python_module_parent_class)->finalize (object);
}
Ejemplo n.º 6
0
GObject *
eom_python_module_new_object (EomPythonModule *module)
{
	EomPythonModulePrivate *priv = EOM_PYTHON_MODULE_GET_PRIVATE (module);

	eom_debug_message (DEBUG_PLUGINS, "Creating object of type %s", g_type_name (priv->type));

	if (priv->type == 0)
		return NULL;

	return g_object_new (priv->type, NULL);
}
Ejemplo n.º 7
0
static void
configure_button_cb (GtkWidget        *button,
		     EomPluginManager *pm)
{
	EomPluginInfo *info;
	GtkWindow *toplevel;

	eom_debug (DEBUG_PLUGINS);

	info = plugin_manager_get_selected_plugin (pm);

	g_return_if_fail (info != NULL);

	eom_debug_message (DEBUG_PLUGINS, "Configuring: %s\n",
			   eom_plugin_engine_get_plugin_name (info));

	toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET(pm)));

	eom_plugin_engine_configure_plugin (info, toplevel);

	eom_debug_message (DEBUG_PLUGINS, "Done");
}
Ejemplo n.º 8
0
static void
eom_statusbar_date_plugin_dispose (GObject *object)
{
	EomStatusbarDatePlugin *plugin = EOM_STATUSBAR_DATE_PLUGIN (object);

	eom_debug_message (DEBUG_PLUGINS, "EomStatusbarDatePlugin disposing");

	if (plugin->window != NULL) {
		g_object_unref (plugin->window);
		plugin->window = NULL;
	}

	G_OBJECT_CLASS (eom_statusbar_date_plugin_parent_class)->dispose (object);
}
Ejemplo n.º 9
0
static void
eom_plugin_info_free (EomPluginInfo *info)
{
	if (info->plugin != NULL) {
	       	eom_debug_message (DEBUG_PLUGINS, "Unref plugin %s", info->name);

		g_object_unref (info->plugin);
	}

	g_free (info->file);
	g_free (info->location);
	g_free (info->name);
	g_free (info->desc);
	g_free (info->icon_name);
	g_free (info->website);
	g_free (info->copyright);
	g_strfreev (info->authors);

	g_free (info);
}
Ejemplo n.º 10
0
static void
eom_statusbar_date_plugin_init (EomStatusbarDatePlugin *plugin)
{
	eom_debug_message (DEBUG_PLUGINS, "EomStatusbarDatePlugin initializing");
}
Ejemplo n.º 11
0
static void
eom_python_module_init (EomPythonModule *module)
{
	eom_debug_message (DEBUG_PLUGINS, "Init of Python module");
}
Ejemplo n.º 12
0
static void eom_statusbar_date_plugin_finalize(GObject* object)
{
	eom_debug_message(DEBUG_PLUGINS, "EomStatusbarDatePlugin finalizing");

	G_OBJECT_CLASS(eom_statusbar_date_plugin_parent_class)->finalize(object);
}
Ejemplo n.º 13
0
static gboolean
load_plugin_module (EomPluginInfo *info)
{
	gchar *path;
	gchar *dirname;

	eom_debug (DEBUG_PLUGINS);

	g_return_val_if_fail (info != NULL, FALSE);
	g_return_val_if_fail (info->file != NULL, FALSE);
	g_return_val_if_fail (info->location != NULL, FALSE);
	g_return_val_if_fail (info->plugin == NULL, FALSE);
	g_return_val_if_fail (info->available, FALSE);

	switch (info->loader) {
	case EOM_PLUGIN_LOADER_C:
		dirname = g_path_get_dirname (info->file);
		g_return_val_if_fail (dirname != NULL, FALSE);

		path = g_module_build_path (dirname, info->location);

		g_free (dirname);

		g_return_val_if_fail (path != NULL, FALSE);

		info->module = G_TYPE_MODULE (eom_module_new (path));

		g_free (path);

		break;

#ifdef ENABLE_PYTHON
	case EOM_PLUGIN_LOADER_PY:
	{
		gchar *dir;

		if (!eom_python_init ()) {
			/* Mark plugin as unavailable and fails */
			info->available = FALSE;

			g_warning ("Cannot load Python plugin '%s' since eom "
			           "was not able to initialize the Python interpreter.",
			           info->name);

			return FALSE;
		}

		g_return_val_if_fail ((info->location != NULL) &&
		                      (info->location[0] != '\0'),
		                      FALSE);

		dir = g_path_get_dirname (info->file);

		info->module = G_TYPE_MODULE (
				eom_python_module_new (dir, info->location));

		g_free (dir);

		break;
	}
#endif
	default:
		g_return_val_if_reached (FALSE);
	}

	if (!g_type_module_use (info->module)) {
		switch (info->loader) {
		case EOM_PLUGIN_LOADER_C:
			g_warning ("Cannot load plugin '%s' since file '%s' cannot be read.",
				   info->name,
				   eom_module_get_path (EOM_MODULE (info->module)));
			break;

		case EOM_PLUGIN_LOADER_PY:
			g_warning ("Cannot load Python plugin '%s' since file '%s' cannot be read.",
				   info->name,
				   info->location);
			break;

		default:
			g_return_val_if_reached (FALSE);
		}

		g_object_unref (G_OBJECT (info->module));

		info->module = NULL;

		/* Mark plugin as unavailable and fails */
		info->available = FALSE;

		return FALSE;
	}

	switch (info->loader) {
	case EOM_PLUGIN_LOADER_C:
		info->plugin =
			EOM_PLUGIN (eom_module_new_object (EOM_MODULE (info->module)));
		break;

#ifdef ENABLE_PYTHON
	case EOM_PLUGIN_LOADER_PY:
		info->plugin =
			EOM_PLUGIN (eom_python_module_new_object (EOM_PYTHON_MODULE (info->module)));
		break;
#endif

	default:
		g_return_val_if_reached (FALSE);
	}

	g_type_module_unuse (info->module);

	eom_debug_message (DEBUG_PLUGINS, "End");

	return TRUE;
}
Ejemplo n.º 14
0
static void
eom_plugin_engine_load_dir (const gchar *dir)
{
	GError *error = NULL;
	GDir *d;
	const gchar *dirent;

	if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) {
		return;
	}

	g_return_if_fail (eom_plugin_engine_settings != NULL);

	eom_debug_message (DEBUG_PLUGINS, "DIR: %s", dir);

	d = g_dir_open (dir, 0, &error);

	if (!d)	{
		g_warning ("%s", error->message);
		g_error_free (error);

		return;
	}

	while ((dirent = g_dir_read_name (d))) {
		if (g_str_has_suffix (dirent, PLUGIN_EXT)) {
			gchar *plugin_file;
			EomPluginInfo *info;

			plugin_file = g_build_filename (dir, dirent, NULL);
			info = eom_plugin_engine_load (plugin_file);
			g_free (plugin_file);

			if (info == NULL)
				continue;

			/* If a plugin with this name has already been loaded
			 * drop this one (user plugins override system plugins) */
			if (g_list_find_custom (eom_plugins_list,
						info,
						(GCompareFunc)compare_plugin_info) != NULL) {
				g_warning ("Two or more plugins named '%s'. "
					   "Only the first will be considered.\n",
					   info->location);

				eom_plugin_info_free (info);

				continue;
			}

			/* Actually, the plugin will be activated when reactivate_all
			 * will be called for the first time. */
			info->active = (g_slist_find_custom (active_plugins,
							     info->location,
							     (GCompareFunc)strcmp) != NULL);

			eom_plugins_list = g_list_prepend (eom_plugins_list, info);

			eom_debug_message (DEBUG_PLUGINS, "Plugin %s loaded", info->name);
		}
	}

	eom_plugins_list = g_list_reverse (eom_plugins_list);

	g_dir_close (d);
}
Ejemplo n.º 15
0
static EomPluginInfo *
eom_plugin_engine_load (const gchar *file)
{
	EomPluginInfo *info;
	GKeyFile *plugin_file = NULL;
	gchar *str;

	g_return_val_if_fail (file != NULL, NULL);

	eom_debug_message (DEBUG_PLUGINS, "Loading plugin: %s", file);

	info = g_new0 (EomPluginInfo, 1);
	info->file = g_strdup (file);

	plugin_file = g_key_file_new ();

	if (!g_key_file_load_from_file (plugin_file, file, G_KEY_FILE_NONE, NULL)) {
		g_warning ("Bad plugin file: %s", file);

		goto error;
	}

	if (!g_key_file_has_key (plugin_file,
			   	 "Eom Plugin",
				 "IAge",
				 NULL))	{
		eom_debug_message (DEBUG_PLUGINS,
				   "IAge key does not exist in file: %s", file);

		goto error;
	}

	/* Check IAge=2 */
	if (g_key_file_get_integer (plugin_file,
				    "Eom Plugin",
				    "IAge",
				    NULL) != 2) {
		eom_debug_message (DEBUG_PLUGINS,
				   "Wrong IAge in file: %s", file);

		goto error;
	}

	/* Get Location */
	str = g_key_file_get_string (plugin_file,
				     "Eom Plugin",
				     "Module",
				     NULL);

	if ((str != NULL) && (*str != '\0')) {
		info->location = str;
	} else {
		g_warning ("Could not find 'Module' in %s", file);

		goto error;
	}

	/* Get the loader for this plugin */
	str = g_key_file_get_string (plugin_file,
				     "Eom Plugin",
				     "Loader",
				     NULL);

	if (str && strcmp(str, "python") == 0) {
		info->loader = EOM_PLUGIN_LOADER_PY;

#ifndef ENABLE_PYTHON
		g_warning ("Cannot load Python plugin '%s' since eom was not "
			   "compiled with Python support.", file);

		goto error;
#endif

	} else {
		info->loader = EOM_PLUGIN_LOADER_C;
	}

	g_free (str);

	/* Get Name */
	str = g_key_file_get_locale_string (plugin_file,
					    "Eom Plugin",
					    "Name",
					    NULL, NULL);
	if (str) {
		info->name = str;
	} else {
		g_warning ("Could not find 'Name' in %s", file);

		goto error;
	}

	/* Get Description */
	str = g_key_file_get_locale_string (plugin_file,
					    "Eom Plugin",
					    "Description",
					    NULL, NULL);
	if (str) {
		info->desc = str;
	} else {
		eom_debug_message (DEBUG_PLUGINS, "Could not find 'Description' in %s", file);
 	}

	/* Get Icon */
	str = g_key_file_get_locale_string (plugin_file,
					    "Eom Plugin",
					    "Icon",
					    NULL, NULL);
	if (str) {
		info->icon_name = str;
	} else {
		eom_debug_message (DEBUG_PLUGINS, "Could not find 'Icon' in %s, "
						  "using 'eom-plugin'", file);
	}

	/* Get Authors */
	info->authors = g_key_file_get_string_list (plugin_file,
						    "Eom Plugin",
						    "Authors",
						    NULL,
						    NULL);

	if (info->authors == NULL)
		eom_debug_message (DEBUG_PLUGINS, "Could not find 'Authors' in %s", file);


	/* Get Copyright */
	str = g_key_file_get_string (plugin_file,
				     "Eom Plugin",
				     "Copyright",
				     NULL);
	if (str) {
		info->copyright = str;
	} else {
		eom_debug_message (DEBUG_PLUGINS, "Could not find 'Copyright' in %s", file);
	}

	/* Get Website */
	str = g_key_file_get_string (plugin_file,
				     "Eom Plugin",
				     "Website",
				     NULL);
	if (str) {
		info->website = str;
	} else {
		eom_debug_message (DEBUG_PLUGINS, "Could not find 'Website' in %s", file);
	}

	g_key_file_free (plugin_file);

	/* If we know nothing about the availability of the plugin,
	   set it as available */
	info->available = TRUE;

	return info;

error:
	g_free (info->file);
	g_free (info->location);
	g_free (info->name);
	g_free (info);
	g_key_file_free (plugin_file);

	return NULL;
}
Ejemplo n.º 16
0
GdkPixbuf*
eom_thumbnail_load (EomImage *image, GError **error)
{
	GdkPixbuf *thumb = NULL;
	GFile *file;
	EomThumbData *data;
	GdkPixbuf *pixbuf;

	g_return_val_if_fail (image != NULL, NULL);
	g_return_val_if_fail (error != NULL && *error == NULL, NULL);

	file = eom_image_get_file (image);
	data = eom_thumb_data_new (file, error);
	g_object_unref (file);

	if (data == NULL)
		return NULL;

	if (!data->can_read ||
	    (data->failed_thumb_exists && mate_desktop_thumbnail_factory_has_valid_failed_thumbnail (factory, data->uri_str, data->mtime))) {
		eom_debug_message (DEBUG_THUMBNAIL, "%s: bad permissions or valid failed thumbnail present",data->uri_str);
		set_thumb_error (error, EOM_THUMB_ERROR_GENERIC, "Thumbnail creation failed");
		return NULL;
	}

	/* check if there is already a valid cached thumbnail */
	thumb = get_valid_thumbnail (data, error);

	if (thumb != NULL) {
		eom_debug_message (DEBUG_THUMBNAIL, "%s: loaded from cache",data->uri_str);
	} else if (mate_desktop_thumbnail_factory_can_thumbnail (factory, data->uri_str, data->mime_type, data->mtime)) {
		pixbuf = eom_image_get_pixbuf (image);

		if (pixbuf != NULL) {
			/* generate a thumbnail from the in-memory image,
			   if we have already loaded the image */
			eom_debug_message (DEBUG_THUMBNAIL, "%s: creating from pixbuf",data->uri_str);
			thumb = create_thumbnail_from_pixbuf (data, pixbuf, error);
			g_object_unref (pixbuf);
		} else {
			/* generate a thumbnail from the file */
			eom_debug_message (DEBUG_THUMBNAIL, "%s: creating from file",data->uri_str);
			thumb = mate_desktop_thumbnail_factory_generate_thumbnail (factory, data->uri_str, data->mime_type);
		}

		if (thumb != NULL) {
			/* Save the new thumbnail */
			mate_desktop_thumbnail_factory_save_thumbnail (factory, thumb, data->uri_str, data->mtime);
			eom_debug_message (DEBUG_THUMBNAIL, "%s: normal thumbnail saved",data->uri_str);
		} else {
			/* Save a failed thumbnail, to stop further thumbnail attempts */
			mate_desktop_thumbnail_factory_create_failed_thumbnail (factory, data->uri_str, data->mtime);
			eom_debug_message (DEBUG_THUMBNAIL, "%s: failed thumbnail saved",data->uri_str);
			set_thumb_error (error, EOM_THUMB_ERROR_GENERIC, "Thumbnail creation failed");
		}
	}

	eom_thumb_data_free (data);

	return thumb;
}