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

kvnc.cpp

Go to the documentation of this file.
00001 #include <opie2/oresource.h>
00002 
00003 #include <qpe/qpeapplication.h>
00004 
00005 #include <qaction.h>
00006 #include <qpopupmenu.h>
00007 #include <qpushbutton.h>
00008 #include <qmessagebox.h>
00009 #include <qlistbox.h>
00010 
00011 #include <assert.h>
00012 
00013 #include "kvnc.h"
00014 #include "krfbcanvas.h"
00015 #include "krfbconnection.h"
00016 #include "kvncconndlg.h"
00017 
00018 static int u_id = 1;
00019 static int get_unique_id()
00020 {
00021                 return u_id++;
00022 }
00023 
00024 
00025 /* XPM */
00026 static char * menu_xpm[] = {
00027 "12 12 5 1",
00028 "       c None",
00029 ".      c #000000",
00030 "+      c #FFFDAD",
00031 "@      c #FFFF00",
00032 "#      c #E5E100",
00033 "            ",
00034 "            ",
00035 "  ......... ",
00036 "  .+++++++. ",
00037 "  .+@@@@#.  ",
00038 "  .+@@@#.   ",
00039 "  .+@@#.    ",
00040 "  .+@#.     ",
00041 "  .+#.      ",
00042 "  .+.       ",
00043 "  ..        ",
00044 "            "};
00045 
00046 const int StatusTextId = 0;
00047 
00048 KVNC::KVNC(  QWidget *parent, const char *name, WFlags ) : QMainWindow( parent, name ,WStyle_ContextHelp)
00049 {
00050     setCaption( tr("VNC Viewer") );
00051     fullscreen = false;
00052 
00053                 stack = new QWidgetStack( this );
00054                 setCentralWidget( stack );
00055 
00056                 bookmarkSelector=new KVNCBookmarkDlg();
00057                 stack->addWidget(bookmarkSelector,get_unique_id());
00058                 stack->raiseWidget( bookmarkSelector );
00059 
00060                 canvas = new KRFBCanvas( stack, "canvas" );
00061                 stack->addWidget(canvas,get_unique_id());
00062     setCentralWidget( stack );
00063 
00064 
00065     connect( bookmarkSelector->bookmarkList, SIGNAL(clicked(QListBoxItem*)),
00066             this, SLOT(openConnection(QListBoxItem*)) );
00067     connect( canvas->connection(), SIGNAL(statusChanged(const QString&)),
00068             this, SLOT(statusMessage(const QString&)) );
00069     connect( canvas->connection(), SIGNAL(error(const QString&)),
00070             this, SLOT(error(const QString&)) );
00071     connect( canvas->connection(), SIGNAL(connected()), this, SLOT(connected()) );
00072     connect( canvas->connection(), SIGNAL(loggedIn()), this, SLOT(loggedIn()) );
00073     connect( canvas->connection(), SIGNAL(disconnected()), this, SLOT(disconnected()) );
00074 
00075     setupActions();
00076 
00077     cornerButton = new QPushButton( this );
00078     cornerButton->setPixmap( QPixmap( (const char**)menu_xpm ) );
00079     connect( cornerButton, SIGNAL(pressed()), this, SLOT(showMenu()) );
00080     canvas->setCornerWidget( cornerButton );
00081 
00082                 stack->raiseWidget( bookmarkSelector );
00083 
00084 
00085                 bar= new QToolBar( this );
00086                 setToolBarsMovable( false );
00087                 setRightJustification(false);
00088 
00089 
00090          QAction *n = new QAction( tr( "New Connection" ), Opie::Core::OResource::loadPixmap( "new",
00091                                    Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00092                  connect( n, SIGNAL( activated() ),
00093                                                 this, SLOT( newConnection() ) );
00094                 n->addTo( bar );
00095 
00096          QAction *o = new QAction( tr( "Open Bookmark" ), Opie::Core::OResource::loadPixmap( "fileopen",
00097                                    Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00098                  connect( o, SIGNAL( activated() ),
00099                                                 this, SLOT( openConnection() ) );
00100                 o->addTo( bar );
00101 
00102          QAction *d = new QAction( tr( "Delete Bookmark" ), Opie::Core::OResource::loadPixmap( "trash",
00103                                    Opie::Core::OResource::SmallIcon ), QString::null, 0, this, 0 );
00104                  connect( d, SIGNAL( activated() ),
00105                                                 this, SLOT( deleteBookmark() ) );
00106                 d->addTo( bar );
00107 }
00108 
00109 KVNC::~KVNC()
00110 {
00111 
00112 }
00113 
00114 void KVNC::newConnection()
00115 {
00116     curServer=new KRFBServer;
00117 
00118                 KVNCConnDlg dlg( curServer,this);
00119                 if ( QPEApplication::execDialog( &dlg )) {
00120                                 if (!curServer->name.isEmpty())
00121                                                 bookmarkSelector->addBookmark(curServer);
00122                                 canvas->openConnection(*curServer);
00123                 } else
00124                                 curServer=0;
00125 }
00126 
00127 void KVNC::openConnection( QString name)
00128 {
00129     curServer=bookmarkSelector->getServer(name);
00130 
00131                 if (curServer) {
00132                                 KVNCConnDlg dlg( curServer,this);
00133                         if ( QPEApplication::execDialog( &dlg ) ) {
00134                                         canvas->openConnection(*curServer);
00135                                         bookmarkSelector->writeBookmarks();
00136                         } else
00137                                         curServer=0;
00138                 }
00139 }
00140 
00141 void KVNC::openConnection( void )
00142 {
00143                 openConnection( bookmarkSelector->selectedBookmark());
00144 }
00145 
00146 void KVNC::openConnection( QListBoxItem * item)
00147 {
00148     if (item)
00149                 openConnection(item->text());
00150 }
00151 
00152 void KVNC::setupActions()
00153 {
00154     cornerMenu = new QPopupMenu( this );
00155 
00156     fullScreenAction = new QAction( tr("Full Screen"), QString::null, 0, 0 );
00157     connect( fullScreenAction, SIGNAL(activated()),
00158             this, SLOT( toggleFullScreen() ) );
00159     fullScreenAction->addTo( cornerMenu );
00160     fullScreenAction->setEnabled( false );
00161 
00162     ctlAltDelAction = new QAction( tr("Send Contrl-Alt-Delete"), QString::null, 0, 0 );
00163     connect( ctlAltDelAction, SIGNAL(activated()),
00164             canvas, SLOT( sendCtlAltDel() ) );
00165     ctlAltDelAction->addTo( cornerMenu );
00166     ctlAltDelAction->setEnabled( false );
00167 
00168     disconnectAction = new QAction( tr("Disconnect"), QString::null, 0, 0 );
00169     connect( disconnectAction, SIGNAL(activated()),
00170             this, SLOT( closeConnection() ) );
00171     disconnectAction->addTo( cornerMenu );
00172     disconnectAction->setEnabled( false );
00173 
00174     doubleClickAction = new QAction( tr("Next Click is Double Click"), QString::null, 0, 0 );
00175     connect( doubleClickAction, SIGNAL(activated()),
00176             canvas, SLOT( markDoubleClick() ) );
00177     doubleClickAction->addTo( cornerMenu );
00178     doubleClickAction->setEnabled( false );
00179 
00180     rightClickAction = new QAction( tr("Next Click is Right Click"), QString::null, 0, 0 );
00181     connect( rightClickAction, SIGNAL(activated()),
00182             canvas, SLOT( markRightClick() ) );
00183     rightClickAction->addTo( cornerMenu );
00184     rightClickAction->setEnabled( false );
00185 }
00186 
00187 void KVNC::toggleFullScreen()
00188 {
00189                 if ( fullscreen ) {
00190                         canvas->releaseKeyboard();
00191                         canvas->reparent( stack, 0, QPoint(0,0), false );
00192                         canvas->setFrameStyle( QFrame::Panel | QFrame::Sunken );
00193                         setCentralWidget( stack );
00194                         stack->addWidget(canvas,get_unique_id());
00195                         stack->raiseWidget(canvas);
00196                         canvas->show();
00197                         stack->show();
00198                         fullScreenAction->setText( tr("Full Screen") );
00199                 } else {
00200                         canvas->setFrameStyle( QFrame::NoFrame );
00201                         stack->removeWidget(canvas);
00202                                 canvas->reparent( 0,WStyle_Tool | WStyle_Customize | WStyle_StaysOnTop,
00203                         QPoint(0,0),false);
00204                         canvas->resize(qApp->desktop()->width(), qApp->desktop()->height());
00205                         canvas->raise();
00206                         canvas->setFocus();
00207                                 canvas->grabKeyboard();
00208                                 canvas->show();
00209 
00210                                 fullScreenAction->setText( tr("Stop Full Screen") );
00211                 }
00212 
00213 
00214     fullscreen = !fullscreen;
00215 }
00216 
00217 void KVNC::closeConnection()
00218 {
00219     if ( fullscreen )
00220         toggleFullScreen();
00221     canvas->closeConnection();
00222 }
00223 
00224 void KVNC::showMenu()
00225 {
00226     QPoint pt = mapToGlobal(cornerButton->pos());
00227     QSize s = cornerMenu->sizeHint();
00228     pt.ry() -= s.height();
00229     pt.rx() -= s.width();
00230     cornerMenu->popup( pt );
00231 }
00232 
00233 void KVNC::connected()
00234 {
00235     static QString msg = tr( "Connected to remote host" );
00236     statusMessage( msg );
00237     ctlAltDelAction->setEnabled(true);
00238     disconnectAction->setEnabled( true );
00239     fullScreenAction->setEnabled( true );
00240     doubleClickAction->setEnabled( false );
00241     rightClickAction->setEnabled( true );
00242                 stack->raiseWidget(canvas);
00243                 bar->hide();
00244 }
00245 
00246 void KVNC::loggedIn()
00247 {
00248     static QString msg = tr( "Logged in to remote host" );
00249     statusMessage( msg );
00250 }
00251 
00252 void KVNC::disconnected()
00253 {
00254 
00255                 if ( fullscreen )
00256                                 toggleFullScreen();
00257     static QString msg = tr( "Connection closed" );
00258     statusMessage( msg );
00259     ctlAltDelAction->setEnabled(false);
00260     disconnectAction->setEnabled( false );
00261     fullScreenAction->setEnabled( false );
00262     doubleClickAction->setEnabled( false );
00263     rightClickAction->setEnabled( false );
00264                 stack->raiseWidget(bookmarkSelector);
00265                 bar->show();
00266 }
00267 
00268 void KVNC::statusMessage( const QString &m )
00269 {
00270     Global::statusMessage( m );
00271 }
00272 
00273 void KVNC::error( const QString &msg )
00274 {
00275     statusMessage( msg );
00276     QMessageBox::warning( this, tr("VNC Viewer"), msg );
00277 }
00278 void KVNC::deleteBookmark(void)
00279 {
00280                 bookmarkSelector->deleteBookmark(bookmarkSelector->selectedBookmark());
00281 }

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