summaryrefslogtreecommitdiff
path: root/noncore/unsupported/ubrowser/mainview.cpp
authormickeyl <mickeyl>2004-11-08 10:38:01 (UTC)
committer mickeyl <mickeyl>2004-11-08 10:38:01 (UTC)
commit9eaf9b69dd95fc20133f2bdff1b624ff9257c420 (patch) (unidiff)
tree4bed7aad0433f50ee004828e904dbc2837715772 /noncore/unsupported/ubrowser/mainview.cpp
parent18875a0d90d0425c066e6fa2cda81a6140fe8606 (diff)
downloadopie-9eaf9b69dd95fc20133f2bdff1b624ff9257c420.zip
opie-9eaf9b69dd95fc20133f2bdff1b624ff9257c420.tar.gz
opie-9eaf9b69dd95fc20133f2bdff1b624ff9257c420.tar.bz2
move ubroser to unsupported
Diffstat (limited to 'noncore/unsupported/ubrowser/mainview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/ubrowser/mainview.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/noncore/unsupported/ubrowser/mainview.cpp b/noncore/unsupported/ubrowser/mainview.cpp
new file mode 100644
index 0000000..f299b54
--- a/dev/null
+++ b/noncore/unsupported/ubrowser/mainview.cpp
@@ -0,0 +1,121 @@
1/*
2Opie-uBrowser. a very small web browser, using on QTextBrowser for html display/parsing
3Copyright (C) 2002 Thomas Stephens
4
5This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7version.
8
9This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11Public License for more details.
12
13You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
14Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15*/
16
17
18#include "mainview.h"
19
20MainView::MainView(QWidget *parent, const char *name, WFlags fl) : QMainWindow(parent, name, fl)
21{
22 setIcon( Resource::loadPixmap( "remote" ) );
23 setCaption(tr("uBrowser"));
24
25 setToolBarsMovable( false );
26
27 QToolBar *toolbar = new QToolBar(this, "toolbar");
28 back = new QToolButton(Resource::loadPixmap("ubrowser/back"), 0, 0, 0, 0, toolbar, "back");
29 forward = new QToolButton(Resource::loadPixmap("ubrowser/forward"), 0, 0, 0, 0, toolbar, "forward");
30 home = new QToolButton(Resource::loadPixmap("ubrowser/home"), 0, 0, 0, 0, toolbar, "home");
31 location = new QComboBox(true, toolbar, "location");
32 go = new QToolButton(Resource::loadPixmap("ubrowser/go"), 0, 0, 0, 0, toolbar, "go");
33
34 toolbar->setStretchableWidget(location);
35 toolbar->setHorizontalStretchable(true);
36 location->setAutoCompletion( true );
37
38 addToolBar(toolbar);
39
40 browser = new QTextBrowser(this, "browser");
41 setCentralWidget(browser);
42
43//make the button take you to the location
44 connect(go, SIGNAL(clicked()), this, SLOT(goClicked()) );
45 connect(location->lineEdit(), SIGNAL(returnPressed()), this, SLOT(goClicked()) );
46
47//make back, forward and home do their thing (isnt QTextBrowser great?)
48 connect(back, SIGNAL(clicked()), browser, SLOT(backward()) );
49 connect(forward, SIGNAL(clicked()), browser, SLOT(forward()) );
50 connect(home, SIGNAL(clicked()), browser, SLOT(home()) );
51
52//make back and forward buttons be enabled, only when you can go back or forward (again, i love QTextBrowser)
53//this doesnt seem to work, but doesnt break anything either...
54 connect(browser, SIGNAL(backwardAvailable(bool)), back, SLOT(setOn(bool)) );
55 connect(browser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setOn(bool)) );
56
57//notify me when the text of the browser has changed (like when the user clicks a link)
58 connect(browser, SIGNAL(textChanged()), this, SLOT(textChanged()) );
59
60 http = new HttpFactory(browser);
61
62 if( qApp->argc() > 1 )
63 {
64 char **argv = qApp->argv();
65 int i = 0;
66 QString *openfile = new QString( argv[0] );
67 while( openfile->contains( "ubrowser" ) == 0 && i < qApp->argc() )
68 {
69 i++;
70 *openfile = argv[i];
71 }
72 *openfile = argv[i+1];
73 if( !openfile->startsWith( "http://" ) && !openfile->startsWith( "/" ) )
74 {
75 openfile->insert( 0, QDir::currentDirPath()+"/" );
76 }
77 location->setEditText( *openfile );
78 goClicked();
79 }
80}
81
82void MainView::goClicked()
83{
84 location->insertItem( location->currentText() );
85
86 if(location->currentText().startsWith("http://") )
87 {
88 location->setEditText(location->currentText().lower());
89 browser->setMimeSourceFactory(http);
90 printf("MainView::goClicked: using http source factory\n");
91 }
92 else
93 {
94 browser->setMimeSourceFactory(QMimeSourceFactory::defaultFactory());
95 printf("MainView::goClicked: using default source factory\n");
96 }
97
98 browser->setSource(location->currentText());
99}
100
101void MainView::textChanged()
102{
103 if(browser->documentTitle().isNull())
104 {
105 setCaption( tr("%1 - uBrowser").arg( browser->source() ) );
106 }
107 else
108 {
109 setCaption(tr(" - uBrowser").arg( browser->documentTitle() ));
110 }
111
112 location->setEditText(browser->source());
113}
114
115void MainView::setDocument( const QString& applnk_filename )
116{
117 DocLnk *file = new DocLnk( applnk_filename );
118
119 location->setEditText( file->file() );
120 goClicked();
121}