Welcome to mirror list, hosted at ThFree Co, Russian Federation.

folderman.h « mirall « src - github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6f51d94a7d7a7496873e7b628320b0fde959a970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
 * Copyright (C) by Klaas Freitag <freitag@owncloud.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 */


#ifndef FOLDERMAN_H
#define FOLDERMAN_H

#include <QObject>
#include <QQueue>
#include <QList>
#include <QPointer>

#include "mirall/folder.h"
#include "mirall/folderwatcher.h"
#include "mirall/syncfileitem.h"

class QSignalMapper;

namespace Mirall {

class Application;
class SyncResult;
class SocketApi;

class FolderMan : public QObject
{
    Q_OBJECT
public:
    static FolderMan* instance();

    int setupFolders();

    Mirall::Folder::Map map();

    /**
      * Add a folder definition to the config
      * Params:
      * QString alias
      * QString sourceFolder on local machine
      * QString targetPath on remote
      */
    void addFolderDefinition(const QString&, const QString&, const QString& ,
                             const QStringList &selectiveSyncBlacklist = QStringList() );

    /** Returns the folder which the file or directory stored in path is in */
    Folder* folderForPath(const QString& path);

    /** Returns the folder by alias or NULL if no folder with the alias exists. */
    Folder *folder( const QString& );

    /** Returns the last sync result by alias */
    SyncResult syncResult( const QString& );

    /** Creates a folder for a specific configuration, identified by alias. */
    Folder* setupFolderFromConfigFile(const QString & );

    /** Wipes all folder defintions. No way back! */
    void removeAllFolderDefinitions();

    /**
     * Ensures that a given directory does not contain a .csync_journal.
     *
     * @returns false if the journal could not be removed, true otherwise.
     */
    static bool ensureJournalGone(const QString &path);

    /** Creates a new and empty local directory. */
    bool startFromScratch( const QString& );

    QString statusToString(SyncResult, bool paused ) const;

    static SyncResult accountStatus( const QList<Folder*> &folders );

    void removeMonitorPath( const QString& alias, const QString& path );
    void addMonitorPath( const QString& alias, const QString& path );

    // Escaping of the alias which is used in QSettings AND the file
    // system, thus need to be escaped.
    static QString escapeAlias( const QString& );

signals:
    /**
      * signal to indicate a folder named by alias has changed its sync state.
      * Get the state via the Folder Map or the syncResult and syncState methods.
      *
      * Attention: The alias string may be zero. Do a general update of the state than.
      */
    void folderSyncStateChange( const QString & );

    void folderListLoaded(const Folder::Map &);

public slots:
    void slotRemoveFolder( const QString& );
    void slotSetFolderPaused(const QString&, bool paused);

    void slotFolderSyncStarted();
    void slotFolderSyncFinished( const SyncResult& );

    /**
     * Terminates the specified folder sync (or the current one).
     *
     * It does not switch the folder to paused state.
     */
    void terminateSyncProcess( const QString& alias = QString::null );

    /* unload and delete on folder object */
    void unloadFolder( const QString& alias );
    /* delete all folder objects */
    int unloadAllFolders();

    // if enabled is set to false, no new folders will start to sync.
    // the current one will finish.
    void setSyncEnabled( bool );

    void slotScheduleAllFolders();

    void setDirtyProxy(bool value = true);
    void setDirtyNetworkLimits();

    // slot to add a folder to the syncing queue
    void slotScheduleSync( const QString & );

private slots:

    // slot to take the next folder from queue and start syncing.
    void slotStartScheduledFolderSync();

private:
    // finds all folder configuration files
    // and create the folders
    QString getBackupName( QString fullPathName ) const;
    void registerFolderMonitor( Folder *folder );

    QString unescapeAlias( const QString& ) const;

    void removeFolder( const QString& );

    QSet<Folder*>  _disabledFolders;
    Folder::Map    _folderMap;
    QString        _folderConfigPath;
    QSignalMapper *_folderChangeSignalMapper;
    QSignalMapper *_folderWatcherSignalMapper;
    QString        _currentSyncFolder;
    bool           _syncEnabled;
    QMap<QString, FolderWatcher*> _folderWatchers;
    QPointer<SocketApi> _socketApi;

    /** The aliases of folders that shall be synced. */
    QQueue<QString> _scheduleQueue;

    static FolderMan *_instance;
    explicit FolderMan(QObject *parent = 0);
    ~FolderMan();
    friend class Mirall::Application;
};

} // namespace Mirall
#endif // FOLDERMAN_H