Project

General

Profile

File browser dialog to specify a path or location

Added by Joseph Nalluri over 9 years ago

Hello,

I am trying to implement a WDialog box, which will have a 'File browsing/choosing' capability. The user would select/specify a location. I could not find this kind of functionality in the WT examples. I do not need to upload a file. Please refer to the attached image.

Any guidelines or pointers would be helpful.

- Joseph


Replies (1)

RE: File browser dialog to specify a path or location - Added by Georgiy Gluhoedov about 9 years ago

I decided a similar problem so:

WFileUpload* fu = //...
WLineEdit* le = //...

fu->setFileTextSize(150);
fu->setMultiple(false);
fu->setFilters("image/*");

fu->changed().connect(fu, &WFileUpload::upload);

fu->uploaded().connect(std::bind([=] ()
{
    // path with the images in the application directory
    std::string appDir = wApp->appRoot() + WString::tr("string.local.directory.img").toUTF8();
    boost::filesystem::path serverImgPath(appDir);

    // all images in this folder
    std::vector< boost::filesystem::path > files;
    std::copy( boost::filesystem::directory_iterator(serverImgPath), boost::filesystem::directory_iterator(), std::back_inserter(files) );

    // for the image extension (png, jpg, et al)
    boost::filesystem::path clientImgPath(fu->clientFileName().toUTF8());
    // new image path and name
    std::string imgPath = appDir + boost::lexical_cast<std::string>(files.size()) + clientImgPath.extension().string();

    // if the image exists in the temporary folder
    if(boost::filesystem::exists(fu->spoolFileName()))
    {
        // copy image
        boost::filesystem::copy_file(fu->spoolFileName(), imgPath);
        // set new path on the server
        le->setText(imgPath);
    }
}));

Br. Georgy

    (1-1/1)