Improved initialization of the working banner. Also banner can now be minimized using the "M" key.

This commit is contained in:
LoRd_MuldeR 2013-11-29 01:20:59 +01:00
parent 578bcb60bd
commit ed34cf1fc8
4 changed files with 130 additions and 65 deletions

View File

@ -88,6 +88,32 @@
} \ } \
while(0) while(0)
#define SHOW_BANNER(TXT) do \
{ \
INIT_BANNER(); \
m_banner->show((TXT)); \
} \
while(0)
#define SHOW_BANNER_ARG(TXT, ARG) do \
{ \
INIT_BANNER(); \
m_banner->show((TXT), (ARG)); \
} \
while(0)
#define SHOW_BANNER_CONDITIONALLY(FLAG, TEST, TXT) do \
{ \
if((!(FLAG)) && ((TEST))) \
{ \
INIT_BANNER(); \
m_banner->show((TXT)); \
FLAG = true; \
} \
} \
while(0)
#define ABORT_IF_BUSY do \ #define ABORT_IF_BUSY do \
{ \ { \
if(BANNER_VISIBLE || m_delayedFileTimer->isActive()) \ if(BANNER_VISIBLE || m_delayedFileTimer->isActive()) \
@ -617,17 +643,19 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel_MetaInfo *me
//Create message handler thread //Create message handler thread
m_messageHandler = new MessageHandlerThread(); m_messageHandler = new MessageHandlerThread();
m_delayedFileList = new QStringList();
m_delayedFileTimer = new QTimer();
m_delayedFileTimer->setSingleShot(true);
m_delayedFileTimer->setInterval(5000);
connect(m_messageHandler, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection); connect(m_messageHandler, SIGNAL(otherInstanceDetected()), this, SLOT(notifyOtherInstance()), Qt::QueuedConnection);
connect(m_messageHandler, SIGNAL(fileReceived(QString)), this, SLOT(addFileDelayed(QString)), Qt::QueuedConnection); connect(m_messageHandler, SIGNAL(fileReceived(QString)), this, SLOT(addFileDelayed(QString)), Qt::QueuedConnection);
connect(m_messageHandler, SIGNAL(folderReceived(QString, bool)), this, SLOT(addFolderDelayed(QString, bool)), Qt::QueuedConnection); connect(m_messageHandler, SIGNAL(folderReceived(QString, bool)), this, SLOT(addFolderDelayed(QString, bool)), Qt::QueuedConnection);
connect(m_messageHandler, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection); connect(m_messageHandler, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection);
connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
m_messageHandler->start(); m_messageHandler->start();
//Init delayed file handling
m_delayedFileList = new QStringList();
m_delayedFileTimer = new QTimer();
m_delayedFileTimer->setSingleShot(true);
m_delayedFileTimer->setInterval(5000);
connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
//Load translation //Load translation
initializeTranslation(); initializeTranslation();
@ -636,6 +664,7 @@ MainWindow::MainWindow(FileListModel *fileListModel, AudioFileModel_MetaInfo *me
changeEvent(&languageChangeEvent); changeEvent(&languageChangeEvent);
//Enable Drag & Drop //Enable Drag & Drop
m_droppedFileList = new QList<QUrl>();
this->setAcceptDrops(true); this->setAcceptDrops(true);
} }
@ -668,6 +697,7 @@ MainWindow::~MainWindow(void)
LAMEXP_DELETE(m_banner); LAMEXP_DELETE(m_banner);
LAMEXP_DELETE(m_fileSystemModel); LAMEXP_DELETE(m_fileSystemModel);
LAMEXP_DELETE(m_messageHandler); LAMEXP_DELETE(m_messageHandler);
LAMEXP_DELETE(m_droppedFileList);
LAMEXP_DELETE(m_delayedFileList); LAMEXP_DELETE(m_delayedFileList);
LAMEXP_DELETE(m_delayedFileTimer); LAMEXP_DELETE(m_delayedFileTimer);
LAMEXP_DELETE(m_metaInfoModel); LAMEXP_DELETE(m_metaInfoModel);
@ -708,7 +738,8 @@ void MainWindow::addFiles(const QStringList &files)
return; return;
} }
ui->tabWidget->setCurrentIndex(0); WITH_BLOCKED_SIGNALS(ui->tabWidget, setCurrentIndex, 0);
tabPageChanged(ui->tabWidget->currentIndex(), true);
INIT_BANNER(); INIT_BANNER();
FileAnalyzer *analyzer = new FileAnalyzer(files); FileAnalyzer *analyzer = new FileAnalyzer(files);
@ -763,13 +794,11 @@ void MainWindow::addFiles(const QStringList &files)
*/ */
void MainWindow::addFolder(const QString &path, bool recursive, bool delayed) void MainWindow::addFolder(const QString &path, bool recursive, bool delayed)
{ {
INIT_BANNER();
QFileInfoList folderInfoList; QFileInfoList folderInfoList;
folderInfoList << QFileInfo(path); folderInfoList << QFileInfo(path);
QStringList fileList; QStringList fileList;
m_banner->show(tr("Scanning folder(s) for files, please wait...")); SHOW_BANNER(tr("Scanning folder(s) for files, please wait..."));
QApplication::processEvents(); QApplication::processEvents();
lamexp_check_escape_state(); lamexp_check_escape_state();
@ -792,7 +821,7 @@ void MainWindow::addFolder(const QString &path, bool recursive, bool delayed)
fileList << fileInfoList.takeFirst().canonicalFilePath(); fileList << fileInfoList.takeFirst().canonicalFilePath();
} }
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
if(recursive) if(recursive)
{ {
@ -947,7 +976,8 @@ void MainWindow::showEvent(QShowEvent *event)
if(!event->spontaneous()) if(!event->spontaneous())
{ {
ui->tabWidget->setCurrentIndex(0); WITH_BLOCKED_SIGNALS(ui->tabWidget, setCurrentIndex, 0);
tabPageChanged(ui->tabWidget->currentIndex(), true);
} }
if(m_firstTimeShown) if(m_firstTimeShown)
@ -1061,53 +1091,12 @@ void MainWindow::dragEnterEvent(QDragEnterEvent *event)
*/ */
void MainWindow::dropEvent(QDropEvent *event) void MainWindow::dropEvent(QDropEvent *event)
{ {
ABORT_IF_BUSY; m_droppedFileList->clear();
(*m_droppedFileList) << event->mimeData()->urls();
if(m_settings->soundsEnabled()) lamexp_play_sound(IDR_WAVE_DROP, true); if(!m_droppedFileList->isEmpty())
QStringList droppedFiles;
QList<QUrl> urls = event->mimeData()->urls();
while(!urls.isEmpty())
{ {
QUrl currentUrl = urls.takeFirst(); if(m_settings->soundsEnabled()) lamexp_play_sound(IDR_WAVE_DROP, true);
QFileInfo file(currentUrl.toLocalFile()); QTimer::singleShot(0, this, SLOT(handleDroppedFiles()));
if(!file.exists())
{
continue;
}
if(file.isFile())
{
qDebug("Dropped File: %s", QUTF8(file.canonicalFilePath()));
droppedFiles << file.canonicalFilePath();
continue;
}
if(file.isDir())
{
qDebug("Dropped Folder: %s", QUTF8(file.canonicalFilePath()));
QList<QFileInfo> list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Files | QDir::NoSymLinks);
if(list.count() > 0)
{
for(int j = 0; j < list.count(); j++)
{
droppedFiles << list.at(j).canonicalFilePath();
}
}
else
{
list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
for(int j = 0; j < list.count(); j++)
{
qDebug("Descending to Folder: %s", QUTF8(list.at(j).canonicalFilePath()));
urls.prepend(QUrl::fromLocalFile(list.at(j).canonicalFilePath()));
}
}
}
}
if(!droppedFiles.isEmpty())
{
addFilesDelayed(droppedFiles, true);
} }
} }
@ -1351,8 +1340,8 @@ void MainWindow::windowShown(void)
return; return;
default: default:
QEventLoop loop; QTimer::singleShot(7000, &loop, SLOT(quit())); QEventLoop loop; QTimer::singleShot(7000, &loop, SLOT(quit()));
INIT_BANNER(); lamexp_play_sound(IDR_WAVE_WAITING, true); lamexp_play_sound(IDR_WAVE_WAITING, true);
m_banner->show(tr("Skipping update check this time, please be patient..."), &loop); SHOW_BANNER_ARG(tr("Skipping update check this time, please be patient..."), &loop);
break; break;
} }
} }
@ -2444,6 +2433,73 @@ void MainWindow::findFileContextActionTriggered(void)
} }
} }
/*
* Add all dropped files
*/
void MainWindow::handleDroppedFiles(void)
{
ABORT_IF_BUSY;
static const int MIN_COUNT = 16;
const QString bannerText = tr("Loading dropped files or folders, please wait...");
bool bUseBanner = false;
SHOW_BANNER_CONDITIONALLY(bUseBanner, (m_droppedFileList->count() >= MIN_COUNT), bannerText);
QStringList droppedFiles;
while(!m_droppedFileList->isEmpty())
{
QFileInfo file(m_droppedFileList->takeFirst().toLocalFile());
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
if(!file.exists())
{
continue;
}
if(file.isFile())
{
qDebug("Dropped File: %s", QUTF8(file.canonicalFilePath()));
droppedFiles << file.canonicalFilePath();
continue;
}
if(file.isDir())
{
qDebug("Dropped Folder: %s", QUTF8(file.canonicalFilePath()));
QFileInfoList list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Files | QDir::NoDotAndDotDot | QDir::NoSymLinks);
if(list.count() > 0)
{
SHOW_BANNER_CONDITIONALLY(bUseBanner, (list.count() >= MIN_COUNT), bannerText);
for(QFileInfoList::ConstIterator iter = list.constBegin(); iter != list.constEnd(); iter++)
{
droppedFiles << (*iter).canonicalFilePath();
}
}
else
{
list = QDir(file.canonicalFilePath()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
SHOW_BANNER_CONDITIONALLY(bUseBanner, (list.count() >= MIN_COUNT), bannerText);
for(QFileInfoList::ConstIterator iter = list.constBegin(); iter != list.constEnd(); iter++)
{
qDebug("Descending to Folder: %s", QUTF8((*iter).canonicalFilePath()));
m_droppedFileList->prepend(QUrl::fromLocalFile((*iter).canonicalFilePath()));
}
}
}
}
if(bUseBanner)
{
m_banner->close();
}
if(!droppedFiles.isEmpty())
{
addFiles(droppedFiles);
}
}
/* /*
* Add all pending files * Add all pending files
*/ */
@ -2462,9 +2518,10 @@ void MainWindow::handleDelayedFiles(void)
return; return;
} }
QStringList selectedFiles; WITH_BLOCKED_SIGNALS(ui->tabWidget, setCurrentIndex, 0);
ui->tabWidget->setCurrentIndex(0); tabPageChanged(ui->tabWidget->currentIndex(), true);
QStringList selectedFiles;
while(!m_delayedFileList->isEmpty()) while(!m_delayedFileList->isEmpty())
{ {
QFileInfo currentFile = QFileInfo(m_delayedFileList->takeFirst()); QFileInfo currentFile = QFileInfo(m_delayedFileList->takeFirst());
@ -4053,7 +4110,7 @@ void MainWindow::addFileDelayed(const QString &filePath, bool tryASAP)
*/ */
void MainWindow::addFilesDelayed(const QStringList &filePaths, bool tryASAP) void MainWindow::addFilesDelayed(const QStringList &filePaths, bool tryASAP)
{ {
if(tryASAP && !m_delayedFileTimer->isActive()) if(tryASAP && (!m_delayedFileTimer->isActive()))
{ {
qDebug("Received %d file(s).", filePaths.count()); qDebug("Received %d file(s).", filePaths.count());
m_delayedFileList->append(filePaths); m_delayedFileList->append(filePaths);

View File

@ -38,6 +38,7 @@ class QButtonGroup;
class QFileSystemModelEx; class QFileSystemModelEx;
class QLabel; class QLabel;
class QMenu; class QMenu;
class QUrl;
class QModelIndex; class QModelIndex;
class SettingsModel; class SettingsModel;
class WorkingBanner; class WorkingBanner;
@ -106,6 +107,7 @@ private slots:
void gotoMusicFolderButtonClicked(void); void gotoMusicFolderButtonClicked(void);
void goUpFolderContextActionTriggered(void); void goUpFolderContextActionTriggered(void);
void handleDelayedFiles(void); void handleDelayedFiles(void);
void handleDroppedFiles(void);
void hibernateComputerActionTriggered(bool checked); void hibernateComputerActionTriggered(bool checked);
void importCueSheetActionTriggered(bool checked); void importCueSheetActionTriggered(bool checked);
void importCsvContextActionTriggered(void); void importCsvContextActionTriggered(void);
@ -197,6 +199,7 @@ private:
lamexp_icon_t *m_windowIcon; lamexp_icon_t *m_windowIcon;
WorkingBanner *m_banner; WorkingBanner *m_banner;
QList<QUrl> *m_droppedFileList;
QStringList *m_delayedFileList; QStringList *m_delayedFileList;
QTimer *m_delayedFileTimer; QTimer *m_delayedFileTimer;
DropBox *m_dropBox; DropBox *m_dropBox;

View File

@ -88,6 +88,7 @@ WorkingBanner::WorkingBanner(QWidget *parent)
if(lamexp_sheet_of_glass(this)) if(lamexp_sheet_of_glass(this))
{ {
m_style = new QWindowsVistaStyle(); m_style = new QWindowsVistaStyle();
this->setStyle(m_style);
ui->labelStatus->setStyle(m_style); ui->labelStatus->setStyle(m_style);
ui->progressBar->setStyle(m_style); ui->progressBar->setStyle(m_style);
ui->labelStatus->setStyleSheet("background-color: rgb(255, 255, 255);"); ui->labelStatus->setStyleSheet("background-color: rgb(255, 255, 255);");
@ -230,6 +231,10 @@ void WorkingBanner::keyPressEvent(QKeyEvent *event)
qDebug("QT::KEY_ESCAPE pressed!"); qDebug("QT::KEY_ESCAPE pressed!");
emit userAbort(); emit userAbort();
} }
else if(event->key() == Qt::Key_M)
{
QTimer::singleShot(0, parent(), SLOT(showMinimized()));
}
event->ignore(); event->ignore();
} }
@ -251,7 +256,7 @@ bool WorkingBanner::winEvent(MSG *message, long *result)
void WorkingBanner::showEvent(QShowEvent *event) void WorkingBanner::showEvent(QShowEvent *event)
{ {
QTimer::singleShot(125, this, SLOT(windowShown())); QTimer::singleShot(25, this, SLOT(windowShown()));
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////

View File

@ -40,7 +40,7 @@ class WorkingBanner: public QDialog
Q_OBJECT Q_OBJECT
public: public:
WorkingBanner(QWidget *parent = 0); WorkingBanner(QWidget *parent);
~WorkingBanner(void); ~WorkingBanner(void);
void show(const QString &text); void show(const QString &text);