kbookmarkbar.cc Source File (kio Library)

| # kio Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kbookmarkbar.cc

    00001 /* This file is part of the KDE project
    00002    Copyright (C) 1999 Kurt Granroth <granroth@kde.org>
    00003    Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
    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., 59 Temple Place - Suite 330,
    00018    Boston, MA 02111-1307, USA.
    00019 */
    00020 #include <qregexp.h>
    00021
    00022 #include <kbookmarkbar.h>
    00023
    00024 #include <kaction.h>
    00025 #include <kbookmarkmenu.h>
    00026
    00027 #include <ktoolbar.h>
    00028
    00029 #include <kconfig.h>
    00030 #include <kpopupmenu.h>
    00031
    00032
    00033 KBookmarkBar::KBookmarkBar( KBookmarkManager* mgr,
    00034                             KBookmarkOwner *_owner, KToolBar *_toolBar,
    00035                             KActionCollection *coll,
    00036                             QObject *parent, const char *name )
    00037     : QObject( parent, name ), m_pOwner(_owner), m_toolBar(_toolBar),
    00038       m_actionCollection( coll ), m_pManager(mgr)
    00039 {
    00040     m_lstSubMenus.setAutoDelete( true );
    00041
    00042     connect( mgr, SIGNAL( changed(const QString &, const QString &) ),
    00043              SLOT( slotBookmarksChanged(const QString &) ) );
    00044
    00045     KBookmarkGroup toolbar = mgr->toolbar();
    00046     fillBookmarkBar( toolbar );
    00047 }
    00048
    00049 KBookmarkBar::~KBookmarkBar()
    00050 {
    00051     clear();
    00052 }
    00053
    00054 void KBookmarkBar::clear()
    00055 {
    00056     m_lstSubMenus.clear();
    00057
    00058     if ( m_toolBar )
    00059         m_toolBar->clear();
    00060 }
    00061
    00062 void KBookmarkBar::slotBookmarksChanged( const QString & group )
    00063 {
    00064     KBookmarkGroup tb = m_pManager->toolbar();
    00065     if ( tb.isNull() )
    00066         return;
    00067     if ( tb.address() == group )
    00068     {
    00069         clear();
    00070
    00071         fillBookmarkBar( tb );
    00072     } else
    00073     {
    00074         // Iterate recursively into child menus
    00075         QPtrListIterator<KBookmarkMenu> it( m_lstSubMenus );
    00076         for (; it.current(); ++it )
    00077         {
    00078             it.current()->slotBookmarksChanged( group );
    00079         }
    00080     }
    00081
    00082 }
    00083
    00084 void KBookmarkBar::fillBookmarkBar(KBookmarkGroup & parent)
    00085 {
    00086     if (parent.isNull())
    00087         return;
    00088
    00089     for (KBookmark bm = parent.first(); !bm.isNull(); bm = parent.next(bm))
    00090     {
    00091         QString text = bm.text();
    00092         text.replace( '&', "&&" );
    00093         if (!bm.isGroup())
    00094         {
    00095             if ( bm.isSeparator() )
    00096                 m_toolBar->insertLineSeparator();
    00097             else
    00098             {
    00099                 KAction *action;
    00100                 // create a normal URL item, with ID as a name
    00101                 action = new KAction(text, bm.icon(), 0,
    00102                                      this, SLOT(slotBookmarkSelected()),
    00103                                      m_actionCollection,
    00104                                      bm.url().url().utf8());
    00105                 action->plug(m_toolBar);
    00106             }
    00107         }
    00108         else
    00109         {
    00110             KActionMenu *action = new KActionMenu(text, bm.icon(),
    00111                                                   m_actionCollection, "bookmarkbar-actionmenu");
    00112             action->setDelayed(false);
    00113
    00114             // this flag doesn't have any UI yet
    00115             KGlobal::config()->setGroup( "Settings" );
    00116             bool addEntriesBookmarkBar = KGlobal::config()->readBoolEntry("AddEntriesBookmarkBar",true);
    00117
    00118             KBookmarkMenu *menu = new KBookmarkMenu(m_pManager, m_pOwner, action->popupMenu(),
    00119                                                     m_actionCollection, false, addEntriesBookmarkBar,
    00120                                                     bm.address());
    00121             menu->fillBookmarkMenu();
    00122             action->plug(m_toolBar);
    00123             m_lstSubMenus.append( menu );
    00124         }
    00125     }
    00126 }
    00127
    00128 void KBookmarkBar::slotBookmarkSelected()
    00129 {
    00130     if (!m_pOwner) return; // this view doesn't handle bookmarks...
    00131
    00132     m_pOwner->openBookmarkURL(QString::fromUtf8(sender()->name()));
    00133 }
    00134
    00135 #include "kbookmarkbar.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:13:10 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001