diff options
-rw-r--r-- | src/history.cpp | 43 | ||||
-rw-r--r-- | src/history.h | 15 | ||||
-rw-r--r-- | src/urlbar.cpp | 50 | ||||
-rw-r--r-- | src/urlbar.h | 6 |
4 files changed, 52 insertions, 62 deletions
diff --git a/src/history.cpp b/src/history.cpp index 574b0cf2..da39c4be 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -42,6 +42,7 @@ #include <KDebug> #include <KStandardDirs> #include <KLocale> +#include <KCompletion> // Qt Includes #include <QtCore/QList> @@ -64,17 +65,23 @@ static const unsigned int HISTORY_VERSION = 23; HistoryManager::HistoryManager(QObject *parent) - : QWebHistoryInterface(parent) - , m_saveTimer(new AutoSaver(this)) - , m_historyLimit(30) - , m_historyModel(0) - , m_historyFilterModel(0) - , m_historyTreeModel(0) + : QWebHistoryInterface(parent) + , m_saveTimer(new AutoSaver(this)) + , m_historyLimit(30) + , m_historyModel(0) + , m_historyFilterModel(0) + , m_historyTreeModel(0) + , m_completion(0) { + // take care of the completion object + m_completion = new KCompletion; + m_completion->setOrder( KCompletion::Weighted ); + m_expiredTimer.setSingleShot(true); connect(&m_expiredTimer, SIGNAL(timeout()), this, SLOT(checkForExpired())); connect(this, SIGNAL(entryAdded(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); connect(this, SIGNAL(entryRemoved(const HistoryItem &)), m_saveTimer, SLOT(changeOccurred())); + load(); m_historyModel = new HistoryModel(this, this); @@ -98,14 +105,12 @@ QList<HistoryItem> HistoryManager::history() const } -// TODO port to KDE history bool HistoryManager::historyContains(const QString &url) const { return m_historyFilterModel->historyContains(url); } -// TODO port to KDE history void HistoryManager::addHistoryEntry(const QString &url) { QUrl cleanUrl(url); @@ -113,6 +118,11 @@ void HistoryManager::addHistoryEntry(const QString &url) cleanUrl.setHost(cleanUrl.host().toLower()); HistoryItem item(cleanUrl.toString(), QDateTime::currentDateTime()); addHistoryEntry(item); + + // Add item to completion object + QString _url(url); + _url.remove(QRegExp("^http://|/$")); + m_completion->addItem(_url); } @@ -199,6 +209,7 @@ void HistoryManager::addHistoryEntry(const HistoryItem &item) m_history.prepend(item); emit entryAdded(item); + if (m_history.count() == 1) checkForExpired(); } @@ -240,6 +251,11 @@ void HistoryManager::removeHistoryEntry(const KUrl &url, const QString &title) break; } } + + // Remove item from completion object + QString _url = url.path(); + _url.remove(QRegExp("^http://|/$")); + m_completion->removeItem(_url); } @@ -340,6 +356,11 @@ void HistoryManager::load() list.prepend(item); lastInsertedItem = item; + + // Add item to completion object + QString _url = item.url; + _url.remove(QRegExp("^http://|/$")); + m_completion->addItem(_url); } if (needToSort) qSort(list.begin(), list.end()); @@ -421,3 +442,9 @@ void HistoryManager::save() } m_lastSavedUrl = m_history.value(0).url; } + + +KCompletion * HistoryManager::completionObject() const +{ + return m_completion; +} diff --git a/src/history.h b/src/history.h index 24e4fea9..bd7fd7fc 100644 --- a/src/history.h +++ b/src/history.h @@ -87,7 +87,14 @@ class HistoryModel; class HistoryFilterModel; class HistoryTreeModel; +class KCompletion; + +/** + * THE History Manager: + * It manages rekonq history + * + */ class HistoryManager : public QWebHistoryInterface { Q_OBJECT @@ -119,6 +126,11 @@ public: HistoryFilterModel *historyFilterModel() const; HistoryTreeModel *historyTreeModel() const; + /** + * @returns the KCompletion object. + */ + KCompletion *completionObject() const; + public slots: void clear(); void loadSettings(); @@ -143,6 +155,9 @@ private: HistoryModel *m_historyModel; HistoryFilterModel *m_historyFilterModel; HistoryTreeModel *m_historyTreeModel; + + // the completion object we sync with + KCompletion *m_completion; }; diff --git a/src/urlbar.cpp b/src/urlbar.cpp index 24df96f7..54aa0ecf 100644 --- a/src/urlbar.cpp +++ b/src/urlbar.cpp @@ -56,8 +56,6 @@ UrlBar::UrlBar(QWidget *parent) : KHistoryComboBox(true, parent) , m_lineEdit(new LineEdit) , m_progress(0) - , m_completion(0) - , m_completionModel(0) { setUrlDropsEnabled(true); setAutoDeleteCompletionObject(true); @@ -77,16 +75,12 @@ UrlBar::UrlBar(QWidget *parent) connect(this, SIGNAL(cleared()), SLOT(slotCleared())); // setup completion box - completionBox()->setTabHandling(true); // Konqueror bug #167135 - setCompletionObject(completion()); + setCompletionObject( Application::historyManager()->completionObject() ); // set dropdown list background QPalette p = view()->palette(); p.setColor(QPalette::Base, palette().color(QPalette::Base)); view()->setPalette(p); -/* - // set empty item with default icon - slotUpdateUrl();*/ } @@ -290,45 +284,3 @@ bool UrlBar::isLoading() } return true; } - - -KCompletion *UrlBar::completion() -{ - // make sure completion was created - if (!m_completion) - { - m_completion = new KCompletion(); - m_completion->setCompletionMode(KGlobalSettings::CompletionPopupAuto); - m_completion->setOrder(KCompletion::Weighted); - m_completion->setIgnoreCase(true); - - kDebug() << "Initialize completion list..."; - HistoryCompletionModel *model = completionModel(); - int count = model->rowCount(); - kDebug() << "...initialize history items" << count; - - // change order to insertion to avoid confusion of the addItem method - // in weighted it expects format string:number and it thinks http it the whole string - m_completion->setOrder(KCompletion::Insertion); - for (int i = 0; i < count; ++i) - { - QString item = model->data(model->index(i, 0)).toString(); - item.remove(QRegExp("^http://|/$")); - m_completion->addItem(item); - } - - m_completion->setOrder(KCompletion::Weighted); - } - return m_completion; -} - - -HistoryCompletionModel *UrlBar::completionModel() -{ - if (!m_completionModel) - { - m_completionModel = new HistoryCompletionModel(this); - m_completionModel->setSourceModel(Application::historyManager()->historyFilterModel()); - } - return m_completionModel; -} diff --git a/src/urlbar.h b/src/urlbar.h index a12c5f62..80fbb759 100644 --- a/src/urlbar.h +++ b/src/urlbar.h @@ -60,8 +60,7 @@ public: QSize sizeHint() const; void setBackgroundColor(QColor); bool isLoading(); - KCompletion *completion(); - HistoryCompletionModel *completionModel(); + void setProgress(int progress); signals: @@ -94,9 +93,6 @@ private: KUrl m_currentUrl; int m_progress; - - KCompletion *m_completion; - HistoryCompletionModel *m_completionModel; }; #endif |