Esempio n. 1
0
QVariant BookmarksModel::data (const QModelIndex& index, int role) const
{
    if (index.row () < 0 || index.row () > Bookmarks_.count ())
        return QVariant ();

    auto bookmark = Bookmarks_.at (index.row ());

    switch (role)
    {
    case BRID:
        return bookmark->GetID ();
    case BRUrl:
        return bookmark->GetUrl ();
    case BRTitle:
        return bookmark->GetTitle ();
    case BRDescription:
        return bookmark->GetDescription ();
    case BRImageUrl:
        return bookmark->GetImageUrl ();
    case BRFavorite:
        return bookmark->IsFavorite ();
    case BRRead:
        return bookmark->IsRead ();
    case BRTags:
        return bookmark->GetTags ().join (',');
    case BRAddTime:
        return bookmark->GetAddTime ();
    case BRUpdateTime:
        return bookmark->GetUpdateTime ();
    case BRStatus:
        return bookmark->GetStatus ();
    default:
        return QVariant ();
    }
}
Esempio n. 2
0
void BookmarksModel::AddBookmarks (const Bookmarks_t& bookmarks)
{
    Bookmarks_t bmss = bookmarks;
    for (int i = bmss.count () - 1; i >= 0; --i)
    {
        auto bms = bmss.at (i);
        auto it = std::find_if (Bookmarks_.begin (), Bookmarks_.end (),
                                [bms] (decltype (Bookmarks_.front ()) bookmark)
        {
            return bms->GetID () == bookmark->GetID ();
        });
        if (it != Bookmarks_.end ())
        {
            const int pos = std::distance (Bookmarks_.begin (), it);
            switch (bms->GetStatus ())
            {
            case Bookmark::SDeleted:
                RemoveBookmark (bms->GetID ());
                break;
            case Bookmark::SArchived:
            {
                Bookmark *bm = Bookmarks_ [pos];
                bm->SetIsRead (true);

                emit dataChanged (index (pos), index (pos));

                break;
            }
            default:
            {
                Bookmark *bm = Bookmarks_ [pos];
                bm->SetUrl (bms->GetUrl ());
                bm->SetTitle (bms->GetTitle ());
                bm->SetDescription (bms->GetDescription ());
                bm->SetIsFavorite (bms->IsFavorite ());
                bm->SetIsRead (bms->IsRead ());
                bm->SetAddTime (bms->GetAddTime ());
                bm->SetUpdateTime (bms->GetUpdateTime ());
                bm->SetTags (bms->GetTags ());
                bm->SetImageUrl (bms->GetImageUrl ());
                bm->SetStatus (bms->GetStatus ());

                emit dataChanged (index (pos), index (pos));

                break;
            }
            }

            bmss.takeAt (i)->deleteLater ();
        }
    }

    beginInsertRows (QModelIndex (), rowCount (),
                     rowCount () + bmss.count () - 1);
    Bookmarks_.append (bmss);
    endInsertRows ();
}
Esempio n. 3
0
void CMyCrawler::SearchUrl(const string &startUrl)
{
	string txt;
	if (!GetWebResponse(startUrl, txt))
		return;
	string filename=ChangeToFileName(startUrl);
	filename = "./html/" + filename + ".txt";
	ofstream outfile(filename.c_str());
	if (!outfile){
		cout << "error:unable to open file:" << filename << endl;
		return;
	}
	outfile << txt;
	outfile.close();
	vector<string> imgUrls;
	GetImageUrl(imgUrls, txt, startUrl);
	DownloadImage(imgUrls, startUrl);
}