int ug_uri_match_file_exts (UgUri* uuri, char** exts) { const char* str; int len; int index; len = ug_uri_part_file_ext (uuri, &str); if (len) { for (index = 0; *exts; exts++, index++) { if (strncasecmp (str, *exts, len) == 0) return index; } } return -1; }
static int decide_file_type (UgetPluginAria2* plugin) { char buf[11]; union { const char* ext; int fd; int path; } temp; plugin->uri_type = URI_UNSUPPORTED; // handle URI file:/// temp.path = plugin->uri_part.path; if (temp.path > 0 && plugin->uri_part.uri[temp.path] != 0) temp.path++; // temp.fd = ug_open (plugin->uri_part.uri + temp.path, UG_O_READONLY | UG_O_BINARY, UG_S_IREAD); if (temp.fd != -1 && ug_read (temp.fd, buf, 11) == 11) { if (strncmp (buf, "d8:announce", 11) == 0) plugin->uri_type = URI_TORRENT; else { buf[10] = 0; if (strchr (buf, '<')) plugin->uri_type = URI_METALINK; } } ug_close (temp.fd); if (plugin->uri_type == URI_UNSUPPORTED && ug_uri_part_file_ext (&plugin->uri_part, &temp.ext)) { if (temp.ext[0] == 'm' || temp.ext[0] == 'M') plugin->uri_type = URI_METALINK; else if (temp.ext[0] == 't' || temp.ext[0] == 'T') plugin->uri_type = URI_TORRENT; else plugin->uri_type = URI_UNSUPPORTED; } return plugin->uri_type; }
void ug_selector_page_make_filter (UgSelectorPage* page) { UgUri* upart; UgSelectorItem* item; GtkTreeModel* model; GtkTreeIter iter; int value; gchar* key; if (g_hash_table_size (page->filter.hash)) return; upart = g_slice_alloc (sizeof (UgUri)); model = GTK_TREE_MODEL (page->store); value = gtk_tree_model_get_iter_first (model, &iter); while (value) { gtk_tree_model_get (model, &iter, 0, &item, -1); // create filter by host ---------------- ug_uri_init (upart, item->uri); if (upart->authority) key = g_strndup (item->uri, upart->path); else key = g_strdup ("(none)"); ug_selector_page_add_filter (page, page->filter.host, key, item); // create filter by filename extension -- value = ug_uri_part_file_ext (upart, (const char**) &key); if (value) key = g_strdup_printf (".%.*s", value, key); else key = g_strdup (".(none)"); ug_selector_page_add_filter (page, page->filter.ext, key, item); // next value = gtk_tree_model_iter_next (model, &iter); } g_slice_free1 (sizeof (UgUri), upart); }
void ugtk_download_form_complete_entry (UgtkDownloadForm* dform) { const gchar* text; // gchar* temp; UgUri upart; gboolean completed = FALSE; // URL text = gtk_entry_get_text ((GtkEntry*) dform->uri_entry); ug_uri_init (&upart, text); if (upart.host != -1) { // disable changed flags dform->changed.enable = FALSE; #if 0 // complete file entry text = gtk_entry_get_text ((GtkEntry*) dform->file_entry); if (text[0] == 0 || dform->changed.file == FALSE) { temp = ug_uri_get_file (&upart); gtk_entry_set_text ((GtkEntry*) dform->file_entry, (temp) ? temp : "index.htm"); g_free (temp); } // complete user entry text = gtk_entry_get_text ((GtkEntry*) dform->username_entry); if (text[0] == 0 || dform->changed.user == FALSE) { temp = ug_uri_get_user (&upart); gtk_entry_set_text ((GtkEntry*) dform->username_entry, (temp) ? temp : ""); g_free (temp); } // complete password entry text = gtk_entry_get_text ((GtkEntry*) dform->password_entry); if (text[0] == 0 || dform->changed.password == FALSE) { temp = ug_uri_get_password (&upart); gtk_entry_set_text ((GtkEntry*) dform->password_entry, (temp) ? temp : ""); g_free (temp); } #endif // enable changed flags dform->changed.enable = TRUE; // status completed = TRUE; } #if 1 // check existing for file name else if (ug_uri_part_file (&upart, &text) > 0) { completed = TRUE; } #else // file extension else if (ug_uri_part_file_ext (&upart, &text) > 0) { // torrent or metalink file path if (*text == 'm' || *text == 'M' || *text == 't' || *text == 'T') completed = TRUE; } #endif else if (upart.path > 0 && upart.uri[upart.path] != 0) completed = TRUE; else if (gtk_widget_is_sensitive (dform->uri_entry) == FALSE) completed = TRUE; dform->completed = completed; }