summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/history/historymanager.cpp53
-rw-r--r--src/history/historymanager.h32
-rw-r--r--src/newtabpage.cpp51
-rw-r--r--src/newtabpage.h7
-rw-r--r--src/protocolhandler.cpp2
-rw-r--r--src/settings/settings_general.ui7
-rw-r--r--src/webpage.cpp105
7 files changed, 213 insertions, 44 deletions
diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp
index 362fe340..39c128f4 100644
--- a/src/history/historymanager.cpp
+++ b/src/history/historymanager.cpp
@@ -451,3 +451,56 @@ KCompletion * HistoryManager::completionObject() const
{
return m_completion;
}
+
+
+void HistoryManager::addDownload(const QString &srcUrl, const QString &destUrl)
+{
+ QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads");
+ QFile downloadFile(downloadFilePath);
+ if ( !downloadFile.open(QFile::WriteOnly | QFile::Append) )
+ {
+ kDebug() << "azz...";
+ return;
+ }
+ QDataStream out(&downloadFile);
+ out << srcUrl;
+ out << destUrl;
+ out << QDateTime::currentDateTime();
+ downloadFile.close();
+}
+
+
+DownloadList HistoryManager::downloads()
+{
+ DownloadList list;
+
+ QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads");
+ QFile downloadFile(downloadFilePath);
+ if ( !downloadFile.open(QFile::ReadOnly) )
+ {
+ kDebug() << "azz...";
+ return list;
+ }
+
+ QDataStream in(&downloadFile);
+ while(!in.atEnd())
+ {
+ QString srcUrl;
+ in >> srcUrl;
+ QString destUrl;
+ in >> destUrl;
+ QDateTime dt;
+ in >> dt;
+ DownloadItem item(srcUrl, destUrl, dt);
+ list << item;
+ }
+ return list;
+}
+
+
+bool HistoryManager::clearDownloadsHistory()
+{
+ QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads");
+ QFile downloadFile(downloadFilePath);
+ return downloadFile.remove();
+}
diff --git a/src/history/historymanager.h b/src/history/historymanager.h
index e744ca4b..8fc5c30e 100644
--- a/src/history/historymanager.h
+++ b/src/history/historymanager.h
@@ -57,7 +57,10 @@ public:
const QDateTime &d = QDateTime(),
const QString &t = QString()
)
- : title(t), url(u), dateTime(d) {}
+ : title(t)
+ , url(u),
+ dateTime(d)
+ {}
inline bool operator==(const HistoryItem &other) const
{
@@ -77,6 +80,29 @@ public:
};
+// ---------------------------------------------------------------------------------------------------------------
+
+
+class DownloadItem
+{
+public:
+ DownloadItem() {}
+ explicit DownloadItem(const QString &srcUrl,
+ const QString &destUrl,
+ const QDateTime &d
+ )
+ : srcUrlString(srcUrl)
+ , destUrlString(destUrl)
+ , dateTime(d)
+ {}
+
+ QString srcUrlString;
+ QString destUrlString;
+ QDateTime dateTime;
+};
+
+
+typedef QList<DownloadItem> DownloadList;
// ---------------------------------------------------------------------------------------------------------------
@@ -131,6 +157,10 @@ public:
*/
KCompletion *completionObject() const;
+ void addDownload(const QString &srcUrl, const QString &destUrl);
+ DownloadList downloads();
+ bool clearDownloadsHistory();
+
public slots:
void clear();
void loadSettings();
diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp
index 69a80b29..36ddafed 100644
--- a/src/newtabpage.cpp
+++ b/src/newtabpage.cpp
@@ -53,6 +53,9 @@
// Qt Includes
#include <QFile>
+// Defines
+#define QL1S(x) QLatin1String(x)
+
NewTabPage::NewTabPage(QWebFrame *frame)
: m_root(frame->documentElement())
@@ -124,6 +127,11 @@ void NewTabPage::generate(const KUrl &url)
bookmarksPage();
title = i18n("Bookmarks");
}
+ else if(url == KUrl("about:downloads"))
+ {
+ downloadsPage();
+ title = i18n("Downloads");
+ }
m_root.document().findFirst("title").setPlainText(title);
}
@@ -315,6 +323,13 @@ void NewTabPage::browsingMenu(const KUrl &currentUrl)
nav.findFirst("a").appendInside(i18n("History"));
navItems.append(nav);
+ nav = markup(".link"); // History
+ nav.findFirst("a").setAttribute("href", "about:downloads");
+ nav.findFirst("img").setAttribute("src" , QString("file:///" +
+ loader->iconPath("download", KIconLoader::Desktop ||KIconLoader::SizeSmall)));
+ nav.findFirst("a").appendInside(i18n("Downloads"));
+ navItems.append(nav);
+
QWebElement it;
foreach(it, navItems)
{
@@ -442,3 +457,39 @@ QString NewTabPage::checkTitle(const QString &title)
}
return t;
}
+
+
+void NewTabPage::downloadsPage()
+{
+ m_root.addClass("downloads");
+
+ DownloadList list = Application::historyManager()->downloads();
+
+ foreach(const DownloadItem &item, list)
+ {
+ m_root.appendInside(markup("h3"));
+ m_root.lastChild().setPlainText("");
+
+ KUrl u = KUrl(item.destUrlString);
+ QString fName = u.fileName();
+ QString dir = QL1S("file://") + u.directory();
+
+ m_root.appendInside( item.dateTime.toString("dddd") );
+ m_root.appendInside("<br/>");
+ m_root.appendInside( item.dateTime.toString("dd MMMM yyyy") );
+ m_root.appendInside(", ");
+ m_root.appendInside( item.dateTime.toString("hh:mm:ss") );
+ m_root.appendInside("<br/>");
+
+ m_root.appendInside(fName);
+ m_root.appendInside("<br/>");
+
+ m_root.appendInside(item.srcUrlString);
+ m_root.appendInside("<br/>");
+
+ m_root.appendInside(markup("a"));
+ m_root.lastChild().setAttribute("href" , dir);
+ m_root.lastChild().setPlainText("browse dir");
+ m_root.appendInside("<br/>");
+ }
+}
diff --git a/src/newtabpage.h b/src/newtabpage.h
index 6d3a7ea9..6604e4df 100644
--- a/src/newtabpage.h
+++ b/src/newtabpage.h
@@ -63,8 +63,8 @@ public:
private:
- // these are the "high-level" functions to build the new tab page
- // basically, you call browsingMenu + one the the *Page methods
+ // these are the "high-level" functions to build the new tab page.
+ // Basically, you call browsingMenu + one of the *Page methods
// to load a page
void browsingMenu(const KUrl &currentUrl);
@@ -72,7 +72,8 @@ private:
void historyPage();
void bookmarksPage();
void closedTabsPage();
-
+ void downloadsPage();
+
// --------------------------------------------------------------------------
// "low-level" functions
// we use these to create the pages over
diff --git a/src/protocolhandler.cpp b/src/protocolhandler.cpp
index 9d1560ed..faba894b 100644
--- a/src/protocolhandler.cpp
+++ b/src/protocolhandler.cpp
@@ -142,6 +142,8 @@ bool ProtocolHandler::preHandling(const QNetworkRequest &request, QWebFrame *fra
case 3: // history
_url = KUrl("about:history");
break;
+ case 4: // downloads
+ _url = KUrl("about:downloads");
default: // unuseful
break;
}
diff --git a/src/settings/settings_general.ui b/src/settings/settings_general.ui
index a4503d4a..98a56591 100644
--- a/src/settings/settings_general.ui
+++ b/src/settings/settings_general.ui
@@ -262,6 +262,11 @@
<string>History</string>
</property>
</item>
+ <item>
+ <property name="text">
+ <string>Downloads</string>
+ </property>
+ </item>
</widget>
</item>
</layout>
@@ -284,7 +289,7 @@
<widget class="QCheckBox" name="kcfg_kgetList">
<property name="whatsThis">
<string>If enabled, rekonq will display an additional context menu entry, which, when selected, lists all available links of the current website in KGet.</string>
- </property>
+ </property>
<property name="text">
<string>List links with KGet</string>
</property>
diff --git a/src/webpage.cpp b/src/webpage.cpp
index 42193ed0..0e7b3d8a 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -71,6 +71,9 @@
#include <QtGui/QKeyEvent>
#include <QWebFrame>
+// Defines
+#define QL1S(x) QLatin1String(x)
+
WebPage::WebPage(QWidget *parent)
: KWebPage(parent, KWalletIntegration)
@@ -292,55 +295,76 @@ QString WebPage::errorPage(QNetworkReply *reply)
}
+// WARNING
+// this code is actually copied from KWebPage::downloadRequest to save
+// downloads data before. If you have some better ideas about,
+// feel free to let us know about :)
void WebPage::downloadRequest(const QNetworkRequest &request)
{
- if (ReKonfig::kgetDownload())
- {
- //*Copy of kwebpage code (Shouldn't be done in kwebpage ?)
-
- KUrl destUrl;
- KUrl srcUrl (request.url());
- int result = KIO::R_OVERWRITE;
-
- do
- {
- destUrl = KFileDialog::getSaveFileName(srcUrl.fileName(), QString(), view());
-
- if (destUrl.isLocalFile())
- {
- QFileInfo finfo (destUrl.toLocalFile());
- if (finfo.exists())
- {
- QDateTime now = QDateTime::currentDateTime();
- QPointer<KIO::RenameDialog> dlg = new KIO::RenameDialog( view(), i18n("Overwrite File?"), srcUrl, destUrl,
- KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP),
- -1, finfo.size(),
- now.toTime_t(), finfo.created().toTime_t(),
- now.toTime_t(), finfo.lastModified().toTime_t());
- result = dlg->exec();
- delete dlg;
- }
- }
- }
- while (result == KIO::R_CANCEL && destUrl.isValid());
-
- if (result == KIO::R_OVERWRITE && destUrl.isValid())
+ KUrl destUrl;
+ KUrl srcUrl (request.url());
+ int result = KIO::R_OVERWRITE;
+
+ do
+ {
+ destUrl = KFileDialog::getSaveFileName(srcUrl.fileName(), QString(), view());
+
+ if (destUrl.isLocalFile())
+ {
+ QFileInfo finfo( destUrl.toLocalFile() );
+ if ( finfo.exists() )
+ {
+ QDateTime now = QDateTime::currentDateTime();
+ QPointer<KIO::RenameDialog> dlg = new KIO::RenameDialog( view(),
+ i18n("Overwrite File?"),
+ srcUrl,
+ destUrl,
+ KIO::RenameDialog_Mode(KIO::M_OVERWRITE | KIO::M_SKIP),
+ -1,
+ finfo.size(),
+ now.toTime_t(),
+ finfo.created().toTime_t(),
+ now.toTime_t(),
+ finfo.lastModified().toTime_t()
+ );
+ result = dlg->exec();
+ delete dlg;
+ }
+ }
+ }
+ while ( result == KIO::R_CANCEL && destUrl.isValid() );
+
+ // now store data
+ // now, destUrl, srcUrl
+ Application::historyManager()->addDownload( srcUrl.pathOrUrl() , destUrl.pathOrUrl() );
+
+ if ( result == KIO::R_OVERWRITE && destUrl.isValid() )
+ {
+ if ( ReKonfig::kgetDownload() )
{
- //*End of copy code
-
//KGet integration:
if(!QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kget"))
{
KToolInvocation::kdeinitExecWait("kget");
}
QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main");
- kget.call("addTransfer", srcUrl.prettyUrl(), destUrl.prettyUrl(), true);
+ if( kget.isValid() )
+ {
+ kget.call("addTransfer", srcUrl.prettyUrl(), destUrl.prettyUrl(), true);
+ return;
+ }
}
- return;
- }
-
- KWebPage::downloadRequest(request);
+ // else, use KIO or fallback to it
+ KIO::Job *job = KIO::file_copy(srcUrl, destUrl, -1, KIO::Overwrite);
+ QVariant attr = request.attribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData));
+ if (attr.isValid() && attr.type() == QVariant::Map)
+ job->setMetaData(KIO::MetaData(attr.toMap()));
+
+ job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache.
+ job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available.
+ job->uiDelegate()->setAutoErrorHandlingEnabled(true);
+ }
}
@@ -369,5 +393,8 @@ void WebPage::downloadAllContentsWithKGet()
KToolInvocation::kdeinitExecWait("kget");
}
QDBusInterface kget("org.kde.kget", "/KGet", "org.kde.kget.main");
- kget.call("importLinks", QVariant(contents.toList()));
+ if( kget.isValid() )
+ {
+ kget.call("importLinks", QVariant(contents.toList()));
+ }
}