Пример #1
0
bool ExportCommon::download(ExportContext *ctx, QString url, QString to) {
	QString filePath = QDir::cleanPath(ctx->outputDir.absoluteFilePath(to));
	QFileInfo fi = QFileInfo(filePath);
	ctx->outputDir.mkpath(fi.dir().absolutePath());
	QFile file(filePath);
	if (file.exists())
		return true;
	if (file.open(QIODevice::WriteOnly)) {
		exportInfo("Downloading %s\n", url.toStdString().c_str());

		QUrl imageUrl(url);
		FileDownloader *m_pImgCtrl = new FileDownloader(imageUrl);

		QEventLoop loop;
		loop.connect(m_pImgCtrl, SIGNAL(downloaded()), &loop, SLOT(quit()));
		loop.exec();

		QByteArray data = m_pImgCtrl->downloadedData();

		delete m_pImgCtrl;

		if (data.length() > 0) {
			file.write(data);
			return true;
		} else
			exportError("Failed to download %s\n", url.toStdString().c_str());
	} else
		exportError("Can't open file %s\n", to.toStdString().c_str());
	return false;
}
Пример #2
0
void WebBridgeRS::downloadURL(QString url){
    QUrl imageUrl(url);
    FileDownloader* fileDownloader = new FileDownloader(imageUrl, this);

    connect(fileDownloader, SIGNAL(downloaded()), SLOT(onUrlDownloaded()));

}
Пример #3
0
QPixmap KWQQuizModel::imageQuestion()
{
    int row =  m_list.at(m_currentQuestion);
    int col = column(row);
    col == 0 ? col = 1 : col = 0;

    QUrl imageUrl(data(index(qAbs(row), col, QModelIndex()), KWQTableModel::ImageRole).toString());
    return QPixmap(imageUrl.toLocalFile());
}
Пример #4
0
void Launcher::run()
{
    if (m_url.isEmpty())
    {
        qWarning("Launcher::run - empty URL!");
        return;
    }
    if (m_url.scheme() != QLatin1String("file"))
    {
        qWarning("URL scheme %s not yet supported", qPrintable(m_url.scheme()));
        return;
    }
    QStringList queue;
    queue.append(m_url.path());
    QSet<QString> loopProtect;
    while (queue.size() > 0 && !m_stop)
    {
        QString path = queue.takeFirst();
        QFileInfo u(path);
        if (u.isSymLink())
            path = u.symLinkTarget();
        if (u.isDir())
        {
            if (!loopProtect.contains(path))
            {
                loopProtect.insert(path);
                QDir dir(path);
                QStringList entries = dir.entryList();
                QStringList::const_iterator it = entries.constBegin();
                for ( ; it != entries.constEnd(); ++it)
                {
                    // ignore hidden files, system directories
                    if ((*it).startsWith(QLatin1Char('.')))
                        continue;
                    queue.append(dir.absoluteFilePath(*it));
                }
            }
        }
        else
        {
            if (u.isFile() && u.isReadable())
            {
                // do no checking here for file extensions etc - just
                // forward any readable file found under the pictures
                // directory to the QImage loader, and let it sort out
                // if the thing can be loaded as an image.
                QUrl url2;
                url2.setScheme(QLatin1String("file"));
                url2.setPath(u.absoluteFilePath());
                m_manager->acquire();
                emit imageUrl(url2);
            }
        }
    }
}
void WebHitTestResultTest::shouldCopyWebHitTestResult()
{
    QPoint pos(5, 5);
    QUrl pageUrl(QStringLiteral("http://www.kde.org"));

    QVariantMap map;
    QString alternateText = QStringLiteral("FOO");
    map.insert(QStringLiteral("alternateText"), alternateText);
    bool contentEditable = true;
    map.insert(QStringLiteral("contentEditable"), contentEditable);
    bool contentSelected = true;
    map.insert(QStringLiteral("contentSelected"), contentSelected);
    QString linkTitle = QStringLiteral("GGGG");
    map.insert(QStringLiteral("linkTitle"), linkTitle);
    QUrl imageUrl(QStringLiteral("https://www.foo.net"));
    map.insert(QStringLiteral("imageUrl"), imageUrl);
    QUrl linkUrl(QStringLiteral("https://www.linux.org"));
    map.insert(QStringLiteral("linkUrl"), linkUrl);
    QUrl mediaUrl(QStringLiteral("https://www.media.org"));
    map.insert(QStringLiteral("mediaUrl"), mediaUrl);
    bool mediaPaused = true;
    map.insert(QStringLiteral("mediaPaused"), mediaPaused);
    bool mediaMuted = true;
    map.insert(QStringLiteral("mediaMuted"), mediaMuted);
    QString tagName = QStringLiteral("HHHHHH");
    map.insert(QStringLiteral("tagName"), tagName);
    QRect boundingRect(5, 7, 9, 11);
    QVariantList lstRect;
    lstRect << boundingRect.left() << boundingRect.top() << boundingRect.width() << boundingRect.height();
    map.insert(QStringLiteral("boundingRect"), lstRect);

    const WebEngineViewer::WebHitTestResult result1(pos, pageUrl, map);
    WebEngineViewer::WebHitTestResult result = result1;

    QCOMPARE(result.alternateText(), alternateText);
    QCOMPARE(result.boundingRect(), boundingRect);
    QCOMPARE(result.imageUrl(), imageUrl);
    QCOMPARE(result.isContentEditable(), contentEditable);
    QCOMPARE(result.isContentSelected(), contentSelected);
    QCOMPARE(result.isNull(), false);
    QCOMPARE(result.linkTitle(), linkTitle);
    QCOMPARE(result.linkUrl(), linkUrl);
    QCOMPARE(result.mediaUrl(), mediaUrl);
    QCOMPARE(result.mediaPaused(), mediaPaused);
    QCOMPARE(result.mediaMuted(), mediaMuted);
    QCOMPARE(result.pos(), pos);
    QCOMPARE(result.tagName(), tagName);
    QCOMPARE(result.pageUrl(), pageUrl);

}
Пример #6
0
void MainWindow::getImageUrl(){
    QString data = m_pImgCtrl->downloadedData();
    QRegExp rx("\\<img[^\\>]*src\\s*=\\s*\"([^\"]*)\"[^\\>]*\\>");

    QStringList list;
    int pos = 0;
    while ((pos = rx.indexIn(data, pos)) != -1){
        list << rx.cap(1);
        pos += rx.matchedLength();
    }
    int randomNo = rand() % list.length();
    ui->statusBar->showMessage("Fetching Image");
    QUrl imageUrl(list[randomNo]);
    imageDownloader = new FileDownloader(imageUrl,this);
    connect(imageDownloader,SIGNAL(downloaded()), SLOT(loadImage()));
}
Пример #7
0
int EntryModel::createItems(int offset, int limit)
{
    QList<DatabaseManager::Entry> list;

    Settings *s = Settings::instance();

    bool ascOrder = s->getShowOldestFirst();

    // Counting 'last' & 'daterow' rows
    if (offset > 0) {
        int dummyRowsCount = 0;
        int l = this->rowCount();
        //qDebug() << "this->rowCount():" << l;
        for (int i = 0; i < l; ++i) {
            EntryItem* item = static_cast<EntryItem*>(readRow(i));
            //qDebug() << item->id();
            if (item->id()=="last" || item->id()=="daterow") {
                ++dummyRowsCount;
            }
        }
        //qDebug() << "dummyRowsCount:" << dummyRowsCount << "orig offset:" << offset;
        if (offset > dummyRowsCount)
            offset = offset - dummyRowsCount;
    }

    int mode = s->getViewMode();
    switch (mode) {
    case 0:
        // View mode: Tabs->Feeds->Entries
        if (s->getShowOnlyUnread())
            list = _db->readEntriesUnreadByStream(_feedId,offset,limit,ascOrder);
        else
            list = _db->readEntriesByStream(_feedId,offset,limit,ascOrder);
        break;
    case 1:
        // View mode: Tabs->Entries
        if (s->getShowOnlyUnread())
            list = _db->readEntriesUnreadByTab(_feedId,offset,limit,ascOrder);
        else
            list = _db->readEntriesByTab(_feedId,offset,limit,ascOrder);
        break;
    case 2:
        // View mode: Feeds->Entries
        if (s->getShowOnlyUnread())
            list = _db->readEntriesUnreadByStream(_feedId,offset,limit,ascOrder);
        else
            list = _db->readEntriesByStream(_feedId,offset,limit,ascOrder);
        break;
    case 3:
        // View mode: Entries
        if (s->getShowOnlyUnread())
            list = _db->readEntriesUnreadByDashboard(s->getDashboardInUse(),offset,limit,ascOrder);
        else
            list = _db->readEntriesByDashboard(s->getDashboardInUse(),offset,limit,ascOrder);
        break;
    case 4:
        // View mode: Saved
        list = _db->readEntriesSavedByDashboard(s->getDashboardInUse(),offset,limit,ascOrder);
        break;
    case 5:
        // View mode: Slow
        if (s->getShowOnlyUnread())
            list = _db->readEntriesSlowUnreadByDashboard(s->getDashboardInUse(),offset,limit,ascOrder);
        else
            list = _db->readEntriesSlowByDashboard(s->getDashboardInUse(),offset,limit,ascOrder);
        break;
    case 6:
        // View mode: Liked
        list = _db->readEntriesLikedByDashboard(s->getDashboardInUse(),offset,limit,ascOrder);
        break;
    case 7:
        // View mode: Broadcast
        list = _db->readEntriesBroadcastByDashboard(s->getDashboardInUse(),offset,limit,ascOrder);
        break;
    }

    //qDebug() << "limit:" << limit << "Row count:" << list.count() << "new offset:" << offset;

    // Remove dummy row
    if (list.count()>0) {
        int l = rowCount();
        if (l>0) {
            EntryItem* item = dynamic_cast<EntryItem*>(readRow(l-1));
            //qDebug() << "item->id()" << item->id() << "l" << l;
            if (item->id()=="last")
                removeRow(l-1);
        }
    }

    QList<DatabaseManager::Entry>::iterator i = list.begin();

    int prevDateRow = 0;
    if (rowCount()>0) {
        EntryItem* item = dynamic_cast<EntryItem*>(readRow(rowCount()-1));
        prevDateRow = getDateRowId(item->date());
        //qDebug() << "prevDateRow UID:" << item->uid();
    }

    QRegExp re("<[^>]*>");
    while( i != list.end() ) {

        // Removing html tags!
        QTextDocument doc;
        doc.setHtml((*i).content);
        QString content0 = doc.toPlainText()
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
                .replace(QChar::ObjectReplacementCharacter,QChar::Space).trimmed();
#else
                .replace(QChar::ObjectReplacementCharacter,QChar(0x0020)).trimmed();
#endif
        QString content = content0.simplified();
        if (content.length()>1000)
            content = content.left(997)+"...";

        doc.setHtml((*i).title);
        //QString title = doc.toPlainText().remove(QRegExp("<[^>]*>"))
        QString title = doc.toPlainText()
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
                .replace(QChar::ObjectReplacementCharacter,QChar::Space)
#else
                .replace(QChar::ObjectReplacementCharacter,QChar(0x0020))
#endif
                .simplified();
        if (title.length()>200)
            title = title.left(197)+QString("...");

        //qDebug() << title;

        /*QRegExp rx("(\\S*)\\s*\((\\S*)\)", Qt::CaseInsensitive);
        if (rx.indexIn((*i).author)!=-1) {
            qDebug() << "(*i).author:" << (*i).author << "cap:" << rx.cap(1).toUtf8();
            //(*i).author = rx.cap(1).toUtf8();
        }*/

        // Detecting invalid images
        bool imageOk = true;
        QUrl imageUrl((*i).image);
        //qDebug() << imageUrl.path();
        if (imageUrl.path() == "/assets/images/transparent.png")
            imageOk = false;
        if (imageUrl.host() == "rc.feedsportal.com")
            imageOk = false;

        // Adding date row
        int dateRow = getDateRowId((*i).publishedAt);
        if ((!ascOrder && dateRow>prevDateRow) || (ascOrder && dateRow<prevDateRow) || prevDateRow == 0) {
            switch (dateRow) {
            case 1:
                appendRow(new EntryItem("daterow",tr("Today"),"","","","","","","","","","",false,false,false,0,0,0,0));
                break;
            case 2:
                appendRow(new EntryItem("daterow",tr("Yesterday"),"","","","","","","","","","",false,false,false,0,0,0,0));
                break;
            case 3:
                appendRow(new EntryItem("daterow",tr("Current week"),"","","","","","","","","","",false,false,false,0,0,0,0));
                break;
            case 4:
                appendRow(new EntryItem("daterow",tr("Current month"),"","","","","","","","","","",false,false,false,0,0,0,0));
                break;
            case 5:
                appendRow(new EntryItem("daterow",tr("Previous month"),"","","","","","","","","","",false,false,false,0,0,0,0));
                break;
            case 6:
                appendRow(new EntryItem("daterow",tr("Current year"),"","","","","","","","","","",false,false,false,0,0,0,0));
                break;
            default:
                appendRow(new EntryItem("daterow",tr("Previous year & older"),"","","","","","","","","","",false,false,false,0,0,0,0));
                break;
            }
        }
        prevDateRow = dateRow;
        //qDebug() << "(*i).broadcast" << (*i).broadcast << ((*i).broadcast==1);
        //qDebug() << (*i).id << (*i).link;
        appendRow(new EntryItem((*i).id,
                                title.remove(re),
                                (*i).author,
                                content,
                                content0,
                                (*i).content,
                                (*i).link,
                                imageOk? (*i).image : "",
                                (*i).feedId,
                                (*i).feedIcon,
                                (*i).feedTitle.remove(re),
                                (*i).annotations,
                                _db->isCacheExistsByEntryId((*i).id),
                                (*i).broadcast==1,
                                (*i).liked==1,
                                (*i).fresh,
                                (*i).read,
                                (*i).saved,
                                (*i).publishedAt
                                ));
        ++i;
    }
Пример #8
0
QVariant ThumbnailModel::data(const QModelIndex &index, int role) const
{
    return role == Qt::DecorationRole && index.isValid()
            ? cache.thumbnail(imageUrl(index))
            : QGalleryQueryModel::data(index, role);
}