24 #include <QtGui/QLabel>
25 #include <QtGui/QLayout>
26 #include <QtGui/QDoubleSpinBox>
27 #include <QtCore/QString>
28 #include <QtCore/QSignalMapper>
47 ui.setupUi(_mainWidget);
53 kError() <<
"No knsrc file named '" << configfile <<
"' was found." << endl;
61 kError() <<
"No knsrc file named '" << configfile <<
"' was found." << endl;
67 kDebug() <<
"Loading KNewStuff3 config: " << configfile;
68 group = conf.
group(
"KNewStuff3");
70 kError() <<
"A knsrc file was found but it doesn't contain a KNewStuff3 section." << endl;
89 ui.mCategoryLabel->setVisible(
false);
90 ui.mCategoryCombo->setVisible(
false);
116 busyWidget->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
117 ui.busyWidget->setLayout(
new QHBoxLayout());
126 ui.busyLabel->setText(message);
127 busyWidget->setVisible(
true);
132 ui.busyLabel->setText(message);
133 busyWidget->setVisible(
false);
138 ui.stackedWidget->setCurrentIndex(page);
141 switch (ui.stackedWidget->currentIndex()) {
142 case UserPasswordPage:
143 ui.username->setFocus();
147 case FileNewUpdatePage:
148 atticaHelper->loadLicenses();
149 atticaHelper->loadCurrency();
150 ui.uploadButton->setFocus();
151 setBusy(
i18n(
"Fetching license data from server..."));
155 if (ui.radioUpdate->isChecked()) {
157 atticaHelper->loadContent(ui.userContentList->currentItem()->data(Qt::UserRole).toString());
158 setBusy(
i18n(
"Fetching content data from server..."));
161 ui.mNameEdit->setFocus();
164 case UploadFinalPage:
165 if (previewFile1.isEmpty()) {
166 ui.uploadPreview1ImageLabel->setVisible(
false);
167 ui.uploadPreview1Label->setVisible(
false);
169 if (previewFile2.isEmpty()) {
170 ui.uploadPreview2ImageLabel->setVisible(
false);
171 ui.uploadPreview2Label->setVisible(
false);
173 if (previewFile3.isEmpty()) {
174 ui.uploadPreview3ImageLabel->setVisible(
false);
175 ui.uploadPreview3Label->setVisible(
false);
185 bool firstPage = ui.stackedWidget->currentIndex() == 0;
188 bool nextEnabled =
false;
189 switch (ui.stackedWidget->currentIndex()) {
190 case UserPasswordPage:
191 if (ui.providerComboBox->count() > 0 && !ui.username->text().isEmpty() && !ui.password->text().isEmpty()) {
196 case FileNewUpdatePage:
198 if (!uploadFile.isEmpty() || ui.uploadFileRequester->url().isLocalFile()) {
199 if (ui.radioNewUpload->isChecked() || ui.userContentList->currentRow() >= 0) {
206 if (!ui.mNameEdit->text().isEmpty()) {
215 case UploadFinalPage:
231 if (providers.size() == 0) {
233 ui.stackedWidget->setEnabled(
false);
234 kWarning() <<
"Could not load providers.";
238 ui.providerComboBox->addItems(providers);
239 ui.providerComboBox->setCurrentIndex(0);
240 atticaHelper->setCurrentProvider(providers.at(0));
244 if (atticaHelper->loadCredentials(user, pass)) {
245 ui.username->setText(user);
246 ui.password->setText(pass);
253 atticaHelper->setCurrentProvider(providerName);
254 ui.username->clear();
255 ui.password->clear();
258 if (atticaHelper->loadCredentials(user, pass)) {
259 ui.username->setText(user);
260 ui.password->setText(pass);
267 _k_showPage(ui.stackedWidget->currentIndex()-1);
273 if (ui.stackedWidget->currentIndex() == UserPasswordPage) {
274 setBusy(
i18n(
"Checking login..."));
276 ui.providerComboBox->setEnabled(
false);
277 ui.username->setEnabled(
false);
278 ui.password->setEnabled(
false);
279 atticaHelper->checkLogin(ui.username->text(), ui.password->text());
281 _k_showPage(ui.stackedWidget->currentIndex()+1);
287 ui.providerComboBox->setEnabled(
true);
288 ui.username->setEnabled(
true);
289 ui.password->setEnabled(
true);
292 atticaHelper->saveCredentials(ui.username->text(), ui.password->text());
293 _k_showPage(FileNewUpdatePage);
295 atticaHelper->loadCategories(categoryNames);
296 setBusy(
i18n(
"Fetching your previously updated content..."));
299 setIdle(
i18n(
"Could not verify login, please try again."));
305 ui.mLicenseCombo->clear();
306 foreach (Attica::License license, licenses) {
307 ui.mLicenseCombo->addItem(license.name(), license.id());
313 ui.priceCurrency->setText(currency);
318 setIdle(
i18n(
"Fetching your previously updated content finished."));
320 foreach(Attica::Content content, contentList) {
321 QListWidgetItem *contentItem =
new QListWidgetItem(content.name());
322 contentItem->setData(Qt::UserRole, content.id());
323 ui.userContentList->addItem(contentItem);
326 if (ui.userContentList->count() > 0) {
327 ui.userContentList->setCurrentRow(0);
328 ui.radioUpdate->setEnabled(
true);
336 setIdle(
i18n(
"Fetching content data from server finished."));
338 contentId = content.id();
340 ui.mNameEdit->setText(content.name());
341 ui.mSummaryEdit->setText(content.description());
342 ui.mVersionEdit->setText(content.version());
343 ui.changelog->setText(content.changelog());
344 ui.priceCheckBox->setChecked(content.attribute(
"downloadbuy1") ==
"1");
345 ui.priceSpinBox->setValue(content.attribute(
"downloadbuyprice1").toDouble());
346 ui.priceReasonLineEdit->setText(content.attribute(
"downloadbuyreason1"));
348 bool conversionOk =
false;
349 int licenseNumber = content.license().toInt(&conversionOk);
352 int row = ui.mLicenseCombo->findData(licenseNumber, Qt::UserRole);
353 ui.mLicenseCombo->setCurrentIndex(row);
355 ui.mLicenseCombo->setEditText(content.license());
358 ui.contentWebsiteLink->setText(QLatin1String(
"<a href=\"") + content.detailpage().toString() + QLatin1String(
"\">")
359 +
i18nc(
"A link to the website where the get hot new stuff upload can be seen",
"Visit website") + QLatin1String(
"</a>"));
360 ui.fetchContentLinkImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
367 ui.previewImage1->setPixmap(QPixmap::fromImage(image));
370 ui.previewImage2->setPixmap(QPixmap::fromImage(image));
373 ui.previewImage3->setPixmap(QPixmap::fromImage(image));
380 ui.userContentList->setEnabled(update);
388 init(name +
".knsrc");
402 bool UploadDialog::init(
const QString &configfile)
404 bool success = d->
init(configfile);
418 connect(d->
ui.username, SIGNAL(textChanged(
QString)),
this, SLOT(_k_updatePage()));
420 connect(d->
ui.password, SIGNAL(textChanged(
QString)),
this, SLOT(_k_updatePage()));
421 connect(d->
ui.mNameEdit, SIGNAL(textChanged(
QString)),
this, SLOT(_k_updatePage()));
422 connect(d->
ui.uploadFileRequester, SIGNAL(textChanged(
QString)),
this, SLOT(_k_updatePage()));
423 connect(d->
ui.priceCheckBox, SIGNAL(toggled(
bool)),
this, SLOT(_k_priceToggled(
bool)));
425 connect(d->
ui.uploadButton, SIGNAL(clicked()),
this, SLOT(_k_startUpload()));
427 connect(
this, SIGNAL(
user3Clicked()),
this, SLOT(_k_backPage()));
428 connect(
this, SIGNAL(
user2Clicked()),
this, SLOT(_k_nextPage()));
431 d->
ui.mTitleWidget->setText(
i18nc(
"Program name followed by 'Add On Uploader'",
432 "%1 Add-On Uploader",
447 d->
ui.uploadFileLabel->setVisible(
false);
448 d->
ui.uploadFileRequester->setVisible(
false);
451 if (!file.open(QIODevice::ReadOnly)) {
458 d->
ui.mNameEdit->setText(name);
463 d->
ui.mCategoryCombo->setCurrentIndex(d->
ui.mCategoryCombo->findText(category, Qt::MatchFixedString));
468 d->
ui.changelog->setText(changelog);
473 d->
ui.mSummaryEdit->setText(description);
478 d->
ui.priceCheckBox->setVisible(enabled);
479 d->
ui.priceGroupBox->setVisible(enabled);
484 d->
ui.priceCheckBox->setEnabled(
true);
485 d->
ui.priceSpinBox->setValue(price);
490 d->
ui.priceReasonLineEdit->setText(reason);
495 d->
ui.mVersionEdit->setText(version);
504 d->
ui.previewImage1->setPixmap(preview.scaled(d->
ui.previewImage1->size()));
508 d->
ui.previewImage2->setPixmap(preview.scaled(d->
ui.previewImage2->size()));
512 d->
ui.previewImage3->setPixmap(preview.scaled(d->
ui.previewImage3->size()));
515 kError() <<
"Wrong preview image file number";
522 ui.priceGroupBox->setEnabled(priceEnabled);
527 categories = loadedCategories;
530 if (categories.count() == 0) {
532 i18np(
"The server does not recognize the category %2 to which you are trying to upload.",
533 "The server does not recognize any of the categories to which you are trying to upload: %2",
534 categoryNames.size(), categoryNames.join(
", ")),
540 foreach(Attica::Category c, categories) {
541 ui.mCategoryCombo->addItem(c.name(), c.id());
543 atticaHelper->loadContentByCurrentUser();
559 ui.uploadButton->setEnabled(
false);
562 ui.uploadProgressBar->setMinimum(0);
563 ui.uploadProgressBar->setMaximum(0);
564 ui.uploadProgressBar->setValue(0);
567 QString categoryName = ui.mCategoryCombo->currentText();
568 QList<Attica::Category>::const_iterator iter = categories.constBegin();
569 Attica::Category category;
570 while (iter != categories.constEnd()) {
571 if (iter->name() == categoryName) {
577 if (!category.isValid()) {
583 Attica::Content content;
584 content.setName(ui.mNameEdit->text());
585 QString summary = ui.mSummaryEdit->toPlainText();
586 content.addAttribute(
"description", summary);
587 content.addAttribute(
"version", ui.mVersionEdit->text());
590 QString licenseId = ui.mLicenseCombo->itemData(ui.mLicenseCombo->currentIndex()).toString();
591 if (licenseId.isEmpty()) {
593 content.addAttribute(
"licensetype",
"0");
594 content.addAttribute(
"license", ui.mLicenseCombo->currentText());
596 content.addAttribute(
"licensetype", licenseId);
599 content.addAttribute(
"changelog", ui.changelog->toPlainText());
607 content.addAttribute(
"downloadbuy1", ui.priceCheckBox->isChecked() ?
"1" :
"0");
608 content.addAttribute(
"downloadbuyprice1", QString::number(ui.priceSpinBox->value()));
609 content.addAttribute(
"downloadbuyreason1", ui.priceReasonLineEdit->text());
611 if (ui.radioNewUpload->isChecked()) {
613 Attica::ItemPostJob<Attica::Content>* job = currentProvider().addNewContent(category, content);
614 q->connect(job, SIGNAL(
finished(Attica::BaseJob*)), q, SLOT(_k_contentAdded(Attica::BaseJob*)));
618 Attica::ItemPostJob<Attica::Content>* job = currentProvider().editContent(category, ui.userContentList->currentItem()->data(Qt::UserRole).toString(), content);
619 q->connect(job, SIGNAL(
finished(Attica::BaseJob*)), q, SLOT(_k_contentAdded(Attica::BaseJob*)));
630 ui.previewImage1->setPixmap(preview.scaled(ui.previewImage1->size()));
638 ui.previewImage2->setPixmap(preview.scaled(ui.previewImage1->size()));
646 ui.previewImage3->setPixmap(preview.scaled(ui.previewImage1->size()));
651 if (baseJob->metadata().error()) {
652 if (baseJob->metadata().error() == Attica::Metadata::NetworkError) {
656 if (baseJob->metadata().error() == Attica::Metadata::OcsError) {
657 if (baseJob->metadata().statusCode() == 102)
663 ui.createContentImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
665 Attica::ItemPostJob<Attica::Content> * job =
static_cast<Attica::ItemPostJob<Attica::Content> *
>(baseJob);
666 if (job->metadata().error() != Attica::Metadata::NoError) {
672 QString id = job->result().id();
677 if (!uploadFile.isEmpty()) {
678 doUpload(
QString(), uploadFile);
680 doUpload(
QString(), ui.uploadFileRequester->url());
684 if (!previewFile1.isEmpty()) {
685 doUpload(
"1", previewFile1);
687 if (!previewFile2.isEmpty()) {
688 doUpload(
"2", previewFile2);
690 if (!previewFile3.isEmpty()) {
691 doUpload(
"3", previewFile3);
694 if (ui.radioNewUpload->isChecked()) {
695 atticaHelper->loadDetailsLink(contentId);
702 if (!file.open(QIODevice::ReadOnly)) {
708 QByteArray fileContents;
709 fileContents.append(file.readAll());
714 Attica::PostJob* job = 0;
715 if (index.isEmpty()) {
716 job = currentProvider().setDownloadFile(contentId, fileName, fileContents);
717 q->connect(job, SIGNAL(
finished(Attica::BaseJob*)), q, SLOT(_k_fileUploadFinished(Attica::BaseJob*)));
718 }
else if (index == QLatin1String(
"1")) {
719 job = currentProvider().setPreviewImage(contentId, index, fileName, fileContents);
720 q->connect(job, SIGNAL(
finished(Attica::BaseJob*)), q, SLOT(_k_preview1UploadFinished(Attica::BaseJob*)));
721 }
else if (index == QLatin1String(
"2")) {
722 job = currentProvider().setPreviewImage(contentId, index, fileName, fileContents);
723 q->connect(job, SIGNAL(
finished(Attica::BaseJob*)), q, SLOT(_k_preview2UploadFinished(Attica::BaseJob*)));
724 }
else if (index == QLatin1String(
"3")) {
725 job = currentProvider().setPreviewImage(contentId, index, fileName, fileContents);
726 q->connect(job, SIGNAL(
finished(Attica::BaseJob*)), q, SLOT(_k_preview3UploadFinished(Attica::BaseJob*)));
734 ui.uploadContentImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
735 finishedContents =
true;
736 uploadFileFinished();
741 ui.uploadPreview1ImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
742 finishedPreview1 =
true;
743 uploadFileFinished();
748 ui.uploadPreview2ImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
749 finishedPreview2 =
true;
750 uploadFileFinished();
755 ui.uploadPreview3ImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
756 finishedPreview3 =
true;
757 uploadFileFinished();
763 if (finishedContents && (previewFile1.isEmpty() || finishedPreview1)
764 && (previewFile2.isEmpty() || finishedPreview2)
765 && (previewFile3.isEmpty() || finishedPreview3)) {
767 ui.uploadProgressBar->setMinimum(0);
768 ui.uploadProgressBar->setMaximum(100);
769 ui.uploadProgressBar->setValue(100);
776 ui.contentWebsiteLink->setText(QLatin1String(
"<a href=\"") + url.toString() + QLatin1String(
"\">")
777 +
i18nc(
"A link to the website where the get hot new stuff upload can be seen",
"Visit website") + QLatin1String(
"</a>"));
778 ui.fetchContentLinkImageLabel->setPixmap(
KIcon(
"dialog-ok").pixmap(16));
781 #include "uploaddialog.moc"