File indexing completed on 2024-05-05 04:48:33

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Leo Franchi <lfranchi@kde.org>                                    *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "GrowlInterface.h"
0018 
0019 #include "amarokconfig.h"
0020 #include "App.h"
0021 #include "core/support/Debug.h"
0022 #include "EngineController.h"
0023 #include "core/meta/Meta.h"
0024 #include "core/meta/support/MetaUtility.h" // for secToPrettyTime
0025 #include "SvgHandler.h"
0026 #include "TrayIcon.h"
0027 
0028 GrowlInterface::GrowlInterface( QString appName ) :
0029                 m_appName( appName )
0030 {
0031     EngineController *engine = The::engineController();
0032 
0033     connect( engine, &EngineController::trackChanged,
0034              this, &GrowlInterface::show );
0035 }
0036 
0037 void
0038 GrowlInterface::show( Meta::TrackPtr track )
0039 {
0040     DEBUG_BLOCK
0041     QString text;
0042     if( !track || track->playableUrl().isEmpty() )
0043         text = i18n( "No track playing" );
0044     else
0045     {
0046         text = track->prettyName();
0047         if( track->artist() && !track->artist()->prettyName().isEmpty() )
0048             text = track->artist()->prettyName() + " - " + text;
0049         if( track->album() && !track->album()->prettyName().isEmpty() )
0050             text += "\n (" + track->album()->prettyName() + ") ";
0051         else
0052             text += '\n';
0053         if( track->length() > 0 )
0054             text += Meta::msToPrettyTime( track->length() );
0055     }
0056 
0057     if( text.isEmpty() )
0058         text =  track->playableUrl().fileName();
0059 
0060     if( text.startsWith( "- " ) ) //When we only have a title tag, _something_ prepends a fucking hyphen. Remove that.
0061         text = text.mid( 2 );
0062 
0063     if( text.isEmpty() ) //still
0064         text = i18n("No information available for this track");
0065 
0066     if( pApp->trayIcon() )
0067     {
0068         if( track && track->album() )
0069         {
0070             pApp->trayIcon()->setIconByPixmap( The::svgHandler()->imageWithBorder( track->album(), 100, 5 ) );
0071         }
0072         pApp->trayIcon()->showMessage( "Amarok", text, QString() );
0073     }
0074 
0075 }