summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/history/autosaver.cpp67
-rw-r--r--src/history/autosaver.h31
-rw-r--r--src/history/historymanager.cpp43
-rw-r--r--src/mainview.cpp12
-rw-r--r--src/mainview.h2
-rw-r--r--src/mainwindow.cpp6
-rw-r--r--src/tabbar.cpp8
7 files changed, 86 insertions, 83 deletions
diff --git a/src/history/autosaver.cpp b/src/history/autosaver.cpp
index 83b3f6b0..3b966b52 100644
--- a/src/history/autosaver.cpp
+++ b/src/history/autosaver.cpp
@@ -25,73 +25,72 @@
* ============================================================ */
-
-
// Self Includes
#include "autosaver.h"
#include "autosaver.moc"
// Qt Includes
#include <QtCore/QMetaObject>
+#include <QtCore/QTimerEvent>
+#include <QtCore/QBasicTimer>
+#include <QtCore/QTime>
-#define AUTOSAVE_IN 1000 * 3 // seconds
-#define MAXWAIT 1000 * 15 // seconds
+const int AUTOSAVE_TIME = 1000 * 3; // seconds
+const int MAX_TIME_LIMIT = 1000 * 15; // seconds
-AutoSaver::AutoSaver(QObject *parent) : QObject(parent)
+AutoSaver::AutoSaver(QObject *parent)
+ : QObject(parent)
+ , m_timer(new QBasicTimer)
+ , m_firstChange(new QTime)
{
- Q_ASSERT(parent);
}
AutoSaver::~AutoSaver()
{
- if (m_timer.isActive())
- {
+ if (m_timer->isActive())
kDebug() << "AutoSaver: still active when destroyed, changes not saved.";
- }
+
+ delete m_firstChange;
+ delete m_timer;
+}
+
+
+void AutoSaver::saveIfNeccessary()
+{
+ if (m_timer->isActive())
+ save();
}
void AutoSaver::changeOccurred()
{
- if (m_firstChange.isNull())
- m_firstChange.start();
+ if (m_firstChange->isNull())
+ m_firstChange->start();
- if (m_firstChange.elapsed() > MAXWAIT)
- {
- saveIfNeccessary();
- }
+ if (m_firstChange->elapsed() > MAX_TIME_LIMIT)
+ save();
else
- {
- m_timer.start(AUTOSAVE_IN, this);
- }
+ m_timer->start(AUTOSAVE_TIME, this);
}
void AutoSaver::timerEvent(QTimerEvent *event)
{
- if (event->timerId() == m_timer.timerId())
- {
- saveIfNeccessary();
- }
+ if (event->timerId() == m_timer->timerId())
+ save();
else
- {
QObject::timerEvent(event);
- }
}
-void AutoSaver::saveIfNeccessary()
+void AutoSaver::save()
{
- if (!m_timer.isActive())
- return;
- m_timer.stop();
- m_firstChange = QTime();
- if (!QMetaObject::invokeMethod(parent(), "save", Qt::DirectConnection))
- {
- kDebug() << "AutoSaver: error invoking slot save() on parent";
- }
-}
+ m_timer->stop();
+ delete m_firstChange;
+ m_firstChange = new QTime;
+ emit saveNeeded();
+}
diff --git a/src/history/autosaver.h b/src/history/autosaver.h
index 6927dbe8..685783a8 100644
--- a/src/history/autosaver.h
+++ b/src/history/autosaver.h
@@ -34,37 +34,42 @@
// Qt Includes
#include <QtCore/QObject>
-#include <QtCore/QBasicTimer>
-#include <QtCore/QTime>
-#include <QtCore/QTimerEvent>
+// Forward Declarations
+class QBasicTimer;
/**
- * 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.
- *
+ * This class emits the saveNeeded() signal.
+ * It will wait several seconds after changeOccurred() to combine
+ * multiple changes preventing continuous writing to disk.
*/
-
class REKONQ_TESTS_EXPORT AutoSaver : public QObject
{
Q_OBJECT
public:
- AutoSaver(QObject *parent);
- ~AutoSaver();
+ explicit AutoSaver(QObject *parent);
+ virtual ~AutoSaver();
+
+ /**
+ * Emits the saveNeeded() signal if there's been any change since we last saved.
+ */
void saveIfNeccessary();
+signals:
+ void saveNeeded();
+
public slots:
void changeOccurred();
protected:
- void timerEvent(QTimerEvent *event);
+ virtual void timerEvent(QTimerEvent *event);
private:
- QBasicTimer m_timer;
- QTime m_firstChange;
+ void save();
+ QBasicTimer *m_timer;
+ QTime *m_firstChange;
};
#endif // AUTOSAVER_H
diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp
index 4a2c0459..92f9caee 100644
--- a/src/history/historymanager.cpp
+++ b/src/history/historymanager.cpp
@@ -72,6 +72,7 @@ HistoryManager::HistoryManager(QObject *parent)
connect(this, SIGNAL(entryAdded(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred()));
connect(this, SIGNAL(entryRemoved(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred()));
+ connect(m_saveTimer, SIGNAL(saveNeeded()), this, SLOT(save()));
load();
@@ -88,11 +89,9 @@ HistoryManager::HistoryManager(QObject *parent)
HistoryManager::~HistoryManager()
{
m_saveTimer->saveIfNeccessary();
-
+
delete m_historyFilterModel;
delete m_historyTreeModel;
-
- delete m_saveTimer;
}
@@ -107,7 +106,7 @@ void HistoryManager::addHistoryEntry(const QString &url)
QWebSettings *globalSettings = QWebSettings::globalSettings();
if (globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled))
return;
-
+
QUrl cleanUrl(url);
// don't store about: urls (home page related)
@@ -129,7 +128,7 @@ void HistoryManager::addHistoryEntry(const QString &url)
void HistoryManager::setHistory(const QList<HistoryItem> &history, bool loadedAndSorted)
{
m_history = history;
-
+
// verify that it is sorted by date
if (!loadedAndSorted)
qSort(m_history.begin(), m_history.end());
@@ -189,14 +188,14 @@ void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title)
urlString.remove(QL1S("www."));
if(urlString.startsWith(QL1S("http")) && urlString.endsWith(QL1C('/')))
urlString.remove(urlString.length()-1,1);
-
+
for (int i = 0; i < m_history.count(); ++i)
{
QString itemUrl = m_history.at(i).url;
itemUrl.remove(QL1S("www."));
if(itemUrl.startsWith(QL1S("http")) && itemUrl.endsWith(QL1C('/')))
itemUrl.remove(itemUrl.length()-1,1);
-
+
if (urlString == itemUrl)
{
m_history[i].title = title;
@@ -204,7 +203,7 @@ void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title)
m_saveTimer->changeOccurred();
if (m_lastSavedUrl.isEmpty())
m_lastSavedUrl = m_history.at(i).url;
-
+
emit entryUpdated(i);
break;
}
@@ -253,7 +252,7 @@ QList<HistoryItem> HistoryManager::find(const QString &text)
if (matches)
list << item;
}
-
+
return list;
}
@@ -274,25 +273,25 @@ void HistoryManager::loadSettings()
int days;
switch (historyExpire)
{
- case 0:
- days = 1;
+ case 0:
+ days = 1;
break;
- case 1:
- days = 7;
+ case 1:
+ days = 7;
break;
- case 2:
- days = 14;
+ case 2:
+ days = 14;
break;
- case 3:
- days = 30;
+ case 3:
+ days = 30;
break;
- case 4:
- days = 365;
+ case 4:
+ days = 365;
break;
- case 5:
- days = -1;
+ case 5:
+ days = -1;
break;
- default:
+ default:
days = -1;
break;
}
diff --git a/src/mainview.cpp b/src/mainview.cpp
index f020fb53..3daee339 100644
--- a/src/mainview.cpp
+++ b/src/mainview.cpp
@@ -633,13 +633,13 @@ void MainView::previousTab()
}
-void MainView::openClosedTabs()
+void MainView::openLastClosedTab()
{
- foreach (const HistoryItem &item, recentlyClosedTabs())
- {
- Application::instance()->loadUrl( KUrl(item.url), Rekonq::NewTab);
- }
- m_recentlyClosedTabs.clear();
+ if (m_recentlyClosedTabs.isEmpty())
+ return;
+
+ const HistoryItem item = m_recentlyClosedTabs.takeFirst();
+ Application::instance()->loadUrl(KUrl(item.url), Rekonq::NewTab);
}
diff --git a/src/mainview.h b/src/mainview.h
index 6fab7fc0..29162dd1 100644
--- a/src/mainview.h
+++ b/src/mainview.h
@@ -135,7 +135,7 @@ public slots:
void nextTab();
void previousTab();
- void openClosedTabs();
+ void openLastClosedTab();
void openClosedTab();
void switchToTab();
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 4c766ba0..4d3dfc91 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -449,10 +449,10 @@ void MainWindow::setupActions()
actionCollection()->addAction(QL1S("show_prev_tab"), a);
connect(a, SIGNAL(triggered(bool)), m_view, SLOT(previousTab()));
- a = new KAction(KIcon("tab-new"), i18n("Open Closed Tabs"), this);
+ a = new KAction(KIcon("tab-new"), i18n("Open Last Closed Tab"), this);
a->setShortcut(KShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_T));
- actionCollection()->addAction(QL1S("open_closed_tabs"), a);
- connect(a, SIGNAL(triggered(bool)), m_view, SLOT(openClosedTabs()));
+ actionCollection()->addAction(QL1S("open_last_closed_tab"), a);
+ connect(a, SIGNAL(triggered(bool)), m_view, SLOT(openLastClosedTab()));
// Closed Tabs Menu
KActionMenu *closedTabsMenu = new KActionMenu(KIcon("tab-new"), i18n("Closed Tabs"), this);
diff --git a/src/tabbar.cpp b/src/tabbar.cpp
index d403a39c..1756c20e 100644
--- a/src/tabbar.cpp
+++ b/src/tabbar.cpp
@@ -293,7 +293,7 @@ void TabBar::contextMenu(int tab, const QPoint &pos)
menu.addAction(mainWindow->actionByName( QL1S("clone_tab") ));
if (count() > 1)
menu.addAction(mainWindow->actionByName( QL1S("detach_tab") ));
- menu.addAction(mainWindow->actionByName( QL1S("open_closed_tabs") ));
+ menu.addAction(mainWindow->actionByName( QL1S("open_last_closed_tab") ));
menu.addAction(mainWindow->actionByName( QL1S("closed_tab_menu") ));
menu.addSeparator();
menu.addAction(mainWindow->actionByName( QL1S("close_tab") ));
@@ -314,7 +314,7 @@ void TabBar::emptyAreaContextMenu(const QPoint &pos)
MainWindow *mainWindow = Application::instance()->mainWindow();
menu.addAction(mainWindow->actionByName( QL1S("new_tab") ));
- menu.addAction(mainWindow->actionByName( QL1S("open_closed_tabs") ));
+ menu.addAction(mainWindow->actionByName( QL1S("open_last_closed_tab") ));
menu.addAction(mainWindow->actionByName( QL1S("closed_tab_menu") ));
menu.addSeparator();
menu.addAction(mainWindow->actionByName( QL1S("reload_all_tabs") ));
@@ -357,8 +357,8 @@ void TabBar::setupHistoryActions()
MainWindow *w = Application::instance()->mainWindow();
MainView *mv = qobject_cast<MainView *>(parent());
- QAction *openClosedTabsAction = w->actionByName( QL1S("open_closed_tabs") );
- openClosedTabsAction->setEnabled( mv->recentlyClosedTabs().size() > 0 );
+ QAction *openLastClosedTabAction = w->actionByName( QL1S("open_last_closed_tab") );
+ openLastClosedTabAction->setEnabled( mv->recentlyClosedTabs().size() > 0 );
// update closed tabs menu
KActionMenu *am = qobject_cast<KActionMenu *>( w->actionByName( QL1S("closed_tab_menu") ));