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

kget

  • sources
  • kde-4.14
  • kdenetwork
  • kget
  • ui
transfersettingsdialog.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2 
3  Copyright (C) 2008 Lukas Appelhans <l.appelhans@gmx.de>
4  Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 */
11 #include "transfersettingsdialog.h"
12 #include "mirror/mirrorsettings.h"
13 #include "renamefile.h"
14 #include "signaturedlg.h"
15 #include "verificationdialog.h"
16 #include "settings.h"
17 
18 #include "core/transferhandler.h"
19 #include "core/filemodel.h"
20 #include "core/verifier.h"
21 
22 #include <KMessageBox>
23 #include <KLineEdit>
24 #include <QSortFilterProxyModel>
25 
26 TransferSettingsDialog::TransferSettingsDialog(QWidget *parent, TransferHandler *transfer)
27  : KGetSaveSizeDialog("TransferSettingsDialog", parent),
28  m_transfer(transfer),
29  m_model(m_transfer->fileModel()),
30  m_proxy(0)
31 {
32  setCaption(i18n("Transfer Settings for %1", m_transfer->source().fileName()));
33  showButtonSeparator(true);
34  QWidget *widget = new QWidget(this);
35  ui.setupUi(widget);
36  setMainWidget(widget);
37  ui.ktitlewidget->setPixmap(SmallIcon("preferences-other"));
38  ui.downloadSpin->setValue(m_transfer->downloadLimit(Transfer::VisibleSpeedLimit));
39  ui.uploadSpin->setValue(m_transfer->uploadLimit(Transfer::VisibleSpeedLimit));
40  ui.ratioSpin->setValue(m_transfer->maximumShareRatio());
41  ui.destination->setUrl(m_transfer->directory().pathOrUrl());
42  ui.destination->lineEdit()->setReadOnly(true);
43  ui.rename->setIcon(KIcon("edit-rename"));
44  ui.mirrors->setIcon(KIcon("download"));
45  ui.signature->setIcon(KIcon("application-pgp-signature"));
46  ui.verification->setIcon(KIcon("document-decrypt"));
47 
48  if (m_model)
49  {
50  m_model->watchCheckState();
51  m_proxy = new QSortFilterProxyModel(this);
52  m_proxy->setSourceModel(m_model);
53  ui.treeView->setModel(m_proxy);
54  ui.treeView->sortByColumn(0, Qt::AscendingOrder);
55 
56  QByteArray loadedState = QByteArray::fromBase64(Settings::transferSettingsHeaderState().toAscii());
57  if (!loadedState.isEmpty()) {
58  ui.treeView->header()->restoreState(loadedState);
59  } else {
60  ui.treeView->header()->resizeSection(0, ui.treeView->header()->defaultSectionSize() * 3);
61  }
62  }
63 
64  updateCapabilities();
65 
66  connect(m_transfer, SIGNAL(capabilitiesChanged()), this, SLOT(updateCapabilities()));
67  connect(this, SIGNAL(accepted()), SLOT(save()));
68  connect(this, SIGNAL(finished()), this, SLOT(slotFinished()));
69  connect(ui.treeView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotSelectionChanged()));
70  connect(ui.rename, SIGNAL(clicked(bool)), this, SLOT(slotRename()));
71  connect(ui.mirrors, SIGNAL(clicked(bool)), this, SLOT(slotMirrors()));
72  connect(ui.verification, SIGNAL(clicked(bool)), this, SLOT(slotVerification()));
73  connect(ui.signature, SIGNAL(clicked(bool)), this, SLOT(slotSignature()));
74 }
75 
76 TransferSettingsDialog::~TransferSettingsDialog()
77 {
78  if (m_model) {
79  Settings::setTransferSettingsHeaderState(ui.treeView->header()->saveState().toBase64());
80  }
81 }
82 
83 QSize TransferSettingsDialog::sizeHint() const
84 {
85  QSize sh = KDialog::sizeHint();
86  sh.setWidth(sh.width() * 1.7);
87  return sh;
88 }
89 
90 void TransferSettingsDialog::updateCapabilities()
91 {
92  const int capabilities = m_transfer->capabilities();
93 
94  const bool supportsSpeedLimit = capabilities & Transfer::Cap_SpeedLimit;
95  ui.labelDownload->setVisible(supportsSpeedLimit);
96  ui.downloadSpin->setVisible(supportsSpeedLimit);
97  ui.labelUpload->setVisible(supportsSpeedLimit);
98  ui.uploadSpin->setVisible(supportsSpeedLimit);
99  ui.labelShareRatio->setVisible(supportsSpeedLimit);
100  ui.ratioSpin->setVisible(supportsSpeedLimit);
101 
102  ui.destination->setEnabled(capabilities & Transfer::Cap_Moving);
103  ui.mirrors->setVisible(capabilities & Transfer::Cap_MultipleMirrors);
104  ui.rename->setVisible(capabilities & Transfer::Cap_Renaming);
105 }
106 
107 void TransferSettingsDialog::slotMirrors()
108 {
109  const QModelIndex index = m_proxy->mapToSource(ui.treeView->selectionModel()->selectedIndexes().first());
110  KDialog *mirrors = new MirrorSettings(this, m_transfer, m_model->getUrl(index));
111  mirrors->setAttribute(Qt::WA_DeleteOnClose);
112  mirrors->show();
113 }
114 
115 void TransferSettingsDialog::slotRename()
116 {
117  const QModelIndex index = m_proxy->mapToSource(ui.treeView->selectionModel()->selectedIndexes().first());
118  RenameFile *renameDlg = new RenameFile(m_model, index, this);
119  renameDlg->setAttribute(Qt::WA_DeleteOnClose);
120  renameDlg->show();
121 }
122 
123 void TransferSettingsDialog::slotVerification()
124 {
125  const QModelIndex index = m_proxy->mapToSource(ui.treeView->selectionModel()->selectedIndexes().first());
126  KDialog *verification = new VerificationDialog(this, m_transfer, m_model->getUrl(index));
127  verification->setAttribute(Qt::WA_DeleteOnClose);
128  verification->show();
129 }
130 
131 void TransferSettingsDialog::slotSignature()
132 {
133  const QModelIndex index = m_proxy->mapToSource(ui.treeView->selectionModel()->selectedIndexes().first());
134 
135  SignatureDlg *signature = new SignatureDlg(m_transfer, m_model->getUrl(index), this);
136  signature->setAttribute(Qt::WA_DeleteOnClose);
137  signature->show();
138 }
139 
140 void TransferSettingsDialog::slotSelectionChanged()
141 {
142  bool enabled = false;
143  //only enable rename when one item is selected and when this item is a file
144  if (ui.treeView->selectionModel()->selectedRows().count() == 1)
145  {
146  const QModelIndex index = m_proxy->mapToSource(ui.treeView->selectionModel()->selectedIndexes().first());
147  if (index.isValid() && !(static_cast<FileItem*>(index.internalPointer()))->childCount())
148  {
149  enabled = true;
150  }
151  }
152  ui.mirrors->setEnabled(enabled);
153  ui.rename->setEnabled(enabled);
154  ui.verification->setEnabled(enabled);
155  ui.signature->setEnabled(enabled);
156 }
157 
158 void TransferSettingsDialog::save()
159 {//TODO: Set to -1 when no limit
160  KUrl oldDirectory = m_transfer->directory();
161  KUrl newDirectory = ui.destination->url();
162  if ((oldDirectory != newDirectory) && !m_transfer->setDirectory(newDirectory))
163  {
164  KMessageBox::error(this, i18n("Changing the destination did not work, the destination stays unmodified."), i18n("Destination unmodified"));
165  }
166 
167  m_transfer->setDownloadLimit(ui.downloadSpin->value(), Transfer::VisibleSpeedLimit);
168  m_transfer->setUploadLimit(ui.uploadSpin->value(), Transfer::VisibleSpeedLimit);
169  m_transfer->setMaximumShareRatio(ui.ratioSpin->value());
170 }
171 
172 void TransferSettingsDialog::slotFinished()
173 {
174  if (m_model)
175  {
176  m_model->stopWatchCheckState();
177  }
178 }
179 
180 #include "transfersettingsdialog.moc"
Settings::setTransferSettingsHeaderState
static void setTransferSettingsHeaderState(const QString &v)
Set TransferSettingsHeaderState.
Definition: settings.h:40
QModelIndex
verificationdialog.h
QWidget
TransferHandler
Class TransferHandler:
Definition: transferhandler.h:48
QSize::width
int width() const
MirrorSettings
Definition: mirrorsettings.h:63
Transfer::VisibleSpeedLimit
Definition: transfer.h:90
FileModel::stopWatchCheckState
void stopWatchCheckState()
Emits checkStateChanged if a CheckState of an entry changend.
Definition: filemodel.cpp:689
QByteArray
FileItem
Definition: filemodel.h:37
QSortFilterProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
TransferSettingsDialog::sizeHint
virtual QSize sizeHint() const
Definition: transfersettingsdialog.cpp:83
TransferSettingsDialog::~TransferSettingsDialog
~TransferSettingsDialog()
Definition: transfersettingsdialog.cpp:76
Transfer::Cap_Renaming
Definition: transfer.h:75
TransferSettingsDialog::TransferSettingsDialog
TransferSettingsDialog(QWidget *parent, TransferHandler *transfer)
Definition: transfersettingsdialog.cpp:26
Settings::transferSettingsHeaderState
static QString transferSettingsHeaderState()
Get TransferSettingsHeaderState.
Definition: settings.h:50
QByteArray::isEmpty
bool isEmpty() const
KDialog
FileModel::watchCheckState
void watchCheckState()
Watches if the check state changes, the result of that will be emitted when stopWatchCheckState() is ...
Definition: filemodel.cpp:684
SignatureDlg
Definition: signaturedlg.h:30
TransferHandler::capabilities
Transfer::Capabilities capabilities() const
Returns the capabilities the Transfer supports.
Definition: transferhandler.cpp:46
QModelIndex::isValid
bool isValid() const
TransferHandler::setUploadLimit
void setUploadLimit(int ulLimit, Transfer::SpeedLimit limit)
Set an UploadLimit for the transfer.
Definition: transferhandler.h:172
Transfer::Cap_MultipleMirrors
Definition: transfer.h:73
TransferHandler::directory
KUrl directory() const
Definition: transferhandler.h:108
renamefile.h
TransferHandler::setDownloadLimit
void setDownloadLimit(int dlLimit, Transfer::SpeedLimit limit)
Set a DownloadLimit for the transfer.
Definition: transferhandler.h:179
QSize::setWidth
void setWidth(int width)
QModelIndex::internalPointer
void * internalPointer() const
TransferHandler::source
const KUrl & source() const
Definition: transferhandler.h:93
Transfer::Cap_Moving
Definition: transfer.h:76
verifier.h
TransferHandler::maximumShareRatio
double maximumShareRatio()
Definition: transferhandler.h:200
TransferHandler::uploadLimit
int uploadLimit(Transfer::SpeedLimit limit) const
Definition: transferhandler.h:184
KGetSaveSizeDialog
Subclass to make sure that the size of the dialog is automatically stored and restored.
Definition: basedialog.h:32
QSize
QSortFilterProxyModel
transferhandler.h
QItemSelection
QSortFilterProxyModel::mapToSource
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
TransferHandler::setMaximumShareRatio
void setMaximumShareRatio(double ratio)
Set the maximum share-ratio.
Definition: transferhandler.h:195
settings.h
QByteArray::fromBase64
QByteArray fromBase64(const QByteArray &base64)
transfersettingsdialog.h
TransferHandler::setDirectory
bool setDirectory(const KUrl &newDirectory)
Move the download to the new destination.
Definition: transferhandler.h:115
TransferHandler::downloadLimit
int downloadLimit(Transfer::SpeedLimit limit) const
Definition: transferhandler.h:189
Transfer::Cap_SpeedLimit
Definition: transfer.h:72
VerificationDialog
Definition: verificationdialog.h:53
signaturedlg.h
FileModel::getUrl
KUrl getUrl(const QModelIndex &index)
The url on the filesystem (no check if the file exists yet!) of index, it can be a folder or file...
Definition: filemodel.cpp:544
RenameFile
Definition: renamefile.h:29
mirrorsettings.h
filemodel.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:28:43 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