22 #include "kbookmarkmenu.h"
23 #include "kbookmarkmenu_p.h"
24 #include "kbookmarkimporter.h"
25 #include "kbookmarkimporter_opera.h"
26 #include "kbookmarkimporter_ie.h"
27 #include "kbookmarkdrag.h"
29 #include <kapplication.h>
32 #include <kdialogbase.h>
33 #include <kiconloader.h>
34 #include <klineedit.h>
36 #include <kmessagebox.h>
37 #include <kpopupmenu.h>
38 #include <kstdaccel.h>
39 #include <kstdaction.h>
40 #include <kstringhandler.h>
42 #include <tqclipboard.h>
47 #include <tqlineedit.h>
48 #include <tqlistview.h>
49 #include <tqpushbutton.h>
51 #include <dptrtemplate.h>
53 template class TQPtrList<KBookmarkMenu>;
55 static TQString makeTextNodeMod(KBookmark bk,
const TQString &m_nodename,
const TQString &m_newText) {
56 TQDomNode subnode = bk.internalElement().namedItem(m_nodename);
57 if (subnode.isNull()) {
58 subnode = bk.internalElement().ownerDocument().createElement(m_nodename);
59 bk.internalElement().appendChild(subnode);
62 if (subnode.firstChild().isNull()) {
63 TQDomText domtext = subnode.ownerDocument().createTextNode(
"");
64 subnode.appendChild(domtext);
67 TQDomText domtext = subnode.firstChild().toText();
69 TQString m_oldText = domtext.data();
70 domtext.setData(m_newText);
81 KActionCollection *collec,
bool _isRoot,
bool _add,
82 const TQString & parentAddress )
84 m_bIsRoot(_isRoot), m_bAddBookmark(_add),
85 m_bAddShortcuts(true),
86 m_pManager(mgr), m_pOwner(_owner),
87 m_parentMenu( _parentMenu ),
88 m_actionCollection( collec ),
89 m_parentAddress( parentAddress )
96 if (m_actionCollection)
98 m_actionCollection->setHighlightingEnabled(
true);
99 disconnect( m_actionCollection, TQT_SIGNAL( actionHighlighted( KAction * ) ), 0, 0 );
100 connect( m_actionCollection, TQT_SIGNAL( actionHighlighted( KAction * ) ),
101 this, TQT_SLOT( slotActionHighlighted( KAction * ) ) );
105 if ( !m_bNSBookmark )
109 connect( _parentMenu, TQT_SIGNAL( aboutToShow() ),
110 TQT_SLOT( slotAboutToShow() ) );
112 if ( KBookmarkSettings::self()->m_contextmenu )
114 (void) _parentMenu->contextMenu();
115 connect( _parentMenu, TQT_SIGNAL( aboutToShowContextMenu(KPopupMenu*,
int, TQPopupMenu*) ),
116 this, TQT_SLOT( slotAboutToShowContextMenu(KPopupMenu*,
int, TQPopupMenu*) ));
121 connect( m_pManager, TQT_SIGNAL( changed(
const TQString &,
const TQString &) ),
122 TQT_SLOT( slotBookmarksChanged(
const TQString &) ) );
129 if ( m_bAddBookmark )
133 addAddBookmarksList();
142 KBookmarkMenu::~KBookmarkMenu()
145 TQPtrListIterator<KAction> it(
m_actions );
146 for (; it.current(); ++it )
147 it.current()->unplugAll();
158 void KBookmarkMenu::slotAboutToShow()
168 TQString KBookmarkMenu::s_highlightedAddress;
169 TQString KBookmarkMenu::s_highlightedImportType;
170 TQString KBookmarkMenu::s_highlightedImportLocation;
172 void KBookmarkMenu::slotActionHighlighted( KAction* action )
174 if (action->isA(
"KBookmarkActionMenu") || action->isA(
"KBookmarkAction"))
176 s_highlightedAddress = action->property(
"address").toString();
179 else if (action->isA(
"KImportedBookmarksActionMenu"))
181 s_highlightedImportType = action->property(
"type").toString();
182 s_highlightedImportLocation = action->property(
"location").toString();
186 s_highlightedAddress = TQString::null;
187 s_highlightedImportType = TQString::null;
188 s_highlightedImportLocation = TQString::null;
196 class KBookmarkMenuRMBAssoc :
public dPtrTemplate<KBookmarkMenu, RMB> { };
197 template<> TQPtrDict<RMB>* dPtrTemplate<KBookmarkMenu, RMB>::d_ptr = 0;
199 static RMB* rmbSelf(
KBookmarkMenu *m) {
return KBookmarkMenuRMBAssoc::d(m); }
205 RMB *s = rmbSelf(
self);
207 s->m_parentAddress =
self->m_parentAddress;
208 s->s_highlightedAddress = KBookmarkMenu::s_highlightedAddress;
209 s->m_pManager =
self->m_pManager;
210 s->m_pOwner =
self->m_pOwner;
211 s->m_parentMenu =
self->m_parentMenu;
214 bool RMB::invalid(
int val )
219 s_highlightedAddress = m_parentAddress;
221 if (s_highlightedAddress.isNull())
227 KBookmark RMB::atAddress(
const TQString & address)
229 KBookmark bookmark = m_pManager->findByAddress( address );
230 Q_ASSERT(!bookmark.isNull());
234 void KBookmarkMenu::slotAboutToShowContextMenu( KPopupMenu*,
int, TQPopupMenu* contextMenu )
237 if (s_highlightedAddress.isNull())
239 KPopupMenu::contextMenuFocus()->hideContextMenu();
242 contextMenu->clear();
243 fillContextMenu( contextMenu, s_highlightedAddress, 0 );
246 void RMB::fillContextMenu( TQPopupMenu* contextMenu,
const TQString & address,
int val )
248 KBookmark bookmark = atAddress(address);
259 id = contextMenu->insertItem( SmallIcon(
"bookmark_add"), i18n(
"Add Bookmark Here" ), recv, TQT_SLOT(slotRMBActionInsert(
int)) );
260 contextMenu->setItemParameter(
id, val );
269 void RMB::fillContextMenu2( TQPopupMenu* contextMenu,
const TQString & address,
int val )
271 KBookmark bookmark = atAddress(address);
275 if (bookmark.isGroup()) {
276 id = contextMenu->insertItem( i18n(
"Open Folder in Bookmark Editor" ), recv, TQT_SLOT(slotRMBActionEditAt(
int)) );
277 contextMenu->setItemParameter(
id, val );
278 contextMenu->insertSeparator();
279 id = contextMenu->insertItem( SmallIcon(
"editdelete"), i18n(
"Delete Folder" ), recv, TQT_SLOT(slotRMBActionRemove(
int)) );
280 contextMenu->setItemParameter(
id, val );
281 contextMenu->insertSeparator();
282 id = contextMenu->insertItem( i18n(
"Properties" ), recv, TQT_SLOT(slotRMBActionProperties(
int)) );
283 contextMenu->setItemParameter(
id, val );
287 id = contextMenu->insertItem( i18n(
"Copy Link Address" ), recv, TQT_SLOT(slotRMBActionCopyLocation(
int)) );
288 contextMenu->setItemParameter(
id, val );
289 contextMenu->insertSeparator();
290 id = contextMenu->insertItem( SmallIcon(
"editdelete"), i18n(
"Delete Bookmark" ), recv, TQT_SLOT(slotRMBActionRemove(
int)) );
291 contextMenu->setItemParameter(
id, val );
292 contextMenu->insertSeparator();
293 id = contextMenu->insertItem( i18n(
"Properties" ), recv, TQT_SLOT(slotRMBActionProperties(
int)) );
294 contextMenu->setItemParameter(
id, val );
298 void RMB::slotRMBActionEditAt(
int val )
300 kdDebug(7043) <<
"KBookmarkMenu::slotRMBActionEditAt" << s_highlightedAddress << endl;
301 if (invalid(val)) { hidePopup();
return; }
303 KBookmark bookmark = atAddress(s_highlightedAddress);
305 m_pManager->slotEditBookmarksAtAddress( s_highlightedAddress );
308 void RMB::slotRMBActionProperties(
int val )
310 kdDebug(7043) <<
"KBookmarkMenu::slotRMBActionProperties" << s_highlightedAddress << endl;
311 if (invalid(val)) { hidePopup();
return; }
313 KBookmark bookmark = atAddress(s_highlightedAddress);
315 TQString folder = bookmark.isGroup() ? TQString::null : bookmark.url().pathOrURL();
316 KBookmarkEditDialog dlg( bookmark.fullText(), folder,
317 m_pManager, KBookmarkEditDialog::ModifyMode, 0,
318 0, 0, i18n(
"Bookmark Properties") );
319 if ( dlg.exec() != KDialogBase::Accepted )
322 makeTextNodeMod(bookmark,
"title", dlg.finalTitle());
323 if ( !dlg.finalUrl().isNull() )
325 KURL u = KURL::fromPathOrURL(dlg.finalUrl());
326 bookmark.internalElement().setAttribute(
"href", u.url(0, 106));
329 kdDebug(7043) <<
"Requested move to " << dlg.finalAddress() <<
"!" << endl;
331 KBookmarkGroup parentBookmark = atAddress(m_parentAddress).toGroup();
332 m_pManager->emitChanged( parentBookmark );
335 void RMB::slotRMBActionInsert(
int val )
337 kdDebug(7043) <<
"KBookmarkMenu::slotRMBActionInsert" << s_highlightedAddress << endl;
338 if (invalid(val)) { hidePopup();
return; }
340 TQString url = m_pOwner->currentURL();
343 KMessageBox::error( 0L, i18n(
"Cannot add bookmark with empty URL."));
346 TQString title = m_pOwner->currentTitle();
350 KBookmark bookmark = atAddress( s_highlightedAddress );
354 if (bookmark.isGroup())
357 Q_ASSERT(!parentBookmark.isNull());
358 parentBookmark.
addBookmark( m_pManager, title, KURL( url ) );
359 m_pManager->emitChanged( parentBookmark );
364 Q_ASSERT(!parentBookmark.isNull());
365 KBookmark newBookmark = parentBookmark.
addBookmark( m_pManager, title, KURL( url ) );
367 m_pManager->emitChanged( parentBookmark );
371 void RMB::slotRMBActionRemove(
int val )
374 if (invalid(val)) { hidePopup();
return; }
376 KBookmark bookmark = atAddress( s_highlightedAddress );
377 bool folder = bookmark.isGroup();
379 if (KMessageBox::warningContinueCancel(
381 folder ? i18n(
"Are you sure you wish to remove the bookmark folder\n\"%1\"?").arg(bookmark.text())
382 : i18n(
"Are you sure you wish to remove the bookmark\n\"%1\"?").arg(bookmark.text()),
383 folder ? i18n(
"Bookmark Folder Deletion")
384 : i18n(
"Bookmark Deletion"),
386 != KMessageBox::Continue
390 KBookmarkGroup parentBookmark = atAddress( m_parentAddress ).toGroup();
392 m_pManager->emitChanged( parentBookmark );
394 m_parentMenu->hide();
397 void RMB::slotRMBActionCopyLocation(
int val )
400 if (invalid(val)) { hidePopup();
return; }
402 KBookmark bookmark = atAddress( s_highlightedAddress );
404 if ( !bookmark.isGroup() )
406 kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0),
407 TQClipboard::Selection );
408 kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0),
409 TQClipboard::Clipboard );
413 void RMB::hidePopup() {
414 KPopupMenu::contextMenuFocus()->hideContextMenu();
421 void KBookmarkMenu::fillContextMenu( TQPopupMenu* contextMenu,
const TQString & address,
int val )
423 RMB::begin_rmb_action(
this);
424 rmbSelf(
this)->fillContextMenu(contextMenu, address, val);
425 emit aboutToShowContextMenu( rmbSelf(
this)->atAddress(address), contextMenu);
426 rmbSelf(
this)->fillContextMenu2(contextMenu, address, val);
429 void KBookmarkMenu::slotRMBActionEditAt(
int val )
430 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionEditAt( val ); }
432 void KBookmarkMenu::slotRMBActionProperties(
int val )
433 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionProperties( val ); }
435 void KBookmarkMenu::slotRMBActionInsert(
int val )
436 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionInsert( val ); }
438 void KBookmarkMenu::slotRMBActionRemove(
int val )
439 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionRemove( val ); }
441 void KBookmarkMenu::slotRMBActionCopyLocation(
int val )
442 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionCopyLocation( val ); }
444 void KBookmarkMenu::slotBookmarksChanged(
const TQString & groupAddress )
458 for (; it.current(); ++it )
460 it.current()->slotBookmarksChanged( groupAddress );
465 void KBookmarkMenu::refill()
470 TQPtrListIterator<KAction> it(
m_actions );
471 for (; it.current(); ++it )
481 void KBookmarkMenu::addAddBookmarksList()
483 if (!kapp->authorizeKAction(
"bookmarks"))
486 TQString title = i18n(
"Bookmark Tabs as Folder..." );
488 KAction * paAddBookmarksList =
new KAction( title,
489 "bookmarks_list_add",
492 TQT_SLOT( slotAddBookmarksList() ),
493 m_actionCollection, m_bIsRoot ?
"add_bookmarks_list" : 0 );
495 paAddBookmarksList->setToolTip( i18n(
"Add a folder of bookmarks for all open tabs." ) );
501 void KBookmarkMenu::addAddBookmark()
503 if (!kapp->authorizeKAction(
"bookmarks"))
506 TQString title = i18n(
"Add Bookmark" );
508 KAction * paAddBookmarks =
new KAction( title,
510 m_bIsRoot && m_bAddShortcuts ? KStdAccel::addBookmark() : KShortcut(),
512 TQT_SLOT( slotAddBookmark() ),
513 m_actionCollection, m_bIsRoot ?
"add_bookmark" : 0 );
515 paAddBookmarks->setToolTip( i18n(
"Add a bookmark for the current document" ) );
521 void KBookmarkMenu::addEditBookmarks()
523 if (!kapp->authorizeKAction(
"bookmarks"))
526 KAction * m_paEditBookmarks = KStdAction::editBookmarks( m_pManager, TQT_SLOT( slotEditBookmarks() ),
527 m_actionCollection,
"edit_bookmarks" );
529 m_paEditBookmarks->setToolTip( i18n(
"Edit your bookmark collection in a separate window" ) );
533 void KBookmarkMenu::addNewFolder()
535 if (!kapp->authorizeKAction(
"bookmarks"))
538 TQString title = i18n(
"&New Bookmark Folder..." );
540 while ( ( p = title.find(
'&' ) ) >= 0 )
541 title.remove( p, 1 );
543 KAction * paNewFolder =
new KAction( title,
547 TQT_SLOT( slotNewFolder() ),
548 m_actionCollection );
550 paNewFolder->setToolTip( i18n(
"Create a new bookmark folder in this menu" ) );
558 if (!kapp->authorizeKAction(
"bookmarks"))
563 if ( m_bAddBookmark )
567 addAddBookmarksList();
572 if ( m_bAddBookmark && !KBookmarkSettings::self()->m_advancedaddbookmark )
579 bool haveSep =
false;
582 TQValueList<TQString>::const_iterator it;
583 for ( it = keys.begin(); it != keys.end(); ++it )
588 if ( !info.show || !TQFile::exists( info.location ) )
597 KActionMenu * actionMenu;
598 actionMenu =
new KImportedBookmarksActionMenu(
599 info.name, info.type,
600 m_actionCollection,
"kbookmarkmenu" );
602 actionMenu->setProperty(
"type", info.type );
603 actionMenu->setProperty(
"location", info.location );
609 new KBookmarkMenu( m_pManager, m_pOwner, actionMenu->popupMenu(),
610 m_actionCollection,
false,
611 m_bAddBookmark, TQString::null );
612 connect( subMenu, TQT_SIGNAL(
openBookmark(
const TQString &, TQt::ButtonState ) ),
613 this, TQT_SIGNAL(
openBookmark(
const TQString &, TQt::ButtonState ) ));
616 connect(actionMenu->popupMenu(), TQT_SIGNAL(aboutToShow()), subMenu, TQT_SLOT(
slotNSLoad()));
621 Q_ASSERT(!parentBookmark.isNull());
622 bool separatorInserted =
false;
623 for ( KBookmark bm = parentBookmark.
first(); !bm.isNull(); bm = parentBookmark.
next(bm) )
625 TQString text = KStringHandler::csqueeze(bm.fullText(), 60);
626 text.replace(
'&',
"&&" );
627 if ( !separatorInserted && m_bIsRoot) {
630 separatorInserted =
true;
634 if ( bm.isSeparator() )
641 KAction * action =
new KBookmarkAction( text, bm.icon(), 0, m_actionCollection, 0 );
642 connect(action, TQT_SIGNAL( activated ( KAction::ActivationReason, TQt::ButtonState )),
643 this, TQT_SLOT( slotBookmarkSelected( KAction::ActivationReason, TQt::ButtonState ) ));
645 action->setProperty(
"url", bm.url().url() );
646 action->setProperty(
"address", bm.address() );
648 action->setToolTip( bm.url().pathOrURL() );
657 KActionMenu * actionMenu =
new KBookmarkActionMenu( text, bm.icon(),
660 actionMenu->setProperty(
"address", bm.address() );
665 m_actionCollection,
false,
669 connect(subMenu, TQT_SIGNAL( aboutToShowContextMenu(
const KBookmark &, TQPopupMenu * ) ),
670 this, TQT_SIGNAL( aboutToShowContextMenu(
const KBookmark &, TQPopupMenu * ) ));
671 connect(subMenu, TQT_SIGNAL(
openBookmark(
const TQString &, TQt::ButtonState ) ),
672 this, TQT_SIGNAL(
openBookmark(
const TQString &, TQt::ButtonState ) ));
677 if ( !m_bIsRoot && m_bAddBookmark )
682 if ( KBookmarkSettings::self()->m_quickactions )
684 KActionMenu * actionMenu =
new KActionMenu( i18n(
"Quick Actions"), m_actionCollection, 0L );
693 addAddBookmarksList();
699 void KBookmarkMenu::slotAddBookmarksList()
704 kdWarning() <<
"erm, sorry ;-)" << endl;
708 KExtendedBookmarkOwner::QStringPairList list;
709 extOwner->fillBookmarksList( list );
712 Q_ASSERT(!parentBookmark.isNull());
714 if ( group.isNull() )
717 KExtendedBookmarkOwner::QStringPairList::const_iterator it;
718 for ( it = list.begin(); it != list.end(); ++it )
719 group.
addBookmark( m_pManager, (*it).first, KURL((*it).second) );
721 m_pManager->emitChanged( parentBookmark );
725 void KBookmarkMenu::slotAddBookmark()
729 if (!parentBookmark.isNull())
730 m_pManager->emitChanged( parentBookmark );
733 void KBookmarkMenu::slotNewFolder()
735 if ( !m_pOwner )
return;
737 Q_ASSERT(!parentBookmark.isNull());
739 if ( !group.isNull() )
742 m_pManager->emitChanged( parentGroup );
746 void KBookmarkMenu::slotBookmarkSelected( KAction::ActivationReason , TQt::ButtonState state )
748 kdDebug(7043) <<
"KBookmarkMenu::slotBookmarkSelected()" << endl;
749 if ( !m_pOwner )
return;
750 const KAction* action =
dynamic_cast<const KAction *
>(sender());
753 const TQString& url = sender()->property(
"url").toString();
759 void KBookmarkMenu::slotBookmarkSelected()
761 slotBookmarkSelected(KAction::PopupMenuActivation, Qt::NoButton);
776 importer.openBookmarks(s_highlightedImportLocation, s_highlightedImportType);
783 KBookmarkEditFields::KBookmarkEditFields(TQWidget *main, TQBoxLayout *vbox, FieldsSet fieldsSet)
785 bool isF = (fieldsSet != FolderFieldsSet);
787 TQGridLayout *grid =
new TQGridLayout( vbox, 2, isF ? 2 : 1 );
789 m_title =
new KLineEdit( main );
790 grid->addWidget( m_title, 0, 1 );
791 grid->addWidget(
new TQLabel( m_title, i18n(
"Name:" ), main ), 0, 0 );
795 m_url =
new KLineEdit( main );
796 grid->addWidget( m_url, 1, 1 );
797 grid->addWidget(
new TQLabel( m_url, i18n(
"Location:" ), main ), 1, 0 );
804 main->setMinimumSize( 300, 0 );
807 void KBookmarkEditFields::setName(
const TQString &str)
809 m_title->setText(str);
812 void KBookmarkEditFields::setLocation(
const TQString &str)
822 KBookmarkEditDialog::KBookmarkEditDialog(
const TQString& title,
const TQString& url,
KBookmarkManager * mgr, BookmarkEditType editType,
const TQString& address,
823 TQWidget * parent,
const char * name,
const TQString& caption )
824 : KDialogBase(parent, name, true, caption,
825 (editType == InsertionMode) ? (User1|Ok|Cancel) : (Ok|Cancel),
826 Ok, false, KGuiItem()),
827 m_folderTree(0), m_mgr(mgr), m_editType(editType), m_address(address)
829 setButtonOK( (editType == InsertionMode) ? KGuiItem( i18n(
"&Add" ),
"bookmark_add") : i18n(
"&Update" ) );
830 if (editType == InsertionMode) {
831 setButtonGuiItem( User1, KGuiItem( i18n(
"&New Folder..." ),
"folder_new") );
834 bool folder = url.isNull();
836 m_main =
new TQWidget(
this );
837 setMainWidget( m_main );
839 TQBoxLayout *vbox =
new TQVBoxLayout( m_main, 0, spacingHint() );
840 KBookmarkEditFields::FieldsSet fs =
841 folder ? KBookmarkEditFields::FolderFieldsSet
842 : KBookmarkEditFields::BookmarkFieldsSet;
843 m_fields =
new KBookmarkEditFields(m_main, vbox, fs);
844 m_fields->setName(title);
846 m_fields->setLocation(url);
848 if ( editType == InsertionMode )
850 m_folderTree = KBookmarkFolderTree::createTree( m_mgr, m_main, name, m_address );
851 connect( m_folderTree, TQT_SIGNAL( doubleClicked(TQListViewItem*) ),
852 this, TQT_SLOT( slotDoubleClicked(TQListViewItem*) ) );
853 vbox->addWidget( m_folderTree );
854 connect(
this, TQT_SIGNAL( user1Clicked() ), TQT_SLOT( slotUser1() ) );
858 void KBookmarkEditDialog::slotDoubleClicked( TQListViewItem* item )
860 Q_ASSERT( m_folderTree );
861 m_folderTree->setCurrentItem( item );
865 void KBookmarkEditDialog::slotOk()
870 void KBookmarkEditDialog::slotCancel()
875 TQString KBookmarkEditDialog::finalAddress()
const
877 Q_ASSERT( m_folderTree );
878 return KBookmarkFolderTree::selectedAddress( m_folderTree );
881 TQString KBookmarkEditDialog::finalUrl()
const
883 return m_fields->m_url ? m_fields->m_url->text() : TQString::null;
886 TQString KBookmarkEditDialog::finalTitle()
const
888 return m_fields->m_title ? m_fields->m_title->text() : TQString::null;
891 void KBookmarkEditDialog::slotUser1()
894 Q_ASSERT( m_folderTree );
896 TQString address = KBookmarkFolderTree::selectedAddress( m_folderTree );
897 if ( address.isNull() )
return;
899 Q_ASSERT(!bm.isNull());
900 Q_ASSERT(m_editType == InsertionMode);
903 if ( !group.isNull() )
906 m_mgr->emitChanged( parentGroup );
908 KBookmarkFolderTree::fillTree( m_folderTree, m_mgr );
915 static void fillGroup( TQListView* listview, KBookmarkFolderTreeItem * parentItem,
KBookmarkGroup group,
bool expandOpenGroups =
true,
const TQString& address = TQString::null )
917 bool noSubGroups =
true;
918 KBookmarkFolderTreeItem * lastItem = 0L;
919 KBookmarkFolderTreeItem * item = 0L;
920 for ( KBookmark bk = group.
first() ; !bk.isNull() ; bk = group.
next(bk) )
925 item =
new KBookmarkFolderTreeItem( parentItem, lastItem, grp );
926 fillGroup( listview, item, grp, expandOpenGroups, address );
927 if ( expandOpenGroups && grp.
isOpen() )
928 item->setOpen(
true );
932 if (bk.address() == address) {
933 listview->setCurrentItem( lastItem );
934 listview->ensureItemVisible( item );
938 parentItem->setOpen(
true );
942 TQListView* KBookmarkFolderTree::createTree(
KBookmarkManager* mgr, TQWidget* parent,
const char* name,
const TQString& address )
944 TQListView *listview =
new TQListView( parent, name );
946 listview->setRootIsDecorated(
false );
947 listview->header()->hide();
948 listview->addColumn( i18n(
"Bookmark"), 200 );
949 listview->setSorting( -1,
false );
950 listview->setSelectionMode( TQListView::Single );
951 listview->setAllColumnsShowFocus(
true );
952 listview->setResizeMode( TQListView::AllColumns );
953 listview->setMinimumSize( 60, 100 );
955 fillTree( listview, mgr, address );
960 void KBookmarkFolderTree::fillTree( TQListView *listview,
KBookmarkManager* mgr,
const TQString& address )
965 KBookmarkFolderTreeItem * rootItem =
new KBookmarkFolderTreeItem( listview, root );
966 listview->setCurrentItem( rootItem );
967 rootItem->setSelected(
true );
968 fillGroup( listview, rootItem, root, (address == root.
groupAddress() || address.isNull()) ?
true :
false, address );
969 rootItem->setOpen(
true );
972 static KBookmarkFolderTreeItem* ft_cast( TQListViewItem *i )
974 return static_cast<KBookmarkFolderTreeItem*
>( i );
977 TQString KBookmarkFolderTree::selectedAddress( TQListView *listview )
980 return TQString::null;
981 KBookmarkFolderTreeItem *item = ft_cast( listview->currentItem() );
982 return item ? item->m_bookmark.address() : TQString::null;
985 void KBookmarkFolderTree::setAddress( TQListView *listview,
const TQString & address )
987 KBookmarkFolderTreeItem* it = ft_cast( listview->firstChild() );
989 kdDebug(7043) << it->m_bookmark.address() << endl;
990 it = ft_cast( it->itemBelow() );
993 if ( it->m_bookmark.address() == address )
996 it->setSelected(
true );
997 listview->setCurrentItem( it );
1005 KBookmarkFolderTreeItem::KBookmarkFolderTreeItem( TQListView *parent,
const KBookmark & gp )
1006 : TQListViewItem(parent, i18n(
"Bookmarks")), m_bookmark(gp)
1008 setPixmap(0, SmallIcon(
"bookmark"));
1009 setExpandable(
true);
1013 KBookmarkFolderTreeItem::KBookmarkFolderTreeItem( KBookmarkFolderTreeItem *parent, TQListViewItem *after,
const KBookmarkGroup & gp )
1014 : TQListViewItem(parent, after, gp.fullText()), m_bookmark(gp)
1016 setPixmap(0, SmallIcon( gp.icon() ) );
1017 setExpandable(
true);
1027 void KBookmarkMenuNSImporter::openNSBookmarks()
1029 openBookmarks( KNSBookmarkImporter::netscapeBookmarksFile(),
"netscape" );
1032 void KBookmarkMenuNSImporter::openBookmarks(
const TQString &location,
const TQString &type )
1034 mstack.push(m_menu);
1039 importer->setFilename(location);
1040 connectToImporter(*importer);
1046 void KBookmarkMenuNSImporter::connectToImporter(
const TQObject &importer)
1048 connect( &importer, TQT_SIGNAL( newBookmark(
const TQString &,
const TQCString &,
const TQString & ) ),
1049 TQT_SLOT( newBookmark(
const TQString &,
const TQCString &,
const TQString & ) ) );
1050 connect( &importer, TQT_SIGNAL( newFolder(
const TQString &,
bool,
const TQString & ) ),
1051 TQT_SLOT( newFolder(
const TQString &,
bool,
const TQString & ) ) );
1052 connect( &importer, TQT_SIGNAL( newSeparator() ), TQT_SLOT( newSeparator() ) );
1053 connect( &importer, TQT_SIGNAL( endFolder() ), TQT_SLOT( endFolder() ) );
1056 void KBookmarkMenuNSImporter::newBookmark(
const TQString & text,
const TQCString & url,
const TQString & )
1058 TQString _text = KStringHandler::csqueeze(text);
1059 _text.replace(
'&',
"&&" );
1060 KAction * action =
new KBookmarkAction(_text,
"html", 0, 0,
"", m_actionCollection, 0);
1061 connect(action, TQT_SIGNAL( activated ( KAction::ActivationReason, TQt::ButtonState )),
1062 m_menu, TQT_SLOT( slotBookmarkSelected( KAction::ActivationReason, TQt::ButtonState ) ));
1063 action->setProperty(
"url", url );
1064 action->setToolTip( url );
1065 action->plug( mstack.top()->m_parentMenu );
1066 mstack.top()->m_actions.append( action );
1069 void KBookmarkMenuNSImporter::newFolder(
const TQString & text,
bool,
const TQString & )
1071 TQString _text = KStringHandler::csqueeze(text);
1072 _text.replace(
'&',
"&&" );
1073 KActionMenu * actionMenu =
new KActionMenu( _text,
"folder", m_actionCollection, 0L );
1074 actionMenu->plug( mstack.top()->m_parentMenu );
1075 mstack.top()->m_actions.append( actionMenu );
1077 m_actionCollection,
false,
1078 m_menu->m_bAddBookmark, TQString::null );
1079 connect( subMenu, TQT_SIGNAL( openBookmark(
const TQString &, TQt::ButtonState ) ),
1080 m_menu, TQT_SIGNAL( openBookmark(
const TQString &, TQt::ButtonState ) ));
1081 mstack.top()->m_lstSubMenus.append( subMenu );
1083 mstack.push(subMenu);
1086 void KBookmarkMenuNSImporter::newSeparator()
1088 mstack.top()->m_parentMenu->insertSeparator();
1091 void KBookmarkMenuNSImporter::endFolder()
1102 KConfig config(
"kbookmarkrc",
false,
false);
1103 config.setGroup(
"Bookmarks");
1108 if (!config.hasKey(
"DynamicMenus")) {
1110 if (
id ==
"netscape") {
1112 info.show = manager->
root().internalElement().attribute(
"hide_nsbk") !=
"yes";
1113 info.location = KNSBookmarkImporter::netscapeBookmarksFile();
1114 info.type =
"netscape";
1115 info.name = i18n(
"Netscape Bookmarks");
1120 if (config.hasGroup(
"DynamicMenu-" +
id)) {
1121 config.setGroup(
"DynamicMenu-" +
id);
1122 info.show = config.readBoolEntry(
"Show");
1123 info.location = config.readPathEntry(
"Location");
1124 info.type = config.readEntry(
"Type");
1125 info.name = config.readEntry(
"Name");
1134 KConfig config(
"kbookmarkrc",
false,
false);
1135 config.setGroup(
"Bookmarks");
1138 if (config.hasKey(
"DynamicMenus"))
1139 mlist = config.readListEntry(
"DynamicMenus");
1141 mlist <<
"netscape";
1148 KConfig config(
"kbookmarkrc",
false,
false);
1151 config.setGroup(
"DynamicMenu-" +
id);
1152 config.writeEntry(
"Show", newMenu.show);
1153 config.writePathEntry(
"Location", newMenu.location);
1154 config.writeEntry(
"Type", newMenu.type);
1155 config.writeEntry(
"Name", newMenu.name);
1159 config.setGroup(
"Bookmarks");
1160 if (!config.hasKey(
"DynamicMenus")) {
1161 if (newMenu.type !=
"netscape") {
1164 config.setGroup(
"DynamicMenu-" "netscape");
1167 config.writeEntry(
"Show", xbelSetting.show);
1168 config.writePathEntry(
"Location", xbelSetting.location);
1169 config.writeEntry(
"Type", xbelSetting.type);
1170 config.writeEntry(
"Name", xbelSetting.name);
1173 elist = config.readListEntry(
"DynamicMenus");
1177 config.setGroup(
"Bookmarks");
1178 if (elist.contains(
id) < 1) {
1180 config.writeEntry(
"DynamicMenus", elist);
1186 #include "kbookmarkmenu.moc"
1187 #include "kbookmarkmenu_p.moc"
KBookmark previous(const KBookmark ¤t) const
Return the prevous sibling of a child bookmark of this group.
virtual TQString currentURL() const
This function is called whenever the user wants to add the current page to the bookmarks list...
KBookmarkGroup createNewFolder(KBookmarkManager *mgr, const TQString &text=TQString::null, bool emitSignal=true)
Create a new bookmark folder, as the last child of this group.
KBookmark addBookmark(KBookmarkManager *mgr, const KBookmark &bm, bool emitSignal=true)
Create a new bookmark, as the last child of this group Don't forget to use KBookmarkManager::self()->...
This class implements the reading/writing of bookmarks in XML.
TQString groupAddress() const
Much like KBookmark::address, but caches the address into m_address.
virtual void openBookmarkURL(const TQString &_url)
This function is called if the user selects a bookmark.
The KBookmarkMenu and KBookmarkBar classes gives the user the ability to either edit bookmarks or add...
static KBookmarkManager * userBookmarksManager()
Returns a pointer to the users main bookmark collection.
static TQString userBookmarksFile()
Returns the path to the user's main bookmark collection file.
KBookmarkGroup root() const
This will return the root bookmark.
virtual TQString currentTitle() const
This function is called whenever the user wants to add the current page to the bookmarks list...
A class for importing NS bookmarks KEditBookmarks uses it to insert bookmarks into its DOM tree...
void deleteBookmark(KBookmark bk)
Delete a bookmark - it has to be one of our children ! Don't forget to use KBookmarkManager::self()->...
bool moveItem(const KBookmark &item, const KBookmark &after)
Moves item after after (which should be a child of ours).
KBookmark next(const KBookmark ¤t) const
Return the next sibling of a child bookmark of this group.
KBookmark first() const
Return the first child bookmark of this group.