File indexing completed on 2024-04-28 04:55:38

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 TWITTERAPISEARCH_H
0010 #define TWITTERAPISEARCH_H
0011 
0012 #include <QDateTime>
0013 #include <QMap>
0014 #include <QPair>
0015 
0016 #include "twitterapihelper_export.h"
0017 
0018 #include "account.h"
0019 #include "choqoktypes.h"
0020 
0021 class TWITTERAPIHELPER_EXPORT SearchInfo
0022 {
0023 public:
0024     SearchInfo();
0025     SearchInfo(Choqok::Account *theAccount, const QString &queryStr,
0026                int optionCode, bool IsBrowsable = false);
0027     QString toString();
0028     bool fromString(const QString &str);
0029 
0030     Choqok::Account *account;
0031     /**
0032     option code
0033     */
0034     int option;
0035 
0036     /**
0037     Query text to search
0038     */
0039     QString query;
0040 
0041     /**
0042     Show if this search type is browsable, next and prev buttons should be displayed or not!
0043     */
0044     bool isBrowsable;
0045 };
0046 
0047 /**
0048     Base class for search feature.
0049     @author Stephen Henderson \<hendersonsk@gmail.com\>
0050     @author Mehrdad Momeny \<mehrdad.momeny@gmail.com\>
0051 */
0052 class TWITTERAPIHELPER_EXPORT TwitterApiSearch : public QObject
0053 {
0054     Q_OBJECT
0055 public:
0056     TwitterApiSearch(QObject *parent = nullptr);
0057     virtual ~TwitterApiSearch();
0058 
0059     /**
0060     The QString in the QPair is a human readable string describing what the type searches for.
0061     The boolean value determines whether or not the search type is traversable
0062     (if the forward and back buttons should be displayed).
0063     */
0064     QMap<int, QPair<QString, bool> > &getSearchTypes();
0065 
0066     /**
0067     Sub classes should implement this!
0068     Result will use on Timeline Widget tab name!
0069     Example:
0070         returned optionCode for option 1 is "#" and query was "Choqok", So tab name will be "#Choqok"
0071     */
0072     virtual QString optionCode(int option) = 0;
0073 
0074     QDateTime dateFromString(const QString &date);
0075 
0076 public Q_SLOTS:
0077     virtual void requestSearchResults(const SearchInfo &searchInfo,
0078                                       const QString &sinceStatusId = QString(),
0079                                       uint count = 0,
0080                                       uint page = 1) = 0;
0081     /**
0082     This is for convenience
0083     */
0084     void requestSearchResults(Choqok::Account *theAccount, const QString &query, int option,
0085                               const QString &sinceStatusId = QString(),
0086                               uint count = 0,
0087                               uint page = 1);
0088 
0089 Q_SIGNALS:
0090     void searchResultsReceived(const SearchInfo &searchInfo,
0091                                QList<Choqok::Post *> &postsList);
0092     void error(const QString &message);
0093 
0094 protected:
0095     /**
0096     The QString in the QPair is a human readable string describing what the type searches for.
0097     The boolean value determines whether or not the search type is traversable
0098     (if the forward and back buttons should be displayed).
0099     */
0100     QMap<int, QPair<QString, bool> > mSearchTypes;
0101 
0102 private:
0103     class Private;
0104     Private *const d;
0105 };
0106 
0107 #endif // TWITTERAPISEARCH_H