Go to the documentation of this file.
2 #include <QApplication>
4 #include <QFontMetrics>
35 MThread(
"FileScanner"), m_parent(parent)
142 for (
int i = 0; i < actions.size() && !handled; i++)
144 QString
action = actions[i];
151 else if (
action ==
"RIGHT")
155 else if (
action ==
"EDIT")
159 else if (
action ==
"MENU")
169 while (track < m_tracks->size())
181 QString msg = tr(
"You might have unsaved changes.\nAre you sure you want to exit this screen?");
268 LOG(VB_GENERAL, LOG_ERR,
"Cannot load screen 'import_music'");
302 fb->SetTypeFilter(QDir::AllDirs | QDir::Readable);
305 fb->SetReturnEvent(
this,
"locationchange");
367 QString origFilename = meta->
Filename();
369 QString fullFilename;
376 QFileInfo fi(origFilename);
377 saveFilename +=
"." + fi.suffix();
378 fullFilename +=
"." + fi.suffix();
380 LOG(VB_FILE, LOG_INFO, QString(
"Copying file from: %1").arg(origFilename));
381 LOG(VB_FILE, LOG_INFO, QString(
"to: ").arg(fullFilename));
384 if (!
copyFile(origFilename, fullFilename))
386 ShowOkPopup(tr(
"Copy Failed\nCould not copy file to: %1").arg(fullFilename));
392 meta->
setFileSize((quint64)QFileInfo(origFilename).size());
410 ShowOkPopup(tr(
"This track is already in the database"));
424 QCoreApplication::processEvents();
432 QCoreApplication::processEvents();
439 ShowOkPopup(tr(
"%1 new tracks were added to the database").arg(newCount));
448 while (track < m_tracks->size())
463 QString host = QUrl(dst).host();
467 new MythUIBusyDialog(tr(
"Copying music file to the 'Music' storage group on %1").arg(host),
484 while (!
copy->isFinished())
486 const struct timespec halfms {0, 500000};
487 nanosleep(&halfms,
nullptr);
488 QCoreApplication::processEvents();
491 res =
copy->GetResult();
505 if (!location.endsWith(
'/'))
506 location.append(
'/');
510 popupStack,
"scanbusydialog");
524 while (!scanner->isFinished())
526 const struct timespec halfms {0, 500000};
527 nanosleep(&halfms,
nullptr);
528 QCoreApplication::processEvents();
555 d.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
556 const QFileInfoList list =
d.entryInfoList();
560 QFileInfoList::const_iterator it = list.begin();
561 while (it != list.end())
563 const QFileInfo *fi = &(*it);
565 QString
filename = fi->absoluteFilePath();
580 track->metadataHasChanged =
false;
581 tracks->push_back(track);
602 if (!editDialog->Create())
608 editDialog->setSaveMetadataOnly();
641 menu->SetReturnEvent(
this,
"menu");
648 menu->AddButton(tr(
"Change Compilation Artist"),
660 QStringList hostList;
664 QString sql =
"SELECT DISTINCT hostname "
666 "WHERE groupname = 'Music'";
668 MythDB::DBError(
"ImportMusicDialog::chooseBackend get host list", query);
673 hostList.append(query.
value(0).toString());
677 if (hostList.isEmpty())
679 LOG(VB_GENERAL, LOG_ERR,
"ImportMusicDialog::chooseBackend: No backends found");
683 QString msg = tr(
"Select where to save tracks");
688 if (!searchDlg->Create())
704 if (dirs.count() > 0)
826 QString title = locale.toLower(data->
Title().simplified());
827 title[0] = title[0].toUpper();
836 QString title = locale.toLower(data->
Title().simplified());
837 QStringList title_words = title.split(
' ');
840 for (
int x = 0; x < title_words.size(); ++x)
841 title_words[x][0] = title_words[x][0].toUpper();
843 data->
setTitle(title_words.join(
' '));
861 if (import->Create())
871 if (dce->GetId() ==
"locationchange")
889 for (
int i = 0; i < actions.size() && !handled; i++)
891 QString
action = actions[i];
898 else if (
action ==
"RIGHT")
931 LOG(VB_GENERAL, LOG_ERR,
"Cannot load screen 'import_coverart'");
942 QVariant::fromValue((
int)
IT_CD));
944 QVariant::fromValue((
int)
IT_INLAY));
1031 "*.png;*.jpg;*.jpeg;*.gif;*.bmp");
1033 QFileInfoList list =
d.entryInfoList(nameFilter.split(
";"),
1034 QDir::Files | QDir::Dirs |
1035 QDir::NoDotAndDotDot);
1039 for (
const auto & fi : qAsConst(list))
1041 QString
filename = fi.absoluteFilePath();
1070 QString fullFilename;
1074 QString dir = fullFilename.section(
'/', 0, -2);
1080 saveFilename =
"front." + fi.suffix();
1083 saveFilename =
"back." + fi.suffix();
1086 saveFilename =
"cd." + fi.suffix();
1089 saveFilename =
"inlay." + fi.suffix();
1092 saveFilename =
"unknown." + fi.suffix();
1095 saveFilename = fi.fileName();
1128 if (
filename.contains(
"front", Qt::CaseInsensitive))
1130 else if (
filename.contains(
"back", Qt::CaseInsensitive))
1132 else if (
filename.contains(
"inlay", Qt::CaseInsensitive))
1134 else if (
filename.contains(
"cd", Qt::CaseInsensitive))
MythUIButton * m_prevButton
bool isActive(void) const
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
QSqlQuery wrapper that fetches a DB connection from the connection pool.
MythScreenStack * GetMainStack()
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Provide a dialog to quickly find an entry in a list.
QString GetMasterHostName(void)
void setTitleWordCaps(void)
bool m_somethingWasImported
void Reset(void) override
Reset the widget to it's original state, should not reset changes made by the theme.
void importFinished(void)
void nextNewPressed(void)
bool Create(void) override
void setCompilationArtist(void)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
MythUIButton * m_scanButton
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
MythUIText * m_statusText
QVariant value(int i) const
MythUICheckBox * m_compilationCheck
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
QStringList m_sourceFiles
MythUIText * m_filenameText
bool isPlaying(void) const
void coverArtPressed(void)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
bool m_defaultCompilation
Screen in which all other widgets are contained and rendered.
std::vector< TrackInfo * > * m_tracks
void locationPressed(void)
void updateTypeSelector(void)
bool Create(void) override
QString GetText(void) const
void ShowMenu(void) override
void Reset(void) override
Reset the image back to the default defined in the theme.
MythUIButton * m_copyButton
MythUIText * m_currentText
MythUIButton * m_addButton
MythUIType * GetFocusWidget(void) const
bool isNewTune(const QString &artist, const QString &album, const QString &title)
try to find a track in the db using the given artist, album and title
MusicMetadata * getCurrentMetadata(void)
get the metadata for the current track in the playlist
void setTitleInitialCap(void)
void SetText(const QString &text, bool moveCursor=true)
void metadataChanged(void)
MusicMetadata * m_metadata
QString m_musicStorageDir
static QString GenMythURL(const QString &host=QString(), int port=0, QString path=QString(), const QString &storageGroup=QString())
MusicMetadata * m_playingMetaData
MythUIButton * m_prevButton
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
~ImportMusicDialog() override
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size=0)
Copies src file to dst file.
Basic menu dialog, message and a list of options.
QString filenameFromMetadata(MusicMetadata *track)
create a filename using the template in the settings and a MusicMetadata object
MythUIButton * m_nextButton
static MythThemedMenu * menu
static MSqlQueryInfo InitCon(ConnectionReuse _reuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
void showEditMetadataDialog(void)
static void DBError(const QString &where, const MSqlQuery &query)
MythUIText * m_artistText
MythUIText * m_compartistText
void BuildFocusList(void)
MythUIButton * m_nextnewButton
MythUIButton * m_exitButton
static QStringList getGroupDirs(const QString &groupname, const QString &host)
void selectorChanged(void)
ImportMusicDialog(MythScreenStack *parent)
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
static QString FindFile(const QString &filename, const QString &host, const QString &storageGroup, bool useRegex=false, bool allowFallback=false)
Search all BE's for a file in the give storage group.
MythUIText * m_filenameText
void scanDirectory(QString &directory, std::vector< TrackInfo * > *tracks)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
static bool CopyFile(const QString &src, const QString &dst, bool overwrite=false, bool verify=false)
void chooseBackend(void) const
static bool Assign(ContainerType *container, UIType *&item, const QString &name, bool *err=nullptr)
MythUITextEdit * m_locationEdit
MythUIButton * m_locationButton
QString m_musicStorageDir
MythUIButtonList * m_typeList
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
MythUIButton * m_addallnewButton
MythUIButton * m_playButton
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
void SetCheckState(MythUIStateType::StateType state)
QString m_defaultCompArtist
ImportMusicDialog * m_parent
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Event dispatched from MythUI modal dialogs to a listening class containing a result of some form.
virtual void SetText(const QString &text)
virtual void SetVisible(bool visible)
This is a wrapper around QThread that does several additional things.
MythUIImage * m_coverartImage
MythMainWindow * GetMythMainWindow(void)
static bool copyFile(const QString &src, const QString &dst)
MythUIText * m_destinationText
MythUIButton * m_coverartButton
MythUIText * m_currentText
MythUIText * m_statusText
MythScreenStack * GetStack(const QString &Stackname)
void setSaveHost(const QString &host)
void showImportCoverArtDialog()
void playFile(const MusicMetadata &mdata)
void setCompilation(void)
void stop(bool stopAll=false)
static const iso6937table * d
MythUIButton * m_nextButton
void SaveSetting(const QString &key, int newValue)
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
void addImage(const AlbumArtImage *newImage)
void dumpToDatabase(void)
saves or updates the image details in the DB
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void customEvent(QEvent *event) override
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
FileScannerThread(ImportMusicDialog *parent)
QString GetSetting(const QString &key, const QString &defaultval="")
void addAllNewPressed(void)