|
|
@ -43,7 +43,6 @@ |
|
|
|
SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, bool systrayIntegration) : QWidget(), BTSession(BTSession), myTrayIcon(myTrayIcon), systrayIntegration(systrayIntegration){ |
|
|
|
SearchEngine::SearchEngine(bittorrent *BTSession, QSystemTrayIcon *myTrayIcon, bool systrayIntegration) : QWidget(), BTSession(BTSession), myTrayIcon(myTrayIcon), systrayIntegration(systrayIntegration){ |
|
|
|
setupUi(this); |
|
|
|
setupUi(this); |
|
|
|
downloader = new downloadThread(this); |
|
|
|
downloader = new downloadThread(this); |
|
|
|
all_tab = new QList<SearchTab*>(); |
|
|
|
|
|
|
|
// new qCompleter to the search pattern
|
|
|
|
// new qCompleter to the search pattern
|
|
|
|
startSearchHistory(); |
|
|
|
startSearchHistory(); |
|
|
|
searchCompleter = new QCompleter(searchHistory, this); |
|
|
|
searchCompleter = new QCompleter(searchHistory, this); |
|
|
@ -76,7 +75,6 @@ SearchEngine::~SearchEngine(){ |
|
|
|
delete searchProcess; |
|
|
|
delete searchProcess; |
|
|
|
delete searchCompleter; |
|
|
|
delete searchCompleter; |
|
|
|
delete downloader; |
|
|
|
delete downloader; |
|
|
|
delete all_tab; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SearchEngine::on_enginesButton_clicked() { |
|
|
|
void SearchEngine::on_enginesButton_clicked() { |
|
|
@ -135,9 +133,9 @@ void SearchEngine::on_search_button_clicked(){ |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// Tab Addition
|
|
|
|
// Tab Addition
|
|
|
|
tab_search=new SearchTab(this); |
|
|
|
currentSearchTab=new SearchTab(this); |
|
|
|
tabWidget->addTab(tab_search, pattern); |
|
|
|
tabWidget->addTab(currentSearchTab, pattern); |
|
|
|
all_tab->append(tab_search); |
|
|
|
all_tab.append(currentSearchTab); |
|
|
|
closeTab_button->setEnabled(true); |
|
|
|
closeTab_button->setEnabled(true); |
|
|
|
// if the pattern is not in the pattern
|
|
|
|
// if the pattern is not in the pattern
|
|
|
|
if(searchHistory.indexOf(pattern) == -1){ |
|
|
|
if(searchHistory.indexOf(pattern) == -1){ |
|
|
@ -165,7 +163,7 @@ void SearchEngine::on_search_button_clicked(){ |
|
|
|
nb_search_results = 0; |
|
|
|
nb_search_results = 0; |
|
|
|
search_result_line_truncated.clear(); |
|
|
|
search_result_line_truncated.clear(); |
|
|
|
//on change le texte du label courrant
|
|
|
|
//on change le texte du label courrant
|
|
|
|
tab_search->getCurrentLabel()->setText(tr("Results")+" <i>(0)</i>:"); |
|
|
|
currentSearchTab->getCurrentLabel()->setText(tr("Results")+" <i>(0)</i>:"); |
|
|
|
// Launch search
|
|
|
|
// Launch search
|
|
|
|
searchProcess->start("python", params, QIODevice::ReadOnly); |
|
|
|
searchProcess->start("python", params, QIODevice::ReadOnly); |
|
|
|
searchTimeout->start(180000); // 3min
|
|
|
|
searchTimeout->start(180000); // 3min
|
|
|
@ -187,11 +185,11 @@ void SearchEngine::searchStarted(){ |
|
|
|
void SearchEngine::downloadSelectedItem(const QModelIndex& index){ |
|
|
|
void SearchEngine::downloadSelectedItem(const QModelIndex& index){ |
|
|
|
int row = index.row(); |
|
|
|
int row = index.row(); |
|
|
|
// Get Item url
|
|
|
|
// Get Item url
|
|
|
|
QString url = searchResultsUrls.value(all_tab->at(tabWidget->currentIndex())->getCurrentSearchListModel()->data(all_tab->at(tabWidget->currentIndex())->getCurrentSearchListModel()->index(row, NAME)).toString()); |
|
|
|
QString url = searchResultsUrls.value(all_tab.at(tabWidget->currentIndex())->getCurrentSearchListModel()->data(all_tab.at(tabWidget->currentIndex())->getCurrentSearchListModel()->index(row, NAME)).toString()); |
|
|
|
// Download from url
|
|
|
|
// Download from url
|
|
|
|
BTSession->downloadFromUrl(url); |
|
|
|
BTSession->downloadFromUrl(url); |
|
|
|
// Set item color to RED
|
|
|
|
// Set item color to RED
|
|
|
|
all_tab->at(tabWidget->currentIndex())->setRowColor(row, "red"); |
|
|
|
all_tab.at(tabWidget->currentIndex())->setRowColor(row, "red"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// search Qprocess return output as soon as it gets new
|
|
|
|
// search Qprocess return output as soon as it gets new
|
|
|
@ -210,7 +208,7 @@ void SearchEngine::readSearchOutput(){ |
|
|
|
foreach(line, lines_list){ |
|
|
|
foreach(line, lines_list){ |
|
|
|
appendSearchResult(QString(line)); |
|
|
|
appendSearchResult(QString(line)); |
|
|
|
} |
|
|
|
} |
|
|
|
tab_search->getCurrentLabel()->setText(tr("Results")+QString::fromUtf8(" <i>(")+misc::toQString(nb_search_results)+QString::fromUtf8(")</i>:")); |
|
|
|
currentSearchTab->getCurrentLabel()->setText(tr("Results")+QString::fromUtf8(" <i>(")+misc::toQString(nb_search_results)+QString::fromUtf8(")</i>:")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Update nova.py search plugin if necessary
|
|
|
|
// Update nova.py search plugin if necessary
|
|
|
@ -297,7 +295,8 @@ void SearchEngine::searchFinished(int exitcode,QProcess::ExitStatus){ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
tab_search->getCurrentLabel()->setText(tr("Results", "i.e: Search results")+QString::fromUtf8(" <i>(")+misc::toQString(nb_search_results)+QString::fromUtf8(")</i>:")); |
|
|
|
if(currentSearchTab) |
|
|
|
|
|
|
|
currentSearchTab->getCurrentLabel()->setText(tr("Results", "i.e: Search results")+QString::fromUtf8(" <i>(")+misc::toQString(nb_search_results)+QString::fromUtf8(")</i>:")); |
|
|
|
search_button->setEnabled(true); |
|
|
|
search_button->setEnabled(true); |
|
|
|
stop_search_button->setEnabled(false); |
|
|
|
stop_search_button->setEnabled(false); |
|
|
|
} |
|
|
|
} |
|
|
@ -317,13 +316,13 @@ void SearchEngine::appendSearchResult(QString line){ |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// Add item to search result list
|
|
|
|
// Add item to search result list
|
|
|
|
int row = tab_search->getCurrentSearchListModel()->rowCount(); |
|
|
|
int row = currentSearchTab->getCurrentSearchListModel()->rowCount(); |
|
|
|
tab_search->getCurrentSearchListModel()->insertRow(row); |
|
|
|
currentSearchTab->getCurrentSearchListModel()->insertRow(row); |
|
|
|
for(int i=0; i<5; ++i){ |
|
|
|
for(int i=0; i<5; ++i){ |
|
|
|
if(parts.at(i).toFloat() == -1 && i != SIZE) |
|
|
|
if(parts.at(i).toFloat() == -1 && i != SIZE) |
|
|
|
tab_search->getCurrentSearchListModel()->setData(tab_search->getCurrentSearchListModel()->index(row, i), tr("Unknown")); |
|
|
|
currentSearchTab->getCurrentSearchListModel()->setData(currentSearchTab->getCurrentSearchListModel()->index(row, i), tr("Unknown")); |
|
|
|
else |
|
|
|
else |
|
|
|
tab_search->getCurrentSearchListModel()->setData(tab_search->getCurrentSearchListModel()->index(row, i), QVariant(parts.at(i))); |
|
|
|
currentSearchTab->getCurrentSearchListModel()->setData(currentSearchTab->getCurrentSearchListModel()->index(row, i), QVariant(parts.at(i))); |
|
|
|
} |
|
|
|
} |
|
|
|
// Add url to searchResultsUrls associative array
|
|
|
|
// Add url to searchResultsUrls associative array
|
|
|
|
searchResultsUrls.insert(filename, url); |
|
|
|
searchResultsUrls.insert(filename, url); |
|
|
@ -343,20 +342,26 @@ void SearchEngine::on_stop_search_button_clicked(){ |
|
|
|
|
|
|
|
|
|
|
|
// Clear search results list
|
|
|
|
// Clear search results list
|
|
|
|
void SearchEngine::on_closeTab_button_clicked(){ |
|
|
|
void SearchEngine::on_closeTab_button_clicked(){ |
|
|
|
//// Kill process
|
|
|
|
if(all_tab.size()) { |
|
|
|
//searchProcess->terminate();
|
|
|
|
qDebug("currentTab rank: %d", tabWidget->currentIndex()); |
|
|
|
//search_stopped = true;
|
|
|
|
qDebug("currentSearchTab rank: %d", tabWidget->indexOf(currentSearchTab)); |
|
|
|
//searchTimeout->stop();
|
|
|
|
if(tabWidget->currentIndex() == tabWidget->indexOf(currentSearchTab)) { |
|
|
|
//searchResultsUrls.clear();
|
|
|
|
qDebug("Deleted current search Tab"); |
|
|
|
//tab_search->getCurrentSearchListModel()->removeRows(0, tab_search->getCurrentSearchListModel()->rowCount());
|
|
|
|
if(searchProcess->state() != QProcess::NotRunning){ |
|
|
|
//// Disable clear & download buttons
|
|
|
|
searchProcess->terminate(); |
|
|
|
//clear_button->setEnabled(false);
|
|
|
|
} |
|
|
|
//download_button->setEnabled(false);
|
|
|
|
if(searchTimeout->isActive()) { |
|
|
|
//nb_search_results = 0;
|
|
|
|
searchTimeout->stop(); |
|
|
|
//tab_search->getCurrentLabel()->setText(tr("Results")+" <i>(0)</i>:");
|
|
|
|
} |
|
|
|
//// focus on search pattern
|
|
|
|
search_stopped = true; |
|
|
|
//search_pattern->clear();
|
|
|
|
currentSearchTab = 0; |
|
|
|
//search_pattern->setFocus();
|
|
|
|
} |
|
|
|
|
|
|
|
delete all_tab.takeAt(tabWidget->currentIndex()); |
|
|
|
|
|
|
|
if(!all_tab.size()) { |
|
|
|
|
|
|
|
closeTab_button->setEnabled(false); |
|
|
|
|
|
|
|
download_button->setEnabled(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SearchEngine::on_clearPatternButton_clicked() { |
|
|
|
void SearchEngine::on_clearPatternButton_clicked() { |
|
|
@ -366,15 +371,15 @@ void SearchEngine::on_clearPatternButton_clicked() { |
|
|
|
|
|
|
|
|
|
|
|
// Download selected items in search results list
|
|
|
|
// Download selected items in search results list
|
|
|
|
void SearchEngine::on_download_button_clicked(){ |
|
|
|
void SearchEngine::on_download_button_clicked(){ |
|
|
|
//QModelIndexList selectedIndexes = tab_search->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
|
|
|
//QModelIndexList selectedIndexes = currentSearchTab->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
|
|
|
QModelIndexList selectedIndexes = all_tab->at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); |
|
|
|
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); |
|
|
|
QModelIndex index; |
|
|
|
QModelIndex index; |
|
|
|
foreach(index, selectedIndexes){ |
|
|
|
foreach(index, selectedIndexes){ |
|
|
|
if(index.column() == NAME){ |
|
|
|
if(index.column() == NAME){ |
|
|
|
// Get Item url
|
|
|
|
// Get Item url
|
|
|
|
QString url = searchResultsUrls.value(index.data().toString()); |
|
|
|
QString url = searchResultsUrls.value(index.data().toString()); |
|
|
|
BTSession->downloadFromUrl(url); |
|
|
|
BTSession->downloadFromUrl(url); |
|
|
|
all_tab->at(tabWidget->currentIndex())->setRowColor(index.row(), "red"); |
|
|
|
all_tab.at(tabWidget->currentIndex())->setRowColor(index.row(), "red"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|