[Pkg-owncloud-commits] [owncloud-client] 147/164: Remote folder wizard: Add optional manual entry #2613

Sandro Knauß hefee-guest at moszumanska.debian.org
Sun Mar 22 11:57:07 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 95f299f865d88e5faacd3154029d71d036fc0f6e
Author: Christian Kamm <kamm at incasoftware.de>
Date:   Thu Mar 12 15:59:59 2015 +0100

    Remote folder wizard: Add optional manual entry #2613
---
 src/gui/folderwizard.cpp          | 118 +++++++++++++++++++++++++++++++-------
 src/gui/folderwizard.h            |   6 ++
 src/gui/folderwizardtargetpage.ui |   7 ++-
 3 files changed, 109 insertions(+), 22 deletions(-)

diff --git a/src/gui/folderwizard.cpp b/src/gui/folderwizard.cpp
index d676084..6326194 100644
--- a/src/gui/folderwizard.cpp
+++ b/src/gui/folderwizard.cpp
@@ -239,10 +239,13 @@ FolderWizardRemotePath::FolderWizardRemotePath(AccountPtr account)
 
     connect(_ui.addFolderButton, SIGNAL(clicked()), SLOT(slotAddRemoteFolder()));
     connect(_ui.refreshButton, SIGNAL(clicked()), SLOT(slotRefreshFolders()));
-    connect(_ui.folderTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*,int)), SIGNAL(completeChanged()));
-    connect(_ui.folderTreeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), SIGNAL(completeChanged()));
     connect(_ui.folderTreeWidget, SIGNAL(itemExpanded(QTreeWidgetItem*)), SLOT(slotItemExpanded(QTreeWidgetItem*)));
+    connect(_ui.folderTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), SLOT(slotCurrentItemChanged(QTreeWidgetItem*)));
+    connect(_ui.folderEntry, SIGNAL(textEdited(QString)), SLOT(slotFolderEntryEdited(QString)));
 
+    _lscolTimer.setInterval(500);
+    _lscolTimer.setSingleShot(true);
+    connect(&_lscolTimer, SIGNAL(timeout()), SLOT(slotLsColFolderEntry()));
 }
 
 void FolderWizardRemotePath::slotAddRemoteFolder()
@@ -315,27 +318,58 @@ static QTreeWidgetItem* findFirstChild(QTreeWidgetItem *parent, const QString& t
 
 void FolderWizardRemotePath::recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path)
 {
-    QFileIconProvider prov;
-    QIcon folderIcon = prov.icon(QFileIconProvider::Folder);
-    if (pathTrail.size() == 0) {        
-        if (path.endsWith('/')) {
-            path.chop(1);
-        }
-        parent->setToolTip(0, path);
-        parent->setData(0, Qt::UserRole, path);
+    if (pathTrail.isEmpty())
+        return;
+
+    const QString parentPath = parent->data(0, Qt::UserRole).toString();
+    const QString folderName = pathTrail.first();
+    QString folderPath;
+    if (parentPath == QLatin1String("/")) {
+        folderPath = folderName;
     } else {
-        QTreeWidgetItem *item = findFirstChild(parent, pathTrail.first());
-        if (!item) {
-            item = new QTreeWidgetItem(parent);
-            item->setIcon(0, folderIcon);
-            item->setText(0, pathTrail.first());
-            item->setData(0, Qt::UserRole, pathTrail.first());
-            item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
-        }
+        folderPath = parentPath + "/" + folderName;
+    }
+    QTreeWidgetItem *item = findFirstChild(parent, folderName);
+    if (!item) {
+        item = new QTreeWidgetItem(parent);
+        QFileIconProvider prov;
+        QIcon folderIcon = prov.icon(QFileIconProvider::Folder);
+        item->setIcon(0, folderIcon);
+        item->setText(0, folderName);
+        item->setData(0, Qt::UserRole, folderPath);
+        item->setToolTip(0, folderPath);
+        item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
+    }
+
+    pathTrail.removeFirst();
+    recursiveInsert(item, pathTrail, path);
+}
 
-        pathTrail.removeFirst();
-        recursiveInsert(item, pathTrail, path);
+bool FolderWizardRemotePath::selectByPath(QString path)
+{
+    if (path.startsWith(QLatin1Char('/'))) {
+        path = path.mid(1);
+    }
+    if (path.endsWith(QLatin1Char('/'))) {
+        path.chop(1);
     }
+
+    QTreeWidgetItem *it = _ui.folderTreeWidget->topLevelItem(0);
+    if (!path.isEmpty()) {
+        const QStringList pathTrail = path.split(QLatin1Char('/'));
+        foreach (const QString& path, pathTrail) {
+            if (!it) {
+                return false;
+            }
+            it = findFirstChild(it, path);
+        }
+    }
+    if (!it) {
+        return false;
+    }
+
+    _ui.folderTreeWidget->setCurrentItem(it);
+    return true;
 }
 
 void FolderWizardRemotePath::slotUpdateDirectories(const QStringList &list)
@@ -367,6 +401,7 @@ void FolderWizardRemotePath::slotRefreshFolders()
             SLOT(slotUpdateDirectories(QStringList)));
     job->start();
     _ui.folderTreeWidget->clear();
