mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 11:54:22 -04:00
rework and code cleaning in customPopupMenu for Transfers (Patch from Phenom)
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6620 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
a98642dab5
commit
8549e10d1c
1 changed files with 82 additions and 77 deletions
|
@ -612,39 +612,24 @@ void TransfersDialog::processSettings(bool bLoad)
|
||||||
void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
|
void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
|
||||||
{
|
{
|
||||||
std::set<std::string> items;
|
std::set<std::string> items;
|
||||||
std::set<std::string>::iterator it;
|
|
||||||
getSelectedItems(&items, NULL);
|
getSelectedItems(&items, NULL);
|
||||||
|
|
||||||
bool single = (items.size() == 1) ;
|
bool single = (items.size() == 1) ;
|
||||||
|
|
||||||
/* check which item is selected
|
bool atLeastOne_Waiting = false;
|
||||||
* - if it is completed - play should appear in menu
|
bool atLeastOne_Downloading = false;
|
||||||
*/
|
bool atLeastOne_Complete = false;
|
||||||
std::cerr << "TransfersDialog::downloadListCustomPopupMenu()" << std::endl;
|
bool atLeastOne_Queued = 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;
|
||||||
|
|
||||||
FileInfo info;
|
FileInfo info;
|
||||||
|
|
||||||
for (it = items.begin(); it != items.end(); it ++) {
|
|
||||||
if (!rsFiles->FileDetails(*it, RS_FILE_HINTS_DOWNLOAD, info)) continue;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool addPlayOption = false;
|
|
||||||
bool addOpenFileOption = false;
|
|
||||||
|
|
||||||
if (info.downloadStatus == FT_STATE_COMPLETE)
|
|
||||||
{
|
|
||||||
std::cerr << "Add Play Option" << std::endl;
|
|
||||||
|
|
||||||
addOpenFileOption = true;
|
|
||||||
|
|
||||||
size_t pos = info.fname.find_last_of('.');
|
|
||||||
|
|
||||||
/* check if the file is a media file */
|
|
||||||
if(pos != std::string::npos && misc::isPreviewable(info.fname.substr(pos + 1).c_str()))
|
|
||||||
addPlayOption = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QMenu priorityQueueMenu(tr("Move in Queue..."), this);
|
QMenu priorityQueueMenu(tr("Move in Queue..."), this);
|
||||||
priorityQueueMenu.setIcon(QIcon(IMAGE_PRIORITY));
|
priorityQueueMenu.setIcon(QIcon(IMAGE_PRIORITY));
|
||||||
priorityQueueMenu.addAction(queueTopAct);
|
priorityQueueMenu.addAction(queueTopAct);
|
||||||
|
@ -666,42 +651,77 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
|
||||||
|
|
||||||
QMenu contextMnu( this );
|
QMenu contextMnu( this );
|
||||||
|
|
||||||
if (addPlayOption)
|
if(!RSLinkClipboard::empty(RetroShareLink::TYPE_FILE))
|
||||||
contextMnu.addAction(playAct);
|
add_PasteLink=true;
|
||||||
|
|
||||||
contextMnu.addSeparator();
|
|
||||||
|
|
||||||
if(!items.empty())
|
if(!items.empty())
|
||||||
{
|
{
|
||||||
bool all_paused = true ;
|
add_CopyLink = true;
|
||||||
bool all_downld = true ;
|
|
||||||
bool all_downloading = true ;
|
|
||||||
bool all_queued = true ;
|
|
||||||
|
|
||||||
QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes ();
|
QModelIndexList lst = ui.downloadList->selectionModel ()->selectedIndexes ();
|
||||||
|
|
||||||
|
//Look for all selected items
|
||||||
for (int i = 0; i < lst.count (); i++)
|
for (int i = 0; i < lst.count (); i++)
|
||||||
{
|
{
|
||||||
if ( lst[i].column() == 0 && info.downloadStatus == FT_STATE_PAUSED )
|
//Look only for first column == File List
|
||||||
all_downld = false ;
|
|
||||||
if ( lst[i].column() == 0 && info.downloadStatus == FT_STATE_DOWNLOADING )
|
|
||||||
all_paused = false ;
|
|
||||||
|
|
||||||
if ( lst[i].column() == 0)
|
if ( lst[i].column() == 0)
|
||||||
{
|
{
|
||||||
|
//Get Info for current item
|
||||||
|
if (rsFiles->FileDetails(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_WAITING = 0x0002 ;
|
||||||
|
const uint32_t FT_STATE_DOWNLOADING = 0x0003 ;
|
||||||
|
const uint32_t FT_STATE_COMPLETE = 0x0004 ;
|
||||||
|
const uint32_t FT_STATE_QUEUED = 0x0005 ;
|
||||||
|
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_DOWNLOADING)
|
||||||
|
{
|
||||||
|
atLeastOne_Downloading=true;
|
||||||
|
}
|
||||||
|
if (info.downloadStatus == FT_STATE_COMPLETE)
|
||||||
|
{
|
||||||
|
atLeastOne_Complete = true;
|
||||||
|
add_OpenFileOption = single;
|
||||||
|
}
|
||||||
if(info.downloadStatus == FT_STATE_QUEUED)
|
if(info.downloadStatus == FT_STATE_QUEUED)
|
||||||
all_downloading = false ;
|
{
|
||||||
else
|
atLeastOne_Queued = true;
|
||||||
all_queued = false ;
|
}
|
||||||
|
if (info.downloadStatus == FT_STATE_PAUSED)
|
||||||
|
{
|
||||||
|
atLeastOne_Paused = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t pos = info.fname.find_last_of('.');
|
||||||
|
/* check if the file is a media file */
|
||||||
|
if(pos != std::string::npos)
|
||||||
|
{
|
||||||
|
if (misc::isPreviewable(info.fname.substr(pos + 1).c_str()))
|
||||||
|
{
|
||||||
|
add_PlayOption = (info.downloadStatus != FT_STATE_COMPLETE);
|
||||||
|
add_PreviewOption = !add_PlayOption;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(all_downloading)
|
}//if (rsFiles->FileDetails(lst[i].data(COLUMN_ID), RS_FILE_HINTS_DOWNLOAD, info))
|
||||||
|
}//if (lst[i].column() == 0)
|
||||||
|
}// for (int i = 0; i < lst.count (); i++)
|
||||||
|
}//if(!items.empty())
|
||||||
|
|
||||||
|
if(atLeastOne_Downloading)
|
||||||
contextMnu.addMenu(&prioritySpeedMenu);
|
contextMnu.addMenu(&prioritySpeedMenu);
|
||||||
else if(all_queued)
|
if(atLeastOne_Queued)
|
||||||
contextMnu.addMenu(&priorityQueueMenu) ;
|
contextMnu.addMenu(&priorityQueueMenu) ;
|
||||||
|
|
||||||
if(all_downloading)
|
if(!atLeastOne_Queued && !items.empty())
|
||||||
{
|
{
|
||||||
contextMnu.addMenu( &chunkMenu);
|
contextMnu.addMenu( &chunkMenu);
|
||||||
|
|
||||||
|
@ -731,55 +751,42 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!all_paused)
|
if(atLeastOne_Paused)
|
||||||
contextMnu.addAction( pauseAct);
|
|
||||||
if(!all_downld)
|
|
||||||
contextMnu.addAction( resumeAct);
|
contextMnu.addAction( resumeAct);
|
||||||
|
if(atLeastOne_Downloading || atLeastOne_Queued || atLeastOne_Waiting)
|
||||||
if(single)
|
|
||||||
{
|
|
||||||
if(info.downloadStatus == FT_STATE_PAUSED)
|
|
||||||
contextMnu.addAction( resumeAct);
|
|
||||||
else if(info.downloadStatus != FT_STATE_COMPLETE)
|
|
||||||
contextMnu.addAction( pauseAct);
|
contextMnu.addAction( pauseAct);
|
||||||
}
|
|
||||||
|
|
||||||
if(info.downloadStatus != FT_STATE_COMPLETE)
|
if(!atLeastOne_Complete && !items.empty())
|
||||||
{
|
{
|
||||||
//#ifdef USE_NEW_CHUNK_CHECKING_CODE
|
|
||||||
contextMnu.addAction( forceCheckAct);
|
contextMnu.addAction( forceCheckAct);
|
||||||
//#endif
|
|
||||||
contextMnu.addAction( cancelAct);
|
contextMnu.addAction( cancelAct);
|
||||||
}
|
}
|
||||||
|
if (add_PlayOption)
|
||||||
contextMnu.addSeparator();
|
{
|
||||||
|
contextMnu.addAction(playAct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(atLeastOne_Paused || atLeastOne_Downloading || atLeastOne_Complete || add_PlayOption)
|
||||||
|
contextMnu.addSeparator();//------------------------------------------------
|
||||||
|
|
||||||
if(single)
|
if(single)
|
||||||
{
|
{
|
||||||
if (addOpenFileOption)
|
if (add_OpenFileOption) contextMnu.addAction( openFileAct);
|
||||||
contextMnu.addAction( openFileAct);
|
if (add_PreviewOption) contextMnu.addAction( previewFileAct);
|
||||||
|
|
||||||
contextMnu.addAction( previewFileAct);
|
|
||||||
contextMnu.addAction( openFolderAct);
|
contextMnu.addAction( openFolderAct);
|
||||||
contextMnu.addAction( detailsFileAct);
|
contextMnu.addAction( detailsFileAct);
|
||||||
contextMnu.addSeparator();
|
contextMnu.addSeparator();//--------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
contextMnu.addAction( clearCompletedAct);
|
contextMnu.addAction( clearCompletedAct);
|
||||||
contextMnu.addSeparator();
|
contextMnu.addSeparator();//------------------------------------------------
|
||||||
|
|
||||||
if(!items.empty())
|
if (add_CopyLink)
|
||||||
contextMnu.addAction( copyLinkAct);
|
contextMnu.addAction( copyLinkAct);
|
||||||
|
if (add_PasteLink)
|
||||||
if(!RSLinkClipboard::empty(RetroShareLink::TYPE_FILE)) {
|
|
||||||
pasteLinkAct->setEnabled(true);
|
|
||||||
} else {
|
|
||||||
pasteLinkAct->setDisabled(true);
|
|
||||||
}
|
|
||||||
contextMnu.addAction( pasteLinkAct);
|
contextMnu.addAction( pasteLinkAct);
|
||||||
|
if (add_CopyLink || add_PasteLink)
|
||||||
contextMnu.addSeparator();
|
contextMnu.addSeparator();//--------------------------------------------
|
||||||
|
|
||||||
if (DLListModel->rowCount()>0 ) {
|
if (DLListModel->rowCount()>0 ) {
|
||||||
contextMnu.addAction( expandAllAct ) ;
|
contextMnu.addAction( expandAllAct ) ;
|
||||||
|
@ -792,8 +799,6 @@ void TransfersDialog::downloadListCustomPopupMenu( QPoint /*point*/ )
|
||||||
toggleShowCacheTransfersAct->setChecked(_show_cache_transfers) ;
|
toggleShowCacheTransfersAct->setChecked(_show_cache_transfers) ;
|
||||||
contextMnu.addAction( openCollectionAct ) ;
|
contextMnu.addAction( openCollectionAct ) ;
|
||||||
|
|
||||||
contextMnu.addSeparator();
|
|
||||||
|
|
||||||
contextMnu.exec(QCursor::pos());
|
contextMnu.exec(QCursor::pos());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue