• 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
  • metalinkcreator
filedlg.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 "filedlg.h"
21 #include "metalinker.h"
22 #include "urlwidget.h"
23 #include "../verificationdialog.h"
24 
25 #include "../../core/verifier.h"
26 #include "../../core/verificationmodel.h"
27 #include "../../core/verificationdelegate.h"
28 
29 #include <QtGui/QSortFilterProxyModel>
30 
31 #include <KLocale>
32 
33 FileDlg::FileDlg(KGetMetalink::File *file, const QStringList &currentFileNames, QSortFilterProxyModel *countrySort, QSortFilterProxyModel *languageSort, QWidget *parent, bool edit)
34  : KGetSaveSizeDialog("FileDlg", parent),
35  m_file(file),
36  m_initialFileName(m_file->name),
37  m_currentFileNames(currentFileNames),
38  m_edit(edit)
39 {
40  //remove the initial name, to see later if the chosen name is still free
41  m_currentFileNames.removeAll(m_initialFileName);
42 
43  QWidget *widget = new QWidget(this);
44  ui.setupUi(widget);
45  setMainWidget(widget);
46 
47  m_urlWidget = new UrlWidget(this);
48  m_urlWidget->init(&m_file->resources, countrySort);
49  ui.urlLayout->addWidget(m_urlWidget->widget());
50  connect(m_urlWidget, SIGNAL(urlsChanged()), this, SLOT(slotUpdateOkButton()));
51 
52  QWidget *data = new QWidget(this);
53  uiData.setupUi(data);
54  ui.dataLayout->addWidget(data);
55 
56  ui.infoWidget->setCloseButtonVisible(false);
57  ui.infoWidget->setMessageType(KMessageWidget::Information);
58 
59  //set the file data
60  ui.name->setText(m_file->name);
61  uiData.identity->setText(m_file->data.identity);
62  uiData.version->setText(m_file->data.version);
63  uiData.description->setText(m_file->data.description);
64  uiData.logo->setUrl(m_file->data.logo);
65  if (m_file->data.oses.count()) {
66  uiData.os->setText(m_file->data.oses.join(i18nc("comma, to seperate members of a list", ",")));
67  }
68  uiData.copyright->setText(m_file->data.copyright);
69  uiData.pub_name->setText(m_file->data.publisher.name);
70  uiData.pub_url->setUrl(m_file->data.publisher.url);
71 
72  if (m_file->size) {
73  ui.size->setText(QString::number(m_file->size));
74  }
75 
76 
77  //create the language selection
78  uiData.language->setModel(languageSort);
79  if (m_file->data.languages.count()) {//TODO 4.5 support multiple languages
80  const int index = uiData.language->findData(m_file->data.languages.first());
81  uiData.language->setCurrentIndex(index);
82  } else {
83  //Do not select a language of a file if none was defined.
84  uiData.language->setCurrentIndex(-1);
85  }
86 
87 
88  //create the verification stuff
89  m_verificationModel = new VerificationModel(this);
90  QHash<QString, QString>::const_iterator it;
91  QHash<QString, QString>::const_iterator itEnd = m_file->verification.hashes.constEnd();
92  for (it = m_file->verification.hashes.constBegin(); it != itEnd; ++it) {
93  m_verificationModel->addChecksum(it.key(), it.value());
94  }
95  ui.add_hash->setGuiItem(KStandardGuiItem::add());
96  ui.remove_hash->setGuiItem(KStandardGuiItem::remove());
97  m_verificationProxy = new QSortFilterProxyModel(this);
98  m_verificationProxy->setSourceModel(m_verificationModel);
99  ui.used_hashes->setSortingEnabled(true);
100  ui.used_hashes->hideColumn(VerificationModel::Verified);
101  ui.used_hashes->setModel(m_verificationProxy);
102  ui.used_hashes->setItemDelegate(new VerificationDelegate(this));
103  slotUpdateVerificationButtons();
104 
105  connect(m_verificationModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(slotUpdateVerificationButtons()));
106  connect(m_verificationModel, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(slotUpdateVerificationButtons()));
107  connect(ui.used_hashes, SIGNAL(clicked(QModelIndex)), this, SLOT(slotUpdateVerificationButtons()));
108  connect(ui.add_hash, SIGNAL(clicked()), this, SLOT(slotAddHash()));
109  connect(ui.remove_hash, SIGNAL(clicked()), this, SLOT(slotRemoveHash()));
110  connect(ui.name, SIGNAL(textEdited(QString)), this, SLOT(slotUpdateOkButton()));
111  connect(this, SIGNAL(okClicked()), this, SLOT(slotOkClicked()));
112 
113  slotUpdateOkButton();
114 
115  setCaption(i18n("File Properties"));
116 }
117 
118 void FileDlg::slotUpdateOkButton()
119 {
120  bool hasName = !ui.name->text().isEmpty();
121  bool hasUrls = m_urlWidget->hasUrls();
122  bool isDuplicate = (m_currentFileNames.indexOf(ui.name->text()) > -1);
123 
124  QStringList information;
125 
126  if (!hasName) {
127  information << i18n("Enter a filename.");
128  }
129  if (isDuplicate) {
130  information << i18n("The filename exists already, choose a different one.");
131  }
132  if (!hasUrls) {
133  information << i18n("Enter at least one URL.");
134  }
135 
136  ui.infoWidget->setText(information.join(" "));
137  ui.infoWidget->setVisible(!information.isEmpty());
138 
139  enableButtonOk(hasName && hasUrls && !isDuplicate);
140 }
141 
142 void FileDlg::slotUpdateVerificationButtons()
143 {
144  ui.remove_hash->setEnabled(ui.used_hashes->selectionModel()->hasSelection());
145 }
146 
147 void FileDlg::slotRemoveHash()
148 {
149  while (ui.used_hashes->selectionModel()->hasSelection()) {
150  const QModelIndex index = ui.used_hashes->selectionModel()->selectedRows().first();
151  m_verificationModel->removeRow(m_verificationProxy->mapToSource(index).row());
152  }
153 }
154 
155 void FileDlg::slotAddHash()
156 {
157  VerificationAddDlg *dialog = new VerificationAddDlg(m_verificationModel, this);
158  dialog->show();
159 }
160 
161 void FileDlg::slotOkClicked()
162 {
163  QList<KGetMetalink::Metaurl> metaurls = m_file->resources.metaurls;//TODO remove once metaurls are also shown
164  QList<KGetMetalink::Pieces> pieces = m_file->verification.pieces;//TODO remove once the partial hashes are also shown
165  m_file->clear();
166 
167  m_file->name = ui.name->text();
168  m_file->size = ui.size->text().toLongLong();
169  m_file->data.identity = uiData.identity->text();
170  m_file->data.version = uiData.version->text();
171  m_file->data.description = uiData.description->text();
172  m_file->data.logo = KUrl(uiData.logo->text());
173  if (!uiData.os->text().isEmpty()) {
174  m_file->data.oses = uiData.os->text().split(i18nc("comma, to seperate members of a list", ","));
175  }
176  m_file->data.copyright = uiData.copyright->text();
177  m_file->data.publisher.name = uiData.pub_name->text();
178  m_file->data.publisher.url = KUrl(uiData.pub_url->text());
179  m_file->data.languages << uiData.language->itemData(uiData.language->currentIndex()).toString();
180 
181  m_urlWidget->save();
182  m_file->resources.metaurls = metaurls;
183 
184 
185  //store the verification data
186  for (int i = 0; i < m_verificationModel->rowCount(); ++i) {
187  const QString type = m_verificationModel->index(i, VerificationModel::Type).data().toString();
188  const QString hash = m_verificationModel->index(i, VerificationModel::Checksum).data().toString();
189  m_file->verification.hashes[type] = hash;
190  }
191  m_file->verification.pieces = pieces;
192 
193  if (m_edit) {
194  //the file has been edited
195  emit fileEdited(m_initialFileName, m_file->name);
196  } else {
197  //a new file should be added, not edited
198  emit addFile();
199  }
200 }
201 
202 #include "filedlg.moc"
KGetMetalink::CommonData::publisher
UrlText publisher
Definition: metalinker.h:116
KGetMetalink::CommonData::languages
QStringList languages
Definition: metalinker.h:115
FileDlg::FileDlg
FileDlg(KGetMetalink::File *file, const QStringList &currentFileNames, QSortFilterProxyModel *countrySort, QSortFilterProxyModel *languageSort, QWidget *parent, bool edit=false)
Definition: filedlg.cpp:33
KGetMetalink::File::resources
Resources resources
Definition: metalinker.h:272
KGetMetalink::CommonData::logo
KUrl logo
Definition: metalinker.h:114
VerificationDelegate
Definition: verificationdelegate.h:27
UrlWidget
Definition: urlwidget.h:36
UrlWidget::widget
QWidget * widget()
Definition: urlwidget.cpp:61
QWidget
FileDlg::fileEdited
void fileEdited(const QString &oldFileName, const QString &newFileName)
VerificationAddDlg
Definition: verificationdialog.h:34
KGetMetalink::CommonData::identity
QString identity
Definition: metalinker.h:110
KGetMetalink::File
Definition: metalinker.h:239
KGetMetalink::UrlText::url
KUrl url
Definition: metalinker.h:86
VerificationModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: verificationmodel.cpp:130
KGetMetalink::File::clear
void clear()
Definition: metalinker.cpp:595
filedlg.h
metalinker.h
KGetMetalink::Resources::metaurls
QList< Metaurl > metaurls
Definition: metalinker.h:203
FileDlg::addFile
void addFile()
VerificationModel::Verified
Definition: verificationmodel.h:40
VerificationModel::data
QVariant data(const QModelIndex &index, int role) const
Definition: verificationmodel.cpp:50
KGetSaveSizeDialog
Subclass to make sure that the size of the dialog is automatically stored and restored.
Definition: basedialog.h:32
QSortFilterProxyModel
urlwidget.h
UrlWidget::save
void save()
Definition: urlwidget.cpp:111
KGetMetalink::CommonData::copyright
QString copyright
Definition: metalinker.h:117
KGetMetalink::CommonData::oses
QStringList oses
Definition: metalinker.h:113
KGetMetalink::File::name
QString name
Definition: metalinker.h:268
KGetMetalink::CommonData::version
QString version
Definition: metalinker.h:111
KGetMetalink::Verification::hashes
QHash< QString, QString > hashes
Definition: metalinker.h:234
VerificationModel
Definition: verificationmodel.h:29
UrlWidget::init
void init(KGetMetalink::Resources *resources, QSortFilterProxyModel *countrySort)
Definition: urlwidget.cpp:66
KGetMetalink::File::verification
Verification verification
Definition: metalinker.h:269
KGetMetalink::Verification::pieces
QList< Pieces > pieces
Definition: metalinker.h:235
KGetMetalink::CommonData::description
QString description
Definition: metalinker.h:112
KGetMetalink::UrlText::name
QString name
Definition: metalinker.h:85
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
UrlWidget::hasUrls
bool hasUrls() const
Definition: urlwidget.cpp:85
KGetMetalink::File::size
KIO::filesize_t size
Definition: metalinker.h:270
VerificationModel::Type
Definition: verificationmodel.h:38
VerificationModel::Checksum
Definition: verificationmodel.h:39
KGetMetalink::File::data
CommonData data
Definition: metalinker.h:271
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 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