working folder wizard, only actual creation of the folder pending

This commit is contained in:
Duncan Mac-Vicar P 2011-04-05 18:31:14 +02:00
parent 9055cdc60d
commit f1d6352f27
8 changed files with 502 additions and 268 deletions

View file

@ -4,7 +4,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include(${QT_USE_FILE})
set(mirall_UI
mirall/folderwizard.ui
mirall/folderwizardsourcepage.ui
mirall/folderwizardtargetpage.ui
)
qt4_wrap_ui(mirall_UI_SRCS ${mirall_UI})

View file

@ -11,6 +11,7 @@
#include "mirall/constants.h"
#include "mirall/application.h"
#include "mirall/folder.h"
#include "mirall/folderwizard.h"
#include "mirall/unisonfolder.h"
#include "mirall/inotify.h"
@ -24,6 +25,9 @@ Application::Application(int argc, char **argv) :
INotify::initialize();
setApplicationName("Mirall");
setQuitOnLastWindowClosed(false);
_folderWizard = new FolderWizard();
_folderConfigPath = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/folders";
@ -89,7 +93,9 @@ void Application::setupContextMenu()
void Application::slotAddFolder()
{
qDebug() << "add a folder here...";
if (_folderWizard->exec() == QDialog::Accepted) {
qDebug() << "* Folder wizard completed";
}
}
void Application::setupKnownFolders()

View file

@ -11,6 +11,7 @@ class QNetworkConfigurationManager;
namespace Mirall {
class Folder;
class FolderWizard;
class Application : public QApplication
{
@ -55,6 +56,7 @@ private:
// counter tracking number of folders doing a sync
int _folderSyncCount;
FolderWizard *_folderWizard;
};
} // namespace Mirall

View file

@ -1,13 +1,136 @@
#include <QDebug>
#include <QDesktopServices>
#include <QFileDialog>
#include <QFileInfo>
#include <QUrl>
#include <QValidator>
#include <QWizardPage>
#include "mirall/folderwizard.h"
namespace Mirall
{
FolderWizardSourcePage::FolderWizardSourcePage()
{
_ui.setupUi(this);
registerField("*sourceFolder", _ui.localFolderLineEdit);
}
FolderWizardSourcePage::~FolderWizardSourcePage()
{
}
bool FolderWizardSourcePage::isComplete() const
{
return QFileInfo(_ui.localFolderLineEdit->text()).isDir();
}
void FolderWizardSourcePage::on_localFolderChooseBtn_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select the source folder"),
QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
if (!dir.isEmpty()) {
_ui.localFolderLineEdit->setText(dir);
}
}
void FolderWizardSourcePage::on_localFolderLineEdit_textChanged()
{
emit completeChanged();
}
FolderWizardTargetPage::FolderWizardTargetPage()
{
_ui.setupUi(this);
registerField("targetLocalFolder", _ui.localFolder2LineEdit);
registerField("targetSSHFolder", _ui.sshFolderLineEdit);
}
FolderWizardTargetPage::~FolderWizardTargetPage()
{
}
bool FolderWizardTargetPage::isComplete() const
{
if (_ui.localFolderRadioBtn->isChecked()) {
return QFileInfo(_ui.localFolder2LineEdit->text()).isDir();
}
else if (_ui.sshFolderRadioBtn->isChecked()) {
QUrl url(_ui.sshFolderLineEdit->text());
return url.isValid() && url.scheme() == "ssh";
}
return false;
}
void FolderWizardTargetPage::initializePage()
{
slotToggleItems();
}
void FolderWizardTargetPage::on_localFolderRadioBtn_toggled()
{
slotToggleItems();
emit completeChanged();
}
void FolderWizardTargetPage::on_sshFolderRadioBtn_toggled()
{
slotToggleItems();
emit completeChanged();
}
void FolderWizardTargetPage::on_checkBoxOnlyOnline_toggled()
{
slotToggleItems();
}
void FolderWizardTargetPage::on_localFolder2LineEdit_textChanged()
{
emit completeChanged();
}
void FolderWizardTargetPage::on_sshFolderLineEdit_textChanged()
{
emit completeChanged();
}
void FolderWizardTargetPage::slotToggleItems()
{
bool enabled = _ui.localFolderRadioBtn->isChecked();
_ui.localFolder2LineEdit->setEnabled(enabled);
_ui.localFolder2ChooseBtn->setEnabled(enabled);
enabled = _ui.sshFolderRadioBtn->isChecked();
_ui.sshFolderLineEdit->setEnabled(enabled);
_ui.checkBoxOnlyOnline->setEnabled(enabled);
_ui.checkBoxOnlyThisLAN->setEnabled(enabled);
_ui.checkBoxOnlyThisLAN->setEnabled(_ui.checkBoxOnlyOnline->isEnabled() &&
_ui.checkBoxOnlyOnline->isChecked());
}
void FolderWizardTargetPage::on_localFolder2ChooseBtn_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this,
tr("Select the target folder"),
QDesktopServices::storageLocation(QDesktopServices::HomeLocation));
if (!dir.isEmpty()) {
_ui.localFolder2LineEdit->setText(dir);
}
}
/**
* Folder wizard itself
*/
FolderWizard::FolderWizard(QWidget *parent)
: QWizard(parent)
{
_ui.setupUi(this);
setPage(Page_Source, new FolderWizardSourcePage());
setPage(Page_Target, new FolderWizardTargetPage());
}
}

