Example #1
0
void BaseTreeBranch::updateOpenFolder()
{
  KFileTreeViewItem *newItem;
  KFileTreeViewItem *item = root();
  while (item) {
    if (item->isDir() && item->isOpen()) {
      updateDirectory( item->url() );
      kapp->processEvents(QEventLoop::ExcludeUserInput | QEventLoop::ExcludeSocketNotifiers);
      // dive into the tree first
      newItem = dynamic_cast<KFileTreeViewItem *>(item->firstChild());
      if (newItem) {
        // found child go ahead
        item = newItem;
        continue;
      };
    };
    // go up if no sibling available
    if (! item->nextSibling())
      item = dynamic_cast<KFileTreeViewItem *>(item->parent());
    if (item == root())
      break;
    if (item)
      item = dynamic_cast<KFileTreeViewItem *>(item->nextSibling());
  };
}
static void
updateInDirectory(struct directory *directory,
		  const char *name, const struct stat *st)
{
	assert(strchr(name, '/') == NULL);

	if (S_ISREG(st->st_mode)) {
		update_regular_file(directory, name, st);
	} else if (S_ISDIR(st->st_mode)) {
		struct directory *subdir;
		bool ret;

		if (inodeFoundInParent(directory, st->st_ino, st->st_dev))
			return;

		subdir = make_subdir(directory, name);
		assert(directory == subdir->parent);

		ret = updateDirectory(subdir, st);
		if (!ret)
			delete_directory(subdir);
	} else {
		g_debug("update: %s is not a directory, archive or music", name);
	}
}
Example #3
0
void SettingsDialog::on_pushButton_2_clicked()
{
    QString path = QFileDialog::getExistingDirectory(this,"Choose a download destination");
    if(!path.isEmpty()){
        ui->label_2->setText(QString("Download to: %1").arg(path));
        ui->verticalLayout->update();
        emit updateDirectory(path);
    }
}
Example #4
0
File: fuseLib.c Project: ferreiro/C
/**
 * @brief Create a file
 *
 * Help from FUSE:
 * 
 * This is called for creation of all non-directory, non-symlink nodes.
 * If the filesystem defines a create() method, then for regular files that will be called instead.
 * 
 * @param path file path
 * @param mode creation mode
 * @param device device where the device will be created (contains both major and minor numbers)
 * @return 0 on success and <0 on error
 **/
