Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
robertopne123
Posts: 27
Registered: ‎06-23-2014
My Device: Blackberry Z10
Accepted Solution

Adding feeds to "feeds.xml"

[ Edited ]

Hello everyone, I am currently taking programming as a hobbie. I like the Blackberry 10 OS and I am interested in coding for the platform.

 

I am using Cascades (QML and C++) and I am trying to make a podcast downloader, like BPod and PodcastAddicts (Android). I have currently designed the UI for the app, but I am running into quite a few problems and I hope that people don't mind helping me out.

 

So firstly: I have a screen that has the controls to add feeds to the library. I am storing the feeds in an xml file called "feeds.xml", but I am stuck on how to write to the file. I want it so when the button is clicked then it gets added to the "feeds.xml" file and the library updates showing the newly added podcast feed.

 

Currently I have this code:

 

import bb.cascades 1.0

NavigationPane{
Page {
    id: myPage   
    Container {

        topPadding: 10
        background: Color.Black
        Container {
            id: addFeedContainer
            layout: StackLayout {
                orientation: LayoutOrientation.LeftToRight

            }
            TextField {
                id: feedUrl
                hintText: qsTr("Add feed url") + Retranslate.onLanguageChanged
                inputMode: TextFieldInputMode.Url
                clearButtonVisible: true
                layoutProperties: StackLayoutProperties {
                    spaceQuota: 1
                }
                input {
                    submitKeyFocusBehavior: SubmitKeyFocusBehavior.Lose
                    submitKey: SubmitKey.Submit
                    onSubmitted: {
                        addFeedContainer.addFeed();
                        
                    }
                }

            }
            Button {
                text: qsTr("Add") + Retranslate.onLanguageChanged
                preferredWidth: feedUrl.focused ? 20 : undefined
                onClicked: {
                    addFeedContainer.addFeed(feedUrl.text);
                }
            }
            function addFeed() {
                

                // Reset the TextField to its original state
                feedUrl.loseFocus()
                feedUrl.text = ""
            }
        }
        ListView {
            topMargin: 50
            dataModel: XmlDataModel {
                id: rss
                source: "feeds.xml"
            }

            listItemComponents: [
                ListItemComponent {
                    type: "item"

                    SettingsListItem {
                        
                    }
                }
            ]
            
        }
    }
}
}

 

 Thanks in advance

Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Need help with Cascades

[ Edited ]

Welcome to the forums.

 

Although it may appear to be one problem to you it's better to split separate questions in to separate threads.

Think about it from an answerer's point of view; looking at a huge OP, you'll get many that won't bother to read it all, and those who don't answer because they can only help with one part. It also prevents separate solutions to be marked as solved and then searched on later.

 

Please edit your first post and split the last two questions in to separate threads for your own benefit.

You can always link the threads if you need to .

 

 

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
robertopne123
Posts: 27
Registered: ‎06-23-2014
My Device: Blackberry Z10

Re: Need help with Cascades

Ok thanks, will do

Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Need help with Cascades

For writing XML data out you will need to use on of the XML classes such as QMLStreamWriter or XMLDataAccess...

 

http://developer.blackberry.com/native/reference/cascades/qxmlstreamwriter.html

 

http://developer.blackberry.com/native/reference/cascades/bb__data__xmldataaccess.html

 

There are others but these are probably the most common.

 

There's also a few samples you can look at on how it works,

http://developer.blackberry.com/native/sampleapps/


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
robertopne123
Posts: 27
Registered: ‎06-23-2014
My Device: Blackberry Z10

Re: Need help with Cascades

Which one of these requires the least amount of coding in C++ as I prefer using the QML language?

Developer
robertopne123
Posts: 27
Registered: ‎06-23-2014
My Device: Blackberry Z10

Re: Need help with Cascades

Wouldn't it just be easier to save each feed url in a seperate .txt file and the title of the feed being the filename?

Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Need help with Cascades

XMLDataAccess but there are limitations on the XML you can write out so if you are planning on adding more complexity later then you might consider using QXmlStreamWriter now.

 

However I use both in my app and so there is nothing stopping you using XMLDataAccess now and then looking at QXmlStreamWriter when you need more complexity.

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
robertopne123
Posts: 27
Registered: ‎06-23-2014
My Device: Blackberry Z10

Re: Need help with Cascades

Thanks

Developer
BBSJdev
Posts: 6,116
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: Need help with Cascades

I would stick to XML rather than text files, once you look at it, and there are examples in those links, then it really is trivial.

 

Don't forget to move the XML file to the Data folder if you are starting with a prewritten one in the assets folder.

 


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
robertopne123
Posts: 27
Registered: ‎06-23-2014
My Device: Blackberry Z10

Re: Need help with Cascades

OK will do thanks