From 2e80475a9d89cfeaf569c8c30d34d9484b87e651 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 20 Apr 2011 16:21:12 +0200 Subject: [PATCH] * Moved --demo stuff to Source class. --- include/tomahawk/tomahawkapp.h | 3 --- src/libtomahawk/source.cpp | 24 +++++++++++++++++------- src/libtomahawk/source.h | 3 ++- src/sourcetree/sourcetreeitem.cpp | 15 +++++---------- src/sourcetree/sourcetreeview.cpp | 2 +- src/tomahawkapp.cpp | 2 -- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/tomahawk/tomahawkapp.h b/include/tomahawk/tomahawkapp.h index 2d55f3a1b..1547254dd 100644 --- a/include/tomahawk/tomahawkapp.h +++ b/include/tomahawk/tomahawkapp.h @@ -98,9 +98,6 @@ public: virtual void activate(); virtual bool loadUrl( const QString& url ); - // because QApplication::arguments() is expensive - bool scrubFriendlyName() const { return m_scrubFriendlyName; } - public slots: void instanceStarted( KDSingleApplicationGuard::Instance ); diff --git a/src/libtomahawk/source.cpp b/src/libtomahawk/source.cpp index d825a7724..46acb5857 100644 --- a/src/libtomahawk/source.cpp +++ b/src/libtomahawk/source.cpp @@ -27,6 +27,8 @@ #include "database/databasecommand_logplayback.h" #include "database/database.h" +#include + using namespace Tomahawk; @@ -40,6 +42,8 @@ Source::Source( int id, const QString& username ) { qDebug() << Q_FUNC_INFO << id << username; + m_scrubFriendlyName = qApp->arguments().contains( "--demo" ); + if ( id == 0 ) { m_isLocal = true; @@ -98,8 +102,8 @@ Source::friendlyName() const return m_username; //TODO: this is a terrible assumption, help me clean this up, mighty muesli! - if ( m_friendlyname.contains( "@conference.") ) - return QString(m_friendlyname).remove( 0, m_friendlyname.lastIndexOf( "/" )+1 ).append(" via MUC"); + if ( m_friendlyname.contains( "@conference." ) ) + return QString( m_friendlyname ).remove( 0, m_friendlyname.lastIndexOf( "/" ) + 1 ).append( " via MUC" ); if ( m_friendlyname.contains( "/tomahawk" ) ) return m_friendlyname.left( m_friendlyname.indexOf( "/tomahawk" ) ); @@ -108,6 +112,15 @@ Source::friendlyName() const } +void +Source::setFriendlyName( const QString& fname ) +{ + m_friendlyname = fname; + if ( m_scrubFriendlyName ) + m_friendlyname = m_friendlyname.split( "@" ).first(); +} + + void Source::addCollection( const collection_ptr& c ) { @@ -164,7 +177,7 @@ Source::dbLoaded( unsigned int id, const QString& fname ) qDebug() << Q_FUNC_INFO << id << fname; m_id = id; - m_friendlyname = fname; + setFriendlyName( fname ); emit syncedWithDatabase(); } @@ -225,10 +238,7 @@ Source::onStateChanged( DBSyncConnection::State newstate, DBSyncConnection::Stat unsigned int Source::trackCount() const { - if ( m_stats.contains( "numfiles" ) ) - return m_stats.value( "numfiles" ).toUInt(); - else - return 0; + return m_stats.value( "numfiles" ).toUInt(); } diff --git a/src/libtomahawk/source.h b/src/libtomahawk/source.h index ed48dfd1b..0f8b766c9 100644 --- a/src/libtomahawk/source.h +++ b/src/libtomahawk/source.h @@ -53,7 +53,7 @@ public: QString userName() const { return m_username; } QString friendlyName() const; - void setFriendlyName( const QString& fname ) { m_friendlyname = fname; } + void setFriendlyName( const QString& fname ); collection_ptr collection() const; void addCollection( const Tomahawk::collection_ptr& c ); @@ -111,6 +111,7 @@ private: QList< QSharedPointer > m_collections; QVariantMap m_stats; QString m_lastOpGuid; + bool m_scrubFriendlyName; Tomahawk::query_ptr m_currentTrack; QString m_textStatus; diff --git a/src/sourcetree/sourcetreeitem.cpp b/src/sourcetree/sourcetreeitem.cpp index c9ec16101..c45bacddf 100644 --- a/src/sourcetree/sourcetreeitem.cpp +++ b/src/sourcetree/sourcetreeitem.cpp @@ -1,5 +1,5 @@ /* === This file is part of Tomahawk Player - === - * + * * Copyright 2010-2011, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify @@ -46,14 +46,9 @@ SourceTreeItem::SourceTreeItem( const source_ptr& source, QObject* parent ) QString name; if( source.isNull() ) name = tr( "Super Collection" ); - else - { - if( TomahawkApp::instance()->scrubFriendlyName() && source->friendlyName().contains( '@' ) ) - name = source->friendlyName().left( source->friendlyName().indexOf( '@' ) ); - else - name = source->friendlyName(); - } - + else + name = source->friendlyName(); + QStandardItem* item = new QStandardItem( name ); item->setIcon( QIcon( RESPATH "images/user-avatar.png" ) ); item->setEditable( false ); @@ -114,7 +109,7 @@ SourceTreeItem::onPlaylistsAdded( const QList& playlists ) { // const-ness is important for getting the right pointer! foreach( const playlist_ptr& p, playlists ) - { + { m_playlists.append( p ); qlonglong ptr = reinterpret_cast( &m_playlists.last() ); diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index 6693bd106..9ae0d8591 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -540,7 +540,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co QString tracks; int figWidth = 0; - if ( status ) + if ( status && sti && !sti->source().isNull() ) { tracks = QString::number( sti->source()->trackCount() ); figWidth = painter->fontMetrics().width( tracks ); diff --git a/src/tomahawkapp.cpp b/src/tomahawkapp.cpp index 77c33ab96..194e5be73 100644 --- a/src/tomahawkapp.cpp +++ b/src/tomahawkapp.cpp @@ -150,7 +150,6 @@ TomahawkApp::TomahawkApp( int& argc, char *argv[] ) , m_sipHandler( 0 ) , m_servent( 0 ) , m_shortcutHandler( 0 ) - , m_scrubFriendlyName( false ) , m_mainwindow( 0 ) { qDebug() << "TomahawkApp thread:" << this->thread(); @@ -193,7 +192,6 @@ TomahawkApp::init() qDebug() << "Init Echonest Factory."; GeneratorFactory::registerFactory( "echonest", new EchonestFactory ); - m_scrubFriendlyName = arguments().contains( "--demo" ); // Register shortcut handler for this platform #ifdef Q_WS_MAC m_shortcutHandler = new MacShortcutHandler( this );