Beispiel #1
0
eOSState cCMDDir::New(void)
{
  MYDEBUG("Verzeichnis: Neu");
  cFileInfo *info = new cFileInfo(CurrentDir());
  if(!info->isWriteable())
  {
    MYDEBUG("Verzeichnis: Neu: Keine Berechtigung in %s", CurrentDir());
    OSD_ERRMSG(tr("no rights to create"));
  }
  else
  {
    State = csDirNew;
    SetCols(5);
    SetTitle(CurrentDir());
    SetDir();

    cMainMenuItem *mItem = (cMainMenuItem*)First();
    Ins(new cMenuEditStrItem(tr("New"), Dir, MaxFileName, trVDR(FileNameChars)),
        true,
        mItem);
    while(mItem)
    {
      mItem->SetSelectable(false);
      mItem = (cMainMenuItem*)Next(mItem);
    }
    Display();
    cOsdMenu::ProcessKey(kRight);
  }

  return osContinue;
}
Beispiel #2
0
int Insere(TipoItem x, TipoPeso p, TipoTabela T)
{
  if (Pesquisa(x.Variavel, p, T) == NULL){
    Ins(x, &T[h(x.Variavel, p)]);
	return 1;
     }
      else
        return 0;
}
Beispiel #3
0
// -------------------------------------------------------------------------------- //
int guTuneInReadStationsThread::AddStations( const wxString &url, guRadioStations * stations, const long minbitrate )
{
    wxString Content = GetTuneInUrl( url );
    //guLogMessage( wxT( "AddStations: %s" ), url.c_str() );

    if( !Content.IsEmpty() )
    {
        wxStringInputStream Ins( Content );
        wxXmlDocument XmlDoc( Ins );
        wxXmlNode * XmlNode = XmlDoc.GetRoot();
        if( XmlNode )
        {
            if( XmlNode->GetName() == wxT( "opml" ) )
            {
                XmlNode = XmlNode->GetChildren();
                while( XmlNode && !TestDestroy() )
                {
                    //guLogMessage( wxT( "XmlNode: '%s'" ), XmlNode->GetName().c_str() );
                    if( XmlNode->GetName() == wxT( "outline" ) )
                    {
                        wxString Type;
                        XmlNode->GetAttribute( wxT( "type" ), &Type );
                        if( Type == wxT( "" ) )
                        {
                            ReadStations( XmlNode->GetChildren(), stations, minbitrate );
                        }
                        else
                        {
                            ReadStations( XmlNode, stations, minbitrate );
                            break;
                        }
                    }
                    else if( XmlNode->GetName() == wxT( "body" ) )
                    {
                        XmlNode = XmlNode->GetChildren();
                        continue;
                    }

                    XmlNode = XmlNode->GetNext();
                }
            }
        }
    }

    if( !TestDestroy() )
    {
        SortStations();

        wxCommandEvent Event( wxEVT_MENU, ID_RADIO_UPDATED );
        wxPostEvent( m_RadioPanel, Event );

        return stations->Count();
    }

    return 0;
}
Beispiel #4
0
/* INSERE UM NOVO REGISTRO VERIFICANDO AS PALAVRAS, CASO EXISTA A QUANTIDADE E INCREMENTADA, CASO CONTRARIA A FUNCAO INSERENAPAGINA() E CHAMADA 
    E RETORNA A QUANTIDADE DE MEMORIA GASTA */
