diff options
Diffstat (limited to 'klipper/toplevel.cpp')
-rw-r--r-- | klipper/toplevel.cpp | 136 |
1 files changed, 85 insertions, 51 deletions
diff --git a/klipper/toplevel.cpp b/klipper/toplevel.cpp index 278e74bbb..b76c7472b 100644 --- a/klipper/toplevel.cpp +++ b/klipper/toplevel.cpp @@ -1,4 +1,3 @@ -// -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- /* This file is part of the KDE project Copyright (C) by Andrew Stanley-Jones @@ -119,9 +118,6 @@ private: }; extern bool tqt_qclipboard_bailout_hack; -#if KDE_IS_VERSION( 15, 0, 0 ) -#error Check status of #80072 with Qt4. -#endif static void ensureGlobalSyncOff(TDEConfig* config); @@ -144,9 +140,10 @@ KlipperWidget::KlipperWidget( TQWidget *parent, TDEConfig* config ) setBackgroundMode( X11ParentRelative ); clip = kapp->clipboard(); - connect( &m_overflowClearTimer, TQT_SIGNAL( timeout()), TQT_SLOT( slotClearOverflow())); + connect( &m_overflowClearTimer, TQ_SIGNAL( timeout()), TQ_SLOT( slotClearOverflow())); m_overflowClearTimer.start( 1000 ); - connect( &m_pendingCheckTimer, TQT_SIGNAL( timeout()), TQT_SLOT( slotCheckPending())); + connect( &m_pendingCheckTimer, TQ_SIGNAL( timeout()), TQ_SLOT( slotCheckPending())); + connect( &m_setClipboardTimer, TQ_SIGNAL( timeout()), TQ_SLOT( slotDelayedSetClipboard())); m_history = new History( this, "main_history" ); @@ -159,25 +156,25 @@ KlipperWidget::KlipperWidget( TQWidget *parent, TDEConfig* config ) clearHistoryAction = new TDEAction( i18n("C&lear Clipboard History"), "history_clear", 0, - TQT_TQOBJECT(history()), - TQT_SLOT( slotClear() ), + history(), + TQ_SLOT( slotClear() ), collection, "clearHistoryAction" ); - connect( clearHistoryAction, TQT_SIGNAL( activated() ), TQT_SLOT( slotClearClipboard() ) ); + connect( clearHistoryAction, TQ_SIGNAL( activated() ), TQ_SLOT( slotClearClipboard() ) ); clearHistoryAction->setGroup( defaultGroup ); configureAction = new TDEAction( i18n("&Configure Klipper..."), "configure", 0, - TQT_TQOBJECT(this), - TQT_SLOT( slotConfigure() ), + this, + TQ_SLOT( slotConfigure() ), collection, "configureAction" ); configureAction->setGroup( defaultGroup ); quitAction = new TDEAction( i18n("&Quit"), "system-log-out", 0, - TQT_TQOBJECT(this), - TQT_SLOT( slotQuit() ), + this, + TQ_SLOT( slotQuit() ), collection, "quitAction" ); quitAction->setGroup( "exit" ); @@ -190,11 +187,11 @@ KlipperWidget::KlipperWidget( TQWidget *parent, TDEConfig* config ) showTimer = new TQTime(); readProperties(m_config); - connect(kapp, TQT_SIGNAL(settingsChanged(int)), TQT_SLOT(slotSettingsChanged(int))); + connect(kapp, TQ_SIGNAL(settingsChanged(int)), TQ_SLOT(slotSettingsChanged(int))); poll = new ClipboardPoll( this ); - connect( poll, TQT_SIGNAL( clipboardChanged( bool ) ), - this, TQT_SLOT( newClipData( bool ) ) ); + connect( poll, TQ_SIGNAL( clipboardChanged( bool ) ), + this, TQ_SLOT( newClipData( bool ) ) ); if ( isApplet() || !isShown() ) { m_pixmap = KSystemTray::loadIcon( "klipper" ); @@ -206,7 +203,7 @@ KlipperWidget::KlipperWidget( TQWidget *parent, TDEConfig* config ) m_iconOrigHeight = m_pixmap.height(); adjustSize(); - globalKeys = new TDEGlobalAccel(TQT_TQOBJECT(this)); + globalKeys = new TDEGlobalAccel(this); TDEGlobalAccel* keys = globalKeys; #include "klipperbindings.cpp" // the keys need to be read from kdeglobals, not kickerrc --ellis, 22/9/02 @@ -214,13 +211,13 @@ KlipperWidget::KlipperWidget( TQWidget *parent, TDEConfig* config ) globalKeys->updateConnections(); toggleURLGrabAction->setShortcut(globalKeys->shortcut("Enable/Disable Clipboard Actions")); - connect( toggleURLGrabAction, TQT_SIGNAL( toggled( bool )), - this, TQT_SLOT( setURLGrabberEnabled( bool ))); + connect( toggleURLGrabAction, TQ_SIGNAL( toggled( bool )), + this, TQ_SLOT( setURLGrabberEnabled( bool ))); KlipperPopup* popup = history()->popup(); - connect ( history(), TQT_SIGNAL( topChanged() ), TQT_SLOT( slotHistoryTopChanged() ) ); - connect( popup, TQT_SIGNAL( aboutToHide() ), TQT_SLOT( slotStartHideTimer() ) ); - connect( popup, TQT_SIGNAL( aboutToShow() ), TQT_SLOT( slotStartShowTimer() ) ); + connect ( history(), TQ_SIGNAL( topChanged() ), TQ_SLOT( slotHistoryTopChanged() ) ); + connect( popup, TQ_SIGNAL( aboutToHide() ), TQ_SLOT( slotStartHideTimer() ) ); + connect( popup, TQ_SIGNAL( aboutToShow() ), TQ_SLOT( slotStartShowTimer() ) ); popup->plugAction( toggleURLGrabAction ); popup->plugAction( clearHistoryAction ); @@ -283,7 +280,7 @@ void KlipperWidget::clearClipboardHistory() void KlipperWidget::mousePressEvent(TQMouseEvent *e) { - if ( e->button() != Qt::LeftButton && e->button() != Qt::RightButton ) + if ( e->button() != TQt::LeftButton && e->button() != TQt::RightButton ) return; // if we only hid the menu less than a third of a second ago, @@ -634,10 +631,10 @@ void KlipperWidget::slotRepeatAction() { if ( !myURLGrabber ) { myURLGrabber = new URLGrabber( m_config ); - connect( myURLGrabber, TQT_SIGNAL( sigPopup( TQPopupMenu * )), - TQT_SLOT( showPopupMenu( TQPopupMenu * )) ); - connect( myURLGrabber, TQT_SIGNAL( sigDisablePopup() ), - this, TQT_SLOT( disableURLGrabber() ) ); + connect( myURLGrabber, TQ_SIGNAL( sigPopup( TQPopupMenu * )), + TQ_SLOT( showPopupMenu( TQPopupMenu * )) ); + connect( myURLGrabber, TQ_SIGNAL( sigDisablePopup() ), + this, TQ_SLOT( disableURLGrabber() ) ); } const HistoryStringItem* top = dynamic_cast<const HistoryStringItem*>( history()->first() ); @@ -669,10 +666,10 @@ void KlipperWidget::setURLGrabberEnabled( bool enable ) toggleURLGrabAction->setText(i18n("&Actions Enabled")); if ( !myURLGrabber ) { myURLGrabber = new URLGrabber( m_config ); - connect( myURLGrabber, TQT_SIGNAL( sigPopup( TQPopupMenu * )), - TQT_SLOT( showPopupMenu( TQPopupMenu * )) ); - connect( myURLGrabber, TQT_SIGNAL( sigDisablePopup() ), - this, TQT_SLOT( disableURLGrabber() ) ); + connect( myURLGrabber, TQ_SIGNAL( sigPopup( TQPopupMenu * )), + TQ_SLOT( showPopupMenu( TQPopupMenu * )) ); + connect( myURLGrabber, TQ_SIGNAL( sigDisablePopup() ), + this, TQ_SLOT( disableURLGrabber() ) ); } } } @@ -789,8 +786,8 @@ bool KlipperWidget::blockFetchingNewData() // contents, so in practice it's like the user has selected only the part which was // selected when Klipper asked first. ButtonState buttonstate = kapp->keyboardMouseState(); - if( ( buttonstate & ( ShiftButton | Qt::LeftButton )) == ShiftButton // #85198 - || ( buttonstate & Qt::LeftButton ) == Qt::LeftButton ) { // #80302 + if( ( buttonstate & ( ShiftButton | TQt::LeftButton )) == ShiftButton // #85198 + || ( buttonstate & TQt::LeftButton ) == TQt::LeftButton ) { // #80302 m_pendingContentsCheck = true; m_pendingCheckTimer.start( 100, true ); return true; @@ -810,6 +807,41 @@ void KlipperWidget::slotCheckPending() 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 ) { if ( ignoreClipboardChanges() ) // internal to klipper, ignoring TQSpinBox selections @@ -869,15 +901,14 @@ void KlipperWidget::checkClipData( bool selectionMode ) bool changed = data->serialNumber() != lastSerialNo; bool clipEmpty = ( data->format() == 0L ); - if ( changed && clipEmpty && bNoNullClipboard ) { - const HistoryItem* top = history()->first(); - if ( top ) { - // keep old clipboard after someone set it to null -#ifdef NOISY_KLIPPER - kdDebug() << "Resetting clipboard (Prevent empty clipboard)" << endl; -#endif - setClipboard( *top, selectionMode ? Selection : Clipboard ); - } + if ( changed && clipEmpty && bNoNullClipboard ) + { + // Make sure to call setClipboard() through the event loop. + // Using a direct call may crash another application that was + // changing the clipboard at the same time. + bSavedSelectionMode = selectionMode; + bCheckForEmpty = true; + m_setClipboardTimer.start(100, TRUE); return; } @@ -946,11 +977,14 @@ void KlipperWidget::checkClipData( bool selectionMode ) #ifdef NOISY_KLIPPER kdDebug() << "Synchronize?" << ( bSynchronize ? "yes" : "no" ) << endl; #endif - if ( bSynchronize ) { - const HistoryItem* topItem = history()->first(); - if ( topItem ) { - setClipboard( *topItem, selectionMode ? Clipboard : Selection ); - } + if ( bSynchronize ) + { + // Make sure to call setClipboard() through the event loop. + // 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); } } @@ -1019,10 +1053,10 @@ bool KlipperWidget::ignoreClipboardChanges() const TQWidget *focusWidget = tqApp->focusWidget(); if ( focusWidget ) { - if ( focusWidget->inherits( TQSPINBOX_OBJECT_NAME_STRING ) || + if ( focusWidget->inherits( "TQSpinBox" ) || (focusWidget->parentWidget() && - focusWidget->inherits(TQLINEEDIT_OBJECT_NAME_STRING) && - focusWidget->parentWidget()->inherits(TQSPINWIDGET_OBJECT_NAME_STRING)) ) + focusWidget->inherits("TQLineEdit") && + focusWidget->parentWidget()->inherits("TQSpinWidget")) ) { return true; } @@ -1080,7 +1114,7 @@ void KlipperWidget::updateTimestamp() { // Qt3.3.0 and 3.3.1 use tqt_x_user_time for clipboard operations Time time = ( strcmp( tqVersion(), "3.3.1" ) == 0 || strcmp( tqVersion(), "3.3.0" ) == 0 ) - ? GET_QT_X_USER_TIME() : GET_QT_X_TIME(); + ? get_tqt_x_user_time() : get_tqt_x_time(); static TQWidget* w = 0; if ( !w ) w = new TQWidget; |