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

« back to all changes in this revision

Viewing changes to core/smb4knotification.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:
 
1
/***************************************************************************
 
2
    smb4knotification  -  This class provides notifications for Smb4K.
 
3
                             -------------------
 
4
    begin                : Son Jun 27 2010
 
5
    copyright            : (C) 2010-2011 by Alexander Reinholdt
 
6
    email                : alexander.reinholdt@kdemail.org
 
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
// KDE includes
 
27
#include <kdebug.h>
 
28
#include <klocale.h>
 
29
#include <kiconloader.h>
 
30
#include <krun.h>
 
31
#include <kurl.h>
 
32
#include <kmessagebox.h>
 
33
#include <knotification.h>
 
34
#include <kdemacros.h>
 
35
#include <kauthactionreply.h>
 
36
 
 
37
// system includes
 
38
#include <string.h>
 
39
 
 
40
// application specific includes
 
41
#include <smb4knotification.h>
 
42
#include <smb4ksettings.h>
 
43
#include <smb4kbookmark.h>
 
44
#include <smb4kworkgroup.h>
 
45
#include <smb4khost.h>
 
46
 
 
47
using namespace KAuth;
 
48
 
 
49
 
 
50
Smb4KNotification::Smb4KNotification( QObject *parent )
 
51
: QObject( parent )
 
52
{
 
53
}
 
54
 
 
55
 
 
56
Smb4KNotification::~Smb4KNotification()
 
57
{
 
58
}
 
59
 
 
60
 
 
61
void Smb4KNotification::shareMounted( Smb4KShare* share )
 
62
{
 
63
  Q_ASSERT( share );
 
64
 
 
65
  if ( Smb4KSettings::self()->showNotifications() )
 
66
  {
 
67
    m_share = *share;
 
68
    
 
69
    KNotification *notification = KNotification::event( KNotification::Notification,
 
70
                                  "Smb4K",
 
71
                                  i18n( "<p>The share <b>%1</b> has been mounted to <b>%2</b>.</p>", 
 
72
                                  share->unc(), share->path() ),
 
73
                                  KIconLoader::global()->loadIcon( "folder-remote", KIconLoader::NoGroup, 0, 
 
74
                                  KIconLoader::DefaultState, QStringList( "emblem-mounted" ) ),
 
75
                                  0L,
 
76
                                  KNotification::CloseOnTimeout );
 
77
    notification->setActions( QStringList( i18n( "Open" ) ) );
 
78
    connect( notification, SIGNAL( activated( unsigned int ) ), this, SLOT( slotOpenShare() ) );
 
79
    connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
80
  }
 
81
  else
 
82
  {
 
83
    // Do nothing
 
84
  }
 
85
}
 
86
 
 
87
 
 
88
void Smb4KNotification::shareUnmounted( Smb4KShare* share )
 
89
{
 
90
  Q_ASSERT( share );
 
91
 
 
92
  if ( Smb4KSettings::self()->showNotifications() )
 
93
  {
 
94
    KNotification *notification = KNotification::event( KNotification::Notification,
 
95
                                  "Smb4K",
 
96
                                  i18n( "<p>The share <b>%1</b> has been unmounted from <b>%2</b>.</p>", 
 
97
                                  share->unc(), share->path() ),
 
98
                                  KIconLoader::global()->loadIcon( "folder-remote", KIconLoader::NoGroup, 0, 
 
99
                                  KIconLoader::DefaultState, QStringList( "emblem-unmounted" ) ),
 
100
                                  0L,
 
101
                                  KNotification::CloseOnTimeout );
 
102
    connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
103
  }
 
104
  else
 
105
  {
 
106
    // Do nothing
 
107
  }
 
108
}
 
109
 
 
110
 
 
111
void Smb4KNotification::sharesMounted( int total, int actual )
 
112
{
 
113
  if ( Smb4KSettings::self()->showNotifications() )
 
114
  {
 
115
    if ( total != actual )
 
116
    {
 
117
      KNotification *notification = KNotification::event( KNotification::Notification,
 
118
                                    "Smb4K",
 
119
                                    i18np( "<p>%1 share out of %2 has been mounted.</p>", "<p>%1 shares out of %2 have been mounted.</p>", actual, total ),
 
120
                                    KIconLoader::global()->loadIcon( "folder-remote", 
 
121
                                    KIconLoader::NoGroup, 0, KIconLoader::DefaultState, QStringList( "emblem-mounted" ) ),
 
122
                                    0L,
 
123
                                    KNotification::CloseOnTimeout );
 
124
      connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
125
    }
 
126
    else
 
127
    {
 
128
      KNotification *notification = KNotification::event( KNotification::Notification,
 
129
                                    "Smb4K",
 
130
                                    i18n( "<p>All shares have been mounted.</p>" ),
 
131
                                    KIconLoader::global()->loadIcon( "folder-remote", 
 
132
                                    KIconLoader::NoGroup, 0, KIconLoader::DefaultState, QStringList( "emblem-mounted" ) ),
 
133
                                    0L,
 
134
                                    KNotification::CloseOnTimeout );
 
135
      connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
136
    }
 
137
  }
 
138
  else
 
139
  {
 
140
    // Do nothing
 
141
  }
 
142
}
 
143
 
 
144
 
 
145
void Smb4KNotification::allSharesUnmounted( int total, int actual )
 
146
{
 
147
  if ( Smb4KSettings::self()->showNotifications() )
 
148
  {
 
149
    if ( total != actual )
 
150
    {
 
151
      KNotification *notification = KNotification::event( KNotification::Notification,
 
152
                                    "Smb4K",
 
153
                                    i18np( "<p>%1 share out of %2 has been unmounted.</p>", "<p>%1 shares out of %2 have been unmounted.</p>", actual, total ),
 
154
                                    KIconLoader::global()->loadIcon( "folder-remote", KIconLoader::NoGroup, 0, 
 
155
                                    KIconLoader::DefaultState, QStringList( "emblem-unmounted" ) ),
 
156
                                    0L,
 
157
                                    KNotification::CloseOnTimeout );
 
158
      connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
159
    }
 
160
    else
 
161
    {
 
162
      KNotification *notification = KNotification::event( KNotification::Notification,
 
163
                                    "Smb4K", 
 
164
                                    i18n( "<p>All shares have been unmounted.</p>" ),
 
165
                                    KIconLoader::global()->loadIcon( "folder-remote", KIconLoader::NoGroup, 0, 
 
166
                                    KIconLoader::DefaultState, QStringList( "emblem-unmounted" ) ),
 
167
                                    0L,
 
168
                                    KNotification::CloseOnTimeout );
 
169
      connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
170
    }
 
171
  }
 
172
  else
 
173
  {
 
174
    // Do nothing
 
175
  }
 
176
}
 
177
 
 
178
 
 
179
//
 
180
// Warnings
 
181
//
 
182
 
 
183
 
 
184
void Smb4KNotification::openingWalletFailed( const QString &name )
 
185
{
 
186
  KNotification *notification = KNotification::event( KNotification::Warning,
 
187
                                "Smb4K",
 
188
                                i18n( "<p>Opening the wallet <b>%1</b> failed.</p>", name ),
 
189
                                KIconLoader::global()->loadIcon( "dialog-warning", KIconLoader::NoGroup, 0, 
 
190
                                KIconLoader::DefaultState ),
 
191
                                0L,
 
192
                                KNotification::CloseOnTimeout );
 
193
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
194
}
 
195
 
 
196
 
 
197
void Smb4KNotification::loginsNotAccessible()
 
198
{
 
199
  KNotification *notification = KNotification::event( KNotification::Warning,
 
200
                                "Smb4K",
 
201
                                i18n( "<p>The logins stored in the wallet could not be accessed. "
 
202
                                "There is either no wallet available or it could not be opened.</p>" ),
 
203
                                KIconLoader::global()->loadIcon( "dialog-warning", KIconLoader::NoGroup, 0, 
 
204
                                KIconLoader::DefaultState ),
 
205
                                0L,
 
206
                                KNotification::CloseOnTimeout );
 
207
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
208
}
 
209
 
 
210
 
 
211
void Smb4KNotification::mimetypeNotSupported( const QString &mt )
 
212
{
 
213
  KNotification *notification = KNotification::event( KNotification::Warning,
 
214
                                "Smb4K",
 
215
                                i18n( "<p>The mimetype <b>%1</b> is not supported for printing. "
 
216
                                "Please convert the file to PDF or Postscript and try again.</p>", mt ),
 
217
                                KIconLoader::global()->loadIcon( "dialog-warning", KIconLoader::NoGroup, 0, 
 
218
                                KIconLoader::DefaultState ),
 
219
                                0L,
 
220
                                KNotification::CloseOnTimeout );
 
221
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
222
}
 
223
 
 
224
 
 
225
void Smb4KNotification::bookmarkExists( Smb4KBookmark *bookmark )
 
226
{
 
227
  KNotification *notification = KNotification::event( KNotification::Warning,
 
228
                                "Smb4K",
 
229
                                i18n( "<p>The bookmark for share <b>%1</b> already exists and will be skipped.", bookmark->unc() ),
 
230
                                KIconLoader::global()->loadIcon( "dialog-warning", KIconLoader::NoGroup, 0, 
 
231
                                KIconLoader::DefaultState ),
 
232
                                0L,
 
233
                                KNotification::CloseOnTimeout );
 
234
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
235
}
 
236
 
 
237
 
 
238
void Smb4KNotification::bookmarkLabelInUse( Smb4KBookmark *bookmark )
 
239
{
 
240
  KNotification *notification = KNotification::event( KNotification::Warning,
 
241
                                "Smb4K",
 
242
                                i18n( "<p>The label <b>%1</b> of the bookmark for the share <b>%2</b> "
 
243
                                "is already being used and will automatically be renamed.</p>", bookmark->label(), bookmark->unc() ),
 
244
                                KIconLoader::global()->loadIcon( "dialog-warning", KIconLoader::NoGroup, 0, 
 
245
                                KIconLoader::DefaultState ),
 
246
                                0L,
 
247
                                KNotification::CloseOnTimeout );
 
248
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
249
}
 
250
 
 
251
 
 
252
void Smb4KNotification::emptyCustomMasterBrowser()
 
253
{
 
254
  KNotification *notification = KNotification::event( KNotification::Warning,
 
255
                                "Smb4K",
 
256
                                i18n( "The entry of the custom master browser is empty. Smb4K is going to "
 
257
                                "try to query the current master browser of your workgroup or domain instead." ),
 
258
                                KIconLoader::global()->loadIcon( "dialog-warning", KIconLoader::NoGroup, 0,
 
259
                                KIconLoader::DefaultState ),
 
260
                                0L,
 
261
                                KNotification::CloseOnTimeout );
 
262
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
263
}
 
264
 
 
265
 
 
266
//
 
267
// Errors
 
268
//
 
269
 
 
270
 
 
271
void Smb4KNotification::retrievingDomainsFailed( const QString &err_msg )
 
272
{
 
273
  QString text;
 
274
  
 
275
  if ( !err_msg.isEmpty() )
 
276
  {
 
277
    text = i18n( "<p>Retrieving the list of available domains failed:</p><p><tt>%1</tt></p>", err_msg );
 
278
  }
 
279
  else
 
280
  {
 
281
    text = i18n( "<p>Retrieving the list of available domains failed.</p>" );
 
282
  }
 
283
  
 
284
  KNotification *notification = KNotification::event( KNotification::Error,
 
285
                                "Smb4K",
 
286
                                text,
 
287
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
288
                                KIconLoader::DefaultState ),
 
289
                                0L,
 
290
                                KNotification::Persistent );
 
291
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );    
 
292
}
 
293
 
 
294
 
 
295
void Smb4KNotification::scanningBroadcastAreaFailed( const QString &err_msg )
 
296
{
 
297
  QString text;
 
298
  
 
299
  if ( !err_msg.isEmpty() )
 
300
  {
 
301
    text = i18n( "<p>Scanning the defined broadcast area(s) failed:</p><p><tt>%1</tt></p>", err_msg );
 
302
  }
 
303
  else
 
304
  {
 
305
    text = i18n( "<p>Scanning the defined broadcast area(s) failed.</p>" );
 
306
  }
 
307
  
 
308
  KNotification *notification = KNotification::event( KNotification::Error,
 
309
                                "Smb4K",
 
310
                                text,
 
311
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
312
                                KIconLoader::DefaultState ),
 
313
                                0L,
 
314
                                KNotification::Persistent );
 
315
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );    
 
316
}
 
317
 
 
318
 
 
319
void Smb4KNotification::retrievingServersFailed( Smb4KWorkgroup* workgroup, const QString &err_msg )
 
320
{
 
321
  QString text;
 
322
  
 
323
  if ( !err_msg.isEmpty() )
 
324
  {
 
325
    text = i18n( "<p>Retrieving the list of servers belonging to domain <b>%1</b> failed.</p><p><tt>%2</tt></p>", workgroup->workgroupName(), err_msg );
 
326
  }
 
327
  else
 
328
  {
 
329
    text = i18n( "<p>Retrieving the list of servers belonging to domain <b>%1</b> failed.</p>", workgroup->workgroupName() );
 
330
  }
 
331
  
 
332
  KNotification *notification = KNotification::event( KNotification::Error,
 
333
                                "Smb4K",
 
334
                                text,
 
335
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
336
                                KIconLoader::DefaultState ),
 
337
                                0L,
 
338
                                KNotification::Persistent );
 
339
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );  
 
340
}
 
341
 
 
342
 
 
343
void Smb4KNotification::retrievingSharesFailed( Smb4KHost *host, const QString &err_msg )
 
344
{
 
345
  QString text;
 
346
  
 
347
  if ( !err_msg.isEmpty() )
 
348
  {
 
349
    text = i18n( "<p>Retrieving the list of shares from <b>%1</b> failed:</p><p><tt>%2</tt></p>", host->hostName(), err_msg );
 
350
  }
 
351
  else
 
352
  {
 
353
    text = i18n( "<p>Retrieving the list of shares from <b>%1</b> failed.</p>", host->hostName() );
 
354
  }
 
355
  
 
356
  KNotification *notification = KNotification::event( KNotification::Error,
 
357
                                "Smb4K",
 
358
                                text,
 
359
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
360
                                KIconLoader::DefaultState ),
 
361
                                0L,
 
362
                                KNotification::Persistent );
 
363
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );  
 
364
}
 
365
 
 
366
 
 
367
void Smb4KNotification::retrievingPreviewFailed( Smb4KShare *share, const QString &err_msg )
 
368
{
 
369
  QString text;
 
370
  
 
371
  if ( !err_msg.isEmpty() )
 
372
  {
 
373
    text =  i18n( "<p>Retrieving the preview of <b>%1</b> failed:</p><p><tt>%2</tt></p>", share->unc(), err_msg );
 
374
  }
 
375
  else
 
376
  {
 
377
    text =  i18n( "<p>Retrieving the preview of <b>%1</b> failed.</p>", share->unc() );
 
378
  }
 
379
  
 
380
  KNotification *notification = KNotification::event( KNotification::Error,
 
381
                                "Smb4K",
 
382
                                text,
 
383
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
384
                                KIconLoader::DefaultState ),
 
385
                                0L,
 
386
                                KNotification::Persistent );
 
387
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
388
}
 
389
 
 
390
 
 
391
void Smb4KNotification::mountingFailed( Smb4KShare *share, const QString &err_msg )
 
392
{
 
393
  QString text;
 
394
  
 
395
  if ( !err_msg.isEmpty() )
 
396
  {
 
397
    text = i18n( "<p>Mounting the share <b>%1</b> failed:</p><p><tt>%2</tt></p>", share->unc(), err_msg );
 
398
  }
 
399
  else
 
400
  {
 
401
    text = i18n( "<p>Mounting the share <b>%1</b> failed.</p>", share->unc() );
 
402
  }
 
403
  
 
404
  KNotification *notification = KNotification::event( KNotification::Error,
 
405
                                "Smb4K",
 
406
                                text,
 
407
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
408
                                KIconLoader::DefaultState ),
 
409
                                0L,
 
410
                                KNotification::Persistent );
 
411
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
412
}
 
413
 
 
414
 
 
415
void Smb4KNotification::unmountingFailed( Smb4KShare *share, const QString &err_msg )
 
416
{
 
417
  QString text;
 
418
  
 
419
  if ( !err_msg.isEmpty() )
 
420
  {
 
421
    text = i18n( "<p>Unmounting the share <b>%1</b> from <b>%2</b> failed:</p><p><tt>%3</tt></p>", share->unc(), share->path(), err_msg );
 
422
  }
 
423
  else
 
424
  {
 
425
    text = i18n( "<p>Unmounting the share <b>%1</b> from <b>%2</b> failed.", share->unc(), share->path() );
 
426
  }
 
427
  
 
428
  KNotification *notification = KNotification::event( KNotification::Error,
 
429
                                "Smb4K",
 
430
                                text,
 
431
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
432
                                KIconLoader::DefaultState ),
 
433
                                0L,
 
434
                                KNotification::Persistent );
 
435
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
436
}
 
437
 
 
438
 
 
439
void Smb4KNotification::unmountingNotAllowed( Smb4KShare *share )
 
440
{
 
441
  KNotification *notification = KNotification::event( KNotification::Error,
 
442
                                "Smb4K",
 
443
                                i18n( "<p>You are not allowed to unmount the share <b>%1</b> from <b>%2</b>. "
 
444
                                "It is owned by the user <b>%3</b>.</p>", share->unc(), share->path(), share->owner() ),
 
445
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
446
                                KIconLoader::DefaultState ),
 
447
                                0L,
 
448
                                KNotification::Persistent );
 
449
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
450
}
 
451
 
 
452
 
 
453
void Smb4KNotification::printingFailed( Smb4KShare *printer, const QString &err_msg )
 
454
{
 
455
  QString text;
 
456
  
 
457
  if ( !err_msg.isEmpty() )
 
458
  {
 
459
    text = i18n( "<p>Printing on printer <b>%1</b> failed:</p><p><tt>%2</tt></p>", printer->unc(), err_msg );
 
460
  }
 
461
  else
 
462
  {
 
463
    text = i18n( "<p>Printing on printer <b>%1</b> failed.</p>", printer->unc() );
 
464
  }
 
465
  
 
466
  KNotification *notification = KNotification::event( KNotification::Error,
 
467
                                "Smb4K",
 
468
                                text,
 
469
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
470
                                KIconLoader::DefaultState ),
 
471
                                0L,
 
472
                                KNotification::Persistent );
 
473
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
474
}
 
475
 
 
476
 
 
477
void Smb4KNotification::synchronizationFailed( const KUrl &src, const KUrl &dest, const QString &err_msg )
 
478
{
 
479
  QString text;
 
480
  
 
481
  if ( !err_msg.isEmpty() )
 
482
  {
 
483
    text = i18n( "<p>Synchronizing <b>%1</b> with <b>%2</b> failed:</p><p><tt>%3</tt></p>", dest.path(), src.path(), err_msg );
 
484
  }
 
485
  else
 
486
  {
 
487
    text = i18n( "<p>Synchronizing <b>%1</b> with <b>%2</b> failed.</p>", dest.path(), src.path() );
 
488
  }
 
489
  
 
490
  KNotification *notification = KNotification::event( KNotification::Error,
 
491
                                "Smb4K",
 
492
                                text,
 
493
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
494
                                KIconLoader::DefaultState ),
 
495
                                0L,
 
496
                                KNotification::Persistent );
 
497
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
498
}
 
499
 
 
500
 
 
501
void Smb4KNotification::searchingFailed( const QString &item, const QString &err_msg )
 
502
{
 
503
  QString text;
 
504
  
 
505
  if ( !err_msg.isEmpty() )
 
506
  {
 
507
    text = i18n( "<p>Searching the network neighborhood for the search item <b>%1</b> failed:</p><p><tt>%2</tt></p>", item, err_msg );
 
508
  }
 
509
  else
 
510
  {
 
511
    text = i18n( "<p>Searching the network neighborhood for the search item <b>%1</b> failed.</p>", item );
 
512
  }
 
513
  
 
514
  KNotification *notification = KNotification::event( KNotification::Error,
 
515
                                "Smb4K",
 
516
                                text,
 
517
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
518
                                KIconLoader::DefaultState ),
 
519
                                0L,
 
520
                                KNotification::Persistent );
 
521
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
522
}
 
523
 
 
524
 
 
525
void Smb4KNotification::commandNotFound( const QString &command )
 
526
{
 
527
  KNotification *notification = KNotification::event( KNotification::Error,
 
528
                                "Smb4K",
 
529
                                i18n( "<p>The command <b>%1</b> could not be found.</p>", command ),
 
530
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
531
                                KIconLoader::DefaultState ),
 
532
                                0L,
 
533
                                KNotification::Persistent );
 
534
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
535
}
 
536
 
 
537
 
 
538
void Smb4KNotification::cannotBookmarkPrinter( Smb4KShare *share )
 
539
{
 
540
  if ( share->isPrinter() )
 
541
  {
 
542
    KNotification *notification = KNotification::event( KNotification::Error,
 
543
                                  "Smb4K",
 
544
                                  i18n( "<p>The share <b>%1</b> is a printer and cannot be bookmarked.</p>", share->unc() ),
 
545
                                  KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
546
                                  KIconLoader::DefaultState ),
 
547
                                  0L,
 
548
                                  KNotification::Persistent );
 
549
    connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
550
  }
 
551
  else
 
552
  {
 
553
    // Do nothing
 
554
  }
 
555
}
 
556
 
 
557
 
 
558
void Smb4KNotification::fileNotFound( const QString &fileName )
 
559
{
 
560
  KNotification *notification = KNotification::event( KNotification::Error,
 
561
                                "Smb4K",
 
562
                                i18n( "<p>The file <b>%1</b> could not be found.</p>", fileName ),
 
563
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
564
                                KIconLoader::DefaultState ),
 
565
                                0L,
 
566
                                KNotification::Persistent );
 
567
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
568
}
 
569
 
 
570
 
 
571
void Smb4KNotification::openingFileFailed( const QFile &file )
 
572
{
 
573
  QString text;
 
574
 
 
575
  if ( !file.errorString().isEmpty() )
 
576
  {
 
577
    text = i18n( "<p>Opening the file <b>%1</b> failed:</p><p><tt>%2</tt></p>", file.fileName(), file.errorString() );
 
578
  }
 
579
  else
 
580
  {
 
581
    text = i18n( "<p>Opening the file <b>%1</b> failed.</p>", file.fileName() );
 
582
  }
 
583
  
 
584
  KNotification *notification = KNotification::event( KNotification::Error,
 
585
                                "Smb4K",
 
586
                                text,
 
587
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
588
                                KIconLoader::DefaultState ),
 
589
                                0L,
 
590
                                KNotification::Persistent );
 
591
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
592
}
 
593
 
 
594
 
 
595
void Smb4KNotification::readingFileFailed( const QFile &file, const QString &err_msg )
 
596
{
 
597
  QString text;
 
598
  
 
599
  if ( !err_msg.isEmpty() )
 
600
  {
 
601
    text = i18n( "<p>Reading from file <b>%1</b> failed:</p><p><tt>%2</tt></p>", file.fileName(), err_msg );
 
602
  }
 
603
  else
 
604
  {
 
605
    if ( !file.errorString().isEmpty() )
 
606
    {
 
607
      text = i18n( "<p>Reading from file <b>%1</b> failed:</p><p><tt>%2</tt></p>", file.fileName(), file.errorString() );
 
608
    }
 
609
    else
 
610
    {
 
611
      text = i18n( "<p>Reading from file <b>%1</b> failed.</p>", file.fileName() );
 
612
    }
 
613
  }
 
614
  
 
615
  KNotification *notification = KNotification::event( KNotification::Error,
 
616
                                "Smb4K",
 
617
                                text,
 
618
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
619
                                KIconLoader::DefaultState ),
 
620
                                0L,
 
621
                                KNotification::Persistent );
 
622
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
623
}
 
624
 
 
625
 
 
626
 
 
627
void Smb4KNotification::mkdirFailed( const QDir &dir )
 
628
{
 
629
  KNotification *notification = KNotification::event( KNotification::Error,
 
630
                                "Smb4K",
 
631
                                i18n( "<p>The following directory could not be created:</p><p><tt>%1</tt></p>", dir.absolutePath() ),
 
632
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
633
                                KIconLoader::DefaultState ),
 
634
                                0L,
 
635
                                KNotification::Persistent );
 
636
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
637
}
 
638
 
 
639
 
 
640
void Smb4KNotification::missingPrograms( const QStringList &programs )
 
641
{
 
642
  KNotification *notification = KNotification::event( KNotification::Error,
 
643
                                "Smb4K",
 
644
                                i18n( "<p>Some required programs could not be found:</p><p><tt>%1</tt></p>", programs.join( ", " ) ),
 
645
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
646
                                KIconLoader::DefaultState ),
 
647
                                0L,
 
648
                                KNotification::Persistent );
 
649
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
650
}
 
651
 
 
652
 
 
653
void Smb4KNotification::processError( QProcess::ProcessError error )
 
654
{
 
655
  QString text;
 
656
 
 
657
  switch ( error )
 
658
  {
 
659
    case QProcess::FailedToStart:
 
660
    {
 
661
      text = i18n( "<p>The process failed to start (error code: <tt>%1</tt>).</p>", error );
 
662
      break;
 
663
    }
 
664
    case QProcess::Crashed:
 
665
    {
 
666
      text = i18n( "<p>The process crashed (error code: <tt>%1</tt>).</p>", error );
 
667
      break;
 
668
    }
 
669
    case QProcess::Timedout:
 
670
    {
 
671
      text = i18n( "<p>The process timed out (error code: <tt>%1</tt>).</p>", error );
 
672
      break;
 
673
    }
 
674
    case QProcess::WriteError:
 
675
    {
 
676
      text = i18n( "<p>Could not write to the process (error code: <tt>%1</tt>).</p>", error );
 
677
      break;
 
678
    }
 
679
    case QProcess::ReadError:
 
680
    {
 
681
      text = i18n( "<p>Could not read from the process (error code: <tt>%1</tt>).</p>", error );
 
682
      break;
 
683
    }
 
684
    case QProcess::UnknownError:
 
685
    default:
 
686
    {
 
687
      text = i18n( "<p>The process reported an unknown error.</p>" );
 
688
      break;
 
689
    }
 
690
  }
 
691
  
 
692
  KNotification *notification = KNotification::event( KNotification::Error,
 
693
                                "Smb4K",
 
694
                                text,
 
695
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
696
                                KIconLoader::DefaultState ),
 
697
                                0L,
 
698
                                KNotification::Persistent );
 
699
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
700
}
 
701
 
 
702
 
 
703
void Smb4KNotification::systemCallFailed( const QString &sys_call, int err_no )
 
704
{
 
705
  QString text;
 
706
  
 
707
  int len = 100;
 
708
  char buf[100];
 
709
  buf[0] = '\0';
 
710
#ifndef Q_OS_FREEBSD
 
711
  // This is thread safe.
 
712
  const char *msg;
 
713
 
 
714
  msg = strerror_r( err_no, buf, len );
 
715
 
 
716
  if ( buf[0] == '\0' )
 
717
  {
 
718
    // Buffer was not used
 
719
    text = i18n( "<p>The system call <b>%1</b> failed:</p><p><tt>%2</tt></p>", sys_call, QString( msg ) );
 
720
  }
 
721
  else
 
722
  {
 
723
    text = i18n( "<p>The system call <b>%1</b> failed:</p><p><tt>%2</tt></p>", sys_call, QString( buf ) );
 
724
  }
 
725
#else
 
726
  if ( strerror_r( err_no, buf, len ) == 0 )
 
727
  {
 
728
    text = i18n( "<p>The system call <b>%1</b> failed:</p><p><tt>%2</tt></p>", sys_call, QString( buf ) );
 
729
  }
 
730
  else
 
731
  {
 
732
    // Do nothing
 
733
  }
 
734
#endif
 
735
 
 
736
  KNotification *notification = KNotification::event( KNotification::Error,
 
737
                                "Smb4K",
 
738
                                text,
 
739
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
740
                                KIconLoader::DefaultState ),
 
741
                                0L,
 
742
                                KNotification::Persistent );
 
743
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
744
}
 
745
 
 
746
 
 
747
void Smb4KNotification::actionFailed( int err_code )
 
748
{
 
749
  QString text, err_msg;
 
750
  
 
751
  switch ( err_code )
 
752
  {
 
753
    case ActionReply::NoResponder:
 
754
    {
 
755
      err_msg = "NoResponder";
 
756
      break;
 
757
    }
 
758
    case ActionReply::NoSuchAction:
 
759
    {
 
760
      err_msg = "NoSuchAction";
 
761
      break;
 
762
    }
 
763
    case ActionReply::InvalidAction:
 
764
    {
 
765
      err_msg = "InvalidAction";
 
766
      break;
 
767
    }
 
768
    case ActionReply::AuthorizationDenied:
 
769
    {
 
770
      err_msg = "AuthorizationDenied";
 
771
      break;
 
772
    }
 
773
    case ActionReply::UserCancelled:
 
774
    {
 
775
      err_msg = "UserCancelled";
 
776
      break;
 
777
    }
 
778
    case ActionReply::HelperBusy:
 
779
    {
 
780
      err_msg = "HelperBusy";
 
781
      break;
 
782
    }
 
783
    case ActionReply::DBusError:
 
784
    {
 
785
      err_msg = "DBusError";
 
786
      break;
 
787
    }
 
788
    default:
 
789
    {
 
790
      break;
 
791
    }
 
792
  }
 
793
 
 
794
  if ( !err_msg.isEmpty() )
 
795
  {
 
796
    text = i18n( "<p>Executing an action with root privileges failed (error code:<tt>%1</tt>).</p>", err_msg );
 
797
  }
 
798
  else
 
799
  {
 
800
    text = i18n( "<p>Executing an action with root privileges failed.</p>", err_msg );
 
801
  }
 
802
  
 
803
  KNotification *notification = KNotification::event( KNotification::Error,
 
804
                                "Smb4K",
 
805
                                text,
 
806
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0, 
 
807
                                KIconLoader::DefaultState ),
 
808
                                0L,
 
809
                                KNotification::Persistent );
 
810
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
811
}
 
812
 
 
813
 
 
814
void Smb4KNotification::invalidURLPassed()
 
815
{
 
816
  KNotification *notification = KNotification::event( KNotification::Error,
 
817
                                "Smb4K",
 
818
                                i18n( "<p>The URL that was passed is invalid.</p>" ),
 
819
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0, 
 
820
                                KIconLoader::DefaultState ),
 
821
                                0L,
 
822
                                KNotification::Persistent );
 
823
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
824
}
 
825
 
 
826
 
 
827
void Smb4KNotification::emptyBroadcastAreas()
 
828
{
 
829
  KNotification *notification = KNotification::event( KNotification::Error,
 
830
                                "Smb4K",
 
831
                                i18n( "<p>There are no broadcast areas defined.</p>" ),
 
832
                                KIconLoader::global()->loadIcon( "dialog-error", KIconLoader::NoGroup, 0,
 
833
                                KIconLoader::DefaultState ),
 
834
                                0L,
 
835
                                KNotification::Persistent );
 
836
  connect( notification, SIGNAL( closed() ), this, SLOT( slotNotificationClosed() ) );
 
837
}
 
838
 
 
839
/////////////////////////////////////////////////////////////////////////////
 
840
// SLOT IMPLEMENTATIONS
 
841
/////////////////////////////////////////////////////////////////////////////
 
842
 
 
843
void Smb4KNotification::slotNotificationClosed()
 
844
{
 
845
  delete this;
 
846
}
 
847
 
 
848
 
 
849
void Smb4KNotification::slotOpenShare()
 
850
{
 
851
  KRun::runUrl( KUrl( m_share.canonicalPath() ), "inode/directory", 0 );
 
852
}
 
853
 
 
854
 
 
855
#include "smb4knotification.moc"