~ubuntu-branches/ubuntu/utopic/smb4k/utopic-proposed

« back to all changes in this revision

Viewing changes to core/smb4kpreviewer_p.h

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mto: This revision was merged to the branch mainline in revision 28.
  • Revision ID: package-import@ubuntu.com-20120519185434-kpqpdrg5i47zm7tl
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    smb4kpreviewer_p  -  Private helper classes for Smb4KPreviewer class.
 
3
                             -------------------
 
4
    begin                : So Dez 21 2008
 
5
    copyright            : (C) 2008-2011 by Alexander Reinholdt
 
6
    email                : alexander.reinholdt@kdemail.net
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *   This program is free software; you can redistribute it and/or modify  *
 
11
 *   it under the terms of the GNU General Public License as published by  *
 
12
 *   the Free Software Foundation; either version 2 of the License, or     *
 
13
 *   (at your option) any later version.                                   *
 
14
 *                                                                         *
 
15
 *   This program is distributed in the hope that it will be useful, but   *
 
16
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
17
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 
18
 *   General Public License for more details.                              *
 
19
 *                                                                         *
 
20
 *   You should have received a copy of the GNU General Public License     *
 
21
 *   along with this program; if not, write to the                         *
 
22
 *   Free Software Foundation, 51 Franklin Street, Suite 500, Boston,      *
 
23
 *   MA 02110-1335, USA                                                    *
 
24
 ***************************************************************************/
 
25
 
 
26
#ifndef SMB4KPREVIEWER_P_H
 
27
#define SMB4KPREVIEWER_P_H
 
28
 
 
29
#ifdef HAVE_CONFIG_H
 
30
#include <config.h>
 
31
#endif
 
32
 
 
33
// Qt includes
 
34
#include <QStringList>
 
35
#include <QListIterator>
 
36
 
 
37
// KDE includes
 
38
#include <kjob.h>
 
39
#include <kdialog.h>
 
40
#include <klistwidget.h>
 
41
#include <khistorycombobox.h>
 
42
#include <kaction.h>
 
43
 
 
44
// application specific includes
 
45
#include <smb4kpreviewer.h>
 
46
#include <smb4kprocess.h>
 
47
 
 
48
// forward declarations
 
49
class Smb4KShare;
 
50
 
 
51
#define FileItem            100
 
52
#define HiddenFileItem      101
 
53
#define DirectoryItem       102
 
54
#define HiddenDirectoryItem 103
 
55
 
 
56
// Use this as follows:
 
57
// - The integer defines the type of the item (see above)
 
58
// - The key of the map is one of the following entries:
 
59
//   + name - The name of the file or directory (mandatory)
 
60
//   + date - The modification date of the file or directory (optional)
 
61
//   + size - The file size (optional)
 
62
typedef QPair< int,QMap<QString,QString> > Item;
 
63
 
 
64
class Smb4KPreviewJob : public KJob
 
