File indexing completed on 2024-04-21 04:55:27

0001 /*
0002     This file is part of Choqok, the KDE micro-blogging client
0003 
0004     SPDX-FileCopyrightText: 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0007 */
0008 
0009 #ifndef CHOQOKSHORTENMANAGER_H
0010 #define CHOQOKSHORTENMANAGER_H
0011 
0012 #include <QObject>
0013 #include <QUrl>
0014 
0015 #include "shortener.h"
0016 
0017 namespace Choqok
0018 {
0019 namespace UI
0020 {
0021 class PostWidget;
0022 }
0023 
0024 class ShortenManagerPrivate;
0025 /**
0026 Singleton class to manage URL shortening
0027 @author Mehrdad Momeny \<mehrdad.momeny@gmail.com\>
0028 */
0029 class CHOQOK_EXPORT ShortenManager: public QObject
0030 {
0031     friend class ShortenManagerPrivate;
0032     Q_OBJECT
0033 public:
0034     static ShortenManager *self();
0035     /**
0036         If there is any shorten plugin loaded/enabled return Shortened URL
0037         else return @p url
0038     */
0039     QString shortenUrl(const QString &url);
0040 
0041     /**
0042         Parse and find Urls and then shorten them. and return result text
0043     */
0044     QString parseText(const QString &text);
0045 
0046     /**
0047         Reload configurations.
0048         Should call after change on shortening plugin!
0049     */
0050     void reloadConfig();
0051 
0052     void emitNewUnshortenedUrl(Choqok::UI::PostWidget *widget, const QUrl &fromUrl, const QUrl &toUrl);
0053 
0054 Q_SIGNALS:
0055     void newUnshortenedUrl(Choqok::UI::PostWidget *widget, const QUrl &fromUrl, const QUrl &toUrl);
0056 
0057 private:
0058     ShortenManager(QObject *parent = nullptr);
0059     ~ShortenManager();
0060 };
0061 
0062 }
0063 #endif