File indexing completed on 2024-04-14 03:50:34

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org>
0004     SPDX-FileCopyrightText: 2006 Daniel Teske <teske@squorn.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "kbookmarkaction.h"
0010 #include "kbookmarkowner.h"
0011 
0012 #include <QDesktopServices>
0013 #include <QGuiApplication>
0014 
0015 KBookmarkAction::KBookmarkAction(const KBookmark &bk, KBookmarkOwner *owner, QObject *parent)
0016     : QAction(bk.text().replace(QLatin1Char('&'), QLatin1String("&&")), parent)
0017     , KBookmarkActionInterface(bk)
0018     , m_pOwner(owner)
0019 {
0020     setIcon(QIcon::fromTheme(bookmark().icon()));
0021     setIconText(text());
0022     setToolTip(bookmark().url().toDisplayString(QUrl::PreferLocalFile));
0023     setStatusTip(toolTip());
0024     setWhatsThis(toolTip());
0025     const QString description = bk.description();
0026     if (!description.isEmpty()) {
0027         setToolTip(description);
0028     }
0029     connect(this, &QAction::triggered, this, &KBookmarkAction::slotTriggered);
0030 }
0031 
0032 KBookmarkAction::~KBookmarkAction()
0033 {
0034 }
0035 
0036 void KBookmarkAction::slotTriggered()
0037 {
0038     slotSelected(QGuiApplication::mouseButtons(), QGuiApplication::keyboardModifiers());
0039 }
0040 
0041 void KBookmarkAction::slotSelected(Qt::MouseButtons mb, Qt::KeyboardModifiers km)
0042 {
0043     if (!m_pOwner) {
0044         QDesktopServices::openUrl(bookmark().url());
0045     } else {
0046         m_pOwner->openBookmark(bookmark(), mb, km);
0047     }
0048 }
0049 
0050 #include "moc_kbookmarkaction.cpp"