From 618cc702a83834bb51d2296101b18c7062cfe983 Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Sun, 31 Oct 2010 19:29:26 +0000 Subject: [PATCH] added file moving utility to rsFile interface to channels file save consistent msgs now save from field in received msgs also allowed user to delete file added in createChanMsg dialog git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3727 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/ft/ftserver.cc | 7 ++++++ libretroshare/src/ft/ftserver.h | 1 + libretroshare/src/retroshare/rsfiles.h | 1 + libretroshare/src/services/p3msgservice.cc | 26 +++++++++++++++++--- libretroshare/src/services/p3msgservice.h | 3 +++ retroshare-gui/src/gui/feeds/SubFileItem.cpp | 24 +++++++++++++++--- 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 727561056..4e1a07de6 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -571,6 +571,13 @@ bool ftServer::InDirectoryCheck() return mFiMon->inDirectoryCheck(); } +bool ftServer::CopyFile(const std::string& source, const std::string& dest) +{ + + mFtController->copyFile(source, dest); + +} + bool ftServer::getSharedDirectories(std::list &dirs) { mFiMon->getSharedDirectories(dirs); diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 8fa49c093..29de52fe3 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -181,6 +181,7 @@ virtual int SearchBoolExp(Expression * exp, std::list &results,uint3 virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath); virtual void ForceDirectoryCheck(); virtual bool InDirectoryCheck(); +virtual bool CopyFile(const std::string& source, const std::string& dest); /*** * Directory Handling diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 8db3ef7db..0e71e07d7 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -170,6 +170,7 @@ class RsFiles virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0; virtual void ForceDirectoryCheck() = 0; virtual bool InDirectoryCheck() = 0; + virtual bool CopyFile(const std::string& source,const std::string& dest) = 0; /*** * Directory Control diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 3c5516502..7ce780940 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -169,6 +169,10 @@ int p3MsgService::incomingMsgs() } imsg[mi->msgId] = mi; + RsMsgSrcId* msi = new RsMsgSrcId(); + msi->msgId = mi->msgId; + msi->srcId = mi->PeerId(); + mSrcIdList.push_back(msi); msgChanged.IndicateChanged(); IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/ @@ -200,7 +204,6 @@ int p3MsgService::checkOutgoingMessages() std::list::iterator it; std::list toErase; - RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ std::map::iterator mit; @@ -281,8 +284,9 @@ std::list p3MsgService::saveList(bool& cleanup) std::map::iterator mit; std::map::iterator mit2; std::map::iterator mit3; + std::list::iterator lit; - MsgTagType stdTags; + MsgTagType stdTags; cleanup = false; @@ -291,6 +295,10 @@ std::list p3MsgService::saveList(bool& cleanup) for(mit = imsg.begin(); mit != imsg.end(); mit++) itemList.push_back(mit->second); + for(lit = mSrcIdList.begin(); lit != mSrcIdList.end(); lit++) + itemList.push_back(*lit); + + for(mit = msgOutgoing.begin(); mit != msgOutgoing.end(); mit++) itemList.push_back(mit->second) ; @@ -362,11 +370,14 @@ bool p3MsgService::loadList(std::list load) RsMsgItem *mitem; RsMsgTagType* mtt; RsMsgTags* mti; - + RsMsgSrcId* msi; std::list items; std::list::iterator it; std::map::iterator tagIt; + std::map srcIdMsgMap; + std::map::iterator srcIt; + // load items and calculate next unique msgId for(it = load.begin(); it != load.end(); it++) @@ -399,6 +410,11 @@ bool p3MsgService::loadList(std::list load) { mMsgTags.insert(std::pair(mti->msgId, mti)); } + else if(NULL != (msi = dynamic_cast(*it))) + { + srcIdMsgMap.insert(std::pair(msi->msgId, msi->srcId)); + mSrcIdList.push_back(msi); // does not need to be kept + } } // sort items into lists @@ -428,6 +444,10 @@ bool p3MsgService::loadList(std::list load) else { RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ + srcIt = srcIdMsgMap.find(mitem->msgId); + + if(srcIt != srcIdMsgMap.end()) + mitem->PeerId(srcIt->second); imsg[mitem->msgId] = mitem; } diff --git a/libretroshare/src/services/p3msgservice.h b/libretroshare/src/services/p3msgservice.h index c00e5690a..6518c9881 100644 --- a/libretroshare/src/services/p3msgservice.h +++ b/libretroshare/src/services/p3msgservice.h @@ -131,6 +131,9 @@ void initStandardTagTypes(); Indicator msgChanged; uint32_t mMsgUniqueId; + // used delete msgSrcIds after config save + std::list mSrcIdList; + std::string config_dir; }; diff --git a/retroshare-gui/src/gui/feeds/SubFileItem.cpp b/retroshare-gui/src/gui/feeds/SubFileItem.cpp index 370a0de2d..3e99aba0c 100644 --- a/retroshare-gui/src/gui/feeds/SubFileItem.cpp +++ b/retroshare-gui/src/gui/feeds/SubFileItem.cpp @@ -227,7 +227,7 @@ void SubFileItem::updateItemStatic() playButton->setEnabled(false); downloadButton->setEnabled(false); - cancelButton->setEnabled(false); + cancelButton->setEnabled(true); progressBar->setValue(0); filename = "[" + tr("EXTRA") + "] " + filename; @@ -281,6 +281,7 @@ void SubFileItem::updateItemStatic() if (mMode == SFI_STATE_LOCAL) { saveButton->setEnabled(true); + cancelButton->setEnabled(true); // channel files which are extra files are removed } else { @@ -538,9 +539,11 @@ void SubFileItem::cancel() mMode = SFI_STATE_ERROR; /* Only occurs - if it is downloading */ - if (mType == SFI_TYPE_ATTACH) + if ((mType == SFI_TYPE_ATTACH) || (mType == SFI_TYPE_CHANNEL)) { hide(); + rsFiles->ExtraFileRemove(FileHash(), RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_EXTRA); + mPath = ""; } else { @@ -624,6 +627,8 @@ void SubFileItem::save() std::cerr << std::endl; #endif + FileInfo fInfo; + if (mType == SFI_TYPE_CHANNEL) { /* only enable these function for Channels. */ @@ -639,7 +644,19 @@ void SubFileItem::save() if (destpath != "") { - rsFiles->ExtraFileMove(mFileName, mFileHash, mFileSize, destpath); + bool copied = rsFiles->ExtraFileMove(mFileName, mFileHash, mFileSize, destpath); + + // may be manually downloaded channel file + if(!copied){ + rsFiles->FileDetails(mFileHash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_EXTRA, fInfo); + + if(fInfo.path != "") + { + + destpath += "/" + fInfo.fname; + rsFiles->CopyFile(fInfo.path, destpath); + } + } } } else @@ -668,3 +685,4 @@ bool SubFileItem::isPlayable(bool &startable) return visible; } +