diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks.cpp | 5 | ||||
-rw-r--r-- | src/cookiedialogs.cpp | 10 | ||||
-rw-r--r-- | src/download.cpp | 225 | ||||
-rw-r--r-- | src/edittableview.cpp | 1 | ||||
-rw-r--r-- | src/edittreeview.cpp | 1 | ||||
-rw-r--r-- | src/lineedit.cpp | 3 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/modelmenu.cpp | 1 | ||||
-rw-r--r-- | src/panelhistory.cpp | 3 | ||||
-rw-r--r-- | src/searchbar.cpp | 1 | ||||
-rw-r--r-- | src/stackedurlbar.cpp | 6 |
11 files changed, 244 insertions, 14 deletions
diff --git a/src/bookmarks.cpp b/src/bookmarks.cpp index 9490ed0f..bddacab4 100644 --- a/src/bookmarks.cpp +++ b/src/bookmarks.cpp @@ -44,8 +44,9 @@ #include <KUrl> // Qt Includes -#include <QActionGroup> -#include <QFile> +#include <QtCore/QFile> +#include <QtGui/QActionGroup> + BookmarkOwner::BookmarkOwner(QObject *parent) diff --git a/src/cookiedialogs.cpp b/src/cookiedialogs.cpp index 9b768f6a..43cbed81 100644 --- a/src/cookiedialogs.cpp +++ b/src/cookiedialogs.cpp @@ -18,14 +18,20 @@ * ============================================================ */ -// Local Includes +// Self Includes #include "cookiedialogs.h" -#include "cookiejar.h" +#include "cookiedialogs.moc" +// Ui Includes #include "ui_cookies.h" +// Local Includes +#include "cookiejar.h" + +// Qt Includes #include <QCompleter> + CookiesDialog::CookiesDialog(CookieJar *cookieJar, QWidget *parent) : KDialog(parent) { diff --git a/src/download.cpp b/src/download.cpp new file mode 100644 index 00000000..2f98d5a4 --- /dev/null +++ b/src/download.cpp @@ -0,0 +1,225 @@ +/* ============================================================ +* +* 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. +* +* ============================================================ */ + + +// Self 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/edittableview.cpp b/src/edittableview.cpp index 8b9bb12d..9ecf8958 100644 --- a/src/edittableview.cpp +++ b/src/edittableview.cpp @@ -21,6 +21,7 @@ // Self Includes #include "edittableview.h" +#include "edittableview.moc" // Qt Includes #include <QtGui/QKeyEvent> diff --git a/src/edittreeview.cpp b/src/edittreeview.cpp index 5547cdb0..8ca18d13 100644 --- a/src/edittreeview.cpp +++ b/src/edittreeview.cpp @@ -21,6 +21,7 @@ // Self Includes #include "edittreeview.h" +#include "edittreeview.moc" // Qt includes #include <QtGui/QKeyEvent> diff --git a/src/lineedit.cpp b/src/lineedit.cpp index dd90ce5a..e3185fc2 100644 --- a/src/lineedit.cpp +++ b/src/lineedit.cpp @@ -79,6 +79,3 @@ void LineEdit::focusOutEvent(QFocusEvent *event) setCursorPosition(0); deselect(); } - - - diff --git a/src/main.cpp b/src/main.cpp index 4a87ae53..009fc4b3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,8 +18,10 @@ * ============================================================ */ +// Local Includes #include "application.h" +// KDE Includes #include <KAboutData> #include <KCmdLineArgs> #include <KDebug> diff --git a/src/modelmenu.cpp b/src/modelmenu.cpp index 57b094ab..9ac9c512 100644 --- a/src/modelmenu.cpp +++ b/src/modelmenu.cpp @@ -21,6 +21,7 @@ // Self Includes #include "modelmenu.h" +#include "modelmenu.moc" ModelMenu::ModelMenu(QWidget * parent) diff --git a/src/panelhistory.cpp b/src/panelhistory.cpp index 8b736074..1282454a 100644 --- a/src/panelhistory.cpp +++ b/src/panelhistory.cpp @@ -32,9 +32,6 @@ #include <KLineEdit> #include <KUrl> -// Local Includes -#include "history.h" - PanelHistory::PanelHistory(QWidget *parent) : QWidget(parent) diff --git a/src/searchbar.cpp b/src/searchbar.cpp index 48e9290a..6d118a7d 100644 --- a/src/searchbar.cpp +++ b/src/searchbar.cpp @@ -129,4 +129,3 @@ void SearchBar::handleNetworkData(QNetworkReply *networkReply) networkReply->deleteLater(); } - diff --git a/src/stackedurlbar.cpp b/src/stackedurlbar.cpp index 113c8769..53a974fe 100644 --- a/src/stackedurlbar.cpp +++ b/src/stackedurlbar.cpp @@ -22,14 +22,14 @@ #include "stackedurlbar.h" #include "stackedurlbar.moc" -// KDE Includes -#include "kdebug.h" - // Local Includes #include "application.h" #include "history.h" #include "urlbar.h" +// KDE Includes +#include <KDebug> + StackedUrlBar::StackedUrlBar(QWidget *parent) : QStackedWidget(parent) |