File indexing completed on 2024-06-16 04:39:06
0001 /* ============================================================ 0002 * Falkon - Qt web browser 0003 * Copyright (C) 2013-2014 Mattias Cibien <mattias@mattiascibien.net> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "ieimporter.h" 0019 #include "bookmarkitem.h" 0020 0021 #include <QDir> 0022 #include <QUrl> 0023 #include <QSettings> 0024 #include <QFileDialog> 0025 0026 IeImporter::IeImporter(QObject* parent) 0027 : BookmarksImporter(parent) 0028 { 0029 } 0030 0031 QString IeImporter::description() const 0032 { 0033 return BookmarksImporter::tr("Internet Explorer stores its bookmarks in <b>Favorites</b> folder. " 0034 "This folder is usually located in"); 0035 } 0036 0037 QString IeImporter::standardPath() const 0038 { 0039 return QDir::homePath() + QLatin1String("/Favorites/"); 0040 } 0041 0042 QString IeImporter::getPath(QWidget* parent) 0043 { 0044 m_path = QFileDialog::getExistingDirectory(parent, BookmarksImporter::tr("Choose file..."), standardPath()); 0045 return m_path; 0046 } 0047 0048 bool IeImporter::prepareImport() 0049 { 0050 QDir dir(m_path); 0051 if (!dir.exists()) { 0052 setError(BookmarksImporter::tr("Directory does not exist.")); 0053 return false; 0054 } 0055 0056 return true; 0057 } 0058 0059 BookmarkItem* IeImporter::importBookmarks() 0060 { 0061 auto* root = new BookmarkItem(BookmarkItem::Folder); 0062 root->setTitle(QStringLiteral("Internet Explorer Import")); 0063 0064 readDir(QDir(m_path), root); 0065 return root; 0066 } 0067 0068 void IeImporter::readDir(const QDir &dir, BookmarkItem *parent) 0069 { 0070 const auto files = dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); 0071 for (const QFileInfo &file : files) { 0072 if (file.isDir()) { 0073 auto* folder = new BookmarkItem(BookmarkItem::Folder, parent); 0074 folder->setTitle(file.baseName()); 0075 0076 QDir folderDir = dir; 0077 folderDir.cd(file.baseName()); 0078 readDir(folderDir, folder); 0079 } 0080 else if (file.isFile()) { 0081 QSettings urlFile(file.absoluteFilePath(), QSettings::IniFormat); 0082 const QUrl url = urlFile.value(QStringLiteral("InternetShortcut/URL")).toUrl(); 0083 0084 auto* item = new BookmarkItem(BookmarkItem::Url, parent); 0085 item->setTitle(file.baseName()); 0086 item->setUrl(url); 0087 } 0088 } 0089 }