• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KIO

kbookmarkmenu.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 "kbookmarkmenu.h"
00022 #include "kbookmarkmenu_p.h"
00023 
00024 #include "kbookmarkdialog.h"
00025 
00026 #include <kauthorized.h>
00027 #include <kdebug.h>
00028 #include <kiconloader.h>
00029 #include <klocale.h>
00030 #include <kmessagebox.h>
00031 #include <kmenu.h>
00032 #include <kstandardshortcut.h>
00033 #include <kstandardaction.h>
00034 #include <kstringhandler.h>
00035 #include <krun.h>
00036 #include <kactioncollection.h>
00037 
00038 #include <qclipboard.h>
00039 #include <qmimedata.h>
00040 
00041 
00042 #include <QtCore/QStack>
00043 #include <QtGui/QHeaderView>
00044 #include <QtGui/QApplication>
00045 
00046 /********************************************************************/
00047 /********************************************************************/
00048 /********************************************************************/
00049 
00050 KBookmarkMenu::KBookmarkMenu( KBookmarkManager* mgr,
00051                               KBookmarkOwner * _owner, KMenu * _parentMenu,
00052                               KActionCollection * actionCollection)
00053   : QObject(),
00054     m_actionCollection( actionCollection ),
00055     m_bIsRoot(true),
00056     m_pManager(mgr), m_pOwner(_owner),
00057     m_parentMenu( _parentMenu ),
00058     m_parentAddress( QString("") ) //TODO KBookmarkAdress::root
00059 {
00060   m_parentMenu->setKeyboardShortcutsEnabled( true );
00061 
00062   //kDebug(7043) << "KBookmarkMenu::KBookmarkMenu " << this << " address : " << m_parentAddress;
00063 
00064   connect( _parentMenu, SIGNAL( aboutToShow() ),
00065             SLOT( slotAboutToShow() ) );
00066 
00067   if ( KBookmarkSettings::self()->m_contextmenu )
00068   {
00069     m_parentMenu->setContextMenuPolicy(Qt::CustomContextMenu);
00070     connect(m_parentMenu, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(slotCustomContextMenu(const QPoint &)));
00071   }
00072 
00073   connect( m_pManager, SIGNAL( changed(const QString &, const QString &) ),
00074               SLOT( slotBookmarksChanged(const QString &) ) );
00075 
00076   m_bDirty = true;
00077 }
00078 
00079 void KBookmarkMenu::addActions()
00080 {
00081   if ( m_bIsRoot )
00082   {
00083     addAddBookmark();
00084     addAddBookmarksList();
00085     addNewFolder();
00086     addEditBookmarks();
00087   }
00088   else
00089   {
00090     if ( m_parentMenu->actions().count() > 0 )
00091       m_parentMenu->addSeparator();
00092 
00093     addOpenInTabs();
00094     addAddBookmark();
00095     addAddBookmarksList();
00096     addNewFolder();
00097   }
00098 }
00099 
00100 KBookmarkMenu::KBookmarkMenu( KBookmarkManager* mgr,
00101                               KBookmarkOwner * _owner, KMenu * _parentMenu,
00102                               const QString & parentAddress)
00103   : QObject(),
00104     m_actionCollection( new KActionCollection(this) ),
00105     m_bIsRoot(false),
00106     m_pManager(mgr), m_pOwner(_owner),
00107     m_parentMenu( _parentMenu ),
00108     m_parentAddress( parentAddress )
00109 {
00110   m_parentMenu->setKeyboardShortcutsEnabled( true );
00111   connect( _parentMenu, SIGNAL( aboutToShow() ), SLOT( slotAboutToShow() ) );
00112   if ( KBookmarkSettings::self()->m_contextmenu )
00113   {
00114     m_parentMenu->setContextMenuPolicy(Qt::CustomContextMenu);
00115     connect(m_parentMenu, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(slotCustomContextMenu(const QPoint &)));
00116   }
00117   m_bDirty = true;
00118 }
00119 
00120 KBookmarkMenu::~KBookmarkMenu()
00121 {
00122   qDeleteAll( m_lstSubMenus );
00123   qDeleteAll( m_actions );
00124 }
00125 
00126 void KBookmarkMenu::ensureUpToDate()
00127 {
00128   slotAboutToShow();
00129 }
00130 
00131 void KBookmarkMenu::slotAboutToShow()
00132 {
00133   // Did the bookmarks change since the last time we showed them ?
00134   if ( m_bDirty )
00135   {
00136     m_bDirty = false;
00137     clear();
00138     refill();
00139     m_parentMenu->adjustSize();
00140   }
00141 }
00142 
00143 void KBookmarkMenu::slotCustomContextMenu( const QPoint & pos)
00144 {
00145     QAction * action = m_parentMenu->actionAt(pos);
00146     KMenu * menu = contextMenu(action);
00147     if(!menu)
00148         return;
00149     menu->setAttribute(Qt::WA_DeleteOnClose);
00150     menu->popup(m_parentMenu->mapToGlobal(pos));
00151 }
00152 
00153 KMenu * KBookmarkMenu::contextMenu( QAction * action )
00154 { 
00155     KBookmarkActionInterface* act = dynamic_cast<KBookmarkActionInterface *>(action);
00156     if (!act)
00157         return 0;
00158     return new KBookmarkContextMenu(act->bookmark(), m_pManager, m_pOwner);
00159 }
00160 
00161 bool KBookmarkMenu::isRoot() const 
00162 {
00163     return m_bIsRoot;
00164 }
00165 
00166 bool KBookmarkMenu::isDirty() const 
00167 {
00168     return m_bDirty;
00169 }
00170 
00171 QString KBookmarkMenu::parentAddress() const 
00172 {
00173     return m_parentAddress;
00174 }
00175 
00176 KBookmarkManager * KBookmarkMenu::manager() const
00177 {
00178     return m_pManager;
00179 }
00180 
00181 KBookmarkOwner * KBookmarkMenu::owner() const 
00182 {
00183     return m_pOwner;
00184 }
00185 
00186 KMenu * KBookmarkMenu::parentMenu() const 
00187 {
00188     return m_parentMenu;
00189 }
00190 
00191 /********************************************************************/
00192 /********************************************************************/
00193 /********************************************************************/
00194 
00195 KBookmarkActionInterface::KBookmarkActionInterface(const KBookmark &bk)
00196 : bm(bk)
00197 {}
00198 
00199 KBookmarkActionInterface::~KBookmarkActionInterface()
00200 {
00201 }
00202 
00203 const KBookmark KBookmarkActionInterface::bookmark() const
00204 {
00205   return bm;
00206 }
00207 
00208 /********************************************************************/
00209 /********************************************************************/
00210 /********************************************************************/
00211 
00212 
00213 KBookmarkContextMenu::KBookmarkContextMenu(const KBookmark & bk, KBookmarkManager * manager, KBookmarkOwner *owner, QWidget * parent)
00214     : KMenu(parent), bm(bk), m_pManager(manager), m_pOwner(owner)
00215 {
00216     connect(this, SIGNAL(aboutToShow()), SLOT(slotAboutToShow()));
00217 }
00218 
00219 void KBookmarkContextMenu::slotAboutToShow()
00220 {
00221     addActions();
00222 }
00223 
00224 void KBookmarkContextMenu::addActions()
00225 {
00226   if (bm.isGroup())
00227   {
00228     addOpenFolderInTabs();
00229     addBookmark();
00230     addFolderActions();
00231   }
00232   else
00233   {
00234     addBookmark();
00235     addBookmarkActions();
00236   }
00237 }
00238 
00239 KBookmarkContextMenu::~KBookmarkContextMenu()
00240 {
00241 
00242 }
00243 
00244 
00245 void KBookmarkContextMenu::addBookmark()
00246 {
00247   if( m_pOwner && m_pOwner->enableOption(KBookmarkOwner::ShowAddBookmark)  )
00248       addAction( SmallIcon("bookmark-new"), i18n( "Add Bookmark Here" ), this, SLOT(slotInsert()) );
00249 }
00250 
00251 void KBookmarkContextMenu::addFolderActions()
00252 {
00253   addAction( i18n( "Open Folder in Bookmark Editor" ), this, SLOT(slotEditAt()) );
00254   addProperties();
00255   addSeparator();
00256   addAction( SmallIcon("edit-delete"), i18n( "Delete Folder" ), this, SLOT(slotRemove()) );
00257 }
00258 
00259 
00260 void KBookmarkContextMenu::addProperties()
00261 {
00262   addAction( i18n( "Properties" ), this, SLOT(slotProperties()) );
00263 }
00264 
00265 void KBookmarkContextMenu::addBookmarkActions()
00266 {
00267   addAction( i18n( "Copy Link Address" ), this, SLOT(slotCopyLocation()) );
00268   addProperties();
00269   addSeparator();
00270   addAction( SmallIcon("edit-delete"), i18n( "Delete Bookmark" ), this, SLOT(slotRemove()) );
00271 }
00272 
00273 void KBookmarkContextMenu::addOpenFolderInTabs()
00274 {
00275    if(m_pOwner->supportsTabs())
00276       addAction(SmallIcon("tab-new"), i18n( "Open Folder in Tabs" ), this, SLOT( slotOpenFolderInTabs() ) );
00277 }
00278 
00279 void KBookmarkContextMenu::slotEditAt()
00280 {
00281   //kDebug(7043) << "KBookmarkMenu::slotEditAt" << m_highlightedAddress;
00282   m_pManager->slotEditBookmarksAtAddress( bm.address() );
00283 }
00284 
00285 void KBookmarkContextMenu::slotProperties()
00286 {
00287   //kDebug(7043) << "KBookmarkMenu::slotProperties" << m_highlightedAddress;
00288 
00289     KBookmarkDialog *  dlg = m_pOwner->bookmarkDialog(m_pManager, QApplication::activeWindow());
00290     dlg->editBookmark(bm);
00291     delete dlg;
00292 }
00293 
00294 void KBookmarkContextMenu::slotInsert()
00295 {
00296   //kDebug(7043) << "KBookmarkMenu::slotInsert" << m_highlightedAddress;
00297 
00298   QString url = m_pOwner->currentUrl();
00299   if (url.isEmpty())
00300   {
00301     KMessageBox::error( QApplication::activeWindow(), i18n("Cannot add bookmark with empty URL."));
00302     return;
00303   }
00304   QString title = m_pOwner->currentTitle();
00305   if (title.isEmpty())
00306     title = url;
00307 
00308   if (bm.isGroup())
00309   {
00310     KBookmarkGroup parentBookmark = bm.toGroup();
00311     Q_ASSERT(!parentBookmark.isNull());
00312     parentBookmark.addBookmark( title, KUrl(url) );
00313     m_pManager->emitChanged( parentBookmark );
00314   }
00315   else
00316   {
00317     KBookmarkGroup parentBookmark = bm.parentGroup();
00318     Q_ASSERT(!parentBookmark.isNull());
00319     KBookmark newBookmark = parentBookmark.addBookmark( title, KUrl(m_pOwner->currentUrl()) );
00320     parentBookmark.moveBookmark( newBookmark, parentBookmark.previous(bm) );
00321     m_pManager->emitChanged( parentBookmark );
00322   }
00323 }
00324 
00325 void KBookmarkContextMenu::slotRemove()
00326 {
00327   //kDebug(7043) << "KBookmarkMenu::slotRemove" << m_highlightedAddress;
00328 
00329   bool folder = bm.isGroup();
00330 
00331   if (KMessageBox::warningContinueCancel(
00332           QApplication::activeWindow(),
00333           folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?", bm.text())
00334                  : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?", bm.text()),
00335           folder ? i18n("Bookmark Folder Deletion")
00336                  : i18n("Bookmark Deletion"),
00337           KStandardGuiItem::del())
00338         != KMessageBox::Continue
00339      )
00340     return;
00341 
00342   KBookmarkGroup parentBookmark = bm.parentGroup();
00343   parentBookmark.deleteBookmark( bm );
00344   m_pManager->emitChanged( parentBookmark );
00345 }
00346 
00347 void KBookmarkContextMenu::slotCopyLocation()
00348 {
00349   //kDebug(7043) << "KBookmarkMenu::slotCopyLocation" << m_highlightedAddress;
00350 
00351   if ( !bm.isGroup() )
00352   {
00353     QMimeData* mimeData = new QMimeData;
00354     bm.populateMimeData( mimeData );
00355     QApplication::clipboard()->setMimeData( mimeData, QClipboard::Selection );
00356     mimeData = new QMimeData;
00357     bm.populateMimeData( mimeData );
00358     QApplication::clipboard()->setMimeData( mimeData, QClipboard::Clipboard );
00359   }
00360 }
00361 
00362 void KBookmarkContextMenu::slotOpenFolderInTabs()
00363 {
00364   owner()->openFolderinTabs(bookmark().toGroup());
00365 }
00366 
00367 KBookmarkManager * KBookmarkContextMenu::manager() const
00368 {
00369     return m_pManager;
00370 }
00371 
00372 KBookmarkOwner * KBookmarkContextMenu::owner() const
00373 {
00374     return m_pOwner;
00375 }
00376 
00377 KBookmark KBookmarkContextMenu::bookmark() const
00378 {
00379     return bm;
00380 }
00381 
00382 /********************************************************************/
00383 /********************************************************************/
00384 /********************************************************************/
00385 void KBookmarkMenu::slotBookmarksChanged( const QString & groupAddress )
00386 {
00387   kDebug(7043)<<"KBookmarkMenu::slotBookmarksChanged( "<<groupAddress;
00388   if ( groupAddress == m_parentAddress )
00389   {
00390     //kDebug(7043) << "KBookmarkMenu::slotBookmarksChanged -> setting m_bDirty on " << groupAddress;
00391     m_bDirty = true;
00392   }
00393   else
00394   {
00395     // Iterate recursively into child menus
00396     for ( QList<KBookmarkMenu *>::iterator it = m_lstSubMenus.begin(), end = m_lstSubMenus.end() ;
00397           it != end ; ++it ) {
00398       (*it)->slotBookmarksChanged( groupAddress );
00399     }
00400   }
00401 }
00402 
00403 void KBookmarkMenu::clear()
00404 {
00405   qDeleteAll( m_lstSubMenus );
00406   m_lstSubMenus.clear();
00407 
00408   for ( QList<QAction *>::iterator it = m_actions.begin(), end = m_actions.end() ;
00409         it != end ; ++it )
00410   {
00411         m_parentMenu->removeAction(*it);
00412   }
00413 
00414   m_parentMenu->clear();
00415   m_actions.clear();
00416 }
00417 
00418 void KBookmarkMenu::refill()
00419 {
00420   //kDebug(7043) << "KBookmarkMenu::refill()";
00421   if(m_bIsRoot)
00422     addActions();
00423   fillBookmarks();
00424   if(!m_bIsRoot)
00425     addActions();
00426 }
00427 
00428 void KBookmarkMenu::addOpenInTabs()
00429 {
00430     if( !m_pOwner || !m_pOwner->supportsTabs() || !KAuthorized::authorizeKAction("bookmarks") )
00431         return;
00432 
00433     QString title = i18n( "Open Folder in Tabs" );
00434 
00435     KAction * paOpenFolderInTabs = new KAction( title, this );
00436     m_actionCollection->addAction( m_bIsRoot ? "open_folder_in_tabs" : 0, paOpenFolderInTabs );
00437     paOpenFolderInTabs->setIcon( KIcon("tab-new") );
00438     paOpenFolderInTabs->setToolTip( i18n( "Open all bookmarks in this folder as a new tab." ) );
00439     connect( paOpenFolderInTabs, SIGNAL( triggered( bool ) ), this, SLOT( slotOpenFolderInTabs() ) );
00440 
00441     m_parentMenu->addAction(paOpenFolderInTabs);
00442     m_actions.append( paOpenFolderInTabs );
00443 }
00444 
00445 void KBookmarkMenu::addAddBookmarksList()
00446 {
00447   if( !m_pOwner || !m_pOwner->enableOption(KBookmarkOwner::ShowAddBookmark) || !m_pOwner->supportsTabs() || !KAuthorized::authorizeKAction("bookmarks") )
00448     return;
00449 
00450   QString title = i18n( "Bookmark Tabs as Folder..." );
00451 
00452   KAction * paAddBookmarksList = new KAction( title, this );
00453   m_actionCollection->addAction( m_bIsRoot ? "add_bookmarks_list" : 0, paAddBookmarksList );
00454   paAddBookmarksList->setIcon( KIcon( "bookmark-new-list" ) );
00455   paAddBookmarksList->setToolTip( i18n( "Add a folder of bookmarks for all open tabs." ) );
00456   connect( paAddBookmarksList, SIGNAL( triggered( bool ) ), this, SLOT( slotAddBookmarksList() ) );
00457 
00458   m_parentMenu->addAction(paAddBookmarksList);
00459   m_actions.append( paAddBookmarksList );
00460 }
00461 
00462 void KBookmarkMenu::addAddBookmark()
00463 {
00464   if( !m_pOwner || !m_pOwner->enableOption(KBookmarkOwner::ShowAddBookmark) || !KAuthorized::authorizeKAction("bookmarks") )
00465     return;
00466 
00467   QString title = i18n( "Add Bookmark" );
00468 
00469   KAction * paAddBookmarks = new KAction( title, this );
00470   m_actionCollection->addAction( m_bIsRoot ? "add_bookmark" : 0, paAddBookmarks );
00471   paAddBookmarks->setIcon( KIcon( "bookmark-new" ) );
00472   paAddBookmarks->setShortcut( m_bIsRoot ? KStandardShortcut::addBookmark() : KShortcut() );
00473   paAddBookmarks->setToolTip( i18n( "Add a bookmark for the current document" ) );
00474   connect( paAddBookmarks, SIGNAL( triggered( bool ) ), this, SLOT( slotAddBookmark() ) );
00475 
00476   m_parentMenu->addAction(paAddBookmarks);
00477   m_actions.append( paAddBookmarks );
00478 }
00479 
00480 void KBookmarkMenu::addEditBookmarks()
00481 {
00482   if( m_pOwner && !m_pOwner->enableOption(KBookmarkOwner::ShowEditBookmark) || !KAuthorized::authorizeKAction("bookmarks") )
00483     return;
00484 
00485   QAction * m_paEditBookmarks = m_actionCollection->addAction( KStandardAction::EditBookmarks, "edit_bookmarks",
00486                                                                m_pManager, SLOT( slotEditBookmarks() ) );
00487   m_parentMenu->addAction(m_paEditBookmarks);
00488   m_paEditBookmarks->setToolTip( i18n( "Edit your bookmark collection in a separate window" ) );
00489   m_actions.append( m_paEditBookmarks );
00490 }
00491 
00492 void KBookmarkMenu::addNewFolder()
00493 {
00494   if( !m_pOwner || !m_pOwner->enableOption(KBookmarkOwner::ShowAddBookmark) || !KAuthorized::authorizeKAction("bookmarks"))
00495     return;
00496 
00497   KAction * paNewFolder = new KAction( i18n( "New Bookmark Folder..." ), this );
00498   m_actionCollection->addAction( "dummyname", paNewFolder );
00499   paNewFolder->setIcon( KIcon( "folder-new" ) );
00500   paNewFolder->setToolTip( i18n( "Create a new bookmark folder in this menu" ) );
00501   connect( paNewFolder, SIGNAL( triggered( bool ) ), this, SLOT( slotNewFolder() ) );
00502 
00503   m_parentMenu->addAction(paNewFolder);
00504   m_actions.append( paNewFolder );
00505 }
00506 
00507 void KBookmarkMenu::fillBookmarks()
00508 {
00509   KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
00510   Q_ASSERT(!parentBookmark.isNull());
00511 
00512   if ( m_bIsRoot && !parentBookmark.first().isNull() ) // at least one bookmark
00513   {
00514       m_parentMenu->addSeparator();
00515   }
00516 
00517   for ( KBookmark bm = parentBookmark.first(); !bm.isNull();  bm = parentBookmark.next(bm) )
00518   {
00519     m_parentMenu->addAction(actionForBookmark(bm));
00520   }
00521 }
00522 
00523 QAction* KBookmarkMenu::actionForBookmark(const KBookmark &bm)
00524 {
00525   if ( bm.isGroup() )
00526   {
00527     //kDebug(7043) << "Creating bookmark submenu named " << bm.text();
00528     KActionMenu * actionMenu = new KBookmarkActionMenu( bm, this );
00529     m_actionCollection->addAction( "kbookmarkmenu", actionMenu );
00530     m_actions.append( actionMenu );
00531     KBookmarkMenu *subMenu = new KBookmarkMenu( m_pManager, m_pOwner, actionMenu->menu(), bm.address() );
00532     m_lstSubMenus.append( subMenu );
00533     return actionMenu;
00534   }
00535   else if ( bm.isSeparator() )
00536   {
00537     QAction *sa = new QAction(this);
00538     sa->setSeparator(true);
00539     m_actions.append(sa);
00540     return sa;
00541   }
00542   else
00543   {
00544     //kDebug(7043) << "Creating bookmark menu item for " << bm.text();
00545     KAction * action = new KBookmarkAction( bm, m_pOwner, this );
00546     m_actionCollection->addAction(action->objectName(), action);
00547     m_actions.append( action );
00548     return action;
00549   }
00550 }
00551 
00552 void KBookmarkMenu::slotAddBookmarksList()
00553 {
00554   if( !m_pOwner || !m_pOwner->supportsTabs())
00555     return;
00556 
00557   KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
00558 
00559   KBookmarkDialog * dlg = m_pOwner->bookmarkDialog(m_pManager, QApplication::activeWindow());
00560   dlg->addBookmarks(m_pOwner->currentBookmarkList(), "", parentBookmark);
00561   delete dlg;
00562 }
00563 
00564 
00565 void KBookmarkMenu::slotAddBookmark()
00566 {
00567   if( !m_pOwner ) return;
00568   KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
00569 
00570   if(KBookmarkSettings::self()->m_advancedaddbookmark)
00571   {
00572       KBookmarkDialog * dlg = m_pOwner->bookmarkDialog(m_pManager, QApplication::activeWindow() );
00573       dlg->addBookmark(m_pOwner->currentTitle(), KUrl(m_pOwner->currentUrl()), parentBookmark );
00574       delete dlg;
00575   }
00576   else
00577   {
00578       parentBookmark.addBookmark(m_pOwner->currentTitle(), KUrl(m_pOwner->currentUrl()));
00579       m_pManager->emitChanged( parentBookmark );
00580   }
00581       
00582 }
00583 
00584 void KBookmarkMenu::slotOpenFolderInTabs()
00585 {
00586   m_pOwner->openFolderinTabs(m_pManager->findByAddress( m_parentAddress ).toGroup());
00587 }
00588 
00589 void KBookmarkMenu::slotNewFolder()
00590 {
00591   if ( !m_pOwner ) return; // this view doesn't handle bookmarks...
00592   KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
00593   Q_ASSERT(!parentBookmark.isNull());
00594   KBookmarkDialog * dlg = m_pOwner->bookmarkDialog(m_pManager, QApplication::activeWindow());
00595   dlg->createNewFolder("", parentBookmark);
00596   delete dlg;
00597 }
00598 
00599 void KImportedBookmarkMenu::slotNSLoad()
00600 {
00601   kDebug(7043)<<"**** slotNSLoad  ****"<<m_type<<"  "<<m_location;
00602   // only fill menu once
00603   parentMenu()->disconnect(SIGNAL(aboutToShow()));
00604 
00605   // not NSImporter, but kept old name for BC reasons
00606   KBookmarkMenuImporter importer( manager(), this );
00607   importer.openBookmarks(m_location, m_type);
00608 }
00609 
00610 KImportedBookmarkMenu::KImportedBookmarkMenu( KBookmarkManager* mgr,
00611                  KBookmarkOwner * owner, KMenu * parentMenu,
00612                  const QString & type, const QString & location )
00613     :KBookmarkMenu(mgr, owner, parentMenu, QString()), m_type(type), m_location(location)
00614 {
00615     connect(parentMenu, SIGNAL(aboutToShow()), this, SLOT(slotNSLoad()));
00616 }
00617 
00618 KImportedBookmarkMenu::KImportedBookmarkMenu( KBookmarkManager* mgr,
00619                  KBookmarkOwner * owner, KMenu * parentMenu)
00620     :KBookmarkMenu(mgr, owner, parentMenu, QString()), m_type(QString()), m_location(QString())
00621 {
00622 
00623 }
00624 
00625 KImportedBookmarkMenu::~KImportedBookmarkMenu()
00626 {
00627 
00628 }
00629 
00630 void KImportedBookmarkMenu::refill()
00631 {
00632 
00633 }
00634 
00635 void KImportedBookmarkMenu::clear()
00636 {
00637 
00638 }
00639 
00640 
00641 /********************************************************************/
00642 /********************************************************************/
00643 /********************************************************************/
00644 
00645 void KBookmarkMenuImporter::openBookmarks( const QString &location, const QString &type )
00646 {
00647   mstack.push(m_menu);
00648 
00649   KBookmarkImporterBase *importer = KBookmarkImporterBase::factory(type);
00650   if (!importer)
00651      return;
00652   importer->setFilename(location);
00653   connectToImporter(*importer);
00654   importer->parse();
00655 
00656   delete importer;
00657 }
00658 
00659 void KBookmarkMenuImporter::connectToImporter(const QObject &importer)
00660 {
00661   connect( &importer, SIGNAL( newBookmark( const QString &, const QString &, const QString & ) ),
00662            SLOT( newBookmark( const QString &, const QString &, const QString & ) ) );
00663   connect( &importer, SIGNAL( newFolder( const QString &, bool, const QString & ) ),
00664            SLOT( newFolder( const QString &, bool, const QString & ) ) );
00665   connect( &importer, SIGNAL( newSeparator() ), SLOT( newSeparator() ) );
00666   connect( &importer, SIGNAL( endFolder() ), SLOT( endFolder() ) );
00667 }
00668 
00669 void KBookmarkMenuImporter::newBookmark( const QString & text, const QString & url, const QString & )
00670 {
00671   KBookmark bm = KBookmark::standaloneBookmark(text, url, QString("html"));
00672   KAction * action = new KBookmarkAction(bm, mstack.top()->owner(), this);
00673   mstack.top()->parentMenu()->addAction(action);
00674   mstack.top()->m_actions.append( action );
00675 }
00676 
00677 void KBookmarkMenuImporter::newFolder( const QString & text, bool, const QString & )
00678 {
00679   QString _text = KStringHandler::csqueeze(text).replace( '&', "&&" );
00680   KActionMenu * actionMenu = new KImportedBookmarkActionMenu( KIcon("folder"), _text, this );
00681   mstack.top()->parentMenu()->addAction(actionMenu);
00682   mstack.top()->m_actions.append( actionMenu );
00683   KImportedBookmarkMenu *subMenu = new KImportedBookmarkMenu( m_pManager, m_menu->owner(), actionMenu->menu());
00684   mstack.top()->m_lstSubMenus.append( subMenu );
00685 
00686   mstack.push(subMenu);
00687 }
00688 
00689 void KBookmarkMenuImporter::newSeparator()
00690 {
00691   mstack.top()->parentMenu()->addSeparator();
00692 }
00693 
00694 void KBookmarkMenuImporter::endFolder()
00695 {
00696   mstack.pop();
00697 }
00698 
00699 /********************************************************************/
00700 /********************************************************************/
00701 /********************************************************************/
00702 
00703 
00704 KBookmarkAction::KBookmarkAction(const KBookmark &bk, KBookmarkOwner* owner, QObject *parent )
00705   : KAction( bk.text().replace('&', "&&"), parent),
00706     KBookmarkActionInterface(bk),
00707     m_pOwner(owner)
00708 {
00709   setIcon(KIcon(bookmark().icon()));
00710   setToolTip( bookmark().url().pathOrUrl() );
00711   connect(this, SIGNAL( triggered(Qt::MouseButtons, Qt::KeyboardModifiers) ),
00712      SLOT( slotSelected(Qt::MouseButtons, Qt::KeyboardModifiers) ));
00713 }
00714 
00715 KBookmarkAction::~KBookmarkAction()
00716 {
00717 }
00718 
00719 void KBookmarkAction::slotSelected(Qt::MouseButtons mb, Qt::KeyboardModifiers km)
00720 {
00721   if( !m_pOwner )
00722     new KRun( bookmark().url() ,(QWidget*)0);
00723   else
00724     m_pOwner->openBookmark( bookmark(), mb, km );
00725 }
00726 
00727 KBookmarkActionMenu::KBookmarkActionMenu(const KBookmark &bm, QObject *parent)
00728   : KActionMenu(KIcon(bm.icon()), bm.text().replace('&', "&&"), parent),
00729     KBookmarkActionInterface(bm)
00730 {
00731 }
00732 
00733 KBookmarkActionMenu::KBookmarkActionMenu(const KBookmark &bm, const QString & text, QObject *parent)
00734   : KActionMenu(text, parent),
00735     KBookmarkActionInterface(bm)
00736 {
00737 }
00738 
00739 KBookmarkActionMenu::~KBookmarkActionMenu()
00740 {
00741 }
00742 
00743 #include "kbookmarkmenu.moc"
00744 #include "kbookmarkmenu_p.moc"

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal