Work on downloader.

This commit is contained in:
Martin Rotter 2015-01-09 19:55:45 +01:00
parent c3aeb0e9db
commit 50ef9c6981
23 changed files with 436 additions and 670 deletions

View File

@ -355,6 +355,8 @@ set(APP_SOURCES
src/gui/styleditemdelegatewithoutfocus.cpp src/gui/styleditemdelegatewithoutfocus.cpp
src/gui/formbackupdatabasesettings.cpp src/gui/formbackupdatabasesettings.cpp
src/gui/formrestoredatabasesettings.cpp src/gui/formrestoredatabasesettings.cpp
src/gui/edittableview.cpp
src/gui/squeezelabel.cpp
# DYNAMIC-SHORTCUTS sources. # DYNAMIC-SHORTCUTS sources.
src/dynamic-shortcuts/shortcutcatcher.cpp src/dynamic-shortcuts/shortcutcatcher.cpp
@ -373,6 +375,7 @@ set(APP_SOURCES
src/miscellaneous/skinfactory.cpp src/miscellaneous/skinfactory.cpp
src/miscellaneous/iconfactory.cpp src/miscellaneous/iconfactory.cpp
src/miscellaneous/iofactory.cpp src/miscellaneous/iofactory.cpp
src/miscellaneous/autosaver.cpp
# CORE sources. # CORE sources.
src/core/messagesmodel.cpp src/core/messagesmodel.cpp
@ -398,9 +401,6 @@ set(APP_SOURCES
src/network-web/webview.cpp src/network-web/webview.cpp
src/network-web/downloader.cpp src/network-web/downloader.cpp
src/network-web/downloadmanager.cpp src/network-web/downloadmanager.cpp
src/network-web/edittableview.cpp
src/network-web/autosaver.cpp
src/network-web/squeezelabel.cpp
# MAIN sources. # MAIN sources.
src/main.cpp src/main.cpp
@ -446,6 +446,8 @@ set(APP_HEADERS
src/gui/formimportexport.h src/gui/formimportexport.h
src/gui/formbackupdatabasesettings.h src/gui/formbackupdatabasesettings.h
src/gui/formrestoredatabasesettings.h src/gui/formrestoredatabasesettings.h
src/gui/edittableview.h
src/gui/squeezelabel.h
# DYNAMIC-SHORTCUTS headers. # DYNAMIC-SHORTCUTS headers.
src/dynamic-shortcuts/dynamicshortcutswidget.h src/dynamic-shortcuts/dynamicshortcutswidget.h
@ -460,6 +462,7 @@ set(APP_HEADERS
src/miscellaneous/databasefactory.h src/miscellaneous/databasefactory.h
src/miscellaneous/iconfactory.h src/miscellaneous/iconfactory.h
src/miscellaneous/skinfactory.h src/miscellaneous/skinfactory.h
src/miscellaneous/autosaver.h
# CORE headers. # CORE headers.
src/core/messagesmodel.h src/core/messagesmodel.h
@ -479,9 +482,6 @@ set(APP_HEADERS
src/network-web/webview.h src/network-web/webview.h
src/network-web/downloader.h src/network-web/downloader.h
src/network-web/downloadmanager.h src/network-web/downloadmanager.h
src/network-web/edittableview.h
src/network-web/autosaver.h
src/network-web/squeezelabel.h
) )
# APP form files. # APP form files.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

69
src/gui/edittableview.cpp Normal file
View File

@ -0,0 +1,69 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard 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 3 of the License, or
// (at your option) any later version.
//
// RSS Guard 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.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#include "edittableview.h"
#include <qevent.h>
EditTableView::EditTableView(QWidget *parent)
: QTableView(parent)
{
}
void EditTableView::keyPressEvent(QKeyEvent *event)
{
if (model() && event->key() == Qt::Key_Delete) {
removeSelected();
event->setAccepted(true);
} else {
QAbstractItemView::keyPressEvent(event);
}
}
void EditTableView::removeSelected()
{
if (!model() || !selectionModel() || !selectionModel()->hasSelection())
return;
QModelIndexList selectedRows = selectionModel()->selectedRows();
if (selectedRows.isEmpty())
return;
int newSelectedRow = selectedRows.at(0).row();
for (int i = selectedRows.count() - 1; i >= 0; --i) {
QModelIndex idx = selectedRows.at(i);
model()->removeRow(idx.row(), rootIndex());
}
// select the item at the same position
QModelIndex newSelectedIndex = model()->index(newSelectedRow, 0, rootIndex());
// if that was the last item
if (!newSelectedIndex.isValid())
newSelectedIndex = model()->index(newSelectedRow - 1, 0, rootIndex());
selectionModel()->select(newSelectedIndex, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
setCurrentIndex(newSelectedIndex);
}
void EditTableView::removeAll()
{
if (!model())
return;
model()->removeRows(0, model()->rowCount(rootIndex()), rootIndex());
}

37
src/gui/edittableview.h Normal file
View File

@ -0,0 +1,37 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard 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 3 of the License, or
// (at your option) any later version.
//
// RSS Guard 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.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#ifndef EDITTABLEVIEW_H
#define EDITTABLEVIEW_H
#include <qtableview.h>
class EditTableView : public QTableView
{
Q_OBJECT
public:
EditTableView(QWidget *parent = 0);
void keyPressEvent(QKeyEvent *event);
public slots:
void removeSelected();
void removeAll();
};
#endif // EDITTABLEVIEW_H

37
src/gui/squeezelabel.cpp Normal file
View File

@ -0,0 +1,37 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard 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 3 of the License, or
// (at your option) any later version.
//
// RSS Guard 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.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#include "squeezelabel.h"
SqueezeLabel::SqueezeLabel(QWidget *parent)
: QLabel(parent)
{
}
void SqueezeLabel::paintEvent(QPaintEvent *event)
{
if (m_SqueezedTextCache != text()) {
m_SqueezedTextCache = text();
QFontMetrics fm = fontMetrics();
if (fm.width(m_SqueezedTextCache) > contentsRect().width()) {
QString elided = fm.elidedText(text(), Qt::ElideMiddle, width());
setText(elided);
}
}
QLabel::paintEvent(event);
}

42
src/gui/squeezelabel.h Normal file
View File

@ -0,0 +1,42 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard 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 3 of the License, or
// (at your option) any later version.
//
// RSS Guard 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.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#ifndef SQUEEZELABEL_H
#define SQUEEZELABEL_H
#include <qlabel.h>
/*
A label that will squeeze the set text to fit within the size of the
widget. The text will be elided in the middle.
*/
class SqueezeLabel : public QLabel
{
Q_OBJECT
public:
SqueezeLabel(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *event);
private:
QString m_SqueezedTextCache;
};
#endif // SQUEEZELABEL_H

View File

@ -112,7 +112,7 @@ void TabBar::mousePressEvent(QMouseEvent *event) {
// NOTE: This needs to be done here because // NOTE: This needs to be done here because
// destination does not know the original event. // destination does not know the original event.
if (event->button() & Qt::MiddleButton && qApp->settings()->value(GROUP(GUI), SETTING(GUI::TabCloseMiddleClick)).toBool()) { if (event->button() & Qt::MiddleButton && qApp->settings()->value(GROUP(GUI), SETTING(GUI::TabCloseMiddleClick)).toBool()) {
if (tabType(tab_index) == TabBar::Closable) { if (tabType(tab_index) == TabBar::Closable || tabType(tab_index) == TabBar::DownloadManager) {
// This tab is closable, so we can close it. // This tab is closable, so we can close it.
emit tabCloseRequested(tab_index); emit tabCloseRequested(tab_index);
} }

View File

@ -0,0 +1,74 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard 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 3 of the License, or
// (at your option) any later version.
//
// RSS Guard 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.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#include "autosaver.h"
#include <qdir.h>
#include <qcoreapplication.h>
#include <qmetaobject.h>
#include <qdebug.h>
#define AUTOSAVE_IN 1000 * 3 // seconds
#define MAXWAIT 1000 * 15 // seconds
AutoSaver::AutoSaver(QObject *parent) : QObject(parent)
{
Q_ASSERT(parent);
}
AutoSaver::~AutoSaver()
{
if (m_timer.isActive()) {
qWarning() << "AutoSaver: still active when destroyed, changes not saved.";
if (parent() && parent()->metaObject())
qWarning() << parent() << parent()->metaObject()->className() << "should call saveIfNeccessary";
}
}
void AutoSaver::changeOccurred()
{
if (m_firstChange.isNull())
m_firstChange.start();
if (m_firstChange.elapsed() > MAXWAIT) {
saveIfNeccessary();
} else {
m_timer.start(AUTOSAVE_IN, this);
}
}
void AutoSaver::timerEvent(QTimerEvent *event)
{
if (event->timerId() == m_timer.timerId()) {
saveIfNeccessary();
} else {
QObject::timerEvent(event);
}
}
void AutoSaver::saveIfNeccessary()
{
if (!m_timer.isActive())
return;
m_timer.stop();
m_firstChange = QTime();
if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection)) {
qWarning() << "AutoSaver: error invoking slot save() on parent";
}
}

View File

@ -0,0 +1,53 @@
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
//
// RSS Guard 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 3 of the License, or
// (at your option) any later version.
//
// RSS Guard 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.
//
// You should have received a copy of the GNU General Public License
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
#ifndef AUTOSAVER_H
#define AUTOSAVER_H
#include <qobject.h>
#include <qbasictimer.h>
#include <qdatetime.h>
/*
This class will call the save() slot on the parent object when the parent changes.
It will wait several seconds after changed() to combining multiple changes and
prevent continuous writing to disk.
*/
class AutoSaver : public QObject
{
Q_OBJECT
public:
AutoSaver(QObject *parent);
~AutoSaver();
void saveIfNeccessary();
public slots:
void changeOccurred();
protected:
void timerEvent(QTimerEvent *event);
private:
QBasicTimer m_timer;
QTime m_firstChange;
};
#endif // AUTOSAVER_H

View File

@ -1,119 +0,0 @@
/*
* Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net>
*
* 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 of the License, 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/****************************************************************************
**
** Copyright (C) 2007-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Alternatively you may (at
** your option) use any later version of the GNU General Public
** License if such license has been publicly approved by Trolltech ASA
** (or its successors, if any) and the KDE Free Qt Foundation. In
** addition, as a special exception, Trolltech gives you certain
** additional rights. These rights are described in the Trolltech GPL
** Exception version 1.2, which can be found at
** http://www.trolltech.com/products/qt/gplexception/ and in the file
** GPL_EXCEPTION.txt in this package.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
** you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** In addition, as a special exception, Trolltech, as the sole
** copyright holder for Qt Designer, grants users of the Qt/Eclipse
** Integration plug-in the right for the Qt/Eclipse Integration to
** link to functionality provided by Qt Designer and its related
** libraries.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
** granted herein.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include "autosaver.h"
#include <qdir.h>
#include <qcoreapplication.h>
#include <qmetaobject.h>
#include <qdebug.h>
#define AUTOSAVE_IN 1000 * 3 // seconds
#define MAXWAIT 1000 * 15 // seconds
AutoSaver::AutoSaver(QObject *parent) : QObject(parent)
{
Q_ASSERT(parent);
}
AutoSaver::~AutoSaver()
{
if (m_timer.isActive()) {
qWarning() << "AutoSaver: still active when destroyed, changes not saved.";
if (parent() && parent()->metaObject())
qWarning() << parent() << parent()->metaObject()->className() << "should call saveIfNeccessary";
}
}
void AutoSaver::changeOccurred()
{
if (m_firstChange.isNull())
m_firstChange.start();
if (m_firstChange.elapsed() > MAXWAIT) {
saveIfNeccessary();
} else {
m_timer.start(AUTOSAVE_IN, this);
}
}
void AutoSaver::timerEvent(QTimerEvent *event)
{
if (event->timerId() == m_timer.timerId()) {
saveIfNeccessary();
} else {
QObject::timerEvent(event);
}
}
void AutoSaver::saveIfNeccessary()
{
if (!m_timer.isActive())
return;
m_timer.stop();
m_firstChange = QTime();
if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection)) {
qWarning() << "AutoSaver: error invoking slot save() on parent";
}
}

View File

@ -1,98 +0,0 @@
/*
* Copyright 2008 Benjamin C. Meyer <ben@meyerhome.net>
*
* 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 of the License, 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/****************************************************************************
**
** Copyright (C) 2007-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Alternatively you may (at
** your option) use any later version of the GNU General Public
** License if such license has been publicly approved by Trolltech ASA
** (or its successors, if any) and the KDE Free Qt Foundation. In
** addition, as a special exception, Trolltech gives you certain
** additional rights. These rights are described in the Trolltech GPL
** Exception version 1.2, which can be found at
** http://www.trolltech.com/products/qt/gplexception/ and in the file
** GPL_EXCEPTION.txt in this package.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
** you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** In addition, as a special exception, Trolltech, as the sole
** copyright holder for Qt Designer, grants users of the Qt/Eclipse
** Integration plug-in the right for the Qt/Eclipse Integration to
** link to functionality provided by Qt Designer and its related
** libraries.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
** granted herein.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef AUTOSAVER_H
#define AUTOSAVER_H
#include <qobject.h>
#include <qbasictimer.h>
#include <qdatetime.h>
/*
This class will call the save() slot on the parent object when the parent changes.
It will wait several seconds after changed() to combining multiple changes and
prevent continuous writing to disk.
*/
class AutoSaver : public QObject
{
Q_OBJECT
public:
AutoSaver(QObject *parent);
~AutoSaver();
void saveIfNeccessary();
public slots:
void changeOccurred();
protected:
void timerEvent(QTimerEvent *event);
private:
QBasicTimer m_timer;
QTime m_firstChange;
};
#endif // AUTOSAVER_H

View File

@ -1,7 +1,8 @@
<ui version="4.0" > <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DownloadItem</class> <class>DownloadItem</class>
<widget class="QWidget" name="DownloadItem" > <widget class="QWidget" name="DownloadItem">
<property name="geometry" > <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
@ -9,54 +10,51 @@
<height>110</height> <height>110</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout" > <layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin" >
<number>0</number>
</property>
<item> <item>
<widget class="QLabel" name="fileIcon" > <widget class="QLabel" name="fileIcon">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy vsizetype="Minimum" hsizetype="Minimum" > <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text" > <property name="text">
<string>Ico</string> <string>Ico</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2" > <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="SqueezeLabel" native="1" name="fileNameLabel" > <widget class="SqueezeLabel" name="fileNameLabel" native="true">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy vsizetype="Preferred" hsizetype="Expanding" > <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text" stdset="0" > <property name="text" stdset="0">
<string>Filename</string> <string>Filename</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QProgressBar" name="progressBar" > <widget class="QProgressBar" name="progressBar">
<property name="value" > <property name="value">
<number>0</number> <number>0</number>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="SqueezeLabel" native="1" name="downloadInfoLabel" > <widget class="SqueezeLabel" name="downloadInfoLabel" native="true">
<property name="sizePolicy" > <property name="sizePolicy">
<sizepolicy vsizetype="Preferred" hsizetype="Minimum" > <sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text" stdset="0" > <property name="text" stdset="0">
<string/> <string/>
</property> </property>
</widget> </widget>
@ -64,13 +62,13 @@
</layout> </layout>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout" > <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<spacer name="verticalSpacer" > <spacer name="verticalSpacer">
<property name="orientation" > <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0" > <property name="sizeHint" stdset="0">
<size> <size>
<width>17</width> <width>17</width>
<height>1</height> <height>1</height>
@ -79,35 +77,35 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QPushButton" name="tryAgainButton" > <widget class="QPushButton" name="tryAgainButton">
<property name="enabled" > <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="text" > <property name="text">
<string>Try Again</string> <string>Try Again</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="stopButton" > <widget class="QPushButton" name="stopButton">
<property name="text" > <property name="text">
<string>Stop</string> <string>Stop</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="openButton" > <widget class="QPushButton" name="openButton">
<property name="text" > <property name="text">
<string>Open</string> <string>Open</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="verticalSpacer_2" > <spacer name="verticalSpacer_2">
<property name="orientation" > <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" stdset="0" > <property name="sizeHint" stdset="0">
<size> <size>
<width>17</width> <width>17</width>
<height>5</height> <height>5</height>

View File

@ -1,69 +1,23 @@
/* // This file is part of RSS Guard.
* Copyright 2008-2009 Benjamin C. Meyer <ben@meyerhome.net> //
* Copyright 2008 Jason A. Donenfeld <Jason@zx2c4.com> // Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
* //
* This program is free software; you can redistribute it and/or modify // RSS Guard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. // (at your option) any later version.
* //
* This program is distributed in the hope that it will be useful, // RSS Guard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. // GNU General Public License for more details.
* //
* You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software // along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/****************************************************************************
**
** Copyright (C) 2008-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Alternatively you may (at
** your option) use any later version of the GNU General Public
** License if such license has been publicly approved by Trolltech ASA
** (or its successors, if any) and the KDE Free Qt Foundation. In
** addition, as a special exception, Trolltech gives you certain
** additional rights. These rights are described in the Trolltech GPL
** Exception version 1.2, which can be found at
** http://www.trolltech.com/products/qt/gplexception/ and in the file
** GPL_EXCEPTION.txt in this package.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
** you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** In addition, as a special exception, Trolltech, as the sole
** copyright holder for Qt Designer, grants users of the Qt/Eclipse
** Integration plug-in the right for the Qt/Eclipse Integration to
** link to functionality provided by Qt Designer and its related
** libraries.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
** granted herein.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#include "downloadmanager.h" #include "downloadmanager.h"
#include "autosaver.h" #include "miscellaneous/autosaver.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
@ -483,7 +437,6 @@ DownloadManager::DownloadManager(QWidget *parent)
downloadsView->horizontalHeader()->setStretchLastSection(true); downloadsView->horizontalHeader()->setStretchLastSection(true);
downloadsView->setModel(m_model); downloadsView->setModel(m_model);
connect(cleanupButton, SIGNAL(clicked()), this, SLOT(cleanup())); connect(cleanupButton, SIGNAL(clicked()), this, SLOT(cleanup()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
load(); load();
} }
@ -570,7 +523,6 @@ void DownloadManager::addItem(DownloadItem *item)
m_model->beginInsertRows(QModelIndex(), row, row); m_model->beginInsertRows(QModelIndex(), row, row);
m_downloads.append(item); m_downloads.append(item);
m_model->endInsertRows(); m_model->endInsertRows();
updateItemCount();
downloadsView->setIndexWidget(m_model->index(row, 0), item); downloadsView->setIndexWidget(m_model->index(row, 0), item);
QIcon icon = style()->standardIcon(QStyle::SP_FileIcon); QIcon icon = style()->standardIcon(QStyle::SP_FileIcon);
item->fileIcon->setPixmap(icon.pixmap(48, 48)); item->fileIcon->setPixmap(icon.pixmap(48, 48));
@ -719,7 +671,6 @@ void DownloadManager::cleanup()
if (m_downloads.isEmpty()) if (m_downloads.isEmpty())
return; return;
m_model->removeRows(0, m_downloads.count()); m_model->removeRows(0, m_downloads.count());
updateItemCount();
updateActiveItemCount(); updateActiveItemCount();
if (m_downloads.isEmpty() && m_iconProvider) { if (m_downloads.isEmpty() && m_iconProvider) {
delete m_iconProvider; delete m_iconProvider;
@ -728,12 +679,6 @@ void DownloadManager::cleanup()
m_autoSaver->changeOccurred(); m_autoSaver->changeOccurred();
} }
void DownloadManager::updateItemCount()
{
int count = m_downloads.count();
itemCount->setText(tr("%n Download(s)", "", count));
}
void DownloadManager::setDownloadDirectory(const QString &directory) void DownloadManager::setDownloadDirectory(const QString &directory)
{ {
m_downloadDirectory = directory; m_downloadDirectory = directory;
@ -821,7 +766,6 @@ bool DownloadModel::removeRows(int row, int count, const QModelIndex &parent)
} }
} }
m_downloadManager->m_autoSaver->changeOccurred(); m_downloadManager->m_autoSaver->changeOccurred();
m_downloadManager->updateItemCount();
return true; return true;
} }

View File

@ -1,65 +1,19 @@
/* // This file is part of RSS Guard.
* Copyright 2008-2009 Benjamin C. Meyer <ben@meyerhome.net> //
* Copyright 2008 Jason A. Donenfeld <Jason@zx2c4.com> // Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com>
* //
* This program is free software; you can redistribute it and/or modify // RSS Guard is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or // the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. // (at your option) any later version.
* //
* This program is distributed in the hope that it will be useful, // RSS Guard is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. // GNU General Public License for more details.
* //
* You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software // along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/****************************************************************************
**
** Copyright (C) 2008-2008 Trolltech ASA. All rights reserved.
**
** This file is part of the demonstration applications of the Qt Toolkit.
**
** This file may be used under the terms of the GNU General Public
** License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the files LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Alternatively you may (at
** your option) use any later version of the GNU General Public
** License if such license has been publicly approved by Trolltech ASA
** (or its successors, if any) and the KDE Free Qt Foundation. In
** addition, as a special exception, Trolltech gives you certain
** additional rights. These rights are described in the Trolltech GPL
** Exception version 1.2, which can be found at
** http://www.trolltech.com/products/qt/gplexception/ and in the file
** GPL_EXCEPTION.txt in this package.
**
** Please review the following information to ensure GNU General
** Public Licensing requirements will be met:
** http://trolltech.com/products/qt/licenses/licensing/opensource/. If
** you are unsure which license is appropriate for your use, please
** review the following information:
** http://trolltech.com/products/qt/licenses/licensing/licensingoverview
** or contact the sales department at sales@trolltech.com.
**
** In addition, as a special exception, Trolltech, as the sole
** copyright holder for Qt Designer, grants users of the Qt/Eclipse
** Integration plug-in the right for the Qt/Eclipse Integration to
** link to functionality provided by Qt Designer and its related
** libraries.
**
** This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE. Trolltech reserves all rights not expressly
** granted herein.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
#ifndef DOWNLOADMANAGER_H #ifndef DOWNLOADMANAGER_H
#define DOWNLOADMANAGER_H #define DOWNLOADMANAGER_H
@ -180,7 +134,6 @@ class DownloadManager : public TabContent, public Ui_DownloadManager {
private: private:
void addItem(DownloadItem *item); void addItem(DownloadItem *item);
void updateItemCount();
void load(); void load();
void updateActiveItemCount(); void updateActiveItemCount();

View File

@ -14,10 +14,13 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2"> <item row="0" column="0">
<widget class="EditTableView" name="downloadsView"> <widget class="EditTableView" name="downloadsView">
<property name="frameShape"> <property name="frameShape">
<enum>QFrame::NoFrame</enum> <enum>QFrame::Box</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property> </property>
<property name="dragEnabled"> <property name="dragEnabled">
<bool>true</bool> <bool>true</bool>
@ -40,7 +43,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<spacer> <spacer name="spacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -54,46 +57,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="1">
<widget class="QLabel" name="itemCount">
<property name="text">
<string>0 Items</string>
</property>
</widget>
</item>
</layout> </layout>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>30</x>
<y>10</y>
<width>133</width>
<height>25</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>50</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>

View File

@ -1,81 +0,0 @@
/**
* Copyright (c) 2008, Benjamin C. Meyer <ben@meyerhome.net>
* Copyright (c) 2009, Jakub Wieczorek <faw217@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "edittableview.h"
#include <qevent.h>
EditTableView::EditTableView(QWidget *parent)
: QTableView(parent)
{
}
void EditTableView::keyPressEvent(QKeyEvent *event)
{
if (model() && event->key() == Qt::Key_Delete) {
removeSelected();
event->setAccepted(true);
} else {
QAbstractItemView::keyPressEvent(event);
}
}
void EditTableView::removeSelected()
{
if (!model() || !selectionModel() || !selectionModel()->hasSelection())
return;
QModelIndexList selectedRows = selectionModel()->selectedRows();
if (selectedRows.isEmpty())
return;
int newSelectedRow = selectedRows.at(0).row();
for (int i = selectedRows.count() - 1; i >= 0; --i) {
QModelIndex idx = selectedRows.at(i);
model()->removeRow(idx.row(), rootIndex());
}
// select the item at the same position
QModelIndex newSelectedIndex = model()->index(newSelectedRow, 0, rootIndex());
// if that was the last item
if (!newSelectedIndex.isValid())
newSelectedIndex = model()->index(newSelectedRow - 1, 0, rootIndex());
selectionModel()->select(newSelectedIndex, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
setCurrentIndex(newSelectedIndex);
}
void EditTableView::removeAll()
{
if (!model())
return;
model()->removeRows(0, model()->rowCount(rootIndex()), rootIndex());
}

View File

@ -1,49 +0,0 @@
/**
* Copyright (c) 2008, Benjamin C. Meyer <ben@meyerhome.net>
* Copyright (c) 2009, Jakub Wieczorek <faw217@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef EDITTABLEVIEW_H
#define EDITTABLEVIEW_H
#include <qtableview.h>
class EditTableView : public QTableView
{
Q_OBJECT
public:
EditTableView(QWidget *parent = 0);
void keyPressEvent(QKeyEvent *event);
public slots:
void removeSelected();
void removeAll();
};
#endif // EDITTABLEVIEW_H

View File

@ -1,48 +0,0 @@
/**
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "squeezelabel.h"
SqueezeLabel::SqueezeLabel(QWidget *parent)
: QLabel(parent)
{
}
void SqueezeLabel::paintEvent(QPaintEvent *event)
{
if (m_SqueezedTextCache != text()) {
m_SqueezedTextCache = text();
QFontMetrics fm = fontMetrics();
if (fm.width(m_SqueezedTextCache) > contentsRect().width()) {
QString elided = fm.elidedText(text(), Qt::ElideMiddle, width());
setText(elided);
}
}
QLabel::paintEvent(event);
}

View File

@ -1,53 +0,0 @@
/**
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef SQUEEZELABEL_H
#define SQUEEZELABEL_H
#include <qlabel.h>
/*
A label that will squeeze the set text to fit within the size of the
widget. The text will be elided in the middle.
*/
class SqueezeLabel : public QLabel
{
Q_OBJECT
public:
SqueezeLabel(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *event);
private:
QString m_SqueezedTextCache;
};
#endif // SQUEEZELABEL_H

View File

@ -19,6 +19,7 @@
#include "network-web/webbrowsernetworkaccessmanager.h" #include "network-web/webbrowsernetworkaccessmanager.h"
#include "network-web/webbrowser.h" #include "network-web/webbrowser.h"
#include "miscellaneous/application.h"
#include <QNetworkReply> #include <QNetworkReply>
#include <QWebFrame> #include <QWebFrame>
@ -29,6 +30,8 @@ WebPage::WebPage(QObject *parent)
// Setup global network access manager. // Setup global network access manager.
// NOTE: This makes network settings easy for all web browsers. // NOTE: This makes network settings easy for all web browsers.
setNetworkAccessManager(WebBrowserNetworkAccessManager::instance()); setNetworkAccessManager(WebBrowserNetworkAccessManager::instance());
setForwardUnsupportedContent(true);
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*)));
} }
WebPage::~WebPage() { WebPage::~WebPage() {
@ -38,6 +41,27 @@ QString WebPage::toPlainText() const {
return mainFrame()->toPlainText(); return mainFrame()->toPlainText();
} }
void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
if (!reply)
return;
QUrl replyUrl = reply->url();
if (replyUrl.scheme() == QLatin1String("abp"))
return;
switch (reply->error()) {
case QNetworkReply::NoError:
if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) {
qApp->downloadManager()->handleUnsupportedContent(reply);
return;
}
default:
return;
}
}
QString WebPage::toHtml() const { QString WebPage::toHtml() const {
return mainFrame()->toHtml(); return mainFrame()->toHtml();
} }

