mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-20 00:41:23 +00:00
indent to 4 spaces
svn path=/trunk/kdebase/konqueror/keditbookmarks/; revision=257985
This commit is contained in:
parent
e921983c51
commit
807e476f82
|
@ -10,7 +10,7 @@
|
|||
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.
|
||||
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
|
||||
|
@ -46,51 +46,51 @@
|
|||
#include <kbookmarkmanager.h>
|
||||
|
||||
void BookmarkInfoWidget::showBookmark(const KBookmark &bk) {
|
||||
m_title_le->setText(bk.text());
|
||||
m_url_le->setText(bk.url().url());
|
||||
m_comment_le->setText("a comment");
|
||||
m_moddate_le->setText("the modification date");
|
||||
m_credate_le->setText("the creation date");
|
||||
m_title_le->setText(bk.text());
|
||||
m_url_le->setText(bk.url().url());
|
||||
m_comment_le->setText("a comment");
|
||||
m_moddate_le->setText("the modification date");
|
||||
m_credate_le->setText("the creation date");
|
||||
}
|
||||
|
||||
BookmarkInfoWidget::BookmarkInfoWidget(
|
||||
QWidget * parent, const char * name
|
||||
QWidget * parent, const char * name
|
||||
) : QWidget (parent, name) {
|
||||
QBoxLayout *vbox = new QVBoxLayout(this);
|
||||
QGridLayout *grid = new QGridLayout(vbox, 3, 4);
|
||||
QBoxLayout *vbox = new QVBoxLayout(this);
|
||||
QGridLayout *grid = new QGridLayout(vbox, 3, 4);
|
||||
|
||||
m_title_le = new KLineEdit(this);
|
||||
m_title_le->setReadOnly(true);
|
||||
grid->addWidget(m_title_le, 0, 1);
|
||||
grid->addWidget(
|
||||
m_title_le = new KLineEdit(this);
|
||||
m_title_le->setReadOnly(true);
|
||||
grid->addWidget(m_title_le, 0, 1);
|
||||
grid->addWidget(
|
||||
new QLabel(m_title_le, i18n("Name:"), this),
|
||||
0, 0);
|
||||
|
||||
m_url_le = new KLineEdit(this);
|
||||
m_url_le->setReadOnly(true);
|
||||
grid->addWidget(m_url_le, 1, 1);
|
||||
grid->addWidget(
|
||||
m_url_le = new KLineEdit(this);
|
||||
m_url_le->setReadOnly(true);
|
||||
grid->addWidget(m_url_le, 1, 1);
|
||||
grid->addWidget(
|
||||
new QLabel(m_url_le, i18n("Location:"), this),
|
||||
1, 0);
|
||||
|
||||
m_comment_le = new KLineEdit(this);
|
||||
m_comment_le->setReadOnly(true);
|
||||
grid->addWidget(m_comment_le, 2, 1);
|
||||
grid->addWidget(
|
||||
m_comment_le = new KLineEdit(this);
|
||||
m_comment_le->setReadOnly(true);
|
||||
grid->addWidget(m_comment_le, 2, 1);
|
||||
grid->addWidget(
|
||||
new QLabel(m_comment_le, i18n("Comment:"), this),
|
||||
2, 0);
|
||||
|
||||
m_moddate_le = new KLineEdit(this);
|
||||
m_moddate_le->setReadOnly(true);
|
||||
grid->addWidget(m_moddate_le, 0, 3);
|
||||
grid->addWidget(
|
||||
m_moddate_le = new KLineEdit(this);
|
||||
m_moddate_le->setReadOnly(true);
|
||||
grid->addWidget(m_moddate_le, 0, 3);
|
||||
grid->addWidget(
|
||||
new QLabel(m_moddate_le, i18n("First viewed:"), this),
|
||||
0, 2 );
|
||||
|
||||
m_credate_le = new KLineEdit(this);
|
||||
m_credate_le->setReadOnly(true);
|
||||
grid->addWidget(m_credate_le, 1, 3);
|
||||
grid->addWidget(
|
||||
m_credate_le = new KLineEdit(this);
|
||||
m_credate_le->setReadOnly(true);
|
||||
grid->addWidget(m_credate_le, 1, 3);
|
||||
grid->addWidget(
|
||||
new QLabel(m_credate_le, i18n("Viewed last:"), this),
|
||||
1, 2);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
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.
|
||||
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
|
||||
|
@ -29,77 +29,77 @@
|
|||
#include <qtimer.h>
|
||||
|
||||
BookmarkIterator::BookmarkIterator(QValueList<KBookmark> bks) : m_bklist(bks) {
|
||||
connect(this, SIGNAL( deleteSelf(BookmarkIterator *) ),
|
||||
SLOT( slotCancelTest(BookmarkIterator *) ));
|
||||
delayedEmitNextOne();
|
||||
connect(this, SIGNAL( deleteSelf(BookmarkIterator *) ),
|
||||
SLOT( slotCancelTest(BookmarkIterator *) ));
|
||||
delayedEmitNextOne();
|
||||
}
|
||||
|
||||
BookmarkIterator::~BookmarkIterator() {
|
||||
;
|
||||
;
|
||||
}
|
||||
|
||||
void BookmarkIterator::delayedEmitNextOne() {
|
||||
QTimer::singleShot(1, this, SLOT( nextOne() ));
|
||||
QTimer::singleShot(1, this, SLOT( nextOne() ));
|
||||
}
|
||||
|
||||
void BookmarkIterator::slotCancelTest(BookmarkIterator *test) {
|
||||
holder()->removeItr(test);
|
||||
holder()->removeItr(test);
|
||||
}
|
||||
|
||||
KEBListViewItem* BookmarkIterator::curItem() const {
|
||||
return ListView::self()->getItemAtAddress(m_bk.address());
|
||||
return ListView::self()->getItemAtAddress(m_bk.address());
|
||||
}
|
||||
|
||||
const KBookmark BookmarkIterator::curBk() const {
|
||||
return m_bk;
|
||||
return m_bk;
|
||||
}
|
||||
|
||||
void BookmarkIterator::nextOne() {
|
||||
// kdDebug() << "BookmarkIterator::nextOne" << endl;
|
||||
// kdDebug() << "BookmarkIterator::nextOne" << endl;
|
||||
|
||||
if (m_bklist.isEmpty()) {
|
||||
emit deleteSelf(this);
|
||||
return;
|
||||
}
|
||||
if (m_bklist.isEmpty()) {
|
||||
emit deleteSelf(this);
|
||||
return;
|
||||
}
|
||||
|
||||
QValueListIterator<KBookmark> head = m_bklist.begin();
|
||||
KBookmark bk = (*head);
|
||||
QValueListIterator<KBookmark> head = m_bklist.begin();
|
||||
KBookmark bk = (*head);
|
||||
|
||||
bool viable = bk.hasParent() && isApplicable(bk);
|
||||
bool viable = bk.hasParent() && isApplicable(bk);
|
||||
|
||||
if (viable) {
|
||||
m_bk = bk;
|
||||
doAction();
|
||||
}
|
||||
if (viable) {
|
||||
m_bk = bk;
|
||||
doAction();
|
||||
}
|
||||
|
||||
m_bklist.remove(head);
|
||||
m_bklist.remove(head);
|
||||
|
||||
if (!viable) {
|
||||
emit nextOne();
|
||||
}
|
||||
if (!viable) {
|
||||
emit nextOne();
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------- */
|
||||
|
||||
BookmarkIteratorHolder::BookmarkIteratorHolder() {
|
||||
m_itrs.setAutoDelete(true);
|
||||
m_itrs.setAutoDelete(true);
|
||||
}
|
||||
|
||||
void BookmarkIteratorHolder::insertItr(BookmarkIterator *itr) {
|
||||
m_itrs.insert(0, itr);
|
||||
doItrListChanged();
|
||||
m_itrs.insert(0, itr);
|
||||
doItrListChanged();
|
||||
}
|
||||
|
||||
void BookmarkIteratorHolder::removeItr(BookmarkIterator *itr) {
|
||||
m_itrs.remove(itr);
|
||||
doItrListChanged();
|
||||
m_itrs.remove(itr);
|
||||
doItrListChanged();
|
||||
}
|
||||
|
||||
void BookmarkIteratorHolder::cancelAllItrs() {
|
||||
BookmarkIterator *itr;
|
||||
for (itr = m_itrs.first(); itr != 0; itr = m_itrs.next()) {
|
||||
removeItr(itr);
|
||||
}
|
||||
BookmarkIterator *itr;
|
||||
for (itr = m_itrs.first(); itr != 0; itr = m_itrs.next()) {
|
||||
removeItr(itr);
|
||||
}
|
||||
}
|
||||
|
||||
#include "bookmarkiterator.moc"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
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.
|
||||
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
|
||||
|
@ -37,523 +37,523 @@
|
|||
CmdGen* CmdGen::s_self = 0;
|
||||
|
||||
QString CreateCommand::name() const {
|
||||
if (m_separator) {
|
||||
return i18n("Insert Separator");
|
||||
} else if (m_group) {
|
||||
return m_konqi ? i18n("Create Folder")
|
||||
: i18n("Create Folder in Konqueror");
|
||||
} else if (!m_originalBookmark.isNull()) {
|
||||
return i18n("Copy %1").arg(m_mytext);
|
||||
} else {
|
||||
return m_konqi ? i18n("Create Bookmark")
|
||||
: i18n("Add Bookmark in Konqueror");
|
||||
}
|
||||
if (m_separator) {
|
||||
return i18n("Insert Separator");
|
||||
} else if (m_group) {
|
||||
return m_konqi ? i18n("Create Folder")
|
||||
: i18n("Create Folder in Konqueror");
|
||||
} else if (!m_originalBookmark.isNull()) {
|
||||
return i18n("Copy %1").arg(m_mytext);
|
||||
} else {
|
||||
return m_konqi ? i18n("Create Bookmark")
|
||||
: i18n("Add Bookmark in Konqueror");
|
||||
}
|
||||
}
|
||||
|
||||
void CreateCommand::execute() {
|
||||
QString parentAddress = KBookmark::parentAddress(m_to);
|
||||
KBookmarkGroup parentGroup =
|
||||
CurrentMgr::bookmarkAt(parentAddress).toGroup();
|
||||
QString parentAddress = KBookmark::parentAddress(m_to);
|
||||
KBookmarkGroup parentGroup =
|
||||
CurrentMgr::bookmarkAt(parentAddress).toGroup();
|
||||
|
||||
QString previousSibling = KBookmark::previousAddress(m_to);
|
||||
QString previousSibling = KBookmark::previousAddress(m_to);
|
||||
|
||||
// kdDebug() << "CreateCommand::execute previousSibling="
|
||||
// << previousSibling << endl;
|
||||
KBookmark prev = (previousSibling.isEmpty())
|
||||
? KBookmark(QDomElement())
|
||||
: CurrentMgr::bookmarkAt(previousSibling);
|
||||
// kdDebug() << "CreateCommand::execute previousSibling="
|
||||
// << previousSibling << endl;
|
||||
KBookmark prev = (previousSibling.isEmpty())
|
||||
? KBookmark(QDomElement())
|
||||
: CurrentMgr::bookmarkAt(previousSibling);
|
||||
|
||||
KBookmark bk = KBookmark(QDomElement());
|
||||
KBookmark bk = KBookmark(QDomElement());
|
||||
|
||||
if (m_separator) {
|
||||
bk = parentGroup.createNewSeparator();
|
||||
if (m_separator) {
|
||||
bk = parentGroup.createNewSeparator();
|
||||
|
||||
} else if (m_group) {
|
||||
Q_ASSERT(!m_text.isEmpty());
|
||||
bk = parentGroup.createNewFolder(CurrentMgr::self()->mgr(),
|
||||
m_text, false);
|
||||
bk.internalElement().setAttribute("folded", (m_open ? "no" : "yes"));
|
||||
if (!m_iconPath.isEmpty()) {
|
||||
bk.internalElement().setAttribute("icon", m_iconPath);
|
||||
}
|
||||
} else if (m_group) {
|
||||
Q_ASSERT(!m_text.isEmpty());
|
||||
bk = parentGroup.createNewFolder(CurrentMgr::self()->mgr(),
|
||||
m_text, false);
|
||||
bk.internalElement().setAttribute("folded", (m_open ? "no" : "yes"));
|
||||
if (!m_iconPath.isEmpty()) {
|
||||
bk.internalElement().setAttribute("icon", m_iconPath);
|
||||
}
|
||||
|
||||
} else if (!m_originalBookmark.isNull()) {
|
||||
// umm.. moveItem needs bk to be a child already!
|
||||
bk = m_originalBookmark;
|
||||
} else if (!m_originalBookmark.isNull()) {
|
||||
// umm.. moveItem needs bk to be a child already!
|
||||
bk = m_originalBookmark;
|
||||
|
||||
} else {
|
||||
bk = parentGroup.addBookmark(CurrentMgr::self()->mgr(),
|
||||
m_text, m_url,
|
||||
m_iconPath, false);
|
||||
}
|
||||
} else {
|
||||
bk = parentGroup.addBookmark(CurrentMgr::self()->mgr(),
|
||||
m_text, m_url,
|
||||
m_iconPath, false);
|
||||
}
|
||||
|
||||
// move to right position
|
||||
parentGroup.moveItem(bk, prev);
|
||||
if (!(name().isEmpty())) {
|
||||
// open the parent (useful if it was empty) - only for manual commands
|
||||
parentGroup.internalElement().setAttribute("folded", "no");
|
||||
}
|
||||
|
||||
Q_ASSERT(bk.address() == m_to);
|
||||
// move to right position
|
||||
parentGroup.moveItem(bk, prev);
|
||||
if (!(name().isEmpty())) {
|
||||
// open the parent (useful if it was empty) - only for manual commands
|
||||
parentGroup.internalElement().setAttribute("folded", "no");
|
||||
}
|
||||
|
||||
Q_ASSERT(bk.address() == m_to);
|
||||
}
|
||||
|
||||
QString CreateCommand::finalAddress() const {
|
||||
Q_ASSERT( !m_to.isEmpty() );
|
||||
return m_to;
|
||||
Q_ASSERT( !m_to.isEmpty() );
|
||||
return m_to;
|
||||
}
|
||||
|
||||
void CreateCommand::unexecute() {
|
||||
// kdDebug() << "CreateCommand::unexecute deleting " << m_to << endl;
|
||||
// kdDebug() << "CreateCommand::unexecute deleting " << m_to << endl;
|
||||
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_to);
|
||||
Q_ASSERT(!bk.isNull() && !bk.parentGroup().isNull());
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_to);
|
||||
Q_ASSERT(!bk.isNull() && !bk.parentGroup().isNull());
|
||||
|
||||
KEBListViewItem *item =
|
||||
static_cast<KEBListViewItem*>(ListView::self()->firstSelected());
|
||||
KEBListViewItem *item =
|
||||
static_cast<KEBListViewItem*>(ListView::self()->firstSelected());
|
||||
|
||||
if (item
|
||||
&& item->bookmark().hasParent()
|
||||
&& item->bookmark().address() == m_to) {
|
||||
item->setSelected(false);
|
||||
if (item
|
||||
&& item->bookmark().hasParent()
|
||||
&& item->bookmark().address() == m_to) {
|
||||
item->setSelected(false);
|
||||
|
||||
// can't use itemBelow here, in case we're deleting a folder
|
||||
QListViewItem *selectItem = item->nextSibling();
|
||||
if (!selectItem) {
|
||||
// no next sibling ? Go to previous one, then.
|
||||
QString selcAddr = bk.parentGroup().previousAddress(bk.address());
|
||||
if (selcAddr.isEmpty()) {
|
||||
KBookmark::parentAddress(bk.address());
|
||||
}
|
||||
ListView::self()->setInitialAddress(selcAddr);
|
||||
}
|
||||
}
|
||||
// can't use itemBelow here, in case we're deleting a folder
|
||||
QListViewItem *selectItem = item->nextSibling();
|
||||
if (!selectItem) {
|
||||
// no next sibling ? Go to previous one, then.
|
||||
QString selcAddr = bk.parentGroup().previousAddress(bk.address());
|
||||
if (selcAddr.isEmpty()) {
|
||||
KBookmark::parentAddress(bk.address());
|
||||
}
|
||||
ListView::self()->setInitialAddress(selcAddr);
|
||||
}
|
||||
}
|
||||
|
||||
bk.parentGroup().deleteBookmark(bk);
|
||||
bk.parentGroup().deleteBookmark(bk);
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
QString EditCommand::name() const {
|
||||
return i18n("%1 Change").arg(m_mytext);
|
||||
return i18n("%1 Change").arg(m_mytext);
|
||||
}
|
||||
|
||||
void EditCommand::execute() {
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_address);
|
||||
Q_ASSERT(!bk.isNull());
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_address);
|
||||
Q_ASSERT(!bk.isNull());
|
||||
|
||||
m_reverseEditions.clear();
|
||||
m_reverseEditions.clear();
|
||||
|
||||
QValueList<Edition>::Iterator it = m_editions.begin();
|
||||
QValueList<Edition>::Iterator it = m_editions.begin();
|
||||
|
||||
for ( ; it != m_editions.end() ; ++it) {
|
||||
// backup current value
|
||||
m_reverseEditions.append( Edition((*it).attr,
|
||||
bk.internalElement().attribute((*it).attr)));
|
||||
// set new value
|
||||
bk.internalElement().setAttribute((*it).attr, (*it).value);
|
||||
}
|
||||
for ( ; it != m_editions.end() ; ++it) {
|
||||
// backup current value
|
||||
m_reverseEditions.append( Edition((*it).attr,
|
||||
bk.internalElement().attribute((*it).attr)));
|
||||
// set new value
|
||||
bk.internalElement().setAttribute((*it).attr, (*it).value);
|
||||
}
|
||||
}
|
||||
|
||||
void EditCommand::unexecute() {
|
||||
// code reuse
|
||||
EditCommand cmd(m_address, m_reverseEditions);
|
||||
cmd.execute();
|
||||
// get the editions back from it,
|
||||
// in case they changed
|
||||
// (hmm, shouldn't happen - TODO CHECK!)
|
||||
m_editions = cmd.m_reverseEditions;
|
||||
// code reuse
|
||||
EditCommand cmd(m_address, m_reverseEditions);
|
||||
cmd.execute();
|
||||
// get the editions back from it,
|
||||
// in case they changed
|
||||
// (hmm, shouldn't happen - TODO CHECK!)
|
||||
m_editions = cmd.m_reverseEditions;
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
QString NodeEditCommand::name() const {
|
||||
// TODO - make dynamic
|
||||
return i18n("Renaming");
|
||||
// TODO - make dynamic
|
||||
return i18n("Renaming");
|
||||
}
|
||||
|
||||
QString NodeEditCommand::getNodeText(KBookmark bk, const QString &nodename) {
|
||||
QDomNode subnode = bk.internalElement().namedItem(nodename);
|
||||
return subnode.isNull() || subnode.firstChild().isNull()
|
||||
QDomNode subnode = bk.internalElement().namedItem(nodename);
|
||||
return subnode.isNull() || subnode.firstChild().isNull()
|
||||
? QString::null
|
||||
: subnode.firstChild().toText().data();
|
||||
}
|
||||
|
||||
void NodeEditCommand::execute() {
|
||||
// DUPLICATED HEAVILY FROM KIO/BOOKMARKS
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_address);
|
||||
Q_ASSERT(!bk.isNull());
|
||||
// DUPLICATED HEAVILY FROM KIO/BOOKMARKS
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_address);
|
||||
Q_ASSERT(!bk.isNull());
|
||||
|
||||
QDomNode subnode = bk.internalElement().namedItem(m_nodename);
|
||||
if (subnode.isNull()) {
|
||||
subnode =
|
||||
bk.internalElement().ownerDocument().createElement(m_nodename);
|
||||
bk.internalElement().appendChild(subnode);
|
||||
}
|
||||
QDomNode subnode = bk.internalElement().namedItem(m_nodename);
|
||||
if (subnode.isNull()) {
|
||||
subnode =
|
||||
bk.internalElement().ownerDocument().createElement(m_nodename);
|
||||
bk.internalElement().appendChild(subnode);
|
||||
}
|
||||
|
||||
if (subnode.firstChild().isNull()) {
|
||||
QDomText domtext = subnode.ownerDocument().createTextNode("");
|
||||
subnode.appendChild(domtext);
|
||||
}
|
||||
if (subnode.firstChild().isNull()) {
|
||||
QDomText domtext = subnode.ownerDocument().createTextNode("");
|
||||
subnode.appendChild(domtext);
|
||||
}
|
||||
|
||||
QDomText domtext = subnode.firstChild().toText();
|
||||
QDomText domtext = subnode.firstChild().toText();
|
||||
|
||||
m_oldText = domtext.data();
|
||||
domtext.setData(m_newText);
|
||||
m_oldText = domtext.data();
|
||||
domtext.setData(m_newText);
|
||||
}
|
||||
|
||||
void NodeEditCommand::unexecute() {
|
||||
// reuse code
|
||||
NodeEditCommand cmd(m_address, m_oldText, m_nodename);
|
||||
cmd.execute();
|
||||
// get the old text back from it, in case they changed
|
||||
// (hmm, shouldn't happen)
|
||||
// AK - DUP'ed from above???
|
||||
m_newText = cmd.m_oldText;
|
||||
// reuse code
|
||||
NodeEditCommand cmd(m_address, m_oldText, m_nodename);
|
||||
cmd.execute();
|
||||
// get the old text back from it, in case they changed
|
||||
// (hmm, shouldn't happen)
|
||||
// AK - DUP'ed from above???
|
||||
m_newText = cmd.m_oldText;
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
void DeleteCommand::execute() {
|
||||
// kdDebug() << "DeleteCommand::execute " << m_from << endl;
|
||||
// kdDebug() << "DeleteCommand::execute " << m_from << endl;
|
||||
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_from);
|
||||
Q_ASSERT(!bk.isNull());
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_from);
|
||||
Q_ASSERT(!bk.isNull());
|
||||
|
||||
if (m_contentOnly) {
|
||||
QDomElement groupRoot = bk.internalElement();
|
||||
if (m_contentOnly) {
|
||||
QDomElement groupRoot = bk.internalElement();
|
||||
|
||||
QDomNode n = groupRoot.firstChild();
|
||||
while (!n.isNull()) {
|
||||
QDomElement e = n.toElement();
|
||||
if (!e.isNull()) {
|
||||
kdDebug() << e.tagName() << endl;
|
||||
}
|
||||
QDomNode next = n.nextSibling();
|
||||
groupRoot.removeChild(n);
|
||||
n = next;
|
||||
}
|
||||
return;
|
||||
}
|
||||
QDomNode n = groupRoot.firstChild();
|
||||
while (!n.isNull()) {
|
||||
QDomElement e = n.toElement();
|
||||
if (!e.isNull()) {
|
||||
kdDebug() << e.tagName() << endl;
|
||||
}
|
||||
QDomNode next = n.nextSibling();
|
||||
groupRoot.removeChild(n);
|
||||
n = next;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO - bug - unparsed xml is lost after undo,
|
||||
// we must store it all therefore
|
||||
if (!m_cmd) {
|
||||
if (bk.isGroup()) {
|
||||
m_cmd = new CreateCommand(
|
||||
m_from, bk.fullText(), bk.icon(),
|
||||
bk.internalElement().attribute("folded") == "no");
|
||||
m_subCmd = deleteAll(bk.toGroup());
|
||||
m_subCmd->execute();
|
||||
// TODO - bug - unparsed xml is lost after undo,
|
||||
// we must store it all therefore
|
||||
if (!m_cmd) {
|
||||
if (bk.isGroup()) {
|
||||
m_cmd = new CreateCommand(
|
||||
m_from, bk.fullText(), bk.icon(),
|
||||
bk.internalElement().attribute("folded") == "no");
|
||||
m_subCmd = deleteAll(bk.toGroup());
|
||||
m_subCmd->execute();
|
||||
|
||||
} else {
|
||||
m_cmd = (bk.isSeparator())
|
||||
? new CreateCommand(m_from)
|
||||
: new CreateCommand(m_from, bk.fullText(),
|
||||
bk.icon(), bk.url());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m_cmd = (bk.isSeparator())
|
||||
? new CreateCommand(m_from)
|
||||
: new CreateCommand(m_from, bk.fullText(),
|
||||
bk.icon(), bk.url());
|
||||
}
|
||||
}
|
||||
|
||||
m_cmd->unexecute();
|
||||
m_cmd->unexecute();
|
||||
}
|
||||
|
||||
void DeleteCommand::unexecute() {
|
||||
// kdDebug() << "DeleteCommand::unexecute " << m_from << endl;
|
||||
// kdDebug() << "DeleteCommand::unexecute " << m_from << endl;
|
||||
|
||||
if (m_contentOnly) {
|
||||
// TODO - recover saved metadata
|
||||
return;
|
||||
}
|
||||
if (m_contentOnly) {
|
||||
// TODO - recover saved metadata
|
||||
return;
|
||||
}
|
||||
|
||||
m_cmd->execute();
|
||||
m_cmd->execute();
|
||||
|
||||
if (m_subCmd) {
|
||||
m_subCmd->unexecute();
|
||||
}
|
||||
if (m_subCmd) {
|
||||
m_subCmd->unexecute();
|
||||
}
|
||||
}
|
||||
|
||||
KMacroCommand* DeleteCommand::deleteAll(const KBookmarkGroup & parentGroup) {
|
||||
KMacroCommand *cmd = new KMacroCommand(QString::null);
|
||||
QStringList lstToDelete;
|
||||
// we need to delete from the end, to avoid index shifting
|
||||
for (KBookmark bk = parentGroup.first();
|
||||
!bk.isNull(); bk = parentGroup.next(bk))
|
||||
lstToDelete.prepend(bk.address());
|
||||
for (QStringList::Iterator it = lstToDelete.begin();
|
||||
it != lstToDelete.end(); ++it)
|
||||
cmd->addCommand(new DeleteCommand((*it)));
|
||||
return cmd;
|
||||
KMacroCommand *cmd = new KMacroCommand(QString::null);
|
||||
QStringList lstToDelete;
|
||||
// we need to delete from the end, to avoid index shifting
|
||||
for (KBookmark bk = parentGroup.first();
|
||||
!bk.isNull(); bk = parentGroup.next(bk))
|
||||
lstToDelete.prepend(bk.address());
|
||||
for (QStringList::Iterator it = lstToDelete.begin();
|
||||
it != lstToDelete.end(); ++it)
|
||||
cmd->addCommand(new DeleteCommand((*it)));
|
||||
return cmd;
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
QString MoveCommand::name() const {
|
||||
return i18n("Move %1").arg(m_mytext);
|
||||
return i18n("Move %1").arg(m_mytext);
|
||||
}
|
||||
|
||||
void MoveCommand::execute() {
|
||||
// kdDebug() << "MoveCommand::execute moving from=" << m_from
|
||||
// << " to=" << m_to << endl;
|
||||
// kdDebug() << "MoveCommand::execute moving from=" << m_from
|
||||
// << " to=" << m_to << endl;
|
||||
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_from);
|
||||
Q_ASSERT(!bk.isNull());
|
||||
KBookmark bk = CurrentMgr::bookmarkAt(m_from);
|
||||
Q_ASSERT(!bk.isNull());
|
||||
|
||||
// look for m_from in the QDom tree
|
||||
KBookmark oldParent =
|
||||
CurrentMgr::bookmarkAt(KBookmark::parentAddress(m_from));
|
||||
bool wasFirstChild = (KBookmark::positionInParent(m_from) == 0);
|
||||
// look for m_from in the QDom tree
|
||||
KBookmark oldParent =
|
||||
CurrentMgr::bookmarkAt(KBookmark::parentAddress(m_from));
|
||||
bool wasFirstChild = (KBookmark::positionInParent(m_from) == 0);
|
||||
|
||||
KBookmark oldPreviousSibling = wasFirstChild
|
||||
? KBookmark(QDomElement())
|
||||
: CurrentMgr::bookmarkAt(
|
||||
KBookmark::previousAddress(m_from));
|
||||
KBookmark oldPreviousSibling = wasFirstChild
|
||||
? KBookmark(QDomElement())
|
||||
: CurrentMgr::bookmarkAt(
|
||||
KBookmark::previousAddress(m_from));
|
||||
|
||||
// look for m_to in the QDom tree
|
||||
QString parentAddress = KBookmark::parentAddress(m_to);
|
||||
// look for m_to in the QDom tree
|
||||
QString parentAddress = KBookmark::parentAddress(m_to);
|
||||
|
||||
KBookmark newParent = CurrentMgr::bookmarkAt(parentAddress);
|
||||
Q_ASSERT(!newParent.isNull());
|
||||
Q_ASSERT(newParent.isGroup());
|
||||
KBookmark newParent = CurrentMgr::bookmarkAt(parentAddress);
|
||||
Q_ASSERT(!newParent.isNull());
|
||||
Q_ASSERT(newParent.isGroup());
|
||||
|
||||
bool isFirstChild = (KBookmark::positionInParent(m_to) == 0);
|
||||
bool isFirstChild = (KBookmark::positionInParent(m_to) == 0);
|
||||
|
||||
if (isFirstChild) {
|
||||
newParent.toGroup().moveItem(bk, QDomElement());
|
||||
if (isFirstChild) {
|
||||
newParent.toGroup().moveItem(bk, QDomElement());
|
||||
|
||||
} else {
|
||||
QString afterAddress = KBookmark::previousAddress(m_to);
|
||||
} else {
|
||||
QString afterAddress = KBookmark::previousAddress(m_to);
|
||||
|
||||
// kdDebug() << "MoveCommand::execute afterAddress="
|
||||
// << afterAddress << endl;
|
||||
KBookmark afterNow = CurrentMgr::bookmarkAt(afterAddress);
|
||||
Q_ASSERT(!afterNow.isNull());
|
||||
// kdDebug() << "MoveCommand::execute afterAddress="
|
||||
// << afterAddress << endl;
|
||||
KBookmark afterNow = CurrentMgr::bookmarkAt(afterAddress);
|
||||
Q_ASSERT(!afterNow.isNull());
|
||||
|
||||
bool movedOkay = newParent.toGroup().moveItem(bk, afterNow);
|
||||
Q_ASSERT(movedOkay);
|
||||
bool movedOkay = newParent.toGroup().moveItem(bk, afterNow);
|
||||
Q_ASSERT(movedOkay);
|
||||
|
||||
// kdDebug() << "MoveCommand::execute after moving in the dom tree"
|
||||
// ": item=" << bk.address() << endl;
|
||||
}
|
||||
// kdDebug() << "MoveCommand::execute after moving in the dom tree"
|
||||
// ": item=" << bk.address() << endl;
|
||||
}
|
||||
|
||||
// because we moved stuff around, the from/to
|
||||
// addresses can have changed, update
|
||||
m_to = bk.address();
|
||||
m_from = (wasFirstChild)
|
||||
? (oldParent.address() + "/0")
|
||||
: KBookmark::nextAddress(oldPreviousSibling.address());
|
||||
// kdDebug() << "MoveCommand::execute : new addresses from="
|
||||
// << m_from << " to=" << m_to << endl;
|
||||
// because we moved stuff around, the from/to
|
||||
// addresses can have changed, update
|
||||
m_to = bk.address();
|
||||
m_from = (wasFirstChild)
|
||||
? (oldParent.address() + "/0")
|
||||
: KBookmark::nextAddress(oldPreviousSibling.address());
|
||||
// kdDebug() << "MoveCommand::execute : new addresses from="
|
||||
// << m_from << " to=" << m_to << endl;
|
||||
}
|
||||
|
||||
QString MoveCommand::finalAddress() const {
|
||||
Q_ASSERT( !m_to.isEmpty() );
|
||||
return m_to;
|
||||
Q_ASSERT( !m_to.isEmpty() );
|
||||
return m_to;
|
||||
}
|
||||
|
||||
void MoveCommand::unexecute() {
|
||||
// let's not duplicate code.
|
||||
MoveCommand undoCmd(m_to, m_from);
|
||||
undoCmd.execute();
|
||||
// get the addresses back from that command, in case they changed
|
||||
m_from = undoCmd.m_to;
|
||||
m_to = undoCmd.m_from;
|
||||
// let's not duplicate code.
|
||||
MoveCommand undoCmd(m_to, m_from);
|
||||
undoCmd.execute();
|
||||
// get the addresses back from that command, in case they changed
|
||||
m_from = undoCmd.m_to;
|
||||
m_to = undoCmd.m_from;
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
class SortItem {
|
||||
public:
|
||||
SortItem(const KBookmark & bk) : m_bk(bk) { ; }
|
||||
public:
|
||||
SortItem(const KBookmark & bk) : m_bk(bk) { ; }
|
||||
|
||||
bool operator == (const SortItem & s) {
|
||||
return (m_bk.internalElement() == s.m_bk.internalElement()); }
|
||||
bool operator == (const SortItem & s) {
|
||||
return (m_bk.internalElement() == s.m_bk.internalElement()); }
|
||||
|
||||
bool isNull() const {
|
||||
return m_bk.isNull(); }
|
||||
bool isNull() const {
|
||||
return m_bk.isNull(); }
|
||||
|
||||
SortItem previousSibling() const {
|
||||
return m_bk.parentGroup().previous(m_bk); }
|
||||
SortItem previousSibling() const {
|
||||
return m_bk.parentGroup().previous(m_bk); }
|
||||
|
||||
SortItem nextSibling() const {
|
||||
return m_bk.parentGroup().next(m_bk); }
|
||||
SortItem nextSibling() const {
|
||||
return m_bk.parentGroup().next(m_bk); }
|
||||
|
||||
const KBookmark& bookmark() const {
|
||||
return m_bk; }
|
||||
const KBookmark& bookmark() const {
|
||||
return m_bk; }
|
||||
|
||||
private:
|
||||
KBookmark m_bk;
|
||||
private:
|
||||
KBookmark m_bk;
|
||||
};
|
||||
|
||||
class SortByName {
|
||||
public:
|
||||
static QString key(const SortItem &item) {
|
||||
return (item.bookmark().isGroup() ? "a" : "b")
|
||||
+ (item.bookmark().fullText().lower());
|
||||
}
|
||||
public:
|
||||
static QString key(const SortItem &item) {
|
||||
return (item.bookmark().isGroup() ? "a" : "b")
|
||||
+ (item.bookmark().fullText().lower());
|
||||
}
|
||||
};
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
void SortCommand::execute() {
|
||||
if (m_commands.isEmpty()) {
|
||||
KBookmarkGroup grp = CurrentMgr::bookmarkAt(m_groupAddress).toGroup();
|
||||
Q_ASSERT(!grp.isNull());
|
||||
SortItem firstChild(grp.first());
|
||||
// this will call moveAfter, which will add
|
||||
// the subcommands for moving the items
|
||||
kInsertionSort<SortItem, SortByName, QString, SortCommand>
|
||||
(firstChild, (*this));
|
||||
if (m_commands.isEmpty()) {
|
||||
KBookmarkGroup grp = CurrentMgr::bookmarkAt(m_groupAddress).toGroup();
|
||||
Q_ASSERT(!grp.isNull());
|
||||
SortItem firstChild(grp.first());
|
||||
// this will call moveAfter, which will add
|
||||
// the subcommands for moving the items
|
||||
kInsertionSort<SortItem, SortByName, QString, SortCommand>
|
||||
(firstChild, (*this));
|
||||
|
||||
} else {
|
||||
// don't execute for second time on addCommand(cmd)
|
||||
KMacroCommand::execute();
|
||||
}
|
||||
} else {
|
||||
// don't execute for second time on addCommand(cmd)
|
||||
KMacroCommand::execute();
|
||||
}
|
||||
}
|
||||
|
||||
void SortCommand::moveAfter(const SortItem &moveMe,
|
||||
const SortItem &afterMe) {
|
||||
QString destAddress =
|
||||
afterMe.isNull()
|
||||
// move as first child
|
||||
? KBookmark::parentAddress(moveMe.bookmark().address()) + "/0"
|
||||
// move after "afterMe"
|
||||
: KBookmark::nextAddress(afterMe.bookmark().address());
|
||||
const SortItem &afterMe) {
|
||||
QString destAddress =
|
||||
afterMe.isNull()
|
||||
// move as first child
|
||||
? KBookmark::parentAddress(moveMe.bookmark().address()) + "/0"
|
||||
// move after "afterMe"
|
||||
: KBookmark::nextAddress(afterMe.bookmark().address());
|
||||
|
||||
MoveCommand *cmd = new MoveCommand(moveMe.bookmark().address(),
|
||||
destAddress);
|
||||
cmd->execute();
|
||||
this->addCommand(cmd);
|
||||
MoveCommand *cmd = new MoveCommand(moveMe.bookmark().address(),
|
||||
destAddress);
|
||||
cmd->execute();
|
||||
this->addCommand(cmd);
|
||||
}
|
||||
|
||||
void SortCommand::unexecute() {
|
||||
KMacroCommand::unexecute();
|
||||
KMacroCommand::unexecute();
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
KMacroCommand* CmdGen::setAsToolbar(const KBookmark &bk) {
|
||||
KMacroCommand *mcmd = new KMacroCommand(i18n("Set as Bookmark Toolbar"));
|
||||
KMacroCommand *mcmd = new KMacroCommand(i18n("Set as Bookmark Toolbar"));
|
||||
|
||||
KBookmarkGroup oldToolbar = CurrentMgr::self()->mgr()->toolbar();
|
||||
if (!oldToolbar.isNull()) {
|
||||
QValueList<EditCommand::Edition> lst;
|
||||
lst.append(EditCommand::Edition("toolbar", "no"));
|
||||
lst.append(EditCommand::Edition("icon", ""));
|
||||
EditCommand *cmd1 = new EditCommand(oldToolbar.address(), lst);
|
||||
mcmd->addCommand(cmd1);
|
||||
}
|
||||
KBookmarkGroup oldToolbar = CurrentMgr::self()->mgr()->toolbar();
|
||||
if (!oldToolbar.isNull()) {
|
||||
QValueList<EditCommand::Edition> lst;
|
||||
lst.append(EditCommand::Edition("toolbar", "no"));
|
||||
lst.append(EditCommand::Edition("icon", ""));
|
||||
EditCommand *cmd1 = new EditCommand(oldToolbar.address(), lst);
|
||||
mcmd->addCommand(cmd1);
|
||||
}
|
||||
|
||||
QValueList<EditCommand::Edition> lst;
|
||||
lst.append(EditCommand::Edition("toolbar", "yes"));
|
||||
lst.append(EditCommand::Edition("icon", "bookmark_toolbar"));
|
||||
// TODO - see below
|
||||
EditCommand *cmd2 = new EditCommand(bk.address(), lst);
|
||||
mcmd->addCommand(cmd2);
|
||||
QValueList<EditCommand::Edition> lst;
|
||||
lst.append(EditCommand::Edition("toolbar", "yes"));
|
||||
lst.append(EditCommand::Edition("icon", "bookmark_toolbar"));
|
||||
// TODO - see below
|
||||
EditCommand *cmd2 = new EditCommand(bk.address(), lst);
|
||||
mcmd->addCommand(cmd2);
|
||||
|
||||
return mcmd;
|
||||
return mcmd;
|
||||
}
|
||||
|
||||
bool CmdGen::shownInToolbar(const KBookmark &bk) {
|
||||
return (bk.internalElement().attribute("showintoolbar") == "yes");
|
||||
return (bk.internalElement().attribute("showintoolbar") == "yes");
|
||||
}
|
||||
|
||||
KMacroCommand* CmdGen::setShownInToolbar(const KBookmark &bk, bool show) {
|
||||
QString i18n_name = i18n("%1 in Bookmark Toolbar").arg(show ? i18n("Show")
|
||||
: i18n("Hide"));
|
||||
KMacroCommand *mcmd = new KMacroCommand(i18n_name);
|
||||
QString i18n_name = i18n("%1 in Bookmark Toolbar").arg(show ? i18n("Show")
|
||||
: i18n("Hide"));
|
||||
KMacroCommand *mcmd = new KMacroCommand(i18n_name);
|
||||
|
||||
QValueList<EditCommand::Edition> lst;
|
||||
lst.append(EditCommand::Edition("showintoolbar", show ? "yes" : "no"));
|
||||
EditCommand *cmd2 = new EditCommand(bk.address(), lst);
|
||||
mcmd->addCommand(cmd2);
|
||||
QValueList<EditCommand::Edition> lst;
|
||||
lst.append(EditCommand::Edition("showintoolbar", show ? "yes" : "no"));
|
||||
EditCommand *cmd2 = new EditCommand(bk.address(), lst);
|
||||
mcmd->addCommand(cmd2);
|
||||
|
||||
return mcmd;
|
||||
return mcmd;
|
||||
}
|
||||
|
||||
KMacroCommand* CmdGen::deleteItems(const QString &commandName,
|
||||
QPtrList<KEBListViewItem> *items) {
|
||||
QPtrListIterator<KEBListViewItem> it(*items);
|
||||
KMacroCommand *mcmd = new KMacroCommand(commandName);
|
||||
for (; it.current() != 0; ++it) {
|
||||
DeleteCommand *dcmd =
|
||||
new DeleteCommand(it.current()->bookmark().address());
|
||||
dcmd->execute();
|
||||
mcmd->addCommand(dcmd);
|
||||
}
|
||||
return mcmd;
|
||||
QPtrList<KEBListViewItem> *items) {
|
||||
QPtrListIterator<KEBListViewItem> it(*items);
|
||||
KMacroCommand *mcmd = new KMacroCommand(commandName);
|
||||
for (; it.current() != 0; ++it) {
|
||||
DeleteCommand *dcmd =
|
||||
new DeleteCommand(it.current()->bookmark().address());
|
||||
dcmd->execute();
|
||||
mcmd->addCommand(dcmd);
|
||||
}
|
||||
return mcmd;
|
||||
}
|
||||
|
||||
KMacroCommand* CmdGen::insertMimeSource(
|
||||
const QString &cmdName, QMimeSource *_data, const QString &addr
|
||||
) {
|
||||
QMimeSource *data = _data;
|
||||
bool modified = false;
|
||||
const char *format = 0;
|
||||
for (int i = 0; format = data->format(i), format; i++) {
|
||||
// qt docs don't say if encodedData(blah) where
|
||||
// blah is not a stored mimetype should return null
|
||||
// or not. so, we search. sucky...
|
||||
if (strcmp(format, "GALEON_BOOKMARK") == 0) {
|
||||
modified = true;
|
||||
QStoredDrag *mydrag = new QStoredDrag("application/x-xbel");
|
||||
mydrag->setEncodedData(data->encodedData("GALEON_BOOKMARK"));
|
||||
data = mydrag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!KBookmarkDrag::canDecode(data))
|
||||
return 0;
|
||||
KMacroCommand *mcmd = new KMacroCommand(cmdName);
|
||||
QString currentAddress = addr;
|
||||
QValueList<KBookmark> bookmarks = KBookmarkDrag::decode(data);
|
||||
for (QValueListConstIterator<KBookmark> it = bookmarks.begin();
|
||||
it != bookmarks.end(); ++it) {
|
||||
CreateCommand *cmd = new CreateCommand(currentAddress, (*it));
|
||||
cmd->execute();
|
||||
mcmd->addCommand(cmd);
|
||||
currentAddress = KBookmark::nextAddress(currentAddress);
|
||||
}
|
||||
if (modified)
|
||||
delete data;
|
||||
return mcmd;
|
||||
const QString &cmdName, QMimeSource *_data, const QString &addr
|
||||
) {
|
||||
QMimeSource *data = _data;
|
||||
bool modified = false;
|
||||
const char *format = 0;
|
||||
for (int i = 0; format = data->format(i), format; i++) {
|
||||
// qt docs don't say if encodedData(blah) where
|
||||
// blah is not a stored mimetype should return null
|
||||
// or not. so, we search. sucky...
|
||||
if (strcmp(format, "GALEON_BOOKMARK") == 0) {
|
||||
modified = true;
|
||||
QStoredDrag *mydrag = new QStoredDrag("application/x-xbel");
|
||||
mydrag->setEncodedData(data->encodedData("GALEON_BOOKMARK"));
|
||||
data = mydrag;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!KBookmarkDrag::canDecode(data))
|
||||
return 0;
|
||||
KMacroCommand *mcmd = new KMacroCommand(cmdName);
|
||||
QString currentAddress = addr;
|
||||
QValueList<KBookmark> bookmarks = KBookmarkDrag::decode(data);
|
||||
for (QValueListConstIterator<KBookmark> it = bookmarks.begin();
|
||||
it != bookmarks.end(); ++it) {
|
||||
CreateCommand *cmd = new CreateCommand(currentAddress, (*it));
|
||||
cmd->execute();
|
||||
mcmd->addCommand(cmd);
|
||||
currentAddress = KBookmark::nextAddress(currentAddress);
|
||||
}
|
||||
if (modified)
|
||||
delete data;
|
||||
return mcmd;
|
||||
}
|
||||
|
||||
KMacroCommand* CmdGen::itemsMoved(QPtrList<KEBListViewItem> *items,
|
||||
const QString &newAddress, bool copy) {
|
||||
KMacroCommand *mcmd = new KMacroCommand(copy ? i18n("Copy Items")
|
||||
: i18n("Move Items"));
|
||||
const QString &newAddress, bool copy) {
|
||||
KMacroCommand *mcmd = new KMacroCommand(copy ? i18n("Copy Items")
|
||||
: i18n("Move Items"));
|
||||
|
||||
QString bkInsertAddr = newAddress;
|
||||
QString bkInsertAddr = newAddress;
|
||||
|
||||
for (QPtrListIterator<KEBListViewItem> it(*items);
|
||||
it.current() != 0; ++it) {
|
||||
if (copy) {
|
||||
CreateCommand *cmd;
|
||||
cmd = new CreateCommand(
|
||||
bkInsertAddr,
|
||||
(*it)->bookmark().internalElement()
|
||||
.cloneNode(true).toElement(),
|
||||
(*it)->bookmark().text());
|
||||
for (QPtrListIterator<KEBListViewItem> it(*items);
|
||||
it.current() != 0; ++it) {
|
||||
if (copy) {
|
||||
CreateCommand *cmd;
|
||||
cmd = new CreateCommand(
|
||||
bkInsertAddr,
|
||||
(*it)->bookmark().internalElement()
|
||||
.cloneNode(true).toElement(),
|
||||
(*it)->bookmark().text());
|
||||
|
||||
cmd->execute();
|
||||
mcmd->addCommand(cmd);
|
||||
|
||||
bkInsertAddr = cmd->finalAddress();
|
||||
cmd->execute();
|
||||
mcmd->addCommand(cmd);
|
||||
|
||||
} else /* if (move) */ {
|
||||
QString oldAddress = (*it)->bookmark().address();
|
||||
if (bkInsertAddr.startsWith(oldAddress))
|
||||
continue;
|
||||
bkInsertAddr = cmd->finalAddress();
|
||||
|
||||
MoveCommand *cmd = new MoveCommand(oldAddress, bkInsertAddr,
|
||||
(*it)->bookmark().text());
|
||||
cmd->execute();
|
||||
mcmd->addCommand(cmd);
|
||||
|
||||
bkInsertAddr = cmd->finalAddress();
|
||||
}
|
||||
} else /* if (move) */ {
|
||||
QString oldAddress = (*it)->bookmark().address();
|
||||
if (bkInsertAddr.startsWith(oldAddress))
|
||||
continue;
|
||||
|
||||
bkInsertAddr = KBookmark::nextAddress(bkInsertAddr);
|
||||
}
|
||||
MoveCommand *cmd = new MoveCommand(oldAddress, bkInsertAddr,
|
||||
(*it)->bookmark().text());
|
||||
cmd->execute();
|
||||
mcmd->addCommand(cmd);
|
||||
|
||||
return mcmd;
|
||||
bkInsertAddr = cmd->finalAddress();
|
||||
}
|
||||
|
||||
bkInsertAddr = KBookmark::nextAddress(bkInsertAddr);
|
||||
}
|
||||
|
||||
return mcmd;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
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.
|
||||
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
|
||||
|
@ -37,52 +37,52 @@
|
|||
#include <kapplication.h>
|
||||
|
||||
KBookmarkEditorIface::KBookmarkEditorIface()
|
||||
: QObject(), DCOPObject("KBookmarkEditor") {
|
||||
// connect(KBookmarkNotifier_stub, SIGNAL( updatedAccessMetadata(QString,QString) ),
|
||||
// this, SLOT( slotDcopUpdatedAccessMetadata(QString,QString) ));
|
||||
connectDCOPSignal(0, "KBookmarkNotifier", "updatedAccessMetadata(QString,QString)", "slotDcopUpdatedAccessMetadata(QString,QString)", false);
|
||||
connectDCOPSignal(0, "KBookmarkNotifier", "addedBookmark(QString,QString,QString,QString,QString)", "slotDcopAddedBookmark(QString,QString,QString,QString,QString)", false);
|
||||
connectDCOPSignal(0, "KBookmarkNotifier", "createdNewFolder(QString,QString,QString)", "slotDcopCreatedNewFolder(QString,QString,QString)", false);
|
||||
: QObject(), DCOPObject("KBookmarkEditor") {
|
||||
// connect(KBookmarkNotifier_stub, SIGNAL( updatedAccessMetadata(QString,QString) ),
|
||||
// this, SLOT( slotDcopUpdatedAccessMetadata(QString,QString) ));
|
||||
connectDCOPSignal(0, "KBookmarkNotifier", "updatedAccessMetadata(QString,QString)", "slotDcopUpdatedAccessMetadata(QString,QString)", false);
|
||||
connectDCOPSignal(0, "KBookmarkNotifier", "addedBookmark(QString,QString,QString,QString,QString)", "slotDcopAddedBookmark(QString,QString,QString,QString,QString)", false);
|
||||
connectDCOPSignal(0, "KBookmarkNotifier", "createdNewFolder(QString,QString,QString)", "slotDcopCreatedNewFolder(QString,QString,QString)", false);
|
||||
}
|
||||
|
||||
void KBookmarkEditorIface::slotDcopUpdatedAccessMetadata(QString filename, QString url) {
|
||||
// evil hack, konqi gets updates by way of historymgr,
|
||||
// therefore konqi does'nt want "save" notification,
|
||||
// unfortunately to stop konqi getting it is difficult
|
||||
// and probably not needed until more notifier events
|
||||
// are added. therefore, we always updateaccessmetadata
|
||||
// without caring about our modified state like normal
|
||||
// and thusly there is no need to the bkmgr to do a "save"
|
||||
// evil hack, konqi gets updates by way of historymgr,
|
||||
// therefore konqi does'nt want "save" notification,
|
||||
// unfortunately to stop konqi getting it is difficult
|
||||
// and probably not needed until more notifier events
|
||||
// are added. therefore, we always updateaccessmetadata
|
||||
// without caring about our modified state like normal
|
||||
// and thusly there is no need to the bkmgr to do a "save"
|
||||
|
||||
// TODO - i'm not sure this is really true :)
|
||||
// TODO - i'm not sure this is really true :)
|
||||
|
||||
if (/*KEBApp::self()->modified() &&*/ filename == CurrentMgr::self()->path()) {
|
||||
kdDebug() << "slotDcopUpdatedAccessMetadata(" << url << ")" << endl;
|
||||
// no undo
|
||||
CurrentMgr::self()->mgr()->updateAccessMetadata(url, false);
|
||||
// notice - no save here! see! :)
|
||||
}
|
||||
if (/*KEBApp::self()->modified() &&*/ filename == CurrentMgr::self()->path()) {
|
||||
kdDebug() << "slotDcopUpdatedAccessMetadata(" << url << ")" << endl;
|
||||
// no undo
|
||||
CurrentMgr::self()->mgr()->updateAccessMetadata(url, false);
|
||||
// notice - no save here! see! :)
|
||||
}
|
||||
}
|
||||
|
||||
void KBookmarkEditorIface::slotDcopAddedBookmark(QString filename, QString url, QString text, QString address, QString icon) {
|
||||
if (KEBApp::self()->modified() && filename == CurrentMgr::self()->path()) {
|
||||
kdDebug() << "slotDcopAddedBookmark(" << url << "," << text << "," << address << "," << icon << ")" << endl;
|
||||
CreateCommand *cmd = new CreateCommand(
|
||||
CurrentMgr::self()->correctAddress(address),
|
||||
text, icon, KURL(url), true /*indirect*/);
|
||||
CmdHistory::self()->addCommand(cmd);
|
||||
}
|
||||
if (KEBApp::self()->modified() && filename == CurrentMgr::self()->path()) {
|
||||
kdDebug() << "slotDcopAddedBookmark(" << url << "," << text << "," << address << "," << icon << ")" << endl;
|
||||
CreateCommand *cmd = new CreateCommand(
|
||||
CurrentMgr::self()->correctAddress(address),
|
||||
text, icon, KURL(url), true /*indirect*/);
|
||||
CmdHistory::self()->addCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void KBookmarkEditorIface::slotDcopCreatedNewFolder(QString filename, QString text, QString address) {
|
||||
if (KEBApp::self()->modified() && filename == CurrentMgr::self()->path()) {
|
||||
kdDebug() << "slotDcopCreatedNewFolder(" << text << "," << address << ")" << endl;
|
||||
CreateCommand *cmd = new CreateCommand(
|
||||
CurrentMgr::self()->correctAddress(address),
|
||||
text, QString::null,
|
||||
true /*open*/, true /*indirect*/);
|
||||
CmdHistory::self()->addCommand(cmd);
|
||||
}
|
||||
if (KEBApp::self()->modified() && filename == CurrentMgr::self()->path()) {
|
||||
kdDebug() << "slotDcopCreatedNewFolder(" << text << "," << address << ")" << endl;
|
||||
CreateCommand *cmd = new CreateCommand(
|
||||
CurrentMgr::self()->correctAddress(address),
|
||||
text, QString::null,
|
||||
true /*open*/, true /*indirect*/);
|
||||
CmdHistory::self()->addCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
#include "dcop.moc"
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
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.
|
||||
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
|
||||
|
@ -27,52 +27,52 @@
|
|||
#include <qfile.h>
|
||||
|
||||
HTMLExporter::HTMLExporter()
|
||||
: m_out(&m_string, IO_WriteOnly) {
|
||||
m_level = 0;
|
||||
}
|
||||
: m_out(&m_string, IO_WriteOnly) {
|
||||
m_level = 0;
|
||||
}
|
||||
|
||||
void HTMLExporter::write(const KBookmarkGroup &grp, const QString &filename) {
|
||||
QFile file(filename);
|
||||
if (!file.open(IO_WriteOnly)) {
|
||||
kdError(7043) << "Can't write to file " << filename << endl;
|
||||
return;
|
||||
}
|
||||
QTextStream tstream(&file);
|
||||
tstream.setEncoding(QTextStream::UnicodeUTF8);
|
||||
tstream << toString(grp);
|
||||
QFile file(filename);
|
||||
if (!file.open(IO_WriteOnly)) {
|
||||
kdError(7043) << "Can't write to file " << filename << endl;
|
||||
return;
|
||||
}
|
||||
QTextStream tstream(&file);
|
||||
tstream.setEncoding(QTextStream::UnicodeUTF8);
|
||||
tstream << toString(grp);
|
||||
}
|
||||
|
||||
QString HTMLExporter::toString(const KBookmarkGroup &grp)
|
||||
{
|
||||
traverse(grp);
|
||||
return
|
||||
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
|
||||
"<HTML><HEAD><TITLE>My Bookmarks</TITLE></HEAD>\n"
|
||||
"<BODY>\n"
|
||||
+ m_string +
|
||||
"</BODY></HTML>\n";
|
||||
traverse(grp);
|
||||
return
|
||||
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
|
||||
"<HTML><HEAD><TITLE>My Bookmarks</TITLE></HEAD>\n"
|
||||
"<BODY>\n"
|
||||
+ m_string +
|
||||
"</BODY></HTML>\n";
|
||||
}
|
||||
|
||||
void HTMLExporter::visit(const KBookmark &bk) {
|
||||
// kdDebug() << "visit(" << bk.text() << ")" << endl;
|
||||
m_out << "<A href=\"" << bk.url().url().utf8() << "\">";
|
||||
m_out << bk.fullText() << "</A><BR>" << endl;
|
||||
// kdDebug() << "visit(" << bk.text() << ")" << endl;
|
||||
m_out << "<A href=\"" << bk.url().url().utf8() << "\">";
|
||||
m_out << bk.fullText() << "</A><BR>" << endl;
|
||||
}
|
||||
|
||||
void HTMLExporter::visitEnter(const KBookmarkGroup &grp) {
|
||||
// kdDebug() << "visitEnter(" << grp.text() << ")" << endl;
|
||||
m_out << "<H3>" << grp.fullText() << "</H3>" << endl;
|
||||
m_out << "<P style=\"margin-left: "
|
||||
<< (m_level * 3) << "em\">" << endl;
|
||||
m_level++;
|
||||
// kdDebug() << "visitEnter(" << grp.text() << ")" << endl;
|
||||
m_out << "<H3>" << grp.fullText() << "</H3>" << endl;
|
||||
m_out << "<P style=\"margin-left: "
|
||||
<< (m_level * 3) << "em\">" << endl;
|
||||
m_level++;
|
||||
}
|
||||
|
||||
void HTMLExporter::visitLeave(const KBookmarkGroup &) {
|
||||
// kdDebug() << "visitLeave()" << endl;
|
||||
m_out << "</P>" << endl;
|
||||
m_level--;
|
||||
if (m_level != 0)
|
||||
m_out << "<P style=\"left-margin: "
|
||||
// kdDebug() << "visitLeave()" << endl;
|
||||
m_out << "</P>" << endl;
|
||||
m_level--;
|
||||
if (m_level != 0)
|
||||
m_out << "<P style=\"left-margin: "
|
||||
<< (m_level * 3) << "em\">" << endl;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
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.
|
||||
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
|
||||
|
@ -32,53 +32,53 @@
|
|||
FavIconsItrHolder *FavIconsItrHolder::s_self = 0;
|
||||
|
||||
FavIconsItrHolder::FavIconsItrHolder()
|
||||
: BookmarkIteratorHolder() {
|
||||
// do stuff
|
||||
}
|
||||
: BookmarkIteratorHolder() {
|
||||
// do stuff
|
||||
}
|
||||
|
||||
void FavIconsItrHolder::doItrListChanged() {
|
||||
KEBApp::self()->setCancelFavIconUpdatesEnabled(count() > 0);
|
||||
KEBApp::self()->setCancelFavIconUpdatesEnabled(count() > 0);
|
||||
}
|
||||
|
||||
/* -------------------------- */
|
||||
|
||||
FavIconsItr::FavIconsItr(QValueList<KBookmark> bks)
|
||||
: BookmarkIterator(bks) {
|
||||
: BookmarkIterator(bks) {
|
||||
|
||||
m_updater = 0;
|
||||
m_done = true;
|
||||
}
|
||||
m_updater = 0;
|
||||
m_done = true;
|
||||
}
|
||||
|
||||
FavIconsItr::~FavIconsItr() {
|
||||
delete m_updater;
|
||||
if (curItem()) {
|
||||
curItem()->restoreStatus();
|
||||
}
|
||||
delete m_updater;
|
||||
if (curItem()) {
|
||||
curItem()->restoreStatus();
|
||||
}
|
||||
}
|
||||
|
||||
void FavIconsItr::slotDone(bool succeeded) {
|
||||
kdDebug() << "FavIconsItr::slotDone()" << endl;
|
||||
m_done = true;
|
||||
curItem()->setTmpStatus(succeeded ? i18n("OK") : i18n("No favicon found"));
|
||||
delayedEmitNextOne();
|
||||
kdDebug() << "FavIconsItr::slotDone()" << endl;
|
||||
m_done = true;
|
||||
curItem()->setTmpStatus(succeeded ? i18n("OK") : i18n("No favicon found"));
|
||||
delayedEmitNextOne();
|
||||
}
|
||||
|
||||
bool FavIconsItr::isApplicable(const KBookmark &bk) const {
|
||||
return (!bk.isGroup() && !bk.isSeparator()
|
||||
&& (bk.url().protocol().startsWith("http")) );
|
||||
}
|
||||
bool FavIconsItr::isApplicable(const KBookmark &bk) const {
|
||||
return (!bk.isGroup() && !bk.isSeparator()
|
||||
&& (bk.url().protocol().startsWith("http")) );
|
||||
}
|
||||
|
||||
void FavIconsItr::doAction() {
|
||||
kdDebug() << "FavIconsItr::doAction()" << endl;
|
||||
m_done = false;
|
||||
curItem()->setTmpStatus(i18n("Updating favicon..."));
|
||||
if (!m_updater) {
|
||||
m_updater = new FavIconUpdater(kapp, "FavIconUpdater");
|
||||
connect(m_updater, SIGNAL( done(bool) ),
|
||||
this, SLOT( slotDone(bool) ) );
|
||||
}
|
||||
m_updater->downloadIcon(curBk());
|
||||
// TODO - a single shot timeout?
|
||||
kdDebug() << "FavIconsItr::doAction()" << endl;
|
||||
m_done = false;
|
||||
curItem()->setTmpStatus(i18n("Updating favicon..."));
|
||||
if (!m_updater) {
|
||||
m_updater = new FavIconUpdater(kapp, "FavIconUpdater");
|
||||
connect(m_updater, SIGNAL( done(bool) ),
|
||||
this, SLOT( slotDone(bool) ) );
|
||||
}
|
||||
m_updater->downloadIcon(curBk());
|
||||
// TODO - a single shot timeout?
|
||||
}
|
||||
|
||||
#include "favicons.moc"
|
||||
|
|
|
@ -41,244 +41,244 @@
|
|||
#include <kbookmarkdombuilder.h>
|
||||
|
||||
QString ImportCommand::name() const {
|
||||
return i18n("Import %1 Bookmarks").arg(visibleName());
|
||||
return i18n("Import %1 Bookmarks").arg(visibleName());
|
||||
}
|
||||
|
||||
QString ImportCommand::folder() const {
|
||||
return m_folder ? i18n("%1 Bookmarks").arg(visibleName()) : QString::null;
|
||||
return m_folder ? i18n("%1 Bookmarks").arg(visibleName()) : QString::null;
|
||||
}
|
||||
|
||||
ImportCommand* ImportCommand::importerFactory(const QCString &type) {
|
||||
if (type == "Galeon") return new GaleonImportCommand();
|
||||
else if (type == "IE") return new IEImportCommand();
|
||||
else if (type == "KDE2") return new KDE2ImportCommand();
|
||||
else if (type == "Opera") return new OperaImportCommand();
|
||||
else if (type == "Crashes") return new CrashesImportCommand();
|
||||
else if (type == "Moz") return new MozImportCommand();
|
||||
else if (type == "NS") return new NSImportCommand();
|
||||
else {
|
||||
kdError() << "ImportCommand::importerFactory() - invalid type (" << type << ")!" << endl;
|
||||
return 0;
|
||||
}
|
||||
if (type == "Galeon") return new GaleonImportCommand();
|
||||
else if (type == "IE") return new IEImportCommand();
|
||||
else if (type == "KDE2") return new KDE2ImportCommand();
|
||||
else if (type == "Opera") return new OperaImportCommand();
|
||||
else if (type == "Crashes") return new CrashesImportCommand();
|
||||
else if (type == "Moz") return new MozImportCommand();
|
||||
else if (type == "NS") return new NSImportCommand();
|
||||
else {
|
||||
kdError() << "ImportCommand::importerFactory() - invalid type (" << type << ")!" << endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ImportCommand* ImportCommand::performImport(const QCString &type, QWidget *top) {
|
||||
ImportCommand *importer = ImportCommand::importerFactory(type);
|
||||
ImportCommand *importer = ImportCommand::importerFactory(type);
|
||||
|
||||
QString mydirname = importer->requestFilename();
|
||||
if (mydirname.isEmpty()) {
|
||||
delete importer;
|
||||
return 0;
|
||||
}
|
||||
QString mydirname = importer->requestFilename();
|
||||
if (mydirname.isEmpty()) {
|
||||
delete importer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int answer =
|
||||
KMessageBox::questionYesNoCancel(
|
||||
top, i18n("Import as a new subfolder or replace all the current bookmarks?"),
|
||||
i18n("%1 Import").arg(importer->visibleName()),
|
||||
i18n("As New Folder"), i18n("Replace"));
|
||||
int answer =
|
||||
KMessageBox::questionYesNoCancel(
|
||||
top, i18n("Import as a new subfolder or replace all the current bookmarks?"),
|
||||
i18n("%1 Import").arg(importer->visibleName()),
|
||||
i18n("As New Folder"), i18n("Replace"));
|
||||
|
||||
if (answer == KMessageBox::Cancel) {
|
||||
delete importer;
|
||||
return 0;
|
||||
}
|
||||
if (answer == KMessageBox::Cancel) {
|
||||
delete importer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
importer->import(mydirname, answer == KMessageBox::Yes);
|
||||
return importer;
|
||||
importer->import(mydirname, answer == KMessageBox::Yes);
|
||||
return importer;
|
||||
}
|
||||
|
||||
void ImportCommand::doCreateHoldingFolder(KBookmarkGroup &bkGroup) {
|
||||
bkGroup = CurrentMgr::self()->mgr()
|
||||
->root().createNewFolder(CurrentMgr::self()->mgr(), folder(), false);
|
||||
bkGroup.internalElement().setAttribute("icon", m_icon);
|
||||
m_group = bkGroup.address();
|
||||
}
|
||||
void ImportCommand::doCreateHoldingFolder(KBookmarkGroup &bkGroup) {
|
||||
bkGroup = CurrentMgr::self()->mgr()
|
||||
->root().createNewFolder(CurrentMgr::self()->mgr(), folder(), false);
|
||||
bkGroup.internalElement().setAttribute("icon", m_icon);
|
||||
m_group = bkGroup.address();
|
||||
}
|
||||
|
||||
void ImportCommand::execute() {
|
||||
KBookmarkGroup bkGroup;
|
||||
KBookmarkGroup bkGroup;
|
||||
|
||||
if (!folder().isNull()) {
|
||||
doCreateHoldingFolder(bkGroup);
|
||||
if (!folder().isNull()) {
|
||||
doCreateHoldingFolder(bkGroup);
|
||||
|
||||
} else {
|
||||
// import into the root, after cleaning it up
|
||||
bkGroup = CurrentMgr::self()->mgr()->root();
|
||||
delete m_cleanUpCmd;
|
||||
m_cleanUpCmd = DeleteCommand::deleteAll(bkGroup);
|
||||
} else {
|
||||
// import into the root, after cleaning it up
|
||||
bkGroup = CurrentMgr::self()->mgr()->root();
|
||||
delete m_cleanUpCmd;
|
||||
m_cleanUpCmd = DeleteCommand::deleteAll(bkGroup);
|
||||
|
||||
KMacroCommand *mcmd = (KMacroCommand*) m_cleanUpCmd;
|
||||
mcmd->addCommand(new DeleteCommand(bkGroup.address(),
|
||||
true /* contentOnly */));
|
||||
|
||||
// unselect current item, it doesn't exist anymore
|
||||
ListView::self()->clearSelection();
|
||||
m_cleanUpCmd->execute();
|
||||
KMacroCommand *mcmd = (KMacroCommand*) m_cleanUpCmd;
|
||||
mcmd->addCommand(new DeleteCommand(bkGroup.address(),
|
||||
true /* contentOnly */));
|
||||
|
||||
// import at the root
|
||||
m_group = "";
|
||||
}
|
||||
// unselect current item, it doesn't exist anymore
|
||||
ListView::self()->clearSelection();
|
||||
m_cleanUpCmd->execute();
|
||||
|
||||
doExecute(bkGroup);
|
||||
// import at the root
|
||||
m_group = "";
|
||||
}
|
||||
|
||||
doExecute(bkGroup);
|
||||
}
|
||||
|
||||
void ImportCommand::unexecute() {
|
||||
if ( !folder().isEmpty() ) {
|
||||
// we created a group -> just delete it
|
||||
DeleteCommand cmd(m_group);
|
||||
cmd.execute();
|
||||
if ( !folder().isEmpty() ) {
|
||||
// we created a group -> just delete it
|
||||
DeleteCommand cmd(m_group);
|
||||
cmd.execute();
|
||||
|
||||
} else {
|
||||
// we imported at the root -> delete everything
|
||||
KBookmarkGroup root = CurrentMgr::self()->mgr()->root();
|
||||
KCommand *cmd = DeleteCommand::deleteAll(root);
|
||||
} else {
|
||||
// we imported at the root -> delete everything
|
||||
KBookmarkGroup root = CurrentMgr::self()->mgr()->root();
|
||||
KCommand *cmd = DeleteCommand::deleteAll(root);
|
||||
|
||||
// unselect current item, it doesn't exist anymore
|
||||
ListView::self()->clearSelection();
|
||||
cmd->execute();
|
||||
delete cmd;
|
||||
// unselect current item, it doesn't exist anymore
|
||||
ListView::self()->clearSelection();
|
||||
cmd->execute();
|
||||
delete cmd;
|
||||
|
||||
// and recreate what was there before
|
||||
m_cleanUpCmd->unexecute();
|
||||
}
|
||||
// and recreate what was there before
|
||||
m_cleanUpCmd->unexecute();
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
QString MozImportCommand::requestFilename() const {
|
||||
static KMozillaBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
static KMozillaBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
}
|
||||
|
||||
QString NSImportCommand::requestFilename() const {
|
||||
static KNSBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
static KNSBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
}
|
||||
|
||||
QString OperaImportCommand::requestFilename() const {
|
||||
static KOperaBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
static KOperaBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
}
|
||||
|
||||
QString CrashesImportCommand::requestFilename() const {
|
||||
static KCrashBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
static KCrashBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
}
|
||||
|
||||
QString IEImportCommand::requestFilename() const {
|
||||
static KIEBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
static KIEBookmarkImporterImpl importer;
|
||||
return importer.findDefaultLocation();
|
||||
}
|
||||
|
||||
// following two are really just xbel
|
||||
|
||||
QString GaleonImportCommand::requestFilename() const {
|
||||
return KFileDialog::getOpenFileName(
|
||||
QDir::homeDirPath() + "/.galeon",
|
||||
i18n("*.xbel|Galeon bookmark files (*.xbel)"));
|
||||
return KFileDialog::getOpenFileName(
|
||||
QDir::homeDirPath() + "/.galeon",
|
||||
i18n("*.xbel|Galeon bookmark files (*.xbel)"));
|
||||
}
|
||||
|
||||
QString KDE2ImportCommand::requestFilename() const {
|
||||
// locateLocal on the bookmarks file and get dir?
|
||||
return KFileDialog::getOpenFileName(
|
||||
QDir::homeDirPath() + "/.kde",
|
||||
i18n("*.xml|KDE bookmark files (*.xml)"));
|
||||
// locateLocal on the bookmarks file and get dir?
|
||||
return KFileDialog::getOpenFileName(
|
||||
QDir::homeDirPath() + "/.kde",
|
||||
i18n("*.xml|KDE bookmark files (*.xml)"));
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
static void parseInto(const KBookmarkGroup &bkGroup, KBookmarkImporterBase *importer) {
|
||||
KBookmarkDomBuilder builder(bkGroup, CurrentMgr::self()->mgr());
|
||||
builder.connectImporter(importer);
|
||||
importer->parse();
|
||||
KBookmarkDomBuilder builder(bkGroup, CurrentMgr::self()->mgr());
|
||||
builder.connectImporter(importer);
|
||||
importer->parse();
|
||||
}
|
||||
|
||||
void OperaImportCommand::doExecute(const KBookmarkGroup &bkGroup) {
|
||||
KOperaBookmarkImporterImpl importer;
|
||||
importer.setFilename(m_fileName);
|
||||
parseInto(bkGroup, &importer);
|
||||
KOperaBookmarkImporterImpl importer;
|
||||
importer.setFilename(m_fileName);
|
||||
parseInto(bkGroup, &importer);
|
||||
}
|
||||
|
||||
void CrashesImportCommand::doExecute(const KBookmarkGroup &bkGroup) {
|
||||
KCrashBookmarkImporterImpl importer;
|
||||
importer.setShouldDelete(true);
|
||||
importer.setFilename(m_fileName);
|
||||
parseInto(bkGroup, &importer);
|
||||
KCrashBookmarkImporterImpl importer;
|
||||
importer.setShouldDelete(true);
|
||||
importer.setFilename(m_fileName);
|
||||
parseInto(bkGroup, &importer);
|
||||
}
|
||||
|
||||
void IEImportCommand::doExecute(const KBookmarkGroup &bkGroup) {
|
||||
KIEBookmarkImporterImpl importer;
|
||||
importer.setFilename(m_fileName);
|
||||
parseInto(bkGroup, &importer);
|
||||
KIEBookmarkImporterImpl importer;
|
||||
importer.setFilename(m_fileName);
|
||||
parseInto(bkGroup, &importer);
|
||||
}
|
||||
|
||||
void HTMLImportCommand::doExecute(const KBookmarkGroup &bkGroup) {
|
||||
KNSBookmarkImporterImpl importer;
|
||||
importer.setFilename(m_fileName);
|
||||
importer.setUtf8(m_utf8);
|
||||
parseInto(bkGroup, &importer);
|
||||
KNSBookmarkImporterImpl importer;
|
||||
importer.setFilename(m_fileName);
|
||||
importer.setUtf8(m_utf8);
|
||||
parseInto(bkGroup, &importer);
|
||||
}
|
||||
|
||||
/* -------------------------------------- */
|
||||
|
||||
void XBELImportCommand::doCreateHoldingFolder(KBookmarkGroup &) {
|
||||
// rather than reuse the old group node we transform the
|
||||
// root xbel node into the group when doing an xbel import
|
||||
// rather than reuse the old group node we transform the
|
||||
// root xbel node into the group when doing an xbel import
|
||||
}
|
||||
|
||||
void XBELImportCommand::doExecute(const KBookmarkGroup &/*bkGroup*/) {
|
||||
KBookmarkManager *pManager;
|
||||
KBookmarkManager *pManager;
|
||||
|
||||
// check if already open first???
|
||||
pManager = KBookmarkManager::managerForFile(m_fileName, false);
|
||||
// check if already open first???
|
||||
pManager = KBookmarkManager::managerForFile(m_fileName, false);
|
||||
|
||||
QDomDocument doc = CurrentMgr::self()->mgr()->internalDocument();
|
||||
QDomDocument doc = CurrentMgr::self()->mgr()->internalDocument();
|
||||
|
||||
// get the xbel
|
||||
QDomNode subDoc = pManager->internalDocument().namedItem("xbel").cloneNode();
|
||||
// get the xbel
|
||||
QDomNode subDoc = pManager->internalDocument().namedItem("xbel").cloneNode();
|
||||
|
||||
if (!folder().isEmpty()) {
|
||||
// transform into folder
|
||||
subDoc.toElement().setTagName("folder");
|
||||
if (!folder().isEmpty()) {
|
||||
// transform into folder
|
||||
subDoc.toElement().setTagName("folder");
|
||||
|
||||
// clear attributes
|
||||
QStringList tags;
|
||||
for (uint i = 0; i < subDoc.attributes().count(); i++)
|
||||
tags << subDoc.attributes().item(i).toAttr().name();
|
||||
for (QStringList::Iterator it = tags.begin(); it != tags.end(); ++it)
|
||||
subDoc.attributes().removeNamedItem((*it));
|
||||
// clear attributes
|
||||
QStringList tags;
|
||||
for (uint i = 0; i < subDoc.attributes().count(); i++)
|
||||
tags << subDoc.attributes().item(i).toAttr().name();
|
||||
for (QStringList::Iterator it = tags.begin(); it != tags.end(); ++it)
|
||||
subDoc.attributes().removeNamedItem((*it));
|
||||
|
||||
subDoc.toElement().setAttribute("icon", m_icon);
|
||||
subDoc.toElement().setAttribute("icon", m_icon);
|
||||
|
||||
// give the folder a name
|
||||
QDomElement textElem = doc.createElement("title");
|
||||
subDoc.insertBefore(textElem, subDoc.firstChild());
|
||||
textElem.appendChild(doc.createTextNode(folder()));
|
||||
}
|
||||
// give the folder a name
|
||||
QDomElement textElem = doc.createElement("title");
|
||||
subDoc.insertBefore(textElem, subDoc.firstChild());
|
||||
textElem.appendChild(doc.createTextNode(folder()));
|
||||
}
|
||||
|
||||
// import and add it
|
||||
QDomNode node = doc.importNode(subDoc, true);
|
||||
// import and add it
|
||||
QDomNode node = doc.importNode(subDoc, true);
|
||||
|
||||
if (!folder().isEmpty()) {
|
||||
CurrentMgr::self()->mgr()->root().internalElement().appendChild(node);
|
||||
m_group = KBookmarkGroup(node.toElement()).address();
|
||||
if (!folder().isEmpty()) {
|
||||
CurrentMgr::self()->mgr()->root().internalElement().appendChild(node);
|
||||
m_group = KBookmarkGroup(node.toElement()).address();
|
||||
|
||||
} else {
|
||||
QDomElement root = CurrentMgr::self()->mgr()->root().internalElement();
|
||||
} else {
|
||||
QDomElement root = CurrentMgr::self()->mgr()->root().internalElement();
|
||||
|
||||
QValueList<QDomElement> childList;
|
||||
QValueList<QDomElement> childList;
|
||||
|
||||
QDomNode n = subDoc.firstChild().toElement();
|
||||
while (!n.isNull()) {
|
||||
QDomElement e = n.toElement();
|
||||
if (!e.isNull())
|
||||
childList.append(e);
|
||||
n = n.nextSibling();
|
||||
}
|
||||
QDomNode n = subDoc.firstChild().toElement();
|
||||
while (!n.isNull()) {
|
||||
QDomElement e = n.toElement();
|
||||
if (!e.isNull())
|
||||
childList.append(e);
|
||||
n = n.nextSibling();
|
||||
}
|
||||
|
||||
QValueList<QDomElement>::Iterator it = childList.begin();
|
||||
QValueList<QDomElement>::Iterator end = childList.end();
|
||||
for (; it!= end ; ++it)
|
||||
root.appendChild((*it));
|
||||
}
|
||||
QValueList<QDomElement>::Iterator it = childList.begin();
|
||||
QValueList<QDomElement>::Iterator end = childList.end();
|
||||
for (; it!= end ; ++it)
|
||||
root.appendChild((*it));
|
||||
}
|
||||
}
|
||||
|
||||
#include "importers.moc"
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue