diff options
author | 2011-10-03 18:58:20 +0000 | |
---|---|---|
committer | 2011-10-03 18:58:20 +0000 | |
commit | 9d7104735ae1d56d5ef7b7bd82c2ab41c509b569 (patch) | |
tree | 6a6fd54d2c013d44b60aec9ccfcbec3687fa083d /src | |
parent | 258a0a450fc822068dc7581b03590a29f93b903f (diff) |
Diffstat (limited to 'src')
-rw-r--r-- | src/requests.c | 2 | ||||
-rw-r--r-- | src/trg-file-parser.c | 4 | ||||
-rw-r--r-- | src/trg-torrent-add-dialog.c | 35 | ||||
-rw-r--r-- | src/util.c | 2 |
4 files changed, 32 insertions, 11 deletions
diff --git a/src/requests.c b/src/requests.c index 0bc52af..380c46a 100644 --- a/src/requests.c +++ b/src/requests.c @@ -221,7 +221,7 @@ JsonNode *torrent_add(gchar * target, gint flags) if (!isUri && !g_file_test(target, G_FILE_TEST_IS_REGULAR)) { - g_error("file \"%s\" does not exist.", target); + g_message("file \"%s\" does not exist.", target); return NULL; } diff --git a/src/trg-file-parser.c b/src/trg-file-parser.c index 582ee82..dc8de3a 100644 --- a/src/trg-file-parser.c +++ b/src/trg-file-parser.c @@ -113,8 +113,8 @@ trg_torrent_file *trg_parse_torrent_file(const gchar *filename) be_node *top_node, *info_node, *name_node; trg_torrent_file *ret = NULL; - if (g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { - g_error("%s does not exist", filename); + if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { + g_message("%s does not exist", filename); return NULL; } diff --git a/src/trg-torrent-add-dialog.c b/src/trg-torrent-add-dialog.c index 8c40486..522d8ee 100644 --- a/src/trg-torrent-add-dialog.c +++ b/src/trg-torrent-add-dialog.c @@ -700,6 +700,18 @@ static void torrent_not_parsed_warning(GtkWindow * parent) gtk_widget_destroy(dialog); } +static void torrent_not_found_error(GtkWindow * parent, gchar *file) +{ + GtkWidget *dialog = + gtk_message_dialog_new(parent, GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, + _ + ("Unable to find torrent file: %s"), file); + gtk_window_set_transient_for(GTK_WINDOW(dialog), parent); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +} + static void trg_torrent_add_dialog_set_filenames(TrgTorrentAddDialog * d, GSList * filenames) { @@ -717,8 +729,10 @@ static void trg_torrent_add_dialog_set_filenames(TrgTorrentAddDialog * d, gtk_widget_set_sensitive(priv->file_list, FALSE); gtk_widget_set_sensitive(priv->delete_check, FALSE); } else { - gchar *file_name_base = g_path_get_basename(file_name); - trg_torrent_file *tor_data = trg_parse_torrent_file(file_name); + gchar *file_name_base; + trg_torrent_file *tor_data = NULL; + + file_name_base = g_path_get_basename(file_name); if (file_name_base) { gtk_button_set_label(chooser, file_name_base); @@ -727,13 +741,20 @@ static void trg_torrent_add_dialog_set_filenames(TrgTorrentAddDialog * d, gtk_button_set_label(chooser, file_name); } - gtk_widget_set_sensitive(priv->file_list, tor_data != NULL); - if (!tor_data) { - torrent_not_parsed_warning(GTK_WINDOW(priv->parent)); + if (g_file_test(file_name, G_FILE_TEST_IS_REGULAR)) + { + tor_data = trg_parse_torrent_file(file_name); + if (!tor_data) { + torrent_not_parsed_warning(GTK_WINDOW(priv->parent)); + } else { + store_add_node(priv->store, NULL, tor_data->top_node); + trg_torrent_file_free(tor_data); + } } else { - store_add_node(priv->store, NULL, tor_data->top_node); - trg_torrent_file_free(tor_data); + torrent_not_found_error(GTK_WINDOW(priv->parent), file_name); } + + gtk_widget_set_sensitive(priv->file_list, tor_data != NULL); } } else { gtk_widget_set_sensitive(priv->file_list, FALSE); @@ -41,7 +41,7 @@ gboolean is_magnet(gchar *string) gboolean is_url(gchar *string) { //return g_regex_match_simple ("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?", string, 0, 0); - return g_regex_match_simple ("^http", string, 0, 0); + return g_regex_match_simple ("^http[s]?://", string, 0, 0); } void add_file_id_to_array(JsonObject * args, gchar * key, gint index) |