File indexing completed on 2025-03-09 04:54:33

0001 /*  -*- c++ -*-
0002     interfaces/urlhandler.h
0003 
0004     This file is part of KMail, the KDE mail client.
0005     SPDX-FileCopyrightText: 2003 Marc Mutz <mutz@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <QUrl>
0013 
0014 class QString;
0015 class QPoint;
0016 
0017 namespace MessasgeViewer
0018 {
0019 class ViewerPrivate;
0020 }
0021 
0022 namespace MimeTreeParser
0023 {
0024 /**
0025  * @short An interface to reader link handlers
0026  * @author Marc Mutz <mutz@kde.org>
0027  *
0028  */
0029 class URLHandler
0030 {
0031 public:
0032     virtual ~URLHandler() = default;
0033 
0034     /**
0035      * Called when LMB-clicking on a link in the reader. Should start
0036      * processing equivalent to "opening" the link.
0037      *
0038      * @return true if the click was handled by this URLHandler,
0039      *         false otherwise.
0040      */
0041     virtual bool handleClick(const QUrl &url, MessageViewer::ViewerPrivate *w) const = 0;
0042 
0043     /**
0044      * Called when RMB-clicking on a link in the reader. Should show
0045      * a context menu at the specified point with the specified
0046      * widget as parent.
0047      *
0048      * @return true if the right-click was handled by this
0049      * URLHandler, false otherwise.
0050      */
0051     virtual bool handleContextMenuRequest(const QUrl &url, const QPoint &p, MessageViewer::ViewerPrivate *w) const = 0;
0052 
0053     /**
0054      * Called when hovering over a link.
0055      *
0056      * @return a string to be shown in the status bar while hovering
0057      * over this link.
0058      */
0059     [[nodiscard]] virtual QString statusBarMessage(const QUrl &url, MessageViewer::ViewerPrivate *w) const = 0;
0060 
0061     /**
0062      * Called when shift-clicking the link in the reader.
0063      * @return true if the click was handled by this URLHandler, false otherwise
0064      */
0065     [[nodiscard]] virtual bool handleShiftClick(const QUrl &url, MessageViewer::ViewerPrivate *window) const
0066     {
0067         Q_UNUSED(url)
0068         Q_UNUSED(window)
0069         return false;
0070     }
0071 
0072     /**
0073      * @return should return true if this URLHandler will handle the drag
0074      */
0075     [[nodiscard]] virtual bool willHandleDrag(const QUrl &url, MessageViewer::ViewerPrivate *window) const
0076     {
0077         Q_UNUSED(url)
0078         Q_UNUSED(window)
0079         return false;
0080     }
0081 
0082     /**
0083      * Called when starting a drag with the given URL.
0084      * If the drag is handled, you should create a drag object.
0085      * @return true if the click was handled by this URLHandler, false otherwise
0086      */
0087     [[nodiscard]] virtual bool handleDrag(const QUrl &url, MessageViewer::ViewerPrivate *window) const
0088     {
0089         Q_UNUSED(url)
0090         Q_UNUSED(window)
0091         return false;
0092     }
0093 };
0094 }