Esempio n. 1
0
bool FileSystemManager::removeObject(Watchable *listener)
{
	int indx = vecContains(listenerList, listener);

	if (indx != -1)
	{
		StrList watchDirs = listener->getWatchDir();

		// Remove it from the directory watcher
		for (uint i = 0; i < watchDirs.size(); i++)
			dirWatcher.UnwatchDirectory((LPCTSTR) watchDirs[i].utf16());

		// Kill off any events that belong to this directory
		for (int i = 0; i < eventList.size(); i++)
		{
			if (eventList[i].obj == listener)
			{
				eventList.erase(eventList.begin() + i);
				i--;
			}
		}

		// Remove the watchable item from our own list
		listenerList.erase(listenerList.begin() + indx);
		return true;
	}

	return false;
}
Esempio n. 2
0
/*
 Must LockFileQueue() first,
 and UnlockFileQueue() after finished opertion.
 */
string PopFile()
{
    if(s_fileList.size() == 0)
        return "";
    
    string ret;
    ret = s_fileList.front();
    s_fileList.pop_front();
    
    return ret;
}
Esempio n. 3
0
void FileSystemManager::onPowerSuspend()
{
	// unwatch all the directories
	for (int i = 0; i < listenerList.size(); ++i)
	{
		Watchable * w = listenerList[i];

		StrList watchDirs = w->getWatchDir();
		for (int j = 0; j < watchDirs.size(); j++)
			dirWatcher.UnwatchDirectory((LPCTSTR) watchDirs[j].utf16());
	}
}
Esempio n. 4
0
void LocalPhotoFrameSource::updateDirectory(QDir dir, vector<PhotoFrameSourceItem>& items)
{
	// assume dir exists
	if (!empty(dir))
	{
		StrList dirListing = fsManager->getDirectoryContents(native(dir));
		for (int i = 0; i < dirListing.size(); ++i)
		{
			QFileInfo file(dirListing[i]);

			if (file.isSymLink()) {
				file = QFile(file.symLinkTarget());
			}

			if (file.isDir())
				// recurse into that directory
				updateDirectory(file.absoluteFilePath(), items);
			else
			{
				// XXX: we can do this smarter with watched directories?!

				// check if this is a valid image file
				QString filename = file.fileName();
				if (filename.size() > 4)
				{
					QString ext = fsManager->getFileExtension(filename);
					bool isValidImage = !ext.isEmpty() && GLOBAL(supportedExtensions).contains(ext + ".");
					if (isValidImage)
					{
						// check if we already have that item in the list
						vector<PhotoFrameSourceItem>::const_iterator itemIter = items.begin();
						vector<PhotoFrameSourceItem>::const_iterator endIter = items.end();
						bool exists = false;
						while (itemIter != endIter)
						{
							if ((*itemIter).getResourceId() == dirListing[i])
								exists = true;
							++itemIter;
						}

						// if not, add it to the list
						if (!exists)
						{
							PhotoFrameSourceItem item(dirListing[i]);
							item.setTexturePath(dirListing[i]);
							items.push_back(item);
						}
					}
				}
			}
		}
	}
}
Esempio n. 5
0
void FileSystemManager::onPowerResume()
{
	// re-watch all the directories
	for (int i = 0; i < listenerList.size(); ++i)
	{
		Watchable * w = listenerList[i];

		uint changeFilter = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES;
		StrList watchDirs = w->getWatchDir();
		for (int j = 0; j < watchDirs.size(); j++)
			dirWatcher.WatchDirectory((LPCTSTR) watchDirs[j].utf16(), changeFilter, this);
	}
}
Esempio n. 6
0
void FlickrPhotoFrameSource::requestSourceUpdate()
{
	// just load the images from cache if there is no internet connection
	if (!ftManager->hasInternetConnection())
		loadPhotosFromCache();

	// ensure we have a valid flickr source
	if (!isValidFlickrPhotoFrame())
		return;

	// remove existing downloads
	ftManager->removeTransfersToHandler(this);

	// See how many photos we currently have cached
	int maxNumFilesToCache = 64;
	createLocalCacheDirectory();
	StrList filesToDelete = fsManager->getDirectoryContents(native(_localCacheDirectory));
	if (filesToDelete.size() > maxNumFilesToCache)
	{
		for (int i = 0; i < filesToDelete.size(); ++i)
		{
			QFile::remove(filesToDelete[i]);
		}
	}

	// Determine what kind of photos to download
	// The order is important here since both getting photos from favourite
	// and getting photos from a specific user both involve the same parameter
	FlickrClient flickrClient(FLICKR_AUTH_TOKEN);
	if (_rssFeedUrl.contains("photos_faves"))
		flickrClient.requestFavouritePhotosFromId(_userId, this);
	else if (!_userId.isEmpty())
		flickrClient.requestPhotosFromId(_userId, false, this);
	else if (!_groupId.isEmpty())
		flickrClient.requestPhotosFromId(_groupId, true, this);
	else
		flickrClient.requestPhotosByTag(_tag, this);
}
Esempio n. 7
0
Watchable *FileSystemManager::getWatchObjFromPath(QString filePath)
{
	for (uint i = 0; i < listenerList.size(); i++)
	{
		StrList watchDirs = listenerList[i]->getWatchDir();
		for (uint k = 0; k < watchDirs.size(); k++)
		{
			// If this directory query is contained in our listener list, return true
			if ((watchDirs[k] == filePath) ||
				(watchDirs[k] == (filePath + "\\")))
			{
				return listenerList[i];
			}
		}
	}

	return NULL;
}
Esempio n. 8
0
bool FileSystemManager::addObject(Watchable *listener)
{
	uint changeFilter = FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE | FILE_NOTIFY_CHANGE_ATTRIBUTES;

	// Check if this item is not part of the listener list
	if (vecContains(listenerList, listener) == -1)
	{
		StrList watchDirs = listener->getWatchDir();

		// Add this directory to the watch list
		for (uint i = 0; i < watchDirs.size(); i++)
		{
			dirWatcher.WatchDirectory((LPCTSTR) watchDirs[i].utf16(), changeFilter, this);
		}

		listenerList.push_back(listener);

		return true;
	}

	// Item is already in the list
	return false;
}
Esempio n. 9
0
FileSystemPile *FileSystemActor::pileize()
{
	StrList dirListing;
	QString dirPath;
	vector<Actor *> objListing;
	FileSystemActor *obj = NULL;
	FileSystemPile *p = NULL;

	// Don't allow Piles to be created recursively
	if (isParentType(BumpPile))
	{
		MessageClearPolicy clearPolicy;
			clearPolicy.setTimeout(4);
		scnManager->messages()->addMessage(new Message("pileize_recPiles", QT_TR_NOOP("Sorry, Items within Piles cannot be viewed as Piles at this time.\nThis feature will be implemented in a later version of BumpTop"), Message::Ok, clearPolicy));
		return NULL;
	}

	// If this item has been pileized, then just return its pile
	if (pileizedPile)
	{
		return pileizedPile;
	}

	if (isFileSystemType(Folder))
	{
		// Get a Directory listing of this folder
		dirPath = getTargetPath();
		dirListing = fsManager->getDirectoryContents(dirPath);

		// Check if this Folder has anything in it
		if (dirListing.empty())
		{
			MessageClearPolicy clearPolicy;
				clearPolicy.setTimeout(4);
			scnManager->messages()->addMessage(new Message("pileize_emptyFolder", QT_TR_NOOP("This folder is empty, so it can't be expanded to a pile"), Message::Ok, clearPolicy));
			return NULL;
		}

		// Create a new Pile
		p = new FileSystemPile();
		if (p)
		{
			for (uint i = 0; i < dirListing.size(); i++)
			{
				obj =  FileSystemActorFactory::createFileSystemActor(dirListing[i]);

				// Create new Actors that represent each item in that directory
				// NOTE: we need to set the initial size of the object, since we try and sync the post it
				//		 in the setFilePath call, which means that it will try and fill to the dims of the
				//		 object, which, in it's default size, is not visible text-wise.
				if (_prevPileizedActorDims.contains(dirListing[i].toLower()))
					obj->setDims(Vec3(_prevPileizedActorDims.value(dirListing[i].toLower())));
				else
					obj->setDims(getDims());
				obj->setGlobalPose(getGlobalPose());
				obj->setFilePath(dirListing[i]);

				objListing.push_back(obj);
			}

			// Add items to this Pile
			for (uint i = 0; i < objListing.size(); i++)
			{
				p->addToPile(objListing[i]);
			}

			// Save and setup initial states
			p->setOwner(this);
			p->setText(getFullText());
			p->stack(getGlobalPosition());
			
			// set the icon to be this actor's 
			if (isFileSystemType(Folder))
				p->setTextIcon(getTextureID());

			// Create custom Animations
			for (uint i = 0; i < objListing.size(); i++)
			{
				objListing[i]->setAlphaAnim(0.0f, 1.0f, 15);
			}

			// Make this actor Non-existent
			this->hideAndDisable();

			// Finish up by setting the pile as the current selection
			pileizedPile = p;
			sel->remove((BumpObject *) this);
			sel->add((Pile *) p);

			textManager->invalidate();

			// record this pilization
			statsManager->getStats().bt.interaction.piles.pilized++;
			return p;
		}		
	}

	return NULL;
}