Ejemplo n.º 1
0
bool BookmarksModel::moveBookmark(BookmarksItem *bookmark, BookmarksItem *newParent, int newRow)
{
	if (!bookmark || !newParent)
	{
		return false;
	}

	BookmarksItem *previousParent = dynamic_cast<BookmarksItem*>(bookmark->parent());

	if (!previousParent)
	{
		if (newRow < 0)
		{
			newParent->appendRow(bookmark);
		}
		else
		{
			newParent->insertRow(newRow, bookmark);
		}

		emit modelModified();

		return true;
	}

	const int previousRow = bookmark->row();

	if (newRow < 0)
	{
		newParent->appendRow(bookmark->parent()->takeRow(bookmark->row()));

		emit bookmarkMoved(bookmark, previousParent, previousRow);
		emit modelModified();

		return true;
	}

	int targetRow = newRow;

	if (bookmark->parent() == newParent && bookmark->row() < newRow)
	{
		--targetRow;
	}

	newParent->insertRow(targetRow, bookmark->parent()->takeRow(bookmark->row()));

	emit bookmarkMoved(bookmark, previousParent, previousRow);
	emit modelModified();

	return true;
}
Ejemplo n.º 2
0
AddressWidget::AddressWidget(QWidget *parent) : QLineEdit(parent),
	m_window(NULL),
	m_completer(new QCompleter(AddressCompletionModel::getInstance(), this)),
	m_bookmarkLabel(NULL),
	m_urlIconLabel(NULL),
	m_lookupIdentifier(0),
	m_lookupTimer(0)
{
	m_completer->setCaseSensitivity(Qt::CaseInsensitive);
	m_completer->setCompletionMode(QCompleter::InlineCompletion);
	m_completer->setCompletionRole(Qt::DisplayRole);
	m_completer->setFilterMode(Qt::MatchStartsWith);

	optionChanged(QLatin1String("AddressField/ShowBookmarkIcon"), SettingsManager::getValue(QLatin1String("AddressField/ShowBookmarkIcon")));
	optionChanged(QLatin1String("AddressField/ShowUrlIcon"), SettingsManager::getValue(QLatin1String("AddressField/ShowUrlIcon")));
	setCompleter(m_completer);
	setMinimumWidth(100);
	setMouseTracking(true);
	installEventFilter(this);

	connect(this, SIGNAL(textChanged(QString)), this, SLOT(setCompletion(QString)));
	connect(this, SIGNAL(returnPressed()), this, SLOT(notifyRequestedLoadUrl()));
	connect(BookmarksManager::getInstance(), SIGNAL(modelModified()), this, SLOT(updateBookmark()));
	connect(SettingsManager::getInstance(), SIGNAL(valueChanged(QString,QVariant)), this, SLOT(optionChanged(QString,QVariant)));
}
Ejemplo n.º 3
0
void HistoryModel::removeEntry(quint64 identifier)
{
	HistoryEntryItem *entry(getEntry(identifier));

	if (!entry)
	{
		return;
	}

	const QUrl url(Utils::normalizeUrl(entry->data(UrlRole).toUrl()));

	if (m_urls.contains(url))
	{
		m_urls[url].removeAll(entry);

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

	if (identifier > 0 && m_identifiers.contains(identifier))
	{
		m_identifiers.remove(identifier);
	}

	emit entryRemoved(entry);

	removeRow(entry->row());

	emit modelModified();
}
Ejemplo n.º 4
0
void BookmarksModel::removeBookmark(BookmarksItem *bookmark)
{
	if (!bookmark)
	{
		return;
	}

	removeBookmarkUrl(bookmark);

	const quint64 identifier = bookmark->data(IdentifierRole).toULongLong();

	if (identifier > 0 && m_identifiers.contains(identifier))
	{
		m_identifiers.remove(identifier);
	}

	if (!bookmark->data(KeywordRole).toString().isEmpty() && m_keywords.contains(bookmark->data(KeywordRole).toString()))
	{
		m_keywords.remove(bookmark->data(KeywordRole).toString());
	}

	emit bookmarkRemoved(bookmark);

	bookmark->parent()->removeRow(bookmark->row());

	emit modelModified();
}
Ejemplo n.º 5
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();
}
Ejemplo n.º 6
0
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();
		}
	}
}
Ejemplo n.º 7
0
StartPageModel::StartPageModel(QObject *parent) : QStandardItemModel(parent),
	m_bookmark(nullptr)
{
	optionChanged(SettingsManager::Backends_WebOption);
	reloadModel();

	connect(BookmarksManager::getModel(), SIGNAL(modelModified()), this, SLOT(reloadModel()));
	connect(SettingsManager::getInstance(), SIGNAL(valueChanged(int,QVariant)), this, SLOT(optionChanged(int)));
}
Ejemplo n.º 8
0
void BookmarksModel::emptyTrash()
{
	BookmarksItem *trashItem = getTrashItem();
	trashItem->removeRows(0, trashItem->rowCount());
	trashItem->setEnabled(false);

	m_trash.clear();

	emit modelModified();
}
Ejemplo n.º 9
0
BookmarksModel* BookmarksManager::getModel()
{
	if (!m_model && m_instance)
	{
		m_model = new BookmarksModel(SessionsManager::getWritableDataPath(QLatin1String("bookmarks.xbel")), BookmarksModel::BookmarksMode, m_instance);

		connect(m_model, SIGNAL(modelModified()), m_instance, SLOT(scheduleSave()));
	}

	return m_model;
}
Ejemplo n.º 10
0
bool HistoryModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
	HistoryEntryItem *entry(dynamic_cast<HistoryEntryItem*>(itemFromIndex(index)));

	if (!entry)
	{
		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(entry);

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

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

			m_urls[newUrl].append(entry);
		}
	}

	entry->setItemData(value, role);

	switch (role)
	{
		case TitleRole:
		case UrlRole:
		case IdentifierRole:
		case TimeVisitedRole:
			emit entryModified(entry);
			emit modelModified();

			break;
	}

	return true;
}
Ejemplo n.º 11
0
void TreeModel::saveNewData(QWidget *widgetContainer, const QModelIndex &parentIndex)
{
    TreeItem *m_parent = itemFromIndex(parentIndex);

	if (m_parent != NULL)
	{
		int totalChilds = m_parent->childCount();
		QGridLayout *gridLayout = dynamic_cast<QGridLayout*>(widgetContainer->layout());

		for (int i = 0; i < gridLayout->rowCount(); i++)
		{
            QWidgetItem *widgetItem = dynamic_cast<QWidgetItem*>(gridLayout->itemAtPosition(i,3));
			if (widgetItem)
			{
				QLabel *label = dynamic_cast<QLabel*>(widgetItem->widget());
				QWidgetItem *widgetItem2 = dynamic_cast<QWidgetItem*>(gridLayout->itemAtPosition(i,1));

				if (label and widgetItem2)
				{
					for (int j = 0; j < totalChilds; j++)
					{
						if (label->text() == m_parent->child(j)->getUID())
						{
							QLineEdit *lineEdit = qobject_cast<QLineEdit*>(widgetItem2->widget());
							QComboBox *comboBox = qobject_cast<QComboBox*>(widgetItem2->widget());
							if (lineEdit)
								m_parent->child(j)->setValue(lineEdit->text());
							else if (comboBox)
                            {
                                QString valAux = "";
                                if (comboBox->currentText() == "TRUE")
                                    valAux = "1";
                                else if (comboBox->currentText() == "FALSE")
                                    valAux = "0";

                                m_parent->child(j)->setValue(valAux);
                            }

							TreeItem *item = new TreeItem(m_parent->child(j));
							m_parent->removeRow(j);
							m_parent->insertRow(j, item);
						}
					}
				}
			}
		}

		emit modelModified();
	}
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
void SpecificWorker::modelModified(const RoboCompAGMWorldModel::Event& modification){
	 printf(" - - - - m - - - -\n");
	 initial_broadcast=true;
	 mutex->lock();
	 AGMModelConverter::fromIceToInternal(modification.newModel, worldModel);
	 //updateRCISModel(modification);
	 buildModificationLists(modification);
	 if (initialized)
	 {
		  updateRCISModel(modification);
		  mutex->unlock();
	 }
	 else
	 {
		  initialized = true;
		  RoboCompAGMWorldModel::Event modification2 = modification;
		  modification2.backModel.nodes.clear();
		  modification2.backModel.edges.clear();
		  mutex->unlock();
		  modelModified(modification2);
	 }
	mutex->unlock();
}
Ejemplo n.º 14
0
		optionChanged(QLatin1String("AddressField/ShowBookmarkIcon"), SettingsManager::getValue(QLatin1String("AddressField/ShowBookmarkIcon")));
		optionChanged(QLatin1String("AddressField/ShowUrlIcon"), SettingsManager::getValue(QLatin1String("AddressField/ShowUrlIcon")));

		lineEdit()->setPlaceholderText(tr("Enter address or search…"));

		connect(SettingsManager::getInstance(), SIGNAL(valueChanged(QString,QVariant)), this, SLOT(optionChanged(QString,QVariant)));

		if (toolBar->getIdentifier() != ToolBarsManager::NavigationBar)
		{
			connect(toolBar, SIGNAL(windowChanged(Window*)), this, SLOT(setWindow(Window*)));
		}
	}

	connect(this, SIGNAL(activated(QString)), this, SLOT(openUrl(QString)));
	connect(lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(setCompletion(QString)));
	connect(BookmarksManager::getModel(), SIGNAL(modelModified()), this, SLOT(updateBookmark()));
	connect(HistoryManager::getInstance(), SIGNAL(typedHistoryModelModified()), this, SLOT(updateLineEdit()));
}

void AddressWidget::changeEvent(QEvent *event)
{
	QComboBox::changeEvent(event);

	if (event->type() == QEvent::LanguageChange && !m_isUsingSimpleMode)
	{
		lineEdit()->setPlaceholderText(tr("Enter address or search…"));
	}
}

void AddressWidget::timerEvent(QTimerEvent *event)
{
Ejemplo n.º 15
0
		optionChanged(SettingsManager::AddressField_ShowUrlIconOption, SettingsManager::getValue(SettingsManager::AddressField_ShowUrlIconOption));

		m_lineEdit->setPlaceholderText(tr("Enter address or search…"));

		connect(SettingsManager::getInstance(), SIGNAL(valueChanged(int,QVariant)), this, SLOT(optionChanged(int,QVariant)));

		if (toolBar->getIdentifier() != ToolBarsManager::NavigationBar)
		{
			connect(toolBar, SIGNAL(windowChanged(Window*)), this, SLOT(setWindow(Window*)));
		}
	}

	connect(this, SIGNAL(activated(QString)), this, SLOT(openUrl(QString)));
	connect(m_lineEdit, SIGNAL(textDropped(QString)), this, SLOT(handleUserInput(QString)));
	connect(m_completionModel, SIGNAL(completionReady(QString)), this, SLOT(setCompletion(QString)));
	connect(BookmarksManager::getModel(), SIGNAL(modelModified()), this, SLOT(updateBookmark()));
	connect(HistoryManager::getTypedHistoryModel(), SIGNAL(modelModified()), this, SLOT(updateLineEdit()));
}

void AddressWidget::changeEvent(QEvent *event)
{
	ComboBoxWidget::changeEvent(event);

	switch (event->type())
	{
		case QEvent::LanguageChange:
			if (!m_isUsingSimpleMode)
			{
				m_lineEdit->setPlaceholderText(tr("Enter address or search…"));
			}
Ejemplo n.º 16
0
Menu::Menu(MenuRole role, QWidget *parent) : QMenu(parent),
	m_actionGroup(NULL),
	m_bookmark(NULL),
	m_role(role)
{
	switch (role)
	{
		case BookmarksMenuRole:
		case BookmarkSelectorMenuRole:
		case NotesMenuRole:
			{
				installEventFilter(this);

				Menu *parentMenu = qobject_cast<Menu*>(parent);

				if (!parentMenu || parentMenu->getRole() != m_role)
				{
					if (m_role == NotesMenuRole)
					{
						connect(NotesManager::getModel(), SIGNAL(modelModified()), this, SLOT(clearModelMenu()));
					}
					else
					{
						connect(BookmarksManager::getModel(), SIGNAL(modelModified()), this, SLOT(clearModelMenu()));
					}
				}

				connect(this, SIGNAL(aboutToShow()), this, SLOT(populateModelMenu()));
			}

			break;
		case CharacterEncodingMenuRole:
			connect(this, SIGNAL(aboutToShow()), this, SLOT(populateCharacterEncodingMenu()));
			connect(this, SIGNAL(triggered(QAction*)), this, SLOT(selectCharacterEncoding(QAction*)));

			break;
		case ClosedWindowsMenu:
			{
				setIcon(Utils::getIcon(QLatin1String("user-trash")));

				MainWindow *mainWindow = MainWindow::findMainWindow(parent);

				if (mainWindow)
				{
					setEnabled(!SessionsManager::getClosedWindows().isEmpty() || !mainWindow->getWindowsManager()->getClosedWindows().isEmpty());

					connect(mainWindow->getWindowsManager(), SIGNAL(closedWindowsAvailableChanged(bool)), this, SLOT(updateClosedWindowsMenu()));
				}

				connect(SessionsManager::getInstance(), SIGNAL(closedWindowsChanged()), this, SLOT(updateClosedWindowsMenu()));
				connect(this, SIGNAL(aboutToShow()), this, SLOT(populateClosedWindowsMenu()));
			}

			break;
		case ImportExportMenuRole:
			QMenu::addAction(tr("Import Opera Bookmarks…"))->setData(QLatin1String("OperaBookmarks"));
			QMenu::addAction(tr("Import HTML Bookmarks…"))->setData(QLatin1String("HtmlBookmarks"));
			QMenu::addSeparator();
			QMenu::addAction(tr("Import Opera Notes…"))->setData(QLatin1String("OperaNotes"));

			connect(this, SIGNAL(triggered(QAction*)), this, SLOT(openImporter(QAction*)));

			break;
		case SessionsMenuRole:
			connect(this, SIGNAL(aboutToShow()), this, SLOT(populateSessionsMenu()));
			connect(this, SIGNAL(triggered(QAction*)), this, SLOT(openSession(QAction*)));

			break;
		case ToolBarsMenuRole:
			connect(this, SIGNAL(aboutToShow()), this, SLOT(populateToolBarsMenu()));

			break;
		case UserAgentMenuRole:
			connect(this, SIGNAL(aboutToShow()), this, SLOT(populateUserAgentMenu()));
			connect(this, SIGNAL(triggered(QAction*)), this, SLOT(selectUserAgent(QAction*)));

			break;
		case WindowsMenuRole:
			connect(this, SIGNAL(aboutToShow()), this, SLOT(populateWindowsMenu()));
			connect(this, SIGNAL(triggered(QAction*)), this, SLOT(selectWindow(QAction*)));

			break;
		default:
			break;
	}
}
Ejemplo n.º 17
0
View::View(QWidget *parent, Recipe *recipe)
    : QWidget(parent), recipe_(recipe), grainmodel_(0), hopmodel_(0),
      miscmodel_(0), notepage_(0)
{
    ui.setupUi(this);

    // get current font information
    QFont bold(font());
    bold.setBold(true);
    QFontMetrics fm(font());
    unsigned mh = (unsigned)(fm.lineSpacing() * 1.5);
    unsigned mw = fm.width('M');

    // additional setup
    ui.ogreclabel->setFont(bold);
    ui.ogrec->setFont(bold);
    ui.ibureclabel->setFont(bold);
    ui.iburec->setFont(bold);
    ui.srmreclabel->setFont(bold);
    ui.srmrec->setFont(bold);
    ui.abvlabel->setFont(bold);
    ui.abv->setFont(bold);
    ui.abwlabel->setFont(bold);
    ui.abw->setFont(bold);
    ui.fglabel->setFont(bold);
    ui.fg->setFont(bold);

    // grain page
    QWidget *widget = new QWidget();
    grainpage.setupUi(widget);
    ui.ingredients->addTab(widget, tr("&Grains"));

    grainmodel_ = new GrainModel(this, recipe_->grains());
    grainpage.view->setModel(grainmodel_);
    QItemDelegate *delegate = new GrainDelegate(this);
    grainpage.view->setItemDelegate(delegate);

    grainpage.view->verticalHeader()->setDefaultSectionSize(mh);
    grainpage.view->verticalHeader()->hide();
    grainpage.view->horizontalHeader()->setClickable(true);
    grainpage.view->horizontalHeader()->setHighlightSections(false);

    grainpage.view->setColumnWidth(GrainModel::NAME, 20*mw);
    grainpage.view->setColumnWidth(GrainModel::WEIGHT, 8*mw);
    grainpage.view->setColumnWidth(GrainModel::EXTRACT, 8*mw);
    grainpage.view->setColumnWidth(GrainModel::COLOR, 8*mw);
    grainpage.view->setColumnWidth(GrainModel::TYPE, 8*mw);
    grainpage.view->setColumnWidth(GrainModel::USE, 8*mw);

    // hop page
    widget = new QWidget();
    hoppage.setupUi(widget);
    ui.ingredients->addTab(widget, tr("&Hops"));

    hopmodel_ = new HopModel(this, recipe_->hops());
    hoppage.view->setModel(hopmodel_);
    delegate = new HopDelegate(this);
    hoppage.view->setItemDelegate(delegate);

    hoppage.view->verticalHeader()->setDefaultSectionSize(mh);
    hoppage.view->verticalHeader()->hide();
    hoppage.view->horizontalHeader()->setClickable(true);
    hoppage.view->horizontalHeader()->setHighlightSections(false);

    hoppage.view->setColumnWidth(HopModel::NAME, 20*mw);
    hoppage.view->setColumnWidth(HopModel::WEIGHT, 8*mw);
    hoppage.view->setColumnWidth(HopModel::ALPHA, 8*mw);
    hoppage.view->setColumnWidth(HopModel::TIME, 8*mw);
    hoppage.view->setColumnWidth(HopModel::TYPE, 8*mw);

    // misc page
    widget = new QWidget();
    miscpage.setupUi(widget);
    ui.ingredients->addTab(widget, tr("&Miscellaneous"));

    miscmodel_ = new MiscModel(this, recipe_->miscs());
    miscpage.view->setModel(miscmodel_);
    delegate = new MiscDelegate(this);
    miscpage.view->setItemDelegate(delegate);

    miscpage.view->verticalHeader()->setDefaultSectionSize(mh);
    miscpage.view->verticalHeader()->hide();
    miscpage.view->horizontalHeader()->setClickable(true);
    miscpage.view->horizontalHeader()->setHighlightSections(false);

    miscpage.view->setColumnWidth(MiscModel::NAME, 20*mw);
    miscpage.view->setColumnWidth(MiscModel::QUANTITY, 8*mw);
    miscpage.view->setColumnWidth(MiscModel::TYPE, 8*mw);
    miscpage.view->horizontalHeader()->setStretchLastSection(true);

    // note page
    notepage_ = new NotePage(0, recipe_);
    ui.ingredients->addTab(notepage_, tr("&Notes"));

    // set icons
    QIcon icon = QIcon(":/icons/22x22/list-add.png");
    icon.addFile(":/icons/16x16/list-add.png");
    grainpage.addbutton->setIcon(icon);
    hoppage.addbutton->setIcon(icon);
    miscpage.addbutton->setIcon(icon);
    icon = QIcon(":/icons/22x22/list-remove.png");
    icon.addFile(":/icons/16x16/list-remove.png");
    grainpage.removebutton->setIcon(icon);
    hoppage.removebutton->setIcon(icon);
    miscpage.removebutton->setIcon(icon);

    // widget connections
    connect(grainmodel_, SIGNAL(modified()),
            this, SLOT(modelModified()));
    connect(grainpage.addbutton, SIGNAL(clicked()),
            grainpage.view, SLOT(addIngredient()));
    connect(grainpage.removebutton, SIGNAL(clicked()),
            grainpage.view, SLOT(removeIngredient()));

    connect(hopmodel_, SIGNAL(modified()),
            this, SLOT(modelModified()));
    connect(hoppage.addbutton, SIGNAL(clicked()),
            hoppage.view, SLOT(addIngredient()));
    connect(hoppage.removebutton, SIGNAL(clicked()),
            hoppage.view, SLOT(removeIngredient()));

    connect(miscmodel_, SIGNAL(modified()),
            this, SLOT(modelModified()));
    connect(miscpage.addbutton, SIGNAL(clicked()),
            miscpage.view, SLOT(addIngredient()));
    connect(miscpage.removebutton, SIGNAL(clicked()),
            miscpage.view, SLOT(removeIngredient()));

    connect(ui.titleedit, SIGNAL(textChanged(const QString &)),
            this, SLOT(setTitle(const QString &)));
    connect(ui.stylecombo, SIGNAL(activated(const QString &)),
            this, SLOT(setStyle(const QString &)));
    connect(ui.breweredit, SIGNAL(textChanged(const QString &)),
            this, SLOT(setBrewer(const QString &)));
    connect(ui.sizespin, SIGNAL(valueChanged(double)),
            this, SLOT(setSize(double)));

    connect(recipe_, SIGNAL(recipeChanged()), this, SLOT(flush()));
    connect(recipe_, SIGNAL(recipeModified()), this, SLOT(refresh()));

    // start with new view
    flush();
}
Ejemplo n.º 18
0
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;
}
Ejemplo n.º 19
0
void StartPageModel::reloadModel()
{
	const QString path(SettingsManager::getValue(SettingsManager::StartPage_BookmarksFolderOption).toString());

	m_bookmark = BookmarksManager::getModel()->getItem(path);

	if (!m_bookmark)
	{
		const QStringList directories(path.split(QLatin1Char('/'), QString::SkipEmptyParts));

		m_bookmark = BookmarksManager::getModel()->getRootItem();

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

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

					hasFound = true;

					break;
				}
			}

			if (!hasFound)
			{
				disconnect(BookmarksManager::getModel(), SIGNAL(modelModified()), this, SLOT(reloadModel()));

				m_bookmark = BookmarksManager::getModel()->addBookmark(BookmarksModel::FolderBookmark, 0, QUrl(), directories.at(i), m_bookmark);

				connect(BookmarksManager::getModel(), SIGNAL(modelModified()), this, SLOT(reloadModel()));
			}
		}
	}

	clear();

	if (m_bookmark)
	{
		for (int i = 0; i < m_bookmark->rowCount(); ++i)
		{
			if (m_bookmark->child(i))
			{
				const BookmarksModel::BookmarkType type(static_cast<BookmarksModel::BookmarkType>(m_bookmark->child(i)->data(BookmarksModel::TypeRole).toInt()));

				if (type != BookmarksModel::UrlBookmark && type != BookmarksModel::FolderBookmark)
				{
					continue;
				}

				const quint64 identifier(m_bookmark->child(i)->data(BookmarksModel::IdentifierRole).toULongLong());
				const QUrl url(m_bookmark->child(i)->data(BookmarksModel::UrlRole).toUrl());
				QStandardItem *item(m_bookmark->child(i)->clone());
				item->setData(identifier, BookmarksModel::IdentifierRole);

				if (url.isValid() && SettingsManager::getValue(SettingsManager::StartPage_TileBackgroundModeOption) == QLatin1String("thumbnail") && !QFile::exists(SessionsManager::getWritableDataPath(QLatin1String("thumbnails/")) + QString::number(identifier) + QLatin1String(".png")))
				{
					m_reloads[url] = qMakePair(identifier, false);

					AddonsManager::getWebBackend()->requestThumbnail(url, QSize(SettingsManager::getValue(SettingsManager::StartPage_TileWidthOption).toInt(), SettingsManager::getValue(SettingsManager::StartPage_TileHeightOption).toInt()));
				}

				appendRow(item);
			}
		}
	}

	if (SettingsManager::getValue(SettingsManager::StartPage_ShowAddTileOption).toBool())
	{
		QStandardItem *item(new QStandardItem());
		item->setData(tr("Add Tile…"), Qt::ToolTipRole);
		item->setData(tr("Add Tile…"), Qt::StatusTipRole);
		item->setData(QLatin1String("add"), Qt::AccessibleDescriptionRole);
		item->setDragEnabled(false);
		item->setDropEnabled(false);

		appendRow(item);
	}

	emit modelModified();
}