summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2012-05-13 12:05:06 +0200
committerAndrea Diamantini <adjam7@gmail.com>2012-05-15 09:53:43 +0200
commitf56f2761ed68aee64fc334230e4fc34f1a7e2213 (patch)
tree2d974dd2cf9252190e42724fab16faccd288ef67 /src
parentClean up NewTabPage API a bit (diff)
downloadrekonq-f56f2761ed68aee64fc334230e4fc34f1a7e2213.tar.xz
Improve downloads page
- remove from list (+ API for DownloadManager to save changes) - open dir in extern app - css
Diffstat (limited to 'src')
-rw-r--r--src/data/home.html2
-rw-r--r--src/downloadmanager.cpp36
-rw-r--r--src/downloadmanager.h15
-rw-r--r--src/newtabpage.cpp29
4 files changed, 76 insertions, 6 deletions
diff --git a/src/data/home.html b/src/data/home.html
index f4b4d12d..295d5d78 100644
--- a/src/data/home.html
+++ b/src/data/home.html
@@ -204,7 +204,7 @@ width: 28%;
/* Downloads page */
.download {
-margin: 1.5em 0;
+margin: 2em 5em;
}
.download img {
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 4dc7e670..5a2467d3 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -59,11 +59,38 @@
DownloadManager::DownloadManager(QObject *parent)
: QObject(parent)
+ , m_needToSave(false)
{
init();
}
+DownloadManager::~DownloadManager()
+{
+ if (!m_needToSave)
+ return;
+
+ QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads");
+ QFile downloadFile(downloadFilePath);
+
+ if (!downloadFile.open(QFile::WriteOnly))
+ {
+ kDebug() << "Unable to open download file (WRITE mode)..";
+ return;
+ }
+
+ QDataStream out(&downloadFile);
+ Q_FOREACH(DownloadItem * item, m_downloadList)
+ {
+ out << item->originUrl();
+ out << item->destinationUrl();
+ out << item->dateTime();
+ }
+
+ downloadFile.close();
+}
+
+
void DownloadManager::init()
{
QString downloadFilePath = KStandardDirs::locateLocal("appdata" , "downloads");
@@ -136,6 +163,15 @@ void DownloadManager::downloadLinksWithKGet(const QVariant &contentList)
}
+void DownloadManager::removeDownloadItem(int index)
+{
+ DownloadItem *item = m_downloadList.takeAt(index);
+ delete item;
+
+ m_needToSave = true;
+}
+
+
// NOTE
// These 2 functions have been copied from the KWebPage class to implement a local version of the downloadResponse method.
// In this way, we can easily provide the extra functionality we need:
diff --git a/src/downloadmanager.h b/src/downloadmanager.h
index c3a91939..7033ef6c 100644
--- a/src/downloadmanager.h
+++ b/src/downloadmanager.h
@@ -53,7 +53,8 @@ class REKONQ_TESTS_EXPORT DownloadManager : public QObject
public:
DownloadManager(QObject *parent = 0);
-
+ ~DownloadManager();
+
DownloadList downloads() const
{
return m_downloadList;
@@ -66,15 +67,21 @@ public:
void downloadLinksWithKGet(const QVariant &contentList);
+ void removeDownloadItem(int index);
+
+private:
+ void init();
+
+ DownloadItem* addDownload(const QString &srcUrl, const QString &destUrl);
+
Q_SIGNALS:
void newDownloadAdded(QObject *item);
void notifyDownload(const QString&, Rekonq::Notify = Rekonq::Download);
private:
- void init();
- DownloadItem* addDownload(const QString &srcUrl, const QString &destUrl);
-
DownloadList m_downloadList;
+
+ bool m_needToSave;
};
#endif // DOWNLOADMANAGER_H
diff --git a/src/newtabpage.cpp b/src/newtabpage.cpp
index abcd41eb..54c0e437 100644
--- a/src/newtabpage.cpp
+++ b/src/newtabpage.cpp
@@ -53,6 +53,7 @@
#include <KIconLoader>
#include <KLocale>
#include <KMimeType>
+#include <KRun>
#include <KStandardDirs>
// Qt Includes
@@ -217,6 +218,21 @@ void NewTabPage::generate(const KUrl &url)
return;
}
+ if (url.fileName() == QL1S("opendir"))
+ {
+ QString value = url.queryItemValue( QL1S("q") );
+ KUrl dirUrl = KUrl(value);
+ (void)new KRun(dirUrl, rApp->mainWindow(), 0, dirUrl.isLocalFile());
+ return;
+ }
+
+ if (url.fileName() == QL1S("removeItem"))
+ {
+ int value = url.queryItemValue( QL1S("item") ).toInt();
+ rApp->downloadManager()->removeDownloadItem(value);
+ loadPageForUrl(KUrl("about:downloads"));
+ return;
+ }
}
if (url == KUrl("about:bookmarks/edit"))
@@ -562,6 +578,8 @@ void NewTabPage::downloadsPage(const QString & filter)
return;
}
+ int i = 0;
+
Q_FOREACH(DownloadItem * item, list)
{
KUrl u = KUrl(item->destinationUrl());
@@ -602,7 +620,7 @@ void NewTabPage::downloadsPage(const QString & filter)
{
div.appendInside(markup(QL1S("a")));
div.lastChild().setAttribute(QL1S("class"), QL1S("greylink"));
- div.lastChild().setAttribute(QL1S("href"), QL1S("file://") + dir);
+ div.lastChild().setAttribute(QL1S("href"), QL1S("about:downloads/opendir?q=") + QL1S("file://") + dir);
div.lastChild().setPlainText(i18n("Open directory"));
div.appendInside(QL1S(" - "));
@@ -616,6 +634,15 @@ void NewTabPage::downloadsPage(const QString & filter)
{
div.appendInside(QL1S("<em>") + QL1S("Removed") + QL1S("</em>"));
}
+
+ div.appendInside(QL1S(" - "));
+
+ div.appendInside(markup(QL1S("a")));
+ div.lastChild().setAttribute(QL1S("class"), QL1S("greylink"));
+ div.lastChild().setAttribute(QL1S("href"), QL1S("about:downloads/removeItem?item=") + QString::number(i));
+ div.lastChild().setPlainText(i18n("Remove from list"));
+
+ i++;
}
}