static void ide_recent_projects_added (IdeRecentProjects *self, IdeProjectInfo *project_info) { g_autofree gchar *uri = NULL; GFile *file; g_assert (IDE_IS_RECENT_PROJECTS (self)); g_assert (IDE_IS_PROJECT_INFO (project_info)); file = ide_project_info_get_file (project_info); uri = g_file_get_uri (file); if (!g_hash_table_contains (self->recent_uris, uri)) { GSequenceIter *iter; gint position; iter = g_sequence_insert_sorted (self->projects, g_object_ref (project_info), (GCompareDataFunc)ide_project_info_compare, NULL); position = g_sequence_iter_get_position (iter); g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1); } }
/** * ide_project_info_get_doap: * * * Returns: (nullable) (transfer none): An #IdeDoap or %NULL. */ IdeDoap * ide_project_info_get_doap (IdeProjectInfo *self) { g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL); return self->doap; }
const gchar * ide_project_info_get_name (IdeProjectInfo *self) { g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL); return self->name; }
/** * ide_project_info_get_last_modified_at: * * * Returns: (transfer none) (nullable): A #GDateTime or %NULL. */ GDateTime * ide_project_info_get_last_modified_at (IdeProjectInfo *self) { g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL); return self->last_modified_at; }
const gchar * ide_project_info_get_description (IdeProjectInfo *self) { g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL); return self->description; }
/** * ide_project_info_get_file: * @self: (in): A #IdeProjectInfo. * * Gets the #IdeProjectInfo:file property. * This is the project file (such as configure.ac) of the project. * * Returns: (nullable) (transfer none): A #GFile. */ GFile * ide_project_info_get_file (IdeProjectInfo *self) { g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), NULL); return self->file; }
gboolean ide_project_info_get_is_recent (IdeProjectInfo *self) { g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), FALSE); return self->is_recent; }
gint ide_project_info_get_priority (IdeProjectInfo *self) { g_return_val_if_fail (IDE_IS_PROJECT_INFO (self), 0); return self->priority; }
/** * ide_recent_projects_remove: * @self: An #IdeRecentProjects * @project_infos: (transfer none) (element-type IdeProjectInfo): A #GList of #IdeProjectInfo. * * Removes the provided projects from the recent projects file. */ void ide_recent_projects_remove (IdeRecentProjects *self, GList *project_infos) { g_autoptr(GBookmarkFile) projects_file = NULL; g_autoptr(GError) error = NULL; GList *liter; g_return_if_fail (IDE_IS_RECENT_PROJECTS (self)); projects_file = ide_recent_projects_get_bookmarks (self, &error); if (projects_file == NULL) { g_warning ("Failed to load bookmarks file: %s", error->message); return; } for (liter = project_infos; liter; liter = liter->next) { IdeProjectInfo *project_info = liter->data; g_autofree gchar *file_uri = NULL; GSequenceIter *iter; GFile *file; g_assert (IDE_IS_PROJECT_INFO (liter->data)); iter = g_sequence_lookup (self->projects, project_info, (GCompareDataFunc)ide_project_info_compare, NULL); if (iter == NULL) { g_warning ("Project \"%s\" was not found, cannot remove.", ide_project_info_get_name (project_info)); g_clear_error (&error); continue; } file = ide_project_info_get_file (project_info); file_uri = g_file_get_uri (file); if (!g_bookmark_file_remove_item (projects_file, file_uri, &error)) { g_warning ("Failed to remove recent project: %s", error->message); g_clear_error (&error); continue; } g_sequence_remove (iter); } if (!g_bookmark_file_to_file (projects_file, self->file_uri, &error)) { g_warning ("Failed to save recent projects file: %s", error->message); return; } }
void ide_project_info_set_file (IdeProjectInfo *self, GFile *file) { g_return_if_fail (IDE_IS_PROJECT_INFO (self)); g_return_if_fail (!file || G_IS_FILE (file)); if (g_set_object (&self->file, file)) g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_FILE]); }
void ide_project_info_set_languages (IdeProjectInfo *self, gchar **languages) { g_return_if_fail (IDE_IS_PROJECT_INFO (self)); g_strfreev (self->languages); self->languages = g_strdupv (languages); g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_LANGUAGES]); }
void ide_project_info_set_doap (IdeProjectInfo *self, IdeDoap *doap) { g_return_if_fail (IDE_IS_PROJECT_INFO (self)); g_return_if_fail (!doap || IDE_IS_DOAP (doap)); if (g_set_object (&self->doap, doap)) g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DOAP]); }
void ide_project_info_set_directory (IdeProjectInfo *self, GFile *directory) { g_return_if_fail (IDE_IS_PROJECT_INFO (self)); g_return_if_fail (!directory || G_IS_FILE (directory)); if (g_set_object (&self->directory, directory)) g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DIRECTORY]); }
static void ide_recent_projects__miner_discovered (IdeRecentProjects *self, IdeProjectInfo *project_info, IdeProjectMiner *miner) { g_assert (IDE_IS_PROJECT_MINER (miner)); g_assert (IDE_IS_RECENT_PROJECTS (self)); g_assert (IDE_IS_PROJECT_INFO (project_info)); ide_recent_projects_added (self, project_info); }
void ide_project_info_set_priority (IdeProjectInfo *self, gint priority) { g_return_if_fail (IDE_IS_PROJECT_INFO (self)); if (self->priority != priority) { self->priority = priority; g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_PRIORITY]); } }
void ide_project_info_set_description (IdeProjectInfo *self, const gchar *description) { g_return_if_fail (IDE_IS_PROJECT_INFO (self)); if (!ide_str_equal0 (self->description, description)) { g_free (self->description); self->description = g_strdup (description); g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_DESCRIPTION]); } }
gint ide_project_info_compare (IdeProjectInfo *info1, IdeProjectInfo *info2) { const gchar *name1; const gchar *name2; GDateTime *dt1; GDateTime *dt2; gint ret; gint prio1; gint prio2; g_assert (IDE_IS_PROJECT_INFO (info1)); g_assert (IDE_IS_PROJECT_INFO (info2)); prio1 = ide_project_info_get_priority (info1); prio2 = ide_project_info_get_priority (info2); if (prio1 != prio2) return prio1 - prio2; dt1 = ide_project_info_get_last_modified_at (info1); dt2 = ide_project_info_get_last_modified_at (info2); ret = g_date_time_compare (dt2, dt1); if (ret != 0) return ret; name1 = ide_project_info_get_name (info1); name2 = ide_project_info_get_name (info2); if (name1 == NULL) return 1; else if (name2 == NULL) return -1; else return strcasecmp (name1, name2); }
void ide_project_info_set_last_modified_at (IdeProjectInfo *self, GDateTime *last_modified_at) { g_assert (IDE_IS_PROJECT_INFO (self)); if (last_modified_at != self->last_modified_at) { g_clear_pointer (&self->last_modified_at, g_date_time_unref); self->last_modified_at = last_modified_at ? g_date_time_ref (last_modified_at) : NULL; g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_LAST_MODIFIED_AT]); } }
void ide_project_info_set_name (IdeProjectInfo *self, const gchar *name) { g_return_if_fail (IDE_IS_PROJECT_INFO (self)); if (!ide_str_equal0 (self->name, name)) { g_free (self->name); self->name = g_strdup (name); g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_NAME]); } }
void ide_project_info_set_is_recent (IdeProjectInfo *self, gboolean is_recent) { g_return_if_fail (IDE_IS_PROJECT_INFO (self)); is_recent = !!is_recent; if (self->is_recent != is_recent) { self->is_recent = is_recent; g_object_notify_by_pspec (G_OBJECT (self), gParamSpecs [PROP_IS_RECENT]); } }
void ide_project_miner_emit_discovered (IdeProjectMiner *self, IdeProjectInfo *project_info) { gpointer *data; g_return_if_fail (IDE_IS_PROJECT_MINER (self)); g_return_if_fail (IDE_IS_PROJECT_INFO (project_info)); data = g_new0 (gpointer, 2); data[0] = g_object_ref (self); data[1] = g_object_ref (project_info); g_timeout_add (0, emit_discovered_cb, data); }
/** * ide_recent_projects_remove: * @self: An #IdeRecentProjects * @project_infos: (transfer none) (element-type IdeProjectInfo): A #GList of #IdeProjectInfo. * * Removes the provided projects from the recent projects file. */ void ide_recent_projects_remove (IdeRecentProjects *self, GList *project_infos) { g_autoptr(GBookmarkFile) projects_file = NULL; g_autoptr(GError) error = NULL; GList *liter; g_return_if_fail (IDE_IS_RECENT_PROJECTS (self)); projects_file = ide_recent_projects_get_bookmarks (self, &error); if (projects_file == NULL) { g_warning ("Failed to load bookmarks file: %s", error->message); return; } for (liter = project_infos; liter; liter = liter->next) { IdeProjectInfo *project_info = liter->data; g_autofree gchar *file_uri = NULL; GSequenceIter *iter; GFile *file; g_assert (IDE_IS_PROJECT_INFO (liter->data)); iter = g_sequence_lookup (self->projects, project_info, (GCompareDataFunc)ide_project_info_compare, NULL); if (iter == NULL) { g_warning ("Project \"%s\" was not found, cannot remove.", ide_project_info_get_name (project_info)); g_clear_error (&error); continue; } file = ide_project_info_get_file (project_info); file_uri = g_file_get_uri (file); if (!g_bookmark_file_remove_item (projects_file, file_uri, &error)) { g_autofree gchar *with_slash = g_strdup_printf ("%s/", file_uri); /* Sometimes we don't get a match because the directory is missing a * trailing slash. Annoying, I know. See the following for the * upstream bug filed in GLib. * * https://bugzilla.gnome.org/show_bug.cgi?id=765449 */ if (!g_bookmark_file_remove_item (projects_file, with_slash, NULL)) { g_warning ("Failed to remove recent project: %s", error->message); g_clear_error (&error); continue; } g_clear_error (&error); } g_sequence_remove (iter); } if (!g_bookmark_file_to_file (projects_file, self->file_uri, &error)) { g_warning ("Failed to save recent projects file: %s", error->message); return; } }