2015-02-03 03:55:30 +05:30
|
|
|
/* Copyright 2013-2015 MultiMC Contributors
|
2013-11-04 07:23:05 +05:30
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-08-10 22:04:08 +05:30
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QAbstractListModel>
|
2013-12-31 05:54:28 +05:30
|
|
|
#include <QFile>
|
|
|
|
#include <QDir>
|
2013-08-10 22:04:08 +05:30
|
|
|
#include <QtGui/QIcon>
|
2013-12-31 05:54:28 +05:30
|
|
|
#include <memory>
|
|
|
|
#include "MMCIcon.h"
|
2014-07-01 05:18:09 +05:30
|
|
|
#include "logic/settings/Setting.h"
|
2013-08-10 22:04:08 +05:30
|
|
|
|
2013-12-31 05:54:28 +05:30
|
|
|
class QFileSystemWatcher;
|
2013-08-10 22:04:08 +05:30
|
|
|
|
|
|
|
class IconList : public QAbstractListModel
|
|
|
|
{
|
2013-12-31 05:54:28 +05:30
|
|
|
Q_OBJECT
|
2013-08-10 22:04:08 +05:30
|
|
|
public:
|
2013-12-31 05:54:28 +05:30
|
|
|
explicit IconList(QObject *parent = 0);
|
|
|
|
virtual ~IconList() {};
|
2013-11-04 07:23:05 +05:30
|
|
|
|
|
|
|
QIcon getIcon(QString key);
|
2014-01-20 05:44:11 +05:30
|
|
|
QIcon getBigIcon(QString key);
|
2013-11-04 07:23:05 +05:30
|
|
|
int getIconIndex(QString key);
|
|
|
|
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
|
|
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
|
|
|
|
2013-12-31 05:54:28 +05:30
|
|
|
bool addIcon(QString key, QString name, QString path, MMCIcon::Type type);
|
2013-08-27 09:09:49 +05:30
|
|
|
bool deleteIcon(QString key);
|
2013-11-04 07:23:05 +05:30
|
|
|
|
2013-08-27 09:09:49 +05:30
|
|
|
virtual QStringList mimeTypes() const;
|
|
|
|
virtual Qt::DropActions supportedDropActions() const;
|
2013-11-04 07:23:05 +05:30
|
|
|
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column,
|
|
|
|
const QModelIndex &parent);
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
|
|
|
|
void installIcons(QStringList iconFiles);
|
|
|
|
|
2013-12-31 05:54:28 +05:30
|
|
|
void startWatching();
|
|
|
|
void stopWatching();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void iconUpdated(QString key);
|
|
|
|
|
2013-08-10 22:04:08 +05:30
|
|
|
private:
|
|
|
|
// hide copy constructor
|
2013-11-04 07:23:05 +05:30
|
|
|
IconList(const IconList &) = delete;
|
2013-08-10 22:04:08 +05:30
|
|
|
// hide assign op
|
2013-11-04 07:23:05 +05:30
|
|
|
IconList &operator=(const IconList &) = delete;
|
2013-08-27 09:09:49 +05:30
|
|
|
void reindex();
|
2013-12-31 05:54:28 +05:30
|
|
|
|
|
|
|
protected
|
|
|
|
slots:
|
|
|
|
void directoryChanged(const QString &path);
|
|
|
|
void fileChanged(const QString &path);
|
2014-07-01 05:18:09 +05:30
|
|
|
void SettingChanged(const Setting & setting, QVariant value);
|
2013-12-31 05:54:28 +05:30
|
|
|
private:
|
|
|
|
std::shared_ptr<QFileSystemWatcher> m_watcher;
|
|
|
|
bool is_watching;
|
|
|
|
QMap<QString, int> name_index;
|
|
|
|
QVector<MMCIcon> icons;
|
|
|
|
QDir m_dir;
|
2013-08-10 22:04:08 +05:30
|
|
|
};
|