void BookmarksModel::trashBookmark(BookmarksItem *bookmark)
{
	if (!bookmark)
	{
		return;
	}

	const BookmarkType type = static_cast<BookmarkType>(bookmark->data(TypeRole).toInt());

	if (type != RootBookmark && type != TrashBookmark)
	{
		if (type == SeparatorBookmark || bookmark->data(IsTrashedRole).toBool())
		{
			bookmark->remove();
		}
		else
		{
			BookmarksItem *trashItem = getTrashItem();

			m_trash[bookmark] = qMakePair(bookmark->parent()->index(), bookmark->row());

			trashItem->appendRow(bookmark->parent()->takeRow(bookmark->row()));
			trashItem->setEnabled(true);

			removeBookmarkUrl(bookmark);

			emit bookmarkModified(bookmark);
			emit bookmarkTrashed(bookmark);
			emit modelModified();
		}
	}
}
QList<QUrl> BookmarksItem::getUrls() const
{
	QList<QUrl> urls;

	if (static_cast<BookmarksModel::BookmarkType>(data(BookmarksModel::TypeRole).toInt()) == BookmarksModel::UrlBookmark)
	{
		urls.append(data(BookmarksModel::UrlRole).toUrl());
	}

	for (int i = 0; i < rowCount(); ++i)
	{
		BookmarksItem *bookmark = dynamic_cast<BookmarksItem*>(child(i, 0));

		if (!bookmark)
		{
			continue;
		}

		const BookmarksModel::BookmarkType type = static_cast<BookmarksModel::BookmarkType>(bookmark->data(BookmarksModel::TypeRole).toInt());

		if (type == BookmarksModel::FolderBookmark)
		{
			urls.append(bookmark->getUrls());
		}
		else if (type == BookmarksModel::UrlBookmark)
		{
			urls.append(bookmark->data(BookmarksModel::UrlRole).toUrl());
		}
	}

	return urls;
}
QList<BookmarksItem*> BookmarksModel::findUrls(const QUrl &url, QStandardItem *branch) const
{
	if (!branch)
	{
		branch = item(0, 0);
	}

	QList<BookmarksItem*> items;

	for (int i = 0; i < branch->rowCount(); ++i)
	{
		BookmarksItem *item = dynamic_cast<BookmarksItem*>(branch->child(i));

		if (item)
		{
			const BookmarkType type = static_cast<BookmarkType>(item->data(TypeRole).toInt());

			if (type == FolderBookmark)
			{
				items.append(findUrls(url, item));
			}
			else if (type == UrlBookmark && item->data(UrlRole).toUrl() == url)
			{
				items.append(item);
			}
		}
	}

	return items;
}
void BookmarksModel::emptyTrash()
{
	BookmarksItem *trashItem = getTrashItem();
	trashItem->removeRows(0, trashItem->rowCount());
	trashItem->setEnabled(false);

	m_trash.clear();

	emit modelModified();
}
void BookmarksContentsWidget::addBookmark()
{
	BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, QUrl(), QString(), findFolder(m_ui->bookmarksViewWidget->currentIndex()));
	BookmarkPropertiesDialog dialog(bookmark, BookmarkPropertiesDialog::AddBookmarkMode, this);

	if (dialog.exec() == QDialog::Rejected)
	{
		bookmark->remove();
	}
}
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()));
}
Exemple #7
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool BookmarksModel::insertRows(int position, int rows, const QModelIndex& parent)
{
  BookmarksItem* parentItem = getItem(parent);
  bool success;

  beginInsertRows(parent, position, position + rows - 1);
  success = parentItem->insertChildren(position, rows, rootItem->columnCount());
  endInsertRows();

  return success;
}
Exemple #8
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool BookmarksModel::removeRows(int position, int rows, const QModelIndex& parent)
{
  BookmarksItem* parentItem = getItem(parent);
  bool success = true;

  beginRemoveRows(parent, position, position + rows - 1);
  success = parentItem->removeChildren(position, rows);
  endRemoveRows();

  return success;
}
void BookmarksContentsWidget::bookmarkProperties()
{
	BookmarksItem *bookmark = dynamic_cast<BookmarksItem*>(BookmarksManager::getModel()->itemFromIndex(m_ui->bookmarksViewWidget->currentIndex()));

	if (bookmark)
	{
		BookmarkPropertiesDialog(bookmark, (bookmark->isInTrash() ? BookmarkPropertiesDialog::ViewBookmarkMode : BookmarkPropertiesDialog::EditBookmarkMode), this).exec();

		updateActions();
	}
}
void WebWidget::pasteNote(QAction *action)
{
	if (action && action->data().isValid())
	{
		BookmarksItem *note = NotesManager::getModel()->bookmarkFromIndex(action->data().toModelIndex());

		if (note)
		{
			pasteText(note->data(BookmarksModel::DescriptionRole).toString());
		}
	}
}
void BookmarksItem::removeChild(int index, bool d)
{
    BookmarksItem * child = this->child(index);
    if(child)
    {
        if(d)
        {
            child->deleteLater();
        }
        m_children.removeAt(index);
    }
}
Exemple #12
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QModelIndex BookmarksModel::index(int row, int column, const QModelIndex& parent) const
{
  if (parent.isValid() && parent.column() != 0)
  { return QModelIndex(); }

  BookmarksItem* parentItem = getItem(parent);

  BookmarksItem* childItem = parentItem->child(row);
  if (childItem)
  { return createIndex(row, column, childItem); }
  else
  { return QModelIndex(); }
}
Exemple #13
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QModelIndex BookmarksModel::parent(const QModelIndex& index) const
{
  if (!index.isValid())
  { return QModelIndex(); }

  BookmarksItem* childItem = getItem(index);
  BookmarksItem* parentItem = childItem->parent();

  if (parentItem == rootItem)
  { return QModelIndex(); }

  return createIndex(parentItem->childNumber(), 0, parentItem);
}
QStandardItem* BookmarksItem::clone() const
{
	BookmarksItem *item = new BookmarksItem();
	item->setData(data(BookmarksModel::TypeRole), BookmarksModel::TypeRole);
	item->setData(data(BookmarksModel::UrlRole), BookmarksModel::UrlRole);
	item->setData(data(BookmarksModel::TitleRole), BookmarksModel::TitleRole);
	item->setData(data(BookmarksModel::DescriptionRole), BookmarksModel::DescriptionRole);
	item->setData(data(BookmarksModel::KeywordRole), BookmarksModel::KeywordRole);
	item->setData(data(BookmarksModel::TimeAddedRole), BookmarksModel::TimeAddedRole);
	item->setData(data(BookmarksModel::TimeModifiedRole), BookmarksModel::TimeModifiedRole);
	item->setData(data(BookmarksModel::TimeVisitedRole), BookmarksModel::TimeVisitedRole);
	item->setData(data(BookmarksModel::VisitsRole), BookmarksModel::VisitsRole);

	return item;
}
int BookmarksItem::index()
{
    BookmarksItem * parent = qobject_cast<BookmarksItem *>(this->parent());
    if(parent)
    {
        for(int i = 0; i < parent->childrenCount(); i++)
        {
            if(parent->child(i) == this)
            {
                return i;
            }
        }
    }
    return -1;
}
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();
}
Exemple #17
0
void MainWindow::addBookmark(const QUrl &url, const QString &title, const QString &description, bool warn)
{
	const QUrl bookmarkUrl = (url.isValid() ? url.adjusted(QUrl::RemovePassword) : m_windowsManager->getUrl().adjusted(QUrl::RemovePassword));

	if (bookmarkUrl.isEmpty() || (warn && BookmarksManager::hasBookmark(bookmarkUrl) && QMessageBox::warning(this, tr("Warning"), tr("You already have this address in your bookmarks.\nDo you want to continue?"), (QMessageBox::Yes | QMessageBox::Cancel)) == QMessageBox::Cancel))
	{
		return;
	}

	BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, bookmarkUrl, (url.isValid() ? title : m_windowsManager->getTitle()));
	bookmark->setData(description, BookmarksModel::DescriptionRole);

	BookmarkPropertiesDialog dialog(bookmark, BookmarkPropertiesDialog::AddBookmarkMode, this);

	if (dialog.exec() == QDialog::Rejected)
	{
		bookmark->remove();
	}
}
Exemple #18
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
Qt::ItemFlags BookmarksModel::flags(const QModelIndex& index) const
{
  if (!index.isValid())
  { return 0; }

  Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);

  BookmarksItem* item = getItem(index);
  QString name = item->data(BookmarksItem::Name).toString();
  if (item->data(BookmarksItem::Path).toString().isEmpty())
  {
    // This is a node
    return (defaultFlags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
  }
  else
  {
    // This is a leaf
    return (defaultFlags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsDragEnabled);
  }
}
Exemple #19
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool BookmarksModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
  BookmarksItem* item = getItem(index);
  bool result = false;

  if (role == Qt::UserRole)
  {
    result = item->setItemHasErrors(value.value<bool>());
  }
  else if (role == Qt::DecorationRole)
  {
    result = item->setIcon(value.value<QIcon>());
  }
  else
  {
    result = item->setData(index.column(), value);
  }

  if (result)
  { emit dataChanged(index, index); }

  return result;
}
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;
}
BookmarksItem* BookmarksManager::getLastUsedFolder()
{
	BookmarksItem *folder = getModel()->getBookmark(m_lastUsedFolder);

	return ((!folder || static_cast<BookmarksModel::BookmarkType>(folder->data(BookmarksModel::TypeRole).toInt()) != BookmarksModel::FolderBookmark) ? getModel()->getRootItem() : folder);
}
Exemple #22
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
bool BookmarksModel::needsToBeExpanded(const QModelIndex& index)
{
  BookmarksItem* item = getItem(index);
  return item->needsToBeExpanded();
}
Exemple #23
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void BookmarksModel::setNeedsToBeExpanded(const QModelIndex& index, bool value)
{
  BookmarksItem* item = getItem(index);
  item->setNeedsToBeExpanded(value);
}
Exemple #24
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
int BookmarksModel::rowCount(const QModelIndex& parent) const
{
  BookmarksItem* parentItem = getItem(parent);

  return parentItem->childCount();
}
bool BookmarksModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
	BookmarksItem *bookmark = dynamic_cast<BookmarksItem*>(itemFromIndex(index));

	if (!bookmark)
	{
		return QStandardItemModel::setData(index, value, role);
	}

	if (role == UrlRole && value.toUrl() != index.data(UrlRole).toUrl())
	{
		const QUrl oldUrl = Utils::normalizeUrl(index.data(UrlRole).toUrl());
		const QUrl newUrl = Utils::normalizeUrl(value.toUrl());

		if (!oldUrl.isEmpty() && m_urls.contains(oldUrl))
		{
			m_urls[oldUrl].removeAll(bookmark);

			if (m_urls[oldUrl].isEmpty())
			{
				m_urls.remove(oldUrl);
			}
		}

		if (!newUrl.isEmpty())
		{
			if (!m_urls.contains(newUrl))
			{
				m_urls[newUrl] = QList<BookmarksItem*>();
			}

			m_urls[newUrl].append(bookmark);
		}
	}
	else if (role == KeywordRole && value.toString() != index.data(KeywordRole).toString())
	{
		const QString oldKeyword = index.data(KeywordRole).toString();
		const QString newKeyword = value.toString();

		if (!oldKeyword.isEmpty() && m_keywords.contains(oldKeyword))
		{
			m_keywords.remove(oldKeyword);
		}

		if (!newKeyword.isEmpty())
		{
			m_keywords[newKeyword] = bookmark;
		}
	}
	else if (m_mode == NotesMode && role == DescriptionRole)
	{
		const QString title = value.toString().section(QLatin1Char('\n'), 0, 0).left(100);

		setData(index, ((title == value.toString().trimmed()) ? title : title + QStringLiteral("…")), TitleRole);
	}

	bookmark->setItemData(value, role);

	switch (role)
	{
		case TitleRole:
		case UrlRole:
		case DescriptionRole:
		case IdentifierRole:
		case TypeRole:
		case KeywordRole:
		case TimeAddedRole:
		case TimeModifiedRole:
		case TimeVisitedRole:
		case VisitsRole:
			emit bookmarkModified(bookmark);
			emit modelModified();

			break;
	}

	return true;
}
void BookmarksModel::readBookmark(QXmlStreamReader *reader, BookmarksItem *parent)
{
	BookmarksItem *bookmark = NULL;

	if (reader->name() == QLatin1String("folder"))
	{
		bookmark = addBookmark(FolderBookmark, reader->attributes().value(QLatin1String("id")).toULongLong(), QUrl(), QString(), parent);
		bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("added")).toString(), Qt::ISODate), TimeAddedRole);
		bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("modified")).toString(), Qt::ISODate), TimeModifiedRole);

		while (reader->readNext())
		{
			if (reader->isStartElement())
			{
				if (reader->name() == QLatin1String("title"))
				{
					bookmark->setData(reader->readElementText().trimmed(), TitleRole);
				}
				else if (reader->name() == QLatin1String("desc"))
				{
					bookmark->setData(reader->readElementText().trimmed(), DescriptionRole);
				}
				else if (reader->name() == QLatin1String("folder") || reader->name() == QLatin1String("bookmark") || reader->name() == QLatin1String("separator"))
				{
					readBookmark(reader, bookmark);
				}
				else if (reader->name() == QLatin1String("info"))
				{
					while (reader->readNext())
					{
						if (reader->isStartElement())
						{
							if (reader->name() == QLatin1String("metadata") && reader->attributes().value(QLatin1String("owner")).toString().startsWith("http://otter-browser.org/"))
							{
								while (reader->readNext())
								{
									if (reader->isStartElement())
									{
										if (reader->name() == QLatin1String("keyword"))
										{
											bookmark->setData(reader->readElementText().trimmed(), KeywordRole);
										}
										else
										{
											reader->skipCurrentElement();
										}
									}
									else if (reader->isEndElement() && reader->name() == QLatin1String("metadata"))
									{
										break;
									}
								}
							}
							else
							{
								reader->skipCurrentElement();
							}
						}
						else if (reader->isEndElement() && reader->name() == QLatin1String("info"))
						{
							break;
						}
					}
				}
				else
				{
					reader->skipCurrentElement();
				}
			}
			else if (reader->isEndElement() && reader->name() == QLatin1String("folder"))
			{
				break;
			}
			else if (reader->hasError())
			{
				return;
			}
		}
	}
	else if (reader->name() == QLatin1String("bookmark"))
	{
		bookmark = addBookmark(UrlBookmark,reader->attributes().value(QLatin1String("id")).toULongLong(), reader->attributes().value(QLatin1String("href")).toString(), QString(), parent);
		bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("added")).toString(), Qt::ISODate), TimeAddedRole);
		bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("modified")).toString(), Qt::ISODate), TimeModifiedRole);
		bookmark->setData(QDateTime::fromString(reader->attributes().value(QLatin1String("visited")).toString(), Qt::ISODate), TimeVisitedRole);

		while (reader->readNext())
		{
			if (reader->isStartElement())
			{
				if (reader->name() == QLatin1String("title"))
				{
					bookmark->setData(reader->readElementText().trimmed(), TitleRole);
				}
				else if (reader->name() == QLatin1String("desc"))
				{
					bookmark->setData(reader->readElementText().trimmed(), DescriptionRole);
				}
				else if (reader->name() == QLatin1String("info"))
				{
					while (reader->readNext())
					{
						if (reader->isStartElement())
						{
							if (reader->name() == QLatin1String("metadata") && reader->attributes().value(QLatin1String("owner")).toString().startsWith("http://otter-browser.org/"))
							{
								while (reader->readNext())
								{
									if (reader->isStartElement())
									{
										if (reader->name() == QLatin1String("keyword"))
										{
											bookmark->setData(reader->readElementText().trimmed(), KeywordRole);
										}
										else if (reader->name() == QLatin1String("visits"))
										{
											bookmark->setData(reader->readElementText().toInt(), VisitsRole);
										}
										else
										{
											reader->skipCurrentElement();
										}
									}
									else if (reader->isEndElement() && reader->name() == QLatin1String("metadata"))
									{
										break;
									}
								}
							}
							else
							{
								reader->skipCurrentElement();
							}
						}
						else if (reader->isEndElement() && reader->name() == QLatin1String("info"))
						{
							break;
						}
					}
				}
				else
				{
					reader->skipCurrentElement();
				}
			}
			else if (reader->isEndElement() && reader->name() == QLatin1String("bookmark"))
			{
				break;
			}
			else if (reader->hasError())
			{
				return;
			}
		}
	}
	else if (reader->name() == QLatin1String("separator"))
	{
		addBookmark(SeparatorBookmark, 0, QUrl(), QString(), parent);

		reader->readNext();
	}
}
Exemple #27
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
QVariant BookmarksModel::data(const QModelIndex& index, int role) const
{
  if (!index.isValid())
  {
    return QVariant();
  }

  BookmarksItem* item = getItem(index);

  if (role == Qt::DisplayRole)
  {
    return item->data(index.column());
  }
  else if (role == Qt::UserRole)
  {
    return item->getItemHasErrors();
  }
  else if (role == Qt::BackgroundRole)
  {
    if (item->getItemHasErrors() == true)
    {
      return QColor(235, 110, 110);
    }
    else
    {
      return QVariant();
    }
  }
  else if (role == Qt::ForegroundRole)
  {
    if (item->getItemHasErrors() == true)
    {
      return QColor(240, 240, 240);
    }
    else
    {
      return QColor(Qt::black);
    }
  }
  else if (role == Qt::ToolTipRole)
  {
    QString tooltip = "'" + this->index(index.row(), BookmarksItem::Path, index.parent()).data().toString() + "' was not found on the file system.\nYou can either locate the file or delete the entry from the table.";

    if (item->getItemHasErrors() == true)
    {
      return tooltip;
    }
    else
    {
      return "";
    }
  }
  else if (role == Qt::DecorationRole)
  {
    QModelIndex nameIndex = this->index(index.row(), BookmarksItem::Name, index.parent());
    if (nameIndex == index)
    {
      BookmarksItem* item = getItem(index);
      return item->getIcon();
    }
    else
    {
      return QVariant();
    }
  }
  else
  {
    return QVariant();
  }
}
QStandardItem* ToolBarDialog::createEntry(const QString &identifier)
{
	QStandardItem *item = new QStandardItem();
	item->setData(identifier, Qt::UserRole);
	item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);

	if (identifier == QLatin1String("separator"))
	{
		item->setText(tr("--- separator ---"));
	}
	else if (identifier == QLatin1String("spacer"))
	{
		item->setText(tr("--- spacer ---"));
	}
	else if (identifier == QLatin1String("AddressWidget"))
	{
		item->setText(tr("Address Field"));
	}
	else if (identifier == QLatin1String("ClosedWindowsWidget"))
	{
		item->setText(tr("List of Closed Windows and Tabs"));
	}
	else if (identifier == QLatin1String("MenuBarWidget"))
	{
		item->setText(tr("Menu Bar"));
	}
	else if (identifier == QLatin1String("MenuButtonWidget"))
	{
		item->setText(tr("Menu Button"));
	}
	else if (identifier == QLatin1String("PanelChooserWidget"))
	{
		item->setText(tr("Sidebar Panel Chooser"));
	}
	else if (identifier == QLatin1String("SearchWidget"))
	{
		item->setText(tr("Search Field"));
	}
	else if (identifier == QLatin1String("StatusMessageWidget"))
	{
		item->setText(tr("Status Message Field"));
	}
	else if (identifier == QLatin1String("TabBarWidget"))
	{
		item->setText(tr("Tab Bar"));
	}
	else if (identifier == QLatin1String("ZoomWidget"))
	{
		item->setText(tr("Zoom Slider"));
	}
	else if (identifier.startsWith(QLatin1String("bookmarks:")))
	{
		BookmarksItem *bookmark = (identifier.startsWith(QLatin1String("bookmarks:/")) ? BookmarksManager::getModel()->getItem(identifier.mid(11)) : BookmarksManager::getBookmark(identifier.mid(10).toULongLong()));

		if (bookmark)
		{
			item->setText(bookmark->data(BookmarksModel::TitleRole).isValid() ? bookmark->data(BookmarksModel::TitleRole).toString() : tr("(Untitled)"));
			item->setIcon(bookmark->data(Qt::DecorationRole).value<QIcon>());
		}
		else
		{
			item->setText(tr("Invalid Bookmark"));
		}
	}
	else if (identifier.endsWith(QLatin1String("Action")))
	{
		const int actionIdentifier = ActionsManager::getActionIdentifier(identifier.left(identifier.length() - 6));

		if (actionIdentifier < 0)
		{
			item->setText(tr("Invalid Entry"));
		}
		else
		{
			const ActionDefinition definition = ActionsManager::getActionDefinition(actionIdentifier);

			item->setText(QCoreApplication::translate("actions", (definition.description.isEmpty() ? definition.text : definition.description).toUtf8().constData()));
			item->setIcon(definition.icon);
		}
	}
	else
	{
		item->setText(tr("Invalid Entry"));
	}

	return item;
}
bool OperaNotesImporter::import()
{
	QTextStream stream(m_file);
	stream.setCodec("UTF-8");

	QString line = stream.readLine();

	if (line != QLatin1String("Opera Hotlist version 2.0"))
	{
		return false;
	}

	BookmarksItem *note = NULL;
	OperaNoteEntry type = NoEntry;
	bool isHeader = true;

	handleOptions();

	while (!stream.atEnd())
	{
		line = stream.readLine();

		if (isHeader && (line.isEmpty() || line.at(0) != QLatin1Char('#')))
		{
			continue;
		}

		isHeader = false;

		if (line.startsWith(QLatin1String("#NOTE")))
		{
			note = NotesManager::addNote(BookmarksModel::UrlBookmark, QUrl(), QString(), getCurrentFolder());
			type = NoteEntry;
		}
		else if (line.startsWith(QLatin1String("#FOLDER")))
		{
			note = NotesManager::addNote(BookmarksModel::FolderBookmark, QUrl(), QString(), getCurrentFolder());
			type = FolderStartEntry;
		}
		else if (line.startsWith(QLatin1String("#SEPERATOR")))
		{
			note = NotesManager::addNote(BookmarksModel::SeparatorBookmark, QUrl(), QString(), getCurrentFolder());
			type = SeparatorEntry;
		}
		else if (line == QLatin1String("-"))
		{
			type = FolderEndEntry;
		}
		else if (line.startsWith(QLatin1String("\tURL=")) && note)
		{
			const QUrl url(line.section(QLatin1Char('='), 1, -1));

			note->setData(url, BookmarksModel::UrlRole);
		}
		else if (line.startsWith(QLatin1String("\tNAME=")) && note)
		{
			note->setData(line.section(QLatin1Char('='), 1, -1).replace(QLatin1String("\x02\x02"), QLatin1String("\n")), BookmarksModel::DescriptionRole);
		}
		else if (line.startsWith(QLatin1String("\tCREATED=")) && note)
		{
			note->setData(QDateTime::fromTime_t(line.section(QLatin1Char('='), 1, -1).toUInt()), BookmarksModel::TimeAddedRole);
		}
		else if (line.isEmpty())
		{
			if (note)
			{
				if (type == FolderStartEntry)
				{
					setCurrentFolder(note);
				}

				note = NULL;
			}
			else if (type == FolderEndEntry)
			{
				goToParent();
			}

			type = NoEntry;
		}
	}

	return true;
}
void HtmlBookmarksImporter::processElement(const QWebElement &element)
{
	if (element.tagName().toLower() == QLatin1String("h3"))
	{
		BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, QUrl(), element.toPlainText(), getCurrentFolder());
		const QString keyword = element.attribute(QLatin1String("SHORTCUTURL"));

		if (!BookmarksManager::hasKeyword(keyword))
		{
			bookmark->setData(keyword, BookmarksModel::KeywordRole);
		}

		if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty())
		{
			const QDateTime time = QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt());

			bookmark->setData(time, BookmarksModel::TimeAddedRole);
			bookmark->setData(time, BookmarksModel::TimeModifiedRole);
		}

		setCurrentFolder(bookmark);
	}
	else if (element.tagName().toLower() == QLatin1String("a"))
	{
		const QUrl url(element.attribute(QLatin1String("href")));

		if (!allowDuplicates() && BookmarksManager::hasBookmark(url))
		{
			return;
		}

		BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, url, element.toPlainText(), getCurrentFolder());
		const QString keyword = element.attribute(QLatin1String("SHORTCUTURL"));

		if (!BookmarksManager::hasKeyword(keyword))
		{
			bookmark->setData(keyword, BookmarksModel::KeywordRole);
		}

		if (element.parent().nextSibling().tagName().toLower() == QLatin1String("dd"))
		{
			bookmark->setData(element.parent().nextSibling().toPlainText(), BookmarksModel::DescriptionRole);
		}

		if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty())
		{
			bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt()), BookmarksModel::TimeAddedRole);
		}

		if (!element.attribute(QLatin1String("LAST_MODIFIED")).isEmpty())
		{
			bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_MODIFIED")).toUInt()), BookmarksModel::TimeModifiedRole);
		}

		if (!element.attribute(QLatin1String("LAST_VISITED")).isEmpty())
		{
			bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_VISITED")).toUInt()), BookmarksModel::TimeVisitedRole);
		}
	}
	else if (element.tagName().toLower() == QLatin1String("hr"))
	{
		BookmarksManager::addBookmark(BookmarksModel::SeparatorBookmark, QUrl(), QString(), getCurrentFolder());
	}

	const QWebElementCollection descendants = element.findAll(QLatin1String("*"));

	for (int i = 0; i < descendants.count(); ++i)
	{
		if (descendants.at(i).parent() == element)
		{
			processElement(descendants.at(i));
		}
	}

	if (element.tagName().toLower() == QLatin1String("dl"))
	{
		goToParent();
	}
}