- Added a parent page widget (class RsAutoUpdatePage) to handle auto-update. The page updates using a timer, only wh

en visible, and each time it gets showed. I already made some RS pages derive from this page.
- Modified and renamed the taskGraphPainterWidget to display info about currently selected file transfers. For know, it only shows file chunks info, but we should use it to display additional info about the transfer. Warning: in its
 current state, only fake chunk info is displayed.
 - Suppressed p3files.h, because it is not used.

 Remains to do (in order):
 - Implement a chunk map class in ft/ to properly manage which chunks should be downloaded 
 - Display correct chunk info by requesting the transfer's chunk map
 - Add check-sum verification of chunks
 - allow RS to import a partially downloaded file by force re-checking chunks
 - Add chunk map exchange from file source peer id to file destination peer id.
 - Manage chunks from different peers.
 - Allow search (turtle search) for partially downloaded files 



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1832 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2009-11-17 12:45:06 +00:00
parent 36c2a726fa
commit 506f14eb2f
28 changed files with 368 additions and 1215 deletions

View File

@ -305,6 +305,21 @@ void ftServer::getDwlDetails(std::list<DwlDetails> & details)
mFtDwlQueue->getDwlDetails(details);
}
bool ftServer::FileChunksDetails(const std::string& hash,FileChunksInfo& info)
{
// for know put some dummy info. It's for display sake only.
info.chunk_size = 1024*1024 ;
info.file_size = 250*info.chunk_size - 123 ; // last chunk is not complete.
info.chunks.resize(250,FileChunksInfo::CHUNK_DONE) ;
int n = rand()%150 + 50 ;
for(int i=0;i<10;++i)
info.chunks[n+i] = FileChunksInfo::CHUNK_ACTIVE ;
for(int i=n+10;i<250;++i)
info.chunks[i] = FileChunksInfo::CHUNK_OUTSTANDING ;
return true ;
}
/* Directory Handling */
void ftServer::setDownloadDirectory(std::string path)
{

View File

@ -137,6 +137,7 @@ virtual void getDwlDetails(std::list<DwlDetails> & details);
virtual bool FileDownloads(std::list<std::string> &hashs);
virtual bool FileUploads(std::list<std::string> &hashs);
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
virtual bool FileChunksDetails(const std::string& hash,FileChunksInfo& info) ;
/***
* Extra List Access

View File

@ -128,6 +128,7 @@ virtual void getDwlDetails(std::list<DwlDetails> & details) = 0;
virtual bool FileDownloads(std::list<std::string> &hashs) = 0;
virtual bool FileUploads(std::list<std::string> &hashs) = 0;
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info) = 0;
virtual bool FileChunksDetails(const std::string& hash,FileChunksInfo& info) = 0 ;
/***
* Extra List Access

View File

@ -208,7 +208,7 @@ class NotifyBase
virtual void notifyOwnAvatarChanged() {}
virtual void notifyOwnStatusMessageChanged() {}
virtual std::string askForPassword(const std::string& window_title,const std::string& text) {}
virtual std::string askForPassword(const std::string& window_title,const std::string& text) { return "" ;}
};
const int NOTIFY_LIST_NEIGHBOURS = 1;

View File

@ -132,6 +132,7 @@ virtual bool getOthersList(std::list<std::string> &ids) = 0;
virtual bool isOnline(std::string id) = 0;
virtual bool isFriend(std::string id) = 0;
virtual std::string getPeerName(std::string id) = 0;
virtual std::string getPeerPGPName(std::string pgp_id) = 0;
virtual bool getPeerDetails(std::string id, RsPeerDetails &d) = 0;
/* Using PGP Ids */

View File

@ -28,6 +28,7 @@
#include <list>
#include <vector>
#include <iostream>
#include <string>
#include <stdint.h>
@ -247,6 +248,16 @@ class FileDetail
enum DwlPriority { Low = 0, Normal, High, Auto };
class FileChunksInfo
{
public:
enum ChunkState { CHUNK_DONE, CHUNK_ACTIVE, CHUNK_OUTSTANDING } ;
uint64_t file_size ; // real size of the file
uint32_t chunk_size ; // size of chunks
std::vector<ChunkState> chunks ; // dl state of chunks. Only the last chunk may have size < chunk_size
};
/* class which encapsulates download details */
class DwlDetails {
public:

View File

@ -1,119 +0,0 @@
#ifndef P3_FILES_TMP_INTERFACE_H
#define P3_FILES_TMP_INTERFACE_H
/*
* libretroshare/src/rsserver: p3files.h
*
* RetroShare C++ Interface.
*
* Copyright 2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include <map>
#include <list>
#include <iostream>
#include <string>
#include "rsiface/rsfiles.h"
#include "util/rsthreads.h"
class filedexserver;
class RsServer;
class p3AuthMgr;
class p3Files: public RsFiles
{
public:
p3Files(filedexserver *s, RsServer *c, p3AuthMgr *a)
:mServer(s), mCore(c), mAuthMgr(a) { return; }
virtual ~p3Files() { return; }
/****************************************/
/* 1) Access to downloading / uploading files. */
virtual bool FileDownloads(std::list<std::string> &hashs);
virtual bool FileUploads(std::list<std::string> &hashs);
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info);
/* 2) Control of Downloads. */
virtual bool FileRequest(std::string fname, std::string hash, uint64_t size,
std::string dest, uint32_t flags,
std::list<std::string> srcIds);
virtual bool FileCancel(std::string hash);
virtual bool FileControl(std::string hash, uint32_t flags);
virtual bool FileClearCompleted();
/* 3) Addition of Extra Files... From File System */
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
uint32_t period, uint32_t flags);
virtual bool ExtraFileRemove(std::string hash, uint32_t flags);
virtual bool ExtraFileHash(std::string localpath,
uint32_t period, uint32_t flags);
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info);
/* 4) Search and Listing Interface */
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details);
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags);
virtual int SearchKeywords(std::list<std::string> keywords, std::list<FileDetail> &results);
virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results);
/* 5) Utility Functions. */
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
virtual void ForceDirectoryCheck();
virtual bool InDirectoryCheck();
virtual void setDownloadDirectory(std::string path);
virtual void setPartialsDirectory(std::string path);
virtual std::string getDownloadDirectory();
virtual std::string getPartialsDirectory();
virtual bool getSharedDirectories(std::list<std::string> &dirs);
virtual bool addSharedDirectory(std::string dir);
virtual bool removeSharedDirectory(std::string dir);
/* Update functions! */
int UpdateAllTransfers();
private:
void lockRsCore();
void unlockRsCore();
filedexserver *mServer;
RsServer *mCore;
p3AuthMgr *mAuthMgr;
RsMutex fMutex;
std::map<std::string, FileInfo> mTransfers;
};
#endif

View File

@ -465,6 +465,12 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
}
std::string p3Peers::getPeerPGPName(std::string id)
{
/* get from mAuthMgr as it should have more peers? */
return mAuthMgr->getIssuerName(id);
}
std::string p3Peers::getPeerName(std::string id)
{
#ifdef P3PEERS_DEBUG

View File

@ -50,6 +50,7 @@ virtual bool getOthersList(std::list<std::string> &ids);
virtual bool isOnline(std::string id);
virtual bool isFriend(std::string id);
virtual std::string getPeerPGPName(std::string pgp_id);
virtual std::string getPeerName(std::string id);
virtual bool getPeerDetails(std::string id, RsPeerDetails &d);

View File

@ -1,4 +1,4 @@
CONFIG += qt gui uic qrc resources uitools pluginmgr newsettings release
CONFIG += qt gui uic qrc resources uitools pluginmgr newsettings
QT += network xml script opengl
TEMPLATE = app
TARGET = RetroShare
@ -159,7 +159,8 @@ HEADERS += rshare.h \
gui/ShareManager.h \
gui/StatisticDialog.h \
gui/SoundManager.h \
gui/taskGraphPainterWidget.h \
gui/FileTransferInfoWidget.h \
gui/RsAutoUpdatePage.h \
gui/HelpDialog.h \
gui/InfoDialog.h \
gui/LogoBar.h \
@ -368,6 +369,7 @@ SOURCES += main.cpp \
gui/MessengerWindow.cpp \
gui/PeersDialog.cpp \
gui/RemoteDirModel.cpp \
gui/RsAutoUpdatePage.cpp \
gui/RetroShareLinkAnalyzer.cpp \
gui/SearchTreeWidget.cpp \
gui/SearchDialog.cpp \
@ -377,7 +379,7 @@ SOURCES += main.cpp \
gui/StatisticDialog.cpp \
gui/SoundManager.cpp \
gui/MessagesDialog.cpp \
gui/taskGraphPainterWidget.cpp \
gui/FileTransferInfoWidget.cpp \
gui/MessagesPopupDialog.cpp \
gui/im_history/IMHistoryKeeper.cpp \
gui/im_history/IMHistoryReader.cpp \

View File

@ -0,0 +1,129 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2009, defnax
* Copyright (c) 2009, lsn752
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QStylePainter>
#include <QDebug>
#include <rsiface/rsfiles.h>
#include "FileTransferInfoWidget.h"
FileTransferInfoWidget::FileTransferInfoWidget(QWidget * parent, Qt::WFlags f )
{
QRect TaskGraphRect = geometry();
maxWidth = TaskGraphRect.width();
pixmap = QPixmap(size());
pixmap.fill(this, 0, 0);
downloadedPixmap.load(":images/graph-downloaded.png");
downloadingPixmap.load(":images/graph-downloading.png");
notDownloadPixmap.load(":images/graph-notdownload.png");
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
void FileTransferInfoWidget::resizeEvent(QResizeEvent *event)
{
QRect TaskGraphRect = geometry();
maxWidth = TaskGraphRect.width();
updateDisplay();
}
void FileTransferInfoWidget::updateDisplay()
{
std::cout << "In TaskGraphPainterWidget::updateDisplay()" << std::endl ;
FileInfo nfo ;
if(!rsFiles->FileDetails(_file_hash, RS_FILE_HINTS_DOWNLOAD, nfo))
return ;
FileChunksInfo info ;
if(!rsFiles->FileChunksDetails(_file_hash, info))
return ;
std::cout << "got details for file " << nfo.fname << std::endl ;
uint64_t fileSize = info.file_size;
uint32_t blockSize = info.chunk_size ;
int blocks = info.chunks.size() ;
int columns = maxWidth/13;
y = blocks/columns*13;
x = blocks%columns*13;
maxHeight = y+15;
pixmap = QPixmap(size());
pixmap.fill(this, 0, 0);
pixmap = QPixmap(maxWidth, maxHeight);
pixmap.fill(this, 0, 0);
setFixedHeight(maxHeight);
QPainter painter(&pixmap);
painter.initFrom(this);
draw(info,&painter) ;
pixmap2 = pixmap;
}
void FileTransferInfoWidget::paintEvent(QPaintEvent *event)
{
std::cout << "In paint event" << std::endl ;
QStylePainter painter(this);
painter.drawPixmap(0, 0, pixmap2);
pixmap = pixmap2;
}
void FileTransferInfoWidget::draw(const FileChunksInfo& info,QPainter *painter)
{
x=0;
y=0;
int blocks = info.chunks.size() ;
uint64_t fileSize = info.file_size ;
uint32_t blockSize = info.chunk_size ;
if (fileSize%blockSize == 0) blocks--;
QRectF source(0.0, 0.0, 12.0, 12.0);
for (int i=0;i<=blocks;i++)
{
if (x > maxWidth - 13)
{
x = 0;
y += 13;
}
QRectF target(x, y, 12.0, 12.0);
switch(info.chunks[i])
{
case FileChunksInfo::CHUNK_DONE: painter->drawPixmap(target, downloadedPixmap, source);
break ;
case FileChunksInfo::CHUNK_ACTIVE: painter->drawPixmap(target, downloadingPixmap, source);
break ;
case FileChunksInfo::CHUNK_OUTSTANDING: painter->drawPixmap(target, notDownloadPixmap, source);
break ;
default: ;
}
x += 13;
}
maxHeight = y+15;
}

View File

@ -0,0 +1,60 @@
#pragma once
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2009, defnax
* Copyright (c) 2009, lsn752
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QWidget>
#include <QPainter>
#include <QBitmap>
#include "RsAutoUpdatePage.h"
class FileChunksInfo ;
class FileTransferInfoWidget : public RsAutoUpdatePage
{
Q_OBJECT
public:
FileTransferInfoWidget(QWidget * parent = 0, Qt::WFlags f = 0 );
void setFileHash(const std::string& hash) { _file_hash = hash ; }
virtual void updateDisplay() ; // update from RsAutoUpdateWidget
protected:
void draw(const FileChunksInfo& details,QPainter *painter) ;
virtual void paintEvent(QPaintEvent *);
virtual void resizeEvent(QResizeEvent *event);
private:
int x;
int y;
int maxWidth;
int maxHeight;
QPixmap pixmap;
QPixmap pixmap2;
QPixmap downloadedPixmap;
QPixmap downloadingPixmap;
QPixmap notDownloadPixmap;
std::string _file_hash ;
};

View File

@ -76,7 +76,8 @@ RsCertId getNeighRsCertId(QTreeWidgetItem *i);
/** Constructor */
NetworkDialog::NetworkDialog(QWidget *parent)
: MainPage(parent), connectdialog(NULL)
: RsAutoUpdatePage(10000,parent), // updates every 10 sec.
connectdialog(NULL)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
@ -346,6 +347,11 @@ void NetworkDialog::loadcert()
#include <sstream>
void NetworkDialog::updateDisplay()
{
insertConnect() ;
}
/* get the list of Neighbours from the RsIface. */
void NetworkDialog::insertConnect()
{
@ -425,7 +431,7 @@ void NetworkDialog::insertConnect()
out << detail.extPort;
} else {
// No Trust => no IP Information
out << "0.0.0.0:0/0.0.0.0:0";
out << "Unknown";
}
item -> setText(5, QString::fromStdString(out.str()));
}
@ -433,7 +439,7 @@ void NetworkDialog::insertConnect()
/* Others */
item -> setText(6, QString::fromStdString(detail.org));
item -> setText(7, QString::fromStdString(detail.location));
item -> setText(8, QString::fromStdString(detail.email));
item -> setText(8, QString::fromStdString(rsPeers->getPeerName(detail.id)));
{
item -> setText(9, QString::fromStdString(detail.id));

View File

@ -30,11 +30,12 @@
#include "mainpage.h"
#include "ui_NetworkDialog.h"
#include "RsAutoUpdatePage.h"
#include "connect/ConnectDialog.h"
class NetworkDialog : public MainPage
class NetworkDialog : public RsAutoUpdatePage
{
Q_OBJECT
@ -46,6 +47,7 @@ public:
void showpeerdetails(std::string id);
//void load();
virtual void updateDisplay() ; // overloaded from RsAutoUpdatePage
public slots:
void insertConnect();

View File

@ -84,7 +84,7 @@
/** Constructor */
PeersDialog::PeersDialog(QWidget *parent)
: MainPage(parent),
: RsAutoUpdatePage(1000,parent),
historyKeeper(Rshare::dataDirectory() + "/his1.xml")
{
/* Invoke the Qt Designer generated object setup routine */
@ -260,7 +260,10 @@ void PeersDialog::peertreeWidgetCostumPopupMenu( QPoint point )
}
void PeersDialog::updateDisplay()
{
insertPeers() ;
}
/* get the list of peers from the RsIface. */
void PeersDialog::insertPeers()

View File

@ -25,6 +25,7 @@
#include <QFileDialog>
#include "chat/PopupChatDialog.h"
#include "RsAutoUpdatePage.h"
#include "mainpage.h"
#include "ui_PeersDialog.h"
@ -37,7 +38,7 @@ class QTextEdit;
class QTextCharFormat;
class ChatDialog;
class PeersDialog : public MainPage
class PeersDialog : public RsAutoUpdatePage
{
Q_OBJECT
@ -53,6 +54,7 @@ class PeersDialog : public MainPage
// void setChatDialog(ChatDialog *cd);
QPixmap picture;
virtual void updateDisplay() ; // overloaded from RsAutoUpdatePage
public slots:

View File

@ -463,7 +463,7 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
switch(coln)
{
case 0:
return QString::fromStdString(details.name);
return QString::fromUtf8(details.name.c_str());
break;
case 1:
{
@ -503,7 +503,7 @@ QString RemoteDirModel::getAgeIndicatorString(const DirDetails &details) const
switch(coln)
{
case 0:
return QString::fromStdString(details.name);
return QString::fromUtf8(details.name.c_str());
break;
case 1:
//return QString("");

View File

@ -0,0 +1,31 @@
#include <iostream>
#include <QTimer>
#include "RsAutoUpdatePage.h"
RsAutoUpdatePage::RsAutoUpdatePage(int ms_update_period,QWidget *parent)
: MainPage(parent)
{
_timer = new QTimer ;
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(timerUpdate())) ;
_timer->start(ms_update_period) ;
}
void RsAutoUpdatePage::showEvent(QShowEvent *event)
{
std::cout << "In show event !!" << std::endl ;
updateDisplay();
}
void RsAutoUpdatePage::timerUpdate()
{
// only update when the widget is visible.
//
if(!isVisible())
return ;
updateDisplay() ;
update() ; // Qt flush
}

View File

@ -0,0 +1,33 @@
#pragma once
#include <QApplication>
#include <QWidget>
#include "mainpage.h"
// This class implement a basic RS functionality which is that widgets displayign info
// should update regularly. They also should update only when visible, to save CPU time.
//
// Using this class simply needs to derive your widget from RsAutoUpdateWidget
// and oveload the update() function with the actual code that updates the
// widget.
//
class QTimer ;
class RsAutoUpdatePage: public MainPage
{
Q_OBJECT
public:
RsAutoUpdatePage(int ms_update_period = 1000,QWidget *parent=NULL) ;
virtual void updateDisplay() {}
protected:
virtual void showEvent(QShowEvent *e) ;
private slots:
void timerUpdate() ;
private:
QTimer *_timer ;
};

View File

@ -29,6 +29,7 @@
#include "RetroShareLinkAnalyzer.h"
#include "DLListDelegate.h"
#include "ULListDelegate.h"
#include "FileTransferInfoWidget.h"
#include <QContextMenuEvent>
#include <QMenu>
@ -70,7 +71,7 @@
/** Constructor */
TransfersDialog::TransfersDialog(QWidget *parent)
: MainPage(parent)
: RsAutoUpdatePage(1000,parent)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
@ -178,16 +179,16 @@ TransfersDialog::TransfersDialog(QWidget *parent)
_sortColUpl = 0;
_sortOrderUpl = Qt::AscendingOrder;
createTaskGraphPainterWidget();
/*
taskGraphDetailLayout = new QHBoxLayout();
taskGraphDetailLayout->addWidget(taskGraphWidget);
ui.tab_2->setLayout(taskGraphDetailLayout);
taskGraphDetailLayout->setSpacing( 0 );
taskGraphDetailLayout->setMargin( 0 );*/
FileTransferInfoWidget *ftiw = new FileTransferInfoWidget();
ui.fileTransferInfoWidget->setWidget(ftiw);
ui.fileTransferInfoWidget->setWidgetResizable(true);
ui.fileTransferInfoWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui.fileTransferInfoWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui.fileTransferInfoWidget->viewport()->setBackgroundRole(QPalette::NoRole);
ui.fileTransferInfoWidget->setFrameStyle(QFrame::NoFrame);
ui.fileTransferInfoWidget->setFocusPolicy(Qt::NoFocus);
QObject::connect(ui.downloadList,SIGNAL(clicked(const QModelIndex&)),this,SLOT(showFileDetails())) ;
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -205,7 +206,7 @@ void TransfersDialog::keyPressEvent(QKeyEvent *e)
e->accept() ;
}
else
MainPage::keyPressEvent(e) ;
RsAutoUpdatePage::keyPressEvent(e) ;
}
void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
@ -222,7 +223,8 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
*/
std::cerr << "TransfersDialog::downloadListCostumPopupMenu()" << std::endl;
bool addPlayOption = false;
bool addPlayOption = false;
for(int i = 0; i <= DLListModel->rowCount(); i++) {
std::cerr << "Row Status :" << getStatus(i, DLListModel).toStdString() << ":" << std::endl;
if(selection->isRowSelected(i, QModelIndex())) {
@ -236,14 +238,13 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
}
}
}
QAction *playAct = NULL;
if (addPlayOption)
{
playAct = new QAction(QIcon(IMAGE_PLAY), tr( "Play" ), this );
connect( playAct , SIGNAL( triggered() ), this, SLOT( playSelectedTransfer() ) );
}
QAction *detailsAct = NULL;
pauseAct = new QAction(QIcon(IMAGE_PAUSE), tr("Pause"), this);
connect(pauseAct, SIGNAL(triggered()), this, SLOT(pauseFileTransfer()));
@ -325,9 +326,9 @@ void TransfersDialog::downloadListCostumPopupMenu( QPoint point )
contextMnu.addAction( clearQueuedDwlAct);
contextMnu.addAction( clearQueueAct);
contextMnu.addSeparator();
contextMnu.addMenu( viewMenu);
contextMnu.exec( mevent->globalPos() );
contextMnu.addMenu( viewMenu);
contextMnu.exec( mevent->globalPos() );
}
void TransfersDialog::playSelectedTransfer()
@ -581,6 +582,10 @@ void TransfersDialog::editItem(int row, int column, QVariant data)
}
/* get the list of Transfers from the RsIface. **/
void TransfersDialog::updateDisplay()
{
insertTransfers();
}
void TransfersDialog::insertTransfers()
{
QString symbol, name, sources, status, priority, coreId;
@ -658,7 +663,7 @@ void TransfersDialog::insertTransfers()
if (info.flags & CB_CODE_CACHE) continue;
symbol = "";
name = QString::fromStdString(info.fname);
name = QString::fromUtf8(info.fname.c_str());
coreId = QString::fromStdString(info.hash);
fileSize = info.size;
progress = (info.transfered * 100.0) / info.size;
@ -779,7 +784,7 @@ void TransfersDialog::insertTransfers()
rsFiles->getDwlDetails(details);
for (dit = details.begin(); dit != details.end(); dit ++)
{
name = QString::fromStdString(dit->fname);
name = QString::fromUtf8(dit->fname.c_str());
coreId = QString::fromStdString(dit->hash);
fileSize = dit->count;
progress = 0;
@ -842,7 +847,7 @@ void TransfersDialog::insertTransfers()
{
symbol = "";
coreId = QString::fromStdString(info.hash);
name = QString::fromStdString(info.fname);
name = QString::fromUtf8(info.fname.c_str());
sources = getPeerName(pit->peerId);
switch(pit->status)
@ -886,7 +891,7 @@ void TransfersDialog::insertTransfers()
{
symbol = "";
coreId = QString::fromStdString(info.hash);
name = QString::fromStdString(info.fname);
name = QString::fromUtf8(info.fname.c_str());
sources = tr("Unknown");
switch(info.downloadStatus)
@ -1305,36 +1310,24 @@ void TransfersDialog::saveSortIndicatorUpl(int logicalIndex, Qt::SortOrder order
_sortOrderUpl = order;
}
void TransfersDialog::createTaskGraphPainterWidget()
void TransfersDialog::showFileDetails()
{
taskGraphPainterWidget = new TaskGraphPainterWidget();
//taskGraphWidget = new QScrollArea();
ui.taskGraphWidget->setWidget(taskGraphPainterWidget);
ui.taskGraphWidget->setWidgetResizable(true);
ui.taskGraphWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui.taskGraphWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
ui.taskGraphWidget->viewport()->setBackgroundRole(QPalette::NoRole);
ui.taskGraphWidget->setFrameStyle(QFrame::NoFrame);
ui.taskGraphWidget->setFocusPolicy(Qt::NoFocus);
std::string file_hash ;
int nb_select = 0 ;
for(int i = 0; i <= DLListModel->rowCount(); i++)
if(selection->isRowSelected(i, QModelIndex()))
{
file_hash = getID(i, DLListModel).toStdString();
++nb_select ;
}
if(nb_select != 1)
return ;
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->setFileHash(file_hash) ;
dynamic_cast<FileTransferInfoWidget*>(ui.fileTransferInfoWidget->widget())->updateDisplay() ;
}
/*void TransfersDialog::setTaskGraphPainterWidget (const QModelIndex& index)
{
Download *dl = (Download *) (index.model ()->
data (index.model ()->index (index.row (), DLListDelegate::PTR)).value <quintptr > ());
if (!dl)
return;
// call takeWidget before setWidget to avoid destruction of the widget
QWidget* lastWidget = taskGraphWidget->takeWidget ();
QWidget* currentWidget = dl->getTaskGraphicWidget ();
taskGraphWidget->setWidget (currentWidget);
taskGraphWidget->show ();
}*/
double TransfersDialog::getProgress(int row, QStandardItemModel *model)
{
return model->data(model->index(row, PROGRESS), Qt::DisplayRole).toDouble();

View File

@ -31,7 +31,7 @@
#include <stdint.h>
#include "mainpage.h"
#include "taskGraphPainterWidget.h"
#include "RsAutoUpdatePage.h"
#include "ui_TransfersDialog.h"
@ -40,7 +40,7 @@ class DLListDelegate;
class ULListDelegate;
class QStandardItemModel;
class TransfersDialog : public MainPage
class TransfersDialog : public RsAutoUpdatePage
{
Q_OBJECT
@ -51,6 +51,7 @@ class TransfersDialog : public MainPage
~TransfersDialog();
virtual void keyPressEvent(QKeyEvent *) ;
virtual void updateDisplay() ; // derived from RsAutoUpdateWidget
public slots:
void insertTransfers();
@ -117,12 +118,6 @@ class TransfersDialog : public MainPage
int _sortColDwl, _sortColUpl;
Qt::SortOrder _sortOrderDwl, _sortOrderUpl;
void createTaskGraphPainterWidget();
/*QHBoxLayout *taskGraphDetailLayout;
QScrollArea *taskGraphWidget;*/
TaskGraphPainterWidget *taskGraphPainterWidget;
/** Create the actions on the tray menu or menubar */
void createActions();
@ -171,6 +166,7 @@ class TransfersDialog : public MainPage
void editItem(int row, int column, QVariant data);
void updateProgress(int value);
void showFileDetails() ;
double getProgress(int row, QStandardItemModel *model);
double getSpeed(int row, QStandardItemModel *model);

View File

@ -656,7 +656,7 @@ p, li { white-space: pre-wrap; }
<normaloff>:/images/blockdevice.png</normaloff>:/images/blockdevice.png</iconset>
</attribute>
<attribute name="title">
<string>File Chunks</string>
<string>Selected transfer</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_7">
<property name="margin">
@ -666,7 +666,7 @@ p, li { white-space: pre-wrap; }
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QScrollArea" name="taskGraphWidget">
<widget class="QScrollArea" name="fileTransferInfoWidget">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>

View File

@ -113,7 +113,6 @@ int TrustView::getRowColId(const string& peerid)
if(itpr == peeridToRow.end())
{
i = trustTableTW->columnCount() ;
// cout << " -> peer not in table. Creating entry # " << i << endl ;
trustTableTW->insertColumn(i) ;
trustTableTW->insertRow(i) ;
@ -146,7 +145,7 @@ void TrustView::update()
if(!rsPeers->getOthersList(neighs))
return ;
neighs.push_back(rsPeers->getOwnId()) ;
// neighs.push_back(rsPeers->getPGPOwnId()) ;
trustTableTW->setSortingEnabled(false) ;
@ -155,17 +154,17 @@ void TrustView::update()
// Fill everything
for(list<string>::const_iterator it1(neighs.begin()); it1 != neighs.end(); ++it1)
{
std::list<std::string> friends_ids ;
if(!rsPeers->getPeerDetails(*it1,details))
continue ;
// cout << "treating neigh = " << details.name << endl ;
// cout << " signers = " ;
int i = getRowColId(details.id) ;
std::string issuer(details.issuer) ; // the one we check for trust.
for(list<string>::const_iterator it2(details.signers.begin());it2!=details.signers.end();++it2)
{
cout << *it2 << " " ;
// Signers are identified by there name, so if we have twice the same signers, this gets crappy.
int j = getRowColId(*it2) ;

View File

@ -1,625 +0,0 @@
/****************************************************************
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <list>
#include "rshare.h"
#include "SearchDialog.h"
#include "rsiface/rsiface.h"
#include "rsiface/rsexpr.h"
#include "rsiface/rsfiles.h"
#include "rsiface/rspeers.h"
#ifdef TURTLE_HOPPING
#include "rsiface/rsturtle.h"
#endif
#include "util/misc.h"
#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"
#define IMAGE_REMOVE ":/images/delete.png"
#define IMAGE_REMOVEALL ":/images/deleteall.png"
/* Key for UI Preferences */
#define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch"
/* indicies for search results item columns SR_ = Search Result */
/* indicies for search results item columns SR_ = Search Result */
#define SR_ICON_COL 0
#define SR_NAME_COL 1
#define SR_SIZE_COL 2
#define SR_ID_COL 3
#define SR_TYPE_COL 4
#define SR_HASH_COL 5
#define SR_SEARCH_ID_COL 6
#define SR_UID_COL 7
#define SR_REALSIZE_COL 8
/* 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
/* static members */
/* These indices MUST be identical to their equivalent indices in the combobox */
const int SearchDialog::FILETYPE_IDX_ANY = 0;
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;
QMap<int, QString> * SearchDialog::FileTypeExtensionMap = new QMap<int, QString>();
bool SearchDialog::initialised = false;
/** Constructor */
SearchDialog::SearchDialog(QWidget *parent)
: MainPage(parent),
advSearchDialog(NULL),
contextMnu(NULL), contextMnu2(NULL),
nextSearchId(1)
{
/* Invoke the Qt Designer generated object setup routine */
ui.setupUi(this);
/* initialise the filetypes mapping */
if (!SearchDialog::initialised)
{
initialiseFileTypeMappings();
}
/* Advanced search panel specifica */
RshareSettings rsharesettings;
QString key (UI_PREF_ADVANCED_SEARCH);
bool useAdvanced = rsharesettings.value(key, QVariant(false)).toBool();
if (useAdvanced)
{
ui.toggleAdvancedSearchBtn->setChecked(true);
ui.SimpleSearchPanel->hide();
} else {
ui.AdvancedSearchPanel->hide();
}
connect(ui.toggleAdvancedSearchBtn, SIGNAL(toggled(bool)), this, SLOT(toggleAdvancedSearchDialog(bool)));
connect(ui.focusAdvSearchDialogBtn, SIGNAL(clicked()), this, SLOT(showAdvSearchDialog()));
/* End Advanced Search Panel specifics */
connect( ui.searchResultWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidgetCostumPopupMenu( QPoint ) ) );
connect( ui.searchSummaryWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidget2CostumPopupMenu( QPoint ) ) );
connect( ui.lineEdit, SIGNAL( returnPressed ( void ) ), this, SLOT( searchKeywords( void ) ) );
connect( ui.pushButtonsearch, SIGNAL( released ( void ) ), this, SLOT( searchKeywords( void ) ) );
connect( ui.pushButtonDownload, SIGNAL( released ( void ) ), this, SLOT( download( void ) ) );
//connect( ui.searchSummaryWidget, SIGNAL( itemSelectionChanged ( void ) ), this, SLOT( selectSearchResults( void ) ) );
connect ( ui.searchSummaryWidget, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem * ) ),
this, SLOT( selectSearchResults( void ) ) );
/* hide the Tree +/- */
ui.searchResultWidget -> setRootIsDecorated( false );
ui.searchResultWidget -> setColumnHidden( SR_UID_COL,true );
ui.searchResultWidget -> setColumnHidden( SR_REALSIZE_COL,true );
ui.searchSummaryWidget -> setRootIsDecorated( false );
/* make it extended selection */
ui.searchResultWidget -> setSelectionMode(QAbstractItemView::ExtendedSelection);
/* Set header resize modes and initial section sizes */
ui.searchSummaryWidget->setColumnCount(3);
QHeaderView * _smheader = ui.searchSummaryWidget->header () ;
_smheader->setResizeMode (0, QHeaderView::Interactive);
_smheader->setResizeMode (1, QHeaderView::Interactive);
_smheader->setResizeMode (2, QHeaderView::Interactive);
_smheader->resizeSection ( 0, 80 );
_smheader->resizeSection ( 1, 75 );
_smheader->resizeSection ( 2, 75 );
ui.searchResultWidget->setColumnCount(6);
_smheader = ui.searchResultWidget->header () ;
_smheader->setResizeMode (0, QHeaderView::Custom);
_smheader->setResizeMode (1, QHeaderView::Interactive);
_smheader->setResizeMode (2, QHeaderView::Interactive);
_smheader->setResizeMode (3, QHeaderView::Interactive);
_smheader->resizeSection ( 0, 20 );
_smheader->resizeSection ( 1, 220 );
_smheader->resizeSection ( 2, 75 );
_smheader->resizeSection ( 3, 75 );
_smheader->resizeSection ( 4, 75 );
_smheader->resizeSection ( 5, 240 );
// set header text aligment
QTreeWidgetItem * headerItem = ui.searchResultWidget->headerItem();
headerItem->setTextAlignment(2, Qt::AlignRight | Qt::AlignRight);
headerItem->setTextAlignment(3, Qt::AlignRight | Qt::AlignRight);
ui.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder);
/* Hide platform specific features */
#ifdef Q_WS_WIN
#endif
}
void SearchDialog::initialiseFileTypeMappings()
{
/* edit these strings to change the range of extensions recognised by the search */
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_ANY, "");
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_AUDIO, "aac aif iff m3u mid midi mp3 mpa ogg ra ram wav wma");
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_ARCHIVE, "7z bz2 gz pkg rar sea sit sitx tar zip");
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_CDIMAGE, "iso nrg mdf");
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_DOCUMENT, "doc odt ott rtf pdf ps txt log msg wpd wps" );
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_PICTURE, "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");
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_PROGRAM, "app bat cgi com bin exe js pif py pl sh vb ws ");
SearchDialog::FileTypeExtensionMap->insert(FILETYPE_IDX_VIDEO, "3gp asf asx avi mov mp4 mkv flv mpeg mpg qt rm swf vob wmv");
SearchDialog::initialised = true;
}
void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint point )
{
// block the popup if no results available
if ((ui.searchResultWidget->selectedItems()).size() == 0) return;
// create the menu as required
if (contextMnu == 0)
{
contextMnu = new QMenu(this);
downloadAct = new QAction(QIcon(IMAGE_START), tr( "Download" ), this );
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( download() ) );
broadcastonchannelAct = new QAction( tr( "Broadcast on Channel" ), this );
connect( broadcastonchannelAct , SIGNAL( triggered() ), this, SLOT( broadcastonchannel() ) );
recommendtofriendsAct = new QAction( tr( "Recommend to Friends" ), this );
connect( recommendtofriendsAct , SIGNAL( triggered() ), this, SLOT( recommendtofriends() ) );
contextMnu->clear();
contextMnu->addAction( downloadAct);
contextMnu->addSeparator();
contextMnu->addAction( broadcastonchannelAct);
contextMnu->addAction( recommendtofriendsAct);
}
QMouseEvent *mevent = new QMouseEvent( QEvent::MouseButtonPress, point,
Qt::RightButton, Qt::RightButton, Qt::NoModifier );
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;
for (int i = 0; i < numdls; ++i)
{
item = itemsForDownload.at(i);
// call the download
if(item->text(SR_ID_COL) != "Local")
{
std::cerr << "SearchDialog::download() Calling File Request";
#ifdef TO_DO
// This is disabled, although it still works for friends files. Indeed, one must first
// warn the turtle router to digg tunnels for the given hashes, then call rsFiles.
//
std::cerr << std::endl;
std::list<std::string> srcIds;
srcIds.push_back(item->text(SR_UID_COL).toStdString()) ;
rsFiles -> FileRequest((item->text(SR_NAME_COL)).toStdString(),
(item->text(SR_HASH_COL)).toStdString(),
(item->text(SR_REALSIZE_COL)).toInt(),
"", 0, srcIds);
#endif
std::list<std::string> srcIds;
std::cout << "Issuing file request from search dialog: -"
<< (item->text(SR_NAME_COL)).toStdString() << "-"
<< (item->text(SR_HASH_COL)).toStdString() << "-"
<< (item->text(SR_REALSIZE_COL)).toInt() << std::endl ;
rsTurtle->monitorFileTunnels(item->text(SR_NAME_COL).toStdString(),item->text(SR_HASH_COL).toStdString(),item->text(SR_REALSIZE_COL).toInt()) ;
rsFiles->FileRequest(item->text(SR_NAME_COL).toStdString(),item->text(SR_HASH_COL).toStdString(),item->text(SR_REALSIZE_COL).toInt(),"",0,srcIds) ;
}
}
if (attemptDownloadLocal)
QMessageBox::information(0, tr("Download Notice"), tr("Skipping Local Files"));
}
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."));
}
/** context menu searchTablewidget2 **/
void SearchDialog::searchtableWidget2CostumPopupMenu( QPoint point )
{
// block the popup if no results available
if ((ui.searchSummaryWidget->selectedItems()).size() == 0) return;
// create the menu as required
if (contextMnu2 == 0)
{
contextMnu2 = new QMenu( this );
searchRemoveAct = new QAction(QIcon(IMAGE_REMOVE), tr( "Remove" ), this );
connect( searchRemoveAct , SIGNAL( triggered() ), this, SLOT( searchRemove() ) );
searchRemoveAllAct = new QAction(QIcon(IMAGE_REMOVEALL), tr( "Remove All" ), this );
connect( searchRemoveAllAct , SIGNAL( triggered() ), this, SLOT( searchRemoveAll() ) );
contextMnu2->clear();
contextMnu2->addAction( searchRemoveAct);
contextMnu2->addAction( searchRemoveAllAct);
}
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()
{
ui.searchResultWidget->clear();
ui.searchSummaryWidget->clear();
nextSearchId = 1;
}
/* *****************************************************************
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));
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();
}
}
void SearchDialog::advancedSearch(Expression* expression)
{
// advSearchDialog->hide();
//
// /* call to core */
// std::list<FileDetail> results;
// rsFiles -> SearchBoolExp(expression, results);
//
// /* abstraction to allow reusee of tree rendering code */
// resultsToTree((advSearchDialog->getSearchAsString()).toStdString(), results);
}
void SearchDialog::searchKeywords()
{
QString qTxt = ui.lineEdit->text();
std::string txt = qTxt.toStdString();
TurtleRequestId id = rsTurtle->turtleSearch(txt) ;
}
void SearchDialog::updateFiles(qulonglong search_id,TurtleFileInfo file)
{
/* which extensions do we use? */
std::string txt = ui.lineEdit->text().toStdString();
if (ui.FileTypeComboBox->currentIndex() == FILETYPE_IDX_ANY)
insertFile(txt,search_id,file);
else
{
// amend the text description of the search
txt += " (" + ui.FileTypeComboBox->currentText().toStdString() + ")";
// collect the extensions to use
QString extStr = SearchDialog::FileTypeExtensionMap->value(ui.FileTypeComboBox->currentIndex());
QStringList extList = extStr.split(" ");
// get this file's extension
QString qName = QString::fromStdString(file.name);
int extIndex = qName.lastIndexOf(".");
if (extIndex >= 0)
{
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);
}
}
}
void SearchDialog::insertFile(const std::string& txt,qulonglong searchId, const TurtleFileInfo& file)
{
// algo:
//
// 1 - look in result window whether the file already exist.
// 1.1 - If yes, just increment the source number.
// 2.2 - Otherwize, add an entry.
// 2 - look in the summary whether there exist the same request id.
// 1.1 - If yes, just increment the result number.
// 2.2 - Otherwize, add an entry.
//
// 1 - look in result window whether the file already exist.
//
int items = ui.searchResultWidget->topLevelItemCount();
bool found = false ;
for(int i = 0; i < items; i++)
if(ui.searchResultWidget->topLevelItem(i)->text(SR_HASH_COL) == QString::fromStdString(file.hash)
&& ui.searchResultWidget->topLevelItem(i)->text(SR_SEARCH_ID_COL).toInt(NULL,16) == searchId)
{
int s = ui.searchResultWidget->topLevelItem(i)->text(SR_ID_COL).toInt() ;
ui.searchResultWidget->topLevelItem(i)->setText(SR_ID_COL,QString::number(s+1));
found = true ;
}
if(!found)
{
/* translate search results */
QTreeWidgetItem *item = new QTreeWidgetItem();
item->setText(SR_NAME_COL, QString::fromStdString(file.name));
item->setText(SR_HASH_COL, QString::fromStdString(file.hash));
QString ext = QFileInfo(QString::fromStdString(file.name)).suffix();
if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp" || ext == "ico" || ext == "svg")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypePicture.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Picture"));
}
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")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeVideo.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Video"));
}
else if (ext == "ogg" || ext == "mp3" || ext == "wav" || ext == "wma")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAudio.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Audio"));
}
else if (ext == "tar" || ext == "bz2" || ext == "zip" || ext == "gz" || ext == "rar" || ext == "rpm" || ext == "deb")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeArchive.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Archive"));
}
else if (ext == "app" || ext == "bat" || ext == "cgi" || ext == "com" || ext == "bin" || ext == "exe" || ext == "js" || ext == "pif" || ext == "py" || ext == "pl" || ext == "sh" || ext == "vb" || ext == "ws")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeProgram.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Program"));
}
else if (ext == "iso" || ext == "nrg" || ext == "mdf" )
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeCDImage.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("CD-Image"));
}
else if (ext == "txt" || ext == "cpp" || ext == "c" || ext == "h")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "doc" || ext == "rtf" || ext == "sxw" || ext == "xls"
|| ext == "sxc" || ext == "odt" || ext == "ods")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else if (ext == "html" || ext == "htm" || ext == "php")
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeDocument.png"));
item->setText(SR_TYPE_COL, QString::fromUtf8("Document"));
}
else
{
item->setIcon(SR_ICON_COL, QIcon(":/images/FileTypeAny.png"));
}
/*
* to facilitate downlaods we need to save the file size too
*/
item->setText(SR_SIZE_COL, misc::friendlyUnit(file.size));
item->setText(SR_REALSIZE_COL, QString::number(file.size));
item->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
item->setText(SR_ID_COL, QString::number(1));
item->setText(SR_SEARCH_ID_COL, QString::number(searchId,16));
ui.searchResultWidget->addTopLevelItem(item);
}
/* add to the summary as well */
int items2 = ui.searchSummaryWidget->topLevelItemCount();
bool found2 = false ;
for(int i = 0; i < items2; i++)
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL).toInt(NULL,16) == searchId)
{
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 ;
}
if(!found2)
{
QTreeWidgetItem *item2 = new QTreeWidgetItem();
item2->setText(SS_TEXT_COL, QString::fromStdString(txt));
item2->setText(SS_COUNT_COL, QString::number(1));
item2->setText(SS_SEARCH_ID_COL, QString::number(searchId,16));
ui.searchSummaryWidget->addTopLevelItem(item2);
ui.searchSummaryWidget->setCurrentItem(item2);
}
/* select this search result */
selectSearchResults();
}
//void QTreeWidget::currentItemChanged ( QTreeWidgetItem * current, QTreeWidgetItem * previous ) [signal]
void SearchDialog::selectSearchResults()
{
/* 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);
std::cerr << "SearchDialog::selectSearchResults(): 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; i++)
{
/* get item */
QTreeWidgetItem *ti = ui.searchResultWidget->topLevelItem(i);
if (ti->text(SR_SEARCH_ID_COL) == searchId)
{
ti->setHidden(false);
}
else
{
ti->setHidden(true);
}
}
ui.searchResultWidget->update();
}

View File

@ -1,296 +0,0 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2009, defnax
* Copyright (c) 2009, lsn752
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QStylePainter>
#include <QDebug>
#include "taskGraphPainterWidget.h"
TaskGraphPainterWidget::TaskGraphPainterWidget(QWidget * parent, Qt::WFlags f )
{
this->fileSize = 0;
this->blockSize = 100*1024;
notDownloadList.clear();
QRect TaskGraphRect = geometry();
maxWidth = TaskGraphRect.width();
pixmap = QPixmap(size());
pixmap.fill(this, 0, 0);
downloadedPixmap.load(":images/graph-downloaded.png");
downloadingPixmap.load(":images/graph-downloading.png");
notDownloadPixmap.load(":images/graph-notdownload.png");
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
void TaskGraphPainterWidget::setData( qint64 fileSize, qint64 blockSize )
{
this->fileSize = fileSize;
this->blockSize = blockSize;
int blocks = fileSize/blockSize;
if (fileSize%blockSize == 0) blocks--;
#ifdef WIN32
if (blocks>=5000)
{
this->blockSize=this->fileSize/5000;
}
#else
if (blocks>=3000)
{
this->blockSize=this->fileSize/3000;
}
#endif
}
void TaskGraphPainterWidget::setBlockSizeData( qint64 blockSize )
{
this->blockSize = blockSize;
int blocks = fileSize/blockSize;
if (fileSize%blockSize == 0) blocks--;
#ifdef WIN32
if (blocks>=5000)
{
this->blockSize=this->fileSize/5000;
}
#else
if (blocks>=3000)
{
this->blockSize=this->fileSize/3000;
}
#endif
refreshAll();
}
void TaskGraphPainterWidget::setNotDownloadListClear()
{
notDownloadList.clear();
}
void TaskGraphPainterWidget::setNotDownloadList( int taskThreadListId, qint64 startPosition, qint64 endPosition)
{
NotDownload notDownload;
notDownload.taskThreadListId = taskThreadListId;
notDownload.startPosition = startPosition;
notDownload.endPosition = endPosition;
notDownloadList.append(notDownload);
}
void TaskGraphPainterWidget::newReceivedListClear()
{
newTaskReceivedList.clear();
}
void TaskGraphPainterWidget::setNewReceived(int taskThreadListId, QList <qint64> newReceivedList)
{
NewReceived newReceived;
newReceived.taskThreadListId = taskThreadListId;
newReceived.newThreadReceivedList = newReceivedList;
newTaskReceivedList.append(newReceived);
}
void TaskGraphPainterWidget::resizeEvent(QResizeEvent *event)
{
QRect TaskGraphRect = geometry();
maxWidth = TaskGraphRect.width();
refreshAll();
}
void TaskGraphPainterWidget::refreshAll()
{
int blocks = fileSize/blockSize;
if (fileSize%blockSize >0) blocks++;
int columns = maxWidth/13;
y = blocks/columns*13;
x = blocks%columns*13;
maxHeight = y+15;
pixmap = QPixmap(size());
pixmap.fill(this, 0, 0);
pixmap = QPixmap(maxWidth, maxHeight);
pixmap.fill(this, 0, 0);
setFixedHeight(maxHeight);
QPainter painter(&pixmap);
painter.initFrom(this);
if (fileSize>0)
{
drawDownloaded(&painter);
drawNotDownload(&painter);
}
else
{
drawNoSizeFile(&painter);
}
pixmap2 = pixmap;
update();
}
void TaskGraphPainterWidget::refreshPixmap()
{
pixmap2 = pixmap;
QPainter painter(&pixmap2);
drawNewReceivedData(&painter);
update();
}
void TaskGraphPainterWidget::refreshThreadLastBlock(int newThreadReceivedListId)
{
pixmap2 = pixmap;
QPainter painter(&pixmap2);
drawThreadLastBlock(&painter, newThreadReceivedListId);
repaint ();
}
void TaskGraphPainterWidget::paintEvent(QPaintEvent *event)
{
QStylePainter painter(this);
painter.drawPixmap(0, 0, pixmap2);
pixmap = pixmap2;
}
void TaskGraphPainterWidget::drawNotDownload(QPainter *painter)
{
if (this->fileSize == 0) return;
int columns = maxWidth/13;
int blocks = fileSize/blockSize;
if (fileSize%blockSize == 0) blocks--;
QRectF source(0.0, 0.0, 12.0, 12.0);
for (int taskThreadListId=0;taskThreadListId<notDownloadList.size();taskThreadListId++)
{
qint64 startPosition = notDownloadList.at(taskThreadListId).startPosition;
qint64 endPosition = notDownloadList.at(taskThreadListId).endPosition;
int startPositionBlocks = startPosition/blockSize;
if (startPosition%blockSize > 0) startPositionBlocks++;
int endPositionBlocks = endPosition/blockSize;
if (endPositionBlocks != blocks) endPositionBlocks--;
for (int block=startPositionBlocks;block<=endPositionBlocks;block++)
{
y = block/columns*13;
x = block%columns*13;
QRectF target(x, y, 12.0, 12.0);
painter->drawPixmap(target, notDownloadPixmap, source);
}
}
}
void TaskGraphPainterWidget::drawDownloaded(QPainter *painter)
{
x=0;
y=0;
int blocks = fileSize/blockSize;
if (fileSize%blockSize == 0) blocks--;
QRectF source(0.0, 0.0, 12.0, 12.0);
for (int i=0;i<=blocks;i++)
{
if (x > maxWidth - 13)
{
x = 0;
y += 13;
}
QRectF target(x, y, 12.0, 12.0);
painter->drawPixmap(target, downloadedPixmap, source);
x += 13;
}
maxHeight = y+15;
}
void TaskGraphPainterWidget::drawNoSizeFile(QPainter *painter)
{
x=0;
y=0;
QList <qint64> newThreadReceivedList;
if (newTaskReceivedList.isEmpty()) return;
newThreadReceivedList = newTaskReceivedList.at(0).newThreadReceivedList;
if (newThreadReceivedList.isEmpty()) return;
qint64 startPosition = newThreadReceivedList.at(newThreadReceivedList.size()-1);
int blocks = startPosition/blockSize;
if (fileSize%blockSize == 0) blocks--;
QRectF source(0.0, 0.0, 12.0, 12.0);
for (int i=0;i<=blocks;i++)
{
if (x > maxWidth - 13)
{
x = 0;
y += 13;
}
QRectF target(x, y, 12.0, 12.0);
painter->drawPixmap(target, downloadedPixmap, source);
x += 13;
}
maxHeight = y+15;
}
void TaskGraphPainterWidget::drawNewReceivedData(QPainter *painter)
{
for (int newTaskReceivedListId=0;newTaskReceivedListId<newTaskReceivedList.size();newTaskReceivedListId++)
{
QList <qint64> newThreadReceivedList;
newThreadReceivedList = newTaskReceivedList.at(newTaskReceivedListId).newThreadReceivedList;
if (newThreadReceivedList.size() < 1) continue;
int columns = maxWidth/13;
QRectF source(0.0, 0.0, 12.0, 12.0);
qint64 startPosition = newThreadReceivedList.at(0);
qint64 endPosition = newThreadReceivedList.at(newThreadReceivedList.size()-1);
int startPositionBlocks = startPosition/blockSize;
int endPositionBlocks = endPosition/blockSize;
if (endPosition%blockSize == 0) endPositionBlocks--;
for (int block=startPositionBlocks;block<=endPositionBlocks;block++)
{
y = block/columns*13;
x = block%columns*13;
QRectF target(x, y, 12.0, 12.0);
if (block==endPositionBlocks)
{
if (newTaskReceivedList.at(newTaskReceivedListId).taskThreadListId>=0)
painter->drawPixmap(target, downloadingPixmap, source);
else
painter->drawPixmap(target, downloadedPixmap, source);
}
else
painter->drawPixmap(target, downloadedPixmap, source);
}
}
}
void TaskGraphPainterWidget::drawThreadLastBlock(QPainter *painter, int newThreadReceivedListId)
{
QList <qint64> newThreadReceivedList;
newThreadReceivedList = newTaskReceivedList.at(newThreadReceivedListId).newThreadReceivedList;
if (newThreadReceivedList.size() < 1) return;
int columns = maxWidth/13;
QRectF source(0.0, 0.0, 12.0, 12.0);
qint64 startPosition = newThreadReceivedList.at(0);
qint64 endPosition = newThreadReceivedList.at(newThreadReceivedList.size()-1);
int startPositionBlocks = startPosition/blockSize;
int endPositionBlocks = endPosition/blockSize;
if (endPosition%blockSize == 0) endPositionBlocks--;
for (int block=startPositionBlocks;block<=endPositionBlocks;block++)
{
y = block/columns*13;
x = block%columns*13;
QRectF target(x, y, 12.0, 12.0);
painter->drawPixmap(target, downloadedPixmap, source);
}
}

View File

@ -1,88 +0,0 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2009, defnax
* Copyright (c) 2009, lsn752
*
* 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
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef __TASKGRAPHPAINTERWIDGET_H__
#define __TASKGRAPHPAINTERWIDGET_H__
#include <QWidget>
#include <QPainter>
#include <QBitmap>
class TaskGraphPainterWidget : public QWidget
{
Q_OBJECT
public:
TaskGraphPainterWidget(QWidget * parent = 0, Qt::WFlags f = 0 );
void setData( qint64 fileSize, qint64 blockSize );
void setBlockSizeData( qint64 blockSize );
void setNotDownloadListClear();
void setNotDownloadList( int taskThreadListId, qint64 startPosition, qint64 endPosition);
void newReceivedListClear();
void setNewReceived(int taskThreadListId, QList <qint64> newReceivedList);
void refreshAll();
void refreshPixmap();
void refreshThreadLastBlock(int newThreadReceivedListId);
qint64 fileSize;
qint64 blockSize;
protected:
void paintEvent(QPaintEvent *);
void resizeEvent(QResizeEvent *event);
private:
void drawNotDownload(QPainter *painter);
void drawDownloaded(QPainter *painter);
void drawNoSizeFile(QPainter *painter);
void drawNewReceivedData(QPainter *painter);
void drawThreadLastBlock(QPainter *painter, int newThreadReceivedListId);
int x;
int y;
int maxWidth;
int maxHeight;
QPixmap pixmap;
QPixmap pixmap2;
QPixmap downloadedPixmap;
QPixmap downloadingPixmap;
QPixmap notDownloadPixmap;
int taskThreadListId;
struct _NotDownload
{
int taskThreadListId;
qint64 startPosition;
qint64 endPosition;
};
typedef struct _NotDownload NotDownload;
QList <NotDownload> notDownloadList;
struct _NewReceived
{
int taskThreadListId;
QList <qint64> newThreadReceivedList;
};
typedef struct _NewReceived NewReceived;
QList <NewReceived> newTaskReceivedList;
};
#endif // __TASKGRAPHPAINTERWIDGET_H__

View File

@ -209,17 +209,6 @@ void NotifyQt::UpdateGUI()
// std::cerr << "Got update signal t=" << lastTs << std::endl ;
if (time(NULL) > lastTs) // always update, every 1 sec.
{
emit transfersChanged();
emit friendsChanged() ;
}
if (time(NULL) > lastTs + 5) // update every 5 seconds. I don't know what to do with these.
{
// displayChannels();
}
lastTs = time(NULL) ;
static bool already_updated = false ; // these only update once at start because they may already have been set before

View File

@ -208,7 +208,7 @@ class NotifyBase
virtual void notifyOwnAvatarChanged() {}
virtual void notifyOwnStatusMessageChanged() {}
virtual std::string askForPassword(const std::string& window_title,const std::string& text) {}
virtual std::string askForPassword(const std::string& window_title,const std::string& text) { return "" ;}
};
const int NOTIFY_LIST_NEIGHBOURS = 1;