double Ins(TipoRegistro Reg, Apontador Ap, int *Cresceu, Registro RegRetorno, Apontador *ApRetorno, int idArquivo)
{
	Apontador ApTemp;
	int i, j;
	double memoria = 0;
	if (Ap == NULL)
	{
		if ( VerificaDados(&Reg.dados, idArquivo) == 1)
			memoria += sizeof(TipoDados);
		*Cresceu = 1;
		*RegRetorno = Reg;
		*ApRetorno = NULL;
		return memoria;
	}
	i = 1;
	while (i < Ap->n && (strncmp(Reg.palavra, Ap->r[i - 1].palavra,N) > 0 )) 
		i++;
	if ( strncmp(Reg.palavra, Ap->r[i - 1].palavra,N) == 0 )
	{
		if ( VerificaDados(&Ap->r[i - 1].dados, idArquivo) == 1)
			memoria += sizeof(TipoDados);
		*Cresceu = 0;
		return memoria;
	}
	if (strncmp(Reg.palavra, Ap->r[i - 1].palavra,N) < 0)
		i--;
	Ins(Reg, Ap->p[i], Cresceu, RegRetorno, ApRetorno, idArquivo);
	if (!*Cresceu)
		return memoria;
	if (Ap->n < mm)
	{  /* Pagina tem espaco */
		InsereNaPagina(Ap, *RegRetorno, *ApRetorno, idArquivo);
		*Cresceu = 0;
		return memoria;
	}
	/* Overflow: Pagina tem que ser dividida */
	ApTemp = (Apontador)malloc(sizeof(Pagina));
	memoria += sizeof(Pagina);
	ApTemp->n = 0;
	ApTemp->p[0] = NULL;
	if (i <= m + 1)
	{
		InsereNaPagina(ApTemp, Ap->r[mm - 1], Ap->p[mm], idArquivo);
		Ap->n--;
		InsereNaPagina(Ap, *RegRetorno, *ApRetorno, idArquivo);
	}
	else
		InsereNaPagina(ApTemp, *RegRetorno, *ApRetorno, idArquivo);
	for (j = m + 2; j <= mm; j++)
		InsereNaPagina(ApTemp, Ap->r[j - 1], Ap->p[j], idArquivo);
	Ap->n = m;
	ApTemp->p[0] = Ap->p[m + 1];
	*RegRetorno = Ap->r[m];
	*ApRetorno = ApTemp;
	return memoria;
}
Beispiel #5
0
void cFileList::SortIn(char *dir, char *file)
{
  cFileListItem *Item = First();
  cFileInfo *ItemInfo = NULL;
  char *NewItem = NULL;
  cFileInfo *NewItemInfo = NULL;

  switch(SortMode)
  {
    case sNone:
      Add(new cFileListItem(dir, file));
      break;
    case sAsc:
    case sDesc:
      if(Item)
      {
        asprintf(&NewItem, "%s/%s", dir, file);
        NewItemInfo = SortToFilename ? new cFileInfo(NewItem) : NULL;
        while(Item)
        {
          if(SortToFilename)
          {
            DELETENULL(ItemInfo);
            ItemInfo = new cFileInfo(Item->Value());
          }

          if((SortMode == sAsc && !SortToFilename && strcasecmp(NewItem, Item->Value()) < 0) ||
             (SortMode == sDesc && !SortToFilename && strcasecmp(NewItem, Item->Value()) > 0))
            break;
          if((SortMode == sAsc && SortToFilename && strcasecmp(NewItemInfo->FileName(), ItemInfo->FileName()) < 0) ||
             (SortMode == sDesc && SortToFilename && strcasecmp(NewItemInfo->FileName(), ItemInfo->FileName()) > 0))
            break;

          Item = Next(Item);
        }
      }
      if(Item)
        Ins(new cFileListItem(dir, file), Item);
      else
        Add(new cFileListItem(dir, file));
      break;
    default:
      break;
  }

  delete(NewItemInfo);
  delete(ItemInfo);
  free(NewItem);
}
void Insere(TipoRegistro Reg, TipoApontador *Ap) {
	short Cresceu;
	TipoRegistro RegRetorno;
	TipoPagina *ApRetorno, *ApTemp;
	Ins(Reg, *Ap, &Cresceu, &RegRetorno, &ApRetorno);

	if (Cresceu) {
		ApTemp = (TipoPagina *)malloc(sizeof(TipoPagina));
		ApTemp->Pt = 1;
		ApTemp->UU->U0->ni=1;
		ApTemp->ri[0] = RegRetorno;
		ApTemp->p[1] =com ApRetorno;
		ApTemp->p[0] = *Ap;  *Ap = ApTemp;
	}
}
Beispiel #7
0
eOSState cCMDDir::Edit(cMainMenuItem *mItem)
{
  MYDEBUG("Verzeichnis: Edit: %s", mItem->FileName());
  cFileInfo *info = new cFileInfo(mItem->FileName());
  if(!info->isWriteable())
  {
    DELETENULL(info);
    info = new cFileInfo(CurrentDir());
    if(!info->isWriteable())
    {
      MYDEBUG("Verzeichnis: Edit: Keine Rechte");
      OSD_ERRMSG(tr("no rights to rename"));
      DELETENULL(info);
      return osContinue;
    }
  }
  DELETENULL(info);
  info = new cFileInfo(mItem->FileName());
  SetDir(info->FileName());
  DELETENULL(info);
  State = csDirEdit;
  SetCols(11);
  SetTitle(CurrentDir());

  cMainMenuItem *dmItem = NULL;
  mItem = (cMainMenuItem*)First();
  while(mItem)
  {
    if(!strcasecmp(mItem->FileName(), LastSelDir()))
    {
      MYDEBUG("Verzeichnis: Edit: Item gefunden: %s", mItem->FileName());
      Ins(new cMenuEditStrItem(tr("Rename"), Dir, MaxFileName, trVDR(FileNameChars)),
          true,
          mItem);
      dmItem = mItem;
    }
    mItem->SetSelectable(false);
    mItem = (cMainMenuItem*)Next(mItem);
  }

  if(dmItem)
    Del(dmItem->Index());
  Display();
  cOsdMenu::ProcessKey(kRight);

  return osContinue;
}
Beispiel #8
0
// -------------------------------------------------------------------------------- //
wxImage * guDbCache::GetImage( const wxString &url, wxBitmapType &imgtype, const int imgsize )
{
  wxImage *             Img = NULL;
  wxString              query;
  wxSQLite3ResultSet    dbRes;
  const unsigned char * Data;
  int                   DataLen = 0;

  query = wxString::Format( wxT( "SELECT cache_data, cache_type FROM cache WHERE cache_key = '%s' " \
                                 "AND cache_size = %u LIMIT 1;" ),
      escape_query_str( url ).c_str(), imgsize );

  dbRes = ExecuteQuery( query );

  if( dbRes.NextRow() )
  {
    Data = dbRes.GetBlob( 0, DataLen );
    imgtype = wxBitmapType( dbRes.GetInt( 1 ) );

    if( DataLen )
    {
      wxMemoryInputStream Ins( Data, DataLen );
      Img = new wxImage( Ins, imgtype );
      if( Img )
      {
        if( !Img->IsOk() )
        {
            guLogMessage( wxT( "Image is not OK" ) );
            delete Img;
            Img = NULL;
        }
      }
//      else
//      {
//        guLogMessage( wxT( "Could not create the image" ) );
//      }
    }
  }
//  else
//  {
//      guLogMessage( wxT( "DbCache failed '%s'" ), url.c_str() );
//  }

  dbRes.Finalize();

  return Img;
}
void Ins(TipoRegistro Reg, TipoApontador Ap, short *Cresceu,
		TipoRegistro *RegRetorno,  TipoApontador *ApRetorno) {
	long i = 1; long j;
	TipoApontador ApTemp;
	if (Ap == NULL){
		*Cresceu = TRUE; (*RegRetorno) = Reg; (*ApRetorno) = NULL;
		return;
	}
	while (i < Ap->n && Reg.Chave > Ap->r[i-1].Chave)
		i++;
	if (Reg.Chave == Ap->r[i-1].Chave) {
		printf(" Erro: Registro ja esta presente\n"); *Cresceu = FALSE;
		return;
	}
	if (Reg.Chave < Ap->r[i-1].Chave)
		i--;
	Ins(Reg, Ap->p[i], Cresceu, RegRetorno, ApRetorno);

	if (!*Cresceu)
		return;

	if (Ap->n < MM) {   /* Pagina tem espaco */
		InsereNaPagina(Ap, *RegRetorno, *ApRetorno);
		*Cresceu = FALSE;
		return;
	}

	/* Overflow: Pagina tem que ser dividida */
	ApTemp = (TipoApontador)malloc(sizeof(TipoPagina));
	ApTemp->n = 0;  ApTemp->p[0] = NULL;
	if (i < M + 1) {
		InsereNaPagina(ApTemp, Ap->r[MM-1], Ap->p[MM]);
		Ap->n--;
		InsereNaPagina(Ap, *RegRetorno, *ApRetorno);
	}
	else InsereNaPagina(ApTemp, *RegRetorno, *ApRetorno);

	for (j = M + 2; j <= MM; j++)
		InsereNaPagina(ApTemp, Ap->r[j-1], Ap->p[j]);

	Ap->n = M;  ApTemp->p[0] = Ap->p[M+1];
	*RegRetorno = Ap->r[M];  *ApRetorno = ApTemp;
}
Beispiel #10
0
/* CRIA E INICIALIZA VARIAVEIS PARA A VERIFICACAO SE A ARVORE CRESCE  E RETORNA A QUANTIDADE DE MEMORIA GASTA */
double Insere(TipoRegistro Reg, Apontador *Ap, int idArquivo)
{
	int Cresceu;
	TipoRegistro RegRetorno;
	Apontador ApRetorno;
	Apontador ApTemp;
	double memoria = 0;
	memoria += Ins(Reg, *Ap, &Cresceu, &RegRetorno, &ApRetorno, idArquivo);
	if (Cresceu != 0)
	{ /* Arvore cresce na altura pela raiz */
		ApTemp = (Apontador) malloc(sizeof(Pagina));
		memoria += sizeof(Pagina);
		ApTemp->n = 1;
		ApTemp->r[0] = RegRetorno;
		ApTemp->p[1] = ApRetorno;
		ApTemp->p[0] = *Ap;
		*Ap = ApTemp;
	}
	return memoria;
}
Beispiel #11
0
// -------------------------------------------------------------------------------- //
void guUserRadioProvider::OnRadioImport( wxCommandEvent &event )
{
    guRadioStations UserStations;

    wxFileDialog * FileDialog = new wxFileDialog( m_RadioPanel,
        wxT( "Select the xml file" ),
        wxGetHomeDir(),
        wxEmptyString,
        wxT( "*.xml;*.xml" ),
        wxFD_OPEN | wxFD_FILE_MUST_EXIST );

    if( FileDialog )
    {
        if( FileDialog->ShowModal() == wxID_OK )
        {
            wxFileInputStream Ins( FileDialog->GetPath() );
            wxXmlDocument XmlDoc( Ins );
            wxXmlNode * XmlNode = XmlDoc.GetRoot();
            if( XmlNode && XmlNode->GetName() == wxT( "RadioStations" ) )
            {
                ReadXmlRadioStations( XmlNode->GetChildren(), &UserStations );
                int Index;
                int Count;
                if( ( Count = UserStations.Count() ) )
                {
                    for( Index = 0; Index < Count; Index++ )
                    {
                        m_Db->SetRadioStation( &UserStations[ Index ] );
                    }
                    //
                    m_RadioPanel->RefreshStations();
                }
            }
        }
        FileDialog->Destroy();
    }
}
Beispiel #12
0
bool cScDlls::Load(void)
{
  Dl_info info;
  static int marker=0;
  if(!dladdr((void *)&marker,&info)) {
    PRINTF(L_GEN_ERROR,"dladdr: %s",dlerror());
    return false;
    }

  // we have to re-dlopen our selfs as VDR doesn't use RTLD_GLOBAL
  // but our symbols have to be available to the sub libs.
  handle=dlopen(info.dli_fname,RTLD_NOW|RTLD_GLOBAL);
  if(!handle) {
    PRINTF(L_GEN_ERROR,"dlopen myself: %s",dlerror());
    return false;
    }

  char *path=strdup(info.dli_fname);
  char *p;
  if((p=rindex(path,'/'))) *p=0;
  PRINTF(L_CORE_DYN,"library path %sn",path);

  char pat[64];
#if APIVERSNUM >= 10711
#ifdef WITH_SDDVB
  {
  snprintf(pat,sizeof(pat),"%s%s%s%s",LIBVDR_PREFIX,"dvbsddevice",SO_INDICATOR,APIVERSION);
  cScDll *dll=new cScDll(AddDirectory(path,pat));
  if(dll) {
    if(dll->Load(false)) {
      PRINTF(L_GEN_INFO,"VDR dvbsddevice plugin loaded as subplugin");
      }
    Ins(dll);
    }
  }
#endif //WITH_SDDVB
#ifdef WITH_HDDVB
  {
  snprintf(pat,sizeof(pat),"%s%s%s%s",LIBVDR_PREFIX,"dvbhddevice",SO_INDICATOR,APIVERSION);
  cScDll *dll=new cScDll(AddDirectory(path,pat));
  if(dll) {
    if(dll->Load(false)) {
      PRINTF(L_GEN_INFO,"VDR dvbhddevice plugin loaded as subplugin");
      }
    Ins(dll);
    }
  }
#endif //WITH_HDDVB
#endif //APIVERSNUM >= 10711

  snprintf(pat,sizeof(pat),"%s*-%d%s%s",LIBSC_PREFIX,SCAPIVERS,SO_INDICATOR,APIVERSION);
  bool res=true;
  cReadDir dir(path);
  struct dirent *e;
  while((e=dir.Next())) {
    if(!fnmatch(pat,e->d_name,FNM_PATHNAME|FNM_NOESCAPE)) {
      cScDll *dll=new cScDll(AddDirectory(path,e->d_name));
      if(dll) {
        if(!dll->Load(true)) res=false;
        Ins(dll);
        }
      }
    }
  free(path);
  return res;
}
Beispiel #13
0
// -------------------------------------------------------------------------------- //
wxString GetUrlContent( const wxString &url, const wxString &referer, bool gzipped )
{
    wxCurlHTTP  http;
    //char *      Buffer;
    wxString RetVal = wxEmptyString;

    http.AddHeader( wxT( "User-Agent: " ) guDEFAULT_BROWSER_USER_AGENT );
    http.AddHeader( wxT( "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" ) );
    if( gzipped )
    {
        http.AddHeader( wxT( "Accept Encoding: gzip,deflate" ) );
    }
    http.AddHeader( wxT( "Accept-Charset: utf-8" ) );
    if( !referer.IsEmpty() )
    {
        http.AddHeader( wxT( "Referer: " ) + referer );
    }

    //guLogMessage( wxT( "Getting content for %s" ), url.c_str() );

    wxMemoryOutputStream Buffer;
    http.SetOpt( CURLOPT_FOLLOWLOCATION, 1 );
    http.Get( Buffer, url );

    if( Buffer.IsOk() )
    {
        int ResponseCode = http.GetResponseCode();
        //guLogMessage( wxT( "ResponseCode: %i" ), ResponseCode );
        if( ResponseCode >= 300  && ResponseCode < 400 )
        {
            //guLogMessage( wxT( "Response %u:\n%s\n%s" ), http.GetResponseCode(), http.GetResponseHeader().c_str(), http.GetResponseBody().c_str() );
            wxString Location = http.GetResponseHeader();
            int Pos = Location.Lower().Find( wxT( "location: " ) );
            if( Pos != wxNOT_FOUND )
            {
                Location = Location.Mid( Pos + 10 );
                Location.Truncate( Location.Find( wxT( "\r\n" ) ) );
                if( Location.StartsWith( wxT( "/" ) ) )
                {
                    wxURI Uri( url );
                    wxString NewURL;
                    if( Uri.HasScheme() )
                        NewURL = Uri.GetScheme() + wxT( "://" );
                    NewURL += Uri.GetServer();
                    NewURL += Location;
                    Location = NewURL;
                }
                return GetUrlContent( Location, referer, gzipped );
            }
        }
        else if( ResponseCode >= 400 )
            return wxEmptyString;

        wxString ResponseHeaders = http.GetResponseHeader();
        //guLogMessage( wxT( "Response %u:\n%s\n%s" ), http.GetResponseCode(), http.GetResponseHeader().c_str(), http.GetResponseBody().c_str() );

        if( ResponseHeaders.Lower().Find( wxT( "content-encoding: gzip" ) ) != wxNOT_FOUND )
        {
            //guLogMessage( wxT( "Response Headers:\n%s" ), ResponseHeaders.c_str() );
            wxMemoryInputStream Ins( Buffer );
            wxZlibInputStream ZIn( Ins );
            wxStringOutputStream Outs( &RetVal );
            ZIn.Read( Outs );
        }
        else
        {
            //RetVal = wxString( Buffer, wxConvUTF8 );
//            wxStringOutputStream Outs( &RetVal );
//            wxMemoryInputStream Ins( Buffer );
//            Ins.Read( Outs );
            if( Buffer.GetLength() )
            {
                size_t Count = Buffer.GetLength();
                const char * pData = ( const char * ) Buffer.GetOutputStreamBuffer()->GetBufferStart();
                RetVal = wxString( pData, wxConvUTF8, Count );
                if( RetVal.IsEmpty() )
                {
                    RetVal = wxString( pData, wxConvISO8859_1, Count );
                    if( RetVal.IsEmpty() )
                    {
                        RetVal = wxString( pData, wxConvLibc, Count );
                    }
                }
            }
        }
        //free( Buffer );
    }
    else
    {
        guLogError( wxT( "Could not get '%s'" ), url.c_str() );
    }
    //guLogMessage( wxT( "Response:\n%s\n###############" ), RetVal.c_str() );
    return RetVal;
}
Beispiel #14
0
// -------------------------------------------------------------------------------- //
wxImage * guGetRemoteImage( const wxString &url, wxBitmapType &imgtype )
{
    wxImage *   Image = NULL;
    wxURI       Uri( url );

    wxString FileName = Uri.GetPath().Lower();

    //guLogMessage( wxT( "Downloading '%s' from '%s'" ), FileName.c_str(), url.c_str() );

    wxMemoryOutputStream Buffer;
    wxCurlHTTP http;
    http.AddHeader( wxT( "User-Agent: " ) guDEFAULT_BROWSER_USER_AGENT );
    //http.AddHeader( wxT( "Accept: */*" ) );
    //http.SetOpt( CURLOPT_FOLLOWLOCATION, 1 );
    try {
        http.Get( Buffer, url );
        if( Buffer.IsOk() )
        {
            long ResCode = http.GetResponseCode();
            //guLogMessage( wxT( "ResCode: %lu" ), ResCode );
            if( ( ResCode < 200 ) || ( ResCode > 299 ) )
            {
                //guLogMessage( wxT( "Code   : %u\n%s" ), ResCode, http.GetResponseHeader().c_str() );
                if( ( ResCode == 301 ) || ( ResCode == 302 ) || ( ResCode == 307 ) )
                {
                    wxString Location = http.GetResponseHeader();
                    int Pos = Location.Lower().Find( wxT( "location: " ) );
                    if( Pos != wxNOT_FOUND )
                    {
                        Location = Location.Mid( Pos + 10 );
                        Location.Truncate( Location.Find( wxT( "\r\n" ) ) );
                        return guGetRemoteImage( Location, imgtype );
                    }
                }
            }

//            if( ResCode != 200 )
//            {
//                guLogMessage( wxT( "Error %u getting remote image '%s'\n%s" ),
//                    http.GetResponseCode(),
//                    url.c_str(),
//                    http.GetResponseHeader().c_str() );
//            }

            wxMemoryInputStream Ins( Buffer );
            if( Ins.IsOk() )
            {
                if( FileName.EndsWith( wxT( ".jpg" ) ) ||
                    FileName.EndsWith( wxT( ".jpeg" ) ) )
                  imgtype = wxBITMAP_TYPE_JPEG;
                else if( FileName.EndsWith( wxT( ".png" ) ) )
                  imgtype = wxBITMAP_TYPE_PNG;
                else if( FileName.EndsWith( wxT( ".gif" ) ) )
                  imgtype = wxBITMAP_TYPE_GIF;
                else if( FileName.EndsWith( wxT( ".bmp" ) ) )
                  imgtype = wxBITMAP_TYPE_BMP;
                else
                  imgtype = wxBITMAP_TYPE_INVALID;

                if( imgtype != wxBITMAP_TYPE_INVALID )
                {
                    Image = new wxImage( Ins, imgtype );
                    if( Image )
                    {
                        if( Image->IsOk() )
                        {
                            return Image;
                        }
                        delete Image;
                    }
                }
            }
        }
    }
    catch( ... )
    {
        guLogError( wxT( "Exception downloading image '%s'" ), url.c_str() );
    }

    return NULL;
}
VOID Instruction_Instrument <T>::__instrument (INS ins, VOID * v)
{
    reinterpret_cast <T *> (v)->handle_instrument (Ins (ins));
}