kbookmarkbar.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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
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;
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.