Added new Patch from Phenom (AddRSCollectionEditor_v0.6_7386)

Some Improvements : added submenu, Edit and view mode.


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7388 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2014-05-29 14:49:45 +00:00
parent 5e1099f47f
commit e65f73a44d
23 changed files with 2693 additions and 811 deletions

View File

@ -70,9 +70,8 @@
/* Images for context menu icons */ /* Images for context menu icons */
#define IMAGE_INFO ":/images/fileinfo.png" #define IMAGE_INFO ":/images/fileinfo.png"
#define IMAGE_CANCEL ":/images/delete.png" #define IMAGE_CANCEL ":/images/delete.png"
#define IMAGE_LIBRARY ":/images/library.png"
#define IMAGE_CLEARCOMPLETED ":/images/deleteall.png" #define IMAGE_CLEARCOMPLETED ":/images/deleteall.png"
#define IMAGE_PLAY ":/images/player_play.png" #define IMAGE_PLAY ":/images/player_play.png"
#define IMAGE_COPYLINK ":/images/copyrslink.png" #define IMAGE_COPYLINK ":/images/copyrslink.png"
#define IMAGE_PASTELINK ":/images/pasterslink.png" #define IMAGE_PASTELINK ":/images/pasterslink.png"
#define IMAGE_PAUSE ":/images/pause.png" #define IMAGE_PAUSE ":/images/pause.png"
@ -86,12 +85,17 @@
#define IMAGE_PRIORITYNORMAL ":/images/prioritynormal.png" #define IMAGE_PRIORITYNORMAL ":/images/prioritynormal.png"
#define IMAGE_PRIORITYHIGH ":/images/priorityhigh.png" #define IMAGE_PRIORITYHIGH ":/images/priorityhigh.png"
#define IMAGE_PRIORITYAUTO ":/images/priorityauto.png" #define IMAGE_PRIORITYAUTO ":/images/priorityauto.png"
#define IMAGE_SEARCH ":/images/filefind.png" #define IMAGE_SEARCH ":/images/filefind.png"
#define IMAGE_EXPAND ":/images/edit_add24.png" #define IMAGE_EXPAND ":/images/edit_add24.png"
#define IMAGE_COLLAPSE ":/images/edit_remove24.png" #define IMAGE_COLLAPSE ":/images/edit_remove24.png"
#define IMAGE_FRIENDSFILES ":/images/fileshare16.png" #define IMAGE_LIBRARY ":/images/library.png"
#define IMAGE_MYFILES ":images/my_documents_16.png" #define IMAGE_COLLCREATE ":/images/library_add.png"
#define IMAGE_RENAMEFILE ":images/filecomments.png" #define IMAGE_COLLMODIF ":/images/library_edit.png"
#define IMAGE_COLLVIEW ":/images/library_view.png"
#define IMAGE_COLLOPEN ":/images/library.png"
#define IMAGE_FRIENDSFILES ":/images/fileshare16.png"
#define IMAGE_MYFILES ":images/my_documents_16.png"
#define IMAGE_RENAMEFILE ":images/filecomments.png"
#define IMAGE_STREAMING ":images/streaming.png" #define IMAGE_STREAMING ":images/streaming.png"
Q_DECLARE_METATYPE(FileProgressInfo) Q_DECLARE_METATYPE(FileProgressInfo)
@ -367,9 +371,6 @@ TransfersDialog::TransfersDialog(QWidget *parent)
toggleShowCacheTransfersAct->setCheckable(true) ; toggleShowCacheTransfersAct->setCheckable(true) ;
connect(toggleShowCacheTransfersAct,SIGNAL(triggered()),this,SLOT(toggleShowCacheTransfers())) ; connect(toggleShowCacheTransfersAct,SIGNAL(triggered()),this,SLOT(toggleShowCacheTransfers())) ;
openCollectionAct = new QAction(QIcon(IMAGE_LIBRARY), tr( "Download from collection file..." ), this );
connect(openCollectionAct, SIGNAL(triggered()), this, SLOT(openCollection()));
// Actions. Only need to be defined once. // Actions. Only need to be defined once.
pauseAct = new QAction(QIcon(IMAGE_PAUSE), tr("Pause"), this); pauseAct = new QAction(QIcon(IMAGE_PAUSE), tr("Pause"), this);
connect(pauseAct, SIGNAL(triggered()), this, SLOT(pauseFileTransfer())); connect(pauseAct, SIGNAL(triggered()), this, SLOT(pauseFileTransfer()));
@ -431,14 +432,22 @@ TransfersDialog::TransfersDialog(QWidget *parent)
connect(chunkProgressiveAct, SIGNAL(triggered()), this, SLOT(chunkProgressive())); connect(chunkProgressiveAct, SIGNAL(triggered()), this, SLOT(chunkProgressive()));
playAct = new QAction(QIcon(IMAGE_PLAY), tr( "Play" ), this ); playAct = new QAction(QIcon(IMAGE_PLAY), tr( "Play" ), this );
connect( playAct , SIGNAL( triggered() ), this, SLOT( openTransfer() ) ); connect( playAct , SIGNAL( triggered() ), this, SLOT( openTransfer() ) );
renameFileAct = new QAction(QIcon(IMAGE_RENAMEFILE), tr("Rename file..."), this); renameFileAct = new QAction(QIcon(IMAGE_RENAMEFILE), tr("Rename file..."), this);
connect(renameFileAct, SIGNAL(triggered()), this, SLOT(renameFile())); connect(renameFileAct, SIGNAL(triggered()), this, SLOT(renameFile()));
specifyDestinationDirectoryAct = new QAction(QIcon(IMAGE_SEARCH),tr("Specify..."),this) ; specifyDestinationDirectoryAct = new QAction(QIcon(IMAGE_SEARCH),tr("Specify..."),this) ;
connect(specifyDestinationDirectoryAct,SIGNAL(triggered()),this,SLOT(chooseDestinationDirectory())) ; connect(specifyDestinationDirectoryAct,SIGNAL(triggered()),this,SLOT(chooseDestinationDirectory()));
expandAllAct= new QAction(QIcon(IMAGE_EXPAND),tr("Expand all"),this); expandAllAct= new QAction(QIcon(IMAGE_EXPAND),tr("Expand all"),this);
connect(expandAllAct,SIGNAL(triggered()),this,SLOT(expandAll())) ; connect(expandAllAct,SIGNAL(triggered()),this,SLOT(expandAll()));
collapseAllAct= new QAction(QIcon(IMAGE_COLLAPSE),tr("Collapse all"),this); collapseAllAct= new QAction(QIcon(IMAGE_COLLAPSE),tr("Collapse all"),this);
connect(collapseAllAct,SIGNAL(triggered()),this,SLOT(collapseAll())) ; connect(collapseAllAct,SIGNAL(triggered()),this,SLOT(collapseAll()));
collCreateAct= new QAction(QIcon(IMAGE_COLLCREATE), tr("Create Collection..."), this);
connect(collCreateAct,SIGNAL(triggered()),this,SLOT(collCreate()));
collModifAct= new QAction(QIcon(IMAGE_COLLMODIF), tr("Modify Collection..."), this);
connect(collModifAct,SIGNAL(triggered()),this,SLOT(collModif()));
collViewAct= new QAction(QIcon(IMAGE_COLLVIEW), tr("View Collection..."), this);
connect(collViewAct,SIGNAL(triggered()),this,SLOT(collView()));
collOpenAct = new QAction(QIcon(IMAGE_COLLOPEN), tr( "Download from collection file..." ), this );
connect(collOpenAct, SIGNAL(triggered()), this, SLOT(collOpen()));
/** Setup the actions for the header context menu */ /** Setup the actions for the header context menu */
showDLSizeAct= new QAction(tr("Size"),this); showDLSizeAct= new QAction(tr("Size"),this);
@ -618,23 +627,24 @@ void TransfersDialog::processSettings(bool bLoad)
void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ ) void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
{ {
std::set<RsFileHash> items; std::set<RsFileHash> items ;
getSelectedItems(&items, NULL); getSelectedItems(&items, NULL) ;
bool single = (items.size() == 1) ; bool single = (items.size() == 1) ;
bool atLeastOne_Waiting = false; bool atLeastOne_Waiting = false ;
bool atLeastOne_Downloading = false; bool atLeastOne_Downloading = false ;
bool atLeastOne_Complete = false; bool atLeastOne_Complete = false ;
bool atLeastOne_Queued = false; bool atLeastOne_Queued = false ;
bool atLeastOne_Paused = false; bool atLeastOne_Paused = false ;
bool add_PlayOption = false ;
bool add_PreviewOption=false ;
bool add_OpenFileOption = false ;
bool add_CopyLink = false ;
bool add_PasteLink = false ;
bool add_CollActions = false ;
bool add_PlayOption = false;
bool add_PreviewOption=false;
bool add_OpenFileOption = false;
bool add_CopyLink = false;
bool add_PasteLink = false;
FileInfo info; FileInfo info;
QMenu priorityQueueMenu(tr("Move in Queue..."), this); QMenu priorityQueueMenu(tr("Move in Queue..."), this);
@ -656,157 +666,168 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
chunkMenu.addAction(chunkProgressiveAct); chunkMenu.addAction(chunkProgressiveAct);
chunkMenu.addAction(chunkRandomAct); chunkMenu.addAction(chunkRandomAct);
QMenu collectionMenu(tr("Collection"), this);
collectionMenu.setIcon(QIcon(IMAGE_LIBRARY));
collectionMenu.addAction(collCreateAct);
collectionMenu.addAction(collModifAct);
collectionMenu.addAction(collViewAct);
collectionMenu.addAction(collOpenAct);
QMenu contextMnu( this ); QMenu contextMnu( this );
if(!RSLinkClipboard::empty(RetroShareLink::TYPE_FILE)) if(!RSLinkClipboard::empty(RetroShareLink::TYPE_FILE)) add_PasteLink=true;
add_PasteLink=true;
if(!items.empty()) if(!items.empty())
{ {
add_CopyLink = true; add_CopyLink = true ;
QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes (); QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes ();
//Look for all selected items //Look for all selected items
for (int i = 0; i < lst.count (); i++) for (int i = 0; i < lst.count(); i++) {
{ //Look only for first column == File List
//Look only for first column == File List if ( lst[i].column() == 0) {
if ( lst[i].column() == 0) //Get Info for current item
{ if (rsFiles->FileDetails(RsFileHash(getID(lst[i].row(), DLListModel).toStdString())
//Get Info for current item , RS_FILE_HINTS_DOWNLOAD, info)) {
if (rsFiles->FileDetails(RsFileHash(getID(lst[i].row(), DLListModel).toStdString()), RS_FILE_HINTS_DOWNLOAD, info)) /*const uint32_t FT_STATE_FAILED = 0x0000;
{ *const uint32_t FT_STATE_OKAY = 0x0001;
/*const uint32_t FT_STATE_FAILED = 0x0000 ; *const uint32_t FT_STATE_WAITING = 0x0002;
const uint32_t FT_STATE_OKAY = 0x0001 ; *const uint32_t FT_STATE_DOWNLOADING = 0x0003;
const uint32_t FT_STATE_WAITING = 0x0002 ; *const uint32_t FT_STATE_COMPLETE = 0x0004;
const uint32_t FT_STATE_DOWNLOADING = 0x0003 ; *const uint32_t FT_STATE_QUEUED = 0x0005;
const uint32_t FT_STATE_COMPLETE = 0x0004 ; *const uint32_t FT_STATE_PAUSED = 0x0006;
const uint32_t FT_STATE_QUEUED = 0x0005 ; *const uint32_t FT_STATE_CHECKING_HASH = 0x0007;
const uint32_t FT_STATE_PAUSED = 0x0006 ; */
const uint32_t FT_STATE_CHECKING_HASH = 0x0007 ; if (info.downloadStatus == FT_STATE_WAITING) {
*/ atLeastOne_Waiting = true ;
if (info.downloadStatus == FT_STATE_WAITING) }//if (info.downloadStatus == FT_STATE_WAITING)
{ if (info.downloadStatus == FT_STATE_DOWNLOADING) {
atLeastOne_Waiting = true; atLeastOne_Downloading=true ;
} }//if (info.downloadStatus == FT_STATE_DOWNLOADING)
if (info.downloadStatus == FT_STATE_DOWNLOADING) if (info.downloadStatus == FT_STATE_COMPLETE) {
{ atLeastOne_Complete = true ;
atLeastOne_Downloading=true; add_OpenFileOption = single ;
} }//if (info.downloadStatus == FT_STATE_COMPLETE)
if (info.downloadStatus == FT_STATE_COMPLETE) if (info.downloadStatus == FT_STATE_QUEUED) {
{ atLeastOne_Queued = true ;
atLeastOne_Complete = true; }//if(info.downloadStatus == FT_STATE_QUEUED)
add_OpenFileOption = single; if (info.downloadStatus == FT_STATE_PAUSED) {
} atLeastOne_Paused = true ;
if(info.downloadStatus == FT_STATE_QUEUED) }//if (info.downloadStatus == FT_STATE_PAUSED)
{
atLeastOne_Queued = true;
}
if (info.downloadStatus == FT_STATE_PAUSED)
{
atLeastOne_Paused = true;
}
size_t pos = info.fname.find_last_of('.'); size_t pos = info.fname.find_last_of('.') ;
/* check if the file is a media file */ if (pos != std::string::npos) {
if(pos != std::string::npos) // Check if the file is a media file
{ if (misc::isPreviewable(info.fname.substr(pos + 1).c_str())) {
if (misc::isPreviewable(info.fname.substr(pos + 1).c_str())) add_PreviewOption = (info.downloadStatus != FT_STATE_COMPLETE) ;
{ add_PlayOption = !add_PreviewOption ;
add_PreviewOption = (info.downloadStatus != FT_STATE_COMPLETE); }// if (misc::isPreviewable(info.fname.substr(pos + 1).c_str()))
add_PlayOption = !add_PreviewOption; // Check if the file is a collection
} if (RsCollectionFile::ExtensionString == info.fname.substr(pos + 1).c_str()) {
} add_CollActions = (info.downloadStatus == FT_STATE_COMPLETE);
}//if (RsCollectionFile::ExtensionString == info
}// if(pos != std::string::npos)
}//if (rsFiles->FileDetails(lst[i].data(COLUMN_ID), RS_FILE_HINTS_DOWNLOAD, info)) }// if (rsFiles->FileDetails(lst[i].data(COLUMN_ID), RS_FILE_HINTS_DOWNLOAD, info))
}//if (lst[i].column() == 0) }// if (lst[i].column() == 0)
}// for (int i = 0; i < lst.count (); i++) }// for (int i = 0; i < lst.count(); i++)
}//if(!items.empty()) }// if (!items.empty())
if(atLeastOne_Downloading) if (atLeastOne_Downloading) {
contextMnu.addMenu(&prioritySpeedMenu); contextMnu.addMenu( &prioritySpeedMenu) ;
if(atLeastOne_Queued) }//if (atLeastOne_Downloading)
contextMnu.addMenu(&priorityQueueMenu) ; if (atLeastOne_Queued) {
contextMnu.addMenu( &priorityQueueMenu) ;
}//if (atLeastOne_Queued)
if( (!items.empty()) && (atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting || atLeastOne_Paused)) if ( (!items.empty())
{ && (atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting || atLeastOne_Paused)) {
contextMnu.addMenu( &chunkMenu); contextMnu.addMenu(&chunkMenu) ;
if(single) if (single) {
contextMnu.addAction(renameFileAct) ; contextMnu.addAction( renameFileAct) ;
}//if (single)
QMenu *directoryMenu = contextMnu.addMenu(QIcon(IMAGE_OPENFOLDER),tr("Set destination directory")) ; QMenu *directoryMenu = contextMnu.addMenu(QIcon(IMAGE_OPENFOLDER), tr("Set destination directory")) ;
directoryMenu->addAction(specifyDestinationDirectoryAct); directoryMenu->addAction(specifyDestinationDirectoryAct) ;
// Now get the list of existing directories. // Now get the list of existing directories.
std::list<SharedDirInfo> dirs ; std::list< SharedDirInfo> dirs ;
rsFiles->getSharedDirectories(dirs) ; rsFiles->getSharedDirectories( dirs) ;
for(std::list<SharedDirInfo>::const_iterator it(dirs.begin());it!=dirs.end();++it) for (std::list<SharedDirInfo>::const_iterator it(dirs.begin());it!=dirs.end();++it){
{ // Check for existence of directory name
// check for existence of directory name QFile directory( QString::fromUtf8((*it).filename.c_str())) ;
QFile directory(QString::fromUtf8((*it).filename.c_str())) ;
if(!directory.exists()) continue ; if (!directory.exists()) continue ;
if(!(directory.permissions() & QFile::WriteOwner)) continue ; if (!(directory.permissions() & QFile::WriteOwner)) continue ;
QAction *act = new QAction(QString::fromUtf8((*it).virtualname.c_str()),directoryMenu) ; QAction *act = new QAction(QString::fromUtf8((*it).virtualname.c_str()), directoryMenu) ;
act->setData(QString::fromUtf8((*it).filename.c_str())) ; act->setData(QString::fromUtf8( (*it).filename.c_str() ) ) ;
connect(act,SIGNAL(triggered()),this,SLOT(setDestinationDirectory())) ; connect(act, SIGNAL(triggered()), this, SLOT(setDestinationDirectory())) ;
directoryMenu->addAction(act) ; directoryMenu->addAction( act) ;
} }//for (std::list<SharedDirInfo>::const_iterator it
} }//if ( (!items.empty()) &&
if(atLeastOne_Paused) if (atLeastOne_Paused) {
contextMnu.addAction( resumeAct); contextMnu.addAction(resumeAct) ;
if(atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting) }//if (atLeastOne_Paused)
contextMnu.addAction( pauseAct); if (atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting) {
contextMnu.addAction(pauseAct) ;
}//if (atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting)
if(!atLeastOne_Complete && !items.empty()) if (!atLeastOne_Complete && !items.empty()) {
{ contextMnu.addAction(forceCheckAct) ;
contextMnu.addAction( forceCheckAct); contextMnu.addAction(cancelAct) ;
contextMnu.addAction( cancelAct); }//if (!atLeastOne_Complete && !items.empty())
} if (add_PlayOption) {
if (add_PlayOption) contextMnu.addAction(playAct) ;
{ }//if (add_PlayOption)
contextMnu.addAction(playAct);
}
if(atLeastOne_Paused || atLeastOne_Downloading || atLeastOne_Complete || add_PlayOption) if (atLeastOne_Paused || atLeastOne_Downloading || atLeastOne_Complete || add_PlayOption) {
contextMnu.addSeparator();//------------------------------------------------ contextMnu.addSeparator() ;//------------------------------------------------
}//if (atLeastOne_Paused ||
if(single) if (single) {
{ if (add_OpenFileOption) contextMnu.addAction( openFileAct) ;
if (add_OpenFileOption) contextMnu.addAction( openFileAct); if (add_PreviewOption) contextMnu.addAction( previewFileAct) ;
if (add_PreviewOption) contextMnu.addAction( previewFileAct); contextMnu.addAction( openFolderAct) ;
contextMnu.addAction( openFolderAct); contextMnu.addAction( detailsFileAct) ;
contextMnu.addAction( detailsFileAct); contextMnu.addSeparator() ;//--------------------------------------------
contextMnu.addSeparator();//-------------------------------------------- }//if (single)
}
contextMnu.addAction( clearCompletedAct); contextMnu.addAction( clearCompletedAct) ;
contextMnu.addSeparator();//------------------------------------------------ contextMnu.addSeparator() ;//------------------------------------------------
if (add_CopyLink) if (add_CopyLink) {
contextMnu.addAction( copyLinkAct); contextMnu.addAction( copyLinkAct) ;
if (add_PasteLink) }//if (add_CopyLink)
contextMnu.addAction( pasteLinkAct); if (add_PasteLink) {
if (add_CopyLink || add_PasteLink) contextMnu.addAction( pasteLinkAct) ;
contextMnu.addSeparator();//-------------------------------------------- }//if (add_PasteLink)
if (add_CopyLink || add_PasteLink) {
contextMnu.addSeparator() ;//--------------------------------------------
}//if (add_CopyLink || add_PasteLink)
if (DLListModel->rowCount()>0 ) { if (DLListModel->rowCount()>0 ) {
contextMnu.addAction( expandAllAct ) ; contextMnu.addAction( expandAllAct ) ;
contextMnu.addAction( collapseAllAct ) ; contextMnu.addAction( collapseAllAct ) ;
} }
contextMnu.addSeparator();//----------------------------------------------- contextMnu.addSeparator() ;//-----------------------------------------------
contextMnu.addAction( toggleShowCacheTransfersAct ) ; contextMnu.addAction( toggleShowCacheTransfersAct ) ;
toggleShowCacheTransfersAct->setChecked(_show_cache_transfers) ; toggleShowCacheTransfersAct->setChecked(_show_cache_transfers) ;
contextMnu.addAction( openCollectionAct ) ;
collCreateAct->setEnabled(true) ;
contextMnu.exec(QCursor::pos()); collModifAct->setEnabled(single && add_CollActions) ;
collViewAct->setEnabled(single && add_CollActions) ;
collOpenAct->setEnabled(true) ;
contextMnu.addMenu(&collectionMenu) ;
contextMnu.exec(QCursor::pos()) ;
} }
void TransfersDialog::downloadListHeaderCustomPopupMenu( QPoint /*point*/ ) void TransfersDialog::downloadListHeaderCustomPopupMenu( QPoint /*point*/ )
@ -1777,8 +1798,8 @@ void TransfersDialog::openTransfer()
{ {
FileInfo info; FileInfo info;
std::set<RsFileHash> items; std::set<RsFileHash> items ;
std::set<RsFileHash>::iterator it; std::set<RsFileHash>::iterator it ;
getSelectedItems(&items, NULL); getSelectedItems(&items, NULL);
for (it = items.begin(); it != items.end(); it ++) { for (it = items.begin(); it != items.end(); it ++) {
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue; if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
@ -2049,13 +2070,130 @@ QString TransfersDialog::getSources(int row, QStandardItemModel *model)
return temp; return temp;
} }
void TransfersDialog::openCollection() void TransfersDialog::collCreate()
{ {
RsCollectionFile Collection; std::vector <DirDetails> dirVec;
if (Collection.load(this)) {
Collection.downloadFiles(); std::set<RsFileHash> items ;
} std::set<RsFileHash>::iterator it ;
getSelectedItems(&items, NULL);
for (it = items.begin(); it != items.end(); it ++) {
FileInfo info;
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
DirDetails details;
details.name = info.fname;
details.hash = info.hash;
details.count = info.size;
details.type = DIR_TYPE_FILE;
dirVec.push_back(details);
}//for (it = items.begin();
RsCollectionFile(dirVec).openNewColl(this);
} }
void TransfersDialog::collModif()
{
FileInfo info;
std::set<RsFileHash> items ;
std::set<RsFileHash>::iterator it ;
getSelectedItems(&items, NULL);
if (items.size() != 1) return;
it = items.begin();
RsFileHash hash = *it;
if (!rsFiles->FileDetails(hash, RS_FILE_HINTS_DOWNLOAD, info)) return;
/* make path for downloaded files */
if (info.downloadStatus == FT_STATE_COMPLETE) {
std::string path;
path = info.path + "/" + info.fname;
/* open collection */
QFileInfo qinfo;
qinfo.setFile(QString::fromUtf8(path.c_str()));
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
collection.openColl(qinfo.absoluteFilePath());
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
}//if (qinfo.exists())
}//if (info.downloadStatus == FT_STATE_COMPLETE)
}
void TransfersDialog::collView()
{
FileInfo info;
std::set<RsFileHash> items;
std::set<RsFileHash>::iterator it;
getSelectedItems(&items, NULL);
if (items.size() != 1) return;
it = items.begin();
RsFileHash hash = *it;
if (!rsFiles->FileDetails(hash, RS_FILE_HINTS_DOWNLOAD, info)) return;
/* make path for downloaded files */
if (info.downloadStatus == FT_STATE_COMPLETE) {
std::string path;
path = info.path + "/" + info.fname;
/* open collection */
QFileInfo qinfo;
qinfo.setFile(QString::fromUtf8(path.c_str()));
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
collection.openColl(qinfo.absoluteFilePath(), true);
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
}//if (qinfo.exists())
}//if (info.downloadStatus == FT_STATE_COMPLETE)
}
void TransfersDialog::collOpen()
{
FileInfo info;
std::set<RsFileHash> items;
std::set<RsFileHash>::iterator it;
getSelectedItems(&items, NULL);
if (items.size() == 1) {
it = items.begin();
RsFileHash hash = *it;
if (rsFiles->FileDetails(hash, RS_FILE_HINTS_DOWNLOAD, info)) {
/* make path for downloaded files */
if (info.downloadStatus == FT_STATE_COMPLETE) {
std::string path;
path = info.path + "/" + info.fname;
/* open file with a suitable application */
QFileInfo qinfo;
qinfo.setFile(QString::fromUtf8(path.c_str()));
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
if (collection.load(qinfo.absoluteFilePath(), this)) {
collection.downloadFiles();
return;
}//if (collection.load(this))
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
}//if (qinfo.exists())
}//if (info.downloadStatus == FT_STATE_COMPLETE)
}//if (rsFiles->FileDetails(
}//if (items.size() == 1)
RsCollectionFile collection;
if (collection.load(this)) {
collection.downloadFiles();
}//if (collection.load(this))
}
void TransfersDialog::setShowDLSizeColumn(bool show) void TransfersDialog::setShowDLSizeColumn(bool show)
{ {
if (!ui.downloadList->isColumnHidden(COLUMN_SIZE) != show) { if (!ui.downloadList->isColumnHidden(COLUMN_SIZE) != show) {

View File

@ -131,13 +131,16 @@ private slots:
void chunkProgressive(); void chunkProgressive();
void chunkStreaming(); void chunkStreaming();
void showDetailsDialog(); void showDetailsDialog();
void updateDetailsDialog(); void updateDetailsDialog();
void openCollection(); void collCreate();
void collModif();
void setShowDLSizeColumn(bool show); void collView();
void setShowDLCompleteColumn(bool show); void collOpen();
void setShowDLSizeColumn(bool show);
void setShowDLCompleteColumn(bool show);
void setShowDLDLSpeedColumn(bool show); void setShowDLDLSpeedColumn(bool show);
void setShowDLProgressColumn(bool show); void setShowDLProgressColumn(bool show);
void setShowDLSourcesColumn(bool show); void setShowDLSourcesColumn(bool show);
@ -164,21 +167,21 @@ private:
ULListDelegate *ULDelegate; ULListDelegate *ULDelegate;
/** Create the actions on the tray menu or menubar */ /** Create the actions on the tray menu or menubar */
void createActions(); void createActions();
/** Defines the actions for the context menu */ /** Defines the actions for the context menu */
QAction* showdownInfoAct; QAction *showdownInfoAct;
QAction* playAct; QAction *playAct;
QAction* cancelAct; QAction *cancelAct;
QAction* forceCheckAct; QAction *forceCheckAct;
QAction* clearCompletedAct; QAction *clearCompletedAct;
QAction* copyLinkAct; QAction *copyLinkAct;
QAction* pasteLinkAct; QAction *pasteLinkAct;
QAction* rootIsNotDecoratedAct; QAction *rootIsNotDecoratedAct;
QAction* rootIsDecoratedAct; QAction *rootIsDecoratedAct;
QAction *pauseAct; QAction *pauseAct;
QAction *resumeAct; QAction *resumeAct;
QAction *openFolderAct; QAction *openFolderAct;
QAction *openFileAct; QAction *openFileAct;
QAction *previewFileAct; QAction *previewFileAct;
// QAction *clearQueuedDwlAct; // QAction *clearQueuedDwlAct;
@ -193,17 +196,20 @@ private:
QAction *queueBottomAct; QAction *queueBottomAct;
QAction *chunkRandomAct; QAction *chunkRandomAct;
QAction *chunkProgressiveAct; QAction *chunkProgressiveAct;
QAction *chunkStreamingAct; QAction *chunkStreamingAct;
QAction *detailsFileAct; QAction *detailsFileAct;
QAction *toggleShowCacheTransfersAct; QAction *toggleShowCacheTransfersAct;
QAction *openCollectionAct; QAction *renameFileAct;
QAction *renameFileAct; QAction *specifyDestinationDirectoryAct;
QAction *specifyDestinationDirectoryAct; QAction *expandAllAct;
QAction *expandAllAct; QAction *collapseAllAct;
QAction *collapseAllAct; QAction *collCreateAct;
QAction *collModifAct;
/** Defines the actions for the header context menu */ QAction *collViewAct;
QAction* showDLSizeAct; QAction *collOpenAct;
/** Defines the actions for the header context menu */
QAction* showDLSizeAct;
QAction* showDLCompleteAct; QAction* showDLCompleteAct;
QAction* showDLDLSpeedAct; QAction* showDLDLSpeedAct;
QAction* showDLProgressAct; QAction* showDLProgressAct;

View File

@ -100,6 +100,7 @@
#include "gui/Posted/PostedDialog.h" #include "gui/Posted/PostedDialog.h"
#include "gui/connect/ConnectFriendWizard.h" #include "gui/connect/ConnectFriendWizard.h"
#include "gui/common/RsCollectionFile.h"
#include "util/rsguiversion.h" #include "util/rsguiversion.h"
#include "settings/rsettingswin.h" #include "settings/rsettingswin.h"
#include "settings/rsharesettings.h" #include "settings/rsharesettings.h"
@ -149,6 +150,7 @@
#define IMAGE_GAMES ":/images/kgames.png" #define IMAGE_GAMES ":/images/kgames.png"
#define IMAGE_PHOTO ":/images/lphoto.png" #define IMAGE_PHOTO ":/images/lphoto.png"
#define IMAGE_ADDFRIEND ":/images/user/add_user24.png" #define IMAGE_ADDFRIEND ":/images/user/add_user24.png"
#define IMAGE_NEWRSCOLLECTION ":/images/library.png"
#define IMAGE_ADDSHARE ":/images/directoryadd_24x24_shadow.png" #define IMAGE_ADDSHARE ":/images/directoryadd_24x24_shadow.png"
#define IMAGE_OPTIONS ":/images/settings.png" #define IMAGE_OPTIONS ":/images/settings.png"
#define IMAGE_QUIT ":/images/exit_24x24.png" #define IMAGE_QUIT ":/images/exit_24x24.png"
@ -480,6 +482,7 @@ void MainWindow::initStackedPage()
/** Add icon on Action bar */ /** Add icon on Action bar */
addAction(new QAction(QIcon(IMAGE_ADDFRIEND), tr("Add"), ui->toolBarAction), &MainWindow::addFriend, SLOT(addFriend())); addAction(new QAction(QIcon(IMAGE_ADDFRIEND), tr("Add"), ui->toolBarAction), &MainWindow::addFriend, SLOT(addFriend()));
addAction(new QAction(QIcon(IMAGE_NEWRSCOLLECTION), tr("New"), ui->toolBarAction), &MainWindow::newRsCollection, SLOT(newRsCollection()));
addAction(new QAction(QIcon(IMAGE_PREFERENCES), tr("Options"), ui->toolBarAction), &MainWindow::showSettings, SLOT(showSettings())); addAction(new QAction(QIcon(IMAGE_PREFERENCES), tr("Options"), ui->toolBarAction), &MainWindow::showSettings, SLOT(showSettings()));
addAction(new QAction(QIcon(IMAGE_ABOUT), tr("About"), ui->toolBarAction), &MainWindow::showabout, SLOT(showabout())); addAction(new QAction(QIcon(IMAGE_ABOUT), tr("About"), ui->toolBarAction), &MainWindow::showabout, SLOT(showabout()));
addAction(new QAction(QIcon(IMAGE_QUIT), tr("Quit"), ui->toolBarAction), &MainWindow::doQuit, SLOT(doQuit())); addAction(new QAction(QIcon(IMAGE_QUIT), tr("Quit"), ui->toolBarAction), &MainWindow::doQuit, SLOT(doQuit()));
@ -1050,6 +1053,14 @@ void MainWindow::addFriend()
connwiz.exec (); connwiz.exec ();
} }
/** New RSCollection ShortCut */
void MainWindow::newRsCollection()
{
std::vector <DirDetails> dirVec;
RsCollectionFile(dirVec).openNewColl(this);
}
/** Shows Share Manager */ /** Shows Share Manager */
void MainWindow::openShareManager() void MainWindow::openShareManager()
{ {

View File

@ -192,6 +192,7 @@ private slots:
/** Toolbar fns. */ /** Toolbar fns. */
void addFriend(); void addFriend();
void newRsCollection();
void showMessengerWindow(); void showMessengerWindow();
void showDhtWindow(); void showDhtWindow();
void showBwCtrlWindow(); void showBwCtrlWindow();

View File

@ -915,16 +915,16 @@ const DirDetailsVector *RetroshareDirModel::requestDirDetails(void *ref, bool re
void RetroshareDirModel::createCollectionFile(QWidget *parent, const QModelIndexList &list) void RetroshareDirModel::createCollectionFile(QWidget *parent, const QModelIndexList &list)
{ {
if(RemoteMode) /* if(RemoteMode)
{ {
std::cerr << "Cannot create a collection file from remote" << std::endl; std::cerr << "Cannot create a collection file from remote" << std::endl;
return ; return ;
} }*/
std::vector <DirDetails> dirVec; std::vector <DirDetails> dirVec;
getDirDetailsFromSelect(list, dirVec); getDirDetailsFromSelect(list, dirVec);
RsCollectionFile(dirVec).save(parent); RsCollectionFile(dirVec).openNewColl(parent);
} }
void RetroshareDirModel::downloadSelected(const QModelIndexList &list) void RetroshareDirModel::downloadSelected(const QModelIndexList &list)
@ -980,7 +980,7 @@ void RetroshareDirModel::downloadDirectory(const DirDetails & dirDetails, int pr
{ {
if (dirDetails.type & DIR_TYPE_FILE) if (dirDetails.type & DIR_TYPE_FILE)
{ {
std::list<RsPeerId> srcIds; std::list<RsPeerId> srcIds ;
QString cleanPath = QDir::cleanPath(QString::fromUtf8(rsFiles->getDownloadDirectory().c_str()) + "/" + QString::fromUtf8(dirDetails.path.substr(prefixLen).c_str())); QString cleanPath = QDir::cleanPath(QString::fromUtf8(rsFiles->getDownloadDirectory().c_str()) + "/" + QString::fromUtf8(dirDetails.path.substr(prefixLen).c_str()));
srcIds.push_back(dirDetails.id); srcIds.push_back(dirDetails.id);

View File

@ -75,7 +75,7 @@ class RetroshareDirModel : public QAbstractItemModel
void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; } void changeAgeIndicator(uint32_t indicator) { ageIndicator = indicator; }
const DirDetailsVector *requestDirDetails(void *ref, bool remote) const; const DirDetailsVector *requestDirDetails(void *ref, bool remote) const;
virtual void update() {} ; virtual void update() {}
public: public:
virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const; virtual QMimeData * mimeData ( const QModelIndexList & indexes ) const;

View File

@ -45,25 +45,30 @@
/* Images for context menu icons */ /* Images for context menu icons */
#define IMAGE_START ":/images/download.png" #define IMAGE_START ":/images/download.png"
#define IMAGE_REMOVE ":/images/delete.png" #define IMAGE_REMOVE ":/images/delete.png"
#define IMAGE_REMOVEALL ":/images/deleteall.png" #define IMAGE_REMOVEALL ":/images/deleteall.png"
#define IMAGE_DIRECTORY ":/images/folder16.png" #define IMAGE_DIRECTORY ":/images/folder16.png"
#define IMAGE_OPENFOLDER ":/images/folderopen.png" #define IMAGE_OPENFOLDER ":/images/folderopen.png"
#define IMAGE_LIBRARY ":/images/library.png"
#define IMAGE_COLLCREATE ":/images/library_add.png"
#define IMAGE_COLLMODIF ":/images/library_edit.png"
#define IMAGE_COLLVIEW ":/images/library_view.png"
#define IMAGE_COLLOPEN ":/images/library.png"
#define IMAGE_COPYLINK ":/images/copyrslink.png"
/* Key for UI Preferences */ /* Key for UI Preferences */
#define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch" #define UI_PREF_ADVANCED_SEARCH "UIOptions/AdvancedSearch"
/* indicies for search summary item columns SS_ = Search Summary */ /* indicies for search summary item columns SS_ = Search Summary */
#define SS_TEXT_COL 0 #define SS_KEYWORDS_COL 0
#define SS_COUNT_COL 1 #define SS_RESULTS_COL 1
#define SS_SEARCH_ID_COL 2 #define SS_SEARCH_ID_COL 2
#define SS_FILE_TYPE_COL 3 #define SS_FILE_TYPE_COL 3
#define SS_DATA_COL SS_TEXT_COL #define SS_COL_COUNT 3 //4 ???
#define SS_DATA_COL SS_KEYWORDS_COL
#define ROLE_KEYWORDS Qt::UserRole #define ROLE_KEYWORDS Qt::UserRole
#define ROLE_SORT Qt::UserRole + 1 #define ROLE_SORT Qt::UserRole + 1
#define IMAGE_COPYLINK ":/images/copyrslink.png"
/* static members */ /* static members */
/* These indices MUST be identical to their equivalent indices in the combobox */ /* These indices MUST be identical to their equivalent indices in the combobox */
const int SearchDialog::FILETYPE_IDX_ANY = 0; const int SearchDialog::FILETYPE_IDX_ANY = 0;
@ -89,20 +94,29 @@ SearchDialog::SearchDialog(QWidget *parent)
m_bProcessSettings = false; m_bProcessSettings = false;
_queueIsAlreadyTakenCareOf = false ; _queueIsAlreadyTakenCareOf = false;
ui.lineEdit->setFocus(); ui.lineEdit->setFocus();
collCreateAct= new QAction(QIcon(IMAGE_COLLCREATE), tr("Create Collection..."), this);
connect(collCreateAct,SIGNAL(triggered()),this,SLOT(collCreate()));
collModifAct= new QAction(QIcon(IMAGE_COLLMODIF), tr("Modify Collection..."), this);
connect(collModifAct,SIGNAL(triggered()),this,SLOT(collModif()));
collViewAct= new QAction(QIcon(IMAGE_COLLVIEW), tr("View Collection..."), this);
connect(collViewAct,SIGNAL(triggered()),this,SLOT(collView()));
collOpenAct = new QAction(QIcon(IMAGE_COLLOPEN), tr( "Download from collection file..." ), this );
connect(collOpenAct, SIGNAL(triggered()), this, SLOT(collOpen()));
/* initialise the filetypes mapping */ /* initialise the filetypes mapping */
if (!SearchDialog::initialised) if (!SearchDialog::initialised)
{ {
initialiseFileTypeMappings(); initialiseFileTypeMappings() ;
} }
connect(ui.toggleAdvancedSearchBtn, SIGNAL(clicked()), this, SLOT(showAdvSearchDialog())); connect(ui.toggleAdvancedSearchBtn, SIGNAL(clicked()), this, SLOT(showAdvSearchDialog()));
connect( ui.searchResultWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidgetCostumPopupMenu( QPoint ) ) ); connect( ui.searchResultWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchResultWidgetCustomPopupMenu( QPoint ) ) );
connect( ui.searchSummaryWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchtableWidget2CostumPopupMenu( QPoint ) ) ); connect( ui.searchSummaryWidget, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( searchSummaryWidgetCustomPopupMenu( QPoint ) ) );
connect( ui.lineEdit, SIGNAL( returnPressed ( void ) ), this, SLOT( searchKeywords( void ) ) ); connect( ui.lineEdit, SIGNAL( returnPressed ( void ) ), this, SLOT( searchKeywords( void ) ) );
connect( ui.lineEdit, SIGNAL( textChanged ( const QString& ) ), this, SLOT( checkText( const QString& ) ) ); connect( ui.lineEdit, SIGNAL( textChanged ( const QString& ) ), this, SLOT( checkText( const QString& ) ) );
@ -121,12 +135,12 @@ SearchDialog::SearchDialog(QWidget *parent)
connect(ui.filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterItems())); connect(ui.filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterItems()));
compareSummaryRole = new RSTreeWidgetItemCompareRole; compareSummaryRole = new RSTreeWidgetItemCompareRole;
compareSummaryRole->setRole(SS_COUNT_COL, ROLE_SORT); compareSummaryRole->setRole(SS_RESULTS_COL, ROLE_SORT);
compareResultRole = new RSTreeWidgetItemCompareRole; compareResultRole = new RSTreeWidgetItemCompareRole;
compareResultRole->setRole(SR_SIZE_COL, ROLE_SORT); compareResultRole->setRole(SR_SIZE_COL, ROLE_SORT);
compareResultRole->setRole(SR_AGE_COL, ROLE_SORT); compareResultRole->setRole(SR_AGE_COL, ROLE_SORT);
compareResultRole->setRole(SR_ID_COL, ROLE_SORT); compareResultRole->setRole(SR_SOURCES_COL, ROLE_SORT);
/* hide the Tree +/- */ /* hide the Tree +/- */
ui.searchResultWidget -> setRootIsDecorated( true ); ui.searchResultWidget -> setRootIsDecorated( true );
@ -134,43 +148,43 @@ SearchDialog::SearchDialog(QWidget *parent)
ui.searchSummaryWidget -> setRootIsDecorated( false ); ui.searchSummaryWidget -> setRootIsDecorated( false );
// We set some delegates to handle the display of size and date. // We set some delegates to handle the display of size and date.
// To allow a proper sorting, be careful to pad at right with spaces. This // To allow a proper sorting, be careful to pad at right with spaces. This
// is achieved by using QString("%1").arg(number,15,10). // is achieved by using QString("%1").arg(number,15,10).
// //
ui.searchResultWidget->setItemDelegateForColumn(SR_SIZE_COL,new RSHumanReadableSizeDelegate()) ; ui.searchResultWidget->setItemDelegateForColumn(SR_SIZE_COL, new RSHumanReadableSizeDelegate()) ;
ui.searchResultWidget->setItemDelegateForColumn(SR_AGE_COL,new RSHumanReadableAgeDelegate()) ; ui.searchResultWidget->setItemDelegateForColumn(SR_AGE_COL, new RSHumanReadableAgeDelegate()) ;
/* make it extended selection */ /* make it extended selection */
ui.searchResultWidget -> setSelectionMode(QAbstractItemView::ExtendedSelection); ui.searchResultWidget -> setSelectionMode(QAbstractItemView::ExtendedSelection);
/* Set header resize modes and initial section sizes */ /* Set header resize modes and initial section sizes */
ui.searchSummaryWidget->setColumnCount(3); ui.searchSummaryWidget->setColumnCount(SS_COL_COUNT);
ui.searchSummaryWidget->setColumnHidden ( 2, true); ui.searchSummaryWidget->setColumnHidden(SS_SEARCH_ID_COL, true);
QHeaderView * _smheader = ui.searchSummaryWidget->header () ; QHeaderView * _smheader = ui.searchSummaryWidget->header () ;
QHeaderView_setSectionResizeMode(_smheader, 0, QHeaderView::Interactive); QHeaderView_setSectionResizeMode(_smheader, SS_KEYWORDS_COL, QHeaderView::Interactive);
QHeaderView_setSectionResizeMode(_smheader, 1, QHeaderView::Interactive); QHeaderView_setSectionResizeMode(_smheader, SS_RESULTS_COL, QHeaderView::Interactive);
_smheader->resizeSection ( 0, 160 ); _smheader->resizeSection ( SS_KEYWORDS_COL, 160 );
_smheader->resizeSection ( 1, 50 ); _smheader->resizeSection ( SS_RESULTS_COL, 50 );
ui.searchResultWidget->setColumnCount(6); ui.searchResultWidget->setColumnCount(SR_COL_COUNT);
_smheader = ui.searchResultWidget->header () ; _smheader = ui.searchResultWidget->header () ;
QHeaderView_setSectionResizeMode(_smheader, 0, QHeaderView::Interactive); QHeaderView_setSectionResizeMode(_smheader, SR_NAME_COL, QHeaderView::Interactive);
QHeaderView_setSectionResizeMode(_smheader, 1, QHeaderView::Interactive); QHeaderView_setSectionResizeMode(_smheader, SR_SIZE_COL, QHeaderView::Interactive);
QHeaderView_setSectionResizeMode(_smheader, 2, QHeaderView::Interactive); QHeaderView_setSectionResizeMode(_smheader, SR_SOURCES_COL, QHeaderView::Interactive);
_smheader->resizeSection ( 0, 240 ); _smheader->resizeSection ( SR_NAME_COL, 240 );
_smheader->resizeSection ( 1, 75 ); _smheader->resizeSection ( SR_SIZE_COL, 75 );
_smheader->resizeSection ( 2, 75 ); _smheader->resizeSection ( SR_SOURCES_COL, 75 );
_smheader->resizeSection ( 3, 75 ); _smheader->resizeSection ( SR_TYPE_COL, 75 );
_smheader->resizeSection ( 4, 90 ); _smheader->resizeSection ( SR_AGE_COL, 90 );
_smheader->resizeSection ( 5, 240 ); _smheader->resizeSection ( SR_HASH_COL, 240 );
// set header text aligment // set header text aligment
QTreeWidgetItem * headerItem = ui.searchResultWidget->headerItem(); QTreeWidgetItem * headerItem = ui.searchResultWidget->headerItem();
headerItem->setTextAlignment(1, Qt::AlignRight | Qt::AlignRight); headerItem->setTextAlignment(SR_NAME_COL, Qt::AlignRight | Qt::AlignRight);
headerItem->setTextAlignment(2, Qt::AlignRight | Qt::AlignRight); headerItem->setTextAlignment(SR_SIZE_COL, Qt::AlignRight | Qt::AlignRight);
ui.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder); ui.searchResultWidget->sortItems(SR_NAME_COL, Qt::AscendingOrder);
@ -181,7 +195,7 @@ SearchDialog::SearchDialog(QWidget *parent)
/* add filter actions */ /* add filter actions */
ui.filterLineEdit->addFilter(QIcon(), tr("File Name"), SR_NAME_COL); ui.filterLineEdit->addFilter(QIcon(), tr("File Name"), SR_NAME_COL);
// ui.filterLineEdit->addFilter(QIcon(), tr("File Size"), SR_SIZE_COL); //ui.filterLineEdit->addFilter(QIcon(), tr("File Size"), SR_SIZE_COL);
ui.filterLineEdit->setCurrentFilter(SR_NAME_COL); ui.filterLineEdit->setCurrentFilter(SR_NAME_COL);
// load settings // load settings
@ -189,11 +203,11 @@ SearchDialog::SearchDialog(QWidget *parent)
ui._ownFiles_CB->setMinimumWidth(20); ui._ownFiles_CB->setMinimumWidth(20);
ui._friendListsearch_SB->setMinimumWidth(20); ui._friendListsearch_SB->setMinimumWidth(20);
ui._anonF2Fsearch_CB->setMinimumWidth(20); ui._anonF2Fsearch_CB->setMinimumWidth(20);
ui.label->setMinimumWidth(20); ui.label->setMinimumWidth(20);
// workaround for Qt bug, should be solved in next Qt release 4.7.0 // workaround for Qt bug, be solved in next Qt release 4.7.0
// http://bugreports.qt.nokia.com/browse/QTBUG-8270 // https://bugreports.qt-project.org/browse/QTBUG-8270
QShortcut *Shortcut = new QShortcut(QKeySequence (Qt::Key_Delete), ui.searchSummaryWidget, 0, 0, Qt::WidgetShortcut); QShortcut *Shortcut = new QShortcut(QKeySequence (Qt::Key_Delete), ui.searchSummaryWidget, 0, 0, Qt::WidgetShortcut);
connect(Shortcut, SIGNAL(activated()), this, SLOT(searchRemove())); connect(Shortcut, SIGNAL(activated()), this, SLOT(searchRemove()));
@ -300,29 +314,49 @@ void SearchDialog::initialiseFileTypeMappings()
SearchDialog::initialised = true; SearchDialog::initialised = true;
} }
void SearchDialog::searchtableWidgetCostumPopupMenu( QPoint /*point*/ ) void SearchDialog::searchResultWidgetCustomPopupMenu( QPoint /*point*/ )
{ {
// block the popup if no results available // Block the popup if no results available
if ((ui.searchResultWidget->selectedItems()).size() == 0) return; if ((ui.searchResultWidget->selectedItems()).size() == 0) return ;
QMenu contextMnu(this); bool add_CollActions = false ;
contextMnu.addAction(QIcon(IMAGE_START), tr("Download"), this, SLOT(download())); QMenu contextMnu(this) ;
contextMnu.addSeparator();
contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyResultLink()));
contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Send RetroShare Link"), this, SLOT(sendLinkTo()));
// contextMnu.addAction(tr("Broadcast on Channel"), this, SLOT(broadcastonchannel())); contextMnu.addAction(QIcon(IMAGE_START), tr("Download"), this, SLOT(download())) ;
// contextMnu.addAction(tr("Recommend to Friends"), this, SLOT(recommendtofriends())); contextMnu.addSeparator();//--------------------------------------
if (ui.searchResultWidget->selectedItems().size() == 1){ contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Copy RetroShare Link"), this, SLOT(copyResultLink())) ;
QList<QTreeWidgetItem*> item =ui.searchResultWidget->selectedItems(); contextMnu.addAction(QIcon(IMAGE_COPYLINK), tr("Send RetroShare Link"), this, SLOT(sendLinkTo())) ;
if (item.at(0)->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool()){ contextMnu.addSeparator();//--------------------------------------
contextMnu.addAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this, SLOT(openFolderSearch()));
}
}
contextMnu.exec(QCursor::pos()); QMenu collectionMenu(tr("Collection"), this);
collectionMenu.setIcon(QIcon(IMAGE_LIBRARY));
collectionMenu.addAction(collCreateAct);
collectionMenu.addAction(collModifAct);
collectionMenu.addAction(collViewAct);
collectionMenu.addAction(collOpenAct);
//contextMnu.addAction(tr("Broadcast on Channel"), this, SLOT(broadcastonchannel()));
//contextMnu.addAction(tr("Recommend to Friends"), this, SLOT(recommendtofriends()));
if (ui.searchResultWidget->selectedItems().size() == 1) {
QList<QTreeWidgetItem*> item =ui.searchResultWidget->selectedItems() ;
if (item.at(0)->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool()) {
contextMnu.addAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this, SLOT(openFolderSearch())) ;
if (item.at(0)->text(SR_NAME_COL).endsWith(RsCollectionFile::ExtensionString)) {
add_CollActions = true ;
}//if (item.at(0)->text(SR_NAME_COL).endsWith(RsCollectionFile::ExtensionString))
}//if (item.at(0)->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool())
}//if (ui.searchResultWidget->selectedItems().size() == 1)
collCreateAct->setEnabled(true) ;
collModifAct->setEnabled(add_CollActions) ;
collViewAct->setEnabled(add_CollActions) ;
collOpenAct->setEnabled(true) ;
contextMnu.addMenu(&collectionMenu) ;
contextMnu.exec(QCursor::pos()) ;
} }
void SearchDialog::getSourceFriendsForHash(const RsFileHash& hash,std::list<RsPeerId>& srcIds) void SearchDialog::getSourceFriendsForHash(const RsFileHash& hash,std::list<RsPeerId>& srcIds)
@ -342,40 +376,178 @@ void SearchDialog::getSourceFriendsForHash(const RsFileHash& hash,std::list<RsPe
void SearchDialog::download() void SearchDialog::download()
{ {
/* should also be able to handle multi-selection */ /* should also be able to handle multi-selection */
QList<QTreeWidgetItem*> itemsForDownload = ui.searchResultWidget->selectedItems(); QList<QTreeWidgetItem*> itemsForDownload = ui.searchResultWidget->selectedItems() ;
int numdls = itemsForDownload.size(); int numdls = itemsForDownload.size() ;
QTreeWidgetItem * item; QTreeWidgetItem * item ;
bool attemptDownloadLocal = false; bool attemptDownloadLocal = false ;
for (int i = 0; i < numdls; ++i) for (int i = 0; i < numdls; ++i) {
{ item = itemsForDownload.at(i) ;
item = itemsForDownload.at(i); // call the download
// call the download // *
// if (item->text(SR_HASH_COL).isEmpty()) { // we have a folder
if (item->text(SR_HASH_COL).isEmpty()) // we have a folder downloadDirectory(item, tr("")) ;
downloadDirectory(item, tr("")); } else {
else std::cerr << "SearchDialog::download() Calling File Request" << std::endl ;
{ std::list<RsPeerId> srcIds ;
std::cerr << "SearchDialog::download() Calling File Request";
std::cerr << std::endl;
std::list<RsPeerId> srcIds;
RsFileHash hash ( item->text(SR_HASH_COL).toStdString()); RsFileHash hash( item->text(SR_HASH_COL).toStdString()) ;
getSourceFriendsForHash(hash,srcIds) ; getSourceFriendsForHash( hash, srcIds) ;
if(!rsFiles -> FileRequest((item->text(SR_NAME_COL)).toUtf8().constData(), hash, (item->text(SR_SIZE_COL)).toULongLong(), "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds)) if(!rsFiles -> FileRequest( (item->text(SR_NAME_COL)).toUtf8().constData()
attemptDownloadLocal = true ; , hash, (item->text(SR_SIZE_COL)).toULongLong()
else , "", RS_FILE_REQ_ANONYMOUS_ROUTING, srcIds)) {
{ attemptDownloadLocal = true;
std::cout << "isuing file request from search dialog: -" << (item->text(SR_NAME_COL)).toStdString() << "-" << hash << "-" << (item->text(SR_SIZE_COL)).toULongLong() << "-ids=" ; } else {
for(std::list<RsPeerId>::const_iterator it(srcIds.begin());it!=srcIds.end();++it) std::cout << "isuing file request from search dialog: -"
std::cout << *it << "-" << std::endl ; << (item->text(SR_NAME_COL)).toStdString()
} << "-" << hash << "-" << (item->text(SR_SIZE_COL)).toULongLong() << "-ids=" ;
} for(std::list<RsPeerId>::const_iterator it(srcIds.begin()); it!=srcIds.end(); ++it) {
} std::cout << *it << "-" << std::endl;
if (attemptDownloadLocal) }//for(std::list<RsPeerId>::const_iterator
QMessageBox::information(this, tr("Download Notice"), tr("Skipping Local Files")); }//if(!rsFiles -> FileRequest(
}//if (item->text(SR_HASH_COL).isEmpty())
}//for (int i = 0
if (attemptDownloadLocal) {
QMessageBox::information(this, tr("Download Notice"), tr("Skipping Local Files")) ;
}//if (attemptDownloadLocal)
}
void SearchDialog::collCreate()
{
std::vector <DirDetails> dirVec;
QList<QTreeWidgetItem*> selectedItems = ui.searchResultWidget->selectedItems() ;
int selectedCount = selectedItems.size() ;
QTreeWidgetItem * item ;
for (int i = 0; i < selectedCount; ++i) {
item = selectedItems.at(i) ;
if (!item->text(SR_HASH_COL).isEmpty()) {
std::string name = item->text(SR_NAME_COL).toUtf8().constData();
RsFileHash hash( item->text(SR_HASH_COL).toStdString() );
uint64_t count = item->text(SR_SIZE_COL).toULongLong();
DirDetails details;
details.name = name;
details.hash = hash;
details.count = count;
details.type = DIR_TYPE_FILE;
dirVec.push_back(details);
}//if (!item->text(SR_HASH_COL).isEmpty())
}//for (int i = 0; i < numdls; ++i)
RsCollectionFile(dirVec).openNewColl(this);
}
void SearchDialog::collModif()
{
FileInfo info;
QList<QTreeWidgetItem*> selectedItems = ui.searchResultWidget->selectedItems() ;
if (selectedItems.size() != 1) return;
QTreeWidgetItem* item ;
item = selectedItems.at(0) ;
if (!item->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool()) return;
RsFileHash hash( item->text(SR_HASH_COL).toStdString() );
if (!rsFiles->FileDetails(hash, RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE
| RS_FILE_HINTS_SPEC_ONLY, info)) return;
/* make path for downloaded files */
std::string path;
path = info.path;
/* open file with a suitable application */
QFileInfo qinfo;
qinfo.setFile(QString::fromUtf8(path.c_str()));
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
collection.openColl(qinfo.absoluteFilePath());
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
}//if (qinfo.exists())
}
void SearchDialog::collView()
{
FileInfo info;
QList<QTreeWidgetItem*> selectedItems = ui.searchResultWidget->selectedItems() ;
if (selectedItems.size() != 1) return;
QTreeWidgetItem* item ;
item = selectedItems.at(0) ;
if (!item->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool()) return;
RsFileHash hash( item->text(SR_HASH_COL).toStdString() );
if (!rsFiles->FileDetails(hash, RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE
| RS_FILE_HINTS_SPEC_ONLY, info)) return;
/* make path for downloaded files */
std::string path;
path = info.path;
/* open file with a suitable application */
QFileInfo qinfo;
qinfo.setFile(QString::fromUtf8(path.c_str()));
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
collection.openColl(qinfo.absoluteFilePath(), true);
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
}//if (qinfo.exists())
}
void SearchDialog::collOpen()
{
FileInfo info;
QList<QTreeWidgetItem*> selectedItems = ui.searchResultWidget->selectedItems() ;
if (selectedItems.size() == 1) {
QTreeWidgetItem* item ;
item = selectedItems.at(0) ;
if (item->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool()) {
RsFileHash hash( item->text(SR_HASH_COL).toStdString() );
if (rsFiles->FileDetails(hash, RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE
| RS_FILE_HINTS_SPEC_ONLY, info)) {
/* make path for downloaded files */
std::string path;
path = info.path;
/* open file with a suitable application */
QFileInfo qinfo;
qinfo.setFile(QString::fromUtf8(path.c_str()));
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
if (collection.load(qinfo.absoluteFilePath(), this)) {
collection.downloadFiles();
return;
}//if (collection.load(this))
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
}//if (qinfo.exists())
}//if (!rsFiles->FileDetails(
}//if (!item->data(SR_DATA_COL, SR_ROLE_LOCAL).toBool())
}//if (selectedItems.size() != 1)
RsCollectionFile collection;
if (collection.load(this)) {
collection.downloadFiles();
}//if (collection.load(this))
} }
void SearchDialog::downloadDirectory(const QTreeWidgetItem *item, const QString &base) void SearchDialog::downloadDirectory(const QTreeWidgetItem *item, const QString &base)
@ -445,7 +617,7 @@ void SearchDialog::recommendtofriends()
/** context menu searchTablewidget2 **/ /** context menu searchTablewidget2 **/
void SearchDialog::searchtableWidget2CostumPopupMenu( QPoint /*point*/ ) void SearchDialog::searchSummaryWidgetCustomPopupMenu( QPoint /*point*/ )
{ {
// block the popup if no results available // block the popup if no results available
if ((ui.searchSummaryWidget->selectedItems()).size() == 0) return; if ((ui.searchSummaryWidget->selectedItems()).size() == 0) return;
@ -527,7 +699,7 @@ void SearchDialog::copySearchLink()
return; return;
/* get the keywords */ /* get the keywords */
QString keywords = ci->text(SS_TEXT_COL); QString keywords = ci->text(SS_KEYWORDS_COL);
std::cerr << "SearchDialog::copySearchLink(): keywords: " << keywords.toStdString(); std::cerr << "SearchDialog::copySearchLink(): keywords: " << keywords.toStdString();
std::cerr << std::endl; std::cerr << std::endl;
@ -585,12 +757,12 @@ void SearchDialog::initSearchResult(const QString& txt, qulonglong searchId, int
QTreeWidgetItem *item2 = new RSTreeWidgetItem(compareSummaryRole); QTreeWidgetItem *item2 = new RSTreeWidgetItem(compareSummaryRole);
if (fileType == FILETYPE_IDX_ANY) { if (fileType == FILETYPE_IDX_ANY) {
item2->setText(SS_TEXT_COL, txt); item2->setText(SS_KEYWORDS_COL, txt);
} else { } else {
item2->setText(SS_TEXT_COL, txt + " (" + ui.FileTypeComboBox->itemText(fileType) + ")"); item2->setText(SS_KEYWORDS_COL, txt + " (" + ui.FileTypeComboBox->itemText(fileType) + ")");
} }
item2->setText(SS_COUNT_COL, QString::number(0)); item2->setText(SS_RESULTS_COL, QString::number(0));
item2->setData(SS_COUNT_COL, ROLE_SORT, 0); item2->setData(SS_RESULTS_COL, ROLE_SORT, 0);
item2->setText(SS_SEARCH_ID_COL, sid_hexa); item2->setText(SS_SEARCH_ID_COL, sid_hexa);
item2->setText(SS_FILE_TYPE_COL, QString::number(fileType)); item2->setText(SS_FILE_TYPE_COL, QString::number(fileType));
@ -798,10 +970,10 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
child->setText(SR_AGE_COL, QString::number(dir.age)); child->setText(SR_AGE_COL, QString::number(dir.age));
child->setData(SR_AGE_COL, ROLE_SORT, dir.age); child->setData(SR_AGE_COL, ROLE_SORT, dir.age);
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight ); child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
child->setText(SR_ID_COL, QString::number(1)); child->setText(SR_SOURCES_COL, QString::number(1));
child->setData(SR_ID_COL, ROLE_SORT, 1); child->setData(SR_SOURCES_COL, ROLE_SORT, 1);
child->setTextAlignment( SR_ID_COL, Qt::AlignRight ); child->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight );
child->setText(SR_SEARCH_ID_COL, sid_hexa); child->setText(SR_SEARCH_ID_COL, sid_hexa);
setIconAndType(child, QString::fromUtf8(dir.name.c_str())); setIconAndType(child, QString::fromUtf8(dir.name.c_str()));
@ -824,9 +996,9 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
child->setText(SR_AGE_COL, QString::number(dir.age)); child->setText(SR_AGE_COL, QString::number(dir.age));
child->setData(SR_AGE_COL, ROLE_SORT, dir.age); child->setData(SR_AGE_COL, ROLE_SORT, dir.age);
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight ); child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
child->setText(SR_ID_COL, QString::number(1)); child->setText(SR_SOURCES_COL, QString::number(1));
child->setData(SR_ID_COL, ROLE_SORT, 1); child->setData(SR_SOURCES_COL, ROLE_SORT, 1);
child->setTextAlignment( SR_ID_COL, Qt::AlignRight ); child->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight );
child->setText(SR_SEARCH_ID_COL, sid_hexa); child->setText(SR_SEARCH_ID_COL, sid_hexa);
child->setText(SR_TYPE_COL, tr("Folder")); child->setText(SR_TYPE_COL, tr("Folder"));
@ -843,19 +1015,19 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL) == sid_hexa) if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL) == sid_hexa)
{ {
// increment result since every item is new // increment result since every item is new
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ; int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_RESULTS_COL).toInt() ;
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1)); ui.searchSummaryWidget->topLevelItem(i)->setText(SS_RESULTS_COL, QString::number(s+1));
ui.searchSummaryWidget->topLevelItem(i)->setData(SS_COUNT_COL, ROLE_SORT, s+1); ui.searchSummaryWidget->topLevelItem(i)->setData(SS_RESULTS_COL, ROLE_SORT, s+1);
found = true ; found = true ;
} }
} }
if(!found) if(!found)
{ {
QTreeWidgetItem *item2 = new RSTreeWidgetItem(compareSummaryRole); QTreeWidgetItem *item2 = new RSTreeWidgetItem(compareSummaryRole);
item2->setText(SS_TEXT_COL, txt); item2->setText(SS_KEYWORDS_COL, txt);
item2->setText(SS_COUNT_COL, QString::number(1)); item2->setText(SS_RESULTS_COL, QString::number(1));
item2->setData(SS_COUNT_COL, ROLE_SORT, 1); item2->setData(SS_RESULTS_COL, ROLE_SORT, 1);
item2->setTextAlignment( SS_COUNT_COL, Qt::AlignRight ); item2->setTextAlignment( SS_RESULTS_COL, Qt::AlignRight );
item2->setText(SS_SEARCH_ID_COL, sid_hexa); item2->setText(SS_SEARCH_ID_COL, sid_hexa);
ui.searchSummaryWidget->addTopLevelItem(item2); ui.searchSummaryWidget->addTopLevelItem(item2);
@ -892,9 +1064,9 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
child->setText(SR_AGE_COL, QString::number(dir.min_age)); child->setText(SR_AGE_COL, QString::number(dir.min_age));
child->setData(SR_AGE_COL, ROLE_SORT, dir.min_age); child->setData(SR_AGE_COL, ROLE_SORT, dir.min_age);
child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight ); child->setTextAlignment( SR_SIZE_COL, Qt::AlignRight );
child->setText(SR_ID_COL, QString::number(1)); child->setText(SR_SOURCES_COL, QString::number(1));
child->setData(SR_ID_COL, ROLE_SORT, 1); child->setData(SR_SOURCES_COL, ROLE_SORT, 1);
child->setTextAlignment( SR_ID_COL, Qt::AlignRight ); child->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight );
child->setText(SR_SEARCH_ID_COL, sid_hexa); child->setText(SR_SEARCH_ID_COL, sid_hexa);
child->setText(SR_TYPE_COL, tr("Folder")); child->setText(SR_TYPE_COL, tr("Folder"));
@ -910,19 +1082,19 @@ void SearchDialog::insertDirectory(const QString &txt, qulonglong searchId, cons
if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL) == sid_hexa) if(ui.searchSummaryWidget->topLevelItem(i)->text(SS_SEARCH_ID_COL) == sid_hexa)
{ {
// increment result since every item is new // increment result since every item is new
int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_COUNT_COL).toInt() ; int s = ui.searchSummaryWidget->topLevelItem(i)->text(SS_RESULTS_COL).toInt() ;
ui.searchSummaryWidget->topLevelItem(i)->setText(SS_COUNT_COL,QString::number(s+1)); ui.searchSummaryWidget->topLevelItem(i)->setText(SS_RESULTS_COL, QString::number(s+1));
ui.searchSummaryWidget->topLevelItem(i)->setData(SS_COUNT_COL, ROLE_SORT, s+1); ui.searchSummaryWidget->topLevelItem(i)->setData(SS_RESULTS_COL, ROLE_SORT, s+1);
found = true ; found = true ;
} }
} }
if(!found) if(!found)
{ {
RSTreeWidgetItem *item2 = new RSTreeWidgetItem(compareSummaryRole); RSTreeWidgetItem *item2 = new RSTreeWidgetItem(compareSummaryRole);
item2->setText(SS_TEXT_COL, txt); item2->setText(SS_KEYWORDS_COL, txt);
item2->setText(SS_COUNT_COL, QString::number(1)); item2->setText(SS_RESULTS_COL, QString::number(1));
item2->setData(SS_COUNT_COL, ROLE_SORT, 1); item2->setData(SS_RESULTS_COL, ROLE_SORT, 1);
item2->setTextAlignment( SS_COUNT_COL, Qt::AlignRight ); item2->setTextAlignment( SS_RESULTS_COL, Qt::AlignRight );
item2->setText(SS_SEARCH_ID_COL, sid_hexa); item2->setText(SS_SEARCH_ID_COL, sid_hexa);
ui.searchSummaryWidget->addTopLevelItem(item2); ui.searchSummaryWidget->addTopLevelItem(item2);
@ -995,8 +1167,8 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
for(QList<QTreeWidgetItem*>::const_iterator it(itms.begin());it!=itms.end();++it) for(QList<QTreeWidgetItem*>::const_iterator it(itms.begin());it!=itms.end();++it)
if((*it)->text(SR_SEARCH_ID_COL) == sid_hexa) if((*it)->text(SR_SEARCH_ID_COL) == sid_hexa)
{ {
QString resultCount = (*it)->text(SR_ID_COL); QString resultCount = (*it)->text(SR_SOURCES_COL);
QStringList modifiedResultCount = resultCount.split("/", QString::SkipEmptyParts); QStringList modifiedResultCount = resultCount.split("/", QString::SkipEmptyParts);
if(searchType == FRIEND_SEARCH) if(searchType == FRIEND_SEARCH)
{ {
friendSource = modifiedResultCount.at(0).toInt() + 1; friendSource = modifiedResultCount.at(0).toInt() + 1;
@ -1009,8 +1181,8 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
} }
modifiedResult = QString::number(friendSource) + "/" + QString::number(anonymousSource); modifiedResult = QString::number(friendSource) + "/" + QString::number(anonymousSource);
float fltRes = friendSource + (float)anonymousSource/1000; float fltRes = friendSource + (float)anonymousSource/1000;
(*it)->setText(SR_ID_COL,modifiedResult); (*it)->setText(SR_SOURCES_COL,modifiedResult);
(*it)->setData(SR_ID_COL, ROLE_SORT, fltRes); (*it)->setData(SR_SOURCES_COL, ROLE_SORT, fltRes);
QTreeWidgetItem *item = (*it); QTreeWidgetItem *item = (*it);
found = true ; found = true ;
@ -1084,9 +1256,9 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
modifiedResult =QString::number(friendSource) + "/" + QString::number(anonymousSource); modifiedResult =QString::number(friendSource) + "/" + QString::number(anonymousSource);
float fltRes = friendSource + (float)anonymousSource/1000; float fltRes = friendSource + (float)anonymousSource/1000;
item->setText(SR_ID_COL,modifiedResult); item->setText(SR_SOURCES_COL,modifiedResult);
item->setData(SR_ID_COL, ROLE_SORT, fltRes); item->setData(SR_SOURCES_COL, ROLE_SORT, fltRes);
item->setTextAlignment( SR_ID_COL, Qt::AlignRight ); item->setTextAlignment( SR_SOURCES_COL, Qt::AlignRight );
item->setText(SR_SEARCH_ID_COL, sid_hexa); item->setText(SR_SEARCH_ID_COL, sid_hexa);
QColor foreground; QColor foreground;
@ -1100,7 +1272,7 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
} else { } else {
item->setData(SR_DATA_COL, SR_ROLE_LOCAL, false); item->setData(SR_DATA_COL, SR_ROLE_LOCAL, false);
sources = item->text(SR_ID_COL).toInt(); sources = item->text(SR_SOURCES_COL).toInt();
if (sources == 1) if (sources == 1)
{ {
foreground = ui.searchResultWidget->palette().color(QPalette::Text); foreground = ui.searchResultWidget->palette().color(QPalette::Text);
@ -1125,9 +1297,9 @@ void SearchDialog::insertFile(qulonglong searchId, const FileDetail& file, int s
/* update the summary as well */ /* update the summary as well */
if(!found) // only increment result when it's a new item. if(!found) // only increment result when it's a new item.
{ {
int s = ui.searchSummaryWidget->topLevelItem(summaryItemIndex)->text(SS_COUNT_COL).toInt() ; int s = ui.searchSummaryWidget->topLevelItem(summaryItemIndex)->text(SS_RESULTS_COL).toInt() ;
ui.searchSummaryWidget->topLevelItem(summaryItemIndex)->setText(SS_COUNT_COL,QString::number(s+1)); ui.searchSummaryWidget->topLevelItem(summaryItemIndex)->setText(SS_RESULTS_COL, QString::number(s+1));
ui.searchSummaryWidget->topLevelItem(summaryItemIndex)->setData(SS_COUNT_COL, ROLE_SORT, s+1); ui.searchSummaryWidget->topLevelItem(summaryItemIndex)->setData(SS_RESULTS_COL, ROLE_SORT, s+1);
} }
} }

View File

@ -65,18 +65,23 @@ public slots:
private slots: private slots:
/** Create the context popup menu and it's submenus */ /** Create the context popup menu and it's submenus */
void searchtableWidgetCostumPopupMenu( QPoint point ); void searchResultWidgetCustomPopupMenu( QPoint point );
void processResultQueue(); void processResultQueue();
void searchtableWidget2CostumPopupMenu( QPoint point ); void searchSummaryWidgetCustomPopupMenu( QPoint point );
void download(); void download();
void collCreate();
void collModif();
void collView();
void collOpen();
void broadcastonchannel(); void broadcastonchannel();
void recommendtofriends(); void recommendtofriends();
void checkText(const QString&) ; void checkText(const QString&);
void copyResultLink(); void copyResultLink();
void copySearchLink(); void copySearchLink();
void openFolderSearch(); void openFolderSearch();
@ -152,6 +157,11 @@ private:
QColor mTextColorLowSources; QColor mTextColorLowSources;
QColor mTextColorHighSources; QColor mTextColorHighSources;
QAction *collCreateAct;
QAction *collModifAct;
QAction *collViewAct;
QAction *collOpenAct;
/** Qt Designer generated object */ /** Qt Designer generated object */
Ui::SearchDialog ui; Ui::SearchDialog ui;

View File

@ -27,12 +27,13 @@
/* indicies for search results item columns SR_ = Search Result */ /* indicies for search results item columns SR_ = Search Result */
#define SR_NAME_COL 0 #define SR_NAME_COL 0
#define SR_SIZE_COL 1 #define SR_SIZE_COL 1
#define SR_ID_COL 2 #define SR_SOURCES_COL 2
#define SR_TYPE_COL 3 #define SR_TYPE_COL 3
#define SR_AGE_COL 4 #define SR_AGE_COL 4
#define SR_HASH_COL 5 #define SR_HASH_COL 5
#define SR_SEARCH_ID_COL 6 #define SR_SEARCH_ID_COL 6
#define SR_UID_COL 7 #define SR_UID_COL 7
#define SR_COL_COUNT 6//8 ??
#define SR_DATA_COL SR_NAME_COL #define SR_DATA_COL SR_NAME_COL
#define SR_ROLE_LOCAL Qt::UserRole #define SR_ROLE_LOCAL Qt::UserRole

View File

@ -40,6 +40,7 @@
#include "ShareDialog.h" #include "ShareDialog.h"
#include "common/PeerDefs.h" #include "common/PeerDefs.h"
#include "util/QtVersion.h" #include "util/QtVersion.h"
#include "gui/common/RsCollectionFile.h"
#include "notifyqt.h" #include "notifyqt.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
@ -57,11 +58,27 @@
#define IMAGE_PROGRESS ":/images/browse-looking.gif" #define IMAGE_PROGRESS ":/images/browse-looking.gif"
#define IMAGE_COPYLINK ":/images/copyrslink.png" #define IMAGE_COPYLINK ":/images/copyrslink.png"
#define IMAGE_OPENFOLDER ":/images/folderopen.png" #define IMAGE_OPENFOLDER ":/images/folderopen.png"
#define IMAGE_OPENFILE ":/images/fileopen.png" #define IMAGE_OPENFILE ":/images/fileopen.png"
#define IMAGE_COLLECTION ":/images/mimetypes/rscollection-16.png" #define IMAGE_LIBRARY ":/images/library.png"
#define IMAGE_COLLCREATE ":/images/library_add.png"
#define IMAGE_COLLMODIF ":/images/library_edit.png"
#define IMAGE_COLLVIEW ":/images/library_view.png"
#define IMAGE_COLLOPEN ":/images/library.png"
#define IMAGE_EDITSHARE ":/images/edit_16.png" #define IMAGE_EDITSHARE ":/images/edit_16.png"
#define IMAGE_MYFILES ":images/my_documents_22.png" #define IMAGE_MYFILES ":images/my_documents_22.png"
/*define dirTreeView Column */
#define COLUMN_NAME 0
#define COLUMN_SIZE 1
#define COLUMN_AGE 2
#define COLUMN_FRIEND 3
#define COLUMN_DIR 4
#define COLUMN_COUNT 5
/*define viewType_CB value */
#define VIEW_TYPE_TREE 0
#define VIEW_TYPE_FLAT 1
// Define to avoid using the search in treeview, because it is really slow for now. // Define to avoid using the search in treeview, because it is really slow for now.
// //
#define DONT_USE_SEARCH_IN_TREE_VIEW 1 #define DONT_USE_SEARCH_IN_TREE_VIEW 1
@ -121,14 +138,14 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD
tree_proxyModel->setSourceModel(tree_model); tree_proxyModel->setSourceModel(tree_model);
tree_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); tree_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
tree_proxyModel->setSortRole(RetroshareDirModel::SortRole); tree_proxyModel->setSortRole(RetroshareDirModel::SortRole);
tree_proxyModel->sort(0); tree_proxyModel->sort(COLUMN_NAME);
flat_proxyModel = new SFDSortFilterProxyModel(flat_model, this); flat_proxyModel = new SFDSortFilterProxyModel(flat_model, this);
flat_proxyModel->setDynamicSortFilter(true); flat_proxyModel->setDynamicSortFilter(true);
flat_proxyModel->setSourceModel(flat_model); flat_proxyModel->setSourceModel(flat_model);
flat_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); flat_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
flat_proxyModel->setSortRole(RetroshareDirModel::SortRole); flat_proxyModel->setSortRole(RetroshareDirModel::SortRole);
flat_proxyModel->sort(0); flat_proxyModel->sort(COLUMN_NAME);
connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter())); connect(ui.filterClearButton, SIGNAL(clicked()), this, SLOT(clearFilter()));
connect(ui.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter())); connect(ui.filterStartButton, SIGNAL(clicked()), this, SLOT(startFilter()));
@ -138,11 +155,11 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD
/* Set header resize modes and initial section sizes */ /* Set header resize modes and initial section sizes */
QHeaderView * header = ui.dirTreeView->header () ; QHeaderView * header = ui.dirTreeView->header () ;
header->resizeSection ( 0, 490 ); header->resizeSection ( COLUMN_NAME, 490 );
header->resizeSection ( 1, 70 ); header->resizeSection ( COLUMN_SIZE, 70 );
header->resizeSection ( 2, 100 ); header->resizeSection ( COLUMN_AGE, 100 );
header->resizeSection ( 3, 100 ); header->resizeSection ( COLUMN_FRIEND, 100 );
header->resizeSection ( 4, 100 ); header->resizeSection ( COLUMN_DIR, 100 );
header->setStretchLastSection(false); header->setStretchLastSection(false);
@ -162,13 +179,22 @@ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareD
addlinkCloudAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Add Links to Cloud" ), this ); addlinkCloudAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Add Links to Cloud" ), this );
connect( addlinkCloudAct , SIGNAL( triggered() ), this, SLOT( addLinkToCloud( ) ) ); connect( addlinkCloudAct , SIGNAL( triggered() ), this, SLOT( addLinkToCloud( ) ) );
#endif #endif
collCreateAct= new QAction(QIcon(IMAGE_COLLCREATE), tr("Create Collection..."), this) ;
connect(collCreateAct,SIGNAL(triggered()),this,SLOT(collCreate())) ;
collModifAct= new QAction(QIcon(IMAGE_COLLMODIF), tr("Modify Collection..."), this) ;
connect(collModifAct,SIGNAL(triggered()),this,SLOT(collModif())) ;
collViewAct= new QAction(QIcon(IMAGE_COLLVIEW), tr("View Collection..."), this) ;
connect(collViewAct,SIGNAL(triggered()),this,SLOT(collView())) ;
collOpenAct = new QAction(QIcon(IMAGE_COLLOPEN), tr( "Download from collection file..." ), this ) ;
connect(collOpenAct, SIGNAL(triggered()), this, SLOT(collOpen())) ;
} }
LocalSharedFilesDialog::LocalSharedFilesDialog(QWidget *parent) LocalSharedFilesDialog::LocalSharedFilesDialog(QWidget *parent)
: SharedFilesDialog(new TreeStyle_RDM(false),new FlatStyle_RDM(false),parent) : SharedFilesDialog(new TreeStyle_RDM(false),new FlatStyle_RDM(false),parent)
{ {
// Hide columns after loading the settings // Hide columns after loading the settings
ui.dirTreeView->setColumnHidden(4,false) ; ui.dirTreeView->setColumnHidden(COLUMN_DIR, false) ;
ui.downloadButton->hide() ; ui.downloadButton->hide() ;
// load settings // load settings
@ -177,27 +203,24 @@ LocalSharedFilesDialog::LocalSharedFilesDialog(QWidget *parent)
// //
changeCurrentViewModel(ui.viewType_CB->currentIndex()) ; changeCurrentViewModel(ui.viewType_CB->currentIndex()) ;
connect(ui.addShares_PB, SIGNAL(clicked()), this, SLOT(addShares())); connect(ui.addShares_PB, SIGNAL(clicked()), this, SLOT(addShares())) ;
connect(ui.checkButton, SIGNAL(clicked()), this, SLOT(forceCheck())); connect(ui.checkButton, SIGNAL(clicked()), this, SLOT(forceCheck())) ;
createcollectionfileAct = new QAction(QIcon(IMAGE_COLLECTION), tr("Create collection file"), this); openfileAct = new QAction(QIcon(IMAGE_OPENFILE), tr("Open File"), this) ;
openfileAct = new QAction(QIcon(IMAGE_OPENFILE), tr("Open File"), this); connect(openfileAct, SIGNAL(triggered()), this, SLOT(openfile())) ;
openfolderAct = new QAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this); openfolderAct = new QAction(QIcon(IMAGE_OPENFOLDER), tr("Open Folder"), this) ;
editshareAct = new QAction(QIcon(IMAGE_EDITSHARE), tr("Edit Share Permissions"), this); connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openfolder())) ;
editshareAct = new QAction(QIcon(IMAGE_EDITSHARE), tr("Edit Share Permissions"), this) ;
connect(editshareAct, SIGNAL(triggered()), this, SLOT(editSharePermissions())) ;
connect(createcollectionfileAct, SIGNAL(triggered()), this, SLOT(createCollectionFile())); ui.titleBarPixmap->setPixmap(QPixmap(IMAGE_MYFILES)) ;
connect(openfileAct, SIGNAL(triggered()), this, SLOT(openfile()));
connect(openfolderAct, SIGNAL(triggered()), this, SLOT(openfolder()));
connect(editshareAct, SIGNAL(triggered()), this, SLOT(editSharePermissions()));
ui.titleBarPixmap->setPixmap(QPixmap(IMAGE_MYFILES));
} }
RemoteSharedFilesDialog::RemoteSharedFilesDialog(QWidget *parent) RemoteSharedFilesDialog::RemoteSharedFilesDialog(QWidget *parent)
: SharedFilesDialog(new TreeStyle_RDM(true),new FlatStyle_RDM(true),parent) : SharedFilesDialog(new TreeStyle_RDM(true),new FlatStyle_RDM(true),parent)
{ {
ui.dirTreeView->setColumnHidden(3,false) ; ui.dirTreeView->setColumnHidden(COLUMN_FRIEND, false) ;
ui.dirTreeView->setColumnHidden(4,true) ; ui.dirTreeView->setColumnHidden(COLUMN_DIR, true) ;
ui.checkButton->hide() ; ui.checkButton->hide() ;
connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(downloadRemoteSelected())); connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(downloadRemoteSelected()));
@ -302,15 +325,15 @@ void RemoteSharedFilesDialog::processSettings(bool bLoad)
Settings->endGroup(); Settings->endGroup();
} }
void SharedFilesDialog::changeCurrentViewModel(int c) void SharedFilesDialog::changeCurrentViewModel(int viewTypeIndex)
{ {
disconnect( ui.dirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), 0, 0 ); //disconnect( ui.dirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), NULL, NULL );
disconnect( ui.dirTreeView, SIGNAL( expanded(const QModelIndex & ) ), 0, 0 ); //disconnect( ui.dirTreeView, SIGNAL( expanded(const QModelIndex & ) ), NULL, NULL );
if(model!=NULL) if(model!=NULL)
model->setVisible(false) ; model->setVisible(false) ;
if(c==0) if(viewTypeIndex==VIEW_TYPE_TREE)
{ {
model = tree_model ; model = tree_model ;
proxyModel = tree_proxyModel ; proxyModel = tree_proxyModel ;
@ -329,19 +352,19 @@ void SharedFilesDialog::changeCurrentViewModel(int c)
model->update() ; model->update() ;
} }
connect( ui.dirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), model, SLOT( collapsed(const QModelIndex & ) ) ); //connect( ui.dirTreeView, SIGNAL( collapsed(const QModelIndex & ) ), model, SLOT( collapsed(const QModelIndex & ) ) );
connect( ui.dirTreeView, SIGNAL( expanded(const QModelIndex & ) ), model, SLOT( expanded(const QModelIndex & ) ) ); //connect( ui.dirTreeView, SIGNAL( expanded(const QModelIndex & ) ), model, SLOT( expanded(const QModelIndex & ) ) );
ui.dirTreeView->setModel(proxyModel); ui.dirTreeView->setModel(proxyModel);
ui.dirTreeView->update(); ui.dirTreeView->update();
QHeaderView * header = ui.dirTreeView->header () ; QHeaderView * header = ui.dirTreeView->header () ;
QHeaderView_setSectionResizeMode(header, 0, QHeaderView::Interactive); QHeaderView_setSectionResizeMode(header, COLUMN_NAME, QHeaderView::Interactive);
ui.dirTreeView->header()->headerDataChanged(Qt::Horizontal,0,4) ; ui.dirTreeView->header()->headerDataChanged(Qt::Horizontal, COLUMN_NAME, COLUMN_DIR) ;
#ifdef DONT_USE_SEARCH_IN_TREE_VIEW #ifdef DONT_USE_SEARCH_IN_TREE_VIEW
if(c == 1) if(viewTypeIndex == VIEW_TYPE_FLAT)
#endif #endif
FilterItems(); FilterItems();
} }
@ -350,8 +373,8 @@ void LocalSharedFilesDialog::showProperColumns()
{ {
if(model == tree_model) if(model == tree_model)
{ {
ui.dirTreeView->setColumnHidden(3,false) ; ui.dirTreeView->setColumnHidden(COLUMN_FRIEND, false) ;
ui.dirTreeView->setColumnHidden(4,false) ; ui.dirTreeView->setColumnHidden(COLUMN_DIR, false) ;
#ifdef DONT_USE_SEARCH_IN_TREE_VIEW #ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui.filterLabel->hide(); ui.filterLabel->hide();
ui.filterPatternLineEdit->hide(); ui.filterPatternLineEdit->hide();
@ -361,8 +384,8 @@ void LocalSharedFilesDialog::showProperColumns()
} }
else else
{ {
ui.dirTreeView->setColumnHidden(3,true) ; ui.dirTreeView->setColumnHidden(COLUMN_FRIEND, true) ;
ui.dirTreeView->setColumnHidden(4,false) ; ui.dirTreeView->setColumnHidden(COLUMN_DIR, false) ;
#ifdef DONT_USE_SEARCH_IN_TREE_VIEW #ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui.filterLabel->show(); ui.filterLabel->show();
ui.filterPatternLineEdit->show(); ui.filterPatternLineEdit->show();
@ -373,8 +396,8 @@ void RemoteSharedFilesDialog::showProperColumns()
{ {
if(model == tree_model) if(model == tree_model)
{ {
ui.dirTreeView->setColumnHidden(3,true) ; ui.dirTreeView->setColumnHidden(COLUMN_FRIEND, true) ;
ui.dirTreeView->setColumnHidden(4,true) ; ui.dirTreeView->setColumnHidden(COLUMN_DIR, true) ;
#ifdef DONT_USE_SEARCH_IN_TREE_VIEW #ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui.filterLabel->hide(); ui.filterLabel->hide();
ui.filterPatternLineEdit->hide(); ui.filterPatternLineEdit->hide();
@ -384,8 +407,8 @@ void RemoteSharedFilesDialog::showProperColumns()
} }
else else
{ {
ui.dirTreeView->setColumnHidden(3,false) ; ui.dirTreeView->setColumnHidden(COLUMN_FRIEND, false) ;
ui.dirTreeView->setColumnHidden(4,false) ; ui.dirTreeView->setColumnHidden(COLUMN_DIR, false) ;
#ifdef DONT_USE_SEARCH_IN_TREE_VIEW #ifdef DONT_USE_SEARCH_IN_TREE_VIEW
ui.filterLabel->show(); ui.filterLabel->show();
ui.filterPatternLineEdit->show(); ui.filterPatternLineEdit->show();
@ -418,70 +441,78 @@ void LocalSharedFilesDialog::forceCheck()
void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) void RemoteSharedFilesDialog::spawnCustomPopupMenu( QPoint point )
{ {
QModelIndex idx = ui.dirTreeView->indexAt(point); if (!rsPeers) return; /* not ready yet! */
if (!idx.isValid())
return;
QModelIndex midx = proxyModel->mapToSource(idx);
if (!midx.isValid())
return;
int type = model->getType(midx); QModelIndex idx = ui.dirTreeView->indexAt(point) ;
if (type != DIR_TYPE_DIR && type != DIR_TYPE_FILE) { if (!idx.isValid()) return;
return;
}
QMenu contextMnu( this ); QModelIndex midx = proxyModel->mapToSource(idx) ;
if (!midx.isValid()) return;
QAction *downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), &contextMnu ); currentFile = model->data(midx, RetroshareDirModel::FileNameRole).toString() ;
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ); int type = model->getType(midx) ;
contextMnu.addAction( downloadAct); if (type != DIR_TYPE_DIR && type != DIR_TYPE_FILE) return;
if (type == DIR_TYPE_FILE) {
//QAction *copyremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), &contextMnu );
//connect( copyremotelinkAct , SIGNAL( triggered() ), this, SLOT( copyLink() ) );
//QAction *sendremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), &contextMnu ); QMenu contextMnu( this ) ;
//connect( sendremotelinkAct , SIGNAL( triggered() ), this, SLOT( sendremoteLinkTo( ) ) );
contextMnu.addSeparator(); //bool bIsRsColl = currentFile.endsWith(RsCollectionFile::ExtensionString);
contextMnu.addAction( copylinkAct); collCreateAct->setEnabled(true);
contextMnu.addAction( sendlinkAct); //collModifAct->setEnabled(bIsRsColl);
contextMnu.addSeparator(); //collViewAct->setEnabled(bIsRsColl);
contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to"), this, SLOT(recommendFilesToMsg())); collOpenAct->setEnabled(true);
}
contextMnu.exec(QCursor::pos()); QMenu collectionMenu(tr("Collection"), this);
collectionMenu.setIcon(QIcon(IMAGE_LIBRARY));
collectionMenu.addAction(collCreateAct);
//collectionMenu.addAction(collModifAct);
//collectionMenu.addAction(collViewAct);
collectionMenu.addAction(collOpenAct);
QAction *downloadAct = new QAction(QIcon(IMAGE_DOWNLOAD), tr( "Download" ), &contextMnu ) ;
connect( downloadAct , SIGNAL( triggered() ), this, SLOT( downloadRemoteSelected() ) ) ;
contextMnu.addAction( downloadAct) ;
if ( type == DIR_TYPE_FILE ) {
//QAction *copyremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Copy retroshare Link" ), &contextMnu ) ;
//connect( copyremotelinkAct , SIGNAL( triggered() ), this, SLOT( copyLink() ) ) ;
//QAction *sendremotelinkAct = new QAction(QIcon(IMAGE_COPYLINK), tr( "Send retroshare Link" ), &contextMnu ) ;
//connect( sendremotelinkAct , SIGNAL( triggered() ), this, SLOT( sendremoteLinkTo( ) ) ) ;
contextMnu.addSeparator() ;//------------------------------------
contextMnu.addAction( copylinkAct) ;
contextMnu.addAction( sendlinkAct) ;
contextMnu.addSeparator() ;//------------------------------------
contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to"), this, SLOT(recommendFilesToMsg())) ;
}//if (type == DIR_TYPE_FILE)
contextMnu.addSeparator() ;//------------------------------------
contextMnu.addMenu(&collectionMenu) ;
contextMnu.exec(QCursor::pos()) ;
} }
QModelIndexList SharedFilesDialog::getSelected() QModelIndexList SharedFilesDialog::getSelected()
{ {
QModelIndexList list = ui.dirTreeView->selectionModel()->selectedIndexes(); QModelIndexList list = ui.dirTreeView->selectionModel()->selectedIndexes() ;
QModelIndexList proxyList; QModelIndexList proxyList ;
for (QModelIndexList::iterator index = list.begin(); index != list.end(); index++) { for (QModelIndexList::iterator index = list.begin(); index != list.end(); index++ ) {
proxyList.append(proxyModel->mapToSource(*index)); proxyList.append(proxyModel->mapToSource(*index)) ;
} }//for (QModelIndexList::iterator index
return proxyList; return proxyList ;
}
void LocalSharedFilesDialog::createCollectionFile()
{
/* call back to the model (which does all the interfacing? */
std::cerr << "Creating a collection file!" << std::endl;
QModelIndexList lst = getSelected();
model->createCollectionFile(this, lst);
} }
void RemoteSharedFilesDialog::downloadRemoteSelected() void RemoteSharedFilesDialog::downloadRemoteSelected()
{ {
/* call back to the model (which does all the interfacing? */ /* call back to the model (which does all the interfacing? */
std::cerr << "Downloading Files"; std::cerr << "Downloading Files" ;
std::cerr << std::endl; std::cerr << std::endl ;
QModelIndexList lst = getSelected(); QModelIndexList lst = getSelected() ;
model -> downloadSelected(lst); model -> downloadSelected(lst) ;
} }
void LocalSharedFilesDialog::editSharePermissions() void LocalSharedFilesDialog::editSharePermissions()
@ -607,6 +638,112 @@ void SharedFilesDialog::addLinkToCloud()
} }
#endif #endif
void SharedFilesDialog::collCreate()
{
QModelIndexList lst = getSelected();
model->createCollectionFile(this, lst);
}
void SharedFilesDialog::collModif()
{
std::list<DirDetails> files_info ;
model->getFileInfoFromIndexList(getSelected(),files_info);
if(files_info.size() != 1) return ;
/* make path for downloaded files */
std::list<DirDetails>::iterator it = files_info.begin();
DirDetails details = (*it);
FileInfo info;
if (!rsFiles->FileDetails(details.hash, RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE
| RS_FILE_HINTS_SPEC_ONLY, info)) return;
std::string path;
path = info.path;
/* open file with a suitable application */
QFileInfo qinfo;
qinfo.setFile(QString::fromUtf8(path.c_str()));
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
collection.openColl(qinfo.absoluteFilePath());
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
}//if (qinfo.exists())
}
void SharedFilesDialog::collView()
{
std::list<DirDetails> files_info ;
model->getFileInfoFromIndexList(getSelected(),files_info);
if(files_info.size() != 1) return ;
/* make path for downloaded files */
std::list<DirDetails>::iterator it = files_info.begin();
DirDetails details = (*it);
FileInfo info;
if (!rsFiles->FileDetails(details.hash, RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE
| RS_FILE_HINTS_SPEC_ONLY, info)) return;
std::string path;
path = info.path;
/* open file with a suitable application */
QFileInfo qinfo;
qinfo.setFile(QString::fromUtf8(path.c_str()));
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
collection.openColl(qinfo.absoluteFilePath(), true);
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
}//if (qinfo.exists())
}
void SharedFilesDialog::collOpen()
{
std::list<DirDetails> files_info ;
model->getFileInfoFromIndexList(getSelected(),files_info);
if(files_info.size() == 1) {
/* make path for downloaded files */
std::list<DirDetails>::iterator it = files_info.begin();
DirDetails details = (*it);
FileInfo info;
if (rsFiles->FileDetails(details.hash, RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_LOCAL
| RS_FILE_HINTS_BROWSABLE | RS_FILE_HINTS_NETWORK_WIDE
| RS_FILE_HINTS_SPEC_ONLY, info)) {
std::string path;
path = info.path;
/* open file with a suitable application */
QFileInfo qinfo;
qinfo.setFile(QString::fromUtf8(path.c_str()));
if (qinfo.exists()) {
if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString)) {
RsCollectionFile collection;
if (collection.load(qinfo.absoluteFilePath(), this)) {
collection.downloadFiles();
return;
}//if (collection.load(this))
}//if (qinfo.absoluteFilePath().endsWith(RsCollectionFile::ExtensionString))
}//if (qinfo.exists())
}//if (rsFiles->FileDetails(
}//if(files_info.size() == 1)
RsCollectionFile collection;
if (collection.load(this)) {
collection.downloadFiles();
}//if (collection.load(this))
}
void LocalSharedFilesDialog::playselectedfiles() void LocalSharedFilesDialog::playselectedfiles()
{ {
/* call back to the model (which does all the interfacing? */ /* call back to the model (which does all the interfacing? */
@ -706,56 +843,64 @@ void SharedFilesDialog::postModDirectories(bool local)
QCoreApplication::flush(); QCoreApplication::flush();
} }
void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point ) void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point )
{ {
if (!rsPeers) if (!rsPeers) return; /* not ready yet! */
{
/* not ready yet! */
return;
}
QModelIndex idx = ui.dirTreeView->indexAt(point); QModelIndex idx = ui.dirTreeView->indexAt(point) ;
if (!idx.isValid()) if (!idx.isValid()) return ;
return;
QModelIndex midx = proxyModel->mapToSource(idx);
if (!midx.isValid())
return;
currentFile = model->data(midx, RetroshareDirModel::FileNameRole).toString(); QModelIndex midx = proxyModel->mapToSource(idx) ;
if (!midx.isValid()) return ;
int type = model->getType(midx);
QMenu contextMnu(this); currentFile = model->data(midx, RetroshareDirModel::FileNameRole).toString() ;
int type = model->getType(midx) ;
if (type != DIR_TYPE_DIR && type != DIR_TYPE_FILE) return;
switch (type) QMenu contextMnu(this) ;
{
case DIR_TYPE_DIR: bool bIsRsColl = currentFile.endsWith(RsCollectionFile::ExtensionString);
contextMnu.addAction(openfolderAct); collCreateAct->setEnabled(true);
contextMnu.addSeparator() ; collModifAct->setEnabled(bIsRsColl);
contextMnu.addAction(createcollectionfileAct) ; collViewAct->setEnabled(bIsRsColl);
break; collOpenAct->setEnabled(true);
case DIR_TYPE_FILE:
contextMnu.addAction(openfileAct); QMenu collectionMenu(tr("Collection"), this);
contextMnu.addSeparator(); collectionMenu.setIcon(QIcon(IMAGE_LIBRARY));
contextMnu.addAction(copylinkAct); collectionMenu.addAction(collCreateAct);
contextMnu.addAction(sendlinkAct); collectionMenu.addAction(collModifAct);
contextMnu.addSeparator(); collectionMenu.addAction(collViewAct);
contextMnu.addAction(createcollectionfileAct) ; collectionMenu.addAction(collOpenAct);
contextMnu.addSeparator();
switch (type) {
case DIR_TYPE_DIR :
contextMnu.addAction(openfolderAct) ;
contextMnu.addSeparator() ;//------------------------------------
contextMnu.addMenu(&collectionMenu) ;
break ;
case DIR_TYPE_FILE :
contextMnu.addAction(openfileAct) ;
contextMnu.addSeparator() ;//------------------------------------
contextMnu.addAction(copylinkAct) ;
contextMnu.addAction(sendlinkAct) ;
contextMnu.addSeparator() ;//------------------------------------
contextMnu.addMenu(&collectionMenu) ;
contextMnu.addSeparator() ;//------------------------------------
#ifdef RS_USE_LINKS #ifdef RS_USE_LINKS
contextMnu.addAction(sendlinkCloudAct); contextMnu.addAction(sendlinkCloudAct) ;
contextMnu.addAction(addlinkCloudAct); contextMnu.addAction(addlinkCloudAct) ;
contextMnu.addSeparator(); contextMnu.addSeparator() ;//------------------------------------
#endif #endif
contextMnu.addSeparator(); contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to"), this, SLOT(recommendFilesToMsg())) ;
contextMnu.addAction(QIcon(IMAGE_MSG), tr("Recommend in a message to"), this, SLOT(recommendFilesToMsg())); break ;
break;
default:
return;
}
contextMnu.exec(QCursor::pos()); default :
return ;
}//switch (type)
contextMnu.exec(QCursor::pos()) ;
} }
//============================================================================ //============================================================================
@ -763,7 +908,7 @@ void LocalSharedFilesDialog::spawnCustomPopupMenu( QPoint point )
QAction* QAction*
LocalSharedFilesDialog::fileAssotiationAction(const QString /*fileName*/) LocalSharedFilesDialog::fileAssotiationAction(const QString /*fileName*/)
{ {
QAction* result = 0; QAction* result = NULL;
Settings->beginGroup("FileAssotiations"); Settings->beginGroup("FileAssotiations");
@ -826,11 +971,11 @@ void SharedFilesDialog::indicatorChanged(int index)
model->changeAgeIndicator(correct_indicator[index]); model->changeAgeIndicator(correct_indicator[index]);
ui.dirTreeView->update(ui.dirTreeView->rootIndex()); ui.dirTreeView->update(ui.dirTreeView->rootIndex());
if (correct_indicator[index] != IND_ALWAYS) if (correct_indicator[index] != IND_ALWAYS)
ui.dirTreeView->sortByColumn(2, Qt::AscendingOrder); ui.dirTreeView->sortByColumn(COLUMN_AGE, Qt::AscendingOrder);
else else
ui.dirTreeView->sortByColumn(0, Qt::AscendingOrder); ui.dirTreeView->sortByColumn(COLUMN_NAME, Qt::AscendingOrder);
updateDisplay() ; updateDisplay() ;
} }
@ -878,11 +1023,11 @@ void SharedFilesDialog::FilterItems()
QCoreApplication::processEvents() ; QCoreApplication::processEvents() ;
int rowCount = ui.dirTreeView->model()->rowCount(); int rowCount = ui.dirTreeView->model()->rowCount();
for (int row = 0; row < rowCount; row++) for (int row = 0; row < rowCount; row++)
if(proxyModel == tree_proxyModel) if(proxyModel == tree_proxyModel)
tree_FilterItem(ui.dirTreeView->model()->index(row, 0), text, 0); tree_FilterItem(ui.dirTreeView->model()->index(row, COLUMN_NAME), text, 0);
else else
flat_FilterItem(ui.dirTreeView->model()->index(row, 0), text, 0); flat_FilterItem(ui.dirTreeView->model()->index(row, COLUMN_NAME), text, 0);
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
} }

View File

@ -67,6 +67,11 @@ private slots:
void addLinkToCloud(); void addLinkToCloud();
#endif #endif
void collCreate();
void collModif();
void collView();
void collOpen();
//== void showFrame(bool show); //== void showFrame(bool show);
//== void showFrameRemote(bool show); //== void showFrameRemote(bool show);
//== void showFrameSplitted(bool show); //== void showFrameSplitted(bool show);
@ -80,7 +85,7 @@ private slots:
void startFilter(); void startFilter();
public slots: public slots:
void changeCurrentViewModel(int) ; void changeCurrentViewModel(int viewTypeIndex);
signals: signals:
void playFiles(QStringList files); void playFiles(QStringList files);
@ -115,6 +120,11 @@ protected:
QAction* sendchatlinkAct; QAction* sendchatlinkAct;
QAction* copylinkhtmlAct; QAction* copylinkhtmlAct;
QAction *collCreateAct;
QAction *collModifAct;
QAction *collViewAct;
QAction *collOpenAct;
/* RetroshareDirModel */ /* RetroshareDirModel */
RetroshareDirModel *tree_model; RetroshareDirModel *tree_model;
RetroshareDirModel *flat_model; RetroshareDirModel *flat_model;
@ -147,7 +157,6 @@ class LocalSharedFilesDialog : public SharedFilesDialog
private slots: private slots:
void addShares(); void addShares();
void createCollectionFile();
void checkUpdate() ; void checkUpdate() ;
void editSharePermissions(); void editSharePermissions();
void playselectedfiles(); void playselectedfiles();
@ -161,10 +170,10 @@ class LocalSharedFilesDialog : public SharedFilesDialog
private: private:
QAction* openfileAct; QAction* openfileAct;
QAction* createcollectionfileAct;
QAction* openfolderAct; QAction* openfolderAct;
QAction* editshareAct; QAction* editshareAct;
}; };
class RemoteSharedFilesDialog : public SharedFilesDialog class RemoteSharedFilesDialog : public SharedFilesDialog
{ {
Q_OBJECT Q_OBJECT

File diff suppressed because it is too large Load Diff

View File

@ -23,31 +23,67 @@
#include "ui_RsCollectionDialog.h" #include "ui_RsCollectionDialog.h"
#include "RsCollectionFile.h" #include "RsCollectionFile.h"
#include <QFileSystemModel>
#include <QSortFilterProxyModel>
class QCheckBox ; class QCheckBox ;
class RsCollectionDialog: public QDialog, public Ui::RsCollectionDialog class RsCollectionDialog: public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
RsCollectionDialog(const QString& filename,const std::vector<RsCollectionFile::DLinfo>& dlinfos) ; RsCollectionDialog(const QString& filename
, const std::vector<ColFileInfo> &colFileInfos
private slots: , const bool& creation
void download() ; , const bool& readOnly = false) ;
void selectAll() ; virtual ~RsCollectionDialog();
void deselectAll() ;
void cancel() ;
void updateSizes() ;
void itemChanged(QTreeWidgetItem *item, int column);
protected: protected:
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev);
private: private slots:
void selectDeselectAll(bool select); void directoryLoaded(QString dirLoaded);
void connectUpdate(bool doConnect); void updateSizes() ;
void changeFileName() ;
void add() ;
void addRecursive() ;
void remove() ;
void processItem(QMap<QString, QString> &dirToAdd
, int &index
, ColFileInfo &parent
) ;
void makeDir() ;
void fileHashingFinished(QList<HashedFile> hashedFiles) ;
void itemChanged(QTreeWidgetItem* item,int col) ;
void cancel() ;
void download() ;
void save() ;
const std::vector<RsCollectionFile::DLinfo>& _dlinfos ; signals:
QString _filename ; void saveColl(std::vector<ColFileInfo>, QString);
private:
void processSettings(bool bLoad) ;
QTreeWidgetItem* getRootItem();
bool updateList();
bool addChild(QTreeWidgetItem *parent, const std::vector<ColFileInfo> &child);
void addRecursive(bool recursive) ;
bool addAllChild(QFileInfo &fileInfoParent
, QMap<QString, QString > &dirToAdd
, QStringList &fileToHash
, int &count);
void saveChild(QTreeWidgetItem *parentItem, ColFileInfo *parentInfo = NULL);
Ui::RsCollectionDialog ui;
QString _fileName ;
const bool _creationMode ;
const bool _readOnly;
std::vector<ColFileInfo> _newColFileInfos ;
QFileSystemModel *_dirModel;
QSortFilterProxyModel *_tree_proxyModel;
QItemSelectionModel *_selectionProxy;
bool _dirLoaded;
QHash<QString,QString> _listOfFilesAddedInDir;
}; };

View File

@ -3,73 +3,138 @@
<class>RsCollectionDialog</class> <class>RsCollectionDialog</class>
<widget class="QDialog" name="RsCollectionDialog"> <widget class="QDialog" name="RsCollectionDialog">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>434</width> <width>693</width>
<height>310</height> <height>331</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Collection</string> <string>Collection</string>
</property> </property>
<property name="windowIcon"> <property name="windowIcon">
<iconset resource="../images.qrc"> <iconset resource="../images.qrc">
<normaloff>:/images/mimetypes/rscollection-16.png</normaloff>:/images/mimetypes/rscollection-16.png</iconset> <normaloff>:/images/mimetypes/rscollection-16.png</normaloff>:/images/mimetypes/rscollection-16.png</iconset>
</property> </property>
<property name="sizeGripEnabled"> <property name="sizeGripEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QSplitter" name="_mainSplitter">
<item> <property name="orientation">
<layout class="QVBoxLayout" name="verticalLayout"> <enum>Qt::Vertical</enum>
<item> </property>
<widget class="QLabel" name="label"> <widget class="QFrame" name="_FrameEdit">
<property name="text"> <property name="frameShape">
<string>File name :</string> <enum>QFrame::NoFrame</enum>
</property> </property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QVBoxLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="_frameInfo">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<layout class="QVBoxLayout">
<item>
<widget class="QLabel" name="label_filename">
<property name="text">
<string>File name :</string>
</property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_totalsize">
<property name="text"> <property name="text">
<string>Total size :</string> <string>Total size :</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_selectedFiles">
<property name="text"> <property name="text">
<string>Selected files:</string> <string>Selected files :</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item> </layout>
<layout class="QVBoxLayout" name="verticalLayout_2"> </item>
<item> <item>
<widget class="QLabel" name="_filename_TL"> <layout class="QVBoxLayout">
<property name="text"> <item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="_filename_TL">
<property name="text">
<string notr="true">TextLabel</string> <string notr="true">TextLabel</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="_totalSize_TL"> <widget class="QPushButton" name="_changeFile">
<property name="text"> <property name="maximumSize">
<string notr="true">TextLabel</string> <size>
<width>21</width>
<height>14</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Change the file were collection will be saved.&lt;/p&gt;&lt;p&gt;If you select an existing file, you could merge it.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="_totalSize_TL">
<property name="text">
<string notr="true">TextLabel</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -80,88 +145,252 @@
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer_2"> <spacer>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
</layout> </layout>
</item> </widget>
<item> </item>
<widget class="QTreeWidget" name="_fileEntriesTW"> <item>
<property name="editTriggers"> <widget class="QFrame" name="_frameLists">
<set>QAbstractItemView::NoEditTriggers</set> <property name="lineWidth">
</property> <number>0</number>
<property name="selectionMode"> </property>
<enum>QAbstractItemView::ExtendedSelection</enum> <layout class="QVBoxLayout">
</property> <property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QSplitter" name="_listSplitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QFrame" name="_treeViewFrame">
<layout class="QHBoxLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QTreeView" name="_systemFileTW">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="sortingEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout">
<item>
<widget class="QPushButton" name="_add_PB">
<property name="minimumSize">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>17</width>
<height>21</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add selected item to collection one by one.&lt;/p&gt;&lt;p&gt;Select parent dir to add this too.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic; vertical-align:sub;&quot;&gt;&amp;lt;Enter&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string notr="true">&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="_addRecur_PB">
<property name="minimumSize">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Add selected item to collection.&lt;/p&gt;&lt;p&gt;If a directory is selected, all of his children will be added.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; text-decoration: underline; vertical-align:sub;&quot;&gt;&amp;lt;Shift + Enter&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>&gt;&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="_remove_PB">
<property name="minimumSize">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Remove selected item of collection.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic; vertical-align:sub;&quot;&gt;&amp;lt;Del&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string notr="true">&lt;</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="_makeDir_PB">
<property name="minimumSize">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>21</width>
<height>21</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Make a new directory in the collection.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic; vertical-align:sub;&quot;&gt;&amp;lt;+&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>+</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QTreeWidget" name="_fileEntriesTW">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum>
</property>
<property name="rootIsDecorated"> <property name="rootIsDecorated">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="allColumnsShowFocus"> <property name="allColumnsShowFocus">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> <column>
</item> <property name="text">
<item> <string notr="true">1</string>
<layout class="QHBoxLayout" name="horizontalLayout"> </property>
<item> </column>
<spacer name="horizontalSpacer"> </widget>
<property name="orientation"> </widget>
<enum>Qt::Horizontal</enum> </item>
</property> </layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>40</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="_selectAll_PB"> <widget class="QPushButton" name="_cancel_PB">
<property name="text"> <property name="text">
<string>Select all</string> <string>Cancel</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="_deselectAll_PB"> <widget class="QPushButton" name="_save_PB">
<property name="text"> <property name="text">
<string>Deselect all</string> <string>Save</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="_cancel_PB"> <widget class="QPushButton" name="_download_PB">
<property name="text"> <property name="text">
<string>Cancel</string> <string>Download!</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="_download_PB">
<property name="text">
<string>Download!</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </widget>
<resources> <widget class="HashBox" name="_hashBox">
<include location="../images.qrc"/> <property name="widgetResizable">
</resources> <bool>true</bool>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>HashBox</class>
<extends>QScrollArea</extends>
<header location="global">gui/common/HashBox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -28,7 +28,6 @@
#include "RsCollectionDialog.h" #include "RsCollectionDialog.h"
#include "util/misc.h" #include "util/misc.h"
#include <QFile>
#include <QDir> #include <QDir>
#include <QObject> #include <QObject>
#include <QTextStream> #include <QTextStream>
@ -39,8 +38,22 @@
const QString RsCollectionFile::ExtensionString = QString("rscollection") ; const QString RsCollectionFile::ExtensionString = QString("rscollection") ;
RsCollectionFile::RsCollectionFile() RsCollectionFile::RsCollectionFile(QObject *parent)
: _xml_doc("RsCollection") : QObject(parent), _xml_doc("RsCollection")
{
}
RsCollectionFile::RsCollectionFile(const std::vector<DirDetails>& file_infos, QObject *parent)
: QObject(parent), _xml_doc("RsCollection")
{
QDomElement root = _xml_doc.createElement("RsCollection");
_xml_doc.appendChild(root);
for(uint32_t i = 0;i<file_infos.size();++i)
recursAddElements(_xml_doc,file_infos[i],root) ;
}
RsCollectionFile::~RsCollectionFile()
{ {
} }
@ -50,11 +63,11 @@ void RsCollectionFile::downloadFiles() const
// of the outermost element. // of the outermost element.
QDomElement docElem = _xml_doc.documentElement(); QDomElement docElem = _xml_doc.documentElement();
std::vector<DLinfo> dlinfos ; std::vector<ColFileInfo> colFileInfos ;
recursCollectDLinfos(docElem,dlinfos,QString(),false) ; recursCollectColFileInfos(docElem,colFileInfos,QString(),false) ;
RsCollectionDialog(_filename, dlinfos).exec() ; RsCollectionDialog(_fileName, colFileInfos, false).exec() ;
} }
static QString purifyFileName(const QString& input,bool& bad) static QString purifyFileName(const QString& input,bool& bad)
@ -74,7 +87,7 @@ static QString purifyFileName(const QString& input,bool& bad)
return output ; return output ;
} }
void RsCollectionFile::recursCollectDLinfos(const QDomElement& e,std::vector<DLinfo>& dlinfos,const QString& current_path, bool bad_chars_in_parent) const void RsCollectionFile::recursCollectColFileInfos(const QDomElement& e,std::vector<ColFileInfo>& colFileInfos,const QString& current_path, bool bad_chars_in_parent) const
{ {
QDomNode n = e.firstChild() ; QDomNode n = e.firstChild() ;
@ -88,22 +101,37 @@ void RsCollectionFile::recursCollectDLinfos(const QDomElement& e,std::vector<DLi
if(ee.tagName() == QString("File")) if(ee.tagName() == QString("File"))
{ {
DLinfo i ; ColFileInfo newChild ;
i.hash = ee.attribute(QString("sha1")) ; newChild.hash = ee.attribute(QString("sha1")) ;
bool bad_chars_detected = false ; bool bad_chars_detected = false ;
i.name = purifyFileName(ee.attribute(QString("name")), bad_chars_detected) ; newChild.name = purifyFileName(ee.attribute(QString("name")), bad_chars_detected) ;
i.filename_has_wrong_characters = bad_chars_detected || bad_chars_in_parent ; newChild.filename_has_wrong_characters = bad_chars_detected || bad_chars_in_parent ;
i.size = ee.attribute(QString("size")).toULongLong() ; newChild.size = ee.attribute(QString("size")).toULongLong() ;
i.path = current_path ; newChild.path = current_path ;
newChild.type = DIR_TYPE_FILE ;
dlinfos.push_back(i) ; colFileInfos.push_back(newChild) ;
} }
else if(ee.tagName() == QString("Directory")) else if(ee.tagName() == QString("Directory"))
{ {
ColFileInfo newParent ;
bool bad_chars_detected = false ; bool bad_chars_detected = false ;
QString cleanDirName = purifyFileName(ee.attribute(QString("name")),bad_chars_detected) ; QString cleanDirName = purifyFileName(ee.attribute(QString("name")),bad_chars_detected) ;
newParent.name=cleanDirName;
newParent.filename_has_wrong_characters = bad_chars_detected || bad_chars_in_parent ;
newParent.size = 0;
newParent.path = current_path ;
newParent.type = DIR_TYPE_DIR ;
recursCollectDLinfos(ee,dlinfos,current_path + "/" + cleanDirName, bad_chars_in_parent || bad_chars_detected) ; recursCollectColFileInfos(ee,newParent.children,current_path + "/" + cleanDirName, bad_chars_in_parent || bad_chars_detected) ;
uint32_t size = newParent.children.size();
for(uint32_t i=0;i<size;++i)
{
const ColFileInfo &colFileInfo = newParent.children[i];
newParent.size +=colFileInfo.size ;
}
colFileInfos.push_back(newParent) ;
} }
n = n.nextSibling() ; n = n.nextSibling() ;
@ -147,41 +175,84 @@ void RsCollectionFile::recursAddElements(QDomDocument& doc,const DirDetails& det
} }
} }
RsCollectionFile::RsCollectionFile(const std::vector<DirDetails>& file_infos) void RsCollectionFile::recursAddElements(QDomDocument& doc,const ColFileInfo& colFileInfo,QDomElement& e) const
: _xml_doc("RsCollection")
{ {
QDomElement root = _xml_doc.createElement("RsCollection"); if (colFileInfo.type == DIR_TYPE_FILE)
_xml_doc.appendChild(root); {
QDomElement f = doc.createElement("File") ;
for(uint32_t i = 0;i<file_infos.size();++i) f.setAttribute(QString("name"),colFileInfo.name) ;
recursAddElements(_xml_doc,file_infos[i],root) ; f.setAttribute(QString("sha1"),colFileInfo.hash) ;
f.setAttribute(QString("size"),QString::number(colFileInfo.size)) ;
e.appendChild(f) ;
}
else if (colFileInfo.type == DIR_TYPE_DIR)
{
QDomElement d = doc.createElement("Directory") ;
d.setAttribute(QString("name"),colFileInfo.name) ;
for (std::vector<ColFileInfo>::const_iterator it = colFileInfo.children.begin(); it != colFileInfo.children.end(); it++)
{
recursAddElements(doc,(*it),d) ;
}
e.appendChild(d) ;
}
} }
static void showErrorBox(const QString& filename, const QString& error) static void showErrorBox(const QString& fileName, const QString& error)
{ {
QMessageBox mb(QMessageBox::Warning, QObject::tr("Failed to process collection file"), QObject::tr("The collection file %1 could not be opened.\nReported error is: \n\n%2").arg(filename).arg(error), QMessageBox::Ok); QMessageBox mb(QMessageBox::Warning, QObject::tr("Failed to process collection file"), QObject::tr("The collection file %1 could not be opened.\nReported error is: \n\n%2").arg(fileName).arg(error), QMessageBox::Ok);
mb.setWindowIcon(QIcon(":/images/rstray3.png")); mb.setWindowIcon(QIcon(":/images/rstray3.png"));
mb.exec(); mb.exec();
} }
bool RsCollectionFile::load(const QString& filename, bool showError /* = true*/) bool RsCollectionFile::load(const QString& fileName, bool showError /* = true*/)
{ {
QFile file(filename);
if (!checkFile(fileName,showError)) return false;
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) if (!file.open(QIODevice::ReadOnly))
{ {
std::cerr << "Cannot open file " << filename.toStdString() << " !!" << std::endl; std::cerr << "Cannot open file " << fileName.toStdString() << " !!" << std::endl;
if (showError) { if (showError) {
showErrorBox(filename, QApplication::translate("RsCollectionFile", "Cannot open file %1").arg(filename)); showErrorBox(fileName, QApplication::translate("RsCollectionFile", "Cannot open file %1").arg(fileName));
} }
return false; return false;
} }
// check that the file is a valid rscollection file, and not a lol bomb or some shit like this bool ok = _xml_doc.setContent(&file) ;
file.close();
std::cerr << "Checking this file for bomb elements and various wrong stuff" << std::endl;
FILE *f = fopen(filename.toStdString().c_str(),"r") ; if (ok) {
_fileName = fileName;
} else {
if (showError) {
showErrorBox(fileName, QApplication::translate("RsCollectionFile", "Error parsing xml file"));
}
}
return ok;
}
// check that the file is a valid rscollection file, and not a lol bomb or some shit like this
bool RsCollectionFile::checkFile(const QString& fileName, bool showError)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
{
std::cerr << "Cannot open file " << fileName.toStdString() << " !!" << std::endl;
if (showError) {
showErrorBox(fileName, QApplication::translate("RsCollectionFile", "Cannot open file %1").arg(fileName));
}
return false;
}
if (file.reset()){
std::cerr << "Checking this file for bomb elements and various wrong stuff" << std::endl;
char c ; char c ;
std::vector<std::string> bad_strings ; std::vector<std::string> bad_strings ;
@ -189,13 +260,18 @@ bool RsCollectionFile::load(const QString& filename, bool showError /* = true*/)
static const int max_size = 12 ; // should be as large as the largest element in bad_strings static const int max_size = 12 ; // should be as large as the largest element in bad_strings
char current[max_size] = { 0,0,0,0,0,0,0,0,0,0,0,0 } ; char current[max_size] = { 0,0,0,0,0,0,0,0,0,0,0,0 } ;
int n=0 ; int n=0 ;
while( (c = fgetc(f)) != EOF || n >= 0) while( !file.atEnd() || n >= 0)
{ {
if (!file.atEnd())
file.getChar(&c);
else
c=0;
if(c == '\t' || c == '\n' || c == '\b' || c == '\r') if(c == '\t' || c == '\n' || c == '\b' || c == '\r')
continue ; continue ;
if(n == max_size || c==EOF) if(n == max_size || file.atEnd())
for(int i=0;i<n-1;++i) for(int i=0;i<n-1;++i)
current[i] = current[i+1] ; current[i] = current[i+1] ;
@ -204,63 +280,51 @@ bool RsCollectionFile::load(const QString& filename, bool showError /* = true*/)
if(c >= 'A' && c <= 'Z') c += 'a' - 'A' ; if(c >= 'A' && c <= 'Z') c += 'a' - 'A' ;
if(c != EOF) if(!file.atEnd())
current[n] = c ; current[n] = c ;
else else
current[n] = 0 ; current[n] = 0 ;
//std::cerr << "n==" << n <<" Checking string " << std::string(current,n+1) << " c = " << std::hex << (int)c << std::dec << std::endl; //std::cerr << "n==" << n <<" Checking string " << std::string(current,n+1) << " c = " << std::hex << (int)c << std::dec << std::endl;
for(int i=0;i<bad_strings.size();++i) for(uint i=0;i<bad_strings.size();++i)
if(std::string(current,bad_strings[i].length()) == bad_strings[i]) if(std::string(current,bad_strings[i].length()) == bad_strings[i])
{ {
showErrorBox(filename, QApplication::translate("RsCollectionFile", "This file contains the string \"%1\" and is therefore an invalid collection file. \n\nIf you believe it is correct, remove the corresponding line from the file and re-open it with Retroshare.").arg(bad_strings[i].c_str())); showErrorBox(file.fileName(), QApplication::translate("RsCollectionFile", "This file contains the string \"%1\" and is therefore an invalid collection file. \n\nIf you believe it is correct, remove the corresponding line from the file and re-open it with Retroshare.").arg(bad_strings[i].c_str()));
file.close();
return false ; return false ;
//std::cerr << "Bad string detected" << std::endl; //std::cerr << "Bad string detected" << std::endl;
} }
if(c == EOF) if(file.atEnd())
n-- ; n-- ;
else if(n < max_size) else if(n < max_size)
n++ ; n++ ;
} }
fclose(f) ;
// std::cerr << "File is clean!" << std::endl;
// return false ;
bool ok = _xml_doc.setContent(&file) ;
file.close(); file.close();
return true;
if (ok) {
_filename = filename;
} else {
if (showError) {
showErrorBox(filename, QApplication::translate("RsCollectionFile", "Error parsing xml file"));
} }
} return false;
return ok;
} }
bool RsCollectionFile::load(QWidget *parent) bool RsCollectionFile::load(QWidget *parent)
{ {
QString filename; QString fileName;
if (!misc::getOpenFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Open collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")", filename)) if (!misc::getOpenFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Open collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")", fileName))
return false; return false;
std::cerr << "Got file name: " << filename.toStdString() << std::endl; std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
return load(filename, true); return load(fileName, true);
} }
bool RsCollectionFile::save(const QString& filename) const bool RsCollectionFile::save(const QString& fileName) const
{ {
QFile file(filename); QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) if (!file.open(QIODevice::WriteOnly))
{ {
std::cerr << "Cannot write to file " << filename.toStdString() << " !!" << std::endl; std::cerr << "Cannot write to file " << fileName.toStdString() << " !!" << std::endl;
return false; return false;
} }
@ -276,37 +340,135 @@ bool RsCollectionFile::save(const QString& filename) const
bool RsCollectionFile::save(QWidget *parent) const bool RsCollectionFile::save(QWidget *parent) const
{ {
QString filename; QString fileName;
if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Create collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")", filename)) if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE, QApplication::translate("RsCollectionFile", "Create collection file"), QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")", fileName))
return false; return false;
if (!filename.endsWith("." + RsCollectionFile::ExtensionString)) if (!fileName.endsWith("." + RsCollectionFile::ExtensionString))
filename += "." + RsCollectionFile::ExtensionString ; fileName += "." + RsCollectionFile::ExtensionString ;
std::cerr << "Got file name: " << filename.toStdString() << std::endl; std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
return save(filename); return save(fileName);
}
bool RsCollectionFile::openNewColl(QWidget *parent)
{
QString fileName;
if(!misc::getSaveFileName(parent, RshareSettings::LASTDIR_EXTRAFILE
, QApplication::translate("RsCollectionFile", "Create collection file")
, QApplication::translate("RsCollectionFile", "Collection files") + " (*." + RsCollectionFile::ExtensionString + ")"
, fileName,0, QFileDialog::DontConfirmOverwrite))
return false;
if (!fileName.endsWith("." + RsCollectionFile::ExtensionString))
fileName += "." + RsCollectionFile::ExtensionString ;
std::cerr << "Got file name: " << fileName.toStdString() << std::endl;
QFile file(fileName) ;
if(file.exists())
{
if (!checkFile(fileName,true)) return false;
QMessageBox mb;
mb.setText(tr("Save Collection File."));
mb.setInformativeText(tr("File already exist.")+"\n"+tr("What do you want to do?"));
QAbstractButton *btnOwerWrite = mb.addButton(tr("Overwrite"), QMessageBox::YesRole);
QAbstractButton *btnMerge = mb.addButton(tr("Merge"), QMessageBox::NoRole);
QAbstractButton *btnCancel = mb.addButton(tr("Cancel"), QMessageBox::ResetRole);
mb.setIcon(QMessageBox::Question);
mb.exec();
if (mb.clickedButton()==btnOwerWrite) {
//Nothing to do _xml_doc already up to date
} else if (mb.clickedButton()==btnMerge) {
//Open old file to merge it with _xml_doc
QDomDocument qddOldFile("RsCollection");
if (qddOldFile.setContent(&file)) {
QDomElement docOldElem = qddOldFile.elementsByTagName("RsCollection").at(0).toElement();
std::vector<ColFileInfo> colOldFileInfos;
recursCollectColFileInfos(docOldElem,colOldFileInfos,QString(),false);
QDomElement root = _xml_doc.elementsByTagName("RsCollection").at(0).toElement();
for(uint32_t i = 0;i<colOldFileInfos.size();++i){
recursAddElements(_xml_doc,colOldFileInfos[i],root) ;
}
}
} else if (mb.clickedButton()==btnCancel) {
return false;
} else {
return false;
}
}//if(file.exists())
_fileName=fileName;
std::vector<ColFileInfo> colFileInfos ;
recursCollectColFileInfos(_xml_doc.documentElement(),colFileInfos,QString(),false) ;
RsCollectionDialog* rcd = new RsCollectionDialog(fileName, colFileInfos,true);
connect(rcd,SIGNAL(saveColl(std::vector<ColFileInfo>, QString)),this,SLOT(saveColl(std::vector<ColFileInfo>, QString))) ;
_saved=false;
rcd->exec() ;
delete rcd;
return _saved;
}
bool RsCollectionFile::openColl(const QString& fileName, bool readOnly /* = false */, bool showError /* = true*/)
{
if (load(fileName, showError)) {
std::vector<ColFileInfo> colFileInfos ;
recursCollectColFileInfos(_xml_doc.documentElement(),colFileInfos,QString(),false) ;
RsCollectionDialog* rcd = new RsCollectionDialog(fileName, colFileInfos, true, readOnly);
connect(rcd,SIGNAL(saveColl(std::vector<ColFileInfo>, QString)),this,SLOT(saveColl(std::vector<ColFileInfo>, QString))) ;
_saved=false;
rcd->exec() ;
delete rcd;
return _saved;
}//if (load(fileName, showError))
return false;
} }
qulonglong RsCollectionFile::size() qulonglong RsCollectionFile::size()
{ {
QDomElement docElem = _xml_doc.documentElement(); QDomElement docElem = _xml_doc.documentElement();
std::vector<DLinfo> dlinfos; std::vector<ColFileInfo> colFileInfos;
recursCollectDLinfos(docElem, dlinfos, QString(),false); recursCollectColFileInfos(docElem, colFileInfos, QString(),false);
uint64_t size = 0; uint64_t size = 0;
for (uint32_t i = 0; i < dlinfos.size(); ++i) { for (uint32_t i = 0; i < colFileInfos.size(); ++i) {
size += dlinfos[i].size; size += colFileInfos[i].size;
} }
return size; return size;
} }
bool RsCollectionFile::isCollectionFile(const QString &filename) bool RsCollectionFile::isCollectionFile(const QString &fileName)
{ {
QString ext = QFileInfo(filename).suffix().toLower(); QString ext = QFileInfo(fileName).suffix().toLower();
return (ext == RsCollectionFile::ExtensionString); return (ext == RsCollectionFile::ExtensionString);
} }
void RsCollectionFile::saveColl(std::vector<ColFileInfo> colFileInfos, const QString &fileName)
{
QDomElement root = _xml_doc.elementsByTagName("RsCollection").at(0).toElement();
while (root.childNodes().count()>0) root.removeChild(root.firstChild());
for(uint32_t i = 0;i<colFileInfos.size();++i)
recursAddElements(_xml_doc,colFileInfos[i],root) ;
_saved=save(fileName);
}

