mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-02-24 20:03:07 +01:00
OSX: Don't quit on window close, to conform to OSX expectations. Add Show/Hide action to tray icon.
This commit is contained in:
parent
1da74e4d81
commit
f36b95fe6b
@ -7,7 +7,6 @@ namespace TomahawkUtils
|
||||
|
||||
void
|
||||
bringToFront() {
|
||||
qDebug() << "foo";
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
|
@ -250,6 +250,8 @@ TomahawkApp::init()
|
||||
|
||||
Tomahawk::setApplicationHandler( this );
|
||||
increaseMaxFileDescriptors();
|
||||
|
||||
setQuitOnLastWindowClosed( false );
|
||||
#endif
|
||||
|
||||
// Connect up shortcuts
|
||||
|
@ -95,10 +95,10 @@ public:
|
||||
Tomahawk::ExternalResolver* resolverForPath( const QString& scriptPath );
|
||||
|
||||
// PlatformInterface
|
||||
virtual void activate();
|
||||
virtual bool loadUrl( const QString& url );
|
||||
|
||||
public slots:
|
||||
virtual void activate();
|
||||
void instanceStarted( KDSingleApplicationGuard::Instance );
|
||||
|
||||
private slots:
|
||||
|
@ -30,6 +30,7 @@
|
||||
TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent )
|
||||
: QSystemTrayIcon( parent )
|
||||
, m_currentAnimationFrame( 0 )
|
||||
, m_showWindowAction( 0 )
|
||||
{
|
||||
QIcon icon( RESPATH "icons/tomahawk-icon-128x128.png" );
|
||||
setIcon( icon );
|
||||
@ -45,6 +46,15 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent )
|
||||
m_contextMenu->addSeparator();
|
||||
m_prevAction = m_contextMenu->addAction( tr( "Previous Track" ) );
|
||||
m_nextAction = m_contextMenu->addAction( tr( "Next Track" ) );
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
// On mac you can close the windows while leaving the app open. We then need a way to show the main window again
|
||||
m_contextMenu->addSeparator();
|
||||
m_showWindowAction = m_contextMenu->addAction( tr( "Hide Tomahawk Window" ) );
|
||||
m_showWindowAction->setData( true );
|
||||
connect( m_showWindowAction, SIGNAL( triggered() ), this, SLOT( showWindow() ) );
|
||||
#endif
|
||||
|
||||
m_contextMenu->addSeparator();
|
||||
m_quitAction = m_contextMenu->addAction( tr( "Quit" ) );
|
||||
|
||||
@ -69,6 +79,33 @@ TomahawkTrayIcon::~TomahawkTrayIcon()
|
||||
delete m_contextMenu;
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkTrayIcon::setShowHideWindow( bool show )
|
||||
{
|
||||
if ( show )
|
||||
{
|
||||
m_showWindowAction->setText( tr( "Hide Tomahawk Window" ) );
|
||||
m_showWindowAction->setData( show );
|
||||
} else {
|
||||
m_showWindowAction->setText( tr( "Show Tomahawk Window" ) );
|
||||
}
|
||||
m_showWindowAction->setData( show );
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkTrayIcon::showWindow()
|
||||
{
|
||||
if( !m_showWindowAction->data().toBool() )
|
||||
{
|
||||
APP->mainWindow()->show();
|
||||
APP->mainWindow()->raise();
|
||||
|
||||
setShowHideWindow( true );
|
||||
} else {
|
||||
APP->mainWindow()->hide();
|
||||
setShowHideWindow( false );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TomahawkTrayIcon::setResult( const Tomahawk::result_ptr& result )
|
||||
|
@ -33,12 +33,15 @@ public:
|
||||
TomahawkTrayIcon( QObject* parent );
|
||||
virtual bool event( QEvent* e );
|
||||
|
||||
void setShowHideWindow( bool show = true );
|
||||
|
||||
public slots:
|
||||
void setResult( const Tomahawk::result_ptr& result );
|
||||
|
||||
private slots:
|
||||
void onAnimationTimer();
|
||||
void onActivated( QSystemTrayIcon::ActivationReason reason );
|
||||
void showWindow();
|
||||
|
||||
private:
|
||||
void refreshToolTip();
|
||||
@ -57,6 +60,10 @@ private:
|
||||
QAction* m_prevAction;
|
||||
QAction* m_nextAction;
|
||||
QAction* m_quitAction;
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
QAction* m_showWindowAction;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // TOMAHAWK_TRAYICON_H
|
||||
|
@ -362,6 +362,8 @@ TomahawkWindow::closeEvent( QCloseEvent* e )
|
||||
e->ignore();
|
||||
return;
|
||||
}
|
||||
#else
|
||||
m_trayIcon->setShowHideWindow( false );
|
||||
#endif
|
||||
|
||||
e->accept();
|
||||
|
Loading…
x
Reference in New Issue
Block a user