[developerteam getadooble] SF.net SVN: dooble:[926] trunk/browser
Brought to you by:
textfield
From: <tex...@us...> - 2009-11-23 01:09:58
|
Revision: 926 http://dooble.svn.sourceforge.net/dooble/?rev=926&view=rev Author: textfield Date: 2009-11-23 01:09:25 +0000 (Mon, 23 Nov 2009) Log Message: ----------- Replaced QMenu::clear(). (http://goldendict.berlios.de/forum/viewtopic.php?f=6&t=650) Ability to navigate directories via the back and forward buttons. Brief history class. Many changes. Please report errors and strange behavior. Modified Paths: -------------- trunk/browser/Include/dfilemanager.h trunk/browser/Include/dview.h trunk/browser/Source/dfilemanager.cc trunk/browser/Source/dooble.cc trunk/browser/Source/dview.cc trunk/browser/dooble.osx.pro trunk/browser/dooble.pro trunk/browser/dooble.win.pro Added Paths: ----------- trunk/browser/Include/dwebhistoryitem.h trunk/browser/Source/dwebhistoryitem.cc Modified: trunk/browser/Include/dfilemanager.h =================================================================== --- trunk/browser/Include/dfilemanager.h 2009-11-18 01:15:07 UTC (rev 925) +++ trunk/browser/Include/dfilemanager.h 2009-11-23 01:09:25 UTC (rev 926) @@ -52,8 +52,12 @@ #define _dfilemanager_h_ #include <QUrl> +#include <QList> +#include <QtDebug> #include <QWidget> +#include <QWebHistory> +#include "dwebhistoryitem.h" #include "ui_fileManagerForm.h" class dfilemanager: public QWidget @@ -64,8 +68,10 @@ dfilemanager(QWidget *parent); ~dfilemanager(); QUrl url(void); + void back(void); void load(const QUrl &url); void reload(void); + void forward(void); QString title(void); private: @@ -82,8 +88,100 @@ } }; + class webHistory + { + public: + webHistory(void) + { + current = 0; + } + + ~webHistory() + { + container.clear(); + } + + QUrl back(void) + { + if(canGoBack()) + { + current += 1; + return container.at(current).url(); + } + else + return QUrl(); + } + + QUrl forward(void) + { + if(canGoForward()) + { + current -= 1; + return container.at(current).url(); + } + else + return QUrl(); + } + + bool canGoBack(void) + { + if(container.isEmpty()) + return false; + else + return current < container.size() - 1; + } + + bool canGoForward(void) + { + if(container.isEmpty()) + return false; + else + return current > 0; + } + + void add(const QUrl &url) + { + if(container.isEmpty()) + container.append(dwebhistoryitem(url)); + else + { + dwebhistoryitem item(url); + + if(!container.contains(item)) + container.insert(current, item); + } + } + + void clear(void) + { + current = 0; + container.clear(); + } + + QList<dwebhistoryitem> backItems(const int n) + { + return container.mid(current, qMin(n, container.size())); + } + + QList<dwebhistoryitem> forwardItems(const int n) + { + return container.mid(0, qMin(n, current)); + } + + private: + int current; + QList<dwebhistoryitem> container; + }; + + public: + webHistory *history(void) + { + return m_history; + } + private: QUrl m_url; + webHistory *m_history; Ui_FileManagerForm ui; private slots: Modified: trunk/browser/Include/dview.h =================================================================== --- trunk/browser/Include/dview.h 2009-11-18 01:15:07 UTC (rev 925) +++ trunk/browser/Include/dview.h 2009-11-23 01:09:25 UTC (rev 926) @@ -54,7 +54,9 @@ #include <QUrl> #include <QWebView> +#include "dwebpage.h" #include "dfilemanager.h" +#include "dwebhistoryitem.h" class dview: public QStackedWidget { @@ -66,6 +68,8 @@ int progress(void); bool isLoaded(void); bool findText(const QString &subString, QWebPage::FindFlags options = 0); + bool canGoBack(void); + bool canGoForward(void); QUrl url(void); void back(void); void load(const QUrl &url); @@ -75,9 +79,9 @@ void clearHistoryAfterNextLoad(void); QIcon icon(void); QString title(void); - QWebPage *page(void); - QWebView *view(void); - QWebHistory *history(void); + dwebpage *page(void); + QList<dwebhistoryitem> backItems(const int n); + QList<dwebhistoryitem> forwardItems(const int n); private: int percentLoaded; Added: trunk/browser/Include/dwebhistoryitem.h =================================================================== --- trunk/browser/Include/dwebhistoryitem.h (rev 0) +++ trunk/browser/Include/dwebhistoryitem.h 2009-11-23 01:09:25 UTC (rev 926) @@ -0,0 +1,76 @@ +/**************************************************************************** +** Dooble - The Secure Internet Web Browser +** +** Copyright (c) 2008, 2009 Alexis Megas, +** Gunther van Dooble, and the Dooble Team. +** All rights reserved. +** +** License: GPL2 only: +** 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; version 2 of the License only. +** +** 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +** or see here: http://www.gnu.org/licenses/gpl.html +** +** For the WebKit library, please see: http://webkit.org. +** +** THE CODE IS PROVIDED BY THE AUTHORS ''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 AUTHOR 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 APPLICATION, EVEN IF ADVISED +** OF THE POSSIBILITY OF SUCH DAMAGE. +** +** Please report all praise, requests, bugs, and problems to the project +** team and administrators: http://sf.net/projects/dooble. +** +** You can find us listed at our project page. New team members are welcome. +** The name of the authors should not be used to endorse or promote products +** derived from Dooble without specific prior written permission. +** If you use this code for other projects, please let us know. +** +** Web sites: +** http://dooble.net/projects/dooble +** http://dooble.sf.net +** http://www.getadooble.com +****************************************************************************/ + +#ifndef _dwebhistoryitem_h_ +#define _dwebhistoryitem_h_ + +#include <QUrl> +#include <QObject> +#include <QString> + +class dwebhistoryitem: public QObject +{ + Q_OBJECT + + public: + dwebhistoryitem(const dwebhistoryitem &other, QObject *parent = 0); + dwebhistoryitem(const QUrl &url, QObject *parent = 0); + ~dwebhistoryitem(); + bool operator==(const dwebhistoryitem &other); + QUrl url(void) const; + QString title(void) const; + dwebhistoryitem &operator=(const dwebhistoryitem &other); + + private: + QUrl m_url; + QString m_title; +}; + +#endif Modified: trunk/browser/Source/dfilemanager.cc =================================================================== --- trunk/browser/Source/dfilemanager.cc 2009-11-18 01:15:07 UTC (rev 925) +++ trunk/browser/Source/dfilemanager.cc 2009-11-23 01:09:25 UTC (rev 926) @@ -59,6 +59,7 @@ dfilemanager::dfilemanager(QWidget *parent):QWidget(parent) { ui.setupUi(this); + m_history = new webHistory(); ui.tableWidget->verticalHeader()->setResizeMode(QHeaderView::Fixed); connect(ui.tableWidget->horizontalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(slotResizeColumnsAfterSort(void))); @@ -68,6 +69,7 @@ dfilemanager::~dfilemanager() { + delete m_history; } void dfilemanager::load(const QUrl &url) @@ -129,10 +131,11 @@ (ui.tableWidget->columnCount() - 1, QHeaderView::Stretch); list.clear(); headers.clear(); + m_history->add(m_url); emit urlChanged(m_url); emit iconChanged(); + emit titleChanged(m_url.toString(QUrl::StripTrailingSlash)); emit loadFinished(true); - emit titleChanged(m_url.toString(QUrl::StripTrailingSlash)); } QUrl dfilemanager::url(void) @@ -167,3 +170,25 @@ if(dir.cd(ui.tableWidget->item(row, 0)->text())) load(QUrl::fromLocalFile(dir.absolutePath())); } + +void dfilemanager::back(void) +{ + QUrl url(m_history->back()); + + if(!url.isEmpty()) + { + m_url = url; + load(m_url); + } +} + +void dfilemanager::forward(void) +{ + QUrl url(m_history->forward()); + + if(!url.isEmpty()) + { + m_url = url; + load(m_url); + } +} Modified: trunk/browser/Source/dooble.cc =================================================================== --- trunk/browser/Source/dooble.cc 2009-11-18 01:15:07 UTC (rev 925) +++ trunk/browser/Source/dooble.cc 2009-11-23 01:09:25 UTC (rev 926) @@ -62,7 +62,6 @@ #include <QFileDialog> #include <QMessageBox> #include <QTranslator> -#include <QWebHistory> #include <QApplication> #include <QPrintDialog> #include <QNetworkReply> @@ -696,7 +695,7 @@ if(p) { - ui.forwardToolButton->setEnabled(p->history()->canGoForward()); + ui.forwardToolButton->setEnabled(p->canGoForward()); sb.progressBar->setVisible(true); ui.stopToolButton->setEnabled(true); ui.actionStop->setEnabled(true); @@ -710,7 +709,7 @@ if(p) { - ui.backToolButton->setEnabled(p->history()->canGoBack()); + ui.backToolButton->setEnabled(p->canGoBack()); sb.progressBar->setVisible(true); ui.stopToolButton->setEnabled(true); ui.actionStop->setEnabled(true); @@ -751,8 +750,8 @@ sb.progressBar->setValue(p->progress()); ui.stopToolButton->setEnabled(!p->isLoaded()); ui.actionStop->setEnabled(!p->isLoaded()); - ui.backToolButton->setEnabled(p->history()->canGoBack()); - ui.forwardToolButton->setEnabled(p->history()->canGoForward()); + ui.backToolButton->setEnabled(p->canGoBack()); + ui.forwardToolButton->setEnabled(p->canGoForward()); ui.locationLineEdit->setIcon(p->icon()); ui.locationLineEdit->blockSignals(true); ui.locationLineEdit->setText @@ -905,8 +904,8 @@ sb.progressBar->setVisible(false); ui.stopToolButton->setEnabled(false); ui.actionStop->setEnabled(false); - ui.backToolButton->setEnabled(p->history()->canGoBack()); - ui.forwardToolButton->setEnabled(p->history()->canGoForward()); + ui.backToolButton->setEnabled(p->canGoBack()); + ui.forwardToolButton->setEnabled(p->canGoForward()); } if(p && !p->title().isNull()) @@ -979,9 +978,11 @@ if(!p) return; - QList<QWebHistoryItem> list(p->history()->backItems(50)); + while(!ui.backToolButton->menu()->actions().isEmpty()) + ui.backToolButton->menu()->removeAction + (ui.backToolButton->menu()->actions().takeFirst()); - ui.backToolButton->menu()->clear(); + QList<dwebhistoryitem> list(p->backItems(50)); for(int i = 0; i < list.size(); i++) { @@ -997,14 +998,11 @@ if(icon.isNull()) { - /* - QSettings settings; - QSettings cfgSettings + QSettings settings; + QSettings cfgSettings (settings.value("iconSet").toString(), QSettings::IniFormat); - cfgSettings.beginGroup("mainWindow"); - icon = QIcon(cfgSettings.value("emptyIcon").toString()); - */ + icon = QIcon(cfgSettings.value("mainWindow/emptyIcon").toString()); } QAction *action = ui.backToolButton->menu()->addAction @@ -1015,9 +1013,14 @@ (QVariant(list.at(i).url().toString(QUrl::StripTrailingSlash))); } - ui.forwardToolButton->menu()->clear(); - list = p->history()->forwardItems(50); + list.clear(); + while(!ui.forwardToolButton->menu()->actions().isEmpty()) + ui.forwardToolButton->menu()->removeAction + (ui.forwardToolButton->menu()->actions().takeFirst()); + + list = p->forwardItems(50); + for(int i = 0; i < list.size(); i++) { QString title(list.at(i).title()); @@ -1032,14 +1035,11 @@ if(icon.isNull()) { - /* - QSettings settings; - QSettings cfgSettings + QSettings settings; + QSettings cfgSettings (settings.value("iconSet").toString(), QSettings::IniFormat); - cfgSettings.beginGroup("mainWindow"); - icon = QIcon(cfgSettings.value("emptyIcon").toString()); - */ + icon = QIcon(cfgSettings.value("mainWindow/emptyIcon").toString()); } QAction *action = ui.forwardToolButton->menu()->addAction @@ -1049,6 +1049,8 @@ action->setData (QVariant(list.at(i).url().toString(QUrl::StripTrailingSlash))); } + + list.clear(); } void dooble::slotGoHome(void) Modified: trunk/browser/Source/dview.cc =================================================================== --- trunk/browser/Source/dview.cc 2009-11-18 01:15:07 UTC (rev 925) +++ trunk/browser/Source/dview.cc 2009-11-23 01:09:25 UTC (rev 926) @@ -247,6 +247,7 @@ void dview::slotClearHistory(void) { webView->history()->clear(); + fileManager->history()->clear(); } void dview::load(const QUrl &url) @@ -274,37 +275,21 @@ QIcon dview::icon(void) { - if(currentIndex() == 0) + if(!url().isEmpty() && url().toLocalFile().isEmpty()) { if(webView->icon().isNull()) - { - QIcon icon(QWebSettings::iconForUrl(webView->url())); - - if(icon.isNull()) - { - QSettings settings; - QSettings cfgSettings - (settings.value("iconSet").toString(), QSettings::IniFormat); - - return QIcon - (cfgSettings.value("mainWindow/emptyIcon").toString()); - } - else - return icon; - } + return QWebSettings::iconForUrl(webView->url()); else return webView->icon(); } - else if(currentIndex() == 1) + else { QSettings settings; QSettings cfgSettings (settings.value("iconSet").toString(), QSettings::IniFormat); - return QIcon(cfgSettings.value("mainWindow/folderIcon").toString()); + return QIcon(cfgSettings.value("mainWindow/emptyIcon").toString()); } - else - return QIcon(); } void dview::slotCopySelectedText(void) @@ -312,9 +297,9 @@ webView->triggerPageAction(QWebPage::Copy); } -QWebPage *dview::page(void) +dwebpage *dview::page(void) { - return webView->page(); + return qobject_cast<dwebpage *> (webView->page()); } QUrl dview::url(void) @@ -342,12 +327,18 @@ void dview::back(void) { - webView->back(); + if(currentIndex() == 0) + webView->back(); + else if(currentIndex() == 1) + fileManager->back(); } void dview::forward(void) { - webView->forward(); + if(currentIndex() == 0) + webView->forward(); + else if(currentIndex() == 1) + fileManager->forward(); } QString dview::title(void) @@ -360,21 +351,11 @@ return QString(); } -QWebHistory *dview::history(void) -{ - return webView->history(); -} - bool dview::findText(const QString &subString, QWebPage::FindFlags options) { return webView->findText(subString, options); } -QWebView *dview::view(void) -{ - return webView; -} - void dview::slotUrlChanged(const QUrl &url) { emit urlChanged(url); @@ -389,3 +370,68 @@ { emit iconChanged(); } + +bool dview::canGoBack(void) +{ + if(currentIndex() == 0) + return webView->history()->canGoBack(); + else if(currentIndex() == 1) + return fileManager->history()->canGoBack(); + else + return false; +} + +bool dview::canGoForward(void) +{ + if(currentIndex() == 0) + return webView->history()->canGoForward(); + else if(currentIndex() == 1) + return fileManager->history()->canGoForward(); + else + return false; +} + +QList<dwebhistoryitem> dview::backItems(const int n) +{ + if(currentIndex() == 0) + { + QList<dwebhistoryitem> list; + + for(int i = 0; i < webView->history()->backItems(n).size(); i++) + { + dwebhistoryitem item(webView->history()->backItems(n).at(i).url()); + + if(!list.contains(item)) + list.append(item); + } + + return list; + } + else if(currentIndex() == 1) + return fileManager->history()->backItems(n); + else + return QList<dwebhistoryitem> (); +} + +QList<dwebhistoryitem> dview::forwardItems(const int n) +{ + if(currentIndex() == 0) + { + QList<dwebhistoryitem> list; + + for(int i = 0; i < webView->history()->forwardItems(n).size(); i++) + { + dwebhistoryitem item + (webView->history()->forwardItems(n).at(i).url()); + + if(!list.contains(item)) + list.append(item); + } + + return list; + } + else if(currentIndex() == 1) + return fileManager->history()->forwardItems(n); + else + return QList<dwebhistoryitem> (); +} Added: trunk/browser/Source/dwebhistoryitem.cc =================================================================== --- trunk/browser/Source/dwebhistoryitem.cc (rev 0) +++ trunk/browser/Source/dwebhistoryitem.cc 2009-11-23 01:09:25 UTC (rev 926) @@ -0,0 +1,93 @@ +/**************************************************************************** +** Dooble - The Secure Internet Web Browser +** +** Copyright (c) 2008, 2009 Alexis Megas, +** Gunther van Dooble, and the Dooble Team. +** All rights reserved. +** +** License: GPL2 only: +** 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; version 2 of the License only. +** +** 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +** or see here: http://www.gnu.org/licenses/gpl.html +** +** For the WebKit library, please see: http://webkit.org. +** +** THE CODE IS PROVIDED BY THE AUTHORS ''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 AUTHOR 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 APPLICATION, EVEN IF ADVISED +** OF THE POSSIBILITY OF SUCH DAMAGE. +** +** Please report all praise, requests, bugs, and problems to the project +** team and administrators: http://sf.net/projects/dooble. +** +** You can find us listed at our project page. New team members are welcome. +** The name of the authors should not be used to endorse or promote products +** derived from Dooble without specific prior written permission. +** If you use this code for other projects, please let us know. +** +** Web sites: +** http://dooble.net/projects/dooble +** http://dooble.sf.net +** http://www.getadooble.com +****************************************************************************/ + +#include <QtDebug> + +#include "dwebhistoryitem.h" + +dwebhistoryitem::dwebhistoryitem(const QUrl &url, + QObject *parent):QObject(parent) +{ + m_url = url; + m_title = m_url.toString(QUrl::StripTrailingSlash); +} + +dwebhistoryitem::dwebhistoryitem(const dwebhistoryitem &other, + QObject *parent):QObject(parent) +{ + m_url = other.m_url; + m_title = other.m_title; +} + +dwebhistoryitem::~dwebhistoryitem() +{ +} + +bool dwebhistoryitem::operator==(const dwebhistoryitem &other) +{ + return m_url == other.m_url; +} + +QUrl dwebhistoryitem::url(void) const +{ + return m_url; +} + +QString dwebhistoryitem::title(void) const +{ + return m_title; +} + +dwebhistoryitem &dwebhistoryitem::operator=(const dwebhistoryitem &other) +{ + m_url = other.m_url; + m_title = other.m_title; + return *this; +} Modified: trunk/browser/dooble.osx.pro =================================================================== --- trunk/browser/dooble.osx.pro 2009-11-18 01:15:07 UTC (rev 925) +++ trunk/browser/dooble.osx.pro 2009-11-23 01:09:25 UTC (rev 926) @@ -34,6 +34,7 @@ Include/dsearchwidget.h \ Include/ddesktopwidget.h \ Include/downloadwindow.h \ + Include/dwebhistoryitem.h \ Include/pagesourcewindow.h \ Include/downloadwindowitem.h @@ -47,6 +48,7 @@ Source/dsearchwidget.cc \ Source/ddesktopwidget.cc \ Source/downloadwindow.cc \ + Source/dwebhistoryitem.cc \ Source/pagesourcewindow.cc \ Source/downloadwindowitem.cc Modified: trunk/browser/dooble.pro =================================================================== --- trunk/browser/dooble.pro 2009-11-18 01:15:07 UTC (rev 925) +++ trunk/browser/dooble.pro 2009-11-23 01:09:25 UTC (rev 926) @@ -34,6 +34,7 @@ Include/dsearchwidget.h \ Include/ddesktopwidget.h \ Include/downloadwindow.h \ + Include/dwebhistoryitem.h \ Include/pagesourcewindow.h \ Include/downloadwindowitem.h @@ -47,6 +48,7 @@ Source/dsearchwidget.cc \ Source/ddesktopwidget.cc \ Source/downloadwindow.cc \ + Source/dwebhistoryitem.cc \ Source/pagesourcewindow.cc \ Source/downloadwindowitem.cc Modified: trunk/browser/dooble.win.pro =================================================================== --- trunk/browser/dooble.win.pro 2009-11-18 01:15:07 UTC (rev 925) +++ trunk/browser/dooble.win.pro 2009-11-23 01:09:25 UTC (rev 926) @@ -34,6 +34,7 @@ Include\dsearchwidget.h \ Include\ddesktopwidget.h \ Include\downloadwindow.h \ + Include\dwebhistoryitem.h \ Include\pagesourcewindow.h \ Include\downloadwindowitem.h @@ -47,6 +48,7 @@ Source\dsearchwidget.cc \ Source\ddesktopwidget.cc \ Source\downloadwindow.cc \ + Source\dwebhistoryitem.cc \ Source\pagesourcewindow.cc \ Source\downloadwindowitem.cc This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |