//! \returns plugin icon
virtual QIcon* icon() = 0;
+ //! \returns plugin icon's path
+ virtual QString iconPath() = 0;
+
//! \returns empty translation object (to be fetched later) for a given key
virtual Translation* getTranslationFor(QString ) {return 0;}
--- /dev/null
+#include "DictManagerModel.h"
+
+DictManagerModel::DictManagerModel(QHash<CommonDictInterface *, bool> dictionaries, QObject *parent) :
+ QAbstractListModel(parent)
+{
+ QHash<int, QByteArray> roles;
+ roles[NameRole] = "name";
+ roles[IconPathRole] = "iconPath";
+ roles[IsSelectedRole] = "isSelected";
+ roles[NumberRole] = "number";
+ setRoleNames(roles);
+
+ setDictionaries(dictionaries);
+}
+
+int DictManagerModel::rowCount(const QModelIndex &parent) const
+{
+ return _dictList.count();
+}
+
+void DictManagerModel::setDictionaries(QHash<CommonDictInterface *, bool> dictionaries)
+{
+ QHashIterator<CommonDictInterface *, bool> i(dictionaries);
+ while (i.hasNext()) {
+ i.next();
+ addDictionary(i.key(), i.value());
+ }
+}
+
+void DictManagerModel::clear()
+{
+ beginRemoveRows(QModelIndex(), 0, rowCount());
+ _dictionaries.clear();
+ _dictList.clear();
+ endRemoveRows();
+ emit dataChanged(QModelIndex(), QModelIndex());
+}
+
+QVariant DictManagerModel::data(const QModelIndex & index, int role) const
+{
+ if (index.row() < 0 || index.row() > _dictList.count())
+ return QVariant();
+
+ CommonDictInterface* dictionary = _dictList[index.row()];
+ if (role == NameRole)
+ {
+ QString name;
+ if (dictionary->type() == "stardict") {
+ name = dictionary->name() + " (" + dictionary->type() + ")";
+ }
+ else {
+ name = dictionary->langFrom() + " - " + dictionary->langTo() +
+ " (" + dictionary->type() + " " +
+ dictionary->name() + ")";
+ }
+ return name;
+ }
+ if (role == NumberRole)
+ return index.row();
+ if (role == IconPathRole)
+ return dictionary->iconPath();
+ if (role == IsSelectedRole)
+ return _dictionaries[dictionary];
+ return QVariant();
+}
+
+bool DictManagerModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ if (index.row() < 0 || index.row() > _dictList.count())
+ return false;
+
+ CommonDictInterface* dictionary = _dictList[index.row()];
+ if (role == NameRole)
+ return true;
+ if (role == NumberRole)
+ return true;
+ if (role == IconPathRole)
+ return true;
+ if (role == IsSelectedRole)
+ {
+ if (value.type() == QVariant::Bool)
+ {
+ _dictionaries[dictionary] = value.toBool();
+ emit dataChanged(index, index);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return false;
+}
+
+Qt::ItemFlags DictManagerModel::flags(const QModelIndex &index) const
+{
+ Qt::ItemFlags fl = QAbstractItemModel::flags(index);
+ return (fl | Qt::ItemIsEditable);
+}
+
+void DictManagerModel::addDictionary(CommonDictInterface *dictionary, bool isActive)
+{
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ _dictionaries.insert(dictionary, isActive);
+ _dictList << dictionary;
+ endInsertRows();
+}
--- /dev/null
+#ifndef DICTMANAGERMODEL_H
+#define DICTMANAGERMODEL_H
+
+#include <QAbstractListModel>
+#include <QHash>
+#include "../../include/GUIInterface.h"
+
+/*!
+ Contains a list of installed dictionaries.
+ Data source for qml list view.
+*/
+class DictManagerModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ enum DictTypeRoles
+ {
+ NameRole = Qt::UserRole + 1,
+ IconPathRole,
+ IsSelectedRole,
+ NumberRole
+ };
+
+ //! Constructor
+ /*!
+ \param dictionaries list of dictionaries
+ \param parent parent of this class.
+ */
+ explicit DictManagerModel(QHash<CommonDictInterface*, bool> dictionaries, QObject *parent = 0);
+
+ int rowCount(const QModelIndex & parent = QModelIndex()) const;
+
+ QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+ bool setData(const QModelIndex &index, const QVariant &value, int role);
+
+ Qt::ItemFlags flags(const QModelIndex &index) const;
+ void setDictionaries(QHash<CommonDictInterface*, bool> dictionaries);
+
+ void clear();
+
+private:
+ QHash<CommonDictInterface*, bool> _dictionaries;
+ QList<CommonDictInterface*> _dictList;
+
+ void addDictionary(CommonDictInterface* dictionary, bool isActive);
+};
+
+#endif // DICTMANAGERMODEL_H
setWindowTitle(tr("Dictionaries"));
this->guiInterface = parent;
+ #ifndef Q_WS_MAEMO_5
+ model = 0;
+ #endif
initalizeUI();
setModal(true);
verticalLayout = new QVBoxLayout;
setLayout(verticalLayout);
+ #ifndef Q_WS_MAEMO_5
+ qmlView = new QDeclarativeView(this);
+ qmlView->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/DictManagerWidget.qml"));
+ ctxt = qmlView->rootContext();
+
+ refreshDictsList();
+ //model = new DictManagerModel(, this);
+ ctxt->setContextProperty("dictModel", &(*model));
+
+ QGraphicsObject *rootObject = qmlView->rootObject();
+ //connect(rootObject, SIGNAL(selectedRow(int)),
+ // this, SLOT(pluginSelected(int)));
+
+ qmlView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+ verticalLayout->addWidget(qmlView);
+
+ //connecty zwrotne
+ #endif
+
+ #ifdef Q_WS_MAEMO_5
dictList = new QListWidget;
verticalLayout->addWidget(dictList);
connect(dictList, SIGNAL(itemChanged(QListWidgetItem*)),
this, SLOT(changed()));
+ #endif
#ifndef Q_WS_MAEMO_5
- connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
- this, SLOT(saveChanges()));
- connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
- this, SLOT(itemSelected(QListWidgetItem*)));
- connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
- settingsButton, SIGNAL(clicked()));
+ //pozmieniać connecty
+// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
+// this, SLOT(saveChanges()));
+// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
+// this, SLOT(itemSelected(QListWidgetItem*)));
+// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)),
+// settingsButton, SIGNAL(clicked()));
#endif
+ #ifdef Q_WS_MAEMO_5
refreshDictsList();
+ #endif
#ifndef Q_WS_MAEMO_5
setMinimumSize(500,300);
- closeButton = new QPushButton(tr("Save"));
- buttonGroup->addWidget(closeButton);
+ //closeButton = new QPushButton(tr("Save"));
+ //buttonGroup->addWidget(closeButton);
setMinimumWidth(sizeHint().width()*1.2);
setMaximumWidth(sizeHint().width()*2);
setMinimumHeight(sizeHint().height());
setMaximumHeight(sizeHint().height()*2);
- connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
+ //connect(closeButton, SIGNAL(clicked()), this, SLOT(save()));
#endif
}
void DictManagerWidget::refreshDictsList() {
+ #ifndef Q_WS_MAEMO_5
+ QHash<CommonDictInterface*, bool> dicts = guiInterface->getDictionaries();
+
+ if (model == 0){
+ model = new DictManagerModel(dicts, this);
+ } else {
+ model->clear();
+ model->setDictionaries(dicts);
+ }
+
+ #endif
+
+ #ifdef Q_WS_MAEMO_5
dictList->clear();
dictsHash.clear();
removeDictButton->setEnabled(false);
while(i.hasNext()) {
i.next();
+
QListWidgetItem* item = new QListWidgetItem();
QString name;
if (i.key()->type() == "stardict") {
}
dictList->sortItems();
+ #endif
}
void DictManagerWidget::showEvent(QShowEvent *e) {
#include <QtGui>
#include "../../include/GUIInterface.h"
#include "MenuWidget.h"
+#include "DictManagerModel.h"
+#include <QtDeclarative/QDeclarativeView>
+#include <QtDeclarative/QDeclarativeContext>
/*!
QHash<QListWidgetItem*, CommonDictInterface*> dictsHash;
GUIInterface* guiInterface;
+ #ifndef Q_WS_MAEMO_5
+ QDeclarativeView* qmlView;
+ QDeclarativeContext* ctxt;
+ DictManagerModel* model;
+ #endif
+
bool _changed;
void refreshDictsList();
gui/DBusAdapter.cpp \
gui/NotifyManager.cpp \
gui/SpinBox.cpp \
- gui/DictTypeModel.cpp
+ gui/DictTypeModel.cpp \
+ gui/DictManagerModel.cpp
HEADERS += gui/MainWindow.h \
backbone/ConfigGenerator.h \
gui/DBusAdapter.h \
gui/NotifyManager.h \
gui/SpinBox.h \
- gui/DictTypeModel.h
+ gui/DictTypeModel.h \
+ gui/DictManagerModel.h
RESOURCES += ../../data/gui.qrc
+/*******************************************************************************
+
+ This file is part of mDictionary.
+
+ mDictionary is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mDictionary is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+/*!
+ author: Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
import Qt 4.7
Rectangle {
- width: 100
- height: 62
+ SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
+// signal selectedRow(int nr)
+
+ id: rectangle1
+ color: myPalette.base
+ anchors.fill: parent
+
+ ElementsListView{
+ id: dictList
+ width: rectangle1.width
+// height: rectangle1.height
+ anchors.top: parent.top
+ highlightResizeSpeed: 1000
+ delegate: Component{
+ id: dictListDelegate
+ Item {
+ width: rectangle1.width
+ height: typeText.height
+ MouseArea{
+ anchors.fill: parent
+ onClicked: {
+ dictTypeList.currentIndex = number
+ }
+ onDoubleClicked: {
+ selectedRow(number)
+ }
+ }
+ Row {
+ //image zaznacz/odznacz
+ //image logo
+ Image {
+ id: logo
+ source: iconPath
+ }
+ Text {
+ id: nameText
+ text: name
+// width: rectangle1.width
+ }
+ }
+ }
+
+ }
+ model: dictModel
+ }
+
+ //buttonki
+
}
_settings->setValue("type","google");
_settings->setValue("connection_accepted","true");
_dictDialog = new GoogleDictDialog(this,this);
- _icon = QIcon("/usr/share/mdictionary/google.png");
+ _iconPath = "/usr/share/mdictionary/google.png";
+ _icon = QIcon(_iconPath);
stopped = false;
initLanguages();
return &_icon;
}
+QString GooglePlugin::iconPath(){
+ return _iconPath;
+}
+
CommonDictInterface* GooglePlugin::getNew(const Settings* settings) const {
GooglePlugin *plugin = new GooglePlugin();
//! \returns plugin icon
QIcon* icon();
+ //! \returns plugin icon's resource path
+ QString iconPath();
+
//! \returns empty translation object (to be fetched later) for a given key
Translation* getTranslationFor(QString key);
//! icon displayed during translations and when a dictionary is chosen
QIcon _icon;
+ //! Path to icon
+ QString _iconPath;
Settings *_settings;
//! indicates if search is stopped
bool stopped;
this, SIGNAL(notify(Notify::NotifyType,QString)));
_settings->setValue("type","stardict");
- _icon = QIcon("/usr/share/mdictionary/stardict.png");
+ _iconPath = "/usr/share/mdictionary/stardict.png";
+ _icon = QIcon(_iconPath);
stopped = false;
_settings->setValue("strip_accents","true");
return &_icon;
}
+QString StarDictPlugin::iconPath(){
+ return _iconPath;
+}
+
Q_EXPORT_PLUGIN2(stardict, StarDictPlugin)
//! \returns plugin icon
QIcon* icon();
+ //! \returns plugin icon's resource path
+ QString iconPath();
+
/*!
plugin should delete any files (eg. cache) that have been created and are ready
to be deleted
QString _name;
QString _infoNote;
QIcon _icon;
+ //! Path to icon
+ QString _iconPath;
volatile bool stopped;
Settings *_settings;
StarDictDialog* _dictDialog;
}
_settings->setValue("type","xdxf");
- _icon = QIcon("/usr/share/mdictionary/xdxf.png");
+ _iconPath = "/usr/share/mdictionary/xdxf.png";
+ _icon = QIcon(_iconPath);
_wordsCount = -1;
stopped = false;
return &_icon;
}
+QString XdxfPlugin::iconPath(){
+ return _iconPath;
+}
+
int XdxfPlugin::countWords() {
if(_wordsCount>0)
//! \returns plugin icon
QIcon* icon();
+ //! \returns plugin icon's resource path
+ QString iconPath();
+
/*!
plugin should delete any files (eg. cache) that have been created and are ready
to be deleted
QString _infoNote;
QString _dictionaryInfo;
QIcon _icon;
+ //! Path to icon
+ QString _iconPath;
QSqlDatabase db;
QString db_name;
long _wordsCount;