00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00044 connect(go, SIGNAL(clicked()), this, SLOT(goClicked()) );
00045 connect(location->lineEdit(), SIGNAL(returnPressed()), this, SLOT(goClicked()) );
00046
00047
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
00053
00054 connect(browser, SIGNAL(backwardAvailable(bool)), back, SLOT(setOn(bool)) );
00055 connect(browser, SIGNAL(forwardAvailable(bool)), forward, SLOT(setOn(bool)) );
00056
00057
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 }