mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
Don't allow to pick local directories or aliases twice.
This commit is contained in:
parent
ecc3a9edd5
commit
91bf272c9b
5 changed files with 102 additions and 52 deletions
|
@ -157,51 +157,53 @@ void Application::slotReparseConfiguration()
|
|||
|
||||
void Application::slotAddFolder()
|
||||
{
|
||||
if (_folderWizard->exec() == QDialog::Accepted) {
|
||||
qDebug() << "* Folder wizard completed";
|
||||
_folderWizard->setFolderMap( &_folderMap );
|
||||
|
||||
QString alias = _folderWizard->field("alias").toString();
|
||||
if (_folderWizard->exec() == QDialog::Accepted) {
|
||||
qDebug() << "* Folder wizard completed";
|
||||
|
||||
QSettings settings(folderConfigPath() + "/" + alias, QSettings::IniFormat);
|
||||
settings.setValue("folder/backend", "csync");
|
||||
settings.setValue("folder/path", _folderWizard->field("sourceFolder"));
|
||||
QString alias = _folderWizard->field("alias").toString();
|
||||
|
||||
if (_folderWizard->field("local?").toBool()) {
|
||||
settings.setValue("backend:csync/secondPath", _folderWizard->field("targetLocalFolder"));
|
||||
} else if (_folderWizard->field("remote?").toBool()) {
|
||||
settings.setValue("backend:csync/secondPath", _folderWizard->field("targetURLFolder"));
|
||||
bool onlyOnline = _folderWizard->field("onlyOnline?").toBool();
|
||||
settings.setValue("folder/onlyOnline", onlyOnline);
|
||||
QSettings settings(folderConfigPath() + "/" + alias, QSettings::IniFormat);
|
||||
settings.setValue("folder/backend", "csync");
|
||||
settings.setValue("folder/path", _folderWizard->field("sourceFolder"));
|
||||
|
||||
if (onlyOnline) {
|
||||
bool onlyThisLAN = _folderWizard->field("onlyThisLAN?").toBool();
|
||||
settings.setValue("folder/onlyThisLAN", onlyThisLAN);
|
||||
if (onlyThisLAN) {
|
||||
settings.setValue("folder/onlyOnline", true);
|
||||
}
|
||||
}
|
||||
} else if( _folderWizard->field("OC?").toBool()) {
|
||||
settings.setValue("folder/backend", "sitecopy");
|
||||
settings.setValue("backend:sitecopy/targetPath", _folderWizard->field("targetOCFolder"));
|
||||
settings.setValue("backend:sitecopy/alias", _folderWizard->field("OCSiteAlias"));
|
||||
if (_folderWizard->field("local?").toBool()) {
|
||||
settings.setValue("backend:csync/secondPath", _folderWizard->field("targetLocalFolder"));
|
||||
} else if (_folderWizard->field("remote?").toBool()) {
|
||||
settings.setValue("backend:csync/secondPath", _folderWizard->field("targetURLFolder"));
|
||||
bool onlyOnline = _folderWizard->field("onlyOnline?").toBool();
|
||||
settings.setValue("folder/onlyOnline", onlyOnline);
|
||||
|
||||
qDebug() << "Now writing sitecopy config " << _folderWizard->field("OCSiteAlias").toString(); ;
|
||||
SitecopyConfig scConfig;
|
||||
|
||||
scConfig.writeSiteConfig( alias,
|
||||
_folderWizard->field("sourceFolder").toString(), /* local path */
|
||||
_folderWizard->field("targetOCFolder").toString() );
|
||||
} else {
|
||||
qWarning() << "* Folder not local and note remote?";
|
||||
return;
|
||||
if (onlyOnline) {
|
||||
bool onlyThisLAN = _folderWizard->field("onlyThisLAN?").toBool();
|
||||
settings.setValue("folder/onlyThisLAN", onlyThisLAN);
|
||||
if (onlyThisLAN) {
|
||||
settings.setValue("folder/onlyOnline", true);
|
||||
}
|
||||
}
|
||||
} else if( _folderWizard->field("OC?").toBool()) {
|
||||
settings.setValue("folder/backend", "sitecopy");
|
||||
settings.setValue("backend:sitecopy/targetPath", _folderWizard->field("targetOCFolder"));
|
||||
settings.setValue("backend:sitecopy/alias", _folderWizard->field("OCSiteAlias"));
|
||||
|
||||
settings.sync();
|
||||
setupFolderFromConfigFile(alias);
|
||||
setupContextMenu();
|
||||
qDebug() << "Now writing sitecopy config " << _folderWizard->field("OCSiteAlias").toString(); ;
|
||||
SitecopyConfig scConfig;
|
||||
|
||||
scConfig.writeSiteConfig( alias,
|
||||
_folderWizard->field("sourceFolder").toString(), /* local path */
|
||||
_folderWizard->field("targetOCFolder").toString() );
|
||||
} else {
|
||||
qWarning() << "* Folder not local and note remote?";
|
||||
return;
|
||||
}
|
||||
else
|
||||
qDebug() << "* Folder wizard cancelled";
|
||||
|
||||
settings.sync();
|
||||
setupFolderFromConfigFile(alias);
|
||||
setupContextMenu();
|
||||
}
|
||||
else
|
||||
qDebug() << "* Folder wizard cancelled";
|
||||
}
|
||||
|
||||
void Application::setupKnownFolders()
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
#define APPLICATION_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QHash>
|
||||
#include <QSystemTrayIcon>
|
||||
|
||||
#include "mirall/syncresult.h"
|
||||
#include "mirall/folder.h"
|
||||
|
||||
class QAction;
|
||||
class QMenu;
|
||||
|
@ -28,7 +28,6 @@ class QNetworkConfigurationManager;
|
|||
|
||||
namespace Mirall {
|
||||
|
||||
class Folder;
|
||||
class FolderWatcher;
|
||||
class FolderWizard;
|
||||
class StatusDialog;
|
||||
|
@ -71,7 +70,7 @@ protected slots:
|
|||
|
||||
private:
|
||||
// configuration file -> folder
|
||||
QHash<QString, Folder *> _folderMap;
|
||||
Folder::Map _folderMap;
|
||||
QSystemTrayIcon *_tray;
|
||||
QAction *_actionQuit;
|
||||
QAction *_actionAddFolder;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QHash>
|
||||
|
||||
#include "mirall/syncresult.h"
|
||||
|
||||
|
@ -37,6 +38,8 @@ public:
|
|||
Folder(const QString &alias, const QString &path, QObject *parent = 0L);
|
||||
virtual ~Folder();
|
||||
|
||||
typedef QHash<QString, Folder*> Map;
|
||||
|
||||
/**
|
||||
* alias or nickname
|
||||
*/
|
||||
|
|
|
@ -32,6 +32,7 @@ namespace Mirall
|
|||
{
|
||||
|
||||
FolderWizardSourcePage::FolderWizardSourcePage()
|
||||
:_folderMap(0)
|
||||
{
|
||||
_ui.setupUi(this);
|
||||
registerField("sourceFolder*", _ui.localFolderLineEdit);
|
||||
|
@ -46,7 +47,42 @@ FolderWizardSourcePage::~FolderWizardSourcePage()
|
|||
|
||||
bool FolderWizardSourcePage::isComplete() const
|
||||
{
|
||||
return QFileInfo(_ui.localFolderLineEdit->text()).isDir();
|
||||
QFileInfo selFile( _ui.localFolderLineEdit->text() );
|
||||
|
||||
bool isOk = selFile.isDir();
|
||||
|
||||
// check if the local directory isn't used yet in another ownCloud sync
|
||||
Folder::Map *map = _folderMap;
|
||||
if( ! map ) return false;
|
||||
|
||||
if( isOk ) {
|
||||
Folder::Map::const_iterator i = map->begin();
|
||||
while( isOk && i != map->constEnd() ) {
|
||||
qDebug() << "Checking local path: " << i.key();
|
||||
if( QFileInfo( i.key() ) == selFile ) {
|
||||
isOk = false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// check if the alias is unique.
|
||||
QString alias = _ui.aliasLineEdit->text();
|
||||
if( alias.isEmpty() ) isOk = false;
|
||||
if( isOk ) {
|
||||
Folder::Map::const_iterator i = map->begin();
|
||||
while( isOk && i != map->constEnd() ) {
|
||||
Folder *f = static_cast<Folder*>(i.value());
|
||||
qDebug() << "Checking local alias: " << f->alias();
|
||||
if( f ) {
|
||||
if( f->alias() == alias ) {
|
||||
isOk = false;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return isOk;
|
||||
}
|
||||
|
||||
void FolderWizardSourcePage::on_localFolderChooseBtn_clicked()
|
||||
|
@ -64,6 +100,8 @@ void FolderWizardSourcePage::on_localFolderLineEdit_textChanged()
|
|||
emit completeChanged();
|
||||
}
|
||||
|
||||
|
||||
// =================================================================================
|
||||
FolderWizardTargetPage::FolderWizardTargetPage()
|
||||
{
|
||||
_ui.setupUi(this);
|
||||
|
@ -273,14 +311,23 @@ bool FolderWizardOwncloudPage::isComplete() const
|
|||
*/
|
||||
|
||||
FolderWizard::FolderWizard(QWidget *parent)
|
||||
: QWizard(parent)
|
||||
: QWizard(parent),
|
||||
_folderWizardSourcePage(0)
|
||||
{
|
||||
setPage(Page_Source, new FolderWizardSourcePage());
|
||||
_folderWizardSourcePage = new FolderWizardSourcePage();
|
||||
setPage(Page_Source, _folderWizardSourcePage );
|
||||
setPage(Page_Target, new FolderWizardTargetPage());
|
||||
// setPage(Page_Network, new FolderWizardNetworkPage());
|
||||
// setPage(Page_Owncloud, new FolderWizardOwncloudPage());
|
||||
}
|
||||
|
||||
void FolderWizard::setFolderMap( Folder::Map *fm)
|
||||
{
|
||||
if( _folderWizardSourcePage ) {
|
||||
_folderWizardSourcePage->setFolderMap( fm );
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace
|
||||
|
||||
#include "folderwizard.moc"
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include <QNetworkReply>
|
||||
#include <QTimer>
|
||||
|
||||
#include "folder.h"
|
||||
|
||||
#include "ui_folderwizardsourcepage.h"
|
||||
#include "ui_folderwizardtargetpage.h"
|
||||
#include "ui_folderwizardnetworkpage.h"
|
||||
|
@ -41,13 +43,14 @@ public:
|
|||
~FolderWizardSourcePage();
|
||||
|
||||
virtual bool isComplete() const;
|
||||
|
||||
void setFolderMap( Folder::Map *fm ) { _folderMap = fm; }
|
||||
protected slots:
|
||||
void on_localFolderChooseBtn_clicked();
|
||||
void on_localFolderLineEdit_textChanged();
|
||||
|
||||
private:
|
||||
Ui_FolderWizardSourcePage _ui;
|
||||
Folder::Map *_folderMap;
|
||||
};
|
||||
|
||||
|
||||
|
@ -123,14 +126,6 @@ private:
|
|||
};
|
||||
|
||||
/**
|
||||
* Available fields registered:
|
||||
*
|
||||
* alias
|
||||
* sourceFolder
|
||||
* local?
|
||||
* remote?
|
||||
* targetLocalFolder
|
||||
* targetURLFolder
|
||||
*
|
||||
*/
|
||||
class FolderWizard : public QWizard
|
||||
|
@ -146,7 +141,11 @@ public:
|
|||
};
|
||||
|
||||
FolderWizard(QWidget *parent = 0L);
|
||||
void setFolderMap( Folder::Map* );
|
||||
|
||||
private:
|
||||
|
||||
FolderWizardSourcePage *_folderWizardSourcePage;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue