40#include <QDomDocument>
43#include <QCryptographicHash>
54 setWindowTitle( tr(
"Sound Library import" ) );
57 headers << tr(
"Sound library" ) << tr(
"Status" );
58 QTreeWidgetItem* header =
new QTreeWidgetItem( headers );
59 m_pDrumkitTree->setHeaderItem( header );
60 m_pDrumkitTree->header()->resizeSection( 0, 200 );
62 connect( m_pDrumkitTree, SIGNAL( currentItemChanged ( QTreeWidgetItem*, QTreeWidgetItem* ) ),
this, SLOT(
soundLibraryItemChanged( QTreeWidgetItem*, QTreeWidgetItem* ) ) );
65 SoundLibraryNameLbl->setText(
"" );
66 SoundLibraryInfoLbl->setText(
"" );
67 DownloadBtn->setEnabled(
false );
69 InstallBtn->setEnabled (
false );
74 setFixedSize( width(), height() );
77 tabWidget->setCurrentIndex( 0 );
79 tabWidget->setCurrentIndex( 1 );
89 pH2App->removeEventListener(
this );
103 pref->
sServerList.push_back(
"http://hydrogen-music.org/feeds/drumkit_list.php" );
106 repositoryCombo->clear();
108 std::list<QString>::const_iterator cur_Server;
110 repositoryCombo->insertItem( 0, *cur_Server );
119 if(!repositoryCombo->currentText().isEmpty())
145 INFOLOG(
"Deleting cached image files from " + cacheDir );
147 QDir dir( cacheDir );
148 dir.setNameFilters(QStringList() <<
"*.png");
149 dir.setFilter(QDir::Files);
150 foreach(QString dirFile, dir.entryList())
152 if ( !dir.remove(dirFile) )
154 WARNINGLOG(
"Error removing image file(s) from cache.");
162 QString serverMd5 = QString(QCryptographicHash::hash(( repositoryCombo->currentText().toLatin1() ),QCryptographicHash::Md5).toHex());
163 QString cacheFile = cacheDir +
"/" + serverMd5;
170 QString kitNameMd5 = QString(QCryptographicHash::hash(( SoundLibraryNameLbl->text().toLatin1() ),QCryptographicHash::Md5).toHex());
171 QString cacheFile = cacheDir +
"/" + kitNameMd5 +
".png";
183 QFile outFile( fileName );
184 if( !outFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
186 ERRORLOG( QString(
"Failed to open file for writing repository cache: %1").arg( fileName ) );
190 QTextStream stream( &outFile );
200 QFile outFile( cacheFile );
201 if( !outFile.open( QIODevice::WriteOnly ) )
203 ERRORLOG( QString(
"Failed to open file for writing repository image cache: %1").arg( imageFile ) );
207 pixmap.save(&outFile);
215 QFile inFile( fileName );
216 if( !inFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
218 ERRORLOG( QString(
"Failed to open file for reading: %1").arg( fileName ) );
222 QDomDocument document;
223 if( !document.setContent( &inFile ) )
230 content = document.toString();
239 QFile file( cacheFile );
261 dom.setContent( sDrumkitXML );
262 QDomNode drumkitNode = dom.documentElement().firstChild();
263 while ( !drumkitNode.isNull() ) {
264 if( !drumkitNode.toElement().isNull() ) {
266 if ( drumkitNode.toElement().tagName() ==
"drumkit" || drumkitNode.toElement().tagName() ==
"song" || drumkitNode.toElement().tagName() ==
"pattern" ) {
270 if ( drumkitNode.toElement().tagName() ==
"song" ) {
271 soundLibInfo.
setType(
"song" );
274 if ( drumkitNode.toElement().tagName() ==
"drumkit" ) {
275 soundLibInfo.
setType(
"drumkit" );
278 if ( drumkitNode.toElement().tagName() ==
"pattern" ) {
279 soundLibInfo.
setType(
"pattern" );
282 QDomElement nameNode = drumkitNode.firstChildElement(
"name" );
283 if ( !nameNode.isNull() ) {
284 soundLibInfo.
setName( nameNode.text() );
287 QDomElement urlNode = drumkitNode.firstChildElement(
"url" );
288 if ( !urlNode.isNull() ) {
289 soundLibInfo.
setUrl( urlNode.text() );
292 QDomElement infoNode = drumkitNode.firstChildElement(
"info" );
293 if ( !infoNode.isNull() ) {
294 soundLibInfo.
setInfo( infoNode.text() );
297 QDomElement authorNode = drumkitNode.firstChildElement(
"author" );
298 if ( !authorNode.isNull() ) {
299 soundLibInfo.
setAuthor( authorNode.text() );
302 QDomElement licenseNode = drumkitNode.firstChildElement(
"license" );
303 if ( !licenseNode.isNull() ) {
304 soundLibInfo.
setLicense( licenseNode.text() );
307 QDomElement imageNode = drumkitNode.firstChildElement(
"image" );
308 if ( !imageNode.isNull() ) {
309 soundLibInfo.
setImage( imageNode.text() );
312 QDomElement imageLicenseNode = drumkitNode.firstChildElement(
"imageLicense" );
313 if ( !imageLicenseNode.isNull() ) {
321 drumkitNode = drumkitNode.nextSibling();
333 QApplication::setOverrideCursor(Qt::WaitCursor);
334 QString downloadUrl = repositoryCombo->currentText();
338 DownloadWidget drumkitList(
this, tr(
"Updating SoundLibrary list..." ), downloadUrl);
343 }
else if (drumkitList.
get_error().isEmpty()) {
352 QMessageBox::warning(
this,
"Hydrogen", drumkitList.
get_error() );
373 QApplication::restoreOverrideCursor();
382 m_pDrumkitTree->clear();
389 m_pSongItem =
new QTreeWidgetItem( m_pDrumkitTree );
400 QTreeWidgetItem* pDrumkitItem =
nullptr;
412 pDrumkitItem->setText( 0, sLibraryName );
413 pDrumkitItem->setText( 1, tr(
"Installed" ) );
416 pDrumkitItem->setText( 0, sLibraryName );
417 pDrumkitItem->setText( 1, tr(
"New" ) );
440 QString sName = QFileInfo( sInfo.
getUrl() ).fileName();
441 sName = sName.left( sName.lastIndexOf(
"." ) );
443 if ( sInfo.
getType() ==
"drumkit" ) {
449 if ( sInfo.
getType() ==
"pattern" ) {
454 if ( sInfo.
getType() ==
"song" ) {
474 int x = (int) drumkitImageLabel->size().width();
475 int y = drumkitImageLabel->size().height();
476 float labelAspect = (float) x / y;
477 float imageAspect = (float) pixmap.width() / pixmap.height();
479 if ( ( x < pixmap.width() ) || ( y < pixmap.height() ) )
481 if ( labelAspect >= imageAspect )
484 pixmap = pixmap.scaledToHeight( y );
489 pixmap = pixmap.scaledToWidth( x );
492 drumkitImageLabel->setPixmap( pixmap );
502 QString selected = current->text(0);
509 SoundLibraryNameLbl->setText( info.
getName() );
511 if( info.
getType() ==
"pattern" ){
512 SoundLibraryInfoLbl->setText(
"");
514 SoundLibraryInfoLbl->setText( info.
getInfo() );
517 AuthorLbl->setText( tr(
"Author: %1" ).arg( info.
getAuthor() ) );
519 LicenseLbl->setText( tr(
"Drumkit License: %1" )
522 ImageLicenseLbl->setText( tr(
"Image License: %1" )
527 drumkitImageLabel->setPixmap( QPixmap() );
528 drumkitImageLabel->setText( info.
getImage() );
530 if ( info.
getImage().length() > 0 ) {
533 QString sName = QFileInfo( info.
getUrl() ).fileName();
534 sName = sName.left( sName.lastIndexOf(
"." ) );
538 if ( pDrumkit !=
nullptr ) {
540 QPixmap pixmap ( pDrumkit->get_path() +
"/" + pDrumkit->get_image() );
541 INFOLOG(
"Loaded image " + pDrumkit->get_image() +
" from local filesystem");
553 if ( cachedFile.length() > 0 ) {
554 QPixmap pixmap ( cachedFile );
556 INFOLOG(
"Loaded image " + info.
getImage() +
" from cache (" + cachedFile +
")" );
565 if ( info.
getImage().length() > 0 ) {
569 sImageUrl = repositoryCombo->currentText().left( repositoryCombo->currentText().lastIndexOf( QString(
"/" )) + 1 ) + info.
getImage() ;
570 sLocalFile = QDir::tempPath() +
"/" + QFileInfo( sImageUrl ).fileName();
577 QFile::remove( sLocalFile );
583 DownloadBtn->setEnabled(
true );
589 SoundLibraryNameLbl->setText(
"" );
590 SoundLibraryInfoLbl->setText(
"" );
591 AuthorLbl->setText(
"" );
592 DownloadBtn->setEnabled(
false );
599 QApplication::setOverrideCursor(Qt::WaitCursor);
600 QString selected = m_pDrumkitTree->currentItem()->text(0);
609 if( sType ==
"drumkit") {
610 sLocalFile = QDir::tempPath() +
"/" + QFileInfo( sURL ).fileName();
613 if( sType ==
"song") {
617 if( sType ==
"pattern") {
624 DownloadWidget dl(
this, tr(
"Downloading SoundLibrary..." ), sURL, sLocalFile );
628 if (redirect_url.isEmpty() ) {
634 sURL = redirect_url.toEncoded();
645 if ( sType ==
"drumkit" ) {
647 QApplication::restoreOverrideCursor();
651 if ( sType ==
"song" || sType ==
"pattern") {
652 QApplication::restoreOverrideCursor();
656 QApplication::restoreOverrideCursor();
657 QMessageBox::warning(
this,
"Hydrogen", tr(
"An error occurred importing the SoundLibrary." ) );
662 QApplication::restoreOverrideCursor();
665 QApplication::setOverrideCursor(Qt::WaitCursor);
667 if( sType ==
"drumkit" ) {
669 dir.remove( sLocalFile );
674 QApplication::restoreOverrideCursor();
687 sPath = QDir::homePath();
691 fd.setAcceptMode( QFileDialog::AcceptOpen );
692 fd.setFileMode(QFileDialog::ExistingFile);
693 fd.setNameFilter(
"Hydrogen drumkit (*.h2drumkit)" );
694 fd.setDirectory( sPath );
696 fd.setWindowTitle( tr(
"Import drumkit" ) );
698 QString filename =
"";
699 if (fd.exec() == QDialog::Accepted) {
700 filename = fd.selectedFiles().first();
703 if (filename !=
"") {
704 SoundLibraryPathTxt->setText( filename );
706 InstallBtn->setEnabled (
true );
715 QApplication::setOverrideCursor(Qt::WaitCursor);
721 QApplication::restoreOverrideCursor();
722 QMessageBox::information(
this,
"Hydrogen",
723 QString( tr(
"SoundLibrary imported in %1" )
727 QApplication::restoreOverrideCursor();
728 QMessageBox::warning(
this,
"Hydrogen", tr(
"An error occurred importing the SoundLibrary." ) );
const QString & get_xml_content()
const QString & get_error()
Custom file dialog checking whether the user has write access to the selected folder before allowing ...
static bool install(const QString &sSourcePath, const QString &sTargetPath="", bool bSilent=false)
Extract a .h2drumkit file.
static bool dir_readable(const QString &path, bool silent=false)
returns true if the given path is a readable regular directory
static bool drumkit_exists(const QString &dk_name)
returns true if the drumkit exists within usable system or user drumkits
static QString songs_dir()
returns user songs path
static QString repositories_cache_dir()
returns user repository cache path
static bool file_exists(const QString &path, bool silent=false)
returns true if the given path is an existing regular file
static QString usr_data_path()
returns user data path
static bool song_exists(const QString &sg_name)
returns true if the song file exists
static QString patterns_dir()
returns user patterns path
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
SoundLibraryDatabase * getSoundLibraryDatabase() const
QString getLicenseString() const
Manager for User Preferences File (singleton)
QString getLastImportDrumkitDirectory() const
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
std::list< QString > sServerList
void setLastImportDrumkitDirectory(QString sPath)
bool isPatternInstalled(const QString &sPatternName) const
std::shared_ptr< Drumkit > getDrumkit(const QString &sDrumkitPath, bool bLoad=true)
Retrieve a drumkit from the database.
This class holds information about a soundlibrary.
QString getAuthor() const
void setAuthor(const QString &author)
void setInfo(const QString &info)
void setUrl(const QString &url)
H2Core::License getLicense() const
void setImage(const QString &image)
void setLicense(const H2Core::License &license)
void setName(const QString &name)
void setImageLicense(const H2Core::License &imageLicense)
H2Core::License getImageLicense() const
void setType(const QString &type)
static HydrogenApp * get_instance()
Returns the instance of HydrogenApp class.
std::vector< H2Core::SoundLibraryInfo > m_soundLibraryList
void loadImage(QString img)
QTreeWidgetItem * m_pDrumkitsItem
bool isSoundLibraryItemAlreadyInstalled(H2Core::SoundLibraryInfo sInfo)
Is the SoundLibrary already installed?
void on_BrowseBtn_clicked()
void writeCachedData(const QString &fileName, const QString &data)
QString getCachedImageFilename()
QString getCachedFilename()
~SoundLibraryImportDialog()
QString readCachedData(const QString &fileName)
void updateSoundLibraryList()
QTreeWidgetItem * m_pSongItem
void showImage(QPixmap pixmap)
QString readCachedImage(const QString &imageFile)
virtual void soundLibraryChangedEvent() override
void soundLibraryItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)
void on_UpdateListBtn_clicked()
Download and update the drumkit list.
void onRepositoryComboBoxIndexChanged(int)
void writeCachedImage(const QString &imageFile, QPixmap &pixmap)
SoundLibraryImportDialog(QWidget *pParent, bool bOnlineImport)
void updateRepositoryCombo()
void on_InstallBtn_clicked()
QTreeWidgetItem * m_pPatternItem
void on_EditListBtn_clicked()
Edit the server list.
void reloadRepositoryData()
void on_DownloadBtn_clicked()
void on_close_btn_clicked()