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 #include "twitterapisearch.h"
0010 
0011 #include "accountmanager.h"
0012 
0013 #include <stdio.h>
0014 
0015 class TwitterApiSearch::Private
0016 {
0017 public:
0018     Private()
0019     {
0020         monthes[QLatin1String("Jan")] = 1;
0021         monthes[QLatin1String("Feb")] = 2;
0022         monthes[QLatin1String("Mar")] = 3;
0023         monthes[QLatin1String("Apr")] = 4;
0024         monthes[QLatin1String("May")] = 5;
0025         monthes[QLatin1String("Jun")] = 6;
0026         monthes[QLatin1String("Jul")] = 7;
0027         monthes[QLatin1String("Aug")] = 8;
0028         monthes[QLatin1String("Sep")] = 9;
0029         monthes[QLatin1String("Oct")] = 10;
0030         monthes[QLatin1String("Nov")] = 11;
0031         monthes[QLatin1String("Dec")] = 12;
0032     }
0033     QMap<QString, int> monthes;
0034 };
0035 
0036 TwitterApiSearch::TwitterApiSearch(QObject *parent)
0037     : QObject(parent), d(new Private)
0038 {
0039 
0040 }
0041 
0042 TwitterApiSearch::~TwitterApiSearch()
0043 {
0044     delete d;
0045 }
0046 
0047 QMap< int, QPair<QString, bool> > &TwitterApiSearch::getSearchTypes()
0048 {
0049     return mSearchTypes;
0050 }
0051 
0052 void TwitterApiSearch::requestSearchResults(Choqok::Account *theAccount, const QString &query,
0053         int option, const QString &sinceStatusId,
0054         uint count, uint page)
0055 {
0056     bool isB = getSearchTypes()[option].second;
0057     SearchInfo info(theAccount, query, option, isB);
0058     requestSearchResults(info, sinceStatusId, count, page);
0059 }
0060 
0061 QDateTime TwitterApiSearch::dateFromString(const QString &date)
0062 {
0063     char s[10];
0064     int year, day, hours, minutes, seconds, tz;
0065     sscanf(qPrintable(date), "%*s %s %d %d:%d:%d %d %d", s, &day, &hours, &minutes, &seconds, &tz, &year);
0066     int month = d->monthes[QLatin1String(s)];
0067     QDateTime recognized(QDate(year, month, day), QTime(hours, minutes, seconds));
0068     if (tz == 0) { //tz is the timezone, in Twitter it's always UTC(0) in Identica it's local +/-NUMBER
0069         recognized.setTimeSpec(Qt::UTC);
0070     }
0071     return recognized.toLocalTime();
0072 }
0073 
0074 SearchInfo::SearchInfo()
0075 {
0076 
0077 }
0078 
0079 SearchInfo::SearchInfo(Choqok::Account *theAccount, const QString &queryStr, int optionCode, bool IsBrowsable)
0080     : account(theAccount), option(optionCode), query(queryStr), isBrowsable(IsBrowsable)
0081 {
0082 
0083 }
0084 
0085 bool SearchInfo::fromString(const QString &str)
0086 {
0087     QStringList lis = str.split(QLatin1String(",,,"));
0088     if (lis.count() != 4) {
0089         return false;
0090     }
0091     account = Choqok::AccountManager::self()->findAccount(lis[0]);
0092     option = lis[1].toInt();
0093     query = lis[2];
0094     isBrowsable = (bool)lis[3].toInt();
0095     return true;
0096 }
0097 
0098 QString SearchInfo::toString()
0099 {
0100     return account->alias() + QLatin1String(",,,") + QString::number(option) + QLatin1String(",,,") + query + QLatin1String(",,,") + QString::number(isBrowsable);
0101 }
0102 
0103 #include "moc_twitterapisearch.cpp"