summaryrefslogtreecommitdiffstats
path: root/smb4k/browser/smb4knetworkbrowser_part.h
blob: d02350b1113ef575c2d9c1527a842dec8d78677b (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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/***************************************************************************
    smb4knetworkbrowser_part  -  This Part encapsulates the network
    browser of Smb4K.
                             -------------------
    begin                : Fr Jan 5 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 SMB4KNETWORKBROWSERPART_H
#define SMB4KNETWORKBROWSERPART_H

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

// KDE includes
#include <tdeactionclasses.h>
#include <tdeparts/part.h>
#include <tdeparts/factory.h>

// TQt includes
#include <tqptrlist.h>
#include <tqlistview.h>

// forward declarations
class Smb4KNetworkBrowser;
class Smb4KNetworkBrowserItem;
class Smb4KWorkgroupItem;
class Smb4KHostItem;
class Smb4KShareItem;

/**
 * This is one of the parts of Smb4K. It contains the network browser.
 *
 * @author Alexander Reinholdt <dustpuppy@users.berlios.de>
 */

class Smb4KNetworkBrowserPart : public KParts::Part
{
  TQ_OBJECT
  

  public:
    /**
     * Mode enumeration
     */
    enum Mode { Normal, KonqPlugin };

    /**
     * The constructor.
     *
     * @param parentWidget        The parent widget
     *
     * @param widgetName          The name the widget should have
     *
     * @param parent              The parent object
     *
     * @param name                The name this object should have
     *
     * @param mode                Determines in which mode the KPart should be started
     */
    Smb4KNetworkBrowserPart( TQWidget *parentWidget = 0,
                             const char *widgetName = 0,
                             TQObject *parent = 0,
                             const char *name = 0,
                             Mode mode = Normal );

    /**
     * The destructor.
     */
    virtual ~Smb4KNetworkBrowserPart();

  protected:
    /**
     * Reimplemented from KParts::Part.
     */
    void customEvent( TQCustomEvent *e );

  protected slots:
    /**
     * This slot is called if the user requests the context menu. It shows
     * the menu with the actions defined for the widget.
     *
     * @param item                The item for which the popup menu has been
     *                            requested or NULL.
     *
     * @param pos                 The position where user clicked.
     *
     * @param col                 The column where the user clicked.
     */
    void slotContextMenuRequested( TQListViewItem *item, const TQPoint &pos, int col );

    /**
     * Is called when the selection changed. This slot takes care of the
     * actions being enabled or disabled accordingly. All widget specific
     * stuff has to be done in the browser widget itself.
     *
     * @param item                The selection list view item.
     */
    void slotSelectionChanged( TQListViewItem *item );

    /**
     * Is called when the user pressed a mouse button somewhere in the widget.
     * In addition to Smb4KNetworkBrowserPart::slotSelectionChanged() this slot
     * takes care of the actions being enabled or disabled accordingly. All
     * widget specific stuff has to be done in the browser widget itself.
     *
     * @param item                The selection list view item.
     */
    void slotPressed( TQListViewItem *item );

    /**
     * This slot is called when an item of the browser's list view has been opened.
     * It is used to invoke the functions of the scanner that need to be run.
     *
     * @param item                The list view item that has been opened.
     */
    void slotItemExpanded( TQListViewItem *item );

    /**
     * This slot is called when an item of the browser's list view has been closed.
     *
     * @param item                The list view item that has been closed.
     */
    void slotItemCollapsed( TQListViewItem *item );

    /**
     * This slot is invoked when the user executed an item. It is used to mount
     * shares.
     *
     * @param item                The list view item that has been executed.
     */
    void slotItemExecuted( TQListViewItem *item );

    /**
     * This slot is called when the user moved the mouse over an @p item in the
     * network browser's list view and a tool tip is about to be shown. It will
     * initiate any actions that have to be taken by the scanner to complete
     * the information on the network items shown in the browser.
     *
     * @param item                The item for which the additional info should
     *                            be retrieved
     */
    void slotAboutToShowToolTip( Smb4KNetworkBrowserItem *item );

    /**
     * This slot receives the workgroups/domains found by the scanner. It takes
     * a list of workgroup items @p list and inserts the respective workgroups
     * into the browser window. Obsolete items will be deleted from the network
     * browser.
     *
     * @param list                A list of Smb4KWorkgroupItem objects
     */
    void slotWorkgroups( const TQValueList<Smb4KWorkgroupItem *> &list );

    /**
     * This slot receives the list of workgroup/domain members that were found
     * by the scanner. It takes this @p list and inserts it into the list view.
     * The parent of the items is the workgroup/domain item with the name
     * @p workgroup. Obsolete items will be deleted from the network browser.
     *
     * @param workgroup           The workgroup where the hosts belong
     *
     * @param list                A list of Smb4KHostItem objects
     */
    void slotWorkgroupMembers( const TQString &workgroup, const TQValueList<Smb4KHostItem *> &list );

    /**
     * This slot receives the list of shared resources a host provides. It takes
     * this @p list and inserts its items as children of @p host into the list
     * view. Obsolete items will be deleted from the network browser.
     *
     * @param host                The host where the shares belong
     *
     * @param list                The list of shares that belong to @p host
     */
    void slotShares( const TQString &host, const TQValueList<Smb4KShareItem *> &list );

    /**
     * This slot takes a Smb4KHostItem object @p item, reads the IP address entry
     * from it and updates the list view item representing the host with it.
     *
     * @param item                A Smb4KHostItem with an updated IP address.
     */
    void slotAddIPAddress( Smb4KHostItem *item );

    /**
     * This slot adds additional information to a browser item. It takes an
     * Smb4KHostItem @p item, searches the assossiated browser item and updates its
     * contents.
     *
     * @param item                A Smb4KHostItem with updated contents.
     */
    void slotAddInformation( Smb4KHostItem *item );

    /**
     * This slots is connected to the Smb4KScanner::hostAdded() signal and inserts
     * a single host in the list view. If the host is already present, nothing is
     * done.
     *
     * @param item                A Smb4KHostItem that is to be added to the
     *                            list view.
     */
    void slotInsertHost( Smb4KHostItem *item );

    /**
     * Rescan the network. This slot is connected to the 'Rescan' action.
     */
    void slotRescan();

    /**
     * Abort a network scan. This slot is connected to the 'Abort' action.
     */
    void slotAbort();

    /**
     * Manually mount a share. This slot is connected to the 'Mount Manually'
     * action and opens a mount dialog.
     */
    void slotMountManually();

    /**
     * Provide authentication for the current network object. This slot is
     * connected to the 'Authentication' action.
     */
    void slotAuthentication();

    /**
     * Provide custom options for a server or share. This slot is connected
     * to the 'Custom Options' action.
     */
    void slotCustomOptions();

    /**
     * Bookmark a remote share. This slot is connected to the 'Add Bookmark'
     * action.
     */
    void slotBookmark();

    /**
     * Preview a share. This slot is connected to the 'Preview' action.
     */
    void slotPreview();

    /**
     * Print a document on a remote printer. This slot is connected to the
     * 'Print File' action.
     */
    void slotPrint();

    /**
     * Mount a remote share. This slot is connected to the 'Mount' action.
     */
    void slotMount();

    /**
     * Unmount a share. This slot is only relevant in the Konqueror plugin
     * mode.
     */
    void slotUnmount();

    /**
     * This slot is invoked by the Smb4KMounter::updated() signal and changes
     * the text and icon of all shares that are already mounted.
     */
    void slotMarkMountedShares();

    /**
     * This slot is connected to the Smb4KCore::runStateChanged() signal and
     * is used to enable/disable actions.
     */
    void slotRunStateChanged();

  private:
    /**
     * Set up the actions
     */
    void setupActions();

    /**
     * Load settings for the widget or the actions.
     */
    void loadSettings();

    /**
     * The action menu
     */
    TDEActionMenu *m_menu;

    /**
     * The network browser widget
     */
    Smb4KNetworkBrowser *m_widget;

    /**
     * Determines with which mode the KPart will be started
     */
    Mode m_mode;
};


class TDEInstance;
class TDEAboutData;

class Smb4KNetworkBrowserPartFactory : public KParts::Factory
{
  TQ_OBJECT
  

  public:
    /**
     * The constructor
     */
    Smb4KNetworkBrowserPartFactory();

    /**
     * The destructor
     */
    virtual ~Smb4KNetworkBrowserPartFactory();

    /**
     * Reimplemented from KParts::Factory. This function is used to
     * create a part object.
     *
     * @param parentWidget            The parent of the part's widget.
     *
     * @param widgetName              The name of the part's widget.
     *
     * @param parent                  The parent of the part.
     *
     * @param name                    The name of the part.
     *
     * @param classname               The class name of the part. This should be "KParts::Part".
     *
     * @param args                    A list of additional arguments. They have to be provided as
     *                                name="value" pairs. At the moment this function understands
     *                                the following pairs:
     *                                konqplugin="true"|"false".
     */
    virtual KParts::Part *createPartObject( TQWidget *parentWidget, const char *widgetName,
                                            TQObject *parent, const char *name,
                                            const char *classname, const TQStringList &args = TQStringList() );

    /**
     * The instance
     */
    static TDEInstance *instance();

  private:
    /**
     * The factory's instance.
     */
    static TDEInstance *m_instance;

    /**
     * The factory's TDEAboutData object
     */
    static TDEAboutData *m_about;
};

#endif