Exemplo n.º 1
0
BookmarksModel::BookmarksModel(const QString &path, FormatMode mode, QObject *parent) : QStandardItemModel(parent),
	m_mode(mode)
{
	BookmarksItem *rootItem = new BookmarksItem();
	rootItem->setData(RootBookmark, TypeRole);
	rootItem->setData(((mode == NotesMode) ? tr("Notes") : tr("Bookmarks")), TitleRole);
	rootItem->setDragEnabled(false);

	BookmarksItem *trashItem = new BookmarksItem();
	trashItem->setData(TrashBookmark, TypeRole);
	trashItem->setData(tr("Trash"), TitleRole);
	trashItem->setDragEnabled(false);
	trashItem->setEnabled(false);

	appendRow(rootItem);
	appendRow(trashItem);
	setItemPrototype(new BookmarksItem());

	QFile file(path);

	if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
	{
		Console::addMessage(((mode == NotesMode) ? tr("Failed to open notes file: %1") : tr("Failed to open bookmarks file: %1")).arg(file.errorString()), OtherMessageCategory, ErrorMessageLevel, path);

		return;
	}

	QXmlStreamReader reader(file.readAll());

	if (reader.readNextStartElement() && reader.name() == QLatin1String("xbel") && reader.attributes().value(QLatin1String("version")).toString() == QLatin1String("1.0"))
	{
		while (reader.readNextStartElement())
		{
			if (reader.name() == QLatin1String("folder") || reader.name() == QLatin1String("bookmark") || reader.name() == QLatin1String("separator"))
			{
				readBookmark(&reader, rootItem);
			}
			else
			{
				reader.skipCurrentElement();
			}

			if (reader.hasError())
			{
				getRootItem()->removeRows(0, getRootItem()->rowCount());

				Console::addMessage(((m_mode == NotesMode) ? tr("Failed to load notes file: %1") : tr("Failed to load bookmarks file: %1")).arg(reader.errorString()), OtherMessageCategory, ErrorMessageLevel, path);

				QMessageBox::warning(NULL, tr("Error"), ((m_mode == NotesMode) ? tr("Failed to load notes file.") : tr("Failed to load bookmarks file.")), QMessageBox::Close);

				return;
			}
		}
	}

	connect(this, SIGNAL(itemChanged(QStandardItem*)), this, SIGNAL(modelModified()));
	connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SIGNAL(modelModified()));
	connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SIGNAL(modelModified()));
	connect(this, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), this, SIGNAL(modelModified()));
}
Exemplo n.º 2
0
BookmarksItem* BookmarksModel::addBookmark(BookmarkType type, quint64 identifier, const QUrl &url, const QString &title, BookmarksItem *parent, int index)
{
	blockSignals(true);

	BookmarksItem *bookmark = new BookmarksItem();

	if (parent)
	{
		parent->insertRow(((index < 0) ? parent->rowCount() : index), bookmark);
	}
	else
	{
		getRootItem()->insertRow(((index < 0) ? getRootItem()->rowCount() : index), bookmark);
	}

	if (type == UrlBookmark || type == SeparatorBookmark)
	{
		bookmark->setDropEnabled(false);
	}

	setData(bookmark->index(), type, TypeRole);
	setData(bookmark->index(), url, UrlRole);
	setData(bookmark->index(), title, TitleRole);

	if (type != RootBookmark && type != TrashBookmark && type != FolderBookmark)
	{
		bookmark->setFlags(bookmark->flags() | Qt::ItemNeverHasChildren);
	}

	if (type != TrashBookmark && type != UnknownBookmark)
	{
		if (identifier == 0 || m_identifiers.contains(identifier))
		{
			identifier = (m_identifiers.isEmpty() ? 1 : (m_identifiers.keys().last() + 1));
		}

		setData(bookmark->index(), identifier, IdentifierRole);

		m_identifiers[identifier] = bookmark;
	}

	blockSignals(false);

	emit bookmarkAdded(bookmark);
	emit modelModified();

	return bookmark;
}
void DBGProfileListView::addToList(DBGProfileData* data)
{
  DBGProfileListViewItem* item;
  DBGProfileListViewItem* parentItem;

  switch(m_view)
  {
    case ModuleView:
    case ContextView:
      parentItem = getRootItem(data);
      if(parentItem == 0)
      {
        item = new DBGProfileListViewItem(this, data, m_view);
        item->moveItem(lastRootItem());
        parentItem = item;
        item = new DBGProfileListViewItem(parentItem, data, m_view);
      }
      else
      {
        item = new DBGProfileListViewItem(parentItem, data, m_view);
        item->moveItem(parentItem->lastItem());
      }
      break;
    case DetailedView:
      item = new DBGProfileListViewItem(this, data, m_view);
      item->moveItem(lastItem());
      break;
  }
}
Exemplo n.º 4
0
void BookmarksModel::restoreBookmark(BookmarksItem *bookmark)
{
	if (!bookmark)
	{
		return;
	}

	BookmarksItem *formerParent = (m_trash.contains(bookmark) ? getBookmark(m_trash[bookmark].first) : getRootItem());

	if (!formerParent || static_cast<BookmarkType>(formerParent->data(TypeRole).toInt()) != FolderBookmark)
	{
		formerParent = getRootItem();
	}

	if (m_trash.contains(bookmark))
	{
		formerParent->insertRow(m_trash[bookmark].second, bookmark->parent()->takeRow(bookmark->row()));

		m_trash.remove(bookmark);
	}
	else
	{
		formerParent->appendRow(bookmark->parent()->takeRow(bookmark->row()));
	}

	readdBookmarkUrl(bookmark);

	BookmarksItem *trashItem = getTrashItem();

	trashItem->setEnabled(trashItem->rowCount() > 0);

	emit bookmarkModified(bookmark);
	emit bookmarkRestored(bookmark);
	emit modelModified();
}
bool luProjPanel::setProjectName(const wxString& name)
{
	wxTreeItemId root = getRootItem();
	if (!root.IsOk()) return false;

	m_tree->SetItemText(root, name);

	return true;
}
Exemplo n.º 6
0
void OverlayConductor::setEnabled(bool enabled) {

    if (enabled == _enabled) {
        return;
    }

    Menu::getInstance()->setIsOptionChecked(MenuOption::Overlays, enabled);

    _enabled = enabled; // set the new value

    // if the new state is visible/enabled...
    if (_enabled) {
        // alpha fadeIn the overlay mesh.
        qApp->getApplicationCompositor().fadeIn();

        // enable mouse clicks from script
        qApp->getOverlays().enable();

        // enable QML events
        auto offscreenUi = DependencyManager::get<OffscreenUi>();
        offscreenUi->getRootItem()->setEnabled(true);

        if (_mode == STANDING) {
            // place the overlay at the current hmd position in world space
            MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
            auto camMat = cancelOutRollAndPitch(myAvatar->getSensorToWorldMatrix() * qApp->getHMDSensorPose());
            Transform t;
            t.setTranslation(extractTranslation(camMat));
            t.setRotation(glm::quat_cast(camMat));
            qApp->getApplicationCompositor().setModelTransform(t);
        }
    } else { // other wise, if the new state is hidden/not enabled
        // alpha fadeOut the overlay mesh.
        qApp->getApplicationCompositor().fadeOut();

        // disable mouse clicks from script
        qApp->getOverlays().disable();

        // disable QML events
        auto offscreenUi = DependencyManager::get<OffscreenUi>();
        offscreenUi->getRootItem()->setEnabled(false);
    }
}
Exemplo n.º 7
0
/**
 * @brief RsCollectionDialog::save: Update collection to save it in caller.
 */
void RsCollectionDialog::save()
{
	std::cerr << "Saving!" << std::endl;
	_newColFileInfos.clear();
	QTreeWidgetItem* root = getRootItem();
	if (root) {
		saveChild(root);

		emit saveColl(_newColFileInfos, _fileName);
	}
	close();
}
wxTreeItemId luProjPanel::addFile(const wxString& path, int data)
{
	wxTreeItemId root = getRootItem();
	if (!root.IsOk()) return root;

	wxString name = wxFileName(path).GetFullName(); //strip dir

	wxTreeItemId item = m_tree->AppendItem(root, name, -1, -1, new luProjTree::ItemData(path, data));
	setItemFont(item, false);

	return item;
}
Exemplo n.º 9
0
BookmarksItem* BookmarksModel::getItem(const QString &path) const
{
	if (path == QLatin1String("/"))
	{
		return getRootItem();
	}

	if (path.startsWith(QLatin1Char('#')))
	{
		return getBookmark(path.mid(1).toULongLong());
	}

	QStandardItem *item = getRootItem();
	const QStringList directories = path.split(QLatin1Char('/'), QString::SkipEmptyParts);

	for (int i = 0; i < directories.count(); ++i)
	{
		bool found = false;

		for (int j = 0; j < item->rowCount(); ++j)
		{
			if (item->child(j) && item->child(j)->data(Qt::DisplayRole) == directories.at(i))
			{
				item = item->child(j);

				found = true;

				break;
			}
		}

		if (!found)
		{
			return NULL;
		}
	}

	return dynamic_cast<BookmarksItem*>(item);
}
Exemplo n.º 10
0
BookmarksItem* BookmarksModel::getBookmark(quint64 identifier) const
{
	if (identifier == 0)
	{
		return getRootItem();
	}

	if (m_identifiers.contains(identifier))
	{
		return m_identifiers[identifier];
	}

	return NULL;
}
Exemplo n.º 11
0
/**
 * @brief RsCollectionDialog::updateList: Update list of item in RsCollection
 * @return If at least one item have a Wrong Char
 */
bool RsCollectionDialog::updateList()
{
	bool wrong_chars = false ;
	wrong_chars = addChild(getRootItem(), _newColFileInfos);

	_newColFileInfos.clear();

	ui._filename_TL->setText(_fileName) ;
	for (int column = 0; column < ui._fileEntriesTW->columnCount(); ++column) {
		ui._fileEntriesTW->resizeColumnToContents(column);
	}

	updateSizes() ;

	return !wrong_chars;
}
Exemplo n.º 12
0
    MenuUserData(const MenuUserData&);

    void init(QObject* widgetObject, QObject* qmlObject) {
        widgetObject->setUserData(USER_DATA_ID, this);
        qmlObject->setUserData(USER_DATA_ID, this);
        qmlObject->setObjectName(uuid.toString());
        // Make sure we can find it again in the future
        Q_ASSERT(VrMenu::_instance->findMenuObject(uuid.toString()));
    }
};

const int MenuUserData::USER_DATA_ID = QObject::registerUserData();

HIFI_QML_DEF_LAMBDA(VrMenu, [&](QQmlContext* context, QObject* newItem) {
    auto offscreenUi = DependencyManager::get<OffscreenUi>();
    QObject* rootMenu = offscreenUi->getRootItem()->findChild<QObject*>("rootMenu");
    Q_ASSERT(rootMenu);
    static_cast<VrMenu*>(newItem)->setRootMenu(rootMenu);
    context->setContextProperty("rootMenu", rootMenu);
});

VrMenu* VrMenu::_instance{ nullptr };
static QQueue<std::function<void(VrMenu*)>> queuedLambdas;

void VrMenu::executeOrQueue(std::function<void(VrMenu*)> f) {
    if (_instance) {
        foreach(std::function<void(VrMenu*)> priorLambda, queuedLambdas) {
            priorLambda(_instance);
        }
        f(_instance);
    } else {
Exemplo n.º 13
0
/**
 * @brief RsCollectionDialog::addDir: Add new empty dir to list
 */
void RsCollectionDialog::makeDir()
{
	QString childName="";
	bool ok, badChar, nameOK = false;
	// Ask for name
	while (!nameOK)
	{
		childName = QInputDialog::getText(this, tr("New Directory")
		                                  , tr("Enter the new directory's name")
		                                  , QLineEdit::Normal, childName, &ok);
		if (ok && !childName.isEmpty())
		{
			childName = purifyFileName(childName, badChar);
			nameOK = !badChar;
			if (badChar)
			{
				QMessageBox msgBox;
				msgBox.setText("The name contains bad characters.");
				msgBox.setInformativeText("Do you want to use the corrected one?\n" + childName);
				msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Retry | QMessageBox::Cancel);
				msgBox.setDefaultButton(QMessageBox::Ok);
				int ret = msgBox.exec();
				switch (ret) {
					case QMessageBox::Ok:
						nameOK = true;
					break;
					case QMessageBox::Retry:
					break;
					case QMessageBox::Cancel:
						return;
					break;
					default:
						// should never be reached
					break;
				}//switch (ret)
			}//if (badChar)
		} else {//if (ok && !childName.isEmpty())
			return;
		}//if (ok && !childName.isEmpty())

	}//while (!nameOK)

	// Process all selected items
	int count = ui._fileEntriesTW->selectedItems().count();
	int curs = 0;
	if (count == 0) curs = -1;
	for (; curs < count; ++curs)
	{
		QTreeWidgetItem *item = NULL;
		if (curs >= 0) {
			item= ui._fileEntriesTW->selectedItems().at(curs);
		} else {
			item = getRootItem();
		}
		if (item) {
			while (item->data(COLUMN_HASH, ROLE_TYPE).toUInt() != DIR_TYPE_DIR) {
				item = item->parent();//Only Dir as Parent
			}
			ColFileInfo newChild;
			newChild.name = childName;
			newChild.filename_has_wrong_characters = false;
			newChild.size = 0;
			newChild.type = DIR_TYPE_DIR;
			newChild.path = item->data(COLUMN_HASH, ROLE_PATH).toString()
			                + "/" + item->data(COLUMN_HASH, ROLE_NAME).toString();
			if (item == getRootItem()) newChild.path = "";

			_newColFileInfos.push_back(newChild);
		}//if (item)
	}//for (; curs < count; ++curs)


	updateList();
}
Exemplo n.º 14
0
/**
 * @brief RsCollectionDialog::remove: Remove selected Items in RSCollection
 */
void RsCollectionDialog::remove()
{
    bool removeOnlyFile=false;
	QString listDir;
	// First, check if selection contains directories
	for (int curs = 0; curs < ui._fileEntriesTW->selectedItems().count(); ++curs)
	{// Have to call ui._fileEntriesTW->selectedItems().count() each time as selected could change
		QTreeWidgetItem *item = NULL;
		item= ui._fileEntriesTW->selectedItems().at(curs);

		//Uncheck child directory item if parent is checked
		if (item != getRootItem()){
			if (item->data(COLUMN_HASH, ROLE_TYPE).toUInt() == DIR_TYPE_DIR) {
				QString path = item->data(COLUMN_HASH, ROLE_PATH).toString();
				if (listDir.contains(path) && !path.isEmpty()) {
					item->setSelected(false);
				} else {
					listDir += item->data(COLUMN_HASH, ROLE_NAME).toString() +"<br>";
				}//if (listDir.contains(item->data(COLUMN_HASH, ROLE_PATH).toString()))
			}//if (item->data(COLUMN_HASH, ROLE_TYPE).toUInt() == DIR_TYPE_DIR)
		}//if (item != getRootItem())
	}//for (int curs = 0; curs < count; ++curs)

	//If directories, ask to remove them or not
	if (!listDir.isEmpty()){
		QMessageBox* msgBox = new QMessageBox(QMessageBox::Information, "", "");
		msgBox->setText("Warning, selection contains directories.");
		//msgBox->setInformativeText(); If text too long, no scroll, so I add an text edit
		QGridLayout* layout = qobject_cast<QGridLayout*>(msgBox->layout());
		if (layout) {
			QTextEdit* edit = new QTextEdit(tr("Do you want to remove them and all their children, too? <br>") + listDir);
			edit->setReadOnly(true);
			layout->addWidget(edit,0 ,1);
		}

		msgBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
		msgBox->setDefaultButton(QMessageBox::Yes);
		int ret = msgBox->exec();
		switch (ret) {
			case QMessageBox::Yes:
			break;
			case QMessageBox::No:
				removeOnlyFile = true;
			break;
			case QMessageBox::Cancel: {
				delete msgBox;
				return;
			}//case QMessageBox::Cancel:
			break;
			default:
				// should never be reached
			break;
		}//switch (ret)
		delete msgBox;
	}//if (!listDir.isEmpty())

	//Remove wanted items
	for (int curs = 0; curs < ui._fileEntriesTW->selectedItems().count(); ++curs)
	{// Have to call ui._fileEntriesTW->selectedItems().count() each time as selected change
		QTreeWidgetItem *item = NULL;
		item= ui._fileEntriesTW->selectedItems().at(curs);

		if (item != getRootItem()){
			if ((item->data(COLUMN_HASH, ROLE_TYPE).toUInt() != DIR_TYPE_DIR) || !removeOnlyFile) {
				QTreeWidgetItem *parent = item->parent();
				parent->removeChild(item);
				curs = 0;//Cause we don't know how many child of this item was selected (and don't want iterate them ;) )
			}
		}//if (item != getRootItem())*
	}//for (int curs = 0; curs < count; ++curs)

}
Exemplo n.º 15
0
/**
 * @brief RsCollectionDialog::addRecursive: Add Selected item to RSCollection
 *   -Add File seperatly if parent folder not selected
 *   -Add File in folder if selected
 *   -Get root folder the selected one
 * @param recursive: If true, add all selected directory childrens
 */
void RsCollectionDialog::addRecursive(bool recursive)
{
	QStringList fileToHash;
	QMap<QString, QString > dirToAdd;
    int count=0;//to not scan all items on list .count()

	QModelIndexList milSelectionList =	ui._systemFileTW->selectionModel()->selectedIndexes();
	foreach (QModelIndex index, milSelectionList)
	{

		if (index.column()==0){//Get only FileName
			QString filePath = _dirModel->filePath(_tree_proxyModel->mapToSource(index));
			QFileInfo fileInfo = filePath;
			if (fileInfo.isDir()) {
				dirToAdd.insert(fileInfo.absoluteFilePath(),fileInfo.absolutePath());
				++count;
				if (recursive) {
					if (!addAllChild(fileInfo, dirToAdd, fileToHash, count)) return;
				} else {
					continue;
				}
			}//if (fileInfo.isDir())
			if (fileInfo.isFile()){
				fileToHash.append(fileInfo.absoluteFilePath());
				++count;
				if (dirToAdd.contains(fileInfo.absolutePath()))
					_listOfFilesAddedInDir.insert(fileInfo.absoluteFilePath(),fileInfo.absolutePath());
				else
					_listOfFilesAddedInDir.insert(fileInfo.absoluteFilePath(),"");
			}//if (fileInfo.isFile())
		}//if (index.column()==0)
	}//foreach (QModelIndex index, milSelectionList)

	// Process Dirs
	QTreeWidgetItem *item = NULL;
	if (!ui._fileEntriesTW->selectedItems().empty())
		item= ui._fileEntriesTW->selectedItems().at(0);
	if (item) {
		while (item->data(COLUMN_HASH, ROLE_TYPE).toUInt() != DIR_TYPE_DIR) {
			item = item->parent();//Only Dir as Parent
		}//while
	}//if (item)

	int index = 0;
	while (index < dirToAdd.count())
	{
		ColFileInfo root;
		if (item && (item != getRootItem())) {
			root.name = "";
			root.path = item->text(COLUMN_FILE);
		} else {
			root.name = "";
			root.path = "";
		}
		//QMap is ordered, so we get parent before child
		//Iterator is moved inside this function
		processItem(dirToAdd, index, root);
	}//while (index < dirToAdd.count())

	//Update liste before attach files to be sure when file is hashed, parent directory exists.
	updateList();

	for (QHash<QString,QString>::Iterator it = _listOfFilesAddedInDir.begin(); it != _listOfFilesAddedInDir.end() ; ++it)
	{
		QString path = it.value();
		it.value() = "";
		if (dirToAdd.contains(path)){
			it.value() = dirToAdd.value(path);
		} else if(item) {
			if (item->data(COLUMN_HASH, ROLE_NAME) != "") {
				it.value() = item->text(COLUMN_FILE);
			}//if (item->data(COLUMN_HASH, ROLE_NAME) != "")
		}//if (dirToAdd.contains(path))
	}//for (QHash<QString,QString>::Iterator it

	// Process Files once all done
	ui._hashBox->addAttachments(fileToHash,RS_FILE_REQ_ANONYMOUS_ROUTING /*, 0*/);
}
Exemplo n.º 16
0
/**
 * @brief RsCollectionDialog::updateSizes: Update Column size of ui._fileEntriesTW)
 */
void RsCollectionDialog::updateSizes()
{
	ui._selectedFiles_TL->setText(QString::number(getRootItem()->data(COLUMN_FILEC,ROLE_SELFILEC).toULongLong())) ;
	ui._totalSize_TL->setText(misc::friendlyUnit(getRootItem()->data(COLUMN_SIZE,ROLE_SELSIZE).toULongLong())) ;
}