1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 09:04:33 +02:00

* Remove TemporaryPageItem from sidebar when its ViewPage gets destroyed.

This commit is contained in:
Christian Muehlhaeuser
2013-09-07 21:29:04 +02:00
parent 41aeff750b
commit 3343062fcc
2 changed files with 40 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -26,6 +27,7 @@
#include "widgets/SearchWidget.h" #include "widgets/SearchWidget.h"
#include "utils/ImageRegistry.h" #include "utils/ImageRegistry.h"
#include "utils/Closure.h" #include "utils/Closure.h"
#include "utils/Logger.h"
#include <QAction> #include <QAction>
@@ -39,7 +41,7 @@ namespace {
using namespace Tomahawk; using namespace Tomahawk;
TemporaryPageItem::TemporaryPageItem ( SourcesModel* mdl, SourceTreeItem* parent, ViewPage* page, int sortValue ) TemporaryPageItem::TemporaryPageItem( SourcesModel* mdl, SourceTreeItem* parent, ViewPage* page, int sortValue )
: SourceTreeItem( mdl, parent, SourcesModel::TemporaryPage ) : SourceTreeItem( mdl, parent, SourcesModel::TemporaryPage )
, m_page( page ) , m_page( page )
, m_icon( ImageRegistry::instance()->icon( RESPATH "images/playlist-icon.svg" ) ) , m_icon( ImageRegistry::instance()->icon( RESPATH "images/playlist-icon.svg" ) )
@@ -79,6 +81,12 @@ TemporaryPageItem::TemporaryPageItem ( SourcesModel* mdl, SourceTreeItem* parent
NewClosure( action, SIGNAL( triggered() ), this, SLOT( linkActionTriggered( QAction* ) ), action ); NewClosure( action, SIGNAL( triggered() ), this, SLOT( linkActionTriggered( QAction* ) ), action );
} }
if ( QObject* obj = dynamic_cast< QObject* >( page ) )
{
if ( obj->metaObject()->indexOfSignal( "destroyed(QObject*)" ) > -1 )
connect( obj, SIGNAL( destroyed( QObject* ) ), SLOT( pageDestroyed() ) );
}
model()->linkSourceItemToPage( this, page ); model()->linkSourceItemToPage( this, page );
} }
@@ -125,6 +133,14 @@ TemporaryPageItem::IDValue() const
void void
TemporaryPageItem::removeFromList() TemporaryPageItem::removeFromList()
{
pageDestroyed();
ViewManager::instance()->destroyPage( m_page );
}
void
TemporaryPageItem::pageDestroyed()
{ {
model()->removeSourceItemLink( this ); model()->removeSourceItemLink( this );
@@ -134,8 +150,6 @@ TemporaryPageItem::removeFromList()
parent()->endRowsRemoved(); parent()->endRowsRemoved();
emit removed(); emit removed();
ViewManager::instance()->destroyPage( m_page );
deleteLater(); deleteLater();
} }
@@ -150,30 +164,30 @@ TemporaryPageItem::linkActionTriggered( QAction* action )
const LinkType type = (LinkType)action->property( "linkType" ).toInt(); const LinkType type = (LinkType)action->property( "linkType" ).toInt();
switch( type ) switch( type )
{ {
case ArtistLink: case ArtistLink:
{ {
ArtistInfoWidget* aPage = dynamic_cast< ArtistInfoWidget* >( m_page ); ArtistInfoWidget* aPage = dynamic_cast< ArtistInfoWidget* >( m_page );
Q_ASSERT( aPage ); Q_ASSERT( aPage );
GlobalActionManager::instance()->copyOpenLink( aPage->artist() ); GlobalActionManager::instance()->copyOpenLink( aPage->artist() );
break; break;
} }
case AlbumLink: case AlbumLink:
{ {
AlbumInfoWidget* aPage = dynamic_cast< AlbumInfoWidget* >( m_page ); AlbumInfoWidget* aPage = dynamic_cast< AlbumInfoWidget* >( m_page );
Q_ASSERT( aPage ); Q_ASSERT( aPage );
GlobalActionManager::instance()->copyOpenLink( aPage->album() ); GlobalActionManager::instance()->copyOpenLink( aPage->album() );
break; break;
} }
case TrackLink: case TrackLink:
{ {
TrackInfoWidget* tPage = dynamic_cast< TrackInfoWidget* >( m_page ); TrackInfoWidget* tPage = dynamic_cast< TrackInfoWidget* >( m_page );
Q_ASSERT( tPage ); Q_ASSERT( tPage );
GlobalActionManager::instance()->copyToClipboard( tPage->query() ); GlobalActionManager::instance()->copyToClipboard( tPage->query() );
break; break;
} }
} }
} }

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org> * Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
* Copyright 2010-2013, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -50,6 +51,7 @@ signals:
private slots: private slots:
void linkActionTriggered( QAction* ); void linkActionTriggered( QAction* );
void pageDestroyed();
private: private:
Tomahawk::ViewPage* m_page; Tomahawk::ViewPage* m_page;