Warning, file /multimedia/amarok/src/amarokurls/BookmarkCurrentButton.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@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 "BookmarkCurrentButton.h" 0018 0019 #include "AmarokUrlHandler.h" 0020 #include "BookmarkModel.h" 0021 0022 #include <QIcon> 0023 #include <KLocalizedString> 0024 0025 #include <QMenu> 0026 #include <QString> 0027 0028 BookmarkCurrentButton::BookmarkCurrentButton( QWidget *parent ) 0029 : QToolButton( parent ) 0030 { 0031 setIcon( QIcon::fromTheme( QStringLiteral("bookmark-new") ) ); 0032 setText( i18n( "New Bookmark" ) ); 0033 setToolButtonStyle( Qt::ToolButtonTextBesideIcon ); 0034 connect( this, &BookmarkCurrentButton::clicked, this, &BookmarkCurrentButton::showMenu ); 0035 } 0036 0037 BookmarkCurrentButton::~BookmarkCurrentButton() 0038 { 0039 } 0040 0041 void BookmarkCurrentButton::showMenu() 0042 { 0043 QPoint pos( 0, height() ); 0044 generateMenu( mapToGlobal( pos ) ); 0045 } 0046 0047 void BookmarkCurrentButton::generateMenu( const QPoint &pos ) 0048 { 0049 0050 QList<AmarokUrlGenerator *> generators = The::amarokUrlHandler()->generators(); 0051 0052 QMenu menu; 0053 0054 QMap<QAction *, AmarokUrlGenerator *> generatorMap; 0055 0056 foreach( AmarokUrlGenerator * generator, generators ) 0057 { 0058 generatorMap.insert( menu.addAction( generator->icon() ,generator->description() ), generator ); 0059 } 0060 0061 QAction * action = menu.exec( pos ); 0062 0063 if( action && generatorMap.contains( action ) ) 0064 { 0065 AmarokUrl url = generatorMap.value( action )->createUrl(); 0066 url.saveToDb(); 0067 BookmarkModel::instance()->reloadFromDb(); 0068 } 0069 } 0070