24 #include <QtGui/QLabel>
25 #include <QtGui/QLayout>
26 #include <QtGui/QDoubleSpinBox>
27 #include <QtCore/QString>
28 #include <QtCore/QSignalMapper>
48 q->setMainWidget(_mainWidget);
49 ui.setupUi(_mainWidget);
55 kError() <<
"No knsrc file named '" << configfile <<
"' was found." << endl;
63 kError() <<
"No knsrc file named '" << configfile <<
"' was found." << endl;
69 kDebug() <<
"Loading KNewStuff3 config: " << configfile;
70 group = conf.
group(
"KNewStuff3");
72 kError() <<
"A knsrc file was found but it doesn't contain a KNewStuff3 section." << endl;
91 ui.mCategoryLabel->setVisible(
false);
92 ui.mCategoryCombo->setVisible(
false);
120 busyWidget->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
121 ui.busyWidget->setLayout(
new QHBoxLayout());
130 ui.busyLabel->setText(message);
131 busyWidget->setVisible(
true);
136 ui.busyLabel->setText(message);
137 busyWidget->setVisible(
false);
142 ui.stackedWidget->setCurrentIndex(page);
145 switch (ui.stackedWidget->currentIndex()) {
146 case UserPasswordPage:
147 ui.username->setFocus();
151 case FileNewUpdatePage:
152 atticaHelper->loadLicenses();
153 atticaHelper->loadCurrency();
154 ui.uploadButton->setFocus();
155 setBusy(
i18n(
"Fetching license data from server..."));
159 if (ui.radioUpdate->isChecked()) {
161 atticaHelper->loadContent(ui.userContentList->currentItem()->data(Qt::UserRole).toString());
162 setBusy(
i18n(
"Fetching content data from server..."));
165 ui.mNameEdit->setFocus();
168 case UploadFinalPage:
169 if (previewFile1.isEmpty()) {
170 ui.uploadPreview1ImageLabel->setVisible(
false);
171 ui.uploadPreview1Label->setVisible(
false);
173 if (previewFile2.isEmpty()) {
174 ui.uploadPreview2ImageLabel->setVisible(
false);
175 ui.uploadPreview2Label->setVisible(
false);
177 if (previewFile3.isEmpty()) {
178 ui.uploadPreview3ImageLabel->setVisible(
false);
179 ui.uploadPreview3Label->setVisible(
false);
189 bool firstPage = ui.stackedWidget->currentIndex() == 0;
190 q->enableButton(
BackButton, !firstPage && !finished);
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()) {
200 case FileNewUpdatePage:
202 if (!uploadFile.isEmpty() || ui.uploadFileRequester->url().isLocalFile()) {
203 if (ui.radioNewUpload->isChecked() || ui.userContentList->currentRow() >= 0) {
210 if (!ui.mNameEdit->text().isEmpty()) {
219 case UploadFinalPage:
228 if (nextEnabled && q->button(KDialog::Cancel)->hasFocus()) {
235 if (providers.size() == 0) {
237 ui.stackedWidget->setEnabled(
false);
238 kWarning() <<
"Could not load providers.";
242 ui.providerComboBox->addItems(providers);
243 ui.providerComboBox->setCurrentIndex(0);
244 atticaHelper->setCurrentProvider(providers.at(0));
248 if (atticaHelper->loadCredentials(user, pass)) {
249 ui.username->setText(user);
250 ui.password->setText(pass);
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>");
263 ui.registerNewAccountLabel->setText(
QString());
265 ui.username->clear();
266 ui.password->clear();
269 if (atticaHelper->loadCredentials(user, pass)) {
270 ui.username->setText(user);
271 ui.password->setText(pass);
278 _k_showPage(ui.stackedWidget->currentIndex()-1);
284 if (ui.stackedWidget->currentIndex() == UserPasswordPage) {
285 setBusy(
i18n(
"Checking login..."));
287 ui.providerComboBox->setEnabled(
false);
288 ui.username->setEnabled(
false);
289 ui.password->setEnabled(
false);
290 atticaHelper->checkLogin(ui.username->text(), ui.password->text());
292 _k_showPage(ui.stackedWidget->currentIndex()+1);
298 ui.providerComboBox->setEnabled(
true);
299 ui.username->setEnabled(
true);
300 ui.password->setEnabled(
true);
303 atticaHelper->saveCredentials(ui.username->text(), ui.password->text());
304 _k_showPage(FileNewUpdatePage);
306 atticaHelper->loadCategories(categoryNames);
307 setBusy(
i18n(
"Fetching your previously updated content..."));
310 setIdle(
i18n(
"Could not verify login, please try again."));
316 ui.mLicenseCombo->clear();
317 foreach (Attica::License license, licenses) {
318 ui.mLicenseCombo->addItem(license.name(), license.id());
324 ui.priceCurrency->setText(currency);
329 setIdle(
i18n(
"Fetching your previously updated content finished."));
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);
337 if (ui.userContentList->count() > 0) {
338 ui.userContentList->setCurrentRow(0);
339 ui.radioUpdate->setEnabled(
true);
347 setIdle(
i18n(
"Fetching content data from server finished."));
349 contentId = content.id();
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"));
359 bool conversionOk =
false;
360 int licenseNumber = content.license().toInt(&conversionOk);
363 int row = ui.mLicenseCombo->findData(licenseNumber, Qt::UserRole);
364 ui.mLicenseCombo->setCurrentIndex(row);
366 ui.mLicenseCombo->setEditText(content.license());
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));
378 ui.previewImage1->setPixmap(QPixmap::fromImage(image));
381 ui.previewImage2->setPixmap(QPixmap::fromImage(image));
384 ui.previewImage3->setPixmap(QPixmap::fromImage(image));
391 ui.userContentList->setEnabled(update);
399 init(name +
".knsrc");
413 bool UploadDialog::init(
const QString &configfile)
415 bool success = d->
init(configfile);
417 setCaption(
i18n(
"Share Hot New Stuff"));
419 setButtons(KDialog::Cancel | KDialog::User1 | KDialog::User2 | KDialog::User3 | KDialog::Help);
420 setButtonGuiItem(
BackButton, KStandardGuiItem::back(KStandardGuiItem::UseRTL) );
423 setButtonIcon(
NextButton, KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon() );
429 connect(d->
ui.username, SIGNAL(textChanged(
QString)),
this, SLOT(_k_updatePage()));
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)));
436 connect(d->
ui.uploadButton, SIGNAL(clicked()),
this, SLOT(_k_startUpload()));
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()));
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()));
458 d->
ui.uploadFileLabel->setVisible(
false);
459 d->
ui.uploadFileRequester->setVisible(
false);
462 if (!file.open(QIODevice::ReadOnly)) {
469 d->
ui.mNameEdit->setText(name);
474 d->
ui.mCategoryCombo->setCurrentIndex(d->
ui.mCategoryCombo->findText(category, Qt::MatchFixedString));
479 d->
ui.changelog->setText(changelog);
484 d->
ui.mSummaryEdit->setText(description);
489 d->
ui.priceCheckBox->setVisible(enabled);
490 d->
ui.priceGroupBox->setVisible(enabled);
495 d->
ui.priceCheckBox->setEnabled(
true);
496 d->
ui.priceSpinBox->setValue(price);
501 d->
ui.priceReasonLineEdit->setText(reason);
506 d->
ui.mVersionEdit->setText(version);
515 d->
ui.previewImage1->setPixmap(preview.scaled(d->
ui.previewImage1->size()));
519 d->
ui.previewImage2->setPixmap(preview.scaled(d->
ui.previewImage2->size()));
523 d->
ui.previewImage3->setPixmap(preview.scaled(d->
ui.previewImage3->size()));
526 kError() <<
"Wrong preview image file number";
533 ui.priceGroupBox->setEnabled(priceEnabled);
538 categories = loadedCategories;
541 if (categories.count() == 0) {
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(
", ")),
551 foreach(Attica::Category c, categories) {
552 ui.mCategoryCombo->addItem(c.name(), c.id());
554 atticaHelper->loadContentByCurrentUser();
568 q->button(KDialog::Cancel)->setEnabled(
false);
570 ui.uploadButton->setEnabled(
false);
573 ui.uploadProgressBar->setMinimum(0);
574 ui.uploadProgressBar->setMaximum(0);
575 ui.uploadProgressBar->setValue(0);
578 QString categoryName = ui.mCategoryCombo->currentText();
580 Attica::Category category;
581 while (iter != categories.constEnd()) {
582 if (iter->name() == categoryName) {
588 if (!category.isValid()) {
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());
601 QString licenseId = ui.mLicenseCombo->itemData(ui.mLicenseCombo->currentIndex()).toString();
602 if (licenseId.isEmpty()) {
604 content.addAttribute(
"licensetype",
"0");
605 content.addAttribute(
"license", ui.mLicenseCombo->currentText());
607 content.addAttribute(
"licensetype", licenseId);
610 content.addAttribute(
"changelog", ui.changelog->toPlainText());
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());
622 if (ui.radioNewUpload->isChecked()) {
624 Attica::ItemPostJob<Attica::Content>* job = currentProvider().addNewContent(category, content);
625 q->connect(job, SIGNAL(finished(Attica::BaseJob*)), q, SLOT(_k_contentAdded(Attica::BaseJob*)));
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*)));
637 KUrl url = KFileDialog::getImageOpenUrl(
KUrl(), q,
i18n(
"Select preview image"));
641 ui.previewImage1->setPixmap(preview.scaled(ui.previewImage1->size()));
646 KUrl url = KFileDialog::getImageOpenUrl(
KUrl(), q,
i18n(
"Select preview image"));
649 ui.previewImage2->setPixmap(preview.scaled(ui.previewImage1->size()));
654 KUrl url = KFileDialog::getImageOpenUrl(
KUrl(), q,
i18n(
"Select preview image"));
657 ui.previewImage3->setPixmap(preview.scaled(ui.previewImage1->size()));
662 if (baseJob->metadata().error()) {
663 if (baseJob->metadata().error() == Attica::Metadata::NetworkError) {
667 if (baseJob->metadata().error() == Attica::Metadata::OcsError) {
668 if (baseJob->metadata().statusCode() == 102)
674 ui.createContentImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
676 Attica::ItemPostJob<Attica::Content> * job =
static_cast<Attica::ItemPostJob<Attica::Content> *
>(baseJob);
677 if (job->metadata().error() != Attica::Metadata::NoError) {
683 QString id = job->result().id();
688 if (!uploadFile.isEmpty()) {
689 doUpload(
QString(), uploadFile);
691 doUpload(
QString(), ui.uploadFileRequester->url());
695 if (!previewFile1.isEmpty()) {
696 doUpload(
"1", previewFile1);
698 if (!previewFile2.isEmpty()) {
699 doUpload(
"2", previewFile2);
701 if (!previewFile3.isEmpty()) {
702 doUpload(
"3", previewFile3);
705 if (ui.radioNewUpload->isChecked()) {
706 atticaHelper->loadDetailsLink(contentId);
711 KRun::runUrl(atticaHelper->provider().getRegisterAccountUrl(),
"text/html", q);
717 if (!file.open(QIODevice::ReadOnly)) {
723 QByteArray fileContents;
724 fileContents.append(file.readAll());
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*)));
749 ui.uploadContentImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
750 finishedContents =
true;
751 uploadFileFinished();
756 ui.uploadPreview1ImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
757 finishedPreview1 =
true;
758 uploadFileFinished();
763 ui.uploadPreview2ImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
764 finishedPreview2 =
true;
765 uploadFileFinished();
770 ui.uploadPreview3ImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
771 finishedPreview3 =
true;
772 uploadFileFinished();
778 if (finishedContents && (previewFile1.isEmpty() || finishedPreview1)
779 && (previewFile2.isEmpty() || finishedPreview2)
780 && (previewFile3.isEmpty() || finishedPreview3)) {
782 ui.uploadProgressBar->setMinimum(0);
783 ui.uploadProgressBar->setMaximum(100);
784 ui.uploadProgressBar->setValue(100);
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));
796 #include "uploaddialog.moc"