static int my_mknod(const char *path, mode_t mode, dev_t device) {
	char modebuf[10];

	mode_string(mode, modebuf);
	fprintf(stderr, "--->>>my_mknod: path %s, mode %s, major %d, minor %d\n", path, modebuf, (int)MAJOR(device), (int)MINOR(device));

	// We check that the length of the file name is correct
	if(strlen(path + 1) > myFileSystem.superBlock.maxLenFileName) {
		return -ENAMETOOLONG;
	}

	// There exist an available inode
	if(myFileSystem.numFreeNodes <= 0) {
		return -ENOSPC;
	}

	// There is still space for a new file
	if(myFileSystem.directory.numFiles >= MAX_FILES_PER_DIRECTORY) {
		return -ENOSPC;
	}
	// The directory exists
	if(findFileByName(&myFileSystem, (char *)path + 1) != -1)
		return -EEXIST;

	/// Update all the information in the backup file:
	int idxNodoI, idxDir;
	if((idxNodoI = findFreeNode(&myFileSystem)) == -1 || (idxDir = findFreeFile(&myFileSystem)) == -1) {
		return -ENOSPC;
	}

	// Update root folder
	myFileSystem.directory.files[idxDir].freeFile = false;
	myFileSystem.directory.numFiles++;
	strcpy(myFileSystem.directory.files[idxDir].fileName, path + 1);
	myFileSystem.directory.files[idxDir].nodeIdx = idxNodoI;
	myFileSystem.numFreeNodes--;

	// Fill the fields of the new inode
	if(myFileSystem.nodes[idxNodoI] == NULL)
		myFileSystem.nodes[idxNodoI] = malloc(sizeof(NodeStruct));

	myFileSystem.nodes[idxNodoI]->fileSize = 0;
	myFileSystem.nodes[idxNodoI]->numBlocks = 0;
	myFileSystem.nodes[idxNodoI]->modificationTime = time(NULL);
	myFileSystem.nodes[idxNodoI]->freeNode = false;

	reserveBlocksForNodes(&myFileSystem, myFileSystem.nodes[idxNodoI]->blocks, 0);

	updateDirectory(&myFileSystem);
	updateNode(&myFileSystem, idxNodoI, myFileSystem.nodes[idxNodoI]);

	return 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);
						}
					}
				}
			}
		}
	}
}
void ImageExporterOutputWidget::browseDirectory(bool)
{
    QFileDialog dialog(this);
    dialog.setFileMode(QFileDialog::Directory);
    dialog.setOption(QFileDialog::ShowDirsOnly);
    dialog.setDirectory(m_dirName);

    if (dialog.exec() && !dialog.selectedFiles().empty())
    {
        m_dirName = dialog.selectedFiles().first();
        updateDirectory();
    }
}
bool
update_walk(const char *path, bool discard)
{
	walk_discard = discard;
	modified = false;

	if (path != NULL && !isRootDirectory(path)) {
		updatePath(path);
	} else {
		struct directory *directory = db_get_root();
		struct stat st;

		if (stat_directory(directory, &st) == 0)
			updateDirectory(directory, &st);
	}

	return modified;
}
Example #8
0
LocalOsmSearchPlugin::LocalOsmSearchPlugin( QObject *parent ) :
    SearchRunnerPlugin( parent ),
    m_databaseFiles()
{
    setSupportedCelestialBodies(QStringList(QStringLiteral("earth")));
    setCanWorkOffline( true );

    QString const path = MarbleDirs::localPath() + QLatin1String("/maps/earth/placemarks/");
    QFileInfo pathInfo( path );
    if ( !pathInfo.exists() ) {
        QDir("/").mkpath( pathInfo.absolutePath() );
        pathInfo.refresh();
    }
    if ( pathInfo.exists() ) {
        m_watcher.addPath( path );
    }
    connect( &m_watcher, SIGNAL(directoryChanged(QString)), this, SLOT(updateDirectory(QString)) );
    connect( &m_watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFile(QString)) );

    updateDatabase();
}
ImageExporterOutputWidget::ImageExporterOutputWidget(gloperate::ResourceManager & resourceManager, gloperate::Painter * painter, gloperate_qt::QtOpenGLWindow * context, QWidget *parent)
    :	QWidget(parent)
    ,	m_context(context)
    ,	m_supportedTags( { { "width", "<width>" }, { "height", "<height>" }, { "enum_num", "<enum#" }, { "year", "<year>" }, { "month", "<month>" }, { "day", "<day>" }, { "hour", "<hour>" }, { "minute", "<minute>" }, { "second", "<second>" }, { "millisec", "<millisecond>" }
})
,	m_ui(new Ui_ImageExporterOutputWidget)
,	m_resolution(new QSize(1,1))
{
    m_ui->setupUi(this);

    m_ui->fileNameTextEdit->setMaximumHeight(m_ui->directoryLineEdit->height() * 2);
    initializeFileNameTextEdit();

    connect(m_ui->saveButton, &QPushButton::clicked,
            this, &ImageExporterOutputWidget::handleSave);
    connect(m_ui->openDirectoryButton, &QPushButton::clicked,
            this, &ImageExporterOutputWidget::browseDirectory);
    connect(m_ui->fileNameTextEdit, &FileNameTextEdit::textChanged,
            this, &ImageExporterOutputWidget::checkFilename);
    connect(m_ui->fileNameTextEdit, &FileNameTextEdit::textChanged,
            this, &ImageExporterOutputWidget::saveFilename);

    connect(this, &ImageExporterOutputWidget::filenameChanged,
            this, &ImageExporterOutputWidget::updateFilenamePreview);

    m_imageExporter = new gloperate::ImageExporter(painter, resourceManager);
    context->makeCurrent();
    m_imageExporter->initialize();
    context->doneCurrent();

    if (!gloperate::ImageExporter::isApplicableTo(painter))
        m_ui->saveButton->setDisabled(true);

    restoreSettings();
    updateDirectory();
    checkFilename();
}
Example #10
0
File: fuseLib.c Project: ferreiro/C
int my_unlink(const char *filename) {
	
	
	// printDirectory(myFileSystem.directory); // DEBUG stuff only for debugging
	
	/***** Copiar filename sin '/' en una nueva variable para 
	 ***** poder pasarla a findFileByNAme (que no admite strings constantes) ****/
	
	int i=0;
	char* fname=(char*)(filename+1); // Convert ffrom const char to char. Y también, quitar el primer character (/) sumando uno al puntero de filename (hace algoritimia de punteros.)
		
	
	/** 1. Buscar si el archivo está en nuestro directorio **/
	/** Si está, liberar el archivo y poner el nombre a empty **/
	/** OJO! NO hay que tocar nodeIdx... **/
	
	int nodeIndexDir = findFileByName(&myFileSystem, fname); // NodeIDx índice que ocupa un nodo en el array de nodos
	 
	if (nodeIndexDir == -1) {
		fprintf(stderr, "File wasn't found on the directory entry\n");  
		return -1; // File is not on the directory.
	}
	
	// FILE to erase is on the directory. Free the directory entry.
	
	myFileSystem.directory.numFiles -= 1; // Decrementar numero de archivos en el directorio.
	myFileSystem.directory.files[nodeIndexDir].freeFile = true; // Put the node in directory as free.
	updateDirectory(&myFileSystem);
	
	int nodeIdx = myFileSystem.directory.files[nodeIndexDir].nodeIdx; // Hacer una copia de nodoIDx del directorio que nos sirve para acceder al array de nodos.
	NodeStruct* inode=myFileSystem.nodes[nodeIdx];
	
	/** 2. Borrar datos y liberar nodo usando el nodeIdx obtenido del directorio **/

	myFileSystem.numFreeNodes += 1; // Increase the number of free nodes by 1 because e erased one.
	
	for (i=0;i<inode->numBlocks;i++)
		myFileSystem.bitMap[inode->blocks[i]] = 0; // Marcar bloques de datos en bitmap como libre
 
	myFileSystem.superBlock.numOfFreeBlocks+=inode->numBlocks;
	updateBitmap(&myFileSystem);
	updateSuperBlock(&myFileSystem);
		
 	/**********************************************
 	 * 	Se podría poner unicamente a NULL? Es peor?
 	 **********************************************/
 	 
	inode->numBlocks=0;
	inode->fileSize=0;
	inode->freeNode=true; // Delete the note from the node's array.

	updateNode(&myFileSystem,nodeIdx,inode);
	
	free(inode);
	myFileSystem.nodes[nodeIdx]=NULL;
	
 	  
 	//printAllNodes(myFileSystem.nodes);
 	//printDirectory(myFileSystem.directory); // DEBUG stuff only for debugging

	fprintf(stderr, "\n Congrats!!! %s file deleted \n", filename);
 	
	return 0;
}
Example #11
0
int myMkfs(MyFileSystem *myFileSystem, int diskSize, char *backupFileName) {
	// We create the virtual disk:
	myFileSystem->fdVirtualDisk = open(backupFileName, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);

	// Some minimal checks:
	assert(sizeof(SuperBlockStruct) <= BLOCK_SIZE_BYTES);
	assert(sizeof(DirectoryStruct) <= BLOCK_SIZE_BYTES);
	int numBlocks = diskSize / BLOCK_SIZE_BYTES;
	int minNumBlocks = 3 + MAX_BLOCKS_WITH_NODES + 1;
	// 3 --> por el superbloque, el raiz y el mapa de bits.
	// 1 --> porque al menos tenemos un bloque para datos.
	int maxNumBlocks = NUM_BITS;
	if(numBlocks < minNumBlocks) {
		return -1;
	}
	if(numBlocks >= maxNumBlocks) {
		return -2;
	}

	/// BITMAP
	// Initialization
	int i;
	for(i = 0; i < NUM_BITS; i++) {
		myFileSystem->bitMap[i] = 0;
	}

	// First three blocks will be superblock, bitmap and directory
	myFileSystem->bitMap[BITMAP_IDX] = 1;
	myFileSystem->bitMap[SUPERBLOCK_IDX] = 1;
	myFileSystem->bitMap[DIRECTORY_IDX] = 1;
	// Next MAX_BLOCKS_WITH_NODES will contain inodes
	for(i = 3; i < 3 + MAX_BLOCKS_WITH_NODES; i++) {
		myFileSystem->bitMap[i] = 1;
	}
	updateBitmap(myFileSystem);

	/// DIRECTORY
	// Initialization
	myFileSystem->directory.numFiles = 0;
	for(i = 0; i < MAX_FILES_PER_DIRECTORY; i++) {
		myFileSystem->directory.files[i].freeFile = 1;
	}
	updateDirectory(myFileSystem);

	/// INODES
	NodeStruct currentNode;
	currentNode.freeNode = 1;
	for(i = 0; i < MAX_NODES; i++) {
		updateNode(myFileSystem, i, &currentNode);
	}

	/// SUPERBLOCK
	initializeSuperBlock(myFileSystem, diskSize);
	updateSuperBlock(myFileSystem);
	sync();

	// At the end we have at least one block
	assert(myQuota(myFileSystem) >= 1);

	if(initializeNodes(myFileSystem)){
		myFree(myFileSystem);
		return -3;
	}

	printf("SF: %s, %d B (%d B/block), %d blocks\n", backupFileName, diskSize, BLOCK_SIZE_BYTES, numBlocks);
	printf("1 block for SUPERBLOCK (%u B)\n", (unsigned int)sizeof(SuperBlockStruct));
	printf("1 block for BITMAP, covering %u blocks, %u B\n", (unsigned int)NUM_BITS, (unsigned int)(NUM_BITS * BLOCK_SIZE_BYTES));
	printf("1 block for DIRECTORY (%u B)\n", (unsigned int)sizeof(DirectoryStruct));
	printf("%d blocks for inodes (%u B/inode, %u inodes)\n", MAX_BLOCKS_WITH_NODES, (unsigned int)sizeof(NodeStruct), (unsigned int)MAX_NODES);
	printf("%d blocks for data (%d B)\n", myFileSystem->superBlock.numOfFreeBlocks, BLOCK_SIZE_BYTES * myFileSystem->superBlock.numOfFreeBlocks);
	printf("Formatting completed!\n");

	return 0;
}
Example #12
0
//-----------------------------------------------------------------------------
// Function: NewDesignDialog::NewDesignDialog()
//-----------------------------------------------------------------------------
NewDesignDialog::NewDesignDialog(LibraryInterface* libInterface,
                                 QSharedPointer<Component> component,
                                 KactusAttribute::Implementation designType,
                                 QWidget *parent)
    : QDialog(parent), 
      lh_(libInterface),
      component_(component),
      viewNameLabel_(new QLabel(tr("View name:"), this)),
      viewNameMatcher_(),
      viewNameEdit_(new LineEditEx(this)),
      vlnvEditor_(new VLNVEditor(VLNV::DESIGN, libInterface, this, this, true)),
      directoryEditor_(new LibrarySelectorWidget(this)), 
      okButton_(new QPushButton(tr("&OK"))),
      designExt_(),
      designConfExt_()
{
    switch (designType)
    {
    case KactusAttribute::HW:
        {
            viewNameLabel_->setText(tr("Name for a new view to HW component:"));
            viewNameEdit_->setDisallowedInputs(component->getViewNames());
            viewNameEdit_->setMessageTemplate("View name '%1' already exists!");
            vlnvEditor_->setTitle("VLNV for new HW design and design configuration");
            designExt_ = ".design";
            designConfExt_ = ".designcfg";
            break;
        }

    case KactusAttribute::SW:
        {
            viewNameLabel_->setText(tr("Name for a new SW view to component:"));
            viewNameEdit_->setDisallowedInputs(component->getSWViewNames());
            viewNameEdit_->setMessageTemplate("SW view name '%1' already exists!");
            vlnvEditor_->setTitle("VLNV for new SW design and design configuration");
            designExt_ = ".swdesign";
            designConfExt_ = ".swdesigncfg";
            break;
        }

    case KactusAttribute::SYSTEM:
        {
            viewNameLabel_->setText(tr("Name for a new system view to HW component:"));
            viewNameEdit_->setDisallowedInputs(component->getSystemViewNames());
            viewNameEdit_->setMessageTemplate("System view name '%1' already exists!");
            vlnvEditor_->setTitle("VLNV for new system design and design configuration");
            designExt_ = ".sysdesign";
            designConfExt_ = ".sysdesigncfg";
            break;
        }

    default:
        {
            Q_ASSERT(false);
            break;
        }
    }

    viewNameEdit_->setMessageIcon(QPixmap(":/icons/common/graphics/exclamation.png"));
    viewNameEdit_->setContentMatcher(&viewNameMatcher_);

    connect(viewNameEdit_, SIGNAL(textChanged(QString const&)), this, SLOT(updateVlnvName()));
    connect(viewNameEdit_, SIGNAL(textChanged(QString const&)), this, SLOT(onContentChanged()));

    vlnvEditor_->addNameExtension(designExt_);
    vlnvEditor_->addNameExtension(designConfExt_);
    vlnvEditor_->addContentType(VLNV::DESIGNCONFIGURATION);

    connect(vlnvEditor_, SIGNAL(contentChanged()), this, SLOT(onContentChanged()));
    connect(vlnvEditor_, SIGNAL(contentChanged()), this, SLOT(updateDirectory()));
        
    directoryEditor_->layout()->setContentsMargins(0,11,0,11);
	connect(directoryEditor_, SIGNAL(contentChanged()), this, SLOT(onContentChanged()));

    okButton_->setEnabled(false);
    connect(okButton_, SIGNAL(released()), this, SLOT(accept()));

    QPushButton *cancelButton = new QPushButton(tr("&Cancel"));
    connect(cancelButton, SIGNAL(released()), this, SLOT(reject()));

    QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Horizontal);
    buttonBox->addButton(okButton_, QDialogButtonBox::ActionRole);
    buttonBox->addButton(cancelButton, QDialogButtonBox::ActionRole);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(viewNameLabel_);
    mainLayout->addWidget(viewNameEdit_);
    mainLayout->addWidget(vlnvEditor_);
    mainLayout->addWidget(directoryEditor_);
    mainLayout->addWidget(buttonBox);
    mainLayout->addStretch(1);
    setLayout(mainLayout);

    setWindowTitle("New HW Design");
    setFixedHeight(sizeHint().height());
    resize(400, sizeHint().height());
    okButton_->setDefault(true);
}
Example #13
0
void NewDesignDialog::setVLNV( const VLNV& vlnv ) {
	vlnvEditor_->setVLNV(vlnv);
    updateDirectory();
}
Example #14
0
void LocalPhotoFrameSource::requestSourceUpdate()
{
	// assume dir exists
	vector<PhotoFrameSourceItem> items;

	if(!QFileInfo(_localPath.absolutePath()).isDir()) {
		// check if this is a valid image file
		QString filename = _localPath.absolutePath();
		if (filename.size() > 4)
		{
			QString ext = fsManager->getFileExtension(filename);
			bool isValidImage = !ext.isEmpty() && GLOBAL(supportedExtensions).contains(ext + ".");
			if (isValidImage)
			{
				PhotoFrameSourceItem newItem(filename);
				newItem.setTexturePath(filename);
				items.push_back(newItem);
			} else {
				MessageClearPolicy clearPolicy;
				clearPolicy.setTimeout(4);
				scnManager->messages()->addMessage(new Message("PhotoFrameActor::resolveSourceFromString", QT_TR_NOOP("Invalid photo frame source given!"), Message::Warning, clearPolicy));
			}
		}
	} else {
		updateDirectory(_localPath, items);

		// randomize the items
		PhotoFrameSourceItem tmp;
		int n = items.size();
		srand(time(NULL));
		for (int i = 0; i < n; ++i)
		{
			int j = (rand() + rand()) % n;
			if (i != j)
			{
				tmp = items[i];
				items[i] = items[j];
				items[j] = tmp;
			}
		}
	}
	
	if (!items.empty())
	{
		// set the items
		_items = items;
		++_sourceUpdateCount;

		// check if the current item is still valid
		bool found = false;
		for (int i = 0; i < _items.size(); ++i)
		{
			if (_items[i].equals(_current))
			{
				found = true;
			}
		}
		if (!found)
			_current.invalidate();
	}
	else
	{
		_current.invalidate();
	}
}