2000-10-26 03:52:56 +00:00
|
|
|
/* This file is part of the KDE project
|
|
|
|
Copyright (C) 2000 David Faure <faure@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public
|
|
|
|
License version 2 as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program 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
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; see the file COPYING. If not, write to
|
|
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "toplevel.h"
|
2000-10-27 00:52:28 +00:00
|
|
|
#include "commands.h"
|
2000-10-26 03:52:56 +00:00
|
|
|
#include <kaction.h>
|
2000-12-07 17:15:03 +00:00
|
|
|
#include <kbookmarkdrag.h>
|
2000-10-26 03:52:56 +00:00
|
|
|
#include <kbookmarkmanager.h>
|
2000-11-05 20:58:15 +00:00
|
|
|
#include <kbookmarkimporter.h>
|
2000-11-18 01:04:45 +00:00
|
|
|
#include <kbookmarkexporter.h>
|
2000-10-26 03:52:56 +00:00
|
|
|
#include <kdebug.h>
|
2001-06-04 01:04:44 +00:00
|
|
|
#include <kedittoolbar.h>
|
|
|
|
#include <kkeydialog.h>
|
2000-10-26 03:52:56 +00:00
|
|
|
#include <kstdaction.h>
|
|
|
|
#include <klocale.h>
|
2001-02-14 11:59:27 +00:00
|
|
|
#include <kglobal.h>
|
2000-10-26 03:52:56 +00:00
|
|
|
#include <kmessagebox.h>
|
|
|
|
#include <krun.h>
|
|
|
|
#include <kiconloader.h>
|
2000-11-18 01:04:45 +00:00
|
|
|
#include <kicondialog.h>
|
2000-10-26 03:52:56 +00:00
|
|
|
#include <kapp.h>
|
2000-11-22 01:46:49 +00:00
|
|
|
#include <qclipboard.h>
|
2000-11-05 20:58:15 +00:00
|
|
|
#include <qfile.h>
|
2000-10-26 03:52:56 +00:00
|
|
|
#include <dcopclient.h>
|
2000-10-27 00:52:28 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-11-18 01:04:45 +00:00
|
|
|
//#define DEBUG_ADDRESSES
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-10-27 00:52:28 +00:00
|
|
|
// toplevel item (there should be only one!)
|
|
|
|
KEBListViewItem::KEBListViewItem(QListView *parent, const KBookmark & group )
|
|
|
|
: QListViewItem(parent, i18n("Bookmarks") ), m_bookmark(group)
|
2000-10-26 03:52:56 +00:00
|
|
|
{
|
2000-10-27 00:52:28 +00:00
|
|
|
setPixmap(0, SmallIcon("bookmark"));
|
2000-11-13 13:52:26 +00:00
|
|
|
setExpandable(true); // Didn't know this was necessary :)
|
2000-10-27 00:52:28 +00:00
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-10-27 00:52:28 +00:00
|
|
|
// bookmark (first of its group)
|
|
|
|
KEBListViewItem::KEBListViewItem(KEBListViewItem *parent, const KBookmark & bk )
|
2000-11-29 16:24:22 +00:00
|
|
|
: QListViewItem(parent, bk.fullText(), bk.url().prettyURL()), m_bookmark(bk)
|
2000-10-27 00:52:28 +00:00
|
|
|
{
|
2000-11-18 01:04:45 +00:00
|
|
|
init(bk);
|
2000-10-27 00:52:28 +00:00
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-10-27 00:52:28 +00:00
|
|
|
// bookmark (after another)
|
|
|
|
KEBListViewItem::KEBListViewItem(KEBListViewItem *parent, QListViewItem *after, const KBookmark & bk )
|
2000-11-29 16:24:22 +00:00
|
|
|
: QListViewItem(parent, after, bk.fullText(), bk.url().prettyURL()), m_bookmark(bk)
|
2000-10-27 00:52:28 +00:00
|
|
|
{
|
2000-11-18 01:04:45 +00:00
|
|
|
init(bk);
|
2000-10-27 00:52:28 +00:00
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-10-27 00:52:28 +00:00
|
|
|
// group
|
|
|
|
KEBListViewItem::KEBListViewItem(KEBListViewItem *parent, QListViewItem *after, const KBookmarkGroup & gp )
|
|
|
|
: QListViewItem(parent, after, gp.fullText()), m_bookmark(gp)
|
|
|
|
{
|
2000-11-18 01:04:45 +00:00
|
|
|
init(gp);
|
2000-11-13 01:58:00 +00:00
|
|
|
setExpandable(true);
|
2000-11-18 01:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBListViewItem::init( const KBookmark & bk )
|
|
|
|
{
|
|
|
|
setPixmap(0, SmallIcon( bk.icon() ) );
|
2000-10-26 03:52:56 +00:00
|
|
|
#ifdef DEBUG_ADDRESSES
|
2000-11-18 01:04:45 +00:00
|
|
|
setText(2, bk.address());
|
2000-10-26 03:52:56 +00:00
|
|
|
#endif
|
2000-10-27 00:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBListViewItem::setOpen( bool open )
|
|
|
|
{
|
2000-11-29 16:24:22 +00:00
|
|
|
m_bookmark.internalElement().setAttribute( "folded", open ? "no" : "yes" );
|
2000-10-27 00:52:28 +00:00
|
|
|
QListViewItem::setOpen( open );
|
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2001-02-24 18:05:56 +00:00
|
|
|
void KEBListView::rename( QListViewItem *_item, int c )
|
2000-10-27 00:52:28 +00:00
|
|
|
{
|
2001-02-24 18:05:56 +00:00
|
|
|
KEBListViewItem * item = static_cast<KEBListViewItem *>(_item);
|
2001-05-16 14:43:54 +00:00
|
|
|
if ( !(item->bookmark().isGroup() && c == 1) && !item->bookmark().isSeparator() && ( firstChild() != item) )
|
2001-02-24 18:05:56 +00:00
|
|
|
KListView::rename( _item, c );
|
|
|
|
}
|
2000-10-27 00:52:28 +00:00
|
|
|
|
2001-02-24 18:05:56 +00:00
|
|
|
bool KEBListView::acceptDrag(QDropEvent * e) const
|
|
|
|
{
|
|
|
|
return e->source() == viewport() || KBookmarkDrag::canDecode( e );
|
|
|
|
}
|
2000-11-14 12:59:21 +00:00
|
|
|
|
2001-02-24 18:05:56 +00:00
|
|
|
QDragObject *KEBListView::dragObject() const
|
|
|
|
{
|
|
|
|
if (!currentItem())
|
|
|
|
return 0;
|
2000-11-14 12:59:21 +00:00
|
|
|
|
2001-02-24 18:05:56 +00:00
|
|
|
KBookmark bk = KEBTopLevel::self()->selectedBookmark();
|
|
|
|
KBookmarkDrag * drag = KBookmarkDrag::newDrag( bk, viewport() /*not sure why klistview does it this way*/ );
|
|
|
|
drag->setPixmap( SmallIcon(bk.icon()) );
|
|
|
|
return drag;
|
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-10-27 00:52:28 +00:00
|
|
|
KEBTopLevel * KEBTopLevel::s_topLevel = 0L;
|
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
KEBTopLevel::KEBTopLevel( const QString & bookmarksFile )
|
2001-02-26 23:19:23 +00:00
|
|
|
: KMainWindow(), m_commandHistory( actionCollection() )
|
2000-10-26 03:52:56 +00:00
|
|
|
{
|
|
|
|
// Create the bookmark manager.
|
|
|
|
// It will be available in KBookmarkManager::self() from now.
|
|
|
|
(void) new KBookmarkManager( bookmarksFile, false );
|
|
|
|
|
|
|
|
// Create the list view
|
2000-10-27 00:52:28 +00:00
|
|
|
m_pListView = new KEBListView( this );
|
2000-10-26 03:52:56 +00:00
|
|
|
m_pListView->setDragEnabled( true );
|
|
|
|
m_pListView->addColumn( i18n("Bookmark"), 300 );
|
|
|
|
m_pListView->addColumn( i18n("URL"), 300 );
|
|
|
|
#ifdef DEBUG_ADDRESSES
|
|
|
|
m_pListView->addColumn( "Address", 100 );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_pListView->setRootIsDecorated( true );
|
|
|
|
m_pListView->setRenameable( 0 );
|
|
|
|
m_pListView->setRenameable( 1 );
|
|
|
|
m_pListView->setItemsRenameable( true );
|
2000-11-22 16:31:09 +00:00
|
|
|
m_pListView->setItemsMovable( false ); // We move items ourselves (for undo)
|
2000-10-26 03:52:56 +00:00
|
|
|
m_pListView->setAcceptDrops( true );
|
2000-11-22 16:31:09 +00:00
|
|
|
m_pListView->setDropVisualizer( true );
|
|
|
|
m_pListView->setDragEnabled( true );
|
2000-10-26 03:52:56 +00:00
|
|
|
m_pListView->setAllColumnsShowFocus( true );
|
|
|
|
m_pListView->setSorting(-1, false);
|
|
|
|
setCentralWidget( m_pListView );
|
2000-10-27 00:52:28 +00:00
|
|
|
resize( m_pListView->sizeHint().width(), 400 );
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2001-02-25 12:11:11 +00:00
|
|
|
connect( m_pListView, SIGNAL(itemRenamed(QListViewItem *, const QString &, int)),
|
|
|
|
SLOT(slotItemRenamed(QListViewItem *, const QString &, int)) );
|
2000-11-22 16:31:09 +00:00
|
|
|
connect( m_pListView, SIGNAL(dropped (QDropEvent* , QListViewItem* , QListViewItem* )),
|
|
|
|
SLOT(slotDropped(QDropEvent* , QListViewItem* , QListViewItem* )) );
|
2000-10-26 03:52:56 +00:00
|
|
|
connect( m_pListView, SIGNAL(contextMenu( KListView *, QListViewItem *, const QPoint & )),
|
|
|
|
SLOT(slotContextMenu( KListView *, QListViewItem *, const QPoint & )) );
|
2000-11-22 16:31:09 +00:00
|
|
|
connect( m_pListView, SIGNAL(selectionChanged() ),
|
|
|
|
SLOT(slotSelectionChanged() ) );
|
|
|
|
connect( kapp->clipboard(), SIGNAL(dataChanged()),
|
2000-11-22 19:28:23 +00:00
|
|
|
SLOT(slotClipboardDataChanged() ) );
|
2000-10-26 03:52:56 +00:00
|
|
|
// If someone plays with konq's bookmarks while we're open, update.
|
2001-02-26 23:19:23 +00:00
|
|
|
connect( KBookmarkManager::self(), SIGNAL( changed(const QString &, const QString &) ),
|
|
|
|
SLOT( slotBookmarksChanged(const QString &, const QString &) ) );
|
2000-11-06 00:34:03 +00:00
|
|
|
// Update GUI after executing command
|
2001-02-26 23:19:23 +00:00
|
|
|
connect( &m_commandHistory, SIGNAL( commandExecuted() ), SLOT( slotCommandExecuted() ) );
|
|
|
|
connect( &m_commandHistory, SIGNAL( documentRestored() ), SLOT( slotDocumentRestored() ) );
|
2000-10-27 00:52:28 +00:00
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
fillListView();
|
|
|
|
|
|
|
|
// Create the actions
|
|
|
|
|
2000-11-22 01:46:49 +00:00
|
|
|
KAction * act = new KAction( i18n( "Import Netscape Bookmarks" ), "netscape", 0, this, SLOT( slotImportNS() ), actionCollection(), "importNS" );
|
2000-11-18 01:04:45 +00:00
|
|
|
act->setEnabled( QFile::exists( KNSBookmarkImporter::netscapeBookmarksFile() ) );
|
2000-11-22 01:46:49 +00:00
|
|
|
(void) new KAction( i18n( "Export To Netscape Bookmarks" ), "netscape", 0, this, SLOT( slotExportNS() ), actionCollection(), "exportNS" );
|
|
|
|
act = new KAction( i18n( "Import Mozilla Bookmarks" ), "mozilla", 0, this, SLOT( slotImportMoz() ), actionCollection(), "importMoz" );
|
|
|
|
(void) new KAction( i18n( "Export To Mozilla Bookmarks" ), "mozilla", 0, this, SLOT( slotExportMoz() ), actionCollection(), "exportMoz" );
|
2000-10-26 03:52:56 +00:00
|
|
|
(void) KStdAction::save( this, SLOT( slotSave() ), actionCollection() );
|
2000-12-06 10:16:06 +00:00
|
|
|
(void) KStdAction::quit( this, SLOT( close() ), actionCollection() );
|
2000-11-22 01:46:49 +00:00
|
|
|
(void) KStdAction::cut( this, SLOT( slotCut() ), actionCollection() );
|
|
|
|
(void) KStdAction::copy( this, SLOT( slotCopy() ), actionCollection() );
|
|
|
|
(void) KStdAction::paste( this, SLOT( slotPaste() ), actionCollection() );
|
2001-06-04 01:04:44 +00:00
|
|
|
(void) KStdAction::keyBindings( this, SLOT( slotConfigureKeyBindings() ), actionCollection() );
|
|
|
|
(void) KStdAction::configureToolbars( this, SLOT( slotConfigureToolbars() ), actionCollection() );
|
2000-12-06 10:16:06 +00:00
|
|
|
(void) new KAction( i18n( "&Delete" ), "editdelete", Key_Delete, this, SLOT( slotDelete() ), actionCollection(), "delete" );
|
2000-11-22 01:46:49 +00:00
|
|
|
(void) new KAction( i18n( "&Rename" ), "text", Key_F2, this, SLOT( slotRename() ), actionCollection(), "rename" );
|
2001-02-24 18:05:56 +00:00
|
|
|
(void) new KAction( i18n( "Change &URL" ), "text", Key_F3, this, SLOT( slotChangeURL() ), actionCollection(), "changeurl" );
|
2001-04-18 22:54:26 +00:00
|
|
|
(void) new KAction( i18n( "Chan&ge Icon" ), 0, this, SLOT( slotChangeIcon() ), actionCollection(), "changeicon" );
|
2000-11-22 01:46:49 +00:00
|
|
|
(void) new KAction( i18n( "&Create New Folder" ), "folder_new", CTRL+Key_N, this, SLOT( slotNewFolder() ), actionCollection(), "newfolder" );
|
2001-04-18 22:54:26 +00:00
|
|
|
(void) new KAction( i18n( "&Create New Bookmark" ), "www", 0, this, SLOT( slotNewBookmark() ), actionCollection(), "newbookmark" );
|
2000-11-22 01:46:49 +00:00
|
|
|
(void) new KAction( i18n( "&Insert separator" ), CTRL+Key_I, this, SLOT( slotInsertSeparator() ), actionCollection(), "insertseparator" );
|
|
|
|
(void) new KAction( i18n( "&Sort alphabetically" ), 0, this, SLOT( slotSort() ), actionCollection(), "sort" );
|
|
|
|
(void) new KAction( i18n( "Set As &Toolbar Folder" ), "bookmark_toolbar", 0, this, SLOT( slotSetAsToolbar() ), actionCollection(), "setastoolbar" );
|
|
|
|
(void) new KAction( i18n( "&Open In Konqueror" ), "fileopen", 0, this, SLOT( slotOpenLink() ), actionCollection(), "openlink" );
|
|
|
|
(void) new KAction( i18n( "Test &Link" ), "bookmark", 0, this, SLOT( slotTestLink() ), actionCollection(), "testlink" );
|
2000-11-05 20:12:58 +00:00
|
|
|
m_taShowNS = new KToggleAction( i18n( "Show Netscape Bookmarks in Konqueror windows" ), 0, this, SLOT( slotShowNS() ), actionCollection(), "settings_showNS" );
|
|
|
|
|
|
|
|
m_taShowNS->setChecked( KBookmarkManager::self()->showNSBookmarks() );
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-11-22 01:46:49 +00:00
|
|
|
actionCollection()->action("testlink")->setEnabled(false); // not implemented
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-11-03 20:40:59 +00:00
|
|
|
slotSelectionChanged();
|
2000-11-22 19:28:23 +00:00
|
|
|
slotClipboardDataChanged();
|
2000-10-26 03:52:56 +00:00
|
|
|
|
|
|
|
createGUI();
|
|
|
|
|
2000-11-22 01:46:49 +00:00
|
|
|
setAutoSaveSettings();
|
2000-10-26 03:52:56 +00:00
|
|
|
setModified(false); // for a nice caption
|
2001-02-26 23:19:23 +00:00
|
|
|
m_commandHistory.documentSaved();
|
2000-10-27 00:52:28 +00:00
|
|
|
|
|
|
|
s_topLevel = this;
|
2001-02-14 11:59:27 +00:00
|
|
|
KGlobal::locale()->insertCatalogue("libkonq");
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KEBTopLevel::~KEBTopLevel()
|
|
|
|
{
|
2000-10-27 00:52:28 +00:00
|
|
|
s_topLevel = 0L;
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
2001-06-04 01:04:44 +00:00
|
|
|
void KEBTopLevel::slotConfigureKeyBindings()
|
|
|
|
{
|
|
|
|
KKeyDialog::configureKeys(actionCollection(), xmlFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotConfigureToolbars()
|
|
|
|
{
|
|
|
|
saveMainWindowSettings( KGlobal::config(), "MainWindow" );
|
|
|
|
KEditToolbar dlg(actionCollection());
|
|
|
|
connect(&dlg,SIGNAL(newToolbarConfig()),this,SLOT(slotNewToolbarConfig()));
|
|
|
|
if (dlg.exec())
|
|
|
|
{
|
|
|
|
createGUI();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotNewToolbarConfig() // This is called when OK or Apply is clicked
|
|
|
|
{
|
|
|
|
applyMainWindowSettings( KGlobal::config(), "MainWindow" );
|
|
|
|
}
|
|
|
|
|
2000-11-22 01:46:49 +00:00
|
|
|
void KEBTopLevel::slotSelectionChanged()
|
|
|
|
{
|
|
|
|
QListViewItem * item = m_pListView->selectedItem();
|
2001-02-24 18:05:56 +00:00
|
|
|
if (item) {
|
|
|
|
kdDebug() << "KEBTopLevel::slotSelectionChanged " << (static_cast<KEBListViewItem *>(item))->bookmark().address() << endl;
|
|
|
|
}
|
2000-11-22 01:46:49 +00:00
|
|
|
bool itemSelected = (item != 0L);
|
|
|
|
bool group = false;
|
|
|
|
bool root = false;
|
|
|
|
bool separator = false;
|
2001-05-09 09:33:08 +00:00
|
|
|
bool urlIsEmpty = false;
|
2000-11-22 01:46:49 +00:00
|
|
|
if ( itemSelected )
|
|
|
|
{
|
|
|
|
KEBListViewItem * kebItem = static_cast<KEBListViewItem *>(item);
|
|
|
|
group = kebItem->bookmark().isGroup();
|
|
|
|
separator = kebItem->bookmark().isSeparator();
|
|
|
|
root = (m_pListView->firstChild() == item);
|
2001-05-09 09:33:08 +00:00
|
|
|
urlIsEmpty= kebItem->bookmark().url().isEmpty();
|
2000-11-22 01:46:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KActionCollection * coll = actionCollection();
|
|
|
|
|
|
|
|
coll->action("edit_cut")->setEnabled(itemSelected && !root);
|
|
|
|
coll->action("edit_copy")->setEnabled(itemSelected && !root);
|
2000-11-22 19:28:23 +00:00
|
|
|
coll->action("edit_paste")->setEnabled(itemSelected && !root && m_bCanPaste);
|
2000-11-22 01:46:49 +00:00
|
|
|
coll->action("rename")->setEnabled(itemSelected && !separator && !root);
|
2001-02-24 18:05:56 +00:00
|
|
|
coll->action("changeurl")->setEnabled(itemSelected && !group && !separator && !root);
|
2000-11-22 01:46:49 +00:00
|
|
|
coll->action("delete")->setEnabled(itemSelected && !root);
|
|
|
|
coll->action("newfolder")->setEnabled(itemSelected);
|
2001-05-09 10:00:45 +00:00
|
|
|
coll->action("changeicon")->setEnabled(itemSelected && !root && !separator);
|
2000-11-22 01:46:49 +00:00
|
|
|
coll->action("insertseparator")->setEnabled(itemSelected);
|
2001-05-09 08:46:07 +00:00
|
|
|
coll->action("newbookmark")->setEnabled(itemSelected);
|
2000-11-22 01:46:49 +00:00
|
|
|
coll->action("sort")->setEnabled(group);
|
|
|
|
coll->action("setastoolbar")->setEnabled(group);
|
2001-05-09 09:33:08 +00:00
|
|
|
coll->action("openlink")->setEnabled(itemSelected && !group && !separator && !urlIsEmpty);
|
2000-11-22 01:46:49 +00:00
|
|
|
//coll->action("testlink")->setEnabled(itemSelected && !group && !separator); // not implemented
|
|
|
|
}
|
|
|
|
|
2000-11-22 19:28:23 +00:00
|
|
|
void KEBTopLevel::slotClipboardDataChanged()
|
|
|
|
{
|
|
|
|
kdDebug() << "KEBTopLevel::slotClipboardDataChanged" << endl;
|
|
|
|
QMimeSource *data = QApplication::clipboard()->data();
|
2000-12-07 17:15:03 +00:00
|
|
|
m_bCanPaste = KBookmarkDrag::canDecode( data );
|
2000-11-22 19:28:23 +00:00
|
|
|
slotSelectionChanged();
|
|
|
|
}
|
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
void KEBTopLevel::slotSave()
|
|
|
|
{
|
|
|
|
(void)save();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KEBTopLevel::save()
|
|
|
|
{
|
|
|
|
bool ok = KBookmarkManager::self()->save();
|
|
|
|
if (ok)
|
|
|
|
{
|
2001-02-26 23:19:23 +00:00
|
|
|
QString data( kapp->name() );
|
|
|
|
kapp->dcopClient()->send( "*", "KBookmarkManager", "notifyCompleteChange(QString)", data );
|
2000-10-26 03:52:56 +00:00
|
|
|
setModified( false );
|
2001-02-26 23:19:23 +00:00
|
|
|
m_commandHistory.documentSaved();
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2000-10-27 00:52:28 +00:00
|
|
|
QString KEBTopLevel::insertionAddress() const
|
2000-10-26 03:52:56 +00:00
|
|
|
{
|
2000-10-27 00:52:28 +00:00
|
|
|
KBookmark current = selectedBookmark();
|
|
|
|
if (current.isGroup())
|
|
|
|
// In a group, we insert as first child
|
|
|
|
return current.address() + "/0";
|
|
|
|
else
|
|
|
|
// Otherwise, as next sibling
|
|
|
|
return KBookmark::nextAddress( current.address() );
|
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-10-27 00:52:28 +00:00
|
|
|
KEBListViewItem * KEBTopLevel::findByAddress( const QString & address ) const
|
|
|
|
{
|
|
|
|
kdDebug() << "KEBTopLevel::findByAddress " << address << endl;
|
|
|
|
QListViewItem * item = m_pListView->firstChild();
|
|
|
|
// The address is something like /5/10/2
|
|
|
|
QStringList addresses = QStringList::split('/',address);
|
|
|
|
for ( QStringList::Iterator it = addresses.begin() ; it != addresses.end() ; ++it )
|
|
|
|
{
|
|
|
|
uint number = (*it).toUInt();
|
|
|
|
//kdDebug() << "KBookmarkManager::findByAddress " << number << endl;
|
|
|
|
assert(item);
|
|
|
|
item = item->firstChild();
|
|
|
|
for ( uint i = 0 ; i < number ; ++i )
|
|
|
|
{
|
|
|
|
assert(item);
|
|
|
|
item = item->nextSibling();
|
|
|
|
}
|
|
|
|
}
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT(item);
|
2000-10-27 00:52:28 +00:00
|
|
|
return static_cast<KEBListViewItem *>(item);
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotRename()
|
|
|
|
{
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT( m_pListView->selectedItem() );
|
2001-03-13 20:36:11 +00:00
|
|
|
if ( m_pListView->selectedItem() )
|
|
|
|
m_pListView->rename( m_pListView->selectedItem(), 0 );
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
2001-02-24 18:05:56 +00:00
|
|
|
void KEBTopLevel::slotChangeURL()
|
|
|
|
{
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT( m_pListView->selectedItem() );
|
2001-03-13 20:36:11 +00:00
|
|
|
if ( m_pListView->selectedItem() )
|
|
|
|
m_pListView->rename( m_pListView->selectedItem(), 1 );
|
2001-02-24 18:05:56 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
void KEBTopLevel::slotDelete()
|
|
|
|
{
|
2000-10-27 00:52:28 +00:00
|
|
|
if( !m_pListView->selectedItem() )
|
|
|
|
{
|
|
|
|
kdWarning() << "KEBTopLevel::slotDelete no selected item !" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
KBookmark bk = selectedBookmark();
|
2000-10-27 00:52:28 +00:00
|
|
|
DeleteCommand * cmd = new DeleteCommand( i18n("Delete item"), bk.address() );
|
|
|
|
m_commandHistory.addCommand( cmd );
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotNewFolder()
|
|
|
|
{
|
2001-03-13 20:36:11 +00:00
|
|
|
if( !m_pListView->selectedItem() )
|
|
|
|
{
|
|
|
|
kdWarning() << "KEBTopLevel::slotNewFolder no selected item !" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2001-02-13 11:53:49 +00:00
|
|
|
// EVIL HACK
|
|
|
|
// We need to ask for the folder name before creating the command, in case of "Cancel".
|
|
|
|
// But in message-freeze time, impossible to add i18n()s. So... we have to call the existing code :
|
|
|
|
QDomDocument doc("xbel"); // Dummy document
|
|
|
|
QDomElement elem = doc.createElement("xbel");
|
|
|
|
doc.appendChild( elem );
|
|
|
|
KBookmarkGroup grp( elem ); // Dummy group
|
|
|
|
KBookmark bk = grp.createNewFolder( QString::null ); // Asks for the name
|
|
|
|
if ( !bk.fullText().isEmpty() ) // Not canceled
|
|
|
|
{
|
2001-05-15 09:14:29 +00:00
|
|
|
CreateCommand * cmd = new CreateCommand( i18n("Create Folder"), insertionAddress(), bk.fullText(),bk.icon() , true /*open*/ );
|
2001-02-13 11:53:49 +00:00
|
|
|
m_commandHistory.addCommand( cmd );
|
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
2001-04-18 22:54:26 +00:00
|
|
|
void KEBTopLevel::slotNewBookmark()
|
|
|
|
{
|
|
|
|
if( !m_pListView->selectedItem() )
|
|
|
|
{
|
|
|
|
kdWarning() << "KEBTopLevel::slotNewBookmark no selected item !" << endl;
|
|
|
|
return;
|
|
|
|
}
|
2001-05-15 09:14:29 +00:00
|
|
|
CreateCommand * cmd = new CreateCommand( i18n("Create bookmark" ), insertionAddress(), QString::null, QString::null, KURL() );
|
2001-04-18 22:54:26 +00:00
|
|
|
m_commandHistory.addCommand( cmd );
|
|
|
|
}
|
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
void KEBTopLevel::slotInsertSeparator()
|
|
|
|
{
|
2000-10-27 00:52:28 +00:00
|
|
|
CreateCommand * cmd = new CreateCommand( i18n("Insert separator"), insertionAddress() );
|
|
|
|
m_commandHistory.addCommand( cmd );
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
2000-11-05 20:12:58 +00:00
|
|
|
void KEBTopLevel::slotImportNS()
|
|
|
|
{
|
2000-11-18 01:04:45 +00:00
|
|
|
// Hmm, there's no questionYesNoCancel...
|
|
|
|
int answer = KMessageBox::questionYesNo( this, i18n("Import as a new subfolder or replace all the current bookmarks ?"),
|
|
|
|
i18n("Netscape Import"), i18n("As New Folder"), i18n("Replace") );
|
|
|
|
bool subFolder = (answer==KMessageBox::Yes);
|
|
|
|
ImportCommand * cmd = new ImportCommand( i18n("Import Netscape Bookmarks"), KNSBookmarkImporter::netscapeBookmarksFile(),
|
2001-06-02 23:24:39 +00:00
|
|
|
subFolder ? i18n("Netscape Bookmarks") : QString::null, "netscape", false);
|
2000-11-05 20:58:15 +00:00
|
|
|
m_commandHistory.addCommand( cmd );
|
2000-11-18 01:04:45 +00:00
|
|
|
|
|
|
|
// Ok, we don't need the dynamic menu anymore
|
|
|
|
if ( m_taShowNS->isChecked() )
|
|
|
|
m_taShowNS->activate();
|
2000-11-05 20:58:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotImportMoz()
|
|
|
|
{
|
2000-11-18 01:04:45 +00:00
|
|
|
// Hmm, there's no questionYesNoCancel...
|
|
|
|
int answer = KMessageBox::questionYesNo( this, i18n("Import as a new subfolder or replace all the current bookmarks ?"),
|
|
|
|
i18n("Mozilla Import"), i18n("As New Folder"), i18n("Replace") );
|
|
|
|
bool subFolder = (answer==KMessageBox::Yes);
|
|
|
|
ImportCommand * cmd = new ImportCommand( i18n("Import Mozilla Bookmarks"), KNSBookmarkImporter::mozillaBookmarksFile(),
|
2001-06-02 23:24:39 +00:00
|
|
|
subFolder ? i18n("Mozilla Bookmarks") : QString::null, "mozilla", true);
|
2000-11-05 20:12:58 +00:00
|
|
|
m_commandHistory.addCommand( cmd );
|
|
|
|
}
|
|
|
|
|
2000-11-18 01:04:45 +00:00
|
|
|
void KEBTopLevel::slotExportNS()
|
|
|
|
{
|
2001-01-11 13:41:24 +00:00
|
|
|
QString path = KNSBookmarkImporter::netscapeBookmarksFile(true);
|
|
|
|
if (!path.isEmpty())
|
|
|
|
{
|
|
|
|
KNSBookmarkExporter exporter( path );
|
2001-06-02 23:24:39 +00:00
|
|
|
exporter.write( false );
|
2001-01-11 13:41:24 +00:00
|
|
|
}
|
2000-11-18 01:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotExportMoz()
|
|
|
|
{
|
2001-01-11 13:41:24 +00:00
|
|
|
QString path = KNSBookmarkImporter::mozillaBookmarksFile(true);
|
|
|
|
if (!path.isEmpty())
|
|
|
|
{
|
|
|
|
KNSBookmarkExporter exporter( path );
|
2001-06-02 23:24:39 +00:00
|
|
|
exporter.write( true );
|
2001-01-11 13:41:24 +00:00
|
|
|
}
|
2000-11-18 01:04:45 +00:00
|
|
|
}
|
|
|
|
|
2000-11-22 01:46:49 +00:00
|
|
|
void KEBTopLevel::slotCut()
|
|
|
|
{
|
|
|
|
KBookmark bk = selectedBookmark();
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT(!bk.isNull());
|
2000-11-22 01:46:49 +00:00
|
|
|
slotCopy();
|
|
|
|
// Very much like slotDelete, except for the name
|
|
|
|
DeleteCommand * cmd = new DeleteCommand( i18n("Cut item"), bk.address() );
|
|
|
|
m_commandHistory.addCommand( cmd );
|
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotCopy()
|
|
|
|
{
|
|
|
|
KBookmark bk = selectedBookmark();
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT(!bk.isNull());
|
2000-11-22 01:46:49 +00:00
|
|
|
// This is not a command, because it can't be undone
|
|
|
|
|
2000-12-07 17:15:03 +00:00
|
|
|
KBookmarkDrag* data = KBookmarkDrag::newDrag( bk, 0L /* not this ! */ );
|
2000-11-22 01:46:49 +00:00
|
|
|
QApplication::clipboard()->setData( data );
|
2000-11-22 19:28:23 +00:00
|
|
|
slotClipboardDataChanged(); // don't ask
|
2000-11-22 01:46:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotPaste()
|
|
|
|
{
|
2000-11-22 16:31:09 +00:00
|
|
|
pasteData( i18n("Paste"), QApplication::clipboard()->data(), insertionAddress() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::pasteData( const QString & cmdName, QMimeSource * data, const QString & insertionAddress )
|
|
|
|
{
|
2000-12-07 17:15:03 +00:00
|
|
|
if ( KBookmarkDrag::canDecode( data ) )
|
2000-11-22 01:46:49 +00:00
|
|
|
{
|
2000-12-07 17:15:03 +00:00
|
|
|
KBookmark bk = KBookmarkDrag::decode( data );
|
2000-11-29 16:24:22 +00:00
|
|
|
kdDebug() << "KEBTopLevel::slotPaste url=" << bk.url().prettyURL() << endl;
|
2000-11-22 16:31:09 +00:00
|
|
|
CreateCommand * cmd = new CreateCommand( cmdName, insertionAddress, bk );
|
2000-11-22 01:46:49 +00:00
|
|
|
m_commandHistory.addCommand( cmd );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
void KEBTopLevel::slotSort()
|
|
|
|
{
|
2000-11-18 17:21:11 +00:00
|
|
|
KBookmark bk = selectedBookmark();
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT(!bk.isNull());
|
|
|
|
Q_ASSERT(bk.isGroup());
|
2000-11-22 01:46:49 +00:00
|
|
|
|
|
|
|
////
|
|
|
|
|
2000-11-18 17:21:11 +00:00
|
|
|
SortCommand * cmd = new SortCommand("Sort alphabetically", bk.address());
|
|
|
|
m_commandHistory.addCommand( cmd );
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotSetAsToolbar()
|
|
|
|
{
|
2000-11-06 00:34:03 +00:00
|
|
|
KMacroCommand * cmd = new KMacroCommand("Set as Bookmark Toolbar");
|
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
KBookmarkGroup oldToolbar = KBookmarkManager::self()->toolbar();
|
|
|
|
if (!oldToolbar.isNull())
|
2000-11-06 00:34:03 +00:00
|
|
|
{
|
|
|
|
QValueList<EditCommand::Edition> lst;
|
2000-12-04 18:19:07 +00:00
|
|
|
lst.append(EditCommand::Edition( "toolbar", "no" ));
|
|
|
|
lst.append(EditCommand::Edition( "icon", "" ));
|
2000-11-06 00:34:03 +00:00
|
|
|
EditCommand * cmd1 = new EditCommand("", oldToolbar.address(), lst);
|
|
|
|
cmd->addCommand(cmd1);
|
|
|
|
}
|
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
KBookmark bk = selectedBookmark();
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT( bk.isGroup() );
|
2000-11-06 00:34:03 +00:00
|
|
|
QValueList<EditCommand::Edition> lst;
|
2000-12-04 18:19:07 +00:00
|
|
|
lst.append(EditCommand::Edition( "toolbar", "yes" ));
|
|
|
|
lst.append(EditCommand::Edition( "icon", "bookmark_toolbar" ));
|
2000-11-06 00:34:03 +00:00
|
|
|
EditCommand * cmd2 = new EditCommand("", bk.address(), lst);
|
|
|
|
cmd->addCommand(cmd2);
|
|
|
|
|
|
|
|
m_commandHistory.addCommand( cmd );
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotOpenLink()
|
|
|
|
{
|
|
|
|
KBookmark bk = selectedBookmark();
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT( !bk.isGroup() );
|
2000-10-26 03:52:56 +00:00
|
|
|
(void) new KRun( bk.url() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotTestLink()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotShowNS()
|
|
|
|
{
|
2000-11-18 01:04:45 +00:00
|
|
|
kdDebug() << "KEBTopLevel::slotShowNS" << endl;
|
2000-11-05 20:12:58 +00:00
|
|
|
QDomElement rootElem = KBookmarkManager::self()->root().internalElement();
|
2000-11-29 16:24:22 +00:00
|
|
|
QString attr = "hide_nsbk";
|
|
|
|
rootElem.setAttribute(attr, rootElem.attribute(attr) == "yes" ? "no" : "yes");
|
2000-11-05 20:12:58 +00:00
|
|
|
setModified(); // one will need to save, to get konq to notice the change
|
|
|
|
// If that's bad, then we need to put this flag in a KConfig.
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::setModified( bool modified )
|
|
|
|
{
|
|
|
|
m_bModified = modified;
|
|
|
|
setCaption( i18n("Bookmark Editor"), m_bModified );
|
|
|
|
actionCollection()->action("file_save")->setEnabled( m_bModified );
|
|
|
|
}
|
|
|
|
|
2001-02-26 23:19:23 +00:00
|
|
|
void KEBTopLevel::slotDocumentRestored()
|
|
|
|
{
|
|
|
|
setModified( false );
|
|
|
|
}
|
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
KBookmark KEBTopLevel::selectedBookmark() const
|
|
|
|
{
|
|
|
|
QListViewItem * item = m_pListView->selectedItem();
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT(item);
|
2000-10-26 03:52:56 +00:00
|
|
|
KEBListViewItem * kebItem = static_cast<KEBListViewItem *>(item);
|
|
|
|
return kebItem->bookmark();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotItemRenamed(QListViewItem * item, const QString & newText, int column)
|
|
|
|
{
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT(item);
|
2000-10-26 03:52:56 +00:00
|
|
|
KEBListViewItem * kebItem = static_cast<KEBListViewItem *>(item);
|
|
|
|
KBookmark bk = kebItem->bookmark();
|
|
|
|
switch (column) {
|
|
|
|
case 0:
|
2001-05-22 13:20:33 +00:00
|
|
|
if ( (bk.fullText() != newText) && !newText.isEmpty())
|
2000-10-26 03:52:56 +00:00
|
|
|
{
|
2000-11-06 00:34:03 +00:00
|
|
|
RenameCommand * cmd = new RenameCommand( i18n("Renaming"), bk.address(), newText );
|
|
|
|
m_commandHistory.addCommand( cmd );
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
2001-05-22 13:20:33 +00:00
|
|
|
else if(newText.isEmpty())
|
|
|
|
{
|
|
|
|
item->setText ( 0, bk.fullText() );
|
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if ( bk.url() != newText )
|
|
|
|
{
|
2000-11-06 00:34:03 +00:00
|
|
|
EditCommand * cmd = new EditCommand( i18n("URL change"), bk.address(),
|
2000-12-03 17:04:21 +00:00
|
|
|
EditCommand::Edition("href", newText) );
|
2000-11-06 00:34:03 +00:00
|
|
|
m_commandHistory.addCommand( cmd );
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
kdWarning() << "No such column " << column << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-18 01:04:45 +00:00
|
|
|
void KEBTopLevel::slotChangeIcon()
|
2000-10-26 03:52:56 +00:00
|
|
|
{
|
2000-11-18 01:04:45 +00:00
|
|
|
KBookmark bk = selectedBookmark();
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT(!bk.isNull());
|
2001-03-13 20:36:11 +00:00
|
|
|
if (bk.isNull()) return;
|
2000-11-18 01:04:45 +00:00
|
|
|
KIconDialog dlg(this);
|
|
|
|
QString newIcon = dlg.selectIcon(KIcon::Small, KIcon::FileSystem);
|
2001-02-11 14:39:55 +00:00
|
|
|
if ( !newIcon.isEmpty() ) {
|
|
|
|
EditCommand * cmd = new EditCommand( i18n("Icon change"), bk.address(),
|
|
|
|
EditCommand::Edition("icon", newIcon) );
|
|
|
|
m_commandHistory.addCommand( cmd );
|
|
|
|
}
|
2000-11-18 01:04:45 +00:00
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
|
2000-11-22 16:31:09 +00:00
|
|
|
void KEBTopLevel::slotDropped (QDropEvent* e, QListViewItem * _newParent, QListViewItem * _afterNow)
|
2000-11-18 01:04:45 +00:00
|
|
|
{
|
2000-11-22 16:31:09 +00:00
|
|
|
// Calculate the address given by parent+afterme
|
2000-11-13 01:58:00 +00:00
|
|
|
KEBListViewItem * newParent = static_cast<KEBListViewItem *>(_newParent);
|
2000-10-26 03:52:56 +00:00
|
|
|
KEBListViewItem * afterNow = static_cast<KEBListViewItem *>(_afterNow);
|
2000-11-13 01:58:00 +00:00
|
|
|
if (!_newParent) // Not allowed to drop something before the root item !
|
2000-10-26 03:52:56 +00:00
|
|
|
return;
|
2000-11-22 16:31:09 +00:00
|
|
|
QString newAddress =
|
|
|
|
afterNow ?
|
2000-10-27 00:52:28 +00:00
|
|
|
// We move as the next child of afterNow
|
2000-11-22 16:31:09 +00:00
|
|
|
KBookmark::nextAddress( afterNow->bookmark().address() )
|
|
|
|
:
|
2000-11-13 01:58:00 +00:00
|
|
|
// We move as first child of newParent
|
2000-11-22 16:31:09 +00:00
|
|
|
newParent->bookmark().address() + "/0";
|
|
|
|
|
|
|
|
if (e->source() == m_pListView->viewport())
|
|
|
|
{
|
|
|
|
// Now a simplified version of movableDropEvent
|
|
|
|
//movableDropEvent (parent, afterme);
|
|
|
|
QListViewItem * i = m_pListView->selectedItem();
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT(i);
|
2000-11-22 16:31:09 +00:00
|
|
|
if (i && i != _afterNow)
|
|
|
|
{
|
|
|
|
// sanity check - don't move a item into it's own child structure
|
|
|
|
QListViewItem *chk = _newParent;
|
|
|
|
while(chk)
|
|
|
|
{
|
|
|
|
if(chk == i)
|
|
|
|
return;
|
|
|
|
chk = chk->parent();
|
|
|
|
}
|
|
|
|
|
2000-11-22 19:28:23 +00:00
|
|
|
itemMoved(i, newAddress, e->action() == QDropEvent::Copy);
|
2000-11-22 16:31:09 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
// Drop from the outside
|
|
|
|
pasteData( i18n("Drop items"), e, newAddress );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-22 19:28:23 +00:00
|
|
|
void KEBTopLevel::itemMoved(QListViewItem *_item, const QString & newAddress, bool copy)
|
2000-11-22 16:31:09 +00:00
|
|
|
{
|
|
|
|
KEBListViewItem * item = static_cast<KEBListViewItem *>(_item);
|
2000-11-22 19:28:23 +00:00
|
|
|
if ( copy )
|
2000-11-14 12:59:21 +00:00
|
|
|
{
|
2000-11-22 19:28:23 +00:00
|
|
|
CreateCommand * cmd = new CreateCommand( i18n("Copy %1").arg(item->bookmark().text()), newAddress,
|
|
|
|
item->bookmark().internalElement().cloneNode( true ).toElement() );
|
2000-11-14 12:59:21 +00:00
|
|
|
m_commandHistory.addCommand( cmd );
|
|
|
|
}
|
2000-11-22 19:28:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
QString oldAddress = item->bookmark().address();
|
|
|
|
if ( oldAddress != newAddress )
|
|
|
|
{
|
|
|
|
kdDebug() << "KEBTopLevel::slotMoved moving " << oldAddress << " to " << newAddress << endl;
|
|
|
|
|
|
|
|
MoveCommand * cmd = new MoveCommand( i18n("Move %1").arg(item->bookmark().text()),
|
|
|
|
oldAddress, newAddress );
|
|
|
|
m_commandHistory.addCommand( cmd );
|
|
|
|
}
|
|
|
|
}
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::slotContextMenu( KListView *, QListViewItem * _item, const QPoint &p )
|
|
|
|
{
|
|
|
|
if (_item)
|
|
|
|
{
|
|
|
|
KEBListViewItem * item = static_cast<KEBListViewItem *>(_item);
|
|
|
|
if ( item->bookmark().isGroup() )
|
|
|
|
{
|
|
|
|
QWidget* popup = factory()->container("popup_folder", this);
|
|
|
|
if ( popup )
|
|
|
|
static_cast<QPopupMenu*>(popup)->popup(p);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QWidget* popup = factory()->container("popup_bookmark", this);
|
|
|
|
if ( popup )
|
|
|
|
static_cast<QPopupMenu*>(popup)->popup(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 23:19:23 +00:00
|
|
|
void KEBTopLevel::slotBookmarksChanged( const QString &, const QString & caller )
|
2000-10-27 00:52:28 +00:00
|
|
|
{
|
|
|
|
// This is called when someone changes bookmarks in konqueror....
|
2001-02-26 23:19:23 +00:00
|
|
|
if ( caller != kapp->name() )
|
2000-11-29 16:24:22 +00:00
|
|
|
{
|
|
|
|
kdDebug() << "KEBTopLevel::slotBookmarksChanged" << endl;
|
|
|
|
m_commandHistory.clear();
|
|
|
|
fillListView();
|
2001-03-14 10:35:17 +00:00
|
|
|
slotSelectionChanged(); // to disable everything, because no more current item
|
2000-11-29 16:24:22 +00:00
|
|
|
}
|
2000-10-27 00:52:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::update()
|
|
|
|
{
|
|
|
|
QListViewItem * item = m_pListView->selectedItem();
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
QString address = static_cast<KEBListViewItem*>(item)->bookmark().address();
|
2001-02-24 18:05:56 +00:00
|
|
|
kdDebug() << "KEBTopLevel::update item=" << address << endl;
|
2000-10-27 00:52:28 +00:00
|
|
|
fillListView();
|
|
|
|
KEBListViewItem * newItem = findByAddress( address );
|
2001-08-31 14:48:01 +00:00
|
|
|
Q_ASSERT(newItem);
|
2000-10-27 00:52:28 +00:00
|
|
|
if (newItem)
|
|
|
|
{
|
|
|
|
m_pListView->setCurrentItem(newItem);
|
|
|
|
m_pListView->setSelected(newItem,true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fillListView();
|
2000-11-03 20:40:59 +00:00
|
|
|
slotSelectionChanged();
|
2000-10-27 00:52:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
void KEBTopLevel::fillListView()
|
|
|
|
{
|
|
|
|
m_pListView->clear();
|
|
|
|
KBookmarkGroup root = KBookmarkManager::self()->root();
|
|
|
|
// Create root item
|
2000-10-27 00:52:28 +00:00
|
|
|
KEBListViewItem * rootItem = new KEBListViewItem( m_pListView, root );
|
2000-10-26 03:52:56 +00:00
|
|
|
fillGroup( rootItem, root );
|
2000-10-27 00:52:28 +00:00
|
|
|
rootItem->QListViewItem::setOpen(true);
|
2000-10-26 03:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KEBTopLevel::fillGroup( KEBListViewItem * parentItem, KBookmarkGroup group )
|
|
|
|
{
|
|
|
|
KEBListViewItem * lastItem = 0L;
|
|
|
|
for ( KBookmark bk = group.first() ; !bk.isNull() ; bk = group.next(bk) )
|
|
|
|
{
|
|
|
|
//kdDebug() << "KEBTopLevel::fillGroup group=" << group.text() << " bk=" << bk.text() << endl;
|
|
|
|
if ( bk.isGroup() )
|
|
|
|
{
|
|
|
|
KBookmarkGroup grp = bk.toGroup();
|
|
|
|
KEBListViewItem * item = new KEBListViewItem( parentItem, lastItem, grp );
|
|
|
|
fillGroup( item, grp );
|
2000-11-29 16:24:22 +00:00
|
|
|
if (grp.isOpen())
|
2000-10-27 00:52:28 +00:00
|
|
|
item->QListViewItem::setOpen(true); // no need to save it again :)
|
2000-10-26 03:52:56 +00:00
|
|
|
lastItem = item;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lastItem = new KEBListViewItem( parentItem, lastItem, bk );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KEBTopLevel::queryClose()
|
|
|
|
{
|
|
|
|
if (m_bModified)
|
|
|
|
{
|
|
|
|
switch ( KMessageBox::warningYesNoCancel( this,
|
2000-11-24 19:34:23 +00:00
|
|
|
i18n("The bookmarks have been modified.\nSave changes ?")) ) {
|
2000-10-26 03:52:56 +00:00
|
|
|
case KMessageBox::Yes :
|
|
|
|
return save();
|
|
|
|
case KMessageBox::No :
|
|
|
|
return true;
|
|
|
|
default: // cancel
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-11-06 00:34:03 +00:00
|
|
|
///////////////////
|
|
|
|
|
|
|
|
void KEBTopLevel::slotCommandExecuted()
|
|
|
|
{
|
2000-11-18 01:04:45 +00:00
|
|
|
kdDebug() << "KEBTopLevel::slotCommandExecuted" << endl;
|
2000-11-06 00:34:03 +00:00
|
|
|
KEBTopLevel::self()->setModified();
|
|
|
|
KEBTopLevel::self()->update(); // Update GUI
|
|
|
|
}
|
2000-11-05 20:12:58 +00:00
|
|
|
|
2000-10-26 03:52:56 +00:00
|
|
|
#include "toplevel.moc"
|