1/*
2 * Copyright (C) by Duncan Mac-Vicar P. <duncan@kde.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 */
14
15#ifndef MIRALL_FOLDERWIZARD_H
16#define MIRALL_FOLDERWIZARD_H
17
18#include <QWizard>
19#include <QNetworkReply>
20#include <QTimer>
21
22#include "folder.h"
23#include "accountfwd.h"
24
25#include "ui_folderwizardsourcepage.h"
26#include "ui_folderwizardtargetpage.h"
27
28class QCheckBox;
29
30namespace OCC {
31
32class SelectiveSyncWidget;
33
34class ownCloudInfo;
35
36/**
37 * @brief The FormatWarningsWizardPage class
38 * @ingroup gui
39 */
40class FormatWarningsWizardPage : public QWizardPage
41{
42 Q_OBJECT
43protected:
44 QString formatWarnings(const QStringList &warnings) const;
45};
46
47/**
48 * @brief Page to ask for the local source folder
49 * @ingroup gui
50 */
51class FolderWizardLocalPath : public FormatWarningsWizardPage
52{
53 Q_OBJECT
54public:
55 explicit FolderWizardLocalPath(const AccountPtr &account);
56 ~FolderWizardLocalPath();
57
58 virtual bool isComplete() const Q_DECL_OVERRIDE;
59 void initializePage() Q_DECL_OVERRIDE;
60 void cleanupPage() Q_DECL_OVERRIDE;
61
62 void setFolderMap(const Folder::Map &fm) { _folderMap = fm; }
63protected slots:
64 void slotChooseLocalFolder();
65
66private:
67 Ui_FolderWizardSourcePage _ui;
68 Folder::Map _folderMap;
69 AccountPtr _account;
70};
71
72
73/**
74 * @brief page to ask for the target folder
75 * @ingroup gui
76 */
77
78class FolderWizardRemotePath : public FormatWarningsWizardPage
79{
80 Q_OBJECT
81public:
82 explicit FolderWizardRemotePath(const AccountPtr &account);
83 ~FolderWizardRemotePath();
84
85 virtual bool isComplete() const Q_DECL_OVERRIDE;
86
87 virtual void initializePage() Q_DECL_OVERRIDE;
88 virtual void cleanupPage() Q_DECL_OVERRIDE;
89
90protected slots:
91
92 void showWarn(const QString & = QString()) const;
93 void slotAddRemoteFolder();
94 void slotCreateRemoteFolder(const QString &);
95 void slotCreateRemoteFolderFinished(QNetworkReply::NetworkError error);
96 void slotHandleMkdirNetworkError(QNetworkReply *);
97 void slotHandleLsColNetworkError(QNetworkReply *);
98 void slotUpdateDirectories(const QStringList &);
99 void slotRefreshFolders();
100 void slotItemExpanded(QTreeWidgetItem *);
101 void slotCurrentItemChanged(QTreeWidgetItem *);
102 void slotFolderEntryEdited(const QString &text);
103 void slotLsColFolderEntry();
104 void slotTypedPathFound(const QStringList &subpaths);
105 void slotTypedPathError(QNetworkReply *reply);
106
107private:
108 LsColJob *runLsColJob(const QString &path);
109 void recursiveInsert(QTreeWidgetItem *parent, QStringList pathTrail, QString path);
110 bool selectByPath(QString path);
111 Ui_FolderWizardTargetPage _ui;
112 bool _warnWasVisible;
113 AccountPtr _account;
114 QTimer _lscolTimer;
115};
116
117/**
118 * @brief The FolderWizardSelectiveSync class
119 * @ingroup gui
120 */
121class FolderWizardSelectiveSync : public QWizardPage
122{
123 Q_OBJECT
124public:
125 explicit FolderWizardSelectiveSync(const AccountPtr &account);
126 ~FolderWizardSelectiveSync();
127
128 virtual bool validatePage() Q_DECL_OVERRIDE;
129
130 virtual void initializePage() Q_DECL_OVERRIDE;
131 virtual void cleanupPage() Q_DECL_OVERRIDE;
132
133private slots:
134 void virtualFilesCheckboxClicked();
135
136private:
137 SelectiveSyncWidget *_selectiveSync;
138 QCheckBox *_virtualFilesCheckBox = nullptr;
139};
140
141/**
142 * @brief The FolderWizard class
143 * @ingroup gui
144 */
145class FolderWizard : public QWizard
146{
147 Q_OBJECT
148public:
149 enum {
150 Page_Source,
151 Page_Target,
152 Page_SelectiveSync
153 };
154
155 explicit FolderWizard(AccountPtr account, QWidget *parent = 0);
156 ~FolderWizard();
157
158 bool eventFilter(QObject *watched, QEvent *event) override;
159 void resizeEvent(QResizeEvent *event) override;
160
161private:
162 FolderWizardLocalPath *_folderWizardSourcePage;
163 FolderWizardRemotePath *_folderWizardTargetPage;
164 FolderWizardSelectiveSync *_folderWizardSelectiveSyncPage;
165};
166
167
168} // namespace OCC
169
170#endif
171