View File

@ -29,53 +29,82 @@
#pragma once #pragma once
#include <QObject>
#include <QString> #include <QString>
#include <QDomDocument> #include <QDomDocument>
#include <QFile>
#include <retroshare/rsfiles.h> #include <retroshare/rsfiles.h>
#include <QMetaType>
class QDomElement ; class QDomElement ;
class QWidget; class QWidget;
class RsCollectionFile class ColFileInfo
{ {
public: public:
static const QString ExtensionString ; ColFileInfo(): name(""), size(0), path(""), hash(""), type(0), filename_has_wrong_characters(false), checked(false) {}
RsCollectionFile() ; public:
QString name ;
qulonglong size ;
QString path ;
QString hash ;
uint8_t type;
bool filename_has_wrong_characters ;
std::vector<ColFileInfo> children;
bool checked;
};
Q_DECLARE_METATYPE(ColFileInfo)
class RsCollectionFile : public QObject
{
Q_OBJECT
public:
RsCollectionFile(QObject *parent = 0) ;
// create from list of files and directories // create from list of files and directories
RsCollectionFile(const std::vector<DirDetails>& file_entries) ; RsCollectionFile(const std::vector<DirDetails>& file_entries, QObject *parent = 0) ;
virtual ~RsCollectionFile() ;
static const QString ExtensionString ;
// Loads file from disk. // Loads file from disk.
bool load(QWidget *parent); bool load(QWidget *parent);
bool load(const QString& filename, bool showError = true); bool load(const QString& fileName, bool showError = true);
// Save to disk // Save to disk
bool save(QWidget *parent) const ; bool save(QWidget *parent) const ;
bool save(const QString& filename) const ; bool save(const QString& fileName) const ;
// Open new collection
bool openNewColl(QWidget *parent);
// Open existing collection
bool openColl(const QString& fileName, bool readOnly = false, bool showError = true);
// Download the content. // Download the content.
void downloadFiles() const ; void downloadFiles() const ;
qulonglong size(); qulonglong size();
static bool isCollectionFile(const QString& filename); static bool isCollectionFile(const QString& fileName);
private slots:
void saveColl(std::vector<ColFileInfo> colFileInfos, const QString& fileName);
private: private:
struct DLinfo
{
QString name ;
qulonglong size ;
QString path ;
QString hash ;
bool filename_has_wrong_characters ;
};
void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ; void recursAddElements(QDomDocument&,const DirDetails&,QDomElement&) const ;
void recursCollectDLinfos(const QDomElement&,std::vector<DLinfo>& dlinfos,const QString& current_dir,bool bad_chars_in_parent) const ; void recursAddElements(QDomDocument&,const ColFileInfo&,QDomElement&) const;
void recursCollectColFileInfos(const QDomElement&,std::vector<ColFileInfo>& colFileInfos,const QString& current_dir,bool bad_chars_in_parent) const ;
// check that the file is a valid rscollection file, and not a lol bomb or some shit like this
static bool checkFile(const QString &fileName, bool showError);
QDomDocument _xml_doc ; QDomDocument _xml_doc ;
QString _filename ; QString _fileName ;
bool _saved;
friend class RsCollectionDialog ; friend class RsCollectionDialog ;
}; };

