dfaure accepted this revision.
dfaure added a comment.
This revision is now accepted and ready to land.


  Oh I see, sorry for the bug in operator bool() in my suggested code. It reads 
strange that operator bool() returns true on failure, but .... yeah it's the 
most common use case for this class. Make sure to add a comment in that class 
docu, it's surely going to surprise someone some day, just like it just 
surprised me despite me writing the pseudo-code for it ;)
  Something like this...
  
    /**
     * PrivilegeOperationReturnValue encapsulates the return value from 
execWithElevatedPrivilege() in a convenient way.
     * Warning, this class will cast to a bool that is false on success and 
true on failure. This unusual solution allows to write
     * kioslave code like this:
    
    if (!dir.rmdir(itemPath)) {
        if (auto ret = execWithElevatedPrivilege(RMDIR, itemPath)) {
            if (!ret.wasCanceled()) {
                error(KIO::ERR_CANNOT_DELETE, itemPath);
            }
            return false;
        }
    }
    // directory successfully removed, continue with the next operation
    */

BRANCH
  second

REVISION DETAIL
  https://phabricator.kde.org/D6829

To: chinmoyr, dfaure, #frameworks
Cc: #frameworks

Reply via email to