Falkon Develop
Cross-platform Qt-based web browser
ieimporter.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2013-2014 Mattias Cibien <mattias@mattiascibien.net>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "ieimporter.h"
19#include "bookmarkitem.h"
20
21#include <QDir>
22#include <QUrl>
23#include <QSettings>
24#include <QFileDialog>
25
26IeImporter::IeImporter(QObject* parent)
27 : BookmarksImporter(parent)
28{
29}
30
32{
33 return BookmarksImporter::tr("Internet Explorer stores its bookmarks in <b>Favorites</b> folder. "
34 "This folder is usually located in");
35}
36
38{
39 return QDir::homePath() + QLatin1String("/Favorites/");
40}
41
42QString IeImporter::getPath(QWidget* parent)
43{
44 m_path = QFileDialog::getExistingDirectory(parent, BookmarksImporter::tr("Choose file..."), standardPath());
45 return m_path;
46}
47
49{
50 QDir dir(m_path);
51 if (!dir.exists()) {
52 setError(BookmarksImporter::tr("Directory does not exist."));
53 return false;
54 }
55
56 return true;
57}
58
60{
61 auto* root = new BookmarkItem(BookmarkItem::Folder);
62 root->setTitle(QStringLiteral("Internet Explorer Import"));
63
64 readDir(QDir(m_path), root);
65 return root;
66}
67
68void IeImporter::readDir(const QDir &dir, BookmarkItem *parent)
69{
70 const auto files = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
71 for (const QFileInfo &file : files) {
72 if (file.isDir()) {
73 auto* folder = new BookmarkItem(BookmarkItem::Folder, parent);
74 folder->setTitle(file.baseName());
75
76 QDir folderDir = dir;
77 folderDir.cd(file.baseName());
78 readDir(folderDir, folder);
79 }
80 else if (file.isFile()) {
81 QSettings urlFile(file.absoluteFilePath(), QSettings::IniFormat);
82 const QUrl url = urlFile.value(QStringLiteral("InternetShortcut/URL")).toUrl();
83
84 auto* item = new BookmarkItem(BookmarkItem::Url, parent);
85 item->setTitle(file.baseName());
86 item->setUrl(url);
87 }
88 }
89}
void setError(const QString &error)
QString getPath(QWidget *parent) override
Definition: ieimporter.cpp:42
QString description() const override
Definition: ieimporter.cpp:31
QString standardPath() const override
Definition: ieimporter.cpp:37
BookmarkItem * importBookmarks() override
Definition: ieimporter.cpp:59
bool prepareImport() override
Definition: ieimporter.cpp:48
IeImporter(QObject *parent=nullptr)
Definition: ieimporter.cpp:26