View file

@ -2,18 +2,76 @@
#ifndef MIRALL_FOLDERWIZARD_H
#define MIRALL_FOLDERWIZARD_H
#include "ui_folderwizard.h"
#include <QWizard>
#include "ui_folderwizardsourcepage.h"
#include "ui_folderwizardtargetpage.h"
namespace Mirall {
/**
* page to ask for the local source folder
*/
class FolderWizardSourcePage : public QWizardPage
{
Q_OBJECT
public:
FolderWizardSourcePage();
~FolderWizardSourcePage();
virtual bool isComplete() const;
protected slots:
void on_localFolderChooseBtn_clicked();
void on_localFolderLineEdit_textChanged();
private:
Ui_FolderWizardSourcePage _ui;
};
/**
* page to ask for the target folder
*/
class FolderWizardTargetPage : public QWizardPage
{
Q_OBJECT
public:
FolderWizardTargetPage();
~FolderWizardTargetPage();
virtual bool isComplete() const;
virtual void initializePage();
protected slots:
void slotToggleItems();
void on_localFolder2ChooseBtn_clicked();
void on_localFolderRadioBtn_toggled();
void on_sshFolderRadioBtn_toggled();
void on_checkBoxOnlyOnline_toggled();
void on_localFolder2LineEdit_textChanged();
void on_sshFolderLineEdit_textChanged();
private:
Ui_FolderWizardTargetPage _ui;
};
class FolderWizard : public QWizard
{
Q_OBJECT
public:
FolderWizard(QWidget *parent);
private:
Ui_FolderWizard _ui;
enum {
Page_Source,
Page_Target
};
FolderWizard(QWidget *parent = 0L);
};

View file

@ -1,261 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FolderWizard</class>
<widget class="QWizard" name="FolderWizard">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>565</width>
<height>387</height>
</rect>
</property>
<property name="windowTitle">
<string>Folder Setup</string>
</property>
<widget class="QWizardPage" name="localFolderPage">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Which folder in your computer you want to backup/synchronize?</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="localFolderLineEdit">
<property name="placeholderText">
<string>/home/local1</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="localFolderChooseBtn">
<property name="text">
<string>&amp;Choose...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWizardPage" name="remoteFolderPage">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Sync with:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="localFolderRadioBtn">
<property name="text">
<string>Another local folder</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="localFolder2LineEdit">
<property name="placeholderText">
<string>/home/local2</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="localFolder2ChooseBtn">
<property name="text">
<string>C&amp;hoose..</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="sshFolderRadioBtn">
<property name="text">
<string>Remote folder (SSH)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="sshFolderLineEdit">
<property name="placeholderText">
<string>ssh://john@host.com//myfolder</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Sync only when the computer is connected to the network</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>38</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>Only when connected to this local network</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FolderWizardSourcePage</class>
<widget class="QWidget" name="FolderWizardSourcePage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="localFolderLineEdit">
<property name="placeholderText">
<string>/home/local1</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="localFolderChooseBtn">
<property name="text">
<string>&amp;Choose...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Which folder in your computer you want to backup/synchronize?</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>234</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,229 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FolderWizardTargetPage</class>
<widget class="QWidget" name="FolderWizardTargetPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Sync with:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_17">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="localFolderRadioBtn">
<property name="text">
<string>Another local folder</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="localFolder2LineEdit">
<property name="placeholderText">
<string>/home/local2</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="localFolder2ChooseBtn">
<property name="text">
<string>C&amp;hoose..</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="sshFolderRadioBtn">
<property name="text">
<string>Remote folder (SSH)</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<spacer name="horizontalSpacer_15">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="sshFolderLineEdit">
<property name="placeholderText">
<string>ssh://john@host.com//myfolder</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_16">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<spacer name="horizontalSpacer_13">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBoxOnlyOnline">
<property name="text">
<string>Sync only when the computer is connected to the network</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_14">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>38</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBoxOnlyThisLAN">
<property name="text">
<string>Only when connected to this local network</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_12">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>102</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>