diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index 0e000f252..4ae1b5057 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -160,6 +160,8 @@ bool FileIndexMonitor::loadLocalCache(const CacheData &data) /* called with sto std::cerr << "FileIndexMonitor::loadCache() Success!"; std::cerr << std::endl; #endif + fi.root->row = 0; + fi.root->name = data.pname ; } else { @@ -466,6 +468,7 @@ void FileIndexMonitor::updateCycle() std::cerr << "List of Files to rehash in: " << dirpath << std::endl; #endif fiMods = true; + cb->notifyListPreChange(NOTIFY_LIST_DIRLIST, 0); } #ifdef FIM_DEBUG @@ -480,10 +483,10 @@ void FileIndexMonitor::updateCycle() } #endif - /* update files */ - for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++) - { -// currentJob = "Hashing file " + realpath ; + /* update files */ + for(hit = filesToHash.begin(); hit != filesToHash.end(); hit++) + { + // currentJob = "Hashing file " + realpath ; if (hashFile(realpath, (*hit))) { @@ -492,8 +495,8 @@ void FileIndexMonitor::updateCycle() /* update fileIndex with new time */ /* update with new time */ - fi.updateFileEntry(dirpath, *hit, stamp); - + fi.updateFileEntry(dirpath, *hit, stamp); + /* unlock dirs */ fiMutex.unlock(); } @@ -503,18 +506,20 @@ void FileIndexMonitor::updateCycle() } /* don't hit the disk too hard! */ -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ + /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ #ifndef WINDOWS_SYS usleep(10000); /* 1/100 sec */ #else - Sleep(10); + Sleep(10); #endif -/********************************** WINDOWS/UNIX SPECIFIC PART ******************/ + /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ - } -// currentJob = "" ; - } + } + + if (filesToHash.size() > 0) + cb->notifyListChange(NOTIFY_LIST_DIRLIST, 0); + } fiMutex.lock(); { /* LOCKED DIRS */ @@ -543,12 +548,12 @@ void FileIndexMonitor::updateCycle() fiMods = true; } - } fiMutex.unlock(); /* UNLOCKED DIRS */ - + } if (fiMods) - saveFileIndexes() ; + locked_saveFileIndexes() ; + fiMutex.unlock(); /* UNLOCKED DIRS */ { RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/ @@ -557,10 +562,10 @@ void FileIndexMonitor::updateCycle() cb->notifyHashingInfo("") ; } -void FileIndexMonitor::saveFileIndexes() + +void FileIndexMonitor::locked_saveFileIndexes() { /* store to the cacheDirectory */ - RsStackMutex mutex(fiMutex) ; /* LOCKED DIRS */ std::string path = getCacheDir(); @@ -634,6 +639,8 @@ void FileIndexMonitor::saveFileIndexes() void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir) { + cb->notifyListPreChange(NOTIFY_LIST_DIRLIST, 0); + bool fimods = false ; #ifdef FIM_DEBUG std::cerr << "*** FileIndexMonitor: Updating flags for " << dir.filename << " to " << dir.shareflags << std::endl ; @@ -665,11 +672,16 @@ void FileIndexMonitor::updateShareFlags(const SharedDirInfo& dir) } } if(fimods) - saveFileIndexes() ; + { + RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */ + locked_saveFileIndexes() ; + } + cb->notifyListChange(NOTIFY_LIST_DIRLIST, 0); } /* interface */ void FileIndexMonitor::setSharedDirectories(std::list dirs) { + cb->notifyListPreChange(NOTIFY_LIST_DIRLIST, 0); std::list checkeddirs; @@ -703,32 +715,30 @@ void FileIndexMonitor::setSharedDirectories(std::list dirs) closedir(dir); } - { - RsStackMutex stack(fiMutex) ;/* LOCKED DIRS */ + RsStackMutex stack(fiMutex) ;/* LOCKED DIRS */ - pendingDirs = true; - pendingDirList = checkeddirs; - } + pendingDirs = true; + pendingDirList = checkeddirs; + + cb->notifyListChange(NOTIFY_LIST_DIRLIST, 0); } /* interface */ void FileIndexMonitor::getSharedDirectories(std::list &dirs) { - { - RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */ + RsStackMutex stack(fiMutex) ; /* LOCKED DIRS */ - /* must provide pendingDirs, as other parts depend on instanteous response */ - if (pendingDirs) - dirs = pendingDirList; - else - { - /* get actual list (not pending stuff) */ - std::map::const_iterator it; + /* must provide pendingDirs, as other parts depend on instanteous response */ +// if (pendingDirs) +// dirs = pendingDirList; +// else +// { + /* get actual list (not pending stuff) */ + std::map::const_iterator it; - for(it = directoryMap.begin(); it != directoryMap.end(); it++) - dirs.push_back(it->second) ; - } - } + for(it = directoryMap.begin(); it != directoryMap.end(); it++) + dirs.push_back(it->second) ; +// } } @@ -821,6 +831,7 @@ bool FileIndexMonitor::internal_setSharedDirectories() fi.setRootDirectories(topdirs, 0); + locked_saveFileIndexes() ; fiMutex.unlock(); /* UNLOCKED DIRS */ return true; @@ -899,3 +910,29 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent) return true; } +int FileIndexMonitor::RequestDirDetails(std::string uid, std::string path, DirDetails &details) const +{ + /* lock it up */ + RsStackMutex mutex(fiMutex) ; + + return (uid == fi.root->id) ; +} + +int FileIndexMonitor::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const +{ + RsStackMutex mutex(fiMutex) ; + +#ifdef FIM_DEBUG + std::cerr << "FileIndexMonitor::RequestDirDetails() ref=" << ref << " flags: " << flags << std::endl; +#endif + + /* root case */ + +#ifdef FIM_DEBUG + fi.root->checkParentPointers(); +#endif + + return fi.RequestDirDetails(ref,details,flags) ; +} + + diff --git a/libretroshare/src/dbase/fimonitor.h b/libretroshare/src/dbase/fimonitor.h index d625156ac..741620b8f 100644 --- a/libretroshare/src/dbase/fimonitor.h +++ b/libretroshare/src/dbase/fimonitor.h @@ -67,9 +67,6 @@ class NotifyBase ; * FileIndexMonitor *****************************************************************************************/ -static const uint32_t RS_SHARED_FLAGS_PUBLIC = 0x0001 ; -static const uint32_t RS_SHARED_FLAGS_ANONYM = 0x0002 ; - class FileIndexMonitor: public CacheSource, public RsThread { public: @@ -95,6 +92,11 @@ class FileIndexMonitor: public CacheSource, public RsThread virtual void run(); /* overloaded from RsThread */ void updateCycle(); + // Interface for browsing dir hirarchy + int RequestDirDetails(void*, DirDetails&, uint32_t) const ; + int RequestDirDetails(std::string uid, std::string path, DirDetails &details) const ; + + // set/update shared directories virtual void setSharedDirectories(std::list dirs); void getSharedDirectories(std::list& dirs); void updateShareFlags(const SharedDirInfo& info) ; @@ -107,7 +109,7 @@ class FileIndexMonitor: public CacheSource, public RsThread private: // saves file indexs and update the cache. - void saveFileIndexes() ; + void locked_saveFileIndexes() ; /* the mutex should be locked before calling... these. */ std::string locked_findRealRoot(std::string base) const; diff --git a/libretroshare/src/dbase/findex.cc b/libretroshare/src/dbase/findex.cc index b86636999..a71928270 100644 --- a/libretroshare/src/dbase/findex.cc +++ b/libretroshare/src/dbase/findex.cc @@ -35,8 +35,8 @@ #include +#define FI_DEBUG 1 /**** - * #define FI_DEBUG 1 * #define FI_DEBUG_ALL 1 ****/ @@ -1110,3 +1110,137 @@ int FileIndex::searchBoolExp(Expression * exp, std::list &results) return 0; } +int FileIndex::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const +{ + /* so cast *ref to a DirEntry */ + + FileEntry *file = (FileEntry *) ref; + DirEntry *dir = dynamic_cast(file); + + if (!ref) + { +#ifdef FI_DEBUG + std::cerr << "FileIndexMonitor::RequestDirDetails() ref=NULL (root)" << std::endl; +#endif + /* local only */ + DirStub stub; + stub.type = DIR_TYPE_PERSON; + stub.name = root->name; + stub.ref = root; + details.children.push_back(stub); + details.count = 1; + + details.parent = NULL; + details.prow = 0; + details.ref = NULL; + details.type = DIR_TYPE_ROOT; + details.name = ""; + details.hash = ""; + details.path = ""; + details.age = 0; + details.rank = 0; + } + else + { + if (dir) /* has children --- fill */ + { +#ifdef FI_DEBUG + std::cerr << "FileIndexStore::RequestDirDetails() ref=dir" << std::endl; +#endif + std::map::iterator fit; + std::map::iterator dit; + /* extract all the entries */ + for(dit = dir->subdirs.begin(); dit != dir->subdirs.end(); dit++) + { + DirStub stub; + stub.type = DIR_TYPE_DIR; + stub.name = (dit->second) -> name; + stub.ref = (dit->second); + + details.children.push_back(stub); + } + + for(fit = dir->files.begin(); fit != dir->files.end(); fit++) + { + DirStub stub; + stub.type = DIR_TYPE_FILE; + stub.name = (fit->second) -> name; + stub.ref = (fit->second); + + details.children.push_back(stub); + } + + details.type = DIR_TYPE_DIR; + details.hash = ""; + details.count = dir->subdirs.size() + dir->files.size(); + } + else + { +#ifdef FI_DEBUG + std::cerr << "FileIndexStore::RequestDirDetails() ref=file" << std::endl; +#endif + details.type = DIR_TYPE_FILE; + details.count = file->size; + } + +#ifdef FI_DEBUG + std::cerr << "FileIndexStore::RequestDirDetails() name: " << file->name << std::endl; +#endif + details.ref = file; + details.name = file->name; + details.hash = file->hash; + details.age = time(NULL) - file->modtime; + details.rank = file->pop; + + /* find parent pointer, and row */ + DirEntry *parent = file->parent; + if (!parent) /* then must be root */ + { + details.parent = NULL; + details.prow = 0; + } + else + { + details.parent = parent; + details.prow = parent->row; + } + + /* find peer id */ + parent = dir; + if (!dir) /* cannot be null -> no files at root level */ + parent=file->parent; + + // Well, yes, it can be null, beleive me. In such a case it may be that + // file is a person entry. + + PersonEntry *person; + + if(parent==NULL) + { + if(NULL == (person = dynamic_cast(file))) + { + std::cerr << "Major Error- Not PersonEntry!"; + exit(1); + } + } + else + { + /* NEW add path (to dir - if dir, or parent dir - if file? */ + details.path = parent->path; + + while(parent->parent) + parent = parent->parent; + + /* we should end up on the PersonEntry */ + if (NULL == (person = dynamic_cast(parent))) + { + std::cerr << "Major Error- Not PersonEntry!"; + exit(1); + } + } + details.id = person->id; + } + + return true; +} + diff --git a/libretroshare/src/dbase/findex.h b/libretroshare/src/dbase/findex.h index f83235199..2a7f42f0f 100644 --- a/libretroshare/src/dbase/findex.h +++ b/libretroshare/src/dbase/findex.h @@ -30,6 +30,7 @@ #include #include #include +#include class ostream; @@ -225,6 +226,8 @@ class FileIndex int searchHash(std::string hash, std::list &results) const; int searchBoolExp(Expression * exp, std::list &results) const; + /* browse thru directories */ + int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) const; PersonEntry *root; }; diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 8eb95a897..fd877f912 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -423,7 +423,10 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) } #endif - return mFiStore->RequestDirDetails(ref, details, flags); + if(flags & DIR_FLAGS_LOCAL) + return mFiMon->RequestDirDetails(ref, details, flags); + else + return mFiStore->RequestDirDetails(ref, details, flags); } /***************************************************************/ diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 600d7b527..c62d54676 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -55,7 +55,7 @@ ShareManager::ShareManager(QWidget *parent, Qt::WFlags flags) connect( ui.shareddirList, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( shareddirListCostumPopupMenu( QPoint ) ) ); ui.addButton->setToolTip(tr("Add a Share Directory")); - ui.removeButton->setToolTip(tr("Remove selected Shared Directory")); + ui.removeButton->setToolTip(tr("Stop sharing selected Directory")); load(); @@ -86,6 +86,8 @@ void ShareManager::shareddirListCostumPopupMenu( QPoint point ) /** Loads the settings for this page */ void ShareManager::load() { + std::cerr << "ShareManager:: In load !!!!!" << std::endl ; + std::list::const_iterator it; std::list dirs; rsFiles->getSharedDirectories(dirs); @@ -154,6 +156,7 @@ void ShareManager::load() //ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory())); listWidget->update(); /* update display */ + update(); } void ShareManager::showYourself() @@ -171,8 +174,8 @@ void ShareManager::addShareDirectory() */ - QString qdir = QFileDialog::getExistingDirectory(this, tr("Add Shared Directory"), "", - QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + QString qdir = QFileDialog::getExistingDirectory(this, tr("Add Shared Directory"), "", + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); /* add it to the server */ std::string dir = qdir.toStdString(); @@ -184,8 +187,8 @@ void ShareManager::addShareDirectory() rsFiles->addSharedDirectory(sdi); + messageBoxOk(tr("Shared Directory Added!")); load(); - messageBoxOk(tr("Shared Directory Added!")); } } @@ -236,7 +239,6 @@ void ShareManager::removeShareDirectory() } else return; - } }