• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kget

  • sources
  • kde-4.12
  • kdenetwork
  • kget
  • core
urlchecker.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright (C) 2007-2009 Lukas Appelhans <l.appelhans@gmx.de> *
3 * Copyright (C) 2008 Dario Freddi <drf54321@gmail.com> *
4 * Copyright (C) 2010 Matthias Fuchs <mat69@gmx.net> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
20 ***************************************************************************/
21 
22 #include "urlchecker.h"
23 #include "urlchecker_p.h"
24 #include "mainwindow.h"
25 #include "core/filedeleter.h"
26 #include "core/kget.h"
27 #include "core/transferhandler.h"
28 #include "core/transfertreemodel.h"
29 #include "settings.h"
30 
31 #include <algorithm>
32 #include <boost/bind.hpp>
33 
34 #include <QtCore/QFileInfo>
35 #include <QtGui/QCheckBox>
36 #include <QtGui/QHBoxLayout>
37 
38 #include <KDialogButtonBox>
39 #include <KIO/RenameDialog>
40 #include <KLocale>
41 #include <KSeparator>
42 #include <KStandardGuiItem>
43 
44 ExistingTransferDialog::ExistingTransferDialog(const QString &text, const QString &caption, QWidget *parent)
45  : KDialog(parent)
46 {
47  setCaption(caption.isEmpty() ? i18n("Question") : caption);
48  setModal(true);
49  setButtons(0);
50 
51  QWidget *widget = new QWidget(this);
52  QVBoxLayout *layout = new QVBoxLayout;
53  QHBoxLayout *bottomLayout = new QHBoxLayout;
54 
55  QLabel *label = new QLabel(text, this);
56  layout->addWidget(label);
57  layout->addWidget(new KSeparator(Qt::Horizontal, this));
58 
59  m_applyAll = new QCheckBox(i18n("Appl&y to all"), this);
60  bottomLayout->addStretch(1);
61  bottomLayout->addWidget(m_applyAll);
62 
63  KDialogButtonBox *buttonBox = new KDialogButtonBox(this);
64  buttonBox->addButton(KStandardGuiItem::yes(), QDialogButtonBox::YesRole, this, SLOT(slotYesClicked()));
65  buttonBox->addButton(KStandardGuiItem::no(), QDialogButtonBox::NoRole, this, SLOT(slotNoClicked()));
66  buttonBox->addButton(KStandardGuiItem::cancel(), QDialogButtonBox::RejectRole, this, SLOT(slotCancelClicked()));
67  bottomLayout->addWidget(buttonBox);
68  layout->addLayout(bottomLayout, 0);
69 
70  widget->setLayout(layout);
71  setMainWidget(widget);
72 }
73 
74 void ExistingTransferDialog::slotYesClicked()
75 {
76  done(m_applyAll->isChecked() ? KDialog::User2 : KDialog::Yes);
77 }
78 
79 void ExistingTransferDialog::slotNoClicked()
80 {
81  done(m_applyAll->isChecked() ? KDialog::User1 : KDialog::No);
82 }
83 
84 void ExistingTransferDialog::slotCancelClicked()
85 {
86  done(QDialog::Rejected);
87 }
88 
89 
90 UrlChecker::UrlChecker(UrlType type)
91  : m_type(type),
92  m_cancle(false),
93  m_overwriteAll(false),
94  m_autoRenameAll(false),
95  m_skipAll(false)
96 {
97 }
98 
99 UrlChecker::~UrlChecker()
100 {
101 }
102 
104 
105 struct lessThan
106 {
107  bool operator()(const KUrl &lhs, const KUrl &rhs) const
108  {
109  return lhs.url() < rhs.url();
110  }
111 };
112 
113 void UrlChecker::removeDuplicates(KUrl::List &urls)
114 {
115  std::sort(urls.begin(), urls.end(), lessThan());//sort the urls, to find duplicates fast
116  urls.erase(std::unique(urls.begin(), urls.end(),
117  boost::bind(&KUrl::equals, _1, _2, KUrl::CompareWithoutTrailingSlash | KUrl::AllowEmptyPath)), urls.end());
118 }
119 
120 UrlChecker::UrlError UrlChecker::checkUrl(const KUrl &url, const UrlChecker::UrlType type, bool showNotification)
121 {
122  switch (type) {
123  case Source:
124  return checkSource(url, showNotification);
125  case Destination:
126  return checkDestination(url, showNotification);
127  case Folder:
128  return checkFolder(url, showNotification);
129  }
130 
131  return NoError;
132 }
133 
134 bool UrlChecker::wouldOverwrite(const KUrl &source, const KUrl &dest)
135 {
136  return (dest.isLocalFile() && QFile::exists(dest.toLocalFile()) && source != dest && !FileDeleter::isFileBeingDeleted(dest));
137 }
138 
139 UrlChecker::UrlError UrlChecker::checkSource(const KUrl &src, bool showNotification)
140 {
141  //NOTE hasPath is not used, as this would dissallow adresses like http://www.kde.org/ as there is no path
142  UrlError error = NoError;
143  if (src.isEmpty()) {
144  return Empty;
145  }
146  if ((error == NoError) && !src.isValid()) {
147  error = Invalid;
148  }
149  if ((error == NoError) && src.protocol().isEmpty()){
150  error = NoProtocol;
151  }
152  /*if ((error == NoError) && !src.hasHost()) {//FIXME deactivated to allow file://....metalink etc
153  error = NoHost;
154  }*/
155 
156  if (showNotification && (error != NoError)) {
157  kDebug(5001) << "Source:" << src << "has error:" << error;
158  KGet::showNotification(KGet::m_mainWindow, "error", message(src, Source, error));
159  }
160 
161  //TODO also check sourceUrl.url() != KUrl(sourceUrl.url()).fileName() as in NewTransferDialog::setSource?
162 
163  return error;
164 }
165 
166 UrlChecker::UrlError UrlChecker::checkDestination(const KUrl &destination, bool showNotification)
167 {
168  UrlError error = NoError;
169 
170  if (destination.isEmpty()) {
171  error = Empty;
172  }
173 
174  if (error == NoError) {
175  //not supposed to be a folder
176  QFileInfo fileInfo(destination.pathOrUrl());
177  if (!destination.isValid() || fileInfo.isDir()) {
178  error = Invalid;
179  }
180 
181  if ((error == NoError) && !QFileInfo(destination.directory()).isWritable()) {
182  error = NotWriteable;
183  }
184  }
185 
186  if (showNotification && (error != NoError)) {
187  kDebug(5001) << "Destination:" << destination << "has error:" << error;
188  KGet::showNotification(KGet::m_mainWindow, "error", message(destination, Destination, error));
189  }
190 
191  return error;
192 }
193 
194 
195 UrlChecker::UrlError UrlChecker::checkFolder(const KUrl &folder, bool showNotification)
196 {
197  UrlError error = NoError;
198 
199  const QString destDir = folder.pathOrUrl();
200  if (folder.isEmpty() || destDir.isEmpty()) {
201  error = Empty;
202  }
203 
204  if (error == NoError) {
205  //has to be a folder
206  QFileInfo fileInfo(destDir);
207  if (!folder.isValid() || !fileInfo.isDir()) {
208  error = Invalid;
209  }
210 
211  //has to be writeable
212  if ((error == NoError) && !fileInfo.isWritable()) {
213  error = NotWriteable;
214  }
215  }
216 
217  if (showNotification && (error != NoError)) {
218  kDebug(5001) << "Folder:" << folder << "has error:" << error;
219  KGet::showNotification(KGet::m_mainWindow, "error", message(folder, Folder, error));
220  }
221 
222  return error;
223 }
224 
225 KUrl UrlChecker::destUrl(const KUrl &destOrFolder, const KUrl &source, const QString &fileName)
226 {
227  KUrl dest = destOrFolder;
228  if (QFileInfo(dest.toLocalFile()).isDir()) {
229  QString usedFileName = (fileName.isEmpty() ? source.fileName() : fileName);
230  if (usedFileName.isEmpty()) {
231  usedFileName = KUrl::toPercentEncoding(source.prettyUrl(), "/");
232  }
233  dest.adjustPath(KUrl::AddTrailingSlash);
234  dest.setFileName(usedFileName);
235  } else if (!fileName.isEmpty()) {
236  dest.setFileName(fileName);
237  }
238 
239  return dest;
240 }
241 
242 TransferHandler *UrlChecker::existingTransfer(const KUrl &url, const UrlChecker::UrlType type, UrlChecker::UrlWarning *warning)
243 {
244  UrlWarning temp;
245  UrlWarning &warn = (warning ? (*warning) : temp);
246  warn = NoWarning;
247 
248  switch (type) {
249  case Source:
250  return existingSource(url, warn);
251  case Destination:
252  return existingDestination(url, warn);
253  default:
254  return 0;
255  }
256 }
257 
258 TransferHandler *UrlChecker::existingSource(const KUrl &source, UrlChecker::UrlWarning &warning)
259 {
260  // Check if a transfer with the same url already exists
261  Transfer *transfer = KGet::m_transferTreeModel->findTransfer(source);
262  if (transfer) {
263  if (transfer->status() == Job::Finished) {
264  warning = ExistingFinishedTransfer;
265  } else {
266  warning = ExistingTransfer;
267  }
268  }
269 
270  return (transfer ? transfer->handler() : 0);
271 }
272 
273 TransferHandler *UrlChecker::existingDestination(const KUrl &url, UrlChecker::UrlWarning &warning)
274 {
275  Transfer *transfer = KGet::m_transferTreeModel->findTransferByDestination(url);
276  if (transfer) {
277  if (transfer->status() == Job::Finished) {
278  warning = ExistingFinishedTransfer;
279  } else {
280  warning = ExistingTransfer;
281  }
282  } else if (QFile::exists(url.pathOrUrl())) {
283  warning = ExistingFile;
284  }
285 
286  return (transfer ? transfer->handler() : 0);
287 }
288 
289 
290 QString UrlChecker::message(const KUrl &url, const UrlChecker::UrlType type, const UrlChecker::UrlError error)
291 {
292  if (url.isEmpty()) {
293  if (type == Folder) {
294  switch (error) {
295  case Empty:
296  return i18n("No download directory specified.");
297  case Invalid:
298  return i18n("Invalid download directory specified.");
299  case NotWriteable:
300  return i18n("Download directory is not writeable.");
301  default:
302  return QString();
303  }
304  }
305  if (type == Destination) {
306  switch (error) {
307  case Empty:
308  return i18n("No download destination specified.");
309  case Invalid:
310  return i18n("Invalid download destination specified.");
311  case NotWriteable:
312  return i18n("Download destination is not writeable.");
313  default:
314  return QString();
315  }
316  }
317  if (type == Source) {
318  switch (error) {
319  case Empty:
320  return i18n("No URL specified.");
321  case Invalid:
322  return i18n("Malformed URL.");
323  case NoProtocol:
324  return i18n("Malformed URL, protocol missing.");
325  case NoHost:
326  return i18n("Malformed URL, host missing.");
327  default:
328  return QString();
329  }
330  }
331  } else {
332  const QString urlString = url.prettyUrl();
333  if (type == Folder) {
334  switch (error) {
335  case Empty:
336  return i18n("No download directory specified.");
337  case Invalid:
338  return i18n("Invalid download directory specified:\n%1", urlString);
339  case NotWriteable:
340  return i18n("Download directory is not writeable:\n%1", urlString);
341  default:
342  return QString();
343  }
344  }
345  if (type == Destination) {
346  switch (error) {
347  case Empty:
348  return i18n("No download destination specified.");
349  case Invalid:
350  return i18n("Invalid download destination specified:\n%1", urlString);
351  case NotWriteable:
352  return i18n("Download destination is not writeable:\n%1", urlString);
353  default:
354  return QString();
355  }
356  }
357  if (type == Source) {
358  switch (error) {
359  case Empty:
360  return i18n("No URL specified.");
361  case Invalid:
362  return i18n("Malformed URL:\n%1", urlString);
363  case NoProtocol:
364  return i18n("Malformed URL, protocol missing:\n%1", urlString);
365  case NoHost:
366  return i18n("Malformed URL, host missing:\n%1", urlString);
367  default:
368  return QString();
369  }
370  }
371  }
372 
373  return QString();
374 }
375 
376 QString UrlChecker::message(const KUrl &url, const UrlChecker::UrlType type, const UrlChecker::UrlWarning warning)
377 {
378  if (url.isEmpty()) {
379  if (type == Destination) {
380  switch (warning) {
381  case ExistingFile:
382  return i18n("File already exists. Overwrite it?");
383  case ExistingFinishedTransfer:
384  return i18n("You have already downloaded that file from another location.\nDownload and delete the previous one?");
385  case ExistingTransfer:
386  return i18n("You are already downloading that file from another location.\nDownload and delete the previous one?");
387  default:
388  return QString();
389  }
390  }
391  if (type == Source) {
392  switch (warning) {
393  case ExistingFile:
394  return i18n("File already exists. Overwrite it?");
395  case ExistingFinishedTransfer:
396  return i18n("You have already completed a download from that location. Download it again?");
397  case ExistingTransfer:
398  return i18n("You have a download in progress from that location.\nDelete it and download again?");
399  default:
400  return QString();
401  }
402  }
403  } else {
404  const QString urlString = url.prettyUrl();
405  if (type == Destination) {
406  switch (warning) {
407  case ExistingFile:
408  return i18n("File already exists:\n%1\nOverwrite it?", urlString);
409  case ExistingFinishedTransfer:
410  return i18n("You have already downloaded that file from another location.\nDownload and delete the previous one?");
411  case ExistingTransfer:
412  return i18n("You are already downloading that file from another location.\nDownload and delete the previous one?");
413  default:
414  return QString();
415  }
416  }
417  if (type == Source) {
418  switch (warning) {
419  case ExistingFinishedTransfer:
420  return i18n("You have already completed a download from the location: \n\n%1\n\nDownload it again?", urlString);
421  case ExistingTransfer:
422  return i18n("You have a download in progress from the location: \n\n%1\n\nDelete it and download again?", urlString);
423  default:
424  return QString();
425  }
426  }
427  }
428 
429  return QString();
430 }
431 
432 QString UrlChecker::message(const KUrl::List &urls, const UrlChecker::UrlType type, const UrlChecker::UrlError error)
433 {
434  QString urlsString;
435  if (!urls.isEmpty()) {
436  urlsString = urls.first().prettyUrl();
437  for (int i = 1; i < urls.count(); ++i) {
438  urlsString += '\n' + urls[i].prettyUrl();
439  }
440  urlsString = QString("<p style=\"font-size: small;\">\%1</p>").arg(urlsString);
441  }
442 
443  if (urls.isEmpty()) {
444  if ((type == Folder) || (type == Destination)) {
445  return message(KUrl(), type, error);
446  }
447  if (type == Source) {
448  switch (error) {
449  case Empty:
450  return i18n("No URL specified.");
451  case Invalid:
452  return i18n("Malformed URLs.");
453  case NoProtocol:
454  return i18n("Malformed URLs, protocol missing.");
455  case NoHost:
456  return i18n("Malformed URLs, host missing.");
457  default:
458  return QString();
459  }
460  }
461  } else {
462  switch (error) {
463  case Empty:
464  return i18n("No URL specified.");
465  case Invalid:
466  return i18n("Malformed URLs:\n%1", urlsString);
467  case NoProtocol:
468  return i18n("Malformed URLs, protocol missing:\n%1", urlsString);
469  case NoHost:
470  return i18n("Malformed URLs, host missing:\n%1", urlsString);
471  case NotWriteable:
472  return i18n("Destinations are not writable:\n%1", urlsString);
473  default:
474  return QString();
475  }
476  }
477 
478  return QString();
479 }
480 
481 QString UrlChecker::message(const KUrl::List &urls, const UrlChecker::UrlType type, const UrlChecker::UrlWarning warning)
482 {
483  QString urlsString;
484  if (!urls.isEmpty()) {
485  urlsString = urls.first().prettyUrl();
486  for (int i = 1; i < urls.count(); ++i) {
487  urlsString += '\n' + urls[i].prettyUrl();
488  }
489  urlsString = QString("<p style=\"font-size: small;\">\%1</p>").arg(urlsString);
490  }
491 
492  if (urls.isEmpty()) {
493  if (type == Destination) {
494  switch (warning) {
495  case ExistingFile:
496  return i18n("Files exist already. Overwrite them?");
497  case ExistingFinishedTransfer:
498  return i18n("You have already completed downloads at those destinations. Download them again?");
499  case ExistingTransfer:
500  return i18n("You have downloads in progress to these destinations.\nDelete them and download again?");
501  default:
502  return QString();
503  }
504  }
505  if (type == Source) {
506  switch (warning) {
507  case ExistingFinishedTransfer:
508  return i18n("You have already completed downloads from these locations. Download them again?");
509  case ExistingTransfer:
510  return i18n("You have downloads in progress from these locations.\nDelete them and download again?");
511  default:
512  return QString();
513  }
514  }
515  } else {
516  if (type == Destination) {
517  switch (warning) {
518  case ExistingFile:
519  return i18n("Files exist already:\n%1\nOverwrite them?", urlsString);
520  case ExistingFinishedTransfer:
521  return i18n("You have already completed downloads at those destinations: \n\n%1\n\n Download them again?", urlsString);
522  case ExistingTransfer:
523  return i18n("You have downloads in progress to these destinations: \n\n%1\n\nDelete them and download again?", urlsString);
524  default:
525  return QString();
526  }
527  }
528  if (type == Source) {
529  switch (warning) {
530  case ExistingFinishedTransfer:
531  return i18n("You have already completed downloads from these locations: \n\n%1\n\nDownload them again?", urlsString);
532  case ExistingTransfer:
533  return i18n("You have downloads in progress from these locations: \n\n%1\n\nDelete them and download again?", urlsString);
534  default:
535  QString();
536  }
537  }
538  }
539 
540  return QString();
541 }
542 
543 
544 KUrl::List UrlChecker::hasExistingTransferMessages(const KUrl::List &urls, const UrlChecker::UrlType type)
545 {
546  UrlWarning warning;
547  QHash<UrlWarning, QList<QPair<KUrl, TransferHandler*> > > splitWarnings;
548  KUrl::List urlsToDownload;
549 
550  //collect all errors
551  foreach(const KUrl &url, urls) {
552  TransferHandler *transfer = existingTransfer(url, type, &warning);
553  if (transfer) {
554  splitWarnings[warning] << qMakePair(url, transfer);
555  } else {
556  urlsToDownload << url;
557  }
558  }
559 
560  //First ask about unfinished existing transfers
561  QList<QPair<KUrl, TransferHandler*> >::const_iterator it;
562  QList<QPair<KUrl, TransferHandler*> >::const_iterator itEnd;
563  QList<UrlWarning> orderOfExecution;
564  QList<TransferHandler*> toDelete;
565  orderOfExecution << ExistingTransfer << ExistingFinishedTransfer;
566  for (int i = 0; i < orderOfExecution.count(); ++i) {
567  warning = orderOfExecution[i];
568  if (splitWarnings.contains(warning)) {
569  QList<QPair<KUrl, TransferHandler*> > existing = splitWarnings[warning];
570  itEnd = existing.constEnd();
571  bool isYesAll = false;
572  bool isNoAll = false;
573  for (it = existing.constBegin(); it != itEnd; ++it) {
574  if (isYesAll) {
575  urlsToDownload << it->first;
576  toDelete << it->second;
577  continue;
578  }
579 
580  if (isNoAll) {
581  break;
582  }
583 
584  int result;
585  if (Settings::filesOverwrite() || (Settings::filesAutomaticRename() && (warning != ExistingTransfer))) {
586  result = YesAll;
587  } else {
588  result = hasExistingDialog(it->first, type, warning);
589  }
590  switch (result) {
591  case YesAll:
592  isYesAll = true;
593  case Yes:
594  urlsToDownload << it->first;
595  toDelete << it->second;
596  break;
597  case NoAll:
598  isNoAll = true;
599  case No:
600  break;
601  case Cancel:
602  default:
603  removeTransfers(toDelete);
604  return urlsToDownload;
605  }
606  }
607  }
608  }
609 
610  removeTransfers(toDelete);
611  return urlsToDownload;
612 }
613 
614 void UrlChecker::removeTransfers(const QList<TransferHandler*> &toRemove)
615 {
616  QList<TransferHandler*> transfers = toRemove;
617  transfers.removeAll(0);
618  if (!transfers.isEmpty()) {
619  KGet::delTransfers(transfers);
620  }
621 }
622 
623 
624 int UrlChecker::hasExistingDialog(const KUrl &url, const UrlChecker::UrlType type, const UrlChecker::UrlWarning warning)
625 {
626  QWidget *parent = KGet::m_mainWindow;
627 
628  //getting the caption
629  QString caption;
630  if (type == Source) {
631  switch (warning) {
632  case ExistingFinishedTransfer:
633  caption = i18n("Delete it and download again?");
634  break;
635  case ExistingTransfer:
636  caption = i18n("Download it again?");
637  break;
638  default:
639  break;
640  }
641  } else if (type == Destination) {
642  switch (warning) {
643  case ExistingFinishedTransfer:
644  case ExistingTransfer:
645  caption = i18n("File already downloaded. Download anyway?");
646  break;
647  case ExistingFile:
648  caption = i18n("File already exists");
649  break;
650  default:
651  break;
652  }
653  }
654 
655  QScopedPointer<KDialog> dialog(new ExistingTransferDialog(message(url, type, warning), caption, parent));
656 
657  const int result = dialog->exec();
658  switch (result) {
659  case QDialog::Rejected:
660  return Cancel;
661  case KDialog::Yes:
662  return Yes;
663  case KDialog::User2:
664  return YesAll;
665  case KDialog::No:
666  return No;
667  case KDialog::User1:
668  return NoAll;
669  default:
670  return result;
671  }
672 }
673 
675 
676 void UrlChecker::clear()
677 {
678  m_correctUrls.clear();
679  m_splitErrorUrls.clear();
680  m_cancle = false;
681  m_overwriteAll = false;
682  m_autoRenameAll = false;
683  m_skipAll = false;
684 }
685 
686 UrlChecker::UrlType UrlChecker::type() const
687 {
688  return m_type;
689 }
690 
691 void UrlChecker::setType(UrlChecker::UrlType type)
692 {
693  clear();
694  m_type = type;
695 }
696 
697 UrlChecker::UrlError UrlChecker::addUrl(const KUrl &url)
698 {
699  const UrlError error = checkUrl(url, m_type);
700  if (error == NoError) {
701  m_correctUrls << url;
702  } else {
703  m_splitErrorUrls[error] << url;
704  }
705 
706  return error;
707 }
708 
709 bool UrlChecker::addUrls(const KUrl::List &urls)
710 {
711  bool worked = true;
712  foreach (const KUrl &url, urls) {
713  const UrlError error = addUrl(url);
714  if (error != NoError) {
715  worked = false;
716  }
717  }
718 
719  return worked;
720 }
721 
722 void UrlChecker::existingTransfers()
723 {
724  m_correctUrls = hasExistingTransferMessages(correctUrls(), m_type);
725 }
726 
727 KUrl UrlChecker::checkExistingFile(const KUrl &source, const KUrl &destination)
728 {
729  KUrl newDestination = destination;
730 
731  //any url is ignored
732  if (m_cancle) {
733  return KUrl();
734  }
735 
736  if (Settings::filesOverwrite()) {
737  m_overwriteAll = true;
738  } else if (Settings::filesAutomaticRename()) {
739  m_autoRenameAll = true;
740  }
741 
742  if (wouldOverwrite(source, destination)) {
743  KIO::RenameDialog_Mode args = static_cast<KIO::RenameDialog_Mode>(KIO::M_MULTI | KIO::M_SKIP | KIO::M_OVERWRITE);
744  QScopedPointer<KIO::RenameDialog> dlg(new KIO::RenameDialog(KGet::m_mainWindow, i18n("File already exists"), source,
745  destination, args));
746 
748  if (m_skipAll) { //only existing are ignored
749  return KUrl();
750  } else if (m_overwriteAll) {
751  FileDeleter::deleteFile(newDestination);
752  return newDestination;
753  } else if (m_autoRenameAll) {
754  newDestination = dlg->autoDestUrl();
755  return newDestination;
756  }
757 
759  const int result = dlg->exec();
760  switch (result) {
761  case KIO::R_OVERWRITE: {
762  //delete the file, that way it won't show up in future calls of this method
763  FileDeleter::deleteFile(newDestination);
764  return newDestination;
765  }
766  case KIO::R_OVERWRITE_ALL: {
767 
768  //delete the file, that way it won't show up in future calls of this method
769  FileDeleter::deleteFile(newDestination);
770  m_overwriteAll = true;
771  return newDestination;
772  }
773  case KIO::R_RENAME:
774  //call it again, as there is no check on the user input
775  return checkExistingFile(source, dlg->newDestUrl());
776  case KIO::R_AUTO_RENAME:
777  newDestination = dlg->autoDestUrl();
778  m_autoRenameAll = true;
779  return newDestination;
780  case KIO::R_SKIP:
781  return KUrl();
782  case KIO::R_AUTO_SKIP:
783  m_skipAll = true;
784  return KUrl();
785  case KIO::R_CANCEL:
786  m_cancle = true;
787  return KUrl();
788  default:
789  return KUrl();
790  }
791  }
792 
793  return newDestination;
794 }
795 
796 
797 KUrl::List UrlChecker::correctUrls() const
798 {
799  return m_correctUrls;
800 }
801 
802 KUrl::List UrlChecker::errorUrls() const
803 {
804  KUrl::List urls;
805 
806  QHash<UrlChecker::UrlError, KUrl::List>::const_iterator it;
807  QHash<UrlChecker::UrlError, KUrl::List>::const_iterator itEnd = m_splitErrorUrls.constEnd();
808  for (it = m_splitErrorUrls.constBegin(); it != itEnd; ++it) {
809  urls << (*it);
810  }
811 
812  return urls;
813 }
814 
815 QHash<UrlChecker::UrlError, KUrl::List> UrlChecker::splitErrorUrls() const
816 {
817  return m_splitErrorUrls;
818 }
819 
820 void UrlChecker::displayErrorMessages()
821 {
822  QHash<UrlChecker::UrlError, KUrl::List>::const_iterator it;
823  QHash<UrlChecker::UrlError, KUrl::List>::const_iterator itEnd = m_splitErrorUrls.constEnd();
824  for (it = m_splitErrorUrls.constBegin(); it != itEnd; ++it) {
825  QString m;
826  if (it->count() > 1) {
827  m = message(*it, m_type, it.key());
828  } else if (!it->isEmpty()) {
829  m = message(it->first(), m_type, it.key());
830  }
831 
832  if (!m.isEmpty()) {
833  KGet::showNotification(KGet::m_mainWindow, "error", m);
834  }
835  }
836 }
TransferTreeModel::findTransfer
Transfer * findTransfer(const KUrl &src)
Definition: transfertreemodel.cpp:467
TransferHandler
Class TransferHandler:
Definition: transferhandler.h:48
UrlChecker::NoError
Definition: urlchecker.h:61
kt::no
static KIcon no
Definition: peerviewmodel.cpp:33
Job::Finished
The job is stopped, but this also indicates that it stopped because an error occurred.
Definition: job.h:47
UrlChecker::correctUrls
KUrl::List correctUrls() const
Returns the correct urls collected with the last call to urlCollectErrors.
Definition: urlchecker.cpp:797
transfertreemodel.h
KGet::delTransfers
static bool delTransfers(const QList< TransferHandler * > &transfers, DeleteMode mode=AutoDelete)
Removes multiple transfers from the KGet.
Definition: kget.cpp:367
QWidget
urlchecker.h
UrlChecker::checkDestination
static UrlError checkDestination(const KUrl &destination, bool showNotification=false)
Convenience method of checkUrl.
Definition: urlchecker.cpp:166
UrlChecker::ExistingTransfer
Definition: urlchecker.h:77
KDialog
UrlChecker::checkUrl
static UrlError checkUrl(const KUrl &url, const UrlType type, bool showNotification=false)
Folder: Checks if the destination url points to is a folder that is writeable and existent...
Definition: urlchecker.cpp:120
UrlChecker::clear
void clear()
Clears all data, like correctUrls, errorUrls, responses from checkExistingFile ...
Definition: urlchecker.cpp:676
FileDeleter::deleteFile
static KJob * deleteFile(const KUrl &dest, QObject *receiver=0, const char *method=0)
Starts the deletion of dest and emits KJob::finished once done.
Definition: filedeleter.cpp:73
UrlChecker::UrlChecker
UrlChecker(UrlType type)
Before using UrlChecker you have to specify a type You can either do that in the constructor and late...
Definition: urlchecker.cpp:90
UrlChecker::type
UrlType type() const
Non static methods following.
Definition: urlchecker.cpp:686
UrlChecker::Folder
Definition: urlchecker.h:40
Settings::filesAutomaticRename
static bool filesAutomaticRename()
Get FilesAutomaticRename.
Definition: settings.h:563
UrlChecker::hasExistingTransferMessages
static KUrl::List hasExistingTransferMessages(const KUrl::List &urls, const UrlType type)
Definition: urlchecker.cpp:544
UrlChecker::UrlError
UrlError
Definition: urlchecker.h:59
UrlChecker::errorUrls
KUrl::List errorUrls() const
Returns all wrong urls.
Definition: urlchecker.cpp:802
UrlChecker::Source
Definition: urlchecker.h:38
UrlChecker::addUrl
UrlError addUrl(const KUrl &url)
Checks url of type()
Definition: urlchecker.cpp:697
UrlChecker::Empty
Definition: urlchecker.h:62
UrlChecker::destUrl
static KUrl destUrl(const KUrl &destOrFolder, const KUrl &source, const QString &fileName=QString())
Takes an url to a source and an url to either the destination or a folder and returns a destination u...
Definition: urlchecker.cpp:225
urlchecker_p.h
mainwindow.h
UrlChecker::NoHost
Definition: urlchecker.h:67
UrlChecker::existingTransfers
void existingTransfers()
Checks all correctUrls() if there are existing Transfers for the specified UrlType and asks the user ...
Definition: urlchecker.cpp:722
ExistingTransferDialog::ExistingTransferDialog
ExistingTransferDialog(const QString &text, const QString &caption, QWidget *parent=0)
Definition: urlchecker.cpp:44
UrlChecker::addUrls
bool addUrls(const KUrl::List &urls)
Does checkUrl for a list of urls.
Definition: urlchecker.cpp:709
UrlChecker::message
static QString message(const KUrl &url, const UrlType type, const UrlError error)
Get a describing message for UrlError.
Definition: urlchecker.cpp:290
UrlChecker::existingTransfer
static TransferHandler * existingTransfer(const KUrl &url, const UrlType type, UrlWarning *warning=0)
Checks if there is an existing transfer for url with type.
Definition: urlchecker.cpp:242
UrlChecker::NoWarning
Definition: urlchecker.h:74
UrlChecker::checkSource
static UrlError checkSource(const KUrl &source, bool showNotification=false)
Convenience method of checkUrl.
Definition: urlchecker.cpp:139
transferhandler.h
UrlChecker::ExistingFinishedTransfer
Definition: urlchecker.h:76
filedeleter.h
Settings::filesOverwrite
static bool filesOverwrite()
Get FilesOverwrite.
Definition: settings.h:582
UrlChecker::~UrlChecker
~UrlChecker()
Definition: urlchecker.cpp:99
UrlChecker::NoProtocol
Definition: urlchecker.h:66
UrlChecker::Invalid
Definition: urlchecker.h:63
settings.h
Job::status
Status status() const
Definition: job.h:93
UrlChecker::removeDuplicates
static void removeDuplicates(KUrl::List &urls)
Removes duplicates of a list of urls.
Definition: urlchecker.cpp:113
Transfer::handler
TransferHandler * handler()
Definition: transfer.cpp:217
TransferTreeModel::findTransferByDestination
Transfer * findTransferByDestination(const KUrl &dest)
Definition: transfertreemodel.cpp:483
UrlChecker::splitErrorUrls
QHash< UrlError, KUrl::List > splitErrorUrls() const
Returns all wrong urls collected with the last call to urlCollectErrors or existingTransfers categori...
Definition: urlchecker.cpp:815
UrlChecker::Destination
Definition: urlchecker.h:39
kget.h
UrlChecker::checkExistingFile
KUrl checkExistingFile(const KUrl &source, const KUrl &destination)
Checks if the file at destination exists already, source needs to be defined to have a nice dialog an...
Definition: urlchecker.cpp:727
KGet::showNotification
static KNotification * showNotification(QWidget *parent, const QString &eventType, const QString &text, const QString &icon=QString("dialog-error"), const QString &title=i18n("KGet"), const KNotification::NotificationFlags &flags=KNotification::CloseOnTimeout)
Shows a knotification.
Definition: kget.cpp:1281
UrlChecker::NotWriteable
Definition: urlchecker.h:70
kt::yes
static KIcon yes
Definition: peerviewmodel.cpp:33
FileDeleter::isFileBeingDeleted
static bool isFileBeingDeleted(const KUrl &dest)
Definition: filedeleter.cpp:78
ExistingTransferDialog
Asks if existing transfers should be overwritten.
Definition: urlchecker_p.h:30
UrlChecker::UrlWarning
UrlWarning
Definition: urlchecker.h:73
UrlChecker::displayErrorMessages
void displayErrorMessages()
Displays error messages for the collected urls if any are needed.
Definition: urlchecker.cpp:820
UrlChecker::ExistingFile
Definition: urlchecker.h:80
UrlChecker::checkFolder
static UrlError checkFolder(const KUrl &folder, bool showNotification=false)
Convenience method of checkUrl.
Definition: urlchecker.cpp:195
UrlChecker::wouldOverwrite
static bool wouldOverwrite(const KUrl &source, const KUrl &dest)
Checks if source is local and exists already.
Definition: urlchecker.cpp:134
UrlChecker::setType
void setType(UrlType type)
Sets the type for the following operations to type.
Definition: urlchecker.cpp:691
UrlChecker::UrlType
UrlType
Definition: urlchecker.h:37
Transfer
Definition: transfer.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:18 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kget

Skip menu "kget"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal