24 #include <QtGui/QLabel>
25 #include <QtGui/QLayout>
26 #include <QtGui/QDoubleSpinBox>
27 #include <QtCore/QString>
28 #include <QtCore/QSignalMapper>
46 q->setMainWidget(_mainWidget);
47 ui.setupUi(_mainWidget);
71 busyWidget->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
72 ui.busyWidget->setLayout(
new QHBoxLayout());
83 ui.busyLabel->setText(message);
84 busyWidget->setVisible(
true);
89 ui.busyLabel->setText(message);
90 busyWidget->setVisible(
false);
95 ui.stackedWidget->setCurrentIndex(page);
98 switch (ui.stackedWidget->currentIndex()) {
99 case UserPasswordPage:
100 ui.username->setFocus();
104 case FileNewUpdatePage:
105 atticaHelper->loadLicenses();
106 atticaHelper->loadCurrency();
107 ui.uploadButton->setFocus();
108 setBusy(
i18n(
"Fetching license data from server..."));
112 if (ui.radioUpdate->isChecked()) {
114 atticaHelper->loadContent(ui.userContentList->currentItem()->data(Qt::UserRole).toString());
115 setBusy(
i18n(
"Fetching content data from server..."));
118 ui.mNameEdit->setFocus();
121 case UploadFinalPage:
122 if (previewFile1.isEmpty()) {
123 ui.uploadPreview1ImageLabel->setVisible(
false);
124 ui.uploadPreview1Label->setVisible(
false);
126 if (previewFile2.isEmpty()) {
127 ui.uploadPreview2ImageLabel->setVisible(
false);
128 ui.uploadPreview2Label->setVisible(
false);
130 if (previewFile3.isEmpty()) {
131 ui.uploadPreview3ImageLabel->setVisible(
false);
132 ui.uploadPreview3Label->setVisible(
false);
142 bool firstPage = ui.stackedWidget->currentIndex() == 0;
143 q->enableButton(
BackButton, !firstPage && !finished);
145 bool nextEnabled =
false;
146 switch (ui.stackedWidget->currentIndex()) {
147 case UserPasswordPage:
148 if (ui.providerComboBox->count() > 0 && !ui.username->text().isEmpty() && !ui.password->text().isEmpty()) {
153 case FileNewUpdatePage:
155 if (!uploadFile.isEmpty() || ui.uploadFileRequester->url().isLocalFile()) {
156 if (ui.radioNewUpload->isChecked() || ui.userContentList->currentRow() >= 0) {
163 if (!ui.mNameEdit->text().isEmpty()) {
172 case UploadFinalPage:
181 if (nextEnabled && q->button(KDialog::Cancel)->hasFocus()) {
188 if (providers.size() == 0) {
190 ui.stackedWidget->setEnabled(
false);
191 kWarning() <<
"Could not load providers.";
195 ui.providerComboBox->addItems(providers);
196 ui.providerComboBox->setCurrentIndex(0);
197 atticaHelper->setCurrentProvider(providers.at(0));
201 if (atticaHelper->loadCredentials(user, pass)) {
202 ui.username->setText(user);
203 ui.password->setText(pass);
210 atticaHelper->setCurrentProvider(providerName);
211 ui.username->clear();
212 ui.password->clear();
215 if (atticaHelper->loadCredentials(user, pass)) {
216 ui.username->setText(user);
217 ui.password->setText(pass);
224 _k_showPage(ui.stackedWidget->currentIndex()-1);
230 if (ui.stackedWidget->currentIndex() == UserPasswordPage) {
231 setBusy(
i18n(
"Checking login..."));
233 ui.providerComboBox->setEnabled(
false);
234 ui.username->setEnabled(
false);
235 ui.password->setEnabled(
false);
236 atticaHelper->checkLogin(ui.username->text(), ui.password->text());
238 _k_showPage(ui.stackedWidget->currentIndex()+1);
244 ui.providerComboBox->setEnabled(
true);
245 ui.username->setEnabled(
true);
246 ui.password->setEnabled(
true);
249 atticaHelper->saveCredentials(ui.username->text(), ui.password->text());
250 _k_showPage(FileNewUpdatePage);
252 atticaHelper->loadCategories(categoryNames);
253 setBusy(
i18n(
"Fetching your previously updated content..."));
256 setIdle(
i18n(
"Could not verify login, please try again."));
262 ui.mLicenseCombo->clear();
263 foreach (Attica::License license, licenses) {
264 ui.mLicenseCombo->addItem(license.name(), license.id());
270 ui.priceCurrency->setText(currency);
275 setIdle(
i18n(
"Fetching your previously updated content finished."));
277 foreach(Attica::Content content, contentList) {
278 QListWidgetItem *contentItem =
new QListWidgetItem(content.name());
279 contentItem->setData(Qt::UserRole, content.id());
280 ui.userContentList->addItem(contentItem);
283 if (ui.userContentList->count() > 0) {
284 ui.userContentList->setCurrentRow(0);
285 ui.radioUpdate->setEnabled(
true);
293 setIdle(
i18n(
"Fetching content data from server finished."));
295 contentId = content.id();
297 ui.mNameEdit->setText(content.name());
298 ui.mSummaryEdit->setText(content.description());
299 ui.mVersionEdit->setText(content.version());
300 ui.changelog->setText(content.changelog());
301 ui.priceCheckBox->setChecked(content.attribute(
"downloadbuy1") ==
"1");
302 ui.priceSpinBox->setValue(content.attribute(
"downloadbuyprice1").toDouble());
303 ui.priceReasonLineEdit->setText(content.attribute(
"downloadbuyreason1"));
305 bool conversionOk =
false;
306 int licenseNumber = content.license().toInt(&conversionOk);
309 int row = ui.mLicenseCombo->findData(licenseNumber, Qt::UserRole);
310 ui.mLicenseCombo->setCurrentIndex(row);
312 ui.mLicenseCombo->setEditText(content.license());
315 ui.contentWebsiteLink->setText(QLatin1String(
"<a href=\"") + content.detailpage().toString() + QLatin1String(
"\">")
316 +
i18nc(
"A link to the website where the get hot new stuff upload can be seen",
"Visit website") + QLatin1String(
"</a>"));
317 ui.fetchContentLinkImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
324 ui.previewImage1->setPixmap(QPixmap::fromImage(image));
327 ui.previewImage2->setPixmap(QPixmap::fromImage(image));
330 ui.previewImage3->setPixmap(QPixmap::fromImage(image));
337 ui.userContentList->setEnabled(update);
345 init(name +
".knsrc");
359 bool UploadDialog::init(
const QString &configfile)
363 setCaption(
i18n(
"Share Hot New Stuff"));
365 setButtons(KDialog::Cancel | KDialog::User1 | KDialog::User2 | KDialog::User3 | KDialog::Help);
366 setButtonGuiItem(
BackButton, KStandardGuiItem::back(KStandardGuiItem::UseRTL) );
369 setButtonIcon(
NextButton, KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon() );
375 connect(d->
ui.username, SIGNAL(textChanged(
QString)),
this, SLOT(_k_updatePage()));
377 connect(d->
ui.password, SIGNAL(textChanged(
QString)),
this, SLOT(_k_updatePage()));
378 connect(d->
ui.mNameEdit, SIGNAL(textChanged(
QString)),
this, SLOT(_k_updatePage()));
379 connect(d->
ui.uploadFileRequester, SIGNAL(textChanged(
QString)),
this, SLOT(_k_updatePage()));
380 connect(d->
ui.priceCheckBox, SIGNAL(toggled(
bool)),
this, SLOT(_k_priceToggled(
bool)));
382 connect(d->
ui.uploadButton, SIGNAL(clicked()),
this, SLOT(_k_startUpload()));
384 connect(
this, SIGNAL(user3Clicked()),
this, SLOT(_k_backPage()));
385 connect(
this, SIGNAL(user2Clicked()),
this, SLOT(_k_nextPage()));
386 connect(
this, SIGNAL(user1Clicked()),
this, SLOT(
accept()));
388 d->
ui.mTitleWidget->setText(
i18nc(
"Program name followed by 'Add On Uploader'",
389 "%1 Add-On Uploader",
390 KGlobal::activeComponent().aboutData()->programName()));
391 d->
ui.mTitleWidget->setPixmap(
KIcon(KGlobal::activeComponent().aboutData()->programIconName()));
395 kError() <<
"No knsrc file named '" << configfile <<
"' was found." << endl;
403 kError() <<
"No knsrc file named '" << configfile <<
"' was found." << endl;
408 if (conf.hasGroup(
"KNewStuff3")) {
409 kDebug() <<
"Loading KNewStuff3 config: " << configfile;
410 group = conf.group(
"KNewStuff3");
412 kError() <<
"A knsrc file was found but it doesn't contain a KNewStuff3 section." << endl;
425 d->
ui.mCategoryLabel->setVisible(
false);
426 d->
ui.mCategoryCombo->setVisible(
false);
440 d->
ui.uploadFileLabel->setVisible(
false);
441 d->
ui.uploadFileRequester->setVisible(
false);
444 if (!file.open(QIODevice::ReadOnly)) {
451 d->
ui.mNameEdit->setText(name);
456 d->
ui.mCategoryCombo->setCurrentIndex(d->
ui.mCategoryCombo->findText(category, Qt::MatchFixedString));
461 d->
ui.changelog->setText(changelog);
466 d->
ui.mSummaryEdit->setText(description);
471 d->
ui.priceCheckBox->setVisible(enabled);
472 d->
ui.priceGroupBox->setVisible(enabled);
477 d->
ui.priceCheckBox->setEnabled(
true);
478 d->
ui.priceSpinBox->setValue(price);
483 d->
ui.priceReasonLineEdit->setText(reason);
488 d->
ui.mVersionEdit->setText(version);
497 d->
ui.previewImage1->setPixmap(preview.scaled(d->
ui.previewImage1->size()));
501 d->
ui.previewImage2->setPixmap(preview.scaled(d->
ui.previewImage2->size()));
505 d->
ui.previewImage3->setPixmap(preview.scaled(d->
ui.previewImage3->size()));
508 kError() <<
"Wrong preview image file number";
515 ui.priceGroupBox->setEnabled(priceEnabled);
520 categories = loadedCategories;
523 if (categories.count() == 0) {
525 i18np(
"The server does not recognize the category %2 to which you are trying to upload.",
526 "The server does not recognize any of the categories to which you are trying to upload: %2",
527 categoryNames.size(), categoryNames.join(
", ")),
533 foreach(Attica::Category c, categories) {
534 ui.mCategoryCombo->addItem(c.name(), c.id());
536 atticaHelper->loadContentByCurrentUser();
550 q->button(KDialog::Cancel)->setEnabled(
false);
552 ui.uploadButton->setEnabled(
false);
555 ui.uploadProgressBar->setMinimum(0);
556 ui.uploadProgressBar->setMaximum(0);
557 ui.uploadProgressBar->setValue(0);
560 QString categoryName = ui.mCategoryCombo->currentText();
562 Attica::Category category;
563 while (iter != categories.constEnd()) {
564 if (iter->name() == categoryName) {
570 if (!category.isValid()) {
576 Attica::Content content;
577 content.setName(ui.mNameEdit->text());
578 QString summary = ui.mSummaryEdit->toPlainText();
579 content.addAttribute(
"description", summary);
580 content.addAttribute(
"version", ui.mVersionEdit->text());
583 QString licenseId = ui.mLicenseCombo->itemData(ui.mLicenseCombo->currentIndex()).toString();
584 if (licenseId.isEmpty()) {
586 content.addAttribute(
"licensetype",
"0");
587 content.addAttribute(
"license", ui.mLicenseCombo->currentText());
589 content.addAttribute(
"licensetype", licenseId);
592 content.addAttribute(
"changelog", ui.changelog->toPlainText());
600 content.addAttribute(
"downloadbuy1", ui.priceCheckBox->isChecked() ?
"1" :
"0");
601 content.addAttribute(
"downloadbuyprice1", QString::number(ui.priceSpinBox->value()));
602 content.addAttribute(
"downloadbuyreason1", ui.priceReasonLineEdit->text());
604 if (ui.radioNewUpload->isChecked()) {
606 Attica::ItemPostJob<Attica::Content>* job = currentProvider().addNewContent(category, content);
607 q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_contentAdded(Attica::BaseJob*)));
611 Attica::ItemPostJob<Attica::Content>* job = currentProvider().editContent(category, ui.userContentList->currentItem()->data(Qt::UserRole).toString(), content);
612 q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_contentAdded(Attica::BaseJob*)));
619 KUrl url = KFileDialog::getImageOpenUrl(
KUrl(), q,
i18n(
"Select preview image"));
623 ui.previewImage1->setPixmap(preview.scaled(ui.previewImage1->size()));
628 KUrl url = KFileDialog::getImageOpenUrl(
KUrl(), q,
i18n(
"Select preview image"));
631 ui.previewImage2->setPixmap(preview.scaled(ui.previewImage1->size()));
636 KUrl url = KFileDialog::getImageOpenUrl(
KUrl(), q,
i18n(
"Select preview image"));
639 ui.previewImage3->setPixmap(preview.scaled(ui.previewImage1->size()));
644 if (baseJob->metadata().error()) {
645 if (baseJob->metadata().error() == Attica::Metadata::NetworkError) {
649 if (baseJob->metadata().error() == Attica::Metadata::OcsError) {
650 if (baseJob->metadata().statusCode() == 102)
656 ui.createContentImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
658 Attica::ItemPostJob<Attica::Content> * job =
static_cast<Attica::ItemPostJob<Attica::Content> *
>(baseJob);
659 if (job->metadata().error() != Attica::Metadata::NoError) {
665 QString id = job->result().id();
670 if (!uploadFile.isEmpty()) {
671 doUpload(
QString(), uploadFile);
673 doUpload(
QString(), ui.uploadFileRequester->url());
677 if (!previewFile1.isEmpty()) {
678 doUpload(
"1", previewFile1);
680 if (!previewFile2.isEmpty()) {
681 doUpload(
"2", previewFile2);
683 if (!previewFile3.isEmpty()) {
684 doUpload(
"3", previewFile3);
687 if (ui.radioNewUpload->isChecked()) {
688 atticaHelper->loadDetailsLink(contentId);
695 if (!file.open(QIODevice::ReadOnly)) {
701 QByteArray fileContents;
702 fileContents.append(file.readAll());
707 Attica::PostJob* job = 0;
708 if (index.isEmpty()) {
709 job = currentProvider().setDownloadFile(contentId, fileName, fileContents);
710 q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_fileUploadFinished(Attica::BaseJob*)));
711 }
else if (index == QLatin1String(
"1")) {
712 job = currentProvider().setPreviewImage(contentId, index, fileName, fileContents);
713 q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_preview1UploadFinished(Attica::BaseJob*)));
714 }
else if (index == QLatin1String(
"2")) {
715 job = currentProvider().setPreviewImage(contentId, index, fileName, fileContents);
716 q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_preview2UploadFinished(Attica::BaseJob*)));
717 }
else if (index == QLatin1String(
"3")) {
718 job = currentProvider().setPreviewImage(contentId, index, fileName, fileContents);
719 q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_preview3UploadFinished(Attica::BaseJob*)));
727 ui.uploadContentImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
728 finishedContents =
true;
729 uploadFileFinished();
734 ui.uploadPreview1ImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
735 finishedPreview1 =
true;
736 uploadFileFinished();
741 ui.uploadPreview2ImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
742 finishedPreview2 =
true;
743 uploadFileFinished();
748 ui.uploadPreview3ImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
749 finishedPreview3 =
true;
750 uploadFileFinished();
756 if (finishedContents && (previewFile1.isEmpty() || finishedPreview1)
757 && (previewFile2.isEmpty() || finishedPreview2)
758 && (previewFile3.isEmpty() || finishedPreview3)) {
760 ui.uploadProgressBar->setMinimum(0);
761 ui.uploadProgressBar->setMaximum(100);
762 ui.uploadProgressBar->setValue(100);
769 ui.contentWebsiteLink->setText(QLatin1String(
"<a href=\"") + url.toString() + QLatin1String(
"\">")
770 +
i18nc(
"A link to the website where the get hot new stuff upload can be seen",
"Visit website") + QLatin1String(
"</a>"));
771 ui.fetchContentLinkImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
774 #include "uploaddialog.moc"