EdsError EDSCALLBACK handleObjectEvent( EdsObjectEvent event,
									   EdsBaseRef object,
									   EdsVoid * context)
{
	//printf("object event (context=\"%s\").\n", (char *)context);
	//printf("object event (object=\"%s\").\n", (char *)object);
	// do something
	switch(event)
	{
	case kEdsObjectEvent_DirItemRequestTransfer:
	   //printf("download!\n");
		downloadImage(object, (char*)context);
		break;
	default:
		break;
	}
	
	// Object must be released
	if(object){
		EdsRelease(object);
	}
	if ( callback != NULL )
		callback((char*)context);
	return EDS_ERR_OK;
}
void LastFmImageFetcher::gotResponse(QNetworkReply* reply)
{

    if (reply->error() != QNetworkReply::NoError) {
        //qDebug() << reply->errorString();
        emit serviceUnavailable();
        return;
    }

    QDomDocument doc;
    doc.setContent(reply->readAll());

    const QDomElement firstElement = doc.firstChildElement().firstChildElement();
    const QString type = firstElement.tagName();

    const QString name = m_currentInfoDownloads.take(reply);
    const QDomNodeList imageList = firstElement.childNodes();

    for (int i=imageList.length(); i>0; i--) {
        const QDomElement element = imageList.at(i).toElement();
        if (element.tagName() == "image" &&
            (element.attribute("size") == "extralarge"
                || element.attribute("size") == "large")) {
            downloadImage(type, name, element.text());
            return;
        }
    }

//    qDebug() << "Webservice has no image for " << name;
    QTimer::singleShot(0, this, SLOT(processQueue()));

    reply->deleteLater();
}
示例#3
0
void WebCoreClass::downloadBanner(MCFCore::Misc::DownloadProvider* dlp, const char* saveFolder)
{
	if (!dlp)
		throw gcException(ERR_BADITEM);

	WebCore::Misc::DownloadImageInfo dii(dlp->getBanner());

	bool stop = false;
	downloadImage(&dii, stop);
	dlp->setBanner(dii.outPath.c_str());
}
示例#4
0
void RefImage::loadImage()
{
//    qDebug() << "Image Cached:" << imageCached;
    if (!isImageCached())
    {
        if (isImageLocal() || isImageOnDisk())
        {
            imageFromFile();
        }
        else
        {
            downloadImage();
        }
    }
    else
        emit newImage(imageItem());
    setInView(true);
}
示例#5
0
文件: myimage.cpp 项目: 9smart/9News
void MyImage::reLoad()
{
    QString str = m_source.toLocalFile();
    if(str == ""){
        str = m_source.toString();
        if(str==""){
            if(pixmap!=NULL){
                delete pixmap;
                pixmap = NULL;
            }
            return;
        }
    }

    QPixmap *temp_pixmap = pixmapCache.object(m_source.toString());
    if(temp_pixmap!=NULL){
        bool temp_cache = m_cache;
        m_cache = false;//先设置false,防止setImage中再次更新缓存
        QImage image = temp_pixmap->toImage();
        setImage(image);
        m_cache = temp_cache;
        return;
    }

    if(str.indexOf("http")==0){//如果是网络图片
        downloadImage(m_source);
        return;
    }

    if( str.mid (0, 3) == "qrc")
        str = str.mid (3, str.count ()-3);

    QImage image;
    if( !image.load (str)){
        emit loadError ();
        setStatus(Error);
        return;
    }
    setImage(image);
}
示例#6
0
void handleImagesDownload(void) // OBSOLETE
{
    if(destDir.isSet == 0) {                    // destination dir not set?
        selectDestinationDir();
        
        if(destDir.isSet == 0) {                // destination dir still not set?
            (void) Clear_home();
            (void) Cconws("You have to select destination dir!\r\nPress any key to continue.\n\r");
            getKey();
            return;
        }
    }
    
    BYTE res;
    
    (void) Clear_home();
    (void) Cconws("Downloading selected images...\r\n");

    while(1) {
        commandShort[4] = FDD_CMD_SEARCH_DOWNLOAD;
        commandShort[5] = 0;
        sectorCount = 1;                        // read 1 sector
        res = Supexec(ce_acsiReadCommand);

        if(res == FDD_DN_WORKING) {             // if downloading
            (void) Cconws(pBfr);                // write out status string
            (void) Cconws("\n\r");
        } else if(res == FDD_DN_NOTHING_MORE) { // if nothing more to download
            (void) Cconws("All selected images downloaded.\r\nPress any key to continue.\n\r");
            getKey();
            break;
        } else if(res == FDD_DN_DONE) {         // if this image finished downloading
            downloadImage(10);                  // store this downloaded image
            (void) Cconws("\n\r\n\r");
        } 

        sleep(1);                               // wait a second
    }
}
void
TrackImageFetcher::onTrackGotInfo( const QByteArray& data )
{
    XmlQuery lfm;

    if ( lfm.parse( data ) )
    {
        lastfm::MutableTrack track( m_track );
        track.setImageUrl( Track::MegaImage, lfm["track"]["image size=mega"].text() );
        track.setImageUrl( Track::ExtraLargeImage, lfm["track"]["image size=extralarge"].text() );
        track.setImageUrl( Track::LargeImage, lfm["track"]["image size=large"].text() );
        track.setImageUrl( Track::MediumImage, lfm["track"]["image size=medium"].text() );
        track.setImageUrl( Track::SmallImage, lfm["track"]["image size=small"].text() );

        if (!downloadImage( 0, "track" ))
            startArtist();
    }
    else
    {
        qWarning() << lfm.parseError().message();
    }
}
bool Images::downloadImages () {
	// all done if we got a valid thumbnail
	//if ( m_thumbnailValid ) return true;

	long  srcLen;
	char *src = NULL;
	long node;

	// downloading an image from diffbot json reply?
	if ( m_xd->m_isDiffbotJSONObject ) {
		// i guess this better not block cuz we'll core!
		char **iup = m_xd->getDiffbotPrimaryImageUrl();
		// if no image, nothing to download
		if ( ! *iup ) {
			//log("no diffbot image url for %s",
			//    m_xd->m_firstUrl.m_url);
			return true;
		}
		// force image count to one
		m_numImages = 1;
		// do not error out
		m_errors[0] = 0;
		// set it to the full url
		src = *iup;
		srcLen = gbstrlen(src);
		// need this
		m_imageUrl.set ( src , srcLen );
		// jump into the for loop below
		//if ( m_phase == 0 ) goto insertionPoint;
	}

	// . download each leftover image
	// . stop as soon as we get one with good dimensions
	// . make a thumbnail of that one
	for (  ; m_j < m_numImages ; m_j++ , m_phase = 0 ) {

		// did collection get nuked?
		CollectionRec *cr = g_collectiondb.getRec(m_collnum);
		if ( ! cr ) { g_errno = ENOCOLLREC; return true; }

		// clear error
		g_errno = 0;

		if ( m_phase == 0 ) {
			// advance
			m_phase++;
			// only if not diffbot, we set "src" above for it
			if ( ! m_xd->m_isDiffbotJSONObject ) {
				// get img tag node
				node = m_imageNodes[m_j];
				// get the url of the image
				src = m_xml->getString(node,"src",&srcLen);
				// use "pageUrl" as the baseUrl
				m_imageUrl.set ( m_pageUrl , src , srcLen ); 
			}
			// if we should stop, stop
			if ( m_stopDownloading ) break;
			// skip if bad or not unique
			if ( m_errors[m_j] ) continue;
			// set status msg
			sprintf ( m_statusBuf ,"downloading image %li",m_j);
			// point to it
			if ( m_xd ) m_xd->setStatus ( m_statusBuf );
		}

		// get image ip
		if ( m_phase == 1 ) {
			// advance
			m_phase++;
			// this increments phase if it should
			if ( ! getImageIp() ) return false;
			// error?
			if ( g_errno ) continue;
		}

		// download the actual image
		if ( m_phase == 2 ) {
			// advance
			m_phase++;
			// download image data
			if ( ! downloadImage() ) return false;
			// error downloading?
			if ( g_errno ) continue;
		}

		// get thumbnail using threaded call to netpbm stuff
		if ( m_phase == 3 ) {
			// advance
			m_phase++;
			// call pnmscale etc. to make thumbnail
			if ( ! makeThumb() ) return false;
			// error downloading?
			if ( g_errno ) continue;
		}

		// error making thumb or just not a good thumb size?
		if ( ! m_thumbnailValid ) {
			// free old image we downloaded, if any
			m_msg13.reset();
			// i guess do this too, it was pointing at it in msg13
			m_imgReply = NULL;
			// try the next image candidate
			continue;
		}

		// it's a keeper
		long urlSize = m_imageUrl.getUrlLen() + 1; // include \0
		// . make our ThumbnailArray out of it
		long need = 0;
		// the array itself
		need += sizeof(ThumbnailArray);
		// and each thumbnail it contains
		need += urlSize;
		need += m_thumbnailSize;
		need += sizeof(ThumbnailInfo);
		// reserve it
		m_imageBuf.reserve ( need );
		// point to array
		ThumbnailArray *ta =(ThumbnailArray *)m_imageBuf.getBufStart();
		// set that as much as possible, version...
		ta->m_version = 0;
		// and thumb count
		ta->m_numThumbnails = 1;
		// now store the thumbnail info
		ThumbnailInfo *ti = ta->getThumbnailInfo (0);
		// and set our one thumbnail
		ti->m_origDX = m_dx;
		ti->m_origDY = m_dy;
		ti->m_dx = m_tdx;
		ti->m_dy = m_tdy;
		ti->m_urlSize = urlSize;
		ti->m_dataSize = m_thumbnailSize;
		// now copy the data over sequentially
		char *p = ti->m_buf;
		// the image url
		memcpy(p,m_imageUrl.getUrl(),urlSize);
		p += urlSize;
		// the image thumbnail data
		memcpy(p,m_imgData,m_thumbnailSize);
		p += m_thumbnailSize;
		// update buf length of course
		m_imageBuf.setLength ( p - m_imageBuf.getBufStart() );

		// validate the buffer
		m_imageBufValid = true;

		// save mem. do this after because m_imgData uses m_msg13's
		// reply buf to store the thumbnail for now...
		m_msg13.reset();
		m_imgReply = NULL;

		g_errno = 0;

		return true;
	}

	// don't tell caller EBADIMG it will make him fail to index doc
	g_errno = 0;

	return true;
}
    //---------------------------------------------------------------------
    bool CanonCameraWrapper::downloadLastImage(){
        preCommand();

        EdsVolumeRef 		theVolumeRef	    = NULL ;
        EdsDirectoryItemRef	dirItemRef_DCIM	    = NULL;
        EdsDirectoryItemRef	dirItemRef_Sub	    = NULL;
        EdsDirectoryItemRef	dirItemRef_Image    = NULL;

        EdsDirectoryItemInfo dirItemInfo_Image;

        EdsError err    = EDS_ERR_OK;
        EdsUInt32 Count = 0;
        bool success    = false;

        //get the number of memory devices
        err = EdsGetChildCount( theCamera, &Count );
        if( Count == 0 ){
            printf("Memory device not found\n");
            err = EDS_ERR_DEVICE_NOT_FOUND;
            return false;
        }

        // Download Card No.0 contents
        err = EdsGetChildAtIndex( theCamera, 0, &theVolumeRef );
//        if ( err == EDS_ERR_OK ){
//            printf("getting volume info\n");
//            //err = EdsGetVolumeInfo( theVolumeRef, &volumeInfo ) ;
//        }

        //Now lets find out how many Folders the volume has
        if ( err == EDS_ERR_OK ){
            err = EdsGetChildCount( theVolumeRef, &Count );

            if ( err == EDS_ERR_OK ){

                //Lets find the folder called DCIM
                bool bFoundDCIM = false;
                for(int i = 0; i < Count; i++){
                    err = EdsGetChildAtIndex( theVolumeRef, i, &dirItemRef_DCIM ) ;
                    if ( err == EDS_ERR_OK ){
                        EdsDirectoryItemInfo dirItemInfo;
                        err = EdsGetDirectoryItemInfo( dirItemRef_DCIM, &dirItemInfo );
                        if( err == EDS_ERR_OK){
                            string folderName = dirItemInfo.szFileName;
                            if( folderName == "DCIM" ){
                                bFoundDCIM = true;
                                printf("Found the DCIM folder at index %i\n", i);
                                break;
                            }
                        }
                    }
                    //we want to release the directories that don't match
                    easyRelease(dirItemRef_DCIM);
                }

                //This is a bit silly.
                //Essentially we traverse into the DCIM folder, then we go into the last folder in there, then we
                //get the last image in last folder.
                if( bFoundDCIM && dirItemRef_DCIM != NULL){
                    //now we are going to look for the last folder in DCIM
                    Count = 0;
                    err = EdsGetChildCount(dirItemRef_DCIM, &Count);

                    bool foundLastFolder = false;
                    if( Count > 0 ){
                        int lastIndex = Count-1;

                        EdsDirectoryItemInfo dirItemInfo_Sub;

                        err = EdsGetChildAtIndex( dirItemRef_DCIM, lastIndex, &dirItemRef_Sub ) ;
                        err = EdsGetDirectoryItemInfo( dirItemRef_Sub, &dirItemInfo_Sub);

                        printf("Last Folder is %s \n", dirItemInfo_Sub.szFileName);

                        EdsUInt32 jpgCount = 0;
                        err = EdsGetChildCount(dirItemRef_Sub, &jpgCount );

                        if( jpgCount > 0 ){
                            int latestJpg = jpgCount-1;

                            err = EdsGetChildAtIndex(dirItemRef_Sub, latestJpg, &dirItemRef_Image ) ;
                            err = EdsGetDirectoryItemInfo(dirItemRef_Image, &dirItemInfo_Image);

                            printf("Latest image is %s \n", dirItemInfo_Image.szFileName);
                            success = true;
                        }else{
                            printf("Error - No jpegs inside %s\n", dirItemInfo_Image.szFileName);
                        }
                    }else{
                        printf("Error - No subfolders inside DCIM!\n");
                    }
                }
            }
        }
        if( success ){
            success = downloadImage(dirItemRef_Image);
        }

        easyRelease(theVolumeRef);
        easyRelease(dirItemRef_DCIM);
        easyRelease(dirItemRef_Sub);
        easyRelease(dirItemRef_Image);

        postCommand();

        return success;
    }
示例#10
0
void
TrackImageFetcher::onAlbumGotInfo()
{
    if (!downloadImage( (QNetworkReply*)sender(), "album" ))
        startTrack();
}
示例#11
0
void
TrackImageFetcher::onArtistGotInfo()
{
    if (!downloadImage( (QNetworkReply*)sender(), "artist" ))
        fail();
}
void CHttpImageDownloader::run()
{
    downloadImage(m_ImageUrl);
}
示例#13
0
void CDoodChatManagerModel::addHistoryMsgToListView(MsgList msgList)
{
    qDebug()<<Q_FUNC_INFO<<"msg size:"<<msgList.size();
    int len = msgList.size();
    bool isUpdate = false;
    if(msgList.size() <= 0){
        return;
    }

    for(int i = 0; i<len;++i){

        Msg msg = msgList.at(i);
        if(/*msg.msgtype.toInt() == MSG_TYPE_IMG || */msg.fromid =="0"||msg.fromid == ""){
            continue;
        }
        if(msg.localid == "" ||msg.localid == "0"){
            msg.localid = createLocalId();
        }

        if(msg.msgtype.toInt() == MEDIA_MSG_REVOKE && msgIsExitById(msg.revokeMsgId)){
            QStringList msgs;
            msgs.push_back(msg.revokeMsgId);
            emit deleteMessage(id(),msgs);
            removeItemByMsgId(msg.revokeMsgId);
        }

        if(!m_pChatMap.contains(msg.localid)&&!msgIsExitById(msg.msgid)) {

            QDateTime msgDate = QDateTime::fromString(msg.time, "yyyy-MM-dd hh:mm:ss");
            bool bShow = isJudageShowTime(msgDate);
            isUpdate = true;
            qDebug()<< Q_FUNC_INFO<<"msgTime:"<<msg.time;
            CDoodChatItem *pChatItem = new CDoodChatItem(this);
            pChatItem->setLocalId(msg.localid);
            pChatItem->setMsgType(msg.msgtype);
            pChatItem->setActiveType(msg.activeType);
            pChatItem->setMsgId(msg.msgid);
            pChatItem->setTargetId(msg.targetid);
            pChatItem->setFromId(msg.fromid);
            pChatItem->setToId(msg.toid);
            pChatItem->setName(msg.name);
            pChatItem->setTime(msgDate);
            pChatItem->setShowTime(bShow);
            pChatItem->setLoading(false);
            pChatItem->setContactThumbAvatar(msg.thumb_avatar);
            pChatItem->setIsMyselft(mAccountUserId == msg.fromid);
            if(msg.msgtype.toInt() == MSG_TYPE_FILE){
                pChatItem->setFileSize(msg.f_size.toLongLong());
                pChatItem->setProgress(0);
                pChatItem->setThumbAvatar(msg.f_url);
                pChatItem->setTar_thumbAvatar(msg.encrypt_user);
                pChatItem->setTextMsg(msg.filename);
                pChatItem->setBody(msg.encrypt_key);
                pChatItem->setFilePath("");
                pChatItem->mFileUrl = msg.f_url;
            }
            else if(msg.msgtype.toInt() == MSG_TYPE_IMG){
                if(msg.body != ""&& fileExistAtLocal(msg.body)){
                    msg.body = "file://"+msg.body;
                }else{
                    msg.body = "qrc:/res/control/defaultimage.png";
                }
                pChatItem->setBody(msg.body);
                pChatItem->setTar_thumbAvatar(msg.thumb_url);
                pChatItem->setTextMsg(msg.main_url);
                pChatItem->setBodyBig(msg.main_url);
                pChatItem->mImageMainUrl = msg.main_url;
                pChatItem->mImageThumbUrl = msg.thumb_url;
                pChatItem->setEncrypt_key(msg.encrypt_key);

            }else if(msg.msgtype.toInt() == MEDIA_MSG_REVOKE){
                pChatItem->setMsgType(QString::number(MSG_TYPE_TIP));
                if(msg.fromid == mAccountUserId){
                    pChatItem->setBody("您撤回了一条消息");
                }else{
                    pChatItem->setBody(msg.body+"撤回了一条消息");
                }
            }
            else{
                pChatItem->setBody(msg.body);
            }

            //addItem(pChatItem);
            qint64 pos = indexOfNewItem(pChatItem->time());
            if(pos>=0 &&pos<= m_pChatMap.size()){
                insertItem(pos,pChatItem);
            }

            m_pChatMap[msg.localid] = pChatItem;
            updateItemNameAndAvatar(msg.localid,msg.fromid);
            pChatItem->mEnkey = msg.encrypt_key;
            pChatItem->mEnkeyUser = msg.encrypt_user;
            if(msg.msgtype.toInt() == MSG_TYPE_IMG){
                if(msg.body == "qrc:/res/control/defaultimage.png"|| !fileExistAtLocal(msg.body)){
                    pChatItem->setLoading(true);
                    emit downloadImage(id(),msg.localid,msg.thumb_url,msg.encrypt_key);
                }
            }
        }
    }
    if(isUpdate){
        emit updateDataFinished();
    }
    if(_list->count()>0){
        QString msgid;
        msgid=qobject_cast<CDoodChatItem*>(_list->at(_list->count()-1))->msgId();
        emit setMsgRead(msgid);
    }
}