Skip to content

Commit

Permalink
Implement dynamic category handling and make it functional
Browse files Browse the repository at this point in the history
Signed-off-by: Yunusemre Şentürk <[email protected]>
  • Loading branch information
Yunusemre Şentürk committed Jan 16, 2019
1 parent aadcc9a commit aaf481c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 82 deletions.
8 changes: 6 additions & 2 deletions src/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,17 @@ void Helper::appListReceivedSlot(const QList<Application> &apps)
{
m_fakelist = apps;
for(int i = 0; i< m_fakelist.length(); i++) {
if(!m_categories.contains(m_fakelist[i].category())) {
if(!m_categories.contains(m_fakelist[i].category()) && m_fakelist[i].category() != "") {
m_categories.append(m_fakelist[i].category());
m_categorieswithlocal.insert(m_fakelist[i].category(),m_fakelist[i].categoryLocal());
}
}
m_categories.sort();
emit categorylistChanged();
if(m_categories.contains("others")) {
m_categories.removeAt(m_categories.indexOf("others"));
m_categories.append("others");
}
emit categorylistChanged();
emit fetchingAppListFinished();
this->updateListUsingPackageManager();
this->getSelfVersion();
Expand Down
2 changes: 1 addition & 1 deletion ui/ApplicationDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ Item {
stackView.push(applicationDetail, {
objectName: "detail",
"current": name,
"previous": categoryIcons[categories.indexOf(selectedCategory)],
"previous": selectedCategory,
"appVersion":version,
"appDownloadSize" : dsize,
"appCategory" : category,
Expand Down
9 changes: 4 additions & 5 deletions ui/ApplicationDetail.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ Rectangle {
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
font.capitalization: Font.Capitalize
text: categories[categoryIcons.indexOf(appCategory)]
text: helper.getCategoryLocal(appCategory)
font.pointSize: 12
font.weight: Font.DemiBold
MouseArea {
Expand All @@ -1020,8 +1020,8 @@ Rectangle {
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if(categoryIcons[categories.indexOf(selectedCategory)] === "all") {
selectedCategory = categories[categoryIcons.indexOf(appCategory)]
if(selectedCategory === "all") {
selectedCategory = appCategory
} else {
stackView.pop()
}
Expand Down Expand Up @@ -1752,7 +1752,7 @@ Rectangle {
z: 92
height: 54
width: height * 2 / 3
opacity: selectedCategory !== qsTr("home") ? 1.0 : 0.0
opacity: 1.0
Material.background: "#515151"
anchors {
top: parent.top
Expand All @@ -1774,7 +1774,6 @@ Rectangle {

onClicked: {
stackView.pop()

}

Behavior on opacity {
Expand Down
2 changes: 1 addition & 1 deletion ui/ApplicationList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Page {
clip: true
cellWidth: (width - scrollBarWidth) / ratio
cellHeight: height / ratio

cacheBuffer: height * 5
visible: true
interactive: count > 15 ? true : false
snapMode: GridView.SnapToRow
Expand Down
14 changes: 7 additions & 7 deletions ui/Home.qml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Rectangle {
id: bannerImage
width: parent.width + 24
height: parent.height + 24
source: helper.getMainUrl() + "/screenshots/banner.png"
source: helper.getMainUrl() + "/files/screenshots/banner.png"
anchors {
centerIn: parent
}
Expand Down Expand Up @@ -183,9 +183,9 @@ Rectangle {

onClicked: {
if(epaPrettyName !== "") {
selectedCategory = qsTr("all")
selectedCategory = "all"
expanded = true
selectedMenu = qsTr("categories")
selectedMenu = "categories"
forceActiveFocus()
applicationModel.setFilterString(epaName, true)
}
Expand Down Expand Up @@ -355,9 +355,9 @@ Rectangle {

onClicked: {
if(mdaPrettyName !== "") {
selectedCategory = qsTr("all")
selectedCategory = "all"
expanded = true
selectedMenu = qsTr("categories")
selectedMenu = "categories"
forceActiveFocus()
applicationModel.setFilterString(mdaName, true)
}
Expand Down Expand Up @@ -528,9 +528,9 @@ Rectangle {

onClicked: {
if(mraPrettyName !== "") {
selectedCategory = qsTr("all")
selectedCategory = "all"
expanded = true
selectedMenu = qsTr("categories")
selectedMenu = "categories"
forceActiveFocus()
applicationModel.setFilterString(mraName, true)
}
Expand Down
57 changes: 30 additions & 27 deletions ui/NavigationBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ Rectangle {
property alias packageName: processOutputLabel.packageName
property alias condition: processOutputLabel.condition

function categoriesReceived() {
for (var i = 0; i < categories.length; i++) {
categoryListModel.append({"name" : categories[i]})
}
}

ListModel {
id: menuListModel
}
Expand All @@ -30,16 +36,17 @@ Rectangle {
}

Component.onCompleted: {
for (var i = 0; i < categories.length; i++) {
categoryListModel.append({"name" : categories[i], "icon" : categoryIcons[i]})
}
for (i = 0; i < menus.length; i++) {
menuListModel.append({"name" : menus[i], "icon" : menuIcons[i]})
categoriesFilled.connect(categoriesReceived)
var cnt = 0;
var index = 1;
for (var key in menuList) {
index = (key === "home") ? cnt : 1
menuListModel.append({"name" : key, "localname": menuList[key]})
cnt = cnt + 1
}
menuListModel.move(index,0,1)
}



Component {
id: categoryItemDelegate
Rectangle {
Expand All @@ -52,7 +59,7 @@ Rectangle {
Image {
id: categoryItemIcon
asynchronous: true
source: "qrc:/images/" + icon + ".svg"
source: ((name === "all") ? "qrc:/images/" : (helper.getMainUrl() + "/files/categoryicons/")) + name + ".svg"
fillMode: Image.PreserveAspectFit
height: categoryItemHeight - anchors.topMargin * 2
width: height
Expand All @@ -65,6 +72,14 @@ Rectangle {
left: parent.left
leftMargin: width / 2
}
onStatusChanged: {
if(name == "test") {
if(status == Image.Error) {
console.log("Error occured")
}
}

}
}

Label {
Expand All @@ -78,7 +93,7 @@ Rectangle {
}
color: name === selectedCategory ? accentColor : "#E4E4E4"
font.capitalization: Font.Capitalize
text: name
text: name === "all" ? qsTr("all") :helper.getCategoryLocal(name)
fontSizeMode: Text.HorizontalFit
}

Expand All @@ -88,7 +103,7 @@ Rectangle {
hoverEnabled: true
onClicked: {
if(name === selectedCategory && applicationModel.getFilterString() !== "") {
applicationModel.setFilterString(selectedCategory === qsTr("all") ? "" : categoryIcons[categories.indexOf(selectedCategory)], false)
applicationModel.setFilterString(selectedCategory === "all" ? "" : name, false)
}

selectedCategory = name
Expand All @@ -114,7 +129,7 @@ Rectangle {
anchors.horizontalCenter: parent.horizontalCenter
width: navi.width
height: menuItemHeight
state: ((name === qsTr("categories")) && expanded) ? "expanded" : ""
state: ((name === "categories") && expanded) ? "expanded" : ""


Item {
Expand All @@ -134,7 +149,7 @@ Rectangle {
Image {
id: menuItemIcon
asynchronous: true
source: "qrc:/images/" + icon + ((bgRect.color == "#f0f0f0") ? "-dark.svg" : ".svg")
source: "qrc:/images/" + name + ((bgRect.color == "#f0f0f0") ? "-dark.svg" : ".svg")
fillMode: Image.PreserveAspectFit
height: 36
width: height
Expand All @@ -149,18 +164,6 @@ Rectangle {
}
}

// DropShadow {
// id:ds
// visible: true
// anchors.fill: menuItemIcon
// horizontalOffset: 3
// verticalOffset: 3
// radius: 8
// samples: 17
// color: "#ff000000"
// source: menuItemIcon
// }

Label {
id: menuItemLabel
anchors {
Expand All @@ -173,7 +176,7 @@ Rectangle {
color: name === selectedMenu ? accentColor : "#E4E4E4"
font.bold: name === selectedMenu
font.capitalization: Font.Capitalize
text: name
text: localname
fontSizeMode: Text.HorizontalFit
}

Expand All @@ -183,9 +186,9 @@ Rectangle {
onClicked: {
forceActiveFocus()
selectedMenu = name
if(selectedMenu === qsTr("categories")) {
if(selectedMenu === "categories") {
expanded = !expanded
selectedCategory = qsTr("all")
selectedCategory = "all"
} else {
expanded = false
}
Expand Down
4 changes: 2 additions & 2 deletions ui/SearchBar.qml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ Item {
if(stackView.depth === 3) {
stackView.pop()
}
selectedMenu = qsTr("categories")
selectedCategory = qsTr("all")
selectedMenu = "categories"
selectedCategory = "all"
expanded = true
applicationModel.setFilterString(searchText.text.trim(), true)
}
Expand Down
2 changes: 1 addition & 1 deletion ui/Settings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Pane {
Material.background: backgroundColor
Material.elevation: 3
z: 92
visible: selectedMenu === qsTr("settings")
visible: selectedMenu === "settings"
width: stackView.width
height: stackView.height
anchors.centerIn: stackView
Expand Down
51 changes: 15 additions & 36 deletions ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,14 @@ ApplicationWindow {
property string popupText: ""
property string popupHeaderText: qsTr("Something went wrong!")
property string lastProcess: ""
property string selectedCategory: qsTr("all")
property string selectedMenu: qsTr("home")
property string selectedCategory: "all"
property string selectedMenu: "home"
property string previousMenu: ""

property variant processQueue: []
property variant menus: [qsTr("home"), qsTr("categories"), qsTr("settings")]
property variant menuIcons: ["home", "categories", "settings"]
property variant processQueue: []
property variant menuList: {"home": qsTr("home"), "categories": qsTr("categories"), "settings": qsTr("settings")}
property variant specialApplications: ["gnome-builder", "xfce4-terminal"]
property variant categories: [
qsTr("all"),
qsTr("internet"),
qsTr("office"),
qsTr("development"),
qsTr("reading"),
qsTr("graphics"),
qsTr("game"),
qsTr("music"),
qsTr("system"),
qsTr("video"),
qsTr("chat"),
qsTr("others")]
property variant categoryIcons: [
"all",
"internet",
"office",
"development",
"reading",
"graphics",
"game",
"music",
"system",
"video",
"chat",
"others"]
property variant categories: []

property alias processingPackageName: navigationBar.packageName
property alias processingCondition: navigationBar.condition
Expand All @@ -77,6 +51,7 @@ ApplicationWindow {
signal surveyJoined()
signal surveyJoinUpdated()
signal errorOccured()
signal categoriesFilled()
signal appDescriptionReceived(variant desc)
signal appDetailsReceived(variant cl, variant ch, variant ct, variant cp,
variant desc, variant down, variant l,
Expand Down Expand Up @@ -276,7 +251,11 @@ ApplicationWindow {
}

onCategorylistChanged: {
console.log(categorylist)
categories.push("all")
for(var i = 0; i < categorylist.length; i++){
categories.push(categorylist[i])
}
categoriesFilled()
}
}

Expand Down Expand Up @@ -414,14 +393,14 @@ ApplicationWindow {
}

onSelectedMenuChanged: {
var m = menuIcons[menus.indexOf(selectedMenu)]
var c = categoryIcons[categories.indexOf(selectedCategory)]
var m = selectedMenu
var c = selectedCategory
var current = stackView.currentItem.current
var name = stackView.currentItem.objectName

if(m !== "categories") {
if(applicationModel.getFilterString() !== "") {
applicationModel.setFilterString(selectedCategory === qsTr("all") ? "" : categoryIcons[categories.indexOf(selectedCategory)], false)
applicationModel.setFilterString(selectedCategory === "all" ? "" : selectedCategory, false)
}
}

Expand All @@ -438,7 +417,7 @@ ApplicationWindow {
}

onSelectedCategoryChanged: {
applicationModel.setFilterString(selectedCategory === qsTr("all") ? "" : categoryIcons[categories.indexOf(selectedCategory)], false)
applicationModel.setFilterString(selectedCategory === "all" ? "" : selectedCategory, false)
if(stackView.currentItem.previous && stackView.currentItem.objectName === "detail") {
stackView.pop()
}
Expand Down

0 comments on commit aaf481c

Please sign in to comment.