#include <kcelbookmarkmenu.h>
Collaboration diagram for KCelBookmarkMenu:

Public Slots | |
| void | slotBookmarksChanged (const QString &) |
Public Member Functions | |
| void | ensureUpToDate () |
| void | fillBookmarkMenu () |
| KCelBookmarkMenu (KBookmarkManager *mgr, KCelBookmarkOwner *owner, KPopupMenu *parentMenu, KActionCollection *collec, bool root, bool add=true, const QString &parentAddress="") | |
| ~KCelBookmarkMenu () | |
Protected Slots | |
| void | slotAboutToShow () |
| void | slotAddBookmark () |
| void | slotAddRelativeBookmark () |
| void | slotAddSettingsBookmark () |
| void | slotBookmarkSelected () |
| void | slotNewFolder () |
Protected Member Functions | |
| void | addAddBookmark () |
| void | addAddRelativeBookmark () |
| void | addAddSettingsBookmark () |
| void | addEditBookmarks () |
| void | addNewFolder () |
| void | refill () |
Protected Attributes | |
| KActionCollection * | m_actionCollection |
| QPtrList< KAction > | m_actions |
| bool | m_bAddBookmark:1 |
| bool | m_bDirty:1 |
| bool | m_bIsRoot:1 |
| bool | m_bNSBookmark:1 |
| QPtrList< KCelBookmarkMenu > | m_lstSubMenus |
| QString | m_parentAddress |
| KPopupMenu * | m_parentMenu |
| KBookmarkManager * | m_pManager |
| KCelBookmarkOwner * | m_pOwner |
This class provides a bookmark menu. It is typically used in cooperation with KActionMenu but doesn't have to be.
If you use this class by itself, then it will use KDE defaults for everything -- the bookmark path, bookmark editor, bookmark launcher.. everything. These defaults reside in the classes KBookmarkOwner (editing bookmarks) and KBookmarkManager (almost everything else). If you wish to change the defaults in any way, you must reimplement and instantiate those classes before this class is ever called.
Using this class is very simple:
1) Create a popup menu (either KActionMenu or KPopupMenu will do) 2) Instantiate a new KBookmarkMenu object using the above popup menu as a parameter 3) Insert your (now full) popup menu wherever you wish
Again, if you wish to modify any defaults, the procedure is:
1a) Reimplement your own KBookmarkOwner 1b) Reimplement and instantiate your own KBookmarkManager
Definition at line 67 of file kcelbookmarkmenu.h.
|
||||||||||||||||||||||||||||||||
|
Fills a bookmark menu (one instance of KBookmarkMenu is created for the toplevel menu, but also one per submenu).
Definition at line 57 of file kcelbookmarkmenu.cpp. References addAddBookmark(), addEditBookmarks(), m_actions, m_bAddBookmark, m_bDirty, m_bIsRoot, m_bNSBookmark, m_lstSubMenus, m_parentAddress, m_pManager, slotAboutToShow(), and slotBookmarksChanged(). Referenced by fillBookmarkMenu(). 00061 : m_bIsRoot(_isRoot), m_bAddBookmark(_add), 00062 m_pManager(mgr), m_pOwner(_owner), 00063 m_parentMenu( _parentMenu ), 00064 m_actionCollection( collec ), 00065 m_parentAddress( parentAddress ) 00066 { 00067 m_lstSubMenus.setAutoDelete( true ); 00068 m_actions.setAutoDelete( true ); 00069 00070 m_bNSBookmark = m_parentAddress.isNull(); 00071 if ( !m_bNSBookmark ) // not for the netscape bookmark 00072 { 00073 //kdDebug(1203) << "KBookmarkMenu::KBookmarkMenu " << this << " address : " << m_parentAddress << endl; 00074 00075 connect( _parentMenu, SIGNAL( aboutToShow() ), 00076 SLOT( slotAboutToShow() ) ); 00077 00078 if ( m_bIsRoot ) 00079 { 00080 connect( m_pManager, SIGNAL( changed(const QString &, const QString &) ), 00081 SLOT( slotBookmarksChanged(const QString &) ) ); 00082 } 00083 } 00084 00085 // add entries that possibly have a shortcut, so they are available _before_ first popup 00086 if ( m_bIsRoot ) 00087 { 00088 if ( m_bAddBookmark ) { 00089 addAddBookmark(); 00090 } 00091 00092 addEditBookmarks(); 00093 } 00094 00095 m_bDirty = true; 00096 }
|
|
|
Definition at line 98 of file kcelbookmarkmenu.cpp. References m_actions, and m_lstSubMenus. 00099 {
00100 //kdDebug(1203) << "KBookmarkMenu::~KBookmarkMenu() " << this << endl;
00101 QPtrListIterator<KAction> it( m_actions );
00102 for (; it.current(); ++it )
00103 it.current()->unplugAll();
00104
00105 m_lstSubMenus.clear();
00106 m_actions.clear();
00107 }
|
|
|
Definition at line 162 of file kcelbookmarkmenu.cpp. References addAddRelativeBookmark(), addAddSettingsBookmark(), m_actionCollection, m_actions, m_bIsRoot, m_parentMenu, and slotAddBookmark(). Referenced by fillBookmarkMenu(), and KCelBookmarkMenu(). 00163 {
00164 KAction * paAddBookmarks = new KAction( i18n( "&Add Bookmark" ),
00165 "bookmark_add",
00166 m_bIsRoot ? ALT + Key_B : 0,
00167 this,
00168 SLOT( slotAddBookmark() ),
00169 m_actionCollection, m_bIsRoot ? "add_bookmark" : 0 );
00170
00171 paAddBookmarks->setStatusText( i18n( "Add a bookmark for the current document" ) );
00172
00173 paAddBookmarks->plug( m_parentMenu );
00174 m_actions.append( paAddBookmarks );
00175 addAddRelativeBookmark();
00176 addAddSettingsBookmark();
00177 }
|
|
|
Definition at line 179 of file kcelbookmarkmenu.cpp. References m_actionCollection, m_actions, m_bIsRoot, m_parentMenu, and slotAddRelativeBookmark(). Referenced by addAddBookmark(). 00180 {
00181 KAction * paAddBookmarks = new KAction( i18n( "Add &Relative Bookmark" ),
00182 "bookmark_add",
00183 m_bIsRoot ? ALT + Key_R : 0, //m_bIsRoot ? KStdAccel::addBookmark() : KShortcut(),
00184 this,
00185 SLOT( slotAddRelativeBookmark() ),
00186 m_actionCollection, m_bIsRoot ? "add_relative_bookmark" : 0 );
00187
00188 paAddBookmarks->setStatusText( i18n( "Add a relative bookmark for the current document" ) );
00189
00190 paAddBookmarks->plug( m_parentMenu );
00191 m_actions.append( paAddBookmarks );
00192 }
|
|
|
Definition at line 194 of file kcelbookmarkmenu.cpp. References m_actionCollection, m_actions, m_bIsRoot, m_parentMenu, and slotAddSettingsBookmark(). Referenced by addAddBookmark(). 00195 {
00196 KAction * paAddBookmarks = new KAction( i18n( "Add &Settings Bookmark" ),
00197 "bookmark_add",
00198 m_bIsRoot ? CTRL + ALT + Key_S : 0, //m_bIsRoot ? KStdAccel::addBookmark() : KShortcut(),
00199 this,
00200 SLOT( slotAddSettingsBookmark() ),
00201 m_actionCollection, m_bIsRoot ? "add_settings_bookmark" : 0 );
00202
00203 paAddBookmarks->setStatusText( i18n( "Add a settings bookmark for the current document" ) );
00204
00205 paAddBookmarks->plug( m_parentMenu );
00206 m_actions.append( paAddBookmarks );
00207 }
|
|
|
Definition at line 209 of file kcelbookmarkmenu.cpp. References m_actionCollection, m_actions, m_parentMenu, and m_pManager. Referenced by fillBookmarkMenu(), and KCelBookmarkMenu(). 00210 {
00211 KAction * m_paEditBookmarks = KStdAction::editBookmarks( m_pManager, SLOT( slotEditBookmarks() ),
00212 m_actionCollection, "edit_bookmarks" );
00213 m_paEditBookmarks->plug( m_parentMenu );
00214 m_paEditBookmarks->setStatusText( i18n( "Edit your bookmark collection in a separate window" ) );
00215 m_actions.append( m_paEditBookmarks );
00216 }
|
|
|
Definition at line 218 of file kcelbookmarkmenu.cpp. References m_actionCollection, m_actions, m_parentMenu, and slotNewFolder(). Referenced by fillBookmarkMenu(). 00219 {
00220 KAction * paNewFolder = new KAction( i18n( "&New Folder..." ),
00221 "folder_new", //"folder",
00222 0,
00223 this,
00224 SLOT( slotNewFolder() ),
00225 m_actionCollection );
00226
00227 paNewFolder->setStatusText( i18n( "Create a new bookmark folder in this menu" ) );
00228
00229 paNewFolder->plug( m_parentMenu );
00230 m_actions.append( paNewFolder );
00231 }
|
|
|
Call ensureUpToDate() if you need KBookmarkMenu to adjust to its final size before it is executed. Definition at line 109 of file kcelbookmarkmenu.cpp. References slotAboutToShow(). 00110 {
00111 slotAboutToShow();
00112 }
|
|
|
Even if you think you need to use this, you are probably wrong. It fills a bookmark menu starting a given KBookmark. This is public for KBookmarkBar. Definition at line 233 of file kcelbookmarkmenu.cpp. References addAddBookmark(), addEditBookmarks(), addNewFolder(), KCelBookmarkMenu(), m_actionCollection, m_actions, m_bAddBookmark, m_bIsRoot, m_lstSubMenus, m_parentAddress, m_parentMenu, m_pManager, m_pOwner, and slotBookmarkSelected(). Referenced by refill(). 00234 {
00235 if ( m_bIsRoot )
00236 {
00237 if ( m_bAddBookmark )
00238 addAddBookmark();
00239
00240 addEditBookmarks();
00241
00242 if ( m_bAddBookmark )
00243 addNewFolder();
00244
00245 }
00246
00247 KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
00248 Q_ASSERT(!parentBookmark.isNull());
00249 bool separatorInserted = false;
00250 for ( KBookmark bm = parentBookmark.first(); !bm.isNull(); bm = parentBookmark.next(bm) )
00251 {
00252 QString text = bm.text();
00253 text.replace( QRegExp( "&" ), "&&" );
00254 if ( !separatorInserted && m_bIsRoot) { // inserted before the first konq bookmark, to avoid the separator if no konq bookmark
00255 m_parentMenu->insertSeparator();
00256 separatorInserted = true;
00257 }
00258 if ( !bm.isGroup() )
00259 {
00260 if ( bm.isSeparator() )
00261 {
00262 m_parentMenu->insertSeparator();
00263 }
00264 else
00265 {
00266 // kdDebug(1203) << "Creating URL bookmark menu item for " << bm.text() << endl;
00267 // create a normal URL item, with ID as a name
00268 KAction * action = new KAction( text, bm.icon(), 0,
00269 this, SLOT( slotBookmarkSelected() ),
00270 m_actionCollection, bm.url().url().utf8() );
00271
00272 action->setStatusText( bm.url().prettyURL() );
00273
00274 action->plug( m_parentMenu );
00275 m_actions.append( action );
00276 }
00277 }
00278 else
00279 {
00280 // kdDebug(1203) << "Creating bookmark submenu named " << bm.text() << endl;
00281 KActionMenu * actionMenu = new KActionMenu( text, bm.icon(),
00282 m_actionCollection, 0L );
00283 actionMenu->plug( m_parentMenu );
00284 m_actions.append( actionMenu );
00285 KCelBookmarkMenu *subMenu = new KCelBookmarkMenu( m_pManager, m_pOwner, actionMenu->popupMenu(),
00286 m_actionCollection, false,
00287 m_bAddBookmark,
00288 bm.address() );
00289 m_lstSubMenus.append( subMenu );
00290 }
00291 }
00292
00293 if ( !m_bIsRoot && m_bAddBookmark )
00294 {
00295 m_parentMenu->insertSeparator();
00296 addAddBookmark();
00297 addNewFolder();
00298 }
00299 }
|
|
|
Definition at line 146 of file kcelbookmarkmenu.cpp. References fillBookmarkMenu(), m_actions, m_lstSubMenus, and m_parentMenu. Referenced by slotAboutToShow(). 00147 {
00148 //kdDebug(1203) << "KBookmarkMenu::refill()" << endl;
00149 m_lstSubMenus.clear();
00150
00151 QPtrListIterator<KAction> it( m_actions );
00152 for (; it.current(); ++it )
00153 it.current()->unplug( m_parentMenu );
00154
00155 m_parentMenu->clear();
00156 m_actions.clear();
00157
00158 fillBookmarkMenu();
00159 m_parentMenu->adjustSize();
00160 }
|
|
|
Definition at line 115 of file kcelbookmarkmenu.cpp. References m_bDirty, and refill(). Referenced by ensureUpToDate(), and KCelBookmarkMenu(). 00116 {
00117 // Did the bookmarks change since the last time we showed them ?
00118 if ( m_bDirty )
00119 {
00120 m_bDirty = false;
00121 refill();
00122 }
00123 }
|
|
|
Definition at line 395 of file kcelbookmarkmenu.cpp. References KCelBookmarkOwner::currentIcon(), KCelBookmarkOwner::currentUrl(), Url::getAsString(), Url::getName(), m_parentAddress, m_pManager, and m_pOwner. Referenced by addAddBookmark(). 00396 {
00397 Url Url = m_pOwner->currentUrl(Url::Absolute);
00398 QString url = QString(Url.getAsString().c_str());;
00399 if (url.isEmpty())
00400 {
00401 KMessageBox::error( 0L, i18n("Can't add bookmark with empty URL"));
00402 return;
00403 }
00404 QString title = QString(Url.getName().c_str());
00405 if (title.isEmpty())
00406 title = url;
00407
00408 KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
00409 Q_ASSERT(!parentBookmark.isNull());
00410 // If this title is already used, we'll try to find something unused.
00411 KBookmark ch = parentBookmark.first();
00412 int count = 1;
00413 QString uniqueTitle = title;
00414 do
00415 {
00416 while ( !ch.isNull() )
00417 {
00418 if ( uniqueTitle == ch.text() )
00419 {
00420 // Title already used !
00421 if ( url != ch.url().url() )
00422 {
00423 uniqueTitle = title + QString(" (%1)").arg(++count);
00424 // New title -> restart search from the beginning
00425 ch = parentBookmark.first();
00426 break;
00427 }
00428 else
00429 {
00430 // this exact URL already exists
00431 return;
00432 }
00433 }
00434 ch = parentBookmark.next( ch );
00435 }
00436 } while ( !ch.isNull() );
00437
00438 parentBookmark.addBookmark( m_pManager, uniqueTitle, url, m_pOwner->currentIcon() );
00439 m_pManager->emitChanged( parentBookmark );
00440 }
|
|
|
Definition at line 301 of file kcelbookmarkmenu.cpp. References KCelBookmarkOwner::currentIcon(), KCelBookmarkOwner::currentUrl(), Url::getAsString(), Url::getName(), m_parentAddress, m_pManager, and m_pOwner. Referenced by addAddRelativeBookmark(). 00302 {
00303 Url Url = m_pOwner->currentUrl(Url::Relative);
00304 QString url = QString(Url.getAsString().c_str());;
00305 if (url.isEmpty())
00306 {
00307 KMessageBox::error( 0L, i18n("Can't add bookmark with empty URL"));
00308 return;
00309 }
00310 QString title = QString(Url.getName().c_str());
00311 if (title.isEmpty())
00312 title = url;
00313
00314 KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
00315 Q_ASSERT(!parentBookmark.isNull());
00316 // If this title is already used, we'll try to find something unused.
00317 KBookmark ch = parentBookmark.first();
00318 int count = 1;
00319 QString uniqueTitle = title;
00320 do
00321 {
00322 while ( !ch.isNull() )
00323 {
00324 if ( uniqueTitle == ch.text() )
00325 {
00326 // Title already used !
00327 if ( url != ch.url().url() )
00328 {
00329 uniqueTitle = title + QString(" (%1)").arg(++count);
00330 // New title -> restart search from the beginning
00331 ch = parentBookmark.first();
00332 break;
00333 }
00334 else
00335 {
00336 // this exact URL already exists
00337 return;
00338 }
00339 }
00340 ch = parentBookmark.next( ch );
00341 }
00342 } while ( !ch.isNull() );
00343
00344 parentBookmark.addBookmark( m_pManager, uniqueTitle, url, m_pOwner->currentIcon() );
00345 m_pManager->emitChanged( parentBookmark );
00346 }
|
|
|
Definition at line 348 of file kcelbookmarkmenu.cpp. References KCelBookmarkOwner::currentIcon(), KCelBookmarkOwner::currentUrl(), Url::getAsString(), Url::getName(), m_parentAddress, m_pManager, and m_pOwner. Referenced by addAddSettingsBookmark(). 00349 {
00350 Url Url = m_pOwner->currentUrl(Url::Settings);
00351 QString url = QString(Url.getAsString().c_str());;
00352 if (url.isEmpty())
00353 {
00354 KMessageBox::error( 0L, i18n("Can't add bookmark with empty URL"));
00355 return;
00356 }
00357 QString title = QString(Url.getName().c_str());
00358 if (title.isEmpty())
00359 title = url;
00360
00361 KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
00362 Q_ASSERT(!parentBookmark.isNull());
00363 // If this title is already used, we'll try to find something unused.
00364 KBookmark ch = parentBookmark.first();
00365 int count = 1;
00366 QString uniqueTitle = title;
00367 do
00368 {
00369 while ( !ch.isNull() )
00370 {
00371 if ( uniqueTitle == ch.text() )
00372 {
00373 // Title already used !
00374 if ( url != ch.url().url() )
00375 {
00376 uniqueTitle = title + QString(" (%1)").arg(++count);
00377 // New title -> restart search from the beginning
00378 ch = parentBookmark.first();
00379 break;
00380 }
00381 else
00382 {
00383 // this exact URL already exists
00384 return;
00385 }
00386 }
00387 ch = parentBookmark.next( ch );
00388 }
00389 } while ( !ch.isNull() );
00390
00391 parentBookmark.addBookmark( m_pManager, uniqueTitle, url, m_pOwner->currentIcon() );
00392 m_pManager->emitChanged( parentBookmark );
00393 }
|
|
|
Definition at line 125 of file kcelbookmarkmenu.cpp. References m_bDirty, m_bNSBookmark, m_lstSubMenus, and m_parentAddress. Referenced by KCelBookmarkMenu(). 00126 {
00127 if (m_bNSBookmark)
00128 return;
00129
00130 if ( groupAddress == m_parentAddress )
00131 {
00132 //kdDebug(1203) << "KBookmarkMenu::slotBookmarksChanged -> setting m_bDirty on " << groupAddress << endl;
00133 m_bDirty = true;
00134 }
00135 else
00136 {
00137 // Iterate recursively into child menus
00138 QPtrListIterator<KCelBookmarkMenu> it( m_lstSubMenus );
00139 for (; it.current(); ++it )
00140 {
00141 it.current()->slotBookmarksChanged( groupAddress );
00142 }
00143 }
00144 }
|
|
|
Definition at line 455 of file kcelbookmarkmenu.cpp. References m_pOwner. Referenced by fillBookmarkMenu(). 00456 {
00457 //kdDebug(1203) << "KBookmarkMenu::slotBookmarkSelected()" << endl;
00458 if ( !m_pOwner ) return; // this view doesn't handle bookmarks...
00459 //kdDebug(1203) << sender()->name() << endl;
00460
00461 // The name of the action is the URL to open
00462 m_pOwner->openBookmarkURL( QString::fromUtf8(sender()->name()) );
00463 }
|
|
|
Definition at line 442 of file kcelbookmarkmenu.cpp. References m_parentAddress, m_pManager, and m_pOwner. Referenced by addNewFolder(). 00443 {
00444 if ( !m_pOwner ) return; // this view doesn't handle bookmarks...
00445 KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
00446 Q_ASSERT(!parentBookmark.isNull());
00447 KBookmarkGroup group = parentBookmark.createNewFolder( m_pManager );
00448 if ( !group.isNull() )
00449 {
00450 KBookmarkGroup parentGroup = group.parentGroup();
00451 m_pManager->emitChanged( parentGroup );
00452 }
00453 }
|
|
|
Definition at line 143 of file kcelbookmarkmenu.h. Referenced by addAddBookmark(), addAddRelativeBookmark(), addAddSettingsBookmark(), addEditBookmarks(), addNewFolder(), and fillBookmarkMenu(). |
|
|
List of our actions. Definition at line 147 of file kcelbookmarkmenu.h. Referenced by addAddBookmark(), addAddRelativeBookmark(), addAddSettingsBookmark(), addEditBookmarks(), addNewFolder(), fillBookmarkMenu(), KCelBookmarkMenu(), refill(), and ~KCelBookmarkMenu(). |
|
|
Definition at line 128 of file kcelbookmarkmenu.h. Referenced by fillBookmarkMenu(), and KCelBookmarkMenu(). |
|
|
Definition at line 129 of file kcelbookmarkmenu.h. Referenced by KCelBookmarkMenu(), slotAboutToShow(), and slotBookmarksChanged(). |
|
|
Definition at line 127 of file kcelbookmarkmenu.h. Referenced by addAddBookmark(), addAddRelativeBookmark(), addAddSettingsBookmark(), fillBookmarkMenu(), and KCelBookmarkMenu(). |
|
|
Definition at line 130 of file kcelbookmarkmenu.h. Referenced by KCelBookmarkMenu(), and slotBookmarksChanged(). |
|
|
List of our sub menus Definition at line 142 of file kcelbookmarkmenu.h. Referenced by fillBookmarkMenu(), KCelBookmarkMenu(), refill(), slotBookmarksChanged(), and ~KCelBookmarkMenu(). |
|
|
Parent bookmark for this menu. Definition at line 151 of file kcelbookmarkmenu.h. Referenced by fillBookmarkMenu(), KCelBookmarkMenu(), slotAddBookmark(), slotAddRelativeBookmark(), slotAddSettingsBookmark(), slotBookmarksChanged(), and slotNewFolder(). |
|
|
The menu in which we plug our actions. Supplied in the constructor. Definition at line 138 of file kcelbookmarkmenu.h. Referenced by addAddBookmark(), addAddRelativeBookmark(), addAddSettingsBookmark(), addEditBookmarks(), addNewFolder(), fillBookmarkMenu(), and refill(). |
|
|
Definition at line 132 of file kcelbookmarkmenu.h. Referenced by addEditBookmarks(), fillBookmarkMenu(), KCelBookmarkMenu(), slotAddBookmark(), slotAddRelativeBookmark(), slotAddSettingsBookmark(), and slotNewFolder(). |
|
|
Definition at line 133 of file kcelbookmarkmenu.h. Referenced by fillBookmarkMenu(), slotAddBookmark(), slotAddRelativeBookmark(), slotAddSettingsBookmark(), slotBookmarkSelected(), and slotNewFolder(). |
1.4.1