Advertisement
Guest User

Untitled

a guest
Jun 13th, 2010
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. using Gtk;
  2. using Gee;
  3.  
  4. // class FileInfoCollection2 - keeps a collection of File2 objects
  5.  
  6. public class FileInfoCollection2 : GLib.Object
  7. {
  8. Gee.ArrayList<File2> innerList;
  9.  
  10. public FileInfoCollection2(){
  11. innerList = new Gee.ArrayList<File2>();
  12. }
  13.  
  14. public void add(FileInfo fileinfo){
  15. innerList.add(new File2(fileinfo));
  16. }
  17.  
  18. public int length(){
  19. return innerList.size;
  20. }
  21.  
  22. public File2 getItem(int i){
  23. return innerList.get(i);
  24. }
  25.  
  26. public void SortByName(){
  27. innerList.sort();
  28. }
  29. }
  30.  
  31.  
  32. // class File - wraps a GLib.FileInfo object
  33.  
  34. public class File2 : GLib.Object, Comparable<File2>
  35. {
  36. private FileInfo f;
  37.  
  38. public File2(FileInfo file){
  39. f = file;
  40. }
  41.  
  42. public string get_name(){
  43. return f.get_name();
  44. }
  45.  
  46. public int compare_to (File2 f ){
  47. var a = f.get_name();
  48. var b = this.get_name();
  49.  
  50. return strcmp(a,b);
  51. }
  52. }
  53.  
  54.  
  55.  
  56. // App - gets a bunch of files from disk
  57.  
  58. public class App {
  59. public void* sync_list_directory(string dir) {
  60.  
  61. try {
  62. var directory = File.new_for_path (dir);
  63. var enumerator = directory.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, 0, null);
  64. FileInfo file_info;
  65. FileInfoCollection2 coll = new FileInfoCollection2();
  66.  
  67. while ((file_info = enumerator.next_file (null)) != null) {
  68. coll.add(file_info);
  69. }
  70.  
  71. coll.SortByName(); // This causes crash. Comment it out and program will not crash.
  72.  
  73. for (var i=0; i<coll.length();i++){
  74. stdout.printf("[%d] - %s\n",i, coll.getItem(i).get_name());
  75. }
  76. }
  77. catch (Error e){
  78. stderr.printf ("Error: %s\n", e.message);
  79. }
  80.  
  81. return null;
  82. }
  83.  
  84. }
  85.  
  86.  
  87.  
  88. // Entry point
  89.  
  90. static int main (string[] args)
  91. {
  92. var app = new App();
  93. app.sync_list_directory("/home/chriniss/");
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement