~ubuntu-branches/ubuntu/vivid/smb4k/vivid

« back to all changes in this revision

Viewing changes to smb4k/sharesview/smb4ksharesview_part.cpp

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2012-05-19 18:54:34 UTC
  • mfrom: (1.1.20)
  • Revision ID: package-import@ubuntu.com-20120519185434-duffny2n87214n1n
Tags: 1.0.1-1
* New upstream release.
* Update debian/compat: bump to 9.
* Update debian/control:
  - bump debhelper to 9.
  - bump kdelibs5-dev build dependency to 4:4.4.0.
  - bump Standards-Version to 3.9.3 (no changes needed).
  - Replace smbfs dependency by cifs-utils. (Closes: #638162)
* Update debian/copyright:
  - update upstream URL.
  - update upstream e-mail.
* Update debian/smb4k.lintian-overrides file.
* Update debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
    smb4ksharesview_part  -  This Part includes the shares view of Smb4K.
3
3
                             -------------------
4
4
    begin                : Sa Jun 30 2007
5
 
    copyright            : (C) 2007-2008 by Alexander Reinholdt
6
 
    email                : dustpuppy@users.berlios.de
 
5
    copyright            : (C) 2007-2011 by Alexander Reinholdt
 
6
    email                : alexander.reinholdt@kdemail.net
7
7
 ***************************************************************************/
8
8
 
9
9
/***************************************************************************
40
40
#include <kurl.h>
41
41
#include <kio/copyjob.h>
42
42
#include <kjobuidelegate.h>
 
43
#include <kstandarddirs.h>
 
44
#include <kglobalsettings.h>
43
45
 
44
46
// application specific includes
45
47
#include <smb4ksharesview_part.h>
46
48
#include <smb4kshareslistviewitem.h>
47
49
#include <smb4ksharesiconviewitem.h>
48
 
#include <../dialogs/smb4ksynchronizationdialog.h>
 
50
#include <../tooltips/smb4ktooltip.h>
49
51
#include <core/smb4kshare.h>
50
52
#include <core/smb4kcore.h>
51
53
#include <core/smb4ksettings.h>
52
54
#include <core/smb4kglobal.h>
 
55
#include <core/smb4kmounter.h>
 
56
#include <core/smb4ksynchronizer.h>
 
57
#include <core/smb4kbookmarkhandler.h>
53
58
 
54
59
using namespace Smb4KGlobal;
55
60
 
56
 
typedef KParts::GenericFactory<Smb4KSharesViewPart> Smb4KSharesViewPartFactory;
57
 
K_EXPORT_COMPONENT_FACTORY( libsmb4ksharesview, Smb4KSharesViewPartFactory )
58
 
 
59
 
 
60
 
Smb4KSharesViewPart::Smb4KSharesViewPart( QWidget *parentWidget, QObject *parent, const QStringList &args )
61
 
: KParts::Part( parent ), m_mode( IconMode )
 
61
K_PLUGIN_FACTORY( Smb4KSharesViewPartFactory, registerPlugin<Smb4KSharesViewPart>(); )
 
62
K_EXPORT_PLUGIN( Smb4KSharesViewPartFactory( "Smb4KSharesViewPart" ) );
 
63
 
 
64
 
 
65
Smb4KSharesViewPart::Smb4KSharesViewPart( QWidget *parentWidget, QObject *parent, const QList<QVariant> &args )
 
66
: KParts::Part( parent ), m_mode( IconMode ), m_bookmark_shortcut( true ), m_silent( false )
62
67
{
63
68
  // Parse the arguments.
64
69
  for ( int i = 0; i < args.size(); ++i )
65
70
  {
66
 
    if ( args.at( i ).startsWith( "viewmode" ) )
 
71
    if ( args.at( i ).toString().startsWith( "viewmode" ) )
67
72
    {
68
 
      if ( QString::compare( args.at( i ).section( "=", 1, 1 ).trimmed(), "list" ) == 0 )
 
73
      if ( QString::compare( args.at( i ).toString().section( "=", 1, 1 ).trimmed(), "list" ) == 0 )
69
74
      {
70
75
        m_mode = ListMode;
71
76
      }
76
81
 
77
82
      continue;
78
83
    }
 
84
    else if ( args.at( i ).toString().startsWith( "bookmark_shortcut" ) )
 
85
    {
 
86
      if ( QString::compare( args.at( i ).toString().section( "=", 1, 1 ).trimmed(), "\"false\"" ) == 0 )
 
87
      {
 
88
        m_bookmark_shortcut = false;
 
89
      }
 
90
      else
 
91
      {
 
92
        // Do nothing
 
93
      }
 
94
 
 
95
      continue;
 
96
    }
 
97
    else if ( args.at( i ).toString().startsWith( "silent" ) )
 
98
    {
 
99
      if ( QString::compare( args.at( i ).toString().section( "=", 1, 1 ).trimmed(), "\"true\"" ) == 0 )
 
100
      {
 
101
        m_silent = true;
 
102
      }
 
103
      else
 
104
      {
 
105
        // Do nothing
 
106
      }
 
107
 
 
108
      continue;
 
109
    }
79
110
    else
80
111
    {
81
112
      continue;
87
118
 
88
119
  // Set the container widget and its layout.
89
120
  m_container = new QWidget( parentWidget );
 
121
  m_container->setFocusPolicy( Qt::WheelFocus );
90
122
 
91
123
  m_layout = new QGridLayout( m_container );
92
124
  m_layout->setMargin( 0 );
105
137
  // will not be shown.
106
138
  setupActions();
107
139
 
108
 
  // Import the shares:
109
 
  slotMountedShares();
110
 
 
111
140
  // Load settings:
112
141
  loadSettings();
113
142
 
114
143
  // Add some connections:
115
 
  connect( Smb4KCore::mounter(),      SIGNAL( updated() ),
116
 
           this,                      SLOT( slotMountedShares() ) );
117
 
 
118
 
  connect( Smb4KCore::synchronizer(), SIGNAL( state( int ) ),
119
 
           this,                      SLOT( slotSynchronizationState( int ) ) );
120
 
 
121
 
  connect( kapp,                      SIGNAL( aboutToQuit() ),
122
 
           this,                      SLOT( slotAboutToQuit() ) );
 
144
  connect( Smb4KMounter::self(), SIGNAL( mounted( Smb4KShare * ) ),
 
145
           this,                 SLOT( slotShareMounted( Smb4KShare * ) ) );
 
146
           
 
147
  connect( Smb4KMounter::self(), SIGNAL( unmounted( Smb4KShare * ) ),
 
148
           this,                 SLOT( slotShareUnmounted( Smb4KShare * ) ) );
 
149
           
 
150
  connect( Smb4KMounter::self(), SIGNAL( updated( Smb4KShare *) ),
 
151
           this,                 SLOT( slotShareUpdated( Smb4KShare * ) ) );
 
152
 
 
153
  connect( Smb4KMounter::self(), SIGNAL( aboutToStart( Smb4KShare *, int ) ),
 
154
           this,                 SLOT( slotMounterAboutToStart( Smb4KShare *, int ) ) );
 
155
 
 
156
  connect( Smb4KMounter::self(), SIGNAL( finished( Smb4KShare *, int ) ),
 
157
           this,                 SLOT( slotMounterFinished( Smb4KShare *, int ) ) );
 
158
 
 
159
  connect( kapp,                 SIGNAL( aboutToQuit() ),
 
160
           this,                 SLOT( slotAboutToQuit() ) );
 
161
           
 
162
  connect( KGlobalSettings::self(), SIGNAL( iconChanged( int ) ),
 
163
           this,                    SLOT( slotIconSizeChanged( int ) ) );
123
164
}
124
165
 
125
166
 
130
171
 
131
172
void Smb4KSharesViewPart::setupView()
132
173
{
133
 
  // First disconnect the signals, so that we do not
134
 
  // get multiple connections.
135
 
  if ( m_icon_view )
136
 
  {
137
 
    disconnect( m_icon_view, SIGNAL( customContextMenuRequested( const QPoint & ) ),
138
 
                this,        SLOT( slotContextMenuRequested( const QPoint & ) ) );
139
 
 
140
 
    disconnect( m_icon_view, SIGNAL( itemSelectionChanged() ),
141
 
                this,        SLOT( slotItemSelectionChanged() ) );
142
 
 
143
 
    disconnect( m_icon_view, SIGNAL( itemPressed( QListWidgetItem * ) ),
144
 
               this,        SLOT( slotItemPressed( QListWidgetItem * ) ) );
145
 
 
146
 
    disconnect( m_icon_view, SIGNAL( itemExecuted( QListWidgetItem * ) ),
147
 
                this,        SLOT( slotItemExecuted( QListWidgetItem * ) ) );
148
 
 
149
 
    disconnect( m_icon_view, SIGNAL( acceptedDropEvent( Smb4KSharesIconViewItem *, QDropEvent * ) ),
150
 
                this,        SLOT( slotIconViewDropEvent( Smb4KSharesIconViewItem *, QDropEvent * ) ) );
151
 
  }
152
 
  else
153
 
  {
154
 
    // Do nothing
155
 
  }
156
 
 
157
 
  if ( m_list_view )
158
 
  {
159
 
    disconnect( m_list_view, SIGNAL( customContextMenuRequested( const QPoint & ) ),
160
 
                this,        SLOT( slotContextMenuRequested( const QPoint & ) ) );
161
 
 
162
 
    disconnect( m_list_view, SIGNAL( itemSelectionChanged() ),
163
 
                this,        SLOT( slotItemSelectionChanged() ) );
164
 
 
165
 
    disconnect( m_list_view, SIGNAL( itemPressed( QTreeWidgetItem *, int ) ),
166
 
                this,        SLOT( slotItemPressed( QTreeWidgetItem *, int ) ) );
167
 
 
168
 
    disconnect( m_list_view, SIGNAL( itemExecuted( QTreeWidgetItem *, int ) ),
169
 
                this,        SLOT( slotItemExecuted( QTreeWidgetItem *, int ) ) );
170
 
 
171
 
    disconnect( m_list_view, SIGNAL( acceptedDropEvent( Smb4KSharesListViewItem *, QDropEvent * ) ),
172
 
                this,        SLOT( slotListViewDropEvent( Smb4KSharesListViewItem *, QDropEvent * ) ) );
173
 
  }
174
 
  else
175
 
  {
176
 
    // Do nothing
177
 
  }
178
 
 
179
174
  // Set the widget of this part:
180
175
  switch ( m_mode )
181
176
  {
183
178
    {
184
179
      if ( m_list_view )
185
180
      {
 
181
        disconnect( m_list_view, SIGNAL( customContextMenuRequested( const QPoint & ) ),
 
182
                    this,        SLOT( slotContextMenuRequested( const QPoint & ) ) );
 
183
 
 
184
        disconnect( m_list_view, SIGNAL( itemSelectionChanged() ),
 
185
                    this,        SLOT( slotItemSelectionChanged() ) );
 
186
 
 
187
        disconnect( m_list_view, SIGNAL( itemPressed( QTreeWidgetItem *, int ) ),
 
188
                    this,        SLOT( slotItemPressed( QTreeWidgetItem *, int ) ) );
 
189
 
 
190
        disconnect( m_list_view, SIGNAL( itemExecuted( QTreeWidgetItem *, int ) ),
 
191
                    this,        SLOT( slotItemExecuted( QTreeWidgetItem *, int ) ) );
 
192
 
 
193
        disconnect( m_list_view, SIGNAL( acceptedDropEvent( Smb4KSharesListViewItem *, QDropEvent * ) ),
 
194
                    this,        SLOT( slotListViewDropEvent( Smb4KSharesListViewItem *, QDropEvent * ) ) );
 
195
    
186
196
        delete m_list_view;
187
197
        m_list_view = NULL;
188
198
      }
194
204
      if ( !m_icon_view )
195
205
      {
196
206
        m_icon_view = new Smb4KSharesIconView( m_container );
197
 
 
198
207
        m_layout->addWidget( m_icon_view, 0, 0, 0 );
199
 
 
200
208
        m_icon_view->setVisible( true );
 
209
        m_container->setFocusProxy( m_icon_view );
 
210
        
 
211
        // Set the icon size
 
212
        int icon_size = KIconLoader::global()->currentSize( KIconLoader::Desktop );
 
213
        m_icon_view->setIconSize( QSize( icon_size, icon_size ) );
 
214
 
 
215
        connect( m_icon_view, SIGNAL( customContextMenuRequested( const QPoint & ) ),
 
216
                 this,        SLOT( slotContextMenuRequested( const QPoint & ) ) );
 
217
 
 
218
        connect( m_icon_view, SIGNAL( itemSelectionChanged() ),
 
219
                 this,        SLOT( slotItemSelectionChanged() ) );
 
220
 
 
221
        connect( m_icon_view, SIGNAL( itemPressed( QListWidgetItem * ) ),
 
222
                 this,        SLOT( slotItemPressed( QListWidgetItem * ) ) );
 
223
 
 
224
        connect( m_icon_view, SIGNAL( itemExecuted( QListWidgetItem * ) ),
 
225
                 this,        SLOT( slotItemExecuted( QListWidgetItem * ) ) );
 
226
 
 
227
        connect( m_icon_view, SIGNAL( acceptedDropEvent( Smb4KSharesIconViewItem *, QDropEvent * ) ),
 
228
                 this,        SLOT( slotIconViewDropEvent( Smb4KSharesIconViewItem *, QDropEvent * ) ) );
201
229
      }
202
230
      else
203
231
      {
204
232
        // Do nothing
205
233
      }
206
234
 
207
 
      connect( m_icon_view, SIGNAL( customContextMenuRequested( const QPoint & ) ),
208
 
               this,        SLOT( slotContextMenuRequested( const QPoint & ) ) );
209
 
 
210
 
      connect( m_icon_view, SIGNAL( itemSelectionChanged() ),
211
 
               this,        SLOT( slotItemSelectionChanged() ) );
212
 
 
213
 
      connect( m_icon_view, SIGNAL( itemPressed( QListWidgetItem * ) ),
214
 
               this,        SLOT( slotItemPressed( QListWidgetItem * ) ) );
215
 
 
216
 
      connect( m_icon_view, SIGNAL( itemExecuted( QListWidgetItem * ) ),
217
 
               this,        SLOT( slotItemExecuted( QListWidgetItem * ) ) );
218
 
 
219
 
      connect( m_icon_view, SIGNAL( acceptedDropEvent( Smb4KSharesIconViewItem *, QDropEvent * ) ),
220
 
               this,        SLOT( slotIconViewDropEvent( Smb4KSharesIconViewItem *, QDropEvent * ) ) );
221
 
 
222
235
      break;
223
236
    }
224
237
    case ListMode:
225
238
    {
226
239
      if ( m_icon_view )
227
240
      {
 
241
        disconnect( m_icon_view, SIGNAL( customContextMenuRequested( const QPoint & ) ),
 
242
                    this,        SLOT( slotContextMenuRequested( const QPoint & ) ) );
 
243
 
 
244
        disconnect( m_icon_view, SIGNAL( itemSelectionChanged() ),
 
245
                    this,        SLOT( slotItemSelectionChanged() ) );
 
246
 
 
247
        disconnect( m_icon_view, SIGNAL( itemPressed( QListWidgetItem * ) ),
 
248
                    this,        SLOT( slotItemPressed( QListWidgetItem * ) ) );
 
249
 
 
250
        disconnect( m_icon_view, SIGNAL( itemExecuted( QListWidgetItem * ) ),
 
251
                    this,        SLOT( slotItemExecuted( QListWidgetItem * ) ) );
 
252
 
 
253
        disconnect( m_icon_view, SIGNAL( acceptedDropEvent( Smb4KSharesIconViewItem *, QDropEvent * ) ),
 
254
                    this,        SLOT( slotIconViewDropEvent( Smb4KSharesIconViewItem *, QDropEvent * ) ) );
 
255
        
228
256
        delete m_icon_view;
229
257
        m_icon_view = NULL;
230
258
      }
236
264
      if ( !m_list_view )
237
265
      {
238
266
        m_list_view = new Smb4KSharesListView( m_container );
239
 
 
240
267
        m_layout->addWidget( m_list_view, 0, 0, 0 );
241
 
 
242
268
        m_list_view->setVisible( true );
 
269
        m_container->setFocusProxy( m_list_view );
 
270
        
 
271
        // Set the icon size
 
272
        int icon_size = KIconLoader::global()->currentSize( KIconLoader::Small );
 
273
        m_list_view->setIconSize( QSize( icon_size, icon_size ) );
 
274
 
 
275
        connect( m_list_view, SIGNAL( customContextMenuRequested( const QPoint & ) ),
 
276
                 this,        SLOT( slotContextMenuRequested( const QPoint & ) ) );
 
277
 
 
278
        connect( m_list_view, SIGNAL( itemSelectionChanged() ),
 
279
                 this,        SLOT( slotItemSelectionChanged() ) );
 
280
 
 
281
        connect( m_list_view, SIGNAL( itemPressed( QTreeWidgetItem *, int ) ),
 
282
                 this,        SLOT( slotItemPressed( QTreeWidgetItem *, int ) ) );
 
283
 
 
284
        connect( m_list_view, SIGNAL( itemExecuted( QTreeWidgetItem *, int ) ),
 
285
                 this,        SLOT( slotItemExecuted( QTreeWidgetItem *, int ) ) );
 
286
 
 
287
        connect( m_list_view, SIGNAL( acceptedDropEvent( Smb4KSharesListViewItem *, QDropEvent * ) ),
 
288
                 this,        SLOT( slotListViewDropEvent( Smb4KSharesListViewItem *, QDropEvent * ) ) );
243
289
      }
244
290
      else
245
291
      {
246
292
        // Do nothing
247
293
      }
248
294
 
249
 
      connect( m_list_view, SIGNAL( customContextMenuRequested( const QPoint & ) ),
250
 
               this,        SLOT( slotContextMenuRequested( const QPoint & ) ) );
251
 
 
252
 
      connect( m_list_view, SIGNAL( itemSelectionChanged() ),
253
 
               this,        SLOT( slotItemSelectionChanged() ) );
254
 
 
255
 
      connect( m_list_view, SIGNAL( itemPressed( QTreeWidgetItem *, int ) ),
256
 
               this,        SLOT( slotItemPressed( QTreeWidgetItem *, int ) ) );
257
 
 
258
 
      connect( m_list_view, SIGNAL( itemExecuted( QTreeWidgetItem *, int ) ),
259
 
               this,        SLOT( slotItemExecuted( QTreeWidgetItem *, int ) ) );
260
 
 
261
 
      connect( m_list_view, SIGNAL( acceptedDropEvent( Smb4KSharesListViewItem *, QDropEvent * ) ),
262
 
               this,        SLOT( slotListViewDropEvent( Smb4KSharesListViewItem *, QDropEvent * ) ) );
263
 
 
264
295
      break;
265
296
    }
266
297
    default:
278
309
  unmount_action->setShortcut( QKeySequence( Qt::CTRL+Qt::Key_U ) );
279
310
  connect( unmount_action, SIGNAL( triggered( bool ) ), this, SLOT( slotUnmountShare( bool ) ) );
280
311
 
281
 
#ifdef __linux__
282
 
  KAction *force_action       = new KAction( KIcon( "media-eject" ), i18n( "&Force Unmounting" ),
283
 
                                actionCollection() );
284
 
  force_action->setShortcut( QKeySequence( Qt::CTRL+Qt::Key_F ) );
285
 
  connect( force_action, SIGNAL( triggered( bool ) ), this, SLOT( slotForceUnmountShare( bool ) ) );
286
 
#endif
287
 
 
288
312
  KAction *unmount_all_action = new KAction( KIcon( "system-run" ), i18n( "U&nmount All" ),
289
313
                                actionCollection() );
290
314
  unmount_all_action->setShortcut( QKeySequence( Qt::CTRL+Qt::Key_N ) );
308
332
  filemanager_action->setShortcuts( shortcuts );
309
333
  connect( filemanager_action, SIGNAL( triggered( bool ) ), this, SLOT( slotFileManager( bool ) ) );
310
334
 
 
335
  KAction *bookmark_action = new KAction( KIcon( "bookmark-new" ), i18n( "Add &Bookmark" ),
 
336
                             actionCollection() );
 
337
  if ( m_bookmark_shortcut )
 
338
  {
 
339
    bookmark_action->setShortcut( QKeySequence( Qt::CTRL+Qt::Key_B ) );
 
340
  }
 
341
  else
 
342
  {
 
343
    // Do nothing
 
344
  }
 
345
 
 
346
  connect( bookmark_action, SIGNAL( triggered( bool ) ), this, SLOT( slotAddBookmark( bool ) ) );
 
347
 
311
348
  actionCollection()->addAction( "unmount_action", unmount_action );
312
 
#ifdef __linux__
313
 
  actionCollection()->addAction( "force_unmount_action", force_action );
314
 
#endif
315
349
  actionCollection()->addAction( "unmount_all_action", unmount_all_action );
 
350
  actionCollection()->addAction( "bookmark_action", bookmark_action );
316
351
  actionCollection()->addAction( "synchronize_action", synchronize_action );
317
352
  actionCollection()->addAction( "konsole_action", konsole_action );
318
353
  actionCollection()->addAction( "filemanager_action", filemanager_action );
319
354
 
320
355
  // Disable all actions for now:
321
356
  unmount_action->setEnabled( false );
322
 
#ifdef __linux__
323
 
  force_action->setEnabled( false );
324
 
#endif
325
357
  unmount_all_action->setEnabled( false );
 
358
  bookmark_action->setEnabled( false );
326
359
  synchronize_action->setEnabled( false );
327
360
  konsole_action->setEnabled( false );
328
361
  filemanager_action->setEnabled( false );
331
364
  m_menu = new KActionMenu( this );
332
365
  m_menu_title = m_menu->menu()->addTitle( KIcon( "folder-remote" ), i18n( "Shares" ) );
333
366
  m_menu->addAction( unmount_action );
334
 
#ifdef __linux__
335
 
  m_menu->addAction( force_action );
336
 
#endif
337
367
  m_menu->addAction( unmount_all_action );
338
368
  m_menu->addSeparator();
 
369
  m_menu->addAction( bookmark_action );
339
370
  m_menu->addAction( synchronize_action );
340
371
  m_menu->addSeparator();
341
372
  m_menu->addAction( konsole_action );
369
400
 
370
401
    m_list_view->setColumnHidden( Smb4KSharesListView::Owner, !Smb4KSettings::showOwner() );
371
402
#ifndef __FreeBSD__
372
 
    m_list_view->setColumnHidden( Smb4KSharesListView::Login, !Smb4KSettings::showLogin() );
 
403
    m_list_view->setColumnHidden( Smb4KSharesListView::Login, !Smb4KSettings::showLoginName() );
373
404
#endif
374
405
    m_list_view->setColumnHidden( Smb4KSharesListView::FileSystem, !Smb4KSettings::showFileSystem() );
375
406
    m_list_view->setColumnHidden( Smb4KSharesListView::Free, !Smb4KSettings::showFreeDiskSpace() );
419
450
    }
420
451
  }
421
452
 
422
 
#ifdef __linux__
423
 
  if ( Smb4KSettings::sharesIconView() )
424
 
  {
425
 
    Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->currentItem() );
426
 
 
427
 
    actionCollection()->action( "force_unmount_action" )->setEnabled( Smb4KSettings::useForceUnmount() &&
428
 
    (item && (!item->itemData()->share()->isForeign() || Smb4KSettings::unmountForeignShares())) );
429
 
  }
430
 
  else
431
 
  {
432
 
    Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( m_list_view->currentItem() );
433
 
 
434
 
    actionCollection()->action( "force_unmount_action" )->setEnabled( Smb4KSettings::useForceUnmount() &&
435
 
    (item && (!item->itemData()->share()->isForeign() || Smb4KSettings::unmountForeignShares())) );
436
 
  }
437
 
#endif
438
 
 
439
 
 
440
453
  // The rest of the settings will be applied on the fly.
441
454
}
442
455
 
482
495
  KAboutData *aboutData = new KAboutData( "smb4ksharesviewpart",
483
496
                          "smb4k",
484
497
                          ki18n( "Smb4KSharesViewPart" ),
485
 
                          "2.0",
 
498
                          "3.0",
486
499
                          ki18n( "The shares view KPart of Smb4K" ),
487
500
                          KAboutData::License_GPL_V2,
488
 
                          ki18n( "(c) 2007-2008, Alexander Reinholdt" ),
 
501
                          ki18n( "\u00A9 2007-2011, Alexander Reinholdt" ),
489
502
                          KLocalizedString(),
490
 
                          "http://smb4k.berlios.de",
491
 
                          "smb4k-bugs@lists.berlios.de" );
 
503
                          "http://smb4k.sourceforge.net",
 
504
                          "smb4k-bugs@lists.sourceforge.net" );
492
505
 
493
506
  return aboutData;
494
507
}
496
509
 
497
510
void Smb4KSharesViewPart::customEvent( QEvent *e )
498
511
{
499
 
  switch ( e->type() )
500
 
  {
501
 
    case EVENT_LOAD_SETTINGS:
502
 
    {
503
 
      // Before we reread the settings, let's save
504
 
      // widget specific things.
505
 
      saveSettings();
506
 
 
507
 
      // Load settings.
508
 
      loadSettings();
509
 
 
510
 
      // (Re-)load the list of shares.
511
 
      slotMountedShares();
512
 
 
513
 
      break;
514
 
    }
515
 
    case EVENT_SET_FOCUS:
516
 
    {
517
 
      switch ( m_mode )
518
 
      {
519
 
        case IconMode:
520
 
        {
521
 
          if ( m_icon_view->count() != 0 )
522
 
          {
523
 
            kDebug() << "Do we need to port the selection stuff?" << endl;
524
 
          }
525
 
          else
526
 
          {
527
 
            // Do nothing
528
 
          }
529
 
 
530
 
          m_icon_view->setFocus( Qt::OtherFocusReason );
531
 
 
532
 
          break;
533
 
        }
534
 
        case ListMode:
535
 
        {
536
 
          if ( m_list_view->topLevelItemCount() != 0 )
537
 
          {
538
 
            kDebug() << "Do we need to port the selection stuff?" << endl;
539
 
          }
540
 
          else
541
 
          {
542
 
            // Do nothing
543
 
          }
544
 
 
545
 
          m_list_view->setFocus( Qt::OtherFocusReason );
546
 
 
547
 
          break;
548
 
        }
549
 
        default:
550
 
        {
551
 
          break;
552
 
        }
553
 
      }
554
 
 
555
 
//       KListView *view = static_cast<KListView *>( m_widget );
556
 
//
557
 
//       if ( view->childCount() != 0 )
558
 
//       {
559
 
//         view->setSelected( !view->currentItem() ?
560
 
//                            view->firstChild() :
561
 
//                            view->currentItem(), true );
562
 
//       }
563
 
//
564
 
//       view->setFocus();
565
 
 
566
 
      break;
567
 
    }
568
 
    default:
569
 
    {
570
 
      break;
571
 
    }
 
512
  if ( e->type() == Smb4KEvent::LoadSettings )
 
513
  {
 
514
    // Before we reread the settings, let's save
 
515
    // widget specific things.
 
516
    saveSettings();
 
517
 
 
518
    // Load settings.
 
519
    loadSettings();
 
520
 
 
521
    // (Re-)load the list of shares.
 
522
    switch ( m_mode )
 
523
    {
 
524
      case IconMode:
 
525
      {
 
526
        while ( m_icon_view->count() != 0 )
 
527
        {
 
528
          delete m_icon_view->takeItem( 0 );
 
529
        }
 
530
          
 
531
        break;
 
532
      }
 
533
      case ListMode:
 
534
      {
 
535
        while ( m_list_view->topLevelItemCount() != 0 )
 
536
        {
 
537
          delete m_list_view->takeTopLevelItem( 0 );
 
538
        }
 
539
         
 
540
        break;
 
541
      }
 
542
      default:
 
543
      {
 
544
        break;
 
545
      }
 
546
    }
 
547
      
 
548
    for ( int i = 0; i < mountedSharesList().size(); ++i )
 
549
    {
 
550
      slotShareMounted( mountedSharesList().at( i ) );
 
551
    }
 
552
  }
 
553
  else if ( e->type() == Smb4KEvent::SetFocus )
 
554
  {
 
555
    switch ( m_mode )
 
556
    {
 
557
      case IconMode:
 
558
      {
 
559
        if ( m_icon_view->count() != 0 )
 
560
        {
 
561
          kDebug() << "Do we need to port the selection stuff?" << endl;
 
562
        }
 
563
        else
 
564
        {
 
565
          // Do nothing
 
566
        }
 
567
 
 
568
        m_icon_view->setFocus( Qt::OtherFocusReason );
 
569
        break;
 
570
      }
 
571
      case ListMode:
 
572
      {
 
573
        if ( m_list_view->topLevelItemCount() != 0 )
 
574
        {
 
575
          kDebug() << "Do we need to port the selection stuff?" << endl;
 
576
        }
 
577
        else
 
578
        {
 
579
          // Do nothing
 
580
        }
 
581
 
 
582
        m_list_view->setFocus( Qt::OtherFocusReason );
 
583
        break;
 
584
      }
 
585
      default:
 
586
      {
 
587
        break;
 
588
      }
 
589
    }
 
590
  }
 
591
  else if ( e->type() == Smb4KEvent::AddBookmark )
 
592
  {
 
593
    slotAddBookmark( false );
 
594
  }
 
595
  else
 
596
  {
 
597
    // Do nothing
572
598
  }
573
599
 
574
600
  KParts::Part::customEvent( e );
647
673
      if ( !items.isEmpty() )
648
674
      {
649
675
        Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( items.first() );
 
676
        bool sync_running = Smb4KSynchronizer::self()->isRunning( item->shareItem() );
650
677
 
651
 
        actionCollection()->action( "unmount_action" )->setEnabled( (!item->itemData()->share()->isForeign() ||
 
678
        actionCollection()->action( "unmount_action" )->setEnabled( (!item->shareItem()->isForeign() ||
652
679
                                                                    Smb4KSettings::unmountForeignShares()) );
653
 
#ifdef __linux__
654
 
        actionCollection()->action( "force_unmount_action" )->setEnabled( Smb4KSettings::useForceUnmount() &&
655
 
                                                                          (!item->itemData()->share()->isForeign() ||
656
 
                                                                          Smb4KSettings::unmountForeignShares()) );
657
 
#endif
658
 
        Smb4KShare *share = item->itemData()->share();
 
680
        actionCollection()->action( "bookmark_action" )->setEnabled( true );
659
681
 
660
 
        if ( !share->isInaccessible() )
 
682
        if ( !item->shareItem()->isInaccessible() )
661
683
        {
662
 
          actionCollection()->action( "synchronize_action" )->setEnabled( !Smb4KSettings::rsync().isEmpty() &&
663
 
                                                                          !Smb4KCore::synchronizer()->isRunning() );
664
 
          actionCollection()->action( "konsole_action" )->setEnabled( !Smb4KSettings::konsole().isEmpty() );
 
684
          actionCollection()->action( "synchronize_action" )->setEnabled( !KStandardDirs::findExe( "rsync" ).isEmpty() && !sync_running );
 
685
          actionCollection()->action( "konsole_action" )->setEnabled( !KGlobal::dirs()->findResource( "exe", "konsole" ).isEmpty() );
665
686
          actionCollection()->action( "filemanager_action" )->setEnabled( true );
666
687
        }
667
688
        else
674
695
      else
675
696
      {
676
697
        actionCollection()->action( "unmount_action" )->setEnabled( false );
677
 
#ifdef __linux__
678
 
        actionCollection()->action( "force_unmount_action" )->setEnabled( false );
679
 
#endif
 
698
        actionCollection()->action( "bookmark_action" )->setEnabled( false );
680
699
        actionCollection()->action( "synchronize_action" )->setEnabled( false );
681
700
        actionCollection()->action( "konsole_action" )->setEnabled( false );
682
701
        actionCollection()->action( "filemanager_action" )->setEnabled( false );
692
711
      if ( !items.isEmpty() )
693
712
      {
694
713
        Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( items.first() );
 
714
        bool sync_running = Smb4KSynchronizer::self()->isRunning( item->shareItem() );
695
715
 
696
 
        actionCollection()->action( "unmount_action" )->setEnabled( (!item->itemData()->share()->isForeign() ||
 
716
        actionCollection()->action( "unmount_action" )->setEnabled( (!item->shareItem()->isForeign() ||
697
717
                                                                    Smb4KSettings::unmountForeignShares()) );
698
 
    #ifdef __linux__
699
 
        actionCollection()->action( "force_unmount_action" )->setEnabled( Smb4KSettings::useForceUnmount() &&
700
 
                                                                          (!item->itemData()->share()->isForeign() ||
701
 
                                                                          Smb4KSettings::unmountForeignShares()) );
702
 
    #endif
703
 
        Smb4KShare *share = item->itemData()->share();
 
718
        actionCollection()->action( "bookmark_action" )->setEnabled( true );
704
719
 
705
 
        if ( !share->isInaccessible() )
 
720
        if ( !item->shareItem()->isInaccessible() )
706
721
        {
707
 
          actionCollection()->action( "synchronize_action" )->setEnabled( !Smb4KSettings::rsync().isEmpty() &&
708
 
                                                                          !Smb4KCore::synchronizer()->isRunning() );
709
 
          actionCollection()->action( "konsole_action" )->setEnabled( !Smb4KSettings::konsole().isEmpty() );
 
722
          actionCollection()->action( "synchronize_action" )->setEnabled( !KStandardDirs::findExe( "rsync" ).isEmpty() && !sync_running );
 
723
          actionCollection()->action( "konsole_action" )->setEnabled( !KGlobal::dirs()->findResource( "exe", "konsole" ).isEmpty() );
710
724
          actionCollection()->action( "filemanager_action" )->setEnabled( true );
711
725
        }
712
726
        else
719
733
      else
720
734
      {
721
735
        actionCollection()->action( "unmount_action" )->setEnabled( false );
722
 
#ifdef __linux__
723
 
        actionCollection()->action( "force_unmount_action" )->setEnabled( false );
724
 
#endif
 
736
        actionCollection()->action( "bookmark_action" )->setEnabled( false );
725
737
        actionCollection()->action( "synchronize_action" )->setEnabled( false );
726
738
        actionCollection()->action( "konsole_action" )->setEnabled( false );
727
739
        actionCollection()->action( "filemanager_action" )->setEnabled( false );
744
756
  if ( !shareItem && m_list_view->selectedItems().isEmpty() )
745
757
  {
746
758
    actionCollection()->action( "unmount_action" )->setEnabled( false );
747
 
#ifndef __linux__
748
 
    actionCollection()->action( "force_unmount_action" )->setEnabled( false );
749
 
#endif
 
759
    actionCollection()->action( "bookmark_action" )->setEnabled( false );
750
760
    actionCollection()->action( "synchronize_action" )->setEnabled( false );
751
761
    actionCollection()->action( "konsole_action" )->setEnabled( false );
752
762
    actionCollection()->action( "filemanager_action" )->setEnabled( false );
753
763
  }
754
764
  else
755
765
  {
756
 
    // Do nothing. This will be done elsewhere.
 
766
    if ( shareItem )
 
767
    {
 
768
      bool sync_running = Smb4KSynchronizer::self()->isRunning( shareItem->shareItem() );
 
769
 
 
770
      actionCollection()->action( "synchronize_action" )->setEnabled( !KStandardDirs::findExe( "rsync" ).isEmpty() &&
 
771
                                                                      !sync_running &&
 
772
                                                                      !shareItem->shareItem()->isInaccessible() );
 
773
    }
 
774
    else
 
775
    {
 
776
      // Do nothing
 
777
    }
 
778
 
 
779
    // The rest will be done elsewhere.
757
780
  }
758
781
}
759
782
 
765
788
  if ( !shareItem && m_icon_view->selectedItems().isEmpty() )
766
789
  {
767
790
    actionCollection()->action( "unmount_action" )->setEnabled( false );
768
 
#ifndef __linux__
769
 
    actionCollection()->action( "force_unmount_action" )->setEnabled( false );
770
 
#endif
 
791
    actionCollection()->action( "bookmark_action" )->setEnabled( false );
771
792
    actionCollection()->action( "synchronize_action" )->setEnabled( false );
772
793
    actionCollection()->action( "konsole_action" )->setEnabled( false );
773
794
    actionCollection()->action( "filemanager_action" )->setEnabled( false );
774
795
  }
775
796
  else
776
797
  {
777
 
    // Do nothing. This will be done elsewhere.
 
798
    if ( shareItem )
 
799
    {
 
800
      bool sync_running = Smb4KSynchronizer::self()->isRunning( shareItem->shareItem() );
 
801
 
 
802
      actionCollection()->action( "synchronize_action" )->setEnabled( !KStandardDirs::findExe( "rsync" ).isEmpty() &&
 
803
                                                                      !sync_running &&
 
804
                                                                      !shareItem->shareItem()->isInaccessible() );
 
805
    }
 
806
    else
 
807
    {
 
808
      // Do nothing
 
809
    }
 
810
 
 
811
    // The rest will be done elsewhere.
778
812
  }
779
813
}
780
814
 
781
815
 
782
816
void Smb4KSharesViewPart::slotItemExecuted( QTreeWidgetItem *item, int /*column*/ )
783
817
{
784
 
  // This is a precaution.
785
 
  if ( item != m_list_view->currentItem() )
 
818
  if ( QApplication::keyboardModifiers() == Qt::NoModifier )
786
819
  {
787
 
    m_list_view->setCurrentItem( item );
 
820
    // This is a precaution.
 
821
    if ( item != m_list_view->currentItem() )
 
822
    {
 
823
      m_list_view->setCurrentItem( item );
 
824
    }
 
825
    else
 
826
    {
 
827
      // Do nothing
 
828
    }
 
829
 
 
830
    slotFileManager( false );
788
831
  }
789
832
  else
790
833
  {
791
834
    // Do nothing
792
835
  }
793
 
 
794
 
  slotFileManager( false );
795
836
}
796
837
 
