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_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;
    }
}
Esempio n. 3
0
static void
ide_project_info_get_property (GObject    *object,
                               guint       prop_id,
                               GValue     *value,
                               GParamSpec *pspec)
{
  IdeProjectInfo *self = IDE_PROJECT_INFO (object);

  switch (prop_id)
    {
    case PROP_DESCRIPTION:
      g_value_set_string (value, ide_project_info_get_description (self));
      break;

    case PROP_DIRECTORY:
      g_value_set_object (value, ide_project_info_get_directory (self));
      break;

    case PROP_DOAP:
      g_value_set_object (value, ide_project_info_get_doap (self));
      break;

    case PROP_FILE:
      g_value_set_object (value, ide_project_info_get_file (self));
      break;

    case PROP_IS_RECENT:
      g_value_set_boolean (value, ide_project_info_get_is_recent (self));
      break;

    case PROP_LANGUAGES:
      g_value_set_boxed (value, ide_project_info_get_languages (self));
      break;

    case PROP_LAST_MODIFIED_AT:
      g_value_set_boxed (value, ide_project_info_get_last_modified_at (self));
      break;

    case PROP_NAME:
      g_value_set_string (value, ide_project_info_get_name (self));
      break;

    case PROP_PRIORITY:
      g_value_set_int (value, ide_project_info_get_priority (self));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}
Esempio n. 4
0
static void
discovered_cb (IdeProjectMiner *miner,
               IdeProjectInfo  *info)
{
  GFile *file;
  gchar *path;

  file = ide_project_info_get_file (info);
  path = g_file_get_path (file);

  g_print ("%s (%s)\n", path, ide_project_info_get_name (info));

  g_free (path);
}
/**
 * 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;
    }
}