File indexing completed on 2024-04-21 04:35:56

0001 /*
0002  * This file is part of KDevelop
0003  *
0004  * Copyright 2010 Alexander Dymo <adymo@kdevelop.org>
0005  * Copyright (C) 2014-2015 Miquel Sabaté Solà <mikisabate@gmail.com>
0006  *
0007  * This program is free software; you can redistribute it and/or modify
0008  * it under the terms of the GNU Library General Public License as
0009  * published by the Free Software Foundation; either version 2 of the
0010  * License, or (at your option) any later version.
0011  *
0012  * This program is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015  * GNU General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU General Public
0018  * License along with this program; if not, write to the
0019  * Free Software Foundation, Inc.,
0020  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0021  */
0022 
0023 #ifndef RAILS_DATA_PROVIDER_H
0024 #define RAILS_DATA_PROVIDER_H
0025 
0026 #include <language/interfaces/quickopendataprovider.h>
0027 #include <rails/export.h>
0028 #include <rails/quickopendata.h>
0029 
0030 namespace ruby {
0031 namespace rails {
0032 
0033 /**
0034  * The kind of providers available.
0035  */
0036 enum class Kind { Views, Tests };
0037 
0038 /**
0039  * @class DataProvider.
0040  *
0041  * This class takes the rails::QuickOpenData class to provide all the
0042  * data that we need to feed the QuickOpen.
0043  */
0044 class KDEVRUBYRAILS_EXPORT DataProvider
0045     : public KDevelop::QuickOpenDataProviderBase
0046     , public KDevelop::PathFilter<QuickOpenItem, DataProvider>
0047 {
0048 public:
0049     explicit DataProvider(const Kind kind);
0050 
0051     /// @returns the item as a KDevelop::Path.
0052     /// NOTE: currently we use QUrl internally because KDevPlatform hasn't
0053     /// moved away from KUrl yet.
0054     inline KDevelop::Path itemPath(const QuickOpenItem &data) const
0055     {
0056         return KDevelop::Path(data.url);
0057     }
0058     inline KDevelop::Path itemPrefixPath(const QuickOpenItem& data) const
0059     {
0060 #ifdef __GNUC__
0061 #warning DataProvider::itemPrefixPath(QuickOpenItem) needs a sane implementation!
0062 #endif
0063         // FIXME: what should/could be returned here?
0064         return KDevelop::Path();
0065     }
0066 
0067     /// @returns all scopes supported by this data-provider.
0068     static QStringList scopes();
0069 
0070 protected:
0071     void setFilterText(const QString &text) override;
0072     void reset() override;
0073     uint itemCount() const override;
0074     uint unfilteredItemCount() const override;
0075     KDevelop::QuickOpenDataPointer data(uint row) const override;
0076     void enableData(const QStringList &items,
0077                     const QStringList &scopes) override;
0078 
0079 private:
0080     Kind m_kind;
0081 };
0082 
0083 }
0084 }
0085 
0086 #endif // RAILS_DATA_PROVIDER_H
0087