예제 #1
0
void Settings::setDashboardInUse(const QString &value)
{
    if (getDashboardInUse() != value) {
        if (getDashboardInUse() == "") {
            settings.setValue("dafaultdashboard", value);
        } else {
            settings.setValue("dafaultdashboard", value);
            emit dashboardInUseChanged();
        }
    }
}
예제 #2
0
파일: entrymodel.cpp 프로젝트: mkiol/kaktus
int EntryModel::createItems(int offset, int limit)
{
    auto s = Settings::instance();
    auto db = DatabaseManager::instance();

    QList<DatabaseManager::Entry> list;

    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 = dynamic_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->getFilter() == 2)
            list = db->readEntriesUnreadByStream(_feedId,offset,limit,ascOrder);
        else if (s->getFilter() == 1)
            list = db->readEntriesUnreadAndSavedByStream(_feedId,offset,limit,ascOrder);
        else
            list = db->readEntriesByStream(_feedId,offset,limit,ascOrder);
        break;
    case 1:
        // View mode: Tabs->Entries
        if (s->getFilter() == 2)
            list = db->readEntriesUnreadByTab(_feedId,offset,limit,ascOrder);
        else if (s->getFilter() == 1)
            list = db->readEntriesUnreadAndSavedByTab(_feedId,offset,limit,ascOrder);
        else
            list = db->readEntriesByTab(_feedId,offset,limit,ascOrder);
        break;
    case 2:
        // View mode: Feeds->Entries
        if (s->getFilter() == 2)
            list = db->readEntriesUnreadByStream(_feedId,offset,limit,ascOrder);
        else if (s->getFilter() == 1)
            list = db->readEntriesUnreadAndSavedByStream(_feedId,offset,limit,ascOrder);
        else
            list = db->readEntriesByStream(_feedId,offset,limit,ascOrder);
        break;
    case 3:
        // View mode: Entries
        if (s->getFilter() == 2)
            list = db->readEntriesUnreadByDashboard(s->getDashboardInUse(),offset,limit,ascOrder);
        else if (s->getFilter() == 1)
            list = db->readEntriesUnreadAndSavedByDashboard(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->getFilter() == 2)
            list = db->readEntriesSlowUnreadByDashboard(s->getDashboardInUse(),offset,limit,ascOrder);
        else if (s->getFilter() == 1)
            list = db->readEntriesSlowUnreadAndSavedByDashboard(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;

#ifndef ANDROID
    // 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);
        }
    }
#endif

    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)+"...";
        } else if (content.length() < 15) {
            content.clear();
        }

        doc.setHtml((*i).title);
        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;
    }