797
838
 
798
839
void Smb4KSharesViewPart::slotItemExecuted( QListWidgetItem *item )
799
840
{
800
 
  // This is a precaution.
801
 
  if ( item != m_icon_view->currentItem() )
 
841
  // Do not execute the item when keyboard modifiers were pressed
 
842
  // or the mouse button is not the left one.
 
843
  if ( QApplication::keyboardModifiers() == Qt::NoModifier )
802
844
  {
803
 
    m_icon_view->setCurrentItem( item );
 
845
    // This is a precaution.
 
846
    if ( item != m_icon_view->currentItem() )
 
847
    {
 
848
      m_icon_view->setCurrentItem( item );
 
849
    }
 
850
    else
 
851
    {
 
852
      // Do nothing
 
853
    }
 
854
 
 
855
    slotFileManager( false );
804
856
  }
805
857
  else
806
858
  {
807
859
    // Do nothing
808
860
  }
809
 
 
810
 
  slotFileManager( false );
811
861
}
812
862
 
813
863
 
824
874
          KUrl::List urlList = KUrl::List::fromMimeData( e->mimeData() );
825
875
 
826
876
          KUrl dest;
827
 
          dest.setPath( item->itemData()->share()->path() );
 
877
          dest.setPath( item->shareItem()->path() );
828
878
 
829
879
          KIO::CopyJob *job = KIO::copy( urlList, dest, KIO::DefaultFlags );
830
880
 
845
895
          KUrl::List urlList = KUrl::List::fromMimeData( e->mimeData() );
846
896
 
847
897
          KUrl dest;
848
 
          dest.setPath( item->itemData()->share()->path() );
 
898
          dest.setPath( item->shareItem()->path() );
849
899
 
850
900
          KIO::CopyJob *job = KIO::move( urlList, dest, KIO::DefaultFlags );
851
901
 
885
935
          KUrl::List urlList = KUrl::List::fromMimeData( e->mimeData() );
886
936
 
887
937
          KUrl dest;
888
 
          dest.setPath( item->itemData()->share()->path() );
 
938
          dest.setPath( item->shareItem()->path() );
889
939
 
890
940
          KIO::CopyJob *job = KIO::copy( urlList, dest, KIO::DefaultFlags );
891
941
 
906
956
          KUrl::List urlList = KUrl::List::fromMimeData( e->mimeData() );
907
957
 
908
958
          KUrl dest;
909
 
          dest.setPath( item->itemData()->share()->path() );
 
959
          dest.setPath( item->shareItem()->path() );
910
960
 
911
961
          KIO::CopyJob *job = KIO::move( urlList, dest, KIO::DefaultFlags );
912
962
 
933
983
}
934
984
 
935
985
 
936
 
void Smb4KSharesViewPart::slotMountedShares()
 
986
void Smb4KSharesViewPart::slotShareMounted( Smb4KShare *share )
937
987
{
938
 
  // Get the list of shares:
939
 
  QList<Smb4KShare *> *list = mountedSharesList();
940
 
 
 
988
  Q_ASSERT( share );
 
989
  
941
990
  switch ( m_mode )
942
991
  {
943
992
    case IconMode:
944
993
    {
945
 
      if ( !list->isEmpty() )
946
 
      {
947
 
        // Remove obsolete items and unset the current item
948
 
        // if we remove it so that we won't get an unwanted
949
 
        // selected item.
950
 
        Smb4KSharesIconViewItem *item = NULL;
951
 
 
952
 
        for ( int i = 0; i < m_icon_view->count(); ++i )
953
 
        {
954
 
          item = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->item( i ) );
955
 
 
956
 
          Smb4KShare *share = findShareByPath( item->itemData()->share()->path() );
957
 
 
958
 
          if ( !share || (share->isForeign() && !Smb4KSettings::showAllShares()) )
959
 
          {
960
 
            if ( item == m_icon_view->currentItem() )
961
 
            {
962
 
              m_icon_view->setCurrentItem( NULL );
963
 
            }
964
 
            else
965
 
            {
966
 
              // Do nothing
967
 
            }
968
 
 
969
 
            delete item;
970
 
            item = NULL;
971
 
          }
972
 
          else
973
 
          {
974
 
            // Do nothing
975
 
          }
976
 
        }
977
 
 
978
 
        // Insert the new items and update the existing ones.
979
 
        Smb4KSharesIconViewItem *shareItem = NULL;
980
 
 
981
 
        for ( int i = 0; i < list->size(); ++i )
982
 
        {
983
 
          // Search for the item in the tree widget. Use the
984
 
          // path for this.
985
 
          Smb4KSharesIconViewItem *tmp = NULL;
986
 
 
987
 
          for ( int j = 0; j < m_icon_view->count(); ++j )
988
 
          {
989
 
            tmp = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->item( j ) );
990
 
 
991
 
            if ( QString::compare( tmp->itemData()->share()->path(), list->at( i )->path() ) == 0 ||
992
 
                 QString::compare( tmp->itemData()->share()->canonicalPath(), list->at( i )->canonicalPath() ) == 0 )
993
 
            {
994
 
              shareItem = tmp;
995
 
            }
996
 
            else
997
 
            {
998
 
              // Do nothing
999
 
            }
1000
 
          }
1001
 
 
1002
 
          if ( shareItem )
1003
 
          {
1004
 
            if ( !shareItem->sameShareObject( list->at( i ) ) )
1005
 
            {
1006
 
              shareItem->replaceShareObject( list->at( i ) );
1007
 
            }
1008
 
            else
1009
 
            {
1010
 
              // Do nothing
1011
 
            }
1012
 
 
1013
 
            m_icon_view->updateToolTip();
1014
 
          }
1015
 
          else
1016
 
          {
1017
 
            if ( !list->at( i )->isForeign() || Smb4KSettings::showAllShares() )
1018
 
            {
1019
 
              shareItem = new Smb4KSharesIconViewItem( list->at( i ), m_icon_view );
1020
 
              shareItem->setShowMountPoint( Smb4KSettings::showMountPoint() );
1021
 
            }
1022
 
            else
1023
 
            {
1024
 
              // Do nothing
1025
 
            }
1026
 
          }
1027
 
 
1028
 
          shareItem = NULL;
1029
 
        }
1030
 
      }
1031
 
      else
1032
 
      {
1033
 
        m_icon_view->clear();
1034
 
      }
1035
 
 
1036
 
      // Sort the items:
 
994
      (void) new Smb4KSharesIconViewItem( m_icon_view, share, Smb4KSettings::showMountPoint() );
1037
995
      m_icon_view->sortItems( Qt::AscendingOrder );
1038
 
 
 
996
      actionCollection()->action( "unmount_all_action" )->setEnabled(
 
997
        ((!onlyForeignMountedShares() || Smb4KSettings::unmountForeignShares()) && m_icon_view->count() != 0) );
1039
998
      break;
1040
999
    }
