diff options
Diffstat (limited to 'src/plugins/fs/directory.c')
-rw-r--r-- | src/plugins/fs/directory.c | 173 |
1 files changed, 76 insertions, 97 deletions
diff --git a/src/plugins/fs/directory.c b/src/plugins/fs/directory.c index ecaf34b8..12ca0bff 100644 --- a/src/plugins/fs/directory.c +++ b/src/plugins/fs/directory.c | |||
@@ -37,135 +37,114 @@ | |||
37 | 37 | ||
38 | #ifndef MINGW | 38 | #ifndef MINGW |
39 | static char * | 39 | static char * |
40 | selectFile() { | 40 | selectFile () |
41 | GladeXML * uploadXML; | 41 | { |
42 | GtkFileChooser * dialog; | 42 | GladeXML *uploadXML; |
43 | char * ret; | 43 | GtkFileChooser *dialog; |
44 | char *ret; | ||
44 | 45 | ||
45 | uploadXML | 46 | uploadXML |
46 | = glade_xml_new(getGladeFileName(), | 47 | = glade_xml_new (getGladeFileName (), |
47 | "openDirectoryFileDialog", | 48 | "openDirectoryFileDialog", PACKAGE_NAME); |
48 | PACKAGE_NAME); | 49 | connectGladeWithPlugins (uploadXML); |
49 | connectGladeWithPlugins(uploadXML); | 50 | dialog = GTK_FILE_CHOOSER (glade_xml_get_widget (uploadXML, |
50 | dialog = GTK_FILE_CHOOSER(glade_xml_get_widget(uploadXML, | 51 | "openDirectoryFileDialog")); |
51 | "openDirectoryFileDialog")); | 52 | if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_CANCEL) |
52 | if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_CANCEL) | 53 | ret = gtk_file_chooser_get_filename (dialog); |
53 | ret = gtk_file_chooser_get_filename(dialog); | ||
54 | else | 54 | else |
55 | ret = NULL; | 55 | ret = NULL; |
56 | gtk_widget_destroy(GTK_WIDGET(dialog)); | 56 | gtk_widget_destroy (GTK_WIDGET (dialog)); |
57 | UNREF(uploadXML); | 57 | UNREF (uploadXML); |
58 | return ret; | 58 | return ret; |
59 | } | 59 | } |
60 | #else /* MINGW */ | 60 | #else /* MINGW */ |
61 | static char * | 61 | static char * |
62 | selectFile() { | 62 | selectFile () |
63 | return plibc_ChooseFile(_("Choose the directory you want to open."), | 63 | { |
64 | OFN_FILEMUSTEXIST | OFN_SHAREAWARE); | 64 | return plibc_ChooseFile (_("Choose the directory you want to open."), |
65 | OFN_FILEMUSTEXIST | OFN_SHAREAWARE); | ||
65 | } | 66 | } |
66 | #endif /* MINGW */ | 67 | #endif /* MINGW */ |
67 | 68 | ||
68 | static int | 69 | static int |
69 | spcb(const ECRS_FileInfo * fi, | 70 | spcb (const ECRS_FileInfo * fi, |
70 | const HashCode512 * key, | 71 | const HashCode512 * key, int isRoot, void *closure) |
71 | int isRoot, | 72 | { |
72 | void * closure) { | 73 | SearchList *list = closure; |
73 | SearchList * list = closure; | 74 | fs_search_result_received (list, fi, list->uri); |
74 | fs_search_result_received(list, | ||
75 | fi, | ||
76 | list->uri); | ||
77 | return OK; | 75 | return OK; |
78 | } | 76 | } |
79 | 77 | ||
80 | 78 | ||
81 | void on_open_menu_activate_fs(GtkWidget * dummy1, | 79 | void |
82 | GtkWidget * dummy2) { | 80 | on_open_menu_activate_fs (GtkWidget * dummy1, GtkWidget * dummy2) |
83 | char * dn; | 81 | { |
84 | char * directory_data; | 82 | char *dn; |
83 | char *directory_data; | ||
85 | unsigned long long directory_data_len; | 84 | unsigned long long directory_data_len; |
86 | size_t dlen; | 85 | size_t dlen; |
87 | struct ECRS_MetaData * md; | 86 | struct ECRS_MetaData *md; |
88 | int fd; | 87 | int fd; |
89 | SearchList * list; | 88 | SearchList *list; |
90 | struct ECRS_URI * uri; | 89 | struct ECRS_URI *uri; |
91 | const char * kws[2]; | 90 | const char *kws[2]; |
92 | GtkNotebook * notebook; | 91 | GtkNotebook *notebook; |
93 | 92 | ||
94 | dn = selectFile(); | 93 | dn = selectFile (); |
95 | if (dn == NULL) | 94 | if (dn == NULL) |
96 | return; | 95 | return; |
97 | if ( (YES != disk_file_test(NULL, | 96 | if ((YES != disk_file_test (NULL, |
98 | dn)) || | 97 | dn)) || |
99 | (OK != disk_file_size(NULL, | 98 | (OK != disk_file_size (NULL, dn, &directory_data_len, YES))) |
100 | dn, | 99 | { |
101 | &directory_data_len, | 100 | addLogEntry (_("Error accessing file `%s'."), dn); |
102 | YES)) ) { | 101 | FREE (dn); |
103 | addLogEntry(_("Error accessing file `%s'."), | 102 | return; |
104 | dn); | 103 | } |
105 | FREE(dn); | 104 | fd = disk_file_open (NULL, dn, O_LARGEFILE | O_RDONLY); |
106 | return; | 105 | if (fd == -1) |
107 | } | 106 | { |
108 | fd = disk_file_open(NULL, | 107 | addLogEntry (_("Error opening file `%s'."), dn); |
109 | dn, | 108 | FREE (dn); |
110 | O_LARGEFILE | O_RDONLY); | 109 | return; |
111 | if (fd == -1) { | 110 | } |
112 | addLogEntry(_("Error opening file `%s'."), | ||
113 | dn); | ||
114 | FREE(dn); | ||
115 | return; | ||
116 | } | ||
117 | dlen = (size_t) directory_data_len; | 111 | dlen = (size_t) directory_data_len; |
118 | directory_data = MMAP(NULL, | 112 | directory_data = MMAP (NULL, dlen, PROT_READ, MAP_SHARED, fd, 0); |
119 | dlen, | 113 | if (directory_data == MAP_FAILED) |
120 | PROT_READ, | 114 | { |
121 | MAP_SHARED, | 115 | addLogEntry (_("Error mapping file `%s' into memory."), dn); |
122 | fd, | 116 | CLOSE (fd); |
123 | 0); | 117 | FREE (dn); |
124 | if (directory_data == MAP_FAILED) { | 118 | return; |
125 | addLogEntry(_("Error mapping file `%s' into memory."), | 119 | } |
126 | dn); | ||
127 | CLOSE(fd); | ||
128 | FREE(dn); | ||
129 | return; | ||
130 | } | ||
131 | kws[0] = dn; | 120 | kws[0] = dn; |
132 | kws[1] = NULL; | 121 | kws[1] = NULL; |
133 | uri = ECRS_keywordsToUri(kws); | 122 | uri = ECRS_keywordsToUri (kws); |
134 | md = NULL; | 123 | md = NULL; |
135 | list = fs_search_started(NULL, | 124 | list = fs_search_started (NULL, uri, 0, 0, NULL, FSUI_COMPLETED); |
136 | uri, | 125 | ECRS_freeUri (uri); |
137 | 0, | 126 | ECRS_listDirectory (NULL, |
138 | 0, | 127 | directory_data, directory_data_len, &md, &spcb, list); |
139 | NULL, | ||
140 | FSUI_COMPLETED); | ||
141 | ECRS_freeUri(uri); | ||
142 | ECRS_listDirectory(NULL, | ||
143 | directory_data, | ||
144 | directory_data_len, | ||
145 | &md, | ||
146 | &spcb, | ||
147 | list); | ||
148 | if (md != NULL) | 128 | if (md != NULL) |
149 | ECRS_freeMetaData(md); | 129 | ECRS_freeMetaData (md); |
150 | MUNMAP(directory_data, dlen); | 130 | MUNMAP (directory_data, dlen); |
151 | CLOSE(fd); | 131 | CLOSE (fd); |
152 | FREE(dn); | 132 | FREE (dn); |
153 | 133 | ||
154 | /* switch view -- select directory */ | 134 | /* switch view -- select directory */ |
155 | notebook | 135 | notebook |
156 | = GTK_NOTEBOOK(glade_xml_get_widget(getMainXML(), | 136 | = GTK_NOTEBOOK (glade_xml_get_widget (getMainXML (), "downloadNotebook")); |
157 | "downloadNotebook")); | 137 | gtk_notebook_set_current_page (notebook, |
158 | gtk_notebook_set_current_page(notebook, | 138 | gtk_notebook_page_num (notebook, |
159 | gtk_notebook_page_num(notebook, | 139 | list->searchpage)); |
160 | list->searchpage)); | ||
161 | 140 | ||
162 | notebook | 141 | notebook |
163 | = GTK_NOTEBOOK(glade_xml_get_widget(getMainXML(), | 142 | = GTK_NOTEBOOK (glade_xml_get_widget (getMainXML (), "fsnotebook")); |
164 | "fsnotebook")); | 143 | gtk_notebook_set_current_page (notebook, |
165 | gtk_notebook_set_current_page(notebook, | 144 | gtk_notebook_page_num (notebook, |
166 | gtk_notebook_page_num(notebook, | 145 | glade_xml_get_widget |
167 | glade_xml_get_widget(getMainXML(), | 146 | (getMainXML (), |
168 | "fsdownloadvbox"))); | 147 | "fsdownloadvbox"))); |
169 | } | 148 | } |
170 | 149 | ||
171 | /* end of directory.c */ | 150 | /* end of directory.c */ |