From ce86e965bd8781f6fe18e4b50eadaf7402a07847 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Wed, 25 Nov 2009 01:36:38 +0100 Subject: Last history fixes --- src/CMakeLists.txt | 3 +- src/autosaver.cpp | 100 -------------------- src/autosaver.h | 67 ------------- src/history/autosaver.cpp | 100 ++++++++++++++++++++ src/history/autosaver.h | 67 +++++++++++++ src/history/history.h | 3 - src/history/historymodels.h | 1 - src/modelmenu.cpp | 223 -------------------------------------------- src/modelmenu.h | 109 ---------------------- 9 files changed, 168 insertions(+), 505 deletions(-) delete mode 100644 src/autosaver.cpp delete mode 100644 src/autosaver.h create mode 100644 src/history/autosaver.cpp create mode 100644 src/history/autosaver.h delete mode 100644 src/modelmenu.cpp delete mode 100644 src/modelmenu.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e214c7d9..96fddbff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,13 +9,11 @@ ADD_SUBDIRECTORY( adblock ) SET( rekonq_KDEINIT_SRCS application.cpp - autosaver.cpp bookmarks.cpp findbar.cpp lineedit.cpp mainview.cpp mainwindow.cpp - modelmenu.cpp previewimage.cpp sessionmanager.cpp sidepanel.cpp @@ -26,6 +24,7 @@ SET( rekonq_KDEINIT_SRCS websnap.cpp webview.cpp #---------------------------------------- + history/autosaver.cpp history/history.cpp history/historymodels.cpp history/historypanel.cpp diff --git a/src/autosaver.cpp b/src/autosaver.cpp deleted file mode 100644 index 236922b5..00000000 --- a/src/autosaver.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved -* Copyright (C) 2008-2009 by Andrea Diamantini -* -* -* 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) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* 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, see . -* -* ============================================================ */ - - - - -// Self Includes -#include "autosaver.h" -#include "autosaver.moc" - -// KDE Includes -#include - -// Qt Includes -#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()) - { - kWarning() << "AutoSaver: still active when destroyed, changes not saved."; - } -} - - -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)) - { - kWarning() << "AutoSaver: error invoking slot save() on parent"; - } -} - diff --git a/src/autosaver.h b/src/autosaver.h deleted file mode 100644 index 80583f9c..00000000 --- a/src/autosaver.h +++ /dev/null @@ -1,67 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved -* Copyright (C) 2008-2009 by Andrea Diamantini -* -* -* 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) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* 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, see . -* -* ============================================================ */ - - -#ifndef AUTOSAVER_H -#define AUTOSAVER_H - - -// Qt Includes -#include -#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/history/autosaver.cpp b/src/history/autosaver.cpp new file mode 100644 index 00000000..236922b5 --- /dev/null +++ b/src/history/autosaver.cpp @@ -0,0 +1,100 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008-2009 by Andrea Diamantini +* +* +* 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) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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, see . +* +* ============================================================ */ + + + + +// Self Includes +#include "autosaver.h" +#include "autosaver.moc" + +// KDE Includes +#include + +// Qt Includes +#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()) + { + kWarning() << "AutoSaver: still active when destroyed, changes not saved."; + } +} + + +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)) + { + kWarning() << "AutoSaver: error invoking slot save() on parent"; + } +} + diff --git a/src/history/autosaver.h b/src/history/autosaver.h new file mode 100644 index 00000000..80583f9c --- /dev/null +++ b/src/history/autosaver.h @@ -0,0 +1,67 @@ +/* ============================================================ +* +* This file is a part of the rekonq project +* +* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved +* Copyright (C) 2008-2009 by Andrea Diamantini +* +* +* 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) version 3 or any later version +* accepted by the membership of KDE e.V. (or its successor approved +* by the membership of KDE e.V.), which shall act as a proxy +* defined in Section 14 of version 3 of the license. +* +* 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, see . +* +* ============================================================ */ + + +#ifndef AUTOSAVER_H +#define AUTOSAVER_H + + +// Qt Includes +#include +#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/history/history.h b/src/history/history.h index 2ccf8cb4..ff3b4381 100644 --- a/src/history/history.h +++ b/src/history/history.h @@ -30,9 +30,6 @@ #define HISTORY_H -// Local Includes -#include "modelmenu.h" - // KDE Includes #include diff --git a/src/history/historymodels.h b/src/history/historymodels.h index 93e72c6a..cb8bea41 100644 --- a/src/history/historymodels.h +++ b/src/history/historymodels.h @@ -32,7 +32,6 @@ // Local Includes #include "history.h" -#include "modelmenu.h" // KDE Includes #include diff --git a/src/modelmenu.cpp b/src/modelmenu.cpp deleted file mode 100644 index 4ef2bd76..00000000 --- a/src/modelmenu.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved -* Copyright (C) 2008-2009 by Andrea Diamantini * -* -* 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) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* 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, see . -* -* ============================================================ */ - - -// Self Includes -#include "modelmenu.h" -#include "modelmenu.moc" - - -ModelMenu::ModelMenu(QWidget * parent) - : KMenu(parent) - , m_maxRows(7) - , m_firstSeparator(-1) - , m_maxWidth(-1) - , m_hoverRole(0) - , m_separatorRole(0) - , m_model(0) -{ - connect(this, SIGNAL(aboutToShow()), this, SLOT(aboutToShow())); -} - - -bool ModelMenu::prePopulated() -{ - return false; -} - - -void ModelMenu::postPopulated() -{ -} - - -void ModelMenu::setModel(QAbstractItemModel *model) -{ - m_model = model; -} - - -QAbstractItemModel *ModelMenu::model() const -{ - return m_model; -} - - -void ModelMenu::setMaxRows(int max) -{ - m_maxRows = max; -} - - -int ModelMenu::maxRows() const -{ - return m_maxRows; -} - - -void ModelMenu::setFirstSeparator(int offset) -{ - m_firstSeparator = offset; -} - - -int ModelMenu::firstSeparator() const -{ - return m_firstSeparator; -} - - -void ModelMenu::setRootIndex(const QModelIndex &index) -{ - m_root = index; -} - - -QModelIndex ModelMenu::rootIndex() const -{ - return m_root; -} - - -void ModelMenu::setHoverRole(int role) -{ - m_hoverRole = role; -} - - -int ModelMenu::hoverRole() const -{ - return m_hoverRole; -} - - -void ModelMenu::setSeparatorRole(int role) -{ - m_separatorRole = role; -} - - -int ModelMenu::separatorRole() const -{ - return m_separatorRole; -} - - -Q_DECLARE_METATYPE(QModelIndex) -void ModelMenu::aboutToShow() -{ - if (QMenu *menu = qobject_cast(sender())) - { - QVariant v = menu->menuAction()->data(); - if (v.canConvert()) - { - QModelIndex idx = qvariant_cast(v); - createMenu(idx, -1, menu, menu); - disconnect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShow())); - return; - } - } - - clear(); - if (prePopulated()) - addSeparator(); - int max = m_maxRows; - if (max != -1) - max += m_firstSeparator; - createMenu(m_root, max, this, this); - postPopulated(); -} - - -// WARNING -// the code commented out here is to create a second separator in the history menu -// with ALL history, subdivided by days. -void ModelMenu::createMenu(const QModelIndex &parent, int max, QMenu *parentMenu, QMenu *menu) -{ - Q_UNUSED(parentMenu) - - if (!menu) - { - return; - } - - int end = m_model->rowCount(parent); - if (max != -1) - end = qMin(max, end); - - connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(triggered(QAction*))); - connect(menu, SIGNAL(hovered(QAction*)), this, SLOT(hovered(QAction*))); - - for (int i = 0; i < end; ++i) - { - QModelIndex idx = m_model->index(i, 0, parent); - - if( !m_model->hasChildren(idx) && ( m_separatorRole == 0 || !idx.data(m_separatorRole).toBool() ) ) - { - menu->addAction(makeAction(idx)); - } - } -} - -KAction *ModelMenu::makeAction(const QModelIndex &index) -{ - QIcon icon = qvariant_cast(index.data(Qt::DecorationRole)); - KAction *action = (KAction *) makeAction(KIcon(icon), index.data().toString(), this); - QVariant v; - v.setValue(index); - action->setData(v); - return action; -} - -KAction *ModelMenu::makeAction(const KIcon &icon, const QString &text, QObject *parent) -{ - QFontMetrics fm(font()); - if (-1 == m_maxWidth) - m_maxWidth = fm.width(QLatin1Char('m')) * 30; - QString smallText = fm.elidedText(text, Qt::ElideMiddle, m_maxWidth); - return new KAction(icon, smallText, parent); -} - -void ModelMenu::triggered(QAction *action) -{ - QVariant v = action->data(); - if (v.canConvert()) - { - QModelIndex idx = qvariant_cast(v); - emit activated(idx); - } -} - -void ModelMenu::hovered(QAction *action) -{ - QVariant v = action->data(); - if (v.canConvert()) - { - QModelIndex idx = qvariant_cast(v); - QString hoveredString = idx.data(m_hoverRole).toString(); - if (!hoveredString.isEmpty()) - emit hovered(hoveredString); - } -} diff --git a/src/modelmenu.h b/src/modelmenu.h deleted file mode 100644 index 719319bc..00000000 --- a/src/modelmenu.h +++ /dev/null @@ -1,109 +0,0 @@ -/* ============================================================ -* -* This file is a part of the rekonq project -* -* Copyright (C) 2007-2008 Trolltech ASA. All rights reserved -* Copyright (C) 2008-2009 by Andrea Diamantini * -* -* 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) version 3 or any later version -* accepted by the membership of KDE e.V. (or its successor approved -* by the membership of KDE e.V.), which shall act as a proxy -* defined in Section 14 of version 3 of the license. -* -* 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, see . -* -* ============================================================ */ - - -#ifndef MODELMENU_H -#define MODELMENU_H - - -// KDE Includes -#include -#include -#include - -// Qt Includes -#include -#include - -// Forward Declarations -class QString; -class QWidget; -class QObject; -class QPersistentModelIndex; - -class KIcon; - - -/** - * A KMenu that is dynamically populated - * from a QAbstractItemModel - * - */ -class ModelMenu : public KMenu -{ - Q_OBJECT - -signals: - void activated(const QModelIndex &index); - void hovered(const QString &text); - -public: - ModelMenu(QWidget *parent = 0); - - void setModel(QAbstractItemModel *model); - QAbstractItemModel *model() const; - - void setMaxRows(int max); - int maxRows() const; - - void setFirstSeparator(int offset); - int firstSeparator() const; - - void setRootIndex(const QModelIndex &index); - QModelIndex rootIndex() const; - - void setHoverRole(int role); - int hoverRole() const; - - void setSeparatorRole(int role); - int separatorRole() const; - - KAction *makeAction(const KIcon &icon, const QString &text, QObject *parent); - -protected: - // add any actions before the tree, return true if any actions are added. - virtual bool prePopulated(); - // add any actions after the tree - virtual void postPopulated(); - // put all of the children of parent into menu up to max - void createMenu(const QModelIndex &parent, int max, QMenu *parentMenu = 0, QMenu *menu = 0); - -private slots: - void aboutToShow(); - void triggered(QAction *action); - void hovered(QAction *action); - -private: - KAction *makeAction(const QModelIndex &index); - int m_maxRows; - int m_firstSeparator; - int m_maxWidth; - int m_hoverRole; - int m_separatorRole; - QAbstractItemModel *m_model; - QPersistentModelIndex m_root; -}; - -#endif // MODELMENU_H -- cgit v1.2.1