20 #include "kbookmarkmenu.h"
21 #include "kbookmarkmenu_p.h"
22 #include "kbookmarkimporter.h"
23 #include "kbookmarkimporter_opera.h"
24 #include "kbookmarkimporter_ie.h"
25 #include "kbookmarkdrag.h"
27 #include <tdeapplication.h>
28 #include <tdeconfig.h>
30 #include <kdialogbase.h>
31 #include <kiconloader.h>
32 #include <klineedit.h>
33 #include <tdelocale.h>
34 #include <tdemessagebox.h>
35 #include <tdepopupmenu.h>
36 #include <tdestdaccel.h>
37 #include <kstdaction.h>
38 #include <kstringhandler.h>
40 #include <tqclipboard.h>
45 #include <tqlineedit.h>
46 #include <tqlistview.h>
47 #include <tqpushbutton.h>
49 #include <dptrtemplate.h>
51 template class TQPtrList<KBookmarkMenu>;
53 static TQString makeTextNodeMod(KBookmark bk,
const TQString &m_nodename,
const TQString &m_newText) {
54 TQDomNode subnode = bk.internalElement().namedItem(m_nodename);
55 if (subnode.isNull()) {
56 subnode = bk.internalElement().ownerDocument().createElement(m_nodename);
57 bk.internalElement().appendChild(subnode);
60 if (subnode.firstChild().isNull()) {
61 TQDomText domtext = subnode.ownerDocument().createTextNode(
"");
62 subnode.appendChild(domtext);
65 TQDomText domtext = subnode.firstChild().toText();
67 TQString m_oldText = domtext.data();
68 domtext.setData(m_newText);
79 TDEActionCollection *collec,
bool _isRoot,
bool _add,
80 const TQString & parentAddress )
82 m_bIsRoot(_isRoot), m_bAddBookmark(_add),
83 m_bAddShortcuts(true),
84 m_pManager(mgr), m_pOwner(_owner),
85 m_parentMenu( _parentMenu ),
86 m_actionCollection( collec ),
87 m_parentAddress( parentAddress )
94 if (m_actionCollection)
96 m_actionCollection->setHighlightingEnabled(
true);
97 disconnect( m_actionCollection, TQ_SIGNAL( actionHighlighted( TDEAction * ) ), 0, 0 );
98 connect( m_actionCollection, TQ_SIGNAL( actionHighlighted( TDEAction * ) ),
99 this, TQ_SLOT( slotActionHighlighted( TDEAction * ) ) );
103 if ( !m_bNSBookmark )
107 connect( _parentMenu, TQ_SIGNAL( aboutToShow() ),
108 TQ_SLOT( slotAboutToShow() ) );
110 if ( KBookmarkSettings::self()->m_contextmenu )
112 (void) _parentMenu->contextMenu();
113 connect( _parentMenu, TQ_SIGNAL( aboutToShowContextMenu(TDEPopupMenu*,
int, TQPopupMenu*) ),
114 this, TQ_SLOT( slotAboutToShowContextMenu(TDEPopupMenu*,
int, TQPopupMenu*) ));
119 connect( m_pManager, TQ_SIGNAL( changed(
const TQString &,
const TQString &) ),
120 TQ_SLOT( slotBookmarksChanged(
const TQString &) ) );
127 if ( m_bAddBookmark )
131 addAddBookmarksList();
140 KBookmarkMenu::~KBookmarkMenu()
143 TQPtrListIterator<TDEAction> it(
m_actions );
144 for (; it.current(); ++it )
145 it.current()->unplugAll();
156 void KBookmarkMenu::slotAboutToShow()
166 TQString KBookmarkMenu::s_highlightedAddress;
167 TQString KBookmarkMenu::s_highlightedImportType;
168 TQString KBookmarkMenu::s_highlightedImportLocation;
170 void KBookmarkMenu::slotActionHighlighted( TDEAction* action )
172 if (action->isA(
"KBookmarkActionMenu") || action->isA(
"KBookmarkAction"))
174 s_highlightedAddress = action->property(
"address").toString();
177 else if (action->isA(
"KImportedBookmarksActionMenu"))
179 s_highlightedImportType = action->property(
"type").toString();
180 s_highlightedImportLocation = action->property(
"location").toString();
184 s_highlightedAddress = TQString::null;
185 s_highlightedImportType = TQString::null;
186 s_highlightedImportLocation = TQString::null;
194 class KBookmarkMenuRMBAssoc :
public dPtrTemplate<KBookmarkMenu, RMB> { };
195 template<> TQPtrDict<RMB>* dPtrTemplate<KBookmarkMenu, RMB>::d_ptr = 0;
197 static RMB* rmbSelf(
KBookmarkMenu *m) {
return KBookmarkMenuRMBAssoc::d(m); }
203 RMB *s = rmbSelf(
self);
205 s->m_parentAddress =
self->m_parentAddress;
206 s->s_highlightedAddress = KBookmarkMenu::s_highlightedAddress;
207 s->m_pManager =
self->m_pManager;
208 s->m_pOwner =
self->m_pOwner;
209 s->m_parentMenu =
self->m_parentMenu;
212 bool RMB::invalid(
int val )
217 s_highlightedAddress = m_parentAddress;
219 if (s_highlightedAddress.isNull())
225 KBookmark RMB::atAddress(
const TQString & address)
227 KBookmark bookmark = m_pManager->findByAddress( address );
228 Q_ASSERT(!bookmark.isNull());
232 void KBookmarkMenu::slotAboutToShowContextMenu( TDEPopupMenu*,
int, TQPopupMenu* contextMenu )
235 if (s_highlightedAddress.isNull())
237 TDEPopupMenu::contextMenuFocus()->hideContextMenu();
240 contextMenu->clear();
241 fillContextMenu( contextMenu, s_highlightedAddress, 0 );
244 void RMB::fillContextMenu( TQPopupMenu* contextMenu,
const TQString & address,
int val )
246 KBookmark bookmark = atAddress(address);
257 id = contextMenu->insertItem( SmallIcon(
"bookmark_add"), i18n(
"Add Bookmark Here" ), recv, TQ_SLOT(slotRMBActionInsert(
int)) );
258 contextMenu->setItemParameter(
id, val );
267 void RMB::fillContextMenu2( TQPopupMenu* contextMenu,
const TQString & address,
int val )
269 KBookmark bookmark = atAddress(address);
273 if (bookmark.isGroup()) {
274 id = contextMenu->insertItem( i18n(
"Open Folder in Bookmark Editor" ), recv, TQ_SLOT(slotRMBActionEditAt(
int)) );
275 contextMenu->setItemParameter(
id, val );
276 contextMenu->insertSeparator();
277 id = contextMenu->insertItem( SmallIcon(
"edit-delete"), i18n(
"Delete Folder" ), recv, TQ_SLOT(slotRMBActionRemove(
int)) );
278 contextMenu->setItemParameter(
id, val );
279 contextMenu->insertSeparator();
280 id = contextMenu->insertItem( i18n(
"Properties" ), recv, TQ_SLOT(slotRMBActionProperties(
int)) );
281 contextMenu->setItemParameter(
id, val );
285 id = contextMenu->insertItem( i18n(
"Copy Link Address" ), recv, TQ_SLOT(slotRMBActionCopyLocation(
int)) );
286 contextMenu->setItemParameter(
id, val );
287 contextMenu->insertSeparator();
288 id = contextMenu->insertItem( SmallIcon(
"edit-delete"), i18n(
"Delete Bookmark" ), recv, TQ_SLOT(slotRMBActionRemove(
int)) );
289 contextMenu->setItemParameter(
id, val );
290 contextMenu->insertSeparator();
291 id = contextMenu->insertItem( i18n(
"Properties" ), recv, TQ_SLOT(slotRMBActionProperties(
int)) );
292 contextMenu->setItemParameter(
id, val );
296 void RMB::slotRMBActionEditAt(
int val )
298 kdDebug(7043) <<
"KBookmarkMenu::slotRMBActionEditAt" << s_highlightedAddress << endl;
299 if (invalid(val)) { hidePopup();
return; }
301 KBookmark bookmark = atAddress(s_highlightedAddress);
303 m_pManager->slotEditBookmarksAtAddress( s_highlightedAddress );
306 void RMB::slotRMBActionProperties(
int val )
308 kdDebug(7043) <<
"KBookmarkMenu::slotRMBActionProperties" << s_highlightedAddress << endl;
309 if (invalid(val)) { hidePopup();
return; }
311 KBookmark bookmark = atAddress(s_highlightedAddress);
313 TQString folder = bookmark.isGroup() ? TQString::null : bookmark.url().pathOrURL();
314 KBookmarkEditDialog dlg( bookmark.fullText(), folder,
315 m_pManager, KBookmarkEditDialog::ModifyMode, 0,
316 0, 0, i18n(
"Bookmark Properties") );
317 if ( dlg.exec() != KDialogBase::Accepted )
320 makeTextNodeMod(bookmark,
"title", dlg.finalTitle());
321 if ( !dlg.finalUrl().isNull() )
323 KURL u = KURL::fromPathOrURL(dlg.finalUrl());
324 bookmark.internalElement().setAttribute(
"href", u.url(0, 106));
327 kdDebug(7043) <<
"Requested move to " << dlg.finalAddress() <<
"!" << endl;
329 KBookmarkGroup parentBookmark = atAddress(m_parentAddress).toGroup();
330 m_pManager->emitChanged( parentBookmark );
333 void RMB::slotRMBActionInsert(
int val )
335 kdDebug(7043) <<
"KBookmarkMenu::slotRMBActionInsert" << s_highlightedAddress << endl;
336 if (invalid(val)) { hidePopup();
return; }
338 TQString url = m_pOwner->currentURL();
341 KMessageBox::error( 0L, i18n(
"Cannot add bookmark with empty URL."));
344 TQString title = m_pOwner->currentTitle();
348 KBookmark bookmark = atAddress( s_highlightedAddress );
352 if (bookmark.isGroup())
355 Q_ASSERT(!parentBookmark.isNull());
356 parentBookmark.
addBookmark( m_pManager, title, KURL( url ) );
357 m_pManager->emitChanged( parentBookmark );
362 Q_ASSERT(!parentBookmark.isNull());
363 KBookmark newBookmark = parentBookmark.
addBookmark( m_pManager, title, KURL( url ) );
365 m_pManager->emitChanged( parentBookmark );
369 void RMB::slotRMBActionRemove(
int val )
372 if (invalid(val)) { hidePopup();
return; }
374 KBookmark bookmark = atAddress( s_highlightedAddress );
375 bool folder = bookmark.isGroup();
377 if (KMessageBox::warningContinueCancel(
379 folder ? i18n(
"Are you sure you wish to remove the bookmark folder\n\"%1\"?").arg(bookmark.text())
380 : i18n(
"Are you sure you wish to remove the bookmark\n\"%1\"?").arg(bookmark.text()),
381 folder ? i18n(
"Bookmark Folder Deletion")
382 : i18n(
"Bookmark Deletion"),
384 != KMessageBox::Continue
388 KBookmarkGroup parentBookmark = atAddress( m_parentAddress ).toGroup();
390 m_pManager->emitChanged( parentBookmark );
392 m_parentMenu->hide();
395 void RMB::slotRMBActionCopyLocation(
int val )
398 if (invalid(val)) { hidePopup();
return; }
400 KBookmark bookmark = atAddress( s_highlightedAddress );
402 if ( !bookmark.isGroup() )
404 kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0),
405 TQClipboard::Selection );
406 kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0),
407 TQClipboard::Clipboard );
411 void RMB::hidePopup() {
412 TDEPopupMenu::contextMenuFocus()->hideContextMenu();
419 void KBookmarkMenu::fillContextMenu( TQPopupMenu* contextMenu,
const TQString & address,
int val )
421 RMB::begin_rmb_action(
this);
422 rmbSelf(
this)->fillContextMenu(contextMenu, address, val);
423 emit aboutToShowContextMenu( rmbSelf(
this)->atAddress(address), contextMenu);
424 rmbSelf(
this)->fillContextMenu2(contextMenu, address, val);
427 void KBookmarkMenu::slotRMBActionEditAt(
int val )
428 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionEditAt( val ); }
430 void KBookmarkMenu::slotRMBActionProperties(
int val )
431 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionProperties( val ); }
433 void KBookmarkMenu::slotRMBActionInsert(
int val )
434 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionInsert( val ); }
436 void KBookmarkMenu::slotRMBActionRemove(
int val )
437 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionRemove( val ); }
439 void KBookmarkMenu::slotRMBActionCopyLocation(
int val )
440 { RMB::begin_rmb_action(
this); rmbSelf(
this)->slotRMBActionCopyLocation( val ); }
442 void KBookmarkMenu::slotBookmarksChanged(
const TQString & groupAddress )
456 for (; it.current(); ++it )
458 it.current()->slotBookmarksChanged( groupAddress );
463 void KBookmarkMenu::refill()
468 TQPtrListIterator<TDEAction> it(
m_actions );
469 for (; it.current(); ++it )
479 void KBookmarkMenu::addAddBookmarksList()
481 if (!kapp->authorizeTDEAction(
"bookmarks"))
484 TQString title = i18n(
"Bookmark Tabs as Folder..." );
486 TDEAction * paAddBookmarksList =
new TDEAction( title,
487 "bookmarks_list_add",
490 TQ_SLOT( slotAddBookmarksList() ),
491 m_actionCollection, m_bIsRoot ?
"add_bookmarks_list" : 0 );
493 paAddBookmarksList->setToolTip( i18n(
"Add a folder of bookmarks for all open tabs." ) );
499 void KBookmarkMenu::addAddBookmark()
501 if (!kapp->authorizeTDEAction(
"bookmarks"))
504 TQString title = i18n(
"Add Bookmark" );
506 TDEAction * paAddBookmarks =
new TDEAction( title,
508 m_bIsRoot && m_bAddShortcuts ? TDEStdAccel::addBookmark() : TDEShortcut(),
510 TQ_SLOT( slotAddBookmark() ),
511 m_actionCollection, m_bIsRoot ?
"add_bookmark" : 0 );
513 paAddBookmarks->setToolTip( i18n(
"Add a bookmark for the current document" ) );
519 void KBookmarkMenu::addEditBookmarks()
521 if (!kapp->authorizeTDEAction(
"bookmarks"))
524 TDEAction * m_paEditBookmarks = KStdAction::editBookmarks( m_pManager, TQ_SLOT( slotEditBookmarks() ),
525 m_actionCollection,
"edit_bookmarks" );
527 m_paEditBookmarks->setToolTip( i18n(
"Edit your bookmark collection in a separate window" ) );
531 void KBookmarkMenu::addNewFolder()
533 if (!kapp->authorizeTDEAction(
"bookmarks"))
536 TQString title = i18n(
"&New Bookmark Folder..." );
538 while ( ( p = title.find(
'&' ) ) >= 0 )
539 title.remove( p, 1 );
541 TDEAction * paNewFolder =
new TDEAction( title,
545 TQ_SLOT( slotNewFolder() ),
546 m_actionCollection );
548 paNewFolder->setToolTip( i18n(
"Create a new bookmark folder in this menu" ) );
556 if (!kapp->authorizeTDEAction(
"bookmarks"))
561 if ( m_bAddBookmark )
565 addAddBookmarksList();
570 if ( m_bAddBookmark && !KBookmarkSettings::self()->m_advancedaddbookmark )
577 bool haveSep =
false;
580 TQValueList<TQString>::const_iterator it;
581 for ( it = keys.begin(); it != keys.end(); ++it )
586 if ( !info.show || !TQFile::exists( info.location ) )
595 TDEActionMenu * actionMenu;
596 actionMenu =
new KImportedBookmarksActionMenu(
597 info.name, info.type,
598 m_actionCollection,
"kbookmarkmenu" );
600 actionMenu->setProperty(
"type", info.type );
601 actionMenu->setProperty(
"location", info.location );
607 new KBookmarkMenu( m_pManager, m_pOwner, actionMenu->popupMenu(),
608 m_actionCollection,
false,
609 m_bAddBookmark, TQString::null );
610 connect( subMenu, TQ_SIGNAL(
openBookmark(
const TQString &, TQt::ButtonState ) ),
611 this, TQ_SIGNAL(
openBookmark(
const TQString &, TQt::ButtonState ) ));
614 connect(actionMenu->popupMenu(), TQ_SIGNAL(aboutToShow()), subMenu, TQ_SLOT(
slotNSLoad()));
619 Q_ASSERT(!parentBookmark.isNull());
620 bool separatorInserted =
false;
621 for ( KBookmark bm = parentBookmark.
first(); !bm.isNull(); bm = parentBookmark.
next(bm) )
623 TQString text = KStringHandler::csqueeze(bm.fullText(), 60);
624 text.replace(
'&',
"&&" );
625 if ( !separatorInserted && m_bIsRoot) {
628 separatorInserted =
true;
632 if ( bm.isSeparator() )
639 TDEAction * action =
new KBookmarkAction( text, bm.icon(), 0, m_actionCollection, 0 );
640 connect(action, TQ_SIGNAL( activated ( TDEAction::ActivationReason, TQt::ButtonState )),
641 this, TQ_SLOT( slotBookmarkSelected( TDEAction::ActivationReason, TQt::ButtonState ) ));
643 action->setProperty(
"url", bm.url().url() );
644 action->setProperty(
"address", bm.address() );
646 action->setToolTip( bm.url().pathOrURL() );
655 TDEActionMenu * actionMenu =
new KBookmarkActionMenu( text, bm.icon(),
658 actionMenu->setProperty(
"address", bm.address() );
663 m_actionCollection,
false,
667 connect(subMenu, TQ_SIGNAL( aboutToShowContextMenu(
const KBookmark &, TQPopupMenu * ) ),
668 this, TQ_SIGNAL( aboutToShowContextMenu(
const KBookmark &, TQPopupMenu * ) ));
669 connect(subMenu, TQ_SIGNAL(
openBookmark(
const TQString &, TQt::ButtonState ) ),
670 this, TQ_SIGNAL(
openBookmark(
const TQString &, TQt::ButtonState ) ));
675 if ( !m_bIsRoot && m_bAddBookmark )
680 if ( KBookmarkSettings::self()->m_quickactions )
682 TDEActionMenu * actionMenu =
new TDEActionMenu( i18n(
"Quick Actions"), m_actionCollection, 0L );
691 addAddBookmarksList();
697 void KBookmarkMenu::slotAddBookmarksList()
702 kdWarning() <<
"erm, sorry ;-)" << endl;
706 KExtendedBookmarkOwner::QStringPairList list;
707 extOwner->fillBookmarksList( list );
710 Q_ASSERT(!parentBookmark.isNull());
712 if ( group.isNull() )
715 KExtendedBookmarkOwner::QStringPairList::const_iterator it;
716 for ( it = list.begin(); it != list.end(); ++it )
717 group.
addBookmark( m_pManager, (*it).first, KURL((*it).second) );
723 void KBookmarkMenu::slotAddBookmark()
727 if (!parentBookmark.isNull())
731 void KBookmarkMenu::slotNewFolder()
733 if ( !m_pOwner )
return;
735 Q_ASSERT(!parentBookmark.isNull());
737 if ( !group.isNull() )
744 void KBookmarkMenu::slotBookmarkSelected( TDEAction::ActivationReason , TQt::ButtonState state )
746 kdDebug(7043) <<
"KBookmarkMenu::slotBookmarkSelected()" << endl;
747 if ( !m_pOwner )
return;
748 const TDEAction* action =
dynamic_cast<const TDEAction *
>(sender());
751 const TQString& url = sender()->property(
"url").toString();
757 void KBookmarkMenu::slotBookmarkSelected()
759 slotBookmarkSelected(TDEAction::PopupMenuActivation, TQt::NoButton);
774 importer.openBookmarks(s_highlightedImportLocation, s_highlightedImportType);
781 KBookmarkEditFields::KBookmarkEditFields(TQWidget *main, TQBoxLayout *vbox, FieldsSet fieldsSet)
783 bool isF = (fieldsSet != FolderFieldsSet);
785 TQGridLayout *grid =
new TQGridLayout( vbox, 2, isF ? 2 : 1 );
787 m_title =
new KLineEdit( main );
788 grid->addWidget( m_title, 0, 1 );
789 grid->addWidget(
new TQLabel( m_title, i18n(
"Name:" ), main ), 0, 0 );
793 m_url =
new KLineEdit( main );
794 grid->addWidget( m_url, 1, 1 );
795 grid->addWidget(
new TQLabel( m_url, i18n(
"Location:" ), main ), 1, 0 );
802 main->setMinimumSize( 300, 0 );
805 void KBookmarkEditFields::setName(
const TQString &str)
807 m_title->setText(str);
810 void KBookmarkEditFields::setLocation(
const TQString &str)
820 KBookmarkEditDialog::KBookmarkEditDialog(
const TQString& title,
const TQString& url,
KBookmarkManager * mgr, BookmarkEditType editType,
const TQString& address,
821 TQWidget * parent,
const char * name,
const TQString& caption )
822 : KDialogBase(parent, name, true, caption,
823 (editType == InsertionMode) ? (User1|Ok|Cancel) : (Ok|Cancel),
824 Ok, false, KGuiItem()),
825 m_folderTree(0), m_mgr(mgr), m_editType(editType), m_address(address)
827 setButtonOK( (editType == InsertionMode) ? KGuiItem( i18n(
"&Add" ),
"bookmark_add") : i18n(
"&Update" ) );
828 if (editType == InsertionMode) {
829 setButtonGuiItem( User1, KGuiItem( i18n(
"&New Folder..." ),
"folder-new") );
832 bool folder = url.isNull();
834 m_main =
new TQWidget(
this );
835 setMainWidget( m_main );
837 TQBoxLayout *vbox =
new TQVBoxLayout( m_main, 0, spacingHint() );
838 KBookmarkEditFields::FieldsSet fs =
839 folder ? KBookmarkEditFields::FolderFieldsSet
840 : KBookmarkEditFields::BookmarkFieldsSet;
841 m_fields =
new KBookmarkEditFields(m_main, vbox, fs);
842 m_fields->setName(title);
844 m_fields->setLocation(url);
846 if ( editType == InsertionMode )
848 m_folderTree = KBookmarkFolderTree::createTree( m_mgr, m_main, name, m_address );
849 connect( m_folderTree, TQ_SIGNAL( doubleClicked(TQListViewItem*) ),
850 this, TQ_SLOT( slotDoubleClicked(TQListViewItem*) ) );
851 vbox->addWidget( m_folderTree );
852 connect(
this, TQ_SIGNAL( user1Clicked() ), TQ_SLOT( slotUser1() ) );
856 void KBookmarkEditDialog::slotDoubleClicked( TQListViewItem* item )
858 Q_ASSERT( m_folderTree );
859 m_folderTree->setCurrentItem( item );
863 void KBookmarkEditDialog::slotOk()
868 void KBookmarkEditDialog::slotCancel()
873 TQString KBookmarkEditDialog::finalAddress()
const
875 Q_ASSERT( m_folderTree );
876 return KBookmarkFolderTree::selectedAddress( m_folderTree );
879 TQString KBookmarkEditDialog::finalUrl()
const
881 return m_fields->m_url ? m_fields->m_url->text() : TQString::null;
884 TQString KBookmarkEditDialog::finalTitle()
const
886 return m_fields->m_title ? m_fields->m_title->text() : TQString::null;
889 void KBookmarkEditDialog::slotUser1()
892 Q_ASSERT( m_folderTree );
894 TQString address = KBookmarkFolderTree::selectedAddress( m_folderTree );
895 if ( address.isNull() )
return;
897 Q_ASSERT(!bm.isNull());
898 Q_ASSERT(m_editType == InsertionMode);
901 if ( !group.isNull() )
904 m_mgr->emitChanged( parentGroup );
906 KBookmarkFolderTree::fillTree( m_folderTree, m_mgr );
913 static void fillGroup( TQListView* listview, KBookmarkFolderTreeItem * parentItem,
KBookmarkGroup group,
bool expandOpenGroups =
true,
const TQString& address = TQString::null )
915 bool noSubGroups =
true;
916 KBookmarkFolderTreeItem * lastItem = 0L;
917 KBookmarkFolderTreeItem * item = 0L;
918 for ( KBookmark bk = group.
first() ; !bk.isNull() ; bk = group.
next(bk) )
923 item =
new KBookmarkFolderTreeItem( parentItem, lastItem, grp );
924 fillGroup( listview, item, grp, expandOpenGroups, address );
925 if ( expandOpenGroups && grp.
isOpen() )
926 item->setOpen(
true );
930 if (bk.address() == address) {
931 listview->setCurrentItem( lastItem );
932 listview->ensureItemVisible( item );
936 parentItem->setOpen(
true );
940 TQListView* KBookmarkFolderTree::createTree(
KBookmarkManager* mgr, TQWidget* parent,
const char* name,
const TQString& address )
942 TQListView *listview =
new TQListView( parent, name );
944 listview->setRootIsDecorated(
false );
945 listview->header()->hide();
946 listview->addColumn( i18n(
"Bookmark"), 200 );
947 listview->setSorting( -1,
false );
948 listview->setSelectionMode( TQListView::Single );
949 listview->setAllColumnsShowFocus(
true );
950 listview->setResizeMode( TQListView::AllColumns );
951 listview->setMinimumSize( 60, 100 );
953 fillTree( listview, mgr, address );
958 void KBookmarkFolderTree::fillTree( TQListView *listview,
KBookmarkManager* mgr,
const TQString& address )
963 KBookmarkFolderTreeItem * rootItem =
new KBookmarkFolderTreeItem( listview, root );
964 listview->setCurrentItem( rootItem );
965 rootItem->setSelected(
true );
966 fillGroup( listview, rootItem, root, (address == root.
groupAddress() || address.isNull()) ?
true :
false, address );
967 rootItem->setOpen(
true );
970 static KBookmarkFolderTreeItem* ft_cast( TQListViewItem *i )
972 return static_cast<KBookmarkFolderTreeItem*
>( i );
975 TQString KBookmarkFolderTree::selectedAddress( TQListView *listview )
978 return TQString::null;
979 KBookmarkFolderTreeItem *item = ft_cast( listview->currentItem() );
980 return item ? item->m_bookmark.address() : TQString::null;
983 void KBookmarkFolderTree::setAddress( TQListView *listview,
const TQString & address )
985 KBookmarkFolderTreeItem* it = ft_cast( listview->firstChild() );
987 kdDebug(7043) << it->m_bookmark.address() << endl;
988 it = ft_cast( it->itemBelow() );
991 if ( it->m_bookmark.address() == address )
994 it->setSelected(
true );
995 listview->setCurrentItem( it );
1003 KBookmarkFolderTreeItem::KBookmarkFolderTreeItem( TQListView *parent,
const KBookmark & gp )
1004 : TQListViewItem(parent, i18n(
"Bookmarks")), m_bookmark(gp)
1006 setPixmap(0, SmallIcon(
"bookmark"));
1007 setExpandable(
true);
1011 KBookmarkFolderTreeItem::KBookmarkFolderTreeItem( KBookmarkFolderTreeItem *parent, TQListViewItem *after,
const KBookmarkGroup & gp )
1012 : TQListViewItem(parent, after, gp.fullText()), m_bookmark(gp)
1014 setPixmap(0, SmallIcon( gp.icon() ) );
1015 setExpandable(
true);
1025 void KBookmarkMenuNSImporter::openNSBookmarks()
1027 openBookmarks( KNSBookmarkImporter::netscapeBookmarksFile(),
"netscape" );
1030 void KBookmarkMenuNSImporter::openBookmarks(
const TQString &location,
const TQString &type )
1032 mstack.push(m_menu);
1037 importer->setFilename(location);
1038 connectToImporter(*importer);
1044 void KBookmarkMenuNSImporter::connectToImporter(
const TQObject &importer)
1046 connect( &importer, TQ_SIGNAL( newBookmark(
const TQString &,
const TQCString &,
const TQString & ) ),
1047 TQ_SLOT( newBookmark(
const TQString &,
const TQCString &,
const TQString & ) ) );
1048 connect( &importer, TQ_SIGNAL( newFolder(
const TQString &,
bool,
const TQString & ) ),
1049 TQ_SLOT( newFolder(
const TQString &,
bool,
const TQString & ) ) );
1050 connect( &importer, TQ_SIGNAL( newSeparator() ), TQ_SLOT( newSeparator() ) );
1051 connect( &importer, TQ_SIGNAL( endFolder() ), TQ_SLOT( endFolder() ) );
1054 void KBookmarkMenuNSImporter::newBookmark(
const TQString & text,
const TQCString & url,
const TQString & )
1056 TQString _text = KStringHandler::csqueeze(text);
1057 _text.replace(
'&',
"&&" );
1058 TDEAction * action =
new KBookmarkAction(_text,
"text-html", 0, 0,
"", m_actionCollection, 0);
1059 connect(action, TQ_SIGNAL( activated ( TDEAction::ActivationReason, TQt::ButtonState )),
1060 m_menu, TQ_SLOT( slotBookmarkSelected( TDEAction::ActivationReason, TQt::ButtonState ) ));
1061 action->setProperty(
"url", url );
1062 action->setToolTip( url );
1063 action->plug( mstack.top()->m_parentMenu );
1064 mstack.top()->m_actions.append( action );
1067 void KBookmarkMenuNSImporter::newFolder(
const TQString & text,
bool,
const TQString & )
1069 TQString _text = KStringHandler::csqueeze(text);
1070 _text.replace(
'&',
"&&" );
1071 TDEActionMenu * actionMenu =
new TDEActionMenu( _text,
"folder", m_actionCollection, 0L );
1072 actionMenu->plug( mstack.top()->m_parentMenu );
1073 mstack.top()->m_actions.append( actionMenu );
1075 m_actionCollection,
false,
1076 m_menu->m_bAddBookmark, TQString::null );
1077 connect( subMenu, TQ_SIGNAL( openBookmark(
const TQString &, TQt::ButtonState ) ),
1078 m_menu, TQ_SIGNAL( openBookmark(
const TQString &, TQt::ButtonState ) ));
1079 mstack.top()->m_lstSubMenus.append( subMenu );
1081 mstack.push(subMenu);
1084 void KBookmarkMenuNSImporter::newSeparator()
1086 mstack.top()->m_parentMenu->insertSeparator();
1089 void KBookmarkMenuNSImporter::endFolder()
1100 TDEConfig config(
"kbookmarkrc",
false,
false);
1101 config.setGroup(
"Bookmarks");
1106 if (!config.hasKey(
"DynamicMenus")) {
1108 if (
id ==
"netscape") {
1110 info.show = manager->
root().internalElement().attribute(
"hide_nsbk") !=
"yes";
1111 info.location = KNSBookmarkImporter::netscapeBookmarksFile();
1112 info.type =
"netscape";
1113 info.name = i18n(
"Netscape Bookmarks");
1118 if (config.hasGroup(
"DynamicMenu-" +
id)) {
1119 config.setGroup(
"DynamicMenu-" +
id);
1120 info.show = config.readBoolEntry(
"Show");
1121 info.location = config.readPathEntry(
"Location");
1122 info.type = config.readEntry(
"Type");
1123 info.name = config.readEntry(
"Name");
1132 TDEConfig config(
"kbookmarkrc",
false,
false);
1133 config.setGroup(
"Bookmarks");
1136 if (config.hasKey(
"DynamicMenus"))
1137 mlist = config.readListEntry(
"DynamicMenus");
1139 mlist <<
"netscape";
1146 TDEConfig config(
"kbookmarkrc",
false,
false);
1149 config.setGroup(
"DynamicMenu-" +
id);
1150 config.writeEntry(
"Show", newMenu.show);
1151 config.writePathEntry(
"Location", newMenu.location);
1152 config.writeEntry(
"Type", newMenu.type);
1153 config.writeEntry(
"Name", newMenu.name);
1157 config.setGroup(
"Bookmarks");
1158 if (!config.hasKey(
"DynamicMenus")) {
1159 if (newMenu.type !=
"netscape") {
1162 config.setGroup(
"DynamicMenu-" "netscape");
1165 config.writeEntry(
"Show", xbelSetting.show);
1166 config.writePathEntry(
"Location", xbelSetting.location);
1167 config.writeEntry(
"Type", xbelSetting.type);
1168 config.writeEntry(
"Name", xbelSetting.name);
1171 elist = config.readListEntry(
"DynamicMenus");
1175 config.setGroup(
"Bookmarks");
1176 if (elist.contains(
id) < 1) {
1178 config.writeEntry(
"DynamicMenus", elist);
1184 #include "kbookmarkmenu.moc"
1185 #include "kbookmarkmenu_p.moc"
KBookmark next(const KBookmark ¤t) const
Return the next sibling of a child bookmark of this group.
TQString groupAddress() const
Much like KBookmark::address, but caches the address into m_address.
KBookmark first() const
Return the first child bookmark 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()->...
void deleteBookmark(KBookmark bk)
Delete a bookmark - it has to be one of our children ! Don't forget to use KBookmarkManager::self()->...
KBookmark previous(const KBookmark ¤t) const
Return the prevous sibling of a child bookmark of this group.
KBookmarkGroup createNewFolder(KBookmarkManager *mgr, const TQString &text=TQString::null, bool emitSignal=true)
Create a new bookmark folder, as the last child of this group.
bool moveItem(const KBookmark &item, const KBookmark &after)
Moves item after after (which should be a child of ours).
A class for importing NS bookmarks KEditBookmarks uses it to insert bookmarks into its DOM tree,...
This class implements the reading/writing of bookmarks in XML.
void emitChanged(KBookmarkGroup &group)
Saves the bookmark file and notifies everyone.
TQString path()
This will return the path that this manager is using to read the bookmarks.
KBookmark findByAddress(const TQString &address, bool tolerate=false)
KBookmarkGroup addBookmarkDialog(const TQString &_url, const TQString &_title, const TQString &_parentBookmarkAddress=TQString::null)
static KBookmarkManager * userBookmarksManager()
Returns a pointer to the users main bookmark collection.
KBookmarkGroup root() const
This will return the root bookmark.
static TQString userBookmarksFile()
Returns the path to the user's main bookmark collection file.
The KBookmarkMenu and KBookmarkBar classes gives the user the ability to either edit bookmarks or add...
virtual TQString currentTitle() const
This function is called whenever the user wants to add the current page to the bookmarks list.
virtual void openBookmarkURL(const TQString &_url)
This function is called if the user selects a bookmark.
virtual TQString currentURL() const
This function is called whenever the user wants to add the current page to the bookmarks list.