示例#1
0
/* Display information about the currently selected file or folder. */
void
on_info_clicked (GtkToolButton *item)
{
  GtkWidget *dialog, *name, *loc, *type, *size, *mod, *access, *treeview;
  gchar *file, *location, *modified, *accessed;
  GtkTreeSelection *selection;
  GtkTreeModel *model;
  GtkTreeIter iter;
  struct stat st;
  gfloat file_size;
  gint i;

  treeview = glade_xml_get_widget (xml, "treeview");
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
  
  if (gtk_tree_selection_get_selected (selection, &model, &iter))
  {
    dialog = glade_xml_get_widget (xml, "dialog");
    name = glade_xml_get_widget (xml, "name");
    loc = glade_xml_get_widget (xml, "filelocation");
    type = glade_xml_get_widget (xml, "type");
    size = glade_xml_get_widget (xml, "size");
    mod = glade_xml_get_widget (xml, "modified");
    access = glade_xml_get_widget (xml, "accessed");
    gtk_tree_model_get (model, &iter, FILENAME, &file, -1);
    
    /* Set the file name, location and whether it is a file or directory. */
    location = path_to_string ();
    gtk_label_set_text (GTK_LABEL (name), file);
    gtk_label_set_text (GTK_LABEL (loc), location);
    file = g_strconcat (location, "/", file, NULL);
    if (g_file_test (file, G_FILE_TEST_IS_DIR))
      gtk_label_set_text (GTK_LABEL (type), "Directory");
    else
      gtk_label_set_text (GTK_LABEL (type), "File");
    
    /* Set the file size, last modified date and last accessed date. */
    if (g_stat (file, &st) == 0)
    {
      i = 0;
      file_size = (gfloat) st.st_size;
      while (file_size >= 1024.0)
      {
        file_size = file_size / 1024.0;
        i++;
      }
    
      modified = g_strndup (ctime (&st.st_mtime), strlen (ctime (&st.st_mtime))-1);
      accessed = g_strndup (ctime (&st.st_atime), strlen (ctime (&st.st_atime))-1);
      gtk_label_set_text (GTK_LABEL (mod), modified);
      gtk_label_set_text (GTK_LABEL (access), accessed);
      gtk_label_set_text (GTK_LABEL (size), 
                          g_strdup_printf ("%.1f %s", file_size, size_type[i]));
    }
    
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_hide (dialog);
  }
}
示例#2
0
文件: libhid.c 项目: ThomasKurz/nut
char *HIDGetDataItem(const HIDData_t *hiddata, usage_tables_t *utab)
{
	/* TODO: not thread safe! */
	static char itemPath[128];

	path_to_string(itemPath, sizeof(itemPath), &hiddata->Path, utab);

	return itemPath;
}
示例#3
0
/* When a row is activated, either move to the desired location or show
 * more information if the file is not a directory. */
void 
on_row_activated (GtkTreeView *treeview,
                  GtkTreePath *path,
                  GtkTreeViewColumn *column) 
{
  GtkTreeModel *model;
  GtkTreeIter iter;
  gchar *file;

  model = gtk_tree_view_get_model (treeview);
  if (gtk_tree_model_get_iter (model, &iter, path))
  {
    gtk_tree_model_get (model, &iter, FILENAME, &file, -1);
    
    /* Move to the parent directory. */
    if (g_ascii_strcasecmp ("..", file) == 0)
    {
      GList *last = g_list_last (current_path);
      store_history ();
      current_path = g_list_remove_link (current_path, last);
      g_list_free_1 (last);
      populate_tree_model (GTK_WIDGET (treeview));
    }
    /* Move to the chosen directory or show more information about the file. */
    else
    {
      gchar *location = path_to_string ();   

      if (g_file_test (g_strconcat (location, "/", file, NULL), G_FILE_TEST_IS_DIR))
      {
        store_history ();
        current_path = g_list_append (current_path, file);
        populate_tree_model (GTK_WIDGET (treeview));
      }
      else
        on_info_clicked (NULL);  
    }
  }
}
示例#4
0
    void Deconstructor::sb2vcf(string outfile){
        Header h;
        h.set_date();
        h.set_source("VG");
        h.set_reference("");
        h.set_version("VCF4.2");

        cout << h << endl;

        // for each superbubble:
        // Fill out a vcflib Variant
        // Check if it is masked by an input vcf
        // if not, print it to stdout



        map<id_t, vcflib::Variant> node_to_var;
        vcflib::VariantCallFile mask;
        if (!mask_file.empty()){
            //node_to_var = my_vg->get_node_to_variant(mask);
        }
        for (auto s : my_sbs){
            vcflib::Variant var;

            // Make subgraphs out of the superbubble:
            // Operating on a pair<id_t, id_t>, vector<id_t>
            // then enumerate k_paths through the SuperBubbles
            set<Node*> nodes;
            set<Edge*> edges;

            for (int i = 0; i < s.second.size(); i++){
                id_t n_id = s.second[i];
                //cerr << n_id << endl;
                Node* n_node = my_vg->get_node(n_id);
                vector<Edge*> e_end = my_vg->edges_from(n_node);
                nodes.insert(n_node);
                if (i < s.second.size() - 1){
                    edges.insert(e_end.begin(), e_end.end());
                }
            }

            vg::VG t_graph = vg::VG(nodes, edges);

            vector<Path> paths;

            std::function<void(NodeTraversal)> no_op = [](NodeTraversal n){};
            std::function<void(size_t, Path&)> extract_path = [&paths](size_t x_size, Path& path){
                paths.push_back(path);
            };

            t_graph.for_each_kpath(10000, false, 100, no_op, no_op, extract_path);

            std::function<std::vector<Path>(vector<Path>)> uniquify = [](vector<Path> v){
                map<string, Path> unqs;
                vector<Path> ret;
                for (auto x: v){
                    unqs[path_to_string(x)] = x;
                }

                for (auto y : unqs){
                    ret.push_back(y.second);
                }
                return ret;
            };

            paths = uniquify(paths);

            std::function<bool(Path)> all_ref = [&](Path p){
                for (int i = 0; i < p.mapping_size(); i++){
                    Mapping m = p.mapping(i);
                    Position pos = m.position();
                    vg::id_t pos_id = pos.node_id();
                    map<string, set<Mapping*> > path_to_mappings =  my_vg->paths.get_node_mapping(pos_id);

                    if (path_to_mappings.size() <= 0){
                        return false;
                    }
                }
                return true;
            };

            /*
             * This means we now have vectors for the superbubble
             * that have the paths through the nodes within it (including end nodes)
             * however, these paths are repeated several times.
             * We should find a way to prevent them being inserted once for each node.
             *
             * Next on the agenda: use the get_path_dist thing from vg call / vg stats
             * to get the distance to the head node.
             * Might need an XG index for this.
             *
             * Also need a way to deal with GAMs for this i.e. a way to 
             * count the number of times we see something come up in the gam
             */
            int first_len = (my_vg->get_node(1))->sequence().size();
            map<string, set<Mapping*> > p_to_mappings =  my_vg->paths.get_node_mapping(s.first.first);
            for (auto p_name : p_to_mappings){
                var.sequenceName = p_name.first;
            }
            var.position = my_xg->approx_path_distance(var.sequenceName, 1, s.first.first) + (s.first.first == 1 ? 0 : first_len);

            //var.sequenceName = my_vg->paths.get_node_mapping(pos_id);
            //
            for (auto x : paths){
                //cerr << path_to_string(x) << endl;
                stringstream ref_seq;
                stringstream alt_seq;
                bool is_ref = true;

                for (int m_i = 1; m_i < x.mapping_size() -1 ; m_i++){
                    Mapping m = x.mapping(m_i);
                    id_t pos_id = m.position().node_id();
                    Node* n = my_vg->get_node(pos_id);
                    string n_seq = n->sequence();
                    map<string, set<Mapping*> > path_to_mappings =  my_vg->paths.get_node_mapping(pos_id);
                    if (path_to_mappings.size() == 0){
                        is_ref = false;
                    }

                    if (is_ref){
                        ref_seq << n_seq;
                    }
                    alt_seq << n_seq;

                    //cerr << " REF: " << ref_seq.str() << " ALT: " << alt_seq.str() << endl;

                }

                if (is_ref){
                    if(var.ref.empty()){
                        string ref_str = ref_seq.str();
                        var.ref = ref_str; //(ref_str.size() > 0) ? ref_str : (my_vg->get_node(s.first.first))->sequence();
                        var.alleles.insert(var.alleles.begin(), var.ref);
                    }
                }
                else{
                    string alt_string = alt_seq.str();
                    var.alt.push_back(alt_string);
                    var.alleles.push_back(alt_string);
                }

            }
            if (! (var.ref.empty() && var.alt.empty()) ){
                cout << var << endl;
            }

        }

    }
示例#5
0
/* Setup the content of the tree model. */
void
populate_tree_model (GtkWidget *treeview)
{
  GtkWidget *entry, *statusbar;
  GdkPixbuf *pixbuf_file, *pixbuf_dir;
  GtkListStore *store;
  GtkTreeIter iter;
  GdkPixbuf *directory;
  struct stat st;
  gchar *location, *file, *message;
  gfloat size, total_size = 0;
  gint i, items = 0;;
  GDir *dir;
  
  store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)));
  gtk_list_store_clear (store);
  location = path_to_string ();
  
  /* If the current location is not the root directory, add the '..' entry. */
  if (g_list_length (current_path) > 0)
  {
    directory = gdk_pixbuf_new_from_file ("directory.png", NULL);
    gtk_list_store_append (store, &iter);
    gtk_list_store_set (store, &iter, ICON, directory, FILENAME, "..", -1);
  }
  
  /* Return if the path does not exist. */
  if (!g_file_test (location, G_FILE_TEST_IS_DIR))
  {
    file_manager_error ("The path %s does not exist!");
    g_free (location);
    return;
  }
  
  /* Display the new location in the address bar. */
  entry = glade_xml_get_widget (xml, "location");
  gtk_entry_set_text (GTK_ENTRY (entry), location);
  
  /* Add each file to the list along with the file size and modified date. */
  pixbuf_dir = gdk_pixbuf_new_from_file ("directory.png", NULL);
  pixbuf_file = gdk_pixbuf_new_from_file ("file.png", NULL);
  dir = g_dir_open (location, 0, NULL);
  while ((file = (gchar*) g_dir_read_name (dir)))
  {
    gchar *fn, *filesize, *modified;
    
    fn = g_strconcat (location, "/", file, NULL);
    if (g_stat (fn, &st) == 0)
    {
      /* Calculate the file size and order of magnitude. */
      i = 0;
      size = (gfloat) st.st_size;
      total_size += size;
      while (size >= 1024.0)
      {
        size = size / 1024.0;
        i++;
      }
      
      /* Create strings for the file size and last modified date. */
      filesize = g_strdup_printf ("%.1f %s", size, size_type[i]);
      modified = g_strdup (ctime (&st.st_mtime));
      modified[strlen(modified)-1] = '\0';
    }
    
    /* Add the file and its properties as a new tree view row. */
    gtk_list_store_append (store, &iter);
    
    if (g_file_test (fn, G_FILE_TEST_IS_DIR))
      gtk_list_store_set (store, &iter, ICON, pixbuf_dir, FILENAME, file,
                          SIZE, filesize, MODIFIED, modified, -1);
    else
      gtk_list_store_set (store, &iter, ICON, pixbuf_file, FILENAME, file,
                          SIZE, filesize, MODIFIED, modified, -1);
    items++;

    g_free (fn);
  }
  
  /* Calculate the total size of the directory content. */
  i = 0;
  while (total_size >= 1024.0)
  {
    total_size = total_size / 1024.0;
    i++;
  }
  
  /* Add the number of items and the total size of the directory content
   * to the status bar. */
  statusbar = glade_xml_get_widget (xml, "statusbar");
  message = g_strdup_printf ("%d items, Total Size: %.1f %s", items,
                             total_size, size_type[i]);
  gtk_statusbar_pop (GTK_STATUSBAR (statusbar), context_id);
  gtk_statusbar_push (GTK_STATUSBAR (statusbar), context_id, message);
  g_object_unref (pixbuf_dir);
  g_object_unref (pixbuf_file);
  g_free (message);
}
示例#6
0
int _file_text_open_read(const boost::filesystem::path& filename, filestream_organizer::encoding enc, bool forced) 
{
	os_string_type fname_string = path_to_string(filename);
	return _file_text_open_read(fname_string, enc, forced);
}