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
khalidup
Posts: 43
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 :No:

 

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

 

 

Please use plain text.
Developer
greenmr
Posts: 871
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 :No:

 

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.
Please use plain text.
Developer
khalidup
Posts: 43
Registered: ‎11-16-2013
My Device: Z10
My Carrier: AT&T

Re: Change the file name ( Download Manager )

Hello greenmr

 

Ok :Sweatdrop:

 

 

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

 

 

:Helpsmilie:

Please use plain text.
Developer
nemory
Posts: 213
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.

Please use plain text.
Developer
khalidup
Posts: 43
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.

Please use plain text.
Developer
nemory
Posts: 213
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

Please use plain text.
Developer
khalidup
Posts: 43
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 :No:

Please use plain text.
Developer
khalidup
Posts: 43
Registered: ‎11-16-2013
My Device: Z10
My Carrier: AT&T

Re: Change the file name ( Download Manager )

any help :Helpsmilie::Helpsmilie::Helpsmilie::Helpsmilie:

Please use plain text.
Developer
BBSJdev
Posts: 5,986
Registered: ‎07-05-2012
My Device: Playbook, Z10 LE, Dev Alpha C
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. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Please use plain text.