diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a71ac42c..9ebc6829a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -355,6 +355,8 @@ set(APP_SOURCES src/gui/styleditemdelegatewithoutfocus.cpp src/gui/formbackupdatabasesettings.cpp src/gui/formrestoredatabasesettings.cpp + src/gui/edittableview.cpp + src/gui/squeezelabel.cpp # DYNAMIC-SHORTCUTS sources. src/dynamic-shortcuts/shortcutcatcher.cpp @@ -373,6 +375,7 @@ set(APP_SOURCES src/miscellaneous/skinfactory.cpp src/miscellaneous/iconfactory.cpp src/miscellaneous/iofactory.cpp + src/miscellaneous/autosaver.cpp # CORE sources. src/core/messagesmodel.cpp @@ -398,9 +401,6 @@ set(APP_SOURCES src/network-web/webview.cpp src/network-web/downloader.cpp src/network-web/downloadmanager.cpp - src/network-web/edittableview.cpp - src/network-web/autosaver.cpp - src/network-web/squeezelabel.cpp # MAIN sources. src/main.cpp @@ -446,6 +446,8 @@ set(APP_HEADERS src/gui/formimportexport.h src/gui/formbackupdatabasesettings.h src/gui/formrestoredatabasesettings.h + src/gui/edittableview.h + src/gui/squeezelabel.h # DYNAMIC-SHORTCUTS headers. src/dynamic-shortcuts/dynamicshortcutswidget.h @@ -460,6 +462,7 @@ set(APP_HEADERS src/miscellaneous/databasefactory.h src/miscellaneous/iconfactory.h src/miscellaneous/skinfactory.h + src/miscellaneous/autosaver.h # CORE headers. src/core/messagesmodel.h @@ -479,9 +482,6 @@ set(APP_HEADERS src/network-web/webview.h src/network-web/downloader.h src/network-web/downloadmanager.h - src/network-web/edittableview.h - src/network-web/autosaver.h - src/network-web/squeezelabel.h ) # APP form files. diff --git a/resources/graphics/icons/mini-kfaenza/document-download.png b/resources/graphics/icons/mini-kfaenza/document-download.png new file mode 100644 index 000000000..c1aedb2d8 Binary files /dev/null and b/resources/graphics/icons/mini-kfaenza/document-download.png differ diff --git a/src/gui/edittableview.cpp b/src/gui/edittableview.cpp new file mode 100644 index 000000000..3179a0c61 --- /dev/null +++ b/src/gui/edittableview.cpp @@ -0,0 +1,69 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// 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 . + +#include "edittableview.h" + +#include + +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()); +} + diff --git a/src/gui/edittableview.h b/src/gui/edittableview.h new file mode 100644 index 000000000..21ae1795f --- /dev/null +++ b/src/gui/edittableview.h @@ -0,0 +1,37 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// 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 . + +#ifndef EDITTABLEVIEW_H +#define EDITTABLEVIEW_H + +#include + +class EditTableView : public QTableView +{ + Q_OBJECT + +public: + EditTableView(QWidget *parent = 0); + void keyPressEvent(QKeyEvent *event); + +public slots: + void removeSelected(); + void removeAll(); +}; + +#endif // EDITTABLEVIEW_H + diff --git a/src/gui/squeezelabel.cpp b/src/gui/squeezelabel.cpp new file mode 100644 index 000000000..1601a6a90 --- /dev/null +++ b/src/gui/squeezelabel.cpp @@ -0,0 +1,37 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// 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 . + +#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); +} + diff --git a/src/gui/squeezelabel.h b/src/gui/squeezelabel.h new file mode 100644 index 000000000..879632973 --- /dev/null +++ b/src/gui/squeezelabel.h @@ -0,0 +1,42 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// 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 . + +#ifndef SQUEEZELABEL_H +#define SQUEEZELABEL_H + +#include + +/* + 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 + diff --git a/src/gui/tabbar.cpp b/src/gui/tabbar.cpp index 56e44a0b9..88cc2ae59 100755 --- a/src/gui/tabbar.cpp +++ b/src/gui/tabbar.cpp @@ -112,7 +112,7 @@ void TabBar::mousePressEvent(QMouseEvent *event) { // NOTE: This needs to be done here because // destination does not know the original event. 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. emit tabCloseRequested(tab_index); } diff --git a/src/miscellaneous/autosaver.cpp b/src/miscellaneous/autosaver.cpp new file mode 100644 index 000000000..428e00cd9 --- /dev/null +++ b/src/miscellaneous/autosaver.cpp @@ -0,0 +1,74 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// 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 . + +#include "autosaver.h" + +#include +#include +#include + +#include + +#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"; + } +} + diff --git a/src/miscellaneous/autosaver.h b/src/miscellaneous/autosaver.h new file mode 100644 index 000000000..d86c259c4 --- /dev/null +++ b/src/miscellaneous/autosaver.h @@ -0,0 +1,53 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// 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 . + +#ifndef AUTOSAVER_H +#define AUTOSAVER_H + +#include +#include +#include + +/* + 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 + diff --git a/src/network-web/autosaver.cpp b/src/network-web/autosaver.cpp deleted file mode 100644 index 017143516..000000000 --- a/src/network-web/autosaver.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright 2008 Benjamin C. Meyer - * - * 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 -#include -#include - -#include - -#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"; - } -} - diff --git a/src/network-web/autosaver.h b/src/network-web/autosaver.h deleted file mode 100644 index bfff7789e..000000000 --- a/src/network-web/autosaver.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2008 Benjamin C. Meyer - * - * 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 -#include -#include - -/* - 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 - diff --git a/src/network-web/downloaditem.ui b/src/network-web/downloaditem.ui index e927a59e4..dd3b9a820 100644 --- a/src/network-web/downloaditem.ui +++ b/src/network-web/downloaditem.ui @@ -1,7 +1,8 @@ - + + DownloadItem - - + + 0 0 @@ -9,54 +10,51 @@ 110 - - - 0 - + - - - + + + 0 0 - + Ico - + - - - + + + 0 0 - + Filename - - + + 0 - - - + + + 0 0 - + @@ -64,13 +62,13 @@ - + - - + + Qt::Vertical - + 17 1 @@ -79,35 +77,35 @@ - - + + false - + Try Again - - + + Stop - - + + Open - - + + Qt::Vertical - + 17 5 diff --git a/src/network-web/downloadmanager.cpp b/src/network-web/downloadmanager.cpp index e531b2d1d..8a31ee869 100644 --- a/src/network-web/downloadmanager.cpp +++ b/src/network-web/downloadmanager.cpp @@ -1,69 +1,23 @@ -/* - * Copyright 2008-2009 Benjamin C. Meyer - * Copyright 2008 Jason A. Donenfeld - * - * 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) 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. -** -****************************************************************************/ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// 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 . #include "downloadmanager.h" -#include "autosaver.h" +#include "miscellaneous/autosaver.h" #include "miscellaneous/application.h" @@ -483,7 +437,6 @@ DownloadManager::DownloadManager(QWidget *parent) downloadsView->horizontalHeader()->setStretchLastSection(true); downloadsView->setModel(m_model); connect(cleanupButton, SIGNAL(clicked()), this, SLOT(cleanup())); - connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); load(); } @@ -570,7 +523,6 @@ void DownloadManager::addItem(DownloadItem *item) m_model->beginInsertRows(QModelIndex(), row, row); m_downloads.append(item); m_model->endInsertRows(); - updateItemCount(); downloadsView->setIndexWidget(m_model->index(row, 0), item); QIcon icon = style()->standardIcon(QStyle::SP_FileIcon); item->fileIcon->setPixmap(icon.pixmap(48, 48)); @@ -719,7 +671,6 @@ void DownloadManager::cleanup() if (m_downloads.isEmpty()) return; m_model->removeRows(0, m_downloads.count()); - updateItemCount(); updateActiveItemCount(); if (m_downloads.isEmpty() && m_iconProvider) { delete m_iconProvider; @@ -728,12 +679,6 @@ void DownloadManager::cleanup() m_autoSaver->changeOccurred(); } -void DownloadManager::updateItemCount() -{ - int count = m_downloads.count(); - itemCount->setText(tr("%n Download(s)", "", count)); -} - void DownloadManager::setDownloadDirectory(const QString &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->updateItemCount(); return true; } diff --git a/src/network-web/downloadmanager.h b/src/network-web/downloadmanager.h index 578bfd132..a39cd42e6 100644 --- a/src/network-web/downloadmanager.h +++ b/src/network-web/downloadmanager.h @@ -1,65 +1,19 @@ -/* - * Copyright 2008-2009 Benjamin C. Meyer - * Copyright 2008 Jason A. Donenfeld - * - * 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) 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. -** -****************************************************************************/ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2015 by Martin Rotter +// +// 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 . #ifndef DOWNLOADMANAGER_H #define DOWNLOADMANAGER_H @@ -180,7 +134,6 @@ class DownloadManager : public TabContent, public Ui_DownloadManager { private: void addItem(DownloadItem *item); - void updateItemCount(); void load(); void updateActiveItemCount(); diff --git a/src/network-web/downloadmanager.ui b/src/network-web/downloadmanager.ui index 259c7861e..e2ba12cae 100644 --- a/src/network-web/downloadmanager.ui +++ b/src/network-web/downloadmanager.ui @@ -14,10 +14,13 @@ Form - + - QFrame::NoFrame + QFrame::Box + + + QFrame::Plain true @@ -40,7 +43,7 @@ - + Qt::Horizontal @@ -54,46 +57,7 @@ - - - - 0 Items - - - - - - - 30 - 10 - 133 - 25 - - - - - - - Qt::Horizontal - - - - 50 - 20 - - - - - - - - QDialogButtonBox::Close - - - - - diff --git a/src/network-web/edittableview.cpp b/src/network-web/edittableview.cpp deleted file mode 100644 index cf7159f32..000000000 --- a/src/network-web/edittableview.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (c) 2008, Benjamin C. Meyer - * Copyright (c) 2009, Jakub Wieczorek - * - * 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 - -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()); -} - diff --git a/src/network-web/edittableview.h b/src/network-web/edittableview.h deleted file mode 100644 index ade02462c..000000000 --- a/src/network-web/edittableview.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (c) 2008, Benjamin C. Meyer - * Copyright (c) 2009, Jakub Wieczorek - * - * 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 - -class EditTableView : public QTableView -{ - Q_OBJECT - -public: - EditTableView(QWidget *parent = 0); - void keyPressEvent(QKeyEvent *event); - -public slots: - void removeSelected(); - void removeAll(); -}; - -#endif // EDITTABLEVIEW_H - diff --git a/src/network-web/squeezelabel.cpp b/src/network-web/squeezelabel.cpp deleted file mode 100644 index ca29a39d9..000000000 --- a/src/network-web/squeezelabel.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2009, Benjamin C. Meyer - * - * 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); -} - diff --git a/src/network-web/squeezelabel.h b/src/network-web/squeezelabel.h deleted file mode 100644 index dd4836ca6..000000000 --- a/src/network-web/squeezelabel.h +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright (c) 2009, Benjamin C. Meyer - * - * 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 - -/* - 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 - diff --git a/src/network-web/webpage.cpp b/src/network-web/webpage.cpp index 54d38a330..2f3727a91 100644 --- a/src/network-web/webpage.cpp +++ b/src/network-web/webpage.cpp @@ -19,6 +19,7 @@ #include "network-web/webbrowsernetworkaccessmanager.h" #include "network-web/webbrowser.h" +#include "miscellaneous/application.h" #include #include @@ -29,6 +30,8 @@ WebPage::WebPage(QObject *parent) // Setup global network access manager. // NOTE: This makes network settings easy for all web browsers. setNetworkAccessManager(WebBrowserNetworkAccessManager::instance()); + setForwardUnsupportedContent(true); + connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*))); } WebPage::~WebPage() { @@ -38,6 +41,27 @@ QString WebPage::toPlainText() const { 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 { return mainFrame()->toHtml(); } diff --git a/src/network-web/webpage.h b/src/network-web/webpage.h index dcbc8a487..fbb4affe0 100644 --- a/src/network-web/webpage.h +++ b/src/network-web/webpage.h @@ -32,6 +32,9 @@ class WebPage : public QWebPage { QString toHtml() const; QString toPlainText() const; + private slots: + void handleUnsupportedContent(QNetworkReply *reply); + protected: bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type); }; diff --git a/src/network-web/webview.cpp b/src/network-web/webview.cpp index 4cdbe3755..515a3ccc7 100755 --- a/src/network-web/webview.cpp +++ b/src/network-web/webview.cpp @@ -112,6 +112,7 @@ void WebView::saveCurrentPageToFile() { void WebView::createConnections() { connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); 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_actionPrint, SIGNAL(triggered()), this, SLOT(printCurrentPage())); @@ -126,6 +127,7 @@ void WebView::setupIcons() { m_actionCopySelectedItem->setIcon(qApp->icons()->fromTheme("edit-copy")); m_actionCopyLink->setIcon(qApp->icons()->fromTheme("edit-copy")); m_actionCopyImage->setIcon(qApp->icons()->fromTheme("edit-copy-image")); + m_actionSaveHyperlinkAs->setIcon(qApp->icons()->fromTheme("document-download")); #if QT_VERSION >= 0x040800 m_actionCopyImageUrl->setIcon(qApp->icons()->fromTheme("edit-copy")); @@ -157,6 +159,11 @@ void WebView::initializeActions() { addAction(m_actionCopySelectedItem); #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->setParent(this); m_actionCopyLink->setText(tr("Copy link url")); @@ -167,7 +174,7 @@ void WebView::initializeActions() { m_actionCopyImage->setText(tr("Copy image")); 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 m_actionCopyImageUrl = pageAction(QWebPage::CopyImageUrlToClipboard); @@ -246,6 +253,7 @@ void WebView::popupContextMenu(const QPoint &pos) { link_submenu.addAction(m_actionOpenLinkNewTab); link_submenu.addAction(m_actionOpenLinkExternally); link_submenu.addAction(m_actionCopyLink); + link_submenu.addAction(m_actionSaveHyperlinkAs); } if (!hit_result.pixmap().isNull()) { @@ -273,6 +281,10 @@ void WebView::printCurrentPage() { print_preview.data()->exec(); } +void WebView::downloadLink(const QNetworkRequest &request) { + qApp->downloadManager()->download(request); +} + void WebView::mousePressEvent(QMouseEvent *event) { if (event->button() & Qt::LeftButton && event->modifiers() & Qt::ControlModifier) { QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(event->pos()); diff --git a/src/network-web/webview.h b/src/network-web/webview.h index 7281e3f2b..8ecad35da 100644 --- a/src/network-web/webview.h +++ b/src/network-web/webview.h @@ -71,6 +71,9 @@ class WebView : public QWebView { void printCurrentPage(); + private slots: + void downloadLink(const QNetworkRequest &request); + protected: // Initializes all actions. void initializeActions(); @@ -97,6 +100,7 @@ class WebView : public QWebView { QAction *m_actionCopyLink; QAction *m_actionCopyImage; QAction *m_actionSavePageAs; + QAction *m_actionSaveHyperlinkAs; #if QT_VERSION >= 0x040800 QAction *m_actionCopyImageUrl;