View File

@ -32,6 +32,9 @@ class WebPage : public QWebPage {
QString toHtml() const; QString toHtml() const;
QString toPlainText() const; QString toPlainText() const;
private slots:
void handleUnsupportedContent(QNetworkReply *reply);
protected: protected:
bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type); bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
}; };

View File

@ -112,6 +112,7 @@ void WebView::saveCurrentPageToFile() {
void WebView::createConnections() { void WebView::createConnections() {
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(popupContextMenu(QPoint))); connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(popupContextMenu(QPoint)));
connect(page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(downloadLink(QNetworkRequest)));
connect(m_actionSavePageAs, SIGNAL(triggered()), this, SLOT(saveCurrentPageToFile())); connect(m_actionSavePageAs, SIGNAL(triggered()), this, SLOT(saveCurrentPageToFile()));
connect(m_actionPrint, SIGNAL(triggered()), this, SLOT(printCurrentPage())); connect(m_actionPrint, SIGNAL(triggered()), this, SLOT(printCurrentPage()));
@ -126,6 +127,7 @@ void WebView::setupIcons() {
m_actionCopySelectedItem->setIcon(qApp->icons()->fromTheme("edit-copy")); m_actionCopySelectedItem->setIcon(qApp->icons()->fromTheme("edit-copy"));
m_actionCopyLink->setIcon(qApp->icons()->fromTheme("edit-copy")); m_actionCopyLink->setIcon(qApp->icons()->fromTheme("edit-copy"));
m_actionCopyImage->setIcon(qApp->icons()->fromTheme("edit-copy-image")); m_actionCopyImage->setIcon(qApp->icons()->fromTheme("edit-copy-image"));
m_actionSaveHyperlinkAs->setIcon(qApp->icons()->fromTheme("document-download"));
#if QT_VERSION >= 0x040800 #if QT_VERSION >= 0x040800
m_actionCopyImageUrl->setIcon(qApp->icons()->fromTheme("edit-copy")); m_actionCopyImageUrl->setIcon(qApp->icons()->fromTheme("edit-copy"));
@ -157,6 +159,11 @@ void WebView::initializeActions() {
addAction(m_actionCopySelectedItem); addAction(m_actionCopySelectedItem);
#endif #endif
m_actionSaveHyperlinkAs = pageAction(QWebPage::DownloadLinkToDisk);
m_actionSaveHyperlinkAs->setParent(this);
m_actionSaveHyperlinkAs->setText(tr("Save as..."));
m_actionSaveHyperlinkAs->setToolTip(tr("Download content from the hyperlink."));
m_actionCopyLink = pageAction(QWebPage::CopyLinkToClipboard); m_actionCopyLink = pageAction(QWebPage::CopyLinkToClipboard);
m_actionCopyLink->setParent(this); m_actionCopyLink->setParent(this);
m_actionCopyLink->setText(tr("Copy link url")); m_actionCopyLink->setText(tr("Copy link url"));
@ -167,7 +174,7 @@ void WebView::initializeActions() {
m_actionCopyImage->setText(tr("Copy image")); m_actionCopyImage->setText(tr("Copy image"));
m_actionCopyImage->setToolTip(tr("Copy image to clipboard.")); m_actionCopyImage->setToolTip(tr("Copy image to clipboard."));
m_actionSavePageAs = new QAction(qApp->icons()->fromTheme("document-export"), tr("Save page as..."), this); m_actionSavePageAs = new QAction(qApp->icons()->fromTheme("document-download"), tr("Save page as..."), this);
#if QT_VERSION >= 0x040800 #if QT_VERSION >= 0x040800
m_actionCopyImageUrl = pageAction(QWebPage::CopyImageUrlToClipboard); m_actionCopyImageUrl = pageAction(QWebPage::CopyImageUrlToClipboard);
@ -246,6 +253,7 @@ void WebView::popupContextMenu(const QPoint &pos) {
link_submenu.addAction(m_actionOpenLinkNewTab); link_submenu.addAction(m_actionOpenLinkNewTab);
link_submenu.addAction(m_actionOpenLinkExternally); link_submenu.addAction(m_actionOpenLinkExternally);
link_submenu.addAction(m_actionCopyLink); link_submenu.addAction(m_actionCopyLink);
link_submenu.addAction(m_actionSaveHyperlinkAs);
} }
if (!hit_result.pixmap().isNull()) { if (!hit_result.pixmap().isNull()) {
@ -273,6 +281,10 @@ void WebView::printCurrentPage() {
print_preview.data()->exec(); print_preview.data()->exec();
} }
void WebView::downloadLink(const QNetworkRequest &request) {
qApp->downloadManager()->download(request);
}
void WebView::mousePressEvent(QMouseEvent *event) { void WebView::mousePressEvent(QMouseEvent *event) {
if (event->button() & Qt::LeftButton && event->modifiers() & Qt::ControlModifier) { if (event->button() & Qt::LeftButton && event->modifiers() & Qt::ControlModifier) {
QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(event->pos()); QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(event->pos());

View File

@ -71,6 +71,9 @@ class WebView : public QWebView {
void printCurrentPage(); void printCurrentPage();
private slots:
void downloadLink(const QNetworkRequest &request);
protected: protected:
// Initializes all actions. // Initializes all actions.
void initializeActions(); void initializeActions();
@ -97,6 +100,7 @@ class WebView : public QWebView {
QAction *m_actionCopyLink; QAction *m_actionCopyLink;
QAction *m_actionCopyImage; QAction *m_actionCopyImage;
QAction *m_actionSavePageAs; QAction *m_actionSavePageAs;
QAction *m_actionSaveHyperlinkAs;
#if QT_VERSION >= 0x040800 #if QT_VERSION >= 0x040800
QAction *m_actionCopyImageUrl; QAction *m_actionCopyImageUrl;