1041
1000
    case ListMode:
1042
1001
    {
1043
 
      if ( !list->isEmpty() )
1044
 
      {
1045
 
        // Remove obsolete items.
1046
 
        QTreeWidgetItemIterator it( m_list_view );
1047
 
        Smb4KSharesListViewItem *item = NULL;
1048
 
 
1049
 
        while ( *it )
1050
 
        {
1051
 
          item = static_cast<Smb4KSharesListViewItem *>( *it );
1052
 
 
1053
 
          Smb4KShare *share = findShareByPath( item->itemData()->share()->path() );
1054
 
 
1055
 
          if ( !share || (share->isForeign() && !Smb4KSettings::showAllShares()) )
1056
 
          {
1057
 
            if ( item == m_list_view->currentItem() )
1058
 
            {
1059
 
              m_list_view->setCurrentItem( NULL );
1060
 
            }
1061
 
            else
1062
 
            {
1063
 
              // Do nothing
1064
 
            }
1065
 
 
1066
 
            delete item;
1067
 
            item = NULL;
1068
 
          }
1069
 
          else
1070
 
          {
1071
 
            // Do nothing
1072
 
          }
1073
 
 
1074
 
          ++it;
1075
 
        }
1076
 
 
1077
 
        // Insert the new items and update the existing ones.
1078
 
        Smb4KSharesListViewItem *shareItem = NULL;
1079
 
 
1080
 
        for ( int i = 0; i < list->size(); ++i )
1081
 
        {
1082
 
          // Search for the item in the tree widget. Use the
1083
 
          // path for this.
1084
 
          it = QTreeWidgetItemIterator( m_list_view );
1085
 
          Smb4KSharesListViewItem *tmp = NULL;
1086
 
 
1087
 
          while ( *it )
1088
 
          {
1089
 
            tmp = static_cast<Smb4KSharesListViewItem *>( *it );
1090
 
 
1091
 
            if ( QString::compare( tmp->itemData()->share()->path(), list->at( i )->path() ) == 0 ||
1092
 
                 QString::compare( tmp->itemData()->share()->canonicalPath(), list->at( i )->canonicalPath() ) == 0 )
1093
 
            {
1094
 
              shareItem = tmp;
1095
 
            }
1096
 
            else
1097
 
            {
1098
 
              // Do nothing
1099
 
            }
1100
 
 
1101
 
            ++it;
1102
 
          }
1103
 
 
1104
 
          if ( shareItem )
1105
 
          {
1106
 
            if ( !shareItem->sameShareObject( list->at( i ) ) )
1107
 
            {
1108
 
              shareItem->replaceShareObject( list->at( i ) );
1109
 
            }
1110
 
            else
1111
 
            {
1112
 
              // Do nothing
1113
 
            }
1114
 
 
1115
 
            m_list_view->updateToolTip();
1116
 
          }
1117
 
          else
1118
 
          {
1119
 
            if ( !list->at( i )->isForeign() || Smb4KSettings::showAllShares() )
1120
 
            {
1121
 
              shareItem = new Smb4KSharesListViewItem( list->at( i ), m_list_view );
1122
 
              shareItem->setShowMountPoint( Smb4KSettings::showMountPoint() );
1123
 
            }
1124
 
            else
1125
 
            {
1126
 
              // Do nothing
1127
 
            }
1128
 
          }
1129
 
 
1130
 
          shareItem = NULL;
1131
 
        }
1132
 
      }
1133
 
      else
1134
 
      {
1135
 
        m_list_view->clear();
1136
 
      }
1137
 
 
1138
 
      // Sort the items:
 
1002
      (void) new Smb4KSharesListViewItem( m_list_view, share, Smb4KSettings::showMountPoint() );
1139
1003
      m_list_view->sortItems( Smb4KSharesListView::Item, Qt::AscendingOrder );
1140
 
 
1141
 
      break;
1142
 
    }
1143
 
    default:
1144
 
    {
1145
 
      break;
1146
 
    }
1147
 
  }
1148
 
 
1149
 
  // Enable the "Unmount All" action.
1150
 
  actionCollection()->action( "unmount_all_action" )->setEnabled( !list->isEmpty() );
 
1004
      actionCollection()->action( "unmount_all_action" )->setEnabled(
 
1005
        ((!onlyForeignMountedShares() || Smb4KSettings::unmountForeignShares()) && m_list_view->topLevelItemCount() != 0) );
 
1006
      break;
 
1007
    }
 
1008
    default:
 
1009
    {
 
1010
      break;
 
1011
    }
 
1012
  }
 
1013
}
 
1014
 
 
1015
 
 
1016
void Smb4KSharesViewPart::slotShareUnmounted( Smb4KShare *share )
 
1017
{
 
1018
  Q_ASSERT( share );
 
1019
  
 
1020
  switch ( m_mode )
 
1021
  {
 
1022
    case IconMode:
 
1023
    {
 
1024
      Smb4KSharesIconViewItem *item = NULL;
 
1025
      
 
1026
      for ( int i = 0; i < m_icon_view->count(); ++i )
 
1027
      {
 
1028
        item = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->item( i ) );
 
1029
        
 
1030
        if ( item && (QString::compare( item->shareItem()->path(), share->path() ) == 0 ||
 
1031
             QString::compare( item->shareItem()->canonicalPath(), share->canonicalPath() ) == 0) )
 
1032
        {
 
1033
          if ( item == m_icon_view->currentItem() )
 
1034
          {
 
1035
            m_icon_view->setCurrentItem( NULL );
 
1036
          }
 
1037
          else
 
1038
          {
 
1039
            // Do nothing
 
1040
          }
 
1041
          
 
1042
          delete m_icon_view->takeItem( i );
 
1043
          break;
 
1044
        }
 
1045
        else
 
1046
        {
 
1047
          continue;
 
1048
        }
 
1049
      }
 
1050
      
 
1051
      actionCollection()->action( "unmount_all_action" )->setEnabled(
 
1052
        ((!onlyForeignMountedShares() || Smb4KSettings::unmountForeignShares()) && m_icon_view->count() != 0) );
 
1053
      
 
1054
      break;
 
1055
    }
 
1056
    case ListMode:
 
1057
    {
 
1058
      Smb4KSharesListViewItem *item = NULL;
 
1059
      
 
1060
      for ( int i = 0; i < m_list_view->topLevelItemCount(); ++i )
 
1061
      {
 
1062
        item = static_cast<Smb4KSharesListViewItem *>( m_list_view->topLevelItem( i ) );
 
1063
        
 
1064
        if ( item && (QString::compare( item->shareItem()->path(), share->path() ) == 0 ||
 
1065
             QString::compare( item->shareItem()->canonicalPath(), share->canonicalPath() ) == 0) )
 
1066
        {
 
1067
          if ( item == m_list_view->currentItem() )
 
1068
          {
 
1069
            m_list_view->setCurrentItem( NULL );
 
1070
          }
 
1071
          else
 
1072
          {
 
1073
            // Do nothing
 
1074
          }
 
1075
          
 
1076
          delete m_list_view->takeTopLevelItem( i );
 
1077
          break;
 
1078
        }
 
1079
        else
 
1080
        {
 
1081
          continue;
 
1082
        }
 
1083
      }
 
1084
      
 
1085
      actionCollection()->action( "unmount_all_action" )->setEnabled(
 
1086
        ((!onlyForeignMountedShares() || Smb4KSettings::unmountForeignShares()) && m_list_view->topLevelItemCount() != 0) );
 
1087
      
 
1088
      break;
 
1089
    }
 
1090
    default:
 
1091
    {
 
1092
      break;
 
1093
    }
 
1094
  }
 
1095
}
 
1096
 
 
1097
 
 
1098
void Smb4KSharesViewPart::slotShareUpdated( Smb4KShare *share )
 
1099
{
 
1100
  switch ( m_mode )
 
1101
  {
 
1102
    case IconMode:
 
1103
    {
 
1104
      Smb4KSharesIconViewItem *item = NULL;
 
1105
      
 
1106
      for ( int i = 0; i < m_icon_view->count(); ++i )
 
1107
      {
 
1108
        item = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->item( i ) );
 
1109
        
 
1110
        if ( item && (QString::compare( item->shareItem()->path(), share->path() ) == 0 ||
 
1111
             QString::compare( item->shareItem()->canonicalPath(), share->canonicalPath() ) == 0) )
 
1112
        {
 
1113
          item->update( share );
 
1114
          m_icon_view->tooltip()->update();
 
1115
          break;
 
1116
        }
 
1117
        else
 
1118
        {
 
1119
          continue;
 
1120
        }
 
1121
      }
 
1122
      break;
 
1123
    }
 
1124
    case ListMode:
 
1125
    {
 
1126
      Smb4KSharesListViewItem *item = NULL;
 
1127
      
 
1128
      for ( int i = 0; i < m_list_view->topLevelItemCount(); ++i )
 
1129
      {
 
1130
        item = static_cast<Smb4KSharesListViewItem *>( m_list_view->topLevelItem( i ) );
 
1131
        
 
1132
        if ( item && (QString::compare( item->shareItem()->path(), share->path() ) == 0 ||
 
1133
             QString::compare( item->shareItem()->canonicalPath(), share->canonicalPath() ) == 0) )
 
1134
        {
 
1135
          item->update( share );
 
1136
          m_list_view->tooltip()->update();
 
1137
          break;
 
1138
        }
 
1139
        else
 
1140
        {
 
1141
          continue;
 
1142
        }
 
1143
      }
 
1144
      break;
 
1145
    }
 
1146
    default:
 
1147
    {
 
1148
      break;
 
1149
    }
 
1150
  }
