summaryrefslogtreecommitdiffstats
path: root/smb4k/core/smb4kpreviewer.h
blob: b9579b6ae28e63db22d8a9516e70d9df8e2ec01e (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
/***************************************************************************
    smb4kpreviewer  -  This class queries a remote share for a preview
                             -------------------
    begin                : Mo Mai 28 2007
    copyright            : (C) 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 SMB4KPREVIEWER_H
#define SMB4KPREVIEWER_H

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

// TQt includes
#include <tqobject.h>
#include <tqstring.h>
#include <tqptrqueue.h>

// KDE includes
#include <kprocess.h>

// forward declarations
class Smb4KPreviewItem;

/**
 * This class is part of the core of Smb4K. It queries a remote SMB share for
 * a preview and returns the result.
 *
 * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
 */

class Smb4KPreviewer : public TQObject
{
  TQ_OBJECT
  

  public:
    /**
     * The constructor
     *
     * @param parent            The parent object
     *
     * @param name              The name of this object
     */
    Smb4KPreviewer( TQObject *parent = 0, const char *name = 0 );

    /**
     * The destructor
     */
    ~Smb4KPreviewer();

    /**
     * Get a preview of the contents of @p item.
     *
     * In the case that @p item represents a 'homes' share, the user will be
     * prompted for the user name with which he wants to log in and the share
     * name of @p item will be set to the result.
     *
     * @param item              The item for which a preview should be
     *                          requested.
     *
     * @returns TRUE if einter the share name is not 'homes' or if it could
     * successfully be set to a user name. Otherwise it returns FALSE.
     */
    bool preview( Smb4KPreviewItem *item );

    /**
     * Using this function, you can find out whether the previewer is running
     * at the moment.
     *
     * @returns TRUE if the previewer is running or FALSE otherwise.
     */
    bool isRunning() { return m_working; }

    /**
     * Abort any action the previewer is performing at the moment and clear
     * the queue.
     */
    void abort();

  signals:
    /**
     * Emits the state the previewer is in
     *
     * @param state             The state
     */
    void state( int state );

    /**
     * Emits the preview after the process exited successfully. Get the contents
     * of the remote share by looping through the Smb4KPreviewItem::contents() list.
     *
     * @param item              The item for which the preview was received.
     */
    void result( Smb4KPreviewItem *item );

    /**
     * This signal is emitted if an error occurred.
     */
    void failed();

  protected:
    /**
     * Reimplemented from TQObject
     */
    void timerEvent( TQTimerEvent *e );

  protected slots:
    /**
     * This slot receives output from stdout.
     *
     * @param proc          The process
     *
     * @param buf           The buffer
     *
     * @param len           The length of the buffer
     */
    void slotReceivedStdout( TDEProcess *proc, char *buf, int len );

    /**
     * This slot receives output from stderr.
     *
     * @param proc          The process
     *
     * @param buf           The buffer
     *
     * @param len           The length of the buffer
     */
    void slotReceivedStderr( TDEProcess *proc, char *buf, int len );

    /**
     * Is called, when the TDEProcess exited.
     *
     * @param proc          The process that exited
     */
    void slotProcessExited( TDEProcess *proc );

  private:
    /**
     * The TDEProcess object
     */
    TDEProcess *m_proc;

    /**
     * The output buffer
     */
    TQString m_buffer;

    /**
     * This is the pointer to the Smb4KPreviewItem that's
     * processed.
     */
    Smb4KPreviewItem *m_item;

    /**
     * Indicates whether the previewer is running or not.
     */
    bool m_working;

    /**
     * This pointer queue holds the pointers to the Smb4KPreviewItem
     * objects that are to be processed.
     */
    TQPtrQueue<Smb4KPreviewItem> m_queue;

    /**
     * The timer id
     */
    int m_timer_id;
};

#endif