[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [muon/newui] installer: General refactoring to make categories and subcategories navigation work.
From: Aleix Pol <aleixpol () kde ! org>
Date: 2012-02-01 4:34:34
Message-ID: 20120201043434.928EDA60A6 () git ! kde ! org
[Download RAW message or body]
Git commit 505cb8bec72d38c5440e5a914045695a4344ecc6 by Aleix Pol.
Committed on 31/01/2012 at 16:36.
Pushed by apol into branch 'newui'.
General refactoring to make categories and subcategories navigation work.
M +1 -36 installer/AvailableView.cpp
M +0 -4 installer/AvailableView.h
M +4 -0 installer/CMakeLists.txt
M +45 -2 installer/CategoryModel.cpp
M +6 -1 installer/CategoryModel.h
M +37 -0 installer/CategoryView/Category.cpp
M +2 -0 installer/CategoryView/Category.h
M +1 -1 installer/CategoryView/CategoryViewWidget.cpp
M +7 -0 installer/muon-qml/MuonInstallerDeclarativeView.cpp
M +52 -20 installer/muon-qml/qml/Main.qml
http://commits.kde.org/muon/505cb8bec72d38c5440e5a914045695a4344ecc6
diff --git a/installer/AvailableView.cpp b/installer/AvailableView.cpp
index 3bb6834..b1d7773 100644
--- a/installer/AvailableView.cpp
+++ b/installer/AvailableView.cpp
@@ -36,11 +36,6 @@
#include "CategoryView/Category.h"
#include "CategoryView/CategoryViewWidget.h"
-bool categoryLessThan(Category *c1, const Category *c2)
-{
- return (QString::localeAwareCompare(c1->name(), c2->name()) < 0);
-}
-
AvailableView::AvailableView(QWidget *parent, ApplicationBackend *appBackend)
: AbstractViewContainer(parent)
, m_backend(0)
@@ -48,11 +43,10 @@ AvailableView::AvailableView(QWidget *parent, ApplicationBackend \
*appBackend) {
m_categoryViewWidget = new CategoryViewWidget(m_viewStack, m_appBackend);
- populateCategories();
QString rootName = i18n("Get Software");
KIcon rootIcon = KIcon("applications-other");
- m_categoryViewWidget->setCategories(m_categoryList, rootName, rootIcon);
+ m_categoryViewWidget->setCategories(Category::populateCategories(), rootName, \
rootIcon);
m_breadcrumbWidget->setRootItem(m_categoryViewWidget->breadcrumbItem());
m_viewStack->addWidget(m_categoryViewWidget);
@@ -77,33 +71,4 @@ void AvailableView::setBackend(QApt::Backend *backend)
m_categoryViewWidget->setBackend(backend);
}
-void AvailableView::populateCategories()
-{
- qDeleteAll(m_categoryList);
- m_categoryList.clear();
- QFile menuFile(KStandardDirs::locate("appdata", "categories.xml"));
-
- if (!menuFile.open(QIODevice::ReadOnly)) {
- // Broken install or broken FS
- return;
- }
-
- QDomDocument menuDocument;
- QString error;
- int line;
- menuDocument.setContent(&menuFile, &error, &line);
-
- QDomElement root = menuDocument.documentElement();
-
- QDomNode node = root.firstChild();
- while(!node.isNull())
- {
- m_categoryList << new Category(node);
-
- node = node.nextSibling();
- }
-
- qSort(m_categoryList.begin(), m_categoryList.end(), categoryLessThan);
-}
-
#include "AvailableView.moc"
diff --git a/installer/AvailableView.h b/installer/AvailableView.h
index fbb85b6..3b478dd 100644
--- a/installer/AvailableView.h
+++ b/installer/AvailableView.h
@@ -42,15 +42,11 @@ public:
private:
QApt::Backend *m_backend;
ApplicationBackend *m_appBackend;
- QList<Category *> m_categoryList;
CategoryViewWidget *m_categoryViewWidget;
public Q_SLOTS:
void setBackend(QApt::Backend *backend);
-
-private Q_SLOTS:
- void populateCategories();
};
#endif
diff --git a/installer/CMakeLists.txt b/installer/CMakeLists.txt
index 659ab23..4168ddc 100644
--- a/installer/CMakeLists.txt
+++ b/installer/CMakeLists.txt
@@ -52,6 +52,10 @@ kde4_add_kcfg_files(muon_installer_SRCS GENERATE_MOC \
config/MuonInstallerSetting
kde4_add_executable(muon-installer ${muon_installer_SRCS})
+if(NOT qjson_LIBRARIES) #hack to compatibilize different qjson finder versions
+ set(qjson_LIBRARIES ${QJSON_LIBRARIES})
+endif()
+
target_link_libraries(muon-installer muonprivate
${KDE4_KIO_LIBS}
${QAPT_LIBRARY}
diff --git a/installer/CategoryModel.cpp b/installer/CategoryModel.cpp
index 2b99ef4..0983484 100644
--- a/installer/CategoryModel.cpp
+++ b/installer/CategoryModel.cpp
@@ -1,16 +1,44 @@
+/***************************************************************************
+ * Copyright © 2012 Aleix Pol Gonzalez <aleixpol@kde.org> *
+ * *
+ * This program 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 2 of *
+ * the License or (at your option) version 3 or any later version *
+ * accepted by the membership of KDE e.V. (or its successor approved *
+ * by the membership of KDE e.V.), which shall act as a proxy *
+ * defined in Section 14 of version 3 of the license. *
+ * *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. *
+ ***************************************************************************/
+
#include "CategoryModel.h"
#include "CategoryView/Category.h"
#include <KIcon>
#include <KCategorizedSortFilterProxyModel>
+#include <QDebug>
CategoryModel::CategoryModel(QObject* parent)
: QStandardItemModel(parent)
{}
+CategoryModel::~CategoryModel()
+{
+ qDeleteAll(m_categoryList);
+}
+
void CategoryModel::setCategories(const QList<Category *> &categoryList,
const QString &rootName)
{
+ qDeleteAll(m_categoryList);
m_categoryList = categoryList;
+ qDebug() << "fuuuuuuuuu";
foreach (Category *category, m_categoryList) {
QStandardItem *categoryItem = new QStandardItem;
categoryItem->setText(category->name());
@@ -28,7 +56,22 @@ void CategoryModel::setCategories(const QList<Category *> \
&categoryList, }
}
-Category* CategoryModel::categoryForIndex(const QModelIndex& index)
+Category* CategoryModel::categoryForIndex(int row)
+{
+ return m_categoryList.at(row);
+}
+
+void CategoryModel::populateCategories(const QString& rootName)
+{
+ setCategories(Category::populateCategories(), rootName);
+}
+
+void CategoryModel::setSubcategories(Category* c)
+{
+ setCategories(c->subCategories(), c->name());
+}
+
+QObject* CategoryModel::objectForIndex(int row)
{
- return m_categoryList.at(index.row());
+ return categoryForIndex(row);
}
diff --git a/installer/CategoryModel.h b/installer/CategoryModel.h
index 3b583d2..80d3b46 100644
--- a/installer/CategoryModel.h
+++ b/installer/CategoryModel.h
@@ -45,9 +45,14 @@ class CategoryModel : public QStandardItemModel
};
explicit CategoryModel(QObject* parent = 0);
+ virtual ~CategoryModel();
void setCategories(const QList<Category *> &categoryList, const QString \
&rootName);
- Category* categoryForIndex(const QModelIndex& index);
+ Q_SCRIPTABLE Category* categoryForIndex(int row);
+ Q_SCRIPTABLE QObject* objectForIndex(int row);
+
+ Q_SCRIPTABLE void populateCategories(const QString& rootName);
+ Q_SCRIPTABLE void setSubcategories(Category* c);
private:
QList<Category*> m_categoryList;
diff --git a/installer/CategoryView/Category.cpp \
b/installer/CategoryView/Category.cpp index cbee85d..9f66b36 100644
--- a/installer/CategoryView/Category.cpp
+++ b/installer/CategoryView/Category.cpp
@@ -23,6 +23,8 @@
#include <QtXml/QDomNode>
#include <KLocale>
+#include <KStandardDirs>
+#include <QFile>
Category::Category(const QDomNode &data, CategoryChildPolicy policy)
: m_iconString("applications-other")
@@ -157,3 +159,38 @@ QList<Category *> Category::subCategories() const
{
return m_subCategories;
}
+
+bool categoryLessThan(Category *c1, const Category *c2)
+{
+ return (QString::localeAwareCompare(c1->name(), c2->name()) < 0);
+}
+
+QList< Category* > Category::populateCategories()
+{
+ QFile menuFile(KStandardDirs::locate("appdata", "categories.xml"));
+ QList<Category *> ret;
+
+ if (!menuFile.open(QIODevice::ReadOnly)) {
+ // Broken install or broken FS
+ return ret;
+ }
+
+ QDomDocument menuDocument;
+ QString error;
+ int line;
+ menuDocument.setContent(&menuFile, &error, &line);
+
+ QDomElement root = menuDocument.documentElement();
+
+ QDomNode node = root.firstChild();
+ while(!node.isNull())
+ {
+ ret << new Category(node);
+
+ node = node.nextSibling();
+ }
+
+ qSort(ret.begin(), ret.end(), categoryLessThan);
+
+ return ret;
+}
diff --git a/installer/CategoryView/Category.h b/installer/CategoryView/Category.h
index 8a4bd8f..f43b8d6 100644
--- a/installer/CategoryView/Category.h
+++ b/installer/CategoryView/Category.h
@@ -60,6 +60,8 @@ public:
bool hasSubCategories() const;
bool shouldShowTechnical() const;
QList<Category *> subCategories() const;
+
+ static QList<Category*> populateCategories();
private:
QString m_name;
diff --git a/installer/CategoryView/CategoryViewWidget.cpp \
b/installer/CategoryView/CategoryViewWidget.cpp index eb23d08..3ac7459 100644
--- a/installer/CategoryView/CategoryViewWidget.cpp
+++ b/installer/CategoryView/CategoryViewWidget.cpp
@@ -93,7 +93,7 @@ void CategoryViewWidget::onIndexActivated(const QModelIndex &index)
}
// Otherwise we have to create a new view
- Category *category = m_categoryModel->categoryForIndex(index);
+ Category *category = m_categoryModel->categoryForIndex(index.row());
switch (index.data(CategoryModel::CategoryTypeRole).toInt()) {
case CategoryModel::CategoryType: { // Displays the apps in a category
diff --git a/installer/muon-qml/MuonInstallerDeclarativeView.cpp \
b/installer/muon-qml/MuonInstallerDeclarativeView.cpp index b6cffe7..6a703e9 100644
--- a/installer/muon-qml/MuonInstallerDeclarativeView.cpp
+++ b/installer/muon-qml/MuonInstallerDeclarativeView.cpp
@@ -19,6 +19,9 @@
#include "MuonInstallerDeclarativeView.h"
#include <kdeclarative.h>
+#include <qdeclarative.h>
+#include <CategoryModel.h>
+#include <CategoryView/Category.h>
MuonInstallerDeclarativeView::MuonInstallerDeclarativeView(QWidget* parent)
: QDeclarativeView(parent)
@@ -29,6 +32,10 @@ MuonInstallerDeclarativeView::MuonInstallerDeclarativeView(QWidget* \
parent) //binds things like kconfig and icons
kdeclarative.setupBindings();
+ qmlRegisterType<CategoryModel>("org.kde.muon", 1, 0, "CategoryModel");
+ qmlRegisterInterface<Category>("Category");
+// qmlRegisterInterface<QList<Category*> >("QList<Category*>");
+
setResizeMode(SizeRootObjectToView);
setSource(QUrl("qrc:/qml/Main.qml"));
}
diff --git a/installer/muon-qml/qml/Main.qml b/installer/muon-qml/qml/Main.qml
index 5bc1ccc..f03f3da 100644
--- a/installer/muon-qml/qml/Main.qml
+++ b/installer/muon-qml/qml/Main.qml
@@ -1,30 +1,60 @@
-import QtQuick 1.0
+import QtQuick 1.1
import org.kde.plasma.components 0.1
+import org.kde.qtextracomponents 0.1
+import org.kde.muon 1.0
Rectangle {
height: 400
width: 300
color: "lightgrey"
- Page {
- id: init
- anchors.margins: 10
-
- ListView {
- id: pluginsView
- anchors.fill: parent
-
- delegate:
- ToolButton {
- iconSource: decoration
- text: i18n("%1 - %2", title, subtitle)
-
- onClicked: goToPage(model.path, decoration)
+ Component {
+ id: categoryComp
+
+ Page {
+ property variant category
+ property QtObject model: cats
+
+ ListView {
+ model: cats
+ anchors.fill: parent
+ delegate: categoryDelegate
+ }
+
+ CategoryModel {
+ id: cats
+ Component.onCompleted: {
+ console.log("lalala "+category)
+ if(category)
+ setSubcategories(category)
+ else
+ populateCategories(i18n("Get Software"))
}
-// model: CategoryModel {}
+ }
+ }
+ }
+
+ Component {
+ id: categoryDelegate
+ ListItem {
+ Row {
+ spacing: 10
+ QIconItem { icon: decoration; width: 40; height: 40 }
+ Label { text: i18n("%1", display) }
+ }
+ MouseArea { anchors.fill: parent; onClicked: goToPage(index) }
+ }
+ }
+
+ function goToPage(idx) {
+ try {
+ console.log("......... "+pageStack.currentPage)
+ var cat = pageStack.currentPage.model.categoryForIndex(idx)
+ var obj = categoryComp.createObject(pageStack, { category: cat })
+ pageStack.push(obj);
+ } catch (e) {
+ console.log("error: "+e)
}
-
- tools: ToolBarLayout {}
}
PageStack
@@ -32,7 +62,9 @@ Rectangle {
id: pageStack
width: parent.width
anchors.fill: parent
-
- initialPage: init
+ }
+
+ Component.onCompleted: {
+ pageStack.initialPage = categoryComp.createObject(pageStack)
}
}
\ No newline at end of file
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic