summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO1
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/application.cpp74
-rw-r--r--src/application.h7
-rw-r--r--src/download.cpp225
-rw-r--r--src/download.h141
-rw-r--r--src/historydialog.cpp7
-rw-r--r--src/mainview.cpp6
-rw-r--r--src/mainwindow.cpp64
-rw-r--r--src/mainwindow.h1
-rw-r--r--src/webpage.cpp1
-rw-r--r--src/webview.cpp1
12 files changed, 73 insertions, 456 deletions
diff --git a/TODO b/TODO
index a7055fea..40ccda35 100644
--- a/TODO
+++ b/TODO
@@ -20,4 +20,5 @@ TO 0.2 release
- bookmarks panel
- MimeType Manager
- BETTER KDE INTEGRATION (What else to be done??)
+- error pages
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4a3f5fed..6b9af51f 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -10,7 +10,6 @@ SET( rekonq_SRCS
history.cpp
historydialog.cpp
historymenu.cpp
- download.cpp
bookmarks.cpp
modelmenu.cpp
networkaccessmanager.cpp
diff --git a/src/application.cpp b/src/application.cpp
index 5f7892c4..09a8a087 100644
--- a/src/application.cpp
+++ b/src/application.cpp
@@ -34,7 +34,6 @@
#include "networkaccessmanager.h"
#include "mainview.h"
#include "webview.h"
-#include "download.h"
// KDE Includes
#include <KCmdLineArgs>
@@ -52,7 +51,6 @@
QPointer<HistoryManager> Application::s_historyManager;
QPointer<NetworkAccessManager> Application::s_networkAccessManager;
-QPointer<DownloadManager> Application::s_downloadManager;
QPointer<BookmarkProvider> Application::s_bookmarkProvider;
@@ -93,7 +91,7 @@ int Application::newInstance()
{
for (int i = 0; i < args->count(); ++i)
{
- KUrl url = MainWindow::guessUrlFromString(args->arg(i));
+ KUrl url = guessUrlFromString(args->arg(i));
newWebView();
mainWindow()->loadUrl(url);
}
@@ -150,7 +148,7 @@ WebView *Application::newWebView(Rekonq::OpenType type)
CookieJar *Application::cookieJar()
{
- return (CookieJar*)networkAccessManager()->cookieJar();
+ return (CookieJar *)networkAccessManager()->cookieJar();
}
@@ -176,16 +174,6 @@ HistoryManager *Application::historyManager()
}
-DownloadManager *Application::downloadManager()
-{
- if (!s_downloadManager)
- {
- s_downloadManager = new DownloadManager();
- }
- return s_downloadManager;
-}
-
-
BookmarkProvider *Application::bookmarkProvider()
{
if (!s_bookmarkProvider)
@@ -206,3 +194,61 @@ KIcon Application::icon(const KUrl &url) const
return icon;
}
+
+KUrl Application::guessUrlFromString(const QString &string)
+{
+ QString urlStr = string.trimmed();
+ QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*"));
+
+ // Check if it looks like a qualified URL. Try parsing it and see.
+ bool hasSchema = test.exactMatch(urlStr);
+
+ if (hasSchema)
+ {
+ QUrl qurl(urlStr, QUrl::TolerantMode);
+ KUrl url(qurl);
+
+ if (url.isValid())
+ {
+ return url;
+ }
+ }
+
+ // Might be a file.
+ if (QFile::exists(urlStr))
+ {
+ QFileInfo info(urlStr);
+ return KUrl::fromPath(info.absoluteFilePath());
+ }
+
+ // Might be a shorturl - try to detect the schema.
+ if (!hasSchema)
+ {
+ int dotIndex = urlStr.indexOf(QLatin1Char('.'));
+
+ if (dotIndex != -1)
+ {
+ QString prefix = urlStr.left(dotIndex).toLower();
+ QString schema = (prefix == QLatin1String("ftp")) ? prefix : QLatin1String("http");
+ QUrl qurl(schema + QLatin1String("://") + urlStr, QUrl::TolerantMode);
+ KUrl url(qurl);
+
+ if (url.isValid())
+ {
+ return url;
+ }
+ }
+ }
+
+ // Fall back to QUrl's own tolerant parser.
+ QUrl qurl = QUrl(string, QUrl::TolerantMode);
+ KUrl url(qurl);
+
+ // finally for cases where the user just types in a hostname add http
+ if (qurl.scheme().isEmpty())
+ {
+ qurl = QUrl(QLatin1String("http://") + string, QUrl::TolerantMode);
+ url = KUrl(qurl);
+ }
+ return url;
+}
diff --git a/src/application.h b/src/application.h
index e0c7a21c..e61b2a31 100644
--- a/src/application.h
+++ b/src/application.h
@@ -40,7 +40,6 @@ class KIcon;
class KUrl;
class BookmarkProvider;
class CookieJar;
-class DownloadManager;
class HistoryManager;
class MainWindow;
class NetworkAccessManager;
@@ -76,14 +75,15 @@ public:
static Application *instance();
MainWindow *mainWindow();
- WebView* newWebView(Rekonq::OpenType type = Rekonq::Default);
+ WebView *newWebView(Rekonq::OpenType type = Rekonq::Default);
KIcon icon(const KUrl &url) const;
+ static KUrl guessUrlFromString(const QString &url);
+
static HistoryManager *historyManager();
static CookieJar *cookieJar();
static NetworkAccessManager *networkAccessManager();
- static DownloadManager *downloadManager();
static BookmarkProvider *bookmarkProvider();
public slots:
@@ -105,7 +105,6 @@ private slots:
private:
static QPointer<HistoryManager> s_historyManager;
static QPointer<NetworkAccessManager> s_networkAccessManager;
- static QPointer<DownloadManager> s_downloadManager;
static QPointer<BookmarkProvider> s_bookmarkProvider;
QPointer<MainWindow> m_mainWindow;
diff --git a/src/download.cpp b/src/download.cpp
deleted file mode 100644
index c365d3c5..00000000
--- a/src/download.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2007 Lukas Appelhans <l.appelhans@gmx.de>
-* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com>
-* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
-* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com>
-*
-*
-* 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 2, 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.
-*
-* ============================================================ */
-
-
-// local Includes
-#include "download.h"
-#include "download.moc"
-
-// KDE Includes
-#include <KDebug>
-#include <KFileDialog>
-#include <KGlobalSettings>
-#include <KMessageBox>
-#include <KMimeType>
-#include <KStandardDirs>
-
-// Qt Includes
-#include <QFile>
-#include <QFileInfo>
-
-// Local Includes
-#include "application.h"
-#include "mainwindow.h"
-
-
-DownloadManager::DownloadManager()
- : QObject()
-{
-}
-
-
-DownloadManager::~DownloadManager()
-{
- foreach(Download *download, m_downloads)
- {
- // cancel all unfinished downloads
- download->cancel();
- delete download;
- }
-}
-
-
-void DownloadManager::newDownload(const KUrl &srcUrl, const KUrl &destUrl)
-{
- KUrl destination = destUrl;
- Download::DownloadType type;
-
- KSharedPtr<KMimeType> mimeType = KMimeType::findByPath(srcUrl.prettyUrl());
-
- QString typeText = KMimeType::extractKnownExtension(srcUrl.fileName());
- typeText += " (" + mimeType->name() + ')';
-
- int answer = KMessageBox::questionYesNoCancel(
- NULL,
- i18n("Download '%1'?\n""Type: %2", srcUrl.prettyUrl(), typeText),
- i18n("Download '%1'...", srcUrl.fileName()),
- KStandardGuiItem::save(),
- KStandardGuiItem::open(),
- KStandardGuiItem::cancel()
- );
-
- switch (answer)
- {
- case KMessageBox::Cancel:
- return;
- break;
-
- case KMessageBox::Yes: // ----- SAVE
- // if destination is empty than ask for download path (if showOpenSaveDownloadDialog setting enabled)
- if (destination.isEmpty())
- {
- destination = downloadDestination(srcUrl.fileName());
- }
- type = Download::Save;
- break;
-
- case KMessageBox::No: // ----- OPEN
- // Download file to tmp dir
- destination.setDirectory(KStandardDirs::locateLocal("tmp", "", true));
- destination.addPath(srcUrl.fileName());
- type = Download::Open;
- break;
-
- default:
- // impossible
- break;
- };
-
- // if user canceled download than abort
- if (destination.isEmpty())
- return;
-
- Download *download = new Download(srcUrl, destination, type);
- connect(download, SIGNAL(downloadFinished(int)), this, SLOT(slotDownloadFinished(int)));
- m_downloads.append(download);
-}
-
-
-const QList<Download *> &DownloadManager::downloads() const
-{
- return m_downloads;
-}
-
-
-KUrl DownloadManager::downloadDestination(const QString &filename)
-{
- KUrl destination = ReKonfig::downloadDir();
- if (destination.isEmpty())
- destination = KGlobalSettings::downloadPath();
- destination.addPath(filename);
-
- if (!ReKonfig::downloadToDefaultDir())
- {
- destination = KFileDialog::getSaveUrl(destination);
- // if user canceled the download return empty url
- if (destination.isEmpty())
- return KUrl();
- }
- return destination;
-}
-
-
-void DownloadManager::slotDownloadFinished(int errorCode)
-{
- Q_UNUSED(errorCode)
-
- // if sender exists and list contains it - (open and) delete it
- Download *download = qobject_cast<Download *>(sender());
- if (download && m_downloads.contains(download))
- {
- if (download->type() == Download::Open)
- {
- KSharedPtr<KMimeType> mimeType = KMimeType::findByPath(download->destUrl().prettyUrl());
- KRun::runUrl(download->destUrl(), mimeType->name(), NULL, true);
- }
- disconnect(download, SIGNAL(downloadFinished(int)), this, SLOT(slotDownloadFinished(int)));
- int index = m_downloads.indexOf(download);
- delete m_downloads.takeAt(index);
- return;
- }
- kWarning() << "Could not find download or invalid sender. Sender:" << sender();
-}
-
-
-//----
-
-#include <KJob>
-#include <KIO/Job>
-#include <KIO/CopyJob>
-
-
-Download::Download(const KUrl &srcUrl, const KUrl &destUrl, DownloadType type)
- : QObject()
- , m_srcUrl(srcUrl)
- , m_destUrl(destUrl)
- , m_type(type)
-{
- Q_ASSERT(!m_srcUrl.isEmpty());
- Q_ASSERT(!m_destUrl.isEmpty());
- kDebug() << "DownloadFile: " << m_srcUrl.url() << " to dest: " << m_destUrl.url();
-
- m_copyJob = KIO::file_copy(m_srcUrl, m_destUrl);
- connect(m_copyJob, SIGNAL(result(KJob *)), SLOT(slotResult(KJob *)));
-}
-
-
-Download::~Download()
-{
-}
-
-
-void Download::cancel()
-{
- bool result = m_copyJob->kill(KJob::EmitResult);
- Q_ASSERT(result);
-}
-
-
-void Download::slotResult(KJob *job)
-{
- switch (job->error())
- {
- case 0: //The download has finished
- {
- kDebug() << "Downloading successfully finished: " << m_destUrl.url();
- break;
- }
- case KIO::ERR_FILE_ALREADY_EXIST:
- {
- kWarning() << "ERROR - File already exists";
- break;
- }
- case KIO::ERR_USER_CANCELED:
- {
- kWarning() << "ERROR - User canceled the downlaod";
- break;
- }
- default:
- kWarning() << "We are sorry to say you, that there were errors while downloading :(";
- break;
- }
-
- // inform the world
- emit downloadFinished(job->error());
-}
-
diff --git a/src/download.h b/src/download.h
deleted file mode 100644
index 0502d500..00000000
--- a/src/download.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/* ============================================================
-*
-* This file is a part of the rekonq project
-*
-* Copyright (C) 2007 Lukas Appelhans <l.appelhans@gmx.de>
-* Copyright (C) 2008-2009 by Andrea Diamantini <adjam7 at gmail dot com>
-* Copyright (C) 2009 by Paweł Prażak <pawelprazak at gmail dot com>
-* Copyright (C) 2009 by Domrachev Alexandr <alexandr.domrachev@gmail.com>
-*
-*
-* 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 2, 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.
-*
-* ============================================================ */
-
-
-#ifndef DOWNLOAD_H
-#define DOWNLOAD_H
-
-// Auto Includes
-#include "rekonq.h"
-
-// KDE Includes
-#include <KIO/FileCopyJob>
-
-// Qt Includes
-#include <QtCore/QObject>
-
-// Forward Declarations
-class KJob;
-
-namespace KIO
-{
-class Job;
-}
-
-
-/**
- * This class lets rekonq to download an object from the network.
- * Creating a new object, you can continue downloading a file also
- * when rekonq is closed.
- *
- */
-class Download : public QObject
-{
- Q_OBJECT
-
-public:
- enum DownloadType { Save, Open };
-
- /**
- * Class constructor. This is the unique method we need to
- * use this class. In fact Download class needs to know just
- * "where" catch the file to download and where it has to put it
- *
- * @param srcUrl the source url
- * @param destUrl the destination url
- *
- */
- Download(const KUrl &srcUrl, const KUrl &destUrl, DownloadType type);
-
- /**
- * class destructor
- */
- ~Download();
-
- KUrl srcUrl() const
- {
- return m_srcUrl;
- }
- KUrl destUrl() const
- {
- return m_destUrl;
- }
- DownloadType type() const
- {
- return m_type;
- }
- void cancel();
-
-signals:
- void downloadFinished(int errorCode);
-
-private slots:
- void slotResult(KJob *job);
-
-private:
- KIO::FileCopyJob *m_copyJob;
- KUrl m_srcUrl;
- KUrl m_destUrl;
- KUrl m_destFile;
- QByteArray m_data;
- DownloadType m_type;
-};
-
-
-// ----------------------
-
-
-class DownloadManager : public QObject
-{
- Q_OBJECT
-
-public:
- DownloadManager();
- ~DownloadManager();
-
- /**
- * @short Creates new download job.
- * This method lets you to download a file from a remote source url
- * to a local destination url.
- *
- * @param srcUrl the source url
- * @param destUrl the destination url (default value is your default download destination setting)
- *
- */
- void newDownload(const KUrl &srcUrl, const KUrl &destUrl = KUrl());
-
- const QList<Download *> &downloads() const;
-
-public slots:
- void slotDownloadFinished(int errorCode);
-
-private:
- KUrl downloadDestination(const QString &filename);
-
- QList<Download *> m_downloads;
-};
-
-
-//--
-
-
-#endif
diff --git a/src/historydialog.cpp b/src/historydialog.cpp
index da1c5858..f4aea3bb 100644
--- a/src/historydialog.cpp
+++ b/src/historydialog.cpp
@@ -69,13 +69,16 @@ HistoryDialog::HistoryDialog(QWidget *parent, HistoryManager *setHistory)
m_historyWidg->tree->setAlternatingRowColors(true);
QFontMetrics fm(font());
- int header = fm.width(QLatin1Char('m')) * 40;
+ int header = fm.width(QLatin1Char('m')) * 30;
m_historyWidg->tree->header()->resizeSection(0, header);
m_historyWidg->tree->header()->setStretchLastSection(true);
- connect(m_historyWidg->tree, SIGNAL(activated(const QModelIndex&)), this, SLOT(open()));
+
m_historyWidg->tree->setContextMenuPolicy(Qt::CustomContextMenu);
+
connect(m_historyWidg->tree, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(customContextMenuRequested(const QPoint &)));
+
+ connect(m_historyWidg->tree, SIGNAL(activated(const QModelIndex&)), this, SLOT(open()));
}
diff --git a/src/mainview.cpp b/src/mainview.cpp
index d8d1c2b5..ea56527d 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -362,10 +362,8 @@ WebView *MainView::newWebView(Rekonq::OpenType type)
connect(webView, SIGNAL(shiftCtrlTabPressed()), this, SLOT(previousTab()));
// connecting webPage signals with mainview
- connect(webView->page(), SIGNAL(windowCloseRequested()),
- this, SLOT(windowCloseRequested()));
- connect(webView->page(), SIGNAL(printRequested(QWebFrame *)),
- this, SIGNAL(printRequested(QWebFrame *)));
+ connect(webView->page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested()));
+ connect(webView->page(), SIGNAL(printRequested(QWebFrame *)), this, SIGNAL(printRequested(QWebFrame *)));
addTab(webView, i18n("(Untitled)"));
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 0c7a0984..26ffbc11 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -37,7 +37,6 @@
#include "webview.h"
#include "mainview.h"
#include "bookmarks.h"
-#include "download.h"
#include "findbar.h"
#include "sidepanel.h"
#include "urlbar.h"
@@ -410,65 +409,6 @@ void MainWindow::slotUpdateBrowser()
}
-KUrl MainWindow::guessUrlFromString(const QString &string)
-{
- QString urlStr = string.trimmed();
- QRegExp test(QLatin1String("^[a-zA-Z]+\\:.*"));
-
- // Check if it looks like a qualified URL. Try parsing it and see.
- bool hasSchema = test.exactMatch(urlStr);
-
- if (hasSchema)
- {
- QUrl qurl(urlStr, QUrl::TolerantMode);
- KUrl url(qurl);
-
- if (url.isValid())
- {
- return url;
- }
- }
-
- // Might be a file.
- if (QFile::exists(urlStr))
- {
- QFileInfo info(urlStr);
- return KUrl::fromPath(info.absoluteFilePath());
- }
-
- // Might be a shorturl - try to detect the schema.
- if (!hasSchema)
- {
- int dotIndex = urlStr.indexOf(QLatin1Char('.'));
-
- if (dotIndex != -1)
- {
- QString prefix = urlStr.left(dotIndex).toLower();
- QString schema = (prefix == QLatin1String("ftp")) ? prefix : QLatin1String("http");
- QUrl qurl(schema + QLatin1String("://") + urlStr, QUrl::TolerantMode);
- KUrl url(qurl);
-
- if (url.isValid())
- {
- return url;
- }
- }
- }
-
- // Fall back to QUrl's own tolerant parser.
- QUrl qurl = QUrl(string, QUrl::TolerantMode);
- KUrl url(qurl);
-
- // finally for cases where the user just types in a hostname add http
- if (qurl.scheme().isEmpty())
- {
- qurl = QUrl(QLatin1String("http://") + string, QUrl::TolerantMode);
- url = KUrl(qurl);
- }
- return url;
-}
-
-
void MainWindow::loadUrl(const KUrl &url)
{
m_view->loadUrl(url);
@@ -485,7 +425,7 @@ void MainWindow::slotOpenLocation()
void MainWindow::slotFileSaveAs()
{
KUrl srcUrl = currentTab()->url();
- Application::downloadManager()->newDownload(srcUrl);
+ // FIXME implement download file
}
@@ -544,7 +484,7 @@ void MainWindow::slotFileOpen()
if (filePath.isEmpty())
return;
- loadUrl(guessUrlFromString(filePath));
+ loadUrl(Application::guessUrlFromString(filePath));
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 7d0b2e5c..cc0aa2e8 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -62,7 +62,6 @@ public:
MainWindow();
~MainWindow();
- static KUrl guessUrlFromString(const QString &url);
MainView *mainView() const;
WebView *currentTab() const;
QAction *actionByName(const QString name);
diff --git a/src/webpage.cpp b/src/webpage.cpp
index cfbc32cf..193f2a82 100644
--- a/src/webpage.cpp
+++ b/src/webpage.cpp
@@ -32,7 +32,6 @@
#include "mainview.h"
#include "cookiejar.h"
#include "networkaccessmanager.h"
-#include "download.h"
#include "history.h"
#include "webview.h"
diff --git a/src/webview.cpp b/src/webview.cpp
index 216c2bd1..0ba33682 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -34,7 +34,6 @@
#include "mainview.h"
#include "cookiejar.h"
#include "networkaccessmanager.h"
-#include "download.h"
#include "history.h"
#include "webpage.h"