Index: linux/search.cc =================================================================== RCS file: /cvsroot/linuxdcpp/linuxdcpp/linux/search.cc,v retrieving revision 1.32 diff -u -r1.32 search.cc --- linux/search.cc 11 Sep 2006 20:44:37 -0000 1.32 +++ linux/search.cc 17 Sep 2006 16:05:37 -0000 @@ -265,7 +265,70 @@ // Build "Download to..." submenu gtk_container_foreach(GTK_CONTAINER(getWidget("downloadMenu")), (GtkCallback)gtk_widget_destroy, NULL); + // Add queued file's with the same TTH/size. + GtkTreeIter iter; + SearchResult *result = NULL; + GList *list = gtk_tree_selection_get_selected_rows(selection, NULL); + gint count = gtk_tree_selection_count_selected_rows(selection); + + // Check if all file's have same TTH/size. + TTHValue *tth = NULL; + string firstTTH, ext; + int64_t size; + GtkTreePath *path = (GtkTreePath *)g_list_nth_data(list, 0); + if (gtk_tree_model_get_iter(GTK_TREE_MODEL(resultStore), &iter, path)) + { + result = resultView.getValue(&iter, "SearchResult"); + if (result->getType() == SearchResult::TYPE_FILE) + { + tth = result->getTTH(); + firstTTH = result->getTTH()->toBase32(); + size = result->getSize(); + ext = Util::getFileExt(result->getFile()); + } + } + gtk_tree_path_free(path); + + for (int i = 1; i < count; i++) + { + path = (GtkTreePath *)g_list_nth_data(list, i); + if (gtk_tree_model_get_iter(GTK_TREE_MODEL(resultStore), &iter, path)) + { + result = resultView.getValue(&iter, "SearchResult"); + if (result->getType() == SearchResult::TYPE_DIRECTORY || firstTTH != result->getTTH()->toBase32()) + tth = NULL; + if (result->getType() == SearchResult::TYPE_DIRECTORY || size != result->getSize()) + size = 0; + } + gtk_tree_path_free(path); + } + g_list_free(list); + + // Search matching file's. + StringList targets; + if (tth != NULL) + { + QueueManager::getInstance()->getTargetsByRoot(targets, *tth); + } + else if (size != 0) + { + QueueManager::getInstance()->getTargetsBySize(targets, size, ext); + } + if (targets.size() > 0) + { + StringIter i = targets.begin(); + menuItem = gtk_menu_item_new_with_label(Text::toT(*i).c_str()); + g_object_set_data_full(G_OBJECT(menuItem), "queueMatch", + g_strdup(Text::toT(*i).c_str()), g_free); + g_signal_connect(menuItem, "activate", G_CALLBACK + (onDownloadToMatchClicked_gui), (gpointer)this); + gtk_menu_shell_append(GTK_MENU_SHELL(getWidget("downloadMenu")), menuItem); + + menuItem = gtk_separator_menu_item_new(); + gtk_menu_shell_append(GTK_MENU_SHELL(getWidget("downloadMenu")), menuItem); + } + // Add favorites. StringPairList spl = FavoriteManager::getInstance()->getFavoriteDirs(); if (spl.size() > 0) { @@ -808,6 +871,39 @@ } } +void Search::onDownloadToMatchClicked_gui(GtkMenuItem *item, gpointer data) +{ + Search *s = (Search *)data; + GtkTreeIter iter; + GtkTreePath *path; + SearchResult *result; + string fileName; + typedef Func2 F2; + F2 *func; + + GList *list = gtk_tree_selection_get_selected_rows(s->selection, NULL); + guint count = gtk_tree_selection_count_selected_rows(s->selection); + + GtkTreeModel *m = GTK_TREE_MODEL(s->resultStore); + + fileName = string((gchar *)g_object_get_data(G_OBJECT(item), "queueMatch")); + for (int i = 0; i < count; i++) + { + path = (GtkTreePath *)g_list_nth_data(list, i); + if (gtk_tree_model_get_iter(m, &iter, path)) + { + result = s->resultView.getValue(&iter, "SearchResult"); + if (result) + { + func = new F2(s, &Search::addSource_client, fileName, result); + WulforManager::get()->dispatchClientFunc(func); + } + } + gtk_tree_path_free(path); + } + g_list_free(list); +} + void Search::onDownloadDirClicked_gui(GtkMenuItem *item, gpointer data) { Search *s = (Search *)data; @@ -1124,6 +1220,23 @@ catch (const Exception&) { } +} + +void Search::addSource_client(std::string target, SearchResult *result) +{ + target = Text::utf8ToAcp(target); + + try + { + if (result->getType() == SearchResult::TYPE_FILE) + QueueManager::getInstance()->add(target, result->getSize(), result->getTTH(), + result->getUser(), result->getFileName(), result->getUtf8()); + } + catch (const Exception&) + { + } + + } void Search::downloadDir_client(string target, SearchResult *result) Index: linux/search.hh =================================================================== RCS file: /cvsroot/linuxdcpp/linuxdcpp/linux/search.hh,v retrieving revision 1.14 diff -u -r1.14 search.hh --- linux/search.hh 21 Aug 2006 15:52:37 -0000 1.14 +++ linux/search.hh 17 Sep 2006 16:05:37 -0000 @@ -64,6 +64,7 @@ static void onDownloadClicked_gui(GtkMenuItem *item, gpointer data); static void onDownloadFavoriteClicked_gui(GtkMenuItem *item, gpointer data); static void onDownloadToClicked_gui(GtkMenuItem *item, gpointer data); + static void onDownloadToMatchClicked_gui(GtkMenuItem *item, gpointer data); static void onDownloadDirClicked_gui(GtkMenuItem *item, gpointer data); static void onDownloadFavoriteDirClicked_gui(GtkMenuItem *item, gpointer data); static void onDownloadDirToClicked_gui(GtkMenuItem *item, gpointer data); @@ -78,6 +79,7 @@ // Client functions void download_client(std::string target, SearchResult *result); + void addSource_client(std::string target, SearchResult *result); void downloadDir_client(std::string target, SearchResult *result); void getFileList_client(User::Ptr &user, QueueItem::FileFlags flags); void addFavUser_client(User::Ptr &user);