1151
1151
}
1152
1152
 
1153
1153
 
1157
1157
  {
1158
1158
    case IconMode:
1159
1159
    {
1160
 
      Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->currentItem() );
1161
 
 
1162
 
      if ( item )
1163
 
      {
1164
 
        Smb4KCore::mounter()->unmountShare( item->itemData()->share(), false );
1165
 
      }
1166
 
      else
1167
 
      {
1168
 
        // Do nothing
1169
 
      }
1170
 
 
1171
 
      break;
1172
 
    }
1173
 
    case ListMode:
1174
 
    {
1175
 
      Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( m_list_view->currentItem() );
1176
 
 
1177
 
      if ( item )
1178
 
      {
1179
 
        Smb4KCore::mounter()->unmountShare( item->itemData()->share(), false );
1180
 
      }
1181
 
      else
1182
 
      {
1183
 
        // Do nothing
1184
 
      }
1185
 
 
1186
 
      break;
1187
 
    }
1188
 
    default:
1189
 
    {
1190
 
      break;
1191
 
    }
1192
 
  }
1193
 
}
1194
 
 
1195
 
 
1196
 
void Smb4KSharesViewPart::slotForceUnmountShare( bool /*checked*/ )
1197
 
{
1198
 
  switch ( m_mode )
1199
 
  {
1200
 
    case IconMode:
1201
 
    {
1202
 
      Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->currentItem() );
1203
 
 
1204
 
      if ( item )
1205
 
      {
1206
 
        Smb4KCore::mounter()->unmountShare( item->itemData()->share(), true );
1207
 
      }
1208
 
      else
1209
 
      {
1210
 
        // Do nothing
1211
 
      }
1212
 
 
1213
 
      break;
1214
 
    }
1215
 
    case ListMode:
1216
 
    {
1217
 
      Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( m_list_view->currentItem() );
1218
 
 
1219
 
      if ( item )
1220
 
      {
1221
 
        Smb4KCore::mounter()->unmountShare( item->itemData()->share(), true );
1222
 
      }
1223
 
      else
1224
 
      {
1225
 
        // Do nothing
 
1160
      QList<QListWidgetItem *> selected_items = m_icon_view->selectedItems();
 
1161
 
 
1162
      for ( int i = 0; i < selected_items.size(); ++i )
 
1163
      {
 
1164
        Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( selected_items.at( i ) );
 
1165
 
 
1166
        if ( item )
 
1167
        {
 
1168
          Smb4KMounter::self()->unmountShare( item->shareItem(), false, m_icon_view );
 
1169
        }
 
1170
        else
 
1171
        {
 
1172
          // Do nothing
 
1173
        }
 
1174
      }
 
1175
 
 
1176
      break;
 
1177
    }
 
1178
    case ListMode:
 
1179
    {
 
1180
      QList<QTreeWidgetItem *> selected_items = m_list_view->selectedItems();
 
1181
 
 
1182
      for ( int i = 0; i < selected_items.size(); ++i )
 
1183
      {
 
1184
        Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( selected_items.at( i ) );
 
1185
 
 
1186
        if ( item )
 
1187
        {
 
1188
          Smb4KMounter::self()->unmountShare( item->shareItem(), false, m_list_view );
 
1189
        }
 
1190
        else
 
1191
        {
 
1192
          // Do nothing
 
1193
        }
1226
1194
      }
1227
1195
 
1228
1196
      break;
1237
1205
 
1238
1206
void Smb4KSharesViewPart::slotUnmountAllShares( bool /*checked*/ )
1239
1207
{
1240
 
  Smb4KCore::mounter()->unmountAllShares();
 
1208
  switch ( m_mode )
 
1209
  {
 
1210
    case IconMode:
 
1211
    {
 
1212
      Smb4KMounter::self()->unmountAllShares( m_icon_view );
 
1213
      break;
 
1214
    }
 
1215
    case ListMode:
 
1216
    {
 
1217
      Smb4KMounter::self()->unmountAllShares( m_list_view );
 
1218
      break;
 
1219
    }
 
1220
    default:
 
1221
    {
 
1222
      break;
 
1223
    }
 
1224
  }
1241
1225
}
1242
1226
 
1243
1227
 
1247
1231
  {
1248
1232
    case IconMode:
1249
1233
    {
1250
 
      Smb4KSynchronizationDialog *dlg = m_icon_view->findChild<Smb4KSynchronizationDialog *>();
1251
 
      Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->currentItem() );
1252
 
 
1253
 
      if ( item && !item->itemData()->share()->isInaccessible() && !dlg )
1254
 
      {
1255
 
        dlg = new Smb4KSynchronizationDialog( item->itemData()->share(), m_icon_view );
1256
 
 
1257
 
        dlg->setVisible( true );
1258
 
      }
1259
 
      else
1260
 
      {
1261
 
        // Do nothing
 
1234
      QList<QListWidgetItem *> selected_items = m_icon_view->selectedItems();
 
1235
 
 
1236
      for ( int i = 0; i < selected_items.size(); ++i )
 
1237
      {
 
1238
        Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( selected_items.at( i ) );
 
1239
 
 
1240
        if ( item && !item->shareItem()->isInaccessible() )
 
1241
        {
 
1242
          Smb4KSynchronizer::self()->synchronize( item->shareItem(), m_icon_view );
 
1243
        }
 
1244
        else
 
1245
        {
 
1246
          // Do nothing
 
1247
        }
1262
1248
      }
1263
1249
 
1264
1250
      break;
1265
1251
    }
1266
1252
    case ListMode:
1267
1253
    {
1268
 
      Smb4KSynchronizationDialog *dlg = m_list_view->findChild<Smb4KSynchronizationDialog *>();
1269
 
      Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( m_list_view->currentItem() );
1270
 
 
1271
 
      if ( item && !item->itemData()->share()->isInaccessible() && !dlg )
1272
 
      {
1273
 
        dlg = new Smb4KSynchronizationDialog( item->itemData()->share(), m_list_view );
1274
 
 
1275
 
        dlg->setVisible( true );
1276
 
      }
1277
 
      else
1278
 
      {
1279
 
        // Do nothing
 
1254
      QList<QTreeWidgetItem *> selected_items = m_list_view->selectedItems();
 
1255
 
 
1256
      for ( int i = 0; i < selected_items.size(); ++i )
 
1257
      {
 
1258
        Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( selected_items.at( i ) );
 
1259
 
 
1260
        if ( item && !item->shareItem()->isInaccessible() )
 
1261
        {
 
1262
          Smb4KSynchronizer::self()->synchronize( item->shareItem(), m_list_view );
 
1263
        }
 
1264
        else
 
1265
        {
 
1266
          // Do nothing
 
1267
        }
1280
1268
      }
1281
1269
 
1282
1270
      break;
1294
1282
  {
1295
1283
    case IconMode:
1296
1284
    {
1297
 
      Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->currentItem() );
1298
 
 
1299
 
      if ( item && !item->itemData()->share()->isInaccessible() )
1300
 
      {
1301
 
        Smb4KCore::open( item->itemData()->share(), Smb4KCore::Konsole );
1302
 
      }
1303
 
      else
1304
 
      {
1305
 
        // Do nothing
1306
 
      }
1307
 
 
 
1285
      QList<QListWidgetItem *> selected_items = m_icon_view->selectedItems();
 
1286
 
 
1287
      for ( int i = 0; i < selected_items.size(); ++i )
 
1288
      {
 
1289
        Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( selected_items.at( i ) );
 
1290
 
 
1291
        if ( item && !item->shareItem()->isInaccessible() )
 
1292
        {
 
1293
          open( item->shareItem(), Konsole );
 
1294
        }
 
1295
        else
 
1296
        {
 
1297
          // Do nothing
 
1298
        }
 
1299
      }
1308
1300
 
1309
1301
      break;
1310
1302
    }
1311
1303
    case ListMode:
1312
1304
    {
1313
 
      Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( m_list_view->currentItem() );
1314
 
 
1315
 
      if ( item && !item->itemData()->share()->isInaccessible() )
1316
 
      {
1317
 
        Smb4KCore::open( item->itemData()->share(), Smb4KCore::Konsole );
1318
 
      }
1319
 
      else
1320
 
      {
1321
 
        // Do nothing
 
1305
      QList<QTreeWidgetItem *> selected_items = m_list_view->selectedItems();
 
1306
 
 
1307
      for ( int i = 0; i < selected_items.size(); ++i )
 
1308
      {
 
1309
        Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( selected_items.at( i ) );
 
1310
 
 
1311
        if ( item && !item->shareItem()->isInaccessible() )
 
1312
        {
 
1313
          open( item->shareItem(), Konsole );
 
1314
        }
 
1315
        else
 
1316
        {
 
1317
          // Do nothing
 
1318
        }
1322
1319
      }
1323
1320
 
1324
1321
      break;
1337
1334
  {
1338
1335
    case IconMode:
1339
1336
    {
1340
 
      Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( m_icon_view->currentItem() );
1341
 
 
1342
 
      if ( item && !item->itemData()->share()->isInaccessible() )
1343
 
      {
1344
 
        Smb4KCore::open( item->itemData()->share(), Smb4KCore::FileManager );
1345
 
      }
1346
 
      else
1347
 
      {
1348
 
        // Do nothing
1349
 
      }
1350
 
 
1351
 
      break;
1352
 
    }
1353
 
    case ListMode:
1354
 
    {
1355
 
      Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( m_list_view->currentItem() );
1356
 
 
1357
 
      if ( item && !item->itemData()->share()->isInaccessible() )
1358
 
      {
1359
 
        Smb4KCore::open( item->itemData()->share(), Smb4KCore::FileManager );
1360
 
      }
1361
 
      else
1362
 
      {
1363
 
        // Do nothing
1364
 
      }
1365
 
 
1366
 
      break;
1367
 
    }
1368
 
    default:
1369
 
    {
1370
 
      break;
1371
 
    }
1372
 
  }
1373
 
}
1374
 
 
1375
 
 
1376
 
void Smb4KSharesViewPart::slotSynchronizationState( int state )
1377
 
{
1378
 
  switch ( state )
1379
 
  {
1380
 
    case SYNCHRONIZER_START:
1381
 
    {
1382
 
      actionCollection()->action( "synchronize_action" )->setEnabled( false );
1383
 
 
1384
 
      break;
1385
 
    }
1386
 
    case SYNCHRONIZER_STOP:
1387
 
    {
1388
 
      actionCollection()->action( "synchronize_action" )->setEnabled( true );
1389
 
 
1390
 
      break;
1391
 
    }
1392
 
    default:
1393
 
    {
1394
 
      break;
1395
 
    }
 
1337
      QList<QListWidgetItem *> selected_items = m_icon_view->selectedItems();
 
1338
 
 
1339
      for ( int i = 0; i < selected_items.size(); ++i )
 
1340
      {
 
1341
        Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( selected_items.at( i ) );
 
1342
 
 
1343
        if ( item && !item->shareItem()->isInaccessible() )
 
1344
        {
 
1345
          open( item->shareItem(), FileManager );
 
1346
        }
 
1347
        else
 
1348
        {
 
1349
          // Do nothing
 
1350
        }
 
1351
      }
 
1352
 
 
1353
      break;
 
1354
    }
 
1355
    case ListMode:
 
1356
    {
 
1357
      QList<QTreeWidgetItem *> selected_items = m_list_view->selectedItems();
 
1358
 
 
1359
      for ( int i = 0; i < selected_items.size(); ++i )
 
1360
      {
 
1361
        Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( selected_items.at( i ) );
 
1362
 
 
1363
        if ( item && !item->shareItem()->isInaccessible() )
 
1364
        {
 
1365
          open( item->shareItem(), FileManager );
 
1366
        }
 
1367
        else
 
1368
        {
 
1369
          // Do nothing
 
1370
        }
 
1371
      }
 
1372
 
 
1373
      break;
 
1374
    }
 
1375
    default:
 
1376
    {
 
1377
      break;
 
1378
    }
 
1379
  }
 
1380
}
 
1381
 
 
1382
 
 
1383
void Smb4KSharesViewPart::slotAddBookmark( bool /*checked */)
 
1384
{
 
1385
  switch ( m_mode )
 
1386
  {
 
1387
    case IconMode:
 
1388
    {
 
1389
      QList<QListWidgetItem *> selected_items = m_icon_view->selectedItems();
 
1390
      QList<Smb4KShare *> shares;
 
1391
 
 
1392
      if ( !selected_items.isEmpty() )
 
1393
      {
 
1394
        for ( int i = 0; i < selected_items.size(); ++i )
 
1395
        {
 
1396
          Smb4KSharesIconViewItem *item = static_cast<Smb4KSharesIconViewItem *>( selected_items.at( i ) );
 
1397
          shares << item->shareItem();
 
1398
          continue;
 
1399
        }
 
1400
      }
 
1401
      else
 
1402
      {
 
1403
        // No selected items. Just return.
 
1404
        return;
 
1405
      }
 
1406
 
 
1407
      if ( !shares.isEmpty() )
 
1408
      {
 
1409
        Smb4KBookmarkHandler::self()->addBookmarks( shares, m_icon_view );
 
1410
      }
 
1411
      else
 
1412
      {
 
1413
        // Do nothing
 
1414
      }
 
1415
 
 
1416
      break;
 
1417
    }
 
1418
    case ListMode:
 
1419
    {
 
1420
      QList<QTreeWidgetItem *> selected_items = m_list_view->selectedItems();
 
1421
      QList<Smb4KShare *> shares;
 
1422
 
 
1423
      if ( !selected_items.isEmpty() )
 
1424
      {
 
1425
        for ( int i = 0; i < selected_items.size(); ++i )
 
1426
        {
 
1427
          Smb4KSharesListViewItem *item = static_cast<Smb4KSharesListViewItem *>( selected_items.at( i ) );
 
1428
          shares << item->shareItem();
 
1429
          continue;
 
1430
        }
 
1431
      }
 
1432
      else
 
1433
      {
 
1434
        // No selected items. Just return.
 
1435
        return;
 
1436
      }
 
1437
 
 
1438
      if ( !shares.isEmpty() )
 
1439
      {
 
1440
        Smb4KBookmarkHandler::self()->addBookmarks( shares, m_list_view );
 
1441
      }
 
1442
      else
 
1443
      {
 
1444
        // Do nothing
 
1445
      }
 
1446
 
 
1447
      break;
 
1448
    }
 
1449
    default:
 
1450
    {
 
1451
      break;
 
1452
    }
 
1453
  }
 
1454
}
 
1455
 
 
1456
 
 
1457
void Smb4KSharesViewPart::slotMounterAboutToStart( Smb4KShare *share, int process )
 
1458
{
 
1459
  switch ( process )
 
1460
  {
 
1461
    case Smb4KMounter::MountShare:
 
1462
    {
 
1463
      if ( !m_silent )
 
1464
      {
 
1465
        emit setStatusBarText( i18n( "Mounting share %1..." ).arg( share->unc() ) );
 
1466
      }
 
1467
      else
 
1468
      {
 
1469
        // Do nothing
 
1470
      }
 
1471
      break;
 
1472
    }
 
1473
    case Smb4KMounter::UnmountShare:
 
1474
    {
 
1475
      if ( !m_silent )
 
1476
      {
 
1477
        emit setStatusBarText( i18n( "Unmounting share %1..." ).arg( share->unc() ) );
 
1478
      }
 
1479
      else
 
1480
      {
 
1481
        // Do nothing
 
1482
      }
 
1483
      break;
 
1484
    }
 
1485
    default:
 
1486
    {
 
1487
      break;
 
1488
    }
 
1489
  }
 
1490
}
 
1491
 
 
1492
 
 
1493
void Smb4KSharesViewPart::slotMounterFinished( Smb4KShare */*share*/, int /*process*/ )
 
1494
{
 
1495
  if ( !m_silent )
 
1496
  {
 
1497
    emit setStatusBarText( i18n( "Done." ) );
 
1498
  }
 
1499
  else
 
1500
  {
 
1501
    // Do nothing
1396
1502
  }
1397
1503
}
1398
1504
 
1403
1509
}
1404
1510
 
1405
1511
 
 
1512
void Smb4KSharesViewPart::slotIconSizeChanged( int group )
 
1513
{
 
1514
  switch ( group )
 
1515
  {
 
1516
    case KIconLoader::Desktop:
 
1517
    {
 
1518
      if ( m_icon_view )
 
1519
      {
 
1520
        int icon_size = KIconLoader::global()->currentSize( KIconLoader::Desktop );
 
1521
        m_icon_view->setIconSize( QSize( icon_size, icon_size ) );
 
1522
      }
 
1523
      else
 
1524
      {
 
1525
        // Do nothing
 
1526
      }
 
1527
      break;
 
1528
    }
 
1529
    case KIconLoader::Small:
 
1530
    {
 
1531
      if ( m_list_view )
 
1532
      {
 
1533
        int icon_size = KIconLoader::global()->currentSize( KIconLoader::Small );
 
1534
        m_list_view->setIconSize( QSize( icon_size, icon_size ) );
 
1535
      }
 
1536
      else
 
1537
      {
 
1538
        // Do nothing
 
1539
      }
 
1540
      break;
 
1541
    }
 
1542
    default:
 
1543
    {
 
1544
      break;
 
1545
    }
 
1546
  }
 
1547
}
 
1548
 
 
1549
 
1406
1550
#include "smb4ksharesview_part.moc"