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

KNewStuff

  • sources
  • kde-4.14
  • kdelibs
  • knewstuff
  • knewstuff3
knewstuff3/uploaddialog.cpp
Go to the documentation of this file.
1 /*
2  knewstuff3/ui/uploaddialog.cpp.
3  Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
4  Copyright (c) 2009 Jeremy Whiting <jpwhiting@kde.org>
5  Copyright (C) 2009-2010 Frederik Gladhorn <gladhorn@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include "uploaddialog.h"
22 #include "uploaddialog_p.h"
23 
24 #include <QtGui/QLabel>
25 #include <QtGui/QLayout>
26 #include <QtGui/QDoubleSpinBox>
27 #include <QtCore/QString>
28 #include <QtCore/QSignalMapper>
29 
30 #include <kaboutdata.h>
31 #include <kcomponentdata.h>
32 #include <kfiledialog.h>
33 #include <kmessagebox.h>
34 #include <kstandarddirs.h>
35 #include <kpixmapsequence.h>
36 #include <kpixmapsequencewidget.h>
37 #include <krun.h>
38 
39 #include <kdebug.h>
40 #include <kconfiggroup.h>
41 #include <kservice.h>
42 
43 using namespace KNS3;
44 
45 bool UploadDialog::Private::init(const QString& configfile)
46 {
47  QWidget* _mainWidget = new QWidget(q);
48  q->setMainWidget(_mainWidget);
49  ui.setupUi(_mainWidget);
50  atticaHelper = new AtticaHelper(q);
51 
52  bool success = true;
53  KConfig conf(configfile);
54  if (conf.accessMode() == KConfig::NoAccess) {
55  kError() << "No knsrc file named '" << configfile << "' was found." << endl;
56  success = false;
57  }
58  // FIXME: accessMode() doesn't return NoAccess for non-existing files
59  // - bug in kdecore?
60  // - this needs to be looked at again until KConfig backend changes for KDE 4
61  // the check below is a workaround
62  if (KStandardDirs::locate("config", configfile).isEmpty()) {
63  kError() << "No knsrc file named '" << configfile << "' was found." << endl;
64  success = false;
65  }
66 
67  KConfigGroup group;
68  if (conf.hasGroup("KNewStuff3")) {
69  kDebug() << "Loading KNewStuff3 config: " << configfile;
70  group = conf.group("KNewStuff3");
71  } else {
72  kError() << "A knsrc file was found but it doesn't contain a KNewStuff3 section." << endl;
73  success = false;
74  }
75 
76  if ( success ) {
77  const QString providersFileUrl = group.readEntry("ProvidersUrl", QString());
78 
79  categoryNames = group.readEntry("UploadCategories", QStringList());
80  // fall back to download categories
81  if (categoryNames.isEmpty()) {
82  categoryNames = group.readEntry("Categories", QStringList());
83  }
84 
85  atticaHelper->addProviderFile(QUrl(providersFileUrl));
86  }
87 
88  ui.mCategoryCombo->addItems(categoryNames);
89 
90  if (categoryNames.size() == 1) {
91  ui.mCategoryLabel->setVisible(false);
92  ui.mCategoryCombo->setVisible(false);
93  }
94 
95  kDebug() << "Categories: " << categoryNames;
96 
97  q->connect(atticaHelper, SIGNAL(providersLoaded(QStringList)), q, SLOT(_k_providersLoaded(QStringList)));
98  q->connect(atticaHelper, SIGNAL(loginChecked(bool)), q, SLOT(_k_checkCredentialsFinished(bool)));
99  q->connect(atticaHelper, SIGNAL(licensesLoaded(Attica::License::List)), q, SLOT(_k_licensesLoaded(Attica::License::List)));
100  q->connect(atticaHelper, SIGNAL(categoriesLoaded(Attica::Category::List)), q, SLOT(_k_categoriesLoaded(Attica::Category::List)));
101  q->connect(atticaHelper, SIGNAL(contentByCurrentUserLoaded(Attica::Content::List)), q, SLOT(_k_contentByCurrentUserLoaded(Attica::Content::List)));
102  q->connect(atticaHelper, SIGNAL(contentLoaded(Attica::Content)), q, SLOT(_k_updatedContentFetched(Attica::Content)));
103  q->connect(atticaHelper, SIGNAL(detailsLinkLoaded(QUrl)), q, SLOT(_k_detailsLinkLoaded(QUrl)));
104  q->connect(atticaHelper, SIGNAL(currencyLoaded(QString)), q, SLOT(_k_currencyLoaded(QString)));
105  q->connect(atticaHelper, SIGNAL(previewLoaded(int,QImage)), q, SLOT(_k_previewLoaded(int,QImage)));
106  atticaHelper->init();
107 
108  q->connect(ui.changePreview1Button, SIGNAL(clicked()), q, SLOT(_k_changePreview1()));
109  q->connect(ui.changePreview2Button, SIGNAL(clicked()), q, SLOT(_k_changePreview2()));
110  q->connect(ui.changePreview3Button, SIGNAL(clicked()), q, SLOT(_k_changePreview3()));
111 
112  q->connect(ui.providerComboBox, SIGNAL(currentIndexChanged(QString)), q, SLOT(_k_providerChanged(QString)));
113  q->connect(ui.radioUpdate, SIGNAL(toggled(bool)), q, SLOT(_k_updateContentsToggled(bool)));
114 
115  q->connect(ui.registerNewAccountLabel, SIGNAL(linkActivated(QString)), q, SLOT(_k_openRegisterAccountWebpage(QString)));
116 
117  //Busy widget
118  busyWidget = new KPixmapSequenceWidget();
119  busyWidget->setSequence(KPixmapSequence("process-working", 22));
120  busyWidget->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
121  ui.busyWidget->setLayout(new QHBoxLayout());
122  ui.busyWidget->layout()->addWidget(busyWidget);
123  busyWidget->setVisible(false);
124 
125  return success;
126 }
127 
128 void UploadDialog::Private::setBusy(const QString& message)
129 {
130  ui.busyLabel->setText(message);
131  busyWidget->setVisible(true);
132 }
133 
134 void UploadDialog::Private::setIdle(const QString& message)
135 {
136  ui.busyLabel->setText(message);
137  busyWidget->setVisible(false);
138 }
139 
140 void UploadDialog::Private::_k_showPage(int page)
141 {
142  ui.stackedWidget->setCurrentIndex(page);
143  setIdle(QString());
144 
145  switch (ui.stackedWidget->currentIndex()) {
146  case UserPasswordPage:
147  ui.username->setFocus();
148  // TODO 4.6 enable new string: setBusy(i18n("Fetching provider information..."));
149  break;
150 
151  case FileNewUpdatePage:
152  atticaHelper->loadLicenses();
153  atticaHelper->loadCurrency();
154  ui.uploadButton->setFocus();
155  setBusy(i18n("Fetching license data from server..."));
156  break;
157 
158  case Details1Page:
159  if (ui.radioUpdate->isChecked()) {
160  // Fetch
161  atticaHelper->loadContent(ui.userContentList->currentItem()->data(Qt::UserRole).toString());
162  setBusy(i18n("Fetching content data from server..."));
163  }
164 
165  ui.mNameEdit->setFocus();
166  break;
167 
168  case UploadFinalPage:
169  if (previewFile1.isEmpty()) {
170  ui.uploadPreview1ImageLabel->setVisible(false);
171  ui.uploadPreview1Label->setVisible(false);
172  }
173  if (previewFile2.isEmpty()) {
174  ui.uploadPreview2ImageLabel->setVisible(false);
175  ui.uploadPreview2Label->setVisible(false);
176  }
177  if (previewFile3.isEmpty()) {
178  ui.uploadPreview3ImageLabel->setVisible(false);
179  ui.uploadPreview3Label->setVisible(false);
180  }
181  break;
182  }
183 
184  _k_updatePage();
185 }
186 
187 void UploadDialog::Private::_k_updatePage()
188 {
189  bool firstPage = ui.stackedWidget->currentIndex() == 0;
190  q->enableButton(BackButton, !firstPage && !finished);
191 
192  bool nextEnabled = false;
193  switch (ui.stackedWidget->currentIndex()) {
194  case UserPasswordPage:
195  if (ui.providerComboBox->count() > 0 && !ui.username->text().isEmpty() && !ui.password->text().isEmpty()) {
196  nextEnabled = true;
197  }
198  break;
199 
200  case FileNewUpdatePage:
201  // FIXME: check if the file requester contains a valid file
202  if (!uploadFile.isEmpty() || ui.uploadFileRequester->url().isLocalFile()) {
203  if (ui.radioNewUpload->isChecked() || ui.userContentList->currentRow() >= 0) {
204  nextEnabled = true;
205  }
206  }
207  break;
208 
209  case Details1Page:
210  if (!ui.mNameEdit->text().isEmpty()) {
211  nextEnabled = true;
212  }
213  break;
214 
215  case Details2Page:
216  nextEnabled = true;
217  break;
218 
219  case UploadFinalPage:
220  break;
221  }
222 
223  q->enableButton(NextButton, nextEnabled);
224  q->enableButton(FinishButton, finished);
225 
226  q->setDefaultButton(nextEnabled ? NextButton : FinishButton);
227 
228  if (nextEnabled && q->button(KDialog::Cancel)->hasFocus()) {
229  q->button(NextButton)->setFocus();
230  }
231 }
232 
233 void UploadDialog::Private::_k_providersLoaded(const QStringList& providers)
234 {
235  if (providers.size() == 0) {
236  // TODO 4.6 enable new string: setIdle(i18n("Could not fetch provider information."));
237  ui.stackedWidget->setEnabled(false);
238  kWarning() << "Could not load providers.";
239  return;
240  }
241  setIdle(QString());
242  ui.providerComboBox->addItems(providers);
243  ui.providerComboBox->setCurrentIndex(0);
244  atticaHelper->setCurrentProvider(providers.at(0));
245 
246  QString user;
247  QString pass;
248  if (atticaHelper->loadCredentials(user, pass)) {
249  ui.username->setText(user);
250  ui.password->setText(pass);
251  }
252  _k_updatePage();
253 }
254 
255 void UploadDialog::Private::_k_providerChanged(const QString& providerName)
256 {
257  atticaHelper->setCurrentProvider(providerName);
258  QString registerUrl = atticaHelper->provider().getRegisterAccountUrl();
259  if ( ! registerUrl.isEmpty() ) {
260  ui.registerNewAccountLabel->setText("<a href=\"register\">" + i18n("Register a new account") + "</a>");
261  }
262  else {
263  ui.registerNewAccountLabel->setText(QString());
264  }
265  ui.username->clear();
266  ui.password->clear();
267  QString user;
268  QString pass;
269  if (atticaHelper->loadCredentials(user, pass)) {
270  ui.username->setText(user);
271  ui.password->setText(pass);
272  }
273  _k_updatePage();
274 }
275 
276 void UploadDialog::Private::_k_backPage()
277 {
278  _k_showPage(ui.stackedWidget->currentIndex()-1);
279 }
280 
281 void UploadDialog::Private::_k_nextPage()
282 {
283  // TODO: validate credentials after user name/password have been entered
284  if (ui.stackedWidget->currentIndex() == UserPasswordPage) {
285  setBusy(i18n("Checking login..."));
286  q->button(NextButton)->setEnabled(false);
287  ui.providerComboBox->setEnabled(false);
288  ui.username->setEnabled(false);
289  ui.password->setEnabled(false);
290  atticaHelper->checkLogin(ui.username->text(), ui.password->text());
291  } else {
292  _k_showPage(ui.stackedWidget->currentIndex()+1);
293  }
294 }
295 
296 void UploadDialog::Private::_k_checkCredentialsFinished(bool success)
297 {
298  ui.providerComboBox->setEnabled(true);
299  ui.username->setEnabled(true);
300  ui.password->setEnabled(true);
301 
302  if (success) {
303  atticaHelper->saveCredentials(ui.username->text(), ui.password->text());
304  _k_showPage(FileNewUpdatePage);
305 
306  atticaHelper->loadCategories(categoryNames);
307  setBusy(i18n("Fetching your previously updated content..."));
308  } else {
309  // TODO check what the actual error is
310  setIdle(i18n("Could not verify login, please try again."));
311  }
312 }
313 
314 void UploadDialog::Private::_k_licensesLoaded(const Attica::License::List& licenses)
315 {
316  ui.mLicenseCombo->clear();
317  foreach (Attica::License license, licenses) {
318  ui.mLicenseCombo->addItem(license.name(), license.id());
319  }
320 }
321 
322 void UploadDialog::Private::_k_currencyLoaded(const QString& currency)
323 {
324  ui.priceCurrency->setText(currency);
325 }
326 
327 void UploadDialog::Private::_k_contentByCurrentUserLoaded(const Attica::Content::List& contentList)
328 {
329  setIdle(i18n("Fetching your previously updated content finished."));
330 
331  foreach(Attica::Content content, contentList) {
332  QListWidgetItem *contentItem = new QListWidgetItem(content.name());
333  contentItem->setData(Qt::UserRole, content.id());
334  ui.userContentList->addItem(contentItem);
335  }
336 
337  if (ui.userContentList->count() > 0) {
338  ui.userContentList->setCurrentRow(0);
339  ui.radioUpdate->setEnabled(true);
340  _k_updatePage();
341  }
342 
343 }
344 
345 void UploadDialog::Private::_k_updatedContentFetched(const Attica::Content& content)
346 {
347  setIdle(i18n("Fetching content data from server finished."));
348 
349  contentId = content.id();
350  // fill in ui
351  ui.mNameEdit->setText(content.name());
352  ui.mSummaryEdit->setText(content.description());
353  ui.mVersionEdit->setText(content.version());
354  ui.changelog->setText(content.changelog());
355  ui.priceCheckBox->setChecked(content.attribute("downloadbuy1") == "1");
356  ui.priceSpinBox->setValue(content.attribute("downloadbuyprice1").toDouble());
357  ui.priceReasonLineEdit->setText(content.attribute("downloadbuyreason1"));
358 
359  bool conversionOk = false;
360  int licenseNumber = content.license().toInt(&conversionOk);
361  if (conversionOk) {
362  // check if that int is in list
363  int row = ui.mLicenseCombo->findData(licenseNumber, Qt::UserRole);
364  ui.mLicenseCombo->setCurrentIndex(row);
365  } else {
366  ui.mLicenseCombo->setEditText(content.license());
367  }
368 
369  ui.contentWebsiteLink->setText(QLatin1String("<a href=\"") + content.detailpage().toString() + QLatin1String("\">")
370  + i18nc("A link to the website where the get hot new stuff upload can be seen", "Visit website") + QLatin1String("</a>"));
371  ui.fetchContentLinkImageLabel->setPixmap(KIcon("dialog-ok").pixmap(16));
372 }
373 
374 void UploadDialog::Private::_k_previewLoaded(int index, const QImage& image)
375 {
376  switch (index) {
377  case 1:
378  ui.previewImage1->setPixmap(QPixmap::fromImage(image));
379  break;
380  case 2:
381  ui.previewImage2->setPixmap(QPixmap::fromImage(image));
382  break;
383  case 3:
384  ui.previewImage3->setPixmap(QPixmap::fromImage(image));
385  break;
386  }
387 }
388 
389 void UploadDialog::Private::_k_updateContentsToggled(bool update)
390 {
391  ui.userContentList->setEnabled(update);
392 }
393 
394 UploadDialog::UploadDialog(QWidget *parent)
395  : KDialog(parent), d(new Private(this))
396 {
397  KComponentData component = KGlobal::activeComponent();
398  QString name = component.componentName();
399  init(name + ".knsrc");
400 }
401 
402 UploadDialog::UploadDialog(const QString& configFile, QWidget *parent)
403  : KDialog(parent), d(new Private(this))
404 {
405  init(configFile);
406 }
407 
408 UploadDialog::~UploadDialog()
409 {
410  delete d;
411 }
412 
413 bool UploadDialog::init(const QString &configfile)
414 {
415  bool success = d->init(configfile);
416 
417  setCaption(i18n("Share Hot New Stuff"));
418 
419  setButtons(KDialog::Cancel | KDialog::User1 | KDialog::User2 | KDialog::User3 /*| KDialog::Help*/);
420  setButtonGuiItem( BackButton, KStandardGuiItem::back(KStandardGuiItem::UseRTL) );
421 
422  setButtonText( NextButton, i18nc("Opposite to Back", "Next") );
423  setButtonIcon( NextButton, KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon() );
424  setButtonText(FinishButton, i18n("Finish"));
425  setButtonIcon( FinishButton, KIcon("dialog-ok-apply") );
426  setDefaultButton(NextButton);
427  d->_k_updatePage();
428 
429  connect(d->ui.username, SIGNAL(textChanged(QString)), this, SLOT(_k_updatePage()));
430 
431  connect(d->ui.password, SIGNAL(textChanged(QString)), this, SLOT(_k_updatePage()));
432  connect(d->ui.mNameEdit, SIGNAL(textChanged(QString)), this, SLOT(_k_updatePage()));
433  connect(d->ui.uploadFileRequester, SIGNAL(textChanged(QString)), this, SLOT(_k_updatePage()));
434  connect(d->ui.priceCheckBox, SIGNAL(toggled(bool)), this, SLOT(_k_priceToggled(bool)));
435 
436  connect(d->ui.uploadButton, SIGNAL(clicked()), this, SLOT(_k_startUpload()));
437 
438  connect(this, SIGNAL(user3Clicked()), this, SLOT(_k_backPage()));
439  connect(this, SIGNAL(user2Clicked()), this, SLOT(_k_nextPage()));
440  connect(this, SIGNAL(user1Clicked()), this, SLOT(accept()));
441 
442  d->ui.mTitleWidget->setText(i18nc("Program name followed by 'Add On Uploader'",
443  "%1 Add-On Uploader",
444  KGlobal::activeComponent().aboutData()->programName()));
445  d->ui.mTitleWidget->setPixmap(KIcon(KGlobal::activeComponent().aboutData()->programIconName()));
446 
447  if ( success ) {
448  d->_k_showPage(0);
449  }
450 
451  return success;
452 }
453 
454 void UploadDialog::setUploadFile(const KUrl& payloadFile)
455 {
456  d->uploadFile = payloadFile;
457 
458  d->ui.uploadFileLabel->setVisible(false);
459  d->ui.uploadFileRequester->setVisible(false);
460 
461  QFile file(d->uploadFile.toLocalFile());
462  if (!file.open(QIODevice::ReadOnly)) {
463  KMessageBox::error(this, i18n("File not found: %1", d->uploadFile.url()), i18n("Upload Failed"));
464  }
465 }
466 
467 void UploadDialog::setUploadName(const QString& name)
468 {
469  d->ui.mNameEdit->setText(name);
470 }
471 
472 void UploadDialog::selectCategory(const QString& category)
473 {
474  d->ui.mCategoryCombo->setCurrentIndex(d->ui.mCategoryCombo->findText(category, Qt::MatchFixedString));
475 }
476 
477 void UploadDialog::setChangelog(const QString& changelog)
478 {
479  d->ui.changelog->setText(changelog);
480 }
481 
482 void UploadDialog::setDescription(const QString& description)
483 {
484  d->ui.mSummaryEdit->setText(description);
485 }
486 
487 void UploadDialog::setPriceEnabled(bool enabled)
488 {
489  d->ui.priceCheckBox->setVisible(enabled);
490  d->ui.priceGroupBox->setVisible(enabled);
491 }
492 
493 void UploadDialog::setPrice(double price)
494 {
495  d->ui.priceCheckBox->setEnabled(true);
496  d->ui.priceSpinBox->setValue(price);
497 }
498 
499 void UploadDialog::setPriceReason(const QString& reason)
500 {
501  d->ui.priceReasonLineEdit->setText(reason);
502 }
503 
504 void UploadDialog::setVersion(const QString& version)
505 {
506  d->ui.mVersionEdit->setText(version);
507 }
508 
509 void UploadDialog::setPreviewImageFile(uint number, const KUrl& file)
510 {
511  QPixmap preview(file.toLocalFile());
512  switch(number) {
513  case 0 :
514  d->previewFile1 = file;
515  d->ui.previewImage1->setPixmap(preview.scaled(d->ui.previewImage1->size()));
516  break;
517  case 1 :
518  d->previewFile2 = file;
519  d->ui.previewImage2->setPixmap(preview.scaled(d->ui.previewImage2->size()));
520  break;
521  case 2 :
522  d->previewFile3 = file;
523  d->ui.previewImage3->setPixmap(preview.scaled(d->ui.previewImage3->size()));
524  break;
525  default :
526  kError() << "Wrong preview image file number";
527  break;
528  }
529 }
530 
531 void UploadDialog::Private::_k_priceToggled(bool priceEnabled)
532 {
533  ui.priceGroupBox->setEnabled(priceEnabled);
534 }
535 
536 void UploadDialog::Private::_k_categoriesLoaded(const Attica::Category::List& loadedCategories)
537 {
538  categories = loadedCategories;
539 
540  // at least one category is needed
541  if (categories.count() == 0) {
542  KMessageBox::error(q,
543  i18np("The server does not recognize the category %2 to which you are trying to upload.",
544  "The server does not recognize any of the categories to which you are trying to upload: %2",
545  categoryNames.size(), categoryNames.join(", ")),
546  i18n("Error"));
547  // close the dialog
548  q->reject();
549  return;
550  }
551  foreach(Attica::Category c, categories) {
552  ui.mCategoryCombo->addItem(c.name(), c.id());
553  }
554  atticaHelper->loadContentByCurrentUser();
555 }
556 
557 void UploadDialog::accept()
558 {
559  KDialog::accept();
560 }
561 
562 void UploadDialog::Private::_k_startUpload()
563 {
564  // FIXME: this only works if categories are set in the .knsrc file
565  // TODO: ask for confirmation when closing the dialog
566 
567  q->button(BackButton)->setEnabled(false);
568  q->button(KDialog::Cancel)->setEnabled(false);
569 
570  ui.uploadButton->setEnabled(false);
571 
572  // idle back and forth, we need a fix in attica to get at real progress values
573  ui.uploadProgressBar->setMinimum(0);
574  ui.uploadProgressBar->setMaximum(0);
575  ui.uploadProgressBar->setValue(0);
576 
577  // check the category
578  QString categoryName = ui.mCategoryCombo->currentText();
579  QList<Attica::Category>::const_iterator iter = categories.constBegin();
580  Attica::Category category;
581  while (iter != categories.constEnd()) {
582  if (iter->name() == categoryName) {
583  category = *iter;
584  break;
585  }
586  ++iter;
587  }
588  if (!category.isValid()) {
589  KMessageBox::error(q, i18n("The selected category \"%1\" is invalid.", categoryName), i18n("Upload Failed"));
590  return;
591  }
592 
593  // fill in the content object
594  Attica::Content content;
595  content.setName(ui.mNameEdit->text());
596  QString summary = ui.mSummaryEdit->toPlainText();
597  content.addAttribute("description", summary);
598  content.addAttribute("version", ui.mVersionEdit->text());
599 
600  // for the license, if one of the licenses coming from the server was used, pass its id, otherwise the string
601  QString licenseId = ui.mLicenseCombo->itemData(ui.mLicenseCombo->currentIndex()).toString();
602  if (licenseId.isEmpty()) {
603  // use other as type and add the string as text
604  content.addAttribute("licensetype", "0");
605  content.addAttribute("license", ui.mLicenseCombo->currentText());
606  } else {
607  content.addAttribute("licensetype", licenseId);
608  }
609 
610  content.addAttribute("changelog", ui.changelog->toPlainText());
611 
612  // TODO: add additional attributes
613  //content.addAttribute("downloadlink1", ui.link1->text());
614  //content.addAttribute("downloadlink2", ui.link2->text());
615  //content.addAttribute("homepage1", ui.homepage->text());
616  //content.addAttribute("blog1", ui.blog->text());
617 
618  content.addAttribute("downloadbuy1", ui.priceCheckBox->isChecked() ? "1" : "0");
619  content.addAttribute("downloadbuyprice1", QString::number(ui.priceSpinBox->value()));
620  content.addAttribute("downloadbuyreason1", ui.priceReasonLineEdit->text());
621 
622  if (ui.radioNewUpload->isChecked()) {
623  // upload a new content
624  Attica::ItemPostJob<Attica::Content>* job = currentProvider().addNewContent(category, content);
625  q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_contentAdded(Attica::BaseJob*)));
626  job->start();
627  } else {
628  // update old content
629  Attica::ItemPostJob<Attica::Content>* job = currentProvider().editContent(category, ui.userContentList->currentItem()->data(Qt::UserRole).toString(), content);
630  q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_contentAdded(Attica::BaseJob*)));
631  job->start();
632  }
633 }
634 
635 void UploadDialog::Private::_k_changePreview1()
636 {
637  KUrl url = KFileDialog::getImageOpenUrl(KUrl(), q, i18n("Select preview image"));
638  previewFile1 = url;
639  kDebug() << "preview is: " << url.url();
640  QPixmap preview(url.toLocalFile());
641  ui.previewImage1->setPixmap(preview.scaled(ui.previewImage1->size()));
642 }
643 
644 void UploadDialog::Private::_k_changePreview2()
645 {
646  KUrl url = KFileDialog::getImageOpenUrl(KUrl(), q, i18n("Select preview image"));
647  previewFile2 = url;
648  QPixmap preview(url.toLocalFile());
649  ui.previewImage2->setPixmap(preview.scaled(ui.previewImage1->size()));
650 }
651 
652 void UploadDialog::Private::_k_changePreview3()
653 {
654  KUrl url = KFileDialog::getImageOpenUrl(KUrl(), q, i18n("Select preview image"));
655  previewFile3 = url;
656  QPixmap preview(url.toLocalFile());
657  ui.previewImage3->setPixmap(preview.scaled(ui.previewImage1->size()));
658 }
659 
660 void UploadDialog::Private::_k_contentAdded(Attica::BaseJob* baseJob)
661 {
662  if (baseJob->metadata().error()) {
663  if (baseJob->metadata().error() == Attica::Metadata::NetworkError) {
664  KMessageBox::error(q, i18n("There was a network error."), i18n("Uploading Failed"));
665  return;
666  }
667  if (baseJob->metadata().error() == Attica::Metadata::OcsError) {
668  if (baseJob->metadata().statusCode() == 102)
669  KMessageBox::error(q, i18n("Authentication error."), i18n("Uploading Failed"));
670  }
671  return;
672  }
673 
674  ui.createContentImageLabel->setPixmap(KIcon("dialog-ok").pixmap(16));
675 
676  Attica::ItemPostJob<Attica::Content> * job = static_cast<Attica::ItemPostJob<Attica::Content> *>(baseJob);
677  if (job->metadata().error() != Attica::Metadata::NoError) {
678  KMessageBox::error(q, i18n("Upload failed: %1", job->metadata().message()));
679  return;
680  }
681 
682  // only when adding new content we get an id returned, otherwise stick with the old one
683  QString id = job->result().id();
684  if (!id.isEmpty()) {
685  contentId = id;
686  }
687 
688  if (!uploadFile.isEmpty()) {
689  doUpload(QString(), uploadFile);
690  } else {
691  doUpload(QString(), ui.uploadFileRequester->url());
692  }
693 
694  // FIXME: status labels need to accomodate 3 previews
695  if (!previewFile1.isEmpty()) {
696  doUpload("1", previewFile1);
697  }
698  if (!previewFile2.isEmpty()) {
699  doUpload("2", previewFile2);
700  }
701  if (!previewFile3.isEmpty()) {
702  doUpload("3", previewFile3);
703  }
704 
705  if (ui.radioNewUpload->isChecked()) {
706  atticaHelper->loadDetailsLink(contentId);
707  }
708 }
709 
710 void UploadDialog::Private::_k_openRegisterAccountWebpage(QString) {
711  KRun::runUrl(atticaHelper->provider().getRegisterAccountUrl(), "text/html", q);
712 }
713 
714 void UploadDialog::Private::doUpload(const QString& index, const KUrl& path)
715 {
716  QFile file(path.toLocalFile());
717  if (!file.open(QIODevice::ReadOnly)) {
718  KMessageBox::error(q, i18n("File not found: %1", uploadFile.url(), i18n("Upload Failed")));
719  q->reject();
720  return;
721  }
722 
723  QByteArray fileContents;
724  fileContents.append(file.readAll());
725  file.close();
726 
727  QString fileName = QFileInfo(path.toLocalFile()).fileName();
728 
729  Attica::PostJob* job = 0;
730  if (index.isEmpty()) {
731  job = currentProvider().setDownloadFile(contentId, fileName, fileContents);
732  q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_fileUploadFinished(Attica::BaseJob*)));
733  } else if (index == QLatin1String("1")) {
734  job = currentProvider().setPreviewImage(contentId, index, fileName, fileContents);
735  q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_preview1UploadFinished(Attica::BaseJob*)));
736  } else if (index == QLatin1String("2")) {
737  job = currentProvider().setPreviewImage(contentId, index, fileName, fileContents);
738  q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_preview2UploadFinished(Attica::BaseJob*)));
739  } else if (index == QLatin1String("3")) {
740  job = currentProvider().setPreviewImage(contentId, index, fileName, fileContents);
741  q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_preview3UploadFinished(Attica::BaseJob*)));
742  }
743  if( job )
744  job->start();
745 }
746 
747 void UploadDialog::Private::_k_fileUploadFinished(Attica::BaseJob* )
748 {
749  ui.uploadContentImageLabel->setPixmap(KIcon("dialog-ok").pixmap(16));
750  finishedContents = true;
751  uploadFileFinished();
752 }
753 
754 void UploadDialog::Private::_k_preview1UploadFinished(Attica::BaseJob* )
755 {
756  ui.uploadPreview1ImageLabel->setPixmap(KIcon("dialog-ok").pixmap(16));
757  finishedPreview1 = true;
758  uploadFileFinished();
759 }
760 
761 void UploadDialog::Private::_k_preview2UploadFinished(Attica::BaseJob* )
762 {
763  ui.uploadPreview2ImageLabel->setPixmap(KIcon("dialog-ok").pixmap(16));
764  finishedPreview2 = true;
765  uploadFileFinished();
766 }
767 
768 void UploadDialog::Private::_k_preview3UploadFinished(Attica::BaseJob* )
769 {
770  ui.uploadPreview3ImageLabel->setPixmap(KIcon("dialog-ok").pixmap(16));
771  finishedPreview3 = true;
772  uploadFileFinished();
773 }
774 
775 void UploadDialog::Private::uploadFileFinished()
776 {
777  // FIXME multiple previews
778  if (finishedContents && (previewFile1.isEmpty() || finishedPreview1)
779  && (previewFile2.isEmpty() || finishedPreview2)
780  && (previewFile3.isEmpty() || finishedPreview3)) {
781  finished = true;
782  ui.uploadProgressBar->setMinimum(0);
783  ui.uploadProgressBar->setMaximum(100);
784  ui.uploadProgressBar->setValue(100);
785  _k_updatePage();
786  }
787 }
788 
789 void UploadDialog::Private::_k_detailsLinkLoaded(const QUrl& url)
790 {
791  ui.contentWebsiteLink->setText(QLatin1String("<a href=\"") + url.toString() + QLatin1String("\">")
792  + i18nc("A link to the website where the get hot new stuff upload can be seen", "Visit website") + QLatin1String("</a>"));
793  ui.fetchContentLinkImageLabel->setPixmap(KIcon("dialog-ok").pixmap(16));
794 }
795 
796 #include "uploaddialog.moc"
KNS3::UploadDialog::Private::_k_updateContentsToggled
void _k_updateContentsToggled(bool update)
Definition: knewstuff3/uploaddialog.cpp:389
i18n
QString i18n(const char *text)
KNS3::UploadDialog::Private
Definition: uploaddialog_p.h:40
QWidget
KNS3::UploadDialog::Private::busyWidget
KPixmapSequenceWidget * busyWidget
Definition: uploaddialog_p.h:70
KPixmapSequence
KNS3::AtticaHelper::addProviderFile
void addProviderFile(const QUrl &file)
Definition: atticahelper.cpp:42
KNS3::UploadDialog::Private::q
UploadDialog * q
Definition: uploaddialog_p.h:54
firstPage
KAction * firstPage(const QObject *recvr, const char *slot, QObject *parent)
KStandardGuiItem::back
KGuiItem back(BidiMode useBidi=IgnoreRTL)
kdebug.h
KNS3::UploadDialog::setPreviewImageFile
void setPreviewImageFile(uint number, const KUrl &file)
Set one of the threee preview images displayed in the upload dialog.
Definition: knewstuff3/uploaddialog.cpp:509
KNS3::UploadDialog::setDescription
void setDescription(const QString &description)
Set the suggested description displayed in the upload dialog.
Definition: knewstuff3/uploaddialog.cpp:482
KNS3::UploadDialog::Private::previewFile3
KUrl previewFile3
Definition: uploaddialog_p.h:77
QByteArray
KNS3::UploadDialog::Private::atticaHelper
AtticaHelper * atticaHelper
Definition: uploaddialog_p.h:72
KNS3::UploadDialog::Private::ui
Ui::UploadDialog ui
Definition: uploaddialog_p.h:69
group
uploaddialog_p.h
kfiledialog.h
i18np
QString i18np(const char *sing, const char *plur, const A1 &a1)
KNS3::UploadDialog::Private::_k_openRegisterAccountWebpage
void _k_openRegisterAccountWebpage(QString)
Definition: knewstuff3/uploaddialog.cpp:710
KStandardDirs::locate
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
QSizePolicy
kpixmapsequence.h
QList::at
const T & at(int i) const
KNS3::UploadDialog::Private::setBusy
void setBusy(const QString &message)
Definition: knewstuff3/uploaddialog.cpp:128
KNS3::UploadDialog::setPrice
void setPrice(double price)
Set the suggested price displayed in the upload dialog.
Definition: knewstuff3/uploaddialog.cpp:493
QListWidgetItem
QWidget::setVisible
virtual void setVisible(bool visible)
KNS3::UploadDialog::Private::categoryNames
QStringList categoryNames
Definition: uploaddialog_p.h:78
KNS3::UploadDialog::Private::_k_currencyLoaded
void _k_currencyLoaded(const QString &currency)
Definition: knewstuff3/uploaddialog.cpp:322
QHBoxLayout
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KConfig::hasGroup
bool hasGroup(const QString &group) const
KConfig::group
KConfigGroup group(const QByteArray &group)
QPixmap::fromImage
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
KUrl::toLocalFile
QString toLocalFile(AdjustPathOption trailing=LeaveTrailingSlash) const
KNS3::UploadDialog::setUploadFile
void setUploadFile(const KUrl &payloadFile)
Set the file to be uploaded.
Definition: knewstuff3/uploaddialog.cpp:454
QWidget::icon
const QPixmap * icon() const
KNS3::UploadDialog::Private::_k_contentAdded
void _k_contentAdded(Attica::BaseJob *)
Definition: knewstuff3/uploaddialog.cpp:660
KDialog
KNS3::UploadDialog::accept
virtual void accept()
Definition: knewstuff3/uploaddialog.cpp:557
KNS3::UploadDialog::setUploadName
void setUploadName(const QString &name)
Set the suggested title for the upload.
Definition: knewstuff3/uploaddialog.cpp:467
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QUrl::toString
QString toString(QFlags< QUrl::FormattingOption > options) const
QList::const_iterator
QFile
QWidget::update
void update()
KUrl
i18nc
QString i18nc(const char *ctxt, const char *text)
QList::size
int size() const
KNS3::UploadDialog::Private::_k_categoriesLoaded
void _k_categoriesLoaded(const Attica::Category::List &loadedCategories)
Definition: knewstuff3/uploaddialog.cpp:536
QString::clear
void clear()
QDialog::finished
void finished(int result)
KNS3::UploadDialog::Private::init
bool init(const QString &configfile)
Definition: knewstuff3/uploaddialog.cpp:45
QObject::name
const char * name() const
KNS3::AtticaHelper
Definition: atticahelper.h:39
QString::number
QString number(int n, int base)
KNS3::UploadDialog::Private::_k_startUpload
void _k_startUpload()
Definition: knewstuff3/uploaddialog.cpp:562
KNS3::UploadDialog::Private::_k_preview1UploadFinished
void _k_preview1UploadFinished(Attica::BaseJob *)
Definition: knewstuff3/uploaddialog.cpp:754
KNS3::UploadDialog::~UploadDialog
~UploadDialog()
Destructor.
Definition: knewstuff3/uploaddialog.cpp:408
FinishButton
#define FinishButton
Definition: uploaddialog_p.h:33
KNS3::UploadDialog::Private::_k_priceToggled
void _k_priceToggled(bool)
Definition: knewstuff3/uploaddialog.cpp:531
KConfig::accessMode
AccessMode accessMode() const
KNS3::UploadDialog::UploadDialog
UploadDialog(QWidget *parent=0)
Create a new upload dialog.
Definition: knewstuff3/uploaddialog.cpp:394
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
KNS3::UploadDialog::Private::_k_updatePage
void _k_updatePage()
Definition: knewstuff3/uploaddialog.cpp:187
KNS3::UploadDialog::Private::_k_previewLoaded
void _k_previewLoaded(int index, const QImage &image)
Definition: knewstuff3/uploaddialog.cpp:374
KIcon
KGlobal::activeComponent
KComponentData activeComponent()
KNS3::UploadDialog::setPriceEnabled
void setPriceEnabled(bool enabled)
Enable the UI to let the user to set a price for the uploaded item.
Definition: knewstuff3/uploaddialog.cpp:487
KNS3::UploadDialog::Private::_k_providerChanged
void _k_providerChanged(const QString &providerName)
Definition: knewstuff3/uploaddialog.cpp:255
KPixmapSequenceWidget
KComponentData::componentName
QString componentName() const
QString
KPixmapSequenceWidget::setSequence
void setSequence(const KPixmapSequence &seq)
KNS3::UploadDialog::setVersion
void setVersion(const QString &version)
Set the suggested version displayed in the upload dialog.
Definition: knewstuff3/uploaddialog.cpp:504
QWidget::setSizePolicy
void setSizePolicy(QSizePolicy)
QDialog::accept
virtual void accept()
QStringList
KNS3::UploadDialog::Private::_k_changePreview3
void _k_changePreview3()
Definition: knewstuff3/uploaddialog.cpp:652
KNS3::UploadDialog::Private::doUpload
void doUpload(const QString &index, const KUrl &filePath)
Definition: knewstuff3/uploaddialog.cpp:714
kservice.h
QPixmap
KStandardGuiItem::forward
KGuiItem forward(BidiMode useBidi=IgnoreRTL)
QByteArray::append
QByteArray & append(char ch)
QFileInfo
KNS3::AtticaHelper::init
void init()
Definition: atticahelper.cpp:36
KNS3::UploadDialog::Private::_k_licensesLoaded
void _k_licensesLoaded(const Attica::License::List &licenses)
Definition: knewstuff3/uploaddialog.cpp:314
KNS3::UploadDialog::Private::_k_checkCredentialsFinished
void _k_checkCredentialsFinished(bool)
Definition: knewstuff3/uploaddialog.cpp:296
KNS3::UploadDialog::Private::_k_detailsLinkLoaded
void _k_detailsLinkLoaded(const QUrl &url)
Definition: knewstuff3/uploaddialog.cpp:789
QUrl
QListWidgetItem::setData
virtual void setData(int role, const QVariant &value)
BackButton
#define BackButton
Definition: uploaddialog_p.h:35
KNS3::UploadDialog::Private::previewFile2
KUrl previewFile2
Definition: uploaddialog_p.h:76
KNS3::UploadDialog::setPriceReason
void setPriceReason(const QString &reason)
Set the suggested rationale why this item costs something to download.
Definition: knewstuff3/uploaddialog.cpp:499
QImage
KConfigGroup
krun.h
KNS3::UploadDialog::Private::_k_backPage
void _k_backPage()
Definition: knewstuff3/uploaddialog.cpp:276
KNS3::UploadDialog::Private::setIdle
void setIdle(const QString &message)
Definition: knewstuff3/uploaddialog.cpp:134
KConfig
KConfig::NoAccess
KRun::runUrl
static bool runUrl(const KUrl &url, const QString &mimetype, QWidget *window, bool tempFile=false, bool runExecutables=true, const QString &suggestedFileName=QString(), const QByteArray &asn=QByteArray())
QLatin1String
KNS3::UploadDialog::Private::_k_contentByCurrentUserLoaded
void _k_contentByCurrentUserLoaded(const Attica::Content::List &contentList)
Definition: knewstuff3/uploaddialog.cpp:327
kstandarddirs.h
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
QWidget::setCaption
void setCaption(const QString &c)
KStandardGuiItem::UseRTL
KNS3::UploadDialog::Private::_k_providersLoaded
void _k_providersLoaded(const QStringList &providerNames)
Definition: knewstuff3/uploaddialog.cpp:233
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KNS3::UploadDialog::selectCategory
void selectCategory(const QString &category)
Set the suggested category for the upload.
Definition: knewstuff3/uploaddialog.cpp:472
KNS3::UploadDialog::Private::_k_showPage
void _k_showPage(int page)
Definition: knewstuff3/uploaddialog.cpp:140
KNS3::UploadDialog::Private::uploadFileFinished
void uploadFileFinished()
Definition: knewstuff3/uploaddialog.cpp:775
KUrl::url
QString url(AdjustPathOption trailing=LeaveTrailingSlash) const
uploaddialog.h
KNS3::UploadDialog::Private::_k_changePreview2
void _k_changePreview2()
Definition: knewstuff3/uploaddialog.cpp:644
KNS3::UploadDialog::Private::_k_updatedContentFetched
void _k_updatedContentFetched(const Attica::Content &content)
Definition: knewstuff3/uploaddialog.cpp:345
KNS3::UploadDialog::Private::_k_preview2UploadFinished
void _k_preview2UploadFinished(Attica::BaseJob *)
Definition: knewstuff3/uploaddialog.cpp:761
kaboutdata.h
KNS3::UploadDialog::Private::_k_changePreview1
void _k_changePreview1()
Definition: knewstuff3/uploaddialog.cpp:635
KNS3::UploadDialog::Private::_k_fileUploadFinished
void _k_fileUploadFinished(Attica::BaseJob *)
Definition: knewstuff3/uploaddialog.cpp:747
kcomponentdata.h
kmessagebox.h
KNS3::UploadDialog::Private::_k_preview3UploadFinished
void _k_preview3UploadFinished(Attica::BaseJob *)
Definition: knewstuff3/uploaddialog.cpp:768
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
kpixmapsequencewidget.h
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
KNS3::UploadDialog::Private::previewFile1
KUrl previewFile1
Definition: uploaddialog_p.h:75
KComponentData
KMessageBox::error
static void error(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
KNS3::UploadDialog::setChangelog
void setChangelog(const QString &changelog)
Set the suggested changelog displayed in the upload dialog.
Definition: knewstuff3/uploaddialog.cpp:477
KNS3::UploadDialog::Private::_k_nextPage
void _k_nextPage()
Definition: knewstuff3/uploaddialog.cpp:281
NextButton
#define NextButton
Definition: uploaddialog_p.h:34
kconfiggroup.h
KNS3::UploadDialog::Private::uploadFile
KUrl uploadFile
Definition: uploaddialog_p.h:74
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

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