void MusicScanner::scanFolder(MusicLibraryItemRoot *library, const QString &topLevel, const QString &f, QSet<FileOnlySong> &existing, int level) { if (stopRequested) { return; } if (level<4) { QDir d(f); QFileInfoList entries=d.entryInfoList(QDir::Files|QDir::NoSymLinks|QDir::Dirs|QDir::NoDotAndDotDot); MusicLibraryItemArtist *artistItem = 0; MusicLibraryItemAlbum *albumItem = 0; foreach (const QFileInfo &info, entries) { if (stopRequested) { return; } if (info.isDir()) { scanFolder(library, topLevel, info.absoluteFilePath(), existing, level+1); } else if(info.isReadable()) { Song song; QString fname=info.absoluteFilePath().mid(topLevel.length()); if (fname.endsWith(".jpg", Qt::CaseInsensitive) || fname.endsWith(".png", Qt::CaseInsensitive) || fname.endsWith(".lyrics", Qt::CaseInsensitive) || fname.endsWith(".pamp", Qt::CaseInsensitive)) { continue; } song.file=fname; QSet<FileOnlySong>::iterator it=existing.find(song); if (existing.end()==it) { song=Tags::read(info.absoluteFilePath()); song.file=fname; } else { song=*it; existing.erase(it); } if (song.isEmpty()) { continue; } count++; int t=time(NULL); if ((t-lastUpdate)>=2 || 0==(count%5)) { lastUpdate=t; emit songCount(count); } song.fillEmptyFields(); song.size=info.size(); if (!artistItem || song.artistOrComposer()!=artistItem->data()) { artistItem = library->artist(song); } if (!albumItem || albumItem->parentItem()!=artistItem || song.albumName()!=albumItem->data()) { albumItem = artistItem->album(song); } MusicLibraryItemSong *songItem = new MusicLibraryItemSong(song, albumItem); albumItem->append(songItem); albumItem->addGenre(song.genre); artistItem->addGenre(song.genre); library->addGenre(song.genre); } } }
void CStatThread::run() { //count files _fileCount = 0; _fileSize = 0; _lineCount = 0; foreach( const QString& folder, _folders) { QDir d(folder); scanFolder(d); }
void MusicScanner::scan(const QString &folder, const QString &cacheFile, bool readCache, const QSet<FileOnlySong> &existingSongs) { lastCacheProg=-1; if (!cacheFile.isEmpty() && readCache) { MusicLibraryItemRoot *lib=new MusicLibraryItemRoot; MusicLibraryModel::convertCache(cacheFile); readProgress(0.0); if (lib->fromXML(cacheFile, QDateTime(), folder)) { lib->applyGrouping(); if (!stopRequested) { emit libraryUpdated(lib); } else { delete lib; } return; } else { delete lib; } } if (stopRequested) { return; } count=0; lastUpdate=0; MusicLibraryItemRoot *library = new MusicLibraryItemRoot; QString topLevel=Utils::fixPath(QDir(folder).absolutePath()); QSet<FileOnlySong> existing=existingSongs; scanFolder(library, topLevel, topLevel, existing, 0); if (!stopRequested) { library->applyGrouping(); if (!cacheFile.isEmpty()) { writeProgress(0.0); library->toXML(cacheFile, QDateTime(), this); } emit libraryUpdated(library); } else { delete library; } }
void MusicScanner::scan(const QString &folder, const QString &cacheFile, bool readCache, const QSet<FileOnlySong> &existingSongs) { if (!cacheFile.isEmpty() && readCache) { MusicLibraryItemRoot *lib=new MusicLibraryItemRoot; readProgress(0.0); if (lib->fromXML(cacheFile, 0, 0, folder)) { if (!stopRequested) { emit libraryUpdated(lib); } else { delete lib; } return; } else { delete lib; } } if (stopRequested) { return; } count=0; MusicLibraryItemRoot *library = new MusicLibraryItemRoot; QString topLevel=Utils::fixPath(QDir(folder).absolutePath()); QSet<FileOnlySong> existing=existingSongs; timer.start(); scanFolder(library, topLevel, topLevel, existing, 0); if (!stopRequested) { if (!cacheFile.isEmpty()) { writeProgress(0.0); library->toXML(cacheFile, 0, false, this); } emit libraryUpdated(library); } else { delete library; } }
MyMainWindow::MyMainWindow(EventManager *event_manager, MediaPlayer *p) : MainWindow(0, Rect(0, 0, GRSYS_WIDTH, GRSYS_HEIGHT), event_manager), m_headText(event_manager, Rect(rect().x(), rect().y(), rect().w(), 24)), m_playPos(Rect(), this), m_lastTouchedButton(0), m_functionalTab(Rect(0, rect().h()-48, rect().w(), 48), this, TabBox::Horizontal), m_stopButton(Rect(), this, ""), m_prevButton(Rect(), this, ""), m_playButton(Rect(), this, ""), m_nextButton(Rect(), this, ""), m_mediaList(Rect(4, 0, rect().w()-8, 0), this), m_musicImage(resource_manager->image("music")), setup_handle(-1), m_player(p), m_currentPlayedItem(0) { setup_handle = SetUP_GetHandle(); m_playImg = &resource_manager->image("play"); m_stopImg = &resource_manager->image("stop"); m_pauseImg = &resource_manager->image("pause"); m_prevImg = &resource_manager->image("prev"); m_nextImg = &resource_manager->image("next"); m_headText.setText( path2name(m_player->file()) ); m_headText.start(200); m_headText.setTextSize(18); m_headText.setTextAttrs(FT_TEXT_H_CENTER); m_playPos.setSize( Rect(9, rect().h()-78, rect().w()-18, 16) ); m_playPos.show(); m_playPos.positionSelected().connect( [this](int pos) { //printf("Percent: %d\n", pos); unsigned int ms = m_player->length()*pos / 100; m_player->seek(ms); }); //m_timer.start(1000); m_timer.timerEventSignal().connect( [this](Timer *) { eventManager()->updateAfterEvent(); }); m_functionalTab.show(); m_functionalTab.addTab("List"); m_functionalTab.addTab("Play"); m_functionalTab.addTab("Info"); m_functionalTab.addTab("Exit"); m_functionalTab.setFocusTab(1); m_functionalTab.onTabChanged().connect( this, &MyMainWindow::tabBoxChanged, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); setupMediaButtons(); ListMenuStyle menu_style = m_mediaList.style(); menu_style.setShadow( Brush() ); menu_style.setBackground( Brush() ); m_mediaList.setStyle(menu_style); Rect rc = m_mediaList.rect(); rc.setY(m_headText.size().h() + m_prevButton.rect().h()+10); rc.setH( rect().h() - (m_mediaList.rect().y() + (rect().h() - m_playPos.rect().y()) + 90 )); m_mediaList.setSize(rc); m_mediaList.resizeEvent(); scanFolder(); m_player->endAction().connect( [this](MediaPlayer *){ playNext(); }); }