m_buttonMask(0),
cursor_x(0),
cursor_y(0),
- m_repaint(false),
m_quitFlag(false),
m_firstPasswordTry(true),
m_dontSendClipboard(false),
m_horizontalFactor(1.0),
m_verticalFactor(1.0),
m_forceLocalCursor(false),
- force_full_repaint(false),
quality(quality),
listen_port(listen_port)
{
connect(&vncThread, SIGNAL(passwordRequest()), this, SLOT(requestPassword()), Qt::BlockingQueuedConnection);
connect(&vncThread, SIGNAL(outputErrorMessage(QString)), this, SLOT(outputErrorMessage(QString)));
+ //don't miss early connection failures
+ connect(&vncThread, SIGNAL(finished()), this, SLOT(startQuitting()));
+
m_clipboard = QApplication::clipboard();
connect(m_clipboard, SIGNAL(selectionChanged()), this, SLOT(clipboardSelectionChanged()));
connect(m_clipboard, SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
startQuitting();
}
-void VncView::forceFullRepaint()
-{
- force_full_repaint = true;
- repaint();
-}
-
bool VncView::eventFilter(QObject *obj, QEvent *event)
{
if (m_viewOnly) {
void VncView::startQuitting()
{
+ if(isQuitting())
+ return;
+
kDebug(5011) << "about to quit";
//const bool connected = status() == RemoteView::Connected;
QHBoxLayout layout1;
QVBoxLayout layout2;
layout2.addWidget(&passwordbox);
- layout2.addWidget(&save_password);
+ if(!m_host.isEmpty()) //don't save incomming connections
+ layout2.addWidget(&save_password);
layout1.addLayout(&layout2);
layout1.addWidget(&ok_button);
dialog.setLayout(&layout1);
if(dialog.exec()) { //dialog accepted
password = passwordbox.text();
- if(save_password.isChecked()) {
+ if(!m_host.isEmpty() and save_password.isChecked()) {
kDebug(5011) << "Saving password for host '" << m_host << "'";
settings.setValue(QString("%1/password").arg(m_host), password);
vncThread.setPassword(password);
} else {
- startQuitting();
+ vncThread.setPassword(QString()); //null string to exit
}
}
void VncView::outputErrorMessage(const QString &message)
{
- kDebug(5011) << message;
-
if (message == "INTERNAL:APPLE_VNC_COMPATIBILTY") {
setCursor(localDotCursor());
m_forceLocalCursor = true;
m_frame = vncThread.image();
- if (!m_initDone) {
+ if (!m_initDone) { //TODO this seems an odd place for initialization
setAttribute(Qt::WA_StaticContents);
setAttribute(Qt::WA_OpaquePaintEvent);
installEventFilter(this);
setMouseTracking(true); // get mouse events even when there is no mousebutton pressed
setFocusPolicy(Qt::WheelFocus);
setStatus(Connected);
-// emit framebufferSizeChanged(m_frame.width(), m_frame.height());
emit connected();
resize(width(), height());
emit framebufferSizeChanged(m_frame.width(), m_frame.height());
}
- m_repaint = true;
repaint(qRound(m_x * m_horizontalFactor), qRound(m_y * m_verticalFactor), qRound(m_w * m_horizontalFactor), qRound(m_h * m_verticalFactor));
- m_repaint = false;
}
void VncView::setViewOnly(bool viewOnly)
event->accept();
- QPainter painter(this);
-
Qt::TransformationMode transformation_mode = Qt::SmoothTransformation;
if( m_horizontalFactor >= 1.0 )
transformation_mode = Qt::FastTransformation;
- if (m_repaint and !force_full_repaint) {
-// kDebug(5011) << "normal repaint";
- painter.drawImage(QRect(qRound(m_x*m_horizontalFactor), qRound(m_y*m_verticalFactor),
- qRound(m_w*m_horizontalFactor), qRound(m_h*m_verticalFactor)),
- m_frame.copy(m_x, m_y, m_w, m_h).scaled(qRound(m_w*m_horizontalFactor),
- qRound(m_h*m_verticalFactor),
- Qt::IgnoreAspectRatio, transformation_mode));
- } else {
- //kDebug(5011) << "resize repaint";
- QRect rect = event->rect();
- if (!force_full_repaint and (rect.width() != width() || rect.height() != height())) {
- // kDebug(5011) << "Partial repaint";
- const int sx = rect.x()/m_horizontalFactor;
- const int sy = rect.y()/m_verticalFactor;
- const int sw = rect.width()/m_horizontalFactor;
- const int sh = rect.height()/m_verticalFactor;
- painter.drawImage(rect,
- m_frame.copy(sx, sy, sw, sh).scaled(rect.width(), rect.height(),
- Qt::IgnoreAspectRatio, transformation_mode));
- } else {
- kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
- painter.drawImage(QRect(0, 0, width(), height()),
- m_frame.scaled(m_frame.width() * m_horizontalFactor, m_frame.height() * m_verticalFactor,
- Qt::IgnoreAspectRatio, transformation_mode));
- force_full_repaint = false;
- }
+ const QRect update_rect = event->rect();
+ QPainter painter(this);
+ if (update_rect != rect()) {
+ // kDebug(5011) << "Partial repaint";
+ const int sx = qRound(update_rect.x()/m_horizontalFactor);
+ const int sy = qRound(update_rect.y()/m_verticalFactor);
+ const int sw = qRound(update_rect.width()/m_horizontalFactor);
+ const int sh = qRound(update_rect.height()/m_verticalFactor);
+
+ painter.drawImage(update_rect,
+ m_frame.copy(sx, sy, sw, sh).scaled(update_rect.size(), Qt::IgnoreAspectRatio, transformation_mode));
+ } else {
+ kDebug(5011) << "Full repaint" << width() << height() << m_frame.width() << m_frame.height();
+
+ painter.drawImage(rect(),
+ m_frame.scaled(size(), Qt::IgnoreAspectRatio, transformation_mode));
}
//draw local cursor ourselves, normal mouse pointer doesn't deal with scrolling
void VncView::resizeEvent(QResizeEvent *event)
{
RemoteView::resizeEvent(event);
- forceFullRepaint();
+ update();
}
bool VncView::event(QEvent *event)
//to get at individual key presses, we split 'keys' into its components
QList<int> key_list;
- for(int i = 0; ; i++) {
- QString k = keys.toString().section('+', i, i);
+ int pos = 0;
+ while(true) {
+ QString k = keys.toString().section('+', pos, pos);
if(k.isEmpty())
break;
+
//kDebug(5011) << "found key: " << k;
if(k == "Alt") {
key_list.append(Qt::Key_Alt);
} else {
key_list.append(QKeySequence(k)[0]);
}
+
+ pos++;
}
for(int i = 0; i < key_list.count(); i++)