Example #1
0
bool ElementImage::LoadCachedTexture()
{
	texture_dirty = false;

	// Get the source URL for the image.
	String image_source = GetAttribute< String >("_cached_src", "");
	if( image_source.Empty() ) {
		SetPseudoClass( "loading", false );
		return false;
	}

 	geometry_dirty = true;

	URL image_url( image_source );
	bool res = texture.Load( image_url.GetHost() + "/" + image_url.GetPathedFileName() );

	SetPseudoClass( "loading", false );

	if( !res ) {
		geometry.SetTexture( NULL );
		return false;
	}

	// Set the texture onto our geometry object.
	geometry.SetTexture( &texture );

	DirtyLayout();
	return true;
}
Example #2
0
void MainWindow::action_on_data_get(QByteArray json_file_data)
{
    QString data_string;
    data_string = json_file_data;
    QStringList propertyNames;
    QStringList propertyKeys;
    QString strReply = json_file_data;
    QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
    jsonObject = jsonResponse.object();
    QPixmap pixmap;
    QUrl image_url(jsonObject["Poster"].toString());
    QNetworkRequest request_image(image_url);

    image_get->get(request_image);


   // int w = ui->img_disp->width();
    //int h = ui->img_disp->height();

    ui->textBrowser->setPlainText("");
    ui->textBrowser->append("Title\t\t:" + jsonObject["Title"].toString());
    ui->textBrowser->append("Year\t\t:" + jsonObject["Year"].toString());
    ui->textBrowser->append("Rated\t\t:" + jsonObject["Rated"].toString());
    ui->textBrowser->append("Released\t\t:" + jsonObject["Released"].toString());
    ui->textBrowser->append("Runtime\t\t:" + jsonObject["Runtime"].toString());
    ui->textBrowser->append("Genre\t\t:" + jsonObject["Genre"].toString());
    ui->textBrowser->append("Director\t\t:" + jsonObject["Director"].toString());
    ui->textBrowser->append("Actors\t\t:" + jsonObject["Actors"].toString());
    ui->textBrowser->append("IMDb Rating\t:" + jsonObject["imdbRating"].toString());
    ui->textBrowser->append("Plot\t\t:" + jsonObject["Plot"].toString());

}
/* try to load image from internet */
FILE *load_icon_by_name(char *name){

  CURL *curl;
  CURLcode res;
  FILE *f;
  char *filename;
  char *lastname=name;
  int i;

  for(i=0;name[i]!='\0';++i){

    if(name[i]=='/')
      lastname=name+i+1;
  }

  filename=malloc(strlen(cache_path)+strlen(lastname)+2);
  if(filename==NULL){mylog("Malloc failed\n");return NULL;}

  /* path to cached image */
  strcpy(filename,cache_path);
  filename[strlen(cache_path)]='/';
  strcpy(filename+strlen(cache_path)+1,lastname);

  f=fopen(filename,"w");
  if(f==NULL){
    free(filename);
    mylog("failed to get icon %s\n",name);
    return NULL;
  }

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, image_url(name));
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_icon);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);
    res = curl_easy_perform(curl);
    /* always cleanup */
    curl_easy_cleanup(curl);

    if(res==0){ // all ok
      free(filename);
      return f;
    }
    fclose(f);
  }
  free(filename);
  mylog("Cannot download %s (%d)\n",name,(int)res);
  return NULL;
}