Example #1
0
static GtkTreeIter *
fill_list(GtkWidget *main_w)
{
  WS_DIR        *dir;             /* scanned directory */
  WS_DIRENT     *file;            /* current file */
  GList         *fl_entry;
  profile_def   *profile;
  GtkTreeView   *profile_l;
  GtkListStore  *store;
  GtkTreeIter    iter, *l_select = NULL;
  const gchar   *profile_name = get_profile_name ();
  const gchar   *profiles_dir, *name;
  gchar         *filename;

  profile_l = GTK_TREE_VIEW(g_object_get_data(G_OBJECT(main_w), E_PROF_PROFILE_L_KEY));
  store = GTK_LIST_STORE(gtk_tree_view_get_model(profile_l));

  fl_entry = add_to_profile_list(DEFAULT_PROFILE, DEFAULT_PROFILE, PROF_STAT_DEFAULT);
  gtk_list_store_append(store, &iter);
  gtk_list_store_set(store, &iter, 0, DEFAULT_PROFILE, 1, fl_entry, -1);
  if (strcmp (profile_name, DEFAULT_PROFILE)==0) {
    l_select = g_memdup(&iter, sizeof(iter));
  }

  /* fill in data */
  profiles_dir = get_profiles_dir();
  if ((dir = ws_dir_open(profiles_dir, 0, NULL)) != NULL) {
    while ((file = ws_dir_read_name(dir)) != NULL) {
      name = ws_dir_get_name(file);
      filename = g_strdup_printf ("%s%s%s", profiles_dir, G_DIR_SEPARATOR_S, name);

      if (test_for_directory(filename) == EISDIR) {
	fl_entry = add_to_profile_list(name, name, PROF_STAT_EXISTS);
	profile    = (profile_def *) fl_entry->data;
	gtk_list_store_append(store, &iter);
	gtk_list_store_set(store, &iter, 0, profile->name, 1, fl_entry, -1);

	if (profile->name) {
	  if (strcmp(profile_name, profile->name) == 0) {
	    /*
	     * XXX - We're assuming that we can just copy a GtkTreeIter
	     * and use it later without any crashes.  This may not be a
	     * valid assumption.
	     */
	    l_select = g_memdup(&iter, sizeof(iter));
	  }
	}
      }
      g_free (filename);
    }
    ws_dir_close (dir);
  }

  /* Make the current list and the edited list equal */
  copy_profile_list ();

  return l_select;
}
Example #2
0
void
init_profile_list(void)
{
    WS_DIR        *dir;             /* scanned directory */
    WS_DIRENT     *file;            /* current file */
    const gchar   *profiles_dir, *name;
    gchar         *filename;

    empty_profile_list(TRUE);

    /* Default entry */
    add_to_profile_list(DEFAULT_PROFILE, DEFAULT_PROFILE, PROF_STAT_DEFAULT, FALSE, FALSE);

    /* Local (user) profiles */
    profiles_dir = get_profiles_dir();
    if ((dir = ws_dir_open(profiles_dir, 0, NULL)) != NULL) {
        while ((file = ws_dir_read_name(dir)) != NULL) {
            name = ws_dir_get_name(file);
            filename = g_strdup_printf ("%s%s%s", profiles_dir, G_DIR_SEPARATOR_S, name);

            if (test_for_directory(filename) == EISDIR) {
                /*fl_entry =*/ add_to_profile_list(name, name, PROF_STAT_EXISTS, FALSE, FALSE);
            }
            g_free (filename);
        }
        ws_dir_close (dir);
    }

    /* Global profiles */
    profiles_dir = get_global_profiles_dir();
    if ((dir = ws_dir_open(profiles_dir, 0, NULL)) != NULL) {
        while ((file = ws_dir_read_name(dir)) != NULL) {
            name = ws_dir_get_name(file);
            filename = g_strdup_printf ("%s%s%s", profiles_dir, G_DIR_SEPARATOR_S, name);

            if (test_for_directory(filename) == EISDIR) {
                /*fl_entry =*/ add_to_profile_list(name, name, PROF_STAT_EXISTS, TRUE, TRUE);
                /*profile = (profile_def *) fl_entry->data;*/
            }
            g_free (filename);
        }
        ws_dir_close (dir);
    }

    /* Make the current list and the edited list equal */
    copy_profile_list ();
}
Example #3
0
const gchar *apply_profile_changes(void) {
    char        *pf_dir_path, *pf_dir_path2, *pf_filename;
    GList       *fl1, *fl2;
    profile_def *profile1, *profile2;
    gboolean     found;
    emem_strbuf_t *message = ep_strbuf_new(NULL);
    const gchar *err_msg;

    /* First validate all profile names */
    fl1 = edited_profile_list();
    while (fl1) {
        profile1 = (profile_def *) fl1->data;
        g_strstrip(profile1->name);
        if ((err_msg = profile_name_is_valid(profile1->name)) != NULL) {
            ep_strbuf_printf(message, "%s", err_msg);
            return message->str;
        }
        fl1 = g_list_next(fl1);
    }

    /* Then do all copy profiles */
    fl1 = edited_profile_list();
    while (fl1) {
        profile1 = (profile_def *) fl1->data;
        g_strstrip(profile1->name);
        if (profile1->status == PROF_STAT_COPY) {
            if (create_persconffile_profile(profile1->name, &pf_dir_path) == -1) {
                ep_strbuf_printf(message,
                        "Can't create directory\n\"%s\":\n%s.",
                        pf_dir_path, g_strerror(errno));

                g_free(pf_dir_path);
            }
            profile1->status = PROF_STAT_EXISTS;

            if (profile1->reference) {
                if (copy_persconffile_profile(profile1->name, profile1->reference, profile1->from_global,
                            &pf_filename, &pf_dir_path, &pf_dir_path2) == -1) {
                    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                            "Can't copy file \"%s\" in directory\n\"%s\" to\n\"%s\":\n%s.",
                            pf_filename, pf_dir_path2, pf_dir_path, g_strerror(errno));

                    g_free(pf_filename);
                    g_free(pf_dir_path);
                    g_free(pf_dir_path2);
                }
            }

            g_free (profile1->reference);
            profile1->reference = g_strdup(profile1->name);
        }
        fl1 = g_list_next(fl1);
    }


    /* Then create new and rename changed */
    fl1 = edited_profile_list();
    while (fl1) {
        profile1 = (profile_def *) fl1->data;
        g_strstrip(profile1->name);
        if (profile1->status == PROF_STAT_NEW) {
            /* We do not create a directory for the default profile */
            if (strcmp(profile1->name, DEFAULT_PROFILE)!=0) {
                if (create_persconffile_profile(profile1->name, &pf_dir_path) == -1) {
                    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                            "Can't create directory\n\"%s\":\n%s.",
                            pf_dir_path, g_strerror(errno));

                    g_free(pf_dir_path);
                }
                profile1->status = PROF_STAT_EXISTS;

                g_free (profile1->reference);
                profile1->reference = g_strdup(profile1->name);
            }
        } else if (profile1->status == PROF_STAT_CHANGED) {
            if (strcmp(profile1->reference, profile1->name)!=0) {
                /* Rename old profile directory to new */
                if (rename_persconffile_profile(profile1->reference, profile1->name,
                            &pf_dir_path, &pf_dir_path2) == -1) {
                    simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                            "Can't rename directory\n\"%s\" to\n\"%s\":\n%s.",
                            pf_dir_path, pf_dir_path2, g_strerror(errno));

                    g_free(pf_dir_path);
                    g_free(pf_dir_path2);
                }
                profile1->status = PROF_STAT_EXISTS;
                g_free (profile1->reference);
                profile1->reference = g_strdup(profile1->name);
            }
        }
        fl1 = g_list_next(fl1);
    }

    /* Last remove deleted */
    fl1 = current_profile_list();
    while (fl1) {
        found = FALSE;
        profile1 = (profile_def *) fl1->data;
        fl2 = edited_profile_list();
        while (fl2) {
            profile2 = (profile_def *) fl2->data;
            if (!profile2->is_global) {
                if (strcmp(profile1->name, profile2->name)==0) {
                    /* Profile exists in both lists */
                    found = TRUE;
                } else if (strcmp(profile1->name, profile2->reference)==0) {
                    /* Profile has been renamed */
                    found = TRUE;
                }
            }
            fl2 = g_list_next(fl2);
        }
        if (!found) {
            /* Exists in existing list and not in edited, this is a deleted profile */
            if (delete_persconffile_profile(profile1->name, &pf_dir_path) == -1) {
                simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                        "Can't delete profile directory\n\"%s\":\n%s.",
                        pf_dir_path, g_strerror(errno));

                g_free(pf_dir_path);
            }
        }
        fl1 = g_list_next(fl1);
    }

    copy_profile_list();
    return NULL;
}
Example #4
0
static void
profile_apply(GtkWidget *main_w, GtkTreeView *profile_l, gboolean destroy)
{
  char        *pf_dir_path, *pf_dir_path2;
  GList       *fl1, *fl2;
  profile_def *profile1, *profile2;
  gboolean     found;

  /* First validate all profile names */
  fl1 = g_list_first(edited_profiles);
  while (fl1) {
    found = FALSE;
    profile1 = (profile_def *) fl1->data;
    g_strstrip(profile1->name);
    if (profile_is_invalid_name(profile1->name)) {
      return;
    }
    fl1 = g_list_next(fl1);
  }

  /* Then create new and rename changed */
  fl1 = g_list_first(edited_profiles);
  while (fl1) {
    found = FALSE;
    profile1 = (profile_def *) fl1->data;
    g_strstrip(profile1->name);
    if (profile1->status == PROF_STAT_NEW) {
      /* We do not create a directory for the default profile */
      if (strcmp(profile1->name, DEFAULT_PROFILE)!=0) {
	if (create_persconffile_profile(profile1->name, &pf_dir_path) == -1) {
	  simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
			"Can't create directory\n\"%s\":\n%s.",
			pf_dir_path, strerror(errno));

	  g_free(pf_dir_path);
	}
	profile1->status = PROF_STAT_EXISTS;

	g_free (profile1->reference);
	profile1->reference = g_strdup(profile1->name);
      }
    } else if (profile1->status == PROF_STAT_CHANGED) {
      if (strcmp(profile1->reference, profile1->name)!=0) {
	/* Rename old profile directory to new */
	if (rename_persconffile_profile(profile1->reference, profile1->name,
					&pf_dir_path, &pf_dir_path2) == -1) {
	  simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
			"Can't rename directory\n\"%s\" to\n\"%s\":\n%s.",
			pf_dir_path, pf_dir_path2, strerror(errno));

	  g_free(pf_dir_path);
	}
	profile1->status = PROF_STAT_EXISTS;
	g_free (profile1->reference);
	profile1->reference = g_strdup(profile1->name);
      }
    }
    fl1 = g_list_next(fl1);
  }

  /* Last remove deleted */
  fl1 = g_list_first(current_profiles);
  while (fl1) {
    found = FALSE;
    profile1 = (profile_def *) fl1->data;
    fl2 = g_list_first(edited_profiles);
    while (fl2) {
      profile2 = (profile_def *) fl2->data;
      if (strcmp(profile1->name, profile2->name)==0) {
	/* Profile exists in both lists */
	found = TRUE;
      } else if (strcmp(profile1->name, profile2->reference)==0) {
	/* Profile has been renamed */
	found = TRUE;
      }
      fl2 = fl2->next;
    }
    if (!found) {
      /* Exists in existing list and not in edited, this is a deleted profile */
      if (delete_persconffile_profile(profile1->name, &pf_dir_path) == -1) {
	simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
		      "Can't delete profile directory\n\"%s\":\n%s.",
		      pf_dir_path, strerror(errno));

	g_free(pf_dir_path);
      }
    }
    fl1 = g_list_next(fl1);
  }

  copy_profile_list();
  profile_select(main_w, profile_l, destroy);
}