mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-13 17:43:59 +02: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:
@@ -7,7 +7,6 @@ namespace TomahawkUtils
|
|||||||
|
|
||||||
void
|
void
|
||||||
bringToFront() {
|
bringToFront() {
|
||||||
qDebug() << "foo";
|
|
||||||
[NSApp activateIgnoringOtherApps:YES];
|
[NSApp activateIgnoringOtherApps:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -250,6 +250,8 @@ TomahawkApp::init()
|
|||||||
|
|
||||||
Tomahawk::setApplicationHandler( this );
|
Tomahawk::setApplicationHandler( this );
|
||||||
increaseMaxFileDescriptors();
|
increaseMaxFileDescriptors();
|
||||||
|
|
||||||
|
setQuitOnLastWindowClosed( false );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Connect up shortcuts
|
// Connect up shortcuts
|
||||||
|
@@ -95,10 +95,10 @@ public:
|
|||||||
Tomahawk::ExternalResolver* resolverForPath( const QString& scriptPath );
|
Tomahawk::ExternalResolver* resolverForPath( const QString& scriptPath );
|
||||||
|
|
||||||
// PlatformInterface
|
// PlatformInterface
|
||||||
virtual void activate();
|
|
||||||
virtual bool loadUrl( const QString& url );
|
virtual bool loadUrl( const QString& url );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
virtual void activate();
|
||||||
void instanceStarted( KDSingleApplicationGuard::Instance );
|
void instanceStarted( KDSingleApplicationGuard::Instance );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent )
|
TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent )
|
||||||
: QSystemTrayIcon( parent )
|
: QSystemTrayIcon( parent )
|
||||||
, m_currentAnimationFrame( 0 )
|
, m_currentAnimationFrame( 0 )
|
||||||
|
, m_showWindowAction( 0 )
|
||||||
{
|
{
|
||||||
QIcon icon( RESPATH "icons/tomahawk-icon-128x128.png" );
|
QIcon icon( RESPATH "icons/tomahawk-icon-128x128.png" );
|
||||||
setIcon( icon );
|
setIcon( icon );
|
||||||
@@ -45,6 +46,15 @@ TomahawkTrayIcon::TomahawkTrayIcon( QObject* parent )
|
|||||||
m_contextMenu->addSeparator();
|
m_contextMenu->addSeparator();
|
||||||
m_prevAction = m_contextMenu->addAction( tr( "Previous Track" ) );
|
m_prevAction = m_contextMenu->addAction( tr( "Previous Track" ) );
|
||||||
m_nextAction = m_contextMenu->addAction( tr( "Next 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_contextMenu->addSeparator();
|
||||||
m_quitAction = m_contextMenu->addAction( tr( "Quit" ) );
|
m_quitAction = m_contextMenu->addAction( tr( "Quit" ) );
|
||||||
|
|
||||||
@@ -69,6 +79,33 @@ TomahawkTrayIcon::~TomahawkTrayIcon()
|
|||||||
delete m_contextMenu;
|
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
|
void
|
||||||
TomahawkTrayIcon::setResult( const Tomahawk::result_ptr& result )
|
TomahawkTrayIcon::setResult( const Tomahawk::result_ptr& result )
|
||||||
|
@@ -33,12 +33,15 @@ public:
|
|||||||
TomahawkTrayIcon( QObject* parent );
|
TomahawkTrayIcon( QObject* parent );
|
||||||
virtual bool event( QEvent* e );
|
virtual bool event( QEvent* e );
|
||||||
|
|
||||||
|
void setShowHideWindow( bool show = true );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setResult( const Tomahawk::result_ptr& result );
|
void setResult( const Tomahawk::result_ptr& result );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onAnimationTimer();
|
void onAnimationTimer();
|
||||||
void onActivated( QSystemTrayIcon::ActivationReason reason );
|
void onActivated( QSystemTrayIcon::ActivationReason reason );
|
||||||
|
void showWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void refreshToolTip();
|
void refreshToolTip();
|
||||||
@@ -57,6 +60,10 @@ private:
|
|||||||
QAction* m_prevAction;
|
QAction* m_prevAction;
|
||||||
QAction* m_nextAction;
|
QAction* m_nextAction;
|
||||||
QAction* m_quitAction;
|
QAction* m_quitAction;
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
QAction* m_showWindowAction;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOMAHAWK_TRAYICON_H
|
#endif // TOMAHAWK_TRAYICON_H
|
||||||
|
@@ -362,6 +362,8 @@ TomahawkWindow::closeEvent( QCloseEvent* e )
|
|||||||
e->ignore();
|
e->ignore();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
m_trayIcon->setShowHideWindow( false );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
e->accept();
|
e->accept();
|
||||||
|
Reference in New Issue
Block a user