Diffstat (limited to 'noncore/net/ubrowser/mainview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/ubrowser/mainview.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/noncore/net/ubrowser/mainview.cpp b/noncore/net/ubrowser/mainview.cpp new file mode 100644 index 0000000..87a7d6a --- a/dev/null +++ b/noncore/net/ubrowser/mainview.cpp | |||
@@ -0,0 +1,88 @@ | |||
1 | /* | ||
2 | Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing | ||
3 | Copyright (C) 2002 Thomas Stephens | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public | ||
6 | License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later | ||
7 | version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | ||
10 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
11 | Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free | ||
14 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
15 | */ | ||
16 | |||
17 | |||
18 | #include "mainview.h" | ||
19 | |||
20 | MainView::MainView(QWidget *parent=0, const char *name=0) : QMainWindow(parent, name) | ||
21 | { | ||
22 | setCaption("uBrowser"); | ||
23 | |||
24 | QPEToolBar *toolbar = new QPEToolBar(this, "toolbar"); | ||
25 | back = new QToolButton(Resource::loadPixmap("ubrowser/back"), 0, 0, 0, 0, toolbar, "back"); | ||
26 | forward = new QToolButton(Resource::loadPixmap("ubrowser/forward"), 0, 0, 0, 0, toolbar, "forward"); | ||
27 | home = new QToolButton(Resource::loadPixmap("ubrowser/home"), 0, 0, 0, 0, toolbar, "home"); | ||
28 | location = new QComboBox(true, toolbar, "location"); | ||
29 | go = new QToolButton(Resource::loadPixmap("ubrowser/go"), 0, 0, 0, 0, toolbar, "go"); | ||
30 | |||
31 | toolbar->setStretchableWidget(location); | ||
32 | toolbar->setHorizontalStretchable(true); | ||
33 | |||
34 | addToolBar(toolbar); | ||
35 | |||
36 | browser = new QTextBrowser(this, "browser"); | ||
37 | setCentralWidget(browser); | ||
38 | |||
39 | //make the button take you to the location | ||
40 | connect(go, SIGNAL(clicked()), this, SLOT(goClicked()) ); | ||
41 | connect(location->lineEdit(), SIGNAL(returnPressed()), this, SLOT(goClicked()) ); | ||
42 | |||
43 | //make back, forward and home do their thing (isnt QTextBrowser great?) | ||
44 | connect(back, SIGNAL(clicked()), browser, SLOT(backward()) ); | ||
45 | connect(forward, SIGNAL(clicked()), browser, SLOT(forward()) ); | ||
46 | connect(home, SIGNAL(clicked()), browser, SLOT(home()) ); | ||
47 | |||
48 | //make back and forward buttons be enabled, only when you can go back or forward (again, i love QTextBrowser) | ||
49 | //this doesnt seem to work, but doesnt break anything either... | ||
50 | connect(browser, SIGNAL(backwardAvailable(bool)), back, SLOT(setOn(bool)) ); | ||
51 | connect(browser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setOn(bool)) ); | ||
52 | |||
53 | //notify me when the text of the browser has changed (like when the user clicks a link) | ||
54 | connect(browser, SIGNAL(textChanged()), this, SLOT(textChanged()) ); | ||
55 | |||
56 | http = new HttpFactory(browser); | ||
57 | } | ||
58 | |||
59 | void MainView::goClicked() | ||
60 | { | ||
61 | if(location->currentText().startsWith("http://") ) | ||
62 | { | ||
63 | location->setEditText(location->currentText().lower()); | ||
64 | browser->setMimeSourceFactory(http); | ||
65 | printf("MainView::goClicked: using http source factory\n"); | ||
66 | } | ||
67 | else | ||
68 | { | ||
69 | browser->setMimeSourceFactory(QMimeSourceFactory::defaultFactory()); | ||
70 | printf("MainView::goClicked: using default source factory\n"); | ||
71 | } | ||
72 | |||
73 | browser->setSource(location->currentText()); | ||
74 | } | ||
75 | |||
76 | void MainView::textChanged() | ||
77 | { | ||
78 | if(browser->documentTitle().isNull()) | ||
79 | { | ||
80 | setCaption(browser->source() + " - uBrowser"); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | setCaption(browser->documentTitle() + " - uBrowser"); | ||
85 | } | ||
86 | |||
87 | location->setEditText(browser->source()); | ||
88 | } | ||