diff --git a/keditbookmarks/bookmarklistview.cpp b/keditbookmarks/bookmarklistview.cpp index 98f933781..0783c63ac 100644 --- a/keditbookmarks/bookmarklistview.cpp +++ b/keditbookmarks/bookmarklistview.cpp @@ -1,279 +1,281 @@ /* This file is part of the KDE project + Copyright (C) 2000 David Faure + Copyright (C) 2002-2003 Alexander Kellett Copyright (C) 2005 Daniel Teske 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., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "bookmarklistview.h" #include "bookmarkmodel.h" #include "toplevel.h" #include "settings.h" #include #include #include #include #include #include #include #include BookmarkListView::BookmarkListView( QWidget * parent ) :QTreeView( parent ) { dirtyGetSelectionAbilies = true; } BookmarkListView::~BookmarkListView() { saveColumnSetting(); } int BookmarkListView::min(int a, int b) { return a < b? a : b; } int BookmarkListView::max(int a, int b) { return a > b? a : b; } QRect BookmarkListView::merge(QRect a, QRect b) { if(a.isNull()) return b; if(b.isNull()) return a; a.normalized(); b.normalized(); int left = min(a.left(), b.left()); int top = min(a.top(), b.top()); int width = max(a.right(), b.right()) - left + 1; int height = max(a.bottom(), b.bottom()) - top + 1; return QRect(left, top, width, height); } QRect BookmarkListView::rectForRow(QModelIndex index) { QModelIndex parent = index.parent(); int row = index.row(); int columnCount = model()->columnCount(parent); QRect result; for(int i = 0; irowCount(index); for(int i=0; irowCount(parent); if(rowCount) { QItemSelection deselect; deselect.select( parent.child(0,0), parent.child(rowCount-1, model()->columnCount(parent)-1)); selectionModel()->select(deselect, QItemSelectionModel::Deselect); for(int i=0; icolumnCount() -1) ); } selectionModel()->select( deselectAgain, QItemSelectionModel::Deselect); //deselect children of selected items for(it = list.constBegin(); it != end; ++it) { if( (*it).column() !=0) continue; deselectChildren(*it); } // ensure that drawRow is called for all children const QModelIndexList & sellist = selected.indexes(); end = sellist.constEnd(); QRect rect; for(it = sellist.constBegin(); it != end; ++it) { if((*it).column() != 0) continue; if( static_cast((*it).internalPointer())->bookmark().address() == "") //FIXME continue; rect = merge(rect, rectForRowWithChildren(*it)); } const QModelIndexList & desellist = deselected.indexes(); end = desellist.constEnd(); for(it = desellist.constBegin(); it != end; ++it) { if((*it).column() != 0) continue; if( static_cast((*it).internalPointer())->bookmark().address() == "") //FIXME continue; rect = merge(rect, rectForRowWithChildren(*it)); } rect.setLeft(0); viewport()->update(rect); } QItemSelectionModel::SelectionFlags BookmarkListView::selectionCommand ( const QModelIndex & index, const QEvent * event ) const { const QMouseEvent * qme = dynamic_cast(event); if(qme && (qme->button() == Qt::RightButton ) && parentSelected(index)) //right click on a parentSelected index return QItemSelectionModel::NoUpdate; // don't modify selection, only show a context menu else return QTreeView::selectionCommand( index, event ); } void BookmarkListView::contextMenuEvent ( QContextMenuEvent * e ) { QModelIndex index = indexAt(e->pos()); KBookmark bk; if(index.isValid()) bk = static_cast(index.internalPointer())->bookmark(); QMenu* popup; if( !index.isValid() || (bk.address() == CurrentMgr::self()->root().address()) || (bk.isGroup())) //FIXME add empty folder padder { popup = KEBApp::self()->popupMenuFactory("popup_folder"); } else { popup = KEBApp::self()->popupMenuFactory("popup_bookmark"); } if (popup) popup->popup(e->globalPos()); } void BookmarkListView::drawRow ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { QStyleOptionViewItem opt = option; if(parentSelected(index)) { int base_h, base_s, base_v; opt.palette.base().color().getHsv(&base_h, &base_s, &base_v); int hilite_h, hilite_s, hilite_v; opt.palette.highlight().color().getHsv(&hilite_h, &hilite_s, &hilite_v); QColor col; col.setHsv(hilite_h, (hilite_s + base_s + base_s ) / 3, (hilite_v + base_v + base_v ) / 3); opt.palette.setBrush(QPalette::Base, QBrush( col ) ); } QTreeView::drawRow( painter, opt, index ); } bool BookmarkListView::parentSelected(const QModelIndex & idx ) const { QModelIndex index = idx.parent(); while(index.isValid()) { QModelIndex parent = index.parent(); if(selectionModel()->isRowSelected(index.row(), parent) && parent.isValid() ) return true; else index = index.parent(); } return false; } //FIXME clean up and remove unneeded things SelcAbilities BookmarkListView::getSelectionAbilities() const { if(dirtyGetSelectionAbilies) { const QModelIndexList & sel = selectionModel()->selectedIndexes(); selctionAbilities.itemSelected = false; selctionAbilities.group = false; selctionAbilities.separator = false; selctionAbilities.urlIsEmpty = false; selctionAbilities.root = false; selctionAbilities.multiSelect = false; selctionAbilities.singleSelect = false; selctionAbilities.notEmpty = false; if ( sel .count() > 0) { KBookmark nbk = static_cast((*sel.constBegin()).internalPointer())->bookmark(); selctionAbilities.itemSelected = true; selctionAbilities.group = nbk.isGroup(); selctionAbilities.separator = nbk.isSeparator(); selctionAbilities.urlIsEmpty = nbk.url().isEmpty(); selctionAbilities.root = nbk.address() == CurrentMgr::self()->root().address(); selctionAbilities.multiSelect = (sel.count() > BookmarkModel::self()->columnCount()); selctionAbilities.singleSelect = (!selctionAbilities.multiSelect && selctionAbilities.itemSelected); } //FIXME check next line, if it actually works selctionAbilities.notEmpty = CurrentMgr::self()->root().first().hasParent(); //FIXME that's insane, checks wheter there exists at least one bookmark // kdDebug()<<"sa.itemSelected "<resizeSection(KEBApp::NameColumn, KEBSettings::name()); header()->resizeSection(KEBApp::UrlColumn, KEBSettings::uRL()); header()->resizeSection(KEBApp::CommentColumn, KEBSettings::comment()); header()->resizeSection(KEBApp::StatusColumn, KEBSettings::status()); } void BookmarkListView::saveColumnSetting() { KEBSettings::setName( header()->sectionSize(KEBApp::NameColumn)); KEBSettings::setURL( header()->sectionSize(KEBApp::UrlColumn)); KEBSettings::setComment( header()->sectionSize(KEBApp::CommentColumn)); KEBSettings::setStatus( header()->sectionSize(KEBApp::StatusColumn)); KEBSettings::writeConfig(); } diff --git a/keditbookmarks/bookmarkmodel.cpp b/keditbookmarks/bookmarkmodel.cpp index 736daf5ed..51ed2fd90 100644 --- a/keditbookmarks/bookmarkmodel.cpp +++ b/keditbookmarks/bookmarkmodel.cpp @@ -1,206 +1,209 @@ /* This file is part of the KDE project Copyright (C) 2005 Daniel Teske 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., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "bookmarkmodel.h" #include "toplevel.h" #include "commands.h" #include #include #include #include #include #include #include #include int BookmarkModel::count = 0; BookmarkModel* BookmarkModel::s_bookmarkModel = 0L; +BookmarkModel* BookmarkModel::self() +{ + if(!s_bookmarkModel) + s_bookmarkModel = new BookmarkModel(CurrentMgr::self()->root()); + return s_bookmarkModel; +} + +BookmarkModel::BookmarkModel(KBookmark root) + :QAbstractItemModel(), mRoot(root) +{ + rootItem = new TreeItem(root, 0); +} + +BookmarkModel::~BookmarkModel() +{ + delete rootItem; +} + void BookmarkModel::resetModel() { + delete rootItem; reset(); + rootItem = new TreeItem(mRoot, 0); } QVariant BookmarkModel::data(const QModelIndex &index, int role) const { //Text if(index.isValid() && (role == Qt::DisplayRole || role == Qt::EditRole)) { KBookmark bk = static_cast(index.internalPointer())->bookmark(); if(bk.address() == "") if(index.column() == 0) return QVariant( i18n("Bookmarks") ); else return QVariant(); switch( index.column() ) { case 0: return QVariant( bk.fullText() ); case 1: return QVariant( bk.url().pathOrURL() ); case 2: return QVariant( EditCommand::getNodeText(bk, QStringList() << QString("desc")) ); case 3: return QVariant( QString() ); //FIXME status column default: return QVariant( QString() ); //can't happen } } //Icon if(index.isValid() && role == Qt::DecorationRole && index.column() == 0) { KBookmark bk = static_cast(index.internalPointer())->bookmark(); if(bk.address() == "") return QVariant( QIcon(SmallIcon("bookmark"))); return QVariant( QIcon(SmallIcon(bk.icon()))); } return QVariant(); } //FIXME QModelIndex BookmarkModel::buddy(const QModelIndex & index) //return parent for empty folder padders Qt::ItemFlags BookmarkModel::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::ItemIsEnabled; KBookmark bk = static_cast(index.internalPointer())->bookmark(); if( bk.address() != "" ) { if( bk.isGroup()) { if(index.column() == 0 || index.column() == 2) return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; } else if(index.column() < 3) return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; } return Qt::ItemIsEnabled | Qt::ItemIsSelectable; } bool BookmarkModel::setData(const QModelIndex &index, const QVariant &value, int role) { if(index.isValid() && role == Qt::EditRole) { //FIXME don't create a commmand if still the same // and ignore if name column and empty QString addr = static_cast(index.internalPointer())->bookmark().address(); CmdHistory::self()->addCommand(new EditCommand( addr, index.column(), value.toString()) ); return true; } return false; } QVariant BookmarkModel::headerData(int section, Qt::Orientation orientation, int role) const { if(role == Qt::DisplayRole && orientation == Qt::Horizontal) { switch(section) { case 0: return i18n("Bookmark"); case 1: return i18n("URL"); case 2: return i18n("Comment"); case 3: return i18n("Status"); default: return QString(); // Can't happpen } } else return QVariant(); } QModelIndex BookmarkModel::index(int row, int column, const QModelIndex &parent) const { if( ! parent.isValid()) return createIndex(row, column, rootItem); TreeItem * item = static_cast(parent.internalPointer()); return createIndex(row, column, item->child(row)); } QModelIndex BookmarkModel::parent(const QModelIndex &index) const { KBookmark bk = static_cast(index.internalPointer())->bookmark(); if(bk.address() == mRoot.address()) return QModelIndex(); KBookmarkGroup parent = bk.parentGroup(); TreeItem * item = static_cast(index.internalPointer()); if(parent.address() != mRoot.address()) return createIndex( KBookmark::positionInParent(parent.address()) , 0, item->parent()); else //parent is root return createIndex( 0, 0, item->parent()); } int BookmarkModel::rowCount(const QModelIndex &parent) const { if(parent.isValid()) - { - KBookmark bk = static_cast(parent.internalPointer())->bookmark(); - return childCount(bk); - } + return static_cast(parent.internalPointer())->childCount(); else //root case { return 1; } } int BookmarkModel::columnCount(const QModelIndex &) const { return 4; } QModelIndex BookmarkModel::bookmarkToIndex(KBookmark bk) { return createIndex( KBookmark::positionInParent(bk.address()), 0, rootItem->treeItemForBookmark(bk)); } -int BookmarkModel::childCount(KBookmark bk) -{ - if(!bk.isGroup()) - return 0; - KBookmark child = bk.toGroup().first(); - int i = 0; - while(child.hasParent()) - { - ++i; - child = bk.toGroup().next(child); - } - return i; -} - void BookmarkModel::emitDataChanged(KBookmark bk) { QModelIndex index = bookmarkToIndex(bk); emit dataChanged(index, index ); } #include "bookmarkmodel.moc" diff --git a/keditbookmarks/bookmarkmodel.h b/keditbookmarks/bookmarkmodel.h index ada9065fc..6da0f3349 100644 --- a/keditbookmarks/bookmarkmodel.h +++ b/keditbookmarks/bookmarkmodel.h @@ -1,128 +1,123 @@ /* This file is part of the KDE project Copyright (C) 2005 Daniel Teske 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., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __bookmarkmodel_h #define __bookmarkmodel_h #include #include #include #include #include #include "toplevel.h" #include "treeitem.h" #include "commands.h" #include #include class BookmarkModel : public QAbstractItemModel { Q_OBJECT public: class insertSentry; friend class insertSentry; class removeSentry; friend class removeSentry; friend class IKEBCommand; - - static BookmarkModel* self() { if(!s_bookmarkModel) s_bookmarkModel = new BookmarkModel(CurrentMgr::self()->root()); return s_bookmarkModel; } - virtual ~BookmarkModel() {} + static BookmarkModel* self(); + virtual ~BookmarkModel(); QVariant data(const QModelIndex &index, int role) const; Qt::ItemFlags flags(const QModelIndex &index) const; QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const; virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; virtual QModelIndex parent(const QModelIndex &index) const; virtual bool setData(const QModelIndex &index, const QVariant &value, int role); int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; QModelIndex bookmarkToIndex(KBookmark bk); - static int BookmarkModel::childCount(KBookmark bk); void emitDataChanged(KBookmark bk); void resetModel(); private: TreeItem * rootItem; - BookmarkModel(KBookmark root) - :QAbstractItemModel(), mRoot(root) - { rootItem = new TreeItem(root, 0); } + BookmarkModel(KBookmark root); static BookmarkModel *s_bookmarkModel; static int count; KBookmark mRoot; - // mutable QList mapIdToAddr; //Sentry public: class insertSentry { public: insertSentry(KBookmark parent, int first, int last) { QModelIndex mParent = BookmarkModel::self()->bookmarkToIndex(parent); BookmarkModel::self()->beginInsertRows( mParent, first, last); mt = static_cast(mParent.internalPointer()); mf = first; ml = last; } ~insertSentry() { mt->insertChildren(mf, ml); BookmarkModel::self()->endInsertRows(); } private: TreeItem * mt; int mf, ml; }; class removeSentry { public: removeSentry(KBookmark parent, int first, int last) { QModelIndex mParent = BookmarkModel::self()->bookmarkToIndex(parent); //FIXME remove this once Qt fixes their really stupid bugs for(int i = first; i <= last; ++i) { KEBApp::self()->mBookmarkListView->selectionModel()->select(mParent.child(i, 0), QItemSelectionModel::Deselect); } BookmarkModel::self()->beginRemoveRows( mParent, first, last); mt = static_cast(mParent.internalPointer()); mf = first; ml = last; } ~removeSentry() { mt->deleteChildren(mf, ml); BookmarkModel::self()->endRemoveRows(); } private: TreeItem * mt; int mf, ml; }; }; #endif diff --git a/keditbookmarks/toplevel.cpp b/keditbookmarks/toplevel.cpp index 34400612e..69504ae3f 100644 --- a/keditbookmarks/toplevel.cpp +++ b/keditbookmarks/toplevel.cpp @@ -1,513 +1,516 @@ // -*- indent-tabs-mode:nil -*- // vim: set ts=4 sts=4 sw=4 et: /* This file is part of the KDE project Copyright (C) 2000 David Faure Copyright (C) 2002-2003 Alexander Kellett 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., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "toplevel.h" #include "bookmarkmodel.h" #include "bookmarkinfo.h" #include "listview.h" #include "actionsimpl.h" #include "dcop.h" #include "exporters.h" #include "settings.h" #include "commands.h" #include "kebsearchline.h" #include "bookmarklistview.h" #include #include #include #include #include //Added by qt3to4: #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include CmdHistory* CmdHistory::s_self = 0; CmdHistory::CmdHistory(KActionCollection *collection) : m_commandHistory(collection) { connect(&m_commandHistory, SIGNAL( commandExecuted(KCommand *) ), SLOT( slotCommandExecuted(KCommand *) )); assert(!s_self); s_self = this; // this is hacky } CmdHistory* CmdHistory::self() { assert(s_self); return s_self; } void CmdHistory::slotCommandExecuted(KCommand *k) { KEBApp::self()->notifyCommandExecuted(); IKEBCommand * cmd = dynamic_cast(k); Q_ASSERT(cmd); KBookmark bk = CurrentMgr::bookmarkAt(cmd->affectedBookmarks()); Q_ASSERT(bk.isGroup()); CurrentMgr::self()->notifyManagers(bk.toGroup()); } void CmdHistory::notifyDocSaved() { m_commandHistory.documentSaved(); } void CmdHistory::didCommand(KCommand *cmd) { if (!cmd) return; m_commandHistory.addCommand(cmd, false); CmdHistory::slotCommandExecuted(cmd); } void CmdHistory::addCommand(KCommand *cmd) { if (!cmd) return; m_commandHistory.addCommand(cmd); } void CmdHistory::addInFlightCommand(KCommand *cmd) { if(!cmd) return; m_commandHistory.addCommand(cmd, false); } void CmdHistory::clearHistory() { m_commandHistory.clear(); } /* -------------------------- */ CurrentMgr *CurrentMgr::s_mgr = 0; KBookmarkGroup CurrentMgr::root() { return mgr()->root(); } KBookmark CurrentMgr::bookmarkAt(const QString &a) { return self()->mgr()->findByAddress(a); } bool CurrentMgr::managerSave() { return mgr()->save(); } void CurrentMgr::saveAs(const QString &fileName) { mgr()->saveAs(fileName); } void CurrentMgr::setUpdate(bool update) { mgr()->setUpdate(update); } QString CurrentMgr::path() const { return mgr()->path(); } bool CurrentMgr::showNSBookmarks() const { return mgr()->showNSBookmarks(); } void CurrentMgr::createManager(const QString &filename) { if (m_mgr) { kdDebug()<<"ERROR calling createManager twice"< 0) //We ignore the first changed signal after every change we did { --ignorenext; return; } CmdHistory::self()->clearHistory(); KEBApp::self()->updateActions(); } void CurrentMgr::notifyManagers(KBookmarkGroup grp) { ++ignorenext; mgr()->emitChanged(grp); } void CurrentMgr::notifyManagers() { notifyManagers( root() ); } void CurrentMgr::reloadConfig() { mgr()->emitConfigChanged(); } QString CurrentMgr::makeTimeStr(const QString & in) { int secs; bool ok; secs = in.toInt(&ok); if (!ok) return QString::null; return makeTimeStr(secs); } QString CurrentMgr::makeTimeStr(int b) { QDateTime dt; dt.setTime_t(b); return (dt.daysTo(QDateTime::currentDateTime()) > 31) ? KGlobal::locale()->formatDate(dt.date(), false) : KGlobal::locale()->formatDateTime(dt, false); } /* -------------------------- */ KEBApp *KEBApp::s_topLevel = 0; KEBApp::KEBApp( const QString &bookmarksFile, bool readonly, const QString &address, bool browser, const QString &caption ) : KMainWindow(), m_dcopIface(0), m_bookmarksFilename(bookmarksFile), m_caption(caption), m_readOnly(readonly), m_browser(browser) { m_cmdHistory = new CmdHistory(actionCollection()); s_topLevel = this; QSplitter *vsplitter = new QSplitter(this); - KToolBar *quicksearch = new KToolBar(vsplitter, "search toolbar"); - KAction *resetQuickSearch = new KAction( i18n( "Reset Quick Search" ), - QApplication::reverseLayout() ? "clear_left" : "locationbar_erase", - 0, actionCollection(), "reset_quicksearch" ); - resetQuickSearch->setWhatsThis( i18n( "Reset Quick Search
" - "Resets the quick search so that all bookmarks are shown again." ) ); - resetQuickSearch->plug( quicksearch ); - - QLabel *lbl = new QLabel(i18n("Se&arch:"), quicksearch, "kde toolbar widget"); - - KListViewSearchLine *searchLineEdit = new KEBSearchLine(quicksearch, 0, "KListViewSearchLine"); - quicksearch->setStretchableWidget(searchLineEdit); - lbl->setBuddy(searchLineEdit); - connect(resetQuickSearch, SIGNAL(activated()), searchLineEdit, SLOT(clear())); - - //FIXME searchLineEdit->setListView(static_cast(ListView::self()->widget())); +//FIXME +// KToolBar *quicksearch = new KToolBar(vsplitter, "search toolbar"); +// +// KAction *resetQuickSearch = new KAction( i18n( "Reset Quick Search" ), +// QApplication::reverseLayout() ? "clear_left" : "locationbar_erase", +// 0, actionCollection(), "reset_quicksearch" ); +// resetQuickSearch->setWhatsThis( i18n( "Reset Quick Search
" +// "Resets the quick search so that all bookmarks are shown again." ) ); +// resetQuickSearch->plug( quicksearch ); +// +// QLabel *lbl = new QLabel(i18n("Se&arch:"), quicksearch, "kde toolbar widget"); + + //K4ListViewSearchLine *searchLineEdit = new K4ListViewSearchLine(/*quicksearch*/ vsplitter, 0, "KListViewSearchLine"); + //quicksearch->setStretchableWidget(searchLineEdit); + //lbl->setBuddy(searchLineEdit); + //connect(resetQuickSearch, SIGNAL(activated()), searchLineEdit, SLOT(clear())); createActions(); if (m_browser) createGUI(); else createGUI("keditbookmarks-genui.rc"); m_dcopIface = new KBookmarkEditorIface(); connect(kapp->clipboard(), SIGNAL( dataChanged() ), SLOT( slotClipboardDataChanged() )); KGlobal::locale()->insertCatalogue("libkonq"); m_canPaste = false; CurrentMgr::self()->createManager(m_bookmarksFilename); //QT 4 new code mBookmarkListView = new BookmarkListView(vsplitter); mBookmarkListView->setModel( BookmarkModel::self() ); + + //searchLineEdit->setTreeView(mBookmarkListView); mBookmarkListView->setSelectionMode(QAbstractItemView::ExtendedSelection); expandAll(); mBookmarkListView->loadColumnSetting(); m_bkinfo = new BookmarkInfoWidget(vsplitter); vsplitter->setOrientation(Qt::Vertical); //FIXME set sensible sizes for vsplitter? setCentralWidget(vsplitter); slotClipboardDataChanged(); setAutoSaveSettings(); connect(mBookmarkListView->selectionModel(), SIGNAL(selectionChanged( const QItemSelection &, const QItemSelection & )), this, SLOT(selectionChanged())); setCancelFavIconUpdatesEnabled(false); setCancelTestsEnabled(false); updateActions(); } void KEBApp::reset(const QString & caption, const QString & bookmarksFileName) { m_caption = caption; m_bookmarksFilename = bookmarksFileName; CurrentMgr::self()->createManager(m_bookmarksFilename); //FIXME this is still a memory leak (iff called by slotLoad) BookmarkModel::self()->resetModel(); expandAll(); updateActions(); } void KEBApp::collapseAll() { collapseAllHelper( BookmarkModel::self()->index(0, 0, QModelIndex())); } void KEBApp::collapseAllHelper( QModelIndex index ) { mBookmarkListView->collapse(index); int rowCount = index.model()->rowCount(index); for(int i=0; iindex(0, 0, QModelIndex())); } void KEBApp::expandAllHelper(QModelIndex index) { mBookmarkListView->expand(index); int rowCount = index.model()->rowCount(index); for(int i=0; iselectionModel()->selectedIndexes(); - QModelIndexList::const_iterator it; - it = list.begin(); - if( (*it).column() == int(c) && (BookmarkModel::self()->flags(*it) & Qt::ItemIsEditable) ) - return mBookmarkListView->edit( *it ); + QModelIndexList::const_iterator it, end; + end = list.constEnd(); + for(it = list.constBegin(); it != end; ++it) + if( (*it).column() == int(c) && (BookmarkModel::self()->flags(*it) & Qt::ItemIsEditable) ) + return mBookmarkListView->edit( *it ); } KBookmark KEBApp::firstSelected() const { const QModelIndexList & list = mBookmarkListView->selectionModel()->selectedIndexes(); QModelIndex index = *list.constBegin(); return static_cast(index.internalPointer())->bookmark(); } QString KEBApp::insertAddress() const { KBookmark current = firstSelected(); return (current.isGroup()) ? (current.address() + "/0") //FIXME internal represantation used : KBookmark::nextAddress(current.address()); } bool lessAddress(QString a, QString b) { if(a == b) return false; QString error("ERROR"); if(a == error) return false; if(b == error) return true; a += "/"; b += "/"; uint aLast = 0; uint bLast = 0; uint aEnd = a.length(); uint bEnd = b.length(); // Each iteration checks one "/"-delimeted part of the address // "" is treated correctly while(true) { // Invariant: a[0 ... aLast] == b[0 ... bLast] if(aLast + 1 == aEnd) //The last position was the last slash return true; // That means a is shorter than b if(bLast +1 == bEnd) return false; uint aNext = a.find("/", aLast + 1); uint bNext = b.find("/", bLast + 1); bool okay; uint aNum = a.mid(aLast + 1, aNext - aLast - 1).toUInt(&okay); if(!okay) return false; uint bNum = b.mid(bLast + 1, bNext - bLast - 1).toUInt(&okay); if(!okay) return true; if(aNum != bNum) return aNum < bNum; aLast = aNext; bLast = bNext; } } bool lessBookmark(const KBookmark & first, const KBookmark & second) //FIXME Using internal represantation { return lessAddress(first.address(), second.address()); } QVector KEBApp::selectedBookmarks() const { QVector bookmarks; const QModelIndexList & list = mBookmarkListView->selectionModel()->selectedIndexes(); bookmarks.reserve(list.count()); QModelIndexList::const_iterator it, end; end = list.constEnd(); for( it = list.constBegin(); it != end; ++it) { if((*it).column() != 0) continue; KBookmark bk = static_cast((*it).internalPointer())->bookmark();; if(bk.address() != CurrentMgr::self()->root().address()) bookmarks.push_back( bk ); } qSort(bookmarks.begin(), bookmarks.end(), lessBookmark); return bookmarks; } QVector KEBApp::selectedBookmarksExpanded() const { QVector bookmarks = selectedBookmarks(); QVector result; result.reserve(bookmarks.size()); // at least QVector::const_iterator it, end; end = bookmarks.constEnd(); for(it = bookmarks.constBegin(); it != end; ++it) { selectedBookmarksExpandedHelper( *it, result ); } return result; } void KEBApp::selectedBookmarksExpandedHelper(KBookmark bk, QVector & bookmarks) const { bookmarks.push_back( bk ); if(bk.isGroup()) { KBookmarkGroup parent = bk.toGroup(); KBookmark child = parent.first(); while(child.hasParent()) { selectedBookmarksExpandedHelper(child, bookmarks); child = parent.next(child); } } } void KEBApp::updateStatus(QString url) { if(m_bkinfo->bookmark().url() == url) m_bkinfo->updateStatus(); } KEBApp::~KEBApp() { s_topLevel = 0; delete m_cmdHistory; delete m_dcopIface; delete ActionsImpl::self(); delete mBookmarkListView; delete BookmarkModel::self(); } KToggleAction* KEBApp::getToggleAction(const char *action) const { return static_cast(actionCollection()->action(action)); } void KEBApp::resetActions() { stateChanged("disablestuff"); stateChanged("normal"); if (!m_readOnly) stateChanged("notreadonly"); getToggleAction("settings_showNS") ->setChecked(CurrentMgr::self()->showNSBookmarks()); } bool KEBApp::nsShown() const { return getToggleAction("settings_showNS")->isChecked(); } void KEBApp::selectionChanged() { updateActions(); } void KEBApp::updateActions() { resetActions(); setActionsEnabled(mBookmarkListView->getSelectionAbilities()); } void KEBApp::slotClipboardDataChanged() { // kdDebug() << "KEBApp::slotClipboardDataChanged" << endl; if (!m_readOnly) { m_canPaste = KBookmarkDrag::canDecode( kapp->clipboard()->data(QClipboard::Clipboard)); updateActions(); } } /* -------------------------- */ void KEBApp::notifyCommandExecuted() { // kdDebug() << "KEBApp::notifyCommandExecuted()" << endl; updateActions(); } /* -------------------------- */ void KEBApp::slotConfigureToolbars() { saveMainWindowSettings(KGlobal::config(), "MainWindow"); KEditToolbar dlg(actionCollection()); connect(&dlg, SIGNAL( newToolbarConfig() ), SLOT( slotNewToolbarConfig() )); dlg.exec(); } void KEBApp::slotNewToolbarConfig() { // called when OK or Apply is clicked createGUI(); applyMainWindowSettings(KGlobal::config(), "MainWindow"); } /* -------------------------- */ #include "toplevel.moc" diff --git a/keditbookmarks/treeitem.cpp b/keditbookmarks/treeitem.cpp index 4b8d79f35..e91cb3970 100644 --- a/keditbookmarks/treeitem.cpp +++ b/keditbookmarks/treeitem.cpp @@ -1,157 +1,160 @@ /* This file is part of the KDE project Copyright (C) 2005 Daniel Teske 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., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "treeitem.h" #include -#define DEBUG_STUPID_QT - TreeItem::TreeItem(KBookmark bk, TreeItem * parent) : mparent(parent), mbk(bk) { init = false; #ifdef DEBUG_STUPID_QT deleted = false; #endif } TreeItem::~TreeItem() { -#ifndef DEBUG_STUPID_QT qDeleteAll(children); -#else - QList::iterator it, end; - for(it = children.begin(); it != end; ++it) - { - (*it)->markDelete(); - } -#endif children.clear(); } TreeItem * TreeItem::child(int row) { #ifdef DEBUG_STUPID_QT if(deleted) kdFatal()<<"child for deleted "<::iterator it, end; + end = children.end(); + for(it = children.begin(); it != end; ++it) + { + (*it)->markDelete(); + } } #endif void TreeItem::insertChildren(int first, int last) { // Find child number last KBookmarkGroup parent = bookmark().toGroup(); KBookmark child = parent.first(); for(int i=0; i < last; ++i) child = parent.next(child); //insert children int i = last; do { children.insert(i, new TreeItem(child, this)); child = parent.previous(child); --i; } while(i >= first); } void TreeItem::deleteChildren(int first, int last) { kdDebug()<<"deleteChildren of "<::iterator firstIt, lastIt, it; firstIt = children.begin() + first; lastIt = children.begin() + last + 1; for( it = firstIt; it != lastIt; ++it) { kdDebug()<<"removing child "<<(*it)->bookmark().address()<markDelete(); #endif } children.erase(firstIt, lastIt); } KBookmark TreeItem::bookmark() { #ifdef DEBUG_STUPID_QT if(deleted) kdFatal()<<"child for deleted "<::const_iterator it, end; end = children.constEnd(); for( it = children.constBegin(); it != end; ++it) { KBookmark child = (*it)->bookmark(); if( KBookmark::commonParent(child.address(), bk.address()) == child.address()) return (*it)->treeItemForBookmark(bk); } return 0; } else { if(parent() == 0) return 0; return parent()->treeItemForBookmark(bk); } } diff --git a/keditbookmarks/treeitem.h b/keditbookmarks/treeitem.h index aa2b05abe..ad8e39306 100644 --- a/keditbookmarks/treeitem.h +++ b/keditbookmarks/treeitem.h @@ -1,50 +1,51 @@ /* This file is part of the KDE project Copyright (C) 2005 Daniel Teske 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., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef __treeitem_h #define __treeitem_h #include #include -#define DEBUG_STUPID_QT +//#define DEBUG_STUPID_QT class TreeItem { public: TreeItem(KBookmark bk, TreeItem * parent); ~TreeItem(); TreeItem * child(int row); TreeItem * parent(); void insertChildren(int first, int last); void deleteChildren(int first, int last); KBookmark bookmark(); + int childCount(); TreeItem * treeItemForBookmark(KBookmark bk); private: #ifdef DEBUG_STUPID_QT void markDelete(); bool deleted; #endif void initChildren(); bool init; QList children; TreeItem * mparent; KBookmark mbk; }; #endif