• 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
  • ui
verificationdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 * Copyright (C) 2009 Matthias Fuchs <mat69@gmx.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
19 
20 #include "verificationdialog.h"
21 
22 #include <QtGui/QSortFilterProxyModel>
23 #include <QtGui/QStandardItemModel>
24 
25 #include <KLocale>
26 #include <KMessageBox>
27 
28 #include "core/filemodel.h"
29 #include "core/transferhandler.h"
30 #include "core/verifier.h"
31 #include "core/verificationmodel.h"
32 #include "core/verificationdelegate.h"
33 #include "settings.h"
34 
35 VerificationAddDlg::VerificationAddDlg(VerificationModel *model, QWidget *parent, Qt::WFlags flags)
36  : KDialog(parent, flags),
37  m_model(model)
38 {
39  setCaption(i18n("Add checksum"));
40  QWidget *widget = new QWidget(this);
41  ui.setupUi(widget);
42  setMainWidget(widget);
43 
44  QStringList supportedTypes = Verifier::supportedVerficationTypes();
45  supportedTypes.sort();
46  ui.hashTypes->addItems(supportedTypes);
47 
48  setButtons(KDialog::Yes | KDialog::Cancel);
49  setButtonGuiItem(KDialog::Yes, KStandardGuiItem::add());
50 
51  updateButton();
52 
53  connect(ui.newHash, SIGNAL(textChanged(QString)), this, SLOT(updateButton()));
54  connect(ui.hashTypes, SIGNAL(currentIndexChanged(int)), this, SLOT(updateButton()));
55  connect(this, SIGNAL(yesClicked()), this, SLOT(addChecksum()));
56 }
57 
58 QSize VerificationAddDlg::sizeHint() const
59 {
60  QSize sh = KDialog::sizeHint();
61  sh.setHeight(minimumSize().height());
62  sh.setWidth(sh.width() * 1.5);
63  return sh;
64 }
65 
66 void VerificationAddDlg::updateButton()
67 {
68  const QString type = ui.hashTypes->currentText();
69  const QString hash = ui.newHash->text();
70  const bool enabled = Verifier::isChecksum(type, hash);
71 
72  enableButton(KDialog::Yes, enabled);
73  enableButton(KDialog::User1, enabled);
74 }
75 
76 void VerificationAddDlg::addChecksum()
77 {
78  if (m_model) {
79  m_model->addChecksum(ui.hashTypes->currentText(), ui.newHash->text());
80  }
81 }
82 
83 VerificationDialog::VerificationDialog(QWidget *parent, TransferHandler *transfer, const KUrl &file)
84  : KGetSaveSizeDialog("VerificationDialog", parent),
85  m_transfer(transfer),
86  m_verifier(transfer->verifier(file)),
87  m_model(0),
88  m_proxy(0),
89  m_fileModel(0)
90 {
91  if (m_verifier) {
92  m_model = m_verifier->model();
93  connect(m_verifier, SIGNAL(verified(bool)), this, SLOT(slotVerified(bool)));
94  }
95 
96  setCaption(i18n("Transfer Verification for %1", file.fileName()));
97  showButtonSeparator(true);
98  QWidget *widget = new QWidget(this);
99  ui.setupUi(widget);
100  setMainWidget(widget);
101  ui.add->setGuiItem(KStandardGuiItem::add());
102  ui.remove->setGuiItem(KStandardGuiItem::remove());
103  ui.verifying->hide();
104 
105  if (m_model) {
106  m_proxy = new QSortFilterProxyModel(this);
107  m_proxy->setSourceModel(m_model);
108  ui.usedHashes->setModel(m_proxy);
109  ui.usedHashes->setItemDelegate(new VerificationDelegate(this));
110 
111  QByteArray loadedState = QByteArray::fromBase64(Settings::verificationHeaderState().toAscii());
112  if (!loadedState.isEmpty()) {
113  ui.usedHashes->header()->restoreState(loadedState);
114  }
115 
116  m_fileModel = m_transfer->fileModel();
117  if (m_fileModel) {
118  m_file = m_fileModel->index(file, FileItem::File);
119  connect(m_fileModel, SIGNAL(fileFinished(KUrl)), this, SLOT(fileFinished(KUrl)));
120  }
121 
122  updateButtons();
123 
124  connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(updateButtons()));
125  connect(m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(updateButtons()));
126  connect(ui.usedHashes, SIGNAL(clicked(QModelIndex)), this, SLOT(updateButtons()));
127  connect(ui.add, SIGNAL(clicked()), this, SLOT(addClicked()));
128  connect(ui.remove, SIGNAL(clicked()), this, SLOT(removeClicked()));
129  connect(ui.verify, SIGNAL(clicked()), this, SLOT(verifyClicked()));
130  }
131 
132  setButtons(KDialog::Close);
133 
134  connect(this, SIGNAL(finished()), this, SLOT(slotFinished()));
135 }
136 
137 QSize VerificationDialog::sizeHint() const
138 {
139  QSize sh = KDialog::sizeHint();
140  sh.setWidth(sh.width() * 1.2);
141  return sh;
142 }
143 
144 void VerificationDialog::slotFinished()
145 {
146  if (m_model) {
147  Settings::setVerificationHeaderState(ui.usedHashes->header()->saveState().toBase64());
148  }
149 }
150 
151 void VerificationDialog::fileFinished(const KUrl &file)
152 {
153  if (m_fileModel && (m_fileModel->getUrl(m_file) == file)) {
154  updateButtons();
155  }
156 }
157 
158 void VerificationDialog::updateButtons()
159 {
160  ui.remove->setEnabled(m_model && ui.usedHashes->selectionModel()->hasSelection());
161 
162  //check if the download finished and if the selected index is verifyable
163  bool verifyEnabled = false;
164  if (m_fileModel && m_fileModel->downloadFinished(m_fileModel->getUrl(m_file))) {
165  const QModelIndexList indexes = ui.usedHashes->selectionModel()->selectedRows();
166  if (indexes.count() == 1) {
167  verifyEnabled = m_verifier->isVerifyable(indexes.first());
168  }
169  }
170  ui.verify->setEnabled(verifyEnabled);
171 }
172 
173 void VerificationDialog::removeClicked()
174 {
175  while (ui.usedHashes->selectionModel()->hasSelection()) {
176  const QModelIndex index = ui.usedHashes->selectionModel()->selectedRows().first();
177  m_model->removeRow(m_proxy->mapToSource(index).row());
178  }
179 }
180 
181 void VerificationDialog::addClicked()
182 {
183  VerificationAddDlg *dialog = new VerificationAddDlg(m_model, this);
184  dialog->show();
185 }
186 
187 void VerificationDialog::verifyClicked()
188 {
189  const QModelIndex index = m_proxy->mapToSource(ui.usedHashes->selectionModel()->selectedRows().first());
190  if (index.isValid()) {
191  m_verifier->verify(index);
192  ui.progressBar->setMaximum(0);
193  ui.verifying->show();
194  }
195 }
196 
197 void VerificationDialog::slotVerified(bool verified)
198 {
199  ui.progressBar->setMaximum(1);
200  ui.verifying->hide();
201 
202  if (verified) {
203  QString fileName;
204  if (m_fileModel) {
205  fileName = m_fileModel->getUrl(m_file).fileName();
206  }
207 
208  KMessageBox::information(this,
209  i18n("%1 was successfully verified.", fileName),
210  i18n("Verification successful"));
211  }
212 }
213 
214 #include "verificationdialog.moc"
FileItem::File
Definition: filemodel.h:45
verificationdialog.h
TransferHandler
Class TransferHandler:
Definition: transferhandler.h:48
Settings::setVerificationHeaderState
static void setVerificationHeaderState(const QString &v)
Set VerificationHeaderState.
Definition: settings.h:59
VerificationDialog::VerificationDialog
VerificationDialog(QWidget *parent, TransferHandler *transfer, const KUrl &file)
Definition: verificationdialog.cpp:83
verificationmodel.h
VerificationDelegate
Definition: verificationdelegate.h:27
Verifier::verify
void verify(const QModelIndex &index=QModelIndex())
Call this method if you want to verify() in its own thread, then signals with the result are emitted...
Definition: verifier.cpp:364
QWidget
Verifier::supportedVerficationTypes
static QStringList supportedVerficationTypes()
Returns the supported verification types.
Definition: verifier.cpp:216
KDialog
VerificationAddDlg
Definition: verificationdialog.h:34
Verifier::isChecksum
static bool isChecksum(const QString &type, const QString &checksum)
Tries to check if the checksum is a checksum and if it is supported it compares the diggestLength and...
Definition: verifier.cpp:256
VerificationDialog::sizeHint
virtual QSize sizeHint() const
Definition: verificationdialog.cpp:137
verifier.h
Settings::verificationHeaderState
static QString verificationHeaderState()
Get VerificationHeaderState.
Definition: settings.h:69
KGetSaveSizeDialog
Subclass to make sure that the size of the dialog is automatically stored and restored.
Definition: basedialog.h:32
QSortFilterProxyModel
transferhandler.h
settings.h
Verifier::model
VerificationModel * model()
Definition: verifier.cpp:211
VerificationAddDlg::VerificationAddDlg
VerificationAddDlg(VerificationModel *model, QWidget *parent=0, Qt::WFlags flags=0)
Definition: verificationdialog.cpp:35
Verifier::isVerifyable
bool isVerifyable() const
Definition: verifier.cpp:279
VerificationModel
Definition: verificationmodel.h:29
VerificationModel::addChecksum
void addChecksum(const QString &type, const QString &checksum, int verified=0)
Add a checksum that is later used in the verification process.
Definition: verificationmodel.cpp:179
FileModel::downloadFinished
bool downloadFinished(const KUrl &file)
Checks if the download for file has been finished.
Definition: filemodel.cpp:622
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
verificationdelegate.h
TransferHandler::fileModel
virtual FileModel * fileModel()
Definition: transferhandler.h:272
FileModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: filemodel.cpp:436
filemodel.h
VerificationAddDlg::sizeHint
virtual QSize sizeHint() const
Definition: verificationdialog.cpp:58
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