File indexing completed on 2023-05-30 11:30:44
0001 /** 0002 * Copyright (C) 2004 Scott Wheeler <wheeler@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 "actioncollection.h" 0018 0019 #include <kactioncollection.h> 0020 0021 #include "juk.h" 0022 #include "juk_debug.h" 0023 0024 namespace ActionCollection 0025 { 0026 KActionCollection *actions() 0027 { 0028 // Use KXMLGUIClient::actionCollection() (class JuK derives from 0029 // KXMLGUIClient) to construct the KActionCollection. 0030 // This makes sure that KActionCollection::parentGUIClient() is not 0031 // NULL and prevents the application from crashing when adding an 0032 // item to a toolbar using RMB (see bug #258641). 0033 // XXX This should not just be: 0034 // return JuK::JuKInstance()->actionCollection(); 0035 // as actions() may be called while within JuK's dtor, in which case 0036 // JuKInstance()->... would result to a crash. 0037 static KActionCollection *a = JuK::JuKInstance()->actionCollection(); 0038 // The widget of the action collection is set in Juk::setupActions(). 0039 return a; 0040 } 0041 0042 QAction *action(const QString &key) 0043 { 0044 #ifndef NO_DEBUG 0045 QAction *a = actions()->action(key); 0046 if(!a) 0047 qCWarning(JUK_LOG) << "QAction \"" << key << "\" is not defined yet."; 0048 return a; 0049 #else 0050 return actions()->action(key); 0051 #endif 0052 } 0053 0054 QAction *operator ""_act(const char *str, std::size_t len) 0055 { 0056 return action(QString::fromLatin1(str, len)); 0057 } 0058 } 0059 0060 // vim: set et sw=4 tw=0 sta: