2013-09-10 15:45:51 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2013-2014 Mattias Cibien <mattias@mattiascibien.net>
|
2013-09-10 15:45:51 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
2013-09-10 15:33:38 +02:00
|
|
|
#include "ieimporter.h"
|
|
|
|
#include "bookmarksimportdialog.h"
|
2014-02-10 14:57:48 +01:00
|
|
|
#include "bookmarkitem.h"
|
2013-09-10 15:33:38 +02:00
|
|
|
|
|
|
|
#include <QDir>
|
2014-02-10 14:57:48 +01:00
|
|
|
#include <QUrl>
|
2013-09-10 15:33:38 +02:00
|
|
|
#include <QSettings>
|
|
|
|
|
2013-09-10 15:45:51 +02:00
|
|
|
IeImporter::IeImporter(QObject* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_error(false)
|
|
|
|
, m_errorString(BookmarksImportDialog::tr("No Error"))
|
2013-09-10 15:33:38 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void IeImporter::setFile(const QString &path)
|
|
|
|
{
|
|
|
|
m_path = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IeImporter::openFile()
|
|
|
|
{
|
|
|
|
QDir dir(m_path);
|
2013-09-10 15:45:51 +02:00
|
|
|
if (!dir.exists()) {
|
2013-09-10 15:33:38 +02:00
|
|
|
m_error = true;
|
2013-09-10 15:53:30 +02:00
|
|
|
m_errorString = BookmarksImportDialog::tr("Directory does not exist.");
|
2013-09-10 15:33:38 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList filters;
|
|
|
|
filters << "*.url";
|
|
|
|
|
|
|
|
urls = dir.entryInfoList(filters);
|
|
|
|
|
2013-09-10 15:45:51 +02:00
|
|
|
if (urls.isEmpty()) {
|
2013-09-10 15:33:38 +02:00
|
|
|
m_error = true;
|
|
|
|
m_errorString = BookmarksImportDialog::tr("The directory does not contain any bookmarks.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-10 14:57:48 +01:00
|
|
|
BookmarkItem* IeImporter::exportBookmarks()
|
2013-09-10 15:33:38 +02:00
|
|
|
{
|
2014-02-10 14:57:48 +01:00
|
|
|
BookmarkItem* root = new BookmarkItem(BookmarkItem::Folder);
|
|
|
|
root->setTitle("Internet Explorer Import");
|
2013-09-10 15:33:38 +02:00
|
|
|
|
|
|
|
foreach (QFileInfo file, urls) {
|
|
|
|
QSettings urlFile(file.absoluteFilePath(), QSettings::IniFormat, this);
|
|
|
|
|
|
|
|
QUrl url = urlFile.value("InternetShortcut/URL").toUrl();
|
|
|
|
|
2014-02-10 14:57:48 +01:00
|
|
|
BookmarkItem* b = new BookmarkItem(BookmarkItem::Url, root);
|
|
|
|
b->setTitle(file.baseName());
|
|
|
|
b->setUrl(url);
|
2013-09-10 15:33:38 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 14:57:48 +01:00
|
|
|
return root;
|
2013-09-10 15:33:38 +02:00
|
|
|
}
|