diff --git a/plugins/kimgalleryplugin/imgallerydialog.cpp b/plugins/kimgalleryplugin/imgallerydialog.cpp index 16a49476a..13282f07c 100644 --- a/plugins/kimgalleryplugin/imgallerydialog.cpp +++ b/plugins/kimgalleryplugin/imgallerydialog.cpp @@ -1,482 +1,482 @@ /* This file is part of the KDE project Copyright (C) 2001, 2003 Lukas Tinkl Andreas Schlapbach This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "imgallerydialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include KIGPDialog::KIGPDialog(QWidget *parent, const QString &path) : KPageDialog(parent) { setStandardButtons(QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Ok | QDialogButtonBox::Cancel); buttonBox()->button(QDialogButtonBox::Ok)->setDefault(true); setModal(true); setFaceType(List); m_path = path; setWindowTitle(i18nc("@title:window", "Create Image Gallery")); KGuiItem::assign(buttonBox()->button(QDialogButtonBox::Ok), KGuiItem(i18n("Create"), QStringLiteral("imagegallery"))); m_config = new KConfig(QStringLiteral("kimgallerypluginrc"), KConfig::NoGlobals); setupLookPage(path); setupDirectoryPage(path); setupThumbnailPage(path); connect(buttonBox()->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), this, SLOT(slotDefault())); } void KIGPDialog::slotDefault() { m_title->setText(i18n("Image Gallery for %1", m_path)); m_imagesPerRow->setValue(4); m_imageName->setChecked(true); m_imageSize->setChecked(false); m_imageProperty->setChecked(false); m_fontName->setItemText(m_fontName->currentIndex(), QFontDatabase::systemFont(QFontDatabase::GeneralFont).family()); m_fontSize->setValue(14); m_foregroundColor->setColor(QColor(QStringLiteral("#d0ffd0"))); m_backgroundColor->setColor(QColor(QStringLiteral("#333333"))); m_imageNameReq->setUrl(QUrl::fromLocalFile(m_path + "images.html")); m_recurseSubDir->setChecked(false); m_recursionLevel->setEnabled(false); m_recursionLevel->setValue(0); m_copyOriginalFiles->setChecked(false); m_useCommentFile->setChecked(false); m_commentFileReq->setUrl(QUrl::fromLocalFile(m_path + "comments")); m_commentFileReq->setEnabled(false); m_imageFormat->setItemText(m_imageFormat->currentIndex(), QStringLiteral("JPEG")); m_thumbnailSize->setValue(140); m_colorDepthSet->setChecked(false); m_colorDepth->setItemText(m_colorDepth->currentIndex(), QStringLiteral("8")); } void KIGPDialog::setupLookPage(const QString &path) { QFrame *page = new QFrame(); KPageWidgetItem *pageItem = new KPageWidgetItem(page, i18n("Look")); pageItem->setHeader(i18n("Page Look")); pageItem->setIcon(QIcon::fromTheme("fill-color")); addPage(pageItem); KConfigGroup look = m_config->group("Look"); QVBoxLayout *vlay = new QVBoxLayout(page); vlay->setMargin(0); QLabel *label = new QLabel(i18n("&Page title:"), page); vlay->addWidget(label); m_title = new QLineEdit(i18n("Image Gallery for %1", path), page); vlay->addWidget(m_title); label->setBuddy(m_title); m_imagesPerRow = new KIntNumInput(look.readEntry("ImagesPerRow", 4), page); m_imagesPerRow->setRange(1, 8, 1); m_imagesPerRow->setSliderEnabled(true); m_imagesPerRow->setLabel(i18n("I&mages per row:")); vlay->addWidget(m_imagesPerRow); QGridLayout *grid = new QGridLayout(); grid->setMargin(2); grid->setSpacing(2); vlay->addLayout(grid); m_imageName = new QCheckBox(i18n("Show image file &name"), page); m_imageName->setChecked(look.readEntry("ImageName", true)); grid->addWidget(m_imageName, 0, 0); m_imageSize = new QCheckBox(i18n("Show image file &size"), page); m_imageSize->setChecked(look.readEntry("ImageSize", false)); grid->addWidget(m_imageSize, 0, 1); m_imageProperty = new QCheckBox(i18n("Show image &dimensions"), page); m_imageProperty->setChecked(look.readEntry("ImageProperty", false)); grid->addWidget(m_imageProperty, 1, 0); QHBoxLayout *hlay11 = new QHBoxLayout(); vlay->addLayout(hlay11); m_fontName = new QComboBox(page); QStringList standardFonts; KFontChooser::getFontList(standardFonts, 0); m_fontName->addItems(standardFonts); m_fontName->setItemText(m_fontName->currentIndex(), look.readEntry("FontName", QFontDatabase::systemFont(QFontDatabase::GeneralFont).family())); label = new QLabel(i18n("Fon&t name:"), page); label->setBuddy(m_fontName); hlay11->addWidget(label); hlay11->addStretch(1); hlay11->addWidget(m_fontName); QHBoxLayout *hlay12 = new QHBoxLayout(); vlay->addLayout(hlay12); m_fontSize = new QSpinBox(page); m_fontSize->setMinimum(6); m_fontSize->setMaximum(15); m_fontSize->setSingleStep(1); m_fontSize->setValue(look.readEntry("FontSize", 14)); label = new QLabel(i18n("Font si&ze:"), page); label->setBuddy(m_fontSize); hlay12->addWidget(label); hlay12->addStretch(1); hlay12->addWidget(m_fontSize); QHBoxLayout *hlay1 = new QHBoxLayout(); vlay->addLayout(hlay1); m_foregroundColor = new KColorButton(page); m_foregroundColor->setColor(QColor(look.readEntry("ForegroundColor", "#d0ffd0"))); label = new QLabel(i18n("&Foreground color:"), page); label->setBuddy(m_foregroundColor); hlay1->addWidget(label); hlay1->addStretch(1); hlay1->addWidget(m_foregroundColor); QHBoxLayout *hlay2 = new QHBoxLayout(); vlay->addLayout(hlay2); m_backgroundColor = new KColorButton(page); m_backgroundColor->setColor(QColor(look.readEntry("BackgroundColor", "#333333"))); label = new QLabel(i18n("&Background color:"), page); hlay2->addWidget(label); label->setBuddy(m_backgroundColor); hlay2->addStretch(1); hlay2->addWidget(m_backgroundColor); vlay->addStretch(1); } void KIGPDialog::setupDirectoryPage(const QString &path) { QFrame *page = new QFrame(); KPageWidgetItem *pageItem = new KPageWidgetItem(page, i18n("Folders")); pageItem->setHeader(i18n("Folders")); - pageItem->setIcon(QIcon("folder")); + pageItem->setIcon(QIcon::fromTheme("folder")); addPage(pageItem); KConfigGroup group = m_config->group("Directory"); QVBoxLayout *dvlay = new QVBoxLayout(page); dvlay->setMargin(0); QLabel *label; label = new QLabel(i18n("&Save to HTML file:"), page); dvlay->addWidget(label); QString whatsThis; whatsThis = i18n("

The name of the HTML file this gallery will be saved to.

"); label->setWhatsThis(whatsThis); m_imageNameReq = new KUrlRequester(QUrl::fromLocalFile(QString(path + "images.html")), page); label->setBuddy(m_imageNameReq); dvlay->addWidget(m_imageNameReq); connect(m_imageNameReq, SIGNAL(textChanged(QString)), this, SLOT(imageUrlChanged(QString))); m_imageNameReq->setWhatsThis(whatsThis); const bool recurseSubDir = group.readEntry("RecurseSubDirectories", false); m_recurseSubDir = new QCheckBox(i18n("&Recurse subfolders"), page); m_recurseSubDir->setChecked(recurseSubDir); whatsThis = i18n("

Whether subfolders should be included for the " "image gallery creation or not.

"); m_recurseSubDir->setWhatsThis(whatsThis); const int recursionLevel = group.readEntry("RecursionLevel", 0); m_recursionLevel = new KIntNumInput(recursionLevel, page); m_recursionLevel->setRange(0, 99, 1); m_recursionLevel->setSliderEnabled(true); m_recursionLevel->setLabel(i18n("Rec&ursion depth:")); if (recursionLevel == 0) { m_recursionLevel->setSpecialValueText(i18n("Endless")); } m_recursionLevel->setEnabled(recurseSubDir); whatsThis = i18n("

You can limit the number of folders the " "image gallery creator will traverse to by setting an " "upper bound for the recursion depth.

"); m_recursionLevel->setWhatsThis(whatsThis); connect(m_recurseSubDir, SIGNAL(toggled(bool)), m_recursionLevel, SLOT(setEnabled(bool))); dvlay->addWidget(m_recurseSubDir); dvlay->addWidget(m_recursionLevel); m_copyOriginalFiles = new QCheckBox(i18n("Copy or&iginal files"), page); m_copyOriginalFiles->setChecked(group.readEntry("CopyOriginalFiles", false)); dvlay->addWidget(m_copyOriginalFiles); whatsThis = i18n("

This makes a copy of all images and the gallery will refer " "to these copies instead of the original images.

"); m_copyOriginalFiles->setWhatsThis(whatsThis); const bool useCommentFile = group.readEntry("UseCommentFile", false); m_useCommentFile = new QCheckBox(i18n("Use &comment file"), page); m_useCommentFile->setChecked(useCommentFile); dvlay->addWidget(m_useCommentFile); whatsThis = i18n("

If you enable this option you can specify " "a comment file which will be used for generating " "subtitles for the images.

" "

For details about the file format please see " "the \"What's This?\" help below.

"); m_useCommentFile->setWhatsThis(whatsThis); label = new QLabel(i18n("Comments &file:"), page); label->setEnabled(useCommentFile); dvlay->addWidget(label); whatsThis = i18n("

You can specify the name of the comment file here. " "The comment file contains the subtitles for the images. " "The format of this file is:

" "

FILENAME1:" "
Description" "
" "
FILENAME2:" "
Description" "
" "
and so on

"); label->setWhatsThis(whatsThis); m_commentFileReq = new KUrlRequester(QUrl::fromLocalFile(QString(path + "comments")), page); m_commentFileReq->setEnabled(useCommentFile); label->setBuddy(m_commentFileReq); dvlay->addWidget(m_commentFileReq); m_commentFileReq->setWhatsThis(whatsThis); connect(m_useCommentFile, SIGNAL(toggled(bool)), label, SLOT(setEnabled(bool))); connect(m_useCommentFile, SIGNAL(toggled(bool)), m_commentFileReq, SLOT(setEnabled(bool))); dvlay->addStretch(1); } void KIGPDialog::setupThumbnailPage(const QString &path) { Q_UNUSED(path); QFrame *page = new QFrame(); KPageWidgetItem *pageItem = new KPageWidgetItem(page, i18n("Thumbnails")); pageItem->setHeader(i18n("Thumbnails")); pageItem->setIcon(QIcon::fromTheme("view-preview")); addPage(pageItem); KConfigGroup group = m_config->group("Thumbnails"); QLabel *label; QVBoxLayout *vlay = new QVBoxLayout(page); vlay->setMargin(0); QHBoxLayout *hlay3 = new QHBoxLayout(); vlay->addLayout(hlay3); m_imageFormat = new QComboBox(page); QStringList lstImgageFormat; lstImgageFormat << QStringLiteral("JPEG") << QStringLiteral("PNG"); m_imageFormat->addItems(lstImgageFormat); m_imageFormat->setItemText(m_imageFormat->currentIndex(), group.readEntry("ImageFormat", "JPEG")); label = new QLabel(i18n("Image format f&or the thumbnails:"), page); hlay3->addWidget(label); label->setBuddy(m_imageFormat); hlay3->addStretch(1); hlay3->addWidget(m_imageFormat); m_thumbnailSize = new KIntNumInput(group.readEntry("ThumbnailSize", 140), page); m_thumbnailSize->setRange(10, 1000, 1); m_thumbnailSize->setLabel(i18n("Thumbnail size:")); m_thumbnailSize->setSliderEnabled(true); vlay->addWidget(m_thumbnailSize); QGridLayout *grid = new QGridLayout(); grid->setMargin(2); grid->setSpacing(2); vlay->addLayout(grid); QHBoxLayout *hlay4 = new QHBoxLayout(); vlay->addLayout(hlay4); const bool colorDepthSet = group.readEntry("ColorDepthSet", false); m_colorDepthSet = new QCheckBox(i18n("&Set different color depth:"), page); m_colorDepthSet->setChecked(colorDepthSet); hlay4->addWidget(m_colorDepthSet); m_colorDepth = new QComboBox(page); QStringList lst; lst << QStringLiteral("1") << QStringLiteral("8") << QStringLiteral("16") << QStringLiteral("32"); m_colorDepth->addItems(lst); m_colorDepth->setItemText(m_colorDepth->currentIndex(), group.readEntry("ColorDepth", "8")); m_colorDepth->setEnabled(colorDepthSet); hlay4->addWidget(m_colorDepth); connect(m_colorDepthSet, SIGNAL(toggled(bool)), m_colorDepth, SLOT(setEnabled(bool))); vlay->addStretch(1); } void KIGPDialog::writeConfig() { KConfigGroup group = m_config->group("Look"); group.writeEntry("ImagesPerRow", getImagesPerRow()); group.writeEntry("ImageName", printImageName()); group.writeEntry("ImageSize", printImageSize()); group.writeEntry("ImageProperty", printImageProperty()); group.writeEntry("FontName", getFontName()); group.writeEntry("FontSize", getFontSize()); group.writeEntry("ForegroundColor", getForegroundColor().name()); group.writeEntry("BackgroundColor", getBackgroundColor().name()); group = m_config->group("Directory"); group.writeEntry("RecurseSubDirectories", recurseSubDirectories()); group.writeEntry("RecursionLevel", recursionLevel()); group.writeEntry("CopyOriginalFiles", copyOriginalFiles()); group.writeEntry("UseCommentFile", useCommentFile()); group = m_config->group("Thumbnails"); group.writeEntry("ThumbnailSize", getThumbnailSize()); group.writeEntry("ColorDepth", getColorDepth()); group.writeEntry("ColorDepthSet", colorDepthSet()); group.writeEntry("ImageFormat", getImageFormat()); group.sync(); } KIGPDialog::~KIGPDialog() { delete m_config; } void KIGPDialog::imageUrlChanged(const QString &url) { buttonBox()->button(QDialogButtonBox::Ok)->setEnabled(!url.isEmpty()); } bool KIGPDialog::printImageName() const { return m_imageName->isChecked(); } bool KIGPDialog::printImageSize() const { return m_imageSize->isChecked(); } bool KIGPDialog::printImageProperty() const { return m_imageProperty->isChecked(); } bool KIGPDialog::recurseSubDirectories() const { return m_recurseSubDir->isChecked(); } int KIGPDialog::recursionLevel() const { return m_recursionLevel->value(); } bool KIGPDialog::copyOriginalFiles() const { return m_copyOriginalFiles->isChecked(); } bool KIGPDialog::useCommentFile() const { return m_useCommentFile->isChecked(); } int KIGPDialog::getImagesPerRow() const { return m_imagesPerRow->value(); } int KIGPDialog::getThumbnailSize() const { return m_thumbnailSize->value(); } int KIGPDialog::getColorDepth() const { return m_colorDepth->currentText().toInt(); } bool KIGPDialog::colorDepthSet() const { return m_colorDepthSet->isChecked(); } const QString KIGPDialog::getTitle() const { return m_title->text(); } const QUrl KIGPDialog::getImageUrl() const { return m_imageNameReq->url(); } const QString KIGPDialog::getCommentFile() const { return m_commentFileReq->url().toLocalFile(); } const QString KIGPDialog::getFontName() const { return m_fontName->currentText(); } const QString KIGPDialog::getFontSize() const { return m_fontSize->text(); } const QColor KIGPDialog::getBackgroundColor() const { return m_backgroundColor->color(); } const QColor KIGPDialog::getForegroundColor() const { return m_foregroundColor->color(); } const QString KIGPDialog::getImageFormat() const { return m_imageFormat->currentText(); } diff --git a/src/konqhistorymodel.cpp b/src/konqhistorymodel.cpp index 4332552f8..149653230 100644 --- a/src/konqhistorymodel.cpp +++ b/src/konqhistorymodel.cpp @@ -1,471 +1,471 @@ /* This file is part of the KDE project Copyright 2009 Pino Toscano This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "konqhistorymodel.h" #include "konqhistory.h" #include "konq_historyprovider.h" #include #include #include #include #include #include #include namespace KHM { struct Entry { enum Type { History, Group, Root }; Entry(Type _type) : type(_type) {} virtual ~Entry() {} virtual QVariant data(int /*role*/, int /*column*/) const { return QVariant(); } const Type type; }; struct HistoryEntry : public Entry { HistoryEntry(const KonqHistoryEntry &_entry, GroupEntry *_parent); QVariant data(int role, int column) const Q_DECL_OVERRIDE; void update(const KonqHistoryEntry &entry); KonqHistoryEntry entry; GroupEntry *parent; QIcon icon; }; struct GroupEntry : public Entry { GroupEntry(const QUrl &_url, const QString &_key); ~GroupEntry() { qDeleteAll(entries); } QVariant data(int role, int column) const Q_DECL_OVERRIDE; HistoryEntry *findChild(const KonqHistoryEntry &entry, int *index = 0) const; QList urls() const; QList entries; QUrl url; QString key; QIcon icon; bool hasFavIcon : 1; }; struct RootEntry : public Entry { RootEntry() : Entry(Root) {} ~RootEntry() { qDeleteAll(groups); } QList groups; QHash groupsByName; }; HistoryEntry::HistoryEntry(const KonqHistoryEntry &_entry, GroupEntry *_parent) : Entry(History), entry(_entry), parent(_parent) { parent->entries.append(this); update(entry); } QVariant HistoryEntry::data(int role, int /*column*/) const { switch (role) { case Qt::DisplayRole: { QString title = entry.title; if (title.trimmed().isEmpty() || title == entry.url.url()) { QString path(entry.url.path()); if (path.isEmpty()) { path += '/'; } title = path; } return title; } case Qt::DecorationRole: return icon; case Qt::ToolTipRole: return entry.url.url(); case KonqHistory::TypeRole: return int(KonqHistory::HistoryType); case KonqHistory::DetailedToolTipRole: return i18n("
%1

Last visited: %2
" "First visited: %3
Number of times visited: %4
", entry.url.toDisplayString().toHtmlEscaped(), QLocale().toString(entry.lastVisited), QLocale().toString(entry.firstVisited), entry.numberOfTimesVisited); case KonqHistory::LastVisitedRole: return entry.lastVisited; case KonqHistory::UrlRole: return entry.url; } return QVariant(); } void HistoryEntry::update(const KonqHistoryEntry &_entry) { entry = _entry; const QString path = entry.url.path(); if (parent->hasFavIcon && (path.isNull() || path == QLatin1String("/"))) { icon = parent->icon; } else { - icon = QIcon(KProtocolInfo::icon(entry.url.scheme())); + icon = QIcon::fromTheme(KProtocolInfo::icon(entry.url.scheme())); } } GroupEntry::GroupEntry(const QUrl &_url, const QString &_key) : Entry(Group), url(_url), key(_key), hasFavIcon(false) { const QString iconPath = KIO::favIconForUrl(url); if (iconPath.isEmpty()) { icon = QIcon::fromTheme(QStringLiteral("folder")); } else { icon = QIcon(iconPath); hasFavIcon = true; } } QVariant GroupEntry::data(int role, int /*column*/) const { switch (role) { case Qt::DisplayRole: return key; case Qt::DecorationRole: return icon; case KonqHistory::TypeRole: return int(KonqHistory::GroupType); case KonqHistory::LastVisitedRole: { if (entries.isEmpty()) { return QDateTime(); } QDateTime dt = entries.first()->entry.lastVisited; Q_FOREACH (HistoryEntry *e, entries) { if (e->entry.lastVisited > dt) { dt = e->entry.lastVisited; } } return dt; } } return QVariant(); } HistoryEntry *GroupEntry::findChild(const KonqHistoryEntry &entry, int *index) const { HistoryEntry *item = 0; QList::const_iterator it = entries.constBegin(), itEnd = entries.constEnd(); int i = 0; for (; it != itEnd; ++it, ++i) { if ((*it)->entry.url == entry.url) { item = *it; break; } } if (index) { *index = item ? i : -1; } return item; } QList GroupEntry::urls() const { QList list; Q_FOREACH (HistoryEntry *e, entries) { list.append(e->entry.url); } return list; } } static QString groupForUrl(const QUrl &url) { if (url.isLocalFile()) { static const QString &local = i18n("Local"); return local; } static const QString &misc = i18n("Miscellaneous"); return url.host().isEmpty() ? misc : url.host(); } KonqHistoryModel::KonqHistoryModel(QObject *parent) : QAbstractItemModel(parent), m_root(new KHM::RootEntry()) { KonqHistoryProvider *provider = KonqHistoryProvider::self(); connect(provider, SIGNAL(cleared()), this, SLOT(clear())); connect(provider, SIGNAL(entryAdded(KonqHistoryEntry)), this, SLOT(slotEntryAdded(KonqHistoryEntry))); connect(provider, SIGNAL(entryRemoved(KonqHistoryEntry)), this, SLOT(slotEntryRemoved(KonqHistoryEntry))); KonqHistoryList entries(provider->entries()); KonqHistoryList::const_iterator it = entries.constBegin(); const KonqHistoryList::const_iterator end = entries.constEnd(); for (; it != end; ++it) { KHM::GroupEntry *group = getGroupItem((*it).url, DontEmitSignals); KHM::HistoryEntry *item = new KHM::HistoryEntry((*it), group); Q_UNUSED(item); } } KonqHistoryModel::~KonqHistoryModel() { delete m_root; } int KonqHistoryModel::columnCount(const QModelIndex &parent) const { KHM::Entry *entry = entryFromIndex(parent, true); switch (entry->type) { case KHM::Entry::History: return 0; case KHM::Entry::Group: case KHM::Entry::Root: return 1; } return 0; } QVariant KonqHistoryModel::data(const QModelIndex &index, int role) const { KHM::Entry *entry = entryFromIndex(index); if (!entry) { return QVariant(); } return entry->data(role, index.column()); } QModelIndex KonqHistoryModel::index(int row, int column, const QModelIndex &parent) const { if (row < 0 || column != 0) { return QModelIndex(); } KHM::Entry *entry = entryFromIndex(parent, true); switch (entry->type) { case KHM::Entry::History: return QModelIndex(); case KHM::Entry::Group: { const KHM::GroupEntry *ge = static_cast(entry); if (row >= ge->entries.count()) { return QModelIndex(); } return createIndex(row, column, ge->entries.at(row)); } case KHM::Entry::Root: { const KHM::RootEntry *re = static_cast(entry); if (row >= re->groups.count()) { return QModelIndex(); } return createIndex(row, column, re->groups.at(row)); } } return QModelIndex(); } QModelIndex KonqHistoryModel::parent(const QModelIndex &index) const { KHM::Entry *entry = entryFromIndex(index); if (!entry) { return QModelIndex(); } switch (entry->type) { case KHM::Entry::History: return indexFor(static_cast(entry)->parent); case KHM::Entry::Group: case KHM::Entry::Root: return QModelIndex(); } return QModelIndex(); } int KonqHistoryModel::rowCount(const QModelIndex &parent) const { KHM::Entry *entry = entryFromIndex(parent, true); switch (entry->type) { case KHM::Entry::History: return 0; case KHM::Entry::Group: return static_cast(entry)->entries.count(); case KHM::Entry::Root: return static_cast(entry)->groups.count(); } return 0; } void KonqHistoryModel::deleteItem(const QModelIndex &index) { KHM::Entry *entry = entryFromIndex(index); if (!entry) { return; } KonqHistoryProvider *provider = KonqHistoryProvider::self(); switch (entry->type) { case KHM::Entry::History: provider->emitRemoveFromHistory(static_cast(entry)->entry.url); break; case KHM::Entry::Group: provider->emitRemoveListFromHistory(static_cast(entry)->urls()); break; case KHM::Entry::Root: break; } } void KonqHistoryModel::clear() { if (m_root->groups.isEmpty()) { return; } delete m_root; m_root = new KHM::RootEntry(); reset(); } void KonqHistoryModel::slotEntryAdded(const KonqHistoryEntry &entry) { KHM::GroupEntry *group = getGroupItem(entry.url, EmitSignals); KHM::HistoryEntry *item = group->findChild(entry); if (!item) { beginInsertRows(indexFor(group), group->entries.count(), group->entries.count()); item = new KHM::HistoryEntry(entry, group); endInsertRows(); } else { // Do not update existing entries, otherwise items jump around when clicking on them (#61450) if (item->entry.lastVisited.isValid()) { return; } item->update(entry); const QModelIndex index = indexFor(item); emit dataChanged(index, index); } // update the parent item, so the sorting by date is updated accordingly const QModelIndex groupIndex = indexFor(group); emit dataChanged(groupIndex, groupIndex); } void KonqHistoryModel::slotEntryRemoved(const KonqHistoryEntry &entry) { const QString groupKey = groupForUrl(entry.url); KHM::GroupEntry *group = m_root->groupsByName.value(groupKey); if (!group) { return; } int index = 0; KHM::HistoryEntry *item = group->findChild(entry, &index); if (index == -1) { return; } if (group->entries.count() > 1) { beginRemoveRows(indexFor(group), index, index); group->entries.removeAt(index); delete item; endRemoveRows(); } else { index = m_root->groups.indexOf(group); if (index == -1) { return; } beginRemoveRows(QModelIndex(), index, index); m_root->groupsByName.remove(groupKey); m_root->groups.removeAt(index); delete group; endRemoveRows(); } } KHM::Entry *KonqHistoryModel::entryFromIndex(const QModelIndex &index, bool returnRootIfNull) const { if (index.isValid()) { return reinterpret_cast(index.internalPointer()); } return returnRootIfNull ? m_root : 0; } KHM::GroupEntry *KonqHistoryModel::getGroupItem(const QUrl &url, SignalEmission se) { const QString &groupKey = groupForUrl(url); KHM::GroupEntry *group = m_root->groupsByName.value(groupKey); if (!group) { if (se == EmitSignals) { beginInsertRows(QModelIndex(), m_root->groups.count(), m_root->groups.count()); } group = new KHM::GroupEntry(url, groupKey); m_root->groups.append(group); m_root->groupsByName.insert(groupKey, group); if (se == EmitSignals) { endInsertRows(); } } return group; } QModelIndex KonqHistoryModel::indexFor(KHM::HistoryEntry *entry) const { const int row = entry->parent->entries.indexOf(entry); if (row < 0) { return QModelIndex(); } return createIndex(row, 0, entry); } QModelIndex KonqHistoryModel::indexFor(KHM::GroupEntry *entry) const { const int row = m_root->groups.indexOf(entry); if (row < 0) { return QModelIndex(); } return createIndex(row, 0, entry); }