Пример #1
0
NS_IMETHODIMP
SmsRequest::NotifyThreadList(const jsval& aThreadList, JSContext* aCx)
{
  MOZ_ASSERT(aThreadList.isObject());

  if (mParent) {
    JSObject* array = const_cast<JSObject*>(&aThreadList.toObject());

    uint32_t length;
    bool ok = JS_GetArrayLength(aCx, array, &length);
    NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);

    ReplyThreadList reply;
    InfallibleTArray<ThreadListItem>& ipcItems = reply.items();

    if (length) {
      ipcItems.SetCapacity(length);

      for (uint32_t i = 0; i < length; i++) {
        jsval arrayEntry;
        ok = JS_GetElement(aCx, array, i, &arrayEntry);
        NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);

        MOZ_ASSERT(arrayEntry.isObject());

        mozilla::idl::SmsThreadListItem item;
        nsresult rv = item.Init(aCx, &arrayEntry);
        NS_ENSURE_SUCCESS(rv, rv);

        ThreadListItem* ipcItem = ipcItems.AppendElement();
        ipcItem->senderOrReceiver() = item.senderOrReceiver;
        ipcItem->timestamp() = item.timestamp;
        ipcItem->body() = item.body;
        ipcItem->unreadCount() = item.unreadCount;
      }
    }

    return SendMessageReply(reply);
  }

  return NotifySuccess(aThreadList);
}
Пример #2
0
void SearchController::parseThreadListing(const QString &caption, const QString &urlFirstPage, bool read, const QString &threadListing) {
	ThreadListItem *item = new ThreadListItem();
	QRegExp andAmp("&amp;");
	QRegExp nbsp("&nbsp;");


	{
		bool inf = false;
		bool slash = false;
		int idx = 0;
		for(int i = 0 ; i < caption.length() ; ++i) {
			if(caption[i] == '<') {
				inf = true;
				continue;
			}
			if(inf && caption[i] == '/') {
				slash = true;
				continue;
			} else {
				inf = false;
			}

			if(slash && caption[i] == 'a') {
				idx = i-2;
				break;
			}
		}

		if(idx != 0)
			item->setTitle(caption.mid(0,idx));
		else
			item->setTitle(caption);
	}

	item->setRead(read);
	item->setUrlFirstPage(urlFirstPage);

	QRegExp lastPostReadRegexp("</td><td class=\"sujetCase5\"><a href=\"(.*#t[0-9bas]+)\"><img src=");
	lastPostReadRegexp.setCaseSensitivity(Qt::CaseSensitive);
	lastPostReadRegexp.setMinimal(true);

	if(lastPostReadRegexp.indexIn(threadListing, 0) != -1) {
		QString s = lastPostReadRegexp.cap(1);
		s.replace(andAmp, "&");
		item->setUrlLastPostRead(s);
	}

	QRegExp pageNumberRegExp("<td class=\"sujetCase4\"><a href=\"(.*)\" class=\"cCatTopic\">([0-9]+)</a></td><td class=\"sujetCase5\">");
	pageNumberRegExp.setCaseSensitivity(Qt::CaseSensitive);
	pageNumberRegExp.setMinimal(true);

	if(pageNumberRegExp.indexIn(threadListing, 0) != -1) {
		item->setPages(pageNumberRegExp.cap(2));

		if(item->getUrlLastPostRead() == "") {
			QString s = pageNumberRegExp.cap(1);
			s.replace(andAmp, "&");
			item->setUrlLastPostRead(s+"#bas");
		}
	} else {
		item->setPages("1");
	}

	QRegExp lastPageRegExp("<td class=\"sujetCase9 cBackCouleurTab[0-9] \"><a href=\"(.*)\" class=\"Tableau\">(.*)<br /><b>(.*)</b>");
	lastPageRegExp.setCaseSensitivity(Qt::CaseSensitive);
	lastPageRegExp.setMinimal(true);

	if(lastPageRegExp.indexIn(threadListing, 0) != -1) {
		QString s = lastPageRegExp.cap(2);
		s.replace(nbsp, " ");
		item->setTimestamp(s);

		s = lastPageRegExp.cap(1);
		s.replace(andAmp, "&");
		item->setUrlLastPage(s);

		item->setLastAuthor(lastPageRegExp.cap(3));
	}

	QRegExp flagTypeRegexp("<img src=\"http://forum-images.hardware.fr/themes_static/images_forum/1/favoris.gif\"");
	if(flagTypeRegexp.indexIn(threadListing, 0) != -1)
		item->setFlagType(Flag::FAVORITE);

	flagTypeRegexp = QRegExp("<img src=\"http://forum-images.hardware.fr/themes_static/images_forum/1/flag([0-1]).gif\"");
	if(flagTypeRegexp.indexIn(threadListing, 0) != -1) {
		switch(flagTypeRegexp.cap(1).toInt()) {
			case 0:
				item->setFlagType(Flag::READ);
				break;

			case 1:
				item->setFlagType(Flag::PARTICIPATE);
				break;
		}
	}


	if(!item->getLastAuthor().isEmpty())
		m_Datas->append(item);
	else
		item->deleteLater();

}
void HeadlessApplication::parseThreadListing(const QString &category, const QString &caption, const QString &urlFirstPage, const QString &threadListing, const QString &today, int groupKey) {
    //                         + ".*<td class=\"sujetCase4\"><a href=\"(.+)\" class=\"cCatTopic\">"     // link to first post
    //                         + "([0-9]+)</a></td>"                                                    // overall number of pages
    //                         + ".*<td class=\"sujetCase5\"><a href=\"(.+)\"><img src"                 // index to last read post
    //                         + ".*p.([0-9]+)"                                     // last page read number
    //                         + ".*<td class=\"sujetCase9.*class=\"Tableau\">(.+)"                     // time stamp
    //                         + "<br /><b>(.+)</b></a></td><td class=\"sujetCase10\"><input type");    // last contributor

    QRegExp andAmp("&amp;");

    if(caption.isEmpty())
        return;

    ThreadListItem *item = new ThreadListItem();
    item->setCategory(category);
    item->setTitle(caption);
    item->setUrlFirstPage(urlFirstPage);

    QRegExp firstPostAndPage(QString("<td class=\"sujetCase4\"><a href=\".+\" class=\"cCatTopic\">")        // link to first post
                                 + "([0-9]+)</a></td>");                                                    // overall number of pages

    firstPostAndPage.setCaseSensitivity(Qt::CaseSensitive);
    firstPostAndPage.setMinimal(true);

    if(firstPostAndPage.indexIn(threadListing, 0) != -1) {
        item->setPages(firstPostAndPage.cap(1));
    }



    QRegExp lastReadAndPage(QString("<td class=\"sujetCase5\"><a href=\"(.+)\"><img src.*p.([0-9]+).*\" alt=\"flag\"")); // index to last read post + last page read number
    lastReadAndPage.setCaseSensitivity(Qt::CaseSensitive);
    lastReadAndPage.setMinimal(true);

    if(lastReadAndPage.indexIn(threadListing, 0) != -1) {
        QString s = lastReadAndPage.cap(1); s.replace(andAmp, "&");
        item->setUrlLastPostRead(s);

        item->setPages(lastReadAndPage.cap(2)  + "/" + item->getPages());
    }


    QRegExp lastContribution("<td class=\"sujetCase9 cBackCouleurTab[0-9] \"><a href=\"(.+)\" class=\"Tableau\">(.+)<br /><b>(.+)</b></a></td><td class=\"sujetCase10\"><input type"); // timestamp + last contributor
    lastContribution.setCaseSensitivity(Qt::CaseSensitive);
    lastContribution.setMinimal(true);

    if(lastContribution.indexIn(threadListing, 0) != -1) {
        QString s = lastContribution.cap(2);
        item->setDetailedTimestamp(s);

        item->setLastAuthor(lastContribution.cap(3));

        s = lastContribution.cap(1);
        s.replace(andAmp, "&");
        item->setUrlLastPage(s);

    }

    QRegExp postIDRegExp("post=([0-9]+)");
    QRegExp catIDRefExp("cat=([0-9]+)");
    if(postIDRegExp.indexIn(item->getUrlLastPage()) != -1 && catIDRefExp.indexIn(item->getUrlLastPage()) != -1) {
        item->setColor(getTagValue(postIDRegExp.cap(1) + "@" + catIDRefExp.cap(1)));
    } else {
        item->setColor(0);
    }

    //qDebug() << item->getTitle() << postIDRegExp.cap(1) + "@" + catIDRefExp.cap(1) << item->getColor();

    if(item->getColor() == 0) {
        item->deleteLater();
        return;
    }


    QSettings settings("Amonchakai", "HFR10");

    /*
    qDebug() << item->getColor()
             << settings.value("NotifGreen",false).toBool()
             << settings.value("NotifBlue",false).toBool()
             << settings.value("NotifOrange",false).toBool()
             << settings.value("NotifPink",false).toBool()
             << settings.value("NotifPurple",false).toBool();
     */
    switch(item->getColor()) {
        case 1:
            if(!settings.value("NotifGreen",false).toBool()){
                item->deleteLater();
                return;
            }
            break;

        case 2:
            if(!settings.value("NotifBlue",false).toBool()){
                item->deleteLater();
                return;
            }
            break;


        case 3:
            if(!settings.value("NotifOrange",false).toBool()){
                item->deleteLater();
                return;
            }
            break;

        case 4:
            if(!settings.value("NotifPink",false).toBool()){
                item->deleteLater();
                return;
            }
            break;

        case 5:
            if(!settings.value("NotifPurple",false).toBool()){
                item->deleteLater();
                return;
            }
            break;
    }



    QString SubjectNumber = postIDRegExp.cap(1) + QString::number(catIDRefExp.cap(1).toInt()*10000);
    qint64 timestamp = QDateTime::fromString(item->getDetailedTimestamp().mid(0,10) + " " + item->getDetailedTimestamp().mid(23), "dd-MM-yyyy hh:mm").toMSecsSinceEpoch();

    // -----------------------------------------------------------
    // add item into the Hub

    QVariantList hubItems = m_Hub->items();

    bool existing = false;
    QVariantMap itemMap;
    for(int i = 0 ; i < hubItems.length() ; ++i) {
        itemMap = hubItems.at(i).toMap();

        if(itemMap["syncId"].toString() == SubjectNumber) {
            existing = true;
            break;
        }
    }




    if(existing) {

        if(itemMap["timestamp"].toULongLong() == timestamp) {
            item->deleteLater();
            return;
        }

        itemMap["description"] = item->getLastAuthor();
        itemMap["timestamp"] = timestamp;
        itemMap["readCount"] = item->isRead();

        if(!item->getUrlLastPostRead().isEmpty())
            itemMap["url"] = item->getUrlLastPostRead();
        else {
            if(!item->getUrlLastPage().isEmpty())
                itemMap["url"] = item->getUrlFirstPage();
            else {
                itemMap["url"] = item->getUrlFirstPage();
            }
        }

        qint64 itemId;
        if (itemMap["sourceId"].toString().length() > 0) {
            itemId = itemMap["sourceId"].toLongLong();
        } else if (itemMap["messageid"].toString().length() > 0) {
            itemId = itemMap["messageid"].toLongLong();
        }

        qDebug() << "New favorite. update post --> notif.";
        m_Hub->updateHubItem(m_Hub->categoryId(), itemId, itemMap, true);

    } else {

        QVariantMap entry;
        if(!item->getUrlLastPostRead().isEmpty())
            entry["url"] = item->getUrlLastPostRead();
        else {
            if(!item->getUrlFirstPage().isEmpty())
                entry["url"] = item->getUrlFirstPage();
            else {
                item->deleteLater();
                return;
            }
        }

        qDebug() << "New favorite. add new entry --> notif.";
        m_Hub->addHubItem(m_Hub->categoryId(), entry, item->getTitle(), item->getLastAuthor(), timestamp, SubjectNumber, SubjectNumber, "",  true);

    }

    item->deleteLater();


}
Пример #4
0
void ListFavoriteController::parseThreadListing(const QString &category, const QString &caption, const QString &urlFirstPage, const QString &threadListing, const QString &today, int groupKey) {
	//						   + ".*<td class=\"sujetCase4\"><a href=\"(.+)\" class=\"cCatTopic\">"		// link to first post
	//						   + "([0-9]+)</a></td>"													// overall number of pages
	//						   + ".*<td class=\"sujetCase5\"><a href=\"(.+)\"><img src"					// index to last read post
	//						   + ".*p.([0-9]+)"										// last page read number
	//						   + ".*<td class=\"sujetCase9.*class=\"Tableau\">(.+)" 					// time stamp
	//						   + "<br /><b>(.+)</b></a></td><td class=\"sujetCase10\"><input type");	// last contributor

	QRegExp andAmp("&amp;");

	if(caption.isEmpty())
	    return;

	ThreadListItem *item = new ThreadListItem();
	item->setCategory(category);
	item->setTitle(caption);
	item->setUrlFirstPage(urlFirstPage);

	QRegExp firstPostAndPage(QString("<td class=\"sujetCase4\"><a href=\".+\" class=\"cCatTopic\">")		// link to first post
								 + "([0-9]+)</a></td>");													// overall number of pages

	firstPostAndPage.setCaseSensitivity(Qt::CaseSensitive);
	firstPostAndPage.setMinimal(true);

	if(firstPostAndPage.indexIn(threadListing, 0) != -1) {
		item->setPages(firstPostAndPage.cap(1));
	}



	QRegExp lastReadAndPage(QString("<td class=\"sujetCase5\"><a href=\"(.+)\"><img src.*p.([0-9]+).*\" alt=\"flag\"")); // index to last read post + last page read number
	lastReadAndPage.setCaseSensitivity(Qt::CaseSensitive);
	lastReadAndPage.setMinimal(true);

	if(lastReadAndPage.indexIn(threadListing, 0) != -1) {
		QString s = lastReadAndPage.cap(1); s.replace(andAmp, "&");
		item->setUrlLastPostRead(s);

		item->setPages(lastReadAndPage.cap(2)  + "/" + item->getPages());
	}


	QRegExp lastContribution("<td class=\"sujetCase9 cBackCouleurTab[0-9] \"><a href=\"(.+)\" class=\"Tableau\">(.+)<br /><b>(.+)</b></a></td><td class=\"sujetCase10\"><input type"); // timestamp + last contributor
	lastContribution.setCaseSensitivity(Qt::CaseSensitive);
	lastContribution.setMinimal(true);

	if(lastContribution.indexIn(threadListing, 0) != -1) {
		QString s = lastContribution.cap(2);
		if(s.mid(0,10).compare(today) == 0)
			item->setTimestamp(s.mid(23,5));
		else
			item->setTimestamp(s.mid(0,10));
		item->setDetailedTimestamp(s);


		item->setLastAuthor(lastContribution.cap(3));

		s = lastContribution.cap(1);
		s.replace(andAmp, "&");
		item->setUrlLastPage(s);

	}

	QRegExp postIDRegExp("post=([0-9]+)");
	QRegExp catIDRefExp("cat=([0-9]+)");
	if(postIDRegExp.indexIn(item->getUrlLastPage()) != -1 && catIDRefExp.indexIn(item->getUrlLastPage()) != -1) {
	    item->setColor(Settings::getTagValue(postIDRegExp.cap(1) + "@" + catIDRefExp.cap(1)));
	} else {
	    item->setColor(0);
	}

	item->setGroupKey(groupKey);

	m_Datas->append(item);

}