// -------------------------------------------------------------------------------- // bool guDbCache::DoSetImage( const wxString &url, wxImage * img, const wxBitmapType imgtype, const int imagesize ) { wxMemoryOutputStream Outs; if( img->SaveFile( Outs, imgtype ) ) { wxSQLite3Statement stmt = m_Db->PrepareStatement( wxString::Format( wxT( "INSERT INTO cache( cache_id, cache_key, cache_data, cache_type, cache_time, cache_size ) " \ "VALUES( NULL, '%s', ?, %u, %lu, %u );" ), escape_query_str( url ).c_str(), ( int ) imgtype, wxDateTime::Now().GetTicks(), imagesize ) ); try { stmt.Bind( 1, ( const unsigned char * ) Outs.GetOutputStreamBuffer()->GetBufferStart(), Outs.GetSize() ); //guLogMessage( wxT( "%s" ), stmt.GetSQL().c_str() ); stmt.ExecuteQuery(); return true; } catch( wxSQLite3Exception &e ) { guLogError( wxT( "%u: %s" ), e.GetErrorCode(), e.GetMessage().c_str() ); } catch(...) { guLogError( wxT( "Other exception found while updating the image in cache" ) ); } } return false; }
// -------------------------------------------------------------------------------- // guEq10Band::~guEq10Band() { guConfig * Config = ( guConfig * ) guConfig::Get(); wxPoint WindowPos = GetPosition(); Config->WriteNum( wxT( "PosX" ), WindowPos.x, wxT( "equalizer" ) ); Config->WriteNum( wxT( "PosY" ), WindowPos.y, wxT( "equalizer" ) ); wxSize WindowSize = GetSize(); Config->WriteNum( wxT( "Width" ), WindowSize.x, wxT( "equalizer" ) ); Config->WriteNum( wxT( "Height" ), WindowSize.y, wxT( "equalizer" ) ); Config->WriteStr( wxT( "LastEqPreset" ), m_BandChanged ? wxT( "" ) : m_PresetComboBox->GetValue(), wxT( "equalizer" ) ); wxFileConfig * EqConfig = new wxFileConfig( wxEmptyString, wxEmptyString, wxGetHomeDir() + wxT( "/.guayadeque/equalizers.conf" ) ); if( EqConfig ) { EqConfig->DeleteGroup( wxT( "Equalizers" ) ); EqConfig->SetPath( wxT( "Equalizers" ) ); int index; int count = m_EQPresets.Count(); for( index = 0; index < count; index++ ) { if( !EqConfig->Write( m_EQPresets[ index ].m_Name, wxString::Format( wxT( "%i,%i,%i,%i,%i,%i,%i,%i,%i,%i" ), m_EQPresets[ index ].m_Sets[ 0 ], m_EQPresets[ index ].m_Sets[ 1 ], m_EQPresets[ index ].m_Sets[ 2 ], m_EQPresets[ index ].m_Sets[ 3 ], m_EQPresets[ index ].m_Sets[ 4 ], m_EQPresets[ index ].m_Sets[ 5 ], m_EQPresets[ index ].m_Sets[ 6 ], m_EQPresets[ index ].m_Sets[ 7 ], m_EQPresets[ index ].m_Sets[ 8 ], m_EQPresets[ index ].m_Sets[ 9 ] ) ) ) guLogError( wxT( "Error writing key %s" ), m_EQPresets[ index ].m_Name.c_str() ); } delete EqConfig; } // m_PresetComboBox->Disconnect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( guEq10Band::OnPresetSelected ), NULL, this ); m_PresetComboBox->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( guEq10Band::OnPresetText ), NULL, this ); m_ResetButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( guEq10Band::OnResetPreset ), NULL, this ); m_SaveButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( guEq10Band::OnAddPreset ), NULL, this ); m_DelButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( guEq10Band::OnDelPreset ), NULL, this ); int Index; for( Index = 0; Index < guEQUALIZER_BAND_COUNT; Index++ ) { m_Bands[ Index ]->Disconnect( wxEVT_SCROLL_CHANGED, wxScrollEventHandler( guEq10Band::OnBandChanged ), NULL, this ); m_Bands[ Index ]->Disconnect( wxEVT_SCROLL_THUMBTRACK, wxScrollEventHandler( guEq10Band::OnUpdateLabel ), NULL, this ); } }
// -------------------------------------------------------------------------------- // bool guSetFileMode( const wxString &filepath, int mode, bool adding ) { int m = mode; if( adding ) { m |= guGetFileMode( filepath ); } if( chmod( ( const char * ) filepath.fn_str(), mode ) == -1 ) { guLogError( wxT( "Failed to set file permission for '%s'"), filepath.c_str() ); return false; } return true; }
// -------------------------------------------------------------------------------- // guFetchCoverLinksThread::ExitCode guFetchCoverLinksThread::Entry() { bool NoMorePics = false; if( m_CoverFetcher ) { while( !TestDestroy() ) { if( m_LastDownload < ( int ) m_CoverLinks.Count() ) { m_CoverEditor->m_DownloadThreadMutex.Lock(); if( !TestDestroy() ) { guDownloadCoverThread * DownloadThread = new guDownloadCoverThread( m_CoverEditor, &m_CoverLinks[ m_LastDownload ] ); if( !DownloadThread ) { guLogError( wxT( "Could not create the download covers thread" ) ); } } m_CoverEditor->m_DownloadThreadMutex.Unlock(); m_LastDownload++; Sleep( 20 ); } else { if( NoMorePics ) break; if( m_CoverLinks.Count() > MAX_COVERLINKS_ITEMS ) break; if( !m_CoverFetcher->AddCoverLinks( m_CurrentPage ) ) { NoMorePics = true; if( m_LastDownload < ( int ) m_CoverLinks.Count() ) { continue; } break; } m_CurrentPage++; } } } return 0; }
// -------------------------------------------------------------------------------- // bool guDbCache::SetContent( const wxString &url, const char * str, const int len ) { try { wxSQLite3Statement stmt = m_Db->PrepareStatement( wxString::Format( wxT( "INSERT INTO cache( cache_id, cache_key, cache_data, cache_type, cache_time, cache_size ) " \ "VALUES( NULL, '%s', ?, %u, %lu, %u );" ), escape_query_str( url ).c_str(), guDBCACHE_TYPE_TEXT, wxDateTime::Now().GetTicks(), 0 ) ); stmt.Bind( 1, ( const unsigned char * ) str, len ); //guLogMessage( wxT( "%s" ), stmt.GetSQL().c_str() ); stmt.ExecuteQuery(); return true; } catch( wxSQLite3Exception &e ) { guLogError( wxT( "%u: %s" ), e.GetErrorCode(), e.GetMessage().c_str() ); } return false; }
// -------------------------------------------------------------------------------- // bool guMediaRecordCtrl::SaveTagInfo( const wxString &filename, const guTrack * Track ) { bool RetVal = true; guTagInfo * TagInfo; if( !filename.IsEmpty() && wxFileExists( filename ) ) { TagInfo = guGetTagInfoHandler( filename ); if( TagInfo ) { if( m_DeleteTracks ) { TagInfo->Read(); if( TagInfo->m_Length < m_DeleteTime ) { wxRemoveFile( filename ); delete TagInfo; return true; } } TagInfo->m_AlbumName = Track->m_AlbumName; TagInfo->m_ArtistName = Track->m_ArtistName; TagInfo->m_GenreName = Track->m_GenreName; TagInfo->m_TrackName = Track->m_SongName; if( !( RetVal = TagInfo->Write( guTRACK_CHANGED_DATA_TAGS ) ) ) { guLogError( wxT( "Could not set tags to the record track" ) ); } delete TagInfo; } } return RetVal; }
// -------------------------------------------------------------------------------- // int guGoogleCoverFetcher::AddCoverLinks( int pagenum ) { wxString SearchString = wxString::Format( wxT( "\"%s\" \"%s\"" ), m_Artist.c_str(), m_Album.c_str() ); //guLogMessage( wxT( "URL: %u %s" ), m_CurrentPage, m_SearchString.c_str() ); wxString SearchUrl = wxString::Format( GOOGLE_IMAGES_SEARCH_URL, guURLEncode( SearchString ).c_str(), ( pagenum * GOOGLE_COVERS_PER_PAGE ) ); //guLogMessage( wxT( "URL: %u %s" ), pagenum, SearchUrl.c_str() ); if( !m_MainThread->TestDestroy() ) { wxString Content = GetUrlContent( SearchUrl ); if( Content.Length() ) { if( !m_MainThread->TestDestroy() ) { //guLogMessage( wxT( "Google:====>>>>\n%s\n<<<<====" ), Content.c_str() ); return ExtractImagesInfo( Content, GOOGLE_COVERS_PER_PAGE ); } } else { guLogError( wxT( "Could not get the remote data from connection" ) ); } } return 0; }
// -------------------------------------------------------------------------------- // void Unmounted_Device( GObject * object, GAsyncResult * result, guGIO_Mount * mnt ) { GError * error = NULL; if( G_IS_MOUNT( object ) ) { GMount * mount = ( GMount * ) object; g_mount_eject_with_operation_finish( mount, result, &error); } if( error ) { if( !g_error_matches( error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED ) ) { guLogError( wxT( "Unable to eject %s" ), error->message ); } else { guLogMessage( wxT( "Eject was already done" ) ); } g_error_free (error); } }
// -------------------------------------------------------------------------------- // int guAmazonCoverFetcher::AddCoverLinks( int pagenum ) { wxDateTime CurTime = wxDateTime::Now(); wxString SearchParams = wxString::Format( AMAZON_SEARCH_PARAMS, pagenum + 1, percentEncodeRfc3986( guURLEncode( m_Artist + wxT( " " ) + m_Album ) ).c_str(), guURLEncode( CurTime.ToUTC().Format( wxT( "%Y-%m-%dT%H:%M:%S.000Z" ) ) ).c_str() ); SearchParams.Replace( wxT( "," ), wxT( "%2C" ) ); wxString SignText = GetAmazonSign( SearchParams ); wxString SearchUrl = AMAZON_SEARCH_URL + SearchParams + wxT( "&Signature=" ) + SignText; //guLogMessage( wxT( "URL: %u %s" ), pagenum, SearchUrl.c_str() ); if( !m_MainThread->TestDestroy() ) { //printf( "Buffer:\n%s\n", Buffer ); wxString Content = GetUrlContent( SearchUrl ); //Content = http.GetContent( SearchUrl, 60 ); //guLogMessage( wxT( "Amazon Response:\n%s" ), Content.c_str() ); if( Content.Length() ) { if( !m_MainThread->TestDestroy() ) { return ExtractImagesInfo( Content ); } } else { guLogError( wxT( "Could not get the remote data from connection" ) ); } } return 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; }
// -------------------------------------------------------------------------------- // 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; }
// -------------------------------------------------------------------------------- // guChannelEditor::guChannelEditor( wxWindow * parent, guPodcastChannel * channel ) : wxDialog( parent, wxID_ANY, _( "Podcast Channel Editor" ), wxDefaultPosition, wxSize( 564,329 ), wxDEFAULT_DIALOG_STYLE ) { wxStaticText* DescLabel; wxStaticText* AuthorLabel; wxStaticText* OwnerLabel; wxStaticText* DownloadLabel; wxStaticText* DeleteLabel; wxStdDialogButtonSizer* ButtonsSizer; wxButton* ButtonsSizerOK; wxButton* ButtonsSizerCancel; m_PodcastChannel = channel; guConfig * Config = ( guConfig * ) guConfig::Get(); this->SetSizeHints( wxDefaultSize, wxDefaultSize ); wxBoxSizer* MainSizer; MainSizer = new wxBoxSizer( wxVERTICAL ); wxStaticBoxSizer* ChannelSizer; ChannelSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _( " Podcast Channel " ) ), wxVERTICAL ); wxFlexGridSizer* FlexGridSizer; FlexGridSizer = new wxFlexGridSizer( 2, 0, 0 ); FlexGridSizer->AddGrowableCol( 1 ); FlexGridSizer->SetFlexibleDirection( wxBOTH ); FlexGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); m_Image = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( guPODCASTS_IMAGE_SIZE,guPODCASTS_IMAGE_SIZE ), 0 ); FlexGridSizer->Add( m_Image, 0, wxALL, 5 ); // Check that the directory to store podcasts are created wxString PodcastsPath = Config->ReadStr( CONFIG_KEY_PODCASTS_PATH, guPATH_PODCASTS, CONFIG_PATH_PODCASTS ); wxFileName ImageFile = wxFileName( PodcastsPath + wxT( "/" ) + channel->m_Title + wxT( "/" ) + channel->m_Title + wxT( ".jpg" ) ); if( ImageFile.Normalize( wxPATH_NORM_ALL | wxPATH_NORM_CASE ) ) { wxImage PodcastImage; if( wxFileExists( ImageFile.GetFullPath() ) && PodcastImage.LoadFile( ImageFile.GetFullPath() ) && PodcastImage.IsOk() ) { m_Image->SetBitmap( PodcastImage ); } else { m_Image->SetBitmap( guBitmap( guIMAGE_INDEX_mid_podcast ) ); if( !channel->m_Image.IsEmpty() ) { guChannelUpdateImageThread * UpdateImageThread = new guChannelUpdateImageThread( this, channel->m_Image.c_str() ); if( !UpdateImageThread ) { guLogError( wxT( "Could not create the Channel Image Thread" ) ); } } } } m_Title = new wxStaticText( this, wxID_ANY, channel->m_Title, wxDefaultPosition, wxDefaultSize, 0 ); FlexGridSizer->Add( m_Title, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 ); DescLabel = new wxStaticText( this, wxID_ANY, _( "Description:" ), wxDefaultPosition, wxDefaultSize, 0 ); DescLabel->Wrap( -1 ); DescLabel->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 90, false, wxEmptyString ) ); FlexGridSizer->Add( DescLabel, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_DescText = new wxStaticText( this, wxID_ANY, ( channel->m_Description.Length() > 200 ? channel->m_Description.Mid( 0, 200 ) + wxT( " ..." ) : channel->m_Description ), wxDefaultPosition, wxDefaultSize, 0 ); m_DescText->Wrap( 450 ); FlexGridSizer->Add( m_DescText, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); AuthorLabel = new wxStaticText( this, wxID_ANY, _("Author:"), wxDefaultPosition, wxDefaultSize, 0 ); AuthorLabel->Wrap( -1 ); AuthorLabel->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 90, false, wxEmptyString ) ); FlexGridSizer->Add( AuthorLabel, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_AuthorText = new wxStaticText( this, wxID_ANY, channel->m_Author, wxDefaultPosition, wxDefaultSize, 0 ); m_AuthorText->Wrap( -1 ); FlexGridSizer->Add( m_AuthorText, 0, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT, 5 ); OwnerLabel = new wxStaticText( this, wxID_ANY, _("Owner:"), wxDefaultPosition, wxDefaultSize, 0 ); OwnerLabel->Wrap( -1 ); OwnerLabel->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), 70, 90, 90, false, wxEmptyString ) ); FlexGridSizer->Add( OwnerLabel, 0, wxALIGN_RIGHT|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_OwnerText = new wxStaticText( this, wxID_ANY, channel->m_OwnerName + wxT( " ( " ) + channel->m_OwnerEmail + wxT( " )" ) , wxDefaultPosition, wxDefaultSize, 0 ); m_OwnerText->Wrap( -1 ); FlexGridSizer->Add( m_OwnerText, 0, wxBOTTOM|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 ); DownloadLabel = new wxStaticText( this, wxID_ANY, _("Download:"), wxDefaultPosition, wxDefaultSize, 0 ); DownloadLabel->Wrap( -1 ); FlexGridSizer->Add( DownloadLabel, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); wxBoxSizer* DownloadSizer; DownloadSizer = new wxBoxSizer( wxHORIZONTAL ); wxString m_DownloadChoiceChoices[] = { _( "Manually" ), _( "Only if contains" ), _( "Everything" ) }; int m_DownloadChoiceNChoices = sizeof( m_DownloadChoiceChoices ) / sizeof( wxString ); m_DownloadChoice = new wxChoice( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_DownloadChoiceNChoices, m_DownloadChoiceChoices, 0 ); m_DownloadChoice->SetSelection( channel->m_DownloadType ); DownloadSizer->Add( m_DownloadChoice, 0, wxTOP|wxBOTTOM|wxRIGHT, 5 ); m_DownloadText = new wxTextCtrl( this, wxID_ANY, channel->m_DownloadText, wxDefaultPosition, wxDefaultSize, 0 ); m_DownloadText->Enable( ( channel->m_DownloadType == guPODCAST_DOWNLOAD_FILTER ) ); DownloadSizer->Add( m_DownloadText, 1, wxEXPAND|wxALIGN_CENTER_VERTICAL|wxALL, 5 ); FlexGridSizer->Add( DownloadSizer, 1, wxEXPAND, 5 ); DeleteLabel = new wxStaticText( this, wxID_ANY, _("Delete:"), wxDefaultPosition, wxDefaultSize, 0 ); DeleteLabel->Wrap( -1 ); FlexGridSizer->Add( DeleteLabel, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); m_DeleteCheckBox = new wxCheckBox( this, wxID_ANY, _( "Allow delete old items" ), wxDefaultPosition, wxDefaultSize, 0 ); m_DeleteCheckBox->SetValue( channel->m_AllowDelete ); FlexGridSizer->Add( m_DeleteCheckBox, 0, wxBOTTOM|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5 ); ChannelSizer->Add( FlexGridSizer, 1, wxEXPAND, 5 ); MainSizer->Add( ChannelSizer, 1, wxEXPAND|wxALL, 5 ); ButtonsSizer = new wxStdDialogButtonSizer(); ButtonsSizerOK = new wxButton( this, wxID_OK ); ButtonsSizer->AddButton( ButtonsSizerOK ); ButtonsSizerCancel = new wxButton( this, wxID_CANCEL ); ButtonsSizer->AddButton( ButtonsSizerCancel ); ButtonsSizer->SetAffirmativeButton( ButtonsSizerOK ); ButtonsSizer->SetCancelButton( ButtonsSizerCancel ); ButtonsSizer->Realize(); MainSizer->Add( ButtonsSizer, 0, wxEXPAND|wxBOTTOM|wxRIGHT|wxLEFT, 5 ); this->SetSizer( MainSizer ); this->Layout(); ButtonsSizerOK->SetDefault(); // Bind Events m_DownloadChoice->Bind( wxEVT_CHOICE, &guChannelEditor::OnDownloadChoice, this ); Bind( guChannelEditorEvent, &guChannelEditor::OnChannelImageUpdated, this, guCHANNELEDITOR_EVENT_UPDATE_IMAGE ); m_DescText->SetFocus(); }
// -------------------------------------------------------------------------------- // guLibUpdateThread::ExitCode guLibUpdateThread::Entry() { int Index; int Count; int LastIndex; wxCommandEvent evtup( wxEVT_MENU, ID_STATUSBAR_GAUGE_UPDATE ); evtup.SetInt( m_GaugeId ); wxCommandEvent evtmax( wxEVT_MENU, ID_STATUSBAR_GAUGE_SETMAX ); evtmax.SetInt( m_GaugeId ); if( m_ScanPath.IsEmpty() ) { Count = m_LibPaths.Count(); if( !Count ) { guLogError( wxT( "No library directories to scan" ) ); return 0; } // For every directory in the library scan for new files and add them to m_TrackFiles Index = 0; while( !TestDestroy() && ( Index < Count ) ) { guLogMessage( wxT( "Doing Library Update in %s" ), m_LibPaths[ Index ].c_str() ); ScanDirectory( m_LibPaths[ Index ] ); Index++; } } else { ScanDirectory( m_ScanPath, true ); } bool EmbeddMetadata = m_MediaViewer->GetMediaCollection()->m_EmbeddMetadata; // For every new track file update it in the database Count = m_TrackFiles.Count(); if( Count ) { m_Db->ExecuteUpdate( wxT( "BEGIN TRANSACTION;" ) ); Index = 0; evtmax.SetExtraLong( Count ); wxPostEvent( m_MainFrame, evtmax ); LastIndex = -1; while( !TestDestroy() ) { //guLogMessage( wxT( "%i - %i" ), Index, Count ); if( ( Index >= Count ) ) break; //guLogMessage( wxT( "Scanning: '%s'" ), m_TrackFiles[ Index ].c_str() ); m_Db->ReadFileTags( m_TrackFiles[ Index ], EmbeddMetadata ); //Sleep( 1 ); Index++; if( Index > LastIndex ) { evtup.SetExtraLong( Index ); wxPostEvent( m_MainFrame, evtup ); LastIndex = Index + 5; } } m_Db->ExecuteUpdate( wxT( "COMMIT TRANSACTION;" ) ); } Count = m_CueFiles.Count(); if( Count ) { m_Db->ExecuteUpdate( wxT( "BEGIN TRANSACTION;" ) ); evtmax.SetExtraLong( Count ); wxPostEvent( m_MainFrame, evtmax ); for( Index = 0; Index < Count; Index++ ) { // // Delete all files from the same cue files // wxString query = wxT( "DELETE FROM songs WHERE song_path = '" ); query += escape_query_str( wxPathOnly( m_CueFiles[ Index ] + wxT( "/" ) ) ); query += wxT( "' AND song_offset > 0" ); m_Db->ExecuteUpdate( query ); //guLogMessage( wxT( "DELETE:\n%s" ), query.c_str() ); } Index = 0; LastIndex = -1; while( !TestDestroy() ) { //guLogMessage( wxT( "%i - %i" ), Index, Count ); if( ( Index >= Count ) ) break; //guLogMessage( wxT( "Scanning: '%s'" ), m_TrackFiles[ Index ].c_str() ); m_Db->ReadFileTags( m_CueFiles[ Index ], EmbeddMetadata ); //Sleep( 1 ); Index++; if( Index > LastIndex ) { evtup.SetExtraLong( Index ); wxPostEvent( m_MainFrame, evtup ); LastIndex = Index + 5; } } m_Db->ExecuteUpdate( wxT( "COMMIT TRANSACTION;" ) ); } ProcessCovers(); Count = m_PlayListFiles.Count(); if( Count ) { m_Db->ExecuteUpdate( wxT( "BEGIN TRANSACTION;" ) ); Index = 0; evtmax.SetExtraLong( Count ); wxPostEvent( m_MainFrame, evtmax ); LastIndex = -1; while( !TestDestroy() ) { //guLogMessage( wxT( "%i - %i" ), Index, Count ); if( ( Index >= Count ) ) break; guPlaylistFile PlayList( m_PlayListFiles[ Index ] ); wxArrayInt PlayListIds; int ItemTrackId; int ItemIndex; int ItemCount; if( ( ItemCount = PlayList.Count() ) ) { for( ItemIndex = 0; ItemIndex < ItemCount; ItemIndex++ ) { if( wxFileExists( PlayList.GetItem( ItemIndex ).m_Location ) ) { ItemTrackId = m_Db->FindTrackFile( PlayList.GetItem( ItemIndex ).m_Location, NULL ); if( ItemTrackId ) { PlayListIds.Add( ItemTrackId ); } } } if( PlayListIds.Count() ) { if( m_Db->GetStaticPlayList( m_PlayListFiles[ Index ] ) == wxNOT_FOUND ) { m_Db->CreateStaticPlayList( m_PlayListFiles[ Index ], PlayListIds ); wxCommandEvent evt( wxEVT_MENU, ID_PLAYLIST_UPDATED ); evt.SetClientData( ( void * ) m_MediaViewer ); wxPostEvent( m_MainFrame, evt ); } } } Index++; if( Index > LastIndex ) { evtup.SetExtraLong( Index ); wxPostEvent( m_MainFrame, evtup ); LastIndex = Index + 5; } } m_Db->ExecuteUpdate( wxT( "COMMIT TRANSACTION;" ) ); } // // This cant be called here as wxBitmap do X11 calls and this can only be done from the main // thread. So we must call DoCleanUp from the main thread once this thread is finished. // in the OnLibraryUpdated Event handler // // delete all orphans entries // m_Db->DoCleanUp(); return 0; }
// -------------------------------------------------------------------------------- // int guAmazonCoverFetcher::ExtractImagesInfo( wxString &content ) { int RetVal = 0; wxStringInputStream ins( content ); wxXmlDocument XmlDoc( ins ); wxXmlNode * XmlSubNode; wxXmlNode * XmlNode = XmlDoc.GetRoot(); if( XmlNode && XmlNode->GetName() == wxT( "ItemSearchResponse" ) ) { XmlNode = XmlNode->GetChildren(); while( XmlNode ) { if( XmlNode->GetName() == wxT( "Items" ) ) { XmlNode = XmlNode->GetChildren(); while( XmlNode ) { if( XmlNode->GetName() == wxT( "Request" ) ) { XmlSubNode = XmlNode->GetChildren(); while( XmlSubNode ) { if( XmlSubNode->GetName() == wxT( "IsValid" ) ) { if( XmlSubNode->GetNodeContent() != wxT( "True" ) ) { guLogError( wxT( "There was an error in the amazon search request." ) ); } break; } XmlSubNode = XmlSubNode->GetNext(); } } else if( XmlNode->GetName() == wxT( "Errors" ) ) { XmlSubNode = XmlNode->GetChildren(); while( XmlSubNode ) { if( XmlSubNode->GetName() == wxT( "Error" ) ) { XmlSubNode = XmlSubNode->GetChildren(); while( XmlSubNode ) { if( XmlSubNode->GetName() == wxT( "Message" ) ) { guLogError( wxT( "Error: %s" ), XmlSubNode->GetNodeContent().c_str() ); break; } XmlSubNode = XmlSubNode->GetNext(); } return 0; } XmlSubNode = XmlSubNode->GetNext(); } } else if( XmlNode->GetName() == wxT( "Item" ) ) { wxArrayString CurItem = GetImageInfo( XmlNode ); if( CurItem.Count() ) { m_CoverLinks->Add( CurItem ); RetVal++; } } XmlNode = XmlNode->GetNext(); } break; } XmlNode = XmlNode->GetNext(); } } return RetVal; }