+    _ui.folderEntry->clear();
 }
 
 void FolderWizardRemotePath::slotItemExpanded(QTreeWidgetItem *item)
@@ -379,6 +414,49 @@ void FolderWizardRemotePath::slotItemExpanded(QTreeWidgetItem *item)
     job->start();
 }
 
+void FolderWizardRemotePath::slotCurrentItemChanged(QTreeWidgetItem *item)
+{
+    if (item) {
+        QString dir = item->data(0, Qt::UserRole).toString();
+        if (!dir.startsWith(QLatin1Char('/'))) {
+            dir.prepend(QLatin1Char('/'));
+        }
+        _ui.folderEntry->setText(dir);
+    }
+
+    emit completeChanged();
+}
+
+void FolderWizardRemotePath::slotFolderEntryEdited(const QString& text)
+{
+    if (selectByPath(text)) {
+        _lscolTimer.stop();
+        return;
+    }
+
+    _ui.folderTreeWidget->setCurrentItem(0);
+    _lscolTimer.start(); // avoid sending a request on each keystroke
+}
+
+void FolderWizardRemotePath::slotLsColFolderEntry()
+{
+    QString path = _ui.folderEntry->text();
+    if (path.startsWith(QLatin1Char('/')))
+        path = path.mid(1);
+
+    LsColJob *job = new LsColJob(_account, path, this);
+    job->setProperties(QList<QByteArray>() << "resourcetype");
+    connect(job, SIGNAL(directoryListingSubfolders(QStringList)),
+            SLOT(slotTypedPathFound(QStringList)));
+    job->start();
+}
+
+void FolderWizardRemotePath::slotTypedPathFound(const QStringList& subpaths)
+{
+    slotUpdateDirectories(subpaths);
+    selectByPath(_ui.folderEntry->text());
+}
+
 FolderWizardRemotePath::~FolderWizardRemotePath()
 {
 }
diff --git a/src/gui/folderwizard.h b/src/gui/folderwizard.h
index 88b8640..06a3476 100644
--- a/src/gui/folderwizard.h
+++ b/src/gui/folderwizard.h
@@ -86,11 +86,17 @@ protected slots:
     void slotUpdateDirectories(const QStringList&);
     void slotRefreshFolders();
     void slotItemExpanded(QTreeWidgetItem*);
+    void slotCurrentItemChanged(QTreeWidgetItem*);
+    void slotFolderEntryEdited(const QString& text);
+    void slotLsColFolderEntry();
+    void slotTypedPathFound(const QStringList& subpaths);
 private:
     void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path);
+    bool selectByPath(QString path);
     Ui_FolderWizardTargetPage _ui;
     bool _warnWasVisible;
     AccountPtr _account;
+    QTimer _lscolTimer;
 };
 
 
diff --git a/src/gui/folderwizardtargetpage.ui b/src/gui/folderwizardtargetpage.ui
index 0f242e1..97850ee 100644
--- a/src/gui/folderwizardtargetpage.ui
+++ b/src/gui/folderwizardtargetpage.ui
@@ -14,7 +14,10 @@
    <string>Form</string>
   </property>
   <layout class="QGridLayout" name="gridLayout_6">
-   <item row="3" column="0">
+   <item row="1" column="0">
+    <widget class="QLineEdit" name="folderEntry"/>
+   </item>
+   <item row="2" column="0">
     <widget class="QFrame" name="warnFrame">
      <property name="palette">
       <palette>
@@ -179,7 +182,7 @@
      </layout>
     </widget>
    </item>
-   <item row="4" column="0">
+   <item row="3" column="0">
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list