65
{
 
66
  Q_OBJECT
 
67
 
 
68
  public:
 
69
    /**
 
70
     * Constructor
 
71
     */
 
72
    Smb4KPreviewJob( QObject *parent = 0 );
 
73
 
 
74
    /**
 
75
     * Destructor
 
76
     */
 
77
    ~Smb4KPreviewJob();
 
78
 
 
79
    /**
 
80
     * Returns TRUE if the job has been started and FALSE otherwise
 
81
     *
 
82
     * @returns TRUE if the job has been started
 
83
     */
 
84
    bool isStarted() { return m_started; }
 
85
 
 
86
    /**
 
87
     * Starts the job
 
88
     */
 
89
    void start();
 
90
 
 
91
    /**
 
92
     * This function sets up the preview job.
 
93
     *
 
94
     * You must run this function before start() is called.
 
95
     *
 
96
     * @param share       The share for which the preview should be acquired
 
97
     *
 
98
     * @param url         The location that should be listed
 
99
     *
 
100
     * @param parent      The parent widget
 
101
     */
 
102
    void setupPreview( Smb4KShare *share,
 
103
                       const QUrl &url,
 
104
                       QWidget *parent );
 
105
 
 
106
    /**
 
107
     * Returns the share object
 
108
     *
 
109
     * @returns the share object
 
110
     */
 
111
    Smb4KShare *share() { return m_share; }
 
112
 
 
113
    /**
 
114
     * Returns the parent widget
 
115
     *
 
116
     * @returns the parent widget
 
117
     */
 
118
    QWidget *parentWidget() { return m_parent_widget; }
 
119
 
 
120
    /**
 
121
     * Returns the url
 
122
     *
 
123
     * @returns the path
 
124
     */
 
125
    const QUrl &location() { return m_url; }
 
126
 
 
127
  signals:
 
128
    /**
 
129
     * Emitted when an authentication error happened.
 
130
     */
 
131
    void authError( Smb4KPreviewJob *job );
 
132
 
 
133
    /**
 
134
     * Emitted when the printing is about to begin.
 
135
     */
 
136
    void aboutToStart( Smb4KShare *share,
 
137
                       const QUrl &url );
 
138
 
 
139
    /**
 
140
     * Emitted after the printing finished.
 
141
     */
 
142
    void finished( Smb4KShare *share,
 
143
                   const QUrl &url );
 
144
 
 
145
    /**
 
146
     * Emits the contents of the directory just listed
 
147
     * 
 
148
     * @param url       The URL that should be previewed
 
149
     *
 
150
     * @param contents  The contents of the URL
 
151
     */
 
152
    void preview( const QUrl &url,
 
153
                  const QList<Item> &contents );
 
154
 
 
155
  protected:
 
156
    bool doKill();
 
157
 
 
158
  protected slots:
 
159
    void slotStartPreview();
 
160
    void slotReadStandardOutput();
 
161
    void slotReadStandardError();
 
162
    void slotProcessFinished( int exitCode, QProcess::ExitStatus status );
 
163
 
 
164
  private:
 
165
    bool m_started;
 
166
    Smb4KShare *m_share;
 
167
    QWidget *m_parent_widget;
 
168
    Smb4KProcess *m_proc;
 
169
    QUrl m_url;
 
170
};
 
171
 
 
172
 
 
173
class KDE_EXPORT Smb4KPreviewDialog : public KDialog
 
