File indexing completed on 2024-04-28 05:35:26
0001 /* 0002 SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "clipboardengine.h" 0008 #include "clipboardservice.h" 0009 #include "history.h" 0010 #include "historyitem.h" 0011 #include "historymodel.h" 0012 #include "klipper.h" 0013 0014 static const QString s_clipboardSourceName = QStringLiteral("clipboard"); 0015 static const QString s_barcodeKey = QStringLiteral("supportsBarcodes"); 0016 0017 ClipboardEngine::ClipboardEngine(QObject *parent) 0018 : Plasma5Support::DataEngine(parent) 0019 , m_klipper(new Klipper(this, KSharedConfig::openConfig(QStringLiteral("klipperrc")))) 0020 { 0021 // TODO: use a filterproxymodel 0022 setModel(s_clipboardSourceName, m_klipper->history()->model()); 0023 setData(s_clipboardSourceName, s_barcodeKey, true); 0024 auto updateCurrent = [this]() { 0025 setData(s_clipboardSourceName, QStringLiteral("current"), m_klipper->history()->empty() ? QString() : m_klipper->history()->first()->text()); 0026 }; 0027 connect(m_klipper->history(), &History::topChanged, this, updateCurrent); 0028 updateCurrent(); 0029 auto updateEmpty = [this]() { 0030 setData(s_clipboardSourceName, QStringLiteral("empty"), m_klipper->history()->empty()); 0031 }; 0032 connect(m_klipper->history(), &History::changed, this, updateEmpty); 0033 updateEmpty(); 0034 } 0035 0036 ClipboardEngine::~ClipboardEngine() 0037 { 0038 m_klipper->saveClipboardHistory(); 0039 } 0040 0041 Plasma5Support::Service *ClipboardEngine::serviceForSource(const QString &source) 0042 { 0043 Plasma5Support::Service *service = new ClipboardService(m_klipper, source); 0044 service->setParent(this); 0045 return service; 0046 } 0047 0048 K_PLUGIN_CLASS_WITH_JSON(ClipboardEngine, "plasma-dataengine-clipboard.json") 0049 0050 #include "clipboardengine.moc"