mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-20 00:41:23 +00:00
html exporting (not finished, just the opera format exporter atm)
svn path=/trunk/kdebase/konqueror/keditbookmarks/; revision=230008
This commit is contained in:
parent
6c9a487d34
commit
4332dd395b
|
@ -123,6 +123,8 @@ void ActionsImpl::slotImport() {
|
|||
|
||||
void ActionsImpl::slotExportOpera() {
|
||||
CurrentMgr::self()->doExport(CurrentMgr::OperaExport); }
|
||||
void ActionsImpl::slotExportHTML() {
|
||||
CurrentMgr::self()->doExport(CurrentMgr::HTMLExport); }
|
||||
void ActionsImpl::slotExportIE() {
|
||||
CurrentMgr::self()->doExport(CurrentMgr::IEExport); }
|
||||
void ActionsImpl::slotExportNS() {
|
||||
|
|
|
@ -52,6 +52,7 @@ public slots:
|
|||
void slotCollapseAll();
|
||||
void slotImport();
|
||||
void slotExportOpera();
|
||||
void slotExportHTML();
|
||||
void slotExportIE();
|
||||
void slotExportNS();
|
||||
void slotExportMoz();
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
</Menu>
|
||||
<Menu name="export" noMerge="1"><text>&Export</text>
|
||||
<Action name="exportOpera"/>
|
||||
<Action name="exportHTML"/>
|
||||
<Action name="exportIE"/>
|
||||
<Action name="exportMoz"/>
|
||||
<Action name="exportNS"/>
|
||||
|
@ -142,6 +143,7 @@
|
|||
<Action name="file_save_as"/>
|
||||
<Action name="file_quit"/>
|
||||
<Action name="exportOpera"/>
|
||||
<Action name="exportHTML"/>
|
||||
<Action name="exportIE"/>
|
||||
<Action name="exportNS"/>
|
||||
<Action name="exportMoz"/>
|
||||
|
|
|
@ -146,18 +146,76 @@ void CurrentMgr::notifyManagers() {
|
|||
DCOPRef("*", objId).send("notifyCompleteChange", QString::fromLatin1(kapp->dcopClient()->appId()));
|
||||
}
|
||||
|
||||
class HTMLExporter : private KBookmarkGroupTraverser {
|
||||
public:
|
||||
HTMLExporter();
|
||||
void write( const KBookmarkGroup &, QString );
|
||||
private:
|
||||
virtual void visit( const KBookmark & );
|
||||
virtual void visitEnter( const KBookmarkGroup & );
|
||||
virtual void visitLeave( const KBookmarkGroup & );
|
||||
private:
|
||||
QString m_string;
|
||||
QTextStream m_out;
|
||||
};
|
||||
|
||||
HTMLExporter::HTMLExporter() : m_out(&m_string, IO_WriteOnly) {
|
||||
;
|
||||
}
|
||||
|
||||
void HTMLExporter::write( const KBookmarkGroup &grp, QString filename ) {
|
||||
HTMLExporter exporter;
|
||||
QFile file(filename);
|
||||
if (!file.open(IO_WriteOnly)) {
|
||||
kdError(7043) << "Can't write to file " << filename << endl;
|
||||
return;
|
||||
}
|
||||
QTextStream fstream(&file);
|
||||
fstream.setEncoding(QTextStream::UnicodeUTF8);
|
||||
traverse(grp);
|
||||
fstream << m_string;
|
||||
}
|
||||
|
||||
void HTMLExporter::visit( const KBookmark &bk ) {
|
||||
kdDebug() << "visit(" << bk.text() << ")" << endl;
|
||||
m_out << "#URL" << endl;
|
||||
m_out << "\tNAME=" << bk.fullText() << endl;
|
||||
m_out << "\tURL=" << bk.url().url().utf8() << endl;
|
||||
m_out << endl;
|
||||
}
|
||||
|
||||
void HTMLExporter::visitEnter( const KBookmarkGroup &grp ) {
|
||||
kdDebug() << "visitEnter(" << grp.text() << ")" << endl;
|
||||
m_out << "#FOLDER" << endl;
|
||||
m_out << "\tNAME="<< grp.fullText() << endl;
|
||||
m_out << endl;
|
||||
}
|
||||
|
||||
void HTMLExporter::visitLeave( const KBookmarkGroup & ) {
|
||||
kdDebug() << "visitLeave()" << endl;
|
||||
m_out << endl;
|
||||
m_out << "-" << endl;
|
||||
m_out << endl;
|
||||
}
|
||||
|
||||
void CurrentMgr::doExport(ExportType type) {
|
||||
// TODO - add a factory and make all this use the base class
|
||||
if (type == IEExport) {
|
||||
QString path = KIEBookmarkImporterImpl().findDefaultLocation(true);
|
||||
KIEBookmarkExporterImpl exporter(mgr(), path);
|
||||
exporter.write(mgr()->root());
|
||||
return;
|
||||
} else if (type == OperaExport) {
|
||||
if (type == OperaExport) {
|
||||
QString path = KOperaBookmarkImporterImpl().findDefaultLocation(true);
|
||||
KOperaBookmarkExporterImpl exporter(mgr(), path);
|
||||
exporter.write(mgr()->root());
|
||||
return;
|
||||
} else if (type == HTMLExport) {
|
||||
QString path = KFileDialog::getSaveFileName( QDir::homeDirPath(),
|
||||
i18n("*.html|HTML Bookmark Listing") );
|
||||
HTMLExporter exporter;
|
||||
exporter.write(mgr()->root(), path);
|
||||
return;
|
||||
} else if (type == IEExport) {
|
||||
QString path = KIEBookmarkImporterImpl().findDefaultLocation(true);
|
||||
KIEBookmarkExporterImpl exporter(mgr(), path);
|
||||
exporter.write(mgr()->root());
|
||||
return;
|
||||
}
|
||||
bool moz = (type == MozillaExport);
|
||||
QString path =
|
||||
|
@ -331,6 +389,8 @@ void KEBApp::createActions() {
|
|||
actn, SLOT( slotExportNS() ), actionCollection(), "exportNS");
|
||||
(void) new KAction(i18n("&Export to Opera Bookmarks"), "opera", 0,
|
||||
actn, SLOT( slotExportOpera() ), actionCollection(), "exportOpera");
|
||||
(void) new KAction(i18n("&Export to HTML Bookmarks"), "opera", 0,
|
||||
actn, SLOT( slotExportHTML() ), actionCollection(), "exportHTML");
|
||||
(void) new KAction(i18n("&Export to IE Bookmarks"), "ie", 0,
|
||||
actn, SLOT( slotExportIE() ), actionCollection(), "exportIE");
|
||||
(void) new KAction(i18n("Export to &Mozilla Bookmarks..."), "mozilla", 0,
|
||||
|
|
|
@ -66,7 +66,7 @@ class CurrentMgr : public QObject {
|
|||
public:
|
||||
static CurrentMgr* self() { if (!s_mgr) { s_mgr = new CurrentMgr(); } return s_mgr; }
|
||||
void createManager(const QString &filename);
|
||||
typedef enum {OperaExport, IEExport, MozillaExport, NetscapeExport} ExportType;
|
||||
typedef enum {HTMLExport, OperaExport, IEExport, MozillaExport, NetscapeExport} ExportType;
|
||||
void doExport(ExportType type);
|
||||
void notifyManagers();
|
||||
QString correctAddress(const QString &address);
|
||||
|
|
Loading…
Reference in a new issue