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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 45
Registered: ‎11-16-2013
My Device: Z10
My Carrier: AT&T

Change the file name ( Download Manager )

[ Edited ]

Hello

 

I'm using a sample app Download Manager

 

and I want to add a word.

 

Example:

http://example.com/blackberry.png

 

When you save a file from the program, saves like this:

blackberry.png

 

I want to add a word when each file saves:

_hello

blackberry_hello.png

 

I change the code in DownloadManager.cpp   but nothing changes

 

The original code:

QString DownloadManager::saveFileName(const QUrl &url)
{
    // First extract the path component from the URL ...
    const QString path = url.path();

    // ... and then extract the file name.
    QString basename = QFileInfo(path).fileName();

    if (basename.isEmpty())
        basename = "download";

    // Replace the file name with 'download' if the URL provides no file name.
    basename = "tmp/" + basename; // locate in tmp directory

 

 

 

For Download Source:

http://downloads.blackberry.com/upr/developers/downloads/sampleapps/qt2/downloadmanager.zip

 

 

Developer
Posts: 1,178
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Change the file name ( Download Manager )

You show how you put stuff together in the basename variable but didn't show what you do with it then. Could you supply the full code for your saveFileName function?


khalidup wrote:

Hello

 

I'm using a sample app Download Manager

 

and I want to add a word.

 

Example:

http://example.com/blackberry.png

 

When you save a file from the program, saves like this:

blackberry.png

 

I want to add a word when each file saves:

_hello

blackberry_hello.png

 

I change the code in DownloadManager.cpp   but nothing changes

 

The original code:

QString DownloadManager::saveFileName(const QUrl &url)
{
    // First extract the path component from the URL ...
    const QString path = url.path();

    // ... and then extract the file name.
    QString basename = QFileInfo(path).fileName();

    if (basename.isEmpty())
        basename = "download";

    // Replace the file name with 'download' if the URL provides no file name.
    basename = "tmp/" + basename; // locate in tmp directory

 

 

 

For Download Source:

http://downloads.blackberry.com/upr/developers/downloads/sampleapps/qt2/downloadmanager.zip

 

 






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 45
Registered: ‎11-16-2013
My Device: Z10
My Carrier: AT&T

Re: Change the file name ( Download Manager )

Hello greenmr

 

Ok

 

 

From DownloadManager.cpp

 

QString DownloadManager::saveFileName(const QUrl &url)
{
    // First extract the path component from the URL ...
    const QString path = url.path();

    // ... and then extract the file name.
    QString basename = QFileInfo(path).fileName();

    if (basename.isEmpty())
        basename = "download";

    // Replace the file name with 'download' if the URL provides no file name.
    basename = "tmp/" + basename; // locate in tmp directory

    /**
     * Check if the file name exists already, if so, append an increasing number and test again.
     */
    if (QFile::exists(basename)) {
        // already exists, don't overwrite
        int i = 0;
        basename += '.';
        while (QFile::exists(basename + QString::number(i)))
            ++i;

        basename += QString::number(i);
    }

    return basename;
}

 

 

From DownloadManager.hpp

 

    // This method determines a file name that can be used to save the given URL
    QString saveFileName(const QUrl &url);

 

 

For Download Full Source:

http://downloads.blackberry.com/upr/developers/downloads/sampleapps/qt2/downloadmanager.zip

 

 

Developer
Posts: 237
Registered: ‎05-21-2012
My Device: BlackBerry RED Z10
My Carrier: WiFi

Re: Change the file name ( Download Manager )

the basename variable is the one you should look into. That's the actual filename it saves.

Developer
Posts: 45
Registered: ‎11-16-2013
My Device: Z10
My Carrier: AT&T

Re: Change the file name ( Download Manager )

Hello nemory

 

I know, and you change the variable (basename) but nothing changes.

Developer
Posts: 237
Registered: ‎05-21-2012
My Device: BlackBerry RED Z10
My Carrier: WiFi

Re: Change the file name ( Download Manager )

not just the variable name you need to change but the value

Developer
Posts: 45
Registered: ‎11-16-2013
My Device: Z10
My Carrier: AT&T

Re: Change the file name ( Download Manager )

Hello nemory

 

I know I have tried to change the value, but nothing changes

Highlighted
Developer
Posts: 45
Registered: ‎11-16-2013
My Device: Z10
My Carrier: AT&T

Re: Change the file name ( Download Manager )

any help

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

Re: Change the file name ( Download Manager )

What exactly did you change, just adding...

 

    // Replace the file name with 'download' if the URL provides no file name.
    basename = "tmp/" + basename + "_hello"; // locate in tmp directory

 

should have worked.


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

Developer of stokLocker, Sympatico and Super Sentences.