u8 PWS_SendData (u8 Slot_u8, u8 Kind_u8)
{
u8 SendString_au8[40];

u32 Ret_u32;

    // LED_GreenOn ();

    switch (Kind_u8)
    {
        case PWS_SEND_PASSWORD:
            Ret_u32 = PWS_GetSlotPassword (Slot_u8, SendString_au8);
            if (FALSE == Ret_u32)
            {
                return (FALSE);
            }
            sendString ((char *) SendString_au8, strlen ((char *) SendString_au8));
            break;
        case PWS_SEND_LOGINNAME:
            Ret_u32 = PWS_GetSlotLoginName (Slot_u8, SendString_au8);
            if (FALSE == Ret_u32)
            {
                return (FALSE);
            }
            sendString ((char *) SendString_au8, strlen ((char *) SendString_au8));
            break;
        case PWS_SEND_TAB:
            sendTab ();
            break;
        case PWS_SEND_CR:
            sendEnter ();
            break;

    }

    // LED_GreenOff ();

    return (TRUE);
}
MainWindow::MainWindow(QString url, int quality, int listen_port, bool view_only):
    QMainWindow(0),
    vnc_view(0),
    scroll_area(new ScrollArea(this)),
    input_toolbuttons(new QActionGroup(this)),
    key_menu(0)
{
    setWindowTitle("Presence VNC");
#ifdef Q_WS_MAEMO_5
    setContextMenuPolicy(Qt::NoContextMenu);
    setAttribute(Qt::WA_Maemo5StackedWindow);
#endif

    migrateConfiguration();

    //set up toolbar
    toolbar = new QToolBar(0);
    key_menu_button = input_toolbuttons->addAction(toolbar->addAction(QChar(0x2026), this, SLOT(showKeyMenu()))); //"..." button
    key_menu_button->setCheckable(true); //used to indicate wether a modifier key is still pressed
    input_toolbuttons->addAction(toolbar->addAction(tr("Tab"), this, SLOT(sendTab())));
    input_toolbuttons->addAction(toolbar->addAction(tr("Esc"), this, SLOT(sendEsc())));
    input_toolbuttons->addAction(toolbar->addAction(tr("PgUp"), this, SLOT(sendPgUp())));
    input_toolbuttons->addAction(toolbar->addAction(tr("PgDn"), this, SLOT(sendPgDn())));
#ifdef Q_WS_MAEMO_5
    input_toolbuttons->addAction(toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/chat_enter.png"), "", this, SLOT(sendReturn())));
    input_toolbuttons->addAction(toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/control_keyboard.png"), "", this, SLOT(showInputPanel())));
#endif

    QSettings settings;
    zoom_slider = new QSlider(Qt::Horizontal, 0);
    zoom_slider->setRange(0, 100);
    connect(zoom_slider, SIGNAL(valueChanged(int)),
            this, SLOT(setZoomLevel(int)));
    connect(zoom_slider, SIGNAL(sliderReleased()),
            this, SLOT(zoomSliderReleased()));
    zoom_slider->setValue(settings.value("zoomlevel", 95).toInt());
    toolbar->addWidget(zoom_slider);

#ifdef Q_WS_MAEMO_5
    toolbar->addAction(QIcon("/usr/share/icons/hicolor/48x48/hildon/general_fullsize.png"), "", this, SLOT(toggleFullscreen()));
#else
    toolbar->addAction(tr("Toggle Fullscreen"), this, SLOT(toggleFullscreen()));
#endif
    addToolBar(toolbar);
    toolbar->setVisible(settings.value("show_toolbar", true).toBool());
    toolbar->setEnabled(false);

    //set up menu
    QAction *connect_action = new QAction(tr("Connect"), this);
    disconnect_action = new QAction(tr("Disconnect"), this);
    show_toolbar = new QAction(tr("Show toolbar"), this);
    show_toolbar->setCheckable(true);
    show_toolbar->setChecked(settings.value("show_toolbar", true).toBool());
    QAction *pref_action = new QAction(tr("Preferences"), this);
    QAction *about_action = new QAction(tr("About"), this);

#ifdef Q_WS_MAEMO_5
    menuBar()->addAction(connect_action);
    menuBar()->addAction(disconnect_action);
    menuBar()->addAction(show_toolbar);
    menuBar()->addAction(pref_action);
    menuBar()->addAction(about_action);
#else
    QMenu* session_menu = menuBar()->addMenu(tr("&Session"));
    session_menu->addAction(connect_action);
    session_menu->addAction(disconnect_action);
    session_menu->addSeparator();
    session_menu->addAction(pref_action);
    session_menu->addSeparator();
    session_menu->addAction(tr("&Quit"), this, SLOT(close()));

    QMenu* view_menu = menuBar()->addMenu(tr("&View"));
    view_menu->addAction(show_toolbar);

    QMenu* help_menu = menuBar()->addMenu(tr("&Help"));
    help_menu->addAction(about_action);
#endif

    connect(about_action, SIGNAL(triggered()),
            this, SLOT(about()));
    connect(pref_action, SIGNAL(triggered()),
            this, SLOT(showPreferences()));
    connect(connect_action, SIGNAL(triggered()),
            this, SLOT(showConnectDialog()));
    connect(disconnect_action, SIGNAL(triggered()),
            this, SLOT(disconnectFromHost()));
    connect(show_toolbar, SIGNAL(toggled(bool)),
            toolbar, SLOT(setVisible(bool)));
    connect(show_toolbar, SIGNAL(toggled(bool)),
            this, SLOT(updateScreenSpaceDelayed()));
#ifdef Q_WS_MAEMO_5
    QDBusConnection::systemBus().connect("", MCE_SIGNAL_PATH, MCE_SIGNAL_IF, MCE_DISPLAY_SIG,
                                         this, SLOT(displayStateChanged(QString)));
#endif

    setCentralWidget(scroll_area);

    connect(scroll_area, SIGNAL(fullscreenButtonClicked()),
            this, SLOT(toggleFullscreen()));

    grabZoomKeys(true);
    reloadSettings();

    if(url.isEmpty() and listen_port == 0) {
        disconnect_action->setEnabled(false);
        showConnectDialog();
    } else {
        connectToHost(url, quality, listen_port, view_only);
    }
}