Fixed random SEGV in Konqueror caused by klipper when the clipboard was being cleared. This resolves issue #147.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/178/head
Michele Calgaro 3 years ago
parent 364708d89e
commit e2158a0f0b
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -146,6 +146,7 @@ KlipperWidget::KlipperWidget( TQWidget *parent, TDEConfig* config )
connect( &m_overflowClearTimer, TQT_SIGNAL( timeout()), TQT_SLOT( slotClearOverflow())); connect( &m_overflowClearTimer, TQT_SIGNAL( timeout()), TQT_SLOT( slotClearOverflow()));
m_overflowClearTimer.start( 1000 ); m_overflowClearTimer.start( 1000 );
connect( &m_pendingCheckTimer, TQT_SIGNAL( timeout()), TQT_SLOT( slotCheckPending())); connect( &m_pendingCheckTimer, TQT_SIGNAL( timeout()), TQT_SLOT( slotCheckPending()));
connect( &m_setClipboardTimer, TQT_SIGNAL( timeout()), TQT_SLOT( slotDelayedSetClipboard()));
m_history = new History( this, "main_history" ); m_history = new History( this, "main_history" );
@ -809,6 +810,41 @@ void KlipperWidget::slotCheckPending()
newClipData( true ); // always selection newClipData( true ); // always selection
} }
void KlipperWidget::slotDelayedSetClipboard()
{
const HistoryItem *top = history()->first();
if (top)
{
if (bCheckForEmpty)
{
TQMimeSource *data = clip->data( bSavedSelectionMode ? TQClipboard::Selection : TQClipboard::Clipboard );
if ( !data )
{
kdWarning("No data in clipboard. This is not supposed to happen." );
return;
}
bool clipEmpty = ( data->format() == 0L );
if ( clipEmpty && bNoNullClipboard )
{
// keep old clipboard after someone set it to null
#ifdef NOISY_KLIPPER
kdDebug() << "Resetting clipboard (Prevent empty clipboard)" << endl;
#endif
setClipboard( *top, bSavedSelectionMode ? Selection : Clipboard );
return;
}
}
else
{
#ifdef NOISY_KLIPPER
kdDebug() << "Syncing selection and clipboard" << endl;
#endif
setClipboard( *top, bSavedSelectionMode ? Selection : Clipboard );
}
}
}
void KlipperWidget::checkClipData( bool selectionMode ) void KlipperWidget::checkClipData( bool selectionMode )
{ {
if ( ignoreClipboardChanges() ) // internal to klipper, ignoring TQSpinBox selections if ( ignoreClipboardChanges() ) // internal to klipper, ignoring TQSpinBox selections
@ -868,15 +904,14 @@ void KlipperWidget::checkClipData( bool selectionMode )
bool changed = data->serialNumber() != lastSerialNo; bool changed = data->serialNumber() != lastSerialNo;
bool clipEmpty = ( data->format() == 0L ); bool clipEmpty = ( data->format() == 0L );
if ( changed && clipEmpty && bNoNullClipboard ) { if ( changed && clipEmpty && bNoNullClipboard )
const HistoryItem* top = history()->first(); {
if ( top ) { // Make sure to call setClipboard() through the event loop.
// keep old clipboard after someone set it to null // Using a direct call may crash another application that was
#ifdef NOISY_KLIPPER // changing the clipboard at the same time.
kdDebug() << "Resetting clipboard (Prevent empty clipboard)" << endl; bSavedSelectionMode = selectionMode;
#endif bCheckForEmpty = true;
setClipboard( *top, selectionMode ? Selection : Clipboard ); m_setClipboardTimer.start(100, TRUE);
}
return; return;
} }
@ -945,11 +980,14 @@ void KlipperWidget::checkClipData( bool selectionMode )
#ifdef NOISY_KLIPPER #ifdef NOISY_KLIPPER
kdDebug() << "Synchronize?" << ( bSynchronize ? "yes" : "no" ) << endl; kdDebug() << "Synchronize?" << ( bSynchronize ? "yes" : "no" ) << endl;
#endif #endif
if ( bSynchronize ) { if ( bSynchronize )
const HistoryItem* topItem = history()->first(); {
if ( topItem ) { // Make sure to call setClipboard() through the event loop.
setClipboard( *topItem, selectionMode ? Clipboard : Selection ); // Using a direct call may crash another application that was
} // changing the clipboard at the same time.
bSavedSelectionMode = !selectionMode; // inverted in order to sync
bCheckForEmpty = false;
m_setClipboardTimer.start(100, TRUE);
} }
} }

@ -154,6 +154,7 @@ private slots:
void slotClearOverflow(); void slotClearOverflow();
void slotCheckPending(); void slotCheckPending();
void slotDelayedSetClipboard();
private: private:
@ -186,6 +187,8 @@ private:
bool bSynchronize :1; bool bSynchronize :1;
bool bSelectionTextOnly :1; bool bSelectionTextOnly :1;
bool bIgnoreImages :1; bool bIgnoreImages :1;
bool bSavedSelectionMode :1;
bool bCheckForEmpty :1;
/** /**
* Avoid reacting to our own changes, using this * Avoid reacting to our own changes, using this
@ -201,6 +204,7 @@ private:
TDEConfig* m_config; TDEConfig* m_config;
TQTimer m_overflowClearTimer; TQTimer m_overflowClearTimer;
TQTimer m_pendingCheckTimer; TQTimer m_pendingCheckTimer;
TQTimer m_setClipboardTimer;
bool m_pendingContentsCheck; bool m_pendingContentsCheck;
ClipboardPoll* poll; ClipboardPoll* poll;
static TDEAboutData* about_data; static TDEAboutData* about_data;

Loading…
Cancel
Save