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

« back to all changes in this revision

Viewing changes to core/smb4kcoremessage.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
 
    smb4kcoremessage  -  This class provides messages for use with the
3
 
    core classes of Smb4K.
4
 
                             -------------------
5
 
    begin                : Sa Mär 8 2008
6
 
    copyright            : (C) 2008 by Alexander Reinholdt
7
 
    email                : dustpuppy@users.berlios.de
8
 
 ***************************************************************************/
9
 
 
10
 
/***************************************************************************
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 *   This program is distributed in the hope that it will be useful, but   *
17
 
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
18
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
19
 
 *   General Public License for more details.                              *
20
 
 *                                                                         *
21
 
 *   You should have received a copy of the GNU General Public License     *
22
 
 *   along with this program; if not, write to the                         *
23
 
 *   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,   *
24
 
 *   MA  02111-1307 USA                                                    *
25
 
 ***************************************************************************/
26
 
 
27
 
// Qt includes
28
 
#include <QDesktopWidget>
29
 
 
30
 
// KDE includes
31
 
#include <kmessagebox.h>
32
 
#include <klocale.h>
33
 
#include <kapplication.h>
34
 
 
35
 
// application specific includes
36
 
#include "smb4kcoremessage.h"
37
 
 
38
 
 
39
 
void Smb4KCoreMessage::error( int code, const QString &text, const QString &details )
40
 
{
41
 
  QWidget *parent = 0;
42
 
 
43
 
  if ( kapp )
44
 
  {
45
 
    if ( kapp->activeWindow() )
46
 
    {
47
 
      parent = kapp->activeWindow();
48
 
    }
49
 
    else
50
 
    {
51
 
      parent = kapp->desktop();
52
 
    }
53
 
  }
54
 
  else
55
 
  {
56
 
    // Do nothing
57
 
  }
58
 
 
59
 
  switch ( code )
60
 
  {
61
 
    case ERROR_GETTING_WORKGROUPS:
62
 
    {
63
 
      if ( details.trimmed().isEmpty() )
64
 
      {
65
 
        KMessageBox::error( parent, i18n( "<qt><p>The list of workgroups and domains could not be retrieved.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
66
 
      }
67
 
      else
68
 
      {
69
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The list of workgroups and domains could not be retrieved.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
70
 
      }
71
 
 
72
 
      break;
73
 
    }
74
 
    case ERROR_PERFORMING_IPSCAN:
75
 
    {
76
 
      if ( details.trimmed().isEmpty() )
77
 
      {
78
 
        KMessageBox::error( parent, i18n( "<qt><p>The list of registered IP addresses within the given broadcast areas could not be retrieved.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
79
 
      }
80
 
      else
81
 
      {
82
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The list of registered IP addresses within the given broadcast areas could not be retrieved.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
83
 
      }
84
 
 
85
 
      break;
86
 
    }
87
 
    case ERROR_GETTING_MEMBERS:
88
 
    {
89
 
      if ( details.trimmed().isEmpty() )
90
 
      {
91
 
        KMessageBox::error( parent, i18n( "<qt><p>The list of servers could not be retrieved.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
92
 
      }
93
 
      else
94
 
      {
95
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The list of servers could not be retrieved.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
96
 
      }
97
 
 
98
 
      break;
99
 
    }
100
 
    case ERROR_GETTING_SHARES:
101
 
    {
102
 
      if ( details.trimmed().isEmpty() )
103
 
      {
104
 
        KMessageBox::error( parent, i18n( "<qt><p>The list of shares could not be retrieved.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
105
 
      }
106
 
      else
107
 
      {
108
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The list of shares could not be retrieved.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
109
 
      }
110
 
 
111
 
      break;
112
 
    }
113
 
    case ERROR_GETTING_PREVIEW:
114
 
    {
115
 
      if ( details.trimmed().isEmpty() )
116
 
      {
117
 
        KMessageBox::error( parent, i18n( "<qt><p>The preview could not be compiled.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
118
 
      }
119
 
      else
120
 
      {
121
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The preview could not be compiled.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
122
 
      }
123
 
 
124
 
      break;
125
 
    }
126
 
    case ERROR_UNMOUNTING_NOT_ALLOWED:
127
 
    {
128
 
      KMessageBox::error( parent, i18n( "<qt>You are not allowed to unmount this share. It is owned by another user.</qt>" ) );
129
 
 
130
 
      break;
131
 
    }
132
 
    case ERROR_MOUNTING_SHARE:
133
 
    {
134
 
      if ( details.trimmed().isEmpty() )
135
 
      {
136
 
        KMessageBox::error( parent, i18n( "<qt><p>The share \"%1\" could not be mounted.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ).arg( text ) );
137
 
      }
138
 
      else
139
 
      {
140
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The share \"%1\" could not be mounted.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ).arg( text ), details );
141
 
      }
142
 
 
143
 
      break;
144
 
    }
145
 
    case ERROR_UNMOUNTING_SHARE:
146
 
    {
147
 
      if ( details.trimmed().isEmpty() )
148
 
      {
149
 
        KMessageBox::error( parent, i18n( "<qt><p>The share \"%1\" could not be unmounted.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ).arg( text ) );
150
 
      }
151
 
      else
152
 
      {
153
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The share \"%1\" could not be unmounted.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ).arg( text ), details );
154
 
      }
155
 
 
156
 
      break;
157
 
    }
158
 
    case ERROR_FILE_NOT_FOUND:
159
 
    {
160
 
      KMessageBox::error( parent, i18n( "<qt>The file \"%1\" could not be found.</qt>" ).arg( text ) );
161
 
 
162
 
      break;
163
 
    }
164
 
    case ERROR_GETTING_HOSTNAME:
165
 
    {
166
 
      if ( details.trimmed().isEmpty() )
167
 
      {
168
 
        KMessageBox::error( parent, i18n( "<qt><p>The name of your computer could not be determined by using the gethostname() system call.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
169
 
      }
170
 
      else
171
 
      {
172
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The name of your computer could not be determined by using the gethostname() system call.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
173
 
      }
174
 
 
175
 
      break;
176
 
    }
177
 
    case ERROR_MISSING_PROGRAMS:
178
 
    {
179
 
      KMessageBox::error( parent, i18n( "<qt><p>Either your PATH environment variable is not set properly or there are the following programs missing on your system:</p><p>%1</p><p>Please correct this and restart Smb4K.</p></qt>" ).arg( text ) );
180
 
 
181
 
      break;
182
 
    }
183
 
    case ERROR_MKDIR_FAILED:
184
 
    {
185
 
      KMessageBox::error( parent, i18n( "<qt>The directory \"%1\" could not be created.</qt>" ).arg( text ) );
186
 
 
187
 
      break;
188
 
    }
189
 
    case ERROR_MOUNTPOINT_EMPTY:
190
 
    {
191
 
      KMessageBox::error( parent, i18n( "<qt>The share could not be unmounted, because the mount point string was empty.</qt>" ) );
192
 
 
193
 
      break;
194
 
    }
195
 
    case ERROR_FEATURE_NOT_ENABLED:
196
 
    {
197
 
      KMessageBox::error( parent, i18n( "<qt>This feature has not been enabled.</qt>" ) );
198
 
 
199
 
      break;
200
 
    }
201
 
    case ERROR_BOOKMARK_PRINTER:
202
 
    {
203
 
      KMessageBox::error( parent, i18n( "<qt>Printers cannot be bookmarked.</qt>" ) );
204
 
 
205
 
      break;
206
 
    }
207
 
    case ERROR_SUDOWRITER:
208
 
    {
209
 
      if ( details.trimmed().isEmpty() )
210
 
      {
211
 
        KMessageBox::error( parent, i18n( "<qt><p>An error occurred while writing to the sudoers file.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
212
 
      }
213
 
      else
214
 
      {
215
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>An error occurred while writing to the sudoers file.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
216
 
      }
217
 
 
218
 
      break;
219
 
    }
220
 
    case ERROR_IMPORTING_SHARES:
221
 
    {
222
 
      if ( details.trimmed().isEmpty() )
223
 
      {
224
 
        KMessageBox::error( parent, i18n( "<qt><p>The list of mounted shares could not be imported.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
225
 
      }
226
 
      else
227
 
      {
228
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The list of mounted shares could not be imported.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
229
 
      }
230
 
 
231
 
      break;
232
 
    }
233
 
    case ERROR_COMMAND_NOT_FOUND:
234
 
    {
235
 
      KMessageBox::error( parent, i18n( "<qt>The command \"%1\" could not be found.</qt>" ).arg( text ) );
236
 
 
237
 
      break;
238
 
    }
239
 
    case ERROR_PRINTING:
240
 
    {
241
 
      if ( details.trimmed().isEmpty() )
242
 
      {
243
 
        KMessageBox::error( parent, i18n( "<qt><p>The file \"%1\" could not be printed.</p></p>Detailed information cannot be provided because there was no error message.</p></qt>" ).arg( text ) );
244
 
      }
245
 
      else
246
 
      {
247
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The file \"%1\" could not be printed.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ).arg( text ), details );
248
 
      }
249
 
 
250
 
      break;
251
 
    }
252
 
    case ERROR_CREATING_TEMP_DIR:
253
 
    {
254
 
      if ( details.trimmed().isEmpty() )
255
 
      {
256
 
        KMessageBox::error( parent, i18n( "<qt><p>The temporary directory \"%1\" could not be created.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ).arg( text ) );
257
 
      }
258
 
      else
259
 
      {
260
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The temporary directory \"%1\" could not be created.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ).arg( text ), details );
261
 
      }
262
 
 
263
 
      break;
264
 
    }
265
 
    case ERROR_SYNCHRONIZING:
266
 
    {
267
 
      if ( details.trimmed().isEmpty() )
268
 
      {
269
 
        KMessageBox::error( parent, i18n( "<qt></p>The synchronization could not be finished successfully.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
270
 
      }
271
 
      else
272
 
      {
273
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The synchronization could not be finished successfully.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
274
 
      }
275
 
 
276
 
      break;
277
 
    }
278
 
    case ERROR_SEARCHING:
279
 
    {
280
 
      if ( details.trimmed().isEmpty() )
281
 
      {
282
 
        KMessageBox::error( parent, i18n( "<qt><p>The search could not be finished successfully.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
283
 
      }
284
 
      else
285
 
      {
286
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The search could not be finished successfully.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
287
 
      }
288
 
 
289
 
      break;
290
 
    }
291
 
    case ERROR_OPENING_FILE:
292
 
    {
293
 
      if ( details.trimmed().isEmpty() )
294
 
      {
295
 
        KMessageBox::error( parent, i18n( "<qt>The file \"%1\" could not be opened.</qt>" ).arg( text ) );
296
 
      }
297
 
      else
298
 
      {
299
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>The file \"%1\" could not be opened.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ).arg( text ), details );
300
 
      }
301
 
 
302
 
      break;
303
 
    }
304
 
    case ERROR_NET_COMMAND:
305
 
    {
306
 
      KMessageBox::error( parent, i18n( "<qt>The list of arguments for the \"net\" command could not be assembled.</qt>" ) );
307
 
 
308
 
      break;
309
 
    }
310
 
    case ERROR_XML_ERROR:
311
 
    {
312
 
      if ( details.trimmed().isEmpty() )
313
 
      {
314
 
        KMessageBox::error( parent, i18n( "<qt><p>An error occurred while parsing the XML file \"%1\".</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ).arg( text ) );
315
 
      }
316
 
      else
317
 
      {
318
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>An error occurred while parsing the XML file \"%1\".</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ).arg( text ), details );
319
 
      }
320
 
 
321
 
      break;
322
 
    }
323
 
    case ERROR_UNKNOWN:
324
 
    default:
325
 
    {
326
 
      if ( details.trimmed().isEmpty() )
327
 
      {
328
 
        KMessageBox::error( parent, i18n( "<qt><p>An unknown error occurred.</p><p>Detailed information cannot be provided because there was no error message.</p></qt>" ) );
329
 
      }
330
 
      else
331
 
      {
332
 
        KMessageBox::detailedError( parent, i18n( "<qt><p>An unknown error occurred.</p><p>Read the error message under \"Details\" to find out more.</p></qt>" ), details );
333
 
      }
334
 
 
335
 
      break;
336
 
    }
337
 
  }
338
 
}
339
 
 
340
 
 
341
 
void Smb4KCoreMessage::processError( int code, QProcess::ProcessError error )
342
 
{
343
 
  QWidget *parent = 0;
344
 
 
345
 
  if ( kapp )
346
 
  {
347
 
    if ( kapp->activeWindow() )
348
 
    {
349
 
      parent = kapp->activeWindow();
350
 
    }
351
 
    else
352
 
    {
353
 
      parent = kapp->desktop();
354
 
    }
355
 
  }
356
 
  else
357
 
  {
358
 
    // Do nothing
359
 
  }
360
 
 
361
 
  switch( code )
362
 
  {
363
 
    case ERROR_PROCESS_ERROR:
364
 
    {
365
 
      switch ( error )
366
 
      {
367
 
        case QProcess::FailedToStart:
368
 
        {
369
 
          KMessageBox::error( parent, i18n( "<qt>The process failed to start (error code: %1).</qt>" ).arg( error ) );
370
 
 
371
 
          break;
372
 
        }
373
 
        case QProcess::Crashed:
374
 
        {
375
 
          KMessageBox::error( parent, i18n( "<qt>The process crashed (error code: %1).</qt>" ).arg( error ) );
376
 
 
377
 
          break;
378
 
        }
379
 
        case QProcess::Timedout:
380
 
        {
381
 
          KMessageBox::error( parent, i18n( "<qt>The process timed out (error code: %1).</qt>" ).arg( error ) );
382
 
 
383
 
          break;
384
 
        }
385
 
        case QProcess::WriteError:
386
 
        {
387
 
          KMessageBox::error( parent, i18n( "<qt>Could not write to the process (error code: %1).</qt>" ).arg( error ) );
388
 
 
389
 
          break;
390
 
        }
391
 
        case QProcess::ReadError:
392
 
        {
393
 
          KMessageBox::error( parent, i18n( "<qt>Could not read from the process (error code: %1).</qt>" ).arg( error ) );
394
 
 
395
 
          break;
396
 
        }
397
 
        case QProcess::UnknownError:
398
 
        default:
399
 
        {
400
 
          KMessageBox::error( parent, i18n( "<qt>The process reported an unknown error.</qt>" ) );
401
 
 
402
 
          break;
403
 
        }
404
 
      }
405
 
 
406
 
      break;
407
 
    }
408
 
    case ERROR_PROCESS_EXIT:
409
 
    {
410
 
      KMessageBox::error( parent, i18n( "<qt>The process exited unexpectedly.</qt>" ) );
411
 
 
412
 
      break;
413
 
    }
414
 
    default:
415
 
    {
416
 
      break;
417
 
    }
418
 
  }
419
 
}
420
 
 
421
 
 
422
 
int Smb4KCoreMessage::warning( int code, const QString &/*text*/, const QString &/*details*/ )
423
 
{
424
 
  QWidget *parent = 0;
425
 
 
426
 
  if ( kapp )
427
 
  {
428
 
    if ( kapp->activeWindow() )
429
 
    {
430
 
      parent = kapp->activeWindow();
431
 
    }
432
 
    else
433
 
    {
434
 
      parent = kapp->desktop();
435
 
    }
436
 
  }
437
 
  else
438
 
  {
439
 
    // Do nothing
440
 
  }
441
 
 
442
 
  int result = 0;
443
 
 
444
 
  switch ( code )
445
 
  {
446
 
    default:
447
 
    {
448
 
      break;
449
 
    }
450
 
  }
451
 
 
452
 
  return result;
453
 
}
454
 
 
455
 
 
456
 
void Smb4KCoreMessage::information( int code, const QString &text, const QString &details )
457
 
{
458
 
  QWidget *parent = 0;
459
 
 
460
 
  if ( kapp )
461
 
  {
462
 
    if ( kapp->activeWindow() )
463
 
    {
464
 
      parent = kapp->activeWindow();
465
 
    }
466
 
    else
467
 
    {
468
 
      parent = kapp->desktop();
469
 
    }
470
 
  }
471
 
  else
472
 
  {
473
 
    // Do nothing
474
 
  }
475
 
 
476
 
  switch ( code )
477
 
  {
478
 
    case INFO_MIMETYPE_NOT_SUPPORTED:
479
 
    {
480
 
      KMessageBox::information( parent, i18n( "<qt>The mimetype \"%1\" is not supported. Please convert the file to PostScript or PDF.</qt>" ).arg( text ) );
481
 
 
482
 
      break;
483
 
    }
484
 
    case INFO_DISABLE_SUID_FEATURE:
485
 
    {
486
 
      KMessageBox::information( parent, i18n( "<qt>You previously chose to use \"%1\", but now it is missing on your system. Smb4K will disable this feature.</qt>" ).arg( text ) );
487
 
 
488
 
      break;
489
 
    }
490
 
    case INFO_BOOKMARK_LABEL_IN_USE:
491
 
    {
492
 
      KMessageBox::information( parent, i18n( "<qt>The label \"%1\" is used more than once. It will automatically be renamed for bookmark \"%2\" to avoid confusion.</qt>" ).arg( text, details ) );
493
 
 
494
 
      break;
495
 
    }
496
 
    case INFO_OPENING_WALLET_FAILED:
497
 
    {
498
 
      KMessageBox::information( parent, i18n( "<qt>The wallet \"%1\" could not be opened. KWallet support will be disabled for this session.</qt>" ).arg( text ) );
499
 
 
500
 
      break;
501
 
    }
502
 
    default:
503
 
    {
504
 
      break;
505
 
    }
506
 
  }
507
 
}
508