Changeset View
Changeset View
Standalone View
Standalone View
klipper/klipper.cpp
Show First 20 Lines • Show All 110 Lines • ▼ Show 20 Line(s) | 97 | { | |||
---|---|---|---|---|---|
111 | 111 | | |||
112 | m_pendingCheckTimer.setSingleShot( true ); | 112 | m_pendingCheckTimer.setSingleShot( true ); | ||
113 | connect( &m_pendingCheckTimer, &QTimer::timeout, this, &Klipper::slotCheckPending); | 113 | connect( &m_pendingCheckTimer, &QTimer::timeout, this, &Klipper::slotCheckPending); | ||
114 | 114 | | |||
115 | 115 | | |||
116 | m_history = new History( this ); | 116 | m_history = new History( this ); | ||
117 | m_popup = new KlipperPopup(m_history); | 117 | m_popup = new KlipperPopup(m_history); | ||
118 | m_popup->setShowHelp(m_mode == KlipperMode::Standalone); | 118 | m_popup->setShowHelp(m_mode == KlipperMode::Standalone); | ||
119 | connect(m_history, &History::changed, this, &Klipper::slotHistoryChanged); | ||||
119 | connect(m_history, &History::changed, m_popup, &KlipperPopup::slotHistoryChanged); | 120 | connect(m_history, &History::changed, m_popup, &KlipperPopup::slotHistoryChanged); | ||
120 | connect(m_history, &History::topIsUserSelectedSet, m_popup, &KlipperPopup::slotTopIsUserSelectedSet); | 121 | connect(m_history, &History::topIsUserSelectedSet, m_popup, &KlipperPopup::slotTopIsUserSelectedSet); | ||
121 | 122 | | |||
122 | // we need that collection, otherwise KToggleAction is not happy :} | 123 | // we need that collection, otherwise KToggleAction is not happy :} | ||
123 | m_collection = new KActionCollection( this ); | 124 | m_collection = new KActionCollection( this ); | ||
124 | 125 | | |||
125 | m_toggleURLGrabAction = new KToggleAction( this ); | 126 | m_toggleURLGrabAction = new KToggleAction( this ); | ||
126 | m_collection->addAction( QStringLiteral("clipboard_action"), m_toggleURLGrabAction ); | 127 | m_collection->addAction( QStringLiteral("clipboard_action"), m_toggleURLGrabAction ); | ||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Line(s) | 283 | { | |||
283 | updateTimestamp(); | 284 | updateTimestamp(); | ||
284 | slotClearClipboard(); | 285 | slotClearClipboard(); | ||
285 | } | 286 | } | ||
286 | 287 | | |||
287 | // DBUS - don't call from Klipper itself | 288 | // DBUS - don't call from Klipper itself | ||
288 | void Klipper::clearClipboardHistory() | 289 | void Klipper::clearClipboardHistory() | ||
289 | { | 290 | { | ||
290 | updateTimestamp(); | 291 | updateTimestamp(); | ||
291 | slotClearClipboard(); | | |||
292 | history()->slotClear(); | 292 | history()->slotClear(); | ||
293 | saveSession(); | 293 | saveSession(); | ||
294 | } | 294 | } | ||
295 | 295 | | |||
296 | // DBUS - don't call from Klipper itself | 296 | // DBUS - don't call from Klipper itself | ||
297 | void Klipper::saveClipboardHistory() | 297 | void Klipper::saveClipboardHistory() | ||
298 | { | 298 | { | ||
299 | if ( m_bKeepContents ) { // save the clipboard eventually | 299 | if ( m_bKeepContents ) { // save the clipboard eventually | ||
Show All 25 Lines | 310 | { | |||
325 | // NOTE: not used atm - kregexpeditor is not ported to kde4 | 325 | // NOTE: not used atm - kregexpeditor is not ported to kde4 | ||
326 | m_bUseGUIRegExpEditor = KlipperSettings::useGUIRegExpEditor(); | 326 | m_bUseGUIRegExpEditor = KlipperSettings::useGUIRegExpEditor(); | ||
327 | m_bSelectionTextOnly = KlipperSettings::selectionTextOnly(); | 327 | m_bSelectionTextOnly = KlipperSettings::selectionTextOnly(); | ||
328 | 328 | | |||
329 | m_bURLGrabber = KlipperSettings::uRLGrabberEnabled(); | 329 | m_bURLGrabber = KlipperSettings::uRLGrabberEnabled(); | ||
330 | // this will cause it to loadSettings too | 330 | // this will cause it to loadSettings too | ||
331 | setURLGrabberEnabled(m_bURLGrabber); | 331 | setURLGrabberEnabled(m_bURLGrabber); | ||
332 | history()->setMaxSize( KlipperSettings::maxClipItems() ); | 332 | history()->setMaxSize( KlipperSettings::maxClipItems() ); | ||
333 | history()->model()->setDisplayImages(!m_bIgnoreImages); | ||||
334 | | ||||
333 | // Convert 4.3 settings | 335 | // Convert 4.3 settings | ||
334 | if (KlipperSettings::synchronize() != 3) { | 336 | if (KlipperSettings::synchronize() != 3) { | ||
335 | // 2 was the id of "Ignore selection" radiobutton | 337 | // 2 was the id of "Ignore selection" radiobutton | ||
336 | m_bIgnoreSelection = KlipperSettings::synchronize() == 2; | 338 | m_bIgnoreSelection = KlipperSettings::synchronize() == 2; | ||
337 | // 0 was the id of "Synchronize contents" radiobutton | 339 | // 0 was the id of "Synchronize contents" radiobutton | ||
338 | m_bSynchronize = KlipperSettings::synchronize() == 0; | 340 | m_bSynchronize = KlipperSettings::synchronize() == 0; | ||
339 | KConfigSkeletonItem* item = KlipperSettings::self()->findItem(QStringLiteral("SyncClipboards")); | 341 | KConfigSkeletonItem* item = KlipperSettings::self()->findItem(QStringLiteral("SyncClipboards")); | ||
340 | item->setProperty(m_bSynchronize); | 342 | item->setProperty(m_bSynchronize); | ||
▲ Show 20 Lines • Show All 258 Lines • ▼ Show 20 Line(s) | |||||
599 | } | 601 | } | ||
600 | 602 | | |||
601 | HistoryItemPtr Klipper::applyClipChanges( const QMimeData* clipData ) | 603 | HistoryItemPtr Klipper::applyClipChanges( const QMimeData* clipData ) | ||
602 | { | 604 | { | ||
603 | if ( m_locklevel ) { | 605 | if ( m_locklevel ) { | ||
604 | return HistoryItemPtr(); | 606 | return HistoryItemPtr(); | ||
605 | } | 607 | } | ||
606 | Ignore lock( m_locklevel ); | 608 | Ignore lock( m_locklevel ); | ||
607 | HistoryItemPtr item = HistoryItem::create( clipData ); | | |||
608 | 609 | | |||
609 | bool saveHistory = true; | 610 | if (!(history()->empty())) { | ||
610 | if (clipData->data(QStringLiteral("x-kde-passwordManagerHint")) == QByteArrayLiteral("secret")) { | 611 | if (m_bIgnoreImages && history()->first()->mimeData()->hasImage()) { | ||
611 | saveHistory = false; | 612 | history()->remove(history()->first()); | ||
612 | } | 613 | } | ||
613 | if (clipData->hasImage() && m_bIgnoreImages) { | | |||
614 | saveHistory = false; | | |||
615 | } | 614 | } | ||
616 | 615 | | |||
617 | m_last = item; | 616 | HistoryItemPtr item = HistoryItem::create( clipData ); | ||
618 | 617 | | |||
619 | if (saveHistory) { | 618 | bool saveToHistory = true; | ||
619 | if (clipData->data(QStringLiteral("x-kde-passwordManagerHint")) == QByteArrayLiteral("secret")) { | ||||
620 | saveToHistory = false; | ||||
621 | } | ||||
622 | if (saveToHistory) { | ||||
620 | history()->insert( item ); | 623 | history()->insert( item ); | ||
621 | } | 624 | } | ||
622 | return item; | | |||
623 | 625 | | |||
626 | return item; | ||||
624 | } | 627 | } | ||
625 | 628 | | |||
626 | void Klipper::newClipData( QClipboard::Mode mode ) | 629 | void Klipper::newClipData( QClipboard::Mode mode ) | ||
627 | { | 630 | { | ||
628 | if ( m_locklevel ) { | 631 | if ( m_locklevel ) { | ||
629 | return; | 632 | return; | ||
630 | } | 633 | } | ||
631 | 634 | | |||
632 | if( mode == QClipboard::Selection && blockFetchingNewData()) | 635 | if( mode == QClipboard::Selection && blockFetchingNewData()) | ||
633 | return; | 636 | return; | ||
634 | 637 | | |||
635 | checkClipData( mode == QClipboard::Selection ? true : false ); | 638 | checkClipData( mode == QClipboard::Selection ? true : false ); | ||
636 | 639 | | |||
637 | } | 640 | } | ||
638 | 641 | | |||
642 | void Klipper::slotHistoryChanged() | ||||
643 | { | ||||
644 | if (history()->empty()) { | ||||
645 | slotClearClipboard(); | ||||
646 | } | ||||
647 | } | ||||
648 | | ||||
639 | // Protection against too many clipboard data changes. Lyx responds to clipboard data | 649 | // Protection against too many clipboard data changes. Lyx responds to clipboard data | ||
640 | // requests with setting new clipboard data, so if Lyx takes over clipboard, | 650 | // requests with setting new clipboard data, so if Lyx takes over clipboard, | ||
641 | // Klipper notices, requests this data, this triggers "new" clipboard contents | 651 | // Klipper notices, requests this data, this triggers "new" clipboard contents | ||
642 | // from Lyx, so Klipper notices again, requests this data, ... you get the idea. | 652 | // from Lyx, so Klipper notices again, requests this data, ... you get the idea. | ||
643 | const int MAX_CLIPBOARD_CHANGES = 10; // max changes per second | 653 | const int MAX_CLIPBOARD_CHANGES = 10; // max changes per second | ||
644 | 654 | | |||
645 | bool Klipper::blockFetchingNewData() | 655 | bool Klipper::blockFetchingNewData() | ||
646 | { | 656 | { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
692 | void Klipper::checkClipData( bool selectionMode ) | 702 | void Klipper::checkClipData( bool selectionMode ) | ||
693 | { | 703 | { | ||
694 | if ( ignoreClipboardChanges() ) // internal to klipper, ignoring QSpinBox selections | 704 | if ( ignoreClipboardChanges() ) // internal to klipper, ignoring QSpinBox selections | ||
695 | { | 705 | { | ||
696 | // keep our old clipboard, thanks | 706 | // keep our old clipboard, thanks | ||
697 | // This won't quite work, but it's close enough for now. | 707 | // This won't quite work, but it's close enough for now. | ||
698 | // The trouble is that the top selection =! top clipboard | 708 | // The trouble is that the top selection =! top clipboard | ||
699 | // but we don't track that yet. We will.... | 709 | // but we don't track that yet. We will.... | ||
700 | auto top = m_last; | 710 | auto top = history()->first(); | ||
701 | if ( top ) { | 711 | if ( top ) { | ||
702 | setClipboard( *top, selectionMode ? Selection : Clipboard); | 712 | setClipboard( *top, selectionMode ? Selection : Clipboard); | ||
703 | } | 713 | } | ||
704 | return; | 714 | return; | ||
705 | } | 715 | } | ||
706 | 716 | | |||
707 | qCDebug(KLIPPER_LOG) << "Checking clip data"; | 717 | qCDebug(KLIPPER_LOG) << "Checking clip data"; | ||
708 | 718 | | |||
709 | const QMimeData* data = m_clip->mimeData( selectionMode ? QClipboard::Selection : QClipboard::Clipboard ); | 719 | const QMimeData* data = m_clip->mimeData( selectionMode ? QClipboard::Selection : QClipboard::Clipboard ); | ||
710 | if ( !data ) { | 720 | if ( !data ) { | ||
711 | qCWarning(KLIPPER_LOG) << "No data in clipboard. This not not supposed to happen."; | 721 | qCWarning(KLIPPER_LOG) << "No data in clipboard. This not not supposed to happen."; | ||
712 | return; | 722 | return; | ||
713 | } | 723 | } | ||
714 | 724 | | |||
715 | bool changed = true; // ### FIXME (only relevant under polling, might be better to simply remove polling and rely on XFixes) | 725 | bool changed = true; // ### FIXME (only relevant under polling, might be better to simply remove polling and rely on XFixes) | ||
716 | bool clipEmpty = data->formats().isEmpty(); | 726 | bool clipEmpty = data->formats().isEmpty(); | ||
717 | if (clipEmpty) { | 727 | if (clipEmpty) { | ||
718 | // Might be a timeout. Try again | 728 | // Might be a timeout. Try again | ||
719 | clipEmpty = data->formats().isEmpty(); | 729 | clipEmpty = data->formats().isEmpty(); | ||
720 | qCDebug(KLIPPER_LOG) << "was empty. Retried, now " << (clipEmpty?" still empty":" no longer empty"); | 730 | qCDebug(KLIPPER_LOG) << "was empty. Retried, now " << (clipEmpty?" still empty":" no longer empty"); | ||
721 | } | 731 | } | ||
722 | 732 | | |||
723 | if ( changed && clipEmpty && m_bNoNullClipboard ) { | 733 | if ( changed && clipEmpty && m_bNoNullClipboard ) { | ||
724 | auto top = m_last; | 734 | auto top = history()->first(); | ||
725 | if ( top ) { | 735 | if ( top ) { | ||
726 | // keep old clipboard after someone set it to null | 736 | // keep old clipboard after someone set it to null | ||
727 | qCDebug(KLIPPER_LOG) << "Resetting clipboard (Prevent empty clipboard)"; | 737 | qCDebug(KLIPPER_LOG) << "Resetting clipboard (Prevent empty clipboard)"; | ||
728 | setClipboard( *top, selectionMode ? Selection : Clipboard ); | 738 | setClipboard( *top, selectionMode ? Selection : Clipboard ); | ||
729 | } | 739 | } | ||
730 | return; | 740 | return; | ||
731 | } | 741 | } | ||
732 | 742 | | |||
▲ Show 20 Lines • Show All 254 Lines • ▼ Show 20 Line(s) | 996 | int clearHist = KMessageBox::questionYesNo(nullptr, | |||
987 | i18n("Really delete entire clipboard history?"), | 997 | i18n("Really delete entire clipboard history?"), | ||
988 | i18n("Delete clipboard history?"), | 998 | i18n("Delete clipboard history?"), | ||
989 | KStandardGuiItem::yes(), | 999 | KStandardGuiItem::yes(), | ||
990 | KStandardGuiItem::no(), | 1000 | KStandardGuiItem::no(), | ||
991 | QStringLiteral("really_clear_history"), | 1001 | QStringLiteral("really_clear_history"), | ||
992 | KMessageBox::Dangerous); | 1002 | KMessageBox::Dangerous); | ||
993 | if (clearHist == KMessageBox::Yes) { | 1003 | if (clearHist == KMessageBox::Yes) { | ||
994 | history()->slotClear(); | 1004 | history()->slotClear(); | ||
995 | slotClearClipboard(); | | |||
996 | saveHistory(); | 1005 | saveHistory(); | ||
997 | } | 1006 | } | ||
998 | 1007 | | |||
999 | } | 1008 | } | ||
1000 | 1009 | | |||
1001 | void Klipper::slotCycleNext() | 1010 | void Klipper::slotCycleNext() | ||
1002 | { | 1011 | { | ||
1003 | //do cycle and show popup only if we have something in clipboard | 1012 | //do cycle and show popup only if we have something in clipboard | ||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |