Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

mainview.cpp

Go to the documentation of this file.
00001 /*
00002 Opie-uBrowser.  a very small web browser, using on QTextBrowser for html display/parsing
00003 Copyright (C) 2002 Thomas Stephens
00004 
00005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
00006 License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
00007 version.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
00010 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00011 Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free
00014 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00015 */
00016 
00017 
00018 #include "mainview.h"
00019 
00020 MainView::MainView(QWidget *parent, const char *name, WFlags fl) : QMainWindow(parent, name, fl)
00021 {
00022         setIcon( Resource::loadPixmap( "remote" ) );
00023         setCaption(tr("uBrowser"));
00024         
00025         setToolBarsMovable( false );
00026 
00027         QToolBar *toolbar = new QToolBar(this, "toolbar");
00028         back = new QToolButton(Resource::loadPixmap("ubrowser/back"), 0, 0, 0, 0, toolbar, "back");
00029         forward = new QToolButton(Resource::loadPixmap("ubrowser/forward"), 0, 0, 0, 0, toolbar, "forward");
00030         home = new QToolButton(Resource::loadPixmap("ubrowser/home"), 0, 0, 0, 0, toolbar, "home");
00031         location = new QComboBox(true, toolbar, "location");
00032         go = new QToolButton(Resource::loadPixmap("ubrowser/go"), 0, 0, 0, 0, toolbar, "go");
00033 
00034         toolbar->setStretchableWidget(location);
00035         toolbar->setHorizontalStretchable(true);
00036         location->setAutoCompletion( true );
00037 
00038         addToolBar(toolbar);
00039 
00040         browser = new QTextBrowser(this, "browser");
00041         setCentralWidget(browser);
00042 
00043 //make the button take you to the location
00044         connect(go, SIGNAL(clicked()), this, SLOT(goClicked()) );
00045         connect(location->lineEdit(), SIGNAL(returnPressed()), this, SLOT(goClicked()) );
00046 
00047 //make back, forward and home do their thing (isnt QTextBrowser great?)
00048         connect(back, SIGNAL(clicked()), browser, SLOT(backward()) );
00049         connect(forward, SIGNAL(clicked()), browser, SLOT(forward()) );
00050         connect(home, SIGNAL(clicked()), browser, SLOT(home()) );
00051         
00052 //make back and forward buttons be enabled, only when you can go back or forward (again, i love QTextBrowser)
00053 //this doesnt seem to work, but doesnt break anything either...
00054         connect(browser, SIGNAL(backwardAvailable(bool)), back, SLOT(setOn(bool)) );
00055         connect(browser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setOn(bool)) );
00056 
00057 //notify me when the text of the browser has changed (like when the user clicks a link)
00058         connect(browser, SIGNAL(textChanged()), this, SLOT(textChanged()) );
00059 
00060         http = new HttpFactory(browser);
00061         
00062         if( qApp->argc() > 1 )
00063         {
00064                 char **argv = qApp->argv();
00065                 int i = 0;
00066                 QString *openfile = new QString( argv[0] );
00067                 while( openfile->contains( "ubrowser" ) == 0 && i < qApp->argc() )
00068                 {
00069                         i++;
00070                         *openfile = argv[i];
00071                 }
00072                 *openfile = argv[i+1];
00073                 if( !openfile->startsWith( "http://" ) && !openfile->startsWith( "/" ) )
00074                 {
00075                         openfile->insert( 0, QDir::currentDirPath()+"/" );
00076                 }
00077                 location->setEditText( *openfile );
00078                 goClicked();
00079         }
00080 }
00081 
00082 void MainView::goClicked()
00083 {
00084         location->insertItem( location->currentText() );
00085         
00086         if(location->currentText().startsWith("http://") )
00087         {
00088                 location->setEditText(location->currentText().lower());
00089                 browser->setMimeSourceFactory(http);
00090                 printf("MainView::goClicked: using http source factory\n");
00091         }
00092         else
00093         {
00094                 browser->setMimeSourceFactory(QMimeSourceFactory::defaultFactory());
00095                 printf("MainView::goClicked: using default source factory\n");
00096         }
00097 
00098         browser->setSource(location->currentText());
00099 }
00100 
00101 void MainView::textChanged()
00102 {
00103         if(browser->documentTitle().isNull())
00104         {
00105                 setCaption( tr("%1 - uBrowser").arg( browser->source() ) );
00106         }
00107         else
00108         {
00109                 setCaption(tr(" - uBrowser").arg( browser->documentTitle() ));
00110         }
00111 
00112         location->setEditText(browser->source());
00113 }
00114 
00115 void MainView::setDocument( const QString& applnk_filename )
00116 {
00117         DocLnk *file = new DocLnk( applnk_filename );
00118         
00119         location->setEditText( file->file() );
00120         goClicked();
00121 }

Generated on Sat Nov 5 16:18:02 2005 for OPIE by  doxygen 1.4.2