← Back to team overview

ubuntu-touch-coreapps-reviewers team mailing list archive

[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-09 into lp:ubuntu-filemanager-app

 

Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-09 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-08 as a prerequisite.

Commit message:
Introduced authentication in DirModel class.


Requested reviews:
  Ubuntu File Manager Developers (ubuntu-filemanager-dev)

For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-09/+merge/252979

Introduced authentication in DirModel class.
The signal DirModel::needsAuthentication() is sent to the UI when a samba browsable item requires user/password
DirModel:setPath() changed to receive "user" and "password" to allow Location class handle authentication.
-- 
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-09 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/dirmodel.cpp'
--- src/plugin/folderlistmodel/dirmodel.cpp	2015-03-14 19:09:24 +0000
+++ src/plugin/folderlistmodel/dirmodel.cpp	2015-03-14 19:09:24 +0000
@@ -39,6 +39,7 @@
 #include "locationurl.h"
 #include "disklocation.h"
 #include "trashlocation.h"
+#include "netauthenticationdata.h"
 
 
 #ifndef DO_NOT_USE_TAG_LIB
@@ -109,6 +110,8 @@
     , mCompareFunction(0)  
     , mExtFSWatcher(false)
     , mClipboard(new Clipboard(this))
+      // create global Authentication Data before mLocationFactory
+    , mAuthData(NetAuthenticationDataList::getInstance(this))
     , mLocationFactory(new LocationsFactory(this))
     , mCurLocation(0)
     , m_fsAction(new FileSystemAction(this) )
@@ -180,6 +183,9 @@
        connect(l,     SIGNAL(extWatcherPathChanged(QString)),
                this,  SLOT(onThereAreExternalChanges(QString)));
 
+       connect(l,      SIGNAL(needsAuthentication(QString,QString)),
+               this,   SIGNAL(needsAuthentication(QString,QString)), Qt::QueuedConnection);
+
        connect(this,  SIGNAL(enabledExternalFSWatcherChanged(bool)),
                l,     SLOT(setUsingExternalWatcher(bool)));
     }
@@ -189,7 +195,8 @@
 
 DirModel::~DirModel()
 {
-
+    // release global Authentication Data
+    NetAuthenticationDataList::releaseInstance(this);
 }
 
 
@@ -420,7 +427,7 @@
 }
 
 
-void DirModel::setPath(const QString &pathName)
+void DirModel::setPath(const QString &pathName, const QString& user, const QString &password, bool savePassword)
 {
     if (pathName.isEmpty())
         return;   
@@ -432,7 +439,7 @@
         return;
     }
 
-    Location *location = mLocationFactory->setNewPath(pathName);
+    Location *location = mLocationFactory->setNewPath(pathName, user, password, savePassword);
     if (location == 0)
     {
         // perhaps a goBack() operation to a folder/location that was removed,
@@ -441,8 +448,11 @@
         {
             mPathList.removeLast();
         }
-        emit error(tr("path or url may not exist or cannot be read"), pathName);
-        qDebug() << Q_FUNC_INFO << this << "path or url may not exist or cannot be read:" << pathName;
+        if (!mLocationFactory->lastUrlNeedsAuthencation())
+        {
+            emit error(tr("path or url may not exist or cannot be read"), pathName);
+            qDebug() << Q_FUNC_INFO << this << "path or url may not exist or cannot be read:" << pathName;
+        }
         return;
     }
 
@@ -910,14 +920,25 @@
 {
     bool ret = false;
     if (fi.isBrowsable())
-    {       
-        if (fi.isContentReadable())
+    {
+        bool authentication = fi.needsAuthentication() &&
+                              !mCurLocation->useAuthenticationDataIfExists(fi);
+        if (authentication)
         {
-            mCurLocation->setInfoItem(fi);
-            setPathFromCurrentLocation();
+            mCurLocation->notifyItemNeedsAuthentication(&fi);
+            //return true to avoid any error message to appear
+            //a dialog must be presented to the user asking for user/password
             ret = true;
         }
-
+        else
+        {
+            if (fi.isContentReadable())
+            {
+                mCurLocation->setInfoItem(fi);
+                setPathFromCurrentLocation();
+                ret = true;
+            }
+        }
     }
     return ret;
 }

=== modified file 'src/plugin/folderlistmodel/dirmodel.h'
--- src/plugin/folderlistmodel/dirmodel.h	2015-03-14 19:09:24 +0000
+++ src/plugin/folderlistmodel/dirmodel.h	2015-03-14 19:09:24 +0000
@@ -48,6 +48,7 @@
 class LocationsFactory;
 class Location;
 class ExternalFSWatcher;
+class NetAuthenticationDataList;
 
 class DirModel : public DirItemAbstractListModel
 {
@@ -113,7 +114,7 @@
 
     Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
     inline QString path() const { return mCurrentDir; }
-    void setPath(const QString &pathName);
+    void setPath(const QString &pathName, const QString& user = QString(), const QString& password = QString(), bool savePassword = false);
 
     Q_INVOKABLE QDateTime   curPathAccessedDate() const;
     Q_INVOKABLE QDateTime   curPathCreatedDate()  const;
@@ -422,6 +423,19 @@
 
 signals:
     /*!
+     * \brief needsAuthentication()
+     *  This notifies the UI that the current URL being browsed needs to set
+     *   user/password to perform an authentication
+     *
+     *  The UI must ask for "user" and "password" for the current URL and then call
+     *  \ref setAuthentication()
+     *
+     * \param user       current user being used
+     * \param urlPath    the current URL asked to be browsed
+     */
+    void     needsAuthentication(const QString& user, const QString& urlPath);
+    
+    /*!
      * \brief insertedItem()
      *
      *  It happens when a new file is inserted in an existent view,
@@ -489,6 +503,7 @@
     bool                mExtFSWatcher;
     Clipboard *         mClipboard;
     DirSelection *      mSelection;
+    NetAuthenticationDataList *mAuthData;
     LocationsFactory *  mLocationFactory;
     Location         *  mCurLocation;
     QStringList         mPathList;    //!< it will be used for goBack()


Follow ups