View File

@ -683,5 +683,8 @@
<file>images/view-certificate-sign-48.png</file> <file>images/view-certificate-sign-48.png</file>
<file>images/toasterEnable.png</file> <file>images/toasterEnable.png</file>
<file>images/toasterDisable.png</file> <file>images/toasterDisable.png</file>
<file>images/library_edit.png</file>
<file>images/library_view.png</file>
<file>images/library_add.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -297,11 +297,13 @@ QPixmap misc::getOpenThumbnailedPicture(QWidget *parent, const QString &caption,
//return QPixmap(fileName).scaledToHeight(width, height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); //return QPixmap(fileName).scaledToHeight(width, height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
} }
bool misc::getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file) bool misc::getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type
, const QString &caption, const QString &filter
, QString &file, QFileDialog::Options options)
{ {
QString lastDir = Settings->getLastDir(type); QString lastDir = Settings->getLastDir(type);
file = QFileDialog::getOpenFileName(parent, caption, lastDir, filter, NULL, QFileDialog::DontResolveSymlinks); file = QFileDialog::getOpenFileName(parent, caption, lastDir, filter, NULL, QFileDialog::DontResolveSymlinks | options);
if (file.isEmpty()) if (file.isEmpty())
return false; return false;
@ -318,11 +320,13 @@ bool misc::getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type, co
return true; return true;
} }
bool misc::getOpenFileNames(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QStringList &files) bool misc::getOpenFileNames(QWidget *parent, RshareSettings::enumLastDir type
, const QString &caption, const QString &filter
, QStringList &files, QFileDialog::Options options)
{ {
QString lastDir = Settings->getLastDir(type); QString lastDir = Settings->getLastDir(type);
files = QFileDialog::getOpenFileNames(parent, caption, lastDir, filter, NULL, QFileDialog::DontResolveSymlinks); files = QFileDialog::getOpenFileNames(parent, caption, lastDir, filter, NULL, QFileDialog::DontResolveSymlinks | options);
if (files.isEmpty()) if (files.isEmpty())
return false; return false;
@ -341,11 +345,14 @@ bool misc::getOpenFileNames(QWidget *parent, RshareSettings::enumLastDir type, c
return true; return true;
} }
bool misc::getSaveFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file) bool misc::getSaveFileName(QWidget *parent, RshareSettings::enumLastDir type
, const QString &caption , const QString &filter
, QString &file, QString *selectedFilter
, QFileDialog::Options options)
{ {
QString lastDir = Settings->getLastDir(type); QString lastDir = Settings->getLastDir(type);
file = QFileDialog::getSaveFileName(parent, caption, lastDir, filter); file = QFileDialog::getSaveFileName(parent, caption, lastDir, filter, selectedFilter, options);
if (file.isEmpty()) if (file.isEmpty())
return false; return false;

View File

@ -27,6 +27,7 @@
#include <QObject> #include <QObject>
#include <QPair> #include <QPair>
#include <QThread> #include <QThread>
#include <QFileDialog>
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
@ -159,10 +160,17 @@ class misc : public QObject
static bool getOpenAvatarPicture(QWidget *parent, QByteArray &image_data); static bool getOpenAvatarPicture(QWidget *parent, QByteArray &image_data);
static QPixmap getOpenThumbnailedPicture(QWidget *parent, const QString &caption, int width, int height); static QPixmap getOpenThumbnailedPicture(QWidget *parent, const QString &caption, int width, int height);
static bool getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file); static bool getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type
static bool getOpenFileNames(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QStringList &files); , const QString &caption, const QString &filter
, QString &file, QFileDialog::Options options = 0);
static bool getOpenFileNames(QWidget *parent, RshareSettings::enumLastDir type
, const QString &caption, const QString &filter
, QStringList &files, QFileDialog::Options options = 0);
static bool getSaveFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file); static bool getSaveFileName(QWidget *parent, RshareSettings::enumLastDir type
, const QString &caption , const QString &filter
, QString &file, QString *selectedFilter = NULL
, QFileDialog::Options options = 0);
}; };
// Trick to get a portable sleep() function // Trick to get a portable sleep() function