Added a system tray icon.

This commit is contained in:
LoRd_MuldeR 2010-12-10 22:17:44 +01:00
parent 6491965610
commit 18bed9ea38
3 changed files with 44 additions and 10 deletions

View File

@ -25,7 +25,7 @@
#define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MAJOR 4
#define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_HI 0
#define VER_LAMEXP_MINOR_LO 0 #define VER_LAMEXP_MINOR_LO 0
#define VER_LAMEXP_BUILD 137 #define VER_LAMEXP_BUILD 138
#define VER_LAMEXP_SUFFIX TechPreview #define VER_LAMEXP_SUFFIX TechPreview
/* /*

View File

@ -46,6 +46,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QDir> #include <QDir>
#include <QMenu> #include <QMenu>
#include <QSystemTrayIcon>
#include <Windows.h> #include <Windows.h>
@ -56,6 +57,12 @@
WIDGET->setPalette(palette); \ WIDGET->setPalette(palette); \
} }
#define SET_PROGRESS_TEXT(TXT) \
{ \
label_progress->setText(TXT); \
m_systemTray->setToolTip(QString().sprintf("LameXP v%d.%02d\n%ls", lamexp_version_major(), lamexp_version_minor(), QString(TXT).utf16())); \
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Constructor // Constructor
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -63,6 +70,7 @@
ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settings, QWidget *parent) ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel *metaInfo, SettingsModel *settings, QWidget *parent)
: :
QDialog(parent), QDialog(parent),
m_systemTray(new QSystemTrayIcon(QIcon(":/icons/cd.png"), this)),
m_settings(settings), m_settings(settings),
m_metaInfo(metaInfo) m_metaInfo(metaInfo)
{ {
@ -118,6 +126,9 @@ ProcessingDialog::ProcessingDialog(FileListModel *fileListModel, AudioFileModel
} }
} }
//Enable system tray icon
connect(m_systemTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systemTrayActivated(QSystemTrayIcon::ActivationReason)));
//Init other vars //Init other vars
m_runningThreads = 0; m_runningThreads = 0;
m_currentFile = 0; m_currentFile = 0;
@ -138,6 +149,7 @@ ProcessingDialog::~ProcessingDialog(void)
LAMEXP_DELETE(m_progressIndicator); LAMEXP_DELETE(m_progressIndicator);
LAMEXP_DELETE(m_progressModel); LAMEXP_DELETE(m_progressModel);
LAMEXP_DELETE(m_contextMenu); LAMEXP_DELETE(m_contextMenu);
LAMEXP_DELETE(m_systemTray);
WinSevenTaskbar::setOverlayIcon(this, NULL); WinSevenTaskbar::setOverlayIcon(this, NULL);
WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNoState); WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNoState);
@ -160,6 +172,7 @@ void ProcessingDialog::showEvent(QShowEvent *event)
setCloseButtonEnabled(false); setCloseButtonEnabled(false);
button_closeDialog->setEnabled(false); button_closeDialog->setEnabled(false);
button_AbortProcess->setEnabled(false); button_AbortProcess->setEnabled(false);
m_systemTray->setVisible(true);
if(!SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS)) if(!SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS))
{ {
@ -171,7 +184,14 @@ void ProcessingDialog::showEvent(QShowEvent *event)
void ProcessingDialog::closeEvent(QCloseEvent *event) void ProcessingDialog::closeEvent(QCloseEvent *event)
{ {
if(!button_closeDialog->isEnabled()) event->ignore(); if(!button_closeDialog->isEnabled())
{
event->ignore();
}
else
{
m_systemTray->setVisible(false);
}
} }
bool ProcessingDialog::eventFilter(QObject *obj, QEvent *event) bool ProcessingDialog::eventFilter(QObject *obj, QEvent *event)
@ -218,7 +238,7 @@ void ProcessingDialog::initEncoding(void)
m_playList.clear(); m_playList.clear();
CHANGE_BACKGROUND_COLOR(frame_header, QColor(Qt::white)); CHANGE_BACKGROUND_COLOR(frame_header, QColor(Qt::white));
label_progress->setText("Encoding files, please wait..."); SET_PROGRESS_TEXT("Encoding files, please wait...");
m_progressIndicator->start(); m_progressIndicator->start();
button_closeDialog->setEnabled(false); button_closeDialog->setEnabled(false);
@ -243,7 +263,7 @@ void ProcessingDialog::abortEncoding(void)
m_userAborted = true; m_userAborted = true;
button_AbortProcess->setEnabled(false); button_AbortProcess->setEnabled(false);
label_progress->setText("Aborted! Waiting for running jobs to terminate..."); SET_PROGRESS_TEXT("Aborted! Waiting for running jobs to terminate...");
for(int i = 0; i < m_threadList.count(); i++) for(int i = 0; i < m_threadList.count(); i++)
{ {
@ -258,7 +278,7 @@ void ProcessingDialog::doneEncoding(void)
if(!m_userAborted) if(!m_userAborted)
{ {
label_progress->setText(QString("Encoding: %1 files of %2 completed so far, please wait...").arg(QString::number(progressBar->value()), QString::number(progressBar->maximum()))); SET_PROGRESS_TEXT(QString("Encoding: %1 files of %2 completed so far, please wait...").arg(QString::number(progressBar->value()), QString::number(progressBar->maximum())));
WinSevenTaskbar::setTaskbarProgress(this, progressBar->value(), progressBar->maximum()); WinSevenTaskbar::setTaskbarProgress(this, progressBar->value(), progressBar->maximum());
} }
@ -286,7 +306,7 @@ void ProcessingDialog::doneEncoding(void)
if(!m_userAborted && m_settings->createPlaylist() && !m_settings->outputToSourceDir()) if(!m_userAborted && m_settings->createPlaylist() && !m_settings->outputToSourceDir())
{ {
label_progress->setText("Creatig the playlist file, please wait..."); SET_PROGRESS_TEXT("Creatig the playlist file, please wait...");
QApplication::processEvents(); QApplication::processEvents();
writePlayList(); writePlayList();
} }
@ -296,7 +316,8 @@ void ProcessingDialog::doneEncoding(void)
CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFF3BA")); CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFF3BA"));
WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState); WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/error.png")); WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/error.png"));
label_progress->setText((m_succeededJobs.count() > 0) ? QString("Process was aborted by the user after %1 file(s)!").arg(QString::number(m_succeededJobs.count())) : "Process was aborted prematurely by the user!"); SET_PROGRESS_TEXT((m_succeededJobs.count() > 0) ? QString("Process was aborted by the user after %1 file(s)!").arg(QString::number(m_succeededJobs.count())) : "Process was aborted prematurely by the user!");
m_systemTray->showMessage("LameXP - Aborted", "Process was aborted by the user.", QSystemTrayIcon::Warning);
QApplication::processEvents(); QApplication::processEvents();
if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABORTED), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC); if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABORTED), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
} }
@ -307,7 +328,8 @@ void ProcessingDialog::doneEncoding(void)
CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFBABA")); CHANGE_BACKGROUND_COLOR(frame_header, QColor("#FFBABA"));
WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState); WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarErrorState);
WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/exclamation.png")); WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/exclamation.png"));
label_progress->setText(QString("Error: %1 of %2 files failed. Double-click failed items for detailed information!").arg(QString::number(m_failedJobs.count()), QString::number(m_failedJobs.count() + m_succeededJobs.count()))); SET_PROGRESS_TEXT(QString("Error: %1 of %2 files failed. Double-click failed items for detailed information!").arg(QString::number(m_failedJobs.count()), QString::number(m_failedJobs.count() + m_succeededJobs.count())));
m_systemTray->showMessage("LameXP - Error", "At least one file has failed!", QSystemTrayIcon::Critical );
QApplication::processEvents(); QApplication::processEvents();
if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC); if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_ERROR), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
} }
@ -316,7 +338,8 @@ void ProcessingDialog::doneEncoding(void)
CHANGE_BACKGROUND_COLOR(frame_header, QColor("#D1FFD5")); CHANGE_BACKGROUND_COLOR(frame_header, QColor("#D1FFD5"));
WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState); WinSevenTaskbar::setTaskbarState(this, WinSevenTaskbar::WinSevenTaskbarNormalState);
WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/accept.png")); WinSevenTaskbar::setOverlayIcon(this, &QIcon(":/icons/accept.png"));
label_progress->setText("Alle files completed successfully."); SET_PROGRESS_TEXT("Alle files completed successfully.");
m_systemTray->showMessage("LameXP - Done", "All files completed successfully.", QSystemTrayIcon::Information);
QApplication::processEvents(); QApplication::processEvents();
if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_SUCCESS), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC); if(m_settings->soundsEnabled()) PlaySound(MAKEINTRESOURCE(IDR_WAVE_SUCCESS), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
} }
@ -507,3 +530,11 @@ void ProcessingDialog::setCloseButtonEnabled(bool enabled)
HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE); HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE);
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED));
} }
void ProcessingDialog::systemTrayActivated(QSystemTrayIcon::ActivationReason reason)
{
if(reason == QSystemTrayIcon::DoubleClick)
{
SetForegroundWindow(this->winId());
}
}

View File

@ -24,6 +24,7 @@
#include "../tmp/UIC_ProcessingDialog.h" #include "../tmp/UIC_ProcessingDialog.h"
#include <QUuid> #include <QUuid>
#include <QSystemTrayIcon>
class QMovie; class QMovie;
class QMenu; class QMenu;
@ -50,6 +51,7 @@ private slots:
void logViewDoubleClicked(const QModelIndex &index); void logViewDoubleClicked(const QModelIndex &index);
void contextMenuTriggered(const QPoint &pos); void contextMenuTriggered(const QPoint &pos);
void contextMenuActionTriggered(void); void contextMenuActionTriggered(void);
void systemTrayActivated(QSystemTrayIcon::ActivationReason reason);
protected: protected:
void showEvent(QShowEvent *event); void showEvent(QShowEvent *event);
@ -76,4 +78,5 @@ private:
QList<QUuid> m_succeededJobs; QList<QUuid> m_succeededJobs;
QList<QUuid> m_failedJobs; QList<QUuid> m_failedJobs;
bool m_userAborted; bool m_userAborted;
QSystemTrayIcon *m_systemTray;
}; };