File indexing completed on 2024-05-19 05:19:20

0001 /*
0002     This file is part of KJots.
0003 
0004     SPDX-FileCopyrightText: 1997 Christoph Neerfeld <Christoph.Neerfeld@home.ivm.de>
0005                   2002, 2003 Aaron J. Seigo <aseigo@kde.org>
0006                   2003 Stanislav Kljuhhin <crz@hot.ee>
0007                   2005-2006 Jaison Lee <lee.jaison@gmail.com>
0008                   2020 Igor Poboiko <igor.poboiko@gmail.com>
0009 
0010     SPDX-License-Identifier: GPL-2.0-or-later
0011 */
0012 
0013 #include "kjotsbookmarks.h"
0014 #include "kjotsmodel.h"
0015 
0016 #include <QItemSelectionModel>
0017 
0018 using namespace Akonadi;
0019 
0020 KJotsBookmarks::KJotsBookmarks(QItemSelectionModel *model, QObject *parent)
0021     : QObject(parent)
0022     , m_model(model)
0023 {
0024 }
0025 
0026 void KJotsBookmarks::openBookmark(const KBookmark &bm, Qt::MouseButtons /*mb*/, Qt::KeyboardModifiers /*km*/)
0027 {
0028     if (bm.url().scheme() != QLatin1String("akonadi")) {
0029         return;
0030     }
0031     Q_EMIT openLink(bm.url());
0032 }
0033 
0034 QString KJotsBookmarks::currentIcon() const
0035 {
0036     const QModelIndexList rows = m_model->selectedRows();
0037     if (rows.size() != 1) {
0038         return QString();
0039     }
0040     const QModelIndex idx = rows.first();
0041     const auto collection = idx.data(EntityTreeModel::CollectionRole).value<Collection>();
0042     if (collection.isValid()) {
0043         return QStringLiteral("x-office-address-book");
0044     }
0045     const auto item = idx.data(EntityTreeModel::ItemRole).value<Item>();
0046     if (item.isValid()) {
0047         return QStringLiteral("x-office-document");
0048     }
0049     return QString();
0050 }
0051 
0052 QUrl KJotsBookmarks::currentUrl() const
0053 {
0054     const QModelIndexList rows = m_model->selectedRows();
0055     if (rows.size() != 1) {
0056         return QUrl();
0057     } else {
0058         return rows.first().data(KJotsModel::EntityUrlRole).toUrl();
0059     }
0060 }
0061 
0062 QString KJotsBookmarks::currentTitle() const
0063 {
0064     const QModelIndexList rows = m_model->selectedRows();
0065     if (rows.size() != 1) {
0066         return QString();
0067     } else {
0068         return KJotsModel::itemPath(rows.first(), QStringLiteral(": "));
0069     }
0070 }
0071 
0072 
0073 #include "moc_kjotsbookmarks.cpp"