2007-11-14 22:18:48 -05:00
|
|
|
/****************************************************************
|
|
|
|
* RShare is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006, crypton
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2009-08-25 16:49:50 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2007-11-14 22:18:48 -05:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
2010-03-10 16:38:26 -05:00
|
|
|
#include <set>
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
#include "rshare.h"
|
|
|
|
#include "SearchDialog.h"
|
2010-03-10 16:38:26 -05:00
|
|
|
#include "RetroShareLink.h"
|
2010-01-21 17:34:10 -05:00
|
|
|
#include "msgs/ChanMsgDialog.h"
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "rsiface/rsiface.h"
|
|
|
|
#include "rsiface/rsexpr.h"
|
2008-07-02 12:59:56 -04:00
|
|
|
#include "rsiface/rsfiles.h"
|
2008-08-31 12:50:36 -04:00
|
|
|
#include "rsiface/rspeers.h"
|
2009-08-16 16:10:53 -04:00
|
|
|
#include "rsiface/rsturtle.h"
|
2008-11-18 07:15:21 -05:00
|
|
|
#include "util/misc.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QCursor>
|
|
|
|
#include <QPoint>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QHeaderView>
|
|
|
|
|
|
|
|
/* Images for context menu icons */
|
|
|
|
#define IMAGE_START ":/images/download.png"
|
2010-02-09 08:49:37 -05:00
|
|
|
#define IMAGE_REMOVE ":/images/delete.png"
|
|
|
|
#define IMAGE_REMOVEALL ":/images/deleteall.png"
|
|
|
|
#define IMAGE_DIRECTORY ":/images/folder16.png"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Key for UI Preferences */
|
|
|
|
#define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch"
|
|
|
|
|
|
|
|
/* indicies for search results item columns SR_ = Search Result */
|
2008-11-18 15:29:40 -05:00
|
|
|
/* indicies for search results item columns SR_ = Search Result */
|
2010-02-14 20:09:23 -05:00
|
|
|
#define SR_NAME_COL 0
|
|
|
|
#define SR_SIZE_COL 1
|
|
|
|
#define SR_ID_COL 2
|
|
|
|
#define SR_TYPE_COL 3
|
|
|
|
#define SR_AGE_COL 4
|
|
|
|
#define SR_HASH_COL 5
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-14 20:09:23 -05:00
|
|
|
#define SR_SEARCH_ID_COL 6
|
2009-09-24 19:18:25 -04:00
|
|
|
|
2010-02-14 20:09:23 -05:00
|
|
|
#define SR_UID_COL 7
|
|
|
|
#define SR_REALSIZE_COL 8
|
2008-12-12 16:41:34 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* indicies for search summary item columns SS_ = Search Summary */
|
|
|
|
#define SS_TEXT_COL 0
|
|
|
|
#define SS_COUNT_COL 1
|
|
|
|
#define SS_SEARCH_ID_COL 2
|
|
|
|
|
2010-01-21 17:34:10 -05:00
|
|
|
#define IMAGE_COPYLINK ":/images/copyrslink.png"
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* static members */
|
|
|
|
/* These indices MUST be identical to their equivalent indices in the combobox */
|
|
|
|
const int SearchDialog::FILETYPE_IDX_ANY = 0;
|
2008-11-18 17:59:33 -05:00
|
|
|
const int SearchDialog::FILETYPE_IDX_ARCHIVE = 1;
|
|
|
|
const int SearchDialog::FILETYPE_IDX_AUDIO = 2;
|
|
|
|
const int SearchDialog::FILETYPE_IDX_CDIMAGE = 3;
|
|
|
|
const int SearchDialog::FILETYPE_IDX_DOCUMENT = 4;
|
|
|
|
const int SearchDialog::FILETYPE_IDX_PICTURE = 5;
|
|
|
|
const int SearchDialog::FILETYPE_IDX_PROGRAM = 6;
|
|
|
|
const int SearchDialog::FILETYPE_IDX_VIDEO = 7;
|
2009-08-25 16:49:50 -04:00
|
|
|
const int SearchDialog::FILETYPE_IDX_DIRECTORY = 8;
|
2007-11-14 22:18:48 -05:00
|
|
|
QMap<int, QString> * SearchDialog::FileTypeExtensionMap = new QMap<int, QString>();
|
|
|
|
bool SearchDialog::initialised = false;
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Constructor */
|
|
|
|
SearchDialog::SearchDialog(QWidget *parent)
|
2009-08-25 16:49:50 -04:00
|
|
|
: MainPage(parent),
|
|
|
|
advSearchDialog(NULL),
|
2007-11-14 22:18:48 -05:00
|
|
|
contextMnu(NULL), contextMnu2(NULL),
|
|
|
|
nextSearchId(1)
|
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
2009-08-13 08:16:35 -04:00
|
|
|
ui.lineEdit->setFocus();
|
2010-02-14 12:58:22 -05:00
|
|
|
ui.lineEdit->setToolTip(tr("Enter a keyword here (at least 3 char long)"));
|
2009-08-13 08:16:35 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* initialise the filetypes mapping */
|
|
|
|
if (!SearchDialog::initialised)
|
|
|
|
{
|
2009-05-11 10:36:32 -04:00
|
|
|
initialiseFileTypeMappings();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
RshareSettings rsharesettings;
|
2009-08-25 16:49:50 -04:00
|
|
|
|
|
|
|
connect(ui.toggleAdvancedSearchBtn, SIGNAL(clicked()), this, SLOT(showAdvSearchDialog()));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
connect( ui.searchResultWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidgetCostumPopupMenu( QPoint ) ) );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
connect( ui.searchSummaryWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidget2CostumPopupMenu( QPoint ) ) );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
connect( ui.lineEdit, SIGNAL( returnPressed ( void ) ), this, SLOT( searchKeywords( void ) ) );
|
2010-02-14 10:34:53 -05:00
|
|
|
connect( ui.lineEdit, SIGNAL( textChanged ( const QString& ) ), this, SLOT( checkText( const QString& ) ) );
|
2007-11-14 22:18:48 -05:00
|
|
|
connect( ui.pushButtonsearch, SIGNAL( released ( void ) ), this, SLOT( searchKeywords( void ) ) );
|
|
|
|
connect( ui.pushButtonDownload, SIGNAL( released ( void ) ), this, SLOT( download( void ) ) );
|
2009-05-10 18:34:38 -04:00
|
|
|
connect( ui.cloaseallsearchresultsButton, SIGNAL(clicked()), this, SLOT(searchRemoveAll()));
|
|
|
|
connect( ui.resetButton, SIGNAL(clicked()), this, SLOT(clearKeyword()));
|
2010-02-13 21:31:37 -05:00
|
|
|
connect( ui.lineEdit, SIGNAL( textChanged(const QString &)), this, SLOT(togglereset()));
|
2009-05-10 18:34:38 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
//connect( ui.searchSummaryWidget, SIGNAL( itemSelectionChanged ( void ) ), this, SLOT( selectSearchResults( void ) ) );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2009-05-10 18:34:38 -04:00
|
|
|
connect( ui.searchResultWidget, SIGNAL( itemDoubleClicked ( QTreeWidgetItem *, int)), this, SLOT(download()));
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
connect ( ui.searchSummaryWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
|
|
|
|
this, SLOT( selectSearchResults( void ) ) );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2010-02-21 08:38:27 -05:00
|
|
|
//connect(ui.FileTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboIndexChanged(int)));
|
|
|
|
connect(ui.FileTypeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectSearchResults(int)));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* hide the Tree +/- */
|
2010-02-06 20:37:06 -05:00
|
|
|
ui.searchResultWidget -> setRootIsDecorated( true );
|
2008-12-12 16:41:34 -05:00
|
|
|
ui.searchResultWidget -> setColumnHidden( SR_UID_COL,true );
|
|
|
|
ui.searchResultWidget -> setColumnHidden( SR_REALSIZE_COL,true );
|
2007-11-14 22:18:48 -05:00
|
|
|
ui.searchSummaryWidget -> setRootIsDecorated( false );
|
|
|
|
|
|
|
|
/* make it extended selection */
|
|
|
|
ui.searchResultWidget -> setSelectionMode(QAbstractItemView::ExtendedSelection);
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Set header resize modes and initial section sizes */
|
|
|
|
ui.searchSummaryWidget->setColumnCount(3);
|
2010-02-14 16:48:54 -05:00
|
|
|
ui.searchSummaryWidget->setColumnHidden ( 2, true);
|
2009-08-25 16:49:50 -04:00
|
|
|
|
|
|
|
QHeaderView * _smheader = ui.searchSummaryWidget->header () ;
|
2007-11-14 22:18:48 -05:00
|
|
|
_smheader->setResizeMode (0, QHeaderView::Interactive);
|
|
|
|
_smheader->setResizeMode (1, QHeaderView::Interactive);
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2010-02-14 20:09:23 -05:00
|
|
|
_smheader->resizeSection ( 0, 160 );
|
|
|
|
_smheader->resizeSection ( 1, 50 );
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-14 20:09:23 -05:00
|
|
|
ui.searchResultWidget->setColumnCount(6);
|
2009-08-25 16:49:50 -04:00
|
|
|
_smheader = ui.searchResultWidget->header () ;
|
2010-02-14 20:09:23 -05:00
|
|
|
_smheader->setResizeMode (0, QHeaderView::Interactive);
|
2007-11-14 22:18:48 -05:00
|
|
|
_smheader->setResizeMode (1, QHeaderView::Interactive);
|
|
|
|
_smheader->setResizeMode (2, QHeaderView::Interactive);
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2010-02-14 20:09:23 -05:00
|
|
|
_smheader->resizeSection ( 0, 240 );
|
|
|
|
_smheader->resizeSection ( 1, 75 );
|
2007-11-14 22:18:48 -05:00
|
|
|
_smheader->resizeSection ( 2, 75 );
|
2008-11-18 15:29:40 -05:00
|
|
|
_smheader->resizeSection ( 3, 75 );
|
2010-02-14 20:09:23 -05:00
|
|
|
_smheader->resizeSection ( 4, 90 );
|
|
|
|
_smheader->resizeSection ( 5, 240 );
|
2008-11-18 17:59:33 -05:00
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2008-02-01 13:55:21 -05:00
|
|
|
// set header text aligment
|
2010-02-27 20:03:37 -05:00
|
|
|
QTreeWidgetItem * headerItem = ui.searchResultWidget->headerItem();
|
|
|
|
headerItem->setTextAlignment(1, Qt::AlignRight | Qt::AlignRight);
|
|
|
|
headerItem->setTextAlignment(2, Qt::AlignRight | Qt::AlignRight);
|
|
|
|
|
|
|
|
ui.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder);
|
|
|
|
|
|
|
|
ui.resetButton->hide();
|
|
|
|
|
|
|
|
ui._ownFiles_CB->setMinimumWidth(20);
|
|
|
|
ui._friendListsearch_SB->setMinimumWidth(20);
|
|
|
|
ui._anonF2Fsearch_CB->setMinimumWidth(20);
|
|
|
|
ui.label->setMinimumWidth(20);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Hide platform specific features */
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-02-14 10:34:53 -05:00
|
|
|
void SearchDialog::checkText(const QString& txt)
|
|
|
|
{
|
2010-02-14 12:58:22 -05:00
|
|
|
if(txt.length() < 3)
|
2010-02-14 10:34:53 -05:00
|
|
|
{
|
|
|
|
std::cout << "setting palette 1" << std::endl ;
|
2010-02-14 12:58:22 -05:00
|
|
|
ui.frame_2->setStyleSheet("QFrame{ border: 2px solid #079E00; background-color: #DBDBDB; }");
|
2010-02-14 10:34:53 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-14 12:58:22 -05:00
|
|
|
ui.frame_2->setStyleSheet("QFrame { border: 2px solid #079E00; background-color: white; }");
|
2010-02-14 10:34:53 -05:00
|
|
|
std::cout << "setting palette 2" << std::endl ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
void SearchDialog::initialiseFileTypeMappings()
|
|
|
|
{
|
|
|
|
/* edit these strings to change the range of extensions recognised by the search */
|
|
|
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_ANY, "");
|
2009-08-25 16:49:50 -04:00
|
|
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_AUDIO,
|
2007-11-14 22:18:48 -05:00
|
|
|
"aac aif iff m3u mid midi mp3 mpa ogg ra ram wav wma");
|
2009-08-25 16:49:50 -04:00
|
|
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_ARCHIVE,
|
2008-11-18 17:59:33 -05:00
|
|
|
"7z bz2 gz pkg rar sea sit sitx tar zip");
|
2009-08-25 16:49:50 -04:00
|
|
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_CDIMAGE,
|
2008-11-18 17:59:33 -05:00
|
|
|
"iso nrg mdf");
|
2009-08-25 16:49:50 -04:00
|
|
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_DOCUMENT,
|
|
|
|
"doc odt ott rtf pdf ps txt log msg wpd wps" );
|
|
|
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_PICTURE,
|
2007-11-19 05:56:12 -05:00
|
|
|
"3dm 3dmf ai bmp drw dxf eps gif ico indd jpe jpeg jpg mng pcx pcc pct pgm "
|
|
|
|
"pix png psd psp qxd qxprgb sgi svg tga tif tiff xbm xcf");
|
2009-08-25 16:49:50 -04:00
|
|
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_PROGRAM,
|
2007-11-14 22:18:48 -05:00
|
|
|
"app bat cgi com bin exe js pif py pl sh vb ws ");
|
2009-08-25 16:49:50 -04:00
|
|
|
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_VIDEO,
|
2008-11-18 17:59:33 -05:00
|
|
|
"3gp asf asx avi mov mp4 mkv flv mpeg mpg qt rm swf vob wmv");
|
2007-11-14 22:18:48 -05:00
|
|
|
SearchDialog::initialised = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point )
|
|
|
|
{
|
|
|
|
// block the popup if no results available
|
2009-08-25 16:49:50 -04:00
|
|
|
if ((ui.searchResultWidget->selectedItems()).size() == 0) return;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
// create the menu as required
|
|
|
|
if (contextMnu == 0)
|
|
|
|
{
|
|
|
|
contextMnu = new QMenu(this);
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
downloadAct = new QAction(QIcon(IMAGE_START), tr( "Download" ), this );
|
|
|
|
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( download() ) );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2010-01-21 17:34:10 -05:00
|
|
|
copysearchlinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), this );
|
|
|
|
connect( copysearchlinkAct , SIGNAL( triggered() ), this, SLOT( copysearchLink() ) );
|
|
|
|
|
|
|
|
sendrslinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), this );
|
|
|
|
connect( sendrslinkAct , SIGNAL( triggered() ), this, SLOT( sendLinkTo( ) ) );
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
broadcastonchannelAct = new QAction( tr( "Broadcast on Channel" ), this );
|
|
|
|
connect( broadcastonchannelAct , SIGNAL( triggered() ), this, SLOT( broadcastonchannel() ) );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
recommendtofriendsAct = new QAction( tr( "Recommend to Friends" ), this );
|
|
|
|
connect( recommendtofriendsAct , SIGNAL( triggered() ), this, SLOT( recommendtofriends() ) );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
contextMnu->clear();
|
|
|
|
contextMnu->addAction( downloadAct);
|
2010-01-21 17:34:10 -05:00
|
|
|
contextMnu->addSeparator();
|
2010-03-10 16:38:26 -05:00
|
|
|
|
2010-03-10 18:09:35 -05:00
|
|
|
contextMnu->addAction( copysearchlinkAct);
|
|
|
|
contextMnu->addAction( sendrslinkAct);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2010-03-10 16:38:26 -05:00
|
|
|
QMouseEvent *mevent = new QMouseEvent(QEvent::MouseButtonPress,point,Qt::RightButton, Qt::RightButton,Qt::NoModifier);
|
2007-11-14 22:18:48 -05:00
|
|
|
contextMnu->exec( mevent->globalPos() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchDialog::download()
|
|
|
|
{
|
|
|
|
/* should also be able to handle multi-selection */
|
|
|
|
QList<QTreeWidgetItem*> itemsForDownload = ui.searchResultWidget->selectedItems();
|
|
|
|
int numdls = itemsForDownload.size();
|
|
|
|
QTreeWidgetItem * item;
|
|
|
|
bool attemptDownloadLocal = false;
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2010-01-21 07:39:26 -05:00
|
|
|
for (int i = 0; i < numdls; ++i)
|
|
|
|
{
|
|
|
|
item = itemsForDownload.at(i);
|
|
|
|
// call the download
|
2010-02-18 19:48:42 -05:00
|
|
|
if (!item->text(SR_HASH_COL).isEmpty() || !item->childCount())
|
2010-01-21 07:39:26 -05:00
|
|
|
{
|
|
|
|
std::cerr << "SearchDialog::download() Calling File Request";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::list<std::string> srcIds;
|
2010-01-22 18:23:37 -05:00
|
|
|
#ifdef SUSPENDED
|
|
|
|
// I suspend this. For turtle F2F download, we dont' need sources:
|
|
|
|
// - if we put sources, they make double with some tunnels.
|
|
|
|
// - they won't transfer because ASSUME_AVAILABILITY can't be used,
|
|
|
|
// and no chunk maps are transfered except in tunnels.
|
2010-01-21 07:39:26 -05:00
|
|
|
srcIds.push_back(item->text(SR_UID_COL).toStdString()) ;
|
2010-01-22 18:23:37 -05:00
|
|
|
#endif
|
2010-01-21 07:39:26 -05:00
|
|
|
|
|
|
|
if(!rsFiles -> FileRequest((item->text(SR_NAME_COL)).toStdString(),
|
|
|
|
(item->text(SR_HASH_COL)).toStdString(),
|
|
|
|
(item->text(SR_REALSIZE_COL)).toInt(),
|
|
|
|
"", RS_FILE_HINTS_NETWORK_WIDE, srcIds))
|
|
|
|
attemptDownloadLocal = true ;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "isuing file request from search dialog: -" << (item->text(SR_NAME_COL)).toStdString() << "-" << (item->text(SR_HASH_COL)).toStdString() << "-" << (item->text(SR_REALSIZE_COL)).toInt() << "-ids=" ;
|
|
|
|
for(std::list<std::string>::const_iterator it(srcIds.begin());it!=srcIds.end();++it)
|
|
|
|
std::cout << *it << "-" << std::endl ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // we have a folder
|
|
|
|
downloadDirectory(item, tr(""));
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
if (attemptDownloadLocal)
|
|
|
|
QMessageBox::information(0, tr("Download Notice"), tr("Skipping Local Files"));
|
|
|
|
}
|
|
|
|
|
2009-09-25 08:17:28 -04:00
|
|
|
void SearchDialog::downloadDirectory(const QTreeWidgetItem *item, const QString &base)
|
|
|
|
{
|
|
|
|
if (!item->childCount()) {
|
|
|
|
std::list<std::string> srcIds;
|
2010-01-22 18:23:37 -05:00
|
|
|
#ifdef SUSPENDED
|
2009-09-25 08:17:28 -04:00
|
|
|
srcIds.push_back(item->text(SR_UID_COL).toStdString());
|
2010-01-22 18:23:37 -05:00
|
|
|
#endif
|
2009-09-25 08:17:28 -04:00
|
|
|
|
|
|
|
QString path = QString::fromStdString(rsFiles->getDownloadDirectory())
|
|
|
|
+ tr("/") + base + tr("/");
|
|
|
|
QString cleanPath = QDir::cleanPath(path);
|
|
|
|
|
|
|
|
rsFiles->FileRequest(item->text(SR_NAME_COL).toStdString(),
|
|
|
|
item->text(SR_HASH_COL).toStdString(),
|
|
|
|
item->text(SR_REALSIZE_COL).toInt(),
|
2010-01-11 17:38:18 -05:00
|
|
|
cleanPath.toStdString(),RS_FILE_HINTS_NETWORK_WIDE, srcIds);
|
2009-09-25 08:17:28 -04:00
|
|
|
|
|
|
|
std::cout << "SearchDialog::downloadDirectory(): "\
|
|
|
|
"issuing file request from search dialog: -"
|
|
|
|
<< (item->text(SR_NAME_COL)).toStdString()
|
|
|
|
<< "-" << (item->text(SR_HASH_COL)).toStdString()
|
|
|
|
<< "-" << (item->text(SR_REALSIZE_COL)).toInt()
|
|
|
|
<< "-ids=" ;
|
|
|
|
for(std::list<std::string>::const_iterator it(srcIds.begin());
|
|
|
|
it!=srcIds.end();++it)
|
|
|
|
std::cout << *it << "-" << std::endl ;
|
|
|
|
} else {
|
|
|
|
QDir dwlDir(QString::fromStdString(rsFiles->getDownloadDirectory()));
|
|
|
|
QString path;
|
|
|
|
if (base == tr(""))
|
|
|
|
path = item->text(SR_NAME_COL);
|
|
|
|
else
|
|
|
|
path = base + tr("/") + item->text(SR_NAME_COL);
|
|
|
|
QString cleanPath = QDir::cleanPath(path);
|
|
|
|
|
|
|
|
// create this folder in download path
|
|
|
|
if (!dwlDir.mkpath(cleanPath)) {
|
|
|
|
std::cerr << "SearchDialog::downloadDirectory() - can't create "
|
|
|
|
<< cleanPath.toStdString() << " directory" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// recursive call for every child - file or folder
|
|
|
|
for (int i = 0, cnt = item->childCount(); i < cnt; i++) {
|
|
|
|
QTreeWidgetItem *child = item->child(i);
|
|
|
|
downloadDirectory(child, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
void SearchDialog::broadcastonchannel()
|
|
|
|
{
|
|
|
|
|
|
|
|
QMessageBox::warning(0, tr("Sorry"), tr("This function is not yet implemented."));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SearchDialog::recommendtofriends()
|
|
|
|
{
|
|
|
|
QMessageBox::warning(0, tr("Sorry"), tr("This function is not yet implemented."));
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** context menu searchTablewidget2 **/
|
|
|
|
void SearchDialog::searchtableWidget2CostumPopupMenu( QPoint point )
|
|
|
|
{
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
// block the popup if no results available
|
2009-08-25 16:49:50 -04:00
|
|
|
if ((ui.searchSummaryWidget->selectedItems()).size() == 0) return;
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
// create the menu as required
|
|
|
|
if (contextMnu2 == 0)
|
|
|
|
{
|
|
|
|
contextMnu2 = new QMenu( this );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
searchRemoveAct = new QAction(QIcon(IMAGE_REMOVE), tr( "Remove" ), this );
|
|
|
|
connect( searchRemoveAct , SIGNAL( triggered() ), this, SLOT( searchRemove() ) );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
searchRemoveAllAct = new QAction(QIcon(IMAGE_REMOVEALL), tr( "Remove All" ), this );
|
2007-11-19 05:56:12 -05:00
|
|
|
connect( searchRemoveAllAct , SIGNAL( triggered() ), this, SLOT( searchRemoveAll() ) );
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
contextMnu2->clear();
|
|
|
|
contextMnu2->addAction( searchRemoveAct);
|
|
|
|
contextMnu2->addAction( searchRemoveAllAct);
|
2009-08-25 16:49:50 -04:00
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
QMouseEvent *mevent2 = new QMouseEvent( QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier );
|
|
|
|
contextMnu2->exec( mevent2->globalPos() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/** remove selected search result **/
|
|
|
|
void SearchDialog::searchRemove()
|
|
|
|
{
|
|
|
|
/* get the current search id from the summary window */
|
|
|
|
QTreeWidgetItem *ci = ui.searchSummaryWidget->currentItem();
|
|
|
|
if (!ci)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* get the searchId text */
|
|
|
|
QString searchId = ci->text(SS_SEARCH_ID_COL);
|
|
|
|
|
|
|
|
std::cerr << "SearchDialog::searchRemove(): searchId: " << searchId.toStdString();
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
/* show only matching searchIds in main window */
|
|
|
|
int items = ui.searchResultWidget->topLevelItemCount();
|
|
|
|
for(int i = 0; i < items;)
|
|
|
|
{
|
|
|
|
/* get item */
|
|
|
|
QTreeWidgetItem *ti = ui.searchResultWidget->topLevelItem(i);
|
|
|
|
if (ti->text(SR_SEARCH_ID_COL) == searchId)
|
|
|
|
{
|
|
|
|
/* remove */
|
|
|
|
delete (ui.searchResultWidget->takeTopLevelItem(i));
|
|
|
|
items--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* step to the next */
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int sii = ui.searchSummaryWidget->indexOfTopLevelItem(ci);
|
|
|
|
if (sii != -1)
|
|
|
|
{
|
|
|
|
delete (ui.searchSummaryWidget->takeTopLevelItem(sii));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.searchResultWidget->update();
|
|
|
|
ui.searchSummaryWidget->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** remove all search results **/
|
|
|
|
void SearchDialog::searchRemoveAll()
|
|
|
|
{
|
2007-11-19 05:56:12 -05:00
|
|
|
ui.searchResultWidget->clear();
|
|
|
|
ui.searchSummaryWidget->clear();
|
2010-03-25 15:20:16 -04:00
|
|
|
ui.FileTypeComboBox->setCurrentIndex(0);
|
2007-11-19 05:56:12 -05:00
|
|
|
nextSearchId = 1;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-05-10 18:34:38 -04:00
|
|
|
/** clear keywords and ComboBox **/
|
|
|
|
void SearchDialog::clearKeyword()
|
|
|
|
{
|
|
|
|
ui.lineEdit->clear();
|
2010-02-14 06:43:28 -05:00
|
|
|
ui.lineEdit->setFocus();
|
2009-05-10 18:34:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* *****************************************************************
|
|
|
|
Advanced search implementation
|
|
|
|
*******************************************************************/
|
|
|
|
// Event handlers for hide and show events
|
|
|
|
void SearchDialog::hideEvent(QHideEvent * event)
|
|
|
|
{
|
|
|
|
showAdvSearchDialog(false);
|
|
|
|
MainPage::hideEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchDialog::toggleAdvancedSearchDialog(bool toggled)
|
|
|
|
{
|
|
|
|
// record the users preference for future reference
|
|
|
|
RshareSettings rsharesettings;
|
|
|
|
QString key (UI_PREF_ADVANCED_SEARCH);
|
|
|
|
rsharesettings.setValue(key, QVariant(toggled));
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
showAdvSearchDialog(toggled);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchDialog::showAdvSearchDialog(bool show)
|
|
|
|
{
|
|
|
|
// instantiate if about to show for the first time
|
|
|
|
if (advSearchDialog == 0 && show)
|
|
|
|
{
|
|
|
|
advSearchDialog = new AdvancedSearchDialog();
|
|
|
|
connect(advSearchDialog, SIGNAL(search(Expression*)),
|
|
|
|
this, SLOT(advancedSearch(Expression*)));
|
|
|
|
}
|
|
|
|
if (show) {
|
|
|
|
advSearchDialog->show();
|
|
|
|
advSearchDialog->raise();
|
|
|
|
advSearchDialog->setFocus();
|
|
|
|
} else if (advSearchDialog != 0){
|
|
|
|
advSearchDialog->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-24 17:08:55 -04:00
|
|
|
// Creates a new entry in the search summary, not to leave it blank whatever happens.
|
|
|
|
//
|
|
|
|
void SearchDialog::initSearchResult(const std::string& txt,qulonglong searchId)
|
|
|
|
{
|
|
|
|
QString sid_hexa = QString::number(searchId,16) ;
|
|
|
|
|
|
|
|
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
|
|
|
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
|
|
|
item2->setText(SS_COUNT_COL, QString::number(0));
|
|
|
|
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
|
|
|
|
|
|
|
ui.searchSummaryWidget->addTopLevelItem(item2);
|
|
|
|
ui.searchSummaryWidget->setCurrentItem(item2);
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
void SearchDialog::advancedSearch(Expression* expression)
|
|
|
|
{
|
|
|
|
advSearchDialog->hide();
|
|
|
|
|
|
|
|
/* call to core */
|
2009-08-25 16:49:50 -04:00
|
|
|
std::list<DirDetails> results;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-25 08:04:43 -04:00
|
|
|
// send a turtle search request
|
|
|
|
LinearizedExpression e ;
|
|
|
|
expression->linearize(e) ;
|
|
|
|
|
|
|
|
TurtleRequestId req_id = rsTurtle->turtleSearch(e) ;
|
|
|
|
|
2009-09-24 17:08:55 -04:00
|
|
|
// This will act before turtle results come to the interface, thanks to the signals scheduling policy.
|
|
|
|
// The text "bool exp" should be replaced by an appropriate text describing the actual search.
|
2009-09-25 08:17:28 -04:00
|
|
|
initSearchResult(std::string("bool exp"),req_id) ;
|
2009-09-24 17:08:55 -04:00
|
|
|
|
2009-08-25 08:04:43 -04:00
|
|
|
rsFiles -> SearchBoolExp(expression, results, DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
|
|
|
|
|
|
|
/* abstraction to allow reusee of tree rendering code */
|
|
|
|
resultsToTree((advSearchDialog->getSearchAsString()).toStdString(),req_id, results);
|
|
|
|
|
2009-08-25 08:17:22 -04:00
|
|
|
// // debug stuff
|
|
|
|
// Expression *expression2 = LinearizedExpression::toExpr(e) ;
|
|
|
|
// results.clear() ;
|
|
|
|
// rsFiles -> SearchBoolExp(expression2, results, DIR_FLAGS_REMOTE | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE);
|
|
|
|
// resultsToTree((advSearchDialog->getSearchAsString()).toStdString(),req_id+1, results);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SearchDialog::searchKeywords()
|
2009-08-25 16:49:50 -04:00
|
|
|
{
|
2007-11-14 22:18:48 -05:00
|
|
|
QString qTxt = ui.lineEdit->text();
|
|
|
|
std::string txt = qTxt.toStdString();
|
|
|
|
|
2010-02-14 12:58:22 -05:00
|
|
|
if(txt.length() < 3)
|
2010-02-14 10:34:53 -05:00
|
|
|
return ;
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "SearchDialog::searchKeywords() : " << txt << std::endl;
|
|
|
|
|
2010-02-27 16:10:54 -05:00
|
|
|
TurtleRequestId req_id ;
|
|
|
|
|
|
|
|
if(ui._anonF2Fsearch_CB->isChecked())
|
|
|
|
req_id = rsTurtle->turtleSearch(txt) ;
|
|
|
|
else
|
|
|
|
req_id = (((uint32_t)rand()) << 16)^0x1e2fd5e4 + ((uint32_t)rand())^0x1b19acfe ; // generate a random 32 bits request id
|
2009-08-16 16:10:53 -04:00
|
|
|
|
2009-09-24 17:08:55 -04:00
|
|
|
initSearchResult(txt,req_id) ; // this will act before turtle results come to the interface, thanks to the signals scheduling policy.
|
|
|
|
|
2010-02-27 16:10:54 -05:00
|
|
|
if(ui._friendListsearch_SB->isChecked() || ui._ownFiles_CB->isChecked())
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-02-27 16:10:54 -05:00
|
|
|
/* extract keywords from lineEdit */
|
|
|
|
QStringList qWords = qTxt.split(" ", QString::SkipEmptyParts);
|
|
|
|
std::list<std::string> words;
|
|
|
|
QStringListIterator qWordsIter(qWords);
|
|
|
|
while (qWordsIter.hasNext())
|
|
|
|
{
|
|
|
|
words.push_back(qWordsIter.next().toStdString());
|
|
|
|
}
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2010-02-27 16:10:54 -05:00
|
|
|
if (words.size() < 1)
|
|
|
|
{
|
|
|
|
/* ignore */
|
|
|
|
return;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-27 16:10:54 -05:00
|
|
|
std::list<DirDetails> finalResults ;
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2010-02-27 16:10:54 -05:00
|
|
|
if(ui._friendListsearch_SB->isChecked())
|
|
|
|
{
|
|
|
|
std::list<DirDetails> initialResults;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-02-27 16:10:54 -05:00
|
|
|
rsFiles -> SearchKeywords(words, initialResults, DIR_FLAGS_REMOTE) ;
|
|
|
|
|
|
|
|
/* which extensions do we use? */
|
|
|
|
DirDetails dd;
|
|
|
|
|
|
|
|
for(std::list<DirDetails>::iterator resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter ++)
|
|
|
|
{
|
|
|
|
dd = *resultsIter;
|
|
|
|
finalResults.push_back(dd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ui._ownFiles_CB->isChecked())
|
|
|
|
{
|
|
|
|
std::list<DirDetails> initialResults;
|
|
|
|
|
|
|
|
rsFiles -> SearchKeywords(words, initialResults, DIR_FLAGS_LOCAL | DIR_FLAGS_NETWORK_WIDE | DIR_FLAGS_BROWSABLE) ;
|
|
|
|
|
|
|
|
/* which extensions do we use? */
|
|
|
|
DirDetails dd;
|
|
|
|
|
|
|
|
for(std::list<DirDetails>::iterator resultsIter = initialResults.begin(); resultsIter != initialResults.end(); resultsIter ++)
|
|
|
|
{
|
|
|
|
dd = *resultsIter;
|
|
|
|
finalResults.push_back(dd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* abstraction to allow reusee of tree rendering code */
|
|
|
|
resultsToTree(txt,req_id, finalResults);
|
|
|
|
ui.lineEdit->clear() ;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
void SearchDialog::updateFiles(qulonglong search_id,FileDetail file)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-08-16 16:10:53 -04:00
|
|
|
/* which extensions do we use? */
|
|
|
|
std::string txt = ui.lineEdit->text().toStdString();
|
2010-02-14 10:34:53 -05:00
|
|
|
#ifdef DEBUG
|
2009-09-24 17:08:55 -04:00
|
|
|
std::cout << "Updating file detail:" << std::endl ;
|
|
|
|
std::cout << " size = " << file.size << std::endl ;
|
|
|
|
std::cout << " name = " << file.name << std::endl ;
|
|
|
|
std::cout << " s_id = " << search_id << std::endl ;
|
2010-02-14 10:34:53 -05:00
|
|
|
#endif
|
2009-09-24 17:08:55 -04:00
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
|
2009-08-16 16:10:53 -04:00
|
|
|
insertFile(txt,search_id,file);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// amend the text description of the search
|
|
|
|
txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
|
|
|
|
// collect the extensions to use
|
2009-08-25 16:49:50 -04:00
|
|
|
QString extStr = SearchDialog::FileTypeExtensionMap->value(ui.FileTypeComboBox->currentIndex());
|
2009-08-16 16:10:53 -04:00
|
|
|
QStringList extList = extStr.split(" ");
|
|
|
|
|
|
|
|
// get this file's extension
|
2009-09-24 17:08:55 -04:00
|
|
|
QString qName = QString::fromUtf8(file.name.c_str());
|
2009-08-16 16:10:53 -04:00
|
|
|
int extIndex = qName.lastIndexOf(".");
|
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
if (extIndex >= 0)
|
2009-08-16 16:10:53 -04:00
|
|
|
{
|
|
|
|
QString qExt = qName.mid(extIndex+1);
|
|
|
|
|
|
|
|
if (qExt != "" )
|
|
|
|
for (int i = 0; i < extList.size(); ++i)
|
|
|
|
if (qExt.toUpper() == extList.at(i).toUpper())
|
|
|
|
insertFile(txt,search_id,file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-25 16:49:50 -04:00
|
|
|
|
|
|
|
void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir, QTreeWidgetItem *item)
|
|
|
|
{
|
2009-09-24 17:08:55 -04:00
|
|
|
QString sid_hexa = QString::number(searchId,16) ;
|
|
|
|
|
2009-09-25 08:17:28 -04:00
|
|
|
if (dir.type == DIR_TYPE_FILE)
|
2009-09-24 17:08:55 -04:00
|
|
|
{
|
2009-08-25 16:49:50 -04:00
|
|
|
QTreeWidgetItem *child;
|
|
|
|
if (item == NULL) {
|
|
|
|
child = new QTreeWidgetItem(ui.searchResultWidget);
|
|
|
|
} else {
|
|
|
|
child = new QTreeWidgetItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* translate search result for a file */
|
2010-02-06 20:37:06 -05:00
|
|
|
|
2009-09-24 17:08:55 -04:00
|
|
|
child->setText(SR_NAME_COL, QString::fromUtf8(dir.name.c_str()));
|
2009-08-25 16:49:50 -04:00
|
|
|
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
|
|
|
QString ext = QFileInfo(QString::fromStdString(dir.name)).suffix();
|
|
|
|
child->setText(SR_SIZE_COL, misc::friendlyUnit(dir.count));
|
2009-09-24 19:18:25 -04:00
|
|
|
child->setText(SR_AGE_COL, misc::userFriendlyDuration(dir.age));
|
2009-08-25 16:49:50 -04:00
|
|
|
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
|
|
|
|
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
2010-02-14 13:56:56 -05:00
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
child->setText(SR_ID_COL, QString::number(1));
|
2010-02-14 20:09:23 -05:00
|
|
|
child->setTextAlignment( SR_ID_COL, Qt::AlignRight );
|
|
|
|
|
2009-09-24 17:08:55 -04:00
|
|
|
child->setText(SR_SEARCH_ID_COL, sid_hexa);
|
2009-08-25 16:49:50 -04:00
|
|
|
setIconAndType(child, ext);
|
|
|
|
|
|
|
|
if (item == NULL) {
|
|
|
|
ui.searchResultWidget->addTopLevelItem(child);
|
|
|
|
} else {
|
|
|
|
item->addChild(child);
|
|
|
|
}
|
2009-09-25 08:17:28 -04:00
|
|
|
}
|
|
|
|
else
|
2009-09-24 17:08:55 -04:00
|
|
|
{ /* it is a directory */
|
2009-08-25 16:49:50 -04:00
|
|
|
QTreeWidgetItem *child;
|
|
|
|
if (item == NULL) {
|
|
|
|
child = new QTreeWidgetItem(ui.searchResultWidget);
|
|
|
|
} else {
|
|
|
|
child = new QTreeWidgetItem(item);
|
|
|
|
}
|
2010-02-06 20:37:06 -05:00
|
|
|
|
|
|
|
child->setIcon(SR_NAME_COL, QIcon(IMAGE_DIRECTORY));
|
2009-09-24 17:08:55 -04:00
|
|
|
child->setText(SR_NAME_COL, QString::fromUtf8(dir.name.c_str()));
|
2009-08-25 16:49:50 -04:00
|
|
|
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
2010-03-25 08:34:44 -04:00
|
|
|
child->setText(SR_SIZE_COL, misc::toQString(dir.count));
|
2009-09-24 19:18:25 -04:00
|
|
|
child->setText(SR_AGE_COL, misc::userFriendlyDuration(dir.age));
|
2009-08-25 16:49:50 -04:00
|
|
|
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
|
|
|
|
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
|
|
|
child->setText(SR_ID_COL, QString::number(1));
|
2010-02-14 20:09:23 -05:00
|
|
|
child->setTextAlignment( SR_ID_COL, Qt::AlignRight );
|
2009-09-24 17:08:55 -04:00
|
|
|
child->setText(SR_SEARCH_ID_COL, sid_hexa);
|
2010-02-06 20:37:06 -05:00
|
|
|
child->setText(SR_TYPE_COL, tr("Folder"));
|
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
|
|
|
|
if (item == NULL) {
|
|
|
|
ui.searchResultWidget->addTopLevelItem(child);
|
|
|
|
|
|
|
|
/* add to the summary as well */
|
|
|
|
|
|
|
|
int items = ui.searchSummaryWidget->topLevelItemCount();
|
|
|
|
bool found = false ;
|
|
|
|
|
|
|
|
for(int i = 0; i < items; i++)
|
|
|
|
{
|
2009-09-24 17:08:55 -04:00
|
|
|
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL) == sid_hexa)
|
2009-08-25 16:49:50 -04:00
|
|
|
{
|
|
|
|
// increment result since every item is new
|
|
|
|
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
|
|
|
|
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
|
|
|
|
found = true ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
|
|
|
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
|
|
|
item2->setText(SS_COUNT_COL, QString::number(1));
|
2010-02-14 20:09:23 -05:00
|
|
|
item2->setTextAlignment( SS_COUNT_COL, Qt::AlignRight );
|
2009-09-24 17:08:55 -04:00
|
|
|
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
2009-08-25 16:49:50 -04:00
|
|
|
|
|
|
|
ui.searchSummaryWidget->addTopLevelItem(item2);
|
|
|
|
ui.searchSummaryWidget->setCurrentItem(item2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* select this search result */
|
|
|
|
selectSearchResults();
|
|
|
|
} else {
|
|
|
|
item->addChild(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* go through all children directories/files for a recursive call */
|
|
|
|
for (std::list<DirStub>::const_iterator it(dir.children.begin()); it != dir.children.end(); it ++) {
|
|
|
|
DirDetails details;
|
|
|
|
rsFiles->RequestDirDetails(it->ref, details, 0);
|
|
|
|
insertDirectory(txt, searchId, details, child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-18 19:48:42 -05:00
|
|
|
void SearchDialog::insertDirectory(const std::string &txt, qulonglong searchId, const DirDetails &dir)
|
|
|
|
{
|
|
|
|
QString sid_hexa = QString::number(searchId,16) ;
|
|
|
|
QTreeWidgetItem *child = new QTreeWidgetItem(ui.searchResultWidget);
|
|
|
|
|
|
|
|
child->setIcon(SR_NAME_COL, QIcon(IMAGE_DIRECTORY));
|
|
|
|
child->setText(SR_NAME_COL, QString::fromUtf8(dir.name.c_str()));
|
|
|
|
child->setText(SR_HASH_COL, QString::fromStdString(dir.hash));
|
2010-03-25 08:34:44 -04:00
|
|
|
child->setText(SR_SIZE_COL, misc::toQString(dir.count));
|
2010-03-25 14:00:43 -04:00
|
|
|
child->setText(SR_AGE_COL, misc::userFriendlyDuration(dir.min_age));
|
2010-02-18 19:48:42 -05:00
|
|
|
child->setText(SR_REALSIZE_COL, QString::number(dir.count));
|
|
|
|
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
|
|
|
child->setText(SR_ID_COL, QString::number(1));
|
|
|
|
child->setTextAlignment( SR_ID_COL, Qt::AlignRight );
|
|
|
|
child->setText(SR_SEARCH_ID_COL, sid_hexa);
|
|
|
|
child->setText(SR_TYPE_COL, tr("Folder"));
|
|
|
|
|
|
|
|
ui.searchResultWidget->addTopLevelItem(child);
|
|
|
|
|
|
|
|
/* add to the summary as well */
|
|
|
|
|
|
|
|
int items = ui.searchSummaryWidget->topLevelItemCount();
|
|
|
|
bool found = false ;
|
|
|
|
|
|
|
|
for(int i = 0; i < items; i++)
|
|
|
|
{
|
|
|
|
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL) == sid_hexa)
|
|
|
|
{
|
|
|
|
// increment result since every item is new
|
|
|
|
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
|
|
|
|
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
|
|
|
|
found = true ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
|
|
|
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
|
|
|
item2->setText(SS_COUNT_COL, QString::number(1));
|
|
|
|
item2->setTextAlignment( SS_COUNT_COL, Qt::AlignRight );
|
|
|
|
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
|
|
|
|
|
|
|
ui.searchSummaryWidget->addTopLevelItem(item2);
|
|
|
|
ui.searchSummaryWidget->setCurrentItem(item2);
|
|
|
|
}
|
|
|
|
|
2010-02-21 08:38:27 -05:00
|
|
|
selectSearchResults();
|
2010-02-18 19:48:42 -05:00
|
|
|
// TODO: check for duplicate directories
|
|
|
|
}
|
|
|
|
|
2010-02-14 13:56:56 -05:00
|
|
|
void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const FileDetail& file, int searchType)
|
2009-08-16 16:10:53 -04:00
|
|
|
{
|
|
|
|
// algo:
|
|
|
|
//
|
2009-08-25 16:49:50 -04:00
|
|
|
// 1 - look in result window whether the file already exist.
|
|
|
|
// 1.1 - If yes, just increment the source number.
|
2009-08-16 16:10:53 -04:00
|
|
|
// 2.2 - Otherwize, add an entry.
|
|
|
|
// 2 - look in the summary whether there exist the same request id.
|
2009-08-25 16:49:50 -04:00
|
|
|
// 1.1 - If yes, just increment the result number.
|
2009-08-16 16:10:53 -04:00
|
|
|
// 2.2 - Otherwize, add an entry.
|
|
|
|
//
|
2010-02-27 15:29:28 -05:00
|
|
|
//
|
|
|
|
static std::map<qulonglong,uint32_t> nb_results ;
|
|
|
|
|
|
|
|
if(nb_results.find(searchId) == nb_results.end())
|
|
|
|
nb_results[searchId] = 0 ;
|
|
|
|
|
|
|
|
if(nb_results[searchId] >= ui._max_results_SB->value())
|
|
|
|
return ;
|
|
|
|
else
|
|
|
|
++nb_results[searchId] ;
|
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
// 1 - look in result window whether the file already exists.
|
2009-08-16 16:10:53 -04:00
|
|
|
//
|
|
|
|
int items = ui.searchResultWidget->topLevelItemCount();
|
|
|
|
bool found = false ;
|
2010-02-13 13:49:56 -05:00
|
|
|
int sources;
|
2010-02-14 13:56:56 -05:00
|
|
|
int friendSource = 0;
|
|
|
|
int anonymousSource = 0;
|
|
|
|
QString modifiedResult;
|
2009-08-16 16:10:53 -04:00
|
|
|
|
2009-09-24 17:08:55 -04:00
|
|
|
QString sid_hexa = QString::number(searchId,16) ;
|
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
for(int i = 0; i < items; i++)
|
|
|
|
if(ui.searchResultWidget->topLevelItem(i)->text(SR_HASH_COL) == QString::fromStdString(file.hash)
|
2009-09-24 17:08:55 -04:00
|
|
|
&& ui.searchResultWidget->topLevelItem(i)->text(SR_SEARCH_ID_COL) == sid_hexa)
|
2009-08-16 16:10:53 -04:00
|
|
|
{
|
2010-02-14 13:56:56 -05:00
|
|
|
QString resultCount = ui.searchResultWidget->topLevelItem(i)->text(SR_ID_COL);
|
|
|
|
QStringList modifiedResultCount = resultCount.split("/", QString::SkipEmptyParts);
|
|
|
|
if(searchType == FRIEND_SEARCH)
|
|
|
|
{
|
|
|
|
friendSource = modifiedResultCount.at(0).toInt() + 1;
|
|
|
|
anonymousSource = modifiedResultCount.at(1).toInt();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
friendSource = modifiedResultCount.at(0).toInt();
|
|
|
|
anonymousSource = modifiedResultCount.at(1).toInt() + 1;
|
|
|
|
}
|
|
|
|
anonymousSource = anonymousSource + friendSource;
|
|
|
|
modifiedResult = QString::number(friendSource) + tr("/") + QString::number(anonymousSource);
|
|
|
|
ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,modifiedResult);
|
2010-02-13 13:49:56 -05:00
|
|
|
QTreeWidgetItem *item = ui.searchResultWidget->topLevelItem(i);
|
2009-08-16 16:10:53 -04:00
|
|
|
found = true ;
|
2010-02-24 11:54:02 -05:00
|
|
|
int sources = friendSource + anonymousSource ;
|
2010-02-13 13:49:56 -05:00
|
|
|
if ( sources < 1)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 19)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 2)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 38)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 3)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 57)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 4)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 76)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 5)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 96)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 6)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 114)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 7)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 133)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 8)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 152)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 9)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 171)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 10)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 190)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 11)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 209)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( sources < 12)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 228)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 228)));
|
|
|
|
}
|
|
|
|
}
|
2009-09-24 17:08:55 -04:00
|
|
|
break ;
|
2009-08-16 16:10:53 -04:00
|
|
|
}
|
2009-08-25 16:49:50 -04:00
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
if(!found)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-08-16 16:10:53 -04:00
|
|
|
/* translate search results */
|
2010-02-06 20:37:06 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
2009-09-24 17:08:55 -04:00
|
|
|
item->setText(SR_NAME_COL, QString::fromUtf8(file.name.c_str()));
|
2009-08-16 16:10:53 -04:00
|
|
|
item->setText(SR_HASH_COL, QString::fromStdString(file.hash));
|
2008-11-18 15:29:40 -05:00
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
QString ext = QFileInfo(QString::fromStdString(file.name)).suffix();
|
2009-08-25 16:49:50 -04:00
|
|
|
setIconAndType(item, ext);
|
2008-11-18 15:29:40 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/*
|
|
|
|
* to facilitate downlaods we need to save the file size too
|
|
|
|
*/
|
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
item->setText(SR_SIZE_COL, misc::friendlyUnit(file.size));
|
|
|
|
item->setText(SR_REALSIZE_COL, QString::number(file.size));
|
2009-09-24 19:18:25 -04:00
|
|
|
item->setText(SR_AGE_COL, misc::userFriendlyDuration(file.age));
|
2009-08-16 16:10:53 -04:00
|
|
|
item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
|
2010-02-14 13:56:56 -05:00
|
|
|
if(searchType == FRIEND_SEARCH)
|
|
|
|
{
|
|
|
|
friendSource = 1;
|
|
|
|
anonymousSource = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
friendSource = 0;
|
|
|
|
anonymousSource = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
anonymousSource = anonymousSource + friendSource;
|
|
|
|
modifiedResult =QString::number(friendSource) + tr("/") + QString::number(anonymousSource);
|
|
|
|
item->setText(SR_ID_COL,modifiedResult);
|
2010-02-14 20:09:23 -05:00
|
|
|
item->setTextAlignment( SR_ID_COL, Qt::AlignRight );
|
2009-09-24 17:08:55 -04:00
|
|
|
item->setText(SR_SEARCH_ID_COL, sid_hexa);
|
2010-02-13 13:49:56 -05:00
|
|
|
|
|
|
|
|
|
|
|
sources = item->text(SR_ID_COL).toInt();
|
|
|
|
if ( sources == 1)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 7; i++)
|
|
|
|
{
|
|
|
|
item->setForeground(i,QBrush( QColor(0, 0, 0)));
|
|
|
|
}
|
|
|
|
}
|
2008-08-31 12:50:36 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
ui.searchResultWidget->addTopLevelItem(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add to the summary as well */
|
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
int items2 = ui.searchSummaryWidget->topLevelItemCount();
|
|
|
|
bool found2 = false ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
for(int i = 0; i < items2; i++)
|
2009-09-24 17:08:55 -04:00
|
|
|
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL) == sid_hexa)
|
2009-08-16 16:10:53 -04:00
|
|
|
{
|
|
|
|
if(!found) // only increment result when it's a new item.
|
|
|
|
{
|
|
|
|
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ;
|
|
|
|
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1));
|
|
|
|
}
|
|
|
|
found2 = true ;
|
2009-09-24 17:08:55 -04:00
|
|
|
break ;
|
2009-08-16 16:10:53 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
if(!found2)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem *item2 = new QTreeWidgetItem();
|
|
|
|
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
|
|
|
|
item2->setText(SS_COUNT_COL, QString::number(1));
|
2010-02-14 20:09:23 -05:00
|
|
|
item2->setTextAlignment( SS_COUNT_COL, Qt::AlignRight );
|
2009-09-24 17:08:55 -04:00
|
|
|
item2->setText(SS_SEARCH_ID_COL, sid_hexa);
|
2009-08-16 16:10:53 -04:00
|
|
|
|
|
|
|
ui.searchSummaryWidget->addTopLevelItem(item2);
|
|
|
|
ui.searchSummaryWidget->setCurrentItem(item2);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* select this search result */
|
|
|
|
selectSearchResults();
|
|
|
|
}
|
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
void SearchDialog::resultsToTree(std::string txt,qulonglong searchId, const std::list<DirDetails>& results)
|
2009-08-16 16:10:53 -04:00
|
|
|
{
|
2009-08-25 16:49:50 -04:00
|
|
|
ui.searchResultWidget->setSortingEnabled(false);
|
|
|
|
|
2009-08-16 16:10:53 -04:00
|
|
|
/* translate search results */
|
|
|
|
std::ostringstream out;
|
|
|
|
out << searchId;
|
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
std::list<DirDetails>::const_iterator it;
|
2009-08-16 16:10:53 -04:00
|
|
|
for(it = results.begin(); it != results.end(); it++)
|
2009-08-25 16:49:50 -04:00
|
|
|
if (it->type == DIR_TYPE_FILE) {
|
|
|
|
FileDetail fd;
|
|
|
|
fd.id = it->id;
|
|
|
|
fd.name = it->name;
|
|
|
|
fd.hash = it->hash;
|
|
|
|
fd.path = it->path;
|
|
|
|
fd.size = it->count;
|
|
|
|
fd.age = it->age;
|
|
|
|
fd.rank = 0;
|
|
|
|
|
2010-02-14 13:56:56 -05:00
|
|
|
insertFile(txt,searchId,fd, FRIEND_SEARCH);
|
2009-08-25 16:49:50 -04:00
|
|
|
} else if (it->type == DIR_TYPE_DIR) {
|
2010-02-18 19:48:42 -05:00
|
|
|
// insertDirectory(txt, searchId, *it, NULL);
|
|
|
|
insertDirectory(txt, searchId, *it);
|
2009-08-25 16:49:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ui.searchResultWidget->setSortingEnabled(true);
|
2009-08-16 16:10:53 -04:00
|
|
|
}
|
|
|
|
|
2010-02-21 08:38:27 -05:00
|
|
|
void SearchDialog::selectSearchResults(int index)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-02-22 16:44:43 -05:00
|
|
|
int cindex = ui.FileTypeComboBox->currentIndex();
|
|
|
|
index = (index == -1) ? (cindex == -1 ? 0 : cindex):index;
|
2010-02-21 08:38:27 -05:00
|
|
|
QString alltypes = FileTypeExtensionMap->value(index);
|
|
|
|
QStringList types = alltypes.split(" ");
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* highlight this search in summary window */
|
|
|
|
QTreeWidgetItem *ci = ui.searchSummaryWidget->currentItem();
|
|
|
|
if (!ci)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* get the searchId text */
|
|
|
|
QString searchId = ci->text(SS_SEARCH_ID_COL);
|
2010-02-14 10:50:38 -05:00
|
|
|
#ifdef DEBUG
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "SearchDialog::selectSearchResults(): searchId: " << searchId.toStdString();
|
|
|
|
std::cerr << std::endl;
|
2010-02-14 10:50:38 -05:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* show only matching searchIds in main window */
|
|
|
|
int items = ui.searchResultWidget->topLevelItemCount();
|
|
|
|
for(int i = 0; i < items; i++)
|
|
|
|
{
|
|
|
|
/* get item */
|
|
|
|
QTreeWidgetItem *ti = ui.searchResultWidget->topLevelItem(i);
|
|
|
|
if (ti->text(SR_SEARCH_ID_COL) == searchId)
|
2010-02-21 08:38:27 -05:00
|
|
|
{
|
|
|
|
if (index == FILETYPE_IDX_ANY)
|
|
|
|
ti->setHidden(false);
|
|
|
|
else if (index == FILETYPE_IDX_DIRECTORY && ti->text(SR_HASH_COL).isEmpty())
|
|
|
|
ti->setHidden(false);
|
|
|
|
else if (types.contains(QFileInfo(ti->text(SR_NAME_COL)).suffix(), Qt::CaseInsensitive))
|
|
|
|
ti->setHidden(false);
|
|
|
|
else
|
|
|
|
ti->setHidden(true);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ti->setHidden(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui.searchResultWidget->update();
|
|
|
|
}
|
|
|
|
|
2009-08-25 16:49:50 -04:00
|
|
|
void SearchDialog::setIconAndType(QTreeWidgetItem *item, QString &ext)
|
|
|
|
{
|
2010-01-27 15:16:33 -05:00
|
|
|
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico"
|
|
|
|
|| ext == "svg" || ext == "tif" || ext == "tiff" || ext == "JPG")
|
2009-08-25 16:49:50 -04:00
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypePicture.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Picture"));
|
|
|
|
}
|
2010-01-27 15:16:33 -05:00
|
|
|
else if (ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "wmv" || ext == "mkv" || ext == "mp4"
|
|
|
|
|| ext == "flv" || ext == "mov" || ext == "vob" || ext == "qt" || ext == "rm" || ext == "3gp"
|
|
|
|
|| ext == "dvx" || ext == "divx")
|
2009-08-25 16:49:50 -04:00
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeVideo.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Video"));
|
|
|
|
}
|
2010-01-27 15:16:33 -05:00
|
|
|
else if (ext == "ogg" || ext == "mp3" || ext == "MP3" || ext == "mp1" || ext == "mp2" || ext == "wav" || ext == "wma")
|
2009-08-25 16:49:50 -04:00
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeAudio.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Audio"));
|
|
|
|
}
|
2010-01-27 15:16:33 -05:00
|
|
|
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "tgz" || ext == "gz" || ext == "rar"
|
|
|
|
|| ext == "rpm" || ext == "7z" || ext == "ace" || ext == "jar" || ext == "cab" || ext == "deb")
|
2009-08-25 16:49:50 -04:00
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeArchive.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Archive"));
|
|
|
|
}
|
2010-02-14 20:09:23 -05:00
|
|
|
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com" || ext == "bin" || ext == "exe" || ext == "js"
|
2010-02-15 12:29:13 -05:00
|
|
|
|| ext == "msi" ||ext == "pif" || ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
|
2009-08-25 16:49:50 -04:00
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeProgram.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Program"));
|
|
|
|
}
|
2010-02-15 12:29:13 -05:00
|
|
|
else if (ext == "iso" || ext == "nrg" || ext == "mdf" || ext == "img" || ext == "dmg" || ext == "bin" || ext == "uif" )
|
2009-08-25 16:49:50 -04:00
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeCDImage.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("CD-Image"));
|
|
|
|
}
|
|
|
|
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
|
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeDocument.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
|
|
|
}
|
2010-02-15 09:52:47 -05:00
|
|
|
else if (ext == "pdf" )
|
|
|
|
{
|
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/mimetypes/pdf.png"));
|
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
|
|
|
}
|
2010-02-14 20:09:23 -05:00
|
|
|
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls" || ext == "pps" || ext == "xml" || ext == "nfo"
|
|
|
|
|| ext == "reg" || ext == "sxc" || ext == "odt" || ext == "ods" || ext == "dot" || ext == "ppt" || ext == "css" || ext == "crt" )
|
2009-08-25 16:49:50 -04:00
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeDocument.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
|
|
|
}
|
|
|
|
else if (ext == "html" || ext == "htm" || ext == "php")
|
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeDocument.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
|
|
|
|
}
|
2010-03-04 07:09:43 -05:00
|
|
|
else if (ext == "sub" || ext == "srt")
|
|
|
|
{
|
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeAny.png"));
|
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Subtitles"));
|
|
|
|
}
|
|
|
|
else if (ext == "nds")
|
|
|
|
{
|
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeAny.png"));
|
|
|
|
item->setText(SR_TYPE_COL, QString::fromUtf8("Nintendo DS Rom"));
|
|
|
|
}
|
2009-08-25 16:49:50 -04:00
|
|
|
else
|
|
|
|
{
|
2010-02-06 20:37:06 -05:00
|
|
|
item->setIcon(SR_NAME_COL, QIcon(":/images/FileTypeAny.png"));
|
2009-08-25 16:49:50 -04:00
|
|
|
}
|
|
|
|
}
|
2010-01-21 17:34:10 -05:00
|
|
|
|
|
|
|
void SearchDialog::copysearchLink()
|
|
|
|
{
|
|
|
|
/* should also be able to handle multi-selection */
|
|
|
|
QList<QTreeWidgetItem*> itemsForCopy = ui.searchResultWidget->selectedItems();
|
|
|
|
int numdls = itemsForCopy.size();
|
|
|
|
QTreeWidgetItem * item;
|
|
|
|
|
2010-03-15 08:57:08 -04:00
|
|
|
std::vector<RetroShareLink> urls ;
|
2010-03-10 18:09:35 -05:00
|
|
|
|
2010-01-21 17:34:10 -05:00
|
|
|
for (int i = 0; i < numdls; ++i)
|
2010-03-10 18:09:35 -05:00
|
|
|
{
|
|
|
|
item = itemsForCopy.at(i);
|
|
|
|
// call copy
|
2010-01-21 17:34:10 -05:00
|
|
|
|
2010-03-10 18:09:35 -05:00
|
|
|
if (!item->childCount())
|
|
|
|
{
|
|
|
|
std::cerr << "SearchDialog::copysearchLink() Calling set retroshare link";
|
|
|
|
std::cerr << std::endl;
|
2010-03-10 16:38:26 -05:00
|
|
|
|
2010-03-10 18:09:35 -05:00
|
|
|
QString fhash = item->text(SR_HASH_COL);
|
|
|
|
qulonglong fsize = item->text(SR_REALSIZE_COL).toULongLong();
|
|
|
|
QString fname = item->text(SR_NAME_COL);
|
2010-01-21 17:34:10 -05:00
|
|
|
|
2010-03-10 18:09:35 -05:00
|
|
|
RetroShareLink link(fname, fsize, fhash);
|
2010-01-21 17:34:10 -05:00
|
|
|
|
2010-03-17 11:34:36 -04:00
|
|
|
std::cerr << "new link added to clipboard: " << link.toString().toStdString() << std::endl ;
|
2010-03-10 18:09:35 -05:00
|
|
|
if(link.valid())
|
2010-03-15 08:57:08 -04:00
|
|
|
urls.push_back(link) ;
|
2010-03-10 18:09:35 -05:00
|
|
|
}
|
|
|
|
}
|
2010-03-15 08:57:08 -04:00
|
|
|
RSLinkClipboard::copyLinks(urls) ;
|
2010-01-21 17:34:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void SearchDialog::sendLinkTo( )
|
|
|
|
{
|
|
|
|
copysearchLink();
|
|
|
|
|
|
|
|
/* create a message */
|
|
|
|
ChanMsgDialog *nMsgDialog = new ChanMsgDialog(true);
|
|
|
|
|
|
|
|
nMsgDialog->newMsg();
|
|
|
|
nMsgDialog->insertTitleText("New RetroShare Link(s)");
|
|
|
|
|
2010-03-15 08:57:08 -04:00
|
|
|
nMsgDialog->insertMsgText(RSLinkClipboard::toHtml().toStdString()) ;
|
2010-01-21 17:34:10 -05:00
|
|
|
nMsgDialog->show();
|
|
|
|
}
|
2010-02-13 21:31:37 -05:00
|
|
|
|
|
|
|
void SearchDialog::togglereset()
|
|
|
|
{
|
|
|
|
QString text = ui.lineEdit->text();
|
|
|
|
|
|
|
|
if (text.isEmpty())
|
|
|
|
{
|
|
|
|
ui.resetButton->hide();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui.resetButton->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-02-18 19:48:42 -05:00
|
|
|
|
2010-02-21 08:38:27 -05:00
|
|
|
// not in use for the moment
|
2010-02-18 19:48:42 -05:00
|
|
|
void SearchDialog::onComboIndexChanged(int index)
|
|
|
|
{
|
|
|
|
if (!FileTypeExtensionMap->contains(index) && index != FILETYPE_IDX_DIRECTORY)
|
|
|
|
return;
|
|
|
|
QString alltypes = FileTypeExtensionMap->value(index);
|
|
|
|
QStringList types = alltypes.split(" ");
|
|
|
|
int items = ui.searchResultWidget->topLevelItemCount();
|
|
|
|
for (int i = 0; i < items; i++) {
|
|
|
|
QTreeWidgetItem *ti = ui.searchResultWidget->topLevelItem(i);
|
|
|
|
QString name = ti->text(SR_NAME_COL);
|
|
|
|
|
|
|
|
if (index == FILETYPE_IDX_ANY) {
|
|
|
|
if (ti->isHidden()) {
|
|
|
|
QTreeWidgetItem *ci = ui.searchSummaryWidget->currentItem();
|
|
|
|
if (!ci) {
|
|
|
|
ti->setHidden(false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ti->text(SR_SEARCH_ID_COL) == ci->text(SS_SEARCH_ID_COL)) {
|
|
|
|
ti->setHidden(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (index == FILETYPE_IDX_DIRECTORY) {
|
|
|
|
if (ti->text(SR_HASH_COL).isEmpty()) {
|
|
|
|
if (ti->isHidden()) {
|
|
|
|
QTreeWidgetItem *ci = ui.searchSummaryWidget->currentItem();
|
|
|
|
if (!ci) {
|
|
|
|
ti->setHidden(false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ti->text(SR_SEARCH_ID_COL) == ci->text(SS_SEARCH_ID_COL)) {
|
|
|
|
ti->setHidden(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ti->setHidden(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (name.lastIndexOf(".") >= 0) {
|
|
|
|
QString ext = name.mid(name.lastIndexOf(".") + 1);
|
|
|
|
if (!ext.isEmpty() && types.contains(ext, Qt::CaseInsensitive)) {
|
|
|
|
if (ti->isHidden()) {
|
|
|
|
QTreeWidgetItem *ci = ui.searchSummaryWidget->currentItem();
|
|
|
|
if (!ci) {
|
|
|
|
ti->setHidden(false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ti->text(SR_SEARCH_ID_COL) == ci->text(SS_SEARCH_ID_COL)) {
|
|
|
|
ti->setHidden(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ti->setHidden(true);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ti->setHidden(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|