/** * i7_app_uninstall_color_scheme: * @self: the app * @id: the id of the color scheme to be uninstalled * * Uninstalls a user color scheme. * * Return value: %TRUE on success, %FALSE otherwise. */ gboolean i7_app_uninstall_color_scheme(I7App *self, const char *id) { I7_APP_USE_PRIVATE(self, priv); GError *error = NULL; g_return_val_if_fail (id != NULL, FALSE); GtkSourceStyleScheme *scheme = gtk_source_style_scheme_manager_get_scheme(priv->color_scheme_manager, id); if(!scheme) return FALSE; const gchar *filename = gtk_source_style_scheme_get_filename(scheme); if(!filename) return FALSE; GFile *file = g_file_new_for_path(filename); if(!g_file_delete(file, NULL, &error)) { WARN(_("Cannot uninstall style scheme"), error); g_error_free(error); g_object_unref(file); return FALSE; } g_object_unref(file); /* Reload the available style schemes */ gtk_source_style_scheme_manager_force_rescan(priv->color_scheme_manager); return TRUE; }
/** * _pluma_style_scheme_manager_uninstall_scheme: * @manager: a #GtkSourceStyleSchemeManager * @id: the id of the style scheme to be uninstalled * * Uninstall a user scheme. * * If the call was succesful, it returns %TRUE * otherwise %FALSE. * * Return value: %TRUE on success, %FALSE otherwise. */ gboolean _pluma_style_scheme_manager_uninstall_scheme (GtkSourceStyleSchemeManager *manager, const gchar *id) { GtkSourceStyleScheme *scheme; const gchar *filename; g_return_val_if_fail (GTK_IS_SOURCE_STYLE_SCHEME_MANAGER (manager), FALSE); g_return_val_if_fail (id != NULL, FALSE); scheme = gtk_source_style_scheme_manager_get_scheme (manager, id); if (scheme == NULL) return FALSE; filename = gtk_source_style_scheme_get_filename (scheme); if (filename == NULL) return FALSE; if (g_unlink (filename) == -1) return FALSE; /* Reload the available style schemes */ gtk_source_style_scheme_manager_force_rescan (manager); return TRUE; }
gboolean _pluma_style_scheme_manager_scheme_is_pluma_user_scheme (GtkSourceStyleSchemeManager *manager, const gchar *scheme_id) { GtkSourceStyleScheme *scheme; const gchar *filename; gchar *dir; gboolean res = FALSE; scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme_id); if (scheme == NULL) return FALSE; filename = gtk_source_style_scheme_get_filename (scheme); if (filename == NULL) return FALSE; dir = get_pluma_styles_path (); res = g_str_has_prefix (filename, dir); g_free (dir); return res; }
/** * i7_app_color_scheme_is_user_scheme: * @self: the app * @id: the string ID of a color scheme * * Determines whether a particular color scheme is an application-specific * scheme installed by the user. * * Returns: %TRUE if @id is user-installed, %FALSE if not. */ gboolean i7_app_color_scheme_is_user_scheme(I7App *self, const char *id) { I7_APP_USE_PRIVATE(self, priv); GtkSourceStyleScheme *scheme = gtk_source_style_scheme_manager_get_scheme(priv->color_scheme_manager, id); if(!scheme) return FALSE; const gchar *filename = gtk_source_style_scheme_get_filename(scheme); if(!filename) return FALSE; GFile *scheme_file = g_file_new_for_path(filename); GFile *user_styles_dir = get_user_styles_dir(); gboolean retval = g_file_has_parent(scheme_file, user_styles_dir); g_object_unref(scheme_file); g_object_unref(user_styles_dir); return retval; }
/** * i7_app_install_color_scheme: * @self: the app * @file: a #GFile reference to the color scheme to be installed * * Install a new user color scheme. * * This function copies @file into the user color scheme directory and asks the * style manager to recompute the list of available style schemes. It then * checks if a style scheme with the right file name exists. * * Return value: (allow-none): the id of the installed scheme, %NULL on error. */ const char * i7_app_install_color_scheme(I7App *self, GFile *file) { I7_APP_USE_PRIVATE(self, priv); GFile *new_file = NULL; GError *error = NULL; gboolean copied = FALSE; g_return_val_if_fail(file != NULL, NULL); GFile *styles_dir = get_user_styles_dir(); if(!g_file_has_parent(file, styles_dir)) { /* Make sure USER_STYLES_DIR exists */ if(!make_directory_unless_exists(styles_dir, NULL, &error)) { g_object_unref(styles_dir); WARN(_("Cannot create user styles directory"), error); g_error_free(error); return NULL; } char *basename = g_file_get_basename(file); new_file = g_file_get_child(styles_dir, basename); g_free(basename); /* Copy the style scheme file into USER_STYLES_DIR */ if(!g_file_copy(file, new_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error)) { g_object_unref(new_file); g_object_unref(styles_dir); WARN(_("Cannot install style scheme"), error); g_error_free(error); return NULL; } copied = TRUE; } else new_file = g_object_ref(file); g_object_unref(styles_dir); /* Reload the available style schemes */ gtk_source_style_scheme_manager_force_rescan(priv->color_scheme_manager); /* Check the new style scheme has been actually installed */ const char * const *ids = gtk_source_style_scheme_manager_get_scheme_ids(priv->color_scheme_manager); while(*ids != NULL) { GtkSourceStyleScheme *scheme = gtk_source_style_scheme_manager_get_scheme(priv->color_scheme_manager, *ids); const gchar *filename = gtk_source_style_scheme_get_filename(scheme); char *new_path = g_file_get_path(new_file); if(filename && (strcmp(filename, new_path) == 0)) { /* The style scheme has been correctly installed */ g_object_unref(new_file); g_free(new_path); return gtk_source_style_scheme_get_id(scheme); } ++ids; } /* The style scheme has not been correctly installed */ if(copied) g_file_delete(new_file, NULL, NULL); /* ignore error */ g_object_unref(new_file); return NULL; }
/** * _pluma_style_scheme_manager_install_scheme: * @manager: a #GtkSourceStyleSchemeManager * @fname: the file name of the style scheme to be installed * * Install a new user scheme. * This function copies @fname in #PLUMA_STYLES_DIR and ask the style manager to * recompute the list of available style schemes. It then checks if a style * scheme with the right file name exists. * * If the call was succesful, it returns the id of the installed scheme * otherwise %NULL. * * Return value: the id of the installed scheme, %NULL otherwise. */ const gchar * _pluma_style_scheme_manager_install_scheme (GtkSourceStyleSchemeManager *manager, const gchar *fname) { gchar *new_file_name = NULL; gchar *dirname; gchar *styles_dir; GError *error = NULL; gboolean copied = FALSE; const gchar* const *ids; g_return_val_if_fail (GTK_IS_SOURCE_STYLE_SCHEME_MANAGER (manager), NULL); g_return_val_if_fail (fname != NULL, NULL); dirname = g_path_get_dirname (fname); styles_dir = get_pluma_styles_path(); if (strcmp (dirname, styles_dir) != 0) { gchar *basename; basename = g_path_get_basename (fname); new_file_name = g_build_filename (styles_dir, basename, NULL); g_free (basename); /* Copy the style scheme file into PLUMA_STYLES_DIR */ if (!file_copy (fname, new_file_name, &error)) { g_free (new_file_name); g_message ("Cannot install style scheme:\n%s", error->message); return NULL; } copied = TRUE; } else { new_file_name = g_strdup (fname); } g_free (dirname); g_free (styles_dir); /* Reload the available style schemes */ gtk_source_style_scheme_manager_force_rescan (manager); /* Check the new style scheme has been actually installed */ ids = gtk_source_style_scheme_manager_get_scheme_ids (manager); while (*ids != NULL) { GtkSourceStyleScheme *scheme; const gchar *filename; scheme = gtk_source_style_scheme_manager_get_scheme ( pluma_get_style_scheme_manager (), *ids); filename = gtk_source_style_scheme_get_filename (scheme); if (filename && (strcmp (filename, new_file_name) == 0)) { /* The style scheme has been correctly installed */ g_free (new_file_name); return gtk_source_style_scheme_get_id (scheme); } ++ids; } /* The style scheme has not been correctly installed */ if (copied) g_unlink (new_file_name); g_free (new_file_name); return NULL; }