174
{
 
175
  Q_OBJECT
 
176
 
 
177
  public:
 
178
    /**
 
179
     * This is the constructor of the preview dialog.
 
180
     *
 
181
     * @param share         The Smb4KShare object.
 
182
     *
 
183
     * @param parent        The parent of this widget
 
184
     */
 
185
    Smb4KPreviewDialog( Smb4KShare *share,
 
186
                        QWidget *parent = 0 );
 
187
 
 
188
    /**
 
189
     * The destructor.
 
190
     */
 
191
    ~Smb4KPreviewDialog();
 
192
 
 
193
    /**
 
194
     * Returns the share for which the preview is to be generated
 
195
     *
 
196
     * @returns the share
 
197
     */
 
198
    Smb4KShare *share() { return m_share; }
 
199
 
 
200
  signals:
 
201
    /**
 
202
     * Emitted when the dialog closes.
 
203
     *
 
204
     * @param dialog        This dialog
 
205
     */
 
206
    void aboutToClose( Smb4KPreviewDialog *dialog );
 
207
 
 
208
    /**
 
209
     * This signal requests a preview for the given share and URL.
 
210
     * Use the share for identification and authentication and the
 
211
     * URL to determine the path.
 
212
     * 
 
213
     * @param share         The share
 
214
     *
 
215
     * @param url           The location
 
216
     *
 
217
     * @param parent        The parent widget that should be used
 
218
     */
 
219
    void requestPreview( Smb4KShare *share,
 
220
                         const QUrl &url,
 
221
                         QWidget *parent = 0 );
 
222
 
 
223
    /**
 
224
     * This signal is emitted when the user wants to abort the acquisition
 
225
     * of the preview for the share.
 
226
     *
 
227
     * @param share         The share
 
228
     */
 
229
    void abortPreview( Smb4KShare *share );
 
230
 
 
231
  protected slots:
 
232
    /**
 
233
     * This slot is called when an action has been triggered.
 
234
     *
 
235
     * @param action        The triggered action
 
236
     */
 
237
    void slotActionTriggered( QAction *action );
 
238
 
 
239
    /**
 
240
     * This slot can be called to request a preview. However, it only
 
241
     * can use the current URL.
 
242
     */
 
243
    void slotRequestPreview();
 
244
 
 
245
    /**
 
246
     * This slot takes the contents of a certain directory and displays
 
247
     * the list of files and directories.
 
248
     *
 
249
     * @param url           The URL that was queried
 
250
     * 
 
251
     * @param contents      The contents of a certain directory
 
252
     */
 
253
    void slotDisplayPreview( const QUrl &url,
 
254
                             const QList<Item> &contents );
 
255
    
 
256
    /**
 
257
     * This slot is called when the preview process is about to start.
 
258
     *
 
259
     * @param item          The Smb4KShare item
 
260
     *
 
261
     * @param url           The location for which the preview should be 
 
262
     *                      acquired
 
263
     */
 
264
    void slotAboutToStart( Smb4KShare *share,
 
265
                           const QUrl &url );
 
266
 
 
267
    /**
 
268
     * This slot is called when the preview process finished.
 
269
     *
 
270
     * @param item          The Smb4KShare item
 
271
     *
 
272
     * @param url           The location for which the preview should be
 
273
     *                      acquired
 
274
     */
 
275
    void slotFinished( Smb4KShare *share,
 
276
                       const QUrl &url );
 
277
 
 
278
    /**
 
279
     * Is called, if an item has been executed.
 
280
     *
 
281
     * @param item          The item that has been exected.
 
282
     */
 
283
    void slotItemExecuted( QListWidgetItem *item );
 
284
 
 
285
    /**
 
286
     * Is called, if an item in the combo box is activated.
 
287
     */
 
288
    void slotItemActivated( const QString &item );
 
289
 
 
290
    /**
 
291
     * This slot is called when the close button was clicked.
 
292
     */
 
293
    void slotCloseClicked();
 
294
 
 
295
    /**
 
296
     * This slot is called if the icon size was changed.
 
297
     *
 
298
     * @param group               The icon group
 
299
     */
 
300
    void slotIconSizeChanged( int group );
 
301
 
 
302
  private:
 
303
    /**
 
304
     * The share object
 
305
     */
 
306
    Smb4KShare *m_share;
 
307
 
 
308
    /**
 
309
     * The current URL
 
310
     */
 
311
    QUrl m_url;
 
312
    
 
313
    /**
 
314
     * Enumeration for the items in the list view.
 
315
     */
 
316
    enum ItemType{ File = 1000,
 
317
                   Directory = 1001 };
 
318
 
 
319
    /**
 
320
     * Sets up the file view.
 
321
     */
 
322
    void setupView();
 
323
 
 
324
    /**
 
325
     * The icon view.
 
326
     */
 
327
    KListWidget *m_view;
 
328
 
 
329
    /**
 
330
     * The combo box.
 
331
     */
 
332
    KHistoryComboBox *m_combo;
 
333
 
 
334
    /**
 
335
     * Reload action
 
336
     */
 
337
    KAction *m_reload;
 
338
 
 
339
    /**
 
340
     * Abort action
 
341
     */
 
342
    KAction *m_abort;
 
343
 
 
344
    /**
 
345
     * Back action
 
346
     */
 
347
    KAction *m_back;
 
348
 
 
349
    /**
 
350
     * Forward action
 
351
     */
 
352
    KAction *m_forward;
 
353
 
 
354
    /**
 
355
     * Up action
 
356
     */
 
357
    KAction *m_up;
 
358
 
 
359
    /**
 
360
     * The current history
 
361
     */
 
362
    QStringList m_history;
 
363
 
 
364
    /**
 
365
     * The current position in the history.
 
366
     */
 
367
    QStringListIterator m_iterator;
 
368
};
 
369
 
 
370
 
 
371
class Smb4KPreviewerPrivate
 
372
{
 
373
  public:
 
374
    Smb4KPreviewerPrivate();
 
375
    ~Smb4KPreviewerPrivate();
 
376
    Smb4KPreviewer instance;
 
377
};
 
378
 
 
379
#endif