KIO
konqbookmarkmenu.cc
Go to the documentation of this file.
00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 00003 Copyright (C) 2006 Daniel Teske <teske@squorn.de> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "konqbookmarkmenu.h" 00022 00023 #include <QMenu> 00024 #include <QFile> 00025 00026 #include <kmenu.h> 00027 #include <kdebug.h> 00028 #include <kconfig.h> 00029 #include <kconfiggroup.h> 00030 #include <kicon.h> 00031 #include <kiconloader.h> 00032 #include <kactioncollection.h> 00033 00034 #include "kbookmarkimporter.h" 00035 #include "kbookmarkimporter_opera.h" 00036 #include "kbookmarkimporter_ie.h" 00037 #include "kbookmarkmenu_p.h" 00038 00039 KonqBookmarkContextMenu::KonqBookmarkContextMenu(const KBookmark & bm, KBookmarkManager * mgr, KonqBookmarkOwner * owner) 00040 : KBookmarkContextMenu(bm, mgr, owner) 00041 { 00042 } 00043 00044 KonqBookmarkContextMenu::~KonqBookmarkContextMenu() 00045 { 00046 } 00047 00048 00049 void KonqBookmarkContextMenu::addActions() 00050 { 00051 KConfigGroup config = KSharedConfig::openConfig("kbookmarkrc", KConfig::NoGlobals)->group("Bookmarks"); 00052 bool filteredToolbar = config.readEntry( "FilteredToolbar", false ); 00053 00054 if (bookmark().isGroup()) 00055 { 00056 addOpenFolderInTabs(); 00057 addBookmark(); 00058 00059 if(filteredToolbar) 00060 { 00061 QString text = bookmark().showInToolbar() ? i18n("Hide in toolbar") : i18n("Show in toolbar"); 00062 addAction( SmallIcon(""), text, this, SLOT( toggleShowInToolbar())); 00063 } 00064 00065 addFolderActions(); 00066 } 00067 else 00068 { 00069 if(owner()) 00070 { 00071 addAction( SmallIcon("window-new"), i18n( "Open in New Window" ), this, SLOT( openInNewWindow() ) ); 00072 addAction( SmallIcon("tab-new"), i18n( "Open in New Tab" ), this, SLOT( openInNewTab() ) ); 00073 } 00074 addBookmark(); 00075 00076 if(filteredToolbar) 00077 { 00078 QString text = bookmark().showInToolbar() ? i18n("Hide in toolbar") : i18n("Show in toolbar"); 00079 addAction( SmallIcon(""), text, this, SLOT( toggleShowInToolbar())); 00080 } 00081 00082 addBookmarkActions(); 00083 } 00084 } 00085 00086 void KonqBookmarkContextMenu::toggleShowInToolbar() 00087 { 00088 bookmark().setShowInToolbar(!bookmark().showInToolbar()); 00089 manager()->emitChanged(bookmark().parentGroup()); 00090 } 00091 00092 void KonqBookmarkContextMenu::openInNewTab() 00093 { 00094 owner()->openInNewTab(bookmark()); 00095 } 00096 00097 void KonqBookmarkContextMenu::openInNewWindow() 00098 { 00099 owner()->openInNewWindow(bookmark()); 00100 } 00101 00102 /******************************/ 00103 /******************************/ 00104 /******************************/ 00105 00106 void KonqBookmarkMenu::fillDynamicBookmarks() 00107 { 00108 if ( isDirty() 00109 && KBookmarkManager::userBookmarksManager()->path() == manager()->path() ) 00110 { 00111 bool haveSep = false; 00112 00113 const QStringList keys = KonqBookmarkMenu::dynamicBookmarksList(); 00114 for ( QStringList::const_iterator it = keys.begin(); it != keys.end(); ++it ) 00115 { 00116 DynMenuInfo info; 00117 info = showDynamicBookmarks((*it)); 00118 00119 if ( !info.show || !QFile::exists( info.location ) ) 00120 continue; 00121 00122 if (!haveSep) 00123 { 00124 parentMenu()->addSeparator(); 00125 haveSep = true; 00126 } 00127 00128 KActionMenu * actionMenu; 00129 actionMenu = new KActionMenu( KIcon(info.type), info.name, this ); 00130 m_actionCollection->addAction( "kbookmarkmenu", actionMenu ); 00131 00132 parentMenu()->addAction(actionMenu); 00133 m_actions.append( actionMenu ); 00134 00135 KImportedBookmarkMenu *subMenu = 00136 new KImportedBookmarkMenu( manager(), owner(), actionMenu->menu(), 00137 info.type, info.location); 00138 m_lstSubMenus.append( subMenu ); 00139 } 00140 } 00141 } 00142 00143 void KonqBookmarkMenu::refill() 00144 { 00145 if(isRoot()) 00146 addActions(); 00147 fillDynamicBookmarks(); 00148 fillBookmarks(); 00149 if(!isRoot()) 00150 addActions(); 00151 } 00152 00153 QAction* KonqBookmarkMenu::actionForBookmark(const KBookmark &bm) 00154 { 00155 if ( bm.isGroup() ) 00156 { 00157 kDebug(7043) << "Creating Konq bookmark submenu named " << bm.text(); 00158 KBookmarkActionMenu * actionMenu = new KBookmarkActionMenu( bm, this ); 00159 m_actionCollection->addAction( "kbookmarkmenu", actionMenu ); 00160 m_actions.append( actionMenu ); 00161 00162 KBookmarkMenu *subMenu = new KonqBookmarkMenu( manager(), owner(), actionMenu, bm.address() ); 00163 00164 m_lstSubMenus.append( subMenu ); 00165 return actionMenu; 00166 } 00167 else if( bm.isSeparator() ) 00168 { 00169 return KBookmarkMenu::actionForBookmark(bm); 00170 } 00171 else 00172 { 00173 kDebug(7043) << "Creating Konq bookmark action named " << bm.text(); 00174 KBookmarkAction * action = new KBookmarkAction( bm, owner(), this ); 00175 m_actionCollection->addAction(action->objectName(), action); 00176 m_actions.append( action ); 00177 return action; 00178 } 00179 } 00180 00181 KonqBookmarkMenu::DynMenuInfo KonqBookmarkMenu::showDynamicBookmarks( const QString &id ) 00182 { 00183 KConfig bookmarkrc("kbookmarkrc", KConfig::NoGlobals); 00184 KConfigGroup config(&bookmarkrc, "Bookmarks"); 00185 00186 DynMenuInfo info; 00187 info.show = false; 00188 00189 if (!config.hasKey("DynamicMenus")) { 00190 if (bookmarkrc.hasGroup("DynamicMenu-" + id)) { 00191 KConfigGroup dynGroup(&bookmarkrc, "DynamicMenu-" + id); 00192 info.show = dynGroup.readEntry("Show", false); 00193 info.location = dynGroup.readPathEntry("Location", QString()); 00194 info.type = dynGroup.readEntry("Type"); 00195 info.name = dynGroup.readEntry("Name"); 00196 } 00197 } 00198 return info; 00199 } 00200 00201 QStringList KonqBookmarkMenu::dynamicBookmarksList() 00202 { 00203 KConfigGroup config = KSharedConfig::openConfig("kbookmarkrc", KConfig::NoGlobals)->group("Bookmarks"); 00204 00205 QStringList mlist; 00206 if (config.hasKey("DynamicMenus")) 00207 mlist = config.readEntry("DynamicMenus", QStringList()); 00208 00209 return mlist; 00210 } 00211 00212 void KonqBookmarkMenu::setDynamicBookmarks(const QString &id, const DynMenuInfo &newMenu) 00213 { 00214 KSharedConfig::Ptr kbookmarkrc = KSharedConfig::openConfig("kbookmarkrc", KConfig::NoGlobals); 00215 KConfigGroup dynConfig = kbookmarkrc->group(QString("DynamicMenu-" + id)); 00216 00217 // add group unconditionally 00218 dynConfig.writeEntry("Show", newMenu.show); 00219 dynConfig.writePathEntry("Location", newMenu.location); 00220 dynConfig.writeEntry("Type", newMenu.type); 00221 dynConfig.writeEntry("Name", newMenu.name); 00222 00223 QStringList elist; 00224 KConfigGroup config = kbookmarkrc->group("Bookmarks"); 00225 if (config.hasKey("DynamicMenus")) { 00226 elist = config.readEntry("DynamicMenus", QStringList()); 00227 } 00228 00229 // make sure list includes type 00230 if (!elist.contains(id)) { 00231 elist << id; 00232 config.writeEntry("DynamicMenus", elist); 00233 } 00234 00235 config.sync(); 00236 } 00237 00238 KonqBookmarkOwner::~KonqBookmarkOwner() 00239 { 00240 } 00241 00242 KMenu * KonqBookmarkMenu::contextMenu(QAction * action) 00243 { 00244 KBookmarkActionInterface* act = dynamic_cast<KBookmarkActionInterface *>(action); 00245 if (!act) 00246 return 0; 00247 return new KonqBookmarkContextMenu(act->bookmark(), manager(), owner()); 00248 } 00249 00250 #include "konqbookmarkmenu.moc"
KDE 4.6 API Reference