summaryrefslogtreecommitdiffstats
path: root/smb4k/core/smb4ksynchronizer.h
blob: ecc279f73bbd964589313706ab8072210841428b (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/***************************************************************************
    smb4ksynchronizer  -  This is the synchronizer of Smb4K.
                             -------------------
    begin                : Mo Jul 4 2005
    copyright            : (C) 2005-2007 by Alexander Reinholdt
    email                : dustpuppy@users.berlios.de
 ***************************************************************************/

/***************************************************************************
 *   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.                              *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,   *
 *   MA  02110-1301 USA                                                    *
 ***************************************************************************/

#ifndef SMB4KSYNCHRONIZER_H
#define SMB4KSYNCHRONIZER_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// KDE includes
#include <kprocess.h>
#include <kdialogbase.h>

// Qt includes
#include <qobject.h>
#include <qstring.h>

// forward declarations
class Smb4KShare;
class Smb4KSynchronizationInfo;


/**
 * This is a core class of Smb4K. It manages the synchronization of remote
 * shares with a local copy (and vice versa).
 *
 * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
 */


class Smb4KSynchronizer : public QObject
{
  Q_OBJECT

  public:
    /**
     * The constructor of the synchronizer.
     *
     * @param parent      The parent of this object
     *
     * @param name        The name of this object
     */
    Smb4KSynchronizer( QObject *parent = 0, const char *name = 0 );

    /**
     * The destructor.
     */
    ~Smb4KSynchronizer();

    /**
     * This function synchronizes a destination with the source.
     *
     * @param source      The source location
     *
     * @param destination The destination
     */
    void synchronize( const QString &source, const QString &destination );

    /**
     * This function reports if the synchronizer is running or not.
     *
     * @returns           TRUE if the synchronizer is running an FALSE otherwise.
     */
    bool isRunning() { return m_working; }

  public slots:
    /**
     * This function aborts the synchronization, i.e. the sync process is killed.
     */
    void abort();

  signals:
    /**
     * This signal emits the run state.
     *
     * @param state       The so-called run state. There are several defined
     *                    in the smb4kdefs.h header file.
     */
    void state( int state );

    /**
     * This signal is emitted just before the synchronization process is
     * started.
     */
    void start();

    /**
     * This signal is emitted when the synchronization process finished.
     */
    void finished();

    /**
     * Emit information about the progress of current synchronization process.
     * The information that's available may only be partial, i.e. that maybe
     * the file name or the rate or somthing else is missing. That's because
     * of the way the output of rsync is processed.
     *
     * @param info        Information about progress of the synchronization
     * process
     */
    void progress( const Smb4KSynchronizationInfo &info );

  protected slots:
    /**
     * Reimplemented from KProcess.
     *
     * @param proc        The process that exited
     */
    void slotProcessExited( KProcess *proc );

    /**
     * Reimplemented from KProcess.
     *
     * @param proc        The process from which output was received on stdout
     *
     * @param buf         The buffer that contains the output
     *
     * @param len         The length of the buffer
     */
    void slotReceivedStdout( KProcess *proc, char *buf, int len );

    /**
     * Reimplemented from KProcess.
     *
     * @param proc        The process from which output was received on stderr
     *
     * @param buf         The buffer that contains the output
     *
     * @param len         The length of the buffer
     */
    void slotReceivedStderr( KProcess *proc, char *buf, int len );

    /**
     * This slot is connected to KApplication::shutDown() signal.
     * It aborts the running KProcess if necessary.
     */
    void slotShutdown();

  private:
    /**
     * The process object for this class.
     */
    KProcess *m_proc;

    /**
     * This booian is TRUE if the synchronizer is working and FALSE otherwise.
     */
    bool m_working;

    /**
     * This function reads the options, that the user chose to use with rsync.
     *
     * @returns     an option string
     */
    const QString readRsyncOptions();

    /**
     * The buffer for the output.
     *
     * NOTE: The buffer is not to contain error messages, that are received
     * via slotReceivedStderr()!
     */
    QString m_buffer;

    /**
     * Total number of files to transfer
     */
    QString m_total_files;
};

#endif