You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1186 lines
39 KiB
1186 lines
39 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "kbookmarkmenu.h"
|
||
|
#include "kbookmarkmenu_p.h"
|
||
|
#include "kbookmarkimporter.h"
|
||
|
#include "kbookmarkimporter_opera.h"
|
||
|
#include "kbookmarkimporter_ie.h"
|
||
|
#include "kbookmarkdrag.h"
|
||
|
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
#include <kdialogbase.h>
|
||
|
#include <kiconloader.h>
|
||
|
#include <klineedit.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdemessagebox.h>
|
||
12 years ago
|
#include <tdepopupmenu.h>
|
||
|
#include <tdestdaccel.h>
|
||
15 years ago
|
#include <kstdaction.h>
|
||
|
#include <kstringhandler.h>
|
||
|
|
||
13 years ago
|
#include <tqclipboard.h>
|
||
15 years ago
|
#include <tqfile.h>
|
||
|
#include <tqheader.h>
|
||
|
#include <tqlabel.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqlineedit.h>
|
||
|
#include <tqlistview.h>
|
||
|
#include <tqpushbutton.h>
|
||
15 years ago
|
|
||
|
#include <dptrtemplate.h>
|
||
|
|
||
15 years ago
|
template class TQPtrList<KBookmarkMenu>;
|
||
15 years ago
|
|
||
15 years ago
|
static TQString makeTextNodeMod(KBookmark bk, const TQString &m_nodename, const TQString &m_newText) {
|
||
|
TQDomNode subnode = bk.internalElement().namedItem(m_nodename);
|
||
15 years ago
|
if (subnode.isNull()) {
|
||
|
subnode = bk.internalElement().ownerDocument().createElement(m_nodename);
|
||
|
bk.internalElement().appendChild(subnode);
|
||
|
}
|
||
|
|
||
|
if (subnode.firstChild().isNull()) {
|
||
15 years ago
|
TQDomText domtext = subnode.ownerDocument().createTextNode("");
|
||
15 years ago
|
subnode.appendChild(domtext);
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDomText domtext = subnode.firstChild().toText();
|
||
15 years ago
|
|
||
15 years ago
|
TQString m_oldText = domtext.data();
|
||
15 years ago
|
domtext.setData(m_newText);
|
||
|
|
||
|
return m_oldText;
|
||
|
}
|
||
|
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
|
||
|
KBookmarkMenu::KBookmarkMenu( KBookmarkManager* mgr,
|
||
12 years ago
|
KBookmarkOwner * _owner, TDEPopupMenu * _parentMenu,
|
||
|
TDEActionCollection *collec, bool _isRoot, bool _add,
|
||
15 years ago
|
const TQString & parentAddress )
|
||
|
: TQObject(),
|
||
15 years ago
|
m_bIsRoot(_isRoot), m_bAddBookmark(_add),
|
||
|
m_bAddShortcuts(true),
|
||
|
m_pManager(mgr), m_pOwner(_owner),
|
||
|
m_parentMenu( _parentMenu ),
|
||
|
m_actionCollection( collec ),
|
||
|
m_parentAddress( parentAddress )
|
||
|
{
|
||
|
m_parentMenu->setKeyboardShortcutsEnabled( true );
|
||
|
|
||
|
m_lstSubMenus.setAutoDelete( true );
|
||
|
m_actions.setAutoDelete( true );
|
||
|
|
||
|
if (m_actionCollection)
|
||
|
{
|
||
|
m_actionCollection->setHighlightingEnabled(true);
|
||
12 years ago
|
disconnect( m_actionCollection, TQT_SIGNAL( actionHighlighted( TDEAction * ) ), 0, 0 );
|
||
|
connect( m_actionCollection, TQT_SIGNAL( actionHighlighted( TDEAction * ) ),
|
||
|
this, TQT_SLOT( slotActionHighlighted( TDEAction * ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
m_bNSBookmark = m_parentAddress.isNull();
|
||
|
if ( !m_bNSBookmark ) // not for the netscape bookmark
|
||
|
{
|
||
|
//kdDebug(7043) << "KBookmarkMenu::KBookmarkMenu " << this << " address : " << m_parentAddress << endl;
|
||
|
|
||
15 years ago
|
connect( _parentMenu, TQT_SIGNAL( aboutToShow() ),
|
||
|
TQT_SLOT( slotAboutToShow() ) );
|
||
15 years ago
|
|
||
|
if ( KBookmarkSettings::self()->m_contextmenu )
|
||
|
{
|
||
|
(void) _parentMenu->contextMenu();
|
||
12 years ago
|
connect( _parentMenu, TQT_SIGNAL( aboutToShowContextMenu(TDEPopupMenu*, int, TQPopupMenu*) ),
|
||
|
this, TQT_SLOT( slotAboutToShowContextMenu(TDEPopupMenu*, int, TQPopupMenu*) ));
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( m_bIsRoot )
|
||
|
{
|
||
15 years ago
|
connect( m_pManager, TQT_SIGNAL( changed(const TQString &, const TQString &) ),
|
||
|
TQT_SLOT( slotBookmarksChanged(const TQString &) ) );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
// add entries that possibly have a shortcut, so they are available _before_ first popup
|
||
|
if ( m_bIsRoot )
|
||
|
{
|
||
|
if ( m_bAddBookmark )
|
||
|
{
|
||
|
addAddBookmark();
|
||
|
if ( extOwner() )
|
||
|
addAddBookmarksList(); // FIXME
|
||
|
}
|
||
|
|
||
|
addEditBookmarks();
|
||
|
}
|
||
|
|
||
|
m_bDirty = true;
|
||
|
}
|
||
|
|
||
|
KBookmarkMenu::~KBookmarkMenu()
|
||
|
{
|
||
|
//kdDebug(7043) << "KBookmarkMenu::~KBookmarkMenu() " << this << endl;
|
||
12 years ago
|
TQPtrListIterator<TDEAction> it( m_actions );
|
||
15 years ago
|
for (; it.current(); ++it )
|
||
|
it.current()->unplugAll();
|
||
|
|
||
|
m_lstSubMenus.clear();
|
||
|
m_actions.clear();
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::ensureUpToDate()
|
||
|
{
|
||
|
slotAboutToShow();
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::slotAboutToShow()
|
||
|
{
|
||
|
// Did the bookmarks change since the last time we showed them ?
|
||
|
if ( m_bDirty )
|
||
|
{
|
||
|
m_bDirty = false;
|
||
|
refill();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KBookmarkMenu::s_highlightedAddress;
|
||
|
TQString KBookmarkMenu::s_highlightedImportType;
|
||
|
TQString KBookmarkMenu::s_highlightedImportLocation;
|
||
15 years ago
|
|
||
12 years ago
|
void KBookmarkMenu::slotActionHighlighted( TDEAction* action )
|
||
15 years ago
|
{
|
||
|
if (action->isA("KBookmarkActionMenu") || action->isA("KBookmarkAction"))
|
||
|
{
|
||
|
s_highlightedAddress = action->property("address").toString();
|
||
|
//kdDebug() << "KBookmarkMenu::slotActionHighlighted" << s_highlightedAddress << endl;
|
||
|
}
|
||
|
else if (action->isA("KImportedBookmarksActionMenu"))
|
||
|
{
|
||
|
s_highlightedImportType = action->property("type").toString();
|
||
|
s_highlightedImportLocation = action->property("location").toString();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
s_highlightedAddress = TQString::null;
|
||
|
s_highlightedImportType = TQString::null;
|
||
|
s_highlightedImportLocation = TQString::null;
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
|
||
|
class KBookmarkMenuRMBAssoc : public dPtrTemplate<KBookmarkMenu, RMB> { };
|
||
15 years ago
|
template<> TQPtrDict<RMB>* dPtrTemplate<KBookmarkMenu, RMB>::d_ptr = 0;
|
||
15 years ago
|
|
||
|
static RMB* rmbSelf(KBookmarkMenu *m) { return KBookmarkMenuRMBAssoc::d(m); }
|
||
|
|
||
|
// TODO check via dcop before making any changes to the bookmarks file???
|
||
|
|
||
|
void RMB::begin_rmb_action(KBookmarkMenu *self)
|
||
|
{
|
||
|
RMB *s = rmbSelf(self);
|
||
|
s->recv = self;
|
||
|
s->m_parentAddress = self->m_parentAddress;
|
||
|
s->s_highlightedAddress = KBookmarkMenu::s_highlightedAddress;
|
||
|
s->m_pManager = self->m_pManager;
|
||
|
s->m_pOwner = self->m_pOwner;
|
||
|
s->m_parentMenu = self->m_parentMenu;
|
||
|
}
|
||
|
|
||
|
bool RMB::invalid( int val )
|
||
|
{
|
||
|
bool valid = true;
|
||
|
|
||
|
if (val == 1)
|
||
|
s_highlightedAddress = m_parentAddress;
|
||
|
|
||
|
if (s_highlightedAddress.isNull())
|
||
|
valid = false;
|
||
|
|
||
|
return !valid;
|
||
|
}
|
||
|
|
||
15 years ago
|
KBookmark RMB::atAddress(const TQString & address)
|
||
15 years ago
|
{
|
||
14 years ago
|
KBookmark bookmark = m_pManager->findByAddress( address );
|
||
15 years ago
|
Q_ASSERT(!bookmark.isNull());
|
||
|
return bookmark;
|
||
|
}
|
||
|
|
||
12 years ago
|
void KBookmarkMenu::slotAboutToShowContextMenu( TDEPopupMenu*, int, TQPopupMenu* contextMenu )
|
||
15 years ago
|
{
|
||
|
//kdDebug(7043) << "KBookmarkMenu::slotAboutToShowContextMenu" << s_highlightedAddress << endl;
|
||
|
if (s_highlightedAddress.isNull())
|
||
|
{
|
||
12 years ago
|
TDEPopupMenu::contextMenuFocus()->hideContextMenu();
|
||
15 years ago
|
return;
|
||
|
}
|
||
|
contextMenu->clear();
|
||
|
fillContextMenu( contextMenu, s_highlightedAddress, 0 );
|
||
|
}
|
||
|
|
||
15 years ago
|
void RMB::fillContextMenu( TQPopupMenu* contextMenu, const TQString & address, int val )
|
||
15 years ago
|
{
|
||
|
KBookmark bookmark = atAddress(address);
|
||
|
|
||
|
int id;
|
||
|
|
||
|
// binner:
|
||
|
// "Add Bookmark Here" when pointing at a bookmark looks strange and if you
|
||
|
// call it you have to close and reopen the menu to see an entry was added?
|
||
|
//
|
||
|
// TODO rename these, but, message freeze... umm...
|
||
|
|
||
|
// if (bookmark.isGroup()) {
|
||
15 years ago
|
id = contextMenu->insertItem( SmallIcon("bookmark_add"), i18n( "Add Bookmark Here" ), recv, TQT_SLOT(slotRMBActionInsert(int)) );
|
||
15 years ago
|
contextMenu->setItemParameter( id, val );
|
||
|
/* }
|
||
|
else
|
||
|
{
|
||
15 years ago
|
id = contextMenu->insertItem( SmallIcon("bookmark_add"), i18n( "Add Bookmark Here" ), recv, TQT_SLOT(slotRMBActionInsert(int)) );
|
||
15 years ago
|
contextMenu->setItemParameter( id, val );
|
||
|
}*/
|
||
|
}
|
||
|
|
||
15 years ago
|
void RMB::fillContextMenu2( TQPopupMenu* contextMenu, const TQString & address, int val )
|
||
15 years ago
|
{
|
||
|
KBookmark bookmark = atAddress(address);
|
||
|
|
||
|
int id;
|
||
|
|
||
|
if (bookmark.isGroup()) {
|
||
15 years ago
|
id = contextMenu->insertItem( i18n( "Open Folder in Bookmark Editor" ), recv, TQT_SLOT(slotRMBActionEditAt(int)) );
|
||
15 years ago
|
contextMenu->setItemParameter( id, val );
|
||
|
contextMenu->insertSeparator();
|
||
10 years ago
|
id = contextMenu->insertItem( SmallIcon("edit-delete"), i18n( "Delete Folder" ), recv, TQT_SLOT(slotRMBActionRemove(int)) );
|
||
15 years ago
|
contextMenu->setItemParameter( id, val );
|
||
|
contextMenu->insertSeparator();
|
||
15 years ago
|
id = contextMenu->insertItem( i18n( "Properties" ), recv, TQT_SLOT(slotRMBActionProperties(int)) );
|
||
15 years ago
|
contextMenu->setItemParameter( id, val );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
id = contextMenu->insertItem( i18n( "Copy Link Address" ), recv, TQT_SLOT(slotRMBActionCopyLocation(int)) );
|
||
15 years ago
|
contextMenu->setItemParameter( id, val );
|
||
|
contextMenu->insertSeparator();
|
||
10 years ago
|
id = contextMenu->insertItem( SmallIcon("edit-delete"), i18n( "Delete Bookmark" ), recv, TQT_SLOT(slotRMBActionRemove(int)) );
|
||
15 years ago
|
contextMenu->setItemParameter( id, val );
|
||
|
contextMenu->insertSeparator();
|
||
15 years ago
|
id = contextMenu->insertItem( i18n( "Properties" ), recv, TQT_SLOT(slotRMBActionProperties(int)) );
|
||
15 years ago
|
contextMenu->setItemParameter( id, val );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void RMB::slotRMBActionEditAt( int val )
|
||
|
{
|
||
|
kdDebug(7043) << "KBookmarkMenu::slotRMBActionEditAt" << s_highlightedAddress << endl;
|
||
|
if (invalid(val)) { hidePopup(); return; }
|
||
|
|
||
|
KBookmark bookmark = atAddress(s_highlightedAddress);
|
||
|
|
||
|
m_pManager->slotEditBookmarksAtAddress( s_highlightedAddress );
|
||
|
}
|
||
|
|
||
|
void RMB::slotRMBActionProperties( int val )
|
||
|
{
|
||
|
kdDebug(7043) << "KBookmarkMenu::slotRMBActionProperties" << s_highlightedAddress << endl;
|
||
|
if (invalid(val)) { hidePopup(); return; }
|
||
|
|
||
|
KBookmark bookmark = atAddress(s_highlightedAddress);
|
||
|
|
||
15 years ago
|
TQString folder = bookmark.isGroup() ? TQString::null : bookmark.url().pathOrURL();
|
||
15 years ago
|
KBookmarkEditDialog dlg( bookmark.fullText(), folder,
|
||
|
m_pManager, KBookmarkEditDialog::ModifyMode, 0,
|
||
|
0, 0, i18n("Bookmark Properties") );
|
||
|
if ( dlg.exec() != KDialogBase::Accepted )
|
||
|
return;
|
||
|
|
||
|
makeTextNodeMod(bookmark, "title", dlg.finalTitle());
|
||
|
if ( !dlg.finalUrl().isNull() )
|
||
|
{
|
||
|
KURL u = KURL::fromPathOrURL(dlg.finalUrl());
|
||
|
bookmark.internalElement().setAttribute("href", u.url(0, 106));
|
||
|
}
|
||
|
|
||
|
kdDebug(7043) << "Requested move to " << dlg.finalAddress() << "!" << endl;
|
||
|
|
||
|
KBookmarkGroup parentBookmark = atAddress(m_parentAddress).toGroup();
|
||
|
m_pManager->emitChanged( parentBookmark );
|
||
|
}
|
||
|
|
||
|
void RMB::slotRMBActionInsert( int val )
|
||
|
{
|
||
|
kdDebug(7043) << "KBookmarkMenu::slotRMBActionInsert" << s_highlightedAddress << endl;
|
||
|
if (invalid(val)) { hidePopup(); return; }
|
||
|
|
||
15 years ago
|
TQString url = m_pOwner->currentURL();
|
||
15 years ago
|
if (url.isEmpty())
|
||
|
{
|
||
|
KMessageBox::error( 0L, i18n("Cannot add bookmark with empty URL."));
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
TQString title = m_pOwner->currentTitle();
|
||
15 years ago
|
if (title.isEmpty())
|
||
|
title = url;
|
||
|
|
||
|
KBookmark bookmark = atAddress( s_highlightedAddress );
|
||
|
|
||
|
// TODO use unique title
|
||
|
|
||
|
if (bookmark.isGroup())
|
||
|
{
|
||
|
KBookmarkGroup parentBookmark = bookmark.toGroup();
|
||
|
Q_ASSERT(!parentBookmark.isNull());
|
||
|
parentBookmark.addBookmark( m_pManager, title, KURL( url ) );
|
||
|
m_pManager->emitChanged( parentBookmark );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
KBookmarkGroup parentBookmark = bookmark.parentGroup();
|
||
|
Q_ASSERT(!parentBookmark.isNull());
|
||
|
KBookmark newBookmark = parentBookmark.addBookmark( m_pManager, title, KURL( url ) );
|
||
|
parentBookmark.moveItem( newBookmark, parentBookmark.previous(bookmark) );
|
||
|
m_pManager->emitChanged( parentBookmark );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void RMB::slotRMBActionRemove( int val )
|
||
|
{
|
||
|
//kdDebug(7043) << "KBookmarkMenu::slotRMBActionRemove" << s_highlightedAddress << endl;
|
||
|
if (invalid(val)) { hidePopup(); return; }
|
||
|
|
||
|
KBookmark bookmark = atAddress( s_highlightedAddress );
|
||
|
bool folder = bookmark.isGroup();
|
||
|
|
||
|
if (KMessageBox::warningContinueCancel(
|
||
|
m_parentMenu,
|
||
|
folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?").arg(bookmark.text())
|
||
|
: i18n("Are you sure you wish to remove the bookmark\n\"%1\"?").arg(bookmark.text()),
|
||
|
folder ? i18n("Bookmark Folder Deletion")
|
||
|
: i18n("Bookmark Deletion"),
|
||
|
KStdGuiItem::del())
|
||
|
!= KMessageBox::Continue
|
||
|
)
|
||
|
return;
|
||
|
|
||
|
KBookmarkGroup parentBookmark = atAddress( m_parentAddress ).toGroup();
|
||
|
parentBookmark.deleteBookmark( bookmark );
|
||
|
m_pManager->emitChanged( parentBookmark );
|
||
|
if (m_parentMenu)
|
||
|
m_parentMenu->hide();
|
||
|
}
|
||
|
|
||
|
void RMB::slotRMBActionCopyLocation( int val )
|
||
|
{
|
||
|
//kdDebug(7043) << "KBookmarkMenu::slotRMBActionCopyLocation" << s_highlightedAddress << endl;
|
||
|
if (invalid(val)) { hidePopup(); return; }
|
||
|
|
||
|
KBookmark bookmark = atAddress( s_highlightedAddress );
|
||
|
|
||
|
if ( !bookmark.isGroup() )
|
||
|
{
|
||
13 years ago
|
kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0),
|
||
14 years ago
|
TQClipboard::Selection );
|
||
13 years ago
|
kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0),
|
||
14 years ago
|
TQClipboard::Clipboard );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
|
void RMB::hidePopup() {
|
||
12 years ago
|
TDEPopupMenu::contextMenuFocus()->hideContextMenu();
|
||
15 years ago
|
}
|
||
|
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
|
||
15 years ago
|
void KBookmarkMenu::fillContextMenu( TQPopupMenu* contextMenu, const TQString & address, int val )
|
||
15 years ago
|
{
|
||
|
RMB::begin_rmb_action(this);
|
||
|
rmbSelf(this)->fillContextMenu(contextMenu, address, val);
|
||
|
emit aboutToShowContextMenu( rmbSelf(this)->atAddress(address), contextMenu);
|
||
|
rmbSelf(this)->fillContextMenu2(contextMenu, address, val);
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::slotRMBActionEditAt( int val )
|
||
|
{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionEditAt( val ); }
|
||
|
|
||
|
void KBookmarkMenu::slotRMBActionProperties( int val )
|
||
|
{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionProperties( val ); }
|
||
|
|
||
|
void KBookmarkMenu::slotRMBActionInsert( int val )
|
||
|
{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionInsert( val ); }
|
||
|
|
||
|
void KBookmarkMenu::slotRMBActionRemove( int val )
|
||
|
{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionRemove( val ); }
|
||
|
|
||
|
void KBookmarkMenu::slotRMBActionCopyLocation( int val )
|
||
|
{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionCopyLocation( val ); }
|
||
|
|
||
15 years ago
|
void KBookmarkMenu::slotBookmarksChanged( const TQString & groupAddress )
|
||
15 years ago
|
{
|
||
|
if (m_bNSBookmark)
|
||
|
return;
|
||
|
|
||
|
if ( groupAddress == m_parentAddress )
|
||
|
{
|
||
|
//kdDebug(7043) << "KBookmarkMenu::slotBookmarksChanged -> setting m_bDirty on " << groupAddress << endl;
|
||
|
m_bDirty = true;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Iterate recursively into child menus
|
||
15 years ago
|
TQPtrListIterator<KBookmarkMenu> it( m_lstSubMenus );
|
||
15 years ago
|
for (; it.current(); ++it )
|
||
|
{
|
||
|
it.current()->slotBookmarksChanged( groupAddress );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::refill()
|
||
|
{
|
||
|
//kdDebug(7043) << "KBookmarkMenu::refill()" << endl;
|
||
|
m_lstSubMenus.clear();
|
||
|
|
||
12 years ago
|
TQPtrListIterator<TDEAction> it( m_actions );
|
||
15 years ago
|
for (; it.current(); ++it )
|
||
|
it.current()->unplug( m_parentMenu );
|
||
|
|
||
|
m_parentMenu->clear();
|
||
|
m_actions.clear();
|
||
|
|
||
|
fillBookmarkMenu();
|
||
|
m_parentMenu->adjustSize();
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::addAddBookmarksList()
|
||
|
{
|
||
12 years ago
|
if (!kapp->authorizeTDEAction("bookmarks"))
|
||
15 years ago
|
return;
|
||
|
|
||
15 years ago
|
TQString title = i18n( "Bookmark Tabs as Folder..." );
|
||
15 years ago
|
|
||
12 years ago
|
TDEAction * paAddBookmarksList = new TDEAction( title,
|
||
15 years ago
|
"bookmarks_list_add",
|
||
|
0,
|
||
|
this,
|
||
15 years ago
|
TQT_SLOT( slotAddBookmarksList() ),
|
||
15 years ago
|
m_actionCollection, m_bIsRoot ? "add_bookmarks_list" : 0 );
|
||
|
|
||
|
paAddBookmarksList->setToolTip( i18n( "Add a folder of bookmarks for all open tabs." ) );
|
||
|
|
||
|
paAddBookmarksList->plug( m_parentMenu );
|
||
|
m_actions.append( paAddBookmarksList );
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::addAddBookmark()
|
||
|
{
|
||
12 years ago
|
if (!kapp->authorizeTDEAction("bookmarks"))
|
||
15 years ago
|
return;
|
||
|
|
||
15 years ago
|
TQString title = i18n( "Add Bookmark" );
|
||
15 years ago
|
|
||
12 years ago
|
TDEAction * paAddBookmarks = new TDEAction( title,
|
||
15 years ago
|
"bookmark_add",
|
||
12 years ago
|
m_bIsRoot && m_bAddShortcuts ? TDEStdAccel::addBookmark() : TDEShortcut(),
|
||
15 years ago
|
this,
|
||
15 years ago
|
TQT_SLOT( slotAddBookmark() ),
|
||
15 years ago
|
m_actionCollection, m_bIsRoot ? "add_bookmark" : 0 );
|
||
|
|
||
|
paAddBookmarks->setToolTip( i18n( "Add a bookmark for the current document" ) );
|
||
|
|
||
|
paAddBookmarks->plug( m_parentMenu );
|
||
|
m_actions.append( paAddBookmarks );
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::addEditBookmarks()
|
||
|
{
|
||
12 years ago
|
if (!kapp->authorizeTDEAction("bookmarks"))
|
||
15 years ago
|
return;
|
||
|
|
||
12 years ago
|
TDEAction * m_paEditBookmarks = KStdAction::editBookmarks( m_pManager, TQT_SLOT( slotEditBookmarks() ),
|
||
15 years ago
|
m_actionCollection, "edit_bookmarks" );
|
||
|
m_paEditBookmarks->plug( m_parentMenu );
|
||
|
m_paEditBookmarks->setToolTip( i18n( "Edit your bookmark collection in a separate window" ) );
|
||
|
m_actions.append( m_paEditBookmarks );
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::addNewFolder()
|
||
|
{
|
||
12 years ago
|
if (!kapp->authorizeTDEAction("bookmarks"))
|
||
15 years ago
|
return;
|
||
|
|
||
15 years ago
|
TQString title = i18n( "&New Bookmark Folder..." );
|
||
15 years ago
|
int p;
|
||
14 years ago
|
while ( ( p = title.find( '&' ) ) >= 0 )
|
||
15 years ago
|
title.remove( p, 1 );
|
||
|
|
||
12 years ago
|
TDEAction * paNewFolder = new TDEAction( title,
|
||
10 years ago
|
"folder-new", //"folder",
|
||
15 years ago
|
0,
|
||
|
this,
|
||
15 years ago
|
TQT_SLOT( slotNewFolder() ),
|
||
15 years ago
|
m_actionCollection );
|
||
|
|
||
|
paNewFolder->setToolTip( i18n( "Create a new bookmark folder in this menu" ) );
|
||
|
|
||
|
paNewFolder->plug( m_parentMenu );
|
||
|
m_actions.append( paNewFolder );
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::fillBookmarkMenu()
|
||
|
{
|
||
12 years ago
|
if (!kapp->authorizeTDEAction("bookmarks"))
|
||
15 years ago
|
return;
|
||
|
|
||
|
if ( m_bIsRoot )
|
||
|
{
|
||
|
if ( m_bAddBookmark )
|
||
|
{
|
||
|
addAddBookmark();
|
||
|
if ( extOwner() )
|
||
|
addAddBookmarksList(); // FIXME
|
||
|
}
|
||
|
|
||
|
addEditBookmarks();
|
||
|
|
||
|
if ( m_bAddBookmark && !KBookmarkSettings::self()->m_advancedaddbookmark )
|
||
|
addNewFolder();
|
||
|
}
|
||
|
|
||
|
if ( m_bIsRoot
|
||
|
&& KBookmarkManager::userBookmarksFile() == m_pManager->path() )
|
||
|
{
|
||
|
bool haveSep = false;
|
||
|
|
||
15 years ago
|
TQValueList<TQString> keys = KBookmarkMenu::dynamicBookmarksList();
|
||
|
TQValueList<TQString>::const_iterator it;
|
||
15 years ago
|
for ( it = keys.begin(); it != keys.end(); ++it )
|
||
|
{
|
||
|
DynMenuInfo info;
|
||
|
info = showDynamicBookmarks((*it));
|
||
|
|
||
15 years ago
|
if ( !info.show || !TQFile::exists( info.location ) )
|
||
15 years ago
|
continue;
|
||
|
|
||
|
if (!haveSep)
|
||
|
{
|
||
|
m_parentMenu->insertSeparator();
|
||
|
haveSep = true;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEActionMenu * actionMenu;
|
||
15 years ago
|
actionMenu = new KImportedBookmarksActionMenu(
|
||
|
info.name, info.type,
|
||
|
m_actionCollection, "kbookmarkmenu" );
|
||
|
|
||
|
actionMenu->setProperty( "type", info.type );
|
||
|
actionMenu->setProperty( "location", info.location );
|
||
|
|
||
|
actionMenu->plug( m_parentMenu );
|
||
|
m_actions.append( actionMenu );
|
||
|
|
||
|
KBookmarkMenu *subMenu =
|
||
|
new KBookmarkMenu( m_pManager, m_pOwner, actionMenu->popupMenu(),
|
||
|
m_actionCollection, false,
|
||
15 years ago
|
m_bAddBookmark, TQString::null );
|
||
14 years ago
|
connect( subMenu, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ),
|
||
|
this, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ));
|
||
15 years ago
|
m_lstSubMenus.append(subMenu);
|
||
|
|
||
15 years ago
|
connect(actionMenu->popupMenu(), TQT_SIGNAL(aboutToShow()), subMenu, TQT_SLOT(slotNSLoad()));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
|
||
15 years ago
|
Q_ASSERT(!parentBookmark.isNull());
|
||
|
bool separatorInserted = false;
|
||
|
for ( KBookmark bm = parentBookmark.first(); !bm.isNull(); bm = parentBookmark.next(bm) )
|
||
|
{
|
||
15 years ago
|
TQString text = KStringHandler::csqueeze(bm.fullText(), 60);
|
||
14 years ago
|
text.replace( '&', "&&" );
|
||
15 years ago
|
if ( !separatorInserted && m_bIsRoot) {
|
||
|
// inserted before the first konq bookmark, to avoid the separator if no konq bookmark
|
||
|
m_parentMenu->insertSeparator();
|
||
|
separatorInserted = true;
|
||
|
}
|
||
|
if ( !bm.isGroup() )
|
||
|
{
|
||
|
if ( bm.isSeparator() )
|
||
|
{
|
||
|
m_parentMenu->insertSeparator();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//kdDebug(7043) << "Creating URL bookmark menu item for " << bm.text() << endl;
|
||
12 years ago
|
TDEAction * action = new KBookmarkAction( text, bm.icon(), 0, m_actionCollection, 0 );
|
||
|
connect(action, TQT_SIGNAL( activated ( TDEAction::ActivationReason, TQt::ButtonState )),
|
||
|
this, TQT_SLOT( slotBookmarkSelected( TDEAction::ActivationReason, TQt::ButtonState ) ));
|
||
15 years ago
|
|
||
|
action->setProperty( "url", bm.url().url() );
|
||
|
action->setProperty( "address", bm.address() );
|
||
|
|
||
|
action->setToolTip( bm.url().pathOrURL() );
|
||
|
|
||
|
action->plug( m_parentMenu );
|
||
|
m_actions.append( action );
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//kdDebug(7043) << "Creating bookmark submenu named " << bm.text() << endl;
|
||
12 years ago
|
TDEActionMenu * actionMenu = new KBookmarkActionMenu( text, bm.icon(),
|
||
15 years ago
|
m_actionCollection,
|
||
|
"kbookmarkmenu" );
|
||
|
actionMenu->setProperty( "address", bm.address() );
|
||
|
actionMenu->plug( m_parentMenu );
|
||
|
m_actions.append( actionMenu );
|
||
|
|
||
|
KBookmarkMenu *subMenu = new KBookmarkMenu( m_pManager, m_pOwner, actionMenu->popupMenu(),
|
||
|
m_actionCollection, false,
|
||
|
m_bAddBookmark,
|
||
|
bm.address() );
|
||
|
|
||
15 years ago
|
connect(subMenu, TQT_SIGNAL( aboutToShowContextMenu( const KBookmark &, TQPopupMenu * ) ),
|
||
|
this, TQT_SIGNAL( aboutToShowContextMenu( const KBookmark &, TQPopupMenu * ) ));
|
||
14 years ago
|
connect(subMenu, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ),
|
||
|
this, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ));
|
||
15 years ago
|
m_lstSubMenus.append( subMenu );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( !m_bIsRoot && m_bAddBookmark )
|
||
|
{
|
||
|
if ( m_parentMenu->count() > 0 )
|
||
|
m_parentMenu->insertSeparator();
|
||
|
|
||
|
if ( KBookmarkSettings::self()->m_quickactions )
|
||
|
{
|
||
12 years ago
|
TDEActionMenu * actionMenu = new TDEActionMenu( i18n("Quick Actions"), m_actionCollection, 0L );
|
||
15 years ago
|
fillContextMenu( actionMenu->popupMenu(), m_parentAddress, 1 );
|
||
|
actionMenu->plug( m_parentMenu );
|
||
|
m_actions.append( actionMenu );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
addAddBookmark();
|
||
|
if ( extOwner() )
|
||
|
addAddBookmarksList(); // FIXME
|
||
|
addNewFolder();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::slotAddBookmarksList()
|
||
|
{
|
||
|
KExtendedBookmarkOwner *extOwner = dynamic_cast<KExtendedBookmarkOwner*>(m_pOwner);
|
||
|
if (!extOwner)
|
||
|
{
|
||
|
kdWarning() << "erm, sorry ;-)" << endl;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
KExtendedBookmarkOwner::QStringPairList list;
|
||
|
extOwner->fillBookmarksList( list );
|
||
|
|
||
14 years ago
|
KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
|
||
15 years ago
|
Q_ASSERT(!parentBookmark.isNull());
|
||
|
KBookmarkGroup group = parentBookmark.createNewFolder( m_pManager );
|
||
|
if ( group.isNull() )
|
||
|
return; // user canceled i guess
|
||
|
|
||
|
KExtendedBookmarkOwner::QStringPairList::const_iterator it;
|
||
|
for ( it = list.begin(); it != list.end(); ++it )
|
||
|
group.addBookmark( m_pManager, (*it).first, KURL((*it).second) );
|
||
|
|
||
|
m_pManager->emitChanged( parentBookmark );
|
||
|
}
|
||
|
|
||
|
|
||
|
void KBookmarkMenu::slotAddBookmark()
|
||
|
{
|
||
|
KBookmarkGroup parentBookmark;
|
||
|
parentBookmark = m_pManager->addBookmarkDialog(m_pOwner->currentURL(), m_pOwner->currentTitle(), m_parentAddress);
|
||
|
if (!parentBookmark.isNull())
|
||
|
m_pManager->emitChanged( parentBookmark );
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::slotNewFolder()
|
||
|
{
|
||
|
if ( !m_pOwner ) return; // this view doesn't handle bookmarks...
|
||
14 years ago
|
KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
|
||
15 years ago
|
Q_ASSERT(!parentBookmark.isNull());
|
||
|
KBookmarkGroup group = parentBookmark.createNewFolder( m_pManager );
|
||
|
if ( !group.isNull() )
|
||
|
{
|
||
|
KBookmarkGroup parentGroup = group.parentGroup();
|
||
|
m_pManager->emitChanged( parentGroup );
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void KBookmarkMenu::slotBookmarkSelected( TDEAction::ActivationReason /*reason*/, TQt::ButtonState state )
|
||
15 years ago
|
{
|
||
|
kdDebug(7043) << "KBookmarkMenu::slotBookmarkSelected()" << endl;
|
||
|
if ( !m_pOwner ) return; // this view doesn't handle bookmarks...
|
||
12 years ago
|
const TDEAction* action = dynamic_cast<const TDEAction *>(sender());
|
||
15 years ago
|
if(action)
|
||
|
{
|
||
15 years ago
|
const TQString& url = sender()->property("url").toString();
|
||
15 years ago
|
m_pOwner->openBookmarkURL( url );
|
||
|
emit openBookmark( url, state );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::slotBookmarkSelected()
|
||
|
{
|
||
12 years ago
|
slotBookmarkSelected(TDEAction::PopupMenuActivation, Qt::NoButton);
|
||
15 years ago
|
}
|
||
|
|
||
|
KExtendedBookmarkOwner* KBookmarkMenu::extOwner()
|
||
|
{
|
||
|
return dynamic_cast<KExtendedBookmarkOwner*>(m_pOwner);
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenu::slotNSLoad()
|
||
|
{
|
||
|
// only fill menu once
|
||
15 years ago
|
m_parentMenu->disconnect(TQT_SIGNAL(aboutToShow()));
|
||
15 years ago
|
|
||
|
// not NSImporter, but kept old name for BC reasons
|
||
|
KBookmarkMenuNSImporter importer( m_pManager, this, m_actionCollection );
|
||
|
importer.openBookmarks(s_highlightedImportLocation, s_highlightedImportType);
|
||
|
}
|
||
|
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
|
||
15 years ago
|
KBookmarkEditFields::KBookmarkEditFields(TQWidget *main, TQBoxLayout *vbox, FieldsSet fieldsSet)
|
||
15 years ago
|
{
|
||
|
bool isF = (fieldsSet != FolderFieldsSet);
|
||
|
|
||
15 years ago
|
TQGridLayout *grid = new TQGridLayout( vbox, 2, isF ? 2 : 1 );
|
||
15 years ago
|
|
||
|
m_title = new KLineEdit( main );
|
||
|
grid->addWidget( m_title, 0, 1 );
|
||
15 years ago
|
grid->addWidget( new TQLabel( m_title, i18n( "Name:" ), main ), 0, 0 );
|
||
15 years ago
|
m_title->setFocus();
|
||
|
if (isF)
|
||
|
{
|
||
|
m_url = new KLineEdit( main );
|
||
|
grid->addWidget( m_url, 1, 1 );
|
||
15 years ago
|
grid->addWidget( new TQLabel( m_url, i18n( "Location:" ), main ), 1, 0 );
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
m_url = 0;
|
||
|
}
|
||
|
|
||
|
main->setMinimumSize( 300, 0 );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkEditFields::setName(const TQString &str)
|
||
15 years ago
|
{
|
||
|
m_title->setText(str);
|
||
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkEditFields::setLocation(const TQString &str)
|
||
15 years ago
|
{
|
||
|
m_url->setText(str);
|
||
|
}
|
||
|
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
|
||
|
// TODO - make the dialog use Properties as a title when in Modify mode... (dirk noticed the bug...)
|
||
15 years ago
|
KBookmarkEditDialog::KBookmarkEditDialog(const TQString& title, const TQString& url, KBookmarkManager * mgr, BookmarkEditType editType, const TQString& address,
|
||
|
TQWidget * parent, const char * name, const TQString& caption )
|
||
15 years ago
|
: KDialogBase(parent, name, true, caption,
|
||
|
(editType == InsertionMode) ? (User1|Ok|Cancel) : (Ok|Cancel),
|
||
|
Ok, false, KGuiItem()),
|
||
|
m_folderTree(0), m_mgr(mgr), m_editType(editType), m_address(address)
|
||
|
{
|
||
|
setButtonOK( (editType == InsertionMode) ? KGuiItem( i18n( "&Add" ), "bookmark_add") : i18n( "&Update" ) );
|
||
|
if (editType == InsertionMode) {
|
||
10 years ago
|
setButtonGuiItem( User1, KGuiItem( i18n( "&New Folder..." ), "folder-new") );
|
||
15 years ago
|
}
|
||
|
|
||
|
bool folder = url.isNull();
|
||
|
|
||
15 years ago
|
m_main = new TQWidget( this );
|
||
15 years ago
|
setMainWidget( m_main );
|
||
|
|
||
15 years ago
|
TQBoxLayout *vbox = new TQVBoxLayout( m_main, 0, spacingHint() );
|
||
15 years ago
|
KBookmarkEditFields::FieldsSet fs =
|
||
|
folder ? KBookmarkEditFields::FolderFieldsSet
|
||
|
: KBookmarkEditFields::BookmarkFieldsSet;
|
||
|
m_fields = new KBookmarkEditFields(m_main, vbox, fs);
|
||
|
m_fields->setName(title);
|
||
|
if ( !folder )
|
||
|
m_fields->setLocation(url);
|
||
|
|
||
|
if ( editType == InsertionMode )
|
||
|
{
|
||
|
m_folderTree = KBookmarkFolderTree::createTree( m_mgr, m_main, name, m_address );
|
||
15 years ago
|
connect( m_folderTree, TQT_SIGNAL( doubleClicked(TQListViewItem*) ),
|
||
|
this, TQT_SLOT( slotDoubleClicked(TQListViewItem*) ) );
|
||
15 years ago
|
vbox->addWidget( m_folderTree );
|
||
15 years ago
|
connect( this, TQT_SIGNAL( user1Clicked() ), TQT_SLOT( slotUser1() ) );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkEditDialog::slotDoubleClicked( TQListViewItem* item )
|
||
15 years ago
|
{
|
||
|
Q_ASSERT( m_folderTree );
|
||
|
m_folderTree->setCurrentItem( item );
|
||
|
accept();
|
||
|
}
|
||
|
|
||
|
void KBookmarkEditDialog::slotOk()
|
||
|
{
|
||
|
accept();
|
||
|
}
|
||
|
|
||
|
void KBookmarkEditDialog::slotCancel()
|
||
|
{
|
||
|
reject();
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KBookmarkEditDialog::finalAddress() const
|
||
15 years ago
|
{
|
||
|
Q_ASSERT( m_folderTree );
|
||
|
return KBookmarkFolderTree::selectedAddress( m_folderTree );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KBookmarkEditDialog::finalUrl() const
|
||
15 years ago
|
{
|
||
15 years ago
|
return m_fields->m_url ? m_fields->m_url->text() : TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString KBookmarkEditDialog::finalTitle() const
|
||
15 years ago
|
{
|
||
15 years ago
|
return m_fields->m_title ? m_fields->m_title->text() : TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
void KBookmarkEditDialog::slotUser1()
|
||
|
{
|
||
|
// kdDebug(7043) << "KBookmarkEditDialog::slotUser1" << endl;
|
||
|
Q_ASSERT( m_folderTree );
|
||
|
|
||
15 years ago
|
TQString address = KBookmarkFolderTree::selectedAddress( m_folderTree );
|
||
15 years ago
|
if ( address.isNull() ) return;
|
||
14 years ago
|
KBookmarkGroup bm = m_mgr->findByAddress( address ).toGroup();
|
||
15 years ago
|
Q_ASSERT(!bm.isNull());
|
||
|
Q_ASSERT(m_editType == InsertionMode);
|
||
|
|
||
|
KBookmarkGroup group = bm.createNewFolder( m_mgr );
|
||
|
if ( !group.isNull() )
|
||
|
{
|
||
|
KBookmarkGroup parentGroup = group.parentGroup();
|
||
|
m_mgr->emitChanged( parentGroup );
|
||
|
}
|
||
|
KBookmarkFolderTree::fillTree( m_folderTree, m_mgr );
|
||
|
}
|
||
|
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
|
||
15 years ago
|
static void fillGroup( TQListView* listview, KBookmarkFolderTreeItem * parentItem, KBookmarkGroup group, bool expandOpenGroups = true, const TQString& address = TQString::null )
|
||
15 years ago
|
{
|
||
|
bool noSubGroups = true;
|
||
|
KBookmarkFolderTreeItem * lastItem = 0L;
|
||
|
KBookmarkFolderTreeItem * item = 0L;
|
||
|
for ( KBookmark bk = group.first() ; !bk.isNull() ; bk = group.next(bk) )
|
||
|
{
|
||
|
if ( bk.isGroup() )
|
||
|
{
|
||
|
KBookmarkGroup grp = bk.toGroup();
|
||
|
item = new KBookmarkFolderTreeItem( parentItem, lastItem, grp );
|
||
|
fillGroup( listview, item, grp, expandOpenGroups, address );
|
||
|
if ( expandOpenGroups && grp.isOpen() )
|
||
|
item->setOpen( true );
|
||
|
lastItem = item;
|
||
|
noSubGroups = false;
|
||
|
}
|
||
|
if (bk.address() == address) {
|
||
|
listview->setCurrentItem( lastItem );
|
||
|
listview->ensureItemVisible( item );
|
||
|
}
|
||
|
}
|
||
|
if ( noSubGroups ) {
|
||
|
parentItem->setOpen( true );
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQListView* KBookmarkFolderTree::createTree( KBookmarkManager* mgr, TQWidget* parent, const char* name, const TQString& address )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQListView *listview = new TQListView( parent, name );
|
||
15 years ago
|
|
||
|
listview->setRootIsDecorated( false );
|
||
|
listview->header()->hide();
|
||
|
listview->addColumn( i18n("Bookmark"), 200 );
|
||
|
listview->setSorting( -1, false );
|
||
15 years ago
|
listview->setSelectionMode( TQListView::Single );
|
||
15 years ago
|
listview->setAllColumnsShowFocus( true );
|
||
15 years ago
|
listview->setResizeMode( TQListView::AllColumns );
|
||
15 years ago
|
listview->setMinimumSize( 60, 100 );
|
||
|
|
||
|
fillTree( listview, mgr, address );
|
||
|
|
||
|
return listview;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkFolderTree::fillTree( TQListView *listview, KBookmarkManager* mgr, const TQString& address )
|
||
15 years ago
|
{
|
||
|
listview->clear();
|
||
|
|
||
|
KBookmarkGroup root = mgr->root();
|
||
|
KBookmarkFolderTreeItem * rootItem = new KBookmarkFolderTreeItem( listview, root );
|
||
|
listview->setCurrentItem( rootItem );
|
||
|
rootItem->setSelected( true );
|
||
|
fillGroup( listview, rootItem, root, (address == root.groupAddress() || address.isNull()) ? true : false, address );
|
||
|
rootItem->setOpen( true );
|
||
|
}
|
||
|
|
||
15 years ago
|
static KBookmarkFolderTreeItem* ft_cast( TQListViewItem *i )
|
||
15 years ago
|
{
|
||
|
return static_cast<KBookmarkFolderTreeItem*>( i );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KBookmarkFolderTree::selectedAddress( TQListView *listview )
|
||
15 years ago
|
{
|
||
|
if ( !listview)
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
KBookmarkFolderTreeItem *item = ft_cast( listview->currentItem() );
|
||
15 years ago
|
return item ? item->m_bookmark.address() : TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkFolderTree::setAddress( TQListView *listview, const TQString & address )
|
||
15 years ago
|
{
|
||
|
KBookmarkFolderTreeItem* it = ft_cast( listview->firstChild() );
|
||
|
while ( true ) {
|
||
|
kdDebug(7043) << it->m_bookmark.address() << endl;
|
||
|
it = ft_cast( it->itemBelow() );
|
||
|
if ( !it )
|
||
|
return;
|
||
|
if ( it->m_bookmark.address() == address )
|
||
|
break;
|
||
|
}
|
||
|
it->setSelected( true );
|
||
|
listview->setCurrentItem( it );
|
||
|
}
|
||
|
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
|
||
|
// toplevel item
|
||
15 years ago
|
KBookmarkFolderTreeItem::KBookmarkFolderTreeItem( TQListView *parent, const KBookmark & gp )
|
||
|
: TQListViewItem(parent, i18n("Bookmarks")), m_bookmark(gp)
|
||
15 years ago
|
{
|
||
|
setPixmap(0, SmallIcon("bookmark"));
|
||
|
setExpandable(true);
|
||
|
}
|
||
|
|
||
|
// group
|
||
15 years ago
|
KBookmarkFolderTreeItem::KBookmarkFolderTreeItem( KBookmarkFolderTreeItem *parent, TQListViewItem *after, const KBookmarkGroup & gp )
|
||
|
: TQListViewItem(parent, after, gp.fullText()), m_bookmark(gp)
|
||
15 years ago
|
{
|
||
|
setPixmap(0, SmallIcon( gp.icon() ) );
|
||
|
setExpandable(true);
|
||
|
}
|
||
|
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
|
||
|
// NOTE - KBookmarkMenuNSImporter is really === KBookmarkMenuImporter
|
||
|
// i.e, it is _not_ ns specific. and in KDE4 it should be renamed.
|
||
|
|
||
|
void KBookmarkMenuNSImporter::openNSBookmarks()
|
||
|
{
|
||
|
openBookmarks( KNSBookmarkImporter::netscapeBookmarksFile(), "netscape" );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkMenuNSImporter::openBookmarks( const TQString &location, const TQString &type )
|
||
15 years ago
|
{
|
||
|
mstack.push(m_menu);
|
||
|
|
||
|
KBookmarkImporterBase *importer = KBookmarkImporterBase::factory(type);
|
||
|
if (!importer)
|
||
|
return;
|
||
|
importer->setFilename(location);
|
||
|
connectToImporter(*importer);
|
||
|
importer->parse();
|
||
|
|
||
|
delete importer;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkMenuNSImporter::connectToImporter(const TQObject &importer)
|
||
15 years ago
|
{
|
||
15 years ago
|
connect( &importer, TQT_SIGNAL( newBookmark( const TQString &, const TQCString &, const TQString & ) ),
|
||
|
TQT_SLOT( newBookmark( const TQString &, const TQCString &, const TQString & ) ) );
|
||
|
connect( &importer, TQT_SIGNAL( newFolder( const TQString &, bool, const TQString & ) ),
|
||
|
TQT_SLOT( newFolder( const TQString &, bool, const TQString & ) ) );
|
||
|
connect( &importer, TQT_SIGNAL( newSeparator() ), TQT_SLOT( newSeparator() ) );
|
||
|
connect( &importer, TQT_SIGNAL( endFolder() ), TQT_SLOT( endFolder() ) );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkMenuNSImporter::newBookmark( const TQString & text, const TQCString & url, const TQString & )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString _text = KStringHandler::csqueeze(text);
|
||
14 years ago
|
_text.replace( '&', "&&" );
|
||
10 years ago
|
TDEAction * action = new KBookmarkAction(_text, "text-html", 0, 0, "", m_actionCollection, 0);
|
||
12 years ago
|
connect(action, TQT_SIGNAL( activated ( TDEAction::ActivationReason, TQt::ButtonState )),
|
||
|
m_menu, TQT_SLOT( slotBookmarkSelected( TDEAction::ActivationReason, TQt::ButtonState ) ));
|
||
15 years ago
|
action->setProperty( "url", url );
|
||
|
action->setToolTip( url );
|
||
|
action->plug( mstack.top()->m_parentMenu );
|
||
|
mstack.top()->m_actions.append( action );
|
||
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkMenuNSImporter::newFolder( const TQString & text, bool, const TQString & )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString _text = KStringHandler::csqueeze(text);
|
||
14 years ago
|
_text.replace( '&', "&&" );
|
||
12 years ago
|
TDEActionMenu * actionMenu = new TDEActionMenu( _text, "folder", m_actionCollection, 0L );
|
||
15 years ago
|
actionMenu->plug( mstack.top()->m_parentMenu );
|
||
|
mstack.top()->m_actions.append( actionMenu );
|
||
|
KBookmarkMenu *subMenu = new KBookmarkMenu( m_pManager, m_menu->m_pOwner, actionMenu->popupMenu(),
|
||
|
m_actionCollection, false,
|
||
15 years ago
|
m_menu->m_bAddBookmark, TQString::null );
|
||
14 years ago
|
connect( subMenu, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ),
|
||
|
m_menu, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ));
|
||
15 years ago
|
mstack.top()->m_lstSubMenus.append( subMenu );
|
||
|
|
||
|
mstack.push(subMenu);
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenuNSImporter::newSeparator()
|
||
|
{
|
||
|
mstack.top()->m_parentMenu->insertSeparator();
|
||
|
}
|
||
|
|
||
|
void KBookmarkMenuNSImporter::endFolder()
|
||
|
{
|
||
|
mstack.pop();
|
||
|
}
|
||
|
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
/********************************************************************/
|
||
|
|
||
15 years ago
|
KBookmarkMenu::DynMenuInfo KBookmarkMenu::showDynamicBookmarks( const TQString &id )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEConfig config("kbookmarkrc", false, false);
|
||
15 years ago
|
config.setGroup("Bookmarks");
|
||
|
|
||
|
DynMenuInfo info;
|
||
|
info.show = false;
|
||
|
|
||
|
if (!config.hasKey("DynamicMenus")) {
|
||
|
// upgrade path
|
||
|
if (id == "netscape") {
|
||
|
KBookmarkManager *manager = KBookmarkManager::userBookmarksManager();
|
||
|
info.show = manager->root().internalElement().attribute("hide_nsbk") != "yes";
|
||
|
info.location = KNSBookmarkImporter::netscapeBookmarksFile();
|
||
|
info.type = "netscape";
|
||
|
info.name = i18n("Netscape Bookmarks");
|
||
|
} // else, no show
|
||
|
|
||
|
} else {
|
||
|
// have new version config
|
||
|
if (config.hasGroup("DynamicMenu-" + id)) {
|
||
|
config.setGroup("DynamicMenu-" + id);
|
||
|
info.show = config.readBoolEntry("Show");
|
||
|
info.location = config.readPathEntry("Location");
|
||
|
info.type = config.readEntry("Type");
|
||
|
info.name = config.readEntry("Name");
|
||
|
} // else, no show
|
||
|
}
|
||
|
|
||
|
return info;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList KBookmarkMenu::dynamicBookmarksList()
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEConfig config("kbookmarkrc", false, false);
|
||
15 years ago
|
config.setGroup("Bookmarks");
|
||
|
|
||
15 years ago
|
TQStringList mlist;
|
||
15 years ago
|
if (config.hasKey("DynamicMenus"))
|
||
|
mlist = config.readListEntry("DynamicMenus");
|
||
|
else
|
||
|
mlist << "netscape";
|
||
|
|
||
|
return mlist;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KBookmarkMenu::setDynamicBookmarks(const TQString &id, const DynMenuInfo &newMenu)
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEConfig config("kbookmarkrc", false, false);
|
||
15 years ago
|
|
||
|
// add group unconditionally
|
||
|
config.setGroup("DynamicMenu-" + id);
|
||
|
config.writeEntry("Show", newMenu.show);
|
||
|
config.writePathEntry("Location", newMenu.location);
|
||
|
config.writeEntry("Type", newMenu.type);
|
||
|
config.writeEntry("Name", newMenu.name);
|
||
|
|
||
15 years ago
|
TQStringList elist;
|
||
15 years ago
|
|
||
|
config.setGroup("Bookmarks");
|
||
|
if (!config.hasKey("DynamicMenus")) {
|
||
|
if (newMenu.type != "netscape") {
|
||
|
// update from old xbel method to new rc method
|
||
|
// though only if not writing the netscape setting
|
||
|
config.setGroup("DynamicMenu-" "netscape");
|
||
|
DynMenuInfo xbelSetting;
|
||
|
xbelSetting = showDynamicBookmarks("netscape");
|
||
|
config.writeEntry("Show", xbelSetting.show);
|
||
|
config.writePathEntry("Location", xbelSetting.location);
|
||
|
config.writeEntry("Type", xbelSetting.type);
|
||
|
config.writeEntry("Name", xbelSetting.name);
|
||
|
}
|
||
|
} else {
|
||
|
elist = config.readListEntry("DynamicMenus");
|
||
|
}
|
||
|
|
||
|
// make sure list includes type
|
||
|
config.setGroup("Bookmarks");
|
||
14 years ago
|
if (elist.contains(id) < 1) {
|
||
15 years ago
|
elist << id;
|
||
|
config.writeEntry("DynamicMenus", elist);
|
||
|
}
|
||
|
|
||
|
config.sync();
|
||
|
}
|
||
|
|
||
|
#include "kbookmarkmenu.moc"
|
||
|
#include "kbookmarkmenu_p.moc"
|