void BookmarksSettingsPage::slotEditButtonClicked() { QListViewItem* item = m_listView->selectedItem(); assert(item != 0); // 'edit' may not get invoked when having no items KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Edit Bookmark"), item->text(NameIdx), KURL(item->text(URLIdx)), item->text(IconIdx)); if (!bookmark.isNull()) { item->setPixmap(PixmapIdx, SmallIcon(bookmark.icon())); item->setText(NameIdx, bookmark.text()); item->setText(URLIdx, bookmark.url().prettyURL()); item->setText(IconIdx, bookmark.icon()); } }
KBookmarkActionMenu::KBookmarkActionMenu(const KBookmark &bm, QObject *parent) : KActionMenu(QIcon::fromTheme(bm.icon()), bm.text().replace('&', QLatin1String("&&")), parent), KBookmarkActionInterface(bm) { setToolTip(bm.description()); setIconText(text()); }
void BookmarkToolBar::startDrag() { KBookmarkActionInterface *action = dynamic_cast<KBookmarkActionInterface *>(m_dragAction); if (action) { QMimeData *mimeData = new QMimeData; KBookmark bookmark = action->bookmark(); QByteArray address = bookmark.address().toLatin1(); mimeData->setData(BookmarkManager::bookmark_mime_type(), address); bookmark.populateMimeData(mimeData); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); if (bookmark.isGroup()) { drag->setPixmap(KIcon(bookmark.icon()).pixmap(24, 24)); } else { drag->setPixmap(IconManager::self()->iconForUrl(action->bookmark().url()).pixmap(24, 24)); } drag->start(Qt::MoveAction); connect(drag, SIGNAL(destroyed()), this, SLOT(dragDestroyed())); } }
bool ClearFaviconsAction::action() { QDir favIconDir(KGlobal::dirs()->saveLocation( "cache", QLatin1String( "favicons/" ) )); QStringList saveTheseFavicons; KBookmarkManager* konqiBookmarkMgr; konqiBookmarkMgr = KBookmarkManager::managerForFile(KStandardDirs::locateLocal("data", QLatin1String("konqueror/bookmarks.xml")), QLatin1String( "konqueror" )); kDebug() << "saving the favicons that are in konqueror bookmarks" ; kDebug() << "opened konqueror bookmarks at " << konqiBookmarkMgr->path() ; // get the entire slew of bookmarks KBookmarkGroup konqiBookmarks = konqiBookmarkMgr->root(); // walk through the bookmarks, if they have a favicon we should keep it KBookmark bookmark = konqiBookmarks.first(); while (!bookmark.isNull()) { if ((bookmark.icon()).startsWith(QLatin1String("favicons/"))) { // pick out the name, throw .png on the end, and store the filename QRegExp regex(QLatin1String( "favicons/(.*)" )); regex.indexIn(bookmark.icon(), 0); kDebug() << "will save " << (regex.cap(1) + QLatin1String( ".png" )) ; saveTheseFavicons << (regex.cap(1) + QLatin1String( ".png" )); } bookmark = konqiBookmarks.next(bookmark); } favIconDir.setFilter( QDir::Files ); const QStringList entries = favIconDir.entryList(); // erase all files in favicon directory... for( QStringList::const_iterator it = entries.begin() ; it != entries.end() ; ++it) { // ...if we're not supposed to save them, of course if (!saveTheseFavicons.contains(*it)) { kDebug() << "removing " << *it ; if(!favIconDir.remove(*it)) { errMsg = i18n("A favicon could not be removed."); return false; } } } return true; }
void DeleteCommand::redo() { KBookmark bk = m_model->bookmarkManager()->findByAddress(m_from); Q_ASSERT(!bk.isNull()); if (m_contentOnly) { QDomElement groupRoot = bk.internalElement(); QDomNode n = groupRoot.firstChild(); while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) { // kDebug() << e.tagName(); } QDomNode next = n.nextSibling(); groupRoot.removeChild(n); n = next; } return; } // TODO - bug - unparsed xml is lost after undo, // we must store it all therefore //FIXME this removes the comments, that's bad! if (!m_cmd) { if (bk.isGroup()) { m_cmd = new CreateCommand(m_model, m_from, bk.fullText(), bk.icon(), bk.internalElement().attribute("folded") == "no"); m_subCmd = deleteAll(m_model, bk.toGroup()); m_subCmd->redo(); } else { m_cmd = (bk.isSeparator()) ? new CreateCommand(m_model, m_from) : new CreateCommand(m_model, m_from, bk.fullText(), bk.icon(), bk.url()); } } m_cmd->undo(); }
void BookmarksSettingsPage::slotAddButtonClicked() { KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add Bookmark"), i18n("New bookmark"), KURL(), "bookmark"); if (!bookmark.isNull()) { // insert bookmark into listview QListViewItem* item = new QListViewItem(m_listView); item->setPixmap(PixmapIdx, SmallIcon(bookmark.icon())); item->setText(NameIdx, bookmark.text()); item->setText(URLIdx, bookmark.url().prettyURL()); item->setText(IconIdx, bookmark.icon()); m_listView->insertItem(item); QListViewItem* lastItem = m_listView->lastChild(); if (lastItem != 0) { item->moveItem(lastItem); } m_listView->setSelected(item, true); updateButtons(); } }
void EditCommand::redo() { KBookmark bk = m_model->bookmarkManager()->findByAddress(mAddress); if(mCol==-2) { if (mOldValue.isEmpty()) mOldValue = bk.internalElement().attribute("toolbar"); bk.internalElement().setAttribute("toolbar", mNewValue); } else if(mCol==-1) { if (mOldValue.isEmpty()) mOldValue = bk.icon(); bk.setIcon(mNewValue); } else if(mCol==0) { if (mOldValue.isEmpty()) // only the first time, not when compressing changes in modify() mOldValue = bk.fullText(); kDebug() << "mOldValue=" << mOldValue; bk.setFullText(mNewValue); } else if(mCol==1) { if (mOldValue.isEmpty()) mOldValue = bk.url().prettyUrl(); const KUrl newUrl(mNewValue); if (!(newUrl.isEmpty() && !mNewValue.isEmpty())) // prevent emptied line if the currently entered url is invalid bk.setUrl(newUrl); } else if(mCol==2) { if (mOldValue.isEmpty()) mOldValue = bk.description(); bk.setDescription(mNewValue); } m_model->emitDataChanged(bk); }
BookmarksSettingsPage::BookmarksSettingsPage(QWidget*parent) : SettingsPageBase(parent), m_addButton(0), m_removeButton(0), m_moveUpButton(0), m_moveDownButton(0) { QVBoxLayout* topLayout = new QVBoxLayout(parent, 2, KDialog::spacingHint()); const int spacing = KDialog::spacingHint(); QHBox* hBox = new QHBox(parent); hBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); hBox->setSpacing(spacing); hBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored); m_listView = new KListView(hBox); m_listView->addColumn(i18n("Icon")); m_listView->addColumn(i18n("Name")); m_listView->addColumn(i18n("Location")); m_listView->setResizeMode(QListView::LastColumn); m_listView->setColumnAlignment(0, Qt::AlignHCenter); m_listView->setAllColumnsShowFocus(true); m_listView->setSorting(-1); connect(m_listView, SIGNAL(selectionChanged()), this, SLOT(updateButtons())); connect(m_listView, SIGNAL(pressed(QListViewItem*)), this, SLOT(slotBookmarkPressed(QListViewItem*))); connect(m_listView, SIGNAL(doubleClicked(QListViewItem*, const QPoint&, int)), this, SLOT(slotBookmarkDoubleClicked(QListViewItem*, const QPoint&, int))); QVBox* buttonBox = new QVBox(hBox); buttonBox->setSpacing(spacing); const QSizePolicy buttonSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum); m_addButton = new KPushButton(i18n("Add..."), buttonBox); connect(m_addButton, SIGNAL(clicked()), this, SLOT(slotAddButtonClicked())); m_addButton->setSizePolicy(buttonSizePolicy); m_editButton = new KPushButton(i18n("Edit..."), buttonBox); connect(m_editButton, SIGNAL(clicked()), this, SLOT(slotEditButtonClicked())); m_editButton->setSizePolicy(buttonSizePolicy); m_removeButton = new KPushButton(i18n("Remove"), buttonBox); connect(m_removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveButtonClicked())); m_removeButton->setSizePolicy(buttonSizePolicy); m_moveUpButton = new KPushButton(i18n("Move Up"), buttonBox); connect(m_moveUpButton, SIGNAL(clicked()), this, SLOT(slotMoveUpButtonClicked())); m_moveUpButton->setSizePolicy(buttonSizePolicy); m_moveDownButton = new KPushButton(i18n("Move Down"), buttonBox); connect(m_moveDownButton, SIGNAL(clicked()), this, SLOT(slotMoveDownButtonClicked())); m_moveDownButton->setSizePolicy(buttonSizePolicy); // Add a dummy widget with no restriction regarding a vertical resizing. // This assures that the spacing between the buttons is not increased. new QWidget(buttonBox); topLayout->addWidget(hBox); // insert all editable bookmarks. KBookmarkGroup root = DolphinSettings::instance().bookmarkManager()->root(); KBookmark bookmark = root.first(); QListViewItem* prev = 0; while (!bookmark.isNull()) { QListViewItem* item = new QListViewItem(m_listView); item->setPixmap(PixmapIdx, SmallIcon(bookmark.icon())); item->setText(NameIdx, bookmark.text()); item->setText(URLIdx, bookmark.url().prettyURL()); // add hidden column to be able to retrieve the icon name again item->setText(IconIdx, bookmark.icon()); m_listView->insertItem(item); if (prev != 0) { item->moveItem(prev); } prev = item; bookmark = root.next(bookmark); } m_listView->setSelected(m_listView->firstChild(), true); updateButtons(); }
void BookmarksProtocol::echoBookmark( const KBookmark &bm) { QString descriptionAsTitle = bm.description().toHtmlEscaped(); if (!descriptionAsTitle.isEmpty()) descriptionAsTitle.prepend(QLatin1String("\" title=\"")); echo ("<li class=\"link\"><a href=\"" + bm.url().url() + descriptionAsTitle + "\"><img src=\"/icon/" + bm.icon() + "\"/>" + bm.text().toHtmlEscaped() + "</a></li>"); }
KonqSidebarBookmarkItem::KonqSidebarBookmarkItem( KonqSidebarTreeItem *parentItem, KonqSidebarTreeTopLevelItem *topLevelItem, const KBookmark & bk, int key ) : KonqSidebarTreeItem( parentItem, topLevelItem ), m_bk(bk), m_key(key) { setText( 0, bk.text() ); setPixmap( 0, SmallIcon(bk.icon()) ); }
void BookmarksSidebarPage::slotContextMenuRequested(QListBoxItem* item, const QPoint& pos) { const int insertID = 1; const int editID = 2; const int deleteID = 3; const int addID = 4; QPopupMenu* popup = new QPopupMenu(); if (item == 0) { popup->insertItem(SmallIcon("filenew"), i18n("Add Bookmark..."), addID); } else { popup->insertItem(SmallIcon("filenew"), i18n("Insert Bookmark..."), insertID); popup->insertItem(SmallIcon("edit"), i18n("Edit..."), editID); popup->insertItem(SmallIcon("editdelete"), i18n("Delete"), deleteID); } KBookmarkManager* manager = DolphinSettings::instance().bookmarkManager(); KBookmarkGroup root = manager->root(); const int index = m_bookmarksList->index(m_bookmarksList->selectedItem()); const int result = popup->exec(pos); switch (result) { case insertID: { KBookmark newBookmark = EditBookmarkDialog::getBookmark(i18n("Insert Bookmark"), i18n("New bookmark"), KURL(), "bookmark"); if (!newBookmark.isNull()) { root.addBookmark(manager, newBookmark); if (index > 0) { KBookmark prevBookmark = DolphinSettings::instance().bookmark(index - 1); root.moveItem(newBookmark, prevBookmark); } else { // insert bookmark at first position (is a little bit tricky as KBookmarkGroup // only allows to move items after existing items) KBookmark firstBookmark = root.first(); root.moveItem(newBookmark, firstBookmark); root.moveItem(firstBookmark, newBookmark); } manager->emitChanged(root); } break; } case editID: { KBookmark oldBookmark = DolphinSettings::instance().bookmark(index); KBookmark newBookmark = EditBookmarkDialog::getBookmark(i18n("Edit Bookmark"), oldBookmark.text(), oldBookmark.url(), oldBookmark.icon()); if (!newBookmark.isNull()) { root.addBookmark(manager, newBookmark); root.moveItem(newBookmark, oldBookmark); root.deleteBookmark(oldBookmark); manager->emitChanged(root); } break; } case deleteID: { KBookmark bookmark = DolphinSettings::instance().bookmark(index); root.deleteBookmark(bookmark); manager->emitChanged(root); break; } case addID: { KBookmark bookmark = EditBookmarkDialog::getBookmark(i18n("Add Bookmark"), "New bookmark", KURL(), "bookmark"); if (!bookmark.isNull()) { root.addBookmark(manager, bookmark); manager->emitChanged(root); } } default: break; } delete popup; popup = 0; DolphinView* view = Dolphin::mainWin().activeView(); adjustSelection(view->url()); }