/* Copyright 2003 Rikard Björklind, Mikael Gransell This file is part of dc-qt. dc-qt 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. dc-qt 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 dc-qt; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include "searchdlg.h" #include "debugdlg.h" #include "filetree.h" #include "searchwdgt.h" #include "util.h" #include "filelistitem.h" #include "dc_settings.h" #include "FileExistsDlg.h" using namespace std; SearchDlg::SearchDlg( QWidget* parent, const char* name ) : QDialog( parent, name ) { int defaultWidth = 600; // load window pos and size wnd_setting wndset(settings.get_setting("wndset_search")); if (wndset.isValid()) { move(QPoint(wndset.x(), wndset.y())); resize(wndset.w(), wndset.h()); } else resize(defaultWidth,400); // setWFlags( WType_TopLevel /*WStyle_Customize | WStyle_MinMax*/ ); QGridLayout* layout = new QGridLayout( this, 2, 1 ); tabs = new QTabWidget( this, "Search tabs" ); // Create the listviews fileList = new QListView( tabs, "Search List" ); fileList->addColumn( "User"); fileList->addColumn( "Name",(int)(0.5*defaultWidth)); fileList->addColumn( "Size"); fileList->addColumn( "Slots"); fileList->addColumn( "Path"); fileList->setAllColumnsShowFocus(true); fileList->setSelectionMode( QListView::Extended); fileList->setShowSortIndicator(true); //fileList->setResizeMode(QListView::AllColumns); fileList->setHScrollBarMode(QScrollView::AlwaysOff); tree = new FileTree( tabs, "Search Tree" ); // load list column-widths intlist_setting wl_flist(settings.get_setting("widthlist_searchdlg_lv_filelist")); set_lv_widths(fileList, wl_flist); intlist_setting wl_ftree(settings.get_setting("widthlist_searchdlg_lv_filetree")); set_lv_widths(tree, wl_ftree); // Add the lists to our tabwidget tabs->addTab( fileList, "List view" ); tabs->addTab( tree, "Tree view" ); layout->addWidget( tabs, 1, 0 ); // Create the search widget searchWdgt = new SearchWdgt( this, "Search Widget" ); searchWdgt->setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Minimum) ); QObject::connect(searchWdgt,SIGNAL(newSearch(const QString&, bool)),this,SLOT(newSearch(const QString&,bool))); layout->addWidget( searchWdgt, 0, 0 ); connect(fileList, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(downloadFile(QListViewItem*))); connect(fileList, SIGNAL(contextMenuRequested ( QListViewItem*, const QPoint& , int )), this, SLOT(dispMenu(QListViewItem* , const QPoint& , int ))); connect(tree, SIGNAL(downloadFile( const QString&, const QString&, const QString&, unsigned long int)), this, SIGNAL(downloadFile( const QString&, const QString&, const QString&, unsigned long int))); connect(tree, SIGNAL(getUserFileList( const QString& )), this, SIGNAL(getUserFiles( const QString& ))); menu = new QPopupMenu(this, "user_lv_menu"); menu->insertItem( "Download File", this, SLOT(downloadFile()),0,0,0 ); menu->insertItem( "Download File to...", this, SLOT(downloadFileTo()),0,1,1 ); menu->insertItem( "Download Directory", this, SLOT(downloadDirectory()),0,2,2 ); menu->insertItem( "Download Directory to...", this, SLOT(downloadDirectoryTo()),0,3,3 ); menu->insertSeparator(4); menu->insertItem( "Get File List", this, SLOT(getUserFiles()),0,4,5 ); // menu->setItemEnabled(1,false); } void SearchDlg::closeEvent(QCloseEvent * e) { // save window position and size wnd_setting wndset(x(), y(), width(), height()); if (wndset.isValid()) { settings.set_setting("common","wndset_search", wndset.toString()); } // save listviews column widths intlist_setting wl_flist, wl_ftree; get_lv_widths(fileList, &wl_flist); get_lv_widths(tree, &wl_ftree); settings.set_setting("common","widthlist_searchdlg_lv_filelist", wl_flist.toString()); settings.set_setting("common","widthlist_searchdlg_lv_filetree", wl_ftree.toString()); e->accept(); } void SearchDlg::newSearch(const QString& s,bool multiHub) { multiSearch = multiHub; fileList->clear(); tree->clear(); emit search( s, multiHub ); } void SearchDlg::addSearchResult( const QString& user, const QString& file, const QString& size, const QString& slot ) { // Split file into path / name QString fileName = file.section('\\',-1,-1); QString path = file.section('\\',0,-2); fileList->insertItem( new FileListItem( fileList, user, fileName, size, slot, path ) ); tree->addItemToTree( user, file, size, slot ); } /// Called when downloading from the listview void SearchDlg::downloadFile( QListViewItem* item ) { FileListItem *i = (FileListItem*)item; QString localfile = checkFile( i->text(4) + "\\" + i->text(1),i->Size() ); if( !localfile.isEmpty() ) { QString user = i->text( 0 ); emit downloadFile( user, i->text(4) + "\\" + i->text(1), localfile , i->Size()); } } /// Called when downloading a directory from the listview void SearchDlg::downloadDirectory() { FileListItem *item = (FileListItem *)fileList->currentItem(); if( item ) { QString nick = item->text(0); QString dir = item->text(4); QString subdir = dir.section( '\\', -1,-1 ); if (subdir.isEmpty()) subdir = dir.section( '/', -1,-1 ); if (subdir.isEmpty()) subdir = dir; item = (FileListItem *)fileList->firstChild(); while(item) { if(item->text(0) == nick && item->text(4) == dir) { QString file = item->text(4) + "\\" + item->text(1); QString localfile = checkFile(file,item->Size()); // Dir and nick matches the clicked item, get this file emit downloadFile( nick, file, subdir+"/"+localfile, item->Size()); } item = (FileListItem *)item->itemBelow(); } } } void SearchDlg::downloadFile() { QListViewItemIterator it( fileList ); while ( it.current() ) { if ( it.current()->isSelected() ) { FileListItem *item = (FileListItem*)it.current(); QString localfile = checkFile( item->text(4) + "\\" + item->text(1),item->Size() ); if( !localfile.isEmpty() ) { QString user = item->text( 0 ); QString file = item->text(4) + "\\" + item->text( 1 ); QString size = item->text( 2 ); emit downloadFile( user, file, localfile, item->Size() ); } } ++it; } } // The following two methods are Called when downloading TO a directory void SearchDlg::downloadDirectoryTo() { QString tgt_dir = selectDlDirDlg(); FileListItem *item = (FileListItem *)fileList->currentItem(); if( item ) { QString nick = item->text(0); QString dir = item->text(4); QString subdir = dir.section( '\\', -1,-1 ); if (subdir.isEmpty()) subdir = dir.section( '/', -1,-1 ); if (subdir.isEmpty()) subdir = dir; item = (FileListItem *)fileList->firstChild(); while(item) { if(item->text(0) == nick && item->text(4) == dir) { QString file = item->text(4) + "\\" + item->text( 1 ); QString localfile = checkFile(file,item->Size()); // Dir and nick matches the clicked item, get this file emit downloadFile( nick, file, tgt_dir+subdir+'/'+localfile, item->Size()); } item = (FileListItem *)item->itemBelow(); } } } void SearchDlg::downloadFileTo() { QString tgt_dir = selectDlDirDlg(); QListViewItemIterator it( fileList ); while ( it.current() ) { if ( it.current()->isSelected() ) { FileListItem *item = (FileListItem*)it.current(); QString localfile = checkFile( item->text(4) + "\\" + item->text(1),item->Size() ); if( !localfile.isEmpty() ) { QString user = item->text( 0 ); QString file = item->text(4) + "\\" + item->text( 1 ); QString size = item->text( 2 ); emit downloadFile( user, file, tgt_dir+localfile, item->Size() ); } } ++it; } } /////////// void SearchDlg::dispMenu( QListViewItem* item, const QPoint& p, int column ) { if( !item ) // We didn't click an item but somewhere else in the list return; // Popup the menu menu->popup( p ); } void SearchDlg::getUserFiles() { QListViewItem* item = fileList->currentItem(); if( item ) { QString user = item->text( 0 ); emit getUserFiles( user ); } } /* * * $Log: searchdlg.cc,v $ * Revision 1.16 2004/03/17 16:43:02 olof * connection profiles * * Revision 1.15 2004/03/01 02:18:26 estrato * Finished rewriting settings code * * Revision 1.14 2004/02/29 22:40:25 olof * dslkjfhsldhl * not working * * Revision 1.13 2004/02/26 22:31:55 estrato * saving more layout info * * Revision 1.12 2004/02/26 12:36:11 estrato * resuming aborted downloads, saving window pos and size * * Revision 1.11 2004/02/23 20:37:09 olof * Userinfo popup * * Revision 1.10 2004/02/18 18:21:08 estrato * Remember alternative dl path, bugfixes * * Revision 1.9 2004/02/18 07:58:42 estrato * download to dir, resume download, bugfixes * * Revision 1.8 2003/12/11 22:11:27 olof * some fixes * * Revision 1.6 2003/08/22 16:45:20 olof * hola * * Revision 1.5 2003/08/18 12:19:43 estrato * Old transfer dialog now completely replaced, but some functionality is gone. Will add complete functionality in next commit. * * Revision 1.4 2003/07/29 17:47:00 olof * stuff * * Revision 1.3 2003/06/26 12:26:00 olof * multi source downloads * * Revision 1.2 2003/06/24 17:00:05 olof * multischeiss * * Revision 1.1.1.1 2003/06/24 10:16:17 olof * remake of cvs tree * * Revision 1.11 2003/06/16 19:48:25 olof * multihub search and password * * Revision 1.10 2003/06/16 12:18:12 olof * loads * * Revision 1.9 2003/06/11 22:14:21 olof * transfers ok again * * Revision 1.8 2003/06/06 11:34:11 olof * mu * * Revision 1.7 2003/05/08 12:34:14 olof * GPL header added * * Revision 1.6 2003/05/07 10:17:00 olof * listview fixes * * Revision 1.5 2003/05/07 00:11:54 olof * massa mandelmassa * * Revision 1.4 2003/04/16 20:54:47 olof * user file list fixed * * Revision 1.3 2003/03/18 14:27:29 mickeg * Filetree working * Hopefully the userfilelisting also works. * * Revision 1.2 2003/03/16 21:00:49 mickeg * Added functionality for the tree view of the search results * Still some bugs * Doesn't iterate through the children accurately * * Revision 1.1 2003/03/04 22:10:40 olof * dcqt2 creation * * Revision 1.4 2003/02/23 16:54:49 ribj4077 * Added some features * * Revision 1.3 2003/02/18 15:47:33 migr8915 * Bastard rightclick signal not working * Should be able to download by doubleclicking item * * */