Просмотр исходного кода

- polished the folder wizard
- bugfixes
- added user warnings if remote root dir is picked.

Klaas Freitag 14 лет назад
Родитель
Сommit
9c27edc6b6

+ 4 - 1
src/CMakeLists.txt

@@ -3,6 +3,8 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 include(${QT_USE_FILE})
 
+QT4_ADD_RESOURCES ( MIRALL_RC_SRC ../mirall.qrc)
+
 set(mirall_UI
 mirall/folderwizardsourcepage.ui
 mirall/folderwizardtargetpage.ui
@@ -37,6 +39,7 @@ mirall/owncloudwizard.cpp
 mirall/owncloudsetup.cpp
 mirall/owncloudinfo.cpp
 mirall/ownclouddircheck.cpp
+
 )
 if(CSYNC_FOUND)
   set(mirall_SRCS
@@ -51,7 +54,7 @@ qt4_automoc(${mirall_SRCS})
 add_library(mirall_static STATIC ${mirall_SRCS} ${mirall_UI_SRCS})
 target_link_libraries(mirall_static ${QT_LIBRARIES})
 
-add_executable(mirall main.cpp)
+add_executable(mirall main.cpp ${MIRALL_RC_SRC})
 target_link_libraries(mirall mirall_static)
 if(CSYNC_FOUND)
   target_link_libraries(mirall ${CSYNC_LIBRARY})

+ 6 - 7
src/mirall/application.cpp

@@ -320,21 +320,20 @@ void Application::setupFolderFromConfigFile(const QString &file) {
     QString backend = settings.value("folder/backend").toString();
     if (!backend.isEmpty()) {
         if( backend == "sitecopy") {
+          QString targetPath = settings.value("backend:sitecopy/targetPath").toString();
 
-            SiteCopyFolder *scf = new SiteCopyFolder( file,
+          SiteCopyFolder *scf = new SiteCopyFolder( file, /* file is the same as the alias */
                                                       path.toString(),
-                                                      QString(),
+                                                      targetPath,
                                                       this);
-            folder = scf;
+          folder = scf;
 
-        }
-        else if (backend == "unison") {
+        } else if (backend == "unison") {
             folder = new UnisonFolder(file,
                                       path.toString(),
                                       settings.value("backend:unison/secondPath").toString(),
                                       this);
-        }
-        else if (backend == "csync") {
+        } else if (backend == "csync") {
 #ifdef WITH_CSYNC
             folder = new CSyncFolder(file,
                                      path.toString(),

+ 50 - 14
src/mirall/folderwizard.cpp

@@ -56,7 +56,7 @@ bool FolderWizardSourcePage::isComplete() const
   bool isOk = selFile.isDir();
   if( !isOk ) {
     warnString = tr("No local directory selected!");
-    }
+  }
   // check if the local directory isn't used yet in another ownCloud sync
   Folder::Map *map = _folderMap;
   if( ! map ) return false;
@@ -65,10 +65,22 @@ bool FolderWizardSourcePage::isComplete() const
     Folder::Map::const_iterator i = map->begin();
     while( isOk && i != map->constEnd() ) {
       Folder *f = static_cast<Folder*>(i.value());
-      qDebug() << "Checking local path: " << f->path() << " <-> " << selFile.absoluteFilePath();
+      QString folderDir = QDir( f->path() ).absolutePath();
+
+      qDebug() << "Checking local path: " << folderDir << " <-> " << selFile.absoluteFilePath();
       if( QFileInfo( f->path() ) == selFile ) {
         isOk = false;
-        warnString.append( tr("The local path %1 is already a upload folder.<br/>Please pick another one!").arg(selFile.absoluteFilePath()) );
+        warnString.append( tr("The local path %1 is already an upload folder.<br/>Please pick another one!").arg(selFile.absoluteFilePath()) );
+      }
+      if( isOk && folderDir.startsWith( selFile.absoluteFilePath() )) {
+        qDebug() << "A already configured folder is child of the current selected";
+        warnString.append( tr("An already configured folder is contained in the current entry."));
+        isOk = false;
+      }
+      if( isOk && selFile.absoluteFilePath().startsWith( folderDir ) ) {
+        qDebug() << "An already configured folder is parent of the current selected";
+        warnString.append( tr("An already configured folder contains the currently entered directory."));
+        isOk = false;
       }
       i++;
     }
@@ -88,7 +100,7 @@ bool FolderWizardSourcePage::isComplete() const
     qDebug() << "Checking local alias: " << f->alias();
     if( f ) {
       if( f->alias() == alias ) {
-        warnString.append( tr("<br/>The alias %1 is already in use. Please change it to something different.").arg(alias) );
+        warnString.append( tr("<br/>The alias <i>%1</i> is already in use. Please change it to something different.").arg(alias) );
         isOk = false;
         goon = false;
       }
@@ -124,6 +136,8 @@ void FolderWizardSourcePage::on_localFolderLineEdit_textChanged()
 
 // =================================================================================
 FolderWizardTargetPage::FolderWizardTargetPage()
+: _dirChecked( false ),
+  _warnWasVisible(false)
 {
     _ui.setupUi(this);
     _ui.warnLabel->hide();
@@ -196,10 +210,15 @@ bool FolderWizardTargetPage::isComplete() const
         QUrl url(_ui.urlFolderLineEdit->text());
         return url.isValid() && (url.scheme() == "sftp" || url.scheme() == "smb");
     } else if( _ui.OCRadioBtn->isChecked()) {
+      /* owncloud selected */
       QString dir = _ui.OCFolderLineEdit->text();
       if( dir.isEmpty() ) {
+        showWarn( tr("Better do not use the remote root directory.<br/>If you do, you can <b>not</b> mirror another local folder."));
         return true;
       } else {
+        if( _dirChecked ) {
+          showWarn();
+        }
         return _dirChecked;
       }
     }
@@ -237,10 +256,14 @@ void FolderWizardTargetPage::slotNoOwnCloudFound()
   _ui.OCFolderLineEdit->setEnabled( false );
 }
 
-void FolderWizardTargetPage::showWarn( const QString& msg )
+void FolderWizardTargetPage::showWarn( const QString& msg ) const
 {
-  _ui.warnLabel->show();
-  _ui.warnLabel->setText( msg );
+  if( msg.isEmpty() ) {
+    _ui.warnLabel->hide();
+  } else {
+    _ui.warnLabel->show();
+    _ui.warnLabel->setText( msg );
+  }
 }
 
 void FolderWizardTargetPage::on_localFolderRadioBtn_toggled()
@@ -273,15 +296,25 @@ void FolderWizardTargetPage::on_urlFolderLineEdit_textChanged()
 
 void FolderWizardTargetPage::slotToggleItems()
 {
-    bool enabled = _ui.localFolderRadioBtn->isChecked();
-    _ui.localFolder2LineEdit->setEnabled(enabled);
-    _ui.localFolder2ChooseBtn->setEnabled(enabled);
 
-    enabled = _ui.urlFolderRadioBtn->isChecked();
-    _ui.urlFolderLineEdit->setEnabled(enabled);
+  bool enabled = _ui.localFolderRadioBtn->isChecked();
+  _ui.localFolder2LineEdit->setEnabled(enabled);
+  _ui.localFolder2ChooseBtn->setEnabled(enabled);
+  if( enabled ) {
+    _warnWasVisible = _ui.warnLabel->isVisible();
+    _ui.warnLabel->hide();
+  }
 
-    enabled = _ui.OCRadioBtn->isChecked();
-    _ui.OCFolderLineEdit->setEnabled(enabled);
+  enabled = _ui.urlFolderRadioBtn->isChecked();
+  _ui.urlFolderLineEdit->setEnabled(enabled);
+  if( enabled ) {
+    _warnWasVisible = _ui.warnLabel->isVisible();
+    _ui.warnLabel->hide();
+  }
+
+  enabled = _ui.OCRadioBtn->isChecked();
+  _ui.OCFolderLineEdit->setEnabled(enabled);
+  if( enabled ) _ui.warnLabel->setVisible( _warnWasVisible );
 }
 
 void FolderWizardTargetPage::on_localFolder2ChooseBtn_clicked()
@@ -294,6 +327,9 @@ void FolderWizardTargetPage::on_localFolder2ChooseBtn_clicked()
     }
 }
 
+
+// ====================================================================================
+
 FolderWizardNetworkPage::FolderWizardNetworkPage()
 {
     _ui.setupUi(this);

+ 2 - 1
src/mirall/folderwizard.h

@@ -85,12 +85,13 @@ protected slots:
     void slotFolderTextChanged( const QString& );
     void slotTimerFires();
     void slotDirCheckReply( const QString&, bool );
-    void showWarn( const QString& );
+    void showWarn( const QString& = QString() ) const;
 private:
     Ui_FolderWizardTargetPage _ui;
     QTimer *_timer;
     ownCloudDirCheck *_ownCloudDirCheck;
     bool _dirChecked;
+    bool _warnWasVisible;
 };
 
 class FolderWizardNetworkPage : public QWizardPage

+ 2 - 2
src/mirall/folderwizardsourcepage.ui

@@ -22,14 +22,14 @@
       </font>
      </property>
      <property name="text">
-      <string>Local Syncronisation Source</string>
+      <string>Express Upload Source</string>
      </property>
     </widget>
    </item>
    <item row="1" column="0">
     <widget class="QGroupBox" name="groupBox">
      <property name="title">
-      <string>Pick a folder on your computer to backup/synchronize:</string>
+      <string>Pick a folder on your computer to upload:</string>
      </property>
      <layout class="QGridLayout" name="gridLayout">
       <item row="0" column="0">

+ 213 - 109
src/mirall/folderwizardtargetpage.ui

@@ -6,14 +6,14 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>431</width>
-    <height>296</height>
+    <width>456</width>
+    <height>336</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>Form</string>
   </property>
-  <layout class="QGridLayout" name="gridLayout_2">
+  <layout class="QGridLayout" name="gridLayout_5">
    <item row="0" column="0">
     <layout class="QHBoxLayout" name="horizontalLayout_12">
      <item>
@@ -26,7 +26,7 @@
         </font>
        </property>
        <property name="text">
-        <string>Syncronisation Target</string>
+        <string>Express Upload Target</string>
        </property>
       </widget>
      </item>
@@ -50,139 +50,238 @@
      <property name="title">
       <string>Pick a place where the data should go to:</string>
      </property>
-     <layout class="QGridLayout" name="gridLayout">
-      <item row="0" column="0" colspan="2">
-       <widget class="QRadioButton" name="localFolderRadioBtn">
+     <property name="checkable">
+      <bool>false</bool>
+     </property>
+     <layout class="QGridLayout" name="gridLayout_4">
+      <item row="0" column="0">
+       <widget class="QRadioButton" name="OCRadioBtn">
         <property name="text">
-         <string>Another local folder</string>
+         <string/>
         </property>
         <property name="checked">
          <bool>true</bool>
         </property>
        </widget>
       </item>
-      <item row="1" column="0">
-       <spacer name="horizontalSpacer">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeType">
-         <enum>QSizePolicy::Fixed</enum>
+      <item row="0" column="1">
+       <widget class="QFrame" name="frame">
+        <property name="frameShape">
+         <enum>QFrame::StyledPanel</enum>
         </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>22</width>
-          <height>13</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item row="1" column="1">
-       <widget class="QLabel" name="label">
-        <property name="text">
-         <string>Folder name:</string>
+        <property name="frameShadow">
+         <enum>QFrame::Raised</enum>
         </property>
+        <layout class="QGridLayout" name="gridLayout">
+         <item row="0" column="1">
+          <widget class="QLabel" name="OCLabel">
+           <property name="font">
+            <font>
+             <weight>75</weight>
+             <bold>true</bold>
+            </font>
+           </property>
+           <property name="text">
+            <string>to your &amp;ownCloud</string>
+           </property>
+           <property name="openExternalLinks">
+            <bool>true</bool>
+           </property>
+           <property name="buddy">
+            <cstring>OCRadioBtn</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="1">
+          <widget class="QLabel" name="label_4">
+           <property name="text">
+            <string>Folder on ownCloud:</string>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="2">
+          <widget class="QLineEdit" name="OCFolderLineEdit">
+           <property name="placeholderText">
+            <string>root</string>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="0" rowspan="2">
+          <widget class="QLabel" name="label_5">
+           <property name="text">
+            <string/>
+           </property>
+           <property name="pixmap">
+            <pixmap resource="../../mirall.qrc">:/new/mirall/resources/ownCloud-48.png</pixmap>
+           </property>
+          </widget>
+         </item>
+        </layout>
        </widget>
       </item>
-      <item row="1" column="2">
-       <widget class="QLineEdit" name="localFolder2LineEdit">
-        <property name="placeholderText">
-         <string>/home/local2</string>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="3">
-       <widget class="QPushButton" name="localFolder2ChooseBtn">
+      <item row="1" column="0">
+       <widget class="QRadioButton" name="localFolderRadioBtn">
         <property name="text">
-         <string>C&amp;hoose..</string>
+         <string/>
         </property>
-       </widget>
-      </item>
-      <item row="2" column="0" colspan="2">
-       <widget class="QRadioButton" name="urlFolderRadioBtn">
-        <property name="text">
-         <string>Remote folder (URL)</string>
+        <property name="checked">
+         <bool>false</bool>
         </property>
        </widget>
       </item>
-      <item row="3" column="0">
-       <spacer name="horizontalSpacer_2">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeType">
-         <enum>QSizePolicy::Fixed</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>22</width>
-          <height>13</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item row="3" column="1">
-       <widget class="QLabel" name="label_2">
-        <property name="text">
-         <string>URL:</string>
+      <item row="1" column="1">
+       <widget class="QFrame" name="frame_2">
+        <property name="frameShape">
+         <enum>QFrame::StyledPanel</enum>
         </property>
-       </widget>
-      </item>
-      <item row="3" column="2">
-       <widget class="QLineEdit" name="urlFolderLineEdit">
-        <property name="placeholderText">
-         <string>scp://john@host.com//myfolder</string>
+        <property name="frameShadow">
+         <enum>QFrame::Raised</enum>
         </property>
+        <layout class="QGridLayout" name="gridLayout_2">
+         <item row="0" column="0" rowspan="2">
+          <widget class="QLabel" name="label_8">
+           <property name="minimumSize">
+            <size>
+             <width>48</width>
+             <height>0</height>
+            </size>
+           </property>
+           <property name="text">
+            <string/>
+           </property>
+           <property name="pixmap">
+            <pixmap resource="../../mirall.qrc">:/new/mirall/resources/folder-grey-32.png</pixmap>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="1">
+          <widget class="QLabel" name="LocalFolderLabel">
+           <property name="font">
+            <font>
+             <weight>75</weight>
+             <bold>true</bold>
+            </font>
+           </property>
+           <property name="text">
+            <string>to a &amp;local folder</string>
+           </property>
+           <property name="openExternalLinks">
+            <bool>true</bool>
+           </property>
+           <property name="buddy">
+            <cstring>localFolderRadioBtn</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="1">
+          <widget class="QLabel" name="label">
+           <property name="text">
+            <string>Folder name:</string>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="2">
+          <widget class="QLineEdit" name="localFolder2LineEdit">
+           <property name="placeholderText">
+            <string>/home/local</string>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="3">
+          <widget class="QPushButton" name="localFolder2ChooseBtn">
+           <property name="text">
+            <string>C&amp;hoose..</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
        </widget>
       </item>
-      <item row="4" column="0">
-       <widget class="QRadioButton" name="OCRadioBtn">
+      <item row="2" column="0">
+       <widget class="QRadioButton" name="urlFolderRadioBtn">
         <property name="text">
          <string/>
         </property>
        </widget>
       </item>
-      <item row="4" column="1">
-       <widget class="QLabel" name="OCLabel">
-        <property name="text">
-         <string>to your ownCloud</string>
-        </property>
-        <property name="openExternalLinks">
-         <bool>true</bool>
-        </property>
-       </widget>
-      </item>
-      <item row="5" column="0">
-       <spacer name="horizontalSpacer_3">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
+      <item row="2" column="1">
+       <widget class="QFrame" name="frame_3">
+        <property name="frameShape">
+         <enum>QFrame::StyledPanel</enum>
         </property>
-        <property name="sizeType">
-         <enum>QSizePolicy::Fixed</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>22</width>
-          <height>13</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item row="5" column="1">
-       <widget class="QLabel" name="label_4">
-        <property name="text">
-         <string>Folder on ownCloud:</string>
-        </property>
-       </widget>
-      </item>
-      <item row="5" column="2">
-       <widget class="QLineEdit" name="OCFolderLineEdit">
-        <property name="placeholderText">
-         <string>Sync-directory</string>
+        <property name="frameShadow">
+         <enum>QFrame::Raised</enum>
         </property>
+        <layout class="QGridLayout" name="gridLayout_3">
+         <item row="0" column="0" rowspan="2">
+          <widget class="QLabel" name="label_9">
+           <property name="minimumSize">
+            <size>
+             <width>48</width>
+             <height>0</height>
+            </size>
+           </property>
+           <property name="layoutDirection">
+            <enum>Qt::LeftToRight</enum>
+           </property>
+           <property name="text">
+            <string/>
+           </property>
+           <property name="pixmap">
+            <pixmap resource="../../mirall.qrc">:/new/mirall/resources/folder-remote-32.png</pixmap>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="1" colspan="2">
+          <widget class="QLabel" name="OCLabel_3">
+           <property name="font">
+            <font>
+             <weight>75</weight>
+             <bold>true</bold>
+            </font>
+           </property>
+           <property name="text">
+            <string>to a &amp;remote folder (URL)</string>
+           </property>
+           <property name="openExternalLinks">
+            <bool>true</bool>
+           </property>
+           <property name="buddy">
+            <cstring>urlFolderRadioBtn</cstring>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="1">
+          <widget class="QLabel" name="label_2">
+           <property name="text">
+            <string>URL:</string>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="2">
+          <widget class="QLineEdit" name="urlFolderLineEdit">
+           <property name="placeholderText">
+            <string>scp://john@host.com//myfolder</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
        </widget>
       </item>
      </layout>
+     <zorder>frame</zorder>
+     <zorder>frame_2</zorder>
+     <zorder>frame_3</zorder>
+     <zorder>OCRadioBtn</zorder>
+     <zorder>label_5</zorder>
+     <zorder>localFolderRadioBtn</zorder>
+     <zorder>urlFolderRadioBtn</zorder>
     </widget>
    </item>
    <item row="2" column="0">
@@ -255,7 +354,10 @@
       <bool>true</bool>
      </property>
      <property name="frameShape">
-      <enum>QFrame::StyledPanel</enum>
+      <enum>QFrame::NoFrame</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Plain</enum>
      </property>
      <property name="text">
       <string>TextLabel</string>
@@ -286,6 +388,8 @@
    </item>
   </layout>
  </widget>
- <resources/>
+ <resources>
+  <include location="../../mirall.qrc"/>
+ </resources>
  <connections/>
 </ui>

+ 3 - 1
src/mirall/owncloudsetup.cpp

@@ -316,7 +316,9 @@ void OwncloudSetup::startFetchFromOC( const QString& syncFolder )
 {
   _scf = new SiteCopyFolder( "ownCloud",
                              syncFolder,
-                             QString(),
+                             QString(), /* Remote folder missing, but thats no problem as the
+                                           fetching does not rely on the information. Its taken
+                                           from the sitecopy config in ~/.sitecopyrc */
                              this);
   connect( _scf, SIGNAL( syncFinished( const SyncResult& )),
            SLOT( slotFetchFinished( const SyncResult& )));

+ 4 - 3
src/mirall/sitecopyfolder.cpp

@@ -30,7 +30,8 @@ namespace Mirall {
                                     QObject *parent)
       : Folder(alias, path, parent),
         _SiteCopy(new QProcess(this)),
-        _syncCount(0)
+        _syncCount(0),
+        _remotePath( secondPath )
 {
     QObject::connect(_SiteCopy, SIGNAL(readyReadStandardOutput()),
                      SLOT(slotReadyReadStandardOutput()));
@@ -60,9 +61,9 @@ bool SiteCopyFolder::isBusy() const
     return (_SiteCopy->state() != QProcess::NotRunning);
 }
 
-QString SiteCopyFolder::siteCopyAlias() const
+QString SiteCopyFolder::remotePath() const
 {
-  return _siteCopyAlias;
+  return _remotePath;
 }
 
 void SiteCopyFolder::startSync(const QStringList &pathList)

+ 2 - 2
src/mirall/sitecopyfolder.h

@@ -43,8 +43,7 @@ public:
 
     virtual bool isBusy() const;
 
-
-    QString siteCopyAlias() const;
+    QString remotePath() const;
 
 signals:
     void statusString( const QString& );
@@ -68,6 +67,7 @@ private:
 
     QByteArray    _lastOutput;
     QString       _StatusString;
+    QString       _remotePath;
     SiteCopyState _NextStep;
     QString       _siteCopyAlias;
     QHash<QString, QStringList> _ChangesHash;