File indexing completed on 2024-04-28 05:52:25
0001 /* 0002 * Copyright 2010-2012 Bart Kroon <bart@tarmack.eu> 0003 * 0004 * Redistribution and use in source and binary forms, with or without 0005 * modification, are permitted provided that the following conditions 0006 * are met: 0007 * 0008 * 1. Redistributions of source code must retain the above copyright 0009 * notice, this list of conditions and the following disclaimer. 0010 * 2. Redistributions in binary form must reproduce the above copyright 0011 * notice, this list of conditions and the following disclaimer in the 0012 * documentation and/or other materials provided with the distribution. 0013 * 0014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0017 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0024 */ 0025 0026 #ifndef Units_H 0027 #define Units_H 0028 0029 #include "Provider.h" 0030 #include <KUnitConversion/Converter> 0031 0032 class QThread; 0033 class QTimer; 0034 0035 class CurrencyRefresher : public QObject 0036 { 0037 Q_OBJECT 0038 0039 public slots: 0040 void refresh(); 0041 void init(); 0042 0043 private: 0044 QTimer *m_timer; 0045 }; 0046 0047 class Units : public Provider 0048 { 0049 Q_OBJECT 0050 public: 0051 Units(QObject *parent); 0052 ~Units(); 0053 public slots: 0054 QList<ProviderResult*> getResults(QString query) override; 0055 int launch(const QString &exec) override; 0056 0057 private: 0058 enum UnitMatchingLevel { 0059 OnlyCommonUnits, 0060 AllUnits 0061 }; 0062 QList<KUnitConversion::Unit> resolveUnitName(const QString &name, const KUnitConversion::UnitCategory &category = KUnitConversion::UnitCategory()); 0063 QList<KUnitConversion::Unit> findCompatibleUnits(const QString &name, const KUnitConversion::UnitCategory &category, const UnitMatchingLevel level); 0064 ProviderResult *createResult(const KUnitConversion::Unit &inputUnit, const KUnitConversion::Value &inputValue, const KUnitConversion::Unit &outputUnit); 0065 0066 KUnitConversion::Converter m_converter; 0067 0068 CurrencyRefresher *m_refresher; 0069 QThread *m_refresherThread; 0070 }; 0071 0072 0073 0074 #endif // Units_H 0075 // kate: indent-mode cstyle; space